Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1 | /* 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 Hofmeyr | 51b42ff | 2020-06-19 01:34:42 +0200 | [diff] [blame] | 26 | #include <osmocom/core/msgb.h> |
Philipp Maier | 889fe7f | 2020-07-06 17:44:12 +0200 | [diff] [blame] | 27 | #include <osmocom/gsm/i460_mux.h> |
Eric | 1e8d5fa | 2021-08-24 01:36:49 +0200 | [diff] [blame] | 28 | #include <osmocom/mgcp/mgcp_protocol.h> |
Neels Hofmeyr | 51b42ff | 2020-06-19 01:34:42 +0200 | [diff] [blame] | 29 | |
Pau Espin Pedrol | a790f0c | 2020-08-31 13:29:11 +0200 | [diff] [blame] | 30 | struct sockaddr; |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 31 | struct mgcp_conn; |
Neels Hofmeyr | 51b42ff | 2020-06-19 01:34:42 +0200 | [diff] [blame] | 32 | struct mgcp_conn_rtp; |
Philipp Maier | edc00f4 | 2018-01-24 11:58:56 +0100 | [diff] [blame] | 33 | struct mgcp_endpoint; |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 34 | |
Philipp Maier | fbcf399 | 2020-07-02 23:08:37 +0200 | [diff] [blame] | 35 | /* Number of E1 subslots (different variants, not all useable at the same time) */ |
| 36 | #define MGCP_ENDP_E1_SUBSLOTS 15 |
| 37 | |
Philipp Maier | 62612e8 | 2020-05-27 16:29:22 +0200 | [diff] [blame] | 38 | #define LOGPENDP(endp, cat, level, fmt, args...) \ |
Philipp Maier | c66ab2c | 2020-06-02 20:55:34 +0200 | [diff] [blame] | 39 | LOGP(cat, level, "endpoint:%s " fmt, \ |
| 40 | endp ? endp->name : "none", \ |
Philipp Maier | 62612e8 | 2020-05-27 16:29:22 +0200 | [diff] [blame] | 41 | ## args) |
| 42 | |
Neels Hofmeyr | 51b42ff | 2020-06-19 01:34:42 +0200 | [diff] [blame] | 43 | struct osmo_rtp_msg_ctx { |
| 44 | int proto; |
| 45 | struct mgcp_conn_rtp *conn_src; |
Pau Espin Pedrol | a790f0c | 2020-08-31 13:29:11 +0200 | [diff] [blame] | 46 | struct osmo_sockaddr *from_addr; |
Neels Hofmeyr | 51b42ff | 2020-06-19 01:34:42 +0200 | [diff] [blame] | 47 | }; |
| 48 | |
| 49 | #define OSMO_RTP_MSG_CTX(MSGB) ((struct osmo_rtp_msg_ctx*)(MSGB)->cb) |
| 50 | |
| 51 | osmo_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. */ |
| 55 | typedef int (*mgcp_dispatch_rtp_cb) (struct msgb *msg); |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 56 | |
Philipp Maier | df5d219 | 2018-01-24 11:39:32 +0100 | [diff] [blame] | 57 | /* 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. */ |
| 61 | typedef void (*mgcp_cleanup_cp) (struct mgcp_endpoint *endp, |
| 62 | struct mgcp_conn *conn); |
| 63 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 64 | /*! MGCP endpoint properties */ |
| 65 | struct mgcp_endpoint_type { |
Neels Hofmeyr | 8838c62 | 2018-06-26 00:05:53 +0200 | [diff] [blame] | 66 | /*! maximum number of connections */ |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 67 | int max_conns; |
| 68 | |
Neels Hofmeyr | 8838c62 | 2018-06-26 00:05:53 +0200 | [diff] [blame] | 69 | /*! callback that defines how to dispatch incoming RTP data */ |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 70 | mgcp_dispatch_rtp_cb dispatch_rtp_cb; |
Philipp Maier | df5d219 | 2018-01-24 11:39:32 +0100 | [diff] [blame] | 71 | |
Neels Hofmeyr | 8838c62 | 2018-06-26 00:05:53 +0200 | [diff] [blame] | 72 | /*! callback that implements endpoint specific cleanup actions */ |
Philipp Maier | df5d219 | 2018-01-24 11:39:32 +0100 | [diff] [blame] | 73 | mgcp_cleanup_cp cleanup_cb; |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 74 | }; |
| 75 | |
| 76 | /*! MGCP endpoint typeset */ |
| 77 | struct mgcp_endpoint_typeset { |
| 78 | struct mgcp_endpoint_type rtp; |
Philipp Maier | 0996a1e | 2020-06-10 15:27:14 +0200 | [diff] [blame] | 79 | struct mgcp_endpoint_type e1; |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 80 | }; |
| 81 | |
| 82 | /*! static MGCP endpoint typeset (pre-initalized, read-only) */ |
| 83 | extern const struct mgcp_endpoint_typeset ep_typeset; |
Philipp Maier | edc00f4 | 2018-01-24 11:58:56 +0100 | [diff] [blame] | 84 | |
Philipp Maier | fdd603c | 2018-02-01 13:31:15 +0100 | [diff] [blame] | 85 | /*! MGCP endpoint model */ |
| 86 | struct mgcp_endpoint { |
| 87 | |
Philipp Maier | c66ab2c | 2020-06-02 20:55:34 +0200 | [diff] [blame] | 88 | /*! Unique endpoint name, used for addressing via MGCP */ |
| 89 | char *name; |
| 90 | |
Neels Hofmeyr | 8838c62 | 2018-06-26 00:05:53 +0200 | [diff] [blame] | 91 | /*! Call identifier string (as supplied by the call agant) */ |
Philipp Maier | fdd603c | 2018-02-01 13:31:15 +0100 | [diff] [blame] | 92 | char *callid; |
| 93 | |
Neels Hofmeyr | 8838c62 | 2018-06-26 00:05:53 +0200 | [diff] [blame] | 94 | /*! Local connection options (see mgcp_internal.h) */ |
Philipp Maier | fdd603c | 2018-02-01 13:31:15 +0100 | [diff] [blame] | 95 | struct mgcp_lco local_options; |
| 96 | |
Neels Hofmeyr | f0504e8 | 2018-08-28 21:12:59 +0200 | [diff] [blame] | 97 | /*! List of struct mgcp_conn, of the connections active on this endpoint */ |
Philipp Maier | fdd603c | 2018-02-01 13:31:15 +0100 | [diff] [blame] | 98 | struct llist_head conns; |
| 99 | |
Philipp Maier | c66ab2c | 2020-06-02 20:55:34 +0200 | [diff] [blame] | 100 | /*! Backpointer to the trunk this endpoint belongs to */ |
Philipp Maier | 14b27a8 | 2020-06-02 20:15:30 +0200 | [diff] [blame] | 101 | struct mgcp_trunk *trunk; |
Philipp Maier | fdd603c | 2018-02-01 13:31:15 +0100 | [diff] [blame] | 102 | |
Neels Hofmeyr | 8838c62 | 2018-06-26 00:05:53 +0200 | [diff] [blame] | 103 | /*! Endpoint properties (see above) */ |
Philipp Maier | fdd603c | 2018-02-01 13:31:15 +0100 | [diff] [blame] | 104 | const struct mgcp_endpoint_type *type; |
| 105 | |
Neels Hofmeyr | 8838c62 | 2018-06-26 00:05:53 +0200 | [diff] [blame] | 106 | /*! Last MGCP transmission (in case re-transmission is required) */ |
Philipp Maier | fdd603c | 2018-02-01 13:31:15 +0100 | [diff] [blame] | 107 | char *last_trans; |
| 108 | |
Neels Hofmeyr | 8838c62 | 2018-06-26 00:05:53 +0200 | [diff] [blame] | 109 | /*! Last MGCP response (in case re-transmission is required) */ |
Philipp Maier | fdd603c | 2018-02-01 13:31:15 +0100 | [diff] [blame] | 110 | char *last_response; |
| 111 | |
Neels Hofmeyr | e6d8e91 | 2018-08-23 16:36:48 +0200 | [diff] [blame] | 112 | /*! MGCP_X_OSMO_IGN_* flags from 'X-Osmo-IGN:' header */ |
| 113 | uint32_t x_osmo_ign; |
Philipp Maier | 889fe7f | 2020-07-06 17:44:12 +0200 | [diff] [blame] | 114 | |
| 115 | /* E1 specific */ |
| 116 | struct { |
| 117 | struct osmo_i460_schan_desc scd; |
| 118 | struct osmo_i460_subchan *schan; |
| 119 | struct osmo_fsm_inst *trau_sync_fi; |
| 120 | struct osmo_trau2rtp_state *trau_rtp_st; |
| 121 | uint8_t last_amr_ft; |
| 122 | struct mgcp_rtp_codec *last_codec; |
| 123 | } e1; |
| 124 | |
Philipp Maier | fdd603c | 2018-02-01 13:31:15 +0100 | [diff] [blame] | 125 | }; |
| 126 | |
Philipp Maier | 7462b95 | 2020-06-10 14:50:34 +0200 | [diff] [blame] | 127 | struct mgcp_endpoint *mgcp_endp_alloc(struct mgcp_trunk *trunk, unsigned int index); |
Philipp Maier | 1355d7e | 2018-02-01 14:30:06 +0100 | [diff] [blame] | 128 | void mgcp_endp_release(struct mgcp_endpoint *endp); |
Philipp Maier | 889fe7f | 2020-07-06 17:44:12 +0200 | [diff] [blame] | 129 | int mgcp_endp_claim(struct mgcp_endpoint *endp, const char *callid); |
| 130 | void mgcp_endp_update(struct mgcp_endpoint *endp); |
Philipp Maier | d64c041 | 2021-07-14 11:53:49 +0200 | [diff] [blame] | 131 | bool mgcp_endp_is_wildcarded(const char *epname); |
Philipp Maier | c66ab2c | 2020-06-02 20:55:34 +0200 | [diff] [blame] | 132 | struct mgcp_endpoint *mgcp_endp_by_name_trunk(int *cause, const char *epname, |
| 133 | const struct mgcp_trunk *trunk); |
| 134 | struct mgcp_endpoint *mgcp_endp_by_name(int *cause, const char *epname, |
| 135 | struct mgcp_config *cfg); |
Philipp Maier | 8d6a193 | 2020-06-18 12:19:31 +0200 | [diff] [blame] | 136 | bool mgcp_endp_avail(struct mgcp_endpoint *endp); |
Pau Espin Pedrol | 6d0a59a | 2020-09-08 16:50:22 +0200 | [diff] [blame] | 137 | void mgcp_endp_add_conn(struct mgcp_endpoint *endp, struct mgcp_conn *conn); |
| 138 | void mgcp_endp_remove_conn(struct mgcp_endpoint *endp, struct mgcp_conn *conn); |
Eric | 25ecc91 | 2021-09-06 03:43:50 +0200 | [diff] [blame] | 139 | void mgcp_endp_strip_name(char *epname_stripped, const char *epname, |
| 140 | const struct mgcp_trunk *trunk); |
| 141 | struct mgcp_endpoint *mgcp_endp_find_specific(const char *epname, |
| 142 | const struct mgcp_trunk *trunk); |