blob: 52ffefd27ee3661d00823ffbe67ad329f38e1c34 [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
Holger Hans Peter Freythered999b22011-07-21 10:24:46 +020035#define RTP_PT_AMR 98
Andreas Eversberg88012b62014-01-22 10:05:51 +010036#define RTP_LEN_GSM_FULL 33
37#define RTP_LEN_GSM_HALF 15
38#define RTP_LEN_GSM_EFR 31
39#define RTP_GSM_DURATION 160
Sylvain Munautb54dda42009-12-20 22:06:40 +010040
Harald Welteead7a7b2009-07-28 00:01:58 +020041enum rtp_rx_action {
42 RTP_NONE,
43 RTP_PROXY,
44 RTP_RECV_UPSTREAM,
45};
46
Harald Welteda7ab742009-12-19 22:23:05 +010047enum rtp_tx_action {
48 RTP_SEND_NONE,
49 RTP_SEND_DOWNSTREAM,
50};
51
Harald Welteead7a7b2009-07-28 00:01:58 +020052struct rtp_sub_socket {
53 struct sockaddr_in sin_local;
54 struct sockaddr_in sin_remote;
55
Pablo Neira Ayuso4db92992011-05-06 12:11:23 +020056 struct osmo_fd bfd;
Harald Welteead7a7b2009-07-28 00:01:58 +020057 /* linked list of to-be-transmitted msgb's */
58 struct llist_head tx_queue;
59};
60
61struct rtp_socket {
62 struct llist_head list;
63
64 struct rtp_sub_socket rtp;
65 struct rtp_sub_socket rtcp;
66
67 /* what should we do on receive? */
68 enum rtp_rx_action rx_action;
69 union {
70 struct {
71 struct rtp_socket *other_sock;
72 } proxy;
73 struct {
Harald Welteda7ab742009-12-19 22:23:05 +010074 struct gsm_network *net;
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +020075 uint32_t callref;
Harald Welteead7a7b2009-07-28 00:01:58 +020076 } receive;
77 };
Harald Welteda7ab742009-12-19 22:23:05 +010078 enum rtp_tx_action tx_action;
79 struct {
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +020080 uint16_t sequence;
81 uint32_t timestamp;
82 uint32_t ssrc;
Harald Welte392736d2009-12-20 13:16:14 +010083 struct timeval last_tv;
Harald Welteda7ab742009-12-19 22:23:05 +010084 } transmit;
Harald Welteead7a7b2009-07-28 00:01:58 +020085};
86
87struct rtp_socket *rtp_socket_create(void);
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +020088int rtp_socket_bind(struct rtp_socket *rs, uint32_t ip);
89int rtp_socket_connect(struct rtp_socket *rs, uint32_t ip, uint16_t port);
Harald Welteead7a7b2009-07-28 00:01:58 +020090int rtp_socket_proxy(struct rtp_socket *this, struct rtp_socket *other);
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +020091int rtp_socket_upstream(struct rtp_socket *this, struct gsm_network *net, uint32_t callref);
Harald Welteead7a7b2009-07-28 00:01:58 +020092int rtp_socket_free(struct rtp_socket *rs);
Harald Welteda7ab742009-12-19 22:23:05 +010093int rtp_send_frame(struct rtp_socket *rs, struct gsm_data_frame *frame);
Harald Welteead7a7b2009-07-28 00:01:58 +020094
95#endif /* _RTP_PROXY_H */