blob: 94d2579ff8d3707a2689d916a4468bd1e74c62d7 [file] [log] [blame]
Harald Welteead7a7b2009-07-28 00:01:58 +02001#ifndef _RTP_PROXY_H
2#define _RTP_PROXY_H
3
4/* RTP proxy handling for ip.access nanoBTS */
5
6/* (C) 2009 by Harald Welte <laforge@gnumonks.org>
7 * All Rights Reserved
8 *
9 * This program is free software; you can redistribute it and/or modify
Harald Welte9af6ddf2011-01-01 15:25:50 +010010 * it under the terms of the GNU Affero General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
Harald Welteead7a7b2009-07-28 00:01:58 +020012 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Harald Welte9af6ddf2011-01-01 15:25:50 +010017 * GNU Affero General Public License for more details.
Harald Welteead7a7b2009-07-28 00:01:58 +020018 *
Harald Welte9af6ddf2011-01-01 15:25:50 +010019 * You should have received a copy of the GNU Affero General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
Harald Welteead7a7b2009-07-28 00:01:58 +020021 *
22 */
23
24
25#include <netinet/in.h>
26
Pablo Neira Ayuso136f4532011-03-22 16:47:59 +010027#include <osmocom/core/linuxlist.h>
28#include <osmocom/core/select.h>
Harald Welteead7a7b2009-07-28 00:01:58 +020029
Harald Weltef142c972011-05-24 13:25:38 +020030#include <openbsc/mncc.h>
31
Sylvain Munautb54dda42009-12-20 22:06:40 +010032#define RTP_PT_GSM_FULL 3
33#define RTP_PT_GSM_HALF 96
34#define RTP_PT_GSM_EFR 97
35#define RTP_PT_AMR_FULL 98
36#define RTP_PT_AMR_HALF 99
37
Harald Welteead7a7b2009-07-28 00:01:58 +020038enum rtp_rx_action {
39 RTP_NONE,
40 RTP_PROXY,
41 RTP_RECV_UPSTREAM,
42};
43
Harald Welteda7ab742009-12-19 22:23:05 +010044enum rtp_tx_action {
45 RTP_SEND_NONE,
46 RTP_SEND_DOWNSTREAM,
47};
48
Harald Welteead7a7b2009-07-28 00:01:58 +020049struct rtp_sub_socket {
50 struct sockaddr_in sin_local;
51 struct sockaddr_in sin_remote;
52
Pablo Neira Ayuso4db92992011-05-06 12:11:23 +020053 struct osmo_fd bfd;
Harald Welteead7a7b2009-07-28 00:01:58 +020054 /* linked list of to-be-transmitted msgb's */
55 struct llist_head tx_queue;
56};
57
58struct rtp_socket {
59 struct llist_head list;
60
61 struct rtp_sub_socket rtp;
62 struct rtp_sub_socket rtcp;
63
64 /* what should we do on receive? */
65 enum rtp_rx_action rx_action;
66 union {
67 struct {
68 struct rtp_socket *other_sock;
69 } proxy;
70 struct {
Harald Welteda7ab742009-12-19 22:23:05 +010071 struct gsm_network *net;
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +020072 uint32_t callref;
Harald Welteead7a7b2009-07-28 00:01:58 +020073 } receive;
74 };
Harald Welteda7ab742009-12-19 22:23:05 +010075 enum rtp_tx_action tx_action;
76 struct {
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +020077 uint16_t sequence;
78 uint32_t timestamp;
79 uint32_t ssrc;
Harald Welte392736d2009-12-20 13:16:14 +010080 struct timeval last_tv;
Harald Welteda7ab742009-12-19 22:23:05 +010081 } transmit;
Harald Welteead7a7b2009-07-28 00:01:58 +020082};
83
84struct rtp_socket *rtp_socket_create(void);
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +020085int rtp_socket_bind(struct rtp_socket *rs, uint32_t ip);
86int rtp_socket_connect(struct rtp_socket *rs, uint32_t ip, uint16_t port);
Harald Welteead7a7b2009-07-28 00:01:58 +020087int rtp_socket_proxy(struct rtp_socket *this, struct rtp_socket *other);
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +020088int rtp_socket_upstream(struct rtp_socket *this, struct gsm_network *net, uint32_t callref);
Harald Welteead7a7b2009-07-28 00:01:58 +020089int rtp_socket_free(struct rtp_socket *rs);
Harald Welteda7ab742009-12-19 22:23:05 +010090int rtp_send_frame(struct rtp_socket *rs, struct gsm_data_frame *frame);
Harald Welteead7a7b2009-07-28 00:01:58 +020091
92#endif /* _RTP_PROXY_H */