1
0
Fork 0

Merge pull request #2992 from Subv/ac_srvframework

Services/AC: Converted the ac:i and ac:u services to the new service framework.
This commit is contained in:
James Rowe 2017-11-04 10:42:09 -06:00 committed by GitHub
commit c14f802381
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 300 additions and 284 deletions

View File

@ -2,11 +2,10 @@
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#include <array>
#include "common/common_types.h"
#include "common/logging/log.h"
#include "core/hle/ipc.h"
#include "core/hle/ipc_helpers.h"
#include "core/hle/kernel/event.h"
#include "core/hle/kernel/handle_table.h"
#include "core/hle/result.h"
@ -17,169 +16,170 @@
namespace Service {
namespace AC {
void Module::Interface::CreateDefaultConfig(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx, 0x1, 0, 0);
struct ACConfig {
std::array<u8, 0x200> data;
};
std::size_t desc_size;
VAddr ac_config_addr = rp.PeekStaticBuffer(0, &desc_size);
static ACConfig default_config{};
ASSERT_MSG(desc_size >= sizeof(Module::ACConfig),
"Output buffer size can't fit ACConfig structure");
static bool ac_connected = false;
Memory::WriteBlock(ac_config_addr, &ac->default_config, sizeof(ACConfig));
static Kernel::SharedPtr<Kernel::Event> close_event;
static Kernel::SharedPtr<Kernel::Event> connect_event;
static Kernel::SharedPtr<Kernel::Event> disconnect_event;
void CreateDefaultConfig(Interface* self) {
u32* cmd_buff = Kernel::GetCommandBuffer();
u32 ac_config_addr = cmd_buff[65];
ASSERT_MSG(cmd_buff[64] == (sizeof(ACConfig) << 14 | 2),
"Output buffer size not equal ACConfig size");
Memory::WriteBlock(ac_config_addr, &default_config, sizeof(ACConfig));
cmd_buff[1] = RESULT_SUCCESS.raw; // No error
IPC::RequestBuilder rb = rp.MakeBuilder(1, 2);
rb.Push(RESULT_SUCCESS);
rb.PushStaticBuffer(ac_config_addr, sizeof(ACConfig), 0);
LOG_WARNING(Service_AC, "(STUBBED) called");
}
void ConnectAsync(Interface* self) {
u32* cmd_buff = Kernel::GetCommandBuffer();
void Module::Interface::ConnectAsync(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx, 0x4, 0, 6);
connect_event = Kernel::g_handle_table.Get<Kernel::Event>(cmd_buff[4]);
if (connect_event) {
connect_event->name = "AC:connect_event";
connect_event->Signal();
ac_connected = true;
rp.Skip(2, false); // ProcessId descriptor
ac->connect_event = rp.PopObject<Kernel::Event>();
if (ac->connect_event) {
ac->connect_event->name = "AC:connect_event";
ac->connect_event->Signal();
ac->ac_connected = true;
}
cmd_buff[1] = RESULT_SUCCESS.raw; // No error
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
rb.Push(RESULT_SUCCESS);
LOG_WARNING(Service_AC, "(STUBBED) called");
}
void GetConnectResult(Interface* self) {
u32* cmd_buff = Kernel::GetCommandBuffer();
void Module::Interface::GetConnectResult(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx, 0x5, 0, 2);
rp.Skip(2, false); // ProcessId descriptor
cmd_buff[1] = RESULT_SUCCESS.raw; // No error
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
rb.Push(RESULT_SUCCESS);
}
void Module::Interface::CloseAsync(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx, 0x8, 0, 4);
rp.Skip(2, false); // ProcessId descriptor
ac->close_event = rp.PopObject<Kernel::Event>();
if (ac->ac_connected && ac->disconnect_event) {
ac->disconnect_event->Signal();
}
if (ac->close_event) {
ac->close_event->name = "AC:close_event";
ac->close_event->Signal();
}
ac->ac_connected = false;
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
rb.Push(RESULT_SUCCESS);
}
void Module::Interface::GetCloseResult(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx, 0x9, 0, 2);
rp.Skip(2, false); // ProcessId descriptor
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
rb.Push(RESULT_SUCCESS);
LOG_WARNING(Service_AC, "(STUBBED) called");
}
void CloseAsync(Interface* self) {
u32* cmd_buff = Kernel::GetCommandBuffer();
if (ac_connected && disconnect_event) {
disconnect_event->Signal();
}
close_event = Kernel::g_handle_table.Get<Kernel::Event>(cmd_buff[4]);
if (close_event) {
close_event->name = "AC:close_event";
close_event->Signal();
}
ac_connected = false;
cmd_buff[1] = RESULT_SUCCESS.raw; // No error
LOG_WARNING(Service_AC, "(STUBBED) called");
}
void GetCloseResult(Interface* self) {
u32* cmd_buff = Kernel::GetCommandBuffer();
cmd_buff[1] = RESULT_SUCCESS.raw; // No error
LOG_WARNING(Service_AC, "(STUBBED) called");
}
void GetWifiStatus(Interface* self) {
u32* cmd_buff = Kernel::GetCommandBuffer();
void Module::Interface::GetWifiStatus(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx, 0xD, 0, 0);
// TODO(purpasmart96): This function is only a stub,
// it returns a valid result without implementing full functionality.
cmd_buff[1] = RESULT_SUCCESS.raw; // No error
cmd_buff[2] = 0; // Connection type set to none
IPC::RequestBuilder rb = rp.MakeBuilder(2, 0);
rb.Push(RESULT_SUCCESS);
rb.Push<u32>(0); // Connection type set to none
LOG_WARNING(Service_AC, "(STUBBED) called");
}
void GetInfraPriority(Interface* self) {
u32* cmd_buff = Kernel::GetCommandBuffer();
void Module::Interface::GetInfraPriority(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx, 0x27, 0, 2);
VAddr ac_config = rp.PopStaticBuffer();
cmd_buff[1] = RESULT_SUCCESS.raw; // No error
cmd_buff[2] = 0; // Infra Priority, default 0
IPC::RequestBuilder rb = rp.MakeBuilder(2, 0);
rb.Push(RESULT_SUCCESS);
rb.Push<u32>(0); // Infra Priority, default 0
LOG_WARNING(Service_AC, "(STUBBED) called");
}
void SetRequestEulaVersion(Interface* self) {
u32* cmd_buff = Kernel::GetCommandBuffer();
void Module::Interface::SetRequestEulaVersion(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx, 0x2D, 2, 2);
u32 major = cmd_buff[1] & 0xFF;
u32 minor = cmd_buff[2] & 0xFF;
u32 major = rp.Pop<u8>();
u32 minor = rp.Pop<u8>();
ASSERT_MSG(cmd_buff[3] == (sizeof(ACConfig) << 14 | 2),
"Input buffer size not equal ACConfig size");
ASSERT_MSG(cmd_buff[64] == (sizeof(ACConfig) << 14 | 2),
"Output buffer size not equal ACConfig size");
VAddr ac_config = rp.PopStaticBuffer();
cmd_buff[1] = RESULT_SUCCESS.raw; // No error
cmd_buff[2] = 0; // Infra Priority
// TODO(Subv): Copy over the input ACConfig to the stored ACConfig.
IPC::RequestBuilder rb = rp.MakeBuilder(1, 2);
rb.Push(RESULT_SUCCESS);
rb.PushStaticBuffer(ac_config, sizeof(ACConfig), 0);
LOG_WARNING(Service_AC, "(STUBBED) called, major=%u, minor=%u", major, minor);
}
void RegisterDisconnectEvent(Interface* self) {
u32* cmd_buff = Kernel::GetCommandBuffer();
void Module::Interface::RegisterDisconnectEvent(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx, 0x30, 0, 4);
rp.Skip(2, false); // ProcessId descriptor
disconnect_event = Kernel::g_handle_table.Get<Kernel::Event>(cmd_buff[4]);
if (disconnect_event) {
disconnect_event->name = "AC:disconnect_event";
ac->disconnect_event = rp.PopObject<Kernel::Event>();
if (ac->disconnect_event) {
ac->disconnect_event->name = "AC:disconnect_event";
}
cmd_buff[1] = RESULT_SUCCESS.raw; // No error
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
rb.Push(RESULT_SUCCESS);
LOG_WARNING(Service_AC, "(STUBBED) called");
}
void IsConnected(Interface* self) {
u32* cmd_buff = Kernel::GetCommandBuffer();
void Module::Interface::IsConnected(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx, 0x3E, 1, 2);
u32 unk = rp.Pop<u32>();
u32 unk_descriptor = rp.Pop<u32>();
u32 unk_param = rp.Pop<u32>();
cmd_buff[1] = RESULT_SUCCESS.raw; // No error
cmd_buff[2] = ac_connected;
IPC::RequestBuilder rb = rp.MakeBuilder(2, 0);
rb.Push(RESULT_SUCCESS);
rb.Push(ac->ac_connected);
LOG_WARNING(Service_AC, "(STUBBED) called");
LOG_WARNING(Service_AC, "(STUBBED) called unk=%08X descriptor=%08X param=%08X", unk,
unk_descriptor, unk_param);
}
void SetClientVersion(Interface* self) {
u32* cmd_buff = Kernel::GetCommandBuffer();
void Module::Interface::SetClientVersion(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx, 0x40, 1, 2);
const u32 version = cmd_buff[1];
self->SetVersion(version);
u32 version = rp.Pop<u32>();
rp.Skip(2, false); // ProcessId descriptor
LOG_WARNING(Service_AC, "(STUBBED) called, version: 0x%08X", version);
cmd_buff[1] = RESULT_SUCCESS.raw; // No error
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
rb.Push(RESULT_SUCCESS);
}
void Init() {
AddService(new AC_I);
AddService(new AC_U);
Module::Interface::Interface(std::shared_ptr<Module> ac, const char* name, u32 max_session)
: ac(std::move(ac)), ServiceFramework(name, max_session) {}
ac_connected = false;
close_event = nullptr;
connect_event = nullptr;
disconnect_event = nullptr;
}
void Shutdown() {
ac_connected = false;
close_event = nullptr;
connect_event = nullptr;
disconnect_event = nullptr;
void InstallInterfaces(SM::ServiceManager& service_manager) {
auto ac = std::make_shared<Module>();
std::make_shared<AC_I>(ac)->InstallAsService(service_manager);
std::make_shared<AC_U>(ac)->InstallAsService(service_manager);
}
} // namespace AC

View File

@ -4,11 +4,22 @@
#pragma once
#include <array>
#include <memory>
#include "core/hle/kernel/kernel.h"
#include "core/hle/service/service.h"
namespace Kernel {
class Event;
}
namespace Service {
class Interface;
namespace AC {
class Module final {
public:
class Interface : public ServiceFramework<Interface> {
public:
Interface(std::shared_ptr<Module> ac, const char* name, u32 max_session);
/**
* AC::CreateDefaultConfig service function
@ -18,7 +29,7 @@ namespace AC {
* Outputs:
* 1 : Result of function, 0 on success, otherwise error code
*/
void CreateDefaultConfig(Interface* self);
void CreateDefaultConfig(Kernel::HLERequestContext& ctx);
/**
* AC::ConnectAsync service function
@ -31,7 +42,7 @@ void CreateDefaultConfig(Interface* self);
* Outputs:
* 1 : Result of function, 0 on success, otherwise error code
*/
void ConnectAsync(Interface* self);
void ConnectAsync(Kernel::HLERequestContext& ctx);
/**
* AC::GetConnectResult service function
@ -40,7 +51,7 @@ void ConnectAsync(Interface* self);
* Outputs:
* 1 : Result of function, 0 on success, otherwise error code
*/
void GetConnectResult(Interface* self);
void GetConnectResult(Kernel::HLERequestContext& ctx);
/**
* AC::CloseAsync service function
@ -51,7 +62,7 @@ void GetConnectResult(Interface* self);
* Outputs:
* 1 : Result of function, 0 on success, otherwise error code
*/
void CloseAsync(Interface* self);
void CloseAsync(Kernel::HLERequestContext& ctx);
/**
* AC::GetCloseResult service function
@ -60,7 +71,7 @@ void CloseAsync(Interface* self);
* Outputs:
* 1 : Result of function, 0 on success, otherwise error code
*/
void GetCloseResult(Interface* self);
void GetCloseResult(Kernel::HLERequestContext& ctx);
/**
* AC::GetWifiStatus service function
@ -68,7 +79,7 @@ void GetCloseResult(Interface* self);
* 1 : Result of function, 0 on success, otherwise error code
* 2 : Output connection type, 0 = none, 1 = Old3DS Internet, 2 = New3DS Internet.
*/
void GetWifiStatus(Interface* self);
void GetWifiStatus(Kernel::HLERequestContext& ctx);
/**
* AC::GetInfraPriority service function
@ -79,7 +90,7 @@ void GetWifiStatus(Interface* self);
* 1 : Result of function, 0 on success, otherwise error code
* 2 : Infra Priority
*/
void GetInfraPriority(Interface* self);
void GetInfraPriority(Kernel::HLERequestContext& ctx);
/**
* AC::SetRequestEulaVersion service function
@ -94,7 +105,7 @@ void GetInfraPriority(Interface* self);
* 1 : Result of function, 0 on success, otherwise error code
* 2 : Infra Priority
*/
void SetRequestEulaVersion(Interface* self);
void SetRequestEulaVersion(Kernel::HLERequestContext& ctx);
/**
* AC::RegisterDisconnectEvent service function
@ -105,7 +116,7 @@ void SetRequestEulaVersion(Interface* self);
* Outputs:
* 1 : Result of function, 0 on success, otherwise error code
*/
void RegisterDisconnectEvent(Interface* self);
void RegisterDisconnectEvent(Kernel::HLERequestContext& ctx);
/**
* AC::IsConnected service function
@ -113,7 +124,7 @@ void RegisterDisconnectEvent(Interface* self);
* 1 : Result of function, 0 on success, otherwise error code
* 2 : bool, is connected
*/
void IsConnected(Interface* self);
void IsConnected(Kernel::HLERequestContext& ctx);
/**
* AC::SetClientVersion service function
@ -122,13 +133,27 @@ void IsConnected(Interface* self);
* Outputs:
* 1 : Result of function, 0 on success, otherwise error code
*/
void SetClientVersion(Interface* self);
void SetClientVersion(Kernel::HLERequestContext& ctx);
/// Initialize AC service
void Init();
protected:
std::shared_ptr<Module> ac;
};
/// Shutdown AC service
void Shutdown();
protected:
struct ACConfig {
std::array<u8, 0x200> data;
};
ACConfig default_config{};
bool ac_connected = false;
Kernel::SharedPtr<Kernel::Event> close_event;
Kernel::SharedPtr<Kernel::Event> connect_event;
Kernel::SharedPtr<Kernel::Event> disconnect_event;
};
void InstallInterfaces(SM::ServiceManager& service_manager);
} // namespace AC
} // namespace Service

View File

@ -2,37 +2,36 @@
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#include "core/hle/service/ac/ac.h"
#include "core/hle/service/ac/ac_i.h"
namespace Service {
namespace AC {
const Interface::FunctionInfo FunctionTable[] = {
{0x00010000, CreateDefaultConfig, "CreateDefaultConfig"},
{0x00040006, ConnectAsync, "ConnectAsync"},
{0x00050002, GetConnectResult, "GetConnectResult"},
// TODO(Subv): Find out the correct number of concurrent sessions allowed
AC_I::AC_I(std::shared_ptr<Module> ac) : Module::Interface(std::move(ac), "ac:i", 1) {
static const FunctionInfo functions[] = {
{0x00010000, &AC_I::CreateDefaultConfig, "CreateDefaultConfig"},
{0x00040006, &AC_I::ConnectAsync, "ConnectAsync"},
{0x00050002, &AC_I::GetConnectResult, "GetConnectResult"},
{0x00070002, nullptr, "CancelConnectAsync"},
{0x00080004, CloseAsync, "CloseAsync"},
{0x00090002, GetCloseResult, "GetCloseResult"},
{0x00080004, &AC_I::CloseAsync, "CloseAsync"},
{0x00090002, &AC_I::GetCloseResult, "GetCloseResult"},
{0x000A0000, nullptr, "GetLastErrorCode"},
{0x000C0000, nullptr, "GetStatus"},
{0x000D0000, GetWifiStatus, "GetWifiStatus"},
{0x000D0000, &AC_I::GetWifiStatus, "GetWifiStatus"},
{0x000E0042, nullptr, "GetCurrentAPInfo"},
{0x00100042, nullptr, "GetCurrentNZoneInfo"},
{0x00110042, nullptr, "GetNZoneApNumService"},
{0x001D0042, nullptr, "ScanAPs"},
{0x00240042, nullptr, "AddDenyApType"},
{0x00270002, GetInfraPriority, "GetInfraPriority"},
{0x002D0082, SetRequestEulaVersion, "SetRequestEulaVersion"},
{0x00300004, RegisterDisconnectEvent, "RegisterDisconnectEvent"},
{0x00270002, &AC_I::GetInfraPriority, "GetInfraPriority"},
{0x002D0082, &AC_I::SetRequestEulaVersion, "SetRequestEulaVersion"},
{0x00300004, &AC_I::RegisterDisconnectEvent, "RegisterDisconnectEvent"},
{0x003C0042, nullptr, "GetAPSSIDList"},
{0x003E0042, IsConnected, "IsConnected"},
{0x00400042, SetClientVersion, "SetClientVersion"},
{0x003E0042, &AC_I::IsConnected, "IsConnected"},
{0x00400042, &AC_I::SetClientVersion, "SetClientVersion"},
};
AC_I::AC_I() {
Register(FunctionTable);
RegisterHandlers(functions);
}
} // namespace AC

View File

@ -4,18 +4,15 @@
#pragma once
#include "core/hle/service/service.h"
#include <memory>
#include "core/hle/service/ac/ac.h"
namespace Service {
namespace AC {
class AC_I final : public Interface {
class AC_I final : public Module::Interface {
public:
AC_I();
std::string GetPortName() const override {
return "ac:i";
}
explicit AC_I(std::shared_ptr<Module> ac);
};
} // namespace AC

View File

@ -2,37 +2,36 @@
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#include "core/hle/service/ac/ac.h"
#include "core/hle/service/ac/ac_u.h"
namespace Service {
namespace AC {
const Interface::FunctionInfo FunctionTable[] = {
{0x00010000, CreateDefaultConfig, "CreateDefaultConfig"},
{0x00040006, ConnectAsync, "ConnectAsync"},
{0x00050002, GetConnectResult, "GetConnectResult"},
// TODO(Subv): Find out the correct number of concurrent sessions allowed
AC_U::AC_U(std::shared_ptr<Module> ac) : Module::Interface(std::move(ac), "ac:u", 1) {
static const FunctionInfo functions[] = {
{0x00010000, &AC_U::CreateDefaultConfig, "CreateDefaultConfig"},
{0x00040006, &AC_U::ConnectAsync, "ConnectAsync"},
{0x00050002, &AC_U::GetConnectResult, "GetConnectResult"},
{0x00070002, nullptr, "CancelConnectAsync"},
{0x00080004, CloseAsync, "CloseAsync"},
{0x00090002, GetCloseResult, "GetCloseResult"},
{0x00080004, &AC_U::CloseAsync, "CloseAsync"},
{0x00090002, &AC_U::GetCloseResult, "GetCloseResult"},
{0x000A0000, nullptr, "GetLastErrorCode"},
{0x000C0000, nullptr, "GetStatus"},
{0x000D0000, GetWifiStatus, "GetWifiStatus"},
{0x000D0000, &AC_U::GetWifiStatus, "GetWifiStatus"},
{0x000E0042, nullptr, "GetCurrentAPInfo"},
{0x00100042, nullptr, "GetCurrentNZoneInfo"},
{0x00110042, nullptr, "GetNZoneApNumService"},
{0x001D0042, nullptr, "ScanAPs"},
{0x00240042, nullptr, "AddDenyApType"},
{0x00270002, GetInfraPriority, "GetInfraPriority"},
{0x002D0082, SetRequestEulaVersion, "SetRequestEulaVersion"},
{0x00300004, RegisterDisconnectEvent, "RegisterDisconnectEvent"},
{0x00270002, &AC_U::GetInfraPriority, "GetInfraPriority"},
{0x002D0082, &AC_U::SetRequestEulaVersion, "SetRequestEulaVersion"},
{0x00300004, &AC_U::RegisterDisconnectEvent, "RegisterDisconnectEvent"},
{0x003C0042, nullptr, "GetAPSSIDList"},
{0x003E0042, IsConnected, "IsConnected"},
{0x00400042, SetClientVersion, "SetClientVersion"},
{0x003E0042, &AC_U::IsConnected, "IsConnected"},
{0x00400042, &AC_U::SetClientVersion, "SetClientVersion"},
};
AC_U::AC_U() {
Register(FunctionTable);
RegisterHandlers(functions);
}
} // namespace AC

View File

@ -4,18 +4,15 @@
#pragma once
#include "core/hle/service/service.h"
#include <memory>
#include "core/hle/service/ac/ac.h"
namespace Service {
namespace AC {
class AC_U final : public Interface {
class AC_U final : public Module::Interface {
public:
AC_U();
std::string GetPortName() const override {
return "ac:u";
}
explicit AC_U(std::shared_ptr<Module> ac);
};
} // namespace AC

View File

@ -216,11 +216,11 @@ void Init() {
SM::ServiceManager::InstallInterfaces(SM::g_service_manager);
NS::InstallInterfaces(*SM::g_service_manager);
AC::InstallInterfaces(*SM::g_service_manager);
AddNamedPort(new ERR::ERR_F);
FS::ArchiveInit();
AC::Init();
ACT::Init();
AM::Init();
APT::Init();
@ -273,7 +273,6 @@ void Shutdown() {
BOSS::Shutdown();
APT::Shutdown();
AM::Shutdown();
AC::Shutdown();
FS::ArchiveShutdown();
SM::g_service_manager = nullptr;