usbconfig: implement a -v option

Implement a -v option to usbconfig(8), as a shortcut for the most
frequently needed commands dump_device_desc, dump_curr_config_desc,
and show_ifdrv.

While here, implement a real -h option that has been promised by the
man page.

Use <sysexits.h> to declare the utility return codes.

Reviewed by:	hselasky
Differential Revision:	https://reviews.freebsd.org/D33586
MFC after:	2 weeks
This commit is contained in:
Joerg Wunsch 2021-12-20 20:33:05 +01:00
parent 2a28b045ca
commit d69b9cc26d
No known key found for this signature in database
GPG Key ID: 7E9EADC3030D34EB
2 changed files with 33 additions and 11 deletions

View File

@ -23,7 +23,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.Dd December 20, 2021
.Dd December 21, 2021
.Dt USBCONFIG 8
.Os
.Sh NAME
@ -34,10 +34,12 @@
.Op Fl u Ar unit
.Op Fl a Ar addr
.Op Fl i Ar interface_index
.Op Fl v
.Op cmds...
.Nm
.Fl d Ar [[/dev/]ugen]<unit>.<addr>
.Op Fl i Ar interface_index
.Op Fl v
.Op cmds...
.Sh DESCRIPTION
The
@ -56,11 +58,19 @@ Limit device range to USB devices connected to the given unit and address.
The unit and address coordinates may be prefixed by the lowercased word "ugen",
or the full path name
.Pa /dev/ugen .
.It Fl h
Show help and available commands.
.It Fl i Ar interface_index
Specify interface index as indicated by the command description.
If this argument is not specified a value of zero will be used for the interface index.
.It Fl h
Show help and available commands.
.It Fl v
Shortcut to activate the
.Cm dump_device_desc ,
.Cm dump_curr_config_desc ,
and
.Cm show_ifdrv
commands
.Pq Dq verbose mode .
.El
.Pp
The following commands may be used with

View File

@ -30,6 +30,7 @@
#include <stdlib.h>
#include <stdint.h>
#include <err.h>
#include <sysexits.h>
#include <string.h>
#include <unistd.h>
#include <pwd.h>
@ -267,12 +268,12 @@ duplicate_option(const char *ptr)
}
static void
usage(void)
usage(int exitcode)
{
fprintf(stderr, ""
"usbconfig - configure the USB subsystem" "\n"
"usage: usbconfig [-u <busnum>] [-a <devaddr>] [-i <ifaceindex>] [cmds...]" "\n"
"usage: usbconfig -d [ugen]<busnum>.<devaddr> [-i <ifaceindex>] [cmds...]" "\n"
"usage: usbconfig [-u <busnum>] [-a <devaddr>] [-i <ifaceindex>] [-v] [cmds...]" "\n"
"usage: usbconfig -d [ugen]<busnum>.<devaddr> [-i <ifaceindex>] [-v] [cmds...]" "\n"
"commands:" "\n"
" set_config <cfg_index>" "\n"
" set_alt <alt_index>" "\n"
@ -558,13 +559,13 @@ main(int argc, char **argv)
int ch;
if (argc < 1) {
usage();
usage(EX_USAGE);
}
pbe = libusb20_be_alloc_default();
if (pbe == NULL)
err(1, "could not access USB backend\n");
while ((ch = getopt(argc, argv, "a:d:i:u:")) != -1) {
while ((ch = getopt(argc, argv, "a:d:hi:u:v")) != -1) {
switch (ch) {
case 'a':
opt->addr = num_id(optarg, "addr");
@ -593,6 +594,10 @@ main(int argc, char **argv)
opt->got_addr = 1;
break;
case 'h':
usage(EX_OK);
break;
case 'i':
opt->iface = num_id(optarg, "iface");
break;
@ -602,8 +607,15 @@ main(int argc, char **argv)
opt->got_bus = 1;
break;
case 'v':
opt->got_dump_device_desc = 1;
opt->got_dump_curr_config = 1;
opt->got_show_iface_driver = 1;
opt->got_any += 2; /* only the dump options count */
break;
default:
usage();
usage(EX_USAGE);
}
}
argc -= optind;
@ -856,7 +868,7 @@ main(int argc, char **argv)
&unit, &addr) != 2) ||
(unit < 0) || (unit > 65535) ||
(addr < 0) || (addr > 65535)) {
usage();
usage(EX_USAGE);
break;
}
@ -866,7 +878,7 @@ main(int argc, char **argv)
opt->got_addr = 1;
break;
}
usage();
usage(EX_USAGE);
break;
}
}