/* the client socket is what we use for reception. It is a UDP socket * that's bound to the GSMTAP UDP port and subscribed to the respective * multicast group */ int mcast_client_sock_setup(struct osmo_fd *ofd, const char *mcast_group, uint16_t mcast_port, int (*fd_rx_cb)(struct osmo_fd *ofd, unsigned int what), void *osmo_fd_data) { int rc; unsigned int flags = OSMO_SOCK_F_BIND | OSMO_SOCK_F_NO_MCAST_ALL | OSMO_SOCK_F_UDP_REUSEADDR; ofd->cb = fd_rx_cb; ofd->when = BSC_FD_READ; ofd->data = osmo_fd_data; /* Create mcast client socket */ rc = osmo_sock_init_ofd(ofd, AF_INET, SOCK_DGRAM, IPPROTO_UDP, NULL, mcast_port, flags); if (rc < 0) { perror("Could not create mcast client socket"); return rc; } /* Configure and join the multicast group */ rc = osmo_sock_mcast_subscribe(ofd->fd, mcast_group); if (rc < 0) { perror("Failed to join to mcast goup"); osmo_fd_close(ofd); return rc; } return 0; }
int main(int argc, char **argv) { struct l1fwd_hdl *l1fh; struct femtol1_hdl *fl1h; int rc, i; printf("sizeof(GsmL1_Prim_t) = %zu\n", sizeof(GsmL1_Prim_t)); printf("sizeof(SuperFemto_Prim_t) = %zu\n", sizeof(SuperFemto_Prim_t)); bts_log_init(NULL); /* allocate new femtol1_handle */ fl1h = talloc_zero(NULL, struct femtol1_hdl); INIT_LLIST_HEAD(&fl1h->wlc_list); /* open the actual hardware transport */ for (i = 0; i < ARRAY_SIZE(fl1h->write_q); i++) { rc = l1if_transport_open(i, fl1h); if (rc < 0) exit(1); } /* create our fwd handle */ l1fh = talloc_zero(NULL, struct l1fwd_hdl); l1fh->fl1h = fl1h; fl1h->priv = l1fh; /* Open UDP */ for (i = 0; i < ARRAY_SIZE(l1fh->udp_wq); i++) { struct osmo_wqueue *wq = &l1fh->udp_wq[i]; osmo_wqueue_init(wq, 10); wq->write_cb = udp_write_cb; wq->read_cb = udp_read_cb; wq->bfd.when |= BSC_FD_READ; wq->bfd.data = l1fh; wq->bfd.priv_nr = i; rc = osmo_sock_init_ofd(&wq->bfd, AF_UNSPEC, SOCK_DGRAM, IPPROTO_UDP, NULL, fwd_udp_ports[i], OSMO_SOCK_F_BIND); if (rc < 0) { perror("sock_init"); exit(1); } } while (1) { rc = osmo_select_main(0); if (rc < 0) { perror("select"); exit(1); } } exit(0); }
int lc15bts_mgr_nl_init(void) { int rc; nl_fd.cb = ipaccess_bcast; rc = osmo_sock_init_ofd(&nl_fd, AF_INET, SOCK_DGRAM, IPPROTO_UDP, "0.0.0.0", 3006, OSMO_SOCK_F_BIND); if (rc < 0) { perror("Socket creation"); return -1; } return 0; }
/* server socket is what we use for transmission. It is not subscribed * to a multicast group or locally bound, but it is just a normal UDP * socket that's connected to the remote mcast group + port */ int mcast_server_sock_setup(struct osmo_fd *ofd, const char* tx_mcast_group, uint16_t tx_mcast_port, bool loopback) { int rc; unsigned int flags = OSMO_SOCK_F_CONNECT | OSMO_SOCK_F_UDP_REUSEADDR; if (!loopback) flags |= OSMO_SOCK_F_NO_MCAST_LOOP; /* setup mcast server socket */ rc = osmo_sock_init_ofd(ofd, AF_INET, SOCK_DGRAM, IPPROTO_UDP, tx_mcast_group, tx_mcast_port, flags); if (rc < 0) { perror("Failed to create Multicast Server Socket"); return rc; } return 0; }
/* open socket */ static int trx_udp_open(void *priv, struct osmo_fd *ofd, const char *host, uint16_t port_local, uint16_t port_remote, int (*cb)(struct osmo_fd *fd, unsigned int what)) { struct sockaddr_storage sas; struct sockaddr *sa = (struct sockaddr *)&sas; socklen_t sa_len; int rc; /* Init */ ofd->fd = -1; ofd->cb = cb; ofd->data = priv; /* Listen / Binds */ rc = osmo_sock_init_ofd(ofd, AF_UNSPEC, SOCK_DGRAM, 0, host, port_local, OSMO_SOCK_F_BIND); if (rc < 0) return rc; /* Connect */ sa_len = sizeof(sas); rc = getsockname(ofd->fd, sa, &sa_len); if (rc) return rc; if (sa->sa_family == AF_INET) { struct sockaddr_in *sin = (struct sockaddr_in *)sa; sin->sin_port = htons(port_remote); } else if (sa->sa_family == AF_INET6) { struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sa; sin6->sin6_port = htons(port_remote); } else { return -EINVAL; } rc = connect(ofd->fd, sa, sa_len); if (rc) return rc; return 0; }
int meas_feed_cfg_set(const char *dst_host, uint16_t dst_port) { int rc; int already_initialized = 0; if (g_mfs.wqueue.bfd.fd) already_initialized = 1; if (already_initialized && !strcmp(dst_host, g_mfs.dst_host) && dst_port == g_mfs.dst_port) return 0; if (!already_initialized) { osmo_wqueue_init(&g_mfs.wqueue, 10); g_mfs.wqueue.write_cb = feed_write_cb; g_mfs.wqueue.read_cb = feed_read_cb; osmo_signal_register_handler(SS_LCHAN, meas_feed_sig_cb, NULL); } if (already_initialized) { osmo_wqueue_clear(&g_mfs.wqueue); osmo_fd_unregister(&g_mfs.wqueue.bfd); close(g_mfs.wqueue.bfd.fd); /* don't set to zero, as that would mean 'not yet initialized' */ g_mfs.wqueue.bfd.fd = -1; } rc = osmo_sock_init_ofd(&g_mfs.wqueue.bfd, AF_UNSPEC, SOCK_DGRAM, IPPROTO_UDP, dst_host, dst_port, OSMO_SOCK_F_CONNECT); if (rc < 0) return rc; g_mfs.wqueue.bfd.when &= ~BSC_FD_READ; if (g_mfs.dst_host) talloc_free(g_mfs.dst_host); g_mfs.dst_host = talloc_strdup(NULL, dst_host); g_mfs.dst_port = dst_port; return 0; }
static int smpp_esme_init(struct esme *esme, const char *host, uint16_t port) { int rc; if (port == 0) port = 2775; esme->own_seq_nr = rand(); esme_inc_seq_nr(esme); osmo_wqueue_init(&esme->wqueue, 10); esme->wqueue.bfd.data = esme; esme->wqueue.read_cb = esme_read_cb; esme->wqueue.write_cb = esme_write_cb; rc = osmo_sock_init_ofd(&esme->wqueue.bfd, AF_UNSPEC, SOCK_STREAM, IPPROTO_TCP, host, port, OSMO_SOCK_F_CONNECT); if (rc < 0) return rc; return bind_transceiver(esme); }
int main(int argc, char **argv) { int rc; struct ctrl_connection *ccon; tall_mgr_ctx = talloc_named_const(NULL, 1, "bts manager"); msgb_talloc_ctx_init(tall_mgr_ctx, 0); srand(time(NULL)); osmo_init_logging2(tall_mgr_ctx, &mgr_log_info); if (classify_bts() != 0) exit(2); osmo_init_ignore_signals(); signal(SIGINT, &signal_handler); signal(SIGTERM, &signal_handler); signal(SIGUSR1, &signal_handler); signal(SIGUSR2, &signal_handler); rc = parse_options(argc, argv); if (rc < 0) exit(2); sysmobts_mgr_vty_init(); logging_vty_add_cmds(&mgr_log_info); rc = sysmobts_mgr_parse_config(&manager); if (rc < 0) { LOGP(DFIND, LOGL_FATAL, "Cannot parse config file\n"); exit(1); } rc = telnet_init(tall_mgr_ctx, NULL, OSMO_VTY_PORT_BTSMGR); if (rc < 0) { fprintf(stderr, "Error initializing telnet\n"); exit(1); } /* start temperature check timer */ temp_timer.cb = check_temp_timer_cb; check_temp_timer_cb(NULL); /* start operational hours timer */ hours_timer.cb = hours_timer_cb; hours_timer_cb(NULL); /* start uc temperature check timer */ sbts2050_uc_initialize(); /* handle broadcast messages for ipaccess-find */ if (sysmobts_mgr_nl_init() != 0) exit(3); /* Initialize the temperature control */ ccon = osmo_ctrl_conn_alloc(tall_mgr_ctx, NULL); rc = -1; if (ccon) { ccon->write_queue.bfd.data = ccon; rc = osmo_sock_init_ofd(&ccon->write_queue.bfd, AF_INET, SOCK_STREAM, IPPROTO_TCP, "localhost", OSMO_CTRL_PORT_BTS, OSMO_SOCK_F_CONNECT); } if (rc < 0) LOGP(DLCTRL, LOGL_ERROR, "Can't connect to CTRL @ localhost:%u\n", OSMO_CTRL_PORT_BTS); else LOGP(DLCTRL, LOGL_NOTICE, "CTRL connected to locahost:%u\n", OSMO_CTRL_PORT_BTS); sysmobts_mgr_temp_init(&manager, ccon); if (sysmobts_mgr_calib_init(&manager) != 0) exit(3); if (daemonize) { rc = osmo_daemonize(); if (rc < 0) { perror("Error during daemonize"); exit(1); } } while (1) { log_reset_context(); osmo_select_main(0); } }
int main(int argc, char **argv) { struct l1fwd_hdl *l1fh; struct femtol1_hdl *fl1h; int rc, i; printf("sizeof(GsmL1_Prim_t) = %zu\n", sizeof(GsmL1_Prim_t)); printf("sizeof(SuperFemto_Prim_t) = %zu\n", sizeof(SuperFemto_Prim_t)); bts_log_init(NULL); /* * hack and prevent that two l1fwd-proxy/sysmobts run at the same * time. This is done by binding to the same VTY port. */ rc = osmo_sock_init(AF_UNSPEC, SOCK_STREAM, IPPROTO_TCP, "127.0.0.1", 4241, OSMO_SOCK_F_BIND); if (rc < 0) { fprintf(stderr, "Failed to bind to the BTS VTY port.\n"); return EXIT_FAILURE; } /* allocate new femtol1_handle */ fl1h = talloc_zero(NULL, struct femtol1_hdl); INIT_LLIST_HEAD(&fl1h->wlc_list); /* open the actual hardware transport */ for (i = 0; i < ARRAY_SIZE(fl1h->write_q); i++) { rc = l1if_transport_open(i, fl1h); if (rc < 0) exit(1); } /* create our fwd handle */ l1fh = talloc_zero(NULL, struct l1fwd_hdl); l1fh->fl1h = fl1h; fl1h->priv = l1fh; /* Open UDP */ for (i = 0; i < ARRAY_SIZE(l1fh->udp_wq); i++) { struct osmo_wqueue *wq = &l1fh->udp_wq[i]; osmo_wqueue_init(wq, 10); wq->write_cb = udp_write_cb; wq->read_cb = udp_read_cb; wq->bfd.when |= BSC_FD_READ; wq->bfd.data = l1fh; wq->bfd.priv_nr = i; rc = osmo_sock_init_ofd(&wq->bfd, AF_UNSPEC, SOCK_DGRAM, IPPROTO_UDP, NULL, fwd_udp_ports[i], OSMO_SOCK_F_BIND); if (rc < 0) { perror("sock_init"); exit(1); } } while (1) { rc = osmo_select_main(0); if (rc < 0) { perror("select"); exit(1); } } exit(0); }