Adapt code for libnx 12.x.x support

This commit is contained in:
ndeadly 2021-05-17 19:46:50 +02:00
parent aa48059df5
commit e32438c9a1
7 changed files with 61 additions and 29 deletions

@ -1 +1 @@
Subproject commit 4d2e16fc336974c2be44a45e1cb549851ed901bc
Subproject commit 089e09de0fd7ce470cb6a1075c650a0d7b58b34f

View file

@ -78,17 +78,17 @@ namespace ams::bluetooth::core {
inline void ModifyEventInfov1(bluetooth::EventInfo *event_info, BtdrvEventType event_type) {
switch (event_type) {
case BtdrvEventType_InquiryDevice:
case BtdrvEventTypeOld_InquiryDevice:
if (controller::IsAllowedDeviceClass(&event_info->inquiry_device.v1.class_of_device) && !controller::IsOfficialSwitchControllerName(event_info->inquiry_device.v1.name)) {
std::strncpy(event_info->inquiry_device.v1.name, controller::pro_controller_name, sizeof(event_info->inquiry_device.v1.name) - 1);
}
break;
case BtdrvEventType_PairingPinCodeRequest:
case BtdrvEventTypeOld_PairingPinCodeRequest:
if (!controller::IsOfficialSwitchControllerName(event_info->pairing_pin_code_request.name)) {
std::strncpy(event_info->pairing_pin_code_request.name, controller::pro_controller_name, sizeof(event_info->pairing_pin_code_request.name) - 1);
}
break;
case BtdrvEventType_SspRequest:
case BtdrvEventTypeOld_SspRequest:
if (!controller::IsOfficialSwitchControllerName(event_info->ssp_request.v1.name)) {
std::strncpy(event_info->ssp_request.v1.name, controller::pro_controller_name, sizeof(event_info->ssp_request.v1.name) - 1);
}
@ -98,19 +98,19 @@ namespace ams::bluetooth::core {
}
}
inline void ModifyEventInfov12(bluetooth::EventInfo *event_info, BtdrvEventTypeV12 event_type) {
inline void ModifyEventInfov12(bluetooth::EventInfo *event_info, BtdrvEventType event_type) {
switch (event_type) {
case BtdrvEventTypeV12_InquiryDevice:
case BtdrvEventType_InquiryDevice:
if (controller::IsAllowedDeviceClass(&event_info->inquiry_device.v12.class_of_device) && !controller::IsOfficialSwitchControllerName(event_info->inquiry_device.v12.name)) {
std::strncpy(event_info->inquiry_device.v12.name, controller::pro_controller_name, sizeof(event_info->inquiry_device.v12.name) - 1);
}
break;
case BtdrvEventTypeV12_PairingPinCodeRequest:
case BtdrvEventType_PairingPinCodeRequest:
if (!controller::IsOfficialSwitchControllerName(event_info->pairing_pin_code_request.name)) {
std::strncpy(event_info->pairing_pin_code_request.name, controller::pro_controller_name, sizeof(event_info->pairing_pin_code_request.name) - 1);
}
break;
case BtdrvEventTypeV12_SspRequest:
case BtdrvEventType_SspRequest:
if (!controller::IsOfficialSwitchControllerName(event_info->ssp_request.v12.name)) {
std::strncpy(event_info->ssp_request.v12.name, controller::pro_controller_name, sizeof(event_info->ssp_request.v12.name) - 1);
}
@ -132,7 +132,7 @@ namespace ams::bluetooth::core {
if (hos::GetVersion() < hos::Version_12_0_0)
ModifyEventInfov1(event_info, g_current_event_type);
else
ModifyEventInfov12(event_info, static_cast<BtdrvEventTypeV12>(g_current_event_type));
ModifyEventInfov12(event_info, g_current_event_type);
}
g_data_read_event.Signal();
@ -149,17 +149,31 @@ namespace ams::bluetooth::core {
if (std::strncmp(g_event_info.pairing_pin_code_request.name, controller::wii_controller_prefix, std::strlen(controller::wii_controller_prefix)) == 0) {
// Fetch host adapter address
bluetooth::Address host_address;
R_ABORT_UNLESS(btdrvGetAdapterProperty(BtdrvBluetoothPropertyType_Address, &host_address, sizeof(bluetooth::Address)));
R_ABORT_UNLESS(btdrvLegacyGetAdapterProperty(BtdrvBluetoothPropertyType_Address, &host_address, sizeof(bluetooth::Address)));
// Reverse host address
*reinterpret_cast<uint64_t *>(&pin) = util::SwapBytes(*reinterpret_cast<uint64_t *>(&host_address)) >> 16;
pin_length = sizeof(bluetooth::Address);
}
R_ABORT_UNLESS(btdrvRespondToPinRequest(g_event_info.pairing_pin_code_request.addr, false, &pin, pin_length));
R_ABORT_UNLESS(btdrvLegacyRespondToPinRequest(g_event_info.pairing_pin_code_request.addr, false, &pin, pin_length));
}
inline void HandlePinCodeRequestEventV12(bluetooth::EventInfo *event_info) {
// Todo: implement pin sending for 12.0.0
// Default pin used by bluetooth service
BtdrvPinCode pin = {"0000", 4};
// Reverse host address as pin code for wii devices
if (std::strncmp(g_event_info.pairing_pin_code_request.name, controller::wii_controller_prefix, std::strlen(controller::wii_controller_prefix)) == 0) {
// Fetch host adapter address
BtdrvAdapterProperty property;
R_ABORT_UNLESS(btdrvGetAdapterProperty(BtdrvAdapterPropertyType_Address, &property));
// Reverse host address
bluetooth::Address host_address = *reinterpret_cast<bluetooth::Address *>(property.data);
*reinterpret_cast<uint64_t *>(&pin.code) = util::SwapBytes(*reinterpret_cast<uint64_t *>(&host_address)) >> 16;
pin.length = sizeof(bluetooth::Address);
}
R_ABORT_UNLESS(btdrvRespondToPinRequest(g_event_info.pairing_pin_code_request.addr, &pin));
}
void HandleEvent(void) {
@ -169,10 +183,10 @@ namespace ams::bluetooth::core {
}
if (!g_redirect_core_events) {
if ((hos::GetVersion() < hos::Version_12_0_0) && (g_current_event_type == BtdrvEventType_PairingPinCodeRequest)) {
if ((hos::GetVersion() < hos::Version_12_0_0) && (g_current_event_type == BtdrvEventTypeOld_PairingPinCodeRequest)) {
HandlePinCodeRequestEventV1(&g_event_info);
}
else if ((hos::GetVersion() >= hos::Version_12_0_0) && static_cast<BtdrvEventTypeV12>(g_current_event_type) == BtdrvEventTypeV12_PairingPinCodeRequest) {
else if ((hos::GetVersion() >= hos::Version_12_0_0) && (g_current_event_type == BtdrvEventType_PairingPinCodeRequest)) {
HandlePinCodeRequestEventV12(&g_event_info);
}
else {

View file

@ -80,10 +80,10 @@ namespace ams::bluetooth::hid {
inline void HandleConnectionStateEventV1(bluetooth::HidEventInfo *event_info) {
switch (event_info->connection.v1.status) {
case BtdrvHidConnectionStatus_Connected:
case BtdrvHidConnectionStatusOld_Opened:
controller::AttachHandler(&event_info->connection.v1.addr);
break;
case BtdrvHidConnectionStatus_Disconnected:
case BtdrvHidConnectionStatusOld_Closed:
controller::RemoveHandler(&event_info->connection.v1.addr);
break;
default:
@ -93,10 +93,10 @@ namespace ams::bluetooth::hid {
inline void HandleConnectionStateEventV12(bluetooth::HidEventInfo *event_info) {
switch (event_info->connection.v12.status) {
case BtdrvHidConnectionStatusV12_Connected:
case BtdrvHidConnectionStatus_Opened:
controller::AttachHandler(&event_info->connection.v12.addr);
break;
case BtdrvHidConnectionStatusV12_Disconnected:
case BtdrvHidConnectionStatus_Closed:
controller::RemoveHandler(&event_info->connection.v12.addr);
break;
default:

View file

@ -151,9 +151,9 @@ namespace ams::bluetooth::hid::report {
}
if (hos::GetVersion() >= hos::Version_12_0_0)
g_fake_buffer->Write(BtdrvHidEventTypeV12_Data, &g_fake_report_event_info, report->size + 0x11);
else
g_fake_buffer->Write(BtdrvHidEventType_Data, &g_fake_report_event_info, report->size + 0x11);
else
g_fake_buffer->Write(BtdrvHidEventTypeOld_Data, &g_fake_report_event_info, report->size + 0x11);
g_system_event_fwd.Signal();
@ -201,7 +201,7 @@ namespace ams::bluetooth::hid::report {
R_ABORT_UNLESS(btdrvGetHidReportEventInfo(&g_event_info, sizeof(bluetooth::HidReportEventInfo), &g_current_event_type));
switch (g_current_event_type) {
case BtdrvHidEventType_Data:
case BtdrvHidEventTypeOld_Data:
{
auto device = controller::LocateHandler(&g_event_info.data_report.v1.addr);
if (!device)
@ -227,7 +227,7 @@ namespace ams::bluetooth::hid::report {
switch (real_packet->header.type) {
case 0xff:
continue;
case BtdrvHidEventType_Data:
case BtdrvHidEventTypeOld_Data:
{
auto device = controller::LocateHandler(hos::GetVersion() < hos::Version_9_0_0 ? &real_packet->data.data_report.v7.addr : &real_packet->data.data_report.v9.addr);
if (!device)
@ -255,7 +255,7 @@ namespace ams::bluetooth::hid::report {
switch (real_packet->header.type) {
case 0xff:
continue;
case BtdrvHidEventTypeV12_Data:
case BtdrvHidEventType_Data:
{
auto device = controller::LocateHandler(&real_packet->data.data_report.v9.addr);
if (!device)

View file

@ -130,7 +130,7 @@ namespace ams::mitm::bluetooth {
uint32_t status;
} event_data = {tsi == 0xff ? 1u : 0u, address, {0, 0}, 0};
ams::bluetooth::hid::SignalFakeEvent(BtdrvHidEventType_Ext, &event_data, sizeof(event_data));
ams::bluetooth::hid::SignalFakeEvent(BtdrvHidEventTypeOld_Ext, &event_data, sizeof(event_data));
}
else if (hos::GetVersion() < hos::Version_12_0_0) {
const struct {
@ -140,7 +140,7 @@ namespace ams::mitm::bluetooth {
uint8_t pad[2];
} event_data = {tsi == 0xff ? 1u : 0u, 0, address, {0, 0}};
ams::bluetooth::hid::SignalFakeEvent(BtdrvHidEventType_Ext, &event_data, sizeof(event_data));
ams::bluetooth::hid::SignalFakeEvent(BtdrvHidEventTypeOld_Ext, &event_data, sizeof(event_data));
}
else {
const struct {
@ -149,7 +149,7 @@ namespace ams::mitm::bluetooth {
uint8_t tsi;
} event_data = { address, 1, tsi };
ams::bluetooth::core::SignalFakeEvent(static_cast<ams::bluetooth::EventType>(BtdrvEventTypeV12_Tsi), &event_data, sizeof(event_data));
ams::bluetooth::core::SignalFakeEvent(BtdrvEventType_Tsi, &event_data, sizeof(event_data));
}
return ams::ResultSuccess();

View file

@ -49,7 +49,7 @@ namespace ams::mitm::btm {
Result BtmMitmService::GetDeviceConditionDeprecated3(sf::Out<ams::btm::DeviceConditionV800> out) {
auto device_condition = reinterpret_cast<BtmDeviceConditionV800 *>(out.GetPointer());
R_TRY(btmGetDeviceConditionDeprecated1Fwd(this->forward_service.get(), device_condition));
R_TRY(btmGetDeviceConditionDeprecated3Fwd(this->forward_service.get(), device_condition));
RenameConnectedDevices(device_condition->devices, device_condition->connected_count);
return ams::ResultSuccess();
}

View file

@ -52,12 +52,30 @@ namespace ams::mitm {
// Set bluetooth adapter host address override
ams::bluetooth::Address null_address = {};
if (std::memcmp(&config->bluetooth.host_address, &null_address, sizeof(ams::bluetooth::Address)) != 0) {
R_ABORT_UNLESS(btdrvSetAdapterProperty(BtdrvBluetoothPropertyType_Address, &config->bluetooth.host_address, sizeof(ams::bluetooth::Address)));
if (hos::GetVersion() < hos::Version_12_0_0) {
R_ABORT_UNLESS(btdrvLegacySetAdapterProperty(BtdrvBluetoothPropertyType_Address, &config->bluetooth.host_address, sizeof(ams::bluetooth::Address)));
}
else {
BtdrvAdapterProperty property;
property.type = BtdrvAdapterPropertyType_Address;
property.size = sizeof(ams::bluetooth::Address);
std::memcpy(property.data, &config->bluetooth.host_address, sizeof(ams::bluetooth::Address));
R_ABORT_UNLESS(btdrvSetAdapterProperty(BtdrvAdapterPropertyType_Address, &property));
}
}
// Set bluetooth adapter host name override
if (std::strlen(config->bluetooth.host_name) > 0) {
R_ABORT_UNLESS(btdrvSetAdapterProperty(BtdrvBluetoothPropertyType_Name, config->bluetooth.host_name, std::strlen(config->bluetooth.host_name)));
if (hos::GetVersion() < hos::Version_12_0_0) {
R_ABORT_UNLESS(btdrvLegacySetAdapterProperty(BtdrvBluetoothPropertyType_Name, config->bluetooth.host_name, std::strlen(config->bluetooth.host_name)));
}
else {
BtdrvAdapterProperty property;
property.type = BtdrvAdapterPropertyType_Name;
property.size = std::strlen(config->bluetooth.host_name);
std::memcpy(property.data, config->bluetooth.host_name, std::strlen(config->bluetooth.host_name));
R_ABORT_UNLESS(btdrvSetAdapterProperty(BtdrvAdapterPropertyType_Name, &property));
}
}
g_init_event.Signal();