diff options
author | Holger Hans Peter Freyther <zecke@selfish.org> | 2011-10-09 20:02:45 +0200 |
---|---|---|
committer | Harald Welte <laforge@gnumonks.org> | 2011-12-14 15:23:26 +0100 |
commit | 943d7d28dc59e7baac8a07078c5efd6b2d8b5f96 (patch) | |
tree | b5be7eddeae1d801258f65eea97a354f9bb57403 /host | |
parent | 56b8045e671005b91a0822f6619e5a2df2dfc7e0 (diff) |
main: Move the mainloop into a separate function
Prepare to have the application wait for the USB device to come
back. This will be done by moving the code around and then having
a simple for loop.
Diffstat (limited to 'host')
-rw-r--r-- | host/main.c | 55 |
1 files changed, 32 insertions, 23 deletions
diff --git a/host/main.c b/host/main.c index 4fbac8d..60fa342 100644 --- a/host/main.c +++ b/host/main.c @@ -42,7 +42,6 @@ #include <osmocom/core/gsmtap_util.h> #include <osmocom/core/utils.h> -static struct libusb_device_handle *devh; static struct apdu_split *as; static struct gsmtap_inst *g_gti; @@ -135,14 +134,37 @@ static const struct option opts[] = { { NULL, 0, 0, 0 } }; -int main(int argc, char **argv) +static void run_mainloop(struct libusb_device_handle *devh) { + unsigned int msg_count, byte_count = 0; char buf[16*265]; + int xfer_len; + int rc; + + printf("Entering main loop\n"); + + while (1) { + rc = libusb_bulk_transfer(devh, SIMTRACE_IN_EP, buf, sizeof(buf), &xfer_len, 100000); + if (rc < 0 && rc != LIBUSB_ERROR_TIMEOUT) { + fprintf(stderr, "BULK IN transfer error; rc=%d\n", rc); + return; + } + if (xfer_len > 0) { + //printf("URB: %s\n", osmo_hexdump(buf, rc)); + process_usb_msg(buf, xfer_len); + msg_count++; + byte_count += xfer_len; + } + } +} + +int main(int argc, char **argv) +{ char *gsmtap_host = "127.0.0.1"; - int rc, c, ret = 1; + int rc; + int c, ret = 1; int skip_atr = 0; - int xfer_len; - unsigned int msg_count, byte_count = 0; + struct libusb_device_handle *devh; print_welcome(); @@ -179,6 +201,10 @@ int main(int argc, char **argv) } gsmtap_source_add_sink(g_gti); + as = apdu_split_init(&apdu_out_cb, NULL); + 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"); @@ -191,24 +217,7 @@ int main(int argc, char **argv) goto close_exit; } - as = apdu_split_init(&apdu_out_cb, NULL); - if (!as) - goto release_exit; - - printf("Entering main loop\n"); - while (1) { - rc = libusb_bulk_transfer(devh, SIMTRACE_IN_EP, buf, sizeof(buf), &xfer_len, 100000); - if (rc < 0 && rc != LIBUSB_ERROR_TIMEOUT) { - fprintf(stderr, "BULK IN transfer error; rc=%d\n", rc); - goto release_exit; - } - if (xfer_len > 0) { - //printf("URB: %s\n", osmo_hexdump(buf, rc)); - process_usb_msg(buf, xfer_len); - msg_count++; - byte_count += xfer_len; - } - } + run_mainloop(devh); ret = 0; release_exit: |