2016-12-08 07:43:27 +00:00
|
|
|
// Copyright 2016 Citra Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2017-12-01 19:37:00 +00:00
|
|
|
#include "core/hle/ipc_helpers.h"
|
2016-12-29 20:38:47 +00:00
|
|
|
#include "core/hle/kernel/event.h"
|
2016-12-08 07:43:27 +00:00
|
|
|
#include "core/hle/service/nfc/nfc.h"
|
|
|
|
#include "core/hle/service/nfc/nfc_m.h"
|
|
|
|
#include "core/hle/service/nfc/nfc_u.h"
|
|
|
|
|
|
|
|
namespace Service {
|
|
|
|
namespace NFC {
|
|
|
|
|
2018-03-05 08:48:09 +00:00
|
|
|
void Module::Interface::Initialize(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp(ctx, 0x01, 1, 0);
|
|
|
|
u8 param = rp.Pop<u8>();
|
2017-01-14 07:42:56 +00:00
|
|
|
|
2018-03-05 08:48:09 +00:00
|
|
|
nfc->nfc_tag_state = TagState::NotScanning;
|
2017-01-14 07:42:56 +00:00
|
|
|
|
2018-03-05 08:48:09 +00:00
|
|
|
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
|
|
|
|
rb.Push(RESULT_SUCCESS);
|
2018-06-29 11:18:07 +00:00
|
|
|
LOG_WARNING(Service_NFC, "(STUBBED) called, param={}", param);
|
2017-01-14 07:42:56 +00:00
|
|
|
}
|
|
|
|
|
2018-03-05 08:48:09 +00:00
|
|
|
void Module::Interface::Shutdown(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp(ctx, 0x02, 1, 0);
|
|
|
|
u8 param = rp.Pop<u8>();
|
2017-01-14 07:42:56 +00:00
|
|
|
|
2018-03-05 08:48:09 +00:00
|
|
|
nfc->nfc_tag_state = TagState::NotInitialized;
|
2017-01-14 07:42:56 +00:00
|
|
|
|
2018-03-05 08:48:09 +00:00
|
|
|
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
|
|
|
|
rb.Push(RESULT_SUCCESS);
|
2018-06-29 11:18:07 +00:00
|
|
|
LOG_WARNING(Service_NFC, "(STUBBED) called, param={}", param);
|
2017-01-14 07:42:56 +00:00
|
|
|
}
|
|
|
|
|
2018-03-05 08:48:09 +00:00
|
|
|
void Module::Interface::StartCommunication(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp(ctx, 0x03, 0, 0);
|
2017-01-14 07:42:56 +00:00
|
|
|
|
2018-03-05 08:48:09 +00:00
|
|
|
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
|
|
|
|
rb.Push(RESULT_SUCCESS);
|
2018-06-29 11:18:07 +00:00
|
|
|
LOG_WARNING(Service_NFC, "(STUBBED) called");
|
2017-01-14 07:42:56 +00:00
|
|
|
}
|
|
|
|
|
2018-03-05 08:48:09 +00:00
|
|
|
void Module::Interface::StopCommunication(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp(ctx, 0x04, 0, 0);
|
2017-01-14 07:42:56 +00:00
|
|
|
|
2018-03-05 08:48:09 +00:00
|
|
|
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
|
|
|
|
rb.Push(RESULT_SUCCESS);
|
2018-06-29 11:18:07 +00:00
|
|
|
LOG_WARNING(Service_NFC, "(STUBBED) called");
|
2017-01-14 07:42:56 +00:00
|
|
|
}
|
|
|
|
|
2018-03-05 08:48:09 +00:00
|
|
|
void Module::Interface::StartTagScanning(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp(ctx, 0x05, 1, 0); // 0x00050040
|
2017-12-01 19:37:00 +00:00
|
|
|
u16 in_val = rp.Pop<u16>();
|
2017-01-14 07:42:56 +00:00
|
|
|
|
2017-12-01 19:37:00 +00:00
|
|
|
ResultCode result = RESULT_SUCCESS;
|
2017-01-14 07:42:56 +00:00
|
|
|
|
2017-12-01 19:37:00 +00:00
|
|
|
// TODO(shinyquagsire23): Implement NFC tag detection, for now stub result
|
|
|
|
result = ResultCode(ErrCodes::CommandInvalidForState, ErrorModule::NFC,
|
|
|
|
ErrorSummary::InvalidState, ErrorLevel::Status);
|
|
|
|
|
|
|
|
if (result == RESULT_SUCCESS) {
|
2018-03-05 08:48:09 +00:00
|
|
|
nfc->nfc_tag_state = TagState::TagInRange;
|
|
|
|
nfc->tag_in_range_event->Signal();
|
2017-12-01 19:37:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
|
|
|
|
rb.Push(result);
|
2018-06-29 11:18:07 +00:00
|
|
|
LOG_WARNING(Service_NFC, "(STUBBED) called, in_val={:04x}", in_val);
|
2017-01-14 07:42:56 +00:00
|
|
|
}
|
|
|
|
|
2018-03-05 08:48:09 +00:00
|
|
|
void Module::Interface::StopTagScanning(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp(ctx, 0x06, 0, 0);
|
2017-01-14 07:42:56 +00:00
|
|
|
|
2018-03-05 08:48:09 +00:00
|
|
|
nfc->nfc_tag_state = TagState::NotScanning;
|
2017-01-14 07:42:56 +00:00
|
|
|
|
2018-03-05 08:48:09 +00:00
|
|
|
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
|
|
|
|
rb.Push(RESULT_SUCCESS);
|
2018-06-29 11:18:07 +00:00
|
|
|
LOG_WARNING(Service_NFC, "(STUBBED) called");
|
2017-01-14 07:42:56 +00:00
|
|
|
}
|
|
|
|
|
2018-03-05 08:48:09 +00:00
|
|
|
void Module::Interface::LoadAmiiboData(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp(ctx, 0x07, 0, 0);
|
2017-01-14 07:42:56 +00:00
|
|
|
|
2018-03-05 08:48:09 +00:00
|
|
|
nfc->nfc_tag_state = TagState::TagDataLoaded;
|
2017-01-14 07:42:56 +00:00
|
|
|
|
2018-03-05 08:48:09 +00:00
|
|
|
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
|
|
|
|
rb.Push(RESULT_SUCCESS);
|
2018-06-29 11:18:07 +00:00
|
|
|
LOG_WARNING(Service_NFC, "(STUBBED) called");
|
2017-01-14 07:42:56 +00:00
|
|
|
}
|
|
|
|
|
2018-03-05 08:48:09 +00:00
|
|
|
void Module::Interface::ResetTagScanState(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp(ctx, 0x08, 0, 0);
|
2017-01-14 07:42:56 +00:00
|
|
|
|
2018-03-05 08:48:09 +00:00
|
|
|
nfc->nfc_tag_state = TagState::NotScanning;
|
2017-01-14 07:42:56 +00:00
|
|
|
|
2018-03-05 08:48:09 +00:00
|
|
|
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
|
|
|
|
rb.Push(RESULT_SUCCESS);
|
2018-06-29 11:18:07 +00:00
|
|
|
LOG_WARNING(Service_NFC, "(STUBBED) called");
|
2017-01-14 07:42:56 +00:00
|
|
|
}
|
2016-12-29 20:38:47 +00:00
|
|
|
|
2018-03-05 08:48:09 +00:00
|
|
|
void Module::Interface::GetTagInRangeEvent(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp(ctx, 0x0B, 0, 0);
|
2016-12-29 20:38:47 +00:00
|
|
|
|
2018-03-05 08:48:09 +00:00
|
|
|
IPC::RequestBuilder rb = rp.MakeBuilder(1, 2);
|
|
|
|
rb.Push(RESULT_SUCCESS);
|
|
|
|
rb.PushCopyObjects(nfc->tag_in_range_event);
|
2018-06-29 11:18:07 +00:00
|
|
|
LOG_WARNING(Service_NFC, "(STUBBED) called");
|
2016-12-29 20:38:47 +00:00
|
|
|
}
|
|
|
|
|
2018-03-05 08:48:09 +00:00
|
|
|
void Module::Interface::GetTagOutOfRangeEvent(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp(ctx, 0x0C, 0, 0);
|
2017-01-14 07:42:56 +00:00
|
|
|
|
2018-03-05 08:48:09 +00:00
|
|
|
IPC::RequestBuilder rb = rp.MakeBuilder(1, 2);
|
|
|
|
rb.Push(RESULT_SUCCESS);
|
|
|
|
rb.PushCopyObjects(nfc->tag_out_of_range_event);
|
2018-06-29 11:18:07 +00:00
|
|
|
LOG_WARNING(Service_NFC, "(STUBBED) called");
|
2017-01-14 07:42:56 +00:00
|
|
|
}
|
|
|
|
|
2018-03-05 08:48:09 +00:00
|
|
|
void Module::Interface::GetTagState(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp(ctx, 0x0D, 0, 0);
|
2017-01-14 07:42:56 +00:00
|
|
|
|
2018-03-05 08:48:09 +00:00
|
|
|
IPC::RequestBuilder rb = rp.MakeBuilder(2, 0);
|
|
|
|
rb.Push(RESULT_SUCCESS);
|
|
|
|
rb.PushEnum(nfc->nfc_tag_state);
|
2018-06-29 11:18:07 +00:00
|
|
|
LOG_DEBUG(Service_NFC, "(STUBBED) called");
|
2017-01-14 07:42:56 +00:00
|
|
|
}
|
|
|
|
|
2018-03-05 08:48:09 +00:00
|
|
|
void Module::Interface::CommunicationGetStatus(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp(ctx, 0x0F, 0, 0);
|
2017-01-14 07:42:56 +00:00
|
|
|
|
2018-03-05 08:48:09 +00:00
|
|
|
IPC::RequestBuilder rb = rp.MakeBuilder(2, 0);
|
|
|
|
rb.Push(RESULT_SUCCESS);
|
|
|
|
rb.PushEnum(nfc->nfc_status);
|
2018-06-29 11:18:07 +00:00
|
|
|
LOG_DEBUG(Service_NFC, "(STUBBED) called");
|
2017-01-14 07:42:56 +00:00
|
|
|
}
|
|
|
|
|
2018-03-05 08:48:09 +00:00
|
|
|
Module::Interface::Interface(std::shared_ptr<Module> nfc, const char* name, u32 max_session)
|
|
|
|
: ServiceFramework(name, max_session), nfc(std::move(nfc)) {}
|
2016-12-29 20:38:47 +00:00
|
|
|
|
2018-03-05 08:48:09 +00:00
|
|
|
Module::Interface::~Interface() = default;
|
|
|
|
|
|
|
|
Module::Module() {
|
2016-12-29 20:38:47 +00:00
|
|
|
tag_in_range_event =
|
|
|
|
Kernel::Event::Create(Kernel::ResetType::OneShot, "NFC::tag_in_range_event");
|
2017-01-14 07:42:56 +00:00
|
|
|
tag_out_of_range_event =
|
|
|
|
Kernel::Event::Create(Kernel::ResetType::OneShot, "NFC::tag_out_range_event");
|
2016-12-29 20:38:47 +00:00
|
|
|
}
|
|
|
|
|
2018-03-05 08:48:09 +00:00
|
|
|
Module::~Module() = default;
|
|
|
|
|
|
|
|
void InstallInterfaces(SM::ServiceManager& service_manager) {
|
|
|
|
auto nfc = std::make_shared<Module>();
|
|
|
|
std::make_shared<NFC_M>(nfc)->InstallAsService(service_manager);
|
|
|
|
std::make_shared<NFC_U>(nfc)->InstallAsService(service_manager);
|
2016-12-08 07:43:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace NFC
|
|
|
|
} // namespace Service
|