Skip to content

Commit

Permalink
Merge branch 'develop' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
ndeadly committed Sep 11, 2020
2 parents a9b2bea + 650b34e commit c380ae7
Show file tree
Hide file tree
Showing 61 changed files with 1,733 additions and 185 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
.patches/
tests/
dist/
btdrv-mitm/build/
bluetooth-mitm/build/
*.log
*.elf
*.nro
Expand Down
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,3 @@
[submodule "borealis"]
path = borealis
url = https://github.com/natinusala/borealis.git
[submodule "Atmosphere"]
path = Atmosphere
url = https://github.com/ndeadly/Atmosphere.git
1 change: 0 additions & 1 deletion Atmosphere
Submodule Atmosphere deleted from 18d59e
2 changes: 1 addition & 1 deletion Atmosphere-libs
Submodule Atmosphere-libs updated 145 files
27 changes: 11 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,33 +1,28 @@
PROJECT_NAME := MissionControl
BTDRVMITM_TID := 010000000000bd00
BLUETOOTH_MITM_TID := 010000000000bd00

TARGETS := boot2 btdrv-mitm
TARGETS := bluetooth-mitm

all: $(TARGETS)

boot2:
$(MAKE) -C Atmosphere/libraries all
$(MAKE) -C Atmosphere/stratosphere/boot2 all

btdrv-mitm:
bluetooth-mitm:
$(MAKE) -C $@

clean:
$(MAKE) -C Atmosphere/libraries clean
$(MAKE) -C Atmosphere/stratosphere/boot2 clean
$(MAKE) -C btdrv-mitm clean
$(MAKE) -C bluetooth-mitm clean
rm -rf dist

dist: all
rm -rf dist

mkdir -p dist/atmosphere/contents/$(BTDRVMITM_TID)
cp btdrv-mitm/btdrv-mitm.nsp dist/atmosphere/contents/$(BTDRVMITM_TID)/exefs.nsp
mkdir -p dist/atmosphere/contents/0100000000000008/
cp Atmosphere/stratosphere/boot2/boot2.nsp dist/atmosphere/contents/0100000000000008/exefs.nsp
#mkdir -p dist/atmosphere/contents/$(BTDRVMITM_TID)/flags
#touch dist/atmosphere/contents/$(BTDRVMITM_TID)/flags/boot2.flag
#echo "btdrv" > mitm.lst
mkdir -p dist/atmosphere/contents/$(BLUETOOTH_MITM_TID)
cp bluetooth-mitm/bluetooth-mitm.nsp dist/atmosphere/contents/$(BLUETOOTH_MITM_TID)/exefs.nsp
echo "btdrv" >> dist/atmosphere/contents/$(BLUETOOTH_MITM_TID)/mitm.lst
echo "btm" >> dist/atmosphere/contents/$(BLUETOOTH_MITM_TID)/mitm.lst

mkdir -p dist/atmosphere/contents/$(BLUETOOTH_MITM_TID)/flags
touch dist/atmosphere/contents/$(BLUETOOTH_MITM_TID)/flags/boot2.flag

