From owner-dev-commits-src-all@freebsd.org Wed Jun 2 12:24:56 2021 Return-Path: Delivered-To: dev-commits-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id CCC9F641C68; Wed, 2 Jun 2021 12:24:56 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Fw7Wr41dNz3FSX; Wed, 2 Jun 2021 12:24:56 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 65D2A16C54; Wed, 2 Jun 2021 12:24:56 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 152COuHu019251; Wed, 2 Jun 2021 12:24:56 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 152COuXv019250; Wed, 2 Jun 2021 12:24:56 GMT (envelope-from git) Date: Wed, 2 Jun 2021 12:24:56 GMT Message-Id: <202106021224.152COuXv019250@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Hans Petter Selasky Subject: git: 4c4416a09805 - stable/13 - Implement own command line option for the frequently used -i usbusX -f Y syntax, -d ugenX.Y, similar to what usbconfig(8) does. MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: hselasky X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 4c4416a0980528ca31efaa8ff63978852c67c03d Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-all@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for all branches of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 02 Jun 2021 12:24:56 -0000 The branch stable/13 has been updated by hselasky: URL: https://cgit.FreeBSD.org/src/commit/?id=4c4416a0980528ca31efaa8ff63978852c67c03d commit 4c4416a0980528ca31efaa8ff63978852c67c03d Author: Hans Petter Selasky AuthorDate: 2021-05-14 15:12:57 +0000 Commit: Hans Petter Selasky CommitDate: 2021-06-02 11:25:20 +0000 Implement own command line option for the frequently used -i usbusX -f Y syntax, -d ugenX.Y, similar to what usbconfig(8) does. Sponsored by: Mellanox Technologies // NVIDIA Networking (cherry picked from commit c904e20cc903d28c1090c531c907cdd6865455ff) --- usr.sbin/usbdump/usbdump.8 | 30 ++++++++++++++++++++++++- usr.sbin/usbdump/usbdump.c | 56 ++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 76 insertions(+), 10 deletions(-) diff --git a/usr.sbin/usbdump/usbdump.8 b/usr.sbin/usbdump/usbdump.8 index 475e832cd03b..6b5ad1920e94 100644 --- a/usr.sbin/usbdump/usbdump.8 +++ b/usr.sbin/usbdump/usbdump.8 @@ -25,7 +25,7 @@ .\" .\" $FreeBSD$ .\" -.Dd April 24, 2012 +.Dd May 14, 2021 .Dt USBDUMP 8 .Os .Sh NAME @@ -33,6 +33,9 @@ .Nd "dump traffic on USB host controller" .Sh SYNOPSIS .Nm +.Op Fl d Ar [ugen]B +.Op Fl d Ar [ugen]B.D +.Op Fl d Ar [ugen]B.D.E .Op Fl i Ar ifname .Op Fl r Ar file .Op Fl s Ar snaplen @@ -48,6 +51,31 @@ utility provides a way to dump USB packets on host controllers. .Pp The following options are accepted: .Bl -tag -width ".Fl f Ar file" +.It Fl d Ar [ugen]bus +Shortcut for +.Fl i +option. +The argument may be prefixed by "ugen". +The option may be specified multiple times, but the bus specified must +be the same. +.It Fl d Ar [ugen]bus.device +Shortcut for +.Fl i +and +.Fl f +options. +The argument may be prefixed by "ugen". +The option may be specified multiple times, but the bus specified must +be the same. +.It Fl d Ar [ugen]bus.device.endpoint +Shortcut for +.Fl i +and +.Fl f +options. +The argument may be prefixed by "ugen". +The option may be specified multiple times, but the bus specified must +be the same. .It Fl b Ar file Store data part of the USB trace in binary format to the given .Ar file . diff --git a/usr.sbin/usbdump/usbdump.c b/usr.sbin/usbdump/usbdump.c index a38d08a252af..00d3b8e8913b 100644 --- a/usr.sbin/usbdump/usbdump.c +++ b/usr.sbin/usbdump/usbdump.c @@ -108,14 +108,14 @@ struct header_32 { uint8_t align; } __packed; -static int doexit = 0; -static int pkt_captured = 0; -static int verbose = 0; +static int doexit; +static int pkt_captured; +static int verbose; static int uf_minor; -static const char *i_arg = "usbus0"; -static const char *r_arg = NULL; -static const char *w_arg = NULL; -static const char *b_arg = NULL; +static char *i_arg; +static char *r_arg; +static char *w_arg; +static char *b_arg; static struct usbcap uc; static const char *errstr_table[USB_ERR_MAX] = { [USB_ERR_NORMAL_COMPLETION] = "0", @@ -779,7 +779,10 @@ usage(void) #define FMT " %-14s %s\n" fprintf(stderr, "usage: usbdump [options]\n"); - fprintf(stderr, FMT, "-i ", "Listen on USB bus interface"); + fprintf(stderr, FMT, "-d [ugen]B", "Listen on bus, B"); + fprintf(stderr, FMT, "-d [ugen]B.D", "Listen on bus, B and device, D"); + fprintf(stderr, FMT, "-d [ugen]B.D.E", "Listen on bus, B, device, D, and endpoint E"); + fprintf(stderr, FMT, "-i ", "Listen on this bus interface"); fprintf(stderr, FMT, "-f ", "Specify a device and endpoint filter"); fprintf(stderr, FMT, "-r ", "Read the raw packets from file"); fprintf(stderr, FMT, "-s ", "Snapshot bytes from each packet"); @@ -828,9 +831,41 @@ main(int argc, char *argv[]) const char *optstring; char *pp; - optstring = "b:hi:r:s:vw:f:"; + optstring = "b:d:hi:r:s:vw:f:"; while ((o = getopt(argc, argv, optstring)) != -1) { switch (o) { + case 'd': + pp = optarg; + if (pp[0] == 'u' && pp[1] == 'g' && pp[2] == 'e' && pp[3] == 'n') + pp += 4; + ifindex = strtol(pp, &pp, 10); + /* Must be same bus when using -d option. */ + if (i_arg != NULL) { + if (atoi(i_arg + 5) != ifindex) + usage(); + } else { + asprintf(&i_arg, "usbus%d", ifindex); + } + /* Parse unit and endpoint, if any. */ + if (pp != NULL) { + if (*pp == '.') { + filt_unit = strtol(pp + 1, &pp, 10); + filt_ep = -1; + if (pp != NULL) { + if (*pp == '.') { + filt_ep = strtol(pp + 1, &pp, 10); + if (pp != NULL && *pp != 0) + usage(); + } else if (*pp != 0) { + usage(); + } + } + add_filter(filt_unit, filt_ep); + } else if (*pp != 0) { + usage(); + } + } + break; case 'i': i_arg = optarg; break; @@ -879,6 +914,9 @@ main(int argc, char *argv[]) } } + if (i_arg == NULL) + i_arg = "usbus0"; + if (b_arg != NULL) { p->bfd = open(b_arg, O_CREAT | O_TRUNC | O_WRONLY, S_IRUSR | S_IWUSR);