diff options
Diffstat (limited to 'src/main_udt.c')
-rw-r--r-- | src/main_udt.c | 134 |
1 files changed, 22 insertions, 112 deletions
diff --git a/src/main_udt.c b/src/main_udt.c index f44be21..f13d4dd 100644 --- a/src/main_udt.c +++ b/src/main_udt.c @@ -1,7 +1,7 @@ /* Relay UDT/all SCCP messages */ /* - * (C) 2010 by Holger Hans Peter Freyther <zecke@selfish.org> - * (C) 2010 by On-Waves + * (C) 2010-2011 by Holger Hans Peter Freyther <zecke@selfish.org> + * (C) 2010-2011 by On-Waves * All Rights Reserved * * This program is free software: you can redistribute it and/or modify @@ -62,59 +62,27 @@ static char *config = "udt_relay.cfg"; struct bsc_data bsc; extern void cell_vty_init(void); -int link_c7_init(struct link_data *data) __attribute__((__weak__)); - -int link_c7_init(struct link_data *data) -{ - return -1; -} - /* * methods called from the MTP Level3 part */ -void mtp_link_submit(struct mtp_link *link, struct msgb *msg) -{ - bsc.link.write(&bsc.link, msg); -} - -void mtp_link_restart(struct mtp_link *link) -{ - LOGP(DINP, LOGL_ERROR, "Need to restart the SS7 link.\n"); - bsc.link.reset(&bsc.link); -} - -void mtp_link_sccp_down(struct mtp_link *link) -{ - msc_clear_queue(&bsc); -} - -void mtp_link_forward_sccp(struct mtp_link *link, struct msgb *_msg, int sls) +void mtp_link_set_forward_sccp(struct mtp_link_set *link, struct msgb *_msg, int sls) { msc_send_direct(&bsc, _msg); } -void bsc_link_down(struct link_data *data) +void mtp_linkset_down(struct mtp_link_set *set) { - int was_up; - struct mtp_link *link = data->the_link; - - link->available = 0; - was_up = link->sccp_up; - mtp_link_stop(link); - - data->clear_queue(data); - - /* clear pending messages from the MSC */ - msc_clear_queue(data->bsc); + set->available = 0; + mtp_link_set_stop(set); /* If we have an A link send a reset to the MSC */ - msc_send_reset(data->bsc); + msc_send_reset(set->bsc); } -void bsc_link_up(struct link_data *data) +void mtp_linkset_up(struct mtp_link_set *set) { - data->the_link->available = 1; - mtp_link_reset(data->the_link); + set->available = 1; + mtp_link_set_reset(set); } static void print_usage() @@ -136,7 +104,7 @@ static void sigint() printf("Terminating.\n"); handled = 1; if (bsc.setup) - bsc.link.shutdown(&bsc.link); + link_shutdown_all(bsc.link_set); exit(0); out: @@ -182,14 +150,14 @@ static void handle_options(int argc, char **argv) print_help(); exit(0); case 'p': - if (bsc.link.pcap_fd >= 0) - close(bsc.link.pcap_fd); - bsc.link.pcap_fd = open(optarg, O_WRONLY | O_TRUNC | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP| S_IROTH); - if (bsc.link.pcap_fd < 0) { + if (bsc.pcap_fd >= 0) + close(bsc.pcap_fd); + bsc.pcap_fd = open(optarg, O_WRONLY | O_TRUNC | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP| S_IROTH); + if (bsc.pcap_fd < 0) { fprintf(stderr, "Failed to open PCAP file.\n"); exit(0); } - mtp_pcap_write_header(bsc.link.pcap_fd); + mtp_pcap_write_header(bsc.pcap_fd); break; case 'c': config = optarg; @@ -205,19 +173,6 @@ static void handle_options(int argc, char **argv) } } -static void start_rest(void *start) -{ - bsc.setup = 1; - - if (msc_init(&bsc, 0) != 0) { - fprintf(stderr, "Failed to init MSC part.\n"); - exit(3); - } - - bsc.link.start(&bsc.link); -} - - int main(int argc, char **argv) { int rc; @@ -232,7 +187,7 @@ int main(int argc, char **argv) bsc.ni_ni = MTP_NI_NATION_NET; bsc.ni_spare = 0; - mtp_link_init(); + mtp_link_set_init(); thread_init(); log_init(&log_info); @@ -252,8 +207,8 @@ int main(int argc, char **argv) bsc.setup = 0; bsc.msc_address = "127.0.0.1"; - bsc.link.pcap_fd = -1; - bsc.link.udp.reset_timeout = 180; + bsc.pcap_fd = -1; + bsc.udp_reset_timeout = 180; bsc.ping_time = 20; bsc.pong_time = 5; bsc.msc_time = 20; @@ -276,51 +231,8 @@ int main(int argc, char **argv) if (rc < 0) return rc; - bsc.link.the_link = mtp_link_alloc(); - bsc.link.the_link->dpc = bsc.dpc; - bsc.link.the_link->opc = bsc.opc; - bsc.link.the_link->sccp_opc = bsc.sccp_opc > -1 ? bsc.sccp_opc : bsc.opc; - bsc.link.the_link->link = 0; - bsc.link.the_link->sltm_once = bsc.once; - bsc.link.the_link->ni = bsc.ni_ni; - bsc.link.the_link->spare = bsc.ni_spare; - bsc.link.bsc = &bsc; - - if (bsc.udp_ip) { - LOGP(DINP, LOGL_NOTICE, "Using UDP MTP mode.\n"); - - /* setup SNMP first, it is blocking */ - bsc.link.udp.session = snmp_mtp_session_create(bsc.udp_ip); - if (!bsc.link.udp.session) - return -1; - - /* now connect to the transport */ - if (link_udp_init(&bsc.link, bsc.src_port, bsc.udp_ip, bsc.udp_port) != 0) - return -1; - - /* - * We will ask the MTP link to be taken down for two - * timeouts of the BSC to make sure we are missing the - * SLTM and it begins a reset. Then we will take it up - * again and do the usual business. - */ - snmp_mtp_deactivate(bsc.link.udp.session); - bsc.start_timer.cb = start_rest; - bsc.start_timer.data = &bsc; - bsc_schedule_timer(&bsc.start_timer, bsc.link.udp.reset_timeout, 0); - LOGP(DMSC, LOGL_NOTICE, "Making sure SLTM will timeout.\n"); - } else { - LOGP(DINP, LOGL_NOTICE, "Using NexusWare C7 input.\n"); - if (link_c7_init(&bsc.link) != 0) - return -1; - - /* give time to things to start*/ - bsc.start_timer.cb = start_rest; - bsc.start_timer.data = &bsc; - bsc_schedule_timer(&bsc.start_timer, 30, 0); - LOGP(DMSC, LOGL_NOTICE, "Waiting to continue to startup.\n"); - } - + if (link_init(&bsc) != 0) + return -1; while (1) { bsc_select_main(0); @@ -331,8 +243,6 @@ int main(int argc, char **argv) void release_bsc_resources(struct bsc_data *bsc) { - /* clear pending messages from the MSC */ - msc_clear_queue(bsc); } struct msgb *create_sccp_rlc(struct sccp_source_reference *src_ref, @@ -348,7 +258,7 @@ struct msgb *create_reset() return NULL; } -void update_con_state(struct mtp_link *link, int rc, struct sccp_parse_result *res, struct msgb *msg, int from_msc, int sls) +void update_con_state(struct mtp_link_set *link, int rc, struct sccp_parse_result *res, struct msgb *msg, int from_msc, int sls) { LOGP(DMSC, LOGL_ERROR, "Should not be called.\n"); return; |