blob: 8271c7f54639a404ba2f8654e2f5c055e4b26e1b [file] [log] [blame]
Holger Hans Peter Freyther97f66e22010-07-28 03:32:52 +08001/* A Media Gateway Control Protocol Media Gateway: RFC 3435 */
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
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (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
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 *
22 */
23
24#ifndef OPENBSC_MGCP_H
25#define OPENBSC_MGCP_H
26
Holger Hans Peter Freythercbf7d182010-07-31 05:25:35 +080027#include <osmocore/msgb.h>
Holger Hans Peter Freyther97f66e22010-07-28 03:32:52 +080028
29#include <arpa/inet.h>
30
31#define RTP_PORT_DEFAULT 4000
Holger Hans Peter Freytherd86208d2010-08-04 06:11:27 +080032
Holger Hans Peter Freyther97f66e22010-07-28 03:32:52 +080033/**
34 * Calculate the RTP audio port for the given multiplex
35 * and the direction. This allows a semi static endpoint
36 * to port calculation removing the need for the BSC
37 * and the MediaGateway to communicate.
38 *
39 * Port usage explained:
40 * base + (multiplex * 2) + 0 == local port to wait for network packets
41 * base + (multiplex * 2) + 1 == local port for rtcp
42 *
43 * The above port will receive packets from the BTS that need
44 * to be patched and forwarded to the network.
45 * The above port will receive packets from the network that
46 * need to be patched and forwarded to the BTS.
47 *
48 * We assume to have a static BTS IP address so we can differentiate
49 * network and BTS.
50 *
51 */
52static inline int rtp_calculate_port(int multiplex, int base)
53{
54 return base + (multiplex * 2);
55}
56
57
58/*
59 * Handling of MGCP Endpoints and the MGCP Config
60 */
61struct mgcp_endpoint;
62struct mgcp_config;
63
64#define MGCP_ENDP_CRCX 1
65#define MGCP_ENDP_DLCX 2
66#define MGCP_ENDP_MDCX 3
67
68/*
69 * what to do with the msg?
70 * - continue as usual?
71 * - reject and send a failure code?
72 * - defer? do not send anything
73 */
74#define MGCP_POLICY_CONT 4
75#define MGCP_POLICY_REJECT 5
76#define MGCP_POLICY_DEFER 6
77
78typedef int (*mgcp_change)(struct mgcp_config *cfg, int endpoint, int state, int local_rtp);
79typedef int (*mgcp_policy)(struct mgcp_config *cfg, int endpoint, int state, const char *transactio_id);
80typedef int (*mgcp_reset)(struct mgcp_config *cfg);
81
82struct mgcp_config {
Holger Hans Peter Freyther97f66e22010-07-28 03:32:52 +080083 int source_port;
84 char *local_ip;
85 char *source_addr;
Holger Hans Peter Freytherd86208d2010-08-04 06:11:27 +080086 unsigned int number_endpoints;
Holger Hans Peter Freyther97f66e22010-07-28 03:32:52 +080087 char *bts_ip;
88 char *call_agent_addr;
89
Holger Hans Peter Freyther97f66e22010-07-28 03:32:52 +080090 struct in_addr bts_in;
91 char *audio_name;
92 int audio_payload;
93 int audio_loop;
94 int early_bind;
95 int rtp_base_port;
96 int endp_dscp;
97
Holger Hans Peter Freyther97f66e22010-07-28 03:32:52 +080098 char *forward_ip;
99 int forward_port;
100
Holger Hans Peter Freyther97f66e22010-07-28 03:32:52 +0800101 /* spec handling */
102 int force_realloc;
103
Holger Hans Peter Freyther97f66e22010-07-28 03:32:52 +0800104 mgcp_change change_cb;
105 mgcp_policy policy_cb;
106 mgcp_reset reset_cb;
107 void *data;
Holger Hans Peter Freytherd86208d2010-08-04 06:11:27 +0800108
109 struct mgcp_endpoint *endpoints;
Holger Hans Peter Freyther5b084012010-08-08 07:51:51 +0800110 uint32_t last_call_id;
Holger Hans Peter Freyther97f66e22010-07-28 03:32:52 +0800111};
112
113/* config management */
114struct mgcp_config *mgcp_config_alloc(void);
115int mgcp_parse_config(const char *config_file, struct mgcp_config *cfg);
116int mgcp_vty_init(void);
Holger Hans Peter Freythere8073762010-08-04 07:34:21 +0800117void mgcp_vty_set_config(struct mgcp_config *cfg);
Holger Hans Peter Freyther97f66e22010-07-28 03:32:52 +0800118int mgcp_endpoints_allocate(struct mgcp_config *cfg);
119int mgcp_bind_rtp_port(struct mgcp_endpoint *endp, int rtp_port);
120void mgcp_free_endp(struct mgcp_endpoint *endp);
121
122/*
123 * format helper functions
124 */
125struct msgb *mgcp_handle_message(struct mgcp_config *cfg, struct msgb *msg);
126struct msgb *mgcp_create_response_with_data(int code, const char *msg, const char *trans, const char *data);
127
128/* adc helper */
129static inline int mgcp_timeslot_to_endpoint(int multiplex, int timeslot)
130{
131 if (timeslot == 0)
132 timeslot = 1;
133 return timeslot + (31 * multiplex);
134}
135
136
137#endif