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 | |
| 26 | struct sockaddr_in; |
| 27 | struct mgcp_conn; |
Philipp Maier | edc00f4 | 2018-01-24 11:58:56 +0100 | [diff] [blame] | 28 | struct mgcp_endpoint; |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 29 | |
Philipp Maier | 62612e8 | 2020-05-27 16:29:22 +0200 | [diff] [blame] | 30 | #define LOGPENDP(endp, cat, level, fmt, args...) \ |
Philipp Maier | c66ab2c | 2020-06-02 20:55:34 +0200 | [diff] [blame] | 31 | LOGP(cat, level, "endpoint:%s " fmt, \ |
| 32 | endp ? endp->name : "none", \ |
Philipp Maier | 62612e8 | 2020-05-27 16:29:22 +0200 | [diff] [blame] | 33 | ## args) |
| 34 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 35 | /* Callback type for RTP dispatcher functions |
| 36 | (e.g mgcp_dispatch_rtp_bridge_cb, see below) */ |
Philipp Maier | 36a8112 | 2018-01-24 11:52:34 +0100 | [diff] [blame] | 37 | typedef int (*mgcp_dispatch_rtp_cb) (int proto, struct sockaddr_in *addr, |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 38 | char *buf, unsigned int buf_size, |
Philipp Maier | 36a8112 | 2018-01-24 11:52:34 +0100 | [diff] [blame] | 39 | struct mgcp_conn *conn); |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 40 | |
Philipp Maier | df5d219 | 2018-01-24 11:39:32 +0100 | [diff] [blame] | 41 | /* Callback type for endpoint specific cleanup actions. This function |
| 42 | * is automatically executed when a connection is freed (see mgcp_conn_free() |
| 43 | * in mgcp_conn.c). Depending on the type of the endpoint there may be endpoint |
| 44 | * specific things to take care of once a connection has been removed. */ |
| 45 | typedef void (*mgcp_cleanup_cp) (struct mgcp_endpoint *endp, |
| 46 | struct mgcp_conn *conn); |
| 47 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 48 | /*! MGCP endpoint properties */ |
| 49 | struct mgcp_endpoint_type { |
Neels Hofmeyr | 8838c62 | 2018-06-26 00:05:53 +0200 | [diff] [blame] | 50 | /*! maximum number of connections */ |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 51 | int max_conns; |
| 52 | |
Neels Hofmeyr | 8838c62 | 2018-06-26 00:05:53 +0200 | [diff] [blame] | 53 | /*! callback that defines how to dispatch incoming RTP data */ |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 54 | mgcp_dispatch_rtp_cb dispatch_rtp_cb; |
Philipp Maier | df5d219 | 2018-01-24 11:39:32 +0100 | [diff] [blame] | 55 | |
Neels Hofmeyr | 8838c62 | 2018-06-26 00:05:53 +0200 | [diff] [blame] | 56 | /*! callback that implements endpoint specific cleanup actions */ |
Philipp Maier | df5d219 | 2018-01-24 11:39:32 +0100 | [diff] [blame] | 57 | mgcp_cleanup_cp cleanup_cb; |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 58 | }; |
| 59 | |
| 60 | /*! MGCP endpoint typeset */ |
| 61 | struct mgcp_endpoint_typeset { |
| 62 | struct mgcp_endpoint_type rtp; |
Philipp Maier | 0996a1e | 2020-06-10 15:27:14 +0200 | [diff] [blame] | 63 | struct mgcp_endpoint_type e1; |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 64 | }; |
| 65 | |
| 66 | /*! static MGCP endpoint typeset (pre-initalized, read-only) */ |
| 67 | extern const struct mgcp_endpoint_typeset ep_typeset; |
Philipp Maier | edc00f4 | 2018-01-24 11:58:56 +0100 | [diff] [blame] | 68 | |
Philipp Maier | fdd603c | 2018-02-01 13:31:15 +0100 | [diff] [blame] | 69 | /*! MGCP endpoint model */ |
| 70 | struct mgcp_endpoint { |
| 71 | |
Philipp Maier | c66ab2c | 2020-06-02 20:55:34 +0200 | [diff] [blame] | 72 | /*! Unique endpoint name, used for addressing via MGCP */ |
| 73 | char *name; |
| 74 | |
Neels Hofmeyr | 8838c62 | 2018-06-26 00:05:53 +0200 | [diff] [blame] | 75 | /*! Call identifier string (as supplied by the call agant) */ |
Philipp Maier | fdd603c | 2018-02-01 13:31:15 +0100 | [diff] [blame] | 76 | char *callid; |
| 77 | |
Neels Hofmeyr | 8838c62 | 2018-06-26 00:05:53 +0200 | [diff] [blame] | 78 | /*! Local connection options (see mgcp_internal.h) */ |
Philipp Maier | fdd603c | 2018-02-01 13:31:15 +0100 | [diff] [blame] | 79 | struct mgcp_lco local_options; |
| 80 | |
Neels Hofmeyr | f0504e8 | 2018-08-28 21:12:59 +0200 | [diff] [blame] | 81 | /*! List of struct mgcp_conn, of the connections active on this endpoint */ |
Philipp Maier | fdd603c | 2018-02-01 13:31:15 +0100 | [diff] [blame] | 82 | struct llist_head conns; |
| 83 | |
Neels Hofmeyr | 8838c62 | 2018-06-26 00:05:53 +0200 | [diff] [blame] | 84 | /*! Backpointer to the MGW configuration */ |
Philipp Maier | fdd603c | 2018-02-01 13:31:15 +0100 | [diff] [blame] | 85 | struct mgcp_config *cfg; |
| 86 | |
Philipp Maier | c66ab2c | 2020-06-02 20:55:34 +0200 | [diff] [blame] | 87 | /*! Backpointer to the trunk this endpoint belongs to */ |
Philipp Maier | 14b27a8 | 2020-06-02 20:15:30 +0200 | [diff] [blame] | 88 | struct mgcp_trunk *trunk; |
Philipp Maier | fdd603c | 2018-02-01 13:31:15 +0100 | [diff] [blame] | 89 | |
Neels Hofmeyr | 8838c62 | 2018-06-26 00:05:53 +0200 | [diff] [blame] | 90 | /*! Endpoint properties (see above) */ |
Philipp Maier | fdd603c | 2018-02-01 13:31:15 +0100 | [diff] [blame] | 91 | const struct mgcp_endpoint_type *type; |
| 92 | |
Neels Hofmeyr | 8838c62 | 2018-06-26 00:05:53 +0200 | [diff] [blame] | 93 | /*! Last MGCP transmission (in case re-transmission is required) */ |
Philipp Maier | fdd603c | 2018-02-01 13:31:15 +0100 | [diff] [blame] | 94 | char *last_trans; |
| 95 | |
Neels Hofmeyr | 8838c62 | 2018-06-26 00:05:53 +0200 | [diff] [blame] | 96 | /*! Last MGCP response (in case re-transmission is required) */ |
Philipp Maier | fdd603c | 2018-02-01 13:31:15 +0100 | [diff] [blame] | 97 | char *last_response; |
| 98 | |
Neels Hofmeyr | 8838c62 | 2018-06-26 00:05:53 +0200 | [diff] [blame] | 99 | /*! Memorize if this endpoint was choosen by the MGW (wildcarded, true) |
Philipp Maier | fdd603c | 2018-02-01 13:31:15 +0100 | [diff] [blame] | 100 | * or if the user has choosen the particular endpoint explicitly. */ |
Philipp Maier | 207ab51 | 2018-02-02 14:19:26 +0100 | [diff] [blame] | 101 | bool wildcarded_req; |
Neels Hofmeyr | e6d8e91 | 2018-08-23 16:36:48 +0200 | [diff] [blame] | 102 | |
| 103 | /*! MGCP_X_OSMO_IGN_* flags from 'X-Osmo-IGN:' header */ |
| 104 | uint32_t x_osmo_ign; |
Philipp Maier | fdd603c | 2018-02-01 13:31:15 +0100 | [diff] [blame] | 105 | }; |
| 106 | |
Philipp Maier | 7462b95 | 2020-06-10 14:50:34 +0200 | [diff] [blame] | 107 | 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] | 108 | void mgcp_endp_release(struct mgcp_endpoint *endp); |
Philipp Maier | c66ab2c | 2020-06-02 20:55:34 +0200 | [diff] [blame] | 109 | struct mgcp_endpoint *mgcp_endp_by_name_trunk(int *cause, const char *epname, |
| 110 | const struct mgcp_trunk *trunk); |
| 111 | struct mgcp_endpoint *mgcp_endp_by_name(int *cause, const char *epname, |
| 112 | struct mgcp_config *cfg); |
Philipp Maier | 8d6a193 | 2020-06-18 12:19:31 +0200 | [diff] [blame] | 113 | bool mgcp_endp_avail(struct mgcp_endpoint *endp); |