diff options
author | Nikolai Kondrashov <spbnick@gmail.com> | 2010-11-17 20:48:07 +0300 |
---|---|---|
committer | Nikolai Kondrashov <spbnick@gmail.com> | 2010-11-17 20:48:07 +0300 |
commit | 4fb9dfd60bd99c1ddaad1f33c8d02ab3dd6182a6 (patch) | |
tree | c8ded8a70200081365cdb0c6b935ae9e27bf8407 | |
parent | fbb23a3cb06b0bc528c4cf9345646f7e82756949 (diff) | |
download | usbhid-dump-4fb9dfd60bd99c1ddaad1f33c8d02ab3dd6182a6.tar.gz |
Move common generic constants to a separate file
Move common generic constants to a separate header file misc.h.
-rw-r--r-- | include/uhd/Makefile.am | 1 | ||||
-rw-r--r-- | include/uhd/misc.h | 63 | ||||
-rw-r--r-- | lib/dev_list.c | 13 | ||||
-rw-r--r-- | src/usbhid-dump.c | 44 |
4 files changed, 83 insertions, 38 deletions
diff --git a/include/uhd/Makefile.am b/include/uhd/Makefile.am index 71cdc11..cc5a087 100644 --- a/include/uhd/Makefile.am +++ b/include/uhd/Makefile.am @@ -22,4 +22,5 @@ noinst_HEADERS = \ iface.h \ iface_list.h \ libusb.h \ + misc.h \ str.h diff --git a/include/uhd/misc.h b/include/uhd/misc.h new file mode 100644 index 0000000..a7ee056 --- /dev/null +++ b/include/uhd/misc.h @@ -0,0 +1,63 @@ +/** @file + * @brief usbhid-dump - miscellaneous declarations + * + * Copyright (C) 2010 Nikolai Kondrashov + * + * This file is part of usbhid-dump. + * + * Usbhid-dump 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. + * + * Usbhid-dump 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 usbhid-dump; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * @author Nikolai Kondrashov <spbnick@gmail.com> + * + * @(#) $Id$ + */ + +#ifndef __UHD_MISC_H__ +#define __UHD_MISC_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Maximum descriptor size. + * + * @note 4096 here is maximum control buffer length. + */ +#define UHD_MAX_DESCRIPTOR_SIZE 4096 + +/** Generic USB I/O timeout */ +#define UHD_IO_TIMEOUT 1000 + +/** Wildcard bus number */ +#define UHD_BUS_NUM_ANY 0 + +/** Wildcard device address */ +#define UHD_DEV_ADDR_ANY 0 + +/** Wildcard vendor ID */ +#define UHD_VID_ANY 0 + +/** Wildcard product ID */ +#define UHD_PID_ANY 0 + +/** Wildcard interface number */ +#define UHD_IFACE_NUM_ANY UINT8_MAX + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* __UHD_MISC_H__ */ diff --git a/lib/dev_list.c b/lib/dev_list.c index 3318b4f..e23686e 100644 --- a/lib/dev_list.c +++ b/lib/dev_list.c @@ -24,6 +24,7 @@ * @(#) $Id$ */ +#include "uhd/misc.h" #include "uhd/dev_list.h" #include <assert.h> #include <stdlib.h> @@ -96,19 +97,21 @@ uhd_dev_list_open(libusb_context *ctx, lusb_dev = lusb_list[idx]; /* Skip devices not matching bus_num/dev_addr mask */ - if ((bus_num != 0 && libusb_get_bus_number(lusb_dev) != bus_num) || - (dev_addr != 0 && libusb_get_device_address(lusb_dev) != dev_addr)) + if ((bus_num != UHD_BUS_NUM_ANY && + libusb_get_bus_number(lusb_dev) != bus_num) || + (dev_addr != UHD_DEV_ADDR_ANY && + libusb_get_device_address(lusb_dev) != dev_addr)) continue; /* Skip devices not matching vendor/product mask */ - if (vendor != 0 || product != 0) + if (vendor != UHD_VID_ANY || product != UHD_PID_ANY) { err = libusb_get_device_descriptor(lusb_dev, &desc); if (err != LIBUSB_SUCCESS) goto cleanup; - if ((vendor != 0 && vendor != desc.idVendor) || - (product != 0 && product != desc.idProduct)) + if ((vendor != UHD_VID_ANY && vendor != desc.idVendor) || + (product != UHD_PID_ANY && product != desc.idProduct)) continue; } diff --git a/src/usbhid-dump.c b/src/usbhid-dump.c index 101ad67..399eb03 100644 --- a/src/usbhid-dump.c +++ b/src/usbhid-dump.c @@ -26,6 +26,7 @@ #include "uhd/iface_list.h" #include "uhd/str.h" #include "uhd/libusb.h" +#include "uhd/misc.h" #include <assert.h> #include <stdbool.h> @@ -41,29 +42,6 @@ #include "config.h" -/** - * Maximum descriptor size. - * - * 4096 here is maximum control buffer length. - */ -#define MAX_DESCRIPTOR_SIZE 4096 - -/** Wildcard bus number */ -#define BUS_NUM_ANY 0 -/** Wildcard device address */ -#define DEV_ADDR_ANY 0 -/** Wildcard vendor ID */ -#define VID_ANY 0 -/** Wildcard product ID */ -#define PID_ANY 0 -/** Wildcard interface number */ -#define IFACE_NUM_ANY UINT8_MAX - -/** - * USB I/O timeout - */ -#define TIMEOUT 1000 - #define ERROR(_fmt, _args...) \ fprintf(stderr, _fmt "\n", ##_args) @@ -172,7 +150,7 @@ static bool dump_iface_list_descriptor(const uhd_iface *list) { const uhd_iface *iface; - uint8_t buf[MAX_DESCRIPTOR_SIZE]; + uint8_t buf[UHD_MAX_DESCRIPTOR_SIZE]; int rc; enum libusb_error err; @@ -183,7 +161,7 @@ dump_iface_list_descriptor(const uhd_iface *list) 0x81, LIBUSB_REQUEST_GET_DESCRIPTOR, (LIBUSB_DT_REPORT << 8), iface->number, - buf, sizeof(buf), TIMEOUT); + buf, sizeof(buf), UHD_IO_TIMEOUT); if (rc < 0) { err = rc; @@ -262,10 +240,10 @@ dump_iface_list_stream(libusb_context *ctx, uhd_iface *list) UHD_IFACE_LIST_FOR_EACH(iface, list) { /* Set report protocol */ - LIBUSB_GUARD(uhd_iface_set_protocol(list, true, TIMEOUT), + LIBUSB_GUARD(uhd_iface_set_protocol(list, true, UHD_IO_TIMEOUT), "set report protocol on an interface"); /* Set infinite idle duration */ - LIBUSB_GUARD(uhd_iface_set_idle(list, 0, TIMEOUT), + LIBUSB_GUARD(uhd_iface_set_idle(list, 0, UHD_IO_TIMEOUT), "set infinite idle duration on an interface"); } @@ -479,7 +457,7 @@ run(bool dump_descriptor, "find HID interfaces"); /* Filter the interface list by specified interface number */ - if (iface_num != IFACE_NUM_ANY) + if (iface_num != UHD_IFACE_NUM_ANY) iface_list = uhd_iface_list_fltr_by_num(iface_list, iface_num); /* Check if there are any interfaces left */ @@ -811,13 +789,13 @@ main(int argc, char **argv) char c; - uint8_t bus_num = BUS_NUM_ANY; - uint8_t dev_addr = DEV_ADDR_ANY; + uint8_t bus_num = UHD_BUS_NUM_ANY; + uint8_t dev_addr = UHD_DEV_ADDR_ANY; - uint16_t vid = VID_ANY; - uint16_t pid = PID_ANY; + uint16_t vid = UHD_VID_ANY; + uint16_t pid = UHD_PID_ANY; - uint8_t iface_num = IFACE_NUM_ANY; + uint8_t iface_num = UHD_IFACE_NUM_ANY; bool dump_descriptor = true; bool dump_stream = false; |