Jonathan Santos | 03fd8d0 | 2011-05-25 13:54:02 -0400 | [diff] [blame^] | 1 | /* MGCP Private Data */ |
| 2 | |
| 3 | /* |
| 4 | * (C) 2009-2011 by Holger Hans Peter Freyther <zecke@selfish.org> |
| 5 | * (C) 2009-2011 by On-Waves |
| 6 | * All Rights Reserved |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU Affero General Public License as published by |
| 10 | * the Free Software Foundation; either version 3 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU Affero General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU Affero General Public License |
| 19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 20 | * |
| 21 | */ |
| 22 | |
| 23 | #ifndef OPENBSC_MGCP_DATA_H |
| 24 | #define OPENBSC_MGCP_DATA_H |
| 25 | |
| 26 | #include <osmocore/select.h> |
| 27 | |
| 28 | #define CI_UNUSED 0 |
| 29 | |
| 30 | enum mgcp_connection_mode { |
| 31 | MGCP_CONN_NONE = 0, |
| 32 | MGCP_CONN_RECV_ONLY = 1, |
| 33 | MGCP_CONN_SEND_ONLY = 2, |
| 34 | MGCP_CONN_RECV_SEND = MGCP_CONN_RECV_ONLY | MGCP_CONN_SEND_ONLY, |
| 35 | MGCP_CONN_LOOPBACK = 4, |
| 36 | }; |
| 37 | |
| 38 | enum mgcp_trunk_type { |
| 39 | MGCP_TRUNK_VIRTUAL, |
| 40 | MGCP_TRUNK_E1, |
| 41 | }; |
| 42 | |
| 43 | struct mgcp_rtp_state { |
| 44 | int initialized; |
| 45 | int patch; |
| 46 | |
| 47 | uint32_t orig_ssrc; |
| 48 | uint32_t ssrc; |
| 49 | uint16_t seq_no; |
| 50 | int lost_no; |
| 51 | int seq_offset; |
| 52 | uint32_t last_timestamp; |
| 53 | int32_t timestamp_offset; |
| 54 | }; |
| 55 | |
| 56 | struct mgcp_rtp_end { |
| 57 | /* statistics */ |
| 58 | unsigned int packets; |
| 59 | struct in_addr addr; |
| 60 | |
| 61 | /* in network byte order */ |
| 62 | int rtp_port, rtcp_port; |
| 63 | |
| 64 | int payload_type; |
| 65 | |
| 66 | /* |
| 67 | * Each end has a socket... |
| 68 | */ |
| 69 | struct bsc_fd rtp; |
| 70 | struct bsc_fd rtcp; |
| 71 | |
| 72 | int local_port; |
| 73 | int local_alloc; |
| 74 | }; |
| 75 | |
| 76 | enum { |
| 77 | MGCP_TAP_BTS_IN, |
| 78 | MGCP_TAP_BTS_OUT, |
| 79 | MGCP_TAP_NET_IN, |
| 80 | MGCP_TAP_NET_OUT, |
| 81 | |
| 82 | /* last element */ |
| 83 | MGCP_TAP_COUNT |
| 84 | }; |
| 85 | |
| 86 | struct mgcp_rtp_tap { |
| 87 | int enabled; |
| 88 | struct sockaddr_in forward; |
| 89 | }; |
| 90 | |
| 91 | struct mgcp_endpoint { |
| 92 | int allocated; |
| 93 | uint32_t ci; |
| 94 | char *callid; |
| 95 | char *local_options; |
| 96 | int conn_mode; |
| 97 | int orig_mode; |
| 98 | |
| 99 | /* backpointer */ |
| 100 | struct mgcp_config *cfg; |
| 101 | struct mgcp_trunk_config *tcfg; |
| 102 | |
| 103 | /* port status for bts/net */ |
| 104 | struct mgcp_rtp_end bts_end; |
| 105 | struct mgcp_rtp_end net_end; |
| 106 | |
| 107 | /* |
| 108 | * For transcoding we will send from the local_port |
| 109 | * of trans_bts and it will arrive at trans_net from |
| 110 | * where we will forward it to the network. |
| 111 | */ |
| 112 | struct mgcp_rtp_end trans_bts; |
| 113 | struct mgcp_rtp_end trans_net; |
| 114 | int is_transcoded; |
| 115 | |
| 116 | /* sequence bits */ |
| 117 | struct mgcp_rtp_state net_state; |
| 118 | struct mgcp_rtp_state bts_state; |
| 119 | |
| 120 | /* SSRC/seq/ts patching for loop */ |
| 121 | int allow_patch; |
| 122 | |
| 123 | /* tap for the endpoint */ |
| 124 | struct mgcp_rtp_tap taps[MGCP_TAP_COUNT]; |
| 125 | }; |
| 126 | |
| 127 | #define ENDPOINT_NUMBER(endp) abs(endp - endp->tcfg->endpoints) |
| 128 | |
| 129 | struct mgcp_msg_ptr { |
| 130 | unsigned int start; |
| 131 | unsigned int length; |
| 132 | }; |
| 133 | |
| 134 | int mgcp_analyze_header(struct mgcp_config *cfg, struct msgb *msg, |
| 135 | struct mgcp_msg_ptr *ptr, int size, |
| 136 | const char **transaction_id, struct mgcp_endpoint **endp); |
| 137 | int mgcp_send_dummy(struct mgcp_endpoint *endp); |
| 138 | int mgcp_bind_bts_rtp_port(struct mgcp_endpoint *endp, int rtp_port); |
| 139 | int mgcp_bind_net_rtp_port(struct mgcp_endpoint *endp, int rtp_port); |
| 140 | int mgcp_bind_trans_bts_rtp_port(struct mgcp_endpoint *enp, int rtp_port); |
| 141 | int mgcp_bind_trans_net_rtp_port(struct mgcp_endpoint *enp, int rtp_port); |
| 142 | int mgcp_free_rtp_port(struct mgcp_rtp_end *end); |
| 143 | |
| 144 | /* For transcoding we need to manage an in and an output that are connected */ |
| 145 | static inline int endp_back_channel(int endpoint) |
| 146 | { |
| 147 | return endpoint + 60; |
| 148 | } |
| 149 | |
| 150 | struct mgcp_trunk_config *mgcp_trunk_alloc(struct mgcp_config *cfg, int index); |
| 151 | struct mgcp_trunk_config *mgcp_trunk_num(struct mgcp_config *cfg, int index); |
| 152 | |
| 153 | |
| 154 | #endif |