usbconfig.c (cae1884d4791726f5acf5d64bba9a3583b63e38b) usbconfig.c (d69b9cc26d1c24a4cbc37478a571b1f531aa7bcc)
1/* $FreeBSD$ */
2/*-
3 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 *
5 * Copyright (c) 2008-2009 Hans Petter Selasky. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions

--- 16 unchanged lines hidden (view full) ---

25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 */
28
29#include <stdio.h>
30#include <stdlib.h>
31#include <stdint.h>
32#include <err.h>
1/* $FreeBSD$ */
2/*-
3 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 *
5 * Copyright (c) 2008-2009 Hans Petter Selasky. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions

--- 16 unchanged lines hidden (view full) ---

25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 */
28
29#include <stdio.h>
30#include <stdlib.h>
31#include <stdint.h>
32#include <err.h>
33#include <sysexits.h>
33#include <string.h>
34#include <unistd.h>
35#include <pwd.h>
36#include <grp.h>
37#include <errno.h>
38#include <ctype.h>
39#include <sys/types.h>
40

--- 221 unchanged lines hidden (view full) ---

262duplicate_option(const char *ptr)
263{
264 fprintf(stderr, "Syntax error: "
265 "Duplicate option: '%s'\n", ptr);
266 exit(1);
267}
268
269static void
34#include <string.h>
35#include <unistd.h>
36#include <pwd.h>
37#include <grp.h>
38#include <errno.h>
39#include <ctype.h>
40#include <sys/types.h>
41

--- 221 unchanged lines hidden (view full) ---

