Holger Hans Peter Freyther | 465313e | 2010-06-15 18:49:53 +0800 | [diff] [blame] | 1 | /* |
| 2 | * (C) 2010 by Holger Hans Peter Freyther <zecke@selfish.org> |
| 3 | * (C) 2010 by On-Waves |
| 4 | * All Rights Reserved |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License along |
| 17 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 18 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | #include <openbsc/bsc_nat.h> |
Holger Hans Peter Freyther | c2b31ed | 2010-07-31 05:17:17 +0800 | [diff] [blame] | 23 | #include <openbsc/bsc_nat_sccp.h> |
Holger Hans Peter Freyther | 465313e | 2010-06-15 18:49:53 +0800 | [diff] [blame] | 24 | #include <openbsc/gsm_data.h> |
Holger Hans Peter Freyther | 465313e | 2010-06-15 18:49:53 +0800 | [diff] [blame] | 25 | #include <openbsc/debug.h> |
Holger Hans Peter Freyther | 241e130 | 2010-03-31 09:16:56 +0200 | [diff] [blame] | 26 | #include <openbsc/mgcp.h> |
| 27 | #include <openbsc/mgcp_internal.h> |
Holger Hans Peter Freyther | 465313e | 2010-06-15 18:49:53 +0800 | [diff] [blame] | 28 | |
Harald Welte | d5db12c | 2010-08-03 15:11:51 +0200 | [diff] [blame] | 29 | #include <osmocom/sccp/sccp.h> |
Holger Hans Peter Freyther | 7b7eef6 | 2010-04-22 12:08:17 +0800 | [diff] [blame] | 30 | |
Holger Hans Peter Freyther | a0df82d | 2010-04-01 08:21:33 +0200 | [diff] [blame] | 31 | #include <osmocore/talloc.h> |
Holger Hans Peter Freyther | 1395948 | 2010-06-15 18:50:57 +0800 | [diff] [blame] | 32 | #include <osmocore/gsm0808.h> |
Holger Hans Peter Freyther | 69d801e | 2010-06-15 20:13:33 +0800 | [diff] [blame] | 33 | #include <osmocore/protocol/gsm_08_08.h> |
Holger Hans Peter Freyther | a0df82d | 2010-04-01 08:21:33 +0200 | [diff] [blame] | 34 | |
Holger Hans Peter Freyther | 465313e | 2010-06-15 18:49:53 +0800 | [diff] [blame] | 35 | #include <netinet/in.h> |
| 36 | #include <arpa/inet.h> |
| 37 | |
Holger Hans Peter Freyther | a7f8018 | 2010-03-31 13:02:22 +0200 | [diff] [blame] | 38 | #include <errno.h> |
| 39 | #include <unistd.h> |
| 40 | |
Holger Hans Peter Freyther | 465313e | 2010-06-15 18:49:53 +0800 | [diff] [blame] | 41 | int bsc_mgcp_assign(struct sccp_connections *con, struct msgb *msg) |
| 42 | { |
Holger Hans Peter Freyther | 7b7eef6 | 2010-04-22 12:08:17 +0800 | [diff] [blame] | 43 | struct sccp_connections *mcon; |
Holger Hans Peter Freyther | 465313e | 2010-06-15 18:49:53 +0800 | [diff] [blame] | 44 | struct tlv_parsed tp; |
Holger Hans Peter Freyther | e2c1520 | 2010-07-23 19:09:21 +0800 | [diff] [blame] | 45 | uint16_t cic; |
Holger Hans Peter Freyther | dbd16fe | 2010-07-23 19:08:55 +0800 | [diff] [blame] | 46 | uint8_t timeslot; |
| 47 | uint8_t multiplex; |
Holger Hans Peter Freyther | 7b7eef6 | 2010-04-22 12:08:17 +0800 | [diff] [blame] | 48 | int combined; |
Holger Hans Peter Freyther | 465313e | 2010-06-15 18:49:53 +0800 | [diff] [blame] | 49 | |
| 50 | if (!msg->l3h) { |
| 51 | LOGP(DNAT, LOGL_ERROR, "Assignment message should have l3h pointer.\n"); |
| 52 | return -1; |
| 53 | } |
| 54 | |
| 55 | if (msgb_l3len(msg) < 3) { |
| 56 | LOGP(DNAT, LOGL_ERROR, "Assignment message has not enough space for GSM0808.\n"); |
| 57 | return -1; |
| 58 | } |
| 59 | |
| 60 | tlv_parse(&tp, gsm0808_att_tlvdef(), msg->l3h + 3, msgb_l3len(msg) - 3, 0, 0); |
| 61 | if (!TLVP_PRESENT(&tp, GSM0808_IE_CIRCUIT_IDENTITY_CODE)) { |
| 62 | LOGP(DNAT, LOGL_ERROR, "Circuit identity code not found in assignment message.\n"); |
| 63 | return -1; |
| 64 | } |
| 65 | |
Holger Hans Peter Freyther | e2c1520 | 2010-07-23 19:09:21 +0800 | [diff] [blame] | 66 | 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] | 67 | timeslot = cic & 0x1f; |
| 68 | multiplex = (cic & ~0x1f) >> 5; |
| 69 | |
Holger Hans Peter Freyther | 7b7eef6 | 2010-04-22 12:08:17 +0800 | [diff] [blame] | 70 | |
| 71 | combined = (32 * multiplex) + timeslot; |
| 72 | |
| 73 | /* find stale connections using that endpoint */ |
| 74 | llist_for_each_entry(mcon, &con->bsc->nat->sccp_connections, list_entry) { |
| 75 | if (mcon->msc_timeslot == combined) { |
| 76 | LOGP(DNAT, LOGL_ERROR, |
| 77 | "Timeslot %d was assigned to 0x%x and now 0x%x\n", |
| 78 | combined, |
| 79 | sccp_src_ref_to_int(&mcon->patched_ref), |
| 80 | sccp_src_ref_to_int(&con->patched_ref)); |
| 81 | bsc_mgcp_dlcx(mcon); |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | con->msc_timeslot = combined; |
Holger Hans Peter Freyther | 465313e | 2010-06-15 18:49:53 +0800 | [diff] [blame] | 86 | con->bsc_timeslot = con->msc_timeslot; |
| 87 | return 0; |
| 88 | } |
| 89 | |
Holger Hans Peter Freyther | 7b7eef6 | 2010-04-22 12:08:17 +0800 | [diff] [blame] | 90 | 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] | 91 | { |
| 92 | if (nat->bsc_endpoints[i].transaction_id) { |
| 93 | talloc_free(nat->bsc_endpoints[i].transaction_id); |
| 94 | nat->bsc_endpoints[i].transaction_id = NULL; |
| 95 | } |
| 96 | |
Holger Hans Peter Freyther | 5b2726e | 2010-08-06 09:05:05 +0800 | [diff] [blame] | 97 | nat->bsc_endpoints[i].transaction_state = 0; |
Holger Hans Peter Freyther | a0df82d | 2010-04-01 08:21:33 +0200 | [diff] [blame] | 98 | nat->bsc_endpoints[i].bsc = NULL; |
Holger Hans Peter Freyther | a0df82d | 2010-04-01 08:21:33 +0200 | [diff] [blame] | 99 | } |
| 100 | |
Holger Hans Peter Freyther | 241e130 | 2010-03-31 09:16:56 +0200 | [diff] [blame] | 101 | void bsc_mgcp_free_endpoints(struct bsc_nat *nat) |
| 102 | { |
| 103 | int i; |
| 104 | |
Holger Hans Peter Freyther | 7b7eef6 | 2010-04-22 12:08:17 +0800 | [diff] [blame] | 105 | for (i = 1; i < nat->mgcp_cfg->number_endpoints; ++i){ |
Holger Hans Peter Freyther | a0df82d | 2010-04-01 08:21:33 +0200 | [diff] [blame] | 106 | bsc_mgcp_free_endpoint(nat, i); |
Holger Hans Peter Freyther | 7b7eef6 | 2010-04-22 12:08:17 +0800 | [diff] [blame] | 107 | mgcp_free_endp(&nat->mgcp_cfg->endpoints[i]); |
| 108 | } |
Holger Hans Peter Freyther | 241e130 | 2010-03-31 09:16:56 +0200 | [diff] [blame] | 109 | } |
Holger Hans Peter Freyther | a7f8018 | 2010-03-31 13:02:22 +0200 | [diff] [blame] | 110 | |
Holger Hans Peter Freyther | 7b7eef6 | 2010-04-22 12:08:17 +0800 | [diff] [blame] | 111 | /* send a MDCX where we do not want a response */ |
| 112 | static void bsc_mgcp_send_mdcx(struct bsc_connection *bsc, struct mgcp_endpoint *endp) |
| 113 | { |
| 114 | char buf[2096]; |
| 115 | int len; |
| 116 | |
| 117 | len = snprintf(buf, sizeof(buf), |
Holger Hans Peter Freyther | f42f45b | 2010-04-22 13:06:24 +0800 | [diff] [blame] | 118 | "MDCX 23 %x@mgw MGCP 1.0\r\n" |
Holger Hans Peter Freyther | 7b7eef6 | 2010-04-22 12:08:17 +0800 | [diff] [blame] | 119 | "Z: noanswer\r\n" |
| 120 | "\r\n" |
| 121 | "c=IN IP4 %s\r\n" |
| 122 | "m=audio %d RTP/AVP 255\r\n", |
| 123 | ENDPOINT_NUMBER(endp), |
| 124 | bsc->nat->mgcp_cfg->source_addr, |
Holger Hans Peter Freyther | 58ff219 | 2010-08-05 03:08:35 +0800 | [diff] [blame] | 125 | endp->bts_end.local_port); |
Holger Hans Peter Freyther | 7b7eef6 | 2010-04-22 12:08:17 +0800 | [diff] [blame] | 126 | if (len < 0) { |
| 127 | LOGP(DMGCP, LOGL_ERROR, "snprintf for DLCX failed.\n"); |
| 128 | return; |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | static void bsc_mgcp_send_dlcx(struct bsc_connection *bsc, int endpoint) |
| 133 | { |
| 134 | char buf[2096]; |
| 135 | int len; |
| 136 | |
| 137 | len = snprintf(buf, sizeof(buf), |
Holger Hans Peter Freyther | f42f45b | 2010-04-22 13:06:24 +0800 | [diff] [blame] | 138 | "DLCX 23 %x@mgw MGCP 1.0\r\n" |
Holger Hans Peter Freyther | 7b7eef6 | 2010-04-22 12:08:17 +0800 | [diff] [blame] | 139 | "Z: noanswer\r\n", endpoint); |
| 140 | if (len < 0) { |
| 141 | LOGP(DMGCP, LOGL_ERROR, "snprintf for DLCX failed.\n"); |
| 142 | return; |
| 143 | } |
| 144 | |
Holger Hans Peter Freyther | dbd16fe | 2010-07-23 19:08:55 +0800 | [diff] [blame] | 145 | bsc_write_mgcp(bsc, (uint8_t *) buf, len); |
Holger Hans Peter Freyther | 7b7eef6 | 2010-04-22 12:08:17 +0800 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | void bsc_mgcp_init(struct sccp_connections *con) |
| 149 | { |
| 150 | con->msc_timeslot = -1; |
| 151 | con->bsc_timeslot = -1; |
Holger Hans Peter Freyther | 959bbcf | 2010-04-22 20:12:13 +0800 | [diff] [blame] | 152 | con->crcx = 0; |
Holger Hans Peter Freyther | 7b7eef6 | 2010-04-22 12:08:17 +0800 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | void bsc_mgcp_dlcx(struct sccp_connections *con) |
| 156 | { |
| 157 | /* send a DLCX down the stream */ |
Holger Hans Peter Freyther | 959bbcf | 2010-04-22 20:12:13 +0800 | [diff] [blame] | 158 | if (con->bsc_timeslot != -1 && con->crcx) { |
Holger Hans Peter Freyther | 5910033 | 2010-08-28 14:56:00 +0800 | [diff] [blame^] | 159 | int bsc_endp = mgcp_timeslot_to_endpoint(0, con->bsc_timeslot); |
| 160 | int msc_endp = mgcp_timeslot_to_endpoint(0, con->msc_timeslot); |
| 161 | bsc_mgcp_send_dlcx(con->bsc, bsc_endp); |
| 162 | bsc_mgcp_free_endpoint(con->bsc->nat, msc_endp); |
Holger Hans Peter Freyther | 7b7eef6 | 2010-04-22 12:08:17 +0800 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | bsc_mgcp_init(con); |
| 166 | } |
| 167 | |
| 168 | |
Holger Hans Peter Freyther | 08a1b16 | 2010-04-18 02:26:16 +0800 | [diff] [blame] | 169 | 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] | 170 | { |
Holger Hans Peter Freyther | 08a1b16 | 2010-04-18 02:26:16 +0800 | [diff] [blame] | 171 | struct sccp_connections *con = NULL; |
Holger Hans Peter Freyther | fc9bd23 | 2010-04-01 03:55:27 +0200 | [diff] [blame] | 172 | struct sccp_connections *sccp; |
| 173 | |
| 174 | llist_for_each_entry(sccp, &nat->sccp_connections, list_entry) { |
| 175 | if (sccp->msc_timeslot == -1) |
| 176 | continue; |
| 177 | if (mgcp_timeslot_to_endpoint(0, sccp->msc_timeslot) != endpoint) |
| 178 | continue; |
| 179 | |
Holger Hans Peter Freyther | 08a1b16 | 2010-04-18 02:26:16 +0800 | [diff] [blame] | 180 | con = sccp; |
Holger Hans Peter Freyther | fc9bd23 | 2010-04-01 03:55:27 +0200 | [diff] [blame] | 181 | } |
| 182 | |
Holger Hans Peter Freyther | 08a1b16 | 2010-04-18 02:26:16 +0800 | [diff] [blame] | 183 | if (con) |
| 184 | return con; |
Holger Hans Peter Freyther | eb52e89 | 2010-04-18 02:14:45 +0800 | [diff] [blame] | 185 | |
Holger Hans Peter Freyther | fc9bd23 | 2010-04-01 03:55:27 +0200 | [diff] [blame] | 186 | LOGP(DMGCP, LOGL_ERROR, "Failed to find the connection.\n"); |
| 187 | return NULL; |
| 188 | } |
| 189 | |
Holger Hans Peter Freyther | a0df82d | 2010-04-01 08:21:33 +0200 | [diff] [blame] | 190 | int bsc_mgcp_policy_cb(struct mgcp_config *cfg, int endpoint, int state, const char *transaction_id) |
| 191 | { |
| 192 | struct bsc_nat *nat; |
| 193 | struct bsc_endpoint *bsc_endp; |
Holger Hans Peter Freyther | 08a1b16 | 2010-04-18 02:26:16 +0800 | [diff] [blame] | 194 | struct sccp_connections *sccp; |
Holger Hans Peter Freyther | a0df82d | 2010-04-01 08:21:33 +0200 | [diff] [blame] | 195 | struct mgcp_endpoint *mgcp_endp; |
| 196 | struct msgb *bsc_msg; |
| 197 | |
| 198 | nat = cfg->data; |
| 199 | bsc_endp = &nat->bsc_endpoints[endpoint]; |
| 200 | mgcp_endp = &nat->mgcp_cfg->endpoints[endpoint]; |
| 201 | |
Holger Hans Peter Freyther | fef7612 | 2010-04-24 21:05:18 +0800 | [diff] [blame] | 202 | if (bsc_endp->transaction_id) { |
| 203 | LOGP(DMGCP, LOGL_ERROR, "Endpoint 0x%x had pending transaction: '%s'\n", |
| 204 | endpoint, bsc_endp->transaction_id); |
| 205 | talloc_free(bsc_endp->transaction_id); |
| 206 | bsc_endp->transaction_id = NULL; |
Holger Hans Peter Freyther | 5b2726e | 2010-08-06 09:05:05 +0800 | [diff] [blame] | 207 | bsc_endp->transaction_state = 0; |
Holger Hans Peter Freyther | fef7612 | 2010-04-24 21:05:18 +0800 | [diff] [blame] | 208 | } |
| 209 | bsc_endp->bsc = NULL; |
| 210 | |
Holger Hans Peter Freyther | 08a1b16 | 2010-04-18 02:26:16 +0800 | [diff] [blame] | 211 | sccp = bsc_mgcp_find_con(nat, endpoint); |
Holger Hans Peter Freyther | a0df82d | 2010-04-01 08:21:33 +0200 | [diff] [blame] | 212 | |
Holger Hans Peter Freyther | 08a1b16 | 2010-04-18 02:26:16 +0800 | [diff] [blame] | 213 | if (!sccp) { |
Holger Hans Peter Freyther | 3d194d9 | 2010-04-24 21:02:01 +0800 | [diff] [blame] | 214 | 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] | 215 | |
| 216 | switch (state) { |
| 217 | case MGCP_ENDP_CRCX: |
| 218 | return MGCP_POLICY_REJECT; |
| 219 | break; |
| 220 | case MGCP_ENDP_DLCX: |
| 221 | return MGCP_POLICY_CONT; |
| 222 | break; |
| 223 | case MGCP_ENDP_MDCX: |
| 224 | return MGCP_POLICY_CONT; |
| 225 | break; |
| 226 | default: |
| 227 | LOGP(DMGCP, LOGL_FATAL, "Unhandled state: %d\n", state); |
| 228 | return MGCP_POLICY_CONT; |
| 229 | break; |
| 230 | } |
| 231 | } |
| 232 | |
Holger Hans Peter Freyther | dd16b42 | 2010-04-07 09:53:54 +0200 | [diff] [blame] | 233 | /* we need to generate a new and patched message */ |
| 234 | bsc_msg = bsc_mgcp_rewrite((char *) nat->mgcp_msg, nat->mgcp_length, |
Holger Hans Peter Freyther | 58ff219 | 2010-08-05 03:08:35 +0800 | [diff] [blame] | 235 | 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] | 236 | if (!bsc_msg) { |
| 237 | LOGP(DMGCP, LOGL_ERROR, "Failed to patch the msg.\n"); |
| 238 | return MGCP_POLICY_CONT; |
| 239 | } |
| 240 | |
| 241 | |
Holger Hans Peter Freyther | b3e0a03 | 2010-04-04 18:11:49 +0200 | [diff] [blame] | 242 | bsc_endp->transaction_id = talloc_strdup(nat, transaction_id); |
Holger Hans Peter Freyther | 5b2726e | 2010-08-06 09:05:05 +0800 | [diff] [blame] | 243 | bsc_endp->transaction_state = state; |
Holger Hans Peter Freyther | 08a1b16 | 2010-04-18 02:26:16 +0800 | [diff] [blame] | 244 | bsc_endp->bsc = sccp->bsc; |
Holger Hans Peter Freyther | a0df82d | 2010-04-01 08:21:33 +0200 | [diff] [blame] | 245 | |
| 246 | /* we need to update some bits */ |
| 247 | if (state == MGCP_ENDP_CRCX) { |
| 248 | struct sockaddr_in sock; |
| 249 | socklen_t len = sizeof(sock); |
Holger Hans Peter Freyther | 08a1b16 | 2010-04-18 02:26:16 +0800 | [diff] [blame] | 250 | 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] | 251 | LOGP(DMGCP, LOGL_ERROR, "Can not get the peername...%d/%s\n", |
| 252 | errno, strerror(errno)); |
Holger Hans Peter Freyther | a0df82d | 2010-04-01 08:21:33 +0200 | [diff] [blame] | 253 | } else { |
Holger Hans Peter Freyther | a17d701 | 2010-08-05 01:34:51 +0800 | [diff] [blame] | 254 | mgcp_endp->bts_end.addr = sock.sin_addr; |
Holger Hans Peter Freyther | a0df82d | 2010-04-01 08:21:33 +0200 | [diff] [blame] | 255 | } |
Holger Hans Peter Freyther | a0df82d | 2010-04-01 08:21:33 +0200 | [diff] [blame] | 256 | |
Holger Hans Peter Freyther | e66cac3 | 2010-08-05 01:50:44 +0800 | [diff] [blame] | 257 | /* send the message and a fake MDCX to force sending of a dummy packet */ |
Holger Hans Peter Freyther | 959bbcf | 2010-04-22 20:12:13 +0800 | [diff] [blame] | 258 | sccp->crcx = 1; |
Holger Hans Peter Freyther | 7b7eef6 | 2010-04-22 12:08:17 +0800 | [diff] [blame] | 259 | bsc_write(sccp->bsc, bsc_msg, NAT_IPAC_PROTO_MGCP); |
| 260 | bsc_mgcp_send_mdcx(sccp->bsc, mgcp_endp); |
| 261 | return MGCP_POLICY_DEFER; |
| 262 | } else if (state == MGCP_ENDP_DLCX) { |
| 263 | /* 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] | 264 | msgb_free(bsc_msg); |
Holger Hans Peter Freyther | 7b7eef6 | 2010-04-22 12:08:17 +0800 | [diff] [blame] | 265 | bsc_mgcp_dlcx(sccp); |
| 266 | return MGCP_POLICY_CONT; |
| 267 | } else { |
| 268 | bsc_write(sccp->bsc, bsc_msg, NAT_IPAC_PROTO_MGCP); |
| 269 | return MGCP_POLICY_DEFER; |
| 270 | } |
Holger Hans Peter Freyther | a0df82d | 2010-04-01 08:21:33 +0200 | [diff] [blame] | 271 | } |
| 272 | |
Holger Hans Peter Freyther | 3c3bce1 | 2010-04-01 10:16:28 +0200 | [diff] [blame] | 273 | /* |
Holger Hans Peter Freyther | 7d47601 | 2010-08-06 19:16:34 +0800 | [diff] [blame] | 274 | * We do have a failure, free data downstream.. |
| 275 | */ |
| 276 | static void free_chan_downstream(struct mgcp_endpoint *endp, struct bsc_endpoint *bsc_endp, |
| 277 | struct bsc_connection *bsc) |
| 278 | { |
| 279 | LOGP(DMGCP, LOGL_ERROR, "No CI, freeing endpoint 0x%x in state %d\n", |
| 280 | ENDPOINT_NUMBER(endp), bsc_endp->transaction_state); |
| 281 | |
| 282 | /* if a CRCX failed... send a DLCX down the stream */ |
| 283 | if (bsc_endp->transaction_state == MGCP_ENDP_CRCX) { |
| 284 | struct sccp_connections *con; |
| 285 | con = bsc_mgcp_find_con(bsc->nat, ENDPOINT_NUMBER(endp)); |
| 286 | if (!con) { |
| 287 | LOGP(DMGCP, LOGL_ERROR, |
| 288 | "No SCCP connection for endp 0x%x\n", |
| 289 | ENDPOINT_NUMBER(endp)); |
| 290 | } else { |
| 291 | if (con->bsc == bsc) { |
| 292 | bsc_mgcp_send_dlcx(bsc, ENDPOINT_NUMBER(endp)); |
| 293 | con->crcx = 0; |
| 294 | } else { |
| 295 | LOGP(DMGCP, LOGL_ERROR, |
| 296 | "Endpoint belongs to a different BSC\n"); |
| 297 | } |
| 298 | } |
| 299 | } |
| 300 | |
| 301 | bsc_mgcp_free_endpoint(bsc->nat, ENDPOINT_NUMBER(endp)); |
| 302 | mgcp_free_endp(endp); |
| 303 | } |
| 304 | |
| 305 | /* |
Holger Hans Peter Freyther | 3c3bce1 | 2010-04-01 10:16:28 +0200 | [diff] [blame] | 306 | * We have received a msg from the BSC. We will see if we know |
| 307 | * this transaction and if it belongs to the BSC. Then we will |
| 308 | * need to patch the content to point to the local network and we |
| 309 | * need to update the I: that was assigned by the BSS. |
| 310 | */ |
| 311 | void bsc_mgcp_forward(struct bsc_connection *bsc, struct msgb *msg) |
| 312 | { |
| 313 | struct msgb *output; |
| 314 | struct bsc_endpoint *bsc_endp = NULL; |
| 315 | struct mgcp_endpoint *endp = NULL; |
Holger Hans Peter Freyther | d2dd6e8 | 2010-04-06 11:06:11 +0200 | [diff] [blame] | 316 | int i, code; |
Holger Hans Peter Freyther | 3c3bce1 | 2010-04-01 10:16:28 +0200 | [diff] [blame] | 317 | char transaction_id[60]; |
| 318 | |
| 319 | /* Some assumption that our buffer is big enough.. and null terminate */ |
| 320 | if (msgb_l2len(msg) > 2000) { |
| 321 | LOGP(DMGCP, LOGL_ERROR, "MGCP message too long.\n"); |
| 322 | return; |
| 323 | } |
| 324 | |
| 325 | msg->l2h[msgb_l2len(msg)] = '\0'; |
| 326 | |
| 327 | if (bsc_mgcp_parse_response((const char *) msg->l2h, &code, transaction_id) != 0) { |
| 328 | LOGP(DMGCP, LOGL_ERROR, "Failed to parse response code.\n"); |
| 329 | return; |
| 330 | } |
| 331 | |
| 332 | for (i = 1; i < bsc->nat->mgcp_cfg->number_endpoints; ++i) { |
| 333 | if (bsc->nat->bsc_endpoints[i].bsc != bsc) |
| 334 | continue; |
Holger Hans Peter Freyther | 3f7c7d0 | 2010-04-05 18:00:05 +0200 | [diff] [blame] | 335 | /* no one listening? a bug? */ |
| 336 | if (!bsc->nat->bsc_endpoints[i].transaction_id) |
| 337 | continue; |
Holger Hans Peter Freyther | 3c3bce1 | 2010-04-01 10:16:28 +0200 | [diff] [blame] | 338 | if (strcmp(transaction_id, bsc->nat->bsc_endpoints[i].transaction_id) != 0) |
| 339 | continue; |
| 340 | |
| 341 | endp = &bsc->nat->mgcp_cfg->endpoints[i]; |
| 342 | bsc_endp = &bsc->nat->bsc_endpoints[i]; |
| 343 | break; |
| 344 | } |
| 345 | |
| 346 | if (!bsc_endp) { |
Holger Hans Peter Freyther | b9ac37d | 2010-04-05 17:58:52 +0200 | [diff] [blame] | 347 | LOGP(DMGCP, LOGL_ERROR, "Could not find active endpoint: %s for msg: '%s'\n", |
| 348 | transaction_id, (const char *) msg->l2h); |
Holger Hans Peter Freyther | 3c3bce1 | 2010-04-01 10:16:28 +0200 | [diff] [blame] | 349 | return; |
| 350 | } |
| 351 | |
Holger Hans Peter Freyther | 7b7eef6 | 2010-04-22 12:08:17 +0800 | [diff] [blame] | 352 | endp->ci = bsc_mgcp_extract_ci((const char *) msg->l2h); |
Holger Hans Peter Freyther | b84b5f6 | 2010-08-06 08:34:46 +0800 | [diff] [blame] | 353 | if (endp->ci == CI_UNUSED) { |
Holger Hans Peter Freyther | 7d47601 | 2010-08-06 19:16:34 +0800 | [diff] [blame] | 354 | free_chan_downstream(endp, bsc_endp, bsc); |
Holger Hans Peter Freyther | b84b5f6 | 2010-08-06 08:34:46 +0800 | [diff] [blame] | 355 | return; |
| 356 | } |
Holger Hans Peter Freyther | dd16b42 | 2010-04-07 09:53:54 +0200 | [diff] [blame] | 357 | |
Holger Hans Peter Freyther | 3c3bce1 | 2010-04-01 10:16:28 +0200 | [diff] [blame] | 358 | /* free some stuff */ |
| 359 | talloc_free(bsc_endp->transaction_id); |
| 360 | bsc_endp->transaction_id = NULL; |
Holger Hans Peter Freyther | 5b2726e | 2010-08-06 09:05:05 +0800 | [diff] [blame] | 361 | bsc_endp->transaction_state = 0; |
Holger Hans Peter Freyther | 3c3bce1 | 2010-04-01 10:16:28 +0200 | [diff] [blame] | 362 | |
Holger Hans Peter Freyther | dd16b42 | 2010-04-07 09:53:54 +0200 | [diff] [blame] | 363 | /* |
| 364 | * rewrite the information. In case the endpoint was deleted |
| 365 | * there should be nothing for us to rewrite so putting endp->rtp_port |
| 366 | * with the value of 0 should be no problem. |
| 367 | */ |
Holger Hans Peter Freyther | 8d20065 | 2010-04-04 18:09:10 +0200 | [diff] [blame] | 368 | output = bsc_mgcp_rewrite((char * ) msg->l2h, msgb_l2len(msg), |
Holger Hans Peter Freyther | 58ff219 | 2010-08-05 03:08:35 +0800 | [diff] [blame] | 369 | 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] | 370 | |
Holger Hans Peter Freyther | 3c3bce1 | 2010-04-01 10:16:28 +0200 | [diff] [blame] | 371 | if (!output) { |
| 372 | LOGP(DMGCP, LOGL_ERROR, "Failed to rewrite MGCP msg.\n"); |
| 373 | return; |
| 374 | } |
| 375 | |
| 376 | if (write_queue_enqueue(&bsc->nat->mgcp_queue, output) != 0) { |
| 377 | LOGP(DMGCP, LOGL_ERROR, "Failed to queue MGCP msg.\n"); |
| 378 | msgb_free(output); |
| 379 | } |
| 380 | } |
| 381 | |
| 382 | int bsc_mgcp_parse_response(const char *str, int *code, char transaction[60]) |
| 383 | { |
| 384 | /* we want to parse two strings */ |
| 385 | return sscanf(str, "%3d %59s\n", code, transaction) != 2; |
| 386 | } |
| 387 | |
Holger Hans Peter Freyther | 4634013 | 2010-08-06 08:26:54 +0800 | [diff] [blame] | 388 | uint32_t bsc_mgcp_extract_ci(const char *str) |
Holger Hans Peter Freyther | 3c3bce1 | 2010-04-01 10:16:28 +0200 | [diff] [blame] | 389 | { |
Holger Hans Peter Freyther | 4634013 | 2010-08-06 08:26:54 +0800 | [diff] [blame] | 390 | unsigned int ci; |
Holger Hans Peter Freyther | 3c3bce1 | 2010-04-01 10:16:28 +0200 | [diff] [blame] | 391 | char *res = strstr(str, "I: "); |
Holger Hans Peter Freyther | 9c31cfc | 2010-08-06 08:19:05 +0800 | [diff] [blame] | 392 | if (!res) { |
| 393 | 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] | 394 | return CI_UNUSED; |
Holger Hans Peter Freyther | 9c31cfc | 2010-08-06 08:19:05 +0800 | [diff] [blame] | 395 | } |
Holger Hans Peter Freyther | 3c3bce1 | 2010-04-01 10:16:28 +0200 | [diff] [blame] | 396 | |
Holger Hans Peter Freyther | 4634013 | 2010-08-06 08:26:54 +0800 | [diff] [blame] | 397 | if (sscanf(res, "I: %u", &ci) != 1) { |
Holger Hans Peter Freyther | 9c31cfc | 2010-08-06 08:19:05 +0800 | [diff] [blame] | 398 | 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] | 399 | return CI_UNUSED; |
Holger Hans Peter Freyther | 9c31cfc | 2010-08-06 08:19:05 +0800 | [diff] [blame] | 400 | } |
| 401 | |
Holger Hans Peter Freyther | 3c3bce1 | 2010-04-01 10:16:28 +0200 | [diff] [blame] | 402 | return ci; |
| 403 | } |
| 404 | |
Holger Hans Peter Freyther | 76c8354 | 2010-04-01 06:48:52 +0200 | [diff] [blame] | 405 | /* we need to replace some strings... */ |
Holger Hans Peter Freyther | 8d20065 | 2010-04-04 18:09:10 +0200 | [diff] [blame] | 406 | struct msgb *bsc_mgcp_rewrite(char *input, int length, const char *ip, int port) |
Holger Hans Peter Freyther | 76c8354 | 2010-04-01 06:48:52 +0200 | [diff] [blame] | 407 | { |
| 408 | static const char *ip_str = "c=IN IP4 "; |
| 409 | static const char *aud_str = "m=audio "; |
| 410 | |
| 411 | char buf[128]; |
| 412 | char *running, *token; |
| 413 | struct msgb *output; |
| 414 | |
Holger Hans Peter Freyther | 8d20065 | 2010-04-04 18:09:10 +0200 | [diff] [blame] | 415 | if (length > 4096 - 128) { |
Holger Hans Peter Freyther | 76c8354 | 2010-04-01 06:48:52 +0200 | [diff] [blame] | 416 | LOGP(DMGCP, LOGL_ERROR, "Input is too long.\n"); |
| 417 | return NULL; |
| 418 | } |
| 419 | |
| 420 | output = msgb_alloc_headroom(4096, 128, "MGCP rewritten"); |
| 421 | if (!output) { |
| 422 | LOGP(DMGCP, LOGL_ERROR, "Failed to allocate new MGCP msg.\n"); |
| 423 | return NULL; |
| 424 | } |
| 425 | |
Holger Hans Peter Freyther | 8d20065 | 2010-04-04 18:09:10 +0200 | [diff] [blame] | 426 | running = input; |
Holger Hans Peter Freyther | 76c8354 | 2010-04-01 06:48:52 +0200 | [diff] [blame] | 427 | output->l2h = output->data; |
Holger Hans Peter Freyther | 9e5300a | 2010-04-04 19:34:44 +0200 | [diff] [blame] | 428 | for (token = strsep(&running, "\n"); running; token = strsep(&running, "\n")) { |
Holger Hans Peter Freyther | 76c8354 | 2010-04-01 06:48:52 +0200 | [diff] [blame] | 429 | int len = strlen(token); |
Holger Hans Peter Freyther | 9e5300a | 2010-04-04 19:34:44 +0200 | [diff] [blame] | 430 | int cr = len > 0 && token[len - 1] == '\r'; |
Holger Hans Peter Freyther | 76c8354 | 2010-04-01 06:48:52 +0200 | [diff] [blame] | 431 | |
| 432 | if (strncmp(ip_str, token, (sizeof ip_str) - 1) == 0) { |
| 433 | output->l3h = msgb_put(output, strlen(ip_str)); |
| 434 | memcpy(output->l3h, ip_str, strlen(ip_str)); |
| 435 | output->l3h = msgb_put(output, strlen(ip)); |
| 436 | memcpy(output->l3h, ip, strlen(ip)); |
Holger Hans Peter Freyther | 9e5300a | 2010-04-04 19:34:44 +0200 | [diff] [blame] | 437 | |
| 438 | if (cr) { |
| 439 | output->l3h = msgb_put(output, 2); |
| 440 | output->l3h[0] = '\r'; |
| 441 | output->l3h[1] = '\n'; |
| 442 | } else { |
| 443 | output->l3h = msgb_put(output, 1); |
| 444 | output->l3h[0] = '\n'; |
| 445 | } |
Holger Hans Peter Freyther | 76c8354 | 2010-04-01 06:48:52 +0200 | [diff] [blame] | 446 | } else if (strncmp(aud_str, token, (sizeof aud_str) - 1) == 0) { |
| 447 | int payload; |
| 448 | if (sscanf(token, "m=audio %*d RTP/AVP %d", &payload) != 1) { |
| 449 | LOGP(DMGCP, LOGL_ERROR, "Could not parsed audio line.\n"); |
| 450 | msgb_free(output); |
| 451 | return NULL; |
| 452 | } |
| 453 | |
Holger Hans Peter Freyther | 9e5300a | 2010-04-04 19:34:44 +0200 | [diff] [blame] | 454 | snprintf(buf, sizeof(buf)-1, "m=audio %d RTP/AVP %d%s", |
| 455 | port, payload, cr ? "\r\n" : "\n"); |
Holger Hans Peter Freyther | 76c8354 | 2010-04-01 06:48:52 +0200 | [diff] [blame] | 456 | buf[sizeof(buf)-1] = '\0'; |
| 457 | |
| 458 | output->l3h = msgb_put(output, strlen(buf)); |
| 459 | memcpy(output->l3h, buf, strlen(buf)); |
| 460 | } else { |
| 461 | output->l3h = msgb_put(output, len + 1); |
| 462 | memcpy(output->l3h, token, len); |
| 463 | output->l3h[len] = '\n'; |
| 464 | } |
| 465 | } |
| 466 | |
| 467 | return output; |
| 468 | } |
| 469 | |
Holger Hans Peter Freyther | a7f8018 | 2010-03-31 13:02:22 +0200 | [diff] [blame] | 470 | static int mgcp_do_read(struct bsc_fd *fd) |
| 471 | { |
| 472 | struct bsc_nat *nat; |
| 473 | struct msgb *msg, *resp; |
| 474 | int rc; |
| 475 | |
Holger Hans Peter Freyther | 8d20065 | 2010-04-04 18:09:10 +0200 | [diff] [blame] | 476 | nat = fd->data; |
| 477 | |
| 478 | rc = read(fd->fd, nat->mgcp_msg, sizeof(nat->mgcp_msg) - 1); |
| 479 | if (rc <= 0) { |
| 480 | LOGP(DMGCP, LOGL_ERROR, "Failed to read errno: %d\n", errno); |
| 481 | return -1; |
| 482 | } |
| 483 | |
| 484 | nat->mgcp_msg[rc] = '\0'; |
| 485 | nat->mgcp_length = rc; |
| 486 | |
| 487 | msg = msgb_alloc(sizeof(nat->mgcp_msg), "MGCP GW Read"); |
Holger Hans Peter Freyther | a7f8018 | 2010-03-31 13:02:22 +0200 | [diff] [blame] | 488 | if (!msg) { |
| 489 | LOGP(DMGCP, LOGL_ERROR, "Failed to create buffer.\n"); |
| 490 | return -1; |
| 491 | } |
| 492 | |
Holger Hans Peter Freyther | a7f8018 | 2010-03-31 13:02:22 +0200 | [diff] [blame] | 493 | msg->l2h = msgb_put(msg, rc); |
Holger Hans Peter Freyther | 8d20065 | 2010-04-04 18:09:10 +0200 | [diff] [blame] | 494 | memcpy(msg->l2h, nat->mgcp_msg, msgb_l2len(msg)); |
Holger Hans Peter Freyther | a7f8018 | 2010-03-31 13:02:22 +0200 | [diff] [blame] | 495 | resp = mgcp_handle_message(nat->mgcp_cfg, msg); |
| 496 | msgb_free(msg); |
| 497 | |
| 498 | /* we do have a direct answer... e.g. AUEP */ |
| 499 | if (resp) { |
| 500 | if (write_queue_enqueue(&nat->mgcp_queue, resp) != 0) { |
| 501 | LOGP(DMGCP, LOGL_ERROR, "Failed to enqueue msg.\n"); |
| 502 | msgb_free(resp); |
| 503 | } |
| 504 | } |
| 505 | |
| 506 | return 0; |
| 507 | } |
| 508 | |
| 509 | static int mgcp_do_write(struct bsc_fd *bfd, struct msgb *msg) |
| 510 | { |
| 511 | int rc; |
| 512 | |
| 513 | rc = write(bfd->fd, msg->data, msg->len); |
| 514 | |
| 515 | if (rc != msg->len) { |
| 516 | LOGP(DMGCP, LOGL_ERROR, "Failed to write msg to MGCP CallAgent.\n"); |
| 517 | return -1; |
| 518 | } |
| 519 | |
| 520 | return rc; |
| 521 | } |
| 522 | |
Holger Hans Peter Freyther | 7b7eef6 | 2010-04-22 12:08:17 +0800 | [diff] [blame] | 523 | int bsc_mgcp_nat_init(struct bsc_nat *nat) |
Holger Hans Peter Freyther | a7f8018 | 2010-03-31 13:02:22 +0200 | [diff] [blame] | 524 | { |
| 525 | int on; |
| 526 | struct sockaddr_in addr; |
| 527 | |
| 528 | if (!nat->mgcp_cfg->call_agent_addr) { |
| 529 | LOGP(DMGCP, LOGL_ERROR, "The BSC nat requires the call agent ip to be set.\n"); |
| 530 | return -1; |
| 531 | } |
| 532 | |
Holger Hans Peter Freyther | a0df82d | 2010-04-01 08:21:33 +0200 | [diff] [blame] | 533 | if (nat->mgcp_cfg->bts_ip) { |
| 534 | LOGP(DMGCP, LOGL_ERROR, "Do not set the BTS ip for the nat.\n"); |
| 535 | return -1; |
| 536 | } |
| 537 | |
Holger Hans Peter Freyther | a7f8018 | 2010-03-31 13:02:22 +0200 | [diff] [blame] | 538 | nat->mgcp_queue.bfd.fd = socket(AF_INET, SOCK_DGRAM, 0); |
| 539 | if (nat->mgcp_queue.bfd.fd < 0) { |
| 540 | LOGP(DMGCP, LOGL_ERROR, "Failed to create MGCP socket. errno: %d\n", errno); |
| 541 | return -1; |
| 542 | } |
| 543 | |
| 544 | on = 1; |
| 545 | setsockopt(nat->mgcp_queue.bfd.fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)); |
| 546 | |
| 547 | addr.sin_family = AF_INET; |
| 548 | addr.sin_port = htons(nat->mgcp_cfg->source_port); |
| 549 | inet_aton(nat->mgcp_cfg->source_addr, &addr.sin_addr); |
| 550 | |
| 551 | if (bind(nat->mgcp_queue.bfd.fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) { |
| 552 | LOGP(DMGCP, LOGL_ERROR, "Failed to bind. errno: %d\n", errno); |
| 553 | close(nat->mgcp_queue.bfd.fd); |
| 554 | nat->mgcp_queue.bfd.fd = -1; |
| 555 | return -1; |
| 556 | } |
| 557 | |
| 558 | addr.sin_port = htons(2727); |
| 559 | inet_aton(nat->mgcp_cfg->call_agent_addr, &addr.sin_addr); |
| 560 | if (connect(nat->mgcp_queue.bfd.fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) { |
| 561 | LOGP(DMGCP, LOGL_ERROR, "Failed to connect to: '%s'. errno: %d\n", |
| 562 | nat->mgcp_cfg->call_agent_addr, errno); |
| 563 | close(nat->mgcp_queue.bfd.fd); |
| 564 | nat->mgcp_queue.bfd.fd = -1; |
| 565 | return -1; |
| 566 | } |
| 567 | |
| 568 | write_queue_init(&nat->mgcp_queue, 10); |
| 569 | nat->mgcp_queue.bfd.when = BSC_FD_READ; |
| 570 | nat->mgcp_queue.bfd.data = nat; |
| 571 | nat->mgcp_queue.read_cb = mgcp_do_read; |
| 572 | nat->mgcp_queue.write_cb = mgcp_do_write; |
| 573 | |
| 574 | if (bsc_register_fd(&nat->mgcp_queue.bfd) != 0) { |
| 575 | LOGP(DMGCP, LOGL_ERROR, "Failed to register MGCP fd.\n"); |
| 576 | close(nat->mgcp_queue.bfd.fd); |
| 577 | nat->mgcp_queue.bfd.fd = -1; |
| 578 | return -1; |
| 579 | } |
| 580 | |
Holger Hans Peter Freyther | a0df82d | 2010-04-01 08:21:33 +0200 | [diff] [blame] | 581 | /* some more MGCP config handling */ |
Holger Hans Peter Freyther | d5e6c23 | 2010-08-05 10:08:36 +0000 | [diff] [blame] | 582 | if (nat->mgcp_cfg->audio_name) |
| 583 | talloc_free(nat->mgcp_cfg->audio_name); |
| 584 | nat->mgcp_cfg->audio_name = NULL; |
| 585 | |
Holger Hans Peter Freyther | 4ad5850 | 2010-04-06 11:14:03 +0200 | [diff] [blame] | 586 | nat->mgcp_cfg->audio_payload = -1; |
Holger Hans Peter Freyther | a0df82d | 2010-04-01 08:21:33 +0200 | [diff] [blame] | 587 | nat->mgcp_cfg->data = nat; |
| 588 | nat->mgcp_cfg->policy_cb = bsc_mgcp_policy_cb; |
Holger Hans Peter Freyther | bba5934 | 2010-04-07 10:52:48 +0200 | [diff] [blame] | 589 | nat->mgcp_cfg->force_realloc = 1; |
Holger Hans Peter Freyther | d5e6c23 | 2010-08-05 10:08:36 +0000 | [diff] [blame] | 590 | |
| 591 | if (nat->mgcp_cfg->bts_ip) |
| 592 | talloc_free(nat->mgcp_cfg->bts_ip); |
Holger Hans Peter Freyther | 290d84e | 2010-04-09 18:51:01 +0200 | [diff] [blame] | 593 | nat->mgcp_cfg->bts_ip = ""; |
Holger Hans Peter Freyther | d5e6c23 | 2010-08-05 10:08:36 +0000 | [diff] [blame] | 594 | |
Holger Hans Peter Freyther | a0df82d | 2010-04-01 08:21:33 +0200 | [diff] [blame] | 595 | nat->bsc_endpoints = talloc_zero_array(nat, |
| 596 | struct bsc_endpoint, |
| 597 | nat->mgcp_cfg->number_endpoints + 1); |
| 598 | |
Holger Hans Peter Freyther | a7f8018 | 2010-03-31 13:02:22 +0200 | [diff] [blame] | 599 | return 0; |
| 600 | } |
Holger Hans Peter Freyther | 26a4389 | 2010-04-05 23:09:27 +0200 | [diff] [blame] | 601 | |
| 602 | void bsc_mgcp_clear_endpoints_for(struct bsc_connection *bsc) |
| 603 | { |
Holger Hans Peter Freyther | 8330c1c | 2010-06-17 18:29:42 +0800 | [diff] [blame] | 604 | struct rate_ctr *ctr = NULL; |
Holger Hans Peter Freyther | 26a4389 | 2010-04-05 23:09:27 +0200 | [diff] [blame] | 605 | int i; |
Holger Hans Peter Freyther | 8330c1c | 2010-06-17 18:29:42 +0800 | [diff] [blame] | 606 | |
| 607 | if (bsc->cfg) |
| 608 | ctr = &bsc->cfg->stats.ctrg->ctr[BCFG_CTR_DROPPED_CALLS]; |
| 609 | |
Holger Hans Peter Freyther | 26a4389 | 2010-04-05 23:09:27 +0200 | [diff] [blame] | 610 | for (i = 1; i < bsc->nat->mgcp_cfg->number_endpoints; ++i) { |
| 611 | struct bsc_endpoint *bsc_endp = &bsc->nat->bsc_endpoints[i]; |
| 612 | |
| 613 | if (bsc_endp->bsc != bsc) |
| 614 | continue; |
| 615 | |
Holger Hans Peter Freyther | 8330c1c | 2010-06-17 18:29:42 +0800 | [diff] [blame] | 616 | if (ctr) |
| 617 | rate_ctr_inc(ctr); |
| 618 | |
Holger Hans Peter Freyther | 7b7eef6 | 2010-04-22 12:08:17 +0800 | [diff] [blame] | 619 | bsc_mgcp_free_endpoint(bsc->nat, i); |
Holger Hans Peter Freyther | 26a4389 | 2010-04-05 23:09:27 +0200 | [diff] [blame] | 620 | mgcp_free_endp(&bsc->nat->mgcp_cfg->endpoints[i]); |
| 621 | } |
| 622 | } |