From 5f9f38378b2602d70bb895393b13b9d642ef7efc Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Mon, 10 Oct 2011 00:06:19 +0200 Subject: main: Move code around to let the SIMtrace keep running... Re-open the USB device, reset the state... handle reconnects of the device. --- host/main.c | 45 ++++++++++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 17 deletions(-) (limited to 'host') diff --git a/host/main.c b/host/main.c index 36d6a06..21d82ba 100644 --- a/host/main.c +++ b/host/main.c @@ -123,6 +123,7 @@ static void print_help(void) printf( "\t-i\t--gsmtap-ip\tA.B.C.D\n" "\t-a\t--skip-atr\n" "\t-h\t--help\n" + "\t-k\t--keep-running\n" "\n" ); } @@ -131,6 +132,7 @@ static const struct option opts[] = { { "gsmtap-ip", 1, 0, 'i' }, { "skip-atr", 0, 0, 'a' }, { "help", 0, 0, 'h' }, + { "keep-running", 0, 0, 'k' }, { NULL, 0, 0, 0 } }; @@ -165,6 +167,7 @@ int main(int argc, char **argv) int rc; int c, ret = 1; int skip_atr = 0; + int keep_running = 0; struct libusb_device_handle *devh; print_welcome(); @@ -172,7 +175,7 @@ int main(int argc, char **argv) while (1) { int option_index = 0; - c = getopt_long(argc, argv, "i:ah", opts, &option_index); + c = getopt_long(argc, argv, "i:ahk", opts, &option_index); if (c == -1) break; switch (c) { @@ -186,6 +189,9 @@ int main(int argc, char **argv) case 'a': skip_atr = 1; break; + case 'k': + keep_running = 1; + break; } } @@ -206,26 +212,31 @@ int main(int argc, char **argv) if (!as) goto release_exit; - devh = libusb_open_device_with_vid_pid(NULL, SIMTRACE_USB_VENDOR, SIMTRACE_USB_PRODUCT); - if (!devh) { - fprintf(stderr, "can't open USB device\n"); - goto close_exit; - } + do { + devh = libusb_open_device_with_vid_pid(NULL, SIMTRACE_USB_VENDOR, SIMTRACE_USB_PRODUCT); + if (!devh) { + fprintf(stderr, "can't open USB device\n"); + goto close_exit; + } - rc = libusb_claim_interface(devh, 0); - if (rc < 0) { - fprintf(stderr, "can't claim interface; rc=%d\n", rc); - goto close_exit; - } + rc = libusb_claim_interface(devh, 0); + if (rc < 0) { + fprintf(stderr, "can't claim interface; rc=%d\n", rc); + goto close_exit; + } - run_mainloop(devh); - ret = 0; + run_mainloop(devh); + ret = 0; -release_exit: - libusb_release_interface(devh, 0); + libusb_release_interface(devh, 0); close_exit: - if (devh) - libusb_close(devh); + if (devh) + libusb_close(devh); + if (keep_running) + sleep(1); + } while (keep_running); + +release_exit: libusb_exit(NULL); return ret; } -- cgit v1.2.3