libnx  v4.2.0
nfc.h
Go to the documentation of this file.
1 /**
2  * @file nfc.h
3  * @brief Nintendo Figurine (amiibo) Platform (nfp:user) service IPC wrapper.
4  * @author averne
5  * @copyright libnx Authors
6  */
7 
8 #pragma once
9 #include "../types.h"
10 #include "../sf/service.h"
11 #include "../services/mii.h"
12 
13 /// NfpServiceType
14 typedef enum {
15  NfpServiceType_User = 0, ///< Initializes nfp:user.
16  NfpServiceType_Debug = 1, ///< Initializes nfp:dbg.
17  NfpServiceType_System = 2, ///< Initializes nfp:sys.
19 
20 /// NfcServiceType
21 typedef enum {
22  NfcServiceType_User = 0, ///< Initializes nfc:user.
23  NfcServiceType_System = 1, ///< Initializes nfc:sys.
25 
26 typedef enum {
27  NfpState_NonInitialized = 0,
28  NfpState_Initialized = 1,
29 } NfpState;
30 
31 typedef enum {
32  NfpDeviceState_Initialized = 0,
33  NfpDeviceState_SearchingForTag = 1,
34  NfpDeviceState_TagFound = 2,
35  NfpDeviceState_TagRemoved = 3,
36  NfpDeviceState_TagMounted = 4,
37  NfpDeviceState_Unavailable = 5,
38  NfpDeviceState_Finalized = 6,
39 } NfpDeviceState;
40 
41 typedef enum {
42  NfpDeviceType_Amiibo = 0,
43 } NfpDeviceType;
44 
45 typedef enum {
46  NfpMountTarget_Rom = 1,
47  NfpMountTarget_Ram = 2,
48  NfpMountTarget_All = 3,
49 } NfpMountTarget;
50 
51 typedef struct {
52  u8 uuid[10];
53  u8 uuid_length;
54  u8 reserved1[0x15];
55  u32 protocol;
56  u32 tag_type;
57  u8 reserved2[0x30];
59 
60 typedef struct {
61  u16 last_write_year;
62  u8 last_write_month;
63  u8 last_write_day;
64  u16 write_counter;
65  u16 version;
66  u32 application_area_size;
67  u8 reserved[0x34];
69 
70 typedef struct {
71  u8 amiibo_id[0x8];
72  u8 reserved[0x38];
74 
75 typedef struct {
76  MiiCharInfo mii;
77  u16 first_write_year;
78  u8 first_write_month;
79  u8 first_write_day;
80  char amiibo_name[10+1]; ///< utf-8, null-terminated
81  u8 reserved[0x99];
83 
84 typedef struct {
85  u64 version;
86  u64 reserved[3];
88 
89 /// Nfc/Nfp DeviceHandle
90 typedef struct {
91  u8 handle[0x8]; ///< Handle.
93 
94 /// Initialize nfp:*.
95 Result nfpInitialize(NfpServiceType service_type);
96 
97 /// Exit nfp:*.
98 void nfpExit(void);
99 
100 /// Initialize nfc:*.
101 Result nfcInitialize(NfcServiceType service_type);
102 
103 /// Exit nfc:*.
104 void nfcExit(void);
105 
106 /// Gets the Service object for the actual nfp:* service session.
108 
109 /// Gets the Service object for the interface from nfp:*.
111 
112 /// Gets the Service object for the actual nfc:* service session.
114 
115 /// Gets the Service object for the interface from nfc:*.
117 
118 Result nfpListDevices(s32 *total_out, NfcDeviceHandle *out, s32 count);
119 Result nfpStartDetection(const NfcDeviceHandle *handle);
120 Result nfpStopDetection(const NfcDeviceHandle *handle);
121 Result nfpMount(const NfcDeviceHandle *handle, NfpDeviceType device_type, NfpMountTarget mount_target);
122 Result nfpUnmount(const NfcDeviceHandle *handle);
123 
124 /// Not available with ::NfpServiceType_System.
125 Result nfpOpenApplicationArea(const NfcDeviceHandle *handle, u32 app_id);
126 
127 /// Not available with ::NfpServiceType_System.
128 Result nfpGetApplicationArea(const NfcDeviceHandle *handle, void* buf, size_t buf_size);
129 
130 /// Not available with ::NfpServiceType_System.
131 Result nfpSetApplicationArea(const NfcDeviceHandle *handle, const void* buf, size_t buf_size);
132 Result nfpFlush(const NfcDeviceHandle *handle);
133 Result nfpRestore(const NfcDeviceHandle *handle);
134 
135 /// Not available with ::NfpServiceType_System.
136 Result nfpCreateApplicationArea(const NfcDeviceHandle *handle, u32 app_id, const void* buf, size_t buf_size);
137 
138 Result nfpGetTagInfo(const NfcDeviceHandle *handle, NfpTagInfo *out);
139 Result nfpGetRegisterInfo(const NfcDeviceHandle *handle, NfpRegisterInfo *out);
140 Result nfpGetCommonInfo(const NfcDeviceHandle *handle, NfpCommonInfo *out);
141 Result nfpGetModelInfo(const NfcDeviceHandle *handle, NfpModelInfo *out);
142 
143 /// Returned event will have autoclear off.
144 Result nfpAttachActivateEvent(const NfcDeviceHandle *handle, Event *out_event);
145 /// Returned event will have autoclear off.
146 Result nfpAttachDeactivateEvent(const NfcDeviceHandle *handle, Event *out_event);
147 
148 Result nfpGetState(NfpState *out);
149 Result nfpGetDeviceState(const NfcDeviceHandle *handle, NfpDeviceState *out);
150 Result nfpGetNpadId(const NfcDeviceHandle *handle, u32 *out);
151 
152 /// Returned event will have autoclear on.
153 /// Only available with [3.0.0+].
155 
156 /// This uses nfc:*.
157 Result nfcIsNfcEnabled(bool *out);
nfcIsNfcEnabled
Result nfcIsNfcEnabled(bool *out)
This uses nfc:*.
NfcDeviceHandle
Nfc/Nfp DeviceHandle.
Definition: nfc.h:90
nfpCreateApplicationArea
Result nfpCreateApplicationArea(const NfcDeviceHandle *handle, u32 app_id, const void *buf, size_t buf_size)
Not available with NfpServiceType_System.
NfpServiceType_Debug
@ NfpServiceType_Debug
Initializes nfp:dbg.
Definition: nfc.h:16
NfpServiceType_System
@ NfpServiceType_System
Initializes nfp:sys.
Definition: nfc.h:17
u8
uint8_t u8
8-bit unsigned integer.
Definition: types.h:19
NfcServiceType_System
@ NfcServiceType_System
Initializes nfc:sys.
Definition: nfc.h:23
Event
Kernel-mode event structure.
Definition: event.h:13
NfpTagInfo
Definition: nfc.h:51
NfpServiceType_User
@ NfpServiceType_User
Initializes nfp:user.
Definition: nfc.h:15
s32
int32_t s32
32-bit signed integer.
Definition: types.h:27
NfpServiceType
NfpServiceType
NfpServiceType.
Definition: nfc.h:14
NfcRequiredMcuVersionData
Definition: nfc.h:84
nfpAttachAvailabilityChangeEvent
Result nfpAttachAvailabilityChangeEvent(Event *out_event)
Returned event will have autoclear on.
NfpRegisterInfo
Definition: nfc.h:75
NfcServiceType
NfcServiceType
NfcServiceType.
Definition: nfc.h:21
NfpCommonInfo
Definition: nfc.h:60
NfpModelInfo
Definition: nfc.h:70
nfpOpenApplicationArea
Result nfpOpenApplicationArea(const NfcDeviceHandle *handle, u32 app_id)
Not available with NfpServiceType_System.
NfcServiceType_User
@ NfcServiceType_User
Initializes nfc:user.
Definition: nfc.h:22
u32
uint32_t u32
32-bit unsigned integer.
Definition: types.h:21
MiiCharInfo
Definition: mii.h:62
nfcGetServiceSession_Interface
Service * nfcGetServiceSession_Interface(void)
Gets the Service object for the interface from nfc:*.
nfpSetApplicationArea
Result nfpSetApplicationArea(const NfcDeviceHandle *handle, const void *buf, size_t buf_size)
Not available with NfpServiceType_System.
u64
uint64_t u64
64-bit unsigned integer.
Definition: types.h:22
nfpExit
void nfpExit(void)
Exit nfp:*.
nfcExit
void nfcExit(void)
Exit nfc:*.
Result
u32 Result
Function error code result type.
Definition: types.h:44
nfpAttachDeactivateEvent
Result nfpAttachDeactivateEvent(const NfcDeviceHandle *handle, Event *out_event)
Returned event will have autoclear off.
nfpGetApplicationArea
Result nfpGetApplicationArea(const NfcDeviceHandle *handle, void *buf, size_t buf_size)
Not available with NfpServiceType_System.
nfpInitialize
Result nfpInitialize(NfpServiceType service_type)
Initialize nfp:*.
nfcInitialize
Result nfcInitialize(NfcServiceType service_type)
Initialize nfc:*.
nfpGetServiceSession_Interface
Service * nfpGetServiceSession_Interface(void)
Gets the Service object for the interface from nfp:*.
PACKED
#define PACKED
Packs a struct so that it won't include padding bytes.
Definition: types.h:59
nfcGetServiceSession
Service * nfcGetServiceSession(void)
Gets the Service object for the actual nfc:* service session.
nfpGetServiceSession
Service * nfpGetServiceSession(void)
Gets the Service object for the actual nfp:* service session.
Service
Service object structure.
Definition: service.h:13
nfpAttachActivateEvent
Result nfpAttachActivateEvent(const NfcDeviceHandle *handle, Event *out_event)
Returned event will have autoclear off.
u16
uint16_t u16
16-bit unsigned integer.
Definition: types.h:20