Obtaining information about /dev/usb/lp* devices - linux

I have a problem obtaining information about /dev/usb/lp* devices.
The lsusb command gives me USB bus and device IDs, and a name of the device but I can't figure out how to get it to tell me the name of the corresponding /dev/usb/lp* device.
I don't have CUPS available.

You can use libudev to get the equivalent of the following command:
$ udevadm info -a /dev/usb/lp*
In my PC it prints something like:
looking at device '/devices/pci0000:00/0000:00:1a.0/usb1/1-1/1-1.3/1-1.3:1.1/usbmisc/lp2':
KERNEL=="lp2"
SUBSYSTEM=="usbmisc"
DRIVER==""
looking at parent device '/devices/pci0000:00/0000:00:1a.0/usb1/1-1/1-1.3/1-1.3:1.1':
KERNELS=="1-1.3:1.1"
SUBSYSTEMS=="usb"
DRIVERS=="usblp"
...
looking at parent device '/devices/pci0000:00/0000:00:1a.0/usb1/1-1/1-1.3':
KERNELS=="1-1.3"
SUBSYSTEMS=="usb"
DRIVERS=="usb"
...
ATTRS{idProduct}=="341b"
ATTRS{idVendor}=="04e8"
...
And there they are! The wanted idProduct and the idVendor
You can also get the information by navigating the /sys directory manually:
$ ls -l /dev/usb/lp2
crw-rw---- 1 root lp 180, 2 Sep 27 11:46 /dev/usb/lp2
$ readlink -f /sys/dev/char/180:2
/sys/devices/pci0000:00/0000:00:1a.0/usb1/1-1/1-1.3/1-1.3:1.1/usbmisc/lp2
$ cat /sys/devices/pci0000:00/0000:00:1a.0/usb1/1-1/1-1.3/{idVendor,idProduct}
04e8
341b

Related

How to troubleshoot an expected CDROM device on custom Linux kernel?

I'm looking for some hints while troubleshooting missing CDROM device.
The problem is, missing configuration option for my custom kernel (linux-5.4.78).
My current .config has:
CONFIG_CDROM=y
CONFIG_BLK_DEV_SR=y
CONFIG_VHOST_SCSI=y
CONFIG_BLK_SCSI_REQUEST=y
CONFIG_SCSI_MOD=y
CONFIG_SCSI=y
CONFIG_SCSI_DMA=y
CONFIG_SCSI_NETLINK=y
CONFIG_SCSI_PROC_FS=y
CONFIG_SCSI_SPI_ATTRS=y
CONFIG_SCSI_FC_ATTRS=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GDTH=y
CONFIG_SCSI_ISCI=y
CONFIG_SCSI_IPS=y
CONFIG_SCSI_INITIO=y
CONFIG_SCSI_INIA100=y
CONFIG_SCSI_PPA=y
CONFIG_SCSI_IMM=y
CONFIG_SCSI_STEX=y
CONFIG_SCSI_SYM53C8XX_2=y
CONFIG_SCSI_SYM53C8XX_MMIO=y
CONFIG_SCSI_IPR=y
CONFIG_SCSI_IPR_TRACE=y
CONFIG_SCSI_IPR_DUMP=y
CONFIG_SCSI_QLOGIC_1280=y
CONFIG_SCSI_QLA_FC=y
CONFIG_SCSI_QLA_ISCSI=y
CONFIG_SCSI_LPFC=y
CONFIG_SCSI_DC395x=y
CONFIG_SCSI_AM53C974=y
CONFIG_SCSI_WD719X=y
CONFIG_SCSI_PMCRAID=y
CONFIG_SCSI_PM8001=y
CONFIG_SCSI_BFA_FC=y
CONFIG_SCSI_VIRTIO=y
CONFIG_SCSI_CHELSIO_FCOE=y
CONFIG_SCSI_LOWLEVEL_PCMCIA=y
CONFIG_SCSI_DH=y
CONFIG_SCSI_DH_RDAC=y
CONFIG_SCSI_DH_HP_SW=y
CONFIG_SCSI_DH_EMC=y
CONFIG_SCSI_DH_ALUA=y
CONFIG_ISCSI_TARGET=y
CONFIG_ISCSI_TARGET_CXGB4=y
CONFIG_QED_ISCSI=y
I'm expecting to see /dev/sr0. It's not there. dmesg is mute about sr0.
However, I'm able to see it using stock kernel and I've identified it was bring by BLK_DEV_SR on my target:
# ls -l /dev/sr0
brw-rw---- 1 root optical 11,0 Apr 21 15:02 /dev/sr0
# readlink /sys/dev/block/11\:0/device/driver
../../../../../../../../../../../../bus/scsi/driver/sr
I'd appreciate any help.
If your custom linux has udev, try udevadm monitor.
When you eject or insert a cd, you should see a change event on the terminal with the device path.
Also it's normally standard for a cdrom drive, no matter the actual device path, to be forwarded to /media/cdrom

