diff options
author | Holger Hans Peter Freyther <zecke@selfish.org> | 2010-01-12 20:40:03 +0100 |
---|---|---|
committer | Holger Hans Peter Freyther <zecke@selfish.org> | 2010-01-12 20:40:39 +0100 |
commit | a92fe9a4ca7e309a80095521160f5d3d946932ec (patch) | |
tree | 7a82003e97371e016d46c3354c0432f928291a2b /openbsc/src | |
parent | e83a3f584e9644f127ed35967c415f19f06a03d5 (diff) |
[bsc_msc] Move the connect to the MSC routine into a new file
Diffstat (limited to 'openbsc/src')
-rw-r--r-- | openbsc/src/Makefile.am | 5 | ||||
-rw-r--r-- | openbsc/src/bsc_msc.c | 72 | ||||
-rw-r--r-- | openbsc/src/bsc_msc_ip.c | 49 |
3 files changed, 78 insertions, 48 deletions
diff --git a/openbsc/src/Makefile.am b/openbsc/src/Makefile.am index 40591397a..b6a8536a5 100644 --- a/openbsc/src/Makefile.am +++ b/openbsc/src/Makefile.am @@ -26,7 +26,8 @@ libsccp_a_SOURCES = sccp/sccp.c bsc_hack_SOURCES = bsc_hack.c bsc_init.c vty_interface.c vty_interface_layer3.c bsc_hack_LDADD = libmsc.a libbsc.a libmsc.a libvty.a -ldl -ldbi $(LIBCRYPT) -bsc_msc_ip_SOURCES = bssap.c bsc_msc_ip.c bsc_init.c vty_interface.c vty_interface_bsc.c +bsc_msc_ip_SOURCES = bssap.c bsc_msc_ip.c bsc_init.c vty_interface.c vty_interface_bsc.c \ + bsc_msc.c bsc_msc_ip_LDADD = libbsc.a libvty.a libsccp.a bs11_config_SOURCES = bs11_config.c abis_nm.c gsm_data.c msgb.c debug.c \ @@ -42,5 +43,5 @@ isdnsync_SOURCES = isdnsync.c bsc_mgcp_SOURCES = bsc_mgcp.c msgb.c talloc.c debug.c select.c timer.c telnet_interface.c bsc_mgcp_LDADD = libvty.a -bsc_nat_SOURCES = nat/bsc_nat.c +bsc_nat_SOURCES = nat/bsc_nat.c bsc_msc.c bsc_nat_LDADD = libbsc.a libsccp.a diff --git a/openbsc/src/bsc_msc.c b/openbsc/src/bsc_msc.c new file mode 100644 index 000000000..48b918ba6 --- /dev/null +++ b/openbsc/src/bsc_msc.c @@ -0,0 +1,72 @@ +/* Routines to talk to the MSC using the IPA Protocol */ +/* + * (C) 2010 by Holger Hans Peter Freyther <zecke@selfish.org> + * (C) 2010 by on-waves.com + * All Rights Reserved + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + */ + +#include <openbsc/bsc_msc.h> + +#include <arpa/inet.h> +#include <sys/socket.h> +#include <stdio.h> +#include <string.h> +#include <unistd.h> + +int connect_to_msc(struct bsc_fd *fd, const char *ip, int port) +{ + struct sockaddr_in sin; + int on = 1, ret; + + printf("Attempting to connect MSC at %s:%d\n", ip, port); + + fd->fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); + fd->when = BSC_FD_READ; + fd->data = NULL; + fd->priv_nr = 1; + + if (fd->fd < 0) { + perror("Creating TCP socket failed"); + return fd->fd; + } + + + memset(&sin, 0, sizeof(sin)); + sin.sin_family = AF_INET; + sin.sin_port = htons(port); + inet_aton(ip, &sin.sin_addr); + + setsockopt(fd->fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)); + ret = connect(fd->fd, (struct sockaddr *) &sin, sizeof(sin)); + + if (ret < 0) { + perror("Connection failed"); + return ret; + } + + ret = bsc_register_fd(fd); + if (ret < 0) { + perror("Registering the fd failed"); + close(fd->fd); + return ret; + } + + return ret; +} + + diff --git a/openbsc/src/bsc_msc_ip.c b/openbsc/src/bsc_msc_ip.c index 491d56c85..73a31ffc3 100644 --- a/openbsc/src/bsc_msc_ip.c +++ b/openbsc/src/bsc_msc_ip.c @@ -45,6 +45,7 @@ #include <openbsc/paging.h> #include <openbsc/signal.h> #include <openbsc/chan_alloc.h> +#include <openbsc/bsc_msc.h> #include <sccp/sccp.h> @@ -605,51 +606,6 @@ static int ipaccess_a_fd_cb(struct bsc_fd *bfd, unsigned int what) return 0; } -/* - * Connect to the MSC - */ -static int connect_to_msc(const char *ip, int port) -{ - struct sockaddr_in sin; - int on = 1, ret; - - printf("Attempting to connect MSC at %s:%d\n", ip, port); - - msc_connection.fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); - msc_connection.cb = ipaccess_a_fd_cb; - msc_connection.when = BSC_FD_READ; - msc_connection.data = NULL; - msc_connection.priv_nr = 1; - - if (msc_connection.fd < 0) { - perror("Creating TCP socket failed"); - return msc_connection.fd; - } - - - memset(&sin, 0, sizeof(sin)); - sin.sin_family = AF_INET; - sin.sin_port = htons(port); - inet_aton(ip, &sin.sin_addr); - - setsockopt(msc_connection.fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)); - ret = connect(msc_connection.fd, (struct sockaddr *) &sin, sizeof(sin)); - - if (ret < 0) { - perror("Connection failed"); - return ret; - } - - ret = bsc_register_fd(&msc_connection); - if (ret < 0) { - perror("Registering the fd failed"); - close(msc_connection.fd); - return ret; - } - - return ret; -} - static void print_help() { printf(" Some useful help...\n"); @@ -796,7 +752,8 @@ int main(int argc, char **argv) /* initialize ipaccess handling */ register_signal_handler(SS_ABISIP, handle_abisip_signal, NULL); - rc = connect_to_msc(msc_address, 5000); + msc_connection.cb = ipaccess_a_fd_cb; + rc = connect_to_msc(&msc_connection, msc_address, 5000); if (rc < 0) { fprintf(stderr, "Opening the MSC connection failed.\n"); exit(1); |