Release 4.0.0-preview1-00051
[platform/core/csapi/tizenfx.git] / src / Tizen.Network.Nfc / Interop / Interop.Nfc.cs
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 using System;
18 using System.Runtime.InteropServices;
19
20 internal static partial class Interop
21 {
22     internal static partial class Nfc
23     {
24         //Callback for async method
25         //nfc_activation_completed_cb
26         //nfc_tag_write_completed_cb
27         //nfc_tag_format_completed_cb
28         //nfc_mifare_authenticate_with_keyA_completed_cb
29         //nfc_mifare_authenticate_with_keyB_completed_cb
30         //nfc_mifare_write_block_completed_cb
31         //nfc_mifare_write_page_completed_cb
32         //nfc_mifare_increment_completed_cb
33         //nfc_mifare_decrement_completed_cb
34         //nfc_mifare_transfer_completed_cb
35         //nfc_mifare_restore_completed_cb
36         //nfc_p2p_send_completed_cb
37         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
38         internal delegate void VoidCallback(int result, IntPtr userData);
39         //nfc_tag_information_cb
40         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
41         internal delegate bool TagInformationCallback(IntPtr key, IntPtr value, int valueSize, IntPtr userData);
42         //nfc_tag_transceive_completed_cb
43         //nfc_mifare_read_block_completed_cb
44         //nfc_mifare_read_page_completed_cb
45         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
46         internal delegate void TagTransceiveCompletedCallback(int result, IntPtr value, int bufferSize, IntPtr userData);
47         //nfc_tag_read_completed_cb
48         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
49         internal delegate bool TagReadCompletedCallback(int result, IntPtr message, IntPtr userData);
50         //nfc_snep_event_cb
51         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
52         internal delegate void SnepEventCallback(IntPtr handle, int snepEvent, int result, IntPtr message, IntPtr userData);
53         //nfc_se_registered_aid_cb
54         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
55         internal delegate void SecureElementRegisteredAidCallback(int seType, IntPtr aid, bool readOnly, IntPtr userData);
56
57
58         //Callback for event
59         //nfc_activation_changed_cb
60         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
61         internal delegate void ActivationChangedCallback(bool activated, IntPtr userData);
62         //nfc_tag_discovered_cb
63         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
64         internal delegate void TagDiscoveredCallback(int type, IntPtr tag, IntPtr userData);
65         //nfc_p2p_target_discovered_cb
66         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
67         internal delegate void P2pTargetDiscoveredCallback(int type, IntPtr p2pTaget, IntPtr userData);
68         //nfc_ndef_discovered_cb
69         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
70         internal delegate void NdefMessageDiscoveredCallback(IntPtr message, IntPtr userData);
71         //nfc_se_event_cb
72         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
73         internal delegate void SecureElementEventCallback(int eventType, IntPtr userData);
74         //nfc_se_transaction_event_cb
75         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
76         internal delegate void SecureElementTransactionEventCallback(int type, IntPtr aid, int aidSize, IntPtr param, int paramSize, IntPtr userData);
77         //nfc_p2p_data_received_cb
78         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
79         internal delegate void P2pDataReceivedCallback(IntPtr target, IntPtr message, IntPtr userData);
80         //nfc_hce_event_cb
81         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
82         internal delegate void HostCardEmulationEventCallback(IntPtr handle, int eventType, IntPtr apdu, uint apduLen, IntPtr userData);
83
84         //capi-network-nfc-0.2.5-6.1.armv7l
85         [DllImport(Libraries.Nfc, EntryPoint = "nfc_manager_initialize")]
86         internal static extern int Initialize();
87         [DllImport(Libraries.Nfc, EntryPoint = "nfc_manager_deinitialize")]
88         internal static extern int Deinitialize();
89
90         ////Nfc Manager
91         [DllImport(Libraries.Nfc, EntryPoint = "nfc_manager_is_supported")]
92         internal static extern bool IsSupported();
93         [DllImport(Libraries.Nfc, EntryPoint = "nfc_manager_set_activation")]
94         internal static extern int SetActivation(bool activation, VoidCallback callback, IntPtr userData);
95         [DllImport(Libraries.Nfc, EntryPoint = "nfc_manager_is_activated")]
96         internal static extern bool IsActivated();
97         [DllImport(Libraries.Nfc, EntryPoint = "nfc_manager_set_activation_changed_cb")]
98         internal static extern int SetActivationChangedCallback(ActivationChangedCallback callback, IntPtr userData);
99         [DllImport(Libraries.Nfc, EntryPoint = "nfc_manager_unset_activation_changed_cb")]
100         internal static extern void UnsetActivationChangedCallback();
101         [DllImport(Libraries.Nfc, EntryPoint = "nfc_manager_set_tag_discovered_cb")]
102         internal static extern int SetTagDiscoveredCallback(TagDiscoveredCallback callback, IntPtr userData);
103         [DllImport(Libraries.Nfc, EntryPoint = "nfc_manager_unset_tag_discovered_cb")]
104         internal static extern void UnsetTagDiscoveredCallback();
105         [DllImport(Libraries.Nfc, EntryPoint = "nfc_manager_set_ndef_discovered_cb")]
106         internal static extern int SetNdefDiscoveredCallback(NdefMessageDiscoveredCallback callback, IntPtr userData);
107         [DllImport(Libraries.Nfc, EntryPoint = "nfc_manager_unset_ndef_discovered_cb")]
108         internal static extern void UnsetNdefDiscoveredCallback();
109         [DllImport(Libraries.Nfc, EntryPoint = "nfc_manager_set_p2p_target_discovered_cb")]
110         internal static extern int SetP2pTargetDiscoveredCallback(P2pTargetDiscoveredCallback callback, IntPtr userData);
111         [DllImport(Libraries.Nfc, EntryPoint = "nfc_manager_unset_p2p_target_discovered_cb")]
112         internal static extern void UnsetP2pTargetDiscoveredCallback();
113         [DllImport(Libraries.Nfc, EntryPoint = "nfc_manager_set_se_event_cb")]
114         internal static extern int SetSecureElementEventCallback(SecureElementEventCallback callback, IntPtr userData);
115         [DllImport(Libraries.Nfc, EntryPoint = "nfc_manager_unset_se_event_cb")]
116         internal static extern void UnsetSecureElementEventCallback();
117         [DllImport(Libraries.Nfc, EntryPoint = "nfc_manager_set_se_transaction_event_cb")]
118         internal static extern int SetSecureElementTransactionEventCallback(int setype, SecureElementTransactionEventCallback callback, IntPtr userData);
119         [DllImport(Libraries.Nfc, EntryPoint = "nfc_manager_unset_se_transaction_event_cb")]
120         internal static extern int UnsetSecureElementTransactionEventCallback(int setype);
121         [DllImport(Libraries.Nfc, EntryPoint = "nfc_manager_set_hce_event_cb")]
122         internal static extern int SetHostCardEmulationEventCallback(HostCardEmulationEventCallback callback, IntPtr userData);
123         [DllImport(Libraries.Nfc, EntryPoint = "nfc_manager_unset_hce_event_cb")]
124         internal static extern void UnsetHostCardEmulationEventCallback();
125         [DllImport(Libraries.Nfc, EntryPoint = "nfc_manager_enable_transaction_fg_dispatch")]
126         internal static extern int EnableTransactionForegroundDispatch();
127         [DllImport(Libraries.Nfc, EntryPoint = "nfc_manager_disable_transaction_fg_dispatch")]
128         internal static extern int DisableTransactionForegroundDispatch();
129         [DllImport(Libraries.Nfc, EntryPoint = "nfc_manager_get_cached_message")]
130         internal static extern int GetCachedMessage(out IntPtr ndefMessage);
131         [DllImport(Libraries.Nfc, EntryPoint = "nfc_manager_set_tag_filter")]
132         internal static extern void SetTagFilter(int filter);
133         [DllImport(Libraries.Nfc, EntryPoint = "nfc_manager_get_tag_filter")]
134         internal static extern int GetTagFilter();
135         [DllImport(Libraries.Nfc, EntryPoint = "nfc_manager_get_connected_tag")]
136         internal static extern int GetConnectedTag(out IntPtr tag);
137         [DllImport(Libraries.Nfc, EntryPoint = "nfc_manager_get_connected_target")]
138         internal static extern int GetConnectedTarget(out IntPtr target);
139         [DllImport(Libraries.Nfc, EntryPoint = "nfc_manager_set_system_handler_enable")]
140         internal static extern int SetSystemHandlerEnable(bool enable);
141         [DllImport(Libraries.Nfc, EntryPoint = "nfc_manager_is_system_handler_enabled")]
142         internal static extern bool IsSystemHandlerEnabled();
143         [DllImport(Libraries.Nfc, EntryPoint = "nfc_manager_set_se_type")]
144         internal static extern int SetSecureElementType(int type);
145         [DllImport(Libraries.Nfc, EntryPoint = "nfc_manager_get_se_type")]
146         internal static extern int GetSecureElementType(out int type);
147
148         ////NDEF - NFC Data Exchange Format, TNF - Type Name Format
149         internal static class NdefRecord
150         {
151             [DllImport(Libraries.Nfc, EntryPoint = "nfc_ndef_record_create")]
152             internal static extern int Create(out IntPtr record, int tnf, byte[] type, int typeSize, byte[] id, int idSize, byte[] payload, uint payloadSize);
153             [DllImport(Libraries.Nfc, EntryPoint = "nfc_ndef_record_create_text")]
154             internal static extern int CreateText(out IntPtr record, string text, string languageCode, int encode);
155             [DllImport(Libraries.Nfc, EntryPoint = "nfc_ndef_record_create_uri")]
156             internal static extern int CreateUri(out IntPtr record, string uri);
157             [DllImport(Libraries.Nfc, EntryPoint = "nfc_ndef_record_create_mime")]
158             internal static extern int CreateMime(out IntPtr record, string mimeType, byte[] data, uint dataSize);
159             [DllImport(Libraries.Nfc, EntryPoint = "nfc_ndef_record_destroy")]
160             internal static extern int Destroy(IntPtr record);
161             [DllImport(Libraries.Nfc, EntryPoint = "nfc_ndef_record_set_id")]
162             internal static extern int SetId(IntPtr record, byte[] id, int idSize);
163             [DllImport(Libraries.Nfc, EntryPoint = "nfc_ndef_record_get_id")]
164             internal static extern int GetId(IntPtr record, out IntPtr id, out int size);
165             [DllImport(Libraries.Nfc, EntryPoint = "nfc_ndef_record_get_payload")]
166             internal static extern int GetPayload(IntPtr record, out IntPtr payload, out uint size);
167             [DllImport(Libraries.Nfc, EntryPoint = "nfc_ndef_record_get_type")]
168             internal static extern int GetType(IntPtr record, out IntPtr type, out int size);
169             [DllImport(Libraries.Nfc, EntryPoint = "nfc_ndef_record_get_tnf")]
170             internal static extern int GetTnf(IntPtr record, out int tnf);
171             [DllImport(Libraries.Nfc, EntryPoint = "nfc_ndef_record_get_text")]
172             internal static extern int GetText(IntPtr record, out string text);
173             [DllImport(Libraries.Nfc, EntryPoint = "nfc_ndef_record_get_langcode")]
174             internal static extern int GetLanguageCode(IntPtr record, out string languageCode);
175             [DllImport(Libraries.Nfc, EntryPoint = "nfc_ndef_record_get_encode_type")]
176             internal static extern int GetEncodeType(IntPtr record, out int encode);
177             [DllImport(Libraries.Nfc, EntryPoint = "nfc_ndef_record_get_uri")]
178             internal static extern int GetUri(IntPtr record, out string uri);
179             [DllImport(Libraries.Nfc, EntryPoint = "nfc_ndef_record_get_mime_type")]
180             internal static extern int GetMimeType(IntPtr record, out string mimeType);
181         }
182
183         internal static class NdefMessage
184         {
185             [DllImport(Libraries.Nfc, EntryPoint = "nfc_ndef_message_create")]
186             internal static extern int Create(out IntPtr ndefMessage);
187             [DllImport(Libraries.Nfc, EntryPoint = "nfc_ndef_message_create_from_rawdata")]
188             internal static extern int CreateRawData(out IntPtr ndefMessage, byte[] rawData, uint rawDataSize);
189             [DllImport(Libraries.Nfc, EntryPoint = "nfc_ndef_message_destroy")]
190             internal static extern int Destroy(IntPtr ndefMessage);
191             [DllImport(Libraries.Nfc, EntryPoint = "nfc_ndef_message_get_record_count")]
192             internal static extern int GetRecordCount(IntPtr ndefMessage, out int count);
193             [DllImport(Libraries.Nfc, EntryPoint = "nfc_ndef_message_get_rawdata")]
194             internal static extern int GetRawData(IntPtr ndefMessage, out IntPtr rawData, out uint rawDataSize);
195             [DllImport(Libraries.Nfc, EntryPoint = "nfc_ndef_message_append_record")]
196             internal static extern int AppendRecord(IntPtr ndefMessage, IntPtr record);
197             [DllImport(Libraries.Nfc, EntryPoint = "nfc_ndef_message_insert_record")]
198             internal static extern int InsertRecord(IntPtr ndefMessage, int index, IntPtr record);
199             [DllImport(Libraries.Nfc, EntryPoint = "nfc_ndef_message_remove_record")]
200             internal static extern int RemoveRecord(IntPtr ndefMessage, int index);
201             [DllImport(Libraries.Nfc, EntryPoint = "nfc_ndef_message_get_record")]
202             internal static extern int GetRecord(IntPtr ndefMessage, int index, out IntPtr record);
203         }
204
205         internal static class Tag
206         {
207             [DllImport(Libraries.Nfc, EntryPoint = "nfc_tag_get_type")]
208             internal static extern int GetType(IntPtr tag, out int type);
209             [DllImport(Libraries.Nfc, EntryPoint = "nfc_tag_is_support_ndef")]
210             internal static extern int IsSupportNdef(IntPtr tag, out bool isSupported);
211             [DllImport(Libraries.Nfc, EntryPoint = "nfc_tag_get_maximum_ndef_size")]
212             internal static extern int GetMaximumNdefSize(IntPtr tag, out uint maximunNdefBytesSize);
213             [DllImport(Libraries.Nfc, EntryPoint = "nfc_tag_get_ndef_size")]
214             internal static extern int GetNdefSize(IntPtr tag, out uint ndefBytesSize);
215             [DllImport(Libraries.Nfc, EntryPoint = "nfc_tag_foreach_information")]
216             internal static extern int ForeachInformation(IntPtr tag, TagInformationCallback callback, IntPtr userData);
217             [DllImport(Libraries.Nfc, EntryPoint = "nfc_tag_transceive")]
218             internal static extern int Transceive(IntPtr tag, byte[] buffer, int bufferSize, TagTransceiveCompletedCallback callback, IntPtr userData);
219             [DllImport(Libraries.Nfc, EntryPoint = "nfc_tag_read_ndef")]
220             internal static extern int ReadNdef(IntPtr tag, TagReadCompletedCallback callback, IntPtr userData);
221             [DllImport(Libraries.Nfc, EntryPoint = "nfc_tag_write_ndef")]
222             internal static extern int WriteNdef(IntPtr tag, IntPtr ndefMessage, VoidCallback callback, IntPtr userData);
223             [DllImport(Libraries.Nfc, EntryPoint = "nfc_tag_format_ndef")]
224             internal static extern int FormatNdef(IntPtr tag, byte[] key, int kyeSize, VoidCallback callback, IntPtr userData);
225
226             ////Mifare
227         }
228
229         ////SNEP - Simple NDEF Exchange Protocol
230         internal static class P2p
231         {
232             [DllImport(Libraries.Nfc, EntryPoint = "nfc_p2p_set_data_received_cb")]
233             internal static extern int SetDataReceivedCallback(IntPtr target, P2pDataReceivedCallback callback, IntPtr userData);
234             [DllImport(Libraries.Nfc, EntryPoint = "nfc_p2p_unset_data_received_cb")]
235             internal static extern int UnsetDataReceivedCallback(IntPtr target);
236             [DllImport(Libraries.Nfc, EntryPoint = "nfc_p2p_send")]
237             internal static extern int Send(IntPtr target, IntPtr ndefMessage, VoidCallback callback, IntPtr userData);
238             [DllImport(Libraries.Nfc, EntryPoint = "nfc_snep_start_server")]
239             internal static extern int SnepStartServer(IntPtr target, string san, int sap, SnepEventCallback callback, IntPtr userData);
240             [DllImport(Libraries.Nfc, EntryPoint = "nfc_snep_start_client")]
241             internal static extern int SnepStartClient(IntPtr target, string san, int sap, SnepEventCallback callback, IntPtr userData);
242             [DllImport(Libraries.Nfc, EntryPoint = "nfc_snep_send_client_request")]
243             internal static extern int SnepSendClientRequest(IntPtr snepHandle, int type, IntPtr ndefMessage, SnepEventCallback callback, IntPtr userData);
244             [DllImport(Libraries.Nfc, EntryPoint = "nfc_snep_stop_service")]
245             internal static extern int SnepStopService(IntPtr target, IntPtr snepHandle);
246             [DllImport(Libraries.Nfc, EntryPoint = "nfc_snep_register_server")]
247             internal static extern int SnepRegisterServer(string san, int sap, SnepEventCallback callback, IntPtr userData);
248             [DllImport(Libraries.Nfc, EntryPoint = "nfc_snep_unregister_server")]
249             internal static extern int SnepUnregisterServer(string sam, int sap);
250         }
251
252         ////SE - Secure Element, HCE - Host Card Emulation, APDU - Application Protocol Data Unit, AID - Application Identifier
253         internal static class CardEmulation
254         {
255             [DllImport(Libraries.Nfc, EntryPoint = "nfc_se_enable_card_emulation")]
256             internal static extern int EnableCardEmulation();
257             [DllImport(Libraries.Nfc, EntryPoint = "nfc_se_disable_card_emulation")]
258             internal static extern int DisableCardEmulatiion();
259             [DllImport(Libraries.Nfc, EntryPoint = "nfc_se_get_card_emulation_mode")]
260             internal static extern int GetCardEmulationMode(out int type);
261             [DllImport(Libraries.Nfc, EntryPoint = "nfc_hce_send_apdu_response")]
262             internal static extern int HceSendApduRespondse(IntPtr seHandle, byte[] response, uint responseLength);
263             [DllImport(Libraries.Nfc, EntryPoint = "nfc_se_set_default_route")]
264             internal static extern int SetDefaultRoute(int poweredOnStatus, int poweredOffStatus, int lowBatteryStatus);
265             [DllImport(Libraries.Nfc, EntryPoint = "nfc_se_is_activated_handler_for_aid")]
266             internal static extern int IsActivatedHandlerForAid(int seType, string aid, out bool isActivatedHandler);
267             [DllImport(Libraries.Nfc, EntryPoint = "nfc_se_is_activated_handler_for_category")]
268             internal static extern int IsActivatedHandlerForCategory(int seType, int category, out bool isActivatedHandler);
269             [DllImport(Libraries.Nfc, EntryPoint = "nfc_se_register_aid")]
270             internal static extern int RegisterAid(int seType, int category, string aid);
271             [DllImport(Libraries.Nfc, EntryPoint = "nfc_se_unregister_aid")]
272             internal static extern int UnregisterAid(int seType, int category, string aid);
273             [DllImport(Libraries.Nfc, EntryPoint = "nfc_se_foreach_registered_aids")]
274             internal static extern int ForeachRegisterdAids(int seType, int category, SecureElementRegisteredAidCallback callback, IntPtr userData);
275             [DllImport(Libraries.Nfc, EntryPoint = "nfc_se_set_preferred_handler")]
276             internal static extern int SetPreferredHandler();
277             [DllImport(Libraries.Nfc, EntryPoint = "nfc_se_unset_preferred_handler")]
278             internal static extern int UnsetPreferredHandler();
279         }
280     }
281 }