usbconfig.c (fa6d8b65d3956f69cde9043a3c5e77fb57788904) usbconfig.c (ae450e6de96b5ec65f425a52b08dc859576ab8d0)
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

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

26 * SUCH DAMAGE.
27 */
28
29#include <stdio.h>
30#include <stdlib.h>
31#include <stdint.h>
32#include <err.h>
33#include <string.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

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

26 * SUCH DAMAGE.
27 */
28
29#include <stdio.h>
30#include <stdlib.h>
31#include <stdint.h>
32#include <err.h>
33#include <string.h>
34#include <unistd.h>
34#include <pwd.h>
35#include <grp.h>
36#include <errno.h>
37#include <ctype.h>
38#include <sys/types.h>
39
40#include <libusb20_desc.h>
41#include <libusb20.h>

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

95
96struct token {
97 const char *name;
98 uint8_t value;
99 uint8_t narg;
100};
101
102enum {
35#include <pwd.h>
36#include <grp.h>
37#include <errno.h>
38#include <ctype.h>
39#include <sys/types.h>
40
41#include <libusb20_desc.h>
42#include <libusb20.h>

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

96
97struct token {
98 const char *name;
99 uint8_t value;
100 uint8_t narg;
101};
102
103enum {
103 T_UNIT,
104 T_ADDR,
105 T_UGEN,
106 T_IFACE,
107 T_SET_CONFIG,
108 T_SET_ALT,
109 T_SET_TEMPLATE,
110 T_GET_TEMPLATE,
111 T_ADD_DEVICE_QUIRK,
112 T_REMOVE_DEVICE_QUIRK,
113 T_ADD_QUIRK,
114 T_REMOVE_QUIRK,

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

131 T_RESET,
132 T_LIST,
133 T_DO_REQUEST,
134};
135
136static struct options options;
137
138static const struct token token[] = {
104 T_SET_CONFIG,
105 T_SET_ALT,
106 T_SET_TEMPLATE,
107 T_GET_TEMPLATE,
108 T_ADD_DEVICE_QUIRK,
109 T_REMOVE_DEVICE_QUIRK,
110 T_ADD_QUIRK,
111 T_REMOVE_QUIRK,

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

128 T_RESET,
129 T_LIST,
130 T_DO_REQUEST,
131};
132
133static struct options options;
134
135static const struct token token[] = {
139 {"-u", T_UNIT, 1},
140 {"-a", T_ADDR, 1},
141 {"-d", T_UGEN, 1},
142 {"-i", T_IFACE, 1},
143 {"set_config", T_SET_CONFIG, 1},
144 {"set_alt", T_SET_ALT, 1},
145 {"set_template", T_SET_TEMPLATE, 1},
146 {"get_template", T_GET_TEMPLATE, 0},
147 {"add_dev_quirk_vplh", T_ADD_DEVICE_QUIRK, 5},
148 {"remove_dev_quirk_vplh", T_REMOVE_DEVICE_QUIRK, 5},
149 {"add_quirk", T_ADD_QUIRK, 1},
150 {"remove_quirk", T_REMOVE_QUIRK, 1},

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

558{
559 struct libusb20_backend *pbe;
560 struct options *opt = &options;
561 const char *ptr;
562 int unit;
563 int addr;
564 int n;
565 int t;
136 {"set_config", T_SET_CONFIG, 1},
137 {"set_alt", T_SET_ALT, 1},
138 {"set_template", T_SET_TEMPLATE, 1},
139 {"get_template", T_GET_TEMPLATE, 0},
140 {"add_dev_quirk_vplh", T_ADD_DEVICE_QUIRK, 5},
141 {"remove_dev_quirk_vplh", T_REMOVE_DEVICE_QUIRK, 5},
142 {"add_quirk", T_ADD_QUIRK, 1},
143 {"remove_quirk", T_REMOVE_QUIRK, 1},

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

551{
552 struct libusb20_backend *pbe;
553 struct options *opt = &options;
554 const char *ptr;
555 int unit;
556 int addr;
557 int n;
558 int t;
559 int ch;
566
567 if (argc < 1) {
568 usage();
569 }
570 pbe = libusb20_be_alloc_default();
571 if (pbe == NULL)
572 err(1, "could not access USB backend\n");
573
560
561 if (argc < 1) {
562 usage();
563 }
564 pbe = libusb20_be_alloc_default();
565 if (pbe == NULL)
566 err(1, "could not access USB backend\n");
567
574 for (n = 1; n != argc; n++) {
568 while ((ch = getopt(argc, argv, "a:d:i:u:")) != -1) {
569 switch (ch) {
570 case 'a':
571 opt->addr = num_id(optarg, "addr");
572 opt->got_addr = 1;
573 break;
575
574
575 case 'd':
576 if (strncmp(optarg, "ugen", strlen("ugen")) == 0) {
577 ptr = optarg + strlen("ugen");
578 } else if (strncmp(optarg, "/dev/ugen",
579 strlen("/dev/ugen")) == 0) {
580 ptr = optarg + strlen("/dev/ugen");
581 } else {
582 ptr = optarg;
583 }
584 if ((sscanf(ptr, "%d.%d",
585 &unit, &addr) != 2) ||
586 (unit < 0) || (unit > 65535) ||
587 (addr < 0) || (addr > 65535)) {
588 errx(1, "cannot "
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 'i':
598 opt->iface = num_id(optarg, "iface");
599 opt->got_iface = 1;
600 break;
601
602 case 'u':
603 opt->bus = num_id(optarg, "busnum");
604 opt->got_bus = 1;
605 break;
606
607 default:
608 usage();
609 }
610 }
611 argc -= optind;
612 argv += optind;
613
614 for (n = 0; n != argc; n++) {
615
576 /* get number of additional options */
577 t = (argc - n - 1);
578 if (t > 255)
579 t = 255;
580 switch (get_token(argv[n], t)) {
581 case T_ADD_QUIRK:
582 if (opt->got_add_quirk) {
583 flush_command(pbe, opt);

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

649 opt->got_dump_device_quirks = 1;
650 opt->got_any++;
651 break;
652
653 case T_SHOW_IFACE_DRIVER:
654 opt->got_show_iface_driver = 1;
655 break;
656
616 /* get number of additional options */
617 t = (argc - n - 1);
618 if (t > 255)
619 t = 255;
620 switch (get_token(argv[n], t)) {
621 case T_ADD_QUIRK:
622 if (opt->got_add_quirk) {
623 flush_command(pbe, opt);

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

689 opt->got_dump_device_quirks = 1;
690 opt->got_any++;
691 break;
692
693 case T_SHOW_IFACE_DRIVER:
694 opt->got_show_iface_driver = 1;
695 break;
696
657 case T_UGEN:
658 if (opt->got_any) {
659 /* allow multiple commands on the same line */
660 flush_command(pbe, opt);
661 }
662 ptr = argv[n + 1];
663
664 if ((ptr[0] == 'u') &&
665 (ptr[1] == 'g') &&
666 (ptr[2] == 'e') &&
667 (ptr[3] == 'n'))
668 ptr += 4;
669
670 if ((sscanf(ptr, "%d.%d",
671 &unit, &addr) != 2) ||
672 (unit < 0) || (unit > 65535) ||
673 (addr < 0) || (addr > 65535)) {
674 errx(1, "cannot "
675 "parse '%s'", argv[n + 1]);
676 }
677 opt->bus = unit;
678 opt->addr = addr;
679 opt->got_bus = 1;
680 opt->got_addr = 1;
681 n++;
682 break;
683
684 case T_UNIT:
685 if (opt->got_any) {
686 /* allow multiple commands on the same line */
687 flush_command(pbe, opt);
688 }
689 opt->bus = num_id(argv[n + 1], "busnum");
690 opt->got_bus = 1;
691 n++;
692 break;
693 case T_ADDR:
694 opt->addr = num_id(argv[n + 1], "addr");
695 opt->got_addr = 1;
696 n++;
697 break;
698 case T_IFACE:
699 opt->iface = num_id(argv[n + 1], "iface");
700 opt->got_iface = 1;
701 n++;
702 break;
703 case T_SET_CONFIG:
704 if (opt->got_set_config)
705 duplicate_option(argv[n]);
706 opt->config_index = num_id(argv[n + 1], "cfg_index");
707 opt->got_set_config = 1;
708 opt->got_any++;
709 n++;
710 break;

--- 184 unchanged lines hidden ---
697 case T_SET_CONFIG:
698 if (opt->got_set_config)
699 duplicate_option(argv[n]);
700 opt->config_index = num_id(argv[n + 1], "cfg_index");
701 opt->got_set_config = 1;
702 opt->got_any++;
703 n++;
704 break;

--- 184 unchanged lines hidden ---