aboutsummaryrefslogtreecommitdiffstats
path: root/host
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <zecke@selfish.org>2011-10-10 00:06:19 +0200
committerHarald Welte <laforge@gnumonks.org>2011-12-14 15:23:27 +0100
commit5f9f38378b2602d70bb895393b13b9d642ef7efc (patch)
treedc037e9c61b0d706c0045b20a57a55ecf9613c5f /host
parent54683c7b8ff2bdbebd51df60dc60d9bd5ae50399 (diff)
main: Move code around to let the SIMtrace keep running...
Re-open the USB device, reset the state... handle reconnects of the device.
Diffstat (limited to 'host')
-rw-r--r--host/main.c45
1 files changed, 28 insertions, 17 deletions
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;
}