Holger Hans Peter Freyther | 07fc097 | 2012-10-24 21:52:16 +0200 | [diff] [blame] | 1 | /** |
| 2 | * This file contains helper routines for MGCP Gateway handling. |
| 3 | * |
| 4 | * The first thing to remember is that each BSC has its own namespace/range |
| 5 | * of endpoints. Whenever a BSSMAP ASSIGNMENT REQUEST is received this code |
| 6 | * will be called to select an endpoint on the BSC. The mapping from original |
| 7 | * multiplex/timeslot to BSC multiplex'/timeslot' will be stored. |
| 8 | * |
| 9 | * The second part is to take messages on the public MGCP GW interface |
| 10 | * and forward them to the right BSC. This requires the MSC to first |
| 11 | * assign the timeslot. This assumption has been true so far. We are using |
| 12 | * the policy_cb of the MGCP protocol code to decide if the request should |
| 13 | * be immediately answered or delayed. An extension "Z: noanswer" is used |
| 14 | * to request the BSC to not respond. This is saving some bytes of bandwidth |
| 15 | * and as we are using TCP to forward the message we know it will arrive. |
| 16 | * The mgcp_do_read method reads these messages and hands them to the protocol |
| 17 | * parsing code which will call the mentioned policy_cb. The bsc_mgcp_forward |
| 18 | * method is used on the way back from the BSC to the network. |
| 19 | * |
| 20 | * The third part is to patch messages forwarded to the BSC. This includes |
| 21 | * the endpoint number, the ports to be used inside the SDP file and maybe |
| 22 | * some other bits. |
| 23 | * |
| 24 | */ |
Holger Hans Peter Freyther | 465313e | 2010-06-15 18:49:53 +0800 | [diff] [blame] | 25 | /* |
Holger Hans Peter Freyther | 07fc097 | 2012-10-24 21:52:16 +0200 | [diff] [blame] | 26 | * (C) 2010-2012 by Holger Hans Peter Freyther <zecke@selfish.org> |
| 27 | * (C) 2010-2012 by On-Waves |
Holger Hans Peter Freyther | 465313e | 2010-06-15 18:49:53 +0800 | [diff] [blame] | 28 | * All Rights Reserved |
| 29 | * |
| 30 | * This program is free software; you can redistribute it and/or modify |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 31 | * it under the terms of the GNU Affero General Public License as published by |
| 32 | * the Free Software Foundation; either version 3 of the License, or |
Holger Hans Peter Freyther | 465313e | 2010-06-15 18:49:53 +0800 | [diff] [blame] | 33 | * (at your option) any later version. |
| 34 | * |
| 35 | * This program is distributed in the hope that it will be useful, |
| 36 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 37 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 38 | * GNU Affero General Public License for more details. |
Holger Hans Peter Freyther | 465313e | 2010-06-15 18:49:53 +0800 | [diff] [blame] | 39 | * |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 40 | * You should have received a copy of the GNU Affero General Public License |
| 41 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
Holger Hans Peter Freyther | 465313e | 2010-06-15 18:49:53 +0800 | [diff] [blame] | 42 | * |
| 43 | */ |
| 44 | |
| 45 | #include <openbsc/bsc_nat.h> |
Holger Hans Peter Freyther | c2b31ed | 2010-07-31 05:17:17 +0800 | [diff] [blame] | 46 | #include <openbsc/bsc_nat_sccp.h> |
Holger Hans Peter Freyther | 465313e | 2010-06-15 18:49:53 +0800 | [diff] [blame] | 47 | #include <openbsc/gsm_data.h> |
Holger Hans Peter Freyther | 465313e | 2010-06-15 18:49:53 +0800 | [diff] [blame] | 48 | #include <openbsc/debug.h> |
Holger Hans Peter Freyther | 19c530c | 2010-10-13 23:52:01 +0200 | [diff] [blame] | 49 | #include <openbsc/ipaccess.h> |
Holger Hans Peter Freyther | 241e130 | 2010-03-31 09:16:56 +0200 | [diff] [blame] | 50 | #include <openbsc/mgcp.h> |
| 51 | #include <openbsc/mgcp_internal.h> |
Holger Hans Peter Freyther | 465313e | 2010-06-15 18:49:53 +0800 | [diff] [blame] | 52 | |
Harald Welte | d5db12c | 2010-08-03 15:11:51 +0200 | [diff] [blame] | 53 | #include <osmocom/sccp/sccp.h> |
Holger Hans Peter Freyther | 7b7eef6 | 2010-04-22 12:08:17 +0800 | [diff] [blame] | 54 | |
Pablo Neira Ayuso | 136f453 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 55 | #include <osmocom/core/talloc.h> |
Harald Welte | d36ff76 | 2011-03-23 18:26:56 +0100 | [diff] [blame] | 56 | #include <osmocom/gsm/gsm0808.h> |
| 57 | #include <osmocom/gsm/protocol/gsm_08_08.h> |
Holger Hans Peter Freyther | a0df82d | 2010-04-01 08:21:33 +0200 | [diff] [blame] | 58 | |
Holger Hans Peter Freyther | 465313e | 2010-06-15 18:49:53 +0800 | [diff] [blame] | 59 | #include <netinet/in.h> |
| 60 | #include <arpa/inet.h> |
| 61 | |
Holger Hans Peter Freyther | a7f8018 | 2010-03-31 13:02:22 +0200 | [diff] [blame] | 62 | #include <errno.h> |
| 63 | #include <unistd.h> |
| 64 | |
Holger Hans Peter Freyther | 9ec030d | 2011-02-27 11:04:27 +0100 | [diff] [blame] | 65 | int bsc_mgcp_nr_multiplexes(int max_endpoints) |
| 66 | { |
| 67 | int div = max_endpoints / 32; |
| 68 | |
| 69 | if ((max_endpoints % 32) != 0) |
| 70 | div += 1; |
| 71 | |
| 72 | return div; |
| 73 | } |
| 74 | |
Holger Hans Peter Freyther | ed500e3 | 2011-02-25 17:09:07 +0100 | [diff] [blame] | 75 | static int bsc_init_endps_if_needed(struct bsc_connection *con) |
| 76 | { |
Holger Hans Peter Freyther | 9ec030d | 2011-02-27 11:04:27 +0100 | [diff] [blame] | 77 | int multiplexes; |
| 78 | |
Holger Hans Peter Freyther | ed500e3 | 2011-02-25 17:09:07 +0100 | [diff] [blame] | 79 | /* we have done that */ |
| 80 | if (con->_endpoint_status) |
| 81 | return 0; |
| 82 | |
| 83 | /* we have no config... */ |
| 84 | if (!con->cfg) |
| 85 | return -1; |
| 86 | |
Holger Hans Peter Freyther | 9ec030d | 2011-02-27 11:04:27 +0100 | [diff] [blame] | 87 | multiplexes = bsc_mgcp_nr_multiplexes(con->cfg->max_endpoints); |
| 88 | con->number_multiplexes = multiplexes; |
| 89 | con->max_endpoints = con->cfg->max_endpoints; |
| 90 | con->_endpoint_status = talloc_zero_array(con, char, 32 * multiplexes + 1); |
Holger Hans Peter Freyther | ed500e3 | 2011-02-25 17:09:07 +0100 | [diff] [blame] | 91 | return con->_endpoint_status == NULL; |
| 92 | } |
| 93 | |
Holger Hans Peter Freyther | 45fd07d | 2010-08-28 18:22:14 +0800 | [diff] [blame] | 94 | static int bsc_assign_endpoint(struct bsc_connection *bsc, struct sccp_connections *con) |
| 95 | { |
Holger Hans Peter Freyther | a9e9331 | 2011-02-26 11:38:00 +0100 | [diff] [blame] | 96 | int multiplex; |
| 97 | int timeslot; |
Holger Hans Peter Freyther | 9ec030d | 2011-02-27 11:04:27 +0100 | [diff] [blame] | 98 | const int number_endpoints = bsc->max_endpoints; |
Holger Hans Peter Freyther | 45fd07d | 2010-08-28 18:22:14 +0800 | [diff] [blame] | 99 | int i; |
| 100 | |
Holger Hans Peter Freyther | a9e9331 | 2011-02-26 11:38:00 +0100 | [diff] [blame] | 101 | mgcp_endpoint_to_timeslot(bsc->last_endpoint, &multiplex, ×lot); |
| 102 | timeslot += 1; |
| 103 | |
| 104 | for (i = 0; i < number_endpoints; ++i) { |
| 105 | int endpoint; |
| 106 | |
| 107 | /* Wrap around timeslots */ |
| 108 | if (timeslot == 0) |
| 109 | timeslot = 1; |
| 110 | |
| 111 | if (timeslot == 0x1f) { |
| 112 | timeslot = 1; |
| 113 | multiplex += 1; |
| 114 | } |
| 115 | |
| 116 | /* Wrap around the multiplex */ |
| 117 | if (multiplex >= bsc->number_multiplexes) |
| 118 | multiplex = 0; |
| 119 | |
| 120 | endpoint = mgcp_timeslot_to_endpoint(multiplex, timeslot); |
Holger Hans Peter Freyther | 45fd07d | 2010-08-28 18:22:14 +0800 | [diff] [blame] | 121 | |
Holger Hans Peter Freyther | 9ec030d | 2011-02-27 11:04:27 +0100 | [diff] [blame] | 122 | /* Now check if we are allowed to assign this one */ |
| 123 | if (endpoint >= bsc->max_endpoints) { |
| 124 | multiplex = 0; |
| 125 | timeslot = 1; |
| 126 | endpoint = mgcp_timeslot_to_endpoint(multiplex, timeslot); |
| 127 | } |
| 128 | |
| 129 | |
Holger Hans Peter Freyther | ed500e3 | 2011-02-25 17:09:07 +0100 | [diff] [blame] | 130 | if (bsc->_endpoint_status[endpoint] == 0) { |
| 131 | bsc->_endpoint_status[endpoint] = 1; |
Holger Hans Peter Freyther | 45fd07d | 2010-08-28 18:22:14 +0800 | [diff] [blame] | 132 | con->bsc_endp = endpoint; |
| 133 | bsc->last_endpoint = endpoint; |
| 134 | return 0; |
| 135 | } |
Holger Hans Peter Freyther | a9e9331 | 2011-02-26 11:38:00 +0100 | [diff] [blame] | 136 | |
| 137 | timeslot += 1; |
Holger Hans Peter Freyther | 45fd07d | 2010-08-28 18:22:14 +0800 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | return -1; |
| 141 | } |
| 142 | |
| 143 | static uint16_t create_cic(int endpoint) |
| 144 | { |
| 145 | int timeslot, multiplex; |
| 146 | |
| 147 | mgcp_endpoint_to_timeslot(endpoint, &multiplex, ×lot); |
| 148 | return (multiplex << 5) | (timeslot & 0x1f); |
| 149 | } |
| 150 | |
| 151 | int bsc_mgcp_assign_patch(struct sccp_connections *con, struct msgb *msg) |
Holger Hans Peter Freyther | 465313e | 2010-06-15 18:49:53 +0800 | [diff] [blame] | 152 | { |
Holger Hans Peter Freyther | 7b7eef6 | 2010-04-22 12:08:17 +0800 | [diff] [blame] | 153 | struct sccp_connections *mcon; |
Holger Hans Peter Freyther | 465313e | 2010-06-15 18:49:53 +0800 | [diff] [blame] | 154 | struct tlv_parsed tp; |
Holger Hans Peter Freyther | e2c1520 | 2010-07-23 19:09:21 +0800 | [diff] [blame] | 155 | uint16_t cic; |
Holger Hans Peter Freyther | dbd16fe | 2010-07-23 19:08:55 +0800 | [diff] [blame] | 156 | uint8_t timeslot; |
| 157 | uint8_t multiplex; |
Holger Hans Peter Freyther | 1406977 | 2010-11-04 17:14:41 +0100 | [diff] [blame] | 158 | unsigned int endp; |
Holger Hans Peter Freyther | 465313e | 2010-06-15 18:49:53 +0800 | [diff] [blame] | 159 | |
| 160 | if (!msg->l3h) { |
| 161 | LOGP(DNAT, LOGL_ERROR, "Assignment message should have l3h pointer.\n"); |
| 162 | return -1; |
| 163 | } |
| 164 | |
| 165 | if (msgb_l3len(msg) < 3) { |
| 166 | LOGP(DNAT, LOGL_ERROR, "Assignment message has not enough space for GSM0808.\n"); |
| 167 | return -1; |
| 168 | } |
| 169 | |
| 170 | tlv_parse(&tp, gsm0808_att_tlvdef(), msg->l3h + 3, msgb_l3len(msg) - 3, 0, 0); |
| 171 | if (!TLVP_PRESENT(&tp, GSM0808_IE_CIRCUIT_IDENTITY_CODE)) { |
| 172 | LOGP(DNAT, LOGL_ERROR, "Circuit identity code not found in assignment message.\n"); |
| 173 | return -1; |
| 174 | } |
| 175 | |
Holger Hans Peter Freyther | e2c1520 | 2010-07-23 19:09:21 +0800 | [diff] [blame] | 176 | cic = ntohs(*(uint16_t *)TLVP_VAL(&tp, GSM0808_IE_CIRCUIT_IDENTITY_CODE)); |
Holger Hans Peter Freyther | 465313e | 2010-06-15 18:49:53 +0800 | [diff] [blame] | 177 | timeslot = cic & 0x1f; |
| 178 | multiplex = (cic & ~0x1f) >> 5; |
| 179 | |
Holger Hans Peter Freyther | 7b7eef6 | 2010-04-22 12:08:17 +0800 | [diff] [blame] | 180 | |
Holger Hans Peter Freyther | f4b3439 | 2010-08-28 16:08:39 +0800 | [diff] [blame] | 181 | endp = mgcp_timeslot_to_endpoint(multiplex, timeslot); |
Holger Hans Peter Freyther | 7b7eef6 | 2010-04-22 12:08:17 +0800 | [diff] [blame] | 182 | |
Holger Hans Peter Freyther | 88ad772 | 2011-02-28 00:56:17 +0100 | [diff] [blame] | 183 | if (endp >= con->bsc->nat->mgcp_cfg->trunk.number_endpoints) { |
Holger Hans Peter Freyther | 1406977 | 2010-11-04 17:14:41 +0100 | [diff] [blame] | 184 | LOGP(DNAT, LOGL_ERROR, |
| 185 | "MSC attempted to assign bad endpoint 0x%x\n", |
| 186 | endp); |
| 187 | return -1; |
| 188 | } |
| 189 | |
Holger Hans Peter Freyther | 7b7eef6 | 2010-04-22 12:08:17 +0800 | [diff] [blame] | 190 | /* find stale connections using that endpoint */ |
| 191 | llist_for_each_entry(mcon, &con->bsc->nat->sccp_connections, list_entry) { |
Holger Hans Peter Freyther | f4b3439 | 2010-08-28 16:08:39 +0800 | [diff] [blame] | 192 | if (mcon->msc_endp == endp) { |
Holger Hans Peter Freyther | 7b7eef6 | 2010-04-22 12:08:17 +0800 | [diff] [blame] | 193 | LOGP(DNAT, LOGL_ERROR, |
Holger Hans Peter Freyther | f4b3439 | 2010-08-28 16:08:39 +0800 | [diff] [blame] | 194 | "Endpoint %d was assigned to 0x%x and now 0x%x\n", |
| 195 | endp, |
Holger Hans Peter Freyther | 7b7eef6 | 2010-04-22 12:08:17 +0800 | [diff] [blame] | 196 | sccp_src_ref_to_int(&mcon->patched_ref), |
| 197 | sccp_src_ref_to_int(&con->patched_ref)); |
| 198 | bsc_mgcp_dlcx(mcon); |
| 199 | } |
| 200 | } |
| 201 | |
Holger Hans Peter Freyther | f4b3439 | 2010-08-28 16:08:39 +0800 | [diff] [blame] | 202 | con->msc_endp = endp; |
Holger Hans Peter Freyther | ed500e3 | 2011-02-25 17:09:07 +0100 | [diff] [blame] | 203 | if (bsc_init_endps_if_needed(con->bsc) != 0) |
| 204 | return -1; |
Holger Hans Peter Freyther | 45fd07d | 2010-08-28 18:22:14 +0800 | [diff] [blame] | 205 | if (bsc_assign_endpoint(con->bsc, con) != 0) |
| 206 | return -1; |
| 207 | |
| 208 | /* |
| 209 | * now patch the message for the new CIC... |
| 210 | * still assumed to be one multiplex only |
| 211 | */ |
| 212 | cic = htons(create_cic(con->bsc_endp)); |
| 213 | memcpy((uint8_t *) TLVP_VAL(&tp, GSM0808_IE_CIRCUIT_IDENTITY_CODE), |
| 214 | &cic, sizeof(cic)); |
| 215 | |
Holger Hans Peter Freyther | 465313e | 2010-06-15 18:49:53 +0800 | [diff] [blame] | 216 | return 0; |
| 217 | } |
| 218 | |
Holger Hans Peter Freyther | 7b7eef6 | 2010-04-22 12:08:17 +0800 | [diff] [blame] | 219 | static void bsc_mgcp_free_endpoint(struct bsc_nat *nat, int i) |
Holger Hans Peter Freyther | a0df82d | 2010-04-01 08:21:33 +0200 | [diff] [blame] | 220 | { |
| 221 | if (nat->bsc_endpoints[i].transaction_id) { |
| 222 | talloc_free(nat->bsc_endpoints[i].transaction_id); |
| 223 | nat->bsc_endpoints[i].transaction_id = NULL; |
| 224 | } |
| 225 | |
Holger Hans Peter Freyther | 5b2726e | 2010-08-06 09:05:05 +0800 | [diff] [blame] | 226 | nat->bsc_endpoints[i].transaction_state = 0; |
Holger Hans Peter Freyther | a0df82d | 2010-04-01 08:21:33 +0200 | [diff] [blame] | 227 | nat->bsc_endpoints[i].bsc = NULL; |
Holger Hans Peter Freyther | a0df82d | 2010-04-01 08:21:33 +0200 | [diff] [blame] | 228 | } |
| 229 | |
Holger Hans Peter Freyther | 241e130 | 2010-03-31 09:16:56 +0200 | [diff] [blame] | 230 | void bsc_mgcp_free_endpoints(struct bsc_nat *nat) |
| 231 | { |
| 232 | int i; |
| 233 | |
Holger Hans Peter Freyther | 88ad772 | 2011-02-28 00:56:17 +0100 | [diff] [blame] | 234 | for (i = 1; i < nat->mgcp_cfg->trunk.number_endpoints; ++i){ |
Holger Hans Peter Freyther | a0df82d | 2010-04-01 08:21:33 +0200 | [diff] [blame] | 235 | bsc_mgcp_free_endpoint(nat, i); |
Holger Hans Peter Freyther | 88ad772 | 2011-02-28 00:56:17 +0100 | [diff] [blame] | 236 | mgcp_free_endp(&nat->mgcp_cfg->trunk.endpoints[i]); |
Holger Hans Peter Freyther | 7b7eef6 | 2010-04-22 12:08:17 +0800 | [diff] [blame] | 237 | } |
Holger Hans Peter Freyther | 241e130 | 2010-03-31 09:16:56 +0200 | [diff] [blame] | 238 | } |
Holger Hans Peter Freyther | a7f8018 | 2010-03-31 13:02:22 +0200 | [diff] [blame] | 239 | |
Holger Hans Peter Freyther | 7b7eef6 | 2010-04-22 12:08:17 +0800 | [diff] [blame] | 240 | /* send a MDCX where we do not want a response */ |
Holger Hans Peter Freyther | 601180f | 2010-08-29 23:40:33 +0800 | [diff] [blame] | 241 | static void bsc_mgcp_send_mdcx(struct bsc_connection *bsc, int port, struct mgcp_endpoint *endp) |
Holger Hans Peter Freyther | 7b7eef6 | 2010-04-22 12:08:17 +0800 | [diff] [blame] | 242 | { |
| 243 | char buf[2096]; |
| 244 | int len; |
| 245 | |
| 246 | len = snprintf(buf, sizeof(buf), |
Holger Hans Peter Freyther | f42f45b | 2010-04-22 13:06:24 +0800 | [diff] [blame] | 247 | "MDCX 23 %x@mgw MGCP 1.0\r\n" |
Holger Hans Peter Freyther | 7b7eef6 | 2010-04-22 12:08:17 +0800 | [diff] [blame] | 248 | "Z: noanswer\r\n" |
| 249 | "\r\n" |
| 250 | "c=IN IP4 %s\r\n" |
| 251 | "m=audio %d RTP/AVP 255\r\n", |
Holger Hans Peter Freyther | 601180f | 2010-08-29 23:40:33 +0800 | [diff] [blame] | 252 | port, |
Holger Hans Peter Freyther | 7b7eef6 | 2010-04-22 12:08:17 +0800 | [diff] [blame] | 253 | bsc->nat->mgcp_cfg->source_addr, |
Holger Hans Peter Freyther | 58ff219 | 2010-08-05 03:08:35 +0800 | [diff] [blame] | 254 | endp->bts_end.local_port); |
Holger Hans Peter Freyther | 7b7eef6 | 2010-04-22 12:08:17 +0800 | [diff] [blame] | 255 | if (len < 0) { |
Holger Hans Peter Freyther | 7456891 | 2012-09-14 15:51:43 +0200 | [diff] [blame] | 256 | LOGP(DMGCP, LOGL_ERROR, "snprintf for MDCX failed.\n"); |
Holger Hans Peter Freyther | 7b7eef6 | 2010-04-22 12:08:17 +0800 | [diff] [blame] | 257 | return; |
| 258 | } |
Holger Hans Peter Freyther | d38aa45 | 2010-08-30 11:58:49 +0800 | [diff] [blame] | 259 | |
| 260 | #warning "The MDCX is not send to the BSC. It should" |
Holger Hans Peter Freyther | 7b7eef6 | 2010-04-22 12:08:17 +0800 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | static void bsc_mgcp_send_dlcx(struct bsc_connection *bsc, int endpoint) |
| 264 | { |
| 265 | char buf[2096]; |
| 266 | int len; |
| 267 | |
| 268 | len = snprintf(buf, sizeof(buf), |
Holger Hans Peter Freyther | bf812fa | 2010-08-30 12:01:36 +0800 | [diff] [blame] | 269 | "DLCX 26 %x@mgw MGCP 1.0\r\n" |
Holger Hans Peter Freyther | 7b7eef6 | 2010-04-22 12:08:17 +0800 | [diff] [blame] | 270 | "Z: noanswer\r\n", endpoint); |
| 271 | if (len < 0) { |
| 272 | LOGP(DMGCP, LOGL_ERROR, "snprintf for DLCX failed.\n"); |
| 273 | return; |
| 274 | } |
| 275 | |
Holger Hans Peter Freyther | dbd16fe | 2010-07-23 19:08:55 +0800 | [diff] [blame] | 276 | bsc_write_mgcp(bsc, (uint8_t *) buf, len); |
Holger Hans Peter Freyther | 7b7eef6 | 2010-04-22 12:08:17 +0800 | [diff] [blame] | 277 | } |
| 278 | |
| 279 | void bsc_mgcp_init(struct sccp_connections *con) |
| 280 | { |
Holger Hans Peter Freyther | f4b3439 | 2010-08-28 16:08:39 +0800 | [diff] [blame] | 281 | con->msc_endp = -1; |
| 282 | con->bsc_endp = -1; |
Holger Hans Peter Freyther | 7b7eef6 | 2010-04-22 12:08:17 +0800 | [diff] [blame] | 283 | } |
| 284 | |
| 285 | void bsc_mgcp_dlcx(struct sccp_connections *con) |
| 286 | { |
| 287 | /* send a DLCX down the stream */ |
Holger Hans Peter Freyther | ed500e3 | 2011-02-25 17:09:07 +0100 | [diff] [blame] | 288 | if (con->bsc_endp != -1 && con->bsc->_endpoint_status) { |
| 289 | if (con->bsc->_endpoint_status[con->bsc_endp] != 1) |
Holger Hans Peter Freyther | f7c86c5 | 2010-08-30 13:44:32 +0800 | [diff] [blame] | 290 | LOGP(DNAT, LOGL_ERROR, "Endpoint 0x%x was not in use\n", con->bsc_endp); |
Holger Hans Peter Freyther | ed500e3 | 2011-02-25 17:09:07 +0100 | [diff] [blame] | 291 | con->bsc->_endpoint_status[con->bsc_endp] = 0; |
Holger Hans Peter Freyther | f4b3439 | 2010-08-28 16:08:39 +0800 | [diff] [blame] | 292 | bsc_mgcp_send_dlcx(con->bsc, con->bsc_endp); |
| 293 | bsc_mgcp_free_endpoint(con->bsc->nat, con->msc_endp); |
Holger Hans Peter Freyther | 7b7eef6 | 2010-04-22 12:08:17 +0800 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | bsc_mgcp_init(con); |
| 297 | } |
| 298 | |
| 299 | |
Holger Hans Peter Freyther | 08a1b16 | 2010-04-18 02:26:16 +0800 | [diff] [blame] | 300 | struct sccp_connections *bsc_mgcp_find_con(struct bsc_nat *nat, int endpoint) |
Holger Hans Peter Freyther | fc9bd23 | 2010-04-01 03:55:27 +0200 | [diff] [blame] | 301 | { |
Holger Hans Peter Freyther | 08a1b16 | 2010-04-18 02:26:16 +0800 | [diff] [blame] | 302 | struct sccp_connections *con = NULL; |
Holger Hans Peter Freyther | fc9bd23 | 2010-04-01 03:55:27 +0200 | [diff] [blame] | 303 | struct sccp_connections *sccp; |
| 304 | |
| 305 | llist_for_each_entry(sccp, &nat->sccp_connections, list_entry) { |
Holger Hans Peter Freyther | f4b3439 | 2010-08-28 16:08:39 +0800 | [diff] [blame] | 306 | if (sccp->msc_endp == -1) |
Holger Hans Peter Freyther | fc9bd23 | 2010-04-01 03:55:27 +0200 | [diff] [blame] | 307 | continue; |
Holger Hans Peter Freyther | f4b3439 | 2010-08-28 16:08:39 +0800 | [diff] [blame] | 308 | if (sccp->msc_endp != endpoint) |
Holger Hans Peter Freyther | fc9bd23 | 2010-04-01 03:55:27 +0200 | [diff] [blame] | 309 | continue; |
| 310 | |
Holger Hans Peter Freyther | 08a1b16 | 2010-04-18 02:26:16 +0800 | [diff] [blame] | 311 | con = sccp; |
Holger Hans Peter Freyther | fc9bd23 | 2010-04-01 03:55:27 +0200 | [diff] [blame] | 312 | } |
| 313 | |
Holger Hans Peter Freyther | 08a1b16 | 2010-04-18 02:26:16 +0800 | [diff] [blame] | 314 | if (con) |
| 315 | return con; |
Holger Hans Peter Freyther | eb52e89 | 2010-04-18 02:14:45 +0800 | [diff] [blame] | 316 | |
Holger Hans Peter Freyther | fc9bd23 | 2010-04-01 03:55:27 +0200 | [diff] [blame] | 317 | LOGP(DMGCP, LOGL_ERROR, "Failed to find the connection.\n"); |
| 318 | return NULL; |
| 319 | } |
| 320 | |
Holger Hans Peter Freyther | cb3c2c9 | 2012-10-24 21:53:07 +0200 | [diff] [blame] | 321 | static int bsc_mgcp_policy_cb(struct mgcp_trunk_config *tcfg, int endpoint, int state, const char *transaction_id) |
Holger Hans Peter Freyther | a0df82d | 2010-04-01 08:21:33 +0200 | [diff] [blame] | 322 | { |
| 323 | struct bsc_nat *nat; |
| 324 | struct bsc_endpoint *bsc_endp; |
Holger Hans Peter Freyther | 08a1b16 | 2010-04-18 02:26:16 +0800 | [diff] [blame] | 325 | struct sccp_connections *sccp; |
Holger Hans Peter Freyther | a0df82d | 2010-04-01 08:21:33 +0200 | [diff] [blame] | 326 | struct mgcp_endpoint *mgcp_endp; |
| 327 | struct msgb *bsc_msg; |
| 328 | |
Holger Hans Peter Freyther | 88ad772 | 2011-02-28 00:56:17 +0100 | [diff] [blame] | 329 | nat = tcfg->cfg->data; |
Holger Hans Peter Freyther | a0df82d | 2010-04-01 08:21:33 +0200 | [diff] [blame] | 330 | bsc_endp = &nat->bsc_endpoints[endpoint]; |
Holger Hans Peter Freyther | 88ad772 | 2011-02-28 00:56:17 +0100 | [diff] [blame] | 331 | mgcp_endp = &nat->mgcp_cfg->trunk.endpoints[endpoint]; |
Holger Hans Peter Freyther | a0df82d | 2010-04-01 08:21:33 +0200 | [diff] [blame] | 332 | |
Holger Hans Peter Freyther | fef7612 | 2010-04-24 21:05:18 +0800 | [diff] [blame] | 333 | if (bsc_endp->transaction_id) { |
| 334 | LOGP(DMGCP, LOGL_ERROR, "Endpoint 0x%x had pending transaction: '%s'\n", |
| 335 | endpoint, bsc_endp->transaction_id); |
| 336 | talloc_free(bsc_endp->transaction_id); |
| 337 | bsc_endp->transaction_id = NULL; |
Holger Hans Peter Freyther | 5b2726e | 2010-08-06 09:05:05 +0800 | [diff] [blame] | 338 | bsc_endp->transaction_state = 0; |
Holger Hans Peter Freyther | fef7612 | 2010-04-24 21:05:18 +0800 | [diff] [blame] | 339 | } |
| 340 | bsc_endp->bsc = NULL; |
| 341 | |
Holger Hans Peter Freyther | 08a1b16 | 2010-04-18 02:26:16 +0800 | [diff] [blame] | 342 | sccp = bsc_mgcp_find_con(nat, endpoint); |
Holger Hans Peter Freyther | a0df82d | 2010-04-01 08:21:33 +0200 | [diff] [blame] | 343 | |
Holger Hans Peter Freyther | 08a1b16 | 2010-04-18 02:26:16 +0800 | [diff] [blame] | 344 | if (!sccp) { |
Holger Hans Peter Freyther | 3d194d9 | 2010-04-24 21:02:01 +0800 | [diff] [blame] | 345 | LOGP(DMGCP, LOGL_ERROR, "Did not find BSC for change on endpoint: 0x%x state: %d\n", endpoint, state); |
Holger Hans Peter Freyther | a0df82d | 2010-04-01 08:21:33 +0200 | [diff] [blame] | 346 | |
| 347 | switch (state) { |
| 348 | case MGCP_ENDP_CRCX: |
| 349 | return MGCP_POLICY_REJECT; |
| 350 | break; |
| 351 | case MGCP_ENDP_DLCX: |
| 352 | return MGCP_POLICY_CONT; |
| 353 | break; |
| 354 | case MGCP_ENDP_MDCX: |
| 355 | return MGCP_POLICY_CONT; |
| 356 | break; |
| 357 | default: |
| 358 | LOGP(DMGCP, LOGL_FATAL, "Unhandled state: %d\n", state); |
| 359 | return MGCP_POLICY_CONT; |
| 360 | break; |
| 361 | } |
| 362 | } |
| 363 | |
Holger Hans Peter Freyther | dd16b42 | 2010-04-07 09:53:54 +0200 | [diff] [blame] | 364 | /* we need to generate a new and patched message */ |
Holger Hans Peter Freyther | f7c86c5 | 2010-08-30 13:44:32 +0800 | [diff] [blame] | 365 | bsc_msg = bsc_mgcp_rewrite((char *) nat->mgcp_msg, nat->mgcp_length, sccp->bsc_endp, |
Holger Hans Peter Freyther | 58ff219 | 2010-08-05 03:08:35 +0800 | [diff] [blame] | 366 | nat->mgcp_cfg->source_addr, mgcp_endp->bts_end.local_port); |
Holger Hans Peter Freyther | dd16b42 | 2010-04-07 09:53:54 +0200 | [diff] [blame] | 367 | if (!bsc_msg) { |
| 368 | LOGP(DMGCP, LOGL_ERROR, "Failed to patch the msg.\n"); |
| 369 | return MGCP_POLICY_CONT; |
| 370 | } |
| 371 | |
| 372 | |
Holger Hans Peter Freyther | b3e0a03 | 2010-04-04 18:11:49 +0200 | [diff] [blame] | 373 | bsc_endp->transaction_id = talloc_strdup(nat, transaction_id); |
Holger Hans Peter Freyther | 5b2726e | 2010-08-06 09:05:05 +0800 | [diff] [blame] | 374 | bsc_endp->transaction_state = state; |
Holger Hans Peter Freyther | 08a1b16 | 2010-04-18 02:26:16 +0800 | [diff] [blame] | 375 | bsc_endp->bsc = sccp->bsc; |
Holger Hans Peter Freyther | a0df82d | 2010-04-01 08:21:33 +0200 | [diff] [blame] | 376 | |
| 377 | /* we need to update some bits */ |
| 378 | if (state == MGCP_ENDP_CRCX) { |
| 379 | struct sockaddr_in sock; |
| 380 | socklen_t len = sizeof(sock); |
Holger Hans Peter Freyther | 08a1b16 | 2010-04-18 02:26:16 +0800 | [diff] [blame] | 381 | if (getpeername(sccp->bsc->write_queue.bfd.fd, (struct sockaddr *) &sock, &len) != 0) { |
Holger Hans Peter Freyther | 92febd3 | 2010-04-06 11:17:07 +0200 | [diff] [blame] | 382 | LOGP(DMGCP, LOGL_ERROR, "Can not get the peername...%d/%s\n", |
| 383 | errno, strerror(errno)); |
Holger Hans Peter Freyther | a0df82d | 2010-04-01 08:21:33 +0200 | [diff] [blame] | 384 | } else { |
Holger Hans Peter Freyther | a17d701 | 2010-08-05 01:34:51 +0800 | [diff] [blame] | 385 | mgcp_endp->bts_end.addr = sock.sin_addr; |
Holger Hans Peter Freyther | a0df82d | 2010-04-01 08:21:33 +0200 | [diff] [blame] | 386 | } |
Holger Hans Peter Freyther | a0df82d | 2010-04-01 08:21:33 +0200 | [diff] [blame] | 387 | |
Holger Hans Peter Freyther | e66cac3 | 2010-08-05 01:50:44 +0800 | [diff] [blame] | 388 | /* send the message and a fake MDCX to force sending of a dummy packet */ |
Holger Hans Peter Freyther | 368a0a7 | 2011-01-07 16:54:46 +0100 | [diff] [blame] | 389 | bsc_write(sccp->bsc, bsc_msg, IPAC_PROTO_MGCP_OLD); |
Holger Hans Peter Freyther | 601180f | 2010-08-29 23:40:33 +0800 | [diff] [blame] | 390 | bsc_mgcp_send_mdcx(sccp->bsc, sccp->bsc_endp, mgcp_endp); |
Holger Hans Peter Freyther | 7b7eef6 | 2010-04-22 12:08:17 +0800 | [diff] [blame] | 391 | return MGCP_POLICY_DEFER; |
| 392 | } else if (state == MGCP_ENDP_DLCX) { |
| 393 | /* we will free the endpoint now and send a DLCX to the BSC */ |
Holger Hans Peter Freyther | 3a347f0 | 2010-05-01 10:31:53 +0800 | [diff] [blame] | 394 | msgb_free(bsc_msg); |
Holger Hans Peter Freyther | 7b7eef6 | 2010-04-22 12:08:17 +0800 | [diff] [blame] | 395 | bsc_mgcp_dlcx(sccp); |
| 396 | return MGCP_POLICY_CONT; |
| 397 | } else { |
Holger Hans Peter Freyther | 368a0a7 | 2011-01-07 16:54:46 +0100 | [diff] [blame] | 398 | bsc_write(sccp->bsc, bsc_msg, IPAC_PROTO_MGCP_OLD); |
Holger Hans Peter Freyther | 7b7eef6 | 2010-04-22 12:08:17 +0800 | [diff] [blame] | 399 | return MGCP_POLICY_DEFER; |
| 400 | } |
Holger Hans Peter Freyther | a0df82d | 2010-04-01 08:21:33 +0200 | [diff] [blame] | 401 | } |
| 402 | |
Holger Hans Peter Freyther | 3c3bce1 | 2010-04-01 10:16:28 +0200 | [diff] [blame] | 403 | /* |
Holger Hans Peter Freyther | 7d47601 | 2010-08-06 19:16:34 +0800 | [diff] [blame] | 404 | * We do have a failure, free data downstream.. |
| 405 | */ |
| 406 | static void free_chan_downstream(struct mgcp_endpoint *endp, struct bsc_endpoint *bsc_endp, |
| 407 | struct bsc_connection *bsc) |
| 408 | { |
Holger Hans Peter Freyther | c021fbe | 2010-08-28 16:46:27 +0800 | [diff] [blame] | 409 | LOGP(DMGCP, LOGL_ERROR, "No CI, freeing endpoint 0x%x in state %d\n", |
| 410 | ENDPOINT_NUMBER(endp), bsc_endp->transaction_state); |
Holger Hans Peter Freyther | 7d47601 | 2010-08-06 19:16:34 +0800 | [diff] [blame] | 411 | |
Holger Hans Peter Freyther | c021fbe | 2010-08-28 16:46:27 +0800 | [diff] [blame] | 412 | /* if a CRCX failed... send a DLCX down the stream */ |
| 413 | if (bsc_endp->transaction_state == MGCP_ENDP_CRCX) { |
| 414 | struct sccp_connections *con; |
| 415 | con = bsc_mgcp_find_con(bsc->nat, ENDPOINT_NUMBER(endp)); |
| 416 | if (!con) { |
| 417 | LOGP(DMGCP, LOGL_ERROR, |
| 418 | "No SCCP connection for endp 0x%x\n", |
| 419 | ENDPOINT_NUMBER(endp)); |
| 420 | } else { |
| 421 | if (con->bsc == bsc) { |
Holger Hans Peter Freyther | 8574dcf | 2010-08-29 22:39:07 +0800 | [diff] [blame] | 422 | bsc_mgcp_send_dlcx(bsc, con->bsc_endp); |
Holger Hans Peter Freyther | 7d47601 | 2010-08-06 19:16:34 +0800 | [diff] [blame] | 423 | } else { |
Holger Hans Peter Freyther | c021fbe | 2010-08-28 16:46:27 +0800 | [diff] [blame] | 424 | LOGP(DMGCP, LOGL_ERROR, |
| 425 | "Endpoint belongs to a different BSC\n"); |
Holger Hans Peter Freyther | 7d47601 | 2010-08-06 19:16:34 +0800 | [diff] [blame] | 426 | } |
| 427 | } |
Holger Hans Peter Freyther | c021fbe | 2010-08-28 16:46:27 +0800 | [diff] [blame] | 428 | } |
Holger Hans Peter Freyther | 7d47601 | 2010-08-06 19:16:34 +0800 | [diff] [blame] | 429 | |
Holger Hans Peter Freyther | c021fbe | 2010-08-28 16:46:27 +0800 | [diff] [blame] | 430 | bsc_mgcp_free_endpoint(bsc->nat, ENDPOINT_NUMBER(endp)); |
| 431 | mgcp_free_endp(endp); |
Holger Hans Peter Freyther | 7d47601 | 2010-08-06 19:16:34 +0800 | [diff] [blame] | 432 | } |
| 433 | |
| 434 | /* |
Holger Hans Peter Freyther | 3c3bce1 | 2010-04-01 10:16:28 +0200 | [diff] [blame] | 435 | * We have received a msg from the BSC. We will see if we know |
| 436 | * this transaction and if it belongs to the BSC. Then we will |
| 437 | * need to patch the content to point to the local network and we |
| 438 | * need to update the I: that was assigned by the BSS. |
| 439 | */ |
| 440 | void bsc_mgcp_forward(struct bsc_connection *bsc, struct msgb *msg) |
| 441 | { |
| 442 | struct msgb *output; |
| 443 | struct bsc_endpoint *bsc_endp = NULL; |
| 444 | struct mgcp_endpoint *endp = NULL; |
Holger Hans Peter Freyther | d2dd6e8 | 2010-04-06 11:06:11 +0200 | [diff] [blame] | 445 | int i, code; |
Holger Hans Peter Freyther | 3c3bce1 | 2010-04-01 10:16:28 +0200 | [diff] [blame] | 446 | char transaction_id[60]; |
| 447 | |
| 448 | /* Some assumption that our buffer is big enough.. and null terminate */ |
| 449 | if (msgb_l2len(msg) > 2000) { |
| 450 | LOGP(DMGCP, LOGL_ERROR, "MGCP message too long.\n"); |
| 451 | return; |
| 452 | } |
| 453 | |
| 454 | msg->l2h[msgb_l2len(msg)] = '\0'; |
| 455 | |
| 456 | if (bsc_mgcp_parse_response((const char *) msg->l2h, &code, transaction_id) != 0) { |
| 457 | LOGP(DMGCP, LOGL_ERROR, "Failed to parse response code.\n"); |
| 458 | return; |
| 459 | } |
| 460 | |
Holger Hans Peter Freyther | 88ad772 | 2011-02-28 00:56:17 +0100 | [diff] [blame] | 461 | for (i = 1; i < bsc->nat->mgcp_cfg->trunk.number_endpoints; ++i) { |
Holger Hans Peter Freyther | 3c3bce1 | 2010-04-01 10:16:28 +0200 | [diff] [blame] | 462 | if (bsc->nat->bsc_endpoints[i].bsc != bsc) |
| 463 | continue; |
Holger Hans Peter Freyther | 3f7c7d0 | 2010-04-05 18:00:05 +0200 | [diff] [blame] | 464 | /* no one listening? a bug? */ |
| 465 | if (!bsc->nat->bsc_endpoints[i].transaction_id) |
| 466 | continue; |
Holger Hans Peter Freyther | 3c3bce1 | 2010-04-01 10:16:28 +0200 | [diff] [blame] | 467 | if (strcmp(transaction_id, bsc->nat->bsc_endpoints[i].transaction_id) != 0) |
| 468 | continue; |
| 469 | |
Holger Hans Peter Freyther | 88ad772 | 2011-02-28 00:56:17 +0100 | [diff] [blame] | 470 | endp = &bsc->nat->mgcp_cfg->trunk.endpoints[i]; |
Holger Hans Peter Freyther | 3c3bce1 | 2010-04-01 10:16:28 +0200 | [diff] [blame] | 471 | bsc_endp = &bsc->nat->bsc_endpoints[i]; |
| 472 | break; |
| 473 | } |
| 474 | |
| 475 | if (!bsc_endp) { |
Holger Hans Peter Freyther | b9ac37d | 2010-04-05 17:58:52 +0200 | [diff] [blame] | 476 | LOGP(DMGCP, LOGL_ERROR, "Could not find active endpoint: %s for msg: '%s'\n", |
| 477 | transaction_id, (const char *) msg->l2h); |
Holger Hans Peter Freyther | 3c3bce1 | 2010-04-01 10:16:28 +0200 | [diff] [blame] | 478 | return; |
| 479 | } |
| 480 | |
Holger Hans Peter Freyther | 7b7eef6 | 2010-04-22 12:08:17 +0800 | [diff] [blame] | 481 | endp->ci = bsc_mgcp_extract_ci((const char *) msg->l2h); |
Holger Hans Peter Freyther | b84b5f6 | 2010-08-06 08:34:46 +0800 | [diff] [blame] | 482 | if (endp->ci == CI_UNUSED) { |
Holger Hans Peter Freyther | 7d47601 | 2010-08-06 19:16:34 +0800 | [diff] [blame] | 483 | free_chan_downstream(endp, bsc_endp, bsc); |
Holger Hans Peter Freyther | b84b5f6 | 2010-08-06 08:34:46 +0800 | [diff] [blame] | 484 | return; |
| 485 | } |
Holger Hans Peter Freyther | dd16b42 | 2010-04-07 09:53:54 +0200 | [diff] [blame] | 486 | |
Holger Hans Peter Freyther | 3c3bce1 | 2010-04-01 10:16:28 +0200 | [diff] [blame] | 487 | /* free some stuff */ |
| 488 | talloc_free(bsc_endp->transaction_id); |
| 489 | bsc_endp->transaction_id = NULL; |
Holger Hans Peter Freyther | 5b2726e | 2010-08-06 09:05:05 +0800 | [diff] [blame] | 490 | bsc_endp->transaction_state = 0; |
Holger Hans Peter Freyther | 3c3bce1 | 2010-04-01 10:16:28 +0200 | [diff] [blame] | 491 | |
Holger Hans Peter Freyther | dd16b42 | 2010-04-07 09:53:54 +0200 | [diff] [blame] | 492 | /* |
| 493 | * rewrite the information. In case the endpoint was deleted |
| 494 | * there should be nothing for us to rewrite so putting endp->rtp_port |
| 495 | * with the value of 0 should be no problem. |
| 496 | */ |
Holger Hans Peter Freyther | f7c86c5 | 2010-08-30 13:44:32 +0800 | [diff] [blame] | 497 | output = bsc_mgcp_rewrite((char * ) msg->l2h, msgb_l2len(msg), -1, |
Holger Hans Peter Freyther | 58ff219 | 2010-08-05 03:08:35 +0800 | [diff] [blame] | 498 | bsc->nat->mgcp_cfg->source_addr, endp->net_end.local_port); |
Holger Hans Peter Freyther | 5cc94fb | 2010-04-05 22:56:49 +0200 | [diff] [blame] | 499 | |
Holger Hans Peter Freyther | 3c3bce1 | 2010-04-01 10:16:28 +0200 | [diff] [blame] | 500 | if (!output) { |
| 501 | LOGP(DMGCP, LOGL_ERROR, "Failed to rewrite MGCP msg.\n"); |
| 502 | return; |
| 503 | } |
| 504 | |
Pablo Neira Ayuso | e1273b1 | 2011-05-06 12:09:47 +0200 | [diff] [blame] | 505 | if (osmo_wqueue_enqueue(&bsc->nat->mgcp_cfg->gw_fd, output) != 0) { |
Holger Hans Peter Freyther | 3c3bce1 | 2010-04-01 10:16:28 +0200 | [diff] [blame] | 506 | LOGP(DMGCP, LOGL_ERROR, "Failed to queue MGCP msg.\n"); |
| 507 | msgb_free(output); |
| 508 | } |
| 509 | } |
| 510 | |
| 511 | int bsc_mgcp_parse_response(const char *str, int *code, char transaction[60]) |
| 512 | { |
| 513 | /* we want to parse two strings */ |
| 514 | return sscanf(str, "%3d %59s\n", code, transaction) != 2; |
| 515 | } |
| 516 | |
Holger Hans Peter Freyther | 4634013 | 2010-08-06 08:26:54 +0800 | [diff] [blame] | 517 | uint32_t bsc_mgcp_extract_ci(const char *str) |
Holger Hans Peter Freyther | 3c3bce1 | 2010-04-01 10:16:28 +0200 | [diff] [blame] | 518 | { |
Holger Hans Peter Freyther | 4634013 | 2010-08-06 08:26:54 +0800 | [diff] [blame] | 519 | unsigned int ci; |
Holger Hans Peter Freyther | 3c3bce1 | 2010-04-01 10:16:28 +0200 | [diff] [blame] | 520 | char *res = strstr(str, "I: "); |
Holger Hans Peter Freyther | 9c31cfc | 2010-08-06 08:19:05 +0800 | [diff] [blame] | 521 | if (!res) { |
| 522 | LOGP(DMGCP, LOGL_ERROR, "No CI in msg '%s'\n", str); |
Holger Hans Peter Freyther | 3c3bce1 | 2010-04-01 10:16:28 +0200 | [diff] [blame] | 523 | return CI_UNUSED; |
Holger Hans Peter Freyther | 9c31cfc | 2010-08-06 08:19:05 +0800 | [diff] [blame] | 524 | } |
Holger Hans Peter Freyther | 3c3bce1 | 2010-04-01 10:16:28 +0200 | [diff] [blame] | 525 | |
Holger Hans Peter Freyther | 4634013 | 2010-08-06 08:26:54 +0800 | [diff] [blame] | 526 | if (sscanf(res, "I: %u", &ci) != 1) { |
Holger Hans Peter Freyther | 9c31cfc | 2010-08-06 08:19:05 +0800 | [diff] [blame] | 527 | LOGP(DMGCP, LOGL_ERROR, "Failed to parse CI in msg '%s'\n", str); |
Holger Hans Peter Freyther | 3c3bce1 | 2010-04-01 10:16:28 +0200 | [diff] [blame] | 528 | return CI_UNUSED; |
Holger Hans Peter Freyther | 9c31cfc | 2010-08-06 08:19:05 +0800 | [diff] [blame] | 529 | } |
| 530 | |
Holger Hans Peter Freyther | 3c3bce1 | 2010-04-01 10:16:28 +0200 | [diff] [blame] | 531 | return ci; |
| 532 | } |
| 533 | |
Holger Hans Peter Freyther | 9592c45 | 2012-01-17 15:58:48 +0100 | [diff] [blame] | 534 | /** |
| 535 | * Create a new MGCPCommand based on the input and endpoint from a message |
| 536 | */ |
Holger Hans Peter Freyther | f7c86c5 | 2010-08-30 13:44:32 +0800 | [diff] [blame] | 537 | static void patch_mgcp(struct msgb *output, const char *op, const char *tok, |
| 538 | int endp, int len, int cr) |
Holger Hans Peter Freyther | 76c8354 | 2010-04-01 06:48:52 +0200 | [diff] [blame] | 539 | { |
Holger Hans Peter Freyther | f7c86c5 | 2010-08-30 13:44:32 +0800 | [diff] [blame] | 540 | int slen; |
| 541 | int ret; |
| 542 | char buf[40]; |
| 543 | |
| 544 | buf[0] = buf[39] = '\0'; |
| 545 | ret = sscanf(tok, "%*s %s", buf); |
Holger Hans Peter Freyther | 9592c45 | 2012-01-17 15:58:48 +0100 | [diff] [blame] | 546 | if (ret != 1) { |
| 547 | LOGP(DMGCP, LOGL_ERROR, |
| 548 | "Failed to find Endpoint in: %s\n", tok); |
| 549 | return; |
| 550 | } |
Holger Hans Peter Freyther | f7c86c5 | 2010-08-30 13:44:32 +0800 | [diff] [blame] | 551 | |
| 552 | slen = sprintf((char *) output->l3h, "%s %s %x@mgw MGCP 1.0%s", |
| 553 | op, buf, endp, cr ? "\r\n" : "\n"); |
| 554 | output->l3h = msgb_put(output, slen); |
| 555 | } |
| 556 | |
| 557 | /* we need to replace some strings... */ |
| 558 | struct msgb *bsc_mgcp_rewrite(char *input, int length, int endpoint, const char *ip, int port) |
| 559 | { |
Holger Hans Peter Freyther | 3dfe8a1 | 2012-11-07 11:36:58 +0100 | [diff] [blame] | 560 | static const char crcx_str[] = "CRCX "; |
| 561 | static const char dlcx_str[] = "DLCX "; |
| 562 | static const char mdcx_str[] = "MDCX "; |
Holger Hans Peter Freyther | f7c86c5 | 2010-08-30 13:44:32 +0800 | [diff] [blame] | 563 | |
Holger Hans Peter Freyther | 3dfe8a1 | 2012-11-07 11:36:58 +0100 | [diff] [blame] | 564 | static const char ip_str[] = "c=IN IP4 "; |
| 565 | static const char aud_str[] = "m=audio "; |
| 566 | static const char fmt_str[] = "a=fmtp:"; |
Holger Hans Peter Freyther | 76c8354 | 2010-04-01 06:48:52 +0200 | [diff] [blame] | 567 | |
| 568 | char buf[128]; |
| 569 | char *running, *token; |
| 570 | struct msgb *output; |
| 571 | |
Holger Hans Peter Freyther | e2f34d5 | 2012-11-06 13:16:26 +0100 | [diff] [blame] | 572 | /* keep state to add the a=fmtp line */ |
| 573 | int found_fmtp = 0; |
| 574 | int payload = -1; |
| 575 | int cr = 1; |
| 576 | |
| 577 | if (length > 4096 - 256) { |
Holger Hans Peter Freyther | 76c8354 | 2010-04-01 06:48:52 +0200 | [diff] [blame] | 578 | LOGP(DMGCP, LOGL_ERROR, "Input is too long.\n"); |
| 579 | return NULL; |
| 580 | } |
| 581 | |
| 582 | output = msgb_alloc_headroom(4096, 128, "MGCP rewritten"); |
| 583 | if (!output) { |
| 584 | LOGP(DMGCP, LOGL_ERROR, "Failed to allocate new MGCP msg.\n"); |
| 585 | return NULL; |
| 586 | } |
| 587 | |
Holger Hans Peter Freyther | 8d20065 | 2010-04-04 18:09:10 +0200 | [diff] [blame] | 588 | running = input; |
Holger Hans Peter Freyther | 76c8354 | 2010-04-01 06:48:52 +0200 | [diff] [blame] | 589 | output->l2h = output->data; |
Holger Hans Peter Freyther | f7c86c5 | 2010-08-30 13:44:32 +0800 | [diff] [blame] | 590 | output->l3h = output->l2h; |
Holger Hans Peter Freyther | 9e5300a | 2010-04-04 19:34:44 +0200 | [diff] [blame] | 591 | for (token = strsep(&running, "\n"); running; token = strsep(&running, "\n")) { |
Holger Hans Peter Freyther | 76c8354 | 2010-04-01 06:48:52 +0200 | [diff] [blame] | 592 | int len = strlen(token); |
Holger Hans Peter Freyther | e2f34d5 | 2012-11-06 13:16:26 +0100 | [diff] [blame] | 593 | cr = len > 0 && token[len - 1] == '\r'; |
Holger Hans Peter Freyther | 76c8354 | 2010-04-01 06:48:52 +0200 | [diff] [blame] | 594 | |
Holger Hans Peter Freyther | f7c86c5 | 2010-08-30 13:44:32 +0800 | [diff] [blame] | 595 | if (strncmp(crcx_str, token, (sizeof crcx_str) - 1) == 0) { |
| 596 | patch_mgcp(output, "CRCX", token, endpoint, len, cr); |
| 597 | } else if (strncmp(dlcx_str, token, (sizeof dlcx_str) - 1) == 0) { |
| 598 | patch_mgcp(output, "DLCX", token, endpoint, len, cr); |
| 599 | } else if (strncmp(mdcx_str, token, (sizeof mdcx_str) - 1) == 0) { |
| 600 | patch_mgcp(output, "MDCX", token, endpoint, len, cr); |
| 601 | } else if (strncmp(ip_str, token, (sizeof ip_str) - 1) == 0) { |
Holger Hans Peter Freyther | 76c8354 | 2010-04-01 06:48:52 +0200 | [diff] [blame] | 602 | output->l3h = msgb_put(output, strlen(ip_str)); |
| 603 | memcpy(output->l3h, ip_str, strlen(ip_str)); |
| 604 | output->l3h = msgb_put(output, strlen(ip)); |
| 605 | memcpy(output->l3h, ip, strlen(ip)); |
Holger Hans Peter Freyther | 9e5300a | 2010-04-04 19:34:44 +0200 | [diff] [blame] | 606 | |
| 607 | if (cr) { |
| 608 | output->l3h = msgb_put(output, 2); |
| 609 | output->l3h[0] = '\r'; |
| 610 | output->l3h[1] = '\n'; |
| 611 | } else { |
| 612 | output->l3h = msgb_put(output, 1); |
| 613 | output->l3h[0] = '\n'; |
| 614 | } |
Holger Hans Peter Freyther | 76c8354 | 2010-04-01 06:48:52 +0200 | [diff] [blame] | 615 | } else if (strncmp(aud_str, token, (sizeof aud_str) - 1) == 0) { |
Holger Hans Peter Freyther | 76c8354 | 2010-04-01 06:48:52 +0200 | [diff] [blame] | 616 | if (sscanf(token, "m=audio %*d RTP/AVP %d", &payload) != 1) { |
| 617 | LOGP(DMGCP, LOGL_ERROR, "Could not parsed audio line.\n"); |
| 618 | msgb_free(output); |
| 619 | return NULL; |
| 620 | } |
| 621 | |
Holger Hans Peter Freyther | 9e5300a | 2010-04-04 19:34:44 +0200 | [diff] [blame] | 622 | snprintf(buf, sizeof(buf)-1, "m=audio %d RTP/AVP %d%s", |
| 623 | port, payload, cr ? "\r\n" : "\n"); |
Holger Hans Peter Freyther | 76c8354 | 2010-04-01 06:48:52 +0200 | [diff] [blame] | 624 | buf[sizeof(buf)-1] = '\0'; |
| 625 | |
| 626 | output->l3h = msgb_put(output, strlen(buf)); |
| 627 | memcpy(output->l3h, buf, strlen(buf)); |
Holger Hans Peter Freyther | e2f34d5 | 2012-11-06 13:16:26 +0100 | [diff] [blame] | 628 | } else if (strncmp(fmt_str, token, (sizeof fmt_str) - 1) == 0) { |
| 629 | found_fmtp = 1; |
| 630 | goto copy; |
Holger Hans Peter Freyther | 76c8354 | 2010-04-01 06:48:52 +0200 | [diff] [blame] | 631 | } else { |
Holger Hans Peter Freyther | e2f34d5 | 2012-11-06 13:16:26 +0100 | [diff] [blame] | 632 | copy: |
Holger Hans Peter Freyther | 76c8354 | 2010-04-01 06:48:52 +0200 | [diff] [blame] | 633 | output->l3h = msgb_put(output, len + 1); |
| 634 | memcpy(output->l3h, token, len); |
| 635 | output->l3h[len] = '\n'; |
| 636 | } |
| 637 | } |
| 638 | |
Holger Hans Peter Freyther | e2f34d5 | 2012-11-06 13:16:26 +0100 | [diff] [blame] | 639 | /* |
| 640 | * the above code made sure that we have 128 bytes lefts. So we can |
| 641 | * safely append another line. |
| 642 | */ |
| 643 | if (!found_fmtp && payload != -1) { |
| 644 | snprintf(buf, sizeof(buf) - 1, "a=fmtp:%d mode-set=2%s", |
| 645 | payload, cr ? "\r\n" : "\n"); |
| 646 | buf[sizeof(buf) - 1] = '\0'; |
| 647 | output->l3h = msgb_put(output, strlen(buf)); |
| 648 | memcpy(output->l3h, buf, strlen(buf)); |
| 649 | } |
| 650 | |
Holger Hans Peter Freyther | 76c8354 | 2010-04-01 06:48:52 +0200 | [diff] [blame] | 651 | return output; |
| 652 | } |
| 653 | |
Pablo Neira Ayuso | 4db9299 | 2011-05-06 12:11:23 +0200 | [diff] [blame] | 654 | static int mgcp_do_read(struct osmo_fd *fd) |
Holger Hans Peter Freyther | a7f8018 | 2010-03-31 13:02:22 +0200 | [diff] [blame] | 655 | { |
| 656 | struct bsc_nat *nat; |
| 657 | struct msgb *msg, *resp; |
| 658 | int rc; |
| 659 | |
Holger Hans Peter Freyther | 8d20065 | 2010-04-04 18:09:10 +0200 | [diff] [blame] | 660 | nat = fd->data; |
| 661 | |
| 662 | rc = read(fd->fd, nat->mgcp_msg, sizeof(nat->mgcp_msg) - 1); |
| 663 | if (rc <= 0) { |
| 664 | LOGP(DMGCP, LOGL_ERROR, "Failed to read errno: %d\n", errno); |
| 665 | return -1; |
| 666 | } |
| 667 | |
| 668 | nat->mgcp_msg[rc] = '\0'; |
| 669 | nat->mgcp_length = rc; |
| 670 | |
| 671 | msg = msgb_alloc(sizeof(nat->mgcp_msg), "MGCP GW Read"); |
Holger Hans Peter Freyther | a7f8018 | 2010-03-31 13:02:22 +0200 | [diff] [blame] | 672 | if (!msg) { |
| 673 | LOGP(DMGCP, LOGL_ERROR, "Failed to create buffer.\n"); |
| 674 | return -1; |
| 675 | } |
| 676 | |
Holger Hans Peter Freyther | a7f8018 | 2010-03-31 13:02:22 +0200 | [diff] [blame] | 677 | msg->l2h = msgb_put(msg, rc); |
Holger Hans Peter Freyther | 8d20065 | 2010-04-04 18:09:10 +0200 | [diff] [blame] | 678 | memcpy(msg->l2h, nat->mgcp_msg, msgb_l2len(msg)); |
Holger Hans Peter Freyther | a7f8018 | 2010-03-31 13:02:22 +0200 | [diff] [blame] | 679 | resp = mgcp_handle_message(nat->mgcp_cfg, msg); |
| 680 | msgb_free(msg); |
| 681 | |
| 682 | /* we do have a direct answer... e.g. AUEP */ |
| 683 | if (resp) { |
Pablo Neira Ayuso | e1273b1 | 2011-05-06 12:09:47 +0200 | [diff] [blame] | 684 | if (osmo_wqueue_enqueue(&nat->mgcp_cfg->gw_fd, resp) != 0) { |
Holger Hans Peter Freyther | a7f8018 | 2010-03-31 13:02:22 +0200 | [diff] [blame] | 685 | LOGP(DMGCP, LOGL_ERROR, "Failed to enqueue msg.\n"); |
| 686 | msgb_free(resp); |
| 687 | } |
| 688 | } |
| 689 | |
| 690 | return 0; |
| 691 | } |
| 692 | |
Pablo Neira Ayuso | 4db9299 | 2011-05-06 12:11:23 +0200 | [diff] [blame] | 693 | static int mgcp_do_write(struct osmo_fd *bfd, struct msgb *msg) |
Holger Hans Peter Freyther | a7f8018 | 2010-03-31 13:02:22 +0200 | [diff] [blame] | 694 | { |
| 695 | int rc; |
| 696 | |
| 697 | rc = write(bfd->fd, msg->data, msg->len); |
| 698 | |
| 699 | if (rc != msg->len) { |
| 700 | LOGP(DMGCP, LOGL_ERROR, "Failed to write msg to MGCP CallAgent.\n"); |
| 701 | return -1; |
| 702 | } |
| 703 | |
| 704 | return rc; |
| 705 | } |
| 706 | |
Holger Hans Peter Freyther | 7b7eef6 | 2010-04-22 12:08:17 +0800 | [diff] [blame] | 707 | int bsc_mgcp_nat_init(struct bsc_nat *nat) |
Holger Hans Peter Freyther | a7f8018 | 2010-03-31 13:02:22 +0200 | [diff] [blame] | 708 | { |
| 709 | int on; |
| 710 | struct sockaddr_in addr; |
Holger Hans Peter Freyther | 249d69a | 2010-09-18 21:13:54 +0800 | [diff] [blame] | 711 | struct mgcp_config *cfg = nat->mgcp_cfg; |
Holger Hans Peter Freyther | a7f8018 | 2010-03-31 13:02:22 +0200 | [diff] [blame] | 712 | |
Holger Hans Peter Freyther | 249d69a | 2010-09-18 21:13:54 +0800 | [diff] [blame] | 713 | if (!cfg->call_agent_addr) { |
Holger Hans Peter Freyther | a7f8018 | 2010-03-31 13:02:22 +0200 | [diff] [blame] | 714 | LOGP(DMGCP, LOGL_ERROR, "The BSC nat requires the call agent ip to be set.\n"); |
| 715 | return -1; |
| 716 | } |
| 717 | |
Holger Hans Peter Freyther | 249d69a | 2010-09-18 21:13:54 +0800 | [diff] [blame] | 718 | if (cfg->bts_ip) { |
Holger Hans Peter Freyther | a0df82d | 2010-04-01 08:21:33 +0200 | [diff] [blame] | 719 | LOGP(DMGCP, LOGL_ERROR, "Do not set the BTS ip for the nat.\n"); |
| 720 | return -1; |
| 721 | } |
| 722 | |
Holger Hans Peter Freyther | 249d69a | 2010-09-18 21:13:54 +0800 | [diff] [blame] | 723 | cfg->gw_fd.bfd.fd = socket(AF_INET, SOCK_DGRAM, 0); |
| 724 | if (cfg->gw_fd.bfd.fd < 0) { |
Holger Hans Peter Freyther | a7f8018 | 2010-03-31 13:02:22 +0200 | [diff] [blame] | 725 | LOGP(DMGCP, LOGL_ERROR, "Failed to create MGCP socket. errno: %d\n", errno); |
| 726 | return -1; |
| 727 | } |
| 728 | |
| 729 | on = 1; |
Holger Hans Peter Freyther | 249d69a | 2010-09-18 21:13:54 +0800 | [diff] [blame] | 730 | setsockopt(cfg->gw_fd.bfd.fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)); |
Holger Hans Peter Freyther | a7f8018 | 2010-03-31 13:02:22 +0200 | [diff] [blame] | 731 | |
| 732 | addr.sin_family = AF_INET; |
Holger Hans Peter Freyther | 249d69a | 2010-09-18 21:13:54 +0800 | [diff] [blame] | 733 | addr.sin_port = htons(cfg->source_port); |
| 734 | inet_aton(cfg->source_addr, &addr.sin_addr); |
Holger Hans Peter Freyther | a7f8018 | 2010-03-31 13:02:22 +0200 | [diff] [blame] | 735 | |
Holger Hans Peter Freyther | 249d69a | 2010-09-18 21:13:54 +0800 | [diff] [blame] | 736 | if (bind(cfg->gw_fd.bfd.fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) { |
Holger Hans Peter Freyther | d000c27 | 2011-03-29 17:12:07 +0200 | [diff] [blame] | 737 | LOGP(DMGCP, LOGL_ERROR, "Failed to bind on %s:%d errno: %d\n", |
| 738 | cfg->source_addr, cfg->source_port, errno); |
Holger Hans Peter Freyther | 249d69a | 2010-09-18 21:13:54 +0800 | [diff] [blame] | 739 | close(cfg->gw_fd.bfd.fd); |
| 740 | cfg->gw_fd.bfd.fd = -1; |
Holger Hans Peter Freyther | a7f8018 | 2010-03-31 13:02:22 +0200 | [diff] [blame] | 741 | return -1; |
| 742 | } |
| 743 | |
| 744 | addr.sin_port = htons(2727); |
Holger Hans Peter Freyther | 249d69a | 2010-09-18 21:13:54 +0800 | [diff] [blame] | 745 | inet_aton(cfg->call_agent_addr, &addr.sin_addr); |
| 746 | if (connect(cfg->gw_fd.bfd.fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) { |
Holger Hans Peter Freyther | a7f8018 | 2010-03-31 13:02:22 +0200 | [diff] [blame] | 747 | LOGP(DMGCP, LOGL_ERROR, "Failed to connect to: '%s'. errno: %d\n", |
Holger Hans Peter Freyther | 249d69a | 2010-09-18 21:13:54 +0800 | [diff] [blame] | 748 | cfg->call_agent_addr, errno); |
| 749 | close(cfg->gw_fd.bfd.fd); |
| 750 | cfg->gw_fd.bfd.fd = -1; |
Holger Hans Peter Freyther | a7f8018 | 2010-03-31 13:02:22 +0200 | [diff] [blame] | 751 | return -1; |
| 752 | } |
| 753 | |
Pablo Neira Ayuso | e1273b1 | 2011-05-06 12:09:47 +0200 | [diff] [blame] | 754 | osmo_wqueue_init(&cfg->gw_fd, 10); |
Holger Hans Peter Freyther | 249d69a | 2010-09-18 21:13:54 +0800 | [diff] [blame] | 755 | cfg->gw_fd.bfd.when = BSC_FD_READ; |
| 756 | cfg->gw_fd.bfd.data = nat; |
| 757 | cfg->gw_fd.read_cb = mgcp_do_read; |
| 758 | cfg->gw_fd.write_cb = mgcp_do_write; |
Holger Hans Peter Freyther | a7f8018 | 2010-03-31 13:02:22 +0200 | [diff] [blame] | 759 | |
Pablo Neira Ayuso | 4db9299 | 2011-05-06 12:11:23 +0200 | [diff] [blame] | 760 | if (osmo_fd_register(&cfg->gw_fd.bfd) != 0) { |
Holger Hans Peter Freyther | a7f8018 | 2010-03-31 13:02:22 +0200 | [diff] [blame] | 761 | LOGP(DMGCP, LOGL_ERROR, "Failed to register MGCP fd.\n"); |
Holger Hans Peter Freyther | 249d69a | 2010-09-18 21:13:54 +0800 | [diff] [blame] | 762 | close(cfg->gw_fd.bfd.fd); |
| 763 | cfg->gw_fd.bfd.fd = -1; |
Holger Hans Peter Freyther | a7f8018 | 2010-03-31 13:02:22 +0200 | [diff] [blame] | 764 | return -1; |
| 765 | } |
| 766 | |
Holger Hans Peter Freyther | a0df82d | 2010-04-01 08:21:33 +0200 | [diff] [blame] | 767 | /* some more MGCP config handling */ |
Holger Hans Peter Freyther | 249d69a | 2010-09-18 21:13:54 +0800 | [diff] [blame] | 768 | cfg->data = nat; |
| 769 | cfg->policy_cb = bsc_mgcp_policy_cb; |
Holger Hans Peter Freyther | 88ad772 | 2011-02-28 00:56:17 +0100 | [diff] [blame] | 770 | cfg->trunk.force_realloc = 1; |
Holger Hans Peter Freyther | d5e6c23 | 2010-08-05 10:08:36 +0000 | [diff] [blame] | 771 | |
Holger Hans Peter Freyther | 249d69a | 2010-09-18 21:13:54 +0800 | [diff] [blame] | 772 | if (cfg->bts_ip) |
| 773 | talloc_free(cfg->bts_ip); |
| 774 | cfg->bts_ip = ""; |
Holger Hans Peter Freyther | d5e6c23 | 2010-08-05 10:08:36 +0000 | [diff] [blame] | 775 | |
Holger Hans Peter Freyther | a0df82d | 2010-04-01 08:21:33 +0200 | [diff] [blame] | 776 | nat->bsc_endpoints = talloc_zero_array(nat, |
| 777 | struct bsc_endpoint, |
Holger Hans Peter Freyther | 88ad772 | 2011-02-28 00:56:17 +0100 | [diff] [blame] | 778 | cfg->trunk.number_endpoints + 1); |
Holger Hans Peter Freyther | 3c79214 | 2010-09-19 04:34:04 +0800 | [diff] [blame] | 779 | if (!nat->bsc_endpoints) { |
| 780 | LOGP(DMGCP, LOGL_ERROR, "Failed to allocate nat endpoints\n"); |
Holger Hans Peter Freyther | 249d69a | 2010-09-18 21:13:54 +0800 | [diff] [blame] | 781 | close(cfg->gw_fd.bfd.fd); |
| 782 | cfg->gw_fd.bfd.fd = -1; |
Holger Hans Peter Freyther | 3c79214 | 2010-09-19 04:34:04 +0800 | [diff] [blame] | 783 | return -1; |
| 784 | } |
Holger Hans Peter Freyther | a0df82d | 2010-04-01 08:21:33 +0200 | [diff] [blame] | 785 | |
Holger Hans Peter Freyther | f2eedff | 2010-09-19 04:36:07 +0800 | [diff] [blame] | 786 | if (mgcp_reset_transcoder(cfg) < 0) { |
| 787 | LOGP(DMGCP, LOGL_ERROR, "Failed to send packet to the transcoder.\n"); |
| 788 | talloc_free(nat->bsc_endpoints); |
| 789 | nat->bsc_endpoints = NULL; |
| 790 | close(cfg->gw_fd.bfd.fd); |
| 791 | cfg->gw_fd.bfd.fd = -1; |
| 792 | return -1; |
| 793 | } |
| 794 | |
Holger Hans Peter Freyther | a7f8018 | 2010-03-31 13:02:22 +0200 | [diff] [blame] | 795 | return 0; |
| 796 | } |
Holger Hans Peter Freyther | 26a4389 | 2010-04-05 23:09:27 +0200 | [diff] [blame] | 797 | |
| 798 | void bsc_mgcp_clear_endpoints_for(struct bsc_connection *bsc) |
| 799 | { |
Holger Hans Peter Freyther | 8330c1c | 2010-06-17 18:29:42 +0800 | [diff] [blame] | 800 | struct rate_ctr *ctr = NULL; |
Holger Hans Peter Freyther | 26a4389 | 2010-04-05 23:09:27 +0200 | [diff] [blame] | 801 | int i; |
Holger Hans Peter Freyther | 8330c1c | 2010-06-17 18:29:42 +0800 | [diff] [blame] | 802 | |
| 803 | if (bsc->cfg) |
| 804 | ctr = &bsc->cfg->stats.ctrg->ctr[BCFG_CTR_DROPPED_CALLS]; |
| 805 | |
Holger Hans Peter Freyther | 88ad772 | 2011-02-28 00:56:17 +0100 | [diff] [blame] | 806 | for (i = 1; i < bsc->nat->mgcp_cfg->trunk.number_endpoints; ++i) { |
Holger Hans Peter Freyther | 26a4389 | 2010-04-05 23:09:27 +0200 | [diff] [blame] | 807 | struct bsc_endpoint *bsc_endp = &bsc->nat->bsc_endpoints[i]; |
| 808 | |
| 809 | if (bsc_endp->bsc != bsc) |
| 810 | continue; |
| 811 | |
Holger Hans Peter Freyther | 8330c1c | 2010-06-17 18:29:42 +0800 | [diff] [blame] | 812 | if (ctr) |
| 813 | rate_ctr_inc(ctr); |
| 814 | |
Holger Hans Peter Freyther | 7b7eef6 | 2010-04-22 12:08:17 +0800 | [diff] [blame] | 815 | bsc_mgcp_free_endpoint(bsc->nat, i); |
Holger Hans Peter Freyther | 88ad772 | 2011-02-28 00:56:17 +0100 | [diff] [blame] | 816 | mgcp_free_endp(&bsc->nat->mgcp_cfg->trunk.endpoints[i]); |
Holger Hans Peter Freyther | 26a4389 | 2010-04-05 23:09:27 +0200 | [diff] [blame] | 817 | } |
| 818 | } |