blob: e8d4bb02d43cda42799daac11dfe9753e00a3e7c [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 Freyther314584a2010-08-05 04:10:21 +080032#define RTP_PORT_NET_DEFAULT 16000
Holger Hans Peter Freytherf67945f2009-10-09 07:08:11 +020033
34/**
35 * Calculate the RTP audio port for the given multiplex
36 * and the direction. This allows a semi static endpoint
37 * to port calculation removing the need for the BSC
38 * and the MediaGateway to communicate.
39 *
40 * Port usage explained:
41 * base + (multiplex * 2) + 0 == local port to wait for network packets
42 * base + (multiplex * 2) + 1 == local port for rtcp
43 *
44 * The above port will receive packets from the BTS that need
45 * to be patched and forwarded to the network.
46 * The above port will receive packets from the network that
47 * need to be patched and forwarded to the BTS.
48 *
49 * We assume to have a static BTS IP address so we can differentiate
50 * network and BTS.
51 *
52 */
Holger Hans Peter Freythere0955022010-02-03 08:50:33 +010053static inline int rtp_calculate_port(int multiplex, int base)
Holger Hans Peter Freytherf67945f2009-10-09 07:08:11 +020054{
55 return base + (multiplex * 2);
56}
Holger Hans Peter Freythere0955022010-02-03 08:50:33 +010057
Holger Hans Peter Freyther62e836c2010-02-03 11:03:45 +010058
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +010059/*
60 * Handling of MGCP Endpoints and the MGCP Config
61 */
62struct mgcp_endpoint;
63struct mgcp_config;
Holger Hans Peter Freyther77f7afe2010-02-03 09:54:43 +010064
Holger Hans Peter Freyther77f7afe2010-02-03 09:54:43 +010065#define MGCP_ENDP_CRCX 1
66#define MGCP_ENDP_DLCX 2
67#define MGCP_ENDP_MDCX 3
68
Holger Hans Peter Freytherfe86d3c2010-02-26 13:37:05 +010069/*
70 * what to do with the msg?
71 * - continue as usual?
72 * - reject and send a failure code?
73 * - defer? do not send anything
74 */
75#define MGCP_POLICY_CONT 4
76#define MGCP_POLICY_REJECT 5
77#define MGCP_POLICY_DEFER 6
78
Holger Hans Peter Freyther58ff2192010-08-05 03:08:35 +080079typedef int (*mgcp_change)(struct mgcp_config *cfg, int endpoint, int state);
Holger Hans Peter Freytherfe86d3c2010-02-26 13:37:05 +010080typedef int (*mgcp_policy)(struct mgcp_config *cfg, int endpoint, int state, const char *transactio_id);
Holger Hans Peter Freyther9bdcc9c2010-03-31 06:39:35 +020081typedef int (*mgcp_reset)(struct mgcp_config *cfg);
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +010082
Holger Hans Peter Freyther15e73892010-08-05 07:10:56 +080083#define PORT_ALLOC_STATIC 0
84#define PORT_ALLOC_DYNAMIC 1
85
86/**
87 * This holds information on how to allocate ports
88 */
89struct mgcp_port_range {
90 int mode;
91
92 /* pre-allocated from a base? */
93 int base_port;
94};
95
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +010096struct mgcp_config {
97 int source_port;
98 char *local_ip;
99 char *source_addr;
100 unsigned int number_endpoints;
101 char *bts_ip;
Holger Hans Peter Freytherb79994c2010-03-31 11:46:41 +0200102 char *call_agent_addr;
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +0100103
104 struct in_addr bts_in;
105 char *audio_name;
106 int audio_payload;
107 int audio_loop;
Holger Hans Peter Freyther15e73892010-08-05 07:10:56 +0800108
109 struct mgcp_port_range bts_ports;
110 struct mgcp_port_range net_ports;
Holger Hans Peter Freytherd0c32292010-07-27 20:34:45 +0800111 int endp_dscp;
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +0100112
Holger Hans Peter Freyther408cc4a2010-04-07 10:51:27 +0200113 /* spec handling */
114 int force_realloc;
115
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +0100116 mgcp_change change_cb;
Holger Hans Peter Freytherfe86d3c2010-02-26 13:37:05 +0100117 mgcp_policy policy_cb;
Holger Hans Peter Freyther9bdcc9c2010-03-31 06:39:35 +0200118 mgcp_reset reset_cb;
Holger Hans Peter Freytherfe86d3c2010-02-26 13:37:05 +0100119 void *data;
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +0100120
121 struct mgcp_endpoint *endpoints;
122 unsigned int last_call_id;
123};
124
125/* config management */
126struct mgcp_config *mgcp_config_alloc(void);
127int mgcp_parse_config(const char *config_file, struct mgcp_config *cfg);
128int mgcp_vty_init(void);
129int mgcp_endpoints_allocate(struct mgcp_config *cfg);
Holger Hans Peter Freyther154b9552010-02-26 13:27:51 +0100130void mgcp_free_endp(struct mgcp_endpoint *endp);
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +0100131
132/*
133 * format helper functions
134 */
135struct msgb *mgcp_handle_message(struct mgcp_config *cfg, struct msgb *msg);
Holger Hans Peter Freyther6414a0c2010-02-21 10:50:46 +0100136struct 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 +0100137
Holger Hans Peter Freyther616d2222010-03-31 09:27:04 +0200138/* adc helper */
139static inline int mgcp_timeslot_to_endpoint(int multiplex, int timeslot)
140{
141 if (timeslot == 0)
142 timeslot = 1;
143 return timeslot + (31 * multiplex);
144}
145
Holger Hans Peter Freyther62e836c2010-02-03 11:03:45 +0100146
147#endif