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 | |
Pau Espin Pedrol | de805b6 | 2022-10-03 16:08:58 +0200 | [diff] [blame] | 43 | enum rtp_proto { |
| 44 | MGCP_PROTO_RTP, |
| 45 | MGCP_PROTO_RTCP, |
| 46 | }; |
| 47 | |
Neels Hofmeyr | 51b42ff | 2020-06-19 01:34:42 +0200 | [diff] [blame] | 48 | struct osmo_rtp_msg_ctx { |
Pau Espin Pedrol | de805b6 | 2022-10-03 16:08:58 +0200 | [diff] [blame] | 49 | enum rtp_proto proto; |
Neels Hofmeyr | 51b42ff | 2020-06-19 01:34:42 +0200 | [diff] [blame] | 50 | struct mgcp_conn_rtp *conn_src; |
Pau Espin Pedrol | a790f0c | 2020-08-31 13:29:11 +0200 | [diff] [blame] | 51 | struct osmo_sockaddr *from_addr; |
Neels Hofmeyr | 51b42ff | 2020-06-19 01:34:42 +0200 | [diff] [blame] | 52 | }; |
| 53 | |
| 54 | #define OSMO_RTP_MSG_CTX(MSGB) ((struct osmo_rtp_msg_ctx*)(MSGB)->cb) |
| 55 | |
| 56 | osmo_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. */ |
| 60 | typedef int (*mgcp_dispatch_rtp_cb) (struct msgb *msg); |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 61 | |
Philipp Maier | df5d219 | 2018-01-24 11:39:32 +0100 | [diff] [blame] | 62 | /* 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. */ |
| 66 | typedef void (*mgcp_cleanup_cp) (struct mgcp_endpoint *endp, |
| 67 | struct mgcp_conn *conn); |
| 68 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 69 | /*! MGCP endpoint properties */ |
| 70 | struct mgcp_endpoint_type { |
Neels Hofmeyr | 8838c62 | 2018-06-26 00:05:53 +0200 | [diff] [blame] | 71 | /*! maximum number of connections */ |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 72 | int max_conns; |
| 73 | |
Neels Hofmeyr | 8838c62 | 2018-06-26 00:05:53 +0200 | [diff] [blame] | 74 | /*! callback that defines how to dispatch incoming RTP data */ |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 75 | mgcp_dispatch_rtp_cb dispatch_rtp_cb; |
Philipp Maier | df5d219 | 2018-01-24 11:39:32 +0100 | [diff] [blame] | 76 | |
Neels Hofmeyr | 8838c62 | 2018-06-26 00:05:53 +0200 | [diff] [blame] | 77 | /*! callback that implements endpoint specific cleanup actions */ |
Philipp Maier | df5d219 | 2018-01-24 11:39:32 +0100 | [diff] [blame] | 78 | mgcp_cleanup_cp cleanup_cb; |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 79 | }; |
| 80 | |
| 81 | /*! MGCP endpoint typeset */ |
| 82 | struct mgcp_endpoint_typeset { |
| 83 | struct mgcp_endpoint_type rtp; |
Philipp Maier | 0996a1e | 2020-06-10 15:27:14 +0200 | [diff] [blame] | 84 | struct mgcp_endpoint_type e1; |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 85 | }; |
| 86 | |
| 87 | /*! static MGCP endpoint typeset (pre-initalized, read-only) */ |
| 88 | extern const struct mgcp_endpoint_typeset ep_typeset; |
Philipp Maier | edc00f4 | 2018-01-24 11:58:56 +0100 | [diff] [blame] | 89 | |
Philipp Maier | fdd603c | 2018-02-01 13:31:15 +0100 | [diff] [blame] | 90 | /*! MGCP endpoint model */ |
| 91 | struct mgcp_endpoint { |
| 92 | |
Philipp Maier | c66ab2c | 2020-06-02 20:55:34 +0200 | [diff] [blame] | 93 | /*! Unique endpoint name, used for addressing via MGCP */ |
| 94 | char *name; |
| 95 | |
Neels Hofmeyr | 8838c62 | 2018-06-26 00:05:53 +0200 | [diff] [blame] | 96 | /*! Call identifier string (as supplied by the call agant) */ |
Philipp Maier | fdd603c | 2018-02-01 13:31:15 +0100 | [diff] [blame] | 97 | char *callid; |
| 98 | |
Neels Hofmeyr | 8838c62 | 2018-06-26 00:05:53 +0200 | [diff] [blame] | 99 | /*! Local connection options (see mgcp_internal.h) */ |
Philipp Maier | fdd603c | 2018-02-01 13:31:15 +0100 | [diff] [blame] | 100 | struct mgcp_lco local_options; |
| 101 | |
Neels Hofmeyr | f0504e8 | 2018-08-28 21:12:59 +0200 | [diff] [blame] | 102 | /*! List of struct mgcp_conn, of the connections active on this endpoint */ |
Philipp Maier | fdd603c | 2018-02-01 13:31:15 +0100 | [diff] [blame] | 103 | struct llist_head conns; |
| 104 | |
Philipp Maier | c66ab2c | 2020-06-02 20:55:34 +0200 | [diff] [blame] | 105 | /*! Backpointer to the trunk this endpoint belongs to */ |
Philipp Maier | 14b27a8 | 2020-06-02 20:15:30 +0200 | [diff] [blame] | 106 | struct mgcp_trunk *trunk; |
Philipp Maier | fdd603c | 2018-02-01 13:31:15 +0100 | [diff] [blame] | 107 | |
Neels Hofmeyr | 8838c62 | 2018-06-26 00:05:53 +0200 | [diff] [blame] | 108 | /*! Endpoint properties (see above) */ |
Philipp Maier | fdd603c | 2018-02-01 13:31:15 +0100 | [diff] [blame] | 109 | const struct mgcp_endpoint_type *type; |
| 110 | |
Neels Hofmeyr | 8838c62 | 2018-06-26 00:05:53 +0200 | [diff] [blame] | 111 | /*! Last MGCP transmission (in case re-transmission is required) */ |
Philipp Maier | fdd603c | 2018-02-01 13:31:15 +0100 | [diff] [blame] | 112 | char *last_trans; |
| 113 | |
Neels Hofmeyr | 8838c62 | 2018-06-26 00:05:53 +0200 | [diff] [blame] | 114 | /*! Last MGCP response (in case re-transmission is required) */ |
Philipp Maier | fdd603c | 2018-02-01 13:31:15 +0100 | [diff] [blame] | 115 | char *last_response; |
| 116 | |
Neels Hofmeyr | e6d8e91 | 2018-08-23 16:36:48 +0200 | [diff] [blame] | 117 | /*! MGCP_X_OSMO_IGN_* flags from 'X-Osmo-IGN:' header */ |
| 118 | uint32_t x_osmo_ign; |
Philipp Maier | 889fe7f | 2020-07-06 17:44:12 +0200 | [diff] [blame] | 119 | |
| 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 Maier | fdd603c | 2018-02-01 13:31:15 +0100 | [diff] [blame] | 130 | }; |
| 131 | |
Philipp Maier | 7462b95 | 2020-06-10 14:50:34 +0200 | [diff] [blame] | 132 | 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] | 133 | void mgcp_endp_release(struct mgcp_endpoint *endp); |
Philipp Maier | 889fe7f | 2020-07-06 17:44:12 +0200 | [diff] [blame] | 134 | int mgcp_endp_claim(struct mgcp_endpoint *endp, const char *callid); |
| 135 | void mgcp_endp_update(struct mgcp_endpoint *endp); |
Philipp Maier | d64c041 | 2021-07-14 11:53:49 +0200 | [diff] [blame] | 136 | bool mgcp_endp_is_wildcarded(const char *epname); |
Philipp Maier | c66ab2c | 2020-06-02 20:55:34 +0200 | [diff] [blame] | 137 | struct mgcp_endpoint *mgcp_endp_by_name_trunk(int *cause, const char *epname, |
| 138 | const struct mgcp_trunk *trunk); |
| 139 | struct mgcp_endpoint *mgcp_endp_by_name(int *cause, const char *epname, |
| 140 | struct mgcp_config *cfg); |
Philipp Maier | 8d6a193 | 2020-06-18 12:19:31 +0200 | [diff] [blame] | 141 | bool mgcp_endp_avail(struct mgcp_endpoint *endp); |
Pau Espin Pedrol | 6d0a59a | 2020-09-08 16:50:22 +0200 | [diff] [blame] | 142 | void mgcp_endp_add_conn(struct mgcp_endpoint *endp, struct mgcp_conn *conn); |
| 143 | void mgcp_endp_remove_conn(struct mgcp_endpoint *endp, struct mgcp_conn *conn); |
Eric | 25ecc91 | 2021-09-06 03:43:50 +0200 | [diff] [blame] | 144 | void mgcp_endp_strip_name(char *epname_stripped, const char *epname, |
| 145 | const struct mgcp_trunk *trunk); |
| 146 | struct mgcp_endpoint *mgcp_endp_find_specific(const char *epname, |
| 147 | const struct mgcp_trunk *trunk); |