2020-09-08 14:17:07 +00:00
|
|
|
/*
|
2021-01-26 03:03:26 +00:00
|
|
|
* Copyright (c) 2020-2021 ndeadly
|
2020-09-08 14:17:07 +00:00
|
|
|
*
|
2021-01-26 03:03:26 +00:00
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms and conditions of the GNU General Public License,
|
|
|
|
* version 2, as published by the Free Software Foundation.
|
2020-09-08 14:17:07 +00:00
|
|
|
*
|
2021-01-26 03:03:26 +00:00
|
|
|
* This program is distributed in the hope it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
* more details.
|
2020-09-08 14:17:07 +00:00
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
#include "btm_mitm_service.hpp"
|
|
|
|
#include "btm_shim.h"
|
2020-09-11 20:03:41 +00:00
|
|
|
#include "../controllers/controller_management.hpp"
|
2020-09-08 14:17:07 +00:00
|
|
|
#include <cstring>
|
|
|
|
|
|
|
|
namespace ams::mitm::btm {
|
|
|
|
|
2020-09-11 15:55:43 +00:00
|
|
|
namespace {
|
2020-09-08 14:17:07 +00:00
|
|
|
|
2020-09-11 15:55:43 +00:00
|
|
|
void RenameConnectedDevices(BtmConnectedDevice devices[], size_t count) {
|
|
|
|
for (unsigned int i = 0; i < count; ++i) {
|
|
|
|
auto device = &devices[i];
|
2020-12-06 14:54:55 +00:00
|
|
|
if (!controller::IsOfficialSwitchControllerName(device->name)) {
|
2020-09-11 15:55:43 +00:00
|
|
|
std::strncpy(device->name, controller::pro_controller_name, sizeof(device->name) - 1);
|
|
|
|
}
|
2020-09-08 14:17:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-11 15:55:43 +00:00
|
|
|
}
|
|
|
|
|
2021-02-03 22:21:32 +00:00
|
|
|
Result BtmMitmService::GetDeviceConditionDeprecated1(sf::Out<ams::btm::DeviceConditionV100> out) {
|
2020-09-11 15:55:43 +00:00
|
|
|
auto device_condition = reinterpret_cast<BtmDeviceConditionV100 *>(out.GetPointer());
|
|
|
|
R_TRY(btmGetDeviceConditionDeprecated1Fwd(this->forward_service.get(), device_condition));
|
|
|
|
RenameConnectedDevices(device_condition->devices, device_condition->connected_count);
|
|
|
|
return ams::ResultSuccess();
|
|
|
|
}
|
|
|
|
|
2021-02-03 22:21:32 +00:00
|
|
|
Result BtmMitmService::GetDeviceConditionDeprecated2(sf::Out<ams::btm::DeviceConditionV510> out) {
|
2020-09-11 15:55:43 +00:00
|
|
|
auto device_condition = reinterpret_cast<BtmDeviceConditionV510 *>(out.GetPointer());
|
|
|
|
R_TRY(btmGetDeviceConditionDeprecated2Fwd(this->forward_service.get(), device_condition));
|
|
|
|
RenameConnectedDevices(device_condition->devices, device_condition->connected_count);
|
|
|
|
return ams::ResultSuccess();
|
|
|
|
}
|
|
|
|
|
2021-02-03 22:21:32 +00:00
|
|
|
Result BtmMitmService::GetDeviceConditionDeprecated3(sf::Out<ams::btm::DeviceConditionV800> out) {
|
2020-09-11 15:55:43 +00:00
|
|
|
auto device_condition = reinterpret_cast<BtmDeviceConditionV800 *>(out.GetPointer());
|
2021-05-17 17:46:50 +00:00
|
|
|
R_TRY(btmGetDeviceConditionDeprecated3Fwd(this->forward_service.get(), device_condition));
|
2020-09-11 15:55:43 +00:00
|
|
|
RenameConnectedDevices(device_condition->devices, device_condition->connected_count);
|
|
|
|
return ams::ResultSuccess();
|
|
|
|
}
|
|
|
|
|
2021-02-03 22:21:32 +00:00
|
|
|
Result BtmMitmService::GetDeviceCondition(sf::Out<ams::btm::DeviceCondition> out) {
|
2020-09-11 15:55:43 +00:00
|
|
|
auto device_condition = reinterpret_cast<BtmDeviceConditionV900 *>(out.GetPointer());
|
|
|
|
R_TRY(btmGetDeviceConditionFwd(this->forward_service.get(), device_condition));
|
|
|
|
RenameConnectedDevices(device_condition->devices, device_condition->connected_count);
|
2020-09-08 14:17:07 +00:00
|
|
|
return ams::ResultSuccess();
|
|
|
|
}
|
|
|
|
|
2021-02-03 22:21:32 +00:00
|
|
|
Result BtmMitmService::GetDeviceInfo(sf::Out<ams::btm::DeviceInfoList> out) {
|
2020-12-02 20:59:05 +00:00
|
|
|
auto device_info = reinterpret_cast<BtmDeviceInfoList *>(out.GetPointer());
|
2020-09-08 14:17:07 +00:00
|
|
|
R_TRY(btmGetDeviceInfoFwd(this->forward_service.get(), device_info));
|
|
|
|
|
2021-03-17 01:44:49 +00:00
|
|
|
for (unsigned int i = 0; i < device_info->device_count; ++i) {
|
2020-09-08 14:17:07 +00:00
|
|
|
auto device = &device_info->devices[i];
|
2021-03-17 01:44:49 +00:00
|
|
|
if (!controller::IsOfficialSwitchControllerName(device->name.name)) {
|
|
|
|
std::strncpy(device->name.name, controller::pro_controller_name, sizeof(device->name) - 1);
|
2020-09-08 14:17:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ams::ResultSuccess();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|