Holger Hans Peter Freyther | 97f66e2 | 2010-07-28 03:32:52 +0800 | [diff] [blame] | 1 | /* A Media Gateway Control Protocol Media Gateway: RFC 3435 */ |
| 2 | |
| 3 | /* |
| 4 | * (C) 2009-2010 by Holger Hans Peter Freyther <zecke@selfish.org> |
| 5 | * (C) 2009-2010 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 General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 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 General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License along |
| 19 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 20 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 21 | * |
| 22 | */ |
| 23 | |
| 24 | #ifndef OPENBSC_MGCP_H |
| 25 | #define OPENBSC_MGCP_H |
| 26 | |
Holger Hans Peter Freyther | cbf7d18 | 2010-07-31 05:25:35 +0800 | [diff] [blame] | 27 | #include <osmocore/msgb.h> |
Holger Hans Peter Freyther | 97f66e2 | 2010-07-28 03:32:52 +0800 | [diff] [blame] | 28 | |
| 29 | #include <arpa/inet.h> |
| 30 | |
| 31 | #define RTP_PORT_DEFAULT 4000 |
Holger Hans Peter Freyther | d86208d | 2010-08-04 06:11:27 +0800 | [diff] [blame] | 32 | |
Holger Hans Peter Freyther | 97f66e2 | 2010-07-28 03:32:52 +0800 | [diff] [blame] | 33 | /** |
| 34 | * Calculate the RTP audio port for the given multiplex |
| 35 | * and the direction. This allows a semi static endpoint |
| 36 | * to port calculation removing the need for the BSC |
| 37 | * and the MediaGateway to communicate. |
| 38 | * |
| 39 | * Port usage explained: |
| 40 | * base + (multiplex * 2) + 0 == local port to wait for network packets |
| 41 | * base + (multiplex * 2) + 1 == local port for rtcp |
| 42 | * |
| 43 | * The above port will receive packets from the BTS that need |
| 44 | * to be patched and forwarded to the network. |
| 45 | * The above port will receive packets from the network that |
| 46 | * need to be patched and forwarded to the BTS. |
| 47 | * |
| 48 | * We assume to have a static BTS IP address so we can differentiate |
| 49 | * network and BTS. |
| 50 | * |
| 51 | */ |
| 52 | static inline int rtp_calculate_port(int multiplex, int base) |
| 53 | { |
| 54 | return base + (multiplex * 2); |
| 55 | } |
| 56 | |
| 57 | |
| 58 | /* |
| 59 | * Handling of MGCP Endpoints and the MGCP Config |
| 60 | */ |
| 61 | struct mgcp_endpoint; |
| 62 | struct mgcp_config; |
| 63 | |
| 64 | #define MGCP_ENDP_CRCX 1 |
| 65 | #define MGCP_ENDP_DLCX 2 |
| 66 | #define MGCP_ENDP_MDCX 3 |
| 67 | |
| 68 | /* |
| 69 | * what to do with the msg? |
| 70 | * - continue as usual? |
| 71 | * - reject and send a failure code? |
| 72 | * - defer? do not send anything |
| 73 | */ |
| 74 | #define MGCP_POLICY_CONT 4 |
| 75 | #define MGCP_POLICY_REJECT 5 |
| 76 | #define MGCP_POLICY_DEFER 6 |
| 77 | |
| 78 | typedef int (*mgcp_change)(struct mgcp_config *cfg, int endpoint, int state, int local_rtp); |
| 79 | typedef int (*mgcp_policy)(struct mgcp_config *cfg, int endpoint, int state, const char *transactio_id); |
| 80 | typedef int (*mgcp_reset)(struct mgcp_config *cfg); |
| 81 | |
| 82 | struct mgcp_config { |
Holger Hans Peter Freyther | 97f66e2 | 2010-07-28 03:32:52 +0800 | [diff] [blame] | 83 | int source_port; |
| 84 | char *local_ip; |
| 85 | char *source_addr; |
Holger Hans Peter Freyther | d86208d | 2010-08-04 06:11:27 +0800 | [diff] [blame] | 86 | unsigned int number_endpoints; |
Holger Hans Peter Freyther | 97f66e2 | 2010-07-28 03:32:52 +0800 | [diff] [blame] | 87 | char *bts_ip; |
| 88 | char *call_agent_addr; |
| 89 | |
Holger Hans Peter Freyther | 97f66e2 | 2010-07-28 03:32:52 +0800 | [diff] [blame] | 90 | struct in_addr bts_in; |
| 91 | char *audio_name; |
| 92 | int audio_payload; |
| 93 | int audio_loop; |
| 94 | int early_bind; |
| 95 | int rtp_base_port; |
| 96 | int endp_dscp; |
| 97 | |
Holger Hans Peter Freyther | 97f66e2 | 2010-07-28 03:32:52 +0800 | [diff] [blame] | 98 | char *forward_ip; |
| 99 | int forward_port; |
| 100 | |
Holger Hans Peter Freyther | 97f66e2 | 2010-07-28 03:32:52 +0800 | [diff] [blame] | 101 | /* spec handling */ |
| 102 | int force_realloc; |
| 103 | |
Holger Hans Peter Freyther | 97f66e2 | 2010-07-28 03:32:52 +0800 | [diff] [blame] | 104 | mgcp_change change_cb; |
| 105 | mgcp_policy policy_cb; |
| 106 | mgcp_reset reset_cb; |
| 107 | void *data; |
Holger Hans Peter Freyther | d86208d | 2010-08-04 06:11:27 +0800 | [diff] [blame] | 108 | |
| 109 | struct mgcp_endpoint *endpoints; |
Holger Hans Peter Freyther | 5b08401 | 2010-08-08 07:51:51 +0800 | [diff] [blame^] | 110 | uint32_t last_call_id; |
Holger Hans Peter Freyther | 97f66e2 | 2010-07-28 03:32:52 +0800 | [diff] [blame] | 111 | }; |
| 112 | |
| 113 | /* config management */ |
| 114 | struct mgcp_config *mgcp_config_alloc(void); |
| 115 | int mgcp_parse_config(const char *config_file, struct mgcp_config *cfg); |
| 116 | int mgcp_vty_init(void); |
Holger Hans Peter Freyther | e807376 | 2010-08-04 07:34:21 +0800 | [diff] [blame] | 117 | void mgcp_vty_set_config(struct mgcp_config *cfg); |
Holger Hans Peter Freyther | 97f66e2 | 2010-07-28 03:32:52 +0800 | [diff] [blame] | 118 | int mgcp_endpoints_allocate(struct mgcp_config *cfg); |
| 119 | int mgcp_bind_rtp_port(struct mgcp_endpoint *endp, int rtp_port); |
| 120 | void mgcp_free_endp(struct mgcp_endpoint *endp); |
| 121 | |
| 122 | /* |
| 123 | * format helper functions |
| 124 | */ |
| 125 | struct msgb *mgcp_handle_message(struct mgcp_config *cfg, struct msgb *msg); |
| 126 | struct msgb *mgcp_create_response_with_data(int code, const char *msg, const char *trans, const char *data); |
| 127 | |
| 128 | /* adc helper */ |
| 129 | static inline int mgcp_timeslot_to_endpoint(int multiplex, int timeslot) |
| 130 | { |
| 131 | if (timeslot == 0) |
| 132 | timeslot = 1; |
| 133 | return timeslot + (31 * multiplex); |
| 134 | } |
| 135 | |
| 136 | |
| 137 | #endif |