blob: a1db9cbc8c5c55977b03d50bdbbcce9446747e90 [file] [log] [blame]
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +01001/* MGCP Private Data */
2
3/*
4 * (C) 2009-2010 by Holger Hans Peter Freyther <zecke@selfish.org>
5 * (C) 2009-2010 by On-Waves
6 * 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
Holger Hans Peter Freyther1ebad742010-02-26 20:16:37 +010026#include <osmocore/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 Freyther31868922010-08-03 11:59:04 +000038struct mgcp_rtp_state {
39 int initialized;
Holger Hans Peter Freyther5c1e6cf2010-08-03 15:36:57 +000040 int patch;
Holger Hans Peter Freyther31868922010-08-03 11:59:04 +000041
Holger Hans Peter Freyther6aa882b2010-08-03 14:35:50 +000042 uint32_t orig_ssrc;
43 uint32_t ssrc;
Holger Hans Peter Freyther31868922010-08-03 11:59:04 +000044 uint16_t seq_no;
45 int lost_no;
Holger Hans Peter Freyther6aa882b2010-08-03 14:35:50 +000046 int seq_offset;
47 uint32_t last_timestamp;
48 int32_t timestamp_offset;
Holger Hans Peter Freyther31868922010-08-03 11:59:04 +000049};
Holger Hans Peter Freyther98a38772010-08-03 02:27:21 +080050
Holger Hans Peter Freythera17d7012010-08-05 01:34:51 +080051struct mgcp_rtp_end {
52 /* statistics */
53 unsigned int packets;
54 struct in_addr addr;
55
56 /* in network byte order */
57 int rtp_port, rtcp_port;
58
59 int payload_type;
Holger Hans Peter Freyther58ff2192010-08-05 03:08:35 +080060
Holger Hans Peter Freytherc4921272010-08-05 03:37:22 +080061 /*
62 * Each end has a socket...
63 */
64 struct bsc_fd rtp;
65 struct bsc_fd rtcp;
66
Holger Hans Peter Freyther58ff2192010-08-05 03:08:35 +080067 int local_port;
Holger Hans Peter Freytherf138f912010-08-05 08:08:17 +080068 int local_alloc;
Holger Hans Peter Freythera17d7012010-08-05 01:34:51 +080069};
70
Holger Hans Peter Freyther260d6ed2010-08-06 01:12:21 +080071enum {
72 MGCP_TAP_BTS_IN,
73 MGCP_TAP_BTS_OUT,
74 MGCP_TAP_NET_IN,
75 MGCP_TAP_NET_OUT,
76
77 /* last element */
78 MGCP_TAP_COUNT
79};
80
81struct mgcp_rtp_tap {
82 int enabled;
83 struct sockaddr_in forward;
84};
85
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +010086struct mgcp_endpoint {
Holger Hans Peter Freyther39a97e22010-08-06 18:03:11 +080087 int allocated;
Holger Hans Peter Freyther46340132010-08-06 08:26:54 +080088 uint32_t ci;
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +010089 char *callid;
90 char *local_options;
91 int conn_mode;
Holger Hans Peter Freytherc597a4e2010-08-03 02:57:02 +080092 int orig_mode;
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +010093
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +010094 /* backpointer */
95 struct mgcp_config *cfg;
Holger Hans Peter Freytherb4b135e2010-04-07 09:37:17 +020096
Holger Hans Peter Freythera17d7012010-08-05 01:34:51 +080097 /* port status for bts/net */
98 struct mgcp_rtp_end bts_end;
99 struct mgcp_rtp_end net_end;
Holger Hans Peter Freyther21262332010-11-01 20:53:31 +0100100
Holger Hans Peter Freytherbd7b3c52010-11-01 21:04:54 +0100101 /*
102 * For transcoding we will send from the local_port
103 * of trans_bts and it will arrive at trans_net from
104 * where we will forward it to the network.
105 */
106 struct mgcp_rtp_end trans_bts;
Holger Hans Peter Freyther21262332010-11-01 20:53:31 +0100107 struct mgcp_rtp_end trans_net;
Holger Hans Peter Freytherb54048f2010-11-01 19:57:50 +0100108 int is_transcoded;
Holger Hans Peter Freyther380b8712010-07-29 02:38:39 +0800109
110 /* sequence bits */
Holger Hans Peter Freyther31868922010-08-03 11:59:04 +0000111 struct mgcp_rtp_state net_state;
112 struct mgcp_rtp_state bts_state;
Holger Hans Peter Freyther6357a8e2010-08-05 12:07:00 +0000113
114 /* SSRC/seq/ts patching for loop */
115 int allow_patch;
Holger Hans Peter Freyther260d6ed2010-08-06 01:12:21 +0800116
117 /* tap for the endpoint */
118 struct mgcp_rtp_tap taps[MGCP_TAP_COUNT];
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +0100119};
120
121#define ENDPOINT_NUMBER(endp) abs(endp - endp->cfg->endpoints)
122
Holger Hans Peter Freytherf2f15912010-04-01 03:27:04 +0200123struct mgcp_msg_ptr {
124 unsigned int start;
125 unsigned int length;
126};
127
128int mgcp_analyze_header(struct mgcp_config *cfg, struct msgb *msg,
129 struct mgcp_msg_ptr *ptr, int size,
130 const char **transaction_id, struct mgcp_endpoint **endp);
Holger Hans Peter Freytherb844b872010-04-21 21:25:13 +0800131int mgcp_send_dummy(struct mgcp_endpoint *endp);
Holger Hans Peter Freytherbb89aa12010-08-05 03:29:33 +0800132int mgcp_bind_bts_rtp_port(struct mgcp_endpoint *endp, int rtp_port);
Holger Hans Peter Freyther314584a2010-08-05 04:10:21 +0800133int mgcp_bind_net_rtp_port(struct mgcp_endpoint *endp, int rtp_port);
Holger Hans Peter Freytherbd7b3c52010-11-01 21:04:54 +0100134int mgcp_bind_trans_bts_rtp_port(struct mgcp_endpoint *enp, int rtp_port);
135int mgcp_bind_trans_net_rtp_port(struct mgcp_endpoint *enp, int rtp_port);
Holger Hans Peter Freytherf138f912010-08-05 08:08:17 +0800136int mgcp_free_rtp_port(struct mgcp_rtp_end *end);
Holger Hans Peter Freytherf2f15912010-04-01 03:27:04 +0200137
Holger Hans Peter Freytherbd7b3c52010-11-01 21:04:54 +0100138/* For transcoding we need to manage an in and an output that are connected */
139static inline int endp_back_channel(int endpoint)
140{
141 return endpoint + 60;
142}
143
144
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +0100145#endif