Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
# Conflicts:
#	lib/libnx
  • Loading branch information
ndeadly committed Jul 11, 2021
2 parents f1c3656 + 4db612c commit 9547d51
Show file tree
Hide file tree
Showing 61 changed files with 1,289 additions and 536 deletions.
9 changes: 3 additions & 6 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
[submodule "libnx"]
path = lib/libnx
url = https://github.com/ndeadly/libnx.git
[submodule "Atmosphere-libs"]
path = lib/Atmosphere-libs
url = https://github.com/Atmosphere-NX/Atmosphere-libs.git
[submodule "borealis"]
path = borealis
url = https://github.com/natinusala/borealis.git
[submodule "libnx"]
path = lib/libnx
url = https://github.com/switchbrew/libnx.git
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ dist: all

cp -r exefs_patches dist/atmosphere/

mkdir -p dist/atmosphere/config_templates
cp mc_mitm/config.ini dist/atmosphere/config_templates/missioncontrol.ini
mkdir -p dist/config/MissionControl
cp mc_mitm/config.ini dist/config/MissionControl/missioncontrol.ini.template

cd dist; zip -r $(PROJECT_NAME)-$(BUILD_VERSION).zip ./*; cd ../;

Expand Down
61 changes: 38 additions & 23 deletions README.md

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion lib/Atmosphere-libs
Submodule Atmosphere-libs updated 623 files
2 changes: 1 addition & 1 deletion lib/libnx
Submodule libnx updated 91 files
+0 −34 .doozer.json
+22 −0 .github/workflows/build.yaml
+39 −0 .github/workflows/doxygen.yaml
+1 −0 .gitignore
+66 −0 Changelog.md
+1 −1 README.md
+1 −1 nx/Doxyfile
+2 −2 nx/Makefile
+6 −0 nx/include/switch.h
+30 −12 nx/include/switch/applets/swkbd.h
+1 −0 nx/include/switch/audio/driver.h
+20 −8 nx/include/switch/crypto/crc.h
+0 −16 nx/include/switch/kernel/virtmem.h
+33 −0 nx/include/switch/nvidia/ioctl.h
+0 −1 nx/include/switch/runtime/devices/console.h
+3 −0 nx/include/switch/runtime/hosversion.h
+68 −0 nx/include/switch/services/audctl.h
+50 −0 nx/include/switch/services/audrec.h
+45 −0 nx/include/switch/services/avm.h
+3 −0 nx/include/switch/services/bsd.h
+637 −339 nx/include/switch/services/btdrv.h
+153 −113 nx/include/switch/services/btdrv_types.h
+7 −147 nx/include/switch/services/btm.h
+255 −0 nx/include/switch/services/btm_types.h
+38 −1 nx/include/switch/services/friends.h
+9 −0 nx/include/switch/services/fs.h
+150 −342 nx/include/switch/services/hid.h
+56 −6 nx/include/switch/services/hiddbg.h
+150 −0 nx/include/switch/services/htcs.h
+31 −0 nx/include/switch/services/mm.h
+9 −4 nx/include/switch/services/pgl.h
+1 −1 nx/include/switch/services/psc.h
+6 −5 nx/include/switch/services/psm.h
+32 −20 nx/include/switch/services/set.h
+27 −1 nx/include/switch/services/sm.h
+25 −3 nx/include/switch/services/smm.h
+6 −6 nx/include/switch/sf/cmif.h
+23 −10 nx/include/switch/sf/service.h
+1 −1 nx/include/switch/sf/sessionmgr.h
+269 −0 nx/include/switch/sf/tipc.h
+16 −16 nx/source/applets/swkbd.c
+0 −1 nx/source/applets/web.c
+8 −8 nx/source/audio/driver.c
+1 −1 nx/source/audio/driver_internal.h
+5 −0 nx/source/audio/voice.c
+6 −4 nx/source/display/framebuffer.c
+4 −5 nx/source/kernel/jit.c
+0 −1 nx/source/kernel/shmem.c
+4 −4 nx/source/kernel/thread.c
+4 −4 nx/source/kernel/tmem.c
+8 −58 nx/source/kernel/virtmem.c
+0 −1 nx/source/nvidia/address_space.c
+0 −1 nx/source/nvidia/channel.c
+0 −1 nx/source/nvidia/gpu_channel.c
+117 −0 nx/source/nvidia/ioctl/nvchannel.c
+15 −0 nx/source/runtime/alloc.c
+6 −0 nx/source/runtime/alloc.h
+1 −1 nx/source/runtime/argv.c
+3 −2 nx/source/runtime/devices/fs_dev.c
+9 −8 nx/source/runtime/devices/romfs_dev.c
+10 −10 nx/source/runtime/devices/socket.c
+7 −7 nx/source/runtime/devices/usb_comms.c
+7 −2 nx/source/runtime/env.c
+6 −1 nx/source/runtime/hosversion.c
+4 −3 nx/source/runtime/newlib.c
+14 −13 nx/source/runtime/resolver.c
+3 −3 nx/source/runtime/ringcon.c
+13 −14 nx/source/runtime/util/inet_addr.c
+342 −0 nx/source/services/audctl.c
+123 −0 nx/source/services/audrec.c
+109 −0 nx/source/services/avm.c
+43 −6 nx/source/services/bsd.c
+432 −168 nx/source/services/btdrv.c
+13 −5 nx/source/services/btm.c
+122 −1 nx/source/services/friends.c
+27 −0 nx/source/services/fs.c
+11 −450 nx/source/services/hid.c
+89 −2 nx/source/services/hiddbg.c
+392 −0 nx/source/services/htcs.c
+66 −0 nx/source/services/mm.c
+8 −4 nx/source/services/nv.c
+147 −43 nx/source/services/pgl.c
+3 −3 nx/source/services/psc.c
+1 −1 nx/source/services/psm.c
+1 −1 nx/source/services/ro.c
+5 −2 nx/source/services/set.c
+75 −16 nx/source/services/sm.c
+88 −11 nx/source/services/smm.c
+1 −1 nx/source/services/time.c
+3 −4 nx/source/sf/sessionmgr.c
+1 −1 nx/switch.specs
4 changes: 4 additions & 0 deletions mc_mitm/config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@
;host_name=Nintendo Switch!
; Override host mac address of Bluetooth adapter
;host_address=04:20:69:04:20:69

[misc]
; Disable the LED lightbar on Sony Dualshock 4 and Dualsense controllers [default false]
;disable_sony_leds=false
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ namespace ams::bluetooth {

struct CircularBufferPacket{
CircularBufferPacketHeader header;
HidReportData data;
HidReportEventInfo data;
};

class CircularBuffer {
Expand Down
136 changes: 98 additions & 38 deletions mc_mitm/source/bluetooth_mitm/bluetooth/bluetooth_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,65 +69,125 @@ namespace ams::bluetooth::core {
return &g_system_event_user_fwd;
}

void SignalFakeEvent(bluetooth::EventType type, const void *data, size_t size) {
g_current_event_type = type;
std::memcpy(&g_event_info, data, size);

g_system_event_fwd.Signal();
}

inline void ModifyEventInfov1(bluetooth::EventInfo *event_info, BtdrvEventType event_type) {
switch (event_type) {
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 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 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);
}
break;
default:
break;
}
}

inline void ModifyEventInfov12(bluetooth::EventInfo *event_info, BtdrvEventType event_type) {
switch (event_type) {
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 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 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);
}
break;
default:
break;
}
}

Result GetEventInfo(ncm::ProgramId program_id, bluetooth::EventType *type, void *buffer, size_t size) {
std::scoped_lock lk(g_event_info_lock);

*type = g_current_event_type;
std::memcpy(buffer, &g_event_info, size);

auto event_info = reinterpret_cast<bluetooth::EventInfo *>(buffer);

if (program_id == ncm::SystemProgramId::Btm) {
switch (g_current_event_type) {
case BtdrvEventType_DeviceFound:
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_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_info->ssp_reply.name)) {
std::strncpy(event_info->ssp_reply.name, controller::pro_controller_name, sizeof(event_info->ssp_reply.name) - 1);
}
break;
default:
break;
}
auto event_info = reinterpret_cast<bluetooth::EventInfo *>(buffer);

if (hos::GetVersion() < hos::Version_12_0_0)
ModifyEventInfov1(event_info, g_current_event_type);
else
ModifyEventInfov12(event_info, g_current_event_type);
}

g_data_read_event.Signal();

return ams::ResultSuccess();
}

inline void HandlePinCodeRequestEventV1(bluetooth::EventInfo *event_info) {
// Default pin used by bluetooth service
bluetooth::PinCode pin = {"0000"};
uint8_t pin_length = std::strlen(pin.code);

// 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
bluetooth::Address host_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(btdrvLegacyRespondToPinRequest(g_event_info.pairing_pin_code_request.addr, false, &pin, pin_length));
}

inline void HandlePinCodeRequestEventV12(bluetooth::EventInfo *event_info) {
// 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) {
{
std::scoped_lock lk(g_event_info_lock);
R_ABORT_UNLESS(btdrvGetEventInfo(&g_event_info, sizeof(bluetooth::EventInfo), &g_current_event_type));
}

if (!g_redirect_core_events) {
if (g_current_event_type == BtdrvEventType_PinRequest) {
// Default pin used by bluetooth service
bluetooth::PinCode pin = {"0000"};
uint8_t pin_length = std::strlen(pin.code);

// Reverse host address as pin code for wii devices
if (std::strncmp(g_event_info.pin_reply.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)));
// Reverse host address
*reinterpret_cast<uint64_t *>(&pin) = util::SwapBytes(*reinterpret_cast<uint64_t *>(&host_address)) >> 16;
pin_length = sizeof(bluetooth::Address);
}

// Fuck BTM, we're sending the pin response ourselves if it won't.
R_ABORT_UNLESS(btdrvRespondToPinRequest(g_event_info.pin_reply.address, false, &pin, pin_length));
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) && (g_current_event_type == BtdrvEventType_PairingPinCodeRequest)) {
HandlePinCodeRequestEventV12(&g_event_info);
}
else {
g_system_event_fwd.Signal();
Expand Down
1 change: 1 addition & 0 deletions mc_mitm/source/bluetooth_mitm/bluetooth/bluetooth_core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ namespace ams::bluetooth::core {
os::SystemEvent *GetForwardEvent(void);
os::SystemEvent *GetUserForwardEvent(void);

void SignalFakeEvent(bluetooth::EventType type, const void *data, size_t size);
Result GetEventInfo(ncm::ProgramId program_id, bluetooth::EventType *type, void *buffer, size_t size);
void HandleEvent(void);

Expand Down
46 changes: 26 additions & 20 deletions mc_mitm/source/bluetooth_mitm/bluetooth/bluetooth_hid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ namespace ams::bluetooth::hid {
return &g_system_event_user_fwd;
}

void SignalFakeEvent(bluetooth::HidEventType type, const void *data, size_t size) {
g_current_event_type = type;
std::memcpy(&g_event_info, data, size);

g_system_event_fwd.Signal();
}

Result GetEventInfo(bluetooth::HidEventType *type, void *buffer, size_t size) {
std::scoped_lock lk(g_event_info_lock);

Expand All @@ -71,42 +78,41 @@ namespace ams::bluetooth::hid {
return ams::ResultSuccess();
}

void SignalFakeEvent(bluetooth::HidEventType type, const void *data, size_t size) {
g_current_event_type = type;
std::memcpy(&g_event_info, data, size);

g_system_event_fwd.Signal();
inline void HandleConnectionStateEventV1(bluetooth::HidEventInfo *event_info) {
switch (event_info->connection.v1.status) {
case BtdrvHidConnectionStatusOld_Opened:
controller::AttachHandler(&event_info->connection.v1.addr);
break;
case BtdrvHidConnectionStatusOld_Closed:
controller::RemoveHandler(&event_info->connection.v1.addr);
break;
default:
break;
}
}

void HandleConnectionStateEvent(bluetooth::HidEventInfo *event_info) {
switch (event_info->connection_state.state) {
case BtdrvHidConnectionState_Connected:
controller::AttachHandler(&event_info->connection_state.address);
inline void HandleConnectionStateEventV12(bluetooth::HidEventInfo *event_info) {
switch (event_info->connection.v12.status) {
case BtdrvHidConnectionStatus_Opened:
controller::AttachHandler(&event_info->connection.v12.addr);
break;
case BtdrvHidConnectionState_Disconnected:
controller::RemoveHandler(&event_info->connection_state.address);
case BtdrvHidConnectionStatus_Closed:
controller::RemoveHandler(&event_info->connection.v12.addr);
break;
default:
break;
}
}

// void HandleUnknown07Event(bluetooth::HidEventInfo *event_info) {
// ;
// }

void HandleEvent(void) {
{
std::scoped_lock lk(g_event_info_lock);
R_ABORT_UNLESS(btdrvGetHidEventInfo(&g_event_info, sizeof(bluetooth::HidEventInfo), &g_current_event_type));
}

switch (g_current_event_type) {
case BtdrvHidEventType_ConnectionState:
HandleConnectionStateEvent(&g_event_info);
break;
case BtdrvHidEventType_Unknown7:
//HandleUnknown07Event(&g_event_info);
case BtdrvHidEventType_Connection:
hos::GetVersion() < hos::Version_12_0_0 ? HandleConnectionStateEventV1(&g_event_info) : HandleConnectionStateEventV12(&g_event_info);
break;
default:
break;
Expand Down
3 changes: 1 addition & 2 deletions mc_mitm/source/bluetooth_mitm/bluetooth/bluetooth_hid.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@ namespace ams::bluetooth::hid {
os::SystemEvent *GetForwardEvent(void);
os::SystemEvent *GetUserForwardEvent(void);

void SignalFakeEvent(bluetooth::HidEventType type, const void *data, size_t size);
Result GetEventInfo(bluetooth::HidEventType *type, void *buffer, size_t size);
void HandleEvent(void);

void SignalFakeEvent(bluetooth::HidEventType type, const void *data, size_t size);

}
Loading

0 comments on commit 9547d51

Please sign in to comment.