Neels Hofmeyr | d95ab1e | 2017-09-22 00:52:54 +0200 | [diff] [blame] | 1 | /* MGCP common implementations. |
| 2 | * These are used in libosmo-mgcp as well as libosmo-mgcp-client. |
| 3 | * To avoid interdependency, these are implemented in .h file only. */ |
| 4 | |
| 5 | /* |
| 6 | * (C) 2017 by sysmocom s.f.m.c. GmbH <info@sysmocom.de> |
| 7 | * (C) 2009-2012 by Holger Hans Peter Freyther <zecke@selfish.org> |
| 8 | * (C) 2009-2012 by On-Waves |
| 9 | * All Rights Reserved |
| 10 | * |
| 11 | * This program is free software; you can redistribute it and/or modify |
| 12 | * it under the terms of the GNU Affero General Public License as published by |
| 13 | * the Free Software Foundation; either version 3 of the License, or |
| 14 | * (at your option) any later version. |
| 15 | * |
| 16 | * This program is distributed in the hope that it will be useful, |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | * GNU Affero General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU Affero General Public License |
| 22 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 23 | * |
| 24 | */ |
| 25 | |
| 26 | /* Two copies of this file are kept in osmocom/mgcp/ and osmocom/mgcp_client/. |
| 27 | * Since both are by definition identical, use the old header exclusion ifdefs |
| 28 | * instead of '#pragma once' to avoid including both of these files. |
| 29 | * Though at the time of writing there are no such users, this allows including |
| 30 | * both libosmo-mgcp and libosmo-mgcp-client headers in the same file. */ |
| 31 | #ifndef OSMO_MGCP_COMMON_H |
| 32 | #define OSMO_MGCP_COMMON_H |
| 33 | |
| 34 | #include <string.h> |
| 35 | #include <errno.h> |
| 36 | |
| 37 | #include <osmocom/core/msgb.h> |
| 38 | #include <osmocom/core/logging.h> |
| 39 | |
| 40 | #define for_each_non_empty_line(line, save) \ |
| 41 | for (line = strtok_r(NULL, "\r\n", &save); line; \ |
| 42 | line = strtok_r(NULL, "\r\n", &save)) |
| 43 | |
| 44 | enum mgcp_connection_mode { |
| 45 | MGCP_CONN_NONE = 0, |
| 46 | MGCP_CONN_RECV_ONLY = 1, |
| 47 | MGCP_CONN_SEND_ONLY = 2, |
| 48 | MGCP_CONN_RECV_SEND = MGCP_CONN_RECV_ONLY | MGCP_CONN_SEND_ONLY, |
| 49 | MGCP_CONN_LOOPBACK = 4 | MGCP_CONN_RECV_SEND, |
| 50 | }; |
| 51 | |
Neels Hofmeyr | e6d8e91 | 2018-08-23 16:36:48 +0200 | [diff] [blame] | 52 | #define MGCP_X_OSMO_IGN_HEADER "X-Osmo-IGN:" |
Pau Espin Pedrol | 900cd65 | 2019-04-24 22:06:22 +0200 | [diff] [blame] | 53 | #define MGCP_X_OSMO_OSMUX_HEADER "X-Osmux:" |
Neels Hofmeyr | e6d8e91 | 2018-08-23 16:36:48 +0200 | [diff] [blame] | 54 | |
| 55 | /* Values should be bitwise-OR-able */ |
| 56 | enum mgcp_x_osmo_ign { |
| 57 | MGCP_X_OSMO_IGN_NONE = 0, |
| 58 | MGCP_X_OSMO_IGN_CALLID = 1, |
| 59 | }; |
| 60 | |
Philipp Maier | 228e591 | 2019-03-05 13:56:59 +0100 | [diff] [blame] | 61 | /* Codec parameters (communicated via SDP/fmtp) */ |
| 62 | struct mgcp_codec_param { |
| 63 | bool amr_octet_aligned_present; |
| 64 | bool amr_octet_aligned; |
| 65 | }; |
| 66 | |
Neels Hofmeyr | d95ab1e | 2017-09-22 00:52:54 +0200 | [diff] [blame] | 67 | /* Ensure that the msg->l2h is NUL terminated. */ |
| 68 | static inline int mgcp_msg_terminate_nul(struct msgb *msg) |
| 69 | { |
| 70 | unsigned char *tail = msg->l2h + msgb_l2len(msg); /* char after l2 data */ |
| 71 | if (tail[-1] == '\0') |
| 72 | /* nothing to do */; |
| 73 | else if (msgb_tailroom(msg) > 0) |
| 74 | tail[0] = '\0'; |
| 75 | else if (tail[-1] == '\r' || tail[-1] == '\n') |
| 76 | tail[-1] = '\0'; |
| 77 | else { |
| 78 | LOGP(DLMGCP, LOGL_ERROR, "Cannot NUL terminate MGCP message: " |
| 79 | "Length: %d, Buffer size: %d\n", |
| 80 | msgb_l2len(msg), msg->data_len); |
| 81 | return -ENOTSUP; |
| 82 | } |
| 83 | return 0; |
| 84 | } |
| 85 | |
Philipp Maier | abe8c89 | 2018-01-20 00:15:12 +0100 | [diff] [blame] | 86 | /* Maximum length of the comment field */ |
| 87 | #define MGCP_COMMENT_MAXLEN 256 |
| 88 | |
Neels Hofmeyr | 55e0dcf | 2018-09-03 21:36:56 +0200 | [diff] [blame] | 89 | /* Maximum allowed String length of Connection Identifiers as per spec |
| 90 | * (see also RFC3435 2.1.3.2 Names of Connections), plus one for '\0'. */ |
| 91 | #define MGCP_CONN_ID_MAXLEN 32+1 |
| 92 | |
| 93 | /* Deprecated: old name of MGCP_CONN_ID_MAXLEN. */ |
| 94 | #define MGCP_CONN_ID_LENGTH MGCP_CONN_ID_MAXLEN |
Philipp Maier | 01d24a3 | 2017-11-21 17:26:09 +0100 | [diff] [blame] | 95 | |
Philipp Maier | 6efb43a | 2018-01-15 13:59:10 +0100 | [diff] [blame] | 96 | /* String length of Endpoint Identifiers. |
| 97 | / (see also RFC3435 section 3.2.1.3) */ |
| 98 | #define MGCP_ENDPOINT_MAXLEN (255*2+1+1) |
| 99 | |
Philipp Maier | 7f0966c | 2018-01-17 18:18:12 +0100 | [diff] [blame] | 100 | /* A prefix to denote the virtual trunk (RTP on both ends) */ |
| 101 | #define MGCP_ENDPOINT_PREFIX_VIRTUAL_TRUNK "rtpbridge/" |
| 102 | |
Philipp Maier | c66ab2c | 2020-06-02 20:55:34 +0200 | [diff] [blame] | 103 | /* A prefix to denote the e1 trunk |
| 104 | * (see also RFC3435 section E.2) */ |
| 105 | #define MGCP_ENDPOINT_PREFIX_E1_TRUNK "ds/e1-" |
| 106 | |
Philipp Maier | bc0346e | 2018-06-07 09:52:16 +0200 | [diff] [blame] | 107 | /* Maximal number of payload types / codecs that can be negotiated via SDP at |
| 108 | * at once. */ |
| 109 | #define MGCP_MAX_CODECS 10 |
| 110 | |
Neels Hofmeyr | d95ab1e | 2017-09-22 00:52:54 +0200 | [diff] [blame] | 111 | #endif |