diff --git a/quantum/vial.c b/quantum/vial.c index da3946662f..f12c017029 100644 --- a/quantum/vial.c +++ b/quantum/vial.c @@ -14,12 +14,15 @@ * along with this program. If not, see . */ +#include "vial.h" + #include #include "protocol/usb_descriptor.h" #include "vial_generated_keyboard_definition.h" enum { + vial_get_keyboard_id = 0x00, vial_get_size = 0x01, vial_get_def = 0x02, }; @@ -31,6 +34,17 @@ void vial_handle_cmd(uint8_t *msg, uint8_t length) { /* msg[0] is 0xFE -- prefix vial magic */ switch (msg[1]) { + /* Get keyboard ID and Vial protocol version */ + case vial_get_keyboard_id: { + uint8_t keyboard_uid[] = VIAL_KEYBOARD_UID; + + msg[0] = VIAL_PROTOCOL_VERSION & 0xFF; + msg[1] = (VIAL_PROTOCOL_VERSION >> 8) & 0xFF; + msg[2] = (VIAL_PROTOCOL_VERSION >> 16) & 0xFF; + msg[3] = (VIAL_PROTOCOL_VERSION >> 24) & 0xFF; + memcpy(&msg[4], keyboard_uid, 8); + break; + } /* Retrieve keyboard definition size */ case vial_get_size: { uint32_t sz = sizeof(keyboard_definition); diff --git a/quantum/vial.h b/quantum/vial.h index 5c79843c83..c1ff05d39a 100644 --- a/quantum/vial.h +++ b/quantum/vial.h @@ -16,4 +16,8 @@ #pragma once +#include + +#define VIAL_PROTOCOL_VERSION 0x00000000 + void vial_handle_cmd(uint8_t *data, uint8_t length); diff --git a/util/vial_generate_keyboard_uid.py b/util/vial_generate_keyboard_uid.py new file mode 100755 index 0000000000..daac8fa252 --- /dev/null +++ b/util/vial_generate_keyboard_uid.py @@ -0,0 +1,12 @@ +#!/usr/bin/env python3 +import secrets + + +def main(): + print("#define VIAL_KEYBOARD_UID {{{}}}".format( + ", ".join(["0x{:02X}".format(x) for x in secrets.token_bytes(8)]) + )) + + +if __name__ == "__main__": + main()