Harald Welte | ead7a7b | 2009-07-28 00:01:58 +0200 | [diff] [blame] | 1 | #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 Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 10 | * 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 Welte | ead7a7b | 2009-07-28 00:01:58 +0200 | [diff] [blame] | 12 | * (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 Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 17 | * GNU Affero General Public License for more details. |
Harald Welte | ead7a7b | 2009-07-28 00:01:58 +0200 | [diff] [blame] | 18 | * |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 19 | * 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 Welte | ead7a7b | 2009-07-28 00:01:58 +0200 | [diff] [blame] | 21 | * |
| 22 | */ |
| 23 | |
| 24 | |
| 25 | #include <netinet/in.h> |
| 26 | |
Pablo Neira Ayuso | 136f453 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 27 | #include <osmocom/core/linuxlist.h> |
| 28 | #include <osmocom/core/select.h> |
Harald Welte | ead7a7b | 2009-07-28 00:01:58 +0200 | [diff] [blame] | 29 | |
Sylvain Munaut | b54dda4 | 2009-12-20 22:06:40 +0100 | [diff] [blame] | 30 | #define RTP_PT_GSM_FULL 3 |
| 31 | #define RTP_PT_GSM_HALF 96 |
| 32 | #define RTP_PT_GSM_EFR 97 |
| 33 | #define RTP_PT_AMR_FULL 98 |
| 34 | #define RTP_PT_AMR_HALF 99 |
| 35 | |
Harald Welte | ead7a7b | 2009-07-28 00:01:58 +0200 | [diff] [blame] | 36 | enum rtp_rx_action { |
| 37 | RTP_NONE, |
| 38 | RTP_PROXY, |
| 39 | RTP_RECV_UPSTREAM, |
| 40 | }; |
| 41 | |
Harald Welte | da7ab74 | 2009-12-19 22:23:05 +0100 | [diff] [blame] | 42 | enum rtp_tx_action { |
| 43 | RTP_SEND_NONE, |
| 44 | RTP_SEND_DOWNSTREAM, |
| 45 | }; |
| 46 | |
Harald Welte | ead7a7b | 2009-07-28 00:01:58 +0200 | [diff] [blame] | 47 | struct rtp_sub_socket { |
| 48 | struct sockaddr_in sin_local; |
| 49 | struct sockaddr_in sin_remote; |
| 50 | |
Pablo Neira Ayuso | 4db9299 | 2011-05-06 12:11:23 +0200 | [diff] [blame^] | 51 | struct osmo_fd bfd; |
Harald Welte | ead7a7b | 2009-07-28 00:01:58 +0200 | [diff] [blame] | 52 | /* linked list of to-be-transmitted msgb's */ |
| 53 | struct llist_head tx_queue; |
| 54 | }; |
| 55 | |
| 56 | struct rtp_socket { |
| 57 | struct llist_head list; |
| 58 | |
| 59 | struct rtp_sub_socket rtp; |
| 60 | struct rtp_sub_socket rtcp; |
| 61 | |
| 62 | /* what should we do on receive? */ |
| 63 | enum rtp_rx_action rx_action; |
| 64 | union { |
| 65 | struct { |
| 66 | struct rtp_socket *other_sock; |
| 67 | } proxy; |
| 68 | struct { |
Harald Welte | da7ab74 | 2009-12-19 22:23:05 +0100 | [diff] [blame] | 69 | struct gsm_network *net; |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 70 | uint32_t callref; |
Harald Welte | ead7a7b | 2009-07-28 00:01:58 +0200 | [diff] [blame] | 71 | } receive; |
| 72 | }; |
Harald Welte | da7ab74 | 2009-12-19 22:23:05 +0100 | [diff] [blame] | 73 | enum rtp_tx_action tx_action; |
| 74 | struct { |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 75 | uint16_t sequence; |
| 76 | uint32_t timestamp; |
| 77 | uint32_t ssrc; |
Harald Welte | 392736d | 2009-12-20 13:16:14 +0100 | [diff] [blame] | 78 | struct timeval last_tv; |
Harald Welte | da7ab74 | 2009-12-19 22:23:05 +0100 | [diff] [blame] | 79 | } transmit; |
Harald Welte | ead7a7b | 2009-07-28 00:01:58 +0200 | [diff] [blame] | 80 | }; |
| 81 | |
| 82 | struct rtp_socket *rtp_socket_create(void); |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 83 | int rtp_socket_bind(struct rtp_socket *rs, uint32_t ip); |
| 84 | int rtp_socket_connect(struct rtp_socket *rs, uint32_t ip, uint16_t port); |
Harald Welte | ead7a7b | 2009-07-28 00:01:58 +0200 | [diff] [blame] | 85 | int rtp_socket_proxy(struct rtp_socket *this, struct rtp_socket *other); |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 86 | int rtp_socket_upstream(struct rtp_socket *this, struct gsm_network *net, uint32_t callref); |
Harald Welte | ead7a7b | 2009-07-28 00:01:58 +0200 | [diff] [blame] | 87 | int rtp_socket_free(struct rtp_socket *rs); |
Harald Welte | da7ab74 | 2009-12-19 22:23:05 +0100 | [diff] [blame] | 88 | int rtp_send_frame(struct rtp_socket *rs, struct gsm_data_frame *frame); |
Harald Welte | ead7a7b | 2009-07-28 00:01:58 +0200 | [diff] [blame] | 89 | |
| 90 | #endif /* _RTP_PROXY_H */ |