Rescan usb devices manually
rescan usb devices
udevadm trigger
have your sudo credentials cached. sudo sh -c "..." works as expected when sudo needs to prompt for a password.
reset a usb controller
==terminal commands, equivalent to disconnecting and connecting a USB device==
There are a number of scripts around using similar methods :
http://billauer.co.il/blog/2013/02/u…ci-uhci-linux/
http://www.zedt.eu/tech/linux/restar…system-centos/
http://www.clearchain.com/blog/posts…us-under-linux
http://marc.info/?l=linux-usb&m=121459435621262&w=2 :
For what it’s worth, I have never seen or heard of a USB device that would not go into the “default” state (i.e., waiting for an address to be assigned) after a port reset – unless its firmware had already crashed. When that happens, all you can do is a power cycle.
Yes, there is a way to force Linux’s USB stack to perform a port reset and re-enumerate a device. It can be done using usbfs; I have attached a C program to carry it out. Note however, that reset followed by re-enumeration is not the same thing as power-cycle followed by reconnect and re-enumeration.
/* usbreset -- send a USB port reset to a USB device */
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <linux/usbdevice_fs.h>
int main(int argc, char **argv)
{
const char *filename;
int fd;
int rc;
if (argc != 2) {
fprintf(stderr, "Usage: usbreset device-filename\n");
return 1;
}
filename = argv[1];
fd = open(filename, O_WRONLY);
if (fd < 0) {
perror("Error opening output file");
return 1;
}
printf("Resetting USB device %s\n", filename);
rc = ioctl(fd, USBDEVFS_RESET, 0);
if (rc < 0) {
perror("Error in ioctl");
return 1;
}
printf("Reset successful\n");
close(fd);
return 0;
}
compile
cd /mnt/data/dev/code/C
gcc usbreset.c -o usbreset
mv usbreset /mnt/data/SYS/tools/usbreset
-# exec perimission is set by compiler
reset keyboard
lsusb
Bus 001 Device 034: ID 045e:07b9 Microsoft Corp. Wired Keyboard 200
cd /mnt/data/SYS/tools/
usbreset
Usage:
usbreset PPPP:VVVV - reset by product and vendor id
usbreset BBB/DDD - reset by bus and device number
usbreset "Product" - reset by product name
Devices:
Number 001/033 ID 413c:301a Dell MS116 USB Optical Mouse
Number 001/007 ID 04f2:b573 HD WebCam
Number 001/005 ID 04ca:3015
Number 001/035 ID 046d:0892 HD Pro Webcam C920
Number 001/003 ID 0bda:5411 4-Port USB 2.0 Hub
Number 001/034 ID 045e:07b9 USB Keyboard
Number 001/032 ID 05e3:0610 USB2.0 Hub
workarround for numlock issue :
==sudo usbreset 045e:07b9==
usbreset 001/034
usbreset ‘USB Keyboard’
=>
this works, but , gets in an ‘endless’ loop
ok to execute usbreset , but not ok to automate it with systemd supend system
, 2 versies van usbreset ?
ja deze in /usr/bin/ is van APT package usbutils
root@lapwm:/tmp# which usbreset
/usr/bin/usbreset
root@lapwm:/tmp# cd /mnt/data/SYS/tools/
root@lapwm:/mnt/data/SYS/tools# ls
usbreset
root@lapwm:/mnt/data/SYS/tools# ./usbreset 045e:07b9
Error opening output file: No such file or directory
root@lapwm:/mnt/data/SYS/tools# ls -l
total 20
-rwxrwxr-x 1 ward ward 17000 jul 21 08:59 usbreset
root@lapwm:/mnt/data/SYS/tools# # cd /usr/bin/
ls -l usbr*
-rwxr-xr-x 1 root root 14640 okt 1 2019 usbreset
as user ward :
/mnt/data/SYS/tools/usbreset 045e:07b9
Error opening output file: No such file or directory
/mnt/data/SYS/tools/usbreset ‘045e:07b9’
Error opening output file: No such file or directory
The keyboard device itself is one of the entries in /dev/input. You can locate keyboards and other input devices by their connection type (e.g. PS/2, USB, …) in /dev/input/by-path.
cd /dev/input
cd /dev/input/by-path (symlinks :)
pci-0000:00:14.0-usb-0:2.3:1.0-event-kbd ( zal het usb keyboard zijn
( platform-i8042-serio-0-event-kbd : zal het laptop keyboard zijn , want geen usb )
sudo /mnt/data/SYS/tools/usbreset pci-0000:00:14.0-usb-0:2.3:1.0-event-kbd
sudo /mnt/data/SYS/tools/usbreset “pci-0000:00:14.0-usb-0:2.3:1.0-event-kbd”
invalid argument
ward@lapwm:/dev/input/by-path$ ls -ltr
lrwxrwxrwx 1 root root 9 aug 7 08:49 pci-0000:00:14.0-usb-0:2.1:1.0-mouse -> ../mouse2
lrwxrwxrwx 1 root root 9 aug 7 08:49 pci-0000:00:15.0-platform-i2c_designware.0-mouse -> ../mouse0
lrwxrwxrwx 1 root root 9 aug 7 08:49 pci-0000:00:15.0-platform-i2c_designware.0-event-mouse -> ../event7
lrwxrwxrwx 1 root root 10 aug 7 08:49 pci-0000:00:14.0-usb-0:7:1.0-event -> ../event11
lrwxrwxrwx 1 root root 10 aug 7 08:49 pci-0000:00:14.0-usb-0:2.4:1.0-event -> ../event12
==lrwxrwxrwx 1 root root 9 aug 7 08:49 pci-0000:00:14.0-usb-0:2.3:1.0-event-kbd -> ../event9==
lrwxrwxrwx 1 root root 9 aug 7 08:49 pci-0000:00:14.0-usb-0:2.1:1.0-event-mouse -> ../event8
lrwxrwxrwx 1 root root 9 aug 7 08:49 platform-i8042-serio-0-event-kbd -> ../event4
=>
sudo /mnt/data/SYS/tools/usbreset /dev/input/event9
sudo /mnt/data/SYS/tools/usbreset ‘/dev/input/event9’
Resetting USB device /dev/input/event9
Error in ioctl: Invalid argument
argument voor deze code moet in de vorm van /dev/bus/usb/busID/devID zijn
zie : https://askubuntu.com/questions/645/how-do-you-reset-a-usb-device-from-the-command-line
sudo /mnt/data/SYS/tools/usbreset /dev/bus/usb/001/006
dit werkt , maar eveneens een eindeloze repeat
python variant
sudo python3 /mnt/data/SYS/scripts/scripts.python/usbreset.py /dev/bus/usb/001/006
dit werkt , maar eveneens een eindeloze repeat
=> er moet iets zijn in de aanroeping van ioctl
https://man7.org/linux/man-pages/man2/ioctl.2.html
error in the C code ?
https://stackoverflow.com/questions/13851212/ioctl-invalid-argument [ZOTERO]
You are passing a FILE* to the ioctl() function, while it expects a file descriptor, that is an int.
There are two solutions:
1. Use the fileno() function to get the file descriptor from the FILE*. It should be something like ioctl(fileno(memfile), IOCTL_ALLOC_MSG).
2. Use open() instead of fopen(). This one is the preferred solution if you are writing low level code, as you avoid the additional abstraction layer that FILE* imposes (all the buffering stuff and so).