diff options
-rw-r--r-- | include/bsc_data.h | 4 | ||||
-rw-r--r-- | include/mtp_data.h | 5 | ||||
-rw-r--r-- | include/sccp_lite.h | 40 | ||||
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/main_stp.c | 20 | ||||
-rw-r--r-- | src/mtp_layer3.c | 63 | ||||
-rw-r--r-- | src/sccp_lite.c | 54 | ||||
-rw-r--r-- | src/sctp_m2ua.c | 52 |
8 files changed, 185 insertions, 55 deletions
diff --git a/include/bsc_data.h b/include/bsc_data.h index 9c1145f..61627b6 100644 --- a/include/bsc_data.h +++ b/include/bsc_data.h @@ -87,6 +87,10 @@ struct bsc_data { struct mtp_transport *m2ua_trans; int m2ua_src_port; + /* sccp lite code */ + struct mtp_transport *lite_trans; + int lite_src_port; + /* MSCs */ struct llist_head mscs; int num_mscs; diff --git a/include/mtp_data.h b/include/mtp_data.h index 295afb2..3ef809c 100644 --- a/include/mtp_data.h +++ b/include/mtp_data.h @@ -202,4 +202,9 @@ struct mtp_link_set *mtp_link_set_num(struct bsc_data *bsc, int num); struct mtp_link *mtp_link_alloc(struct mtp_link_set *set); struct mtp_link *mtp_link_num(struct mtp_link_set *set, int num); +/* transport management */ +struct mtp_transport *mtp_transport_create(struct bsc_data *trans); +int mtp_transport_bind(struct mtp_transport *, int proto, const char *ip, int port); + + #endif diff --git a/include/sccp_lite.h b/include/sccp_lite.h new file mode 100644 index 0000000..9abc1b9 --- /dev/null +++ b/include/sccp_lite.h @@ -0,0 +1,40 @@ +/* Run SCCP over IP/TCP/IPA */ +/* (C) 2011-2013 by Holger Hans Peter Freyther <zecke@selfish.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation; either version 3 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef sccp_lite_h +#define sccp_lite_h + +#include "mtp_data.h" + +struct sccp_lite_link { + struct mtp_link *base; + + int active; + int established; + struct sccp_lite_conn *conn; + + /* token handling for pseudo-authentication */ + char *token; + + /* back pointer and management */ + struct mtp_transport *transport; +}; + +struct mtp_transport *sccp_lite_transp_create(struct bsc_data *bsc); +int sccp_lite_transp_bind(struct mtp_transport *trans, const char *ip, int port); + +#endif diff --git a/src/Makefile.am b/src/Makefile.am index d2e211d..8a2ad3f 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -26,7 +26,7 @@ osmo_stp_SOURCES = main_stp.c mtp_layer3.c thread.c pcap.c link_udp.c snmp_mtp.c bss_patch.c bssap_sccp.c bsc_sccp.c bsc_ussd.c input/ipaccess.c \ mtp_link.c counter.c bsc.c ss7_application.c \ vty_interface.c vty_interface_cmds.c mgcp_patch.c \ - mgcp_callagent.c isup_filter.c + mgcp_callagent.c isup_filter.c sccp_lite.c osmo_stp_LDADD = $(LIBOSMOCORE_LIBS) $(LIBOSMOGSM_LIBS) $(LIBOSMOVTY_LIBS) \ $(LIBOSMOSCCP_LIBS) $(NEXUSWARE_C7_LIBS) \ -lpthread -lnetsnmp -lcrypto -lm2ua -lsctp diff --git a/src/main_stp.c b/src/main_stp.c index 11f6255..2efc078 100644 --- a/src/main_stp.c +++ b/src/main_stp.c @@ -1,7 +1,7 @@ /* Relay UDT/all SCCP messages */ /* - * (C) 2010-2011 by Holger Hans Peter Freyther <zecke@selfish.org> - * (C) 2010-2011 by On-Waves + * (C) 2010-2013 by Holger Hans Peter Freyther <zecke@selfish.org> + * (C) 2010-2013 by On-Waves * All Rights Reserved * * This program is free software; you can redistribute it and/or modify @@ -28,6 +28,7 @@ #include <snmp_mtp.h> #include <cellmgr_debug.h> #include <sctp_m2ua.h> +#include <sccp_lite.h> #include <ss7_application.h> #include <osmocom/m2ua/m2ua_msg.h> @@ -251,6 +252,12 @@ int main(int argc, char **argv) return -1; } + bsc->lite_trans = sccp_lite_transp_create(bsc); + if (!bsc->lite_trans) { + LOGP(DINP, LOGL_ERROR, "Failed to create SCCP lite transport.\n"); + return -1; + } + if (vty_read_config_file(config, NULL) < 0) { fprintf(stderr, "Failed to read the VTY config.\n"); return -1; @@ -267,6 +274,15 @@ int main(int argc, char **argv) return -1; } + /* initialize only if there is a user */ + if (bsc->lite_src_port != 0 + && sccp_lite_transp_bind(bsc->lite_trans, "0.0.0.0", + bsc->lite_src_port) != 0) { + LOGP(DINP, LOGL_ERROR, + "Failed to bind on port %d\n", bsc->lite_src_port); + return -1; + } + if (mgcp_create_port(&bsc->mgcp_agent) != 0) { LOGP(DINP, LOGL_ERROR, "Failed to create the MGCP call agent.\n"); diff --git a/src/mtp_layer3.c b/src/mtp_layer3.c index 92e8f41..a3aa2e9 100644 --- a/src/mtp_layer3.c +++ b/src/mtp_layer3.c @@ -1,7 +1,7 @@ /* MTP layer3 main handling code */ /* - * (C) 2010-2011 by Holger Hans Peter Freyther <zecke@selfish.org> - * (C) 2010-2011 by On-Waves + * (C) 2010-2013 by Holger Hans Peter Freyther <zecke@selfish.org> + * (C) 2010-2013 by On-Waves * All Rights Reserved * * This program is free software: you can redistribute it and/or modify @@ -32,6 +32,7 @@ #include <arpa/inet.h> #include <string.h> +#include <unistd.h> static int mtp_int_submit(struct mtp_link_set *set, int opc, int dpc, int sls, int type, const uint8_t *data, unsigned int length); @@ -680,3 +681,61 @@ struct mtp_link_set *mtp_link_set_num(struct bsc_data *bsc, int num) return NULL; } + +struct mtp_transport *mtp_transport_create(struct bsc_data *bsc) +{ + struct mtp_transport *trans; + + trans = talloc_zero(bsc, struct mtp_transport); + if (!trans) { + LOGP(DINP, LOGL_ERROR, "Allocation failure.\n"); + return NULL; + } + + INIT_LLIST_HEAD(&trans->conns); + INIT_LLIST_HEAD(&trans->links); + + return trans; +} + +int mtp_transport_bind(struct mtp_transport *transp, int proto, + const char *ip, int port) +{ + int fd; + struct sockaddr_in addr; + + fd = socket(PF_INET, SOCK_STREAM, proto); + if (!fd) { + LOGP(DINP, LOGL_ERROR, "Failed to create socket.\n"); + return -1; + } + + memset(&addr, 0, sizeof(addr)); + addr.sin_family = AF_INET; + addr.sin_port = htons(port); + addr.sin_addr.s_addr = inet_addr(ip); + + if (bind(fd, (struct sockaddr *) &addr, sizeof(addr)) != 0) { + LOGP(DINP, LOGL_ERROR, "Failed to bind.\n"); + close(fd); + return -2; + } + + if (listen(fd, 1) != 0) { + LOGP(DINP, LOGL_ERROR, "Failed to listen.\n"); + close(fd); + return -3; + } + + transp->bsc.fd = fd; + transp->bsc.data = transp; + transp->bsc.when = BSC_FD_READ; + + if (osmo_fd_register(&transp->bsc) != 0) { + LOGP(DINP, LOGL_ERROR, "Failed to register the fd.\n"); + close(fd); + return -4; + } + + return 0; +} diff --git a/src/sccp_lite.c b/src/sccp_lite.c new file mode 100644 index 0000000..fb8c1d3 --- /dev/null +++ b/src/sccp_lite.c @@ -0,0 +1,54 @@ +/* Run SCCP over IP/TCP/IPA here */ +/* (C) 2011-2013 by Holger Hans Peter Freyther <zecke@selfish.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation; either version 3 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <sccp_lite.h> +#include <cellmgr_debug.h> + +#include <sys/types.h> +#include <sys/socket.h> +#include <arpa/inet.h> + +#include <unistd.h> + +static int sccp_lite_transp_accept(struct osmo_fd *fd, unsigned int what) +{ + struct sockaddr_in addr; + socklen_t len = sizeof(addr); + int s; + + s = accept(fd->fd, (struct sockaddr *) &addr, &len); + if (s < 0) { + LOGP(DINP, LOGL_ERROR, "Failed to accept.\n"); + return -1; + } + + LOGP(DINP, LOGL_NOTICE, "Socket handling not implemented yet.\n"); + close(s); + return 0; +} + +struct mtp_transport *sccp_lite_transp_create(struct bsc_data *bsc) +{ + return mtp_transport_create(bsc); +} + +int sccp_lite_transp_bind(struct mtp_transport *transp, + const char *ip, int port) +{ + transp->bsc.cb = sccp_lite_transp_accept; + return mtp_transport_bind(transp, IPPROTO_TCP, ip, port); +} diff --git a/src/sctp_m2ua.c b/src/sctp_m2ua.c index e458325..9fd1dd5 100644 --- a/src/sctp_m2ua.c +++ b/src/sctp_m2ua.c @@ -759,62 +759,14 @@ static int sctp_m2ua_reset(struct mtp_link *_link) struct mtp_transport *sctp_m2ua_transp_create(struct bsc_data *bsc) { - struct mtp_transport *trans; - - trans = talloc_zero(bsc, struct mtp_transport); - if (!trans) { - LOGP(DINP, LOGL_ERROR, "Remove the talloc.\n"); - return NULL; - } - - INIT_LLIST_HEAD(&trans->conns); - INIT_LLIST_HEAD(&trans->links); - - - return trans; + return mtp_transport_create(bsc); } int sctp_m2ua_transport_bind(struct mtp_transport *trans, const char *ip, int port) { - int sctp; - struct sockaddr_in addr; - - sctp = socket(PF_INET, SOCK_STREAM, IPPROTO_SCTP); - if (!sctp) { - LOGP(DINP, LOGL_ERROR, "Failed to create socket.\n"); - return -1; - } - - memset(&addr, 0, sizeof(addr)); - addr.sin_family = AF_INET; - addr.sin_port = htons(port); - addr.sin_addr.s_addr = inet_addr(ip); - - if (bind(sctp, (struct sockaddr *) &addr, sizeof(addr)) != 0) { - LOGP(DINP, LOGL_ERROR, "Failed to bind.\n"); - close(sctp); - return -2; - } - - if (listen(sctp, 1) != 0) { - LOGP(DINP, LOGL_ERROR, "Failed to listen.\n"); - close(sctp); - return -3; - } - - trans->bsc.fd = sctp; - trans->bsc.data = trans; trans->bsc.cb = sctp_trans_accept; - trans->bsc.when = BSC_FD_READ; - - if (osmo_fd_register(&trans->bsc) != 0) { - LOGP(DINP, LOGL_ERROR, "Failed to register the fd.\n"); - close(sctp); - return -4; - } - - return 0; + return mtp_transport_bind(trans, IPPROTO_SCTP, ip, port); } struct mtp_m2ua_link *mtp_m2ua_link_init(struct mtp_link *blnk) |