summaryrefslogtreecommitdiff
path: root/source/a/usbutils
diff options
context:
space:
mode:
authorPatrick J Volkerding <volkerdi@slackware.com>2018-05-28 19:12:29 +0000
committerEric Hameleers <alien@slackware.com>2018-05-31 23:39:35 +0200
commit646a5c1cbfd95873950a87b5f75d52073a967023 (patch)
treeb8b8d2ab3b0d432ea69ad1a64d1c789649d65020 /source/a/usbutils
parentd31c50870d0bee042ce660e445c9294a59a3a65b (diff)
downloadcurrent-646a5c1cbfd95873950a87b5f75d52073a967023.tar.gz
Mon May 28 19:12:29 UTC 201820180528191229
a/pkgtools-15.0-noarch-13.txz: Rebuilt. installpkg: default line length for --terselength is the number of columns. removepkg: added --terse mode. upgradepkg: default line length for --terselength is the number of columns. upgradepkg: accept -option in addition to --option. ap/vim-8.1.0026-x86_64-1.txz: Upgraded. d/bison-3.0.5-x86_64-1.txz: Upgraded. e/emacs-26.1-x86_64-1.txz: Upgraded. kde/kopete-4.14.3-x86_64-8.txz: Rebuilt. Recompiled against libidn-1.35. n/conntrack-tools-1.4.5-x86_64-1.txz: Upgraded. n/libnetfilter_conntrack-1.0.7-x86_64-1.txz: Upgraded. n/libnftnl-1.1.0-x86_64-1.txz: Upgraded. n/links-2.16-x86_64-2.txz: Rebuilt. Rebuilt to enable X driver for -g mode. n/lynx-2.8.9dev.19-x86_64-1.txz: Upgraded. n/nftables-0.8.5-x86_64-1.txz: Upgraded. n/p11-kit-0.23.11-x86_64-1.txz: Upgraded. n/ulogd-2.0.7-x86_64-1.txz: Upgraded. n/whois-5.3.1-x86_64-1.txz: Upgraded. xap/network-manager-applet-1.8.12-x86_64-1.txz: Upgraded. xap/vim-gvim-8.1.0026-x86_64-1.txz: Upgraded.
Diffstat (limited to 'source/a/usbutils')
-rw-r--r--source/a/usbutils/slack-desc6
-rw-r--r--source/a/usbutils/usbreset.c188
-rw-r--r--source/a/usbutils/usbutils-008.tar.sign17
-rw-r--r--source/a/usbutils/usbutils-010.tar.sign16
-rwxr-xr-xsource/a/usbutils/usbutils.SlackBuild19
5 files changed, 223 insertions, 23 deletions
diff --git a/source/a/usbutils/slack-desc b/source/a/usbutils/slack-desc
index ffca25c2..a519fd7f 100644
--- a/source/a/usbutils/slack-desc
+++ b/source/a/usbutils/slack-desc
@@ -1,8 +1,8 @@
# HOW TO EDIT THIS FILE:
-# The "handy ruler" below makes it easier to edit a package description. Line
+# The "handy ruler" below makes it easier to edit a package description. Line
# up the first '|' above the ':' following the base package name, and the '|'
-# on the right side marks the last column you can put a character in. You must
-# make exactly 11 lines for the formatting to be correct. It's also
+# on the right side marks the last column you can put a character in. You must
+# make exactly 11 lines for the formatting to be correct. It's also
# customary to leave one space after the ':'.
|-----handy-ruler------------------------------------------------------|
diff --git a/source/a/usbutils/usbreset.c b/source/a/usbutils/usbreset.c
new file mode 100644
index 00000000..abab5434
--- /dev/null
+++ b/source/a/usbutils/usbreset.c
@@ -0,0 +1,188 @@
+/* usbreset -- send a USB port reset to a USB device */
+/* To build: gcc -o usbreset usbreset.c */
+
+#include <stdio.h>
+#include <stdbool.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <string.h>
+#include <ctype.h>
+#include <limits.h>
+#include <dirent.h>
+#include <sys/ioctl.h>
+#include <sys/types.h>
+
+#include <linux/usbdevice_fs.h>
+
+
+static char *usbfs = NULL;
+
+struct usbentry {
+ int bus_num;
+ int dev_num;
+ int vendor_id;
+ int product_id;
+ char vendor_name[128];
+ char product_name[128];
+};
+
+static char *sysfs_attr(const char *dev, const char *attr)
+{
+ int fd, len = 0;
+ char path[PATH_MAX];
+ static char buf[129];
+
+ memset(buf, 0, sizeof(buf));
+ snprintf(path, sizeof(path) - 1, "/sys/bus/usb/devices/%s/%s", dev, attr);
+
+ fd = open(path, O_RDONLY);
+ if (fd >= 0) {
+ len = read(fd, buf, sizeof(buf) - 1);
+ close(fd);
+ }
+
+ while (--len > 0 && isspace(buf[len]))
+ buf[len] = 0;
+
+ return (len >= 0) ? buf : NULL;
+}
+
+static struct usbentry *parse_devlist(DIR *d)
+{
+ char *attr;
+ struct dirent *e;
+ static struct usbentry dev;
+
+ do {
+ e = readdir(d);
+
+ if (!e)
+ return NULL;
+ } while (!isdigit(e->d_name[0]) || strchr(e->d_name, ':'));
+
+ memset(&dev, 0, sizeof(dev));
+
+ attr = sysfs_attr(e->d_name, "busnum");
+ if (attr)
+ dev.bus_num = strtoul(attr, NULL, 10);
+
+ attr = sysfs_attr(e->d_name, "devnum");
+ if (attr)
+ dev.dev_num = strtoul(attr, NULL, 10);
+
+ attr = sysfs_attr(e->d_name, "idVendor");
+ if (attr)
+ dev.vendor_id = strtoul(attr, NULL, 16);
+
+ attr = sysfs_attr(e->d_name, "idProduct");
+ if (attr)
+ dev.product_id = strtoul(attr, NULL, 16);
+
+ attr = sysfs_attr(e->d_name, "manufacturer");
+ if (attr)
+ strcpy(dev.vendor_name, attr);
+
+ attr = sysfs_attr(e->d_name, "product");
+ if (attr)
+ strcpy(dev.product_name, attr);
+
+ if (dev.bus_num && dev.dev_num && dev.vendor_id && dev.product_id)
+ return &dev;
+
+ return NULL;
+}
+
+static void list_devices(void)
+{
+ DIR *devs = opendir("/sys/bus/usb/devices");
+ struct usbentry *dev;
+
+ if (!devs)
+ return;
+
+ while ((dev = parse_devlist(devs)) != NULL)
+ printf(" Number %03d/%03d ID %04x:%04x %s\n",
+ dev->bus_num, dev->dev_num,
+ dev->vendor_id, dev->product_id,
+ dev->product_name);
+
+ closedir(devs);
+}
+
+struct usbentry *find_device(int *bus, int *dev, int *vid, int *pid,
+ const char *product)
+{
+ DIR *devs = opendir("/sys/bus/usb/devices");
+
+ struct usbentry *e, *match = NULL;
+
+ if (!devs)
+ return NULL;
+
+ while ((e = parse_devlist(devs)) != NULL)
+ if ((bus && (e->bus_num == *bus) && (e->dev_num == *dev)) ||
+ (vid && (e->vendor_id == *vid) && (e->product_id == *pid)) ||
+ (product && !strcasecmp(e->product_name, product))) {
+ match = e;
+ break;
+ }
+
+ closedir(devs);
+
+ return match;
+}
+
+static void reset_device(struct usbentry *dev)
+{
+ int fd;
+ char path[PATH_MAX];
+
+ snprintf(path, sizeof(path) - 1, "/dev/bus/usb/%03d/%03d",
+ dev->bus_num, dev->dev_num);
+
+ printf("Resetting %s ... ", dev->product_name);
+
+ fd = open(path, O_WRONLY);
+ if (fd > -1) {
+ if (ioctl(fd, USBDEVFS_RESET, 0) < 0)
+ printf("failed [%s]\n", strerror(errno));
+ else
+ printf("ok\n");
+
+ close(fd);
+ } else {
+ printf("can't open [%s]\n", strerror(errno));
+ }
+}
+
+
+int main(int argc, char **argv)
+{
+ int id1, id2;
+ struct usbentry *dev;
+
+ if ((argc == 2) && (sscanf(argv[1], "%3d/%3d", &id1, &id2) == 2))
+ dev = find_device(&id1, &id2, NULL, NULL, NULL);
+ else if ((argc == 2) && (sscanf(argv[1], "%4x:%4x", &id1, &id2) == 2))
+ dev = find_device(NULL, NULL, &id1, &id2, NULL);
+ else if ((argc == 2) && strlen(argv[1]) < 128)
+ dev = find_device(NULL, NULL, NULL, NULL, argv[1]);
+ else {
+ printf("Usage:\n"
+ " usbreset PPPP:VVVV - reset by product and vendor id\n"
+ " usbreset BBB/DDD - reset by bus and device number\n"
+ " usbreset \"Product\" - reset by product name\n\n"
+ "Devices:\n");
+ list_devices();
+ return 1;
+ }
+
+ if (!dev) {
+ fprintf(stderr, "No such device found\n");
+ return 1;
+ }
+
+ reset_device(dev);
+ return 0;
+}
diff --git a/source/a/usbutils/usbutils-008.tar.sign b/source/a/usbutils/usbutils-008.tar.sign
deleted file mode 100644
index 52f8495a..00000000
--- a/source/a/usbutils/usbutils-008.tar.sign
+++ /dev/null
@@ -1,17 +0,0 @@
------BEGIN PGP SIGNATURE-----
-Version: GnuPG v2
-
-iQIcBAABAgAGBQJURsk6AAoJEDjbvchgkmk+F+EQAKVI4MKXye0qmoTgZR70q+o/
-ANwlSg+mwTrpIxHO+dVUY3NPJlj0ZT/TnV3Xbe2UjxDe0JW7CkMeLAocqhdWy4sq
-cGUlLASeiANSgv+tilqwHZTpTlM4Wo0EtnDJ29U0oVim8vPED7AXZbENZ3S6nuCk
-RrcxVzo9UsBckniIkuY8fsTpcU0FcLsPIhgasw0iToBdVfeZp3LuLF9s69Gt6BK/
-BJKa1L3q14jGcH8MJBO+gQuiu/gYxgdYGXdzqxGmfDSHON/pyOAlzYDdxLAqR76B
-+LbQW6lTnlPutlW4QEYfnmKYXvXkof7saKt/UXrJcXNK/YwbiTHiRQ4lxtlP5WyW
-vTunBLssJCDVRyQMV2iD9c0PLTiPcGcFp2tpkM1ULUMpnrWLF4K83KQQ2y51NA0p
-J/4jQLQWOXjX+e/Ns6R9Mp3D3vh7Jy/fsdyDlsCR2YVMVePBSbQ8n0UqNzQnqa+Z
-na2w/51XIazG5ijk4dPhx0hkO+fZVgfMSX+rITlsIjga+ezwwwUDgSc/NZhoteN/
-5pHGXXnsPRmhc+7sG6T3D17w1euu9rZ6eznXGQqrN6pDaxbiH8AnbyYteXQcANr0
-8duSxDb3R74ZVAlhfRF9MeSIdq+bBZCOptiXtAgnEYbYoG8vU3UBuhMc+q7y3Adw
-Abrr12hSiLQDnX+T+YlF
-=rTq4
------END PGP SIGNATURE-----
diff --git a/source/a/usbutils/usbutils-010.tar.sign b/source/a/usbutils/usbutils-010.tar.sign
new file mode 100644
index 00000000..2c9a1f07
--- /dev/null
+++ b/source/a/usbutils/usbutils-010.tar.sign
@@ -0,0 +1,16 @@
+-----BEGIN PGP SIGNATURE-----
+
+iQIzBAABCAAdFiEEZH8oZUiU471FcZm+ONu9yGCSaT4FAlr67JkACgkQONu9yGCS
+aT5S1BAAyRPPT8ZTDkoVKoqtS3SigzjGhs4DAdPyS/mgzlegcEFebM/3AlROrS2t
+dPYeDvrPiRA/nFIRGx3nTJH+OfhJ8NfR+pc2CJ22PY3EQKwSLAJcn1jp9Xc/IXB9
+LQE0Ed4tEAK5p0diysr3CbH3UrQU1sQUGWCUNEZDb9FiNCOWFQqRMpE4dESxgZeD
+GiIVk9ppZYv2mcbHjLvELtrf4Huy9HaWcQ42MWRK0tbmZPcgnpVLwSZff95NtH9P
+D3v7RGrtCpYhQl4BEIZZK2TGx/BhdyQ1siwUiFN3ZtkCkdAP9HbB1nYy8S190XhJ
+5+EaTgEA1LbVYfoHtJ4qp47EsoZCVdUunec38k8G7qTagX/NGi0KDZick+Z+V9pm
+eh7cLX5S0gEIroBI3o/Uh28GnLs+zekfAEycc4qwm8l5qNXYbWsqZ0LODMGbVfv8
+dg+R/HzwclCiAzI8l/7jv7F0fK1TWTZm4vCn07rm2zA7JkFbFQ9pcEFwHGy3b4ou
+k7Xugs9BQdB8OhxSdnalYKfR+X9X3R58XSnF9r0Ymg2OkUoEvK7RNqSKxyKWKCJf
+ruE75l4SpOh38woUDppGxts7hZSWOYwxvjxnx5Pih0CJZVyaK6wHgl66naFyC/sO
+pZcjq09gqerE82dc32963UXYR0knDgA0FsSEpzWxfzMaA6uZrYM=
+=qAeG
+-----END PGP SIGNATURE-----
diff --git a/source/a/usbutils/usbutils.SlackBuild b/source/a/usbutils/usbutils.SlackBuild
index 26336742..c45e6cb5 100755
--- a/source/a/usbutils/usbutils.SlackBuild
+++ b/source/a/usbutils/usbutils.SlackBuild
@@ -1,6 +1,6 @@
-#!/bin/sh
+#!/bin/bash
-# Copyright 2008, 2009, 2010, 2011, 2013, 2015 Patrick J. Volkerding, Sebeka, MN, USA
+# Copyright 2008, 2009, 2010, 2011, 2013, 2015, 2018 Patrick J. Volkerding, Sebeka, MN, USA
# All rights reserved.
#
# Redistribution and use of this script, with or without modification, is
@@ -20,7 +20,9 @@
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+cd $(dirname $0) ; CWD=$(pwd)
+PKGNAM=usbutils
VERSION=${VERSION:-$(echo usbutils-*.tar.xz | rev | cut -f 3- -d . | cut -f 1 -d - | rev)}
BUILD=${BUILD:-1}
@@ -36,7 +38,14 @@ if [ -z "$ARCH" ]; then
esac
fi
-CWD=$(pwd)
+# If the variable PRINT_PACKAGE_NAME is set, then this script will report what
+# the name of the created package would be, and then exit. This information
+# could be useful to other scripts.
+if [ ! -z "${PRINT_PACKAGE_NAME}" ]; then
+ echo "$PKGNAM-$VERSION-$ARCH-$BUILD.txz"
+ exit 0
+fi
+
TMP=${TMP:-/tmp}
PKG=$TMP/package-usbutils
@@ -85,6 +94,10 @@ CFLAGS="$SLKCFLAGS" \
make $NUMJOBS || make || exit 1
make install DESTDIR=$PKG || exit 1
+# Include the example usbreset program
+gcc ${SLKCFLAGS} -o $PKG/usr/bin/usbreset $CWD/usbreset.c || exit 1
+chmod 0755 $PKG/usr/bin/usbreset
+
find $PKG | xargs file | grep -e "executable" -e "shared object" \
| grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null