blob: 914571a40dd753326234caf7625ab65fef889675 [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
27#include <laf0rge1/msgb.h>
28
29#include <arpa/inet.h>
30
31#define RTP_PORT_DEFAULT 4000
32/**
33 * Calculate the RTP audio port for the given multiplex
34 * and the direction. This allows a semi static endpoint
35 * to port calculation removing the need for the BSC
36 * and the MediaGateway to communicate.
37 *
38 * Port usage explained:
39 * base + (multiplex * 2) + 0 == local port to wait for network packets
40 * base + (multiplex * 2) + 1 == local port for rtcp
41 *
42 * The above port will receive packets from the BTS that need
43 * to be patched and forwarded to the network.
44 * The above port will receive packets from the network that
45 * need to be patched and forwarded to the BTS.
46 *
47 * We assume to have a static BTS IP address so we can differentiate
48 * network and BTS.
49 *
50 */
51static inline int rtp_calculate_port(int multiplex, int base)
52{
53 return base + (multiplex * 2);
54}
55
56
57/*
58 * Handling of MGCP Endpoints and the MGCP Config
59 */
60struct mgcp_endpoint;
61struct mgcp_config;
62
63#define MGCP_ENDP_CRCX 1
64#define MGCP_ENDP_DLCX 2
65#define MGCP_ENDP_MDCX 3
66
67/*
68 * what to do with the msg?
69 * - continue as usual?
70 * - reject and send a failure code?
71 * - defer? do not send anything
72 */
73#define MGCP_POLICY_CONT 4
74#define MGCP_POLICY_REJECT 5
75#define MGCP_POLICY_DEFER 6
76
77typedef int (*mgcp_change)(struct mgcp_config *cfg, int endpoint, int state, int local_rtp);
78typedef int (*mgcp_policy)(struct mgcp_config *cfg, int endpoint, int state, const char *transactio_id);
79typedef int (*mgcp_reset)(struct mgcp_config *cfg);
80
81struct mgcp_config {
82 /* common configuration */
83 int source_port;
84 char *local_ip;
85 char *source_addr;
86 char *bts_ip;
87 char *call_agent_addr;
88
89 /* default endpoint data */
90 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
98 /* only used in forward mode */
99 char *forward_ip;
100 int forward_port;
101
102 unsigned int last_call_id;
103
104 /* endpoint configuration */
105 unsigned int number_endpoints;
106 struct mgcp_endpoint *endpoints;
107
108 /* spec handling */
109 int force_realloc;
110
111 /* callback functionality */
112 mgcp_change change_cb;
113 mgcp_policy policy_cb;
114 mgcp_reset reset_cb;
115 void *data;
116};
117
118/* config management */
119struct mgcp_config *mgcp_config_alloc(void);
120int mgcp_parse_config(const char *config_file, struct mgcp_config *cfg);
121int mgcp_vty_init(void);
122int mgcp_endpoints_allocate(struct mgcp_config *cfg);
123int mgcp_bind_rtp_port(struct mgcp_endpoint *endp, int rtp_port);
124void mgcp_free_endp(struct mgcp_endpoint *endp);
125
126/*
127 * format helper functions
128 */
129struct msgb *mgcp_handle_message(struct mgcp_config *cfg, struct msgb *msg);
130struct msgb *mgcp_create_response_with_data(int code, const char *msg, const char *trans, const char *data);
131
132/* adc helper */
133static inline int mgcp_timeslot_to_endpoint(int multiplex, int timeslot)
134{
135 if (timeslot == 0)
136 timeslot = 1;
137 return timeslot + (31 * multiplex);
138}
139
140
141#endif