2014-10-30 01:38:33 +00:00
|
|
|
// Copyright 2014 Citra Emulator Project
|
2014-12-17 05:38:14 +00:00
|
|
|
// Licensed under GPLv2 or any later version
|
2014-10-30 01:38:33 +00:00
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2016-12-10 12:51:50 +00:00
|
|
|
#include <array>
|
|
|
|
|
2015-01-21 01:16:47 +00:00
|
|
|
#include "common/logging/log.h"
|
2016-04-07 08:26:12 +00:00
|
|
|
#include "core/hle/kernel/event.h"
|
2016-09-21 06:52:38 +00:00
|
|
|
#include "core/hle/service/ac_u.h"
|
2014-10-30 01:38:33 +00:00
|
|
|
|
2016-12-10 12:51:50 +00:00
|
|
|
namespace Service {
|
|
|
|
namespace AC {
|
2014-10-30 01:38:33 +00:00
|
|
|
|
2016-10-27 06:29:05 +00:00
|
|
|
struct ACConfig {
|
|
|
|
std::array<u8, 0x200> data;
|
|
|
|
};
|
|
|
|
|
2016-11-02 06:38:30 +00:00
|
|
|
static ACConfig default_config{};
|
2016-10-26 12:53:09 +00:00
|
|
|
|
2016-11-02 06:38:30 +00:00
|
|
|
static bool ac_connected = false;
|
2016-10-26 12:53:09 +00:00
|
|
|
|
|
|
|
static Kernel::SharedPtr<Kernel::Event> close_event;
|
|
|
|
static Kernel::SharedPtr<Kernel::Event> connect_event;
|
|
|
|
static Kernel::SharedPtr<Kernel::Event> disconnect_event;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* AC_U::CreateDefaultConfig service function
|
|
|
|
* Inputs:
|
2016-10-27 06:29:05 +00:00
|
|
|
* 64 : ACConfig size << 14 | 2
|
|
|
|
* 65 : pointer to ACConfig struct
|
2016-10-26 12:53:09 +00:00
|
|
|
* Outputs:
|
|
|
|
* 1 : Result of function, 0 on success, otherwise error code
|
|
|
|
*/
|
2016-12-10 12:51:50 +00:00
|
|
|
static void CreateDefaultConfig(Interface* self) {
|
2016-10-26 12:53:09 +00:00
|
|
|
u32* cmd_buff = Kernel::GetCommandBuffer();
|
|
|
|
|
|
|
|
u32 ac_config_addr = cmd_buff[65];
|
|
|
|
|
2016-10-27 06:29:05 +00:00
|
|
|
ASSERT_MSG(cmd_buff[64] == (sizeof(ACConfig) << 14 | 2),
|
|
|
|
"Output buffer size not equal ACConfig size");
|
2016-10-26 12:53:09 +00:00
|
|
|
|
2016-10-27 06:29:05 +00:00
|
|
|
Memory::WriteBlock(ac_config_addr, &default_config, sizeof(ACConfig));
|
2016-10-26 12:53:09 +00:00
|
|
|
cmd_buff[1] = RESULT_SUCCESS.raw; // No error
|
|
|
|
|
|
|
|
LOG_WARNING(Service_AC, "(STUBBED) called");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* AC_U::ConnectAsync service function
|
|
|
|
* Inputs:
|
|
|
|
* 1 : ProcessId Header
|
|
|
|
* 3 : Copy Handle Header
|
|
|
|
* 4 : Connection Event handle
|
2016-10-27 06:29:05 +00:00
|
|
|
* 5 : ACConfig size << 14 | 2
|
|
|
|
* 6 : pointer to ACConfig struct
|
2016-10-26 12:53:09 +00:00
|
|
|
* Outputs:
|
|
|
|
* 1 : Result of function, 0 on success, otherwise error code
|
|
|
|
*/
|
2016-12-10 12:51:50 +00:00
|
|
|
static void ConnectAsync(Interface* self) {
|
2016-10-26 12:53:09 +00:00
|
|
|
u32* cmd_buff = Kernel::GetCommandBuffer();
|
|
|
|
|
|
|
|
connect_event = Kernel::g_handle_table.Get<Kernel::Event>(cmd_buff[4]);
|
|
|
|
if (connect_event) {
|
|
|
|
connect_event->name = "AC_U:connect_event";
|
|
|
|
connect_event->Signal();
|
|
|
|
ac_connected = true;
|
|
|
|
}
|
|
|
|
cmd_buff[1] = RESULT_SUCCESS.raw; // No error
|
|
|
|
|
|
|
|
LOG_WARNING(Service_AC, "(STUBBED) called");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* AC_U::GetConnectResult service function
|
|
|
|
* Inputs:
|
|
|
|
* 1 : ProcessId Header
|
|
|
|
* Outputs:
|
|
|
|
* 1 : Result of function, 0 on success, otherwise error code
|
|
|
|
*/
|
2016-12-10 12:51:50 +00:00
|
|
|
static void GetConnectResult(Interface* self) {
|
2016-10-26 12:53:09 +00:00
|
|
|
u32* cmd_buff = Kernel::GetCommandBuffer();
|
|
|
|
|
|
|
|
cmd_buff[1] = RESULT_SUCCESS.raw; // No error
|
|
|
|
|
|
|
|
LOG_WARNING(Service_AC, "(STUBBED) called");
|
|
|
|
}
|
|
|
|
|
2016-04-07 08:26:12 +00:00
|
|
|
/**
|
|
|
|
* AC_U::CloseAsync service function
|
|
|
|
* Inputs:
|
2016-10-26 12:53:09 +00:00
|
|
|
* 1 : ProcessId Header
|
|
|
|
* 3 : Copy Handle Header
|
2016-04-07 08:26:12 +00:00
|
|
|
* 4 : Event handle, should be signaled when AC connection is closed
|
|
|
|
* Outputs:
|
|
|
|
* 1 : Result of function, 0 on success, otherwise error code
|
|
|
|
*/
|
2016-12-10 12:51:50 +00:00
|
|
|
static void CloseAsync(Interface* self) {
|
2016-04-07 08:26:12 +00:00
|
|
|
u32* cmd_buff = Kernel::GetCommandBuffer();
|
|
|
|
|
2016-10-26 12:53:09 +00:00
|
|
|
if (ac_connected && disconnect_event) {
|
|
|
|
disconnect_event->Signal();
|
|
|
|
}
|
2016-04-07 08:26:12 +00:00
|
|
|
|
2016-10-26 12:53:09 +00:00
|
|
|
close_event = Kernel::g_handle_table.Get<Kernel::Event>(cmd_buff[4]);
|
|
|
|
if (close_event) {
|
|
|
|
close_event->name = "AC_U:close_event";
|
|
|
|
close_event->Signal();
|
2016-04-07 08:26:12 +00:00
|
|
|
}
|
2016-10-26 12:53:09 +00:00
|
|
|
|
|
|
|
ac_connected = false;
|
|
|
|
|
|
|
|
cmd_buff[1] = RESULT_SUCCESS.raw; // No error
|
|
|
|
LOG_WARNING(Service_AC, "(STUBBED) called");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* AC_U::GetCloseResult service function
|
|
|
|
* Inputs:
|
|
|
|
* 1 : ProcessId Header
|
|
|
|
* Outputs:
|
|
|
|
* 1 : Result of function, 0 on success, otherwise error code
|
|
|
|
*/
|
2016-12-10 12:51:50 +00:00
|
|
|
static void GetCloseResult(Interface* self) {
|
2016-10-26 12:53:09 +00:00
|
|
|
u32* cmd_buff = Kernel::GetCommandBuffer();
|
|
|
|
|
2016-04-07 08:26:12 +00:00
|
|
|
cmd_buff[1] = RESULT_SUCCESS.raw; // No error
|
|
|
|
|
|
|
|
LOG_WARNING(Service_AC, "(STUBBED) called");
|
|
|
|
}
|
2016-10-26 12:53:09 +00:00
|
|
|
|
2014-11-29 01:17:55 +00:00
|
|
|
/**
|
|
|
|
* AC_U::GetWifiStatus service function
|
|
|
|
* Outputs:
|
|
|
|
* 1 : Result of function, 0 on success, otherwise error code
|
|
|
|
* 2 : Output connection type, 0 = none, 1 = Old3DS Internet, 2 = New3DS Internet.
|
|
|
|
*/
|
2016-12-10 12:51:50 +00:00
|
|
|
static void GetWifiStatus(Interface* self) {
|
2014-12-14 05:30:11 +00:00
|
|
|
u32* cmd_buff = Kernel::GetCommandBuffer();
|
2014-11-29 01:17:55 +00:00
|
|
|
|
|
|
|
// TODO(purpasmart96): This function is only a stub,
|
|
|
|
// it returns a valid result without implementing full functionality.
|
|
|
|
|
2016-02-28 14:12:01 +00:00
|
|
|
cmd_buff[1] = RESULT_SUCCESS.raw; // No error
|
2016-09-18 00:38:01 +00:00
|
|
|
cmd_buff[2] = 0; // Connection type set to none
|
2014-11-29 01:17:55 +00:00
|
|
|
|
2014-12-06 01:53:49 +00:00
|
|
|
LOG_WARNING(Service_AC, "(STUBBED) called");
|
2014-11-29 01:17:55 +00:00
|
|
|
}
|
|
|
|
|
2016-10-26 12:53:09 +00:00
|
|
|
/**
|
|
|
|
* AC_U::GetInfraPriority service function
|
|
|
|
* Inputs:
|
2016-10-27 06:29:05 +00:00
|
|
|
* 1 : ACConfig size << 14 | 2
|
|
|
|
* 2 : pointer to ACConfig struct
|
2016-10-26 12:53:09 +00:00
|
|
|
* Outputs:
|
|
|
|
* 1 : Result of function, 0 on success, otherwise error code
|
|
|
|
* 2 : Infra Priority
|
|
|
|
*/
|
2016-12-10 12:51:50 +00:00
|
|
|
static void GetInfraPriority(Interface* self) {
|
2016-10-26 12:53:09 +00:00
|
|
|
u32* cmd_buff = Kernel::GetCommandBuffer();
|
|
|
|
|
|
|
|
cmd_buff[1] = RESULT_SUCCESS.raw; // No error
|
|
|
|
cmd_buff[2] = 0; // Infra Priority, default 0
|
|
|
|
|
|
|
|
LOG_WARNING(Service_AC, "(STUBBED) called");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* AC_U::SetRequestEulaVersion service function
|
|
|
|
* Inputs:
|
|
|
|
* 1 : Eula Version major
|
|
|
|
* 2 : Eula Version minor
|
2016-10-27 06:29:05 +00:00
|
|
|
* 3 : ACConfig size << 14 | 2
|
|
|
|
* 4 : Input pointer to ACConfig struct
|
|
|
|
* 64 : ACConfig size << 14 | 2
|
|
|
|
* 65 : Output pointer to ACConfig struct
|
2016-10-26 12:53:09 +00:00
|
|
|
* Outputs:
|
|
|
|
* 1 : Result of function, 0 on success, otherwise error code
|
|
|
|
* 2 : Infra Priority
|
|
|
|
*/
|
2016-12-10 12:51:50 +00:00
|
|
|
static void SetRequestEulaVersion(Interface* self) {
|
2016-10-26 12:53:09 +00:00
|
|
|
u32* cmd_buff = Kernel::GetCommandBuffer();
|
|
|
|
|
2016-10-27 06:29:05 +00:00
|
|
|
u32 major = cmd_buff[1] & 0xFF;
|
|
|
|
u32 minor = cmd_buff[2] & 0xFF;
|
2016-10-26 12:53:09 +00:00
|
|
|
|
2016-10-27 06:29:05 +00:00
|
|
|
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");
|
2016-10-26 12:53:09 +00:00
|
|
|
|
|
|
|
cmd_buff[1] = RESULT_SUCCESS.raw; // No error
|
|
|
|
cmd_buff[2] = 0; // Infra Priority
|
|
|
|
|
2016-10-27 06:29:05 +00:00
|
|
|
LOG_WARNING(Service_AC, "(STUBBED) called, major=%u, minor=%u", major, minor);
|
2016-10-26 12:53:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* AC_U::RegisterDisconnectEvent service function
|
|
|
|
* Inputs:
|
|
|
|
* 1 : ProcessId Header
|
|
|
|
* 3 : Copy Handle Header
|
|
|
|
* 4 : Event handle, should be signaled when AC connection is closed
|
|
|
|
* Outputs:
|
|
|
|
* 1 : Result of function, 0 on success, otherwise error code
|
|
|
|
*/
|
2016-12-10 12:51:50 +00:00
|
|
|
static void RegisterDisconnectEvent(Interface* self) {
|
2016-10-26 12:53:09 +00:00
|
|
|
u32* cmd_buff = Kernel::GetCommandBuffer();
|
|
|
|
|
|
|
|
disconnect_event = Kernel::g_handle_table.Get<Kernel::Event>(cmd_buff[4]);
|
|
|
|
if (disconnect_event) {
|
|
|
|
disconnect_event->name = "AC_U:disconnect_event";
|
|
|
|
}
|
|
|
|
cmd_buff[1] = RESULT_SUCCESS.raw; // No error
|
|
|
|
|
|
|
|
LOG_WARNING(Service_AC, "(STUBBED) called");
|
|
|
|
}
|
|
|
|
|
2016-02-28 14:12:01 +00:00
|
|
|
/**
|
|
|
|
* AC_U::IsConnected service function
|
|
|
|
* Outputs:
|
|
|
|
* 1 : Result of function, 0 on success, otherwise error code
|
|
|
|
* 2 : bool, is connected
|
|
|
|
*/
|
2016-12-10 12:51:50 +00:00
|
|
|
static void IsConnected(Interface* self) {
|
2016-02-28 14:12:01 +00:00
|
|
|
u32* cmd_buff = Kernel::GetCommandBuffer();
|
|
|
|
|
|
|
|
cmd_buff[1] = RESULT_SUCCESS.raw; // No error
|
2016-10-26 12:53:09 +00:00
|
|
|
cmd_buff[2] = ac_connected;
|
2016-02-28 14:12:01 +00:00
|
|
|
|
|
|
|
LOG_WARNING(Service_AC, "(STUBBED) called");
|
|
|
|
}
|
|
|
|
|
2016-11-20 05:50:48 +00:00
|
|
|
/**
|
|
|
|
* AC_U::SetClientVersion service function
|
|
|
|
* Inputs:
|
|
|
|
* 1 : Used SDK Version
|
|
|
|
* Outputs:
|
|
|
|
* 1 : Result of function, 0 on success, otherwise error code
|
|
|
|
*/
|
2016-12-10 12:51:50 +00:00
|
|
|
static void SetClientVersion(Interface* self) {
|
2016-11-20 05:50:48 +00:00
|
|
|
u32* cmd_buff = Kernel::GetCommandBuffer();
|
|
|
|
|
|
|
|
const u32 version = cmd_buff[1];
|
|
|
|
self->SetVersion(version);
|
|
|
|
|
|
|
|
LOG_WARNING(Service_AC, "(STUBBED) called, version: 0x%08X", version);
|
|
|
|
|
|
|
|
cmd_buff[1] = RESULT_SUCCESS.raw; // No error
|
|
|
|
}
|
|
|
|
|
2014-10-30 01:38:33 +00:00
|
|
|
const Interface::FunctionInfo FunctionTable[] = {
|
2016-10-26 12:53:09 +00:00
|
|
|
{0x00010000, CreateDefaultConfig, "CreateDefaultConfig"},
|
|
|
|
{0x00040006, ConnectAsync, "ConnectAsync"},
|
|
|
|
{0x00050002, GetConnectResult, "GetConnectResult"},
|
|
|
|
{0x00070002, nullptr, "CancelConnectAsync"},
|
2016-09-18 00:38:01 +00:00
|
|
|
{0x00080004, CloseAsync, "CloseAsync"},
|
2016-10-26 12:53:09 +00:00
|
|
|
{0x00090002, GetCloseResult, "GetCloseResult"},
|
2016-09-18 00:38:01 +00:00
|
|
|
{0x000A0000, nullptr, "GetLastErrorCode"},
|
2016-10-26 12:53:09 +00:00
|
|
|
{0x000C0000, nullptr, "GetStatus"},
|
2016-09-18 00:38:01 +00:00
|
|
|
{0x000D0000, GetWifiStatus, "GetWifiStatus"},
|
|
|
|
{0x000E0042, nullptr, "GetCurrentAPInfo"},
|
|
|
|
{0x00100042, nullptr, "GetCurrentNZoneInfo"},
|
|
|
|
{0x00110042, nullptr, "GetNZoneApNumService"},
|
2016-10-26 12:53:09 +00:00
|
|
|
{0x001D0042, nullptr, "ScanAPs"},
|
2016-09-18 00:38:01 +00:00
|
|
|
{0x00240042, nullptr, "AddDenyApType"},
|
2016-10-26 12:53:09 +00:00
|
|
|
{0x00270002, GetInfraPriority, "GetInfraPriority"},
|
|
|
|
{0x002D0082, SetRequestEulaVersion, "SetRequestEulaVersion"},
|
|
|
|
{0x00300004, RegisterDisconnectEvent, "RegisterDisconnectEvent"},
|
2016-09-18 00:38:01 +00:00
|
|
|
{0x003C0042, nullptr, "GetAPSSIDList"},
|
|
|
|
{0x003E0042, IsConnected, "IsConnected"},
|
2016-11-20 05:50:48 +00:00
|
|
|
{0x00400042, SetClientVersion, "SetClientVersion"},
|
2014-10-30 01:38:33 +00:00
|
|
|
};
|
|
|
|
|
2016-12-10 12:51:50 +00:00
|
|
|
AC_U::AC_U() {
|
2015-01-30 18:56:49 +00:00
|
|
|
Register(FunctionTable);
|
2016-10-26 12:53:09 +00:00
|
|
|
|
|
|
|
ac_connected = false;
|
|
|
|
|
|
|
|
close_event = nullptr;
|
|
|
|
connect_event = nullptr;
|
|
|
|
disconnect_event = nullptr;
|
|
|
|
}
|
|
|
|
|
2016-12-10 12:51:50 +00:00
|
|
|
AC_U::~AC_U() {
|
2016-10-26 12:53:09 +00:00
|
|
|
close_event = nullptr;
|
|
|
|
connect_event = nullptr;
|
|
|
|
disconnect_event = nullptr;
|
2014-10-30 01:38:33 +00:00
|
|
|
}
|
|
|
|
|
2016-12-10 12:51:50 +00:00
|
|
|
} // namespace AC
|
|
|
|
} // namespace Service
|