Debian 9 Dummy Output after resume from suspend (snd_hda_intel codec)

I have an external monitor that I plug-in my Dell laptop after turn it on. The sound works before and after plug it in the Laptop, So the headphone works too, plugin it in and out too. The problem is when I resume Debian after suspend. The sound has gone, and some times when increasing and decreasing volume one of the three options appears in the screen: Headphone unplugged, HDMI output (or something like), or Dummy Output.
I will show now what happens when Dummy Output is displayed and some outputs of commands.
$ lspci | grep Audio
Output:
00:1f.3 Audio device: Intel Corporation Sunrise Point-LP HD Audio (rev 21)
$ lsmod | grep hda
Output:
snd_hda_ext_core 28672 1 snd_soc_skl
snd_hda_intel 36864 0
snd_hda_codec 135168 1 snd_hda_intel
snd_hda_core 90112 4 snd_hda_intel,snd_hda_codec,snd_hda_ext_core,snd_soc_skl
snd_hwdep 16384 1 snd_hda_codec
snd_pcm 110592 6 snd_hda_intel,snd_hda_codec,snd_hda_ext_core,snd_hda_core,snd_soc_skl,snd_soc_core
snd 86016 7 snd_compress,snd_hda_intel,snd_hwdep,snd_hda_codec,snd_timer,snd_soc_core,snd_pcm
$ sudo dmesg | grep snd
Output (when rebooting):
[ 13.341580] snd_hda_intel 0000:00:1f.3: bound 0000:00:02.0 (ops i915_audio_component_bind_ops [i915])
[ 13.461226] snd_hda_intel 0000:00:1f.3: CORB reset timeout#1, CORBRP = 0
[ 13.462799] snd_hda_intel 0000:00:1f.3: no codecs found!
$ sudo alsactl init
Output:
alsactl: init:1757: No soundcards found...
Complete Alsa Information script:
https://alsa-project.org/db/?f=ff03c7d8dac369fc1211822de963b337c132420c
So it looks like the sound card is there but alsa does not recognize it.
Many forums/sites recommend to blacklist snd_hda_codec_hdmi (that would be the case when the problem is with connecting/desconnecting HDMI for the external monitor), and also put a line:
options snd-hda-intel model=generic
in a file, e.g., /etc/modprobe.d/alsa-base-blacklist.conf.
But it didn't work.
Other sites suggest to disable and enable sound in BIOS. Didn't work.
Can anyone help me solve this forever issue?

Udev rule for input device

