blob: 5baf0ca1d22a9c467d6fb6160a85f1c83fa349b4 [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
27#include "msgb.h"
28
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 Freyther7bdc6372010-02-20 21:21:02 +010068typedef int (*mgcp_change)(struct mgcp_config *cfg, int endpoint, int state, int local_rtp);
69
70struct mgcp_config {
71 int source_port;
72 char *local_ip;
73 char *source_addr;
74 unsigned int number_endpoints;
75 char *bts_ip;
76
77 struct in_addr bts_in;
78 char *audio_name;
79 int audio_payload;
80 int audio_loop;
81 int early_bind;
82 int rtp_base_port;
83
84 char *forward_ip;
85 int forward_port;
86
87 mgcp_change change_cb;
88
89 struct mgcp_endpoint *endpoints;
90 unsigned int last_call_id;
91};
92
93/* config management */
94struct mgcp_config *mgcp_config_alloc(void);
95int mgcp_parse_config(const char *config_file, struct mgcp_config *cfg);
96int mgcp_vty_init(void);
97int mgcp_endpoints_allocate(struct mgcp_config *cfg);
98int mgcp_bind_rtp_port(struct mgcp_endpoint *endp, int rtp_port);
99
100/*
101 * format helper functions
102 */
103struct msgb *mgcp_handle_message(struct mgcp_config *cfg, struct msgb *msg);
104struct msgb *mgcp_create_rsip(void);
105
Holger Hans Peter Freyther62e836c2010-02-03 11:03:45 +0100106
107#endif