1
0
Fork 0
mirror of https://github.com/Atmosphere-NX/Atmosphere.git synced 2024-12-18 08:22:04 +00:00

uart.mitm: update for new sf semantics

This commit is contained in:
Michael Scire 2021-02-02 15:00:49 -08:00 committed by yellows8
parent 6e1b0abf1d
commit 2b3c7fd104
No known key found for this signature in database
GPG key ID: 0AF90DA3F1E60E43
3 changed files with 45 additions and 27 deletions

View file

@ -15,7 +15,6 @@
*/
#include <stratosphere.hpp>
#include "uart_mitm_service.hpp"
#include "../amsmitm_debug.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. */
@ -358,13 +357,13 @@ namespace ams::mitm::uart {
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. */
UartPortSession port;
R_TRY(uartCreatePortSessionFwd(this->forward_service.get(), &port));
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();
}

View file

@ -18,29 +18,25 @@
#include "uart_shim.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), (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), (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), (out)) \
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), (out)) \
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), (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), (out, port_event_type))
AMS_SF_DEFINE_INTERFACE(ams::mitm::uart::impl, IPortSession, AMS_UART_IPORTSESSION_MITM_INTERFACE_INFO)
#define AMS_UART_MITM_INTERFACE_INFO(C, H) \
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(ams::mitm::uart::impl, IUartMitmInterface, AMS_UART_MITM_INTERFACE_INFO)
namespace ams::mitm::uart {
namespace impl {
#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, 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, 2, Result, GetWritableLength, (sf::Out<u64> 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, 4, Result, GetReadableLength, (sf::Out<u64> 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, 6, Result, BindPortEvent, (sf::Out<bool> out, sf::OutCopyHandle out_event_handle, UartPortEventType port_event_type, s64 threshold)) \
AMS_SF_METHOD_INFO(C, H, 7, Result, UnbindPortEvent, (sf::Out<bool> out, UartPortEventType port_event_type)) \
AMS_SF_DEFINE_INTERFACE(IPortSession, AMS_UART_IPORTSESSION_MITM_INTERFACE_INFO)
#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_DEFINE_MITM_INTERFACE(IUartMitmInterface, AMS_UART_MITM_INTERFACE_INFO)
}
class UartPortService {
private:
sm::MitmProcessInfo client_info;
@ -101,7 +97,7 @@ namespace ams::mitm::uart {
return client_info.program_id == ncm::SystemProgramId::Bluetooth;
}
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>);

View file

@ -22,6 +22,11 @@ namespace ams::mitm::uart {
namespace {
enum PortIndex {
PortIndex_Mitm,
PortIndex_Count,
};
constexpr sm::ServiceName UartMitmServiceName = sm::ServiceName::Encode("uart");
struct ServerOptions {
@ -33,7 +38,25 @@ namespace ams::mitm::uart {
constexpr size_t MaxServers = 1;
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() {
u8 en = 0;
@ -59,7 +82,7 @@ namespace ams::mitm::uart {
}
/* 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. */
g_server_manager.LoopProcess();