blob: b130050419866952146df70b37a486c2c00c016a [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
Pau Espin Pedrolde805b62022-10-03 16:08:58 +020043enum rtp_proto {
44 MGCP_PROTO_RTP,
45 MGCP_PROTO_RTCP,
46};
47
Neels Hofmeyr51b42ff2020-06-19 01:34:42 +020048struct osmo_rtp_msg_ctx {
Pau Espin Pedrolde805b62022-10-03 16:08:58 +020049 enum rtp_proto proto;
Neels Hofmeyr51b42ff2020-06-19 01:34:42 +020050 struct mgcp_conn_rtp *conn_src;
Pau Espin Pedrola790f0c2020-08-31 13:29:11 +020051 struct osmo_sockaddr *from_addr;
Neels Hofmeyr51b42ff2020-06-19 01:34:42 +020052};
53
54#define OSMO_RTP_MSG_CTX(MSGB) ((struct osmo_rtp_msg_ctx*)(MSGB)->cb)
55
56osmo_static_assert(sizeof(((struct msgb*)0)->cb) >= sizeof(struct osmo_rtp_msg_ctx), osmo_rtp_msg_ctx_fits_in_msgb_cb);
57
58/* Callback type for RTP dispatcher functions (e.g mgcp_dispatch_rtp_bridge_cb, see below).
59 * The OSMO_RTP_MSG_CTX() should be set appropriately on the msg. */
60typedef int (*mgcp_dispatch_rtp_cb) (struct msgb *msg);
Philipp Maier87bd9be2017-08-22 16:35:41 +020061
Philipp Maierdf5d2192018-01-24 11:39:32 +010062/* Callback type for endpoint specific cleanup actions. This function
63 * is automatically executed when a connection is freed (see mgcp_conn_free()
64 * in mgcp_conn.c). Depending on the type of the endpoint there may be endpoint
65 * specific things to take care of once a connection has been removed. */
66typedef void (*mgcp_cleanup_cp) (struct mgcp_endpoint *endp,
67 struct mgcp_conn *conn);
68
Philipp Maier87bd9be2017-08-22 16:35:41 +020069/*! MGCP endpoint properties */
70struct mgcp_endpoint_type {
Neels Hofmeyr8838c622018-06-26 00:05:53 +020071 /*! maximum number of connections */
Philipp Maier87bd9be2017-08-22 16:35:41 +020072 int max_conns;
73
Neels Hofmeyr8838c622018-06-26 00:05:53 +020074 /*! callback that defines how to dispatch incoming RTP data */
Philipp Maier87bd9be2017-08-22 16:35:41 +020075 mgcp_dispatch_rtp_cb dispatch_rtp_cb;
Philipp Maierdf5d2192018-01-24 11:39:32 +010076
Neels Hofmeyr8838c622018-06-26 00:05:53 +020077 /*! callback that implements endpoint specific cleanup actions */
Philipp Maierdf5d2192018-01-24 11:39:32 +010078 mgcp_cleanup_cp cleanup_cb;
Philipp Maier87bd9be2017-08-22 16:35:41 +020079};
80
81/*! MGCP endpoint typeset */
82struct mgcp_endpoint_typeset {
83 struct mgcp_endpoint_type rtp;
Philipp Maier0996a1e2020-06-10 15:27:14 +020084 struct mgcp_endpoint_type e1;
Philipp Maier87bd9be2017-08-22 16:35:41 +020085};
86
87/*! static MGCP endpoint typeset (pre-initalized, read-only) */
88extern const struct mgcp_endpoint_typeset ep_typeset;
Philipp Maieredc00f42018-01-24 11:58:56 +010089
Philipp Maierfdd603c2018-02-01 13:31:15 +010090/*! MGCP endpoint model */
91struct mgcp_endpoint {
92
Philipp Maierc66ab2c2020-06-02 20:55:34 +020093 /*! Unique endpoint name, used for addressing via MGCP */
94 char *name;
95
Neels Hofmeyr8838c622018-06-26 00:05:53 +020096 /*! Call identifier string (as supplied by the call agant) */
Philipp Maierfdd603c2018-02-01 13:31:15 +010097 char *callid;
98
Neels Hofmeyr8838c622018-06-26 00:05:53 +020099 /*! Local connection options (see mgcp_internal.h) */
Philipp Maierfdd603c2018-02-01 13:31:15 +0100100 struct mgcp_lco local_options;
101
Neels Hofmeyrf0504e82018-08-28 21:12:59 +0200102 /*! List of struct mgcp_conn, of the connections active on this endpoint */
Philipp Maierfdd603c2018-02-01 13:31:15 +0100103 struct llist_head conns;
104
Philipp Maierc66ab2c2020-06-02 20:55:34 +0200105 /*! Backpointer to the trunk this endpoint belongs to */
Philipp Maier14b27a82020-06-02 20:15:30 +0200106 struct mgcp_trunk *trunk;
Philipp Maierfdd603c2018-02-01 13:31:15 +0100107
Neels Hofmeyr8838c622018-06-26 00:05:53 +0200108 /*! Endpoint properties (see above) */
Philipp Maierfdd603c2018-02-01 13:31:15 +0100109 const struct mgcp_endpoint_type *type;
110
Neels Hofmeyr8838c622018-06-26 00:05:53 +0200111 /*! Last MGCP transmission (in case re-transmission is required) */
Philipp Maierfdd603c2018-02-01 13:31:15 +0100112 char *last_trans;
113
Neels Hofmeyr8838c622018-06-26 00:05:53 +0200114 /*! Last MGCP response (in case re-transmission is required) */
Philipp Maierfdd603c2018-02-01 13:31:15 +0100115 char *last_response;
116
Neels Hofmeyre6d8e912018-08-23 16:36:48 +0200117 /*! MGCP_X_OSMO_IGN_* flags from 'X-Osmo-IGN:' header */
118 uint32_t x_osmo_ign;
Philipp Maier889fe7f2020-07-06 17:44:12 +0200119
120 /* E1 specific */
121 struct {
122 struct osmo_i460_schan_desc scd;
123 struct osmo_i460_subchan *schan;
124 struct osmo_fsm_inst *trau_sync_fi;
125 struct osmo_trau2rtp_state *trau_rtp_st;
126 uint8_t last_amr_ft;
127 struct mgcp_rtp_codec *last_codec;
128 } e1;
129
Philipp Maierfdd603c2018-02-01 13:31:15 +0100130};
131
Philipp Maier7462b952020-06-10 14:50:34 +0200132struct mgcp_endpoint *mgcp_endp_alloc(struct mgcp_trunk *trunk, unsigned int index);
Philipp Maier1355d7e2018-02-01 14:30:06 +0100133void mgcp_endp_release(struct mgcp_endpoint *endp);
Philipp Maier889fe7f2020-07-06 17:44:12 +0200134int mgcp_endp_claim(struct mgcp_endpoint *endp, const char *callid);
135void mgcp_endp_update(struct mgcp_endpoint *endp);
Philipp Maierd64c0412021-07-14 11:53:49 +0200136bool mgcp_endp_is_wildcarded(const char *epname);
Philipp Maierc66ab2c2020-06-02 20:55:34 +0200137struct mgcp_endpoint *mgcp_endp_by_name_trunk(int *cause, const char *epname,
138 const struct mgcp_trunk *trunk);
139struct mgcp_endpoint *mgcp_endp_by_name(int *cause, const char *epname,
140 struct mgcp_config *cfg);
Philipp Maier8d6a1932020-06-18 12:19:31 +0200141bool mgcp_endp_avail(struct mgcp_endpoint *endp);
Pau Espin Pedrol6d0a59a2020-09-08 16:50:22 +0200142void mgcp_endp_add_conn(struct mgcp_endpoint *endp, struct mgcp_conn *conn);
143void mgcp_endp_remove_conn(struct mgcp_endpoint *endp, struct mgcp_conn *conn);
Eric25ecc912021-09-06 03:43:50 +0200144void mgcp_endp_strip_name(char *epname_stripped, const char *epname,
145 const struct mgcp_trunk *trunk);
146struct mgcp_endpoint *mgcp_endp_find_specific(const char *epname,
147 const struct mgcp_trunk *trunk);