aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Welte <laforge@osmocom.org>2020-10-27 15:40:39 +0100
committerHarald Welte <laforge@osmocom.org>2020-10-27 15:48:35 +0100
commit80b8877a231f4cd36a76d02d55bff0a19cc0416d (patch)
treec52a71e780ddbca3213dc03366c68307902e0750
parent1372aca28e1f731c91b1043352b5e8a8ca6620a0 (diff)
remove usb2udp
The UDP based forwarding really only ever was a quick hack to demonstrate the capabilities. Meanwhile, we've had the proper osmo-remsim project implemented, which provides a much more reliable and comprehensive way of managing SIM card emulation devices (SIMtrace2, sysmoQMOD, ...) and collection of card readers (sysmoOCTSIM or any other PC/SC supported readers). Hence, remove the "UDP forwarding part. Change-Id: Ia4b9447b95872b6e0dda6dca644f1ed4a87355a0
-rw-r--r--.gitignore1
-rw-r--r--host/.gitignore1
-rw-r--r--host/contrib/simtrace2.spec.in1
-rw-r--r--host/src/Makefile.am4
-rw-r--r--host/src/simtrace2-remsim.c121
-rw-r--r--host/src/usb2udp.c285
6 files changed, 43 insertions, 370 deletions
diff --git a/.gitignore b/.gitignore
index a5393d9..4920c22 100644
--- a/.gitignore
+++ b/.gitignore
@@ -19,7 +19,6 @@ tags
*.p
host/simtrace2-list
host/simtrace2-remsim
-host/simtrace2-remsim-usb2udp
host/contrib/simtrace2.spec
usb_strings_generated.h
firmware/usbstring/usbstring
diff --git a/host/.gitignore b/host/.gitignore
index 13ea291..0aa1ca7 100644
--- a/host/.gitignore
+++ b/host/.gitignore
@@ -35,4 +35,3 @@ libtool
simtrace2-list
simtrace2-sniff
simtrace2-remsim
-simtrace2-remsim-usb2udp
diff --git a/host/contrib/simtrace2.spec.in b/host/contrib/simtrace2.spec.in
index e2067b1..36bf0e6 100644
--- a/host/contrib/simtrace2.spec.in
+++ b/host/contrib/simtrace2.spec.in
@@ -82,7 +82,6 @@ find %{buildroot} -type f -name "*.la" -delete -print
%files
%doc README.md
%{_bindir}/simtrace2-remsim
-%{_bindir}/simtrace2-remsim-usb2udp
%{_bindir}/simtrace2-list
%{_bindir}/simtrace2-sniff
%{_udevrulesdir}/99-simtrace2.rules
diff --git a/host/src/Makefile.am b/host/src/Makefile.am
index c3283ba..e9cd801 100644
--- a/host/src/Makefile.am
+++ b/host/src/Makefile.am
@@ -5,12 +5,10 @@ AM_LDFLAGS=$(COVERAGE_LDFLAGS)
LDADD= $(top_builddir)/lib/libosmo-simtrace2.la \
$(LIBOSMOCORE_LIBS) $(LIBOSMOSIM_LIBS) $(LIBOSMOUSB_LIBS) $(LIBUSB_LIBS)
-bin_PROGRAMS = simtrace2-remsim simtrace2-remsim-usb2udp simtrace2-list simtrace2-sniff
+bin_PROGRAMS = simtrace2-remsim simtrace2-list simtrace2-sniff
simtrace2_remsim_SOURCES = simtrace2-remsim.c
-simtrace2_remsim_usb2udp_SOURCES = usb2udp.c
-
simtrace2_list_SOURCES = simtrace2_usb.c
simtrace2_sniff_SOURCES = simtrace2-sniff.c
diff --git a/host/src/simtrace2-remsim.c b/host/src/simtrace2-remsim.c
index 6752fc6..1c4cced 100644
--- a/host/src/simtrace2-remsim.c
+++ b/host/src/simtrace2-remsim.c
@@ -178,9 +178,7 @@ static void print_welcome(void)
static void print_help(void)
{
- printf( "\t-r\t--remote-udp-host HOST\n"
- "\t-p\t--remote-udp-port PORT\n"
- "\t-h\t--help\n"
+ printf( "\t-h\t--help\n"
"\t-i\t--gsmtap-ip\tA.B.C.D\n"
"\t-a\t--skip-atr\n"
"\t-t\t--set-atr\tATR-STRING in HEX\n"
@@ -198,8 +196,6 @@ static void print_help(void)
}
static const struct option opts[] = {
- { "remote-udp-host", 1, 0, 'r' },
- { "remote-udp-port", 1, 0, 'p' },
{ "gsmtap-ip", 1, 0, 'i' },
{ "skip-atr", 0, 0, 'a' },
{ "set-atr", 1, 0, 't' },
@@ -228,22 +224,13 @@ static void run_mainloop(struct osmo_st2_cardem_inst *ci)
while (1) {
/* read data from SIMtrace2 device (local or via USB) */
- if (transp->udp_fd < 0) {
- rc = libusb_bulk_transfer(transp->usb_devh, transp->usb_ep.in,
- buf, sizeof(buf), &xfer_len, 100);
- if (rc < 0 && rc != LIBUSB_ERROR_TIMEOUT &&
- rc != LIBUSB_ERROR_INTERRUPTED &&
- rc != LIBUSB_ERROR_IO) {
- fprintf(stderr, "BULK IN transfer error; rc=%d\n", rc);
- return;
- }
- } else {
- rc = read(transp->udp_fd, buf, sizeof(buf));
- if (rc <= 0) {
- fprintf(stderr, "shor read from UDP\n");
- return;
- }
- xfer_len = rc;
+ rc = libusb_bulk_transfer(transp->usb_devh, transp->usb_ep.in,
+ buf, sizeof(buf), &xfer_len, 100);
+ if (rc < 0 && rc != LIBUSB_ERROR_TIMEOUT &&
+ rc != LIBUSB_ERROR_INTERRUPTED &&
+ rc != LIBUSB_ERROR_IO) {
+ fprintf(stderr, "BULK IN transfer error; rc=%d\n", rc);
+ return;
}
/* dispatch any incoming data */
if (xfer_len > 0) {
@@ -291,11 +278,9 @@ int main(int argc, char **argv)
uint8_t real_atr[ATR_MAX_LEN];
int atr_len;
int keep_running = 0;
- int remote_udp_port = 52342;
int if_num = 0, vendor_id = -1, product_id = -1;
int config_id = -1, altsetting = 0, addr = -1;
int reader_num = 0;
- char *remote_udp_host = NULL;
char *path = NULL;
struct osim_reader_hdl *reader;
struct osim_card_hdl *card;
@@ -305,16 +290,10 @@ int main(int argc, char **argv)
while (1) {
int option_index = 0;
- c = getopt_long(argc, argv, "r:p:hi:V:P:C:I:S:A:H:akn:t:", opts, &option_index);
+ c = getopt_long(argc, argv, "hi:V:P:C:I:S:A:H:akn:t:", opts, &option_index);
if (c == -1)
break;
switch (c) {
- case 'r':
- remote_udp_host = optarg;
- break;
- case 'p':
- remote_udp_port = atoi(optarg);
- break;
case 'h':
print_help();
exit(0);
@@ -365,29 +344,17 @@ int main(int argc, char **argv)
goto do_exit;
}
- if (!remote_udp_host && (vendor_id < 0 || product_id < 0)) {
+ if (vendor_id < 0 || product_id < 0) {
fprintf(stderr, "You have to specify the vendor and product ID\n");
goto do_exit;
}
- transp->udp_fd = -1;
-
ci->card_prof = &osim_uicc_sim_cic_profile;
- if (!remote_udp_host) {
- rc = libusb_init(NULL);
- if (rc < 0) {
- fprintf(stderr, "libusb initialization failed\n");
- goto do_exit;
- }
- } else {
- transp->udp_fd = osmo_sock_init(AF_INET, SOCK_DGRAM, IPPROTO_UDP,
- remote_udp_host, remote_udp_port+if_num,
- OSMO_SOCK_F_CONNECT);
- if (transp->udp_fd < 0) {
- fprintf(stderr, "error binding UDP port\n");
- goto do_exit;
- }
+ rc = libusb_init(NULL);
+ if (rc < 0) {
+ fprintf(stderr, "libusb initialization failed\n");
+ goto do_exit;
}
rc = osmo_st2_gsmtap_init(gsmtap_host);
@@ -417,34 +384,32 @@ int main(int argc, char **argv)
signal(SIGINT, &signal_handler);
do {
- if (transp->udp_fd < 0) {
- struct usb_interface_match _ifm, *ifm = &_ifm;
- ifm->vendor = vendor_id;
- ifm->product = product_id;
- ifm->configuration = config_id;
- ifm->interface = if_num;
- ifm->altsetting = altsetting;
- ifm->addr = addr;
- if (path)
- osmo_strlcpy(ifm->path, path, sizeof(ifm->path));
- transp->usb_devh = osmo_libusb_open_claim_interface(NULL, NULL, ifm);
- if (!transp->usb_devh) {
- fprintf(stderr, "can't open USB device\n");
- goto close_exit;
- }
-
- rc = libusb_claim_interface(transp->usb_devh, if_num);
- if (rc < 0) {
- fprintf(stderr, "can't claim interface %d; rc=%d\n", if_num, rc);
- goto close_exit;
- }
-
- rc = osmo_libusb_get_ep_addrs(transp->usb_devh, if_num, &transp->usb_ep.out,
- &transp->usb_ep.in, &transp->usb_ep.irq_in);
- if (rc < 0) {
- fprintf(stderr, "can't obtain EP addrs; rc=%d\n", rc);
- goto close_exit;
- }
+ struct usb_interface_match _ifm, *ifm = &_ifm;
+ ifm->vendor = vendor_id;
+ ifm->product = product_id;
+ ifm->configuration = config_id;
+ ifm->interface = if_num;
+ ifm->altsetting = altsetting;
+ ifm->addr = addr;
+ if (path)
+ osmo_strlcpy(ifm->path, path, sizeof(ifm->path));
+ transp->usb_devh = osmo_libusb_open_claim_interface(NULL, NULL, ifm);
+ if (!transp->usb_devh) {
+ fprintf(stderr, "can't open USB device\n");
+ goto close_exit;
+ }
+
+ rc = libusb_claim_interface(transp->usb_devh, if_num);
+ if (rc < 0) {
+ fprintf(stderr, "can't claim interface %d; rc=%d\n", if_num, rc);
+ goto close_exit;
+ }
+
+ rc = osmo_libusb_get_ep_addrs(transp->usb_devh, if_num, &transp->usb_ep.out,
+ &transp->usb_ep.in, &transp->usb_ep.irq_in);
+ if (rc < 0) {
+ fprintf(stderr, "can't obtain EP addrs; rc=%d\n", rc);
+ goto close_exit;
}
/* simulate card-insert to modem (owhw, not qmod) */
@@ -465,8 +430,7 @@ int main(int argc, char **argv)
run_mainloop(ci);
ret = 0;
- if (transp->udp_fd < 0)
- libusb_release_interface(transp->usb_devh, 0);
+ libusb_release_interface(transp->usb_devh, 0);
close_exit:
if (transp->usb_devh)
libusb_close(transp->usb_devh);
@@ -474,8 +438,7 @@ close_exit:
sleep(1);
} while (keep_running);
- if (transp->udp_fd < 0)
- libusb_exit(NULL);
+ libusb_exit(NULL);
do_exit:
return ret;
}
diff --git a/host/src/usb2udp.c b/host/src/usb2udp.c
deleted file mode 100644
index 2c07a3a..0000000
--- a/host/src/usb2udp.c
+++ /dev/null
@@ -1,285 +0,0 @@
-/* simtrace - main program for the host PC
- *
- * (C) 2010-2016 by Harald Welte <hwelte@hmw-consulting.de>
- *
- * 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 <errno.h>
-#include <unistd.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdint.h>
-#include <time.h>
-#define _GNU_SOURCE
-#include <getopt.h>
-#include <poll.h>
-
-#include <sys/time.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-
-#include <libusb.h>
-
-#include <osmocom/usb/libusb.h>
-#include <osmocom/simtrace2/simtrace_usb.h>
-#include <osmocom/simtrace2/simtrace_prot.h>
-
-#include <osmocom/core/utils.h>
-#include <osmocom/core/socket.h>
-#include <osmocom/core/select.h>
-
-struct libusb_device_handle *g_devh;
-static struct sockaddr_in g_sa_remote;
-static struct osmo_fd g_udp_ofd;
-
-static void print_welcome(void)
-{
- printf("usb2udp - UDP/IP forwarding of SIMtrace card emulation\n"
- "(C) 2016 by Harald Welte <laforge@gnumonks.org>\n\n");
-}
-
-static void print_help(void)
-{
- printf( "\t-h\t--help\n"
- "\t-i\t--interface <0-255>\n"
- "\n"
- );
-}
-
-struct ep_buf {
- uint8_t ep;
- uint8_t buf[1024];
- struct libusb_transfer *xfer;
-};
-static struct ep_buf g_buf_in;
-static struct ep_buf g_buf_out;
-
-static void usb_in_xfer_cb(struct libusb_transfer *xfer)
-{
- int rc;
-
- printf("xfer_cb(ep=%02x): status=%d, flags=0x%x, type=%u, len=%u, act_len=%u\n",
- xfer->endpoint, xfer->status, xfer->flags, xfer->type, xfer->length, xfer->actual_length);
- switch (xfer->status) {
- case LIBUSB_TRANSFER_COMPLETED:
- if (xfer->endpoint == g_buf_in.ep) {
- /* process the data */
- printf("read %d bytes from SIMTRACE, forwarding to UDP\n", xfer->actual_length);
- rc = sendto(g_udp_ofd.fd, xfer->buffer, xfer->actual_length, 0, (struct sockaddr *)&g_sa_remote, sizeof(g_sa_remote));
- if (rc <= 0) {
- fprintf(stderr, "error writing to UDP\n");
- }
- /* and re-submit the URB */
- libusb_submit_transfer(xfer);
- } else if (xfer->endpoint == g_buf_out.ep) {
- /* re-enable reading from the UDP side */
- g_udp_ofd.when |= OSMO_FD_READ;
- }
- break;
- default:
- fprintf(stderr, "xfer_cb(ERROR '%s')\n", osmo_hexdump_nospc(xfer->buffer, xfer->actual_length));
- break;
- }
-}
-
-static void init_ep_buf(struct ep_buf *epb)
-{
- if (!epb->xfer)
- epb->xfer = libusb_alloc_transfer(0);
-
- epb->xfer->flags = 0;
-
- libusb_fill_bulk_transfer(epb->xfer, g_devh, epb->ep, epb->buf, sizeof(epb->buf), usb_in_xfer_cb, NULL, 0);
-}
-
-/***********************************************************************
- * libosmocore main loop integration of libusb async I/O
- ***********************************************************************/
-
-static int g_libusb_pending = 0;
-
-static int ofd_libusb_cb(struct osmo_fd *ofd, unsigned int what)
-{
- /* FIXME */
- g_libusb_pending = 1;
-
- return 0;
-}
-
-/* call-back when libusb adds a FD */
-static void libusb_fd_added_cb(int fd, short events, void *user_data)
-{
- struct osmo_fd *ofd = talloc_zero(NULL, struct osmo_fd);
-
- printf("%s(%u, %x)\n", __func__, fd, events);
-
- ofd->fd = fd;
- ofd->cb = &ofd_libusb_cb;
- if (events & POLLIN)
- ofd->when |= OSMO_FD_READ;
- if (events & POLLOUT)
- ofd->when |= OSMO_FD_WRITE;
-
- osmo_fd_register(ofd);
-}
-
-/* call-back when libusb removes a FD */
-static void libusb_fd_removed_cb(int fd, void *user_data)
-{
-
- printf("%s(%u)\n", __func__, fd);
-#if 0
- struct osmo_fd *ofd;
- /* FIXME: This needs new export in libosmocore! */
- ofd = osmo_fd_get_by_fd(fd);
-
- if (ofd) {
- osmo_fd_unregister(ofd);
- talloc_free(ofd);
- }
-#endif
-}
-
-/* call-back when the UDP socket is readable */
-static int ofd_udp_cb(struct osmo_fd *ofd, unsigned int what)
-{
- int rc;
- socklen_t addrlen = sizeof(g_sa_remote);
-
- rc = recvfrom(ofd->fd, g_buf_out.buf, sizeof(g_buf_out.buf), 0,
- (struct sockaddr *)&g_sa_remote, &addrlen);
- if (rc <= 0) {
- fprintf(stderr, "error reading from UDP\n");
- return 0;
- }
- printf("read %d bytes from UDP, forwarding to SIMTRACE\n", rc);
- g_buf_out.xfer->length = rc;
-
- /* disable further READ interest for the UDP socket */
- ofd->when &= ~OSMO_FD_READ;
-
- /* submit the URB on the OUT end point */
- libusb_submit_transfer(g_buf_out.xfer);
-
- return 0;
-}
-
-static void run_mainloop(void)
-{
- int rc;
-
- printf("Entering main loop\n");
-
- while (1) {
- osmo_select_main(0);
- if (g_libusb_pending) {
- struct timeval tv;
- memset(&tv, 0, sizeof(tv));
- rc = libusb_handle_events_timeout_completed(NULL, &tv, NULL);
- if (rc != 0) {
- fprintf(stderr, "handle_events_timeout_completed == %d\n", rc);
- break;
- }
- }
- }
-}
-
-int main(int argc, char **argv)
-{
- int rc;
- int c, ret = 1;
- int local_udp_port = 52342;
- unsigned int if_num = 0;
-
- print_welcome();
-
- while (1) {
- int option_index = 0;
- static const struct option opts[] = {
- { "udp-port", 1, 0, 'u' },
- { "interface", 1, 0, 'I' },
- { "help", 0, 0, 'h' },
- { NULL, 0, 0, 0 }
- };
-
- c = getopt_long(argc, argv, "u:I:h", opts, &option_index);
- if (c == -1)
- break;
- switch (c) {
- case 'u':
- local_udp_port = atoi(optarg);
- break;
- case 'I':
- if_num = atoi(optarg);
- break;
- case 'h':
- print_help();
- exit(0);
- break;
- }
- }
-
- rc = libusb_init(NULL);
- if (rc < 0) {
- fprintf(stderr, "libusb initialization failed\n");
- goto close_exit;
- }
-
- libusb_set_pollfd_notifiers(NULL, &libusb_fd_added_cb, &libusb_fd_removed_cb, NULL);
-
- g_devh = libusb_open_device_with_vid_pid(NULL, USB_VENDOR_OPENMOKO, USB_PRODUCT_OWHW_SAM3);
- if (!g_devh) {
- fprintf(stderr, "can't open USB device\n");
- goto close_exit;
- }
-
- rc = libusb_claim_interface(g_devh, if_num);
- if (rc < 0) {
- fprintf(stderr, "can't claim interface %u; rc=%d\n", if_num, rc);
- goto close_exit;
- }
-
- /* open UDP socket, register with select handling and mark it
- * readable */
- g_udp_ofd.cb = ofd_udp_cb;
- osmo_sock_init_ofd(&g_udp_ofd, AF_INET, SOCK_DGRAM, IPPROTO_UDP, NULL, local_udp_port + if_num, OSMO_SOCK_F_BIND);
-
- rc = osmo_libusb_get_ep_addrs(g_devh, if_num, &g_buf_out.ep, &g_buf_in.ep, NULL);
- if (rc < 0) {
- fprintf(stderr, "couldn't find enpdoint addresses; rc=%d\n", rc);
- goto close_exit;
- }
- /* initialize USB buffers / transfers */
- init_ep_buf(&g_buf_out);
- init_ep_buf(&g_buf_in);
-
- /* submit the first transfer for the IN endpoint */
- libusb_submit_transfer(g_buf_in.xfer);
-
- run_mainloop();
-
- ret = 0;
-
- libusb_release_interface(g_devh, 0);
-close_exit:
- if (g_devh)
- libusb_close(g_devh);
-
- libusb_exit(NULL);
- return ret;
-}