From 2798d055648340d65c3220fdea39f63c294b4faa Mon Sep 17 00:00:00 2001 From: ndeadly <24677491+ndeadly@users.noreply.github.com> Date: Sun, 20 Sep 2020 19:55:42 +0200 Subject: [PATCH] bluetooth-mitm: rename IsGamepad function to IsAllowedDevice and add keyboard device class to allowed devices --- .../source/btdrv_mitm/bluetooth/bluetooth_core.cpp | 2 +- bluetooth-mitm/source/controllers/controller_management.cpp | 5 +++-- bluetooth-mitm/source/controllers/controller_management.hpp | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/bluetooth-mitm/source/btdrv_mitm/bluetooth/bluetooth_core.cpp b/bluetooth-mitm/source/btdrv_mitm/bluetooth/bluetooth_core.cpp index 5dfd003..5d727d2 100644 --- a/bluetooth-mitm/source/btdrv_mitm/bluetooth/bluetooth_core.cpp +++ b/bluetooth-mitm/source/btdrv_mitm/bluetooth/bluetooth_core.cpp @@ -84,7 +84,7 @@ namespace ams::bluetooth::core { if (program_id == ncm::SystemProgramId::Btm) { switch (g_current_event_type) { case BluetoothEvent_DeviceFound: - if (controller::IsGamepad(&event_data->deviceFound.cod) && !controller::IsOfficialSwitchControllerName(event_data->deviceFound.name, sizeof(BluetoothName))) { + if (controller::IsAllowedDevice(&event_data->deviceFound.cod) && !controller::IsOfficialSwitchControllerName(event_data->deviceFound.name, sizeof(BluetoothName))) { std::strncpy(event_data->deviceFound.name, controller::pro_controller_name, sizeof(BluetoothName) - 1); } break; diff --git a/bluetooth-mitm/source/controllers/controller_management.cpp b/bluetooth-mitm/source/controllers/controller_management.cpp index 788588a..a07f16e 100644 --- a/bluetooth-mitm/source/controllers/controller_management.cpp +++ b/bluetooth-mitm/source/controllers/controller_management.cpp @@ -28,6 +28,7 @@ namespace ams::controller { constexpr auto cod_major_peripheral = 0x05; constexpr auto cod_minor_gamepad = 0x08; constexpr auto cod_minor_joystick = 0x04; + constexpr auto cod_minor_keyboard = 0x40; os::Mutex g_controller_lock(false); std::vector> g_controllers; @@ -118,9 +119,9 @@ namespace ams::controller { return ControllerType_Unknown; } - bool IsGamepad(const bluetooth::DeviceClass *cod) { + bool IsAllowedDevice(const bluetooth::DeviceClass *cod) { return ((cod->cod[1] & 0x0f) == cod_major_peripheral) && - (((cod->cod[2] & 0x0f) == cod_minor_gamepad) || ((cod->cod[2] & 0x0f) == cod_minor_joystick)); + (((cod->cod[2] & 0x0f) == cod_minor_gamepad) || ((cod->cod[2] & 0x0f) == cod_minor_joystick) || ((cod->cod[2] & 0x40) == cod_minor_keyboard)); } bool IsOfficialSwitchControllerName(const char *name, size_t size) { diff --git a/bluetooth-mitm/source/controllers/controller_management.hpp b/bluetooth-mitm/source/controllers/controller_management.hpp index e5a5f30..6530f0e 100644 --- a/bluetooth-mitm/source/controllers/controller_management.hpp +++ b/bluetooth-mitm/source/controllers/controller_management.hpp @@ -54,7 +54,7 @@ namespace ams::controller { }; ControllerType Identify(const BluetoothDevicesSettings *device); - bool IsGamepad(const bluetooth::DeviceClass *cod); + bool IsAllowedDevice(const bluetooth::DeviceClass *cod); bool IsOfficialSwitchControllerName(const char *name, size_t size); void AttachHandler(const bluetooth::Address *address);