From 52ccf6a480f15a32d2fa79ed4ffcb6f334d1550f Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Fri, 6 Aug 2010 07:48:41 +0800 Subject: mgcp: Fix discovering the RTCP port with the more strict check. If we have found the BTS and we receive data on the RTCP port from the IP of the BTS we will set our RTCP port and forward it to the network and hope it will be useful. --- openbsc/src/mgcp/mgcp_network.c | 40 +++++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/openbsc/src/mgcp/mgcp_network.c b/openbsc/src/mgcp/mgcp_network.c index d38542c39..ce81f3c7a 100644 --- a/openbsc/src/mgcp/mgcp_network.c +++ b/openbsc/src/mgcp/mgcp_network.c @@ -265,6 +265,32 @@ static int rtp_data_net(struct bsc_fd *fd, unsigned int what) return send_to(endp, DEST_BTS, proto == PROTO_RTP, &addr, &buf[0], rc); } +static void discover_bts(struct mgcp_endpoint *endp, int proto, struct sockaddr_in *addr) +{ + struct mgcp_config *cfg = endp->cfg; + + if (proto == PROTO_RTP && endp->bts_end.rtp_port == 0) { + if (!cfg->bts_ip || + memcmp(&addr->sin_addr, + &cfg->bts_in, sizeof(cfg->bts_in)) == 0 || + memcmp(&addr->sin_addr, + &endp->bts_end.addr, sizeof(endp->bts_end.addr)) == 0) { + + endp->bts_end.rtp_port = addr->sin_port; + endp->bts_end.addr = addr->sin_addr; + + LOGP(DMGCP, LOGL_NOTICE, + "Found BTS for endpoint: 0x%x on port: %d/%d of %s\n", + ENDPOINT_NUMBER(endp), ntohs(endp->bts_end.rtp_port), + ntohs(endp->bts_end.rtcp_port), inet_ntoa(addr->sin_addr)); + } + } else if (proto == PROTO_RTCP && endp->bts_end.rtcp_port == 0) { + if (memcmp(&endp->bts_end.addr, &addr->sin_addr, + sizeof(endp->bts_end.addr)) == 0) { + endp->bts_end.rtcp_port = addr->sin_port; + } + } +} static int rtp_data_bts(struct bsc_fd *fd, unsigned int what) { @@ -285,19 +311,7 @@ static int rtp_data_bts(struct bsc_fd *fd, unsigned int what) /* We have no idea who called us, maybe it is the BTS. */ /* it was the BTS... */ - if (endp->bts_end.rtp_port == 0 && (!cfg->bts_ip - || memcmp(&addr.sin_addr, &cfg->bts_in, sizeof(cfg->bts_in)) == 0 - || memcmp(&addr.sin_addr, &endp->bts_end.addr, sizeof(endp->bts_end.addr)) == 0)) { - if (proto == PROTO_RTP) - endp->bts_end.rtp_port = addr.sin_port; - else - endp->bts_end.rtcp_port = addr.sin_port; - - endp->bts_end.addr = addr.sin_addr; - LOGP(DMGCP, LOGL_NOTICE, "Found BTS for endpoint: 0x%x on port: %d/%d of %s\n", - ENDPOINT_NUMBER(endp), ntohs(endp->bts_end.rtp_port), ntohs(endp->bts_end.rtcp_port), - inet_ntoa(addr.sin_addr)); - } + discover_bts(endp, proto, &addr); if (memcmp(&endp->bts_end.addr, &addr.sin_addr, sizeof(addr.sin_addr)) != 0) { LOGP(DMGCP, LOGL_ERROR, -- cgit v1.2.3