blob: a55281c6da1de55464a10f9a3fc1342ee017e232 [file] [log] [blame]
Neels Hofmeyr538d2c52019-01-28 03:51:35 +01001/* FSM to manage multiple connections of an MGW endpoint
2 *
3 * (C) 2018-2019 by sysmocom - s.f.m.c. GmbH <info@sysmocom.de>
4 * All Rights Reserved
5 *
6 * Author: Neels Hofmeyr <neels@hofmeyr.de>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU Affero General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Affero General Public License for more details.
17 *
18 * You should have received a copy of the GNU Affero General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 *
21 */
22
23#include <sys/socket.h>
24#include <netinet/in.h>
25#include <arpa/inet.h>
26
27#include <osmocom/core/fsm.h>
28#include <osmocom/core/byteswap.h>
29#include <osmocom/core/tdef.h>
Pau Espin Pedrol729bf3e2020-08-28 19:28:07 +020030#include <osmocom/core/sockaddr_str.h>
Neels Hofmeyr538d2c52019-01-28 03:51:35 +010031
32#include <osmocom/mgcp_client/mgcp_client_endpoint_fsm.h>
33
34#define LOG_CI(ci, level, fmt, args...) do { \
35 if (!ci || !ci->ep) \
36 LOGP(DLGLOBAL, level, "(unknown MGW endpoint) " fmt, ## args); \
37 else \
38 LOG_MGCPC_EP(ci->ep, level, "CI[%d] %s%s%s: " fmt, \
39 (int)(ci - ci->ep->ci), \
40 ci->label ? : "-", \
41 ci->mgcp_ci_str[0] ? " CI=" : "", \
42 ci->mgcp_ci_str[0] ? ci->mgcp_ci_str : "", \
43 ## args); \
44 } while(0)
45
46#define LOG_CI_VERB(ci, level, fmt, args...) do { \
47 if (ci->verb_info.addr[0]) \
48 LOG_CI(ci, level, "%s %s:%u: " fmt, \
49 osmo_mgcp_verb_name(ci->verb), ci->verb_info.addr, ci->verb_info.port, \
50 ## args); \
51 else \
52 LOG_CI(ci, level, "%s: " fmt, \
53 osmo_mgcp_verb_name(ci->verb), \
54 ## args); \
55 } while(0)
56
57enum osmo_mgcpc_ep_fsm_state {
58 OSMO_MGCPC_EP_ST_UNUSED = 0,
59 OSMO_MGCPC_EP_ST_WAIT_MGW_RESPONSE,
60 OSMO_MGCPC_EP_ST_IN_USE,
61};
62
63enum osmo_mgcpc_ep_fsm_event {
64 _OSMO_MGCPC_EP_EV_LAST = 0,
65 /* and MGW response events are allocated dynamically */
66};
67
68#define FIRST_CI_EVENT (_OSMO_MGCPC_EP_EV_LAST + (_OSMO_MGCPC_EP_EV_LAST & 1)) /* rounded up to even nr */
69#define USABLE_CI ((32 - FIRST_CI_EVENT)/2)
70#define EV_TO_CI_IDX(event) ((event - FIRST_CI_EVENT) / 2)
71
72#define CI_EV_SUCCESS(ci) (FIRST_CI_EVENT + (((ci) - ci->ep->ci) * 2))
73#define CI_EV_FAILURE(ci) (CI_EV_SUCCESS(ci) + 1)
74
75static struct osmo_fsm osmo_mgcpc_ep_fsm;
76
Neels Hofmeyr3ff71282019-10-29 17:41:20 +010077struct fsm_notify {
Neels Hofmeyrf2bf8dc2019-10-29 17:39:56 +010078 struct llist_head entry;
Neels Hofmeyr3ff71282019-10-29 17:41:20 +010079 struct osmo_fsm_inst *fi;
80 uint32_t success;
81 uint32_t failure;
82 void *data;
83};
84
Neels Hofmeyr538d2c52019-01-28 03:51:35 +010085/*! One connection on an endpoint, corresponding to a connection identifier (CI) as returned by the MGW.
86 * An endpoint has a fixed number of slots of these, which may or may not be in use.
87 */
88struct osmo_mgcpc_ep_ci {
89 struct osmo_mgcpc_ep *ep;
90
91 bool occupied;
92 char label[64];
93 struct osmo_fsm_inst *mgcp_client_fi;
94
95 bool pending;
96 bool sent;
97 enum mgcp_verb verb;
98 struct mgcp_conn_peer verb_info;
Neels Hofmeyr3ff71282019-10-29 17:41:20 +010099 struct fsm_notify notify;
Neels Hofmeyr538d2c52019-01-28 03:51:35 +0100100
101 bool got_port_info;
102 struct mgcp_conn_peer rtp_info;
103 char mgcp_ci_str[MGCP_CONN_ID_LENGTH];
104};
105
106/*! An MGW endpoint with N connections, like "rtpbridge/23@mgw". */
107struct osmo_mgcpc_ep {
108 /*! MGCP client connection to the MGW. */
109 struct mgcp_client *mgcp_client;
110 struct osmo_fsm_inst *fi;
111
112 /*! Endpoint string; at first this might be a wildcard, and upon the first CRCX OK response, this will reflect
113 * the endpoint name returned by the MGW. */
114 char endpoint[MGCP_ENDPOINT_MAXLEN];
115
116 /*! Timeout definitions used for this endpoint, see osmo_mgcpc_ep_fsm_timeouts. */
117 const struct osmo_tdef *T_defs;
118
Neels Hofmeyrc5479fe2019-04-05 01:36:06 +0200119 /*! True as soon as the first CRCX OK is received. The endpoint name may be determined by the first CRCX
120 * response, so to dispatch any other messages, the FSM instance *must* wait for the first CRCX OK to arrive
121 * first. Once the endpoint name is pinpointed, any amount of operations may be dispatched concurrently. */
122 bool first_crcx_complete;
123
Neels Hofmeyr538d2c52019-01-28 03:51:35 +0100124 /*! Endpoint connection slots. Note that each connection has its own set of FSM event numbers to signal success
125 * and failure, depending on its index within this array. See CI_EV_SUCCESS and CI_EV_FAILURE. */
126 struct osmo_mgcpc_ep_ci ci[USABLE_CI];
Neels Hofmeyrf2bf8dc2019-10-29 17:39:56 +0100127
128 /*! Internal use: if a function keeps an fsm_notify for later dispatch while already clearing or re-using the
129 * ci[], the fsm_notify should be kept here to also get canceled by osmo_mgcpc_ep_cancel_notify(). */
130 struct llist_head background_notify;
Neels Hofmeyr538d2c52019-01-28 03:51:35 +0100131};
132
133const struct value_string osmo_mgcp_verb_names[] = {
134 { MGCP_VERB_CRCX, "CRCX" },
135 { MGCP_VERB_MDCX, "MDCX" },
136 { MGCP_VERB_DLCX, "DLCX" },
137 { MGCP_VERB_AUEP, "AUEP" },
138 { MGCP_VERB_RSIP, "RSIP" },
139 {}
140};
141
Neels Hofmeyrc5479fe2019-04-05 01:36:06 +0200142static void osmo_mgcpc_ep_count(struct osmo_mgcpc_ep *ep, int *occupied, int *pending_not_sent,
143 int *waiting_for_response);
144
Neels Hofmeyr538d2c52019-01-28 03:51:35 +0100145static struct osmo_mgcpc_ep_ci *osmo_mgcpc_ep_check_ci(struct osmo_mgcpc_ep_ci *ci)
146{
147 if (!ci)
148 return NULL;
149 if (!ci->ep)
150 return NULL;
151 if (ci < ci->ep->ci || ci >= &ci->ep->ci[USABLE_CI])
152 return NULL;
153 return ci;
154}
155
156static struct osmo_mgcpc_ep_ci *osmo_mgcpc_ep_ci_for_event(struct osmo_mgcpc_ep *ep, uint32_t event)
157{
158 int idx;
159 if (event < FIRST_CI_EVENT)
160 return NULL;
161 idx = EV_TO_CI_IDX(event);
162 if (idx >= sizeof(ep->ci))
163 return NULL;
164 return osmo_mgcpc_ep_check_ci(&ep->ci[idx]);
165}
166
167const char *osmo_mgcpc_ep_name(const struct osmo_mgcpc_ep *ep)
168{
169 if (!ep)
170 return "NULL";
171 if (ep->endpoint[0])
172 return ep->endpoint;
173 return osmo_fsm_inst_name(ep->fi);
174}
175
176const char *mgcp_conn_peer_name(const struct mgcp_conn_peer *info)
177{
178 /* I'd be fine with a smaller buffer and accept truncation, but gcc possibly refuses to build if
179 * this buffer is too small. */
180 static char buf[1024];
181
182 if (!info)
183 return "NULL";
184
185 if (info->endpoint[0]
186 && info->addr[0])
187 snprintf(buf, sizeof(buf), "%s:%s:%u",
188 info->endpoint, info->addr, info->port);
189 else if (info->endpoint[0])
190 snprintf(buf, sizeof(buf), "%s", info->endpoint);
191 else if (info->addr[0])
192 snprintf(buf, sizeof(buf), "%s:%u", info->addr, info->port);
193 else
194 return "empty";
195 return buf;
196}
197
198const char *osmo_mgcpc_ep_ci_name(const struct osmo_mgcpc_ep_ci *ci)
199{
200 const struct mgcp_conn_peer *rtp_info;
201
202 if (!ci)
203 return "NULL";
204
205 rtp_info = osmo_mgcpc_ep_ci_get_rtp_info(ci);
206
207 if (rtp_info)
208 return mgcp_conn_peer_name(rtp_info);
209 return osmo_mgcpc_ep_name(ci->ep);
210}
211
212const char *osmo_mgcpc_ep_ci_id(const struct osmo_mgcpc_ep_ci *ci)
213{
214 if (!ci || !ci->mgcp_ci_str[0])
215 return NULL;
216 return ci->mgcp_ci_str;
217}
218
219static struct value_string osmo_mgcpc_ep_fsm_event_names[33] = {};
220
221static char osmo_mgcpc_ep_fsm_event_name_bufs[32][32] = {};
222
223static void fill_event_names()
224{
225 int i;
226 for (i = 0; i < (ARRAY_SIZE(osmo_mgcpc_ep_fsm_event_names) - 1); i++) {
227 if (i < _OSMO_MGCPC_EP_EV_LAST)
228 continue;
229 if (i < FIRST_CI_EVENT || EV_TO_CI_IDX(i) > USABLE_CI) {
230 osmo_mgcpc_ep_fsm_event_names[i] = (struct value_string){i, "Unused"};
231 continue;
232 }
233 snprintf(osmo_mgcpc_ep_fsm_event_name_bufs[i], sizeof(osmo_mgcpc_ep_fsm_event_name_bufs[i]),
234 "MGW Response for CI #%d", EV_TO_CI_IDX(i));
235 osmo_mgcpc_ep_fsm_event_names[i] = (struct value_string){i, osmo_mgcpc_ep_fsm_event_name_bufs[i]};
236 }
237}
238
Neels Hofmeyr538d2c52019-01-28 03:51:35 +0100239static __attribute__((constructor)) void osmo_mgcpc_ep_fsm_init()
240{
241 OSMO_ASSERT(osmo_fsm_register(&osmo_mgcpc_ep_fsm) == 0);
242 fill_event_names();
243}
244
245struct osmo_mgcpc_ep *osmo_mgcpc_ep_fi_mgwep(struct osmo_fsm_inst *fi)
246{
247 OSMO_ASSERT(fi);
248 OSMO_ASSERT(fi->fsm == &osmo_mgcpc_ep_fsm);
249 OSMO_ASSERT(fi->priv);
250 return fi->priv;
251}
252
253/*! Allocate an osmo_mgcpc_ep FSM.
254 * MGCP messages to set up the endpoint will be sent on the given mgcp_client, as soon as the first
255 * osmo_mgcpc_ep_ci_request() is invoked.
256 *
Neels Hofmeyrca2aec02019-10-04 22:47:31 +0200257 * IMPORTANT: To avoid use-after-free problems, using this FSM requires use of deferred FSM deallocation using
258 * osmo_fsm_set_dealloc_ctx(), e.g. using osmo_select_main_ctx(OTC_SELECT) with osmo_select_main_ctx() as main loop.
259 *
Neels Hofmeyr538d2c52019-01-28 03:51:35 +0100260 * A typical sequence of events would be:
261 *
262 * ep = osmo_mgcpc_ep_alloc(..., mgcp_client_rtpbridge_wildcard(client));
263 * ci_to_ran = osmo_mgcpc_ep_ci_add(ep);
264 * osmo_mgcpc_ep_ci_request(ci_to_ran, MGCP_VERB_CRCX, verb_info,
265 * my_call_fsm, MY_EVENT_MGCP_OK, MY_EVENT_MGCP_FAIL);
266 * ci_to_cn = osmo_mgcpc_ep_ci_add(ep);
267 * osmo_mgcpc_ep_ci_request(ci_to_cn, MGCP_VERB_CRCX, verb_info,
268 * my_call_fsm, MY_EVENT_MGCP_OK, MY_EVENT_MGCP_FAIL);
269 * ...
270 * osmo_mgcpc_ep_ci_request(ci_to_ran, MGCP_VERB_MDCX, ...);
271 * ...
272 * osmo_mgcpc_ep_clear(ep);
273 * ep = NULL;
274 *
275 * \param parent Parent FSM.
276 * \param parent_term_event Event to dispatch to the parent on termination of this FSM instance.
277 * \param mgcp_client Connection to the MGW.
278 * \param T_defs Timeout definitions to be used for FSM states, see osmo_mgcpc_ep_fsm_timeouts.
279 * \param fsm_id FSM instance ID.
280 * \param endpoint_str_fmt The endpoint string format to send to the MGW upon the first CRCX.
281 * See mgcp_client_rtpbridge_wildcard() for "rtpbridge" endpoints.
282 */
283struct osmo_mgcpc_ep *osmo_mgcpc_ep_alloc(struct osmo_fsm_inst *parent, uint32_t parent_term_event,
284 struct mgcp_client *mgcp_client,
285 const struct osmo_tdef *T_defs,
286 const char *fsm_id,
287 const char *endpoint_str_fmt, ...)
288{
289 va_list ap;
290 struct osmo_fsm_inst *fi;
291 struct osmo_mgcpc_ep *ep;
292 int rc;
293
294 if (!mgcp_client)
295 return NULL;
296
297 fi = osmo_fsm_inst_alloc_child(&osmo_mgcpc_ep_fsm, parent, parent_term_event);
298 OSMO_ASSERT(fi);
299
300 osmo_fsm_inst_update_id(fi, fsm_id);
301
302 ep = talloc_zero(fi, struct osmo_mgcpc_ep);
303 OSMO_ASSERT(ep);
304
305 *ep = (struct osmo_mgcpc_ep){
306 .mgcp_client = mgcp_client,
307 .fi = fi,
308 .T_defs = T_defs,
309 };
Neels Hofmeyrf2bf8dc2019-10-29 17:39:56 +0100310 INIT_LLIST_HEAD(&ep->background_notify);
Neels Hofmeyr538d2c52019-01-28 03:51:35 +0100311 fi->priv = ep;
312
313 va_start(ap, endpoint_str_fmt);
314 rc = vsnprintf(ep->endpoint, sizeof(ep->endpoint), endpoint_str_fmt ? : "", ap);
315 va_end(ap);
316
317 if (rc <= 0 || rc >= sizeof(ep->endpoint)) {
318 LOG_MGCPC_EP(ep, LOGL_ERROR, "Endpoint name too long or too short: %s\n",
319 ep->endpoint);
320 osmo_fsm_inst_term(ep->fi, OSMO_FSM_TERM_ERROR, 0);
321 return NULL;
322 }
323
324 return ep;
325}
326
327/*! Add a connection to an endpoint.
328 * Allocate a connection identifier slot in the osmo_mgcpc_ep instance, do not yet dispatch a CRCX.
329 * The CRCX is dispatched only upon the first osmo_mgcpc_ep_ci_request().
330 * \param ep Parent endpoint instance.
331 * \param label_fmt Label for logging.
332 */
333struct osmo_mgcpc_ep_ci *osmo_mgcpc_ep_ci_add(struct osmo_mgcpc_ep *ep,
334 const char *label_fmt, ...)
335{
336 va_list ap;
337 int i;
338 struct osmo_mgcpc_ep_ci *ci;
339
340 for (i = 0; i < USABLE_CI; i++) {
341 ci = &ep->ci[i];
342
343 if (ci->occupied || ci->mgcp_client_fi)
344 continue;
345
346 *ci = (struct osmo_mgcpc_ep_ci){
347 .ep = ep,
348 .occupied = true,
349 };
350 if (label_fmt) {
351 va_start(ap, label_fmt);
352 vsnprintf(ci->label, sizeof(ci->label), label_fmt, ap);
353 va_end(ap);
354 }
355 return ci;
356 }
357
358 LOG_MGCPC_EP(ep, LOGL_ERROR,
359 "Cannot allocate another endpoint, all "
360 OSMO_STRINGIFY_VAL(USABLE_CI) " are in use\n");
361
362 return NULL;
363}
364
365static bool osmo_mgcpc_ep_fsm_check_state_chg_after_response(struct osmo_fsm_inst *fi);
366
367static void on_failure(struct osmo_mgcpc_ep_ci *ci)
368{
Neels Hofmeyrcc0b97e2019-10-01 19:44:10 +0200369 struct osmo_mgcpc_ep *ep = ci->ep;
Neels Hofmeyr3ff71282019-10-29 17:41:20 +0100370 struct fsm_notify notify;
Neels Hofmeyrcc0b97e2019-10-01 19:44:10 +0200371 int i;
Neels Hofmeyr538d2c52019-01-28 03:51:35 +0100372
373 if (!ci->occupied)
374 return;
375
Neels Hofmeyr3ff71282019-10-29 17:41:20 +0100376 /* When dispatching an event for this CI, the user may decide to trigger the next request for this conn right
377 * away. So we must be ready with a cleared *ci. Store the notify separately and clear before dispatching. */
378 notify = ci->notify;
Neels Hofmeyrf2bf8dc2019-10-29 17:39:56 +0100379 /* Register the planned notification in ep->background_notify so we also catch any osmo_mgcpc_ep_cancel_notify()
380 * that might be triggered between clearing the ci and actually dispatching the event. */
381 llist_add(&notify.entry, &ep->background_notify);
Neels Hofmeyr3ff71282019-10-29 17:41:20 +0100382
Neels Hofmeyr538d2c52019-01-28 03:51:35 +0100383 *ci = (struct osmo_mgcpc_ep_ci){
384 .ep = ci->ep,
385 };
386
Neels Hofmeyrcc0b97e2019-10-01 19:44:10 +0200387 /* An MGCP failure typically means the endpoint becomes unusable, cancel all pending request (except DLCX).
388 * Particularly, if two CRCX were scheduled and the first fails, we must no longer dispatch the second CRCX. */
389 for (i = 0; i < ARRAY_SIZE(ep->ci); i++) {
390 struct osmo_mgcpc_ep_ci *other_ci = &ep->ci[i];
391 if (other_ci == ci)
392 continue;
393 if (!other_ci->occupied)
394 continue;
395 if (!other_ci->pending)
396 continue;
397 if (other_ci->sent)
398 continue;
399 if (other_ci->verb == MGCP_VERB_DLCX)
400 continue;
401 /* Just clear the pending request, don't fire more events than below. */
402 other_ci->pending = false;
403 }
404
Neels Hofmeyr538d2c52019-01-28 03:51:35 +0100405 /* If this check has terminated the FSM instance, don't fire any more events to prevent use-after-free problems.
406 * The endpoint FSM does dispatch a term event to its parent, and everything should be cleaned like that. */
Neels Hofmeyrf2bf8dc2019-10-29 17:39:56 +0100407 if (!osmo_mgcpc_ep_fsm_check_state_chg_after_response(ep->fi)) {
408 /* The ep has deallocated, no need to llist_del(&notify.entry) here. */
Neels Hofmeyr538d2c52019-01-28 03:51:35 +0100409 return;
Neels Hofmeyrf2bf8dc2019-10-29 17:39:56 +0100410 }
Neels Hofmeyr538d2c52019-01-28 03:51:35 +0100411
Neels Hofmeyr3ff71282019-10-29 17:41:20 +0100412 if (notify.fi)
413 osmo_fsm_inst_dispatch(notify.fi, notify.failure, notify.data);
Neels Hofmeyrf2bf8dc2019-10-29 17:39:56 +0100414
415 llist_del(&notify.entry);
Neels Hofmeyr538d2c52019-01-28 03:51:35 +0100416}
417
Neels Hofmeyrc5479fe2019-04-05 01:36:06 +0200418static int update_endpoint_name(struct osmo_mgcpc_ep_ci *ci, const char *new_endpoint_name)
419{
420 struct osmo_mgcpc_ep *ep = ci->ep;
421 int rc;
422 int i;
423
424 if (!strcmp(ep->endpoint, new_endpoint_name)) {
425 /* Same endpoint name, nothing to do. */
426 return 0;
427 }
428
429 /* The endpoint name should only change on the very first CRCX response. */
430 if (ep->first_crcx_complete) {
431 LOG_CI(ci, LOGL_ERROR, "Reponse returned mismatching endpoint name."
432 " This is endpoint %s, instead received %s\n",
433 ep->endpoint, new_endpoint_name);
434 on_failure(ci);
435 return -EINVAL;
436 }
437
438 /* This is the first CRCX response, update endpoint name. */
439 rc = OSMO_STRLCPY_ARRAY(ep->endpoint, new_endpoint_name);
440 if (rc <= 0 || rc >= sizeof(ep->endpoint)) {
441 LOG_CI(ci, LOGL_ERROR, "Unable to copy endpoint name %s\n", osmo_quote_str(new_endpoint_name, -1));
442 osmo_mgcpc_ep_ci_dlcx(ci);
443 on_failure(ci);
444 return -ENOSPC;
445 }
446
447 /* Make sure already pending requests use this updated endpoint name. */
448 for (i = 0; i < ARRAY_SIZE(ep->ci); i++) {
449 struct osmo_mgcpc_ep_ci *other_ci = &ep->ci[i];
450 if (!other_ci->occupied)
451 continue;
452 if (!other_ci->pending)
453 continue;
454 if (other_ci->sent)
455 continue;
456 OSMO_STRLCPY_ARRAY(other_ci->verb_info.endpoint, ep->endpoint);
457 }
458 return 0;
459}
460
Neels Hofmeyr538d2c52019-01-28 03:51:35 +0100461static void on_success(struct osmo_mgcpc_ep_ci *ci, void *data)
462{
463 struct mgcp_conn_peer *rtp_info;
464
465 if (!ci->occupied)
466 return;
467
468 ci->pending = false;
469
Pau Espin Pedrol2741d6b2020-09-02 19:31:17 +0200470 rtp_info = data;
471
Neels Hofmeyr538d2c52019-01-28 03:51:35 +0100472 switch (ci->verb) {
473 case MGCP_VERB_CRCX:
474 /* If we sent a wildcarded endpoint name on CRCX, we need to store the resulting endpoint
475 * name here. Also, we receive the MGW's RTP port information. */
Neels Hofmeyr538d2c52019-01-28 03:51:35 +0100476 osmo_strlcpy(ci->mgcp_ci_str, mgcp_conn_get_ci(ci->mgcp_client_fi),
477 sizeof(ci->mgcp_ci_str));
478 if (rtp_info->endpoint[0]) {
Neels Hofmeyrc5479fe2019-04-05 01:36:06 +0200479 /* On errors, this instance might already be deallocated. Make sure to not access anything after
480 * error. */
481 if (update_endpoint_name(ci, rtp_info->endpoint))
Neels Hofmeyr538d2c52019-01-28 03:51:35 +0100482 return;
Neels Hofmeyr538d2c52019-01-28 03:51:35 +0100483 }
Neels Hofmeyrc5479fe2019-04-05 01:36:06 +0200484 ci->ep->first_crcx_complete = true;
Pau Espin Pedrol2741d6b2020-09-02 19:31:17 +0200485 OSMO_ASSERT(rtp_info);
486 /* fall through */
487 case MGCP_VERB_MDCX:
488 /* Always update the received RTP ip/port information, since MGW
489 * may provide new one after remote end params changed */
490 if (rtp_info) {
491 ci->got_port_info = true;
492 ci->rtp_info = *rtp_info;
493 }
Neels Hofmeyr538d2c52019-01-28 03:51:35 +0100494 break;
495
496 default:
497 break;
498 }
499
500 LOG_CI(ci, LOGL_DEBUG, "received successful response to %s: RTP=%s%s\n",
501 osmo_mgcp_verb_name(ci->verb),
502 mgcp_conn_peer_name(ci->got_port_info? &ci->rtp_info : NULL),
Neels Hofmeyr3ff71282019-10-29 17:41:20 +0100503 ci->notify.fi ? "" : " (not sending a notification)");
Neels Hofmeyr538d2c52019-01-28 03:51:35 +0100504
Neels Hofmeyr3ff71282019-10-29 17:41:20 +0100505 if (ci->notify.fi)
506 osmo_fsm_inst_dispatch(ci->notify.fi, ci->notify.success, ci->notify.data);
Neels Hofmeyr538d2c52019-01-28 03:51:35 +0100507
508 osmo_mgcpc_ep_fsm_check_state_chg_after_response(ci->ep->fi);
509}
510
Neels Hofmeyr59e7cf42021-05-01 02:31:01 +0000511/*! Return the MGW's local RTP port information for this connection, i.e. the local port that MGW is receiving on, as
512 * returned by the last CRCX-OK / MDCX-OK message. */
Neels Hofmeyr538d2c52019-01-28 03:51:35 +0100513const struct mgcp_conn_peer *osmo_mgcpc_ep_ci_get_rtp_info(const struct osmo_mgcpc_ep_ci *ci)
514{
515 ci = osmo_mgcpc_ep_check_ci((struct osmo_mgcpc_ep_ci*)ci);
516 if (!ci)
517 return NULL;
518 if (!ci->got_port_info)
519 return NULL;
520 return &ci->rtp_info;
521}
522
Neels Hofmeyr59e7cf42021-05-01 02:31:01 +0000523/*! Return the MGW's remote RTP port information for this connection, i.e. the remote RTP port that the MGW is sending
524 * to, as sent to the MGW by the last CRCX / MDCX message. */
525const struct mgcp_conn_peer *osmo_mgcpc_ep_ci_get_remote_rtp_info(const struct osmo_mgcpc_ep_ci *ci)
526{
527 ci = osmo_mgcpc_ep_check_ci((struct osmo_mgcpc_ep_ci*)ci);
528 if (!ci)
529 return NULL;
530 return &ci->verb_info;
531}
532
Neels Hofmeyr538d2c52019-01-28 03:51:35 +0100533/*! Return the MGW's RTP port information for this connection, as returned by the last CRCX/MDCX OK message. */
534bool osmo_mgcpc_ep_ci_get_crcx_info_to_sockaddr(const struct osmo_mgcpc_ep_ci *ci, struct sockaddr_storage *dest)
535{
536 const struct mgcp_conn_peer *rtp_info;
Pau Espin Pedrol729bf3e2020-08-28 19:28:07 +0200537 int family;
Neels Hofmeyr538d2c52019-01-28 03:51:35 +0100538 struct sockaddr_in *sin;
Pau Espin Pedrol729bf3e2020-08-28 19:28:07 +0200539 struct sockaddr_in6 *sin6;
Neels Hofmeyr538d2c52019-01-28 03:51:35 +0100540
541 rtp_info = osmo_mgcpc_ep_ci_get_rtp_info(ci);
542 if (!rtp_info)
543 return false;
544
Pau Espin Pedrol729bf3e2020-08-28 19:28:07 +0200545 family = osmo_ip_str_type(rtp_info->addr);
546 switch (family) {
547 case AF_INET:
548 sin = (struct sockaddr_in *)dest;
549 sin->sin_family = AF_INET;
550 sin->sin_port = osmo_ntohs(rtp_info->port);
551 if (inet_pton(AF_INET, rtp_info->addr, &sin->sin_addr) != 1)
552 return false;
553 break;
554 case AF_INET6:
555 sin6 = (struct sockaddr_in6 *)dest;
556 sin6->sin6_family = AF_INET6;
557 sin6->sin6_port = osmo_ntohs(rtp_info->port);
558 if (inet_pton(AF_INET6, rtp_info->addr, &sin6->sin6_addr) != 1)
559 return false;
560 break;
561 default:
562 return false;
563 }
Neels Hofmeyr538d2c52019-01-28 03:51:35 +0100564 return true;
565}
566
Pau Espin Pedrol30907dc2019-05-06 11:54:17 +0200567bool osmo_mgcpc_ep_ci_get_crcx_info_to_osmux_cid(const struct osmo_mgcpc_ep_ci *ci, uint8_t* cid)
568{
569 const struct mgcp_conn_peer *rtp_info;
570
571 rtp_info = osmo_mgcpc_ep_ci_get_rtp_info(ci);
572 if (!rtp_info)
573 return false;
574
575 if (!rtp_info->x_osmo_osmux_use)
576 return false;
577
578 *cid = rtp_info->x_osmo_osmux_cid;
579 return true;
580}
Neels Hofmeyr538d2c52019-01-28 03:51:35 +0100581
582static const struct osmo_tdef_state_timeout osmo_mgcpc_ep_fsm_timeouts[32] = {
Neels Hofmeyrfbf07f32020-09-15 23:59:23 +0200583 [OSMO_MGCPC_EP_ST_WAIT_MGW_RESPONSE] = { .T=-2427 },
Neels Hofmeyr538d2c52019-01-28 03:51:35 +0100584};
585
586/* Transition to a state, using the T timer defined in assignment_fsm_timeouts.
587 * The actual timeout value is in turn obtained from osmo_mgcpc_ep.T_defs.
588 * Assumes local variable fi exists. */
589#define osmo_mgcpc_ep_fsm_state_chg(state) \
590 osmo_tdef_fsm_inst_state_chg(fi, state, osmo_mgcpc_ep_fsm_timeouts, \
591 ((struct osmo_mgcpc_ep*)fi->priv)->T_defs, 5)
592
593/*! Dispatch an actual CRCX/MDCX/DLCX message for this connection.
Neels Hofmeyrf2bf8dc2019-10-29 17:39:56 +0100594 *
595 * If the 'notify' instance deallocates before it received a notification of event_success or event_failure,
596 * osmo_mgcpc_ep_ci_cancel_notify() or osmo_mgcpc_ep_cancel_notify() must be called. It is not harmful to cancel
597 * notification after an event has been received.
598 *
Neels Hofmeyr538d2c52019-01-28 03:51:35 +0100599 * \param ci Connection identifier as obtained from osmo_mgcpc_ep_ci_add().
600 * \param verb MGCP operation to dispatch.
601 * \param verb_info Parameters for the MGCP operation.
602 * \param notify Peer FSM instance to notify of completed/failed operation.
603 * \param event_success Which event to dispatch to 'notify' upon OK response.
604 * \param event_failure Which event to dispatch to 'notify' upon failure response.
605 * \param notify_data Data pointer to pass to the event dispatch for both success and failure.
606 */
607void osmo_mgcpc_ep_ci_request(struct osmo_mgcpc_ep_ci *ci,
608 enum mgcp_verb verb, const struct mgcp_conn_peer *verb_info,
609 struct osmo_fsm_inst *notify,
610 uint32_t event_success, uint32_t event_failure,
611 void *notify_data)
612{
613 struct osmo_mgcpc_ep *ep;
614 struct osmo_fsm_inst *fi;
615 struct osmo_mgcpc_ep_ci cleared_ci;
616 ci = osmo_mgcpc_ep_check_ci(ci);
617
618 if (!ci) {
619 LOGP(DLGLOBAL, LOGL_ERROR, "Invalid MGW endpoint request: no ci\n");
620 goto dispatch_error;
621 }
622 if (!verb_info && verb != MGCP_VERB_DLCX) {
623 LOG_CI(ci, LOGL_ERROR, "Invalid MGW endpoint request: missing verb details for %s\n",
624 osmo_mgcp_verb_name(verb));
625 goto dispatch_error;
626 }
627 if ((verb < 0) || (verb > MGCP_VERB_RSIP)) {
628 LOG_CI(ci, LOGL_ERROR, "Invalid MGW endpoint request: unknown verb: %s\n",
629 osmo_mgcp_verb_name(verb));
630 goto dispatch_error;
631 }
632
633 ep = ci->ep;
634 fi = ep->fi;
635
636 /* Clear volatile state by explicitly keeping those that should remain. Because we can't assign
637 * the char[] directly, dance through cleared_ci and copy back. */
638 cleared_ci = (struct osmo_mgcpc_ep_ci){
639 .ep = ep,
640 .mgcp_client_fi = ci->mgcp_client_fi,
641 .got_port_info = ci->got_port_info,
642 .rtp_info = ci->rtp_info,
643
644 .occupied = true,
645 /* .pending = true follows below */
646 .verb = verb,
Neels Hofmeyr3ff71282019-10-29 17:41:20 +0100647 .notify = {
648 .fi = notify,
649 .success = event_success,
650 .failure = event_failure,
651 .data = notify_data,
652 }
Neels Hofmeyr538d2c52019-01-28 03:51:35 +0100653 };
654 osmo_strlcpy(cleared_ci.label, ci->label, sizeof(cleared_ci.label));
655 osmo_strlcpy(cleared_ci.mgcp_ci_str, ci->mgcp_ci_str, sizeof(cleared_ci.mgcp_ci_str));
656 *ci = cleared_ci;
657
Neels Hofmeyr3ff71282019-10-29 17:41:20 +0100658 LOG_CI_VERB(ci, LOGL_DEBUG, "notify=%s\n", osmo_fsm_inst_name(ci->notify.fi));
Neels Hofmeyr538d2c52019-01-28 03:51:35 +0100659
660 if (verb_info)
661 ci->verb_info = *verb_info;
662
663 if (ep->endpoint[0]) {
664 if (ci->verb_info.endpoint[0] && strcmp(ci->verb_info.endpoint, ep->endpoint))
665 LOG_CI(ci, LOGL_ERROR,
666 "Warning: Requested %s on endpoint %s, but this CI is on endpoint %s."
667 " Using the proper endpoint instead.\n",
668 osmo_mgcp_verb_name(verb), ci->verb_info.endpoint, ep->endpoint);
669 osmo_strlcpy(ci->verb_info.endpoint, ep->endpoint, sizeof(ci->verb_info.endpoint));
670 }
671
672 switch (ci->verb) {
673 case MGCP_VERB_CRCX:
674 if (ci->mgcp_client_fi) {
675 LOG_CI(ci, LOGL_ERROR, "CRCX can be called only once per MGW endpoint CI\n");
676 on_failure(ci);
677 return;
678 }
679 break;
680
681 case MGCP_VERB_MDCX:
682 if (!ci->mgcp_client_fi) {
683 LOG_CI_VERB(ci, LOGL_ERROR, "The first verb on an unused MGW endpoint CI must be CRCX, not %s\n",
684 osmo_mgcp_verb_name(ci->verb));
685 on_failure(ci);
686 return;
687 }
688 break;
689
690 case MGCP_VERB_DLCX:
691 if (!ci->mgcp_client_fi) {
692 LOG_CI_VERB(ci, LOGL_DEBUG, "Ignoring DLCX on unused MGW endpoint CI\n");
693 return;
694 }
695 break;
696
697 default:
698 LOG_CI(ci, LOGL_ERROR, "This verb is not supported: %s\n", osmo_mgcp_verb_name(ci->verb));
699 on_failure(ci);
700 return;
701 }
702
703 ci->pending = true;
704
705 LOG_CI_VERB(ci, LOGL_DEBUG, "Scheduling\n");
706
707 if (ep->fi->state != OSMO_MGCPC_EP_ST_WAIT_MGW_RESPONSE)
708 osmo_mgcpc_ep_fsm_state_chg(OSMO_MGCPC_EP_ST_WAIT_MGW_RESPONSE);
709
710 return;
711dispatch_error:
712 if (notify)
713 osmo_fsm_inst_dispatch(notify, event_failure, notify_data);
714}
715
Neels Hofmeyrf2bf8dc2019-10-29 17:39:56 +0100716/*! No longer notify for any state changes for any conns of this endpoint.
717 * Useful if the notify instance passed to osmo_mgcpc_ep_ci_request() is about to deallocate.
718 * \param ep The endpoint FSM instance.
719 * \param notify Which target to cancel notification for, if NULL cancel all notifications. */
720void osmo_mgcpc_ep_cancel_notify(struct osmo_mgcpc_ep *ep, struct osmo_fsm_inst *notify)
721{
722 struct fsm_notify *n;
723 int i;
724 for (i = 0; i < ARRAY_SIZE(ep->ci); i++) {
725 struct osmo_mgcpc_ep_ci *ci = &ep->ci[i];
726 if (!notify || ci->notify.fi == notify)
727 ci->notify.fi = NULL;
728 }
729 llist_for_each_entry(n, &ep->background_notify, entry) {
730 if (!notify || n->fi == notify)
731 n->fi = NULL;
732 }
733
734}
735
Neels Hofmeyr923d60b2019-10-29 17:40:08 +0100736/* Return the osmo_mgcpc_ep that this conn belongs to. */
737struct osmo_mgcpc_ep *osmo_mgcpc_ep_ci_ep(struct osmo_mgcpc_ep_ci *conn)
738{
739 if (!conn)
740 return NULL;
741 return conn->ep;
742}
743
Neels Hofmeyr538d2c52019-01-28 03:51:35 +0100744static int send_verb(struct osmo_mgcpc_ep_ci *ci)
745{
746 int rc;
747 struct osmo_mgcpc_ep *ep = ci->ep;
Neels Hofmeyr055ded72019-10-29 17:46:30 +0100748 struct fsm_notify notify;
Neels Hofmeyr538d2c52019-01-28 03:51:35 +0100749
750 if (!ci->occupied || !ci->pending || ci->sent)
751 return 0;
752
753 switch (ci->verb) {
754
755 case MGCP_VERB_CRCX:
756 OSMO_ASSERT(!ci->mgcp_client_fi);
757 LOG_CI_VERB(ci, LOGL_DEBUG, "Sending\n");
758 ci->mgcp_client_fi = mgcp_conn_create(ep->mgcp_client, ep->fi,
759 CI_EV_FAILURE(ci), CI_EV_SUCCESS(ci),
760 &ci->verb_info);
761 ci->sent = true;
762 if (!ci->mgcp_client_fi){
763 LOG_CI_VERB(ci, LOGL_ERROR, "Cannot send\n");
764 on_failure(ci);
Neels Hofmeyrc5479fe2019-04-05 01:36:06 +0200765 return -EINVAL;
Neels Hofmeyr538d2c52019-01-28 03:51:35 +0100766 }
767 osmo_fsm_inst_update_id(ci->mgcp_client_fi, ci->label);
768 break;
769
770 case MGCP_VERB_MDCX:
771 OSMO_ASSERT(ci->mgcp_client_fi);
772 LOG_CI_VERB(ci, LOGL_DEBUG, "Sending\n");
773 rc = mgcp_conn_modify(ci->mgcp_client_fi, CI_EV_SUCCESS(ci), &ci->verb_info);
774 ci->sent = true;
775 if (rc) {
776 LOG_CI_VERB(ci, LOGL_ERROR, "Cannot send (rc=%d %s)\n", rc, strerror(-rc));
777 on_failure(ci);
Neels Hofmeyrc5479fe2019-04-05 01:36:06 +0200778 return -EINVAL;
Neels Hofmeyr538d2c52019-01-28 03:51:35 +0100779 }
780 break;
781
782 case MGCP_VERB_DLCX:
783 LOG_CI(ci, LOGL_DEBUG, "Sending MGCP: %s %s\n",
784 osmo_mgcp_verb_name(ci->verb), ci->mgcp_ci_str);
785 /* The way this is designed, we actually need to forget all about the ci right away. */
786 mgcp_conn_delete(ci->mgcp_client_fi);
Neels Hofmeyr055ded72019-10-29 17:46:30 +0100787 notify = ci->notify;
Neels Hofmeyr538d2c52019-01-28 03:51:35 +0100788 *ci = (struct osmo_mgcpc_ep_ci){
789 .ep = ep,
790 };
Neels Hofmeyr055ded72019-10-29 17:46:30 +0100791 /* When dispatching an event for this CI, the user may decide to trigger the next request for this conn
792 * right away. So we must be ready with a cleared *ci. */
793 if (notify.fi)
794 osmo_fsm_inst_dispatch(notify.fi, notify.success, notify.data);
Neels Hofmeyr538d2c52019-01-28 03:51:35 +0100795 break;
796
797 default:
798 OSMO_ASSERT(false);
799 }
800
801 return 1;
802}
803
804/*! DLCX all connections, terminate the endpoint FSM and free. */
805void osmo_mgcpc_ep_clear(struct osmo_mgcpc_ep *ep)
806{
807 if (!ep)
808 return;
Neels Hofmeyrf2bf8dc2019-10-29 17:39:56 +0100809 osmo_mgcpc_ep_cancel_notify(ep, NULL);
Neels Hofmeyr538d2c52019-01-28 03:51:35 +0100810 osmo_fsm_inst_term(ep->fi, OSMO_FSM_TERM_REGULAR, 0);
811}
812
813static void osmo_mgcpc_ep_count(struct osmo_mgcpc_ep *ep, int *occupied, int *pending_not_sent,
814 int *waiting_for_response)
815{
816 int i;
817
818 if (occupied)
819 *occupied = 0;
820
821 if (pending_not_sent)
822 *pending_not_sent = 0;
823
824 if (waiting_for_response)
825 *waiting_for_response = 0;
826
827 for (i = 0; i < ARRAY_SIZE(ep->ci); i++) {
828 struct osmo_mgcpc_ep_ci *ci = &ep->ci[i];
829 if (ci->occupied) {
830 if (occupied)
831 (*occupied)++;
832 } else
833 continue;
834
835 if (ci->pending)
836 LOG_CI_VERB(ci, LOGL_DEBUG, "%s\n",
837 ci->sent ? "waiting for response" : "waiting to be sent");
838 else
839 LOG_CI_VERB(ci, LOGL_DEBUG, "done (%s)\n", mgcp_conn_peer_name(osmo_mgcpc_ep_ci_get_rtp_info(ci)));
840
841 if (ci->pending && ci->sent)
842 if (waiting_for_response)
843 (*waiting_for_response)++;
844 if (ci->pending && !ci->sent)
845 if (pending_not_sent)
846 (*pending_not_sent)++;
847 }
848}
849
850static bool osmo_mgcpc_ep_fsm_check_state_chg_after_response(struct osmo_fsm_inst *fi)
851{
852 int waiting_for_response;
853 int occupied;
854 struct osmo_mgcpc_ep *ep = osmo_mgcpc_ep_fi_mgwep(fi);
855
856 osmo_mgcpc_ep_count(ep, &occupied, NULL, &waiting_for_response);
857 LOG_MGCPC_EP(ep, LOGL_DEBUG, "CI in use: %d, waiting for response: %d\n", occupied, waiting_for_response);
858
859 if (!occupied) {
860 /* All CI have been released. The endpoint no longer exists. Notify the parent FSM, by
861 * terminating. */
862 osmo_fsm_inst_term(fi, OSMO_FSM_TERM_REGULAR, 0);
863 return false;
864 }
865
866 if (!waiting_for_response) {
867 if (fi->state != OSMO_MGCPC_EP_ST_IN_USE)
868 osmo_mgcpc_ep_fsm_state_chg(OSMO_MGCPC_EP_ST_IN_USE);
869 }
870
871 return true;
872}
873
874static void osmo_mgcpc_ep_fsm_wait_mgw_response_onenter(struct osmo_fsm_inst *fi, uint32_t prev_state)
875{
Neels Hofmeyrc5479fe2019-04-05 01:36:06 +0200876 static int re_enter = 0;
877 int rc;
Neels Hofmeyr538d2c52019-01-28 03:51:35 +0100878 int count = 0;
879 int i;
880 struct osmo_mgcpc_ep *ep = osmo_mgcpc_ep_fi_mgwep(fi);
881
Neels Hofmeyrc5479fe2019-04-05 01:36:06 +0200882 re_enter++;
883 OSMO_ASSERT(re_enter < 10);
884
885 /* The first CRCX gives us the endpoint name in the CRCX response. So we must wait for the first CRCX endpoint
886 * response to come in before sending any other MGCP requests -- otherwise we might end up creating new
887 * endpoints instead of acting on the same. This FSM always sends out N requests and waits for all of them to
888 * complete before sending out new requests. Hence we're safe when the very first time at most one request is
889 * sent (which needs to be a CRCX). */
890
Neels Hofmeyr538d2c52019-01-28 03:51:35 +0100891 for (i = 0; i < ARRAY_SIZE(ep->ci); i++) {
Neels Hofmeyrc5479fe2019-04-05 01:36:06 +0200892 struct osmo_mgcpc_ep_ci *ci = &ep->ci[i];
893
894 /* Make sure that only CRCX get dispatched if no CRCX were sent yet. */
895 if (!ep->first_crcx_complete) {
896 if (ci->occupied && ci->verb != MGCP_VERB_CRCX)
897 continue;
898 }
899
900 rc = send_verb(&ep->ci[i]);
901 /* Need to be careful not to access the instance after failure. Event chains may already have
902 * deallocated this memory. */
903 if (rc < 0)
904 return;
905 if (!rc)
906 continue;
907 count++;
908 /* Make sure that we wait for the first CRCX response before dispatching more requests. */
909 if (!ep->first_crcx_complete)
910 break;
Neels Hofmeyr538d2c52019-01-28 03:51:35 +0100911 }
912
913 LOG_MGCPC_EP(ep, LOGL_DEBUG, "Sent messages: %d\n", count);
Neels Hofmeyrc5479fe2019-04-05 01:36:06 +0200914 if (ep->first_crcx_complete)
915 osmo_mgcpc_ep_fsm_check_state_chg_after_response(fi);
916 re_enter--;
Neels Hofmeyr538d2c52019-01-28 03:51:35 +0100917}
918
919static void osmo_mgcpc_ep_fsm_handle_ci_events(struct osmo_fsm_inst *fi, uint32_t event, void *data)
920{
921 struct osmo_mgcpc_ep_ci *ci;
922 struct osmo_mgcpc_ep *ep = osmo_mgcpc_ep_fi_mgwep(fi);
923 ci = osmo_mgcpc_ep_ci_for_event(ep, event);
924 if (ci) {
925 if (event == CI_EV_SUCCESS(ci))
926 on_success(ci, data);
927 else
928 on_failure(ci);
929 }
930}
931
932static void osmo_mgcpc_ep_fsm_in_use_onenter(struct osmo_fsm_inst *fi, uint32_t prev_state)
933{
934 int pending_not_sent;
935 struct osmo_mgcpc_ep *ep = osmo_mgcpc_ep_fi_mgwep(fi);
936
937 osmo_mgcpc_ep_count(ep, NULL, &pending_not_sent, NULL);
938 if (pending_not_sent)
939 osmo_mgcpc_ep_fsm_state_chg(OSMO_MGCPC_EP_ST_WAIT_MGW_RESPONSE);
940}
941
942#define S(x) (1 << (x))
943
944static const struct osmo_fsm_state osmo_mgcpc_ep_fsm_states[] = {
945 [OSMO_MGCPC_EP_ST_UNUSED] = {
946 .name = "UNUSED",
947 .in_event_mask = 0,
948 .out_state_mask = 0
949 | S(OSMO_MGCPC_EP_ST_WAIT_MGW_RESPONSE)
950 ,
951 },
952 [OSMO_MGCPC_EP_ST_WAIT_MGW_RESPONSE] = {
953 .name = "WAIT_MGW_RESPONSE",
954 .onenter = osmo_mgcpc_ep_fsm_wait_mgw_response_onenter,
955 .action = osmo_mgcpc_ep_fsm_handle_ci_events,
956 .in_event_mask = 0xffffffff,
957 .out_state_mask = 0
958 | S(OSMO_MGCPC_EP_ST_IN_USE)
959 ,
960 },
961 [OSMO_MGCPC_EP_ST_IN_USE] = {
962 .name = "IN_USE",
963 .onenter = osmo_mgcpc_ep_fsm_in_use_onenter,
964 .action = osmo_mgcpc_ep_fsm_handle_ci_events,
965 .in_event_mask = 0xffffffff, /* mgcp_client_fsm may send parent term anytime */
966 .out_state_mask = 0
967 | S(OSMO_MGCPC_EP_ST_WAIT_MGW_RESPONSE)
968 ,
969 },
970};
971
972static int osmo_mgcpc_ep_fsm_timer_cb(struct osmo_fsm_inst *fi)
973{
974 int i;
975 struct osmo_mgcpc_ep *ep = osmo_mgcpc_ep_fi_mgwep(fi);
976
977 switch (fi->T) {
978 default:
979 for (i = 0; i < ARRAY_SIZE(ep->ci); i++) {
980 struct osmo_mgcpc_ep_ci *ci = &ep->ci[i];
981 if (!ci->occupied)
982 continue;
983 if (!(ci->pending && ci->sent))
984 continue;
985 on_failure(ci);
986 }
987 return 0;
988 }
989
990 return 0;
991}
992
993static struct osmo_fsm osmo_mgcpc_ep_fsm = {
Pau Espin Pedrol182ca3b2019-05-08 14:01:20 +0200994 .name = "mgw-endp",
Neels Hofmeyr538d2c52019-01-28 03:51:35 +0100995 .states = osmo_mgcpc_ep_fsm_states,
996 .num_states = ARRAY_SIZE(osmo_mgcpc_ep_fsm_states),
997 .log_subsys = DLMGCP,
998 .event_names = osmo_mgcpc_ep_fsm_event_names,
999 .timer_cb = osmo_mgcpc_ep_fsm_timer_cb,
1000 /* The FSM termination will automatically trigger any mgcp_client_fsm instances to DLCX. */
1001};