blob: ab830e6e505add9d5a9df8ae836c29c9ecf9d4ad [file] [log] [blame]
Holger Hans Peter Freyther465313e2010-06-15 18:49:53 +08001/*
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>
23#include <openbsc/gsm_data.h>
24#include <openbsc/bssap.h>
25#include <openbsc/debug.h>
Holger Hans Peter Freyther241e1302010-03-31 09:16:56 +020026#include <openbsc/mgcp.h>
27#include <openbsc/mgcp_internal.h>
Holger Hans Peter Freyther465313e2010-06-15 18:49:53 +080028
Holger Hans Peter Freythera0df82d2010-04-01 08:21:33 +020029#include <osmocore/talloc.h>
Holger Hans Peter Freyther13959482010-06-15 18:50:57 +080030#include <osmocore/gsm0808.h>
Holger Hans Peter Freythera0df82d2010-04-01 08:21:33 +020031
Holger Hans Peter Freyther465313e2010-06-15 18:49:53 +080032#include <netinet/in.h>
33#include <arpa/inet.h>
34
Holger Hans Peter Freythera7f80182010-03-31 13:02:22 +020035#include <errno.h>
36#include <unistd.h>
37
Holger Hans Peter Freyther465313e2010-06-15 18:49:53 +080038int bsc_mgcp_assign(struct sccp_connections *con, struct msgb *msg)
39{
40 struct tlv_parsed tp;
41 u_int16_t cic;
42 u_int8_t timeslot;
43 u_int8_t multiplex;
44
45 if (!msg->l3h) {
46 LOGP(DNAT, LOGL_ERROR, "Assignment message should have l3h pointer.\n");
47 return -1;
48 }
49
50 if (msgb_l3len(msg) < 3) {
51 LOGP(DNAT, LOGL_ERROR, "Assignment message has not enough space for GSM0808.\n");
52 return -1;
53 }
54
55 tlv_parse(&tp, gsm0808_att_tlvdef(), msg->l3h + 3, msgb_l3len(msg) - 3, 0, 0);
56 if (!TLVP_PRESENT(&tp, GSM0808_IE_CIRCUIT_IDENTITY_CODE)) {
57 LOGP(DNAT, LOGL_ERROR, "Circuit identity code not found in assignment message.\n");
58 return -1;
59 }
60
61 cic = ntohs(*(u_int16_t *)TLVP_VAL(&tp, GSM0808_IE_CIRCUIT_IDENTITY_CODE));
62 timeslot = cic & 0x1f;
63 multiplex = (cic & ~0x1f) >> 5;
64
65 con->msc_timeslot = (32 * multiplex) + timeslot;
66 con->bsc_timeslot = con->msc_timeslot;
67 return 0;
68}
69
70void bsc_mgcp_clear(struct sccp_connections *con)
71{
72 con->msc_timeslot = -1;
73 con->bsc_timeslot = -1;
74}
Holger Hans Peter Freyther241e1302010-03-31 09:16:56 +020075
Holger Hans Peter Freythera0df82d2010-04-01 08:21:33 +020076void bsc_mgcp_free_endpoint(struct bsc_nat *nat, int i)
77{
78 if (nat->bsc_endpoints[i].transaction_id) {
79 talloc_free(nat->bsc_endpoints[i].transaction_id);
80 nat->bsc_endpoints[i].transaction_id = NULL;
81 }
82
83 nat->bsc_endpoints[i].bsc = NULL;
84 mgcp_free_endp(&nat->mgcp_cfg->endpoints[i]);
85}
86
Holger Hans Peter Freyther241e1302010-03-31 09:16:56 +020087void bsc_mgcp_free_endpoints(struct bsc_nat *nat)
88{
89 int i;
90
91 for (i = 1; i < nat->mgcp_cfg->number_endpoints; ++i)
Holger Hans Peter Freythera0df82d2010-04-01 08:21:33 +020092 bsc_mgcp_free_endpoint(nat, i);
Holger Hans Peter Freyther241e1302010-03-31 09:16:56 +020093}
Holger Hans Peter Freythera7f80182010-03-31 13:02:22 +020094
Holger Hans Peter Freytherfc9bd232010-04-01 03:55:27 +020095struct bsc_connection *bsc_mgcp_find_con(struct bsc_nat *nat, int endpoint)
96{
Holger Hans Peter Freythereb52e892010-04-18 02:14:45 +080097 struct bsc_connection *bsc = NULL;
Holger Hans Peter Freytherfc9bd232010-04-01 03:55:27 +020098 struct sccp_connections *sccp;
99
100 llist_for_each_entry(sccp, &nat->sccp_connections, list_entry) {
101 if (sccp->msc_timeslot == -1)
102 continue;
103 if (mgcp_timeslot_to_endpoint(0, sccp->msc_timeslot) != endpoint)
104 continue;
105
Holger Hans Peter Freythereb52e892010-04-18 02:14:45 +0800106 bsc = sccp->bsc;
Holger Hans Peter Freytherfc9bd232010-04-01 03:55:27 +0200107 }
108
Holger Hans Peter Freythereb52e892010-04-18 02:14:45 +0800109 if (bsc)
110 return bsc;
111
Holger Hans Peter Freytherfc9bd232010-04-01 03:55:27 +0200112 LOGP(DMGCP, LOGL_ERROR, "Failed to find the connection.\n");
113 return NULL;
114}
115
Holger Hans Peter Freythera0df82d2010-04-01 08:21:33 +0200116int bsc_mgcp_policy_cb(struct mgcp_config *cfg, int endpoint, int state, const char *transaction_id)
117{
118 struct bsc_nat *nat;
119 struct bsc_endpoint *bsc_endp;
120 struct bsc_connection *bsc_con;
121 struct mgcp_endpoint *mgcp_endp;
122 struct msgb *bsc_msg;
123
124 nat = cfg->data;
125 bsc_endp = &nat->bsc_endpoints[endpoint];
126 mgcp_endp = &nat->mgcp_cfg->endpoints[endpoint];
127
128 bsc_con = bsc_mgcp_find_con(nat, endpoint);
129
130 if (!bsc_con) {
131 LOGP(DMGCP, LOGL_ERROR, "Did not find BSC for a new connection on 0x%x for %d\n", endpoint, state);
132
133 switch (state) {
134 case MGCP_ENDP_CRCX:
135 return MGCP_POLICY_REJECT;
136 break;
137 case MGCP_ENDP_DLCX:
138 return MGCP_POLICY_CONT;
139 break;
140 case MGCP_ENDP_MDCX:
141 return MGCP_POLICY_CONT;
142 break;
143 default:
144 LOGP(DMGCP, LOGL_FATAL, "Unhandled state: %d\n", state);
145 return MGCP_POLICY_CONT;
146 break;
147 }
148 }
149
150 if (bsc_endp->transaction_id) {
151 LOGP(DMGCP, LOGL_ERROR, "One transaction with id '%s' on 0x%x\n",
152 bsc_endp->transaction_id, endpoint);
153 talloc_free(bsc_endp->transaction_id);
154 }
155
Holger Hans Peter Freytherdd16b422010-04-07 09:53:54 +0200156 /* we need to generate a new and patched message */
157 bsc_msg = bsc_mgcp_rewrite((char *) nat->mgcp_msg, nat->mgcp_length,
158 nat->mgcp_cfg->source_addr, mgcp_endp->rtp_port);
159 if (!bsc_msg) {
160 LOGP(DMGCP, LOGL_ERROR, "Failed to patch the msg.\n");
161 return MGCP_POLICY_CONT;
162 }
163
164
Holger Hans Peter Freytherb3e0a032010-04-04 18:11:49 +0200165 bsc_endp->transaction_id = talloc_strdup(nat, transaction_id);
Holger Hans Peter Freythera0df82d2010-04-01 08:21:33 +0200166 bsc_endp->bsc = bsc_con;
Holger Hans Peter Freytherdd16b422010-04-07 09:53:54 +0200167 bsc_endp->pending_delete = 0;
Holger Hans Peter Freythera0df82d2010-04-01 08:21:33 +0200168
169 /* we need to update some bits */
170 if (state == MGCP_ENDP_CRCX) {
171 struct sockaddr_in sock;
172 socklen_t len = sizeof(sock);
Holger Hans Peter Freyther2066b8c2010-04-06 11:17:56 +0200173 if (getpeername(bsc_con->write_queue.bfd.fd, (struct sockaddr *) &sock, &len) != 0) {
Holger Hans Peter Freyther92febd32010-04-06 11:17:07 +0200174 LOGP(DMGCP, LOGL_ERROR, "Can not get the peername...%d/%s\n",
175 errno, strerror(errno));
Holger Hans Peter Freythera0df82d2010-04-01 08:21:33 +0200176 } else {
177 mgcp_endp->bts = sock.sin_addr;
178 }
Holger Hans Peter Freytherdd16b422010-04-07 09:53:54 +0200179 } else if (state == MGCP_ENDP_DLCX) {
180 /* we will free the endpoint now in case the BSS does not respond */
181 bsc_endp->pending_delete = 1;
182 mgcp_free_endp(mgcp_endp);
Holger Hans Peter Freythera0df82d2010-04-01 08:21:33 +0200183 }
184
Holger Hans Peter Freyther2896df72010-04-08 10:24:57 +0200185 bsc_write(bsc_con, bsc_msg, NAT_IPAC_PROTO_MGCP);
Holger Hans Peter Freythera0df82d2010-04-01 08:21:33 +0200186 return MGCP_POLICY_DEFER;
187}
188
Holger Hans Peter Freyther3c3bce12010-04-01 10:16:28 +0200189/*
190 * We have received a msg from the BSC. We will see if we know
191 * this transaction and if it belongs to the BSC. Then we will
192 * need to patch the content to point to the local network and we
193 * need to update the I: that was assigned by the BSS.
194 */
195void bsc_mgcp_forward(struct bsc_connection *bsc, struct msgb *msg)
196{
197 struct msgb *output;
198 struct bsc_endpoint *bsc_endp = NULL;
199 struct mgcp_endpoint *endp = NULL;
Holger Hans Peter Freytherd2dd6e82010-04-06 11:06:11 +0200200 int i, code;
Holger Hans Peter Freyther3c3bce12010-04-01 10:16:28 +0200201 char transaction_id[60];
202
203 /* Some assumption that our buffer is big enough.. and null terminate */
204 if (msgb_l2len(msg) > 2000) {
205 LOGP(DMGCP, LOGL_ERROR, "MGCP message too long.\n");
206 return;
207 }
208
209 msg->l2h[msgb_l2len(msg)] = '\0';
210
211 if (bsc_mgcp_parse_response((const char *) msg->l2h, &code, transaction_id) != 0) {
212 LOGP(DMGCP, LOGL_ERROR, "Failed to parse response code.\n");
213 return;
214 }
215
216 for (i = 1; i < bsc->nat->mgcp_cfg->number_endpoints; ++i) {
217 if (bsc->nat->bsc_endpoints[i].bsc != bsc)
218 continue;
Holger Hans Peter Freyther3f7c7d02010-04-05 18:00:05 +0200219 /* no one listening? a bug? */
220 if (!bsc->nat->bsc_endpoints[i].transaction_id)
221 continue;
Holger Hans Peter Freyther3c3bce12010-04-01 10:16:28 +0200222 if (strcmp(transaction_id, bsc->nat->bsc_endpoints[i].transaction_id) != 0)
223 continue;
224
225 endp = &bsc->nat->mgcp_cfg->endpoints[i];
226 bsc_endp = &bsc->nat->bsc_endpoints[i];
227 break;
228 }
229
230 if (!bsc_endp) {
Holger Hans Peter Freytherb9ac37d2010-04-05 17:58:52 +0200231 LOGP(DMGCP, LOGL_ERROR, "Could not find active endpoint: %s for msg: '%s'\n",
232 transaction_id, (const char *) msg->l2h);
Holger Hans Peter Freyther3c3bce12010-04-01 10:16:28 +0200233 return;
234 }
235
Holger Hans Peter Freytherdd16b422010-04-07 09:53:54 +0200236 /* make it point to our endpoint if it was not deleted */
237 if (bsc_endp->pending_delete) {
238 bsc_endp->bsc = NULL;
239 bsc_endp->pending_delete = 0;
240 } else {
241 endp->ci = bsc_mgcp_extract_ci((const char *) msg->l2h);
242 }
243
Holger Hans Peter Freyther3c3bce12010-04-01 10:16:28 +0200244 /* free some stuff */
245 talloc_free(bsc_endp->transaction_id);
246 bsc_endp->transaction_id = NULL;
247
Holger Hans Peter Freytherdd16b422010-04-07 09:53:54 +0200248 /*
249 * rewrite the information. In case the endpoint was deleted
250 * there should be nothing for us to rewrite so putting endp->rtp_port
251 * with the value of 0 should be no problem.
252 */
Holger Hans Peter Freyther8d200652010-04-04 18:09:10 +0200253 output = bsc_mgcp_rewrite((char * ) msg->l2h, msgb_l2len(msg),
254 bsc->nat->mgcp_cfg->source_addr, endp->rtp_port);
Holger Hans Peter Freyther5cc94fb2010-04-05 22:56:49 +0200255
Holger Hans Peter Freyther3c3bce12010-04-01 10:16:28 +0200256 if (!output) {
257 LOGP(DMGCP, LOGL_ERROR, "Failed to rewrite MGCP msg.\n");
258 return;
259 }
260
261 if (write_queue_enqueue(&bsc->nat->mgcp_queue, output) != 0) {
262 LOGP(DMGCP, LOGL_ERROR, "Failed to queue MGCP msg.\n");
263 msgb_free(output);
264 }
265}
266
267int bsc_mgcp_parse_response(const char *str, int *code, char transaction[60])
268{
269 /* we want to parse two strings */
270 return sscanf(str, "%3d %59s\n", code, transaction) != 2;
271}
272
273int bsc_mgcp_extract_ci(const char *str)
274{
275 int ci;
276 char *res = strstr(str, "I: ");
277 if (!res)
278 return CI_UNUSED;
279
Holger Hans Peter Freyther806aca92010-04-05 09:07:39 +0200280 if (sscanf(res, "I: %d", &ci) != 1)
Holger Hans Peter Freyther3c3bce12010-04-01 10:16:28 +0200281 return CI_UNUSED;
282 return ci;
283}
284
Holger Hans Peter Freyther76c83542010-04-01 06:48:52 +0200285/* we need to replace some strings... */
Holger Hans Peter Freyther8d200652010-04-04 18:09:10 +0200286struct msgb *bsc_mgcp_rewrite(char *input, int length, const char *ip, int port)
Holger Hans Peter Freyther76c83542010-04-01 06:48:52 +0200287{
288 static const char *ip_str = "c=IN IP4 ";
289 static const char *aud_str = "m=audio ";
290
291 char buf[128];
292 char *running, *token;
293 struct msgb *output;
294
Holger Hans Peter Freyther8d200652010-04-04 18:09:10 +0200295 if (length > 4096 - 128) {
Holger Hans Peter Freyther76c83542010-04-01 06:48:52 +0200296 LOGP(DMGCP, LOGL_ERROR, "Input is too long.\n");
297 return NULL;
298 }
299
300 output = msgb_alloc_headroom(4096, 128, "MGCP rewritten");
301 if (!output) {
302 LOGP(DMGCP, LOGL_ERROR, "Failed to allocate new MGCP msg.\n");
303 return NULL;
304 }
305
Holger Hans Peter Freyther8d200652010-04-04 18:09:10 +0200306 running = input;
Holger Hans Peter Freyther76c83542010-04-01 06:48:52 +0200307 output->l2h = output->data;
Holger Hans Peter Freyther9e5300a2010-04-04 19:34:44 +0200308 for (token = strsep(&running, "\n"); running; token = strsep(&running, "\n")) {
Holger Hans Peter Freyther76c83542010-04-01 06:48:52 +0200309 int len = strlen(token);
Holger Hans Peter Freyther9e5300a2010-04-04 19:34:44 +0200310 int cr = len > 0 && token[len - 1] == '\r';
Holger Hans Peter Freyther76c83542010-04-01 06:48:52 +0200311
312 if (strncmp(ip_str, token, (sizeof ip_str) - 1) == 0) {
313 output->l3h = msgb_put(output, strlen(ip_str));
314 memcpy(output->l3h, ip_str, strlen(ip_str));
315 output->l3h = msgb_put(output, strlen(ip));
316 memcpy(output->l3h, ip, strlen(ip));
Holger Hans Peter Freyther9e5300a2010-04-04 19:34:44 +0200317
318 if (cr) {
319 output->l3h = msgb_put(output, 2);
320 output->l3h[0] = '\r';
321 output->l3h[1] = '\n';
322 } else {
323 output->l3h = msgb_put(output, 1);
324 output->l3h[0] = '\n';
325 }
Holger Hans Peter Freyther76c83542010-04-01 06:48:52 +0200326 } else if (strncmp(aud_str, token, (sizeof aud_str) - 1) == 0) {
327 int payload;
328 if (sscanf(token, "m=audio %*d RTP/AVP %d", &payload) != 1) {
329 LOGP(DMGCP, LOGL_ERROR, "Could not parsed audio line.\n");
330 msgb_free(output);
331 return NULL;
332 }
333
Holger Hans Peter Freyther9e5300a2010-04-04 19:34:44 +0200334 snprintf(buf, sizeof(buf)-1, "m=audio %d RTP/AVP %d%s",
335 port, payload, cr ? "\r\n" : "\n");
Holger Hans Peter Freyther76c83542010-04-01 06:48:52 +0200336 buf[sizeof(buf)-1] = '\0';
337
338 output->l3h = msgb_put(output, strlen(buf));
339 memcpy(output->l3h, buf, strlen(buf));
340 } else {
341 output->l3h = msgb_put(output, len + 1);
342 memcpy(output->l3h, token, len);
343 output->l3h[len] = '\n';
344 }
345 }
346
347 return output;
348}
349
Holger Hans Peter Freythera7f80182010-03-31 13:02:22 +0200350static int mgcp_do_read(struct bsc_fd *fd)
351{
352 struct bsc_nat *nat;
353 struct msgb *msg, *resp;
354 int rc;
355
Holger Hans Peter Freyther8d200652010-04-04 18:09:10 +0200356 nat = fd->data;
357
358 rc = read(fd->fd, nat->mgcp_msg, sizeof(nat->mgcp_msg) - 1);
359 if (rc <= 0) {
360 LOGP(DMGCP, LOGL_ERROR, "Failed to read errno: %d\n", errno);
361 return -1;
362 }
363
364 nat->mgcp_msg[rc] = '\0';
365 nat->mgcp_length = rc;
366
367 msg = msgb_alloc(sizeof(nat->mgcp_msg), "MGCP GW Read");
Holger Hans Peter Freythera7f80182010-03-31 13:02:22 +0200368 if (!msg) {
369 LOGP(DMGCP, LOGL_ERROR, "Failed to create buffer.\n");
370 return -1;
371 }
372
Holger Hans Peter Freythera7f80182010-03-31 13:02:22 +0200373 msg->l2h = msgb_put(msg, rc);
Holger Hans Peter Freyther8d200652010-04-04 18:09:10 +0200374 memcpy(msg->l2h, nat->mgcp_msg, msgb_l2len(msg));
Holger Hans Peter Freythera7f80182010-03-31 13:02:22 +0200375 resp = mgcp_handle_message(nat->mgcp_cfg, msg);
376 msgb_free(msg);
377
378 /* we do have a direct answer... e.g. AUEP */
379 if (resp) {
380 if (write_queue_enqueue(&nat->mgcp_queue, resp) != 0) {
381 LOGP(DMGCP, LOGL_ERROR, "Failed to enqueue msg.\n");
382 msgb_free(resp);
383 }
384 }
385
386 return 0;
387}
388
389static int mgcp_do_write(struct bsc_fd *bfd, struct msgb *msg)
390{
391 int rc;
392
393 rc = write(bfd->fd, msg->data, msg->len);
394
395 if (rc != msg->len) {
396 LOGP(DMGCP, LOGL_ERROR, "Failed to write msg to MGCP CallAgent.\n");
397 return -1;
398 }
399
400 return rc;
401}
402
403int bsc_mgcp_init(struct bsc_nat *nat)
404{
405 int on;
406 struct sockaddr_in addr;
407
408 if (!nat->mgcp_cfg->call_agent_addr) {
409 LOGP(DMGCP, LOGL_ERROR, "The BSC nat requires the call agent ip to be set.\n");
410 return -1;
411 }
412
Holger Hans Peter Freythera0df82d2010-04-01 08:21:33 +0200413 if (nat->mgcp_cfg->bts_ip) {
414 LOGP(DMGCP, LOGL_ERROR, "Do not set the BTS ip for the nat.\n");
415 return -1;
416 }
417
Holger Hans Peter Freythera7f80182010-03-31 13:02:22 +0200418 nat->mgcp_queue.bfd.fd = socket(AF_INET, SOCK_DGRAM, 0);
419 if (nat->mgcp_queue.bfd.fd < 0) {
420 LOGP(DMGCP, LOGL_ERROR, "Failed to create MGCP socket. errno: %d\n", errno);
421 return -1;
422 }
423
424 on = 1;
425 setsockopt(nat->mgcp_queue.bfd.fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
426
427 addr.sin_family = AF_INET;
428 addr.sin_port = htons(nat->mgcp_cfg->source_port);
429 inet_aton(nat->mgcp_cfg->source_addr, &addr.sin_addr);
430
431 if (bind(nat->mgcp_queue.bfd.fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
432 LOGP(DMGCP, LOGL_ERROR, "Failed to bind. errno: %d\n", errno);
433 close(nat->mgcp_queue.bfd.fd);
434 nat->mgcp_queue.bfd.fd = -1;
435 return -1;
436 }
437
438 addr.sin_port = htons(2727);
439 inet_aton(nat->mgcp_cfg->call_agent_addr, &addr.sin_addr);
440 if (connect(nat->mgcp_queue.bfd.fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
441 LOGP(DMGCP, LOGL_ERROR, "Failed to connect to: '%s'. errno: %d\n",
442 nat->mgcp_cfg->call_agent_addr, errno);
443 close(nat->mgcp_queue.bfd.fd);
444 nat->mgcp_queue.bfd.fd = -1;
445 return -1;
446 }
447
448 write_queue_init(&nat->mgcp_queue, 10);
449 nat->mgcp_queue.bfd.when = BSC_FD_READ;
450 nat->mgcp_queue.bfd.data = nat;
451 nat->mgcp_queue.read_cb = mgcp_do_read;
452 nat->mgcp_queue.write_cb = mgcp_do_write;
453
454 if (bsc_register_fd(&nat->mgcp_queue.bfd) != 0) {
455 LOGP(DMGCP, LOGL_ERROR, "Failed to register MGCP fd.\n");
456 close(nat->mgcp_queue.bfd.fd);
457 nat->mgcp_queue.bfd.fd = -1;
458 return -1;
459 }
460
Holger Hans Peter Freythera0df82d2010-04-01 08:21:33 +0200461 /* some more MGCP config handling */
Holger Hans Peter Freyther4ad58502010-04-06 11:14:03 +0200462 nat->mgcp_cfg->audio_payload = -1;
Holger Hans Peter Freythera0df82d2010-04-01 08:21:33 +0200463 nat->mgcp_cfg->data = nat;
464 nat->mgcp_cfg->policy_cb = bsc_mgcp_policy_cb;
Holger Hans Peter Freytherbba59342010-04-07 10:52:48 +0200465 nat->mgcp_cfg->force_realloc = 1;
Holger Hans Peter Freyther290d84e2010-04-09 18:51:01 +0200466 nat->mgcp_cfg->bts_ip = "";
Holger Hans Peter Freythera0df82d2010-04-01 08:21:33 +0200467 nat->bsc_endpoints = talloc_zero_array(nat,
468 struct bsc_endpoint,
469 nat->mgcp_cfg->number_endpoints + 1);
470
Holger Hans Peter Freythera7f80182010-03-31 13:02:22 +0200471 return 0;
472}
Holger Hans Peter Freyther26a43892010-04-05 23:09:27 +0200473
474void bsc_mgcp_clear_endpoints_for(struct bsc_connection *bsc)
475{
476 int i;
477 for (i = 1; i < bsc->nat->mgcp_cfg->number_endpoints; ++i) {
478 struct bsc_endpoint *bsc_endp = &bsc->nat->bsc_endpoints[i];
479
480 if (bsc_endp->bsc != bsc)
481 continue;
482
483 bsc_endp->bsc = NULL;
484 bsc_endp->pending_delete = 0;
485 if (bsc_endp->transaction_id)
486 talloc_free(bsc_endp->transaction_id);
487 bsc_endp->transaction_id = NULL;
488 mgcp_free_endp(&bsc->nat->mgcp_cfg->endpoints[i]);
489 }
490}