I have a camera device that has an input device listed under /dev/input. I would like to add that input device to the group plugdev.
When I plug in the camera:
[ 704.406837] input: See3CAM_CU51 as /devices/pci0000:00/0000:00:14.0/usb4/4-2/4-2:1.0/input/input21
[ 705.157657] hid-generic 0003:2560:C152.0007: hiddev0,hidraw4: USB HID v1.11 Device [e-con Systems See3CAM_CU51] on usb-0000:00:1
It's now symlinked under /dev/input/by-id
0 lrwxrwxrwx 1 root root 10 Aug 31 10:50 usb-e-con_Systems_See3CAM_CU51_172A0202-event-if00 -> ../event20
However, event20 has the following permissions:
0 crw-rw---- 1 root input 13, 84 Aug 31 10:50 event20
I've written udev rules for the hiddevice itself with success, but for some reason, I can't get the rule right for the input device. Here's what I've tried:
KERNEL=="input", ATTR{name}=="See3CAM_CU51", MODE="0666" GROUP="plugdev"
But it does not appear to work. There's not a huge deal of examples of changing the ownership of input devices out there (that I've found at least).
Update:
When I change my udev rule to
KERNEL=="input", MODE="0666" GROUP="plugdev"
that is, I leave out the device name, all my input devices in /dev/input have the correct permissions.
So basically, I'm saying "every input device gets set to mode 0666, and belong to the plugdev group", which works. But adding the ATTR{name}== breaks it.
Here's the output of udevadm info:
udevadm info -a -p /devices/pci0000:00/0000:00:14.0/usb4/4-2/4-2:1.0/input/input21
looking at device '/devices/pci0000:00/0000:00:14.0/usb4/4-2/4-2:1.0/input/input21':
KERNEL=="input21"
SUBSYSTEM=="input"
DRIVER==""
ATTR{name}=="See3CAM_CU51"
ATTR{phys}=="usb-0000:00:14.0-2/button"
ATTR{properties}=="0"
ATTR{uniq}==""
It should be working, I have the correct name set for the device, what stupid mistake am I making?
udev rules support string matching, you're probably looking for:
ACTION=="...", KERNEL=="input[0-9]*", SUBSYSTEM=="input", ...
to match on the specific action for any inputN devices, then you can add your ATTR filter(s) to select the specific device.

Disconnect and reconnect ttyUSB0 programmatically in Linux

Trying to solve this problem (ttyUSB0 that works properly than stop working after about 1hr)I'm thinking on if disconnecting and reconnecting the usb device could be a good fix.
So, it is possibile to cut down power to the USB device and repower it programmatically (bash)?
# lsusb -t
1-1:1.0: No such file or directory
/: Bus 01.Port 1: Dev 1, Class=root_hub, Driver=musb-hdrc/1p, 480M
|__ Port 1: Dev 2, If 0, Class=vend., Driver=, 12M
|__ Port 1: Dev 2, If 1, Class=vend., Driver=cp210x, 12M
On am335x, kernel 3.2.0, ubuntu core armhf.
[ 1.784332] usb 1-1: cp210x converter now attached to ttyUSB0
At the moment I need a complete power cycle to have ttyUSB0 back.
This is the solution:
Find the identity of your usb device.
# tree /sys/bus/usb/drivers/cp210x/
/sys/bus/usb/drivers/cp210x/
|-- 1-1:1.1 -> ../../../../devices/platform/omap/musb-ti81xx/musb-hdrc.1/usb1/1-1/1-1:1.1
|-- bind
|-- module -> ../../../../module/cp210x
|-- remove_id
|-- uevent
-- unbind
So 1-1:1.1 is the identifier of my ttyUSB0(it can be discovered also via dmesg).
Then, disconnect the device (as root):
# echo -n "1-1:1.1" > /sys/bus/usb/drivers/cp210x/unbind
reconnect it
# echo -n "1-1:1.1" > /sys/bus/usb/drivers/cp210x/bind
At this point I had the same device but with a different name, it was now ttyUSB1 instead of ttyUSB0.
- To avoid this I added a new rule in /etc/udev/rules.d/ by creating a new file named 99-usb-serial.rules with this line:
SUBSYSTEM=="tty", ATTRS{idVendor}=="10c4", ATTRS{idProduct}=="ea70", ATTRS{serial}=="002DCFAF", SYMLINK+="sameName", MODE:="0666"
where idVendor, idProduct and serial must be the values of your device. This rule will create a new device called sameName linked to the ttyUSB* device normally generated from the OS.
As #Robert Harvey Said,
You first need to find our driver that will help you 'unplug and plug' the usb. Type: ls /sys/bus/usb/drivers which should print something like this: btusb ftdi_sio hub usb usbfs usbhid usbserial_generic uvcvideo. These, are all the drivers for each usb device. Now, lets say mine is ftdi_sio, which is a device i use to program my arduino (atmega328p chip). I am not sure how Your/other usb devices name themselves there. Like, i dont know which of these is my mouse.
Now, you can see the driver's commands using:
ls /sys/bus/usb/drivers/ftdi_sio/, which will print something like: 1-4:1.0 bind module uevent unbind, Where 1-4:1.0 is the device's characteristic code, and the bind and unbind command, which are the 'plug' and 'unplug' command respectively.
Now, if i want to unplug programatically the ftdi usb port, i will type:
echo -n "1-4:1.0" > /sys/bus/usb/drivers/ftdi_sio/unbind
and, to plug it again:
echo -n "1-4:1.0" > /sys/bus/usb/drivers/ftdi_sio/bind
Now, we can combine all the commands together, with a ';':
echo -n "1-4:1.0" > /sys/bus/usb/drivers/ftdi_sio/unbind ; echo -n "1-4:1.0" > /sys/bus/usb/drivers/ftdi_sio/bind

