Skip to content

Commit

Permalink
Add getusbprinterid script
Browse files Browse the repository at this point in the history
Add getusbprinterid script (based on the getusbprinterid.pl script described in
https://github.com/OpenPrinting/foomatic-db/blob/master/README).
  • Loading branch information
Andreas Gruenbacher authored and philpem committed May 21, 2020
1 parent 6e15f4b commit 41df68c
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions getusbprinterid
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/perl

# len = 1024
# LPIOC_GET_DEVICE_ID(len) = _IOC(_IOC_READ, 'P', IOCNR_GET_DEVICE_ID, len)
# _IOC(), _IOC_READ as defined in /usr/include/asm/ioctl.h
$LPIOC_GET_DEVICE_ID = 0x84005001;
$LPIOC_GET_VID_PID = 0x84005006;

open FILE, "$ARGV[0]" or die "cannot open $ARGV[0]";

my $result;
ioctl(FILE, $LPIOC_GET_DEVICE_ID , $result) or die;
# Cut resulting string to its real length
my $length = ord(substr($result, 1, 1)) + (ord(substr($result, 0, 1)) << 8);
$result = substr($result, 2, $length-2);
# Remove non-printable characters
$result =~ tr/[\x0-\x1f]/\./;
print "DeviceID $result\n";

$result = pack("LL",0);
ioctl(FILE, $LPIOC_GET_VID_PID, $result) or die;
my( $v1, $v2 ) = unpack("LL", $result );
print "Vendor '$v1', Product '$v2'\n";

close FILE;

0 comments on commit 41df68c

Please sign in to comment.