Difference between revisions of "NFC services"

From Nintendo Switch Brew
Jump to navigation Jump to search
Line 46: Line 46:
 
| 2 || [[#ListDevices]]
 
| 2 || [[#ListDevices]]
 
|-
 
|-
| 3 || StartDetection
+
| 3 || [[#StartDetection_2|StartDetection]]
 
|-
 
|-
| 4 || StopDetection
+
| 4 || [[#StopDetection]]
 
|-
 
|-
 
| 5 || [[#ReadMifare|Read]]
 
| 5 || [[#ReadMifare|Read]]
Line 110: Line 110:
 
| 407 || [4.0.0+] [[#AttachAvailabilityChangeEvent]]
 
| 407 || [4.0.0+] [[#AttachAvailabilityChangeEvent]]
 
|-
 
|-
| 408 || [4.0.0+] StartDetection
+
| 408 || [4.0.0+] [[#StartDetection]]
 
|-
 
|-
| 409 || [4.0.0+] StopDetection
+
| 409 || [4.0.0+] [[#StopDetection]]
 
|-
 
|-
 
| 410 || [4.0.0+] [[#GetTagInfo]]
 
| 410 || [4.0.0+] [[#GetTagInfo]]
Line 131: Line 131:
 
|}
 
|}
  
== GetStateOld ==
+
=== GetStateOld ===
 
No input, returns an output u32.
 
No input, returns an output u32.
  
== IsNfcEnabledOld ==
+
=== IsNfcEnabledOld ===
 
No input, returns an output bool.
 
No input, returns an output bool.
  
 
This runs the same code as [[#IsNfcEnabled]].
 
This runs the same code as [[#IsNfcEnabled]].
  
== GetState ==
+
=== GetState ===
 
No input, returns an output u32.
 
No input, returns an output u32.
  
 
This replaces [[#GetStateOld]].
 
This replaces [[#GetStateOld]].
  
== IsNfcEnabled ==
+
=== IsNfcEnabled ===
 
No input, returns an output bool.
 
No input, returns an output bool.
  
 
This replaces [[#IsNfcEnabledOld]].
 
This replaces [[#IsNfcEnabledOld]].
 +
 +
=== StartDetection ===
 +
Takes an input [[#DeviceHandle]] and a [[#NfcProtocol]], no output.
 +
 +
=== StopDetection ===
 +
Takes an input [[#DeviceHandle]], no output.
 +
 +
=== ReadMifare ===
 +
Takes an input [[#DeviceHandle]], a type-0x6 output buffer containing an array of [[#MifareReadBlockData]], a type-0x5 input buffer containing an array of [[#MifareReadBlockParameter]], no output.
 +
 +
sdknso passes the same user-specified array-count for both buffers.
 +
 +
=== WriteMifare ===
 +
Takes an input [[#DeviceHandle]], a type-0x5 input buffer containing an array of [[#MifareWriteBlockParameter]], no output.
 +
 +
=== SendCommandByPassThrough ===
 +
Takes an input [[#DeviceHandle]], a nn::TimeSpan timeout, a type-0x6 output buffer, a type-0x5 input buffer, returns an output u32 out_size.
 +
 +
sdknso copies the output u32 into an u64. This is the actual size which was copied into the output buffer.
 +
 +
This allows using a raw NFC command. The input buffer contains the command data (id + params), and the output buffer contains the response.
 +
 +
=== KeepPassThroughSession ===
 +
Takes an input [[#DeviceHandle]], no output.
 +
 +
=== ReleasePassThroughSession ===
 +
Takes an input [[#DeviceHandle]], no output.
  
 
= nfc:sys =
 
= nfc:sys =
Line 192: Line 219:
 
| 407 || [4.0.0+] [[#AttachAvailabilityChangeEvent]]
 
| 407 || [4.0.0+] [[#AttachAvailabilityChangeEvent]]
 
|-
 
|-
| 408 || [4.0.0+] StartDetection
+
| 408 || [4.0.0+] [[#StartDetection]]
 
|-
 
|-
| 409 || [4.0.0+] StopDetection
+
| 409 || [4.0.0+] [[#StopDetection]]
 
|-
 
|-
 
| 410 || [4.0.0+] [[#GetTagInfo]]
 
| 410 || [4.0.0+] [[#GetTagInfo]]
Line 229: Line 256:
 
=== OutputTestWave ===
 
=== OutputTestWave ===
 
Takes an input bool and a [[#TestWaveType]], no output.
 
Takes an input bool and a [[#TestWaveType]], no output.
 
=== ReadMifare ===
 
Takes an input [[#DeviceHandle]], a type-0x6 output buffer containing an array of [[#MifareReadBlockData]], a type-0x5 input buffer containing an array of [[#MifareReadBlockParameter]], no output.
 
 
sdknso passes the same user-specified array-count for both buffers.
 
 
=== WriteMifare ===
 
Takes an input [[#DeviceHandle]], a type-0x5 input buffer containing an array of [[#MifareWriteBlockParameter]], no output.
 
 
=== SendCommandByPassThrough ===
 
Takes an input [[#DeviceHandle]], a nn::TimeSpan timeout, a type-0x6 output buffer, a type-0x5 input buffer, returns an output u32 out_size.
 
 
sdknso copies the output u32 into an u64. This is the actual size which was copied into the output buffer.
 
 
This allows using a raw NFC command. The input buffer contains the command data (id + params), and the output buffer contains the response.
 
 
=== KeepPassThroughSession ===
 
Takes an input [[#DeviceHandle]], no output.
 
 
=== ReleasePassThroughSession ===
 
Takes an input [[#DeviceHandle]], no output.
 
  
 
= nfp:user =
 
= nfp:user =
Line 274: Line 280:
 
| 2 || [[#ListDevices]]
 
| 2 || [[#ListDevices]]
 
|-
 
|-
| 3 || StartDetection
+
| 3 || [[#StartDetection_2|StartDetection]]
 
|-
 
|-
| 4 || StopDetection
+
| 4 || [[#StopDetection]]
 
|-
 
|-
 
| 5 || Mount
 
| 5 || Mount
Line 335: Line 341:
  
 
This can return a maximum of 0xA entries.
 
This can return a maximum of 0xA entries.
 +
 +
=== StartDetection ===
 +
Takes an input [[#DeviceHandle]], no output.
 +
 +
This runs the same code as nfc [[#StartDetection]] with [[#NfcProtocol]] = -1.
  
 
=== GetTagInfo ===
 
=== GetTagInfo ===
Line 385: Line 396:
 
| 2 || [[#ListDevices]]
 
| 2 || [[#ListDevices]]
 
|-
 
|-
| 3 || StartDetection
+
| 3 || [[#StartDetection_2|StartDetection]]
 
|-
 
|-
| 4 || StopDetection
+
| 4 || [[#StopDetection]]
 
|-
 
|-
 
| 5 || Mount
 
| 5 || Mount
Line 518: Line 529:
 
| 2 || [[#ListDevices]]
 
| 2 || [[#ListDevices]]
 
|-
 
|-
| 3 || StartDetection
+
| 3 || [[#StartDetection_2|StartDetection]]
 
|-
 
|-
| 4 || StopDetection
+
| 4 || [[#StopDetection]]
 
|-
 
|-
 
| 5 || Mount
 
| 5 || Mount
Line 570: Line 581:
 
= DeviceHandle =
 
= DeviceHandle =
 
This is "nn::nfc::DeviceHandle". This is a 8-byte struct with 4-byte alignment.
 
This is "nn::nfc::DeviceHandle". This is a 8-byte struct with 4-byte alignment.
 +
 +
= NfcProtocol =
 +
This is s32 enum "nn::nfc::NfcProtocol". Value -1 can be used as a default.
  
 
= TagInfo =
 
= TagInfo =

Revision as of 03:10, 1 December 2021

nfc:am

This is "nn::nfc::am::detail::IAmManager".

Cmd Name
0 CreateAmInterface

IAm

This is "nn::nfc::am::detail::IAm".

Cmd Name
0 Initialize
1 Finalize
2 NotifyForegroundApplet

nfc:mf:u

This is "nn::nfc::mifare::detail::IUserManager".

Cmd Name
0 CreateUserInterface

IUser

This is "nn::nfc::mifare::detail::IUser".

Cmd Name
0 #Initialize
1 #Finalize
2 #ListDevices
3 StartDetection
4 #StopDetection
5 Read
6 Write
7 #GetTagInfo
8 GetActivateEventHandle
9 GetDeactivateEventHandle
10 #GetState
11 #GetDeviceState
12 #GetNpadId
13 [3.0.0+] GetAvailabilityChangeEventHandle

nfc:user

This is "nn::nfc::detail::IUserManager".

Cmd Name
0 CreateUserInterface

IUser

This is "nn::nfc::detail::IUser".

Cmd Name
0 InitializeOld
1 FinalizeOld
2 #GetStateOld
3 #IsNfcEnabledOld
400 [4.0.0+] #Initialize
401 [4.0.0+] #Finalize
402 [4.0.0+] #GetState
403 [4.0.0+] #IsNfcEnabled
404 [4.0.0+] #ListDevices
405 [4.0.0+] #GetDeviceState
406 [4.0.0+] #GetNpadId
407 [4.0.0+] #AttachAvailabilityChangeEvent
408 [4.0.0+] #StartDetection
409 [4.0.0+] #StopDetection
410 [4.0.0+] #GetTagInfo
411 [4.0.0+] #AttachActivateEvent
412 [4.0.0+] #AttachDeactivateEvent
1000 [4.0.0+] #ReadMifare
1001 [4.0.0+] #WriteMifare
1300 [4.0.0+] #SendCommandByPassThrough
1301 [4.0.0+] #KeepPassThroughSession
1302 [4.0.0+] #ReleasePassThroughSession

GetStateOld

No input, returns an output u32.

IsNfcEnabledOld

No input, returns an output bool.

This runs the same code as #IsNfcEnabled.

GetState

No input, returns an output u32.

This replaces #GetStateOld.

IsNfcEnabled

No input, returns an output bool.

This replaces #IsNfcEnabledOld.

StartDetection

Takes an input #DeviceHandle and a #NfcProtocol, no output.

StopDetection

Takes an input #DeviceHandle, no output.

ReadMifare

Takes an input #DeviceHandle, a type-0x6 output buffer containing an array of #MifareReadBlockData, a type-0x5 input buffer containing an array of #MifareReadBlockParameter, no output.

sdknso passes the same user-specified array-count for both buffers.

WriteMifare

Takes an input #DeviceHandle, a type-0x5 input buffer containing an array of #MifareWriteBlockParameter, no output.

SendCommandByPassThrough

Takes an input #DeviceHandle, a nn::TimeSpan timeout, a type-0x6 output buffer, a type-0x5 input buffer, returns an output u32 out_size.

sdknso copies the output u32 into an u64. This is the actual size which was copied into the output buffer.

This allows using a raw NFC command. The input buffer contains the command data (id + params), and the output buffer contains the response.

KeepPassThroughSession

Takes an input #DeviceHandle, no output.

ReleasePassThroughSession

Takes an input #DeviceHandle, no output.

nfc:sys

This is "nn::nfc::detail::ISystemManager".

Cmd Name
0 CreateSystemInterface

ISystem

This is "nn::nfc::detail::ISystem".

Cmd Name
0 #Initialize
1 #Finalize
2 #GetStateOld
3 #IsNfcEnabledOld
100 #SetNfcEnabledOld
400 [4.0.0+] InitializeSystem
401 [4.0.0+] FinalizeSystem
402 [4.0.0+] #GetState
403 [4.0.0+] #IsNfcEnabled
404 [4.0.0+] #ListDevices
405 [4.0.0+] #GetDeviceState
406 [4.0.0+] #GetNpadId
407 [4.0.0+] #AttachAvailabilityChangeEvent
408 [4.0.0+] #StartDetection
409 [4.0.0+] #StopDetection
410 [4.0.0+] #GetTagInfo
411 [4.0.0+] #AttachActivateEvent
412 [4.0.0+] #AttachDeactivateEvent
500 [4.0.0+] #SetNfcEnabled
510 [7.0.0+] #OutputTestWave
1000 [4.0.0+] #ReadMifare
1001 [4.0.0+] #WriteMifare
1300 [4.0.0+] #SendCommandByPassThrough
1301 [4.0.0+] #KeepPassThroughSession
1302 [4.0.0+] #ReleasePassThroughSession

SetNfcEnabledOld

Takes an input bool, no output.

This runs the same code as #SetNfcEnabled.

SetNfcEnabled

Takes an input bool, no output.

This replaces #SetNfcEnabledOld.

OutputTestWave

Takes an input bool and a #TestWaveType, no output.

nfp:user

This is "nn::nfp::detail::IUserManager".

Cmd Name
0 CreateUserInterface

IUser

This is "nn::nfp::detail::IUser".

Cmd Name
0 #Initialize
1 #Finalize
2 #ListDevices
3 StartDetection
4 #StopDetection
5 Mount
6 Unmount
7 OpenApplicationArea
8 GetApplicationArea
9 SetApplicationArea
10 Flush
11 Restore
12 CreateApplicationArea
13 #GetTagInfo
14 GetRegisterInfo
15 GetCommonInfo
16 GetModelInfo
17 #AttachActivateEvent
18 #AttachDeactivateEvent
19 #GetState
20 #GetDeviceState
21 #GetNpadId
22 GetApplicationAreaSize
23 [3.0.0+] #AttachAvailabilityChangeEvent
24 [3.0.0+] RecreateApplicationArea

Initialize

Takes a PID, an AppletResourceUserId, an u64, a type-0x5 input buffer containing an array of #RequiredMcuVersionData, no output.

sdknso passes value 0 for the u64.

Internally this is mostly the same for each service, this differs depending on the service/cmd however.

Finalize

No input/output.

Internally this is mostly the same for each service, this differs depending on the service/cmd however.

ListDevices

Takes a type-0xA output buffer containing an array of #DeviceHandle, returns an output s32 total_out.

This can return a maximum of 0xA entries.

StartDetection

Takes an input #DeviceHandle, no output.

This runs the same code as nfc #StartDetection with #NfcProtocol = -1.

GetTagInfo

Takes an input #DeviceHandle and a type-0x1A output buffer containing a #TagInfo.

AttachActivateEvent

Takes an input #DeviceHandle, returns an output Event handle.

sdknso uses EventClearMode=1.

AttachDeactivateEvent

Takes an input #DeviceHandle, returns an output Event handle.

sdknso uses EventClearMode=1.

GetDeviceState

Takes an input #DeviceHandle, returns an output u32.

The returned u32 is loaded from a lookup table. nfp services uses the same table, mifare uses a separate one, and the nfc services use another separate table.

GetNpadId

Takes an input #DeviceHandle, returns an output u32 NpadId.

AttachAvailabilityChangeEvent

No input, returns an output Event handle.

sdknso uses EventClearMode=1.

nfp:dbg

This is "nn::nfp::detail::IDebugManager".

Cmd Name
0 CreateDebugInterface

IDebug

This is "nn::nfp::detail::IDebug".

Cmd Name
0 InitializeDebug
1 FinalizeDebug
2 #ListDevices
3 StartDetection
4 #StopDetection
5 Mount
6 Unmount
7 OpenApplicationArea
8 GetApplicationArea
9 SetApplicationArea
10 Flush
11 Restore
12 CreateApplicationArea
13 #GetTagInfo
14 GetRegisterInfo
15 GetCommonInfo
16 GetModelInfo
17 #AttachActivateEvent
18 #AttachDeactivateEvent
19 #GetState
20 #GetDeviceState
21 #GetNpadId
22 GetApplicationArea2
23 [3.0.0+] #AttachAvailabilityChangeEvent
24 [3.0.0+] RecreateApplicationArea
100 Format
101 GetAdminInfo
102 GetRegisterInfo
103 SetRegisterInfo
104 DeleteRegisterInfo
105 DeleteApplicationArea
106 ExistsApplicationArea
200 GetAll
201 SetAll
202 FlushDebug
203 BreakTag
204 ReadBackupData
205 WriteBackupData
206 #WriteNtf
300 [3.0.0-3.0.2]
301 [3.0.0-3.0.2]
302 [3.0.0-3.0.2]
303 [3.0.0-3.0.2]
304 [3.0.0-3.0.2]
305 [3.0.0-3.0.2]
306 [3.0.0-3.0.2]
307 [3.0.0-3.0.2]
308 [3.0.0-3.0.2]
309 [3.0.0-3.0.2]
310 [3.0.0-3.0.2]
311 [3.0.0-3.0.2]
312 [3.0.0-3.0.2]
313 [3.0.0-3.0.2]
314 [3.0.0-3.0.2]

WriteNtf

Takes an input #DeviceHandle, an u32, a type-0x5 input buffer, no output.

The input buffer size must match 0x2A0.

This handles Amiibo crypto etc.

nfp:sys

This is "nn::nfp::detail::ISystemManager".

Cmd Name
0 CreateSystemInterface

ISystem

This is "nn::nfp::detail::ISystem".

Cmd Name
0 InitializeSystem
1 FinalizeSystem
2 #ListDevices
3 StartDetection
4 #StopDetection
5 Mount
6 Unmount
10 Flush
11 Restore
13 #GetTagInfo
14 GetRegisterInfo
15 GetCommonInfo
16 GetModelInfo
17 #AttachActivateEvent
18 #AttachDeactivateEvent
19 #GetState
20 #GetDeviceState
21 #GetNpadId
23 [3.0.0+] #AttachAvailabilityChangeEvent
100 Format
101 GetAdminInfo
102 GetRegisterInfo
103 SetRegisterInfo
104 DeleteRegisterInfo
105 DeleteApplicationArea
106 ExistsApplicationArea

RequiredMcuVersionData

In sdknso, the global data containing the array data for this is "nn::nfc::client::RequiredMcuVersionData". The array entry is 0x20-bytes.

DeviceHandle

This is "nn::nfc::DeviceHandle". This is a 8-byte struct with 4-byte alignment.

NfcProtocol

This is s32 enum "nn::nfc::NfcProtocol". Value -1 can be used as a default.

TagInfo

This is "nn::nfc::TagInfo" / "nn::nfp::TagInfo". This is a 0x58-byte struct.

TestWaveType

This is u32 enum "nn::nfc::TestWaveType".

MifareReadBlockData

This is "nn::nfc::MifareReadBlockData". This is a 0x18-byte struct.

MifareReadBlockParameter

This is "nn::nfc::MifareReadBlockParameter". This is a 0x18-byte struct.

MifareWriteBlockParameter

This is "nn::nfc::MifareWriteBlockParameter". This is a 0x28-byte struct.

RomFS

[9.0.0+] The nfc-sysmodule RomFS contains:

 ST21NFCD_01_05_6811.bin

These are firmware files for the NFC IC inside Switch Lite units.

Application IDs

Application IDs (also referenced as "access_id" in official software) are game-unique u32s used to access the amiibo 0xd8-big application area.

Game AppID
Super Smash Bros. Ultimate 0x34f80200