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 | 85f9401 | 2018-10-08 03:36:45 +0200 | [diff] [blame] | 26 | #include <osmocom/core/msgb.h> |
| 27 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 28 | struct sockaddr_in; |
| 29 | struct mgcp_conn; |
Neels Hofmeyr | 85f9401 | 2018-10-08 03:36:45 +0200 | [diff] [blame] | 30 | struct mgcp_conn_rtp; |
Philipp Maier | edc00f4 | 2018-01-24 11:58:56 +0100 | [diff] [blame] | 31 | struct mgcp_endpoint; |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 32 | |
Neels Hofmeyr | 85f9401 | 2018-10-08 03:36:45 +0200 | [diff] [blame] | 33 | struct osmo_rtp_msg_ctx { |
| 34 | int proto; |
| 35 | struct mgcp_conn_rtp *conn_src; |
| 36 | struct sockaddr_in *from_addr; |
| 37 | }; |
| 38 | |
| 39 | #define OSMO_RTP_MSG_CTX(MSGB) (*(struct osmo_rtp_msg_ctx**)&((MSGB)->dst)) |
| 40 | |
Neels Hofmeyr | 3243c7c | 2018-09-30 05:01:20 +0200 | [diff] [blame] | 41 | #define LOG_ENDP(endp, level, fmt, args...) \ |
| 42 | LOGP(DRTP, level, "%x@ " fmt, ENDPOINT_NUMBER(endp), ## args) |
| 43 | |
Neels Hofmeyr | 85f9401 | 2018-10-08 03:36:45 +0200 | [diff] [blame] | 44 | /* Callback type for RTP dispatcher functions (e.g mgcp_dispatch_rtp_bridge_cb, see below). |
| 45 | * The fields OSMO_RTP_MSG_PROTO, OSMO_RTP_MSG_CONN_SRC, OSMO_RTP_MSG_FROM_ADDR should be set |
| 46 | * appropriately on the msg. */ |
| 47 | typedef int (*mgcp_dispatch_rtp_cb) (struct msgb *msg); |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 48 | |
Philipp Maier | df5d219 | 2018-01-24 11:39:32 +0100 | [diff] [blame] | 49 | /* Callback type for endpoint specific cleanup actions. This function |
| 50 | * is automatically executed when a connection is freed (see mgcp_conn_free() |
| 51 | * in mgcp_conn.c). Depending on the type of the endpoint there may be endpoint |
| 52 | * specific things to take care of once a connection has been removed. */ |
| 53 | typedef void (*mgcp_cleanup_cp) (struct mgcp_endpoint *endp, |
| 54 | struct mgcp_conn *conn); |
| 55 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 56 | /*! MGCP endpoint properties */ |
| 57 | struct mgcp_endpoint_type { |
Neels Hofmeyr | 8838c62 | 2018-06-26 00:05:53 +0200 | [diff] [blame] | 58 | /*! maximum number of connections */ |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 59 | int max_conns; |
| 60 | |
Neels Hofmeyr | 8838c62 | 2018-06-26 00:05:53 +0200 | [diff] [blame] | 61 | /*! callback that defines how to dispatch incoming RTP data */ |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 62 | mgcp_dispatch_rtp_cb dispatch_rtp_cb; |
Philipp Maier | df5d219 | 2018-01-24 11:39:32 +0100 | [diff] [blame] | 63 | |
Neels Hofmeyr | 8838c62 | 2018-06-26 00:05:53 +0200 | [diff] [blame] | 64 | /*! callback that implements endpoint specific cleanup actions */ |
Philipp Maier | df5d219 | 2018-01-24 11:39:32 +0100 | [diff] [blame] | 65 | mgcp_cleanup_cp cleanup_cb; |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 66 | }; |
| 67 | |
| 68 | /*! MGCP endpoint typeset */ |
| 69 | struct mgcp_endpoint_typeset { |
| 70 | struct mgcp_endpoint_type rtp; |
| 71 | }; |
| 72 | |
| 73 | /*! static MGCP endpoint typeset (pre-initalized, read-only) */ |
| 74 | extern const struct mgcp_endpoint_typeset ep_typeset; |
Philipp Maier | edc00f4 | 2018-01-24 11:58:56 +0100 | [diff] [blame] | 75 | |
Philipp Maier | fdd603c | 2018-02-01 13:31:15 +0100 | [diff] [blame] | 76 | /*! MGCP endpoint model */ |
| 77 | struct mgcp_endpoint { |
| 78 | |
Neels Hofmeyr | 8838c62 | 2018-06-26 00:05:53 +0200 | [diff] [blame] | 79 | /*! Call identifier string (as supplied by the call agant) */ |
Philipp Maier | fdd603c | 2018-02-01 13:31:15 +0100 | [diff] [blame] | 80 | char *callid; |
| 81 | |
Neels Hofmeyr | 8838c62 | 2018-06-26 00:05:53 +0200 | [diff] [blame] | 82 | /*! Local connection options (see mgcp_internal.h) */ |
Philipp Maier | fdd603c | 2018-02-01 13:31:15 +0100 | [diff] [blame] | 83 | struct mgcp_lco local_options; |
| 84 | |
Neels Hofmeyr | f0504e8 | 2018-08-28 21:12:59 +0200 | [diff] [blame] | 85 | /*! List of struct mgcp_conn, of the connections active on this endpoint */ |
Philipp Maier | fdd603c | 2018-02-01 13:31:15 +0100 | [diff] [blame] | 86 | struct llist_head conns; |
| 87 | |
Neels Hofmeyr | 8838c62 | 2018-06-26 00:05:53 +0200 | [diff] [blame] | 88 | /*! Backpointer to the MGW configuration */ |
Philipp Maier | fdd603c | 2018-02-01 13:31:15 +0100 | [diff] [blame] | 89 | struct mgcp_config *cfg; |
| 90 | |
Neels Hofmeyr | 8838c62 | 2018-06-26 00:05:53 +0200 | [diff] [blame] | 91 | /*! Backpointer to the Trunk specific configuration */ |
Philipp Maier | fdd603c | 2018-02-01 13:31:15 +0100 | [diff] [blame] | 92 | struct mgcp_trunk_config *tcfg; |
| 93 | |
Neels Hofmeyr | 8838c62 | 2018-06-26 00:05:53 +0200 | [diff] [blame] | 94 | /*! Endpoint properties (see above) */ |
Philipp Maier | fdd603c | 2018-02-01 13:31:15 +0100 | [diff] [blame] | 95 | const struct mgcp_endpoint_type *type; |
| 96 | |
Neels Hofmeyr | 8838c62 | 2018-06-26 00:05:53 +0200 | [diff] [blame] | 97 | /*! Last MGCP transmission (in case re-transmission is required) */ |
Philipp Maier | fdd603c | 2018-02-01 13:31:15 +0100 | [diff] [blame] | 98 | char *last_trans; |
| 99 | |
Neels Hofmeyr | 8838c62 | 2018-06-26 00:05:53 +0200 | [diff] [blame] | 100 | /*! Last MGCP response (in case re-transmission is required) */ |
Philipp Maier | fdd603c | 2018-02-01 13:31:15 +0100 | [diff] [blame] | 101 | char *last_response; |
| 102 | |
Neels Hofmeyr | 8838c62 | 2018-06-26 00:05:53 +0200 | [diff] [blame] | 103 | /*! Memorize if this endpoint was choosen by the MGW (wildcarded, true) |
Philipp Maier | fdd603c | 2018-02-01 13:31:15 +0100 | [diff] [blame] | 104 | * or if the user has choosen the particular endpoint explicitly. */ |
Philipp Maier | 207ab51 | 2018-02-02 14:19:26 +0100 | [diff] [blame] | 105 | bool wildcarded_req; |
Neels Hofmeyr | e6d8e91 | 2018-08-23 16:36:48 +0200 | [diff] [blame] | 106 | |
| 107 | /*! MGCP_X_OSMO_IGN_* flags from 'X-Osmo-IGN:' header */ |
| 108 | uint32_t x_osmo_ign; |
Philipp Maier | fdd603c | 2018-02-01 13:31:15 +0100 | [diff] [blame] | 109 | }; |
| 110 | |
| 111 | /*! Extract endpoint number for a given endpoint */ |
| 112 | #define ENDPOINT_NUMBER(endp) abs((int)(endp - endp->tcfg->endpoints)) |
| 113 | |
Philipp Maier | 1355d7e | 2018-02-01 14:30:06 +0100 | [diff] [blame] | 114 | void mgcp_endp_release(struct mgcp_endpoint *endp); |
| 115 | |