blob: 04c3d18298c053cd64af0a88ae7d46b2f26dca83 [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
Neels Hofmeyrf2a65b82018-09-30 05:01:20 +020026#include <osmocom/core/msgb.h>
27
Philipp Maier87bd9be2017-08-22 16:35:41 +020028struct sockaddr_in;
29struct mgcp_conn;
Neels Hofmeyrf2a65b82018-09-30 05:01:20 +020030struct mgcp_conn_rtp;
Philipp Maieredc00f42018-01-24 11:58:56 +010031struct mgcp_endpoint;
Philipp Maier87bd9be2017-08-22 16:35:41 +020032
Neels Hofmeyrf2a65b82018-09-30 05:01:20 +020033struct osmo_rtp_msg_ctx {
34 int proto;
35 struct mgcp_conn_rtp *conn_src;
36 struct sockaddr_in *from_addr;
37};
38
39#define OSMO_RTP_MSG_CTX(MSGB) (*(struct osmo_rtp_msg_ctx**)&((MSGB)->dst))
40
41#define LOG_ENDP(endp, level, fmt, args...) \
42 LOGP(DRTP, level, "%x@ " fmt, ENDPOINT_NUMBER(endp), ## args)
43
44/* Callback type for RTP dispatcher functions (e.g mgcp_dispatch_rtp_bridge_cb, see below).
45 * The fields OSMO_RTP_MSG_PROTO, OSMO_RTP_MSG_CONN_SRC, OSMO_RTP_MSG_FROM_ADDR should be set
46 * appropriately on the msg. */
47typedef int (*mgcp_dispatch_rtp_cb) (struct msgb *msg);
Philipp Maier87bd9be2017-08-22 16:35:41 +020048
Philipp Maierdf5d2192018-01-24 11:39:32 +010049/* Callback type for endpoint specific cleanup actions. This function
50 * is automatically executed when a connection is freed (see mgcp_conn_free()
51 * in mgcp_conn.c). Depending on the type of the endpoint there may be endpoint
52 * specific things to take care of once a connection has been removed. */
53typedef void (*mgcp_cleanup_cp) (struct mgcp_endpoint *endp,
54 struct mgcp_conn *conn);
55
Philipp Maier87bd9be2017-08-22 16:35:41 +020056/*! MGCP endpoint properties */
57struct mgcp_endpoint_type {
Neels Hofmeyr8838c622018-06-26 00:05:53 +020058 /*! maximum number of connections */
Philipp Maier87bd9be2017-08-22 16:35:41 +020059 int max_conns;
60
Neels Hofmeyr8838c622018-06-26 00:05:53 +020061 /*! callback that defines how to dispatch incoming RTP data */
Philipp Maier87bd9be2017-08-22 16:35:41 +020062 mgcp_dispatch_rtp_cb dispatch_rtp_cb;
Philipp Maierdf5d2192018-01-24 11:39:32 +010063
Neels Hofmeyr8838c622018-06-26 00:05:53 +020064 /*! callback that implements endpoint specific cleanup actions */
Philipp Maierdf5d2192018-01-24 11:39:32 +010065 mgcp_cleanup_cp cleanup_cb;
Philipp Maier87bd9be2017-08-22 16:35:41 +020066};
67
68/*! MGCP endpoint typeset */
69struct mgcp_endpoint_typeset {
70 struct mgcp_endpoint_type rtp;
71};
72
73/*! static MGCP endpoint typeset (pre-initalized, read-only) */
74extern const struct mgcp_endpoint_typeset ep_typeset;
Philipp Maieredc00f42018-01-24 11:58:56 +010075
Philipp Maierfdd603c2018-02-01 13:31:15 +010076/*! MGCP endpoint model */
77struct mgcp_endpoint {
78
Neels Hofmeyr8838c622018-06-26 00:05:53 +020079 /*! Call identifier string (as supplied by the call agant) */
Philipp Maierfdd603c2018-02-01 13:31:15 +010080 char *callid;
81
Neels Hofmeyr8838c622018-06-26 00:05:53 +020082 /*! Local connection options (see mgcp_internal.h) */
Philipp Maierfdd603c2018-02-01 13:31:15 +010083 struct mgcp_lco local_options;
84
Neels Hofmeyrf0504e82018-08-28 21:12:59 +020085 /*! List of struct mgcp_conn, of the connections active on this endpoint */
Philipp Maierfdd603c2018-02-01 13:31:15 +010086 struct llist_head conns;
87
Neels Hofmeyr8838c622018-06-26 00:05:53 +020088 /*! Backpointer to the MGW configuration */
Philipp Maierfdd603c2018-02-01 13:31:15 +010089 struct mgcp_config *cfg;
90
Neels Hofmeyr8838c622018-06-26 00:05:53 +020091 /*! Backpointer to the Trunk specific configuration */
Philipp Maierfdd603c2018-02-01 13:31:15 +010092 struct mgcp_trunk_config *tcfg;
93
Neels Hofmeyr8838c622018-06-26 00:05:53 +020094 /*! Endpoint properties (see above) */
Philipp Maierfdd603c2018-02-01 13:31:15 +010095 const struct mgcp_endpoint_type *type;
96
Neels Hofmeyr8838c622018-06-26 00:05:53 +020097 /*! Last MGCP transmission (in case re-transmission is required) */
Philipp Maierfdd603c2018-02-01 13:31:15 +010098 char *last_trans;
99
Neels Hofmeyr8838c622018-06-26 00:05:53 +0200100 /*! Last MGCP response (in case re-transmission is required) */
Philipp Maierfdd603c2018-02-01 13:31:15 +0100101 char *last_response;
102
Neels Hofmeyr8838c622018-06-26 00:05:53 +0200103 /*! Memorize if this endpoint was choosen by the MGW (wildcarded, true)
Philipp Maierfdd603c2018-02-01 13:31:15 +0100104 * or if the user has choosen the particular endpoint explicitly. */
Philipp Maier207ab512018-02-02 14:19:26 +0100105 bool wildcarded_req;
Neels Hofmeyre6d8e912018-08-23 16:36:48 +0200106
107 /*! MGCP_X_OSMO_IGN_* flags from 'X-Osmo-IGN:' header */
108 uint32_t x_osmo_ign;
Philipp Maierfdd603c2018-02-01 13:31:15 +0100109};
110
111/*! Extract endpoint number for a given endpoint */
112#define ENDPOINT_NUMBER(endp) abs((int)(endp - endp->tcfg->endpoints))
113
Philipp Maier1355d7e2018-02-01 14:30:06 +0100114void mgcp_endp_release(struct mgcp_endpoint *endp);
115