blob: c60a4550c37551db693ac21bbd9d434b71e07dc2 [file] [log] [blame]
Holger Hans Peter Freytherf67945f2009-10-09 07:08:11 +02001/* A Media Gateway Control Protocol Media Gateway: RFC 3435 */
2
3/*
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +01004 * (C) 2009-2010 by Holger Hans Peter Freyther <zecke@selfish.org>
5 * (C) 2009-2010 by On-Waves
Holger Hans Peter Freytherf67945f2009-10-09 07:08:11 +02006 * 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
Holger Hans Peter Freyther62e836c2010-02-03 11:03:45 +010024#ifndef OPENBSC_MGCP_H
25#define OPENBSC_MGCP_H
26
Harald Weltedfe6c7d2010-02-20 16:24:02 +010027#include <osmocore/msgb.h>
Holger Hans Peter Freyther62e836c2010-02-03 11:03:45 +010028
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +010029#include <arpa/inet.h>
30
Holger Hans Peter Freythere0955022010-02-03 08:50:33 +010031#define RTP_PORT_DEFAULT 4000
Holger Hans Peter Freytherf67945f2009-10-09 07:08:11 +020032
33/**
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 */
Holger Hans Peter Freythere0955022010-02-03 08:50:33 +010052static inline int rtp_calculate_port(int multiplex, int base)
Holger Hans Peter Freytherf67945f2009-10-09 07:08:11 +020053{
54 return base + (multiplex * 2);
55}
Holger Hans Peter Freythere0955022010-02-03 08:50:33 +010056
Holger Hans Peter Freyther62e836c2010-02-03 11:03:45 +010057
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +010058/*
59 * Handling of MGCP Endpoints and the MGCP Config
60 */
61struct mgcp_endpoint;
62struct mgcp_config;
Holger Hans Peter Freyther77f7afe2010-02-03 09:54:43 +010063
Holger Hans Peter Freyther77f7afe2010-02-03 09:54:43 +010064#define MGCP_ENDP_CRCX 1
65#define MGCP_ENDP_DLCX 2
66#define MGCP_ENDP_MDCX 3
67
Holger Hans Peter Freytherfe86d3c2010-02-26 13:37:05 +010068/*
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
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +010078typedef int (*mgcp_change)(struct mgcp_config *cfg, int endpoint, int state, int local_rtp);
Holger Hans Peter Freytherfe86d3c2010-02-26 13:37:05 +010079typedef int (*mgcp_policy)(struct mgcp_config *cfg, int endpoint, int state, const char *transactio_id);
Holger Hans Peter Freyther9bdcc9c2010-03-31 06:39:35 +020080typedef int (*mgcp_reset)(struct mgcp_config *cfg);
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +010081
82struct mgcp_config {
83 int source_port;
84 char *local_ip;
85 char *source_addr;
86 unsigned int number_endpoints;
87 char *bts_ip;
88
89 struct in_addr bts_in;
90 char *audio_name;
91 int audio_payload;
92 int audio_loop;
93 int early_bind;
94 int rtp_base_port;
95
96 char *forward_ip;
97 int forward_port;
98
99 mgcp_change change_cb;
Holger Hans Peter Freytherfe86d3c2010-02-26 13:37:05 +0100100 mgcp_policy policy_cb;
Holger Hans Peter Freyther9bdcc9c2010-03-31 06:39:35 +0200101 mgcp_reset reset_cb;
Holger Hans Peter Freytherfe86d3c2010-02-26 13:37:05 +0100102 void *data;
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +0100103
104 struct mgcp_endpoint *endpoints;
105 unsigned int last_call_id;
106};
107
108/* config management */
109struct mgcp_config *mgcp_config_alloc(void);
110int mgcp_parse_config(const char *config_file, struct mgcp_config *cfg);
111int mgcp_vty_init(void);
112int mgcp_endpoints_allocate(struct mgcp_config *cfg);
113int mgcp_bind_rtp_port(struct mgcp_endpoint *endp, int rtp_port);
Holger Hans Peter Freyther154b9552010-02-26 13:27:51 +0100114void mgcp_free_endp(struct mgcp_endpoint *endp);
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +0100115
116/*
117 * format helper functions
118 */
119struct msgb *mgcp_handle_message(struct mgcp_config *cfg, struct msgb *msg);
Holger Hans Peter Freyther6414a0c2010-02-21 10:50:46 +0100120struct msgb *mgcp_create_response_with_data(int code, const char *msg, const char *trans, const char *data);
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +0100121
Holger Hans Peter Freyther616d2222010-03-31 09:27:04 +0200122/* adc helper */
123static inline int mgcp_timeslot_to_endpoint(int multiplex, int timeslot)
124{
125 if (timeslot == 0)
126 timeslot = 1;
127 return timeslot + (31 * multiplex);
128}
129
Holger Hans Peter Freyther62e836c2010-02-03 11:03:45 +0100130
131#endif