From 7bcae5f2d206d24ba1214b0df11d2d29a1201e48 Mon Sep 17 00:00:00 2001 From: Adam Spiers Date: Thu, 8 Mar 2018 11:26:10 +0000 Subject: [PATCH 1/5] Ensure that ModemManager ignores keyboard https://github.com/timvideos/HDMI2USB-mode-switch/blob/7bd2e9fbb732a67c8d245dd7603af1f293e174ef/udev/99-hdmi2usb-mm-blacklist.rules#L4 says: It should be enough to set ID_MM_DEVICE_IGNORE:="1" but it seems many versions of modem manager have a bug which makes them ignore that value. Setting ID_MM_CANDIDATE:="0" has the same effect but is an "internal implementation detail" of modem manager. so set both to be safe. Also use := rather than =, in order to prevent any later rules from overriding the settings. --- etc/99-kaleidoscope.rules | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/etc/99-kaleidoscope.rules b/etc/99-kaleidoscope.rules index cae399b2..c69b9053 100644 --- a/etc/99-kaleidoscope.rules +++ b/etc/99-kaleidoscope.rules @@ -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}=="2301", 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", ENV{ID_MM_CANDIDATE}:="0" From 084679d2d124088c27116083a7897852380109b5 Mon Sep 17 00:00:00 2001 From: Adam Spiers Date: Thu, 8 Mar 2018 11:39:17 +0000 Subject: [PATCH 2/5] Deal with the device port containing unexpected whitespace This should never happen, but could if something goes badly wrong in the device detection code, e.g. someone changing it in a way which caused extra output on STDOUT. --- bin/kaleidoscope-builder | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/bin/kaleidoscope-builder b/bin/kaleidoscope-builder index 4bf28ffb..8f4007bb 100755 --- a/bin/kaleidoscope-builder +++ b/bin/kaleidoscope-builder @@ -249,13 +249,27 @@ reset_device() { } check_device_port () { - if [ -z $DEVICE_PORT ]; then - echo "Couldn't autodetect the keyboard's serial port." - echo "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 - echo "Please report this issue at https://github.com/keyboardio/Kaleidoscope"; - exit 0; + if [ -z "$DEVICE_PORT" ]; then + cat <&2 +Couldn't autodetect the keyboard's serial port. +If you see this message and your keyboard is connected to your computer, +it probably means that our serial port detection logic is buggy or incomplete. + +Please report this issue at https://github.com/keyboardio/Kaleidoscope +EOF + exit 1 + elif echo "$DEVICE_PORT" | grep -q '[[:space:]]'; then + cat <&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 } From dd1aca0f13962f301d3958ecf4924c2088972e4a Mon Sep 17 00:00:00 2001 From: Adam Spiers Date: Thu, 8 Mar 2018 11:43:41 +0000 Subject: [PATCH 3/5] find-device-port-linux-udev: ensure called with correct args The VID and PID must be provided. --- bin/find-device-port-linux-udev | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bin/find-device-port-linux-udev b/bin/find-device-port-linux-udev index 79201857..704d6dec 100644 --- a/bin/find-device-port-linux-udev +++ b/bin/find-device-port-linux-udev @@ -2,6 +2,8 @@ use warnings; use strict; +die "Usage: $0 VID PID\n" unless @ARGV == 2; + my $vid = shift; my $pid = shift; my $prefix = '/dev/serial/by-id/'; From 980d703f5e37eac104f480fa599dcdfde11f67b0 Mon Sep 17 00:00:00 2001 From: Adam Spiers Date: Thu, 8 Mar 2018 11:44:44 +0000 Subject: [PATCH 4/5] make find-device-port-linux-udev more friendly Add some helpful debugging, and if there is a risk of contention with ModemManager, provide some helpful advice. --- bin/find-device-port-linux-udev | 48 +++++++++++++++++++++++++++------ 1 file changed, 40 insertions(+), 8 deletions(-) diff --git a/bin/find-device-port-linux-udev b/bin/find-device-port-linux-udev index 704d6dec..0e284c37 100644 --- a/bin/find-device-port-linux-udev +++ b/bin/find-device-port-linux-udev @@ -2,6 +2,9 @@ use warnings; use strict; + +use FindBin qw{$Bin}; + die "Usage: $0 VID PID\n" unless @ARGV == 2; my $vid = shift; @@ -10,8 +13,16 @@ my $prefix = '/dev/serial/by-id/'; my @paths = `ls $prefix`; my %devices; +sub debug { + print STDERR @_; +} + +debug "Looking for USB device with vid=$vid and pid=$pid\n"; + for my $path (@paths) { chomp($path); + debug "Examining $path\n"; + debug " not symlink\n" unless -l $prefix . $path; next unless -l $prefix . $path; my @data = `udevadm info -q property --name=${prefix}${path}`; for my $line (@data) { @@ -19,15 +30,36 @@ for my $path (@paths) { my ( $key, $val ) = split( /=/, $line, 2 ); $devices{$path}{$key} = $val; } - if ( ( hex $devices{$path}{'ID_VENDOR_ID'} == hex $vid ) - && ( hex $devices{$path}{'ID_MODEL_ID'} == hex $pid ) ) - { + if ( hex $devices{$path}{'ID_VENDOR_ID'} != hex $vid ) { + 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; + } - if ( $devices{$path}{'ID_MM_CANDIDATE'} ) { - warn "Yikes. ModemManager wants to pwn your keyboard"; - } + debug " Found keyboard!\n"; - print $devices{$path}{DEVNAME}; - exit(0); + if ( $devices{$path}{'ID_MM_DEVICE_IGNORE'} ) { + debug " ID_MM_DEVICE_IGNORE is set - good!\n"; } + + if ( $devices{$path}{'ID_MM_CANDIDATE'}) { + my $rules = "$Bin/../etc/99-kaleidoscope.rules"; + debug < Date: Thu, 8 Mar 2018 12:03:52 +0000 Subject: [PATCH 5/5] add check for DEVICE_PORT being writable If the user has missed the step about setting up their account with the right group membership, they would get a cryptic failure from stty, so catch this and explain the problem. --- bin/kaleidoscope-builder | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/bin/kaleidoscope-builder b/bin/kaleidoscope-builder index 8f4007bb..c95cfb88 100755 --- a/bin/kaleidoscope-builder +++ b/bin/kaleidoscope-builder @@ -268,6 +268,26 @@ 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 <&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