From 94b486031dc93abf05d8d1cf5a828da9b0b93d85 Mon Sep 17 00:00:00 2001 From: ndeadly <24677491+ndeadly@users.noreply.github.com> Date: Sun, 6 Dec 2020 15:54:55 +0100 Subject: [PATCH 1/3] bluetooth-mitm: fix issue checking official controller names with L and R variants --- .../btdrv_mitm/bluetooth/bluetooth_core.cpp | 6 ++-- .../source/btm_mitm/btm_mitm_service.cpp | 4 +-- .../controllers/controller_management.cpp | 28 ++++++++++++------- .../controllers/controller_management.hpp | 4 ++- .../source/controllers/switch_controller.hpp | 2 +- 5 files changed, 27 insertions(+), 17 deletions(-) diff --git a/bluetooth-mitm/source/btdrv_mitm/bluetooth/bluetooth_core.cpp b/bluetooth-mitm/source/btdrv_mitm/bluetooth/bluetooth_core.cpp index 385f5426..d0a6c8b8 100644 --- a/bluetooth-mitm/source/btdrv_mitm/bluetooth/bluetooth_core.cpp +++ b/bluetooth-mitm/source/btdrv_mitm/bluetooth/bluetooth_core.cpp @@ -83,17 +83,17 @@ namespace ams::bluetooth::core { if (program_id == ncm::SystemProgramId::Btm) { switch (g_current_event_type) { case BtdrvEventType_DeviceFound: - if (controller::IsAllowedDevice(&event_data->device_found.cod) && !controller::IsOfficialSwitchControllerName(event_data->device_found.name, sizeof(bluetooth::Name))) { + if (controller::IsAllowedDevice(&event_data->device_found.cod) && !controller::IsOfficialSwitchControllerName(event_data->device_found.name)) { std::strncpy(event_data->device_found.name, controller::pro_controller_name, sizeof(bluetooth::Name) - 1); } break; case BtdrvEventType_PinRequest: - if (!controller::IsOfficialSwitchControllerName(event_data->pin_reply.name, sizeof(bluetooth::Name))) { + if (!controller::IsOfficialSwitchControllerName(event_data->pin_reply.name)) { std::strncpy(event_data->pin_reply.name, controller::pro_controller_name, sizeof(bluetooth::Name) - 1); } break; case BtdrvEventType_SspRequest: - if (!controller::IsOfficialSwitchControllerName(event_data->ssp_reply.name, sizeof(bluetooth::Name))) { + if (!controller::IsOfficialSwitchControllerName(event_data->ssp_reply.name)) { std::strncpy(event_data->ssp_reply.name, controller::pro_controller_name, sizeof(bluetooth::Name) - 1); } break; diff --git a/bluetooth-mitm/source/btm_mitm/btm_mitm_service.cpp b/bluetooth-mitm/source/btm_mitm/btm_mitm_service.cpp index 1cb6d71b..8f2fb2ca 100644 --- a/bluetooth-mitm/source/btm_mitm/btm_mitm_service.cpp +++ b/bluetooth-mitm/source/btm_mitm/btm_mitm_service.cpp @@ -26,7 +26,7 @@ namespace ams::mitm::btm { void RenameConnectedDevices(BtmConnectedDevice devices[], size_t count) { for (unsigned int i = 0; i < count; ++i) { auto device = &devices[i]; - if (!controller::IsOfficialSwitchControllerName(device->name, sizeof(device->name))) { + if (!controller::IsOfficialSwitchControllerName(device->name)) { std::strncpy(device->name, controller::pro_controller_name, sizeof(device->name) - 1); } } @@ -68,7 +68,7 @@ namespace ams::mitm::btm { for (unsigned int i = 0; i < device_info->total_entries; ++i) { auto device = &device_info->devices[i]; - if (!controller::IsOfficialSwitchControllerName(device->name, sizeof(device->name))) { + if (!controller::IsOfficialSwitchControllerName(device->name)) { std::strncpy(device->name, controller::pro_controller_name, sizeof(device->name) - 1); } } diff --git a/bluetooth-mitm/source/controllers/controller_management.cpp b/bluetooth-mitm/source/controllers/controller_management.cpp index 25b91373..3d9abc7f 100644 --- a/bluetooth-mitm/source/controllers/controller_management.cpp +++ b/bluetooth-mitm/source/controllers/controller_management.cpp @@ -24,6 +24,16 @@ namespace ams::controller { namespace { + const std::string official_npad_names[] = { + "Joy-Con", + "Pro Controller", + "Lic Pro Controller", + "NES Controller", + "HVC Controller", + "SNES Controller", + "NintendoGamepad", + }; + constexpr auto cod_major_peripheral = 0x05; constexpr auto cod_minor_gamepad = 0x08; constexpr auto cod_minor_joystick = 0x04; @@ -40,7 +50,7 @@ namespace ams::controller { ControllerType Identify(const bluetooth::DevicesSettings *device) { - if (IsOfficialSwitchControllerName(device->name, sizeof(device->name))) + if (IsOfficialSwitchControllerName(device->name)) return ControllerType_Switch; for (auto hwId : WiiController::hardware_ids) { @@ -153,15 +163,13 @@ namespace ams::controller { (((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) { - return std::strncmp(name, "Joy-Con (L)", size) == 0 || - std::strncmp(name, "Joy-Con (R)", size) == 0 || - std::strncmp(name, "Pro Controller", size) == 0 || - std::strncmp(name, "Lic Pro Controller", size) == 0 || - std::strncmp(name, "NES Controller", size) == 0 || - std::strncmp(name, "HVC Controller", size) == 0 || - std::strncmp(name, "SNES Controller", size) == 0 || - std::strncmp(name, "NintendoGamepad", size) == 0 ; + bool IsOfficialSwitchControllerName(const std::string& name) { + for (auto n : official_npad_names) { + if (name.rfind(n, 0) == 0) + return true; + } + + return false; } void AttachHandler(const bluetooth::Address *address) { diff --git a/bluetooth-mitm/source/controllers/controller_management.hpp b/bluetooth-mitm/source/controllers/controller_management.hpp index 78448e0f..b0c90dfb 100644 --- a/bluetooth-mitm/source/controllers/controller_management.hpp +++ b/bluetooth-mitm/source/controllers/controller_management.hpp @@ -15,6 +15,8 @@ */ #pragma once #include +#include + #include "switch_controller.hpp" #include "wii_controller.hpp" #include "dualshock4_controller.hpp" @@ -71,7 +73,7 @@ namespace ams::controller { ControllerType Identify(const bluetooth::DevicesSettings *device); bool IsAllowedDevice(const bluetooth::DeviceClass *cod); - bool IsOfficialSwitchControllerName(const char *name, size_t size); + bool IsOfficialSwitchControllerName(const std::string& name); void AttachHandler(const bluetooth::Address *address); void RemoveHandler(const bluetooth::Address *address); diff --git a/bluetooth-mitm/source/controllers/switch_controller.hpp b/bluetooth-mitm/source/controllers/switch_controller.hpp index 70cd21f5..b90fed3b 100644 --- a/bluetooth-mitm/source/controllers/switch_controller.hpp +++ b/bluetooth-mitm/source/controllers/switch_controller.hpp @@ -189,7 +189,7 @@ namespace ams::controller { public: static constexpr const HardwareID hardware_ids[] = { {0x057e, 0x2006}, // Official Joycon(L) Controller - {0x057e, 0x2007}, // Official Joycon(R) Controller + {0x057e, 0x2007}, // Official Joycon(R) Controller/NES Online Controller {0x057e, 0x2009}, // Official Switch Pro Controller {0x057e, 0x2017} // Official SNES Online Controller }; From e971110fdf5fc9dcc11f69c71ff56d8bb5b554ca Mon Sep 17 00:00:00 2001 From: ndeadly <24677491+ndeadly@users.noreply.github.com> Date: Mon, 7 Dec 2020 22:47:23 +0100 Subject: [PATCH 2/3] bluetooth-mitm: fix incorrect data type in mitm of btm GetDeviceInfo --- bluetooth-mitm/source/btm_mitm/btm/btm_types.hpp | 4 ++-- bluetooth-mitm/source/btm_mitm/btm_mitm_service.cpp | 2 +- bluetooth-mitm/source/btm_mitm/btm_mitm_service.hpp | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/bluetooth-mitm/source/btm_mitm/btm/btm_types.hpp b/bluetooth-mitm/source/btm_mitm/btm/btm_types.hpp index 6fd951bd..547320ac 100644 --- a/bluetooth-mitm/source/btm_mitm/btm/btm_types.hpp +++ b/bluetooth-mitm/source/btm_mitm/btm/btm_types.hpp @@ -36,8 +36,8 @@ namespace ams::mitm::btm { BtmDeviceConditionV900 condition; }; - struct DeviceInfo : sf::LargeData { - BtmDeviceInfo info; + struct DeviceInfoList : sf::LargeData { + BtmDeviceInfoList info; }; } diff --git a/bluetooth-mitm/source/btm_mitm/btm_mitm_service.cpp b/bluetooth-mitm/source/btm_mitm/btm_mitm_service.cpp index 8f2fb2ca..6aad32c4 100644 --- a/bluetooth-mitm/source/btm_mitm/btm_mitm_service.cpp +++ b/bluetooth-mitm/source/btm_mitm/btm_mitm_service.cpp @@ -62,7 +62,7 @@ namespace ams::mitm::btm { return ams::ResultSuccess(); } - Result BtmMitmService::GetDeviceInfo(sf::Out out) { + Result BtmMitmService::GetDeviceInfo(sf::Out out) { auto device_info = reinterpret_cast(out.GetPointer()); R_TRY(btmGetDeviceInfoFwd(this->forward_service.get(), device_info)); diff --git a/bluetooth-mitm/source/btm_mitm/btm_mitm_service.hpp b/bluetooth-mitm/source/btm_mitm/btm_mitm_service.hpp index ba4ce276..68945bfc 100644 --- a/bluetooth-mitm/source/btm_mitm/btm_mitm_service.hpp +++ b/bluetooth-mitm/source/btm_mitm/btm_mitm_service.hpp @@ -27,7 +27,7 @@ namespace ams::mitm::btm { AMS_SF_METHOD_INFO(C, H, 3, Result, GetDeviceConditionDeprecated2, (sf::Out), hos::Version_5_1_0, hos::Version_7_0_1) \ AMS_SF_METHOD_INFO(C, H, 3, Result, GetDeviceConditionDeprecated3, (sf::Out), hos::Version_8_0_0, hos::Version_8_1_1) \ AMS_SF_METHOD_INFO(C, H, 3, Result, GetDeviceCondition, (sf::Out), hos::Version_9_0_0) \ - AMS_SF_METHOD_INFO(C, H, 9, Result, GetDeviceInfo, (sf::Out)) \ + AMS_SF_METHOD_INFO(C, H, 9, Result, GetDeviceInfo, (sf::Out)) \ AMS_SF_DEFINE_MITM_INTERFACE(IBtmMitmInterface, AMS_BTM_MITM_INTERFACE_INFO) @@ -48,7 +48,7 @@ namespace ams::mitm::btm { Result GetDeviceConditionDeprecated2(sf::Out out); Result GetDeviceConditionDeprecated3(sf::Out out); Result GetDeviceCondition(sf::Out out); - Result GetDeviceInfo(sf::Out out); + Result GetDeviceInfo(sf::Out out); }; static_assert(IsIBtmMitmInterface); From 42ebafced78739f4cc3f72a9435aa4c5b168efb7 Mon Sep 17 00:00:00 2001 From: ndeadly <24677491+ndeadly@users.noreply.github.com> Date: Sat, 12 Dec 2020 00:07:41 +0100 Subject: [PATCH 3/3] bluetooth-mitm: update for ams 0.16.1 (11.0.1 support) --- Atmosphere-libs | 2 +- .../btdrv_mitm/bluetooth/bluetooth_core.cpp | 32 +-- .../btdrv_mitm/bluetooth/bluetooth_hid.cpp | 36 ++-- .../bluetooth/bluetooth_hid_report.cpp | 30 +-- .../btdrv_mitm/bluetooth/bluetooth_types.hpp | 185 ++---------------- .../controllers/controller_management.cpp | 2 +- .../controllers/controller_management.hpp | 2 +- libnx | 2 +- 8 files changed, 66 insertions(+), 225 deletions(-) diff --git a/Atmosphere-libs b/Atmosphere-libs index 2c3ccef1..59b4e750 160000 --- a/Atmosphere-libs +++ b/Atmosphere-libs @@ -1 +1 @@ -Subproject commit 2c3ccef17e9b267a5d9d232f1aba689f2c591b95 +Subproject commit 59b4e75021fbaf3fcf4c0e8dd2c07e309e1869d1 diff --git a/bluetooth-mitm/source/btdrv_mitm/bluetooth/bluetooth_core.cpp b/bluetooth-mitm/source/btdrv_mitm/bluetooth/bluetooth_core.cpp index d0a6c8b8..10f56d8e 100644 --- a/bluetooth-mitm/source/btdrv_mitm/bluetooth/bluetooth_core.cpp +++ b/bluetooth-mitm/source/btdrv_mitm/bluetooth/bluetooth_core.cpp @@ -26,8 +26,8 @@ namespace ams::bluetooth::core { std::atomic g_is_initialized(false); - os::Mutex g_event_data_lock(false); - uint8_t g_event_data_buffer[0x400]; + os::Mutex g_event_info_lock(false); + uint8_t g_event_info_buffer[0x400]; BtdrvEventType g_current_event_type; os::SystemEventType g_system_event; @@ -74,27 +74,27 @@ namespace ams::bluetooth::core { } Result GetEventInfo(ncm::ProgramId program_id, EventType *type, uint8_t* buffer, size_t size) { - std::scoped_lock lk(g_event_data_lock); + std::scoped_lock lk(g_event_info_lock); *type = g_current_event_type; - std::memcpy(buffer, g_event_data_buffer, size); + std::memcpy(buffer, g_event_info_buffer, size); - auto event_data = reinterpret_cast(buffer); + auto event_info = reinterpret_cast(buffer); if (program_id == ncm::SystemProgramId::Btm) { switch (g_current_event_type) { case BtdrvEventType_DeviceFound: - if (controller::IsAllowedDevice(&event_data->device_found.cod) && !controller::IsOfficialSwitchControllerName(event_data->device_found.name)) { - std::strncpy(event_data->device_found.name, controller::pro_controller_name, sizeof(bluetooth::Name) - 1); + if (controller::IsAllowedDeviceClass(&event_info->device_found.cod) && !controller::IsOfficialSwitchControllerName(event_info->device_found.name)) { + std::strncpy(event_info->device_found.name, controller::pro_controller_name, sizeof(event_info->device_found.name) - 1); } break; case BtdrvEventType_PinRequest: - if (!controller::IsOfficialSwitchControllerName(event_data->pin_reply.name)) { - std::strncpy(event_data->pin_reply.name, controller::pro_controller_name, sizeof(bluetooth::Name) - 1); + if (!controller::IsOfficialSwitchControllerName(event_info->pin_reply.name)) { + std::strncpy(event_info->pin_reply.name, controller::pro_controller_name, sizeof(event_info->pin_reply.name) - 1); } break; case BtdrvEventType_SspRequest: - if (!controller::IsOfficialSwitchControllerName(event_data->ssp_reply.name)) { - std::strncpy(event_data->ssp_reply.name, controller::pro_controller_name, sizeof(bluetooth::Name) - 1); + if (!controller::IsOfficialSwitchControllerName(event_info->ssp_reply.name)) { + std::strncpy(event_info->ssp_reply.name, controller::pro_controller_name, sizeof(event_info->ssp_reply.name) - 1); } break; default: @@ -109,19 +109,19 @@ namespace ams::bluetooth::core { void HandleEvent(void) { { - std::scoped_lock lk(g_event_data_lock); - R_ABORT_UNLESS(btdrvGetEventInfo(g_event_data_buffer, sizeof(g_event_data_buffer), &g_current_event_type)); + std::scoped_lock lk(g_event_info_lock); + R_ABORT_UNLESS(btdrvGetEventInfo(g_event_info_buffer, sizeof(g_event_info_buffer), &g_current_event_type)); } if (!g_redirect_core_events) { if (g_current_event_type == BtdrvEventType_PinRequest) { - auto event_data = reinterpret_cast(g_event_data_buffer); + auto event_info = reinterpret_cast(g_event_info_buffer); bluetooth::PinCode pin_code = {0x30, 0x30, 0x30, 0x30}; uint8_t pin_length = sizeof(uint32_t); // Reverse host address as pin code for wii devices - if (std::strncmp(event_data->pin_reply.name, controller::wii_controller_prefix, std::strlen(controller::wii_controller_prefix)) == 0) { + if (std::strncmp(event_info->pin_reply.name, controller::wii_controller_prefix, std::strlen(controller::wii_controller_prefix)) == 0) { // Fetch host adapter properties AdapterProperty properties; R_ABORT_UNLESS(btdrvGetAdapterProperties(&properties)); @@ -131,7 +131,7 @@ namespace ams::bluetooth::core { } // Fuck BTM, we're sending the pin response ourselves if it won't. - R_ABORT_UNLESS(btdrvRespondToPinRequest(event_data->pin_reply.address, false, &pin_code, pin_length)); + R_ABORT_UNLESS(btdrvRespondToPinRequest(event_info->pin_reply.address, false, &pin_code, pin_length)); } else { os::SignalSystemEvent(&g_system_event_fwd); diff --git a/bluetooth-mitm/source/btdrv_mitm/bluetooth/bluetooth_hid.cpp b/bluetooth-mitm/source/btdrv_mitm/bluetooth/bluetooth_hid.cpp index 0fed4f96..8f483144 100644 --- a/bluetooth-mitm/source/btdrv_mitm/bluetooth/bluetooth_hid.cpp +++ b/bluetooth-mitm/source/btdrv_mitm/bluetooth/bluetooth_hid.cpp @@ -26,8 +26,8 @@ namespace ams::bluetooth::hid { std::atomic g_is_initialized(false); - os::Mutex g_event_data_lock(false); - uint8_t g_event_data_buffer[0x480]; + os::Mutex g_event_info_lock(false); + uint8_t g_event_info_buffer[0x480]; HidEventType g_current_event_type; os::SystemEventType g_system_event; @@ -74,52 +74,52 @@ namespace ams::bluetooth::hid { } Result GetEventInfo(ncm::ProgramId program_id, HidEventType *type, uint8_t* buffer, size_t size) { - std::scoped_lock lk(g_event_data_lock); + std::scoped_lock lk(g_event_info_lock); *type = g_current_event_type; - std::memcpy(buffer, g_event_data_buffer, size); + std::memcpy(buffer, g_event_info_buffer, size); os::SignalEvent(&g_data_read_event); return ams::ResultSuccess(); } - void handleConnectionStateEvent(HidEventData *event_data) { - switch (event_data->connection_state.state) { - case BluetoothHidConnectionState_Connected: - controller::AttachHandler(&event_data->connection_state.address); + void handleConnectionStateEvent(bluetooth::HidEventInfo *event_info) { + switch (event_info->connection_state.state) { + case BtdrvHidConnectionState_Connected: + controller::AttachHandler(&event_info->connection_state.address); break; - case BluetoothHidConnectionState_Disconnected: - controller::RemoveHandler(&event_data->connection_state.address); + case BtdrvHidConnectionState_Disconnected: + controller::RemoveHandler(&event_info->connection_state.address); break; default: break; } } - void handleUnknown07Event(HidEventData *event_data) { + void handleUnknown07Event(bluetooth::HidEventInfo *event_info) { // Fix for xbox one disconnection. Don't know what this value is for, but it appears to be 0 for other controllers if (hos::GetVersion() < hos::Version_9_0_0) - event_data->unknown07._unk1 = 0; + event_info->type7.v1.unk_xC = 0; else - event_data->unknown07.v2._unk1 = 0; + event_info->type7.v9.unk_x4 = 0; } void HandleEvent(void) { { - std::scoped_lock lk(g_event_data_lock); - R_ABORT_UNLESS(btdrvGetHidEventInfo(g_event_data_buffer, sizeof(g_event_data_buffer), &g_current_event_type)); + std::scoped_lock lk(g_event_info_lock); + R_ABORT_UNLESS(btdrvGetHidEventInfo(g_event_info_buffer, sizeof(g_event_info_buffer), &g_current_event_type)); } - auto event_data = reinterpret_cast(g_event_data_buffer); + auto event_info = reinterpret_cast(g_event_info_buffer); switch (g_current_event_type) { case BtdrvHidEventType_ConnectionState: - handleConnectionStateEvent(event_data); + handleConnectionStateEvent(event_info); break; case BtdrvHidEventType_Unknown7: - handleUnknown07Event(event_data); + handleUnknown07Event(event_info); break; default: break; diff --git a/bluetooth-mitm/source/btdrv_mitm/bluetooth/bluetooth_hid_report.cpp b/bluetooth-mitm/source/btdrv_mitm/bluetooth/bluetooth_hid_report.cpp index 93f01d2c..5f2ea297 100644 --- a/bluetooth-mitm/source/btdrv_mitm/bluetooth/bluetooth_hid_report.cpp +++ b/bluetooth-mitm/source/btdrv_mitm/bluetooth/bluetooth_hid_report.cpp @@ -36,7 +36,7 @@ namespace ams::bluetooth::hid::report { s32 g_event_handler_thread_priority = mitm::utils::ConvertToUserPriority(17); // This is only required on fw < 7.0.0 - uint8_t g_event_data_buffer[0x480]; + uint8_t g_event_info_buffer[0x480]; bluetooth::HidEventType g_current_event_type; os::SystemEventType g_system_event; @@ -145,11 +145,11 @@ namespace ams::bluetooth::hid::report { Result WriteHidReportBuffer(const bluetooth::Address *address, const bluetooth::HidReport *report) { if (hos::GetVersion() < hos::Version_9_0_0) { - g_fake_report_data.size = g_fake_report_data.report.size + 0x11; - std::memcpy(&g_fake_report_data.address, address, sizeof(bluetooth::Address)); + g_fake_report_data.v1.size = g_fake_report_data.report.size + 0x11; + std::memcpy(&g_fake_report_data.v1.address, address, sizeof(bluetooth::Address)); } else { - std::memcpy(&g_fake_report_data.v2.address, address, sizeof(bluetooth::Address)); + std::memcpy(&g_fake_report_data.v9.address, address, sizeof(bluetooth::Address)); } std::memcpy(&g_fake_report_data.report, report, report->size + sizeof(report->size)); @@ -182,14 +182,14 @@ namespace ams::bluetooth::hid::report { continue; } else { - auto event_data = reinterpret_cast(buffer); + auto event_info = reinterpret_cast(buffer); *type = static_cast(packet->header.type); - std::memcpy(&event_data->get_report.address, &packet->data.address, sizeof(bluetooth::Address)); - event_data->get_report.status = BluetoothHidStatus_Ok; - event_data->get_report.report_length = packet->header.size; + std::memcpy(&event_info->get_report.address, &packet->data.v1.address, sizeof(bluetooth::Address)); + event_info->get_report.status = BtdrvHidStatus_Ok; + event_info->get_report.report_length = packet->header.size; - std::memcpy(&event_data->get_report.report_data, &packet->data, packet->header.size); + std::memcpy(&event_info->get_report.report_data, &packet->data, packet->header.size); break; } } @@ -200,21 +200,21 @@ namespace ams::bluetooth::hid::report { void HandleEvent(void) { if (!g_redirect_hid_report_events) { if (hos::GetVersion() < hos::Version_7_0_0) { - auto event_data = reinterpret_cast(g_event_data_buffer); - R_ABORT_UNLESS(btdrvGetHidReportEventInfo(g_event_data_buffer, sizeof(g_event_data_buffer), &g_current_event_type)); + auto event_info = reinterpret_cast(g_event_info_buffer); + R_ABORT_UNLESS(btdrvGetHidReportEventInfo(g_event_info_buffer, sizeof(g_event_info_buffer), &g_current_event_type)); switch (g_current_event_type) { case BtdrvHidEventType_GetReport: { - auto device = controller::LocateHandler(&event_data->get_report.address); + auto device = controller::LocateHandler(&event_info->get_report.address); if (!device) return; - device->HandleIncomingReport(&event_data->get_report.report_data.report); + device->HandleIncomingReport(&event_info->get_report.report_data.report); } break; default: - g_fake_buffer->Write(g_current_event_type, &event_data->get_report.report_data, event_data->get_report.report_length); + g_fake_buffer->Write(g_current_event_type, &event_info->get_report.report_data, event_info->get_report.report_length); break; } } @@ -231,7 +231,7 @@ namespace ams::bluetooth::hid::report { continue; case BtdrvHidEventType_GetReport: { - auto device = controller::LocateHandler(hos::GetVersion() < hos::Version_9_0_0 ? &real_packet->data.address : &real_packet->data.v2.address); + auto device = controller::LocateHandler(hos::GetVersion() < hos::Version_9_0_0 ? &real_packet->data.v1.address : &real_packet->data.v9.address); if (!device) continue; diff --git a/bluetooth-mitm/source/btdrv_mitm/bluetooth/bluetooth_types.hpp b/bluetooth-mitm/source/btdrv_mitm/bluetooth/bluetooth_types.hpp index 3f39bd6f..754d27e6 100644 --- a/bluetooth-mitm/source/btdrv_mitm/bluetooth/bluetooth_types.hpp +++ b/bluetooth-mitm/source/btdrv_mitm/bluetooth/bluetooth_types.hpp @@ -19,187 +19,28 @@ namespace ams::bluetooth { - typedef char Name[0xf9]; typedef BtdrvAddress Address; + typedef BtdrvDeviceClass DeviceClass; typedef BtdrvBluetoothPinCode PinCode; typedef BtdrvAdapterProperty AdapterProperty; typedef BtdrvHidReport HidReport; typedef BtdrvBluetoothHhReportType HhReportType; typedef SetSysBluetoothDevicesSettings DevicesSettings; + typedef BtdrvBluetoothSspVariant SspVariant; + typedef BtdrvBluetoothTransport Transport; + typedef BtdrvBluetoothDiscoveryState DiscoveryState; + typedef BtdrvBluetoothBondState BondState; typedef BtdrvEventType EventType; - typedef BtdrvHidEventType HidEventType; - typedef BtdrvBleEventType BleEventType; - - struct DeviceClass { - u8 cod[0x3]; - }; - - struct HidReportData { - union { - // Pre 9.0.0 - struct { - u16 size; - u8 _unk0; - Address address; - u8 _unk1[3]; - }; - // 9.0.0+ - struct { - u8 _unk0[5]; - Address address; - u8 _unk1; - } v2; - }; - - HidReport report; - }; - - enum SspVariant { - BluetoothSspVariant_PasskeyConfirmation, - BluetoothSspVariant_PasskeyEntry, - BluetoothSspVariant_Consent, - BluetoothSspVariant_PasskeyNotification - }; - - enum Transport { - BluetoothTransport_Auto, - BluetoothTransport_BREDR, - BluetoothTransport_LE - }; - - enum DiscoveryState { - BluetoothDiscoveryState_Stopped, - BluetoothDiscoveryState_Started - }; - - enum BondState { - BluetoothBondState_None, - BluetoothBondState_Bonding, - BluetoothBondState_Bonded - }; - - enum Status { - BluetoothStatus_Success, - BluetoothStatus_Fail, - BluetoothStatus_NotReady, - BluetoothStatus_NoMemory, - BluetoothStatus_Busy, - BluetoothStatus_Done, - BluetoothStatus_Unsupported, - BluetoothStatus_ParameterInvalid, - BluetoothStatus_Unhandled, - BluetoothStatus_AuthenticationFailure, - BluetoothStatus_RemoteDeviceDown, - BluetoothStatus_AuthenticationRejected, - BluetoothStatus_JniEnvironmentError, - BluetoothStatus_JniThreadAttachError, - BluetoothStatus_WakelockError - }; + typedef BtdrvEventInfo EventInfo; - enum HidConnectionState { - BluetoothHidConnectionState_Connected = 0, - BluetoothHidConnectionState_Connecting, - BluetoothHidConnectionState_Disconnected, - BluetoothHidConnectionState_Disconnecting, - BluetoothHidConnectionState_FailedMouseFromHost, - BluetoothHidConnectionState_FailedKeyboardFromHost, - BluetoothHidConnectionState_FailedTooManyDevices, - BluetoothHidConnectionState_FailedNoBluetoothHidDriver, - BluetoothHidConnectionState_FailedGeneric, - BluetoothHidConnectionState_Unknown - }; - - enum HidStatus { - BluetoothHidStatus_Ok = 0, - BluetoothHidStatus_HandshakeHidNotReady, - BluetoothHidStatus_HandshakeInvalidReportId, - BluetoothHidStatus_HandshakeTransactionNotSpt, - BluetoothHidStatus_HandshakeInvalidParameter, - BluetoothHidStatus_HandshakeError, - BluetoothHidStatus_Error, - BluetoothHidStatus_ErrorSdp, - BluetoothHidStatus_ErrorProtocol, - BluetoothHidStatus_ErrorDatabaseFull, - BluetoothHidStatus_ErrorDeviceTypeUnsupported, - BluetoothHidStatus_ErrorNoResources, - BluetoothHidStatus_ErrorAuthenicationFailed, - BluetoothHidStatus_ErrorHdl - }; - - union EventData { - u8 raw[0x480]; - - struct __attribute__ ((__packed__)) { - Name name; - Address address; - u8 uuid[0x10]; - DeviceClass cod; - /* + more items we don't care about */ - u8 _unk0; - u8 _unk1[0x252]; - u32 _unk2; - } device_found; - - struct { - DiscoveryState state; - } discovery_state; - - struct { - Address address; - Name name; - DeviceClass cod; - } pin_reply; - - struct { - Address address; - Name name; - DeviceClass cod; - SspVariant variant; - u32 passkey; - } ssp_reply; - - union { - struct { - Address address; - Status status; - BondState state; - }; - struct { - Status status; - Address address; - BondState state; - } v2; - } bond_state; - }; - - union HidEventData { - u8 raw[0x480]; - - struct { - Address address; - HidConnectionState state; - } connection_state; - - struct { - Address address; - HidStatus status; - u32 report_length; - HidReportData report_data; - } get_report; + typedef BtdrvHidEventType HidEventType; + typedef BtdrvHidEventInfo HidEventInfo; - union { - struct { - Address address; - u32 _unk0; - u32 _unk1; - }; - struct { - u32 _unk0; - u32 _unk1; - Address address; - } v2; - } unknown07; - }; + typedef BtdrvBleEventType BleEventType; + typedef BtdrvBleEventInfo BleEventInfo; + typedef BtdrvHidConnectionState HidConnectionState; + typedef BtdrvHidReportData HidReportData; + } diff --git a/bluetooth-mitm/source/controllers/controller_management.cpp b/bluetooth-mitm/source/controllers/controller_management.cpp index 3d9abc7f..6d039ad0 100644 --- a/bluetooth-mitm/source/controllers/controller_management.cpp +++ b/bluetooth-mitm/source/controllers/controller_management.cpp @@ -158,7 +158,7 @@ namespace ams::controller { return ControllerType_Unknown; } - bool IsAllowedDevice(const bluetooth::DeviceClass *cod) { + bool IsAllowedDeviceClass(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] & 0x40) == cod_minor_keyboard)); } diff --git a/bluetooth-mitm/source/controllers/controller_management.hpp b/bluetooth-mitm/source/controllers/controller_management.hpp index b0c90dfb..b0232424 100644 --- a/bluetooth-mitm/source/controllers/controller_management.hpp +++ b/bluetooth-mitm/source/controllers/controller_management.hpp @@ -72,7 +72,7 @@ namespace ams::controller { }; ControllerType Identify(const bluetooth::DevicesSettings *device); - bool IsAllowedDevice(const bluetooth::DeviceClass *cod); + bool IsAllowedDeviceClass(const bluetooth::DeviceClass *cod); bool IsOfficialSwitchControllerName(const std::string& name); void AttachHandler(const bluetooth::Address *address); diff --git a/libnx b/libnx index 9d939bcd..be5801d3 160000 --- a/libnx +++ b/libnx @@ -1 +1 @@ -Subproject commit 9d939bcd7e821cef3cb8ef2529b409252b883041 +Subproject commit be5801d3d67bc6e823e5d5a8e2582ed9e4f0ec22