blob: a9d51494b69be4482c4de45289fa0d0ad4b61ff2 [file] [log] [blame]
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +01001/* MGCP Private Data */
2
3/*
Holger Hans Peter Freyther88ad7722011-02-28 00:56:17 +01004 * (C) 2009-2011 by Holger Hans Peter Freyther <zecke@selfish.org>
5 * (C) 2009-2011 by On-Waves
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +01006 * All Rights Reserved
7 *
8 * This program is free software; you can redistribute it and/or modify
Harald Welte9af6ddf2011-01-01 15:25:50 +01009 * it under the terms of the GNU Affero General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +010011 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Harald Welte9af6ddf2011-01-01 15:25:50 +010016 * GNU Affero General Public License for more details.
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +010017 *
Harald Welte9af6ddf2011-01-01 15:25:50 +010018 * You should have received a copy of the GNU Affero General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +010020 *
21 */
22
23#ifndef OPENBSC_MGCP_DATA_H
24#define OPENBSC_MGCP_DATA_H
25
Pablo Neira Ayuso136f4532011-03-22 16:47:59 +010026#include <osmocom/core/select.h>
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +010027
28#define CI_UNUSED 0
29
Holger Hans Peter Freyther98a38772010-08-03 02:27:21 +080030enum mgcp_connection_mode {
31 MGCP_CONN_NONE = 0,
32 MGCP_CONN_RECV_ONLY = 1,
33 MGCP_CONN_SEND_ONLY = 2,
34 MGCP_CONN_RECV_SEND = MGCP_CONN_RECV_ONLY | MGCP_CONN_SEND_ONLY,
35 MGCP_CONN_LOOPBACK = 4,
36};
37
Holger Hans Peter Freyther88ad7722011-02-28 00:56:17 +010038enum mgcp_trunk_type {
39 MGCP_TRUNK_VIRTUAL,
40 MGCP_TRUNK_E1,
41};
42
Holger Hans Peter Freyther31868922010-08-03 11:59:04 +000043struct mgcp_rtp_state {
44 int initialized;
Holger Hans Peter Freyther5c1e6cf2010-08-03 15:36:57 +000045 int patch;
Holger Hans Peter Freyther31868922010-08-03 11:59:04 +000046
Holger Hans Peter Freyther6aa882b2010-08-03 14:35:50 +000047 uint32_t orig_ssrc;
48 uint32_t ssrc;
Holger Hans Peter Freyther31868922010-08-03 11:59:04 +000049 uint16_t seq_no;
50 int lost_no;
Holger Hans Peter Freyther6aa882b2010-08-03 14:35:50 +000051 int seq_offset;
52 uint32_t last_timestamp;
53 int32_t timestamp_offset;
Holger Hans Peter Freyther31868922010-08-03 11:59:04 +000054};
Holger Hans Peter Freyther98a38772010-08-03 02:27:21 +080055
Holger Hans Peter Freythera17d7012010-08-05 01:34:51 +080056struct mgcp_rtp_end {
57 /* statistics */
58 unsigned int packets;
59 struct in_addr addr;
60
61 /* in network byte order */
62 int rtp_port, rtcp_port;
63
64 int payload_type;
Holger Hans Peter Freyther58ff2192010-08-05 03:08:35 +080065
Holger Hans Peter Freytherc4921272010-08-05 03:37:22 +080066 /*
67 * Each end has a socket...
68 */
Pablo Neira Ayuso4db92992011-05-06 12:11:23 +020069 struct osmo_fd rtp;
70 struct osmo_fd rtcp;
Holger Hans Peter Freytherc4921272010-08-05 03:37:22 +080071
Holger Hans Peter Freyther58ff2192010-08-05 03:08:35 +080072 int local_port;
Holger Hans Peter Freytherf138f912010-08-05 08:08:17 +080073 int local_alloc;
Holger Hans Peter Freythera17d7012010-08-05 01:34:51 +080074};
75
Holger Hans Peter Freyther260d6ed2010-08-06 01:12:21 +080076enum {
77 MGCP_TAP_BTS_IN,
78 MGCP_TAP_BTS_OUT,
79 MGCP_TAP_NET_IN,
80 MGCP_TAP_NET_OUT,
81
82 /* last element */
83 MGCP_TAP_COUNT
84};
85
86struct mgcp_rtp_tap {
87 int enabled;
88 struct sockaddr_in forward;
89};
90
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +010091struct mgcp_endpoint {
Holger Hans Peter Freyther39a97e22010-08-06 18:03:11 +080092 int allocated;
Holger Hans Peter Freyther46340132010-08-06 08:26:54 +080093 uint32_t ci;
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +010094 char *callid;
95 char *local_options;
96 int conn_mode;
Holger Hans Peter Freytherc597a4e2010-08-03 02:57:02 +080097 int orig_mode;
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +010098
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +010099 /* backpointer */
100 struct mgcp_config *cfg;
Holger Hans Peter Freyther88ad7722011-02-28 00:56:17 +0100101 struct mgcp_trunk_config *tcfg;
Holger Hans Peter Freytherb4b135e2010-04-07 09:37:17 +0200102
Holger Hans Peter Freythera17d7012010-08-05 01:34:51 +0800103 /* port status for bts/net */
104 struct mgcp_rtp_end bts_end;
105 struct mgcp_rtp_end net_end;
Holger Hans Peter Freyther21262332010-11-01 20:53:31 +0100106
Holger Hans Peter Freytherbd7b3c52010-11-01 21:04:54 +0100107 /*
108 * For transcoding we will send from the local_port
109 * of trans_bts and it will arrive at trans_net from
110 * where we will forward it to the network.
111 */
112 struct mgcp_rtp_end trans_bts;
Holger Hans Peter Freyther21262332010-11-01 20:53:31 +0100113 struct mgcp_rtp_end trans_net;
Holger Hans Peter Freytherb54048f2010-11-01 19:57:50 +0100114 int is_transcoded;
Holger Hans Peter Freyther380b8712010-07-29 02:38:39 +0800115
116 /* sequence bits */
Holger Hans Peter Freyther31868922010-08-03 11:59:04 +0000117 struct mgcp_rtp_state net_state;
118 struct mgcp_rtp_state bts_state;
Holger Hans Peter Freyther6357a8e2010-08-05 12:07:00 +0000119
120 /* SSRC/seq/ts patching for loop */
121 int allow_patch;
Holger Hans Peter Freyther260d6ed2010-08-06 01:12:21 +0800122
123 /* tap for the endpoint */
124 struct mgcp_rtp_tap taps[MGCP_TAP_COUNT];
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +0100125};
126
Holger Hans Peter Freyther88ad7722011-02-28 00:56:17 +0100127#define ENDPOINT_NUMBER(endp) abs(endp - endp->tcfg->endpoints)
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +0100128
Holger Hans Peter Freytherf2f15912010-04-01 03:27:04 +0200129struct mgcp_msg_ptr {
130 unsigned int start;
131 unsigned int length;
132};
133
134int mgcp_analyze_header(struct mgcp_config *cfg, struct msgb *msg,
135 struct mgcp_msg_ptr *ptr, int size,
136 const char **transaction_id, struct mgcp_endpoint **endp);
Holger Hans Peter Freytherb844b872010-04-21 21:25:13 +0800137int mgcp_send_dummy(struct mgcp_endpoint *endp);
Holger Hans Peter Freytherbb89aa12010-08-05 03:29:33 +0800138int mgcp_bind_bts_rtp_port(struct mgcp_endpoint *endp, int rtp_port);
Holger Hans Peter Freyther314584a2010-08-05 04:10:21 +0800139int mgcp_bind_net_rtp_port(struct mgcp_endpoint *endp, int rtp_port);
Holger Hans Peter Freytherbd7b3c52010-11-01 21:04:54 +0100140int mgcp_bind_trans_bts_rtp_port(struct mgcp_endpoint *enp, int rtp_port);
141int mgcp_bind_trans_net_rtp_port(struct mgcp_endpoint *enp, int rtp_port);
Holger Hans Peter Freytherf138f912010-08-05 08:08:17 +0800142int mgcp_free_rtp_port(struct mgcp_rtp_end *end);
Holger Hans Peter Freytherf2f15912010-04-01 03:27:04 +0200143
Holger Hans Peter Freytherbd7b3c52010-11-01 21:04:54 +0100144/* For transcoding we need to manage an in and an output that are connected */
145static inline int endp_back_channel(int endpoint)
146{
147 return endpoint + 60;
148}
149
Holger Hans Peter Freyther0e939fe2011-02-28 12:11:02 +0100150struct mgcp_trunk_config *mgcp_trunk_alloc(struct mgcp_config *cfg, int index);
151struct mgcp_trunk_config *mgcp_trunk_num(struct mgcp_config *cfg, int index);
152
Holger Hans Peter Freytherbd7b3c52010-11-01 21:04:54 +0100153
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +0100154#endif