Merge pull request #304 from aspiers/harden

Harden device detection/setup
pull/308/head
Jesse Vincent 7 years ago committed by GitHub
commit 856b595903
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -2,14 +2,27 @@
use warnings; use warnings;
use strict; use strict;
use FindBin qw{$Bin};
die "Usage: $0 VID PID\n" unless @ARGV == 2;
my $vid = shift; my $vid = shift;
my $pid = shift; my $pid = shift;
my $prefix = '/dev/serial/by-id/'; my $prefix = '/dev/serial/by-id/';
my @paths = `ls $prefix`; my @paths = `ls $prefix`;
my %devices; my %devices;
sub debug {
print STDERR @_;
}
debug "Looking for USB device with vid=$vid and pid=$pid\n";
for my $path (@paths) { for my $path (@paths) {
chomp($path); chomp($path);
debug "Examining $path\n";
debug " not symlink\n" unless -l $prefix . $path;
next unless -l $prefix . $path; next unless -l $prefix . $path;
my @data = `udevadm info -q property --name=${prefix}${path}`; my @data = `udevadm info -q property --name=${prefix}${path}`;
for my $line (@data) { for my $line (@data) {
@ -17,15 +30,36 @@ for my $path (@paths) {
my ( $key, $val ) = split( /=/, $line, 2 ); my ( $key, $val ) = split( /=/, $line, 2 );
$devices{$path}{$key} = $val; $devices{$path}{$key} = $val;
} }
if ( ( hex $devices{$path}{'ID_VENDOR_ID'} == hex $vid ) if ( hex $devices{$path}{'ID_VENDOR_ID'} != hex $vid ) {
&& ( hex $devices{$path}{'ID_MODEL_ID'} == hex $pid ) ) debug " ID_VENDOR_ID $devices{$path}{'ID_VENDOR_ID'} != $vid\n";
{ next;
}
if ( hex $devices{$path}{'ID_MODEL_ID'} != hex $pid ) {
debug " ID_MODEL_ID $devices{$path}{'ID_MODEL_ID'} != $pid\n";
next;
}
debug " Found keyboard!\n";
if ( $devices{$path}{'ID_MM_DEVICE_IGNORE'} ) {
debug " ID_MM_DEVICE_IGNORE is set - good!\n";
}
if ( $devices{$path}{'ID_MM_CANDIDATE'}) { if ( $devices{$path}{'ID_MM_CANDIDATE'}) {
warn "Yikes. ModemManager wants to pwn your keyboard"; my $rules = "$Bin/../etc/99-kaleidoscope.rules";
debug <<EOWARN
WARNING: your udev rules are currently configured to suggest
that your keyboard is suitable for use by ModemManager. This
means that there is a risk of ModemManager interfering. To avoid
this, copy
$rules
to /etc/udev/rules.d
EOWARN
} }
print $devices{$path}{DEVNAME}; print $devices{$path}{DEVNAME};
exit(0); exit(0);
} }
}

@ -249,13 +249,47 @@ reset_device() {
} }
check_device_port () { check_device_port () {
if [ -z $DEVICE_PORT ]; then if [ -z "$DEVICE_PORT" ]; then
echo "Couldn't autodetect the keyboard's serial port." cat <<EOF >&2
echo "If you see this message and your keyboard is connected to your computer," Couldn't autodetect the keyboard's serial port.
echo "it probably means that our serial port detection logic is buggy or incomplete." If you see this message and your keyboard is connected to your computer,
echo it probably means that our serial port detection logic is buggy or incomplete.
echo "Please report this issue at https://github.com/keyboardio/Kaleidoscope";
exit 0; Please report this issue at https://github.com/keyboardio/Kaleidoscope
EOF
exit 1
elif echo "$DEVICE_PORT" | grep -q '[[:space:]]'; then
cat <<EOF >&2
Unexpected whitespace found in detected serial port:
$DEVICE_PORT
If you see this message, it means that our serial port
detection logic is buggy or incomplete.
Please report this issue at https://github.com/keyboardio/Kaleidoscope
EOF
exit 1
fi
if ! [ -w "$DEVICE_PORT" ]; then
cat <<EOF >&2
$DEVICE_PORT is not writable:
`ls -l $DEVICE_PORT`
You are currently in the following groups:
`id -Gn`
Please ensure you have followed the instructions on setting up your
account to be in the right group:
https://github.com/keyboardio/Kaleidoscope/wiki/Install-Arduino-support-on-Linux
EOF
exit 1
fi fi
} }

@ -1,4 +1,2 @@
SUBSYSTEMS=="usb", ATTRS{idVendor}=="1209", ATTRS{idProduct}=="2300", SYMLINK+="model01", ENV{ID_MM_DEVICE_IGNORE}="1" SUBSYSTEMS=="usb", ATTRS{idVendor}=="1209", ATTRS{idProduct}=="2300", SYMLINK+="model01", ENV{ID_MM_DEVICE_IGNORE}:="1", ENV{ID_MM_CANDIDATE}:="0"
SUBSYSTEMS=="usb", ATTRS{idVendor}=="1209", ATTRS{idProduct}=="2301", SYMLINK+="model01", ENV{ID_MM_DEVICE_IGNORE}="1" SUBSYSTEMS=="usb", ATTRS{idVendor}=="1209", ATTRS{idProduct}=="2301", SYMLINK+="model01", ENV{ID_MM_DEVICE_IGNORE}:="1", ENV{ID_MM_CANDIDATE}:="0"

Loading…
Cancel
Save