blob: f687bae769b164946713c4e43ee5aab1c710e512 [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 Hofmeyr51b42ff2020-06-19 01:34:42 +020026#include <osmocom/core/msgb.h>
Philipp Maier889fe7f2020-07-06 17:44:12 +020027#include <osmocom/gsm/i460_mux.h>
Eric1e8d5fa2021-08-24 01:36:49 +020028#include <osmocom/mgcp/mgcp_protocol.h>
Neels Hofmeyr51b42ff2020-06-19 01:34:42 +020029
Pau Espin Pedrola790f0c2020-08-31 13:29:11 +020030struct sockaddr;
Philipp Maier87bd9be2017-08-22 16:35:41 +020031struct mgcp_conn;
Neels Hofmeyr51b42ff2020-06-19 01:34:42 +020032struct mgcp_conn_rtp;
Philipp Maieredc00f42018-01-24 11:58:56 +010033struct mgcp_endpoint;
Philipp Maier87bd9be2017-08-22 16:35:41 +020034
Philipp Maierfbcf3992020-07-02 23:08:37 +020035/* Number of E1 subslots (different variants, not all useable at the same time) */
36#define MGCP_ENDP_E1_SUBSLOTS 15
37
Philipp Maier62612e82020-05-27 16:29:22 +020038#define LOGPENDP(endp, cat, level, fmt, args...) \
Philipp Maierc66ab2c2020-06-02 20:55:34 +020039LOGP(cat, level, "endpoint:%s " fmt, \
40 endp ? endp->name : "none", \
Philipp Maier62612e82020-05-27 16:29:22 +020041 ## args)
42
Neels Hofmeyr51b42ff2020-06-19 01:34:42 +020043struct osmo_rtp_msg_ctx {
44 int proto;
45 struct mgcp_conn_rtp *conn_src;
Pau Espin Pedrola790f0c2020-08-31 13:29:11 +020046 struct osmo_sockaddr *from_addr;
Neels Hofmeyr51b42ff2020-06-19 01:34:42 +020047};
48
49#define OSMO_RTP_MSG_CTX(MSGB) ((struct osmo_rtp_msg_ctx*)(MSGB)->cb)
50
51osmo_static_assert(sizeof(((struct msgb*)0)->cb) >= sizeof(struct osmo_rtp_msg_ctx), osmo_rtp_msg_ctx_fits_in_msgb_cb);
52
53/* Callback type for RTP dispatcher functions (e.g mgcp_dispatch_rtp_bridge_cb, see below).
54 * The OSMO_RTP_MSG_CTX() should be set appropriately on the msg. */
55typedef int (*mgcp_dispatch_rtp_cb) (struct msgb *msg);
Philipp Maier87bd9be2017-08-22 16:35:41 +020056
Philipp Maierdf5d2192018-01-24 11:39:32 +010057/* Callback type for endpoint specific cleanup actions. This function
58 * is automatically executed when a connection is freed (see mgcp_conn_free()
59 * in mgcp_conn.c). Depending on the type of the endpoint there may be endpoint
60 * specific things to take care of once a connection has been removed. */
61typedef void (*mgcp_cleanup_cp) (struct mgcp_endpoint *endp,
62 struct mgcp_conn *conn);
63
Philipp Maier87bd9be2017-08-22 16:35:41 +020064/*! MGCP endpoint properties */
65struct mgcp_endpoint_type {
Neels Hofmeyr8838c622018-06-26 00:05:53 +020066 /*! maximum number of connections */
Philipp Maier87bd9be2017-08-22 16:35:41 +020067 int max_conns;
68
Neels Hofmeyr8838c622018-06-26 00:05:53 +020069 /*! callback that defines how to dispatch incoming RTP data */
Philipp Maier87bd9be2017-08-22 16:35:41 +020070 mgcp_dispatch_rtp_cb dispatch_rtp_cb;
Philipp Maierdf5d2192018-01-24 11:39:32 +010071
Neels Hofmeyr8838c622018-06-26 00:05:53 +020072 /*! callback that implements endpoint specific cleanup actions */
Philipp Maierdf5d2192018-01-24 11:39:32 +010073 mgcp_cleanup_cp cleanup_cb;
Philipp Maier87bd9be2017-08-22 16:35:41 +020074};
75
76/*! MGCP endpoint typeset */
77struct mgcp_endpoint_typeset {
78 struct mgcp_endpoint_type rtp;
Philipp Maier0996a1e2020-06-10 15:27:14 +020079 struct mgcp_endpoint_type e1;
Philipp Maier87bd9be2017-08-22 16:35:41 +020080};
81
82/*! static MGCP endpoint typeset (pre-initalized, read-only) */
83extern const struct mgcp_endpoint_typeset ep_typeset;
Philipp Maieredc00f42018-01-24 11:58:56 +010084
Philipp Maierfdd603c2018-02-01 13:31:15 +010085/*! MGCP endpoint model */
86struct mgcp_endpoint {
87
Philipp Maierc66ab2c2020-06-02 20:55:34 +020088 /*! Unique endpoint name, used for addressing via MGCP */
89 char *name;
90
Neels Hofmeyr8838c622018-06-26 00:05:53 +020091 /*! Call identifier string (as supplied by the call agant) */
Philipp Maierfdd603c2018-02-01 13:31:15 +010092 char *callid;
93
Neels Hofmeyr8838c622018-06-26 00:05:53 +020094 /*! Local connection options (see mgcp_internal.h) */
Philipp Maierfdd603c2018-02-01 13:31:15 +010095 struct mgcp_lco local_options;
96
Neels Hofmeyrf0504e82018-08-28 21:12:59 +020097 /*! List of struct mgcp_conn, of the connections active on this endpoint */
Philipp Maierfdd603c2018-02-01 13:31:15 +010098 struct llist_head conns;
99
Neels Hofmeyr8838c622018-06-26 00:05:53 +0200100 /*! Backpointer to the MGW configuration */
Philipp Maierfdd603c2018-02-01 13:31:15 +0100101 struct mgcp_config *cfg;
102
Philipp Maierc66ab2c2020-06-02 20:55:34 +0200103 /*! Backpointer to the trunk this endpoint belongs to */
Philipp Maier14b27a82020-06-02 20:15:30 +0200104 struct mgcp_trunk *trunk;
Philipp Maierfdd603c2018-02-01 13:31:15 +0100105
Neels Hofmeyr8838c622018-06-26 00:05:53 +0200106 /*! Endpoint properties (see above) */
Philipp Maierfdd603c2018-02-01 13:31:15 +0100107 const struct mgcp_endpoint_type *type;
108
Neels Hofmeyr8838c622018-06-26 00:05:53 +0200109 /*! Last MGCP transmission (in case re-transmission is required) */
Philipp Maierfdd603c2018-02-01 13:31:15 +0100110 char *last_trans;
111
Neels Hofmeyr8838c622018-06-26 00:05:53 +0200112 /*! Last MGCP response (in case re-transmission is required) */
Philipp Maierfdd603c2018-02-01 13:31:15 +0100113 char *last_response;
114
Neels Hofmeyre6d8e912018-08-23 16:36:48 +0200115 /*! MGCP_X_OSMO_IGN_* flags from 'X-Osmo-IGN:' header */
116 uint32_t x_osmo_ign;
Philipp Maier889fe7f2020-07-06 17:44:12 +0200117
118 /* E1 specific */
119 struct {
120 struct osmo_i460_schan_desc scd;
121 struct osmo_i460_subchan *schan;
122 struct osmo_fsm_inst *trau_sync_fi;
123 struct osmo_trau2rtp_state *trau_rtp_st;
124 uint8_t last_amr_ft;
125 struct mgcp_rtp_codec *last_codec;
126 } e1;
127
Philipp Maierfdd603c2018-02-01 13:31:15 +0100128};
129
Philipp Maier7462b952020-06-10 14:50:34 +0200130struct mgcp_endpoint *mgcp_endp_alloc(struct mgcp_trunk *trunk, unsigned int index);
Philipp Maier1355d7e2018-02-01 14:30:06 +0100131void mgcp_endp_release(struct mgcp_endpoint *endp);
Philipp Maier889fe7f2020-07-06 17:44:12 +0200132int mgcp_endp_claim(struct mgcp_endpoint *endp, const char *callid);
133void mgcp_endp_update(struct mgcp_endpoint *endp);
Philipp Maierd64c0412021-07-14 11:53:49 +0200134bool mgcp_endp_is_wildcarded(const char *epname);
Philipp Maierc66ab2c2020-06-02 20:55:34 +0200135struct mgcp_endpoint *mgcp_endp_by_name_trunk(int *cause, const char *epname,
136 const struct mgcp_trunk *trunk);
137struct mgcp_endpoint *mgcp_endp_by_name(int *cause, const char *epname,
138 struct mgcp_config *cfg);
Philipp Maier8d6a1932020-06-18 12:19:31 +0200139bool mgcp_endp_avail(struct mgcp_endpoint *endp);
Pau Espin Pedrol6d0a59a2020-09-08 16:50:22 +0200140void mgcp_endp_add_conn(struct mgcp_endpoint *endp, struct mgcp_conn *conn);
141void mgcp_endp_remove_conn(struct mgcp_endpoint *endp, struct mgcp_conn *conn);