Skip to content

Commit

Permalink
changed names to match ams denomionation of Interface and Service
Browse files Browse the repository at this point in the history
  • Loading branch information
brenodantas10 authored and spacemeowx2 committed Aug 13, 2020
1 parent 14dbfdb commit c5964ea
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@ namespace ams::mitm::ldn {
AMS_SF_METHOD_INFO(C, H, 401, Result, Finalize, ()) \
AMS_SF_METHOD_INFO(C, H, 402, Result, InitializeSystem2, (u64 unk, const sf::ClientProcessId &client_process_id))

AMS_SF_DEFINE_INTERFACE(ILdnCommunication, AMS_LDN_ICOMMUNICATION)
AMS_SF_DEFINE_INTERFACE(ICommunicationInterface, AMS_LDN_ICOMMUNICATION)
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace ams::mitm::ldn {
#define AMS_ILDN_MITM_SERVICE(C, H) \
AMS_SF_METHOD_INFO(C, H, 0, Result, CreateUserLocalCommunicationService, (sf::Out<std::shared_ptr<ILdnCommunication>> out)) \
AMS_SF_METHOD_INFO(C, H, 0, Result, CreateUserLocalCommunicationService, (sf::Out<std::shared_ptr<ICommunicationInterface>> out)) \
AMS_SF_METHOD_INFO(C, H, 65000, Result, CreateLdnMitmConfigService, (sf::Out<std::shared_ptr<ILdnConfig>> out)) \

AMS_SF_DEFINE_MITM_INTERFACE(ILdnMitMService, AMS_ILDN_MITM_SERVICE)
Expand Down
66 changes: 33 additions & 33 deletions ldn_mitm/source/ldn_icommunication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ namespace ams::mitm::ldn {

// https://reswitched.github.io/SwIPC/ifaces.html#nn::ldn::detail::IUserLocalCommunicationService

Result ICommunicationInterface::Initialize(const sf::ClientProcessId &client_process_id) {
LogFormat("ICommunicationInterface::Initialize pid: %" PRIu64, client_process_id);
Result ICommunicationService::Initialize(const sf::ClientProcessId &client_process_id) {
LogFormat("ICommunicationService::Initialize pid: %" PRIu64, client_process_id);

if (this->state_event == nullptr) {
// ClearMode, inter_process
Expand All @@ -22,13 +22,13 @@ namespace ams::mitm::ldn {
return ResultSuccess();
}

Result ICommunicationInterface::InitializeSystem2(u64 unk, const sf::ClientProcessId &client_process_id) {
LogFormat("ICommunicationInterface::InitializeSystem2 unk: %" PRIu64, unk);
Result ICommunicationService::InitializeSystem2(u64 unk, const sf::ClientProcessId &client_process_id) {
LogFormat("ICommunicationService::InitializeSystem2 unk: %" PRIu64, unk);
this->error_state = unk;
return this->Initialize(client_process_id);
}

Result ICommunicationInterface::Finalize() {
Result ICommunicationService::Finalize() {
Result rc = lanDiscovery.finalize();
if (this->state_event) {
delete this->state_event;
Expand All @@ -37,39 +37,39 @@ namespace ams::mitm::ldn {
return rc;
}

Result ICommunicationInterface::OpenAccessPoint() {
Result ICommunicationService::OpenAccessPoint() {
return this->lanDiscovery.openAccessPoint();
}

Result ICommunicationInterface::CloseAccessPoint() {
Result ICommunicationService::CloseAccessPoint() {
return this->lanDiscovery.closeAccessPoint();
}

Result ICommunicationInterface::DestroyNetwork() {
Result ICommunicationService::DestroyNetwork() {
return this->lanDiscovery.destroyNetwork();
}

Result ICommunicationInterface::OpenStation() {
Result ICommunicationService::OpenStation() {
return this->lanDiscovery.openStation();
}

Result ICommunicationInterface::CloseStation() {
Result ICommunicationService::CloseStation() {
return this->lanDiscovery.closeStation();
}

Result ICommunicationInterface::Disconnect() {
Result ICommunicationService::Disconnect() {
return this->lanDiscovery.disconnect();
}

Result ICommunicationInterface::CreateNetwork(CreateNetworkConfig data) {
Result ICommunicationService::CreateNetwork(CreateNetworkConfig data) {
return this->lanDiscovery.createNetwork(&data.securityConfig, &data.userConfig, &data.networkConfig);;
}

Result ICommunicationInterface::SetAdvertiseData(sf::InAutoSelectBuffer data) {
Result ICommunicationService::SetAdvertiseData(sf::InAutoSelectBuffer data) {
return lanDiscovery.setAdvertiseData(data.GetPointer(), data.GetSize());
}

Result ICommunicationInterface::GetState(sf::Out<u32> state) {
Result ICommunicationService::GetState(sf::Out<u32> state) {
state.SetValue(static_cast<u32>(this->lanDiscovery.getState()));

if (this->error_state) {
Expand All @@ -81,36 +81,36 @@ namespace ams::mitm::ldn {
return 0;
}

Result ICommunicationInterface::GetIpv4Address(sf::Out<u32> address, sf::Out<u32> netmask) {
Result ICommunicationService::GetIpv4Address(sf::Out<u32> address, sf::Out<u32> netmask) {
Result rc = ipinfoGetIpConfig(address.GetPointer(), netmask.GetPointer());

LogFormat("get_ipv4_address %x %x", address.GetValue(), netmask.GetValue());

return rc;
}

Result ICommunicationInterface::GetNetworkInfo(sf::Out<NetworkInfo> buffer) {
Result ICommunicationService::GetNetworkInfo(sf::Out<NetworkInfo> buffer) {
LogFormat("get_network_info %p state: %d", buffer.GetPointer(), static_cast<u32>(this->lanDiscovery.getState()));

return lanDiscovery.getNetworkInfo(buffer.GetPointer());
}

Result ICommunicationInterface::GetDisconnectReason(sf::Out<u32> reason) {
Result ICommunicationService::GetDisconnectReason(sf::Out<u32> reason) {
auto dr = static_cast<u32>(this->lanDiscovery.disconnect_reason);
LogFormat("GetDisconnectReason %p state: %d reason: %u", reason.GetPointer(), static_cast<u32>(this->lanDiscovery.getState()), dr);
reason.SetValue(dr);

return 0;
}

Result ICommunicationInterface::GetNetworkInfoLatestUpdate(sf::Out<NetworkInfo> buffer, sf::OutArray<NodeLatestUpdate> pUpdates) {
Result ICommunicationService::GetNetworkInfoLatestUpdate(sf::Out<NetworkInfo> buffer, sf::OutArray<NodeLatestUpdate> pUpdates) {
LogFormat("get_network_info_latest buffer %p", buffer.GetPointer());
LogFormat("get_network_info_latest pUpdates %p %" PRIu64, pUpdates.GetPointer(), pUpdates.GetSize());

return lanDiscovery.getNetworkInfo(buffer.GetPointer(), pUpdates.GetPointer(), pUpdates.GetSize());
}

Result ICommunicationInterface::GetSecurityParameter(sf::Out<SecurityParameter> out) {
Result ICommunicationService::GetSecurityParameter(sf::Out<SecurityParameter> out) {
Result rc = 0;

SecurityParameter data;
Expand All @@ -124,7 +124,7 @@ namespace ams::mitm::ldn {
return rc;
}

Result ICommunicationInterface::GetNetworkConfig(sf::Out<NetworkConfig> out) {
Result ICommunicationService::GetNetworkConfig(sf::Out<NetworkConfig> out) {
Result rc = 0;

NetworkConfig data;
Expand All @@ -138,12 +138,12 @@ namespace ams::mitm::ldn {
return rc;
}

Result ICommunicationInterface::AttachStateChangeEvent(sf::Out<sf::CopyHandle> handle) {
Result ICommunicationService::AttachStateChangeEvent(sf::Out<sf::CopyHandle> handle) {
handle.SetValue(this->state_event->GetReadableHandle());
return ResultSuccess();
}

Result ICommunicationInterface::Scan(sf::Out<u32> outCount, sf::OutAutoSelectArray<NetworkInfo> buffer, u16 channel, ScanFilter filter) {
Result ICommunicationService::Scan(sf::Out<u32> outCount, sf::OutAutoSelectArray<NetworkInfo> buffer, u16 channel, ScanFilter filter) {
Result rc = 0;
u16 count = buffer.GetSize();

Expand All @@ -155,51 +155,51 @@ namespace ams::mitm::ldn {
return rc;
}

Result ICommunicationInterface::Connect(ConnectNetworkData param, NetworkInfo &data) {
LogFormat("ICommunicationInterface::connect");
Result ICommunicationService::Connect(ConnectNetworkData param, NetworkInfo &data) {
LogFormat("ICommunicationService::connect");
LogHex(&data, sizeof(NetworkInfo));
LogHex(&param, sizeof(param));

return lanDiscovery.connect(&data, &param.userConfig, param.localCommunicationVersion);
}

void ICommunicationInterface::onEventFired() {
void ICommunicationService::onEventFired() {
if (this->state_event) {
LogFormat("onEventFired signal_event");
this->state_event->Signal();
}
}

/*nyi*/
Result ICommunicationInterface::SetStationAcceptPolicy(u8 policy) {
Result ICommunicationService::SetStationAcceptPolicy(u8 policy) {
return 0;
}

Result ICommunicationInterface::SetWirelessControllerRestriction() {
Result ICommunicationService::SetWirelessControllerRestriction() {
return 0;
}

Result ICommunicationInterface::ScanPrivate() {
Result ICommunicationService::ScanPrivate() {
return 0;
}

Result ICommunicationInterface::CreateNetworkPrivate() {
Result ICommunicationService::CreateNetworkPrivate() {
return 0;
}

Result ICommunicationInterface::Reject() {
Result ICommunicationService::Reject() {
return 0;
}

Result ICommunicationInterface::AddAcceptFilterEntry() {
Result ICommunicationService::AddAcceptFilterEntry() {
return 0;
}

Result ICommunicationInterface::ClearAcceptFilter() {
Result ICommunicationService::ClearAcceptFilter() {
return 0;
}

Result ICommunicationInterface::ConnectPrivate() {
Result ICommunicationService::ConnectPrivate() {
return 0;
}
}
15 changes: 7 additions & 8 deletions ldn_mitm/source/ldn_icommunication.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,22 @@
#include "lan_discovery.hpp"
#include "ldn_types.hpp"
#include "ipinfo.hpp"
#include "prov/icommunication.hpp"
#include "interfaces/icommunication.hpp"

namespace ams::mitm::ldn {
// class ICommunicationInterface : public sf::IServiceObject {
class ICommunicationInterface final{
class ICommunicationService final{
private:
LANDiscovery lanDiscovery;
os::SystemEvent *state_event;
u64 error_state;
public:
ICommunicationInterface() : state_event(nullptr), error_state(0) {
LogFormat("ICommunicationInterface");
ICommunicationService() : state_event(nullptr), error_state(0) {
LogFormat("ICommunicationService");
/* ... */
};

~ICommunicationInterface() {
LogFormat("~ICommunicationInterface");
~ICommunicationService() {
LogFormat("~ICommunicationService");
if (this->state_event != nullptr) {
delete this->state_event;
this->state_event = nullptr;
Expand Down Expand Up @@ -80,5 +79,5 @@ namespace ams::mitm::ldn {
Result InitializeSystem2(u64 unk, const sf::ClientProcessId &client_process_id);
/*-------------------------------------------------------------------------------*/
};
static_assert(ams::mitm::ldn::IsILdnCommunication<ICommunicationInterface>);
static_assert(ams::mitm::ldn::IsICommunicationInterface<ICommunicationService>);
}
1 change: 0 additions & 1 deletion ldn_mitm/source/ldnmitm_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace ams::mitm::ldn {
std::atomic_bool LdnConfig::LdnEnabled = true;
// LdnEnabled = true;

Result LdnConfig::SaveLogToFile() {
return ::SaveLogToFile();
Expand Down
3 changes: 1 addition & 2 deletions ldn_mitm/source/ldnmitm_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

#include <switch.h>
#include <stratosphere.hpp>
#include "prov/iconfig.hpp"
#include "interfaces/iconfig.hpp"

namespace ams::mitm::ldn {

// class LdnConfig : public sf::IServiceObject {
class LdnConfig final {
public:
static bool getEnabled() {
Expand Down
6 changes: 2 additions & 4 deletions ldn_mitm/source/ldnmitm_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,18 @@
#include "ldn_icommunication.hpp"

namespace ams::mitm::ldn {
Result LdnMitMService::CreateUserLocalCommunicationService(sf::Out<std::shared_ptr<ILdnCommunication>> out) {
Result LdnMitMService::CreateUserLocalCommunicationService(sf::Out<std::shared_ptr<ICommunicationInterface>> out) {
LogFormat("CreateUserLocalCommunicationService: enabled %d", static_cast<u32>(LdnConfig::getEnabled()));

if (LdnConfig::getEnabled()) {
// auto comm = std::make_shared<ILdnCommunication>();
auto comm = sf::MakeShared<ILdnCommunication, ICommunicationInterface>();
auto comm = sf::MakeShared<ICommunicationInterface, ICommunicationService>();
out.SetValue(std::move(comm));
return 0;
}

return sm::mitm::ResultShouldForwardToSession();
}
Result LdnMitMService::CreateLdnMitmConfigService(sf::Out<std::shared_ptr<ILdnConfig>> out) {
// out.SetValue(std::move(std::make_shared<ILdnConfig>()));
out.SetValue(std::move(sf::MakeShared<ILdnConfig, LdnConfig>()));

return 0;
Expand Down
5 changes: 2 additions & 3 deletions ldn_mitm/source/ldnmitm_service.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
#include "ldn_icommunication.hpp"
#include "ldnmitm_config.hpp"
#include "debug.hpp"
#include "prov/iservice.hpp"
#include "interfaces/iservice.hpp"

namespace ams::mitm::ldn {
// class LdnMitMService : public sf::IMitmServiceObject {
class LdnMitMService final{
protected:
std::shared_ptr<::Service> forward_service;
Expand All @@ -24,7 +23,7 @@ namespace ams::mitm::ldn {
// protected:
public:
/* Overridden commands. */
Result CreateUserLocalCommunicationService(sf::Out<std::shared_ptr<ILdnCommunication>> out);
Result CreateUserLocalCommunicationService(sf::Out<std::shared_ptr<ICommunicationInterface>> out);
Result CreateLdnMitmConfigService(sf::Out<std::shared_ptr<ILdnConfig>> out);
};
static_assert(ams::mitm::ldn::IsILdnMitMService<LdnMitMService>);
Expand Down

0 comments on commit c5964ea

Please sign in to comment.