aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Challis <git@zvecr.com>2019-11-25 20:33:02 +0000
committerGitHub <noreply@github.com>2019-11-25 20:33:02 +0000
commitf0f161e5724375b7a289699703d86d6de2adae8d (patch)
tree2560653fc37df8ee0210e3bb3414628ba74b28ef
parent3a7085dee4389bfc3356336180b44d294cf0738a (diff)
downloadqmk_firmware-f0f161e5724375b7a289699703d86d6de2adae8d.tar.gz
qmk_firmware-f0f161e5724375b7a289699703d86d6de2adae8d.zip
Remove vusb 'reset to bootloader' hid message due to security implications (#7456)
-rw-r--r--tmk_core/protocol/vusb/vusb.c13
-rwxr-xr-xutil/atmega32a_program.py110
2 files changed, 1 insertions, 122 deletions
diff --git a/tmk_core/protocol/vusb/vusb.c b/tmk_core/protocol/vusb/vusb.c
index 72445e00b..e66938445 100644
--- a/tmk_core/protocol/vusb/vusb.c
+++ b/tmk_core/protocol/vusb/vusb.c
@@ -26,7 +26,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
26#include "debug.h" 26#include "debug.h"
27#include "host_driver.h" 27#include "host_driver.h"
28#include "vusb.h" 28#include "vusb.h"
29#include "bootloader.h"
30#include <util/delay.h> 29#include <util/delay.h>
31 30
32static uint8_t vusb_keyboard_leds = 0; 31static uint8_t vusb_keyboard_leds = 0;
@@ -145,7 +144,7 @@ static void send_consumer(uint16_t data) {
145 *------------------------------------------------------------------*/ 144 *------------------------------------------------------------------*/
146static struct { 145static struct {
147 uint16_t len; 146 uint16_t len;
148 enum { NONE, BOOTLOADER, SET_LED } kind; 147 enum { NONE, SET_LED } kind;
149} last_req; 148} last_req;
150 149
151usbMsgLen_t usbFunctionSetup(uchar data[8]) { 150usbMsgLen_t usbFunctionSetup(uchar data[8]) {
@@ -173,11 +172,6 @@ usbMsgLen_t usbFunctionSetup(uchar data[8]) {
173 debug("SET_LED: "); 172 debug("SET_LED: ");
174 last_req.kind = SET_LED; 173 last_req.kind = SET_LED;
175 last_req.len = rq->wLength.word; 174 last_req.len = rq->wLength.word;
176#ifdef BOOTLOADER_SIZE
177 } else if (rq->wValue.word == 0x0301) {
178 last_req.kind = BOOTLOADER;
179 last_req.len = rq->wLength.word;
180#endif
181 } 175 }
182 return USB_NO_MSG; // to get data in usbFunctionWrite 176 return USB_NO_MSG; // to get data in usbFunctionWrite
183 } else { 177 } else {
@@ -204,11 +198,6 @@ uchar usbFunctionWrite(uchar *data, uchar len) {
204 last_req.len = 0; 198 last_req.len = 0;
205 return 1; 199 return 1;
206 break; 200 break;
207 case BOOTLOADER:
208 usbDeviceDisconnect();
209 bootloader_jump();
210 return 1;
211 break;
212 case NONE: 201 case NONE:
213 default: 202 default:
214 return -1; 203 return -1;
diff --git a/util/atmega32a_program.py b/util/atmega32a_program.py
deleted file mode 100755
index 9438c7e77..000000000
--- a/util/atmega32a_program.py
+++ /dev/null
@@ -1,110 +0,0 @@
1#!/usr/bin/env python
2# Copyright 2017 Luiz Ribeiro <luizribeiro@gmail.com>, Sebastian Kaim <sebb@sebb767.de>
3#
4# This program is free software: you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
6# the Free Software Foundation, either version 2 of the License, or
7# (at your option) any later version.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17from __future__ import print_function
18
19import os
20import sys
21import time
22import argparse
23import usb
24
25
26def check_keyboard_normal_mode(vendor, product):
27 """Returns a device if a ps2avrGB device in normal made (that is in keyboard mode) or None if it is not found."""
28 return usb.core.find(idVendor=vendor, idProduct=product)
29
30def check_keyboard_bootloader_mode():
31 """Returns True if a ps2avrGB device in bootloader (flashable) mode is found and False otherwise."""
32 return (usb.core.find(idVendor=0x16c0, idProduct=0x05df) is not None)
33
34def flash_keyboard(firmware_file):
35 """Calls bootloadHID to flash the given file to the device."""
36 print('Flashing firmware to device ...')
37 if os.system('bootloadHID -r "%s"' % firmware_file) == 0:
38 print('\nDone!')
39 else:
40 print('\nbootloadHID returned an error.')
41
42def print_device_info(dev):
43 """Prints all infos for a given USB device"""
44 print('Device Information:')
45 print(' idVendor: %d (0x%04x)' % (dev.idVendor, dev.idVendor))
46 print(' idProduct: %d (0x%04x)' % (dev.idProduct, dev.idProduct))
47 print('Manufacturer: %s' % (dev.iManufacturer))
48 print('Serial: %s' % (dev.iSerialNumber))
49 print('Product: %s' % (dev.iProduct), end='\n\n')
50
51def send_device_to_bootloader_mode(dev):
52 """Tries to send a given ps2avrGB keyboard to bootloader mode to allow flashing."""
53 try:
54 dev.set_configuration()
55
56 request_type = usb.util.build_request_type(
57 usb.util.CTRL_OUT,
58 usb.util.CTRL_TYPE_CLASS,
59 usb.util.CTRL_RECIPIENT_DEVICE)
60
61 USBRQ_HID_SET_REPORT = 0x09
62 HID_REPORT_OPTION = 0x0301
63
64 dev.ctrl_transfer(request_type, USBRQ_HID_SET_REPORT, HID_REPORT_OPTION, 0, [0, 0, 0xFF] + [0] * 5)
65 except usb.core.USBError:
66 # for some reason I keep getting USBError, but it works!
67 pass
68
69def auto_int(value):
70 """Helper for argparse to enable auto base detection"""
71 return int(value, 0)
72
73parser = argparse.ArgumentParser(description='Flash bootloadHID device')
74parser.add_argument('--vendor', type=auto_int, default=0x20A0, help='Non bootloader idVendor to search for (default: 0x%(default)04x)')
75parser.add_argument('--product', type=auto_int, default=0x422D, help='Non bootloader idProduct to search for (default: 0x%(default)04x)')
76parser.add_argument('firmware_hex', type=argparse.FileType('r'), help='Firmware hex file to flash')
77args = parser.parse_args()
78
79kb = check_keyboard_normal_mode(args.vendor, args.product)
80
81if kb is not None:
82 print('Found a keyboard in normal mode. Attempting to send it to bootloader mode ...', end='')
83 send_device_to_bootloader_mode(kb)
84 print(' done.')
85 print("Hint: If your keyboard can't be set to bootloader mode automatically, plug it in while pressing the bootloader key to do so manually.")
86 print(" You can find more infos about this here: https://github.com/qmk/qmk_firmware/tree/master/keyboards/ps2avrGB#setting-the-board-to-bootloader-mode")
87
88attempts = 12 # 60 seconds
89found = False
90for attempt in range(1, attempts + 1):
91 print("Searching for keyboard in bootloader mode (%i/%i) ... " % (attempt, attempts), end='')
92
93 if check_keyboard_bootloader_mode():
94 print('Found', end='\n\n')
95 flash_keyboard(args.firmware_hex.name)
96 found = True
97 break
98 else:
99 print('Nothing.', end='')
100
101 if attempt != attempts: # no need to wait on the last attempt
102 print(' Sleeping 5 seconds.', end='')
103 time.sleep(5)
104
105 # print a newline
106 print()
107
108if not found:
109 print("Couldn't find a flashable keyboard. Aborting.")
110 sys.exit(2)