nfc.cpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. // Copyright 2016 Citra Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include "core/hle/kernel/event.h"
  5. #include "core/hle/service/nfc/nfc.h"
  6. #include "core/hle/service/nfc/nfc_m.h"
  7. #include "core/hle/service/nfc/nfc_u.h"
  8. namespace Service {
  9. namespace NFC {
  10. static Kernel::SharedPtr<Kernel::Event> tag_in_range_event;
  11. static Kernel::SharedPtr<Kernel::Event> tag_out_of_range_event;
  12. static TagState nfc_tag_state = TagState::NotInitialized;
  13. static CommunicationStatus nfc_status = CommunicationStatus::NfcInitialized;
  14. void Initialize(Interface* self) {
  15. u32* cmd_buff = Kernel::GetCommandBuffer();
  16. u8 param = static_cast<u8>(cmd_buff[1] & 0xFF);
  17. nfc_tag_state = TagState::NotScanning;
  18. cmd_buff[1] = RESULT_SUCCESS.raw; // No error
  19. LOG_WARNING(Service_NFC, "(STUBBED) called, param=%u", param);
  20. }
  21. void Shutdown(Interface* self) {
  22. u32* cmd_buff = Kernel::GetCommandBuffer();
  23. u8 param = static_cast<u8>(cmd_buff[1] & 0xFF);
  24. nfc_tag_state = TagState::NotInitialized;
  25. cmd_buff[1] = RESULT_SUCCESS.raw; // No error
  26. LOG_WARNING(Service_NFC, "(STUBBED) called, param=%u", param);
  27. }
  28. void StartCommunication(Interface* self) {
  29. u32* cmd_buff = Kernel::GetCommandBuffer();
  30. cmd_buff[1] = RESULT_SUCCESS.raw; // No error
  31. LOG_WARNING(Service_NFC, "(STUBBED) called");
  32. }
  33. void StopCommunication(Interface* self) {
  34. u32* cmd_buff = Kernel::GetCommandBuffer();
  35. cmd_buff[1] = RESULT_SUCCESS.raw; // No error
  36. LOG_WARNING(Service_NFC, "(STUBBED) called");
  37. }
  38. void StartTagScanning(Interface* self) {
  39. u32* cmd_buff = Kernel::GetCommandBuffer();
  40. nfc_tag_state = TagState::TagInRange;
  41. tag_in_range_event->Signal();
  42. cmd_buff[1] = RESULT_SUCCESS.raw; // No error
  43. LOG_WARNING(Service_NFC, "(STUBBED) called");
  44. }
  45. void StopTagScanning(Interface* self) {
  46. u32* cmd_buff = Kernel::GetCommandBuffer();
  47. nfc_tag_state = TagState::NotScanning;
  48. cmd_buff[1] = RESULT_SUCCESS.raw; // No error
  49. LOG_WARNING(Service_NFC, "(STUBBED) called");
  50. }
  51. void LoadAmiiboData(Interface* self) {
  52. u32* cmd_buff = Kernel::GetCommandBuffer();
  53. nfc_tag_state = TagState::TagDataLoaded;
  54. cmd_buff[1] = RESULT_SUCCESS.raw; // No error
  55. LOG_WARNING(Service_NFC, "(STUBBED) called");
  56. }
  57. void ResetTagScanState(Interface* self) {
  58. u32* cmd_buff = Kernel::GetCommandBuffer();
  59. nfc_tag_state = TagState::NotScanning;
  60. cmd_buff[1] = RESULT_SUCCESS.raw; // No error
  61. LOG_WARNING(Service_NFC, "(STUBBED) called");
  62. }
  63. void GetTagInRangeEvent(Interface* self) {
  64. u32* cmd_buff = Kernel::GetCommandBuffer();
  65. cmd_buff[0] = IPC::MakeHeader(0xB, 1, 2);
  66. cmd_buff[1] = RESULT_SUCCESS.raw;
  67. cmd_buff[2] = IPC::CopyHandleDesc();
  68. cmd_buff[3] = Kernel::g_handle_table.Create(tag_in_range_event).MoveFrom();
  69. LOG_WARNING(Service_NFC, "(STUBBED) called");
  70. }
  71. void GetTagOutOfRangeEvent(Interface* self) {
  72. u32* cmd_buff = Kernel::GetCommandBuffer();
  73. cmd_buff[0] = IPC::MakeHeader(0xC, 1, 2);
  74. cmd_buff[1] = RESULT_SUCCESS.raw;
  75. cmd_buff[2] = IPC::CopyHandleDesc();
  76. cmd_buff[3] = Kernel::g_handle_table.Create(tag_out_of_range_event).MoveFrom();
  77. LOG_WARNING(Service_NFC, "(STUBBED) called");
  78. }
  79. void GetTagState(Interface* self) {
  80. u32* cmd_buff = Kernel::GetCommandBuffer();
  81. cmd_buff[1] = RESULT_SUCCESS.raw; // No error
  82. cmd_buff[2] = static_cast<u8>(nfc_tag_state);
  83. LOG_DEBUG(Service_NFC, "(STUBBED) called");
  84. }
  85. void CommunicationGetStatus(Interface* self) {
  86. u32* cmd_buff = Kernel::GetCommandBuffer();
  87. cmd_buff[1] = RESULT_SUCCESS.raw; // No error
  88. cmd_buff[2] = static_cast<u8>(nfc_status);
  89. LOG_DEBUG(Service_NFC, "(STUBBED) called");
  90. }
  91. void Init() {
  92. AddService(new NFC_M());
  93. AddService(new NFC_U());
  94. tag_in_range_event =
  95. Kernel::Event::Create(Kernel::ResetType::OneShot, "NFC::tag_in_range_event");
  96. tag_out_of_range_event =
  97. Kernel::Event::Create(Kernel::ResetType::OneShot, "NFC::tag_out_range_event");
  98. nfc_tag_state = TagState::NotInitialized;
  99. }
  100. void Shutdown() {
  101. tag_in_range_event = nullptr;
  102. tag_out_of_range_event = nullptr;
  103. }
  104. } // namespace NFC
  105. } // namespace Service