blob: 5737cd2474878b1424a68c9d7dc99bc32386e7dd [file] [log] [blame]
Philipp Maier87bd9be2017-08-22 16:35:41 +02001/* Endpoint types */
2
3/*
4 * (C) 2017 by sysmocom s.f.m.c. GmbH <info@sysmocom.de>
5 * All Rights Reserved
6 *
7 * Author: Philipp Maier
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU Affero General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Affero General Public License for more details.
18 *
19 * You should have received a copy of the GNU Affero General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 *
22 */
23
24#pragma once
25
26struct sockaddr_in;
27struct mgcp_conn;
Philipp Maieredc00f42018-01-24 11:58:56 +010028struct mgcp_endpoint;
Philipp Maier87bd9be2017-08-22 16:35:41 +020029
Philipp Maier62612e82020-05-27 16:29:22 +020030#define LOGPENDP(endp, cat, level, fmt, args...) \
Philipp Maierc66ab2c2020-06-02 20:55:34 +020031LOGP(cat, level, "endpoint:%s " fmt, \
32 endp ? endp->name : "none", \
Philipp Maier62612e82020-05-27 16:29:22 +020033 ## args)
34
Philipp Maier87bd9be2017-08-22 16:35:41 +020035/* Callback type for RTP dispatcher functions
36 (e.g mgcp_dispatch_rtp_bridge_cb, see below) */
Philipp Maier36a81122018-01-24 11:52:34 +010037typedef int (*mgcp_dispatch_rtp_cb) (int proto, struct sockaddr_in *addr,
Philipp Maier87bd9be2017-08-22 16:35:41 +020038 char *buf, unsigned int buf_size,
Philipp Maier36a81122018-01-24 11:52:34 +010039 struct mgcp_conn *conn);
Philipp Maier87bd9be2017-08-22 16:35:41 +020040
Philipp Maierdf5d2192018-01-24 11:39:32 +010041/* Callback type for endpoint specific cleanup actions. This function
42 * is automatically executed when a connection is freed (see mgcp_conn_free()
43 * in mgcp_conn.c). Depending on the type of the endpoint there may be endpoint
44 * specific things to take care of once a connection has been removed. */
45typedef void (*mgcp_cleanup_cp) (struct mgcp_endpoint *endp,
46 struct mgcp_conn *conn);
47
Philipp Maier87bd9be2017-08-22 16:35:41 +020048/*! MGCP endpoint properties */
49struct mgcp_endpoint_type {
Neels Hofmeyr8838c622018-06-26 00:05:53 +020050 /*! maximum number of connections */
Philipp Maier87bd9be2017-08-22 16:35:41 +020051 int max_conns;
52
Neels Hofmeyr8838c622018-06-26 00:05:53 +020053 /*! callback that defines how to dispatch incoming RTP data */
Philipp Maier87bd9be2017-08-22 16:35:41 +020054 mgcp_dispatch_rtp_cb dispatch_rtp_cb;
Philipp Maierdf5d2192018-01-24 11:39:32 +010055
Neels Hofmeyr8838c622018-06-26 00:05:53 +020056 /*! callback that implements endpoint specific cleanup actions */
Philipp Maierdf5d2192018-01-24 11:39:32 +010057 mgcp_cleanup_cp cleanup_cb;
Philipp Maier87bd9be2017-08-22 16:35:41 +020058};
59
60/*! MGCP endpoint typeset */
61struct mgcp_endpoint_typeset {
62 struct mgcp_endpoint_type rtp;
63};
64
65/*! static MGCP endpoint typeset (pre-initalized, read-only) */
66extern const struct mgcp_endpoint_typeset ep_typeset;
Philipp Maieredc00f42018-01-24 11:58:56 +010067
Philipp Maierfdd603c2018-02-01 13:31:15 +010068/*! MGCP endpoint model */
69struct mgcp_endpoint {
70
Philipp Maierc66ab2c2020-06-02 20:55:34 +020071 /*! Unique endpoint name, used for addressing via MGCP */
72 char *name;
73
Neels Hofmeyr8838c622018-06-26 00:05:53 +020074 /*! Call identifier string (as supplied by the call agant) */
Philipp Maierfdd603c2018-02-01 13:31:15 +010075 char *callid;
76
Neels Hofmeyr8838c622018-06-26 00:05:53 +020077 /*! Local connection options (see mgcp_internal.h) */
Philipp Maierfdd603c2018-02-01 13:31:15 +010078 struct mgcp_lco local_options;
79
Neels Hofmeyrf0504e82018-08-28 21:12:59 +020080 /*! List of struct mgcp_conn, of the connections active on this endpoint */
Philipp Maierfdd603c2018-02-01 13:31:15 +010081 struct llist_head conns;
82
Neels Hofmeyr8838c622018-06-26 00:05:53 +020083 /*! Backpointer to the MGW configuration */
Philipp Maierfdd603c2018-02-01 13:31:15 +010084 struct mgcp_config *cfg;
85
Philipp Maierc66ab2c2020-06-02 20:55:34 +020086 /*! Backpointer to the trunk this endpoint belongs to */
Philipp Maier14b27a82020-06-02 20:15:30 +020087 struct mgcp_trunk *trunk;
Philipp Maierfdd603c2018-02-01 13:31:15 +010088
Neels Hofmeyr8838c622018-06-26 00:05:53 +020089 /*! Endpoint properties (see above) */
Philipp Maierfdd603c2018-02-01 13:31:15 +010090 const struct mgcp_endpoint_type *type;
91
Neels Hofmeyr8838c622018-06-26 00:05:53 +020092 /*! Last MGCP transmission (in case re-transmission is required) */
Philipp Maierfdd603c2018-02-01 13:31:15 +010093 char *last_trans;
94
Neels Hofmeyr8838c622018-06-26 00:05:53 +020095 /*! Last MGCP response (in case re-transmission is required) */
Philipp Maierfdd603c2018-02-01 13:31:15 +010096 char *last_response;
97
Neels Hofmeyr8838c622018-06-26 00:05:53 +020098 /*! Memorize if this endpoint was choosen by the MGW (wildcarded, true)
Philipp Maierfdd603c2018-02-01 13:31:15 +010099 * or if the user has choosen the particular endpoint explicitly. */
Philipp Maier207ab512018-02-02 14:19:26 +0100100 bool wildcarded_req;
Neels Hofmeyre6d8e912018-08-23 16:36:48 +0200101
102 /*! MGCP_X_OSMO_IGN_* flags from 'X-Osmo-IGN:' header */
103 uint32_t x_osmo_ign;
Philipp Maierfdd603c2018-02-01 13:31:15 +0100104};
105
Philipp Maierc66ab2c2020-06-02 20:55:34 +0200106struct mgcp_endpoint *mgcp_endp_alloc(struct mgcp_trunk *trunk, char *name);
Philipp Maier1355d7e2018-02-01 14:30:06 +0100107void mgcp_endp_release(struct mgcp_endpoint *endp);
Philipp Maierc66ab2c2020-06-02 20:55:34 +0200108struct mgcp_endpoint *mgcp_endp_by_name_trunk(int *cause, const char *epname,
109 const struct mgcp_trunk *trunk);
110struct mgcp_endpoint *mgcp_endp_by_name(int *cause, const char *epname,
111 struct mgcp_config *cfg);