263duplicate_option(const char *ptr)
264{
265 fprintf(stderr, "Syntax error: "
266 "Duplicate option: '%s'\n", ptr);
267 exit(1);
268}
269
270static void
270usage(void)
271usage(int exitcode)
271{
272 fprintf(stderr, ""
273 "usbconfig - configure the USB subsystem" "\n"
272{
273 fprintf(stderr, ""
274 "usbconfig - configure the USB subsystem" "\n"
274 "usage: usbconfig [-u <busnum>] [-a <devaddr>] [-i <ifaceindex>] [cmds...]" "\n"
275 "usage: usbconfig -d [ugen]<busnum>.<devaddr> [-i <ifaceindex>] [cmds...]" "\n"
275 "usage: usbconfig [-u <busnum>] [-a <devaddr>] [-i <ifaceindex>] [-v] [cmds...]" "\n"
276 "usage: usbconfig -d [ugen]<busnum>.<devaddr> [-i <ifaceindex>] [-v] [cmds...]" "\n"
276 "commands:" "\n"
277 " set_config <cfg_index>" "\n"
278 " set_alt <alt_index>" "\n"
279 " set_template <template>" "\n"
280 " get_template" "\n"
281 " add_dev_quirk_vplh <vid> <pid> <lo_rev> <hi_rev> <quirk>" "\n"
282 " remove_dev_quirk_vplh <vid> <pid> <lo_rev> <hi_rev> <quirk>" "\n"
283 " add_quirk <quirk>" "\n"

--- 269 unchanged lines hidden (view full) ---

553 const char *ptr;
554 int unit;
555 int addr;
556 int n;
557 int t;
558 int ch;
559
560 if (argc < 1) {
277 "commands:" "\n"
278 " set_config <cfg_index>" "\n"
279 " set_alt <alt_index>" "\n"
280 " set_template <template>" "\n"
281 " get_template" "\n"
282 " add_dev_quirk_vplh <vid> <pid> <lo_rev> <hi_rev> <quirk>" "\n"
283 " remove_dev_quirk_vplh <vid> <pid> <lo_rev> <hi_rev> <quirk>" "\n"
284 " add_quirk <quirk>" "\n"

--- 269 unchanged lines hidden (view full) ---

554 const char *ptr;
555 int unit;
556 int addr;
557 int n;
558 int t;
559 int ch;
560
561 if (argc < 1) {
561 usage();
562 usage(EX_USAGE);
562 }
563 pbe = libusb20_be_alloc_default();
564 if (pbe == NULL)
565 err(1, "could not access USB backend\n");
566
563 }
564 pbe = libusb20_be_alloc_default();
565 if (pbe == NULL)
566 err(1, "could not access USB backend\n");
567
567 while ((ch = getopt(argc, argv, "a:d:i:u:")) != -1) {
568 while ((ch = getopt(argc, argv, "a:d:hi:u:v")) != -1) {
568 switch (ch) {
569 case 'a':
570 opt->addr = num_id(optarg, "addr");
571 opt->got_addr = 1;
572 break;
573
574 case 'd':
575 if (strncmp(optarg, "ugen", strlen("ugen")) == 0) {

--- 12 unchanged lines hidden (view full) ---

588 "parse '%s'", optarg);
589 }
590 opt->bus = unit;
591 opt->addr = addr;
592 opt->got_bus = 1;
593 opt->got_addr = 1;
594 break;
595
569 switch (ch) {
570 case 'a':
571 opt->addr = num_id(optarg, "addr");
572 opt->got_addr = 1;
573 break;
574
575 case 'd':
576 if (strncmp(optarg, "ugen", strlen("ugen")) == 0) {

--- 12 unchanged lines hidden (view full) ---

589 "parse '%s'", optarg);
590 }
591 opt->bus = unit;
592 opt->addr = addr;
593 opt->got_bus = 1;
594 opt->got_addr = 1;
595 break;
596
597 case 'h':
598 usage(EX_OK);
599 break;
600
596 case 'i':
597 opt->iface = num_id(optarg, "iface");
598 break;
599
600 case 'u':
601 opt->bus = num_id(optarg, "busnum");
602 opt->got_bus = 1;
603 break;
604
601 case 'i':
602 opt->iface = num_id(optarg, "iface");
603 break;
604
605 case 'u':
606 opt->bus = num_id(optarg, "busnum");
607 opt->got_bus = 1;
608 break;
609
610 case 'v':
611 opt->got_dump_device_desc = 1;
612 opt->got_dump_curr_config = 1;
613 opt->got_show_iface_driver = 1;
614 opt->got_any += 2; /* only the dump options count */
615 break;
616
605 default:
617 default:
606 usage();
618 usage(EX_USAGE);
607 }
608 }
609 argc -= optind;
610 argv += optind;
611
612 for (n = 0; n != argc; n++) {
613
614 /* get number of additional options */

--- 236 unchanged lines hidden (view full) ---

851 (ptr[2] == 'e') &&
852 (ptr[3] == 'n'))
853 ptr += 4;
854
855 if ((sscanf(ptr, "%d.%d",
856 &unit, &addr) != 2) ||
857 (unit < 0) || (unit > 65535) ||
858 (addr < 0) || (addr > 65535)) {
619 }
620 }
621 argc -= optind;
622 argv += optind;
623
624 for (n = 0; n != argc; n++) {
625
626 /* get number of additional options */

--- 236 unchanged lines hidden (view full) ---

863 (ptr[2] == 'e') &&
864 (ptr[3] == 'n'))
865 ptr += 4;
866
867 if ((sscanf(ptr, "%d.%d",
868 &unit, &addr) != 2) ||
869 (unit < 0) || (unit > 65535) ||
870 (addr < 0) || (addr > 65535)) {
859 usage();
871 usage(EX_USAGE);
860 break;
861 }
862
863 opt->bus = unit;
864 opt->addr = addr;
865 opt->got_bus = 1;
866 opt->got_addr = 1;
867 break;
868 }
872 break;
873 }
874
875 opt->bus = unit;
876 opt->addr = addr;
877 opt->got_bus = 1;
878 opt->got_addr = 1;
879 break;
880 }
869 usage();
881 usage(EX_USAGE);
870 break;
871 }
872 }
873 if (opt->got_any) {
874 /* flush out last command */
875 flush_command(pbe, opt);
876 } else {
877 /* list all the devices */
878 opt->got_list = 1;
879 opt->got_any++;
880 flush_command(pbe, opt);
881 }
882 /* release data */
883 libusb20_be_free(pbe);
884
885 return (0);
886}
882 break;
883 }
884 }
885 if (opt->got_any) {
886 /* flush out last command */
887 flush_command(pbe, opt);
888 } else {
889 /* list all the devices */
890 opt->got_list = 1;
891 opt->got_any++;
892 flush_command(pbe, opt);
893 }
894 /* release data */
895 libusb20_be_free(pbe);
896
897 return (0);
898}