9
0
Fork 0

sccp: Begin to introduce a SCCP-lite/MAP-lite handler

The goal is to have a simple IP/TCP/IPA/SCCP connector that can
talk IP/SCTP/M2UA/SCCP on the other side of the link. Refactor
and share the code with the sctp handler.
This commit is contained in:
Holger Hans Peter Freyther 2013-03-11 18:58:13 +01:00
parent 2031c9510c
commit 53e2ba8e5a
8 changed files with 185 additions and 55 deletions

View File

@ -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;

View File

@ -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

40
include/sccp_lite.h Normal file
View File

@ -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

View File

@ -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

View File

@ -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");

View File

@ -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;
}

54
src/sccp_lite.c Normal file
View File

@ -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);
}

View File

@ -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)