bash, search for usb storage devices. output location

I am looking for a way to list any usb connected devices or removable storage media.
I will be using this list for a gtk boot media writer, so a user can easily write an iso to a usb.
This creates a perfect list of ALL partitions:
ls /dev | grep "[sh]d[a-z][1-9]"
How can I get a similar looking list that is only removable media?
On my system (Ubuntu 12.04), I can get a list of USB devices and partitions with
ls /dev/disk/by-path/*usb*
giving
/dev/disk/by-path/pci-0000:00:02.1-usb-0:1.1:1.0-scsi-0:0:0:0
/dev/disk/by-path/pci-0000:00:02.1-usb-0:1.1:1.0-scsi-0:0:0:0-part1
or partitions alone
ls /dev/disk/by-path/*usb*part*
These are symbolic links, pointing to the real device files, /dev/sdd and /dev/sdd1 for example.
I have tested this with a USB stick and an external USB hard disk only. I cannot say, whether or how this works with eSATA or Firewire disks.
Based on the answer of Olaf Dietsche, I end up with the following:
devs=`ls -al /dev/disk/by-path/*usb*part* 2>/dev/null | awk '{print($11)}'`; for dev in $devs; do dev=${dev##*\/}; echo -n "$dev ("; echo -n `mount | grep \`echo -E ${dev}\` | awk '{print($3)}'`; echo ")"; done
For me the above code is showing the usb devices and where they are mounted (between parentheses). It worked on Ubuntu 13.04 and 12.04.2, but I do not know if it will work on any other system.
Maybe you can use the output of lsusb command :
lsusb
Bus 001 Device 002: ID 8087:0020 Intel Corp. Integrated Rate Matching Hub
Bus 002 Device 002: ID 8087:0020 Intel Corp. Integrated Rate Matching Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 003: ID 0db0:3870 Micro Star International
Bus 002 Device 003: ID 0000:0000
Bus 002 Device 004: ID 14cd:6116 Super Top M6116 SATA Bridge
To get the mounted path of usb storage use
mount|grep /media|awk '{print $3}'
explanation to command
mount will print all the mounted drives and grep will display only drives mounted in /media, (considering /media is default mount point ) this output is piped to awk which will print the mounted path of usb drive
bootiso BASH utility just do that when called with -l option. Here is the output of a slightly modified bash snippet:
/dev/sdd /dev/sde
Relevant snippet:
printUSBDevices() {
typeset -a usbDevices
typeset -a devices
getDeviceType() {
typeset deviceName=/sys/block/${1#/dev/}
typeset deviceType=$(udevadm info --query=property --path="$deviceName" | grep -Po 'ID_BUS=\K\w+')
echo "$deviceType"
}
mapfile -t devices < <(lsblk -o NAME,TYPE | grep --color=never -oP '^\K\w+(?=\s+disk$)')
for device in "${devices[#]}" ; do
if [ "$(getDeviceType "/dev/$device")" == "usb" ]; then
usbDevices+=("/dev/$device")
fi
done
echo "${usbDevices[#]}"
}
printUSBDevices

Resources