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 | |
Neels Hofmeyr | 9084396 | 2017-09-04 15:04:35 +0200 | [diff] [blame] | 30 | #include <osmocom/msc/mncc.h> |
Harald Welte | f142c97 | 2011-05-24 13:25:38 +0200 | [diff] [blame] | 31 | |
Sylvain Munaut | b54dda4 | 2009-12-20 22:06:40 +0100 | [diff] [blame] | 32 | #define RTP_PT_GSM_FULL 3 |
| 33 | #define RTP_PT_GSM_HALF 96 |
| 34 | #define RTP_PT_GSM_EFR 97 |
Holger Hans Peter Freyther | ed999b2 | 2011-07-21 10:24:46 +0200 | [diff] [blame] | 35 | #define RTP_PT_AMR 98 |
Andreas Eversberg | 88012b6 | 2014-01-22 10:05:51 +0100 | [diff] [blame] | 36 | #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 Munaut | b54dda4 | 2009-12-20 22:06:40 +0100 | [diff] [blame] | 40 | |
Harald Welte | ead7a7b | 2009-07-28 00:01:58 +0200 | [diff] [blame] | 41 | enum rtp_rx_action { |
| 42 | RTP_NONE, |
| 43 | RTP_PROXY, |
| 44 | RTP_RECV_UPSTREAM, |
| 45 | }; |
| 46 | |
Harald Welte | da7ab74 | 2009-12-19 22:23:05 +0100 | [diff] [blame] | 47 | enum rtp_tx_action { |
| 48 | RTP_SEND_NONE, |
| 49 | RTP_SEND_DOWNSTREAM, |
| 50 | }; |
| 51 | |
Harald Welte | ead7a7b | 2009-07-28 00:01:58 +0200 | [diff] [blame] | 52 | struct rtp_sub_socket { |
| 53 | struct sockaddr_in sin_local; |
| 54 | struct sockaddr_in sin_remote; |
| 55 | |
Pablo Neira Ayuso | 4db9299 | 2011-05-06 12:11:23 +0200 | [diff] [blame] | 56 | struct osmo_fd bfd; |
Harald Welte | ead7a7b | 2009-07-28 00:01:58 +0200 | [diff] [blame] | 57 | /* linked list of to-be-transmitted msgb's */ |
| 58 | struct llist_head tx_queue; |
| 59 | }; |
| 60 | |
| 61 | struct 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 Welte | da7ab74 | 2009-12-19 22:23:05 +0100 | [diff] [blame] | 74 | struct gsm_network *net; |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 75 | uint32_t callref; |
Harald Welte | ead7a7b | 2009-07-28 00:01:58 +0200 | [diff] [blame] | 76 | } receive; |
| 77 | }; |
Harald Welte | da7ab74 | 2009-12-19 22:23:05 +0100 | [diff] [blame] | 78 | enum rtp_tx_action tx_action; |
| 79 | struct { |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 80 | uint16_t sequence; |
| 81 | uint32_t timestamp; |
| 82 | uint32_t ssrc; |
Harald Welte | 392736d | 2009-12-20 13:16:14 +0100 | [diff] [blame] | 83 | struct timeval last_tv; |
Harald Welte | da7ab74 | 2009-12-19 22:23:05 +0100 | [diff] [blame] | 84 | } transmit; |
Harald Welte | ead7a7b | 2009-07-28 00:01:58 +0200 | [diff] [blame] | 85 | }; |
| 86 | |
| 87 | struct rtp_socket *rtp_socket_create(void); |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 88 | int rtp_socket_bind(struct rtp_socket *rs, uint32_t ip); |
| 89 | 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] | 90 | 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] | 91 | 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] | 92 | int rtp_socket_free(struct rtp_socket *rs); |
Harald Welte | da7ab74 | 2009-12-19 22:23:05 +0100 | [diff] [blame] | 93 | 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] | 94 | |
| 95 | #endif /* _RTP_PROXY_H */ |