cp -r exefs_patches dist/atmosphere/

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "btdrv.mitm",
"name": "bluetooth.mitm",
"title_id": "0x010000000000bd00",
"title_id_range_min": "0x010000000000bd00",
"title_id_range_max": "0x010000000000bd00",
"main_thread_stack_size": "0x4000",
"main_thread_priority": 16,
"main_thread_stack_size": "0x1000",
"main_thread_priority": 42,
"default_cpu_id": 3,
"process_category": 1,
"is_retail": true,
Expand All @@ -25,7 +25,7 @@
"type": "kernel_flags",
"value": {
"highest_thread_priority": 63,
"lowest_thread_priority": 4,
"lowest_thread_priority": 12,
"lowest_cpu_id": 3,
"highest_cpu_id": 3
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@
*/
#include <switch.h>
#include <stratosphere.hpp>
#include "btdrv_mitm_service.hpp"
#include "bluetooth/bluetooth_events.hpp"
#include <memory>
#include "btdrv_mitm/btdrvmitm_module.hpp"
#include "btm_mitm/btmmitm_module.hpp"

extern "C" {

Expand Down Expand Up @@ -72,7 +71,6 @@ void __appInit(void) {
R_ABORT_UNLESS(fsInitialize());
R_ABORT_UNLESS(pmdmntInitialize());
R_ABORT_UNLESS(pminfoInitialize());
R_ABORT_UNLESS(btdrvInitialize());
});

R_ABORT_UNLESS(fsdevMountSdmc());
Expand All @@ -93,26 +91,20 @@ void __libnx_exception_handler(ThreadExceptionDump* ctx) {
ams::CrashHandler(ctx);
}

namespace {

constexpr sm::ServiceName BtdrvMitmServiceName = sm::ServiceName::Encode("btdrv");

struct ServerOptions {
static constexpr size_t PointerBufferSize = 0x1000;
static constexpr size_t MaxDomains = 0;
static constexpr size_t MaxDomainObjects = 0;
};
ams::Result LaunchModules(void) {
R_TRY(ams::mitm::btdrv::Launch());
R_TRY(ams::mitm::btm::Launch());
return ams::ResultSuccess();
}

constexpr size_t MaxServers = 1;
constexpr size_t MaxSessions = 6;

void WaitModules(void) {
ams::mitm::btm::WaitFinished();
ams::mitm::btdrv::WaitFinished();
}

int main(int argc, char **argv) {
auto server_manager = std::make_unique<sf::hipc::ServerManager<MaxServers, ServerOptions, MaxSessions>>();
R_ABORT_UNLESS((server_manager->RegisterMitmServer<ams::mitm::btdrv::IBtdrvMitmInterface, ams::mitm::btdrv::BtdrvMitmService>(BtdrvMitmServiceName)));
R_ABORT_UNLESS(bluetooth::events::Initialize());
server_manager->LoopProcess();

R_ABORT_UNLESS(LaunchModules());
WaitModules();

return 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
#include "bluetooth_core.hpp"
#include "../btdrv_mitm_flags.hpp"
#include "../controllers/controller_management.hpp"
#include "../../controllers/controller_management.hpp"
#include <atomic>
#include <mutex>
#include <cstring>
Expand Down Expand Up @@ -83,17 +83,17 @@ 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)) {
if (controller::IsGamepad(&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;
case BluetoothEvent_PinRequest:
if (!controller::IsOfficialSwitchControllerName(event_data->pinReply.name)) {
if (!controller::IsOfficialSwitchControllerName(event_data->pinReply.name, sizeof(BluetoothName))) {
std::strncpy(event_data->pinReply.name, controller::pro_controller_name, sizeof(BluetoothName) - 1);
}
break;
case BluetoothEvent_SspRequest:
if (!controller::IsOfficialSwitchControllerName(event_data->sspReply.name)) {
if (!controller::IsOfficialSwitchControllerName(event_data->sspReply.name, sizeof(BluetoothName))) {
std::strncpy(event_data->sspReply.name, controller::pro_controller_name, sizeof(BluetoothName) - 1);
}
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,24 @@ namespace ams::bluetooth::events {
svc::SleepThread(1'000'000ul);
}

// Initialise the btdrv service now that we can be sure the MITM is up and running
sm::DoWithSession([&]() {
R_ABORT_UNLESS(btdrvInitialize());
});

os::InitializeWaitableManager(&g_manager);

os::InitializeWaitableHolder(&g_holder_bt_core, core::GetSystemEvent());
os::SetWaitableHolderUserData(&g_holder_bt_core, BtdrvEventType_BluetoothCore);
os::LinkWaitableHolder(&g_manager, &g_holder_bt_core);

os::InitializeWaitableHolder(&g_holder_bt_hid, hid::GetSystemEvent());
os::SetWaitableHolderUserData(&g_holder_bt_hid, BtdrvEventType_BluetoothHid);
os::InitializeWaitableHolder(&g_holder_bt_hid, hid::GetSystemEvent());
os::SetWaitableHolderUserData(&g_holder_bt_hid, BtdrvEventType_BluetoothHid);
os::LinkWaitableHolder(&g_manager, &g_holder_bt_hid);

if (hos::GetVersion() >= hos::Version_5_0_0) {
os::InitializeWaitableHolder(&g_holder_bt_ble, ble::GetSystemEvent());
os::SetWaitableHolderUserData(&g_holder_bt_ble, BtdrvEventType_BluetoothBle);
os::InitializeWaitableHolder(&g_holder_bt_ble, ble::GetSystemEvent());
os::SetWaitableHolderUserData(&g_holder_bt_ble, BtdrvEventType_BluetoothBle);
os::LinkWaitableHolder(&g_manager, &g_holder_bt_ble);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
#include "bluetooth_hid.hpp"
#include "../btdrv_mitm_flags.hpp"
#include "../controllers/controller_management.hpp"
#include "../../controllers/controller_management.hpp"
#include <atomic>
#include <mutex>
#include <cstring>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include "bluetooth_circular_buffer.hpp"
#include "../btdrv_shim.h"
#include "../btdrv_mitm_flags.hpp"
#include "../controllers/controller_management.hpp"
#include "../../controllers/controller_management.hpp"
#include <atomic>
#include <mutex>
#include <cstring>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,6 @@

namespace ams::bluetooth {

enum SubCmdType : u8 {
SubCmd_GetControllerState = 0x00,
SubCmd_ManualPair = 0x01,
SubCmd_RequestDeviceInfo = 0x02,
SubCmd_SetInputReportMode = 0x03,
SubCmd_TriggersElapsedTime = 0x04,
SubCmd_SetHciState = 0x06,
SubCmd_ResetPairingInfo = 0x07,
SubCmd_SetShipPowerState = 0x08,
SubCmd_SpiFlashRead = 0x10,
SubCmd_SpiFlashWrite = 0x11,
SubCmd_SpiSectorErase = 0x12,
SubCmd_ResetMcu = 0x20,
SubCmd_SetMcuConfig = 0x21,
SubCmd_SetMcuState = 0x22,
SubCmd_SetPlayerLeds = 0x30,
SubCmd_GetPlayerLeds = 0x31,
SubCmd_SetHomeLed = 0x38,
SubCmd_EnableImu = 0x40,
SubCmd_SetImuSensitivity = 0x41,
SubCmd_WriteImuRegisters = 0x42,
SubCmd_ReadImuRegisters = 0x43,
SubCmd_EnableVibration = 0x48,
SubCmd_GetRegulatedVoltage = 0x50,
};

typedef BluetoothEventType EventType;
typedef BluetoothHidEventType HidEventType;
typedef BluetoothBleEventType BleEventType;
Expand All @@ -62,8 +36,4 @@ namespace ams::bluetooth {

typedef BluetoothHhReportType HhReportType;

struct DeviceSettings : sf::LargeData {
BluetoothDevicesSettings device;
};

}
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include "btdrv_mitm_flags.hpp"
#include "btdrv_shim.h"
#include "bluetooth/bluetooth_events.hpp"
#include "controllers/controller_management.hpp"
#include "../controllers/controller_management.hpp"
#include <switch.h>
#include <cstring>

Expand Down Expand Up @@ -87,20 +87,6 @@ namespace ams::mitm::btdrv {

return ams::ResultSuccess();
}

Result BtdrvMitmService::GetPairedDeviceInfo(sf::Out<bluetooth::DeviceSettings> out, bluetooth::Address address) {
auto device = reinterpret_cast<BluetoothDevicesSettings *>(out.GetPointer());

R_TRY(btdrvGetPairedDeviceInfoFwd(this->forward_service.get(), &address, device));

if (this->client_info.program_id == ncm::SystemProgramId::Btm) {
if (!controller::IsOfficialSwitchControllerName(device->name)) {
std::strncpy(device->name, controller::pro_controller_name, sizeof(BluetoothLocalName) - 1);
}
}

return ams::ResultSuccess();
}

Result BtdrvMitmService::FinalizeHid(void) {
// Only btm should be able to make this call
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ namespace ams::mitm::btdrv {
AMS_SF_METHOD_INFO(C, H, 15, Result, GetEventInfo, (sf::Out<bluetooth::EventType> out_type, const sf::OutPointerBuffer &out_buffer)) \
AMS_SF_METHOD_INFO(C, H, 16, Result, InitializeHid, (sf::OutCopyHandle out_handle, u16 version)) \
AMS_SF_METHOD_INFO(C, H, 19, Result, WriteHidData, (bluetooth::Address address, const sf::InPointerBuffer &buffer)) \
AMS_SF_METHOD_INFO(C, H, 25, Result, GetPairedDeviceInfo, (sf::Out<bluetooth::DeviceSettings> out, bluetooth::Address address)) \
AMS_SF_METHOD_INFO(C, H, 26, Result, FinalizeHid, (void)) \
AMS_SF_METHOD_INFO(C, H, 27, Result, GetHidEventInfo, (sf::Out<bluetooth::HidEventType> out_type, const sf::OutPointerBuffer &out_buffer)) \
AMS_SF_METHOD_INFO(C, H, 36, Result, RegisterHidReportEventDeprecated, (sf::OutCopyHandle out_handle), hos::Version_1_0_0, hos::Version_3_0_2) \
Expand Down Expand Up @@ -66,7 +65,6 @@ namespace ams::mitm::btdrv {
Result GetEventInfo(sf::Out<bluetooth::EventType> out_type, const sf::OutPointerBuffer &out_buffer);
Result InitializeHid(sf::OutCopyHandle out_handle, u16 version);
Result WriteHidData(bluetooth::Address address, const sf::InPointerBuffer &buffer);
Result GetPairedDeviceInfo(sf::Out<bluetooth::DeviceSettings> out, bluetooth::Address address);
Result FinalizeHid(void);
Result GetHidEventInfo(sf::Out<bluetooth::HidEventType> out_type, const sf::OutPointerBuffer &out_buffer);
Result RegisterHidReportEventDeprecated(sf::OutCopyHandle out_handle);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,6 @@ Result btdrvWriteHidDataFwd(Service* srv, const BluetoothAddress *address, const
);
}

Result btdrvGetPairedDeviceInfoFwd(Service* srv, const BluetoothAddress *address, BluetoothDevicesSettings *device) {
const struct {
BluetoothAddress address;
} in = { *address };

return serviceMitmDispatchIn(srv, 25, in,
.buffer_attrs = { SfBufferAttr_FixedSize | SfBufferAttr_HipcPointer | SfBufferAttr_Out },
.buffers = { {device, sizeof(BluetoothDevicesSettings)} }
);
}

Result btdrvFinalizeHidFwd(Service* srv) {
return serviceMitmDispatch(srv, 26);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ Result btdrvInitializeBluetoothFwd(Service* srv, Handle *out_handle);
Result btdrvFinalizeBluetoothFwd(Service* srv);
Result btdrvInitializeHidFwd(Service* srv, Handle *out_handle, u16 version);
Result btdrvWriteHidDataFwd(Service* srv, const BluetoothAddress *address, const BluetoothHidReport *data);
Result btdrvGetPairedDeviceInfoFwd(Service* srv, const BluetoothAddress *address, BluetoothDevicesSettings *device);
Result btdrvFinalizeHidFwd(Service* srv);
Result btdrvRegisterHidReportEventFwd(Service* srv, Handle *out_handle);
Result btdrvGetHidReportEventInfoFwd(Service* srv, Handle *out_handle);
Expand Down
Loading

0 comments on commit c380ae7

Please sign in to comment.