mirror of
				https://github.com/PabloMK7/citra.git
				synced 2025-10-30 21:30:04 +00:00 
			
		
		
		
	Merge pull request #2434 from mailwl/nfc-amiibo
Service/NFC: stub some functions
This commit is contained in:
		
						commit
						3feb3ce283
					
				
					 4 changed files with 249 additions and 20 deletions
				
			
		|  | @ -11,6 +11,81 @@ namespace Service { | ||||||
| namespace NFC { | namespace NFC { | ||||||
| 
 | 
 | ||||||
| static Kernel::SharedPtr<Kernel::Event> tag_in_range_event; | static Kernel::SharedPtr<Kernel::Event> tag_in_range_event; | ||||||
|  | static Kernel::SharedPtr<Kernel::Event> tag_out_of_range_event; | ||||||
|  | static TagState nfc_tag_state = TagState::NotInitialized; | ||||||
|  | static CommunicationStatus nfc_status = CommunicationStatus::NfcInitialized; | ||||||
|  | 
 | ||||||
|  | void Initialize(Interface* self) { | ||||||
|  |     u32* cmd_buff = Kernel::GetCommandBuffer(); | ||||||
|  | 
 | ||||||
|  |     u8 param = static_cast<u8>(cmd_buff[1] & 0xFF); | ||||||
|  | 
 | ||||||
|  |     nfc_tag_state = TagState::NotScanning; | ||||||
|  | 
 | ||||||
|  |     cmd_buff[1] = RESULT_SUCCESS.raw; // No error
 | ||||||
|  |     LOG_WARNING(Service_NFC, "(STUBBED) called, param=%u", param); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | void Shutdown(Interface* self) { | ||||||
|  |     u32* cmd_buff = Kernel::GetCommandBuffer(); | ||||||
|  | 
 | ||||||
|  |     u8 param = static_cast<u8>(cmd_buff[1] & 0xFF); | ||||||
|  |     nfc_tag_state = TagState::NotInitialized; | ||||||
|  | 
 | ||||||
|  |     cmd_buff[1] = RESULT_SUCCESS.raw; // No error
 | ||||||
|  |     LOG_WARNING(Service_NFC, "(STUBBED) called, param=%u", param); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | void StartCommunication(Interface* self) { | ||||||
|  |     u32* cmd_buff = Kernel::GetCommandBuffer(); | ||||||
|  | 
 | ||||||
|  |     cmd_buff[1] = RESULT_SUCCESS.raw; // No error
 | ||||||
|  |     LOG_WARNING(Service_NFC, "(STUBBED) called"); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | void StopCommunication(Interface* self) { | ||||||
|  |     u32* cmd_buff = Kernel::GetCommandBuffer(); | ||||||
|  | 
 | ||||||
|  |     cmd_buff[1] = RESULT_SUCCESS.raw; // No error
 | ||||||
|  |     LOG_WARNING(Service_NFC, "(STUBBED) called"); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | void StartTagScanning(Interface* self) { | ||||||
|  |     u32* cmd_buff = Kernel::GetCommandBuffer(); | ||||||
|  | 
 | ||||||
|  |     nfc_tag_state = TagState::TagInRange; | ||||||
|  |     tag_in_range_event->Signal(); | ||||||
|  | 
 | ||||||
|  |     cmd_buff[1] = RESULT_SUCCESS.raw; // No error
 | ||||||
|  |     LOG_WARNING(Service_NFC, "(STUBBED) called"); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | void StopTagScanning(Interface* self) { | ||||||
|  |     u32* cmd_buff = Kernel::GetCommandBuffer(); | ||||||
|  | 
 | ||||||
|  |     nfc_tag_state = TagState::NotScanning; | ||||||
|  | 
 | ||||||
|  |     cmd_buff[1] = RESULT_SUCCESS.raw; // No error
 | ||||||
|  |     LOG_WARNING(Service_NFC, "(STUBBED) called"); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | void LoadAmiiboData(Interface* self) { | ||||||
|  |     u32* cmd_buff = Kernel::GetCommandBuffer(); | ||||||
|  | 
 | ||||||
|  |     nfc_tag_state = TagState::TagDataLoaded; | ||||||
|  | 
 | ||||||
|  |     cmd_buff[1] = RESULT_SUCCESS.raw; // No error
 | ||||||
|  |     LOG_WARNING(Service_NFC, "(STUBBED) called"); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | void ResetTagScanState(Interface* self) { | ||||||
|  |     u32* cmd_buff = Kernel::GetCommandBuffer(); | ||||||
|  | 
 | ||||||
|  |     nfc_tag_state = TagState::NotScanning; | ||||||
|  | 
 | ||||||
|  |     cmd_buff[1] = RESULT_SUCCESS.raw; // No error
 | ||||||
|  |     LOG_WARNING(Service_NFC, "(STUBBED) called"); | ||||||
|  | } | ||||||
| 
 | 
 | ||||||
| void GetTagInRangeEvent(Interface* self) { | void GetTagInRangeEvent(Interface* self) { | ||||||
|     u32* cmd_buff = Kernel::GetCommandBuffer(); |     u32* cmd_buff = Kernel::GetCommandBuffer(); | ||||||
|  | @ -22,16 +97,46 @@ void GetTagInRangeEvent(Interface* self) { | ||||||
|     LOG_WARNING(Service_NFC, "(STUBBED) called"); |     LOG_WARNING(Service_NFC, "(STUBBED) called"); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | void GetTagOutOfRangeEvent(Interface* self) { | ||||||
|  |     u32* cmd_buff = Kernel::GetCommandBuffer(); | ||||||
|  | 
 | ||||||
|  |     cmd_buff[0] = IPC::MakeHeader(0xC, 1, 2); | ||||||
|  |     cmd_buff[1] = RESULT_SUCCESS.raw; | ||||||
|  |     cmd_buff[2] = IPC::CopyHandleDesc(); | ||||||
|  |     cmd_buff[3] = Kernel::g_handle_table.Create(tag_out_of_range_event).MoveFrom(); | ||||||
|  |     LOG_WARNING(Service_NFC, "(STUBBED) called"); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | void GetTagState(Interface* self) { | ||||||
|  |     u32* cmd_buff = Kernel::GetCommandBuffer(); | ||||||
|  | 
 | ||||||
|  |     cmd_buff[1] = RESULT_SUCCESS.raw; // No error
 | ||||||
|  |     cmd_buff[2] = static_cast<u8>(nfc_tag_state); | ||||||
|  |     LOG_DEBUG(Service_NFC, "(STUBBED) called"); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | void CommunicationGetStatus(Interface* self) { | ||||||
|  |     u32* cmd_buff = Kernel::GetCommandBuffer(); | ||||||
|  | 
 | ||||||
|  |     cmd_buff[1] = RESULT_SUCCESS.raw; // No error
 | ||||||
|  |     cmd_buff[2] = static_cast<u8>(nfc_status); | ||||||
|  |     LOG_DEBUG(Service_NFC, "(STUBBED) called"); | ||||||
|  | } | ||||||
|  | 
 | ||||||
| void Init() { | void Init() { | ||||||
|     AddService(new NFC_M()); |     AddService(new NFC_M()); | ||||||
|     AddService(new NFC_U()); |     AddService(new NFC_U()); | ||||||
| 
 | 
 | ||||||
|     tag_in_range_event = |     tag_in_range_event = | ||||||
|         Kernel::Event::Create(Kernel::ResetType::OneShot, "NFC::tag_in_range_event"); |         Kernel::Event::Create(Kernel::ResetType::OneShot, "NFC::tag_in_range_event"); | ||||||
|  |     tag_out_of_range_event = | ||||||
|  |         Kernel::Event::Create(Kernel::ResetType::OneShot, "NFC::tag_out_range_event"); | ||||||
|  |     nfc_tag_state = TagState::NotInitialized; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void Shutdown() { | void Shutdown() { | ||||||
|     tag_in_range_event = nullptr; |     tag_in_range_event = nullptr; | ||||||
|  |     tag_out_of_range_event = nullptr; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| } // namespace NFC
 | } // namespace NFC
 | ||||||
|  |  | ||||||
|  | @ -4,12 +4,103 @@ | ||||||
| 
 | 
 | ||||||
| #pragma once | #pragma once | ||||||
| 
 | 
 | ||||||
|  | #include "common/common_types.h" | ||||||
|  | 
 | ||||||
| namespace Service { | namespace Service { | ||||||
| 
 | 
 | ||||||
| class Interface; | class Interface; | ||||||
| 
 | 
 | ||||||
| namespace NFC { | namespace NFC { | ||||||
| 
 | 
 | ||||||
|  | enum class TagState : u8 { | ||||||
|  |     NotInitialized = 0, | ||||||
|  |     NotScanning = 1, | ||||||
|  |     Scanning = 2, | ||||||
|  |     TagInRange = 3, | ||||||
|  |     TagOutOfRange = 4, | ||||||
|  |     TagDataLoaded = 5, | ||||||
|  | }; | ||||||
|  | 
 | ||||||
|  | enum class CommunicationStatus : u8 { | ||||||
|  |     AttemptInitialize = 1, | ||||||
|  |     NfcInitialized = 2, | ||||||
|  | }; | ||||||
|  | 
 | ||||||
|  | /**
 | ||||||
|  |  * NFC::Initialize service function | ||||||
|  |  *  Inputs: | ||||||
|  |  *      0 : Header code [0x00010040] | ||||||
|  |  *      1 : (u8) unknown parameter. Can be either value 0x1 or 0x2 | ||||||
|  |  *  Outputs: | ||||||
|  |  *      1 : Result of function, 0 on success, otherwise error code | ||||||
|  |  */ | ||||||
|  | void Initialize(Interface* self); | ||||||
|  | 
 | ||||||
|  | /**
 | ||||||
|  |  * NFC::Shutdown service function | ||||||
|  |  *  Inputs: | ||||||
|  |  *      0 : Header code [0x00020040] | ||||||
|  |  *      1 : (u8) unknown parameter | ||||||
|  |  *  Outputs: | ||||||
|  |  *      1 : Result of function, 0 on success, otherwise error code | ||||||
|  |  */ | ||||||
|  | void Shutdown(Interface* self); | ||||||
|  | 
 | ||||||
|  | /**
 | ||||||
|  |  * NFC::StartCommunication service function | ||||||
|  |  *  Inputs: | ||||||
|  |  *      0 : Header code [0x00030000] | ||||||
|  |  *  Outputs: | ||||||
|  |  *      1 : Result of function, 0 on success, otherwise error code | ||||||
|  |  */ | ||||||
|  | void StartCommunication(Interface* self); | ||||||
|  | 
 | ||||||
|  | /**
 | ||||||
|  |  * NFC::StopCommunication service function | ||||||
|  |  *  Inputs: | ||||||
|  |  *      0 : Header code [0x00040000] | ||||||
|  |  *  Outputs: | ||||||
|  |  *      1 : Result of function, 0 on success, otherwise error code | ||||||
|  |  */ | ||||||
|  | void StopCommunication(Interface* self); | ||||||
|  | 
 | ||||||
|  | /**
 | ||||||
|  |  * NFC::StartTagScanning service function | ||||||
|  |  *  Inputs: | ||||||
|  |  *      0 : Header code [0x00050040] | ||||||
|  |  *      1 : (u16) unknown. This is normally 0x0 | ||||||
|  |  *  Outputs: | ||||||
|  |  *      1 : Result of function, 0 on success, otherwise error code | ||||||
|  |  */ | ||||||
|  | void StartTagScanning(Interface* self); | ||||||
|  | 
 | ||||||
|  | /**
 | ||||||
|  |  * NFC::StopTagScanning service function | ||||||
|  |  *  Inputs: | ||||||
|  |  *      0 : Header code [0x00060000] | ||||||
|  |  *  Outputs: | ||||||
|  |  *      1 : Result of function, 0 on success, otherwise error code | ||||||
|  |  */ | ||||||
|  | void StopTagScanning(Interface* self); | ||||||
|  | 
 | ||||||
|  | /**
 | ||||||
|  |  * NFC::LoadAmiiboData service function | ||||||
|  |  *  Inputs: | ||||||
|  |  *      0 : Header code [0x00070000] | ||||||
|  |  *  Outputs: | ||||||
|  |  *      1 : Result of function, 0 on success, otherwise error code | ||||||
|  |  */ | ||||||
|  | void LoadAmiiboData(Interface* self); | ||||||
|  | 
 | ||||||
|  | /**
 | ||||||
|  |  * NFC::ResetTagScanState service function | ||||||
|  |  *  Inputs: | ||||||
|  |  *      0 : Header code [0x00080000] | ||||||
|  |  *  Outputs: | ||||||
|  |  *      1 : Result of function, 0 on success, otherwise error code | ||||||
|  |  */ | ||||||
|  | void ResetTagScanState(Interface* self); | ||||||
|  | 
 | ||||||
| /**
 | /**
 | ||||||
|  * NFC::GetTagInRangeEvent service function |  * NFC::GetTagInRangeEvent service function | ||||||
|  *  Inputs: |  *  Inputs: | ||||||
|  | @ -21,6 +112,37 @@ namespace NFC { | ||||||
|  */ |  */ | ||||||
| void GetTagInRangeEvent(Interface* self); | void GetTagInRangeEvent(Interface* self); | ||||||
| 
 | 
 | ||||||
|  | /**
 | ||||||
|  |  * NFC::GetTagOutOfRangeEvent service function | ||||||
|  |  *  Inputs: | ||||||
|  |  *      0 : Header code [0x000C0000] | ||||||
|  |  *  Outputs: | ||||||
|  |  *      1 : Result of function, 0 on success, otherwise error code | ||||||
|  |  *      2 : Copy handle descriptor | ||||||
|  |  *      3 : Event Handle | ||||||
|  |  */ | ||||||
|  | void GetTagOutOfRangeEvent(Interface* self); | ||||||
|  | 
 | ||||||
|  | /**
 | ||||||
|  |  * NFC::GetTagState service function | ||||||
|  |  *  Inputs: | ||||||
|  |  *      0 : Header code [0x000D0000] | ||||||
|  |  *  Outputs: | ||||||
|  |  *      1 : Result of function, 0 on success, otherwise error code | ||||||
|  |  *      2 : (u8) Tag state | ||||||
|  |  */ | ||||||
|  | void GetTagState(Interface* self); | ||||||
|  | 
 | ||||||
|  | /**
 | ||||||
|  |  * NFC::CommunicationGetStatus service function | ||||||
|  |  *  Inputs: | ||||||
|  |  *      0 : Header code [0x000F0000] | ||||||
|  |  *  Outputs: | ||||||
|  |  *      1 : Result of function, 0 on success, otherwise error code | ||||||
|  |  *      2 : (u8) Communication state | ||||||
|  |  */ | ||||||
|  | void CommunicationGetStatus(Interface* self); | ||||||
|  | 
 | ||||||
| /// Initialize all NFC services.
 | /// Initialize all NFC services.
 | ||||||
| void Init(); | void Init(); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -11,18 +11,19 @@ namespace NFC { | ||||||
| const Interface::FunctionInfo FunctionTable[] = { | const Interface::FunctionInfo FunctionTable[] = { | ||||||
|     // clang-format off
 |     // clang-format off
 | ||||||
|     // nfc:u shared commands
 |     // nfc:u shared commands
 | ||||||
|     {0x00010040, nullptr, "Initialize"}, |     {0x00010040, Initialize, "Initialize"}, | ||||||
|     {0x00020040, nullptr, "Shutdown"}, |     {0x00020040, Shutdown, "Shutdown"}, | ||||||
|     {0x00030000, nullptr, "StartCommunication"}, |     {0x00030000, StartCommunication, "StartCommunication"}, | ||||||
|     {0x00040000, nullptr, "StopCommunication"}, |     {0x00040000, StopCommunication, "StopCommunication"}, | ||||||
|     {0x00050040, nullptr, "StartTagScanning"}, |     {0x00050040, StartTagScanning, "StartTagScanning"}, | ||||||
|     {0x00060000, nullptr, "StopTagScanning"}, |     {0x00060000, StopTagScanning, "StopTagScanning"}, | ||||||
|     {0x00070000, nullptr, "LoadAmiiboData"}, |     {0x00070000, LoadAmiiboData, "LoadAmiiboData"}, | ||||||
|     {0x00080000, nullptr, "ResetTagScanState"}, |     {0x00080000, ResetTagScanState, "ResetTagScanState"}, | ||||||
|     {0x00090002, nullptr, "UpdateStoredAmiiboData"}, |     {0x00090002, nullptr, "UpdateStoredAmiiboData"}, | ||||||
|     {0x000B0000, GetTagInRangeEvent, "GetTagInRangeEvent"}, |     {0x000B0000, GetTagInRangeEvent, "GetTagInRangeEvent"}, | ||||||
|     {0x000D0000, nullptr, "GetTagState"}, |     {0x000C0000, GetTagOutOfRangeEvent, "GetTagOutOfRangeEvent"}, | ||||||
|     {0x000F0000, nullptr, "CommunicationGetStatus"}, |     {0x000D0000, GetTagState, "GetTagState"}, | ||||||
|  |     {0x000F0000, CommunicationGetStatus, "CommunicationGetStatus"}, | ||||||
|     {0x00100000, nullptr, "GetTagInfo2"}, |     {0x00100000, nullptr, "GetTagInfo2"}, | ||||||
|     {0x00110000, nullptr, "GetTagInfo"}, |     {0x00110000, nullptr, "GetTagInfo"}, | ||||||
|     {0x00120000, nullptr, "CommunicationGetResult"}, |     {0x00120000, nullptr, "CommunicationGetResult"}, | ||||||
|  |  | ||||||
|  | @ -10,18 +10,19 @@ namespace NFC { | ||||||
| 
 | 
 | ||||||
| const Interface::FunctionInfo FunctionTable[] = { | const Interface::FunctionInfo FunctionTable[] = { | ||||||
|     // clang-format off
 |     // clang-format off
 | ||||||
|     {0x00010040, nullptr, "Initialize"}, |     {0x00010040, Initialize, "Initialize"}, | ||||||
|     {0x00020040, nullptr, "Shutdown"}, |     {0x00020040, Shutdown, "Shutdown"}, | ||||||
|     {0x00030000, nullptr, "StartCommunication"}, |     {0x00030000, StartCommunication, "StartCommunication"}, | ||||||
|     {0x00040000, nullptr, "StopCommunication"}, |     {0x00040000, StopCommunication, "StopCommunication"}, | ||||||
|     {0x00050040, nullptr, "StartTagScanning"}, |     {0x00050040, StartTagScanning, "StartTagScanning"}, | ||||||
|     {0x00060000, nullptr, "StopTagScanning"}, |     {0x00060000, StopTagScanning, "StopTagScanning"}, | ||||||
|     {0x00070000, nullptr, "LoadAmiiboData"}, |     {0x00070000, LoadAmiiboData, "LoadAmiiboData"}, | ||||||
|     {0x00080000, nullptr, "ResetTagScanState"}, |     {0x00080000, ResetTagScanState, "ResetTagScanState"}, | ||||||
|     {0x00090002, nullptr, "UpdateStoredAmiiboData"}, |     {0x00090002, nullptr, "UpdateStoredAmiiboData"}, | ||||||
|     {0x000B0000, GetTagInRangeEvent, "GetTagInRangeEvent"}, |     {0x000B0000, GetTagInRangeEvent, "GetTagInRangeEvent"}, | ||||||
|     {0x000D0000, nullptr, "GetTagState"}, |     {0x000C0000, GetTagOutOfRangeEvent, "GetTagOutOfRangeEvent"}, | ||||||
|     {0x000F0000, nullptr, "CommunicationGetStatus"}, |     {0x000D0000, GetTagState, "GetTagState"}, | ||||||
|  |     {0x000F0000, CommunicationGetStatus, "CommunicationGetStatus"}, | ||||||
|     {0x00100000, nullptr, "GetTagInfo2"}, |     {0x00100000, nullptr, "GetTagInfo2"}, | ||||||
|     {0x00110000, nullptr, "GetTagInfo"}, |     {0x00110000, nullptr, "GetTagInfo"}, | ||||||
|     {0x00120000, nullptr, "CommunicationGetResult"}, |     {0x00120000, nullptr, "CommunicationGetResult"}, | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue