2009-10-09 05:08:11 +00:00
|
|
|
/* A Media Gateway Control Protocol Media Gateway: RFC 3435 */
|
|
|
|
|
|
|
|
/*
|
2012-11-29 11:54:22 +00:00
|
|
|
* (C) 2009-2012 by Holger Hans Peter Freyther <zecke@selfish.org>
|
|
|
|
* (C) 2009-2012 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
|
2011-01-01 14:25:50 +00:00
|
|
|
* it under the terms of the GNU Affero General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2009-10-09 05:08:11 +00:00
|
|
|
* (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
|
2011-01-01 14:25:50 +00:00
|
|
|
* GNU Affero General Public License for more details.
|
2009-10-09 05:08:11 +00:00
|
|
|
*
|
2011-01-01 14:25:50 +00:00
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2009-10-09 05:08:11 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2010-02-03 10:03:45 +00:00
|
|
|
#ifndef OPENBSC_MGCP_H
|
|
|
|
#define OPENBSC_MGCP_H
|
|
|
|
|
2011-03-22 15:47:59 +00:00
|
|
|
#include <osmocom/core/msgb.h>
|
|
|
|
#include <osmocom/core/write_queue.h>
|
2010-02-03 10:03:45 +00:00
|
|
|
|
2010-09-19 17:07:23 +00:00
|
|
|
#include "debug.h"
|
|
|
|
|
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;
|
2011-02-27 23:56:17 +00:00
|
|
|
struct mgcp_trunk_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
|
|
|
|
|
2011-02-27 23:56:17 +00:00
|
|
|
typedef int (*mgcp_realloc)(struct mgcp_trunk_config *cfg, int endpoint);
|
|
|
|
typedef int (*mgcp_change)(struct mgcp_trunk_config *cfg, int endpoint, int state);
|
|
|
|
typedef int (*mgcp_policy)(struct mgcp_trunk_config *cfg, int endpoint, int state, const char *transactio_id);
|
2011-06-09 22:04:55 +00:00
|
|
|
typedef int (*mgcp_reset)(struct mgcp_trunk_config *cfg);
|
2012-12-07 14:04:07 +00:00
|
|
|
typedef int (*mgcp_rqnt)(struct mgcp_endpoint *endp, char tone);
|
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-08-04 23:20:09 +00:00
|
|
|
|
|
|
|
/* dynamically allocated */
|
|
|
|
int range_start;
|
|
|
|
int range_end;
|
|
|
|
int last_port;
|
2010-08-04 23:10:56 +00:00
|
|
|
};
|
|
|
|
|
2011-02-27 23:56:17 +00:00
|
|
|
struct mgcp_trunk_config {
|
2011-02-28 11:11:02 +00:00
|
|
|
struct llist_head entry;
|
|
|
|
|
2011-02-27 23:56:17 +00:00
|
|
|
struct mgcp_config *cfg;
|
|
|
|
|
|
|
|
int trunk_nr;
|
|
|
|
int trunk_type;
|
|
|
|
|
2012-09-02 22:07:39 +00:00
|
|
|
char *audio_fmtp_extra;
|
2011-02-27 23:56:17 +00:00
|
|
|
char *audio_name;
|
|
|
|
int audio_payload;
|
|
|
|
int audio_loop;
|
|
|
|
|
2012-05-11 11:00:45 +00:00
|
|
|
int omit_rtcp;
|
|
|
|
|
2011-02-27 23:56:17 +00:00
|
|
|
/* spec handling */
|
|
|
|
int force_realloc;
|
|
|
|
|
|
|
|
unsigned int number_endpoints;
|
|
|
|
struct mgcp_endpoint *endpoints;
|
|
|
|
};
|
|
|
|
|
2010-02-20 20:21:02 +00:00
|
|
|
struct mgcp_config {
|
|
|
|
int source_port;
|
|
|
|
char *local_ip;
|
|
|
|
char *source_addr;
|
|
|
|
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;
|
2010-08-04 23:10:56 +00:00
|
|
|
|
2010-09-18 20:21:39 +00:00
|
|
|
/* transcoder handling */
|
|
|
|
char *transcoder_ip;
|
|
|
|
struct in_addr transcoder_in;
|
|
|
|
int transcoder_remote_base;
|
|
|
|
|
2011-05-06 10:09:47 +00:00
|
|
|
struct osmo_wqueue gw_fd;
|
2010-09-18 12:40:22 +00:00
|
|
|
|
2010-08-04 23:10:56 +00:00
|
|
|
struct mgcp_port_range bts_ports;
|
|
|
|
struct mgcp_port_range net_ports;
|
2010-09-17 15:35:53 +00:00
|
|
|
struct mgcp_port_range transcoder_ports;
|
2010-07-27 12:34:45 +00:00
|
|
|
int endp_dscp;
|
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-08-06 09:54:27 +00:00
|
|
|
mgcp_realloc realloc_cb;
|
2012-11-29 11:54:22 +00:00
|
|
|
mgcp_rqnt rqnt_cb;
|
2010-02-26 12:37:05 +00:00
|
|
|
void *data;
|
2010-02-20 20:21:02 +00:00
|
|
|
|
2010-08-06 00:26:54 +00:00
|
|
|
uint32_t last_call_id;
|
2011-02-27 23:56:17 +00:00
|
|
|
|
|
|
|
/* trunk handling */
|
|
|
|
struct mgcp_trunk_config trunk;
|
2011-02-28 11:11:02 +00:00
|
|
|
struct llist_head trunks;
|
2011-02-28 13:46:01 +00:00
|
|
|
|
|
|
|
/* only used for start with a static configuration */
|
|
|
|
int last_net_port;
|
|
|
|
int last_bts_port;
|
2010-02-20 20:21:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* 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);
|
2011-02-28 13:37:03 +00:00
|
|
|
int mgcp_endpoints_allocate(struct mgcp_trunk_config *cfg);
|
2010-02-26 12:27:51 +00:00
|
|
|
void mgcp_free_endp(struct mgcp_endpoint *endp);
|
2010-09-18 20:36:07 +00:00
|
|
|
int mgcp_reset_transcoder(struct mgcp_config *cfg);
|
2012-09-14 15:18:12 +00:00
|
|
|
void mgcp_format_stats(struct mgcp_endpoint *endp, char *stats, size_t size);
|
2012-10-24 19:53:40 +00:00
|
|
|
int mgcp_parse_stats(struct msgb *msg, uint32_t *ps, uint32_t *os, uint32_t *pr, uint32_t *_or, int *loss, uint32_t *jitter);
|
2010-02-20 20:21:02 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* format helper functions
|
|
|
|
*/
|
|
|
|
struct msgb *mgcp_handle_message(struct mgcp_config *cfg, struct msgb *msg);
|
|
|
|
|
2010-03-31 07:27:04 +00:00
|
|
|
/* adc helper */
|
|
|
|
static inline int mgcp_timeslot_to_endpoint(int multiplex, int timeslot)
|
|
|
|
{
|
2010-09-19 17:07:23 +00:00
|
|
|
if (timeslot == 0) {
|
|
|
|
LOGP(DMGCP, LOGL_ERROR, "Timeslot should not be 0\n");
|
|
|
|
timeslot = 255;
|
|
|
|
}
|
|
|
|
|
2010-08-10 12:24:24 +00:00
|
|
|
return timeslot + (32 * multiplex);
|
2010-03-31 07:27:04 +00:00
|
|
|
}
|
|
|
|
|
2010-08-28 09:59:15 +00:00
|
|
|
static inline void mgcp_endpoint_to_timeslot(int endpoint, int *multiplex, int *timeslot)
|
|
|
|
{
|
|
|
|
*multiplex = endpoint / 32;
|
|
|
|
*timeslot = endpoint % 32;
|
|
|
|
}
|
|
|
|
|
2012-01-26 23:46:49 +00:00
|
|
|
int mgcp_send_reset_ep(struct mgcp_endpoint *endp, int endpoint);
|
|
|
|
int mgcp_send_reset_all(struct mgcp_config *cfg);
|
|
|
|
|
2010-02-03 10:03:45 +00:00
|
|
|
|
|
|
|
#endif
|