2009-10-09 05:08:11 +00:00
|
|
|
/* A Media Gateway Control Protocol Media Gateway: RFC 3435 */
|
|
|
|
|
|
|
|
/*
|
2010-02-20 20:21:02 +00:00
|
|
|
* (C) 2009-2010 by Holger Hans Peter Freyther <zecke@selfish.org>
|
|
|
|
* (C) 2009-2010 by On-Waves
|
2009-10-09 05:08:11 +00:00
|
|
|
* All Rights Reserved
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2010-02-03 10:03:45 +00:00
|
|
|
#ifndef OPENBSC_MGCP_H
|
|
|
|
#define OPENBSC_MGCP_H
|
|
|
|
|
split 'libosmocore' from openbsc codebase
This library is intended to collect all generic/common funcitionality
of all Osmocom.org projects, including OpenBSC but also OsmocomBB
The library currently includes the following modules:
bitvec, comp128, gsm_utils, msgb, select, signal, statistics, talloc, timer,
tlv_parse, linuxlist
msgb allocation error debugging had to be temporarily disabled as it depends on
'debug.c' functionality which at the moment remains in OpenBSC
2010-02-20 15:24:02 +00:00
|
|
|
#include <osmocore/msgb.h>
|
2010-02-03 10:03:45 +00:00
|
|
|
|
2010-02-20 20:21:02 +00:00
|
|
|
#include <arpa/inet.h>
|
|
|
|
|
2010-02-03 07:50:33 +00:00
|
|
|
#define RTP_PORT_DEFAULT 4000
|
2010-08-04 20:10:21 +00:00
|
|
|
#define RTP_PORT_NET_DEFAULT 16000
|
2009-10-09 05:08:11 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Calculate the RTP audio port for the given multiplex
|
|
|
|
* and the direction. This allows a semi static endpoint
|
|
|
|
* to port calculation removing the need for the BSC
|
|
|
|
* and the MediaGateway to communicate.
|
|
|
|
*
|
|
|
|
* Port usage explained:
|
|
|
|
* base + (multiplex * 2) + 0 == local port to wait for network packets
|
|
|
|
* base + (multiplex * 2) + 1 == local port for rtcp
|
|
|
|
*
|
|
|
|
* The above port will receive packets from the BTS that need
|
|
|
|
* to be patched and forwarded to the network.
|
|
|
|
* The above port will receive packets from the network that
|
|
|
|
* need to be patched and forwarded to the BTS.
|
|
|
|
*
|
|
|
|
* We assume to have a static BTS IP address so we can differentiate
|
|
|
|
* network and BTS.
|
|
|
|
*
|
|
|
|
*/
|
2010-02-03 07:50:33 +00:00
|
|
|
static inline int rtp_calculate_port(int multiplex, int base)
|
2009-10-09 05:08:11 +00:00
|
|
|
{
|
|
|
|
return base + (multiplex * 2);
|
|
|
|
}
|
2010-02-03 07:50:33 +00:00
|
|
|
|
2010-02-03 10:03:45 +00:00
|
|
|
|
2010-02-20 20:21:02 +00:00
|
|
|
/*
|
|
|
|
* Handling of MGCP Endpoints and the MGCP Config
|
|
|
|
*/
|
|
|
|
struct mgcp_endpoint;
|
|
|
|
struct mgcp_config;
|
2010-02-03 08:54:43 +00:00
|
|
|
|
|
|
|
#define MGCP_ENDP_CRCX 1
|
|
|
|
#define MGCP_ENDP_DLCX 2
|
|
|
|
#define MGCP_ENDP_MDCX 3
|
|
|
|
|
2010-02-26 12:37:05 +00:00
|
|
|
/*
|
|
|
|
* what to do with the msg?
|
|
|
|
* - continue as usual?
|
|
|
|
* - reject and send a failure code?
|
|
|
|
* - defer? do not send anything
|
|
|
|
*/
|
|
|
|
#define MGCP_POLICY_CONT 4
|
|
|
|
#define MGCP_POLICY_REJECT 5
|
|
|
|
#define MGCP_POLICY_DEFER 6
|
|
|
|
|
2010-08-04 19:08:35 +00:00
|
|
|
typedef int (*mgcp_change)(struct mgcp_config *cfg, int endpoint, int state);
|
2010-02-26 12:37:05 +00:00
|
|
|
typedef int (*mgcp_policy)(struct mgcp_config *cfg, int endpoint, int state, const char *transactio_id);
|
2010-03-31 04:39:35 +00:00
|
|
|
typedef int (*mgcp_reset)(struct mgcp_config *cfg);
|
2010-02-20 20:21:02 +00:00
|
|
|
|
2010-08-04 23:10:56 +00:00
|
|
|
#define PORT_ALLOC_STATIC 0
|
|
|
|
#define PORT_ALLOC_DYNAMIC 1
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This holds information on how to allocate ports
|
|
|
|
*/
|
|
|
|
struct mgcp_port_range {
|
|
|
|
int mode;
|
|
|
|
|
|
|
|
/* pre-allocated from a base? */
|
|
|
|
int base_port;
|
|
|
|
};
|
|
|
|
|
2010-02-20 20:21:02 +00:00
|
|
|
struct mgcp_config {
|
|
|
|
int source_port;
|
|
|
|
char *local_ip;
|
|
|
|
char *source_addr;
|
|
|
|
unsigned int number_endpoints;
|
|
|
|
char *bts_ip;
|
2010-03-31 09:46:41 +00:00
|
|
|
char *call_agent_addr;
|
2010-02-20 20:21:02 +00:00
|
|
|
|
|
|
|
struct in_addr bts_in;
|
|
|
|
char *audio_name;
|
|
|
|
int audio_payload;
|
|
|
|
int audio_loop;
|
2010-08-04 23:10:56 +00:00
|
|
|
|
|
|
|
struct mgcp_port_range bts_ports;
|
|
|
|
struct mgcp_port_range net_ports;
|
2010-07-27 12:34:45 +00:00
|
|
|
int endp_dscp;
|
2010-02-20 20:21:02 +00:00
|
|
|
|
2010-04-07 08:51:27 +00:00
|
|
|
/* spec handling */
|
|
|
|
int force_realloc;
|
|
|
|
|
2010-02-20 20:21:02 +00:00
|
|
|
mgcp_change change_cb;
|
2010-02-26 12:37:05 +00:00
|
|
|
mgcp_policy policy_cb;
|
2010-03-31 04:39:35 +00:00
|
|
|
mgcp_reset reset_cb;
|
2010-02-26 12:37:05 +00:00
|
|
|
void *data;
|
2010-02-20 20:21:02 +00:00
|
|
|
|
|
|
|
struct mgcp_endpoint *endpoints;
|
|
|
|
unsigned int last_call_id;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* config management */
|
|
|
|
struct mgcp_config *mgcp_config_alloc(void);
|
|
|
|
int mgcp_parse_config(const char *config_file, struct mgcp_config *cfg);
|
|
|
|
int mgcp_vty_init(void);
|
|
|
|
int mgcp_endpoints_allocate(struct mgcp_config *cfg);
|
2010-02-26 12:27:51 +00:00
|
|
|
void mgcp_free_endp(struct mgcp_endpoint *endp);
|
2010-02-20 20:21:02 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* format helper functions
|
|
|
|
*/
|
|
|
|
struct msgb *mgcp_handle_message(struct mgcp_config *cfg, struct msgb *msg);
|
2010-02-21 09:50:46 +00:00
|
|
|
struct msgb *mgcp_create_response_with_data(int code, const char *msg, const char *trans, const char *data);
|
2010-02-20 20:21:02 +00:00
|
|
|
|
2010-03-31 07:27:04 +00:00
|
|
|
/* adc helper */
|
|
|
|
static inline int mgcp_timeslot_to_endpoint(int multiplex, int timeslot)
|
|
|
|
{
|
|
|
|
if (timeslot == 0)
|
|
|
|
timeslot = 1;
|
|
|
|
return timeslot + (31 * multiplex);
|
|
|
|
}
|
|
|
|
|
2010-02-03 10:03:45 +00:00
|
|
|
|
|
|
|
#endif
|