mirror of
https://github.com/Atmosphere-NX/Atmosphere
synced 2024-12-22 20:31:14 +00:00
uart.mitm: update for new sf semantics
This commit is contained in:
parent
6e1b0abf1d
commit
2b3c7fd104
3 changed files with 45 additions and 27 deletions
|
@ -15,7 +15,6 @@
|
||||||
*/
|
*/
|
||||||
#include <stratosphere.hpp>
|
#include <stratosphere.hpp>
|
||||||
#include "uart_mitm_service.hpp"
|
#include "uart_mitm_service.hpp"
|
||||||
#include "../amsmitm_debug.hpp"
|
|
||||||
#include "../amsmitm_fs_utils.hpp"
|
#include "../amsmitm_fs_utils.hpp"
|
||||||
|
|
||||||
/* TODO: This should really use async fs-writing, there's a slowdown with bluetooth communications with current fs-writing. */
|
/* TODO: This should really use async fs-writing, there's a slowdown with bluetooth communications with current fs-writing. */
|
||||||
|
@ -358,13 +357,13 @@ namespace ams::mitm::uart {
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
Result UartMitmService::CreatePortSession(sf::Out<std::shared_ptr<impl::IPortSession>> out) {
|
Result UartMitmService::CreatePortSession(sf::Out<sf::SharedPointer<impl::IPortSession>> out) {
|
||||||
/* Open a port interface. */
|
/* Open a port interface. */
|
||||||
UartPortSession port;
|
UartPortSession port;
|
||||||
R_TRY(uartCreatePortSessionFwd(this->forward_service.get(), &port));
|
R_TRY(uartCreatePortSessionFwd(this->forward_service.get(), &port));
|
||||||
const sf::cmif::DomainObjectId target_object_id{serviceGetObjectId(&port.s)};
|
const sf::cmif::DomainObjectId target_object_id{serviceGetObjectId(&port.s)};
|
||||||
|
|
||||||
out.SetValue(sf::MakeShared<impl::IPortSession, UartPortService>(this->client_info, std::make_unique<UartPortSession>(port)), target_object_id);
|
out.SetValue(sf::CreateSharedObjectEmplaced<impl::IPortSession, UartPortService>(this->client_info, std::make_unique<UartPortSession>(port)), target_object_id);
|
||||||
return ResultSuccess();
|
return ResultSuccess();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,28 +18,24 @@
|
||||||
|
|
||||||
#include "uart_shim.h"
|
#include "uart_shim.h"
|
||||||
|
|
||||||
namespace ams::mitm::uart {
|
|
||||||
|
|
||||||
namespace impl {
|
|
||||||
|
|
||||||
#define AMS_UART_IPORTSESSION_MITM_INTERFACE_INFO(C, H) \
|
#define AMS_UART_IPORTSESSION_MITM_INTERFACE_INFO(C, H) \
|
||||||
AMS_SF_METHOD_INFO(C, H, 0, Result, OpenPort, (sf::Out<bool> out, u32 port, u32 baud_rate, UartFlowControlMode flow_control_mode, u32 device_variation, bool is_invert_tx, bool is_invert_rx, bool is_invert_rts, bool is_invert_cts, sf::CopyHandle send_handle, sf::CopyHandle receive_handle, u64 send_buffer_length, u64 receive_buffer_length)) \
|
AMS_SF_METHOD_INFO(C, H, 0, Result, OpenPort, (sf::Out<bool> out, u32 port, u32 baud_rate, UartFlowControlMode flow_control_mode, u32 device_variation, bool is_invert_tx, bool is_invert_rx, bool is_invert_rts, bool is_invert_cts, sf::CopyHandle send_handle, sf::CopyHandle receive_handle, u64 send_buffer_length, u64 receive_buffer_length), (out, port, baud_rate, flow_control_mode, device_variation, is_invert_tx, is_invert_rx, is_invert_rts, is_invert_cts, send_handle, receive_handle, send_buffer_length, receive_buffer_length)) \
|
||||||
AMS_SF_METHOD_INFO(C, H, 1, Result, OpenPortForDev, (sf::Out<bool> out, u32 port, u32 baud_rate, UartFlowControlMode flow_control_mode, u32 device_variation, bool is_invert_tx, bool is_invert_rx, bool is_invert_rts, bool is_invert_cts, sf::CopyHandle send_handle, sf::CopyHandle receive_handle, u64 send_buffer_length, u64 receive_buffer_length)) \
|
AMS_SF_METHOD_INFO(C, H, 1, Result, OpenPortForDev, (sf::Out<bool> out, u32 port, u32 baud_rate, UartFlowControlMode flow_control_mode, u32 device_variation, bool is_invert_tx, bool is_invert_rx, bool is_invert_rts, bool is_invert_cts, sf::CopyHandle send_handle, sf::CopyHandle receive_handle, u64 send_buffer_length, u64 receive_buffer_length), (out, port, baud_rate, flow_control_mode, device_variation, is_invert_tx, is_invert_rx, is_invert_rts, is_invert_cts, send_handle, receive_handle, send_buffer_length, receive_buffer_length)) \
|
||||||
AMS_SF_METHOD_INFO(C, H, 2, Result, GetWritableLength, (sf::Out<u64> out)) \
|
AMS_SF_METHOD_INFO(C, H, 2, Result, GetWritableLength, (sf::Out<u64> out), (out)) \
|
||||||
AMS_SF_METHOD_INFO(C, H, 3, Result, Send, (sf::Out<u64> out_size, const sf::InAutoSelectBuffer &data)) \
|
AMS_SF_METHOD_INFO(C, H, 3, Result, Send, (sf::Out<u64> out_size, const sf::InAutoSelectBuffer &data), (out_size, data)) \
|
||||||
AMS_SF_METHOD_INFO(C, H, 4, Result, GetReadableLength, (sf::Out<u64> out)) \
|
AMS_SF_METHOD_INFO(C, H, 4, Result, GetReadableLength, (sf::Out<u64> out), (out)) \
|
||||||
AMS_SF_METHOD_INFO(C, H, 5, Result, Receive, (sf::Out<u64> out_size, const sf::OutAutoSelectBuffer &data)) \
|
AMS_SF_METHOD_INFO(C, H, 5, Result, Receive, (sf::Out<u64> out_size, const sf::OutAutoSelectBuffer &data), (out_size, data)) \
|
||||||
AMS_SF_METHOD_INFO(C, H, 6, Result, BindPortEvent, (sf::Out<bool> out, sf::OutCopyHandle out_event_handle, UartPortEventType port_event_type, s64 threshold)) \
|
AMS_SF_METHOD_INFO(C, H, 6, Result, BindPortEvent, (sf::Out<bool> out, sf::OutCopyHandle out_event_handle, UartPortEventType port_event_type, s64 threshold), (out, out_event_handle, port_event_type, threshold)) \
|
||||||
AMS_SF_METHOD_INFO(C, H, 7, Result, UnbindPortEvent, (sf::Out<bool> out, UartPortEventType port_event_type)) \
|
AMS_SF_METHOD_INFO(C, H, 7, Result, UnbindPortEvent, (sf::Out<bool> out, UartPortEventType port_event_type), (out, port_event_type))
|
||||||
|
|
||||||
AMS_SF_DEFINE_INTERFACE(IPortSession, AMS_UART_IPORTSESSION_MITM_INTERFACE_INFO)
|
AMS_SF_DEFINE_INTERFACE(ams::mitm::uart::impl, IPortSession, AMS_UART_IPORTSESSION_MITM_INTERFACE_INFO)
|
||||||
|
|
||||||
#define AMS_UART_MITM_INTERFACE_INFO(C, H) \
|
#define AMS_UART_MITM_INTERFACE_INFO(C, H) \
|
||||||
AMS_SF_METHOD_INFO(C, H, 6, Result, CreatePortSession, (sf::Out<std::shared_ptr<IPortSession>> out))
|
AMS_SF_METHOD_INFO(C, H, 6, Result, CreatePortSession, (sf::Out<sf::SharedPointer<::ams::mitm::uart::impl::IPortSession>> out), (out))
|
||||||
|
|
||||||
AMS_SF_DEFINE_MITM_INTERFACE(IUartMitmInterface, AMS_UART_MITM_INTERFACE_INFO)
|
AMS_SF_DEFINE_MITM_INTERFACE(ams::mitm::uart::impl, IUartMitmInterface, AMS_UART_MITM_INTERFACE_INFO)
|
||||||
|
|
||||||
}
|
namespace ams::mitm::uart {
|
||||||
|
|
||||||
class UartPortService {
|
class UartPortService {
|
||||||
private:
|
private:
|
||||||
|
@ -101,7 +97,7 @@ namespace ams::mitm::uart {
|
||||||
return client_info.program_id == ncm::SystemProgramId::Bluetooth;
|
return client_info.program_id == ncm::SystemProgramId::Bluetooth;
|
||||||
}
|
}
|
||||||
public:
|
public:
|
||||||
Result CreatePortSession(sf::Out<std::shared_ptr<impl::IPortSession>> out);
|
Result CreatePortSession(sf::Out<sf::SharedPointer<impl::IPortSession>> out);
|
||||||
};
|
};
|
||||||
static_assert(impl::IsIUartMitmInterface<UartMitmService>);
|
static_assert(impl::IsIUartMitmInterface<UartMitmService>);
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,11 @@ namespace ams::mitm::uart {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
enum PortIndex {
|
||||||
|
PortIndex_Mitm,
|
||||||
|
PortIndex_Count,
|
||||||
|
};
|
||||||
|
|
||||||
constexpr sm::ServiceName UartMitmServiceName = sm::ServiceName::Encode("uart");
|
constexpr sm::ServiceName UartMitmServiceName = sm::ServiceName::Encode("uart");
|
||||||
|
|
||||||
struct ServerOptions {
|
struct ServerOptions {
|
||||||
|
@ -33,7 +38,25 @@ namespace ams::mitm::uart {
|
||||||
constexpr size_t MaxServers = 1;
|
constexpr size_t MaxServers = 1;
|
||||||
constexpr size_t MaxSessions = 10;
|
constexpr size_t MaxSessions = 10;
|
||||||
|
|
||||||
sf::hipc::ServerManager<MaxServers, ServerOptions, MaxSessions> g_server_manager;
|
class ServerManager final : public sf::hipc::ServerManager<MaxServers, ServerOptions, MaxSessions> {
|
||||||
|
private:
|
||||||
|
virtual Result OnNeedsToAccept(int port_index, Server *server) override;
|
||||||
|
};
|
||||||
|
|
||||||
|
ServerManager g_server_manager;
|
||||||
|
|
||||||
|
Result ServerManager::OnNeedsToAccept(int port_index, Server *server) {
|
||||||
|
/* Acknowledge the mitm session. */
|
||||||
|
std::shared_ptr<::Service> fsrv;
|
||||||
|
sm::MitmProcessInfo client_info;
|
||||||
|
server->AcknowledgeMitmSession(std::addressof(fsrv), std::addressof(client_info));
|
||||||
|
|
||||||
|
switch (port_index) {
|
||||||
|
case PortIndex_Mitm:
|
||||||
|
return this->AcceptMitmImpl(server, sf::CreateSharedObjectEmplaced<impl::IUartMitmInterface, UartMitmService>(decltype(fsrv)(fsrv), client_info), fsrv);
|
||||||
|
AMS_UNREACHABLE_DEFAULT_CASE();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool ShouldMitmUart() {
|
bool ShouldMitmUart() {
|
||||||
u8 en = 0;
|
u8 en = 0;
|
||||||
|
@ -59,7 +82,7 @@ namespace ams::mitm::uart {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Create mitm servers. */
|
/* Create mitm servers. */
|
||||||
R_ABORT_UNLESS((g_server_manager.RegisterMitmServer<impl::IUartMitmInterface, UartMitmService>(UartMitmServiceName)));
|
R_ABORT_UNLESS((g_server_manager.RegisterMitmServer<UartMitmService>(PortIndex_Mitm, UartMitmServiceName)));
|
||||||
|
|
||||||
/* Loop forever, servicing our services. */
|
/* Loop forever, servicing our services. */
|
||||||
g_server_manager.LoopProcess();
|
g_server_manager.LoopProcess();
|
||||||
|
|
Loading…
Reference in a new issue