2 * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
4 * Licensed under the Flora License, Version 1.1 (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
8 * http://floralicense.org/license/
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.
19 #include "net_nfc_typedef_internal.h"
20 #include "net_nfc_debug_internal.h"
21 #include "net_nfc_util_internal.h"
22 #include "net_nfc_util_ndef_message.h"
23 #include "net_nfc_util_gdbus_internal.h"
24 #include "net_nfc_gdbus.h"
25 #include "net_nfc_client.h"
26 #include "net_nfc_client_util_internal.h"
27 #include "net_nfc_client_manager.h"
28 #include "net_nfc_client_se.h"
31 #ifndef NET_NFC_EXPORT_API
32 #define NET_NFC_EXPORT_API __attribute__((visibility("default")))
37 typedef struct _SeFuncData SeFuncData;
44 typedef struct _SeEventHandler SeEventHandler;
46 struct _SeEventHandler {
47 net_nfc_client_se_event se_event_cb;
48 gpointer se_event_data;
51 typedef struct _SeTransEventHandler SeTransEventHandler;
53 struct _SeTransEventHandler {
54 net_nfc_client_se_transaction_event transaction_event_cb;
55 gpointer transaction_event_data;
58 typedef struct _SeESEDetectedHandler SeESEDetectedHandler;
60 struct _SeESEDetectedHandler {
61 net_nfc_client_se_ese_detected_event se_ese_detected_cb;
62 gpointer se_ese_detected_data;
66 static NetNfcGDbusSecureElement *se_proxy = NULL;
67 static NetNfcGDbusSecureElement *auto_start_proxy = NULL;
69 static SeEventHandler se_eventhandler;
70 static SeTransEventHandler uicc_transactionEventHandler;
71 static SeTransEventHandler ese_transactionEventHandler;
72 static SeESEDetectedHandler se_esedetecthandler;
74 static void se_ese_detected(GObject *source_object,
79 static void se_type_changed(GObject *source_object,
82 static void set_secure_element(GObject *source_object,
86 static void open_secure_element(GObject *source_object,
90 static void close_secure_element(GObject *source_object,
94 static void send_apdu_secure_element(GObject *source_object,
98 static void get_atr_secure_element(GObject *source_object,
102 static void se_rf_detected(GObject *source_object,
107 static void se_ese_detected(GObject *source_object,
112 INFO_MSG(">>> SIGNAL arrived");
114 if (se_esedetecthandler.se_ese_detected_cb != NULL) {
115 data_s buffer_data = { NULL, 0 };
116 net_nfc_client_se_ese_detected_event callback =
117 (net_nfc_client_se_ese_detected_event)se_esedetecthandler.se_ese_detected_cb;
119 net_nfc_util_gdbus_variant_to_data_s(arg_data, &buffer_data);
121 callback((net_nfc_target_handle_h)GUINT_TO_POINTER(arg_handle),
122 arg_se_type, &buffer_data,
123 se_esedetecthandler.se_ese_detected_data);
125 net_nfc_util_clear_data(&buffer_data);
129 static void se_rf_detected(GObject *source_object,
134 INFO_MSG(">>> SIGNAL arrived");
136 if (se_eventhandler.se_event_cb != NULL) {
137 net_nfc_client_se_event callback =
138 (net_nfc_client_se_event)se_eventhandler.se_event_cb;
140 callback((net_nfc_message_e)NET_NFC_MESSAGE_SE_FIELD_ON,
141 se_eventhandler.se_event_data);
146 static void se_type_changed(GObject *source_object,
149 INFO_MSG(">>> SIGNAL arrived");
151 if (se_eventhandler.se_event_cb != NULL) {
152 net_nfc_client_se_event callback =
153 (net_nfc_client_se_event)se_eventhandler.se_event_cb;
155 callback((net_nfc_message_e)NET_NFC_MESSAGE_SE_TYPE_CHANGED,
156 se_eventhandler.se_event_data);
161 static void se_transaction_event(GObject *source_object,
168 void *user_data = NULL;
169 net_nfc_client_se_transaction_event callback = NULL;
170 pid_t mypid = getpid();
172 INFO_MSG(">>> SIGNAL arrived");
174 if (fg_dispatch == true && focus_app_pid != getpgid(mypid)) {
175 SECURE_MSG("skip transaction event, fg_dispatch [%d], focus_app_pid [%d]", fg_dispatch, focus_app_pid);
178 #ifdef CHECK_NFC_ACCESS_FOR_ESE
179 if (net_nfc_gdbus_secure_element_call_check_transaction_permission_sync(
180 NET_NFC_GDBUS_SECURE_ELEMENT(source_object),
185 DEBUG_ERR_MSG("net_nfc_gdbus_secure_element_call_check_transaction_permission_sync failed : %s", error->message);
190 if (result != NET_NFC_OK) {
191 DEBUG_ERR_MSG("not allowed process [%d]", result);
195 switch (arg_se_type) {
196 case NET_NFC_SE_TYPE_UICC:
197 if (uicc_transactionEventHandler.transaction_event_cb != NULL) {
198 callback = uicc_transactionEventHandler.transaction_event_cb;
199 user_data = uicc_transactionEventHandler.transaction_event_data;
203 case NET_NFC_SE_TYPE_ESE:
204 if (ese_transactionEventHandler.transaction_event_cb != NULL) {
205 callback = ese_transactionEventHandler.transaction_event_cb;
206 user_data = ese_transactionEventHandler.transaction_event_data;
211 DEBUG_ERR_MSG("Transaction event SE type wrong [%d]", arg_se_type);
215 if (callback != NULL) {
216 data_s aid = { NULL, 0 };
217 data_s param = { NULL, 0 };
219 net_nfc_util_gdbus_variant_to_data_s(arg_aid, &aid);
220 net_nfc_util_gdbus_variant_to_data_s(arg_param, ¶m);
222 callback(arg_se_type, &aid, ¶m, user_data);
224 net_nfc_util_clear_data(¶m);
225 net_nfc_util_clear_data(&aid);
229 static void se_card_emulation_mode_changed(GObject *source_object,
232 INFO_MSG(">>> SIGNAL arrived");
234 if (se_eventhandler.se_event_cb != NULL) {
235 net_nfc_client_se_event callback =
236 (net_nfc_client_se_event)se_eventhandler.se_event_cb;
238 callback((net_nfc_message_e)NET_NFC_MESSAGE_SE_CARD_EMULATION_CHANGED,
239 se_eventhandler.se_event_data);
243 static void set_secure_element(GObject *source_object,
247 SeFuncData *func_data = (SeFuncData *)user_data;
248 net_nfc_error_e result;
249 GError *error = NULL;
251 g_assert(user_data != NULL);
253 if (net_nfc_gdbus_secure_element_call_set_finish(se_proxy,
258 DEBUG_ERR_MSG("Could not set secure element: %s",
260 result = NET_NFC_IPC_FAIL;
265 if (func_data->se_callback != NULL) {
266 net_nfc_se_set_se_cb se_callback =
267 (net_nfc_se_set_se_cb)func_data->se_callback;
269 se_callback(result, func_data->se_data);
275 static void open_secure_element(GObject *source_object,
279 SeFuncData *func_data = (SeFuncData *)user_data;
280 net_nfc_error_e result;
281 guint out_handle = 0;
282 GError *error = NULL;
284 g_assert(user_data != NULL);
286 if (net_nfc_gdbus_secure_element_call_open_secure_element_finish(
293 DEBUG_ERR_MSG("Could not open secure element: %s",
295 result = NET_NFC_IPC_FAIL;
300 if (func_data->se_callback != NULL) {
301 net_nfc_se_open_se_cb se_callback =
302 (net_nfc_se_open_se_cb)func_data->se_callback;
305 (net_nfc_target_handle_h)GUINT_TO_POINTER(out_handle),
313 static void close_secure_element(GObject *source_object,
317 SeFuncData *func_data = (SeFuncData *)user_data;
318 net_nfc_error_e result;
319 GError *error = NULL;
321 g_assert(user_data != NULL);
323 if (net_nfc_gdbus_secure_element_call_close_secure_element_finish(
328 DEBUG_ERR_MSG("Could not close secure element: %s", error->message);
329 result = NET_NFC_IPC_FAIL;
334 if (func_data->se_callback != NULL) {
335 net_nfc_se_close_se_cb se_callback =
336 (net_nfc_se_close_se_cb)func_data->se_callback;
338 se_callback(result, func_data->se_data);
345 static void send_apdu_secure_element(GObject *source_object,
349 SeFuncData *func_data = (SeFuncData *)user_data;
350 net_nfc_error_e result;
351 GVariant *out_response = NULL;
352 GError *error = NULL;
354 g_assert(user_data != NULL);
356 if (net_nfc_gdbus_secure_element_call_send_apdu_finish(
362 DEBUG_ERR_MSG("Could not send apdu: %s", error->message);
363 result = NET_NFC_IPC_FAIL;
368 if (func_data->se_callback != NULL) {
369 net_nfc_se_send_apdu_cb se_callback =
370 (net_nfc_se_send_apdu_cb)func_data->se_callback;
371 data_s data = { NULL, };
373 net_nfc_util_gdbus_variant_to_data_s(out_response, &data);
375 se_callback(result, &data, func_data->se_data);
377 net_nfc_util_clear_data(&data);
384 static void get_atr_secure_element(GObject *source_object,
388 SeFuncData *func_data = (SeFuncData *)user_data;
389 net_nfc_error_e result;
390 GVariant *out_atr = NULL;
391 GError *error = NULL;
393 g_assert(user_data != NULL);
395 if (net_nfc_gdbus_secure_element_call_get_atr_finish(
401 DEBUG_ERR_MSG("Could not get atr: %s", error->message);
402 result = NET_NFC_IPC_FAIL;
407 if (func_data->se_callback != NULL) {
408 net_nfc_se_get_atr_cb se_callback =
409 (net_nfc_se_get_atr_cb)func_data->se_callback;
410 data_s data = { NULL, };
412 net_nfc_util_gdbus_variant_to_data_s(out_atr, &data);
414 se_callback(result, &data, func_data->se_data);
416 net_nfc_util_clear_data(&data);
424 net_nfc_error_e net_nfc_client_se_set_secure_element_type(
425 net_nfc_se_type_e se_type,
426 net_nfc_se_set_se_cb callback,
429 SeFuncData *func_data;
431 if (se_proxy == NULL) {
432 if (net_nfc_client_se_init() != NET_NFC_OK) {
433 DEBUG_ERR_MSG("se_proxy fail");
434 /* FIXME : return result of this error */
435 return NET_NFC_NOT_INITIALIZED;
439 /* prevent executing daemon when nfc is off */
440 if (net_nfc_client_manager_is_activated() == false)
441 return NET_NFC_NOT_ACTIVATED;
443 func_data = g_try_new0(SeFuncData, 1);
444 if (func_data == NULL)
445 return NET_NFC_ALLOC_FAIL;
447 func_data->se_callback = (gpointer)callback;
448 func_data->se_data = user_data;
450 net_nfc_gdbus_secure_element_call_set(
462 net_nfc_error_e net_nfc_client_se_set_secure_element_type_sync(
463 net_nfc_se_type_e se_type)
465 net_nfc_error_e result = NET_NFC_OK;
466 GError *error = NULL;
468 if (se_proxy == NULL) {
469 if (net_nfc_client_se_init() != NET_NFC_OK) {
470 DEBUG_ERR_MSG("se_proxy fail");
471 return NET_NFC_NOT_INITIALIZED;
475 /* prevent executing daemon when nfc is off */
476 if (net_nfc_client_manager_is_activated() == false)
477 return NET_NFC_NOT_ACTIVATED;
479 if (net_nfc_gdbus_secure_element_call_set_sync(
485 DEBUG_ERR_MSG("Set secure element failed: %s", error->message);
486 result = NET_NFC_IPC_FAIL;
495 net_nfc_error_e net_nfc_client_se_get_secure_element_type_sync(
496 net_nfc_se_type_e *se_type)
498 net_nfc_error_e result = NET_NFC_OK;
501 GError *error = NULL;
503 if (se_proxy == NULL) {
504 if (net_nfc_client_se_init() != NET_NFC_OK) {
505 DEBUG_ERR_MSG("se_proxy fail");
506 return NET_NFC_NOT_INITIALIZED;
510 /* prevent executing daemon when nfc is off */
511 if (net_nfc_client_manager_is_activated() == false)
512 return NET_NFC_NOT_ACTIVATED;
514 if (vconf_get_int(VCONFKEY_NFC_SE_TYPE, &type) == 0)
517 result = NET_NFC_OPERATION_FAIL;
519 if (net_nfc_gdbus_secure_element_call_get_sync(
526 SECURE_MSG("type [%d]", type);
529 DEBUG_ERR_MSG("get secure element failed: %s", error->message);
533 result = NET_NFC_IPC_FAIL;
540 net_nfc_error_e net_nfc_set_card_emulation_mode_sync(
541 net_nfc_card_emulation_mode_t mode)
543 net_nfc_error_e result = NET_NFC_OK;
544 GError *error = NULL;
546 if (se_proxy == NULL) {
547 if (net_nfc_client_se_init() != NET_NFC_OK) {
548 DEBUG_ERR_MSG("se_proxy fail");
549 return NET_NFC_NOT_INITIALIZED;
553 /* prevent executing daemon when nfc is off */
554 if (net_nfc_client_manager_is_activated() == false)
555 return NET_NFC_NOT_ACTIVATED;
557 if (net_nfc_gdbus_secure_element_call_set_card_emulation_sync(
563 DEBUG_ERR_MSG("Set card emulation failed: %s", error->message);
564 result = NET_NFC_IPC_FAIL;
573 net_nfc_error_e net_nfc_get_card_emulation_mode_sync(
574 net_nfc_card_emulation_mode_t *se_type)
576 net_nfc_error_e result = NET_NFC_OK;
578 GError *error = NULL;
580 if (se_proxy == NULL) {
581 if (net_nfc_client_se_init() != NET_NFC_OK) {
582 DEBUG_ERR_MSG("se_proxy fail");
583 return NET_NFC_NOT_INITIALIZED;
587 /* prevent executing daemon when nfc is off */
588 if (net_nfc_client_manager_is_activated() == false)
589 return NET_NFC_NOT_ACTIVATED;
591 if (net_nfc_gdbus_secure_element_call_get_card_emulation_sync(
599 DEBUG_ERR_MSG("get secure element failed: %s", error->message);
603 result = NET_NFC_IPC_FAIL;
610 net_nfc_error_e net_nfc_client_se_open_internal_secure_element(
611 net_nfc_se_type_e se_type,
612 net_nfc_se_open_se_cb callback,
615 SeFuncData *func_data;
617 if (auto_start_proxy == NULL) {
618 GError *error = NULL;
620 auto_start_proxy = net_nfc_gdbus_secure_element_proxy_new_for_bus_sync(
622 G_DBUS_PROXY_FLAGS_NONE,
623 "org.tizen.NetNfcService",
624 "/org/tizen/NetNfcService/SecureElement",
627 if (auto_start_proxy == NULL) {
628 DEBUG_ERR_MSG("Can not create proxy : %s", error->message);
631 return NET_NFC_UNKNOWN_ERROR;
635 /* allow this function even nfc is off */
637 func_data = g_try_new0(SeFuncData, 1);
638 if (func_data == NULL)
639 return NET_NFC_ALLOC_FAIL;
641 func_data->se_callback = (gpointer)callback;
642 func_data->se_data = user_data;
644 net_nfc_gdbus_secure_element_call_open_secure_element(
656 net_nfc_error_e net_nfc_client_se_open_internal_secure_element_sync(
657 net_nfc_se_type_e se_type,
658 net_nfc_target_handle_h *handle)
660 net_nfc_error_e result = NET_NFC_OK;
661 guint out_handle = 0;
662 GError *error = NULL;
665 return NET_NFC_NULL_PARAMETER;
667 if (auto_start_proxy == NULL) {
668 GError *error = NULL;
670 auto_start_proxy = net_nfc_gdbus_secure_element_proxy_new_for_bus_sync(
672 G_DBUS_PROXY_FLAGS_NONE,
673 "org.tizen.NetNfcService",
674 "/org/tizen/NetNfcService/SecureElement",
677 if (auto_start_proxy == NULL) {
678 DEBUG_ERR_MSG("Can not create proxy : %s", error->message);
681 return NET_NFC_UNKNOWN_ERROR;
685 /* allow this function even nfc is off */
687 if (net_nfc_gdbus_secure_element_call_open_secure_element_sync(
694 *handle = GUINT_TO_POINTER(out_handle);
696 DEBUG_ERR_MSG("Open internal secure element failed: %s",
698 result = NET_NFC_IPC_FAIL;
708 net_nfc_error_e net_nfc_client_se_close_internal_secure_element(
709 net_nfc_target_handle_h handle,
710 net_nfc_se_close_se_cb callback,
713 SeFuncData *func_data;
715 if (auto_start_proxy == NULL) {
716 GError *error = NULL;
718 auto_start_proxy = net_nfc_gdbus_secure_element_proxy_new_for_bus_sync(
720 G_DBUS_PROXY_FLAGS_NONE,
721 "org.tizen.NetNfcService",
722 "/org/tizen/NetNfcService/SecureElement",
725 if (auto_start_proxy == NULL) {
726 DEBUG_ERR_MSG("Can not create proxy : %s", error->message);
729 return NET_NFC_UNKNOWN_ERROR;
733 /* allow this function even nfc is off */
735 func_data = g_try_new0(SeFuncData, 1);
736 if (func_data == NULL)
737 return NET_NFC_ALLOC_FAIL;
739 func_data->se_callback = (gpointer)callback;
740 func_data->se_data = user_data;
742 net_nfc_gdbus_secure_element_call_close_secure_element(
744 GPOINTER_TO_UINT(handle),
746 close_secure_element,
754 net_nfc_error_e net_nfc_client_se_close_internal_secure_element_sync(
755 net_nfc_target_handle_h handle)
757 net_nfc_error_e result = NET_NFC_OK;
758 GError *error = NULL;
760 if (auto_start_proxy == NULL) {
761 GError *error = NULL;
763 auto_start_proxy = net_nfc_gdbus_secure_element_proxy_new_for_bus_sync(
765 G_DBUS_PROXY_FLAGS_NONE,
766 "org.tizen.NetNfcService",
767 "/org/tizen/NetNfcService/SecureElement",
770 if (auto_start_proxy == NULL) {
771 DEBUG_ERR_MSG("Can not create proxy : %s", error->message);
774 return NET_NFC_UNKNOWN_ERROR;
778 /* allow this function even nfc is off */
780 if (net_nfc_gdbus_secure_element_call_close_secure_element_sync(
782 GPOINTER_TO_UINT(handle),
786 DEBUG_ERR_MSG("close internal secure element failed: %s",
788 result = NET_NFC_IPC_FAIL;
798 net_nfc_error_e net_nfc_client_se_get_atr(
799 net_nfc_target_handle_h handle,
800 net_nfc_se_get_atr_cb callback,
803 SeFuncData *func_data;
805 if (auto_start_proxy == NULL) {
806 GError *error = NULL;
808 auto_start_proxy = net_nfc_gdbus_secure_element_proxy_new_for_bus_sync(
810 G_DBUS_PROXY_FLAGS_NONE,
811 "org.tizen.NetNfcService",
812 "/org/tizen/NetNfcService/SecureElement",
815 if (auto_start_proxy == NULL) {
816 DEBUG_ERR_MSG("Can not create proxy : %s", error->message);
819 return NET_NFC_UNKNOWN_ERROR;
823 /* allow this function even nfc is off */
825 func_data = g_try_new0(SeFuncData, 1);
826 if (func_data == NULL)
827 return NET_NFC_ALLOC_FAIL;
829 func_data->se_callback = (gpointer)callback;
830 func_data->se_data = user_data;
832 net_nfc_gdbus_secure_element_call_get_atr(
834 GPOINTER_TO_UINT(handle),
836 get_atr_secure_element,
844 net_nfc_error_e net_nfc_client_se_get_atr_sync(
845 net_nfc_target_handle_h handle,
848 net_nfc_error_e result = NET_NFC_OK;
849 GVariant *out_atr = NULL;
850 GError *error = NULL;
853 return NET_NFC_NULL_PARAMETER;
857 if (auto_start_proxy == NULL) {
858 GError *error = NULL;
860 auto_start_proxy = net_nfc_gdbus_secure_element_proxy_new_for_bus_sync(
862 G_DBUS_PROXY_FLAGS_NONE,
863 "org.tizen.NetNfcService",
864 "/org/tizen/NetNfcService/SecureElement",
867 if (auto_start_proxy == NULL) {
868 DEBUG_ERR_MSG("Can not create proxy : %s", error->message);
871 return NET_NFC_UNKNOWN_ERROR;
875 /* allow this function even nfc is off */
877 if (net_nfc_gdbus_secure_element_call_get_atr_sync(
879 GPOINTER_TO_UINT(handle),
884 *atr = net_nfc_util_gdbus_variant_to_data(out_atr);
886 DEBUG_ERR_MSG("Get attributes failed: %s", error->message);
887 result = NET_NFC_IPC_FAIL;
897 net_nfc_error_e net_nfc_client_se_send_apdu(
898 net_nfc_target_handle_h handle,
900 net_nfc_se_send_apdu_cb callback,
903 SeFuncData *func_data;
906 if (auto_start_proxy == NULL) {
907 GError *error = NULL;
909 auto_start_proxy = net_nfc_gdbus_secure_element_proxy_new_for_bus_sync(
911 G_DBUS_PROXY_FLAGS_NONE,
912 "org.tizen.NetNfcService",
913 "/org/tizen/NetNfcService/SecureElement",
916 if (auto_start_proxy == NULL) {
917 DEBUG_ERR_MSG("Can not create proxy : %s", error->message);
920 return NET_NFC_UNKNOWN_ERROR;
924 /* allow this function even nfc is off */
926 arg_data = net_nfc_util_gdbus_data_to_variant((data_s *)apdu_data);
927 if (arg_data == NULL)
928 return NET_NFC_INVALID_PARAM;
930 func_data = g_try_new0(SeFuncData, 1);
931 if (func_data == NULL) {
932 g_variant_unref(arg_data);
934 return NET_NFC_ALLOC_FAIL;
937 func_data->se_callback = (gpointer)callback;
938 func_data->se_data = user_data;
940 net_nfc_gdbus_secure_element_call_send_apdu(
942 GPOINTER_TO_UINT(handle),
945 send_apdu_secure_element,
953 net_nfc_error_e net_nfc_client_se_send_apdu_sync(
954 net_nfc_target_handle_h handle,
958 net_nfc_error_e result = NET_NFC_OK;
959 GVariant *out_data = NULL;
960 GError *error = NULL;
963 if (response == NULL)
964 return NET_NFC_NULL_PARAMETER;
968 if (auto_start_proxy == NULL) {
969 GError *error = NULL;
971 auto_start_proxy = net_nfc_gdbus_secure_element_proxy_new_for_bus_sync(
973 G_DBUS_PROXY_FLAGS_NONE,
974 "org.tizen.NetNfcService",
975 "/org/tizen/NetNfcService/SecureElement",
978 if (auto_start_proxy == NULL) {
979 DEBUG_ERR_MSG("Can not create proxy : %s", error->message);
982 return NET_NFC_UNKNOWN_ERROR;
986 /* allow this function even nfc is off */
988 arg_data = net_nfc_util_gdbus_data_to_variant((data_s *)apdu_data);
989 if (arg_data == NULL)
990 return NET_NFC_INVALID_PARAM;
992 if (net_nfc_gdbus_secure_element_call_send_apdu_sync(
994 GPOINTER_TO_UINT(handle),
1000 *response = net_nfc_util_gdbus_variant_to_data(out_data);
1002 DEBUG_ERR_MSG("Send APDU failed: %s", error->message);
1003 result = NET_NFC_IPC_FAIL;
1005 g_error_free(error);
1013 void net_nfc_client_se_set_ese_detection_cb(
1014 net_nfc_client_se_ese_detected_event callback,
1017 if (se_proxy == NULL) {
1018 if (net_nfc_client_se_init() != NET_NFC_OK) {
1019 DEBUG_ERR_MSG("se_proxy fail");
1020 /* FIXME : return result of this error */
1025 se_esedetecthandler.se_ese_detected_cb = callback;
1026 se_esedetecthandler.se_ese_detected_data = user_data;
1031 void net_nfc_client_se_unset_ese_detection_cb(void)
1033 se_esedetecthandler.se_ese_detected_cb = NULL;
1034 se_esedetecthandler.se_ese_detected_data = NULL;
1039 void net_nfc_client_se_set_transaction_event_cb(
1040 net_nfc_se_type_e se_type,
1041 net_nfc_client_se_transaction_event callback,
1044 if (se_proxy == NULL) {
1045 if (net_nfc_client_se_init() != NET_NFC_OK) {
1046 DEBUG_ERR_MSG("se_proxy fail");
1047 /* FIXME : return result of this error */
1052 if (se_type == NET_NFC_SE_TYPE_ESE) {
1053 ese_transactionEventHandler.transaction_event_cb = callback;
1054 ese_transactionEventHandler.transaction_event_data = user_data;
1055 } else if (se_type == NET_NFC_SE_TYPE_UICC) {
1056 uicc_transactionEventHandler.transaction_event_cb = callback;
1057 uicc_transactionEventHandler.transaction_event_data = user_data;
1063 void net_nfc_client_se_unset_transaction_event_cb(net_nfc_se_type_e type)
1065 if (type == NET_NFC_SE_TYPE_ESE) {
1066 ese_transactionEventHandler.transaction_event_cb = NULL;
1067 ese_transactionEventHandler.transaction_event_data = NULL;
1068 } else if (type == NET_NFC_SE_TYPE_UICC) {
1069 uicc_transactionEventHandler.transaction_event_cb = NULL;
1070 uicc_transactionEventHandler.transaction_event_data = NULL;
1075 void net_nfc_client_se_set_event_cb(net_nfc_client_se_event callback,
1078 if (se_proxy == NULL) {
1079 if (net_nfc_client_se_init() != NET_NFC_OK) {
1080 DEBUG_ERR_MSG("se_proxy fail");
1081 /* FIXME : return result of this error */
1086 se_eventhandler.se_event_cb = callback;
1087 se_eventhandler.se_event_data = user_data;
1092 void net_nfc_client_se_unset_event_cb(void)
1094 se_eventhandler.se_event_cb = NULL;
1095 se_eventhandler.se_event_data = NULL;
1099 net_nfc_error_e net_nfc_client_se_set_transaction_fg_dispatch(int mode)
1101 net_nfc_error_e result = NET_NFC_OK;
1102 GError *error = NULL;
1104 if (auto_start_proxy == NULL) {
1105 GError *error = NULL;
1107 auto_start_proxy = net_nfc_gdbus_secure_element_proxy_new_for_bus_sync(
1109 G_DBUS_PROXY_FLAGS_NONE,
1110 "org.tizen.NetNfcService",
1111 "/org/tizen/NetNfcService/SecureElement",
1114 if (auto_start_proxy == NULL) {
1115 DEBUG_ERR_MSG("Can not create proxy : %s", error->message);
1116 g_error_free(error);
1118 return NET_NFC_UNKNOWN_ERROR;
1122 if (net_nfc_gdbus_secure_element_call_set_transaction_fg_dispatch_sync(
1129 DEBUG_ERR_MSG("set transaction fg dispatch failed: %s", error->message);
1130 result = NET_NFC_IPC_FAIL;
1132 g_error_free(error);
1139 net_nfc_error_e net_nfc_client_se_set_default_route_sync(
1140 net_nfc_se_type_e switch_on,
1141 net_nfc_se_type_e switch_off,
1142 net_nfc_se_type_e battery_off)
1144 net_nfc_error_e result = NET_NFC_OK;
1145 GError *error = NULL;
1147 if (se_proxy == NULL) {
1148 result = net_nfc_client_se_init();
1149 if (result != NET_NFC_OK) {
1150 DEBUG_ERR_MSG("net_nfc_client_se_init failed, [%d]", result);
1152 return NET_NFC_NOT_INITIALIZED;
1156 if (net_nfc_gdbus_secure_element_call_set_default_route_sync(
1164 DEBUG_ERR_MSG("Set Route Aid failed: %s", error->message);
1165 result = NET_NFC_IPC_FAIL;
1167 g_error_free(error);
1170 DEBUG_CLIENT_MSG("net_nfc_gdbus_secure_element_call_set_default_route_sync end");
1176 net_nfc_error_e net_nfc_client_se_is_activated_aid_handler_sync(
1177 net_nfc_se_type_e se_type, const char *aid, bool *activated)
1179 net_nfc_error_e result = NET_NFC_OK;
1180 GError *error = NULL;
1181 gboolean ret = false;
1183 if (activated == NULL)
1184 return NET_NFC_NULL_PARAMETER;
1186 if (se_proxy == NULL) {
1187 result = net_nfc_client_se_init();
1188 if (result != NET_NFC_OK) {
1189 DEBUG_ERR_MSG("net_nfc_client_se_init failed, [%d]", result);
1191 return NET_NFC_NOT_INITIALIZED;
1195 if (net_nfc_gdbus_secure_element_call_is_activated_aid_handler_sync(
1205 DEBUG_ERR_MSG("net_nfc_gdbus_secure_element_call_is_activated_aid_handler_sync failed : %s", error->message);
1206 result = NET_NFC_IPC_FAIL;
1208 g_error_free(error);
1215 net_nfc_error_e net_nfc_client_se_is_activated_category_handler_sync(
1216 net_nfc_se_type_e se_type,
1217 net_nfc_card_emulation_category_t category, bool *activated)
1219 net_nfc_error_e result = NET_NFC_OK;
1220 GError *error = NULL;
1221 gboolean ret = false;
1223 if (activated == NULL)
1224 return NET_NFC_NULL_PARAMETER;
1226 if (se_proxy == NULL) {
1227 result = net_nfc_client_se_init();
1228 if (result != NET_NFC_OK) {
1229 DEBUG_ERR_MSG("net_nfc_client_se_init failed, [%d]", result);
1231 return NET_NFC_NOT_INITIALIZED;
1235 if (net_nfc_gdbus_secure_element_call_is_activated_category_handler_sync(
1245 DEBUG_ERR_MSG("net_nfc_gdbus_secure_element_call_is_activated_category_handler_sync failed : %s", error->message);
1246 result = NET_NFC_IPC_FAIL;
1248 g_error_free(error);
1255 net_nfc_error_e net_nfc_client_se_get_registered_aids_count_sync(
1256 net_nfc_se_type_e se_type,
1257 net_nfc_card_emulation_category_t category,
1260 net_nfc_error_e result = NET_NFC_OK;
1261 GError *error = NULL;
1262 GVariant *aids = NULL;
1265 return NET_NFC_NULL_PARAMETER;
1267 if (se_proxy == NULL) {
1268 result = net_nfc_client_se_init();
1269 if (result != NET_NFC_OK) {
1270 DEBUG_ERR_MSG("net_nfc_client_se_init failed, [%d]", result);
1272 return NET_NFC_NOT_INITIALIZED;
1276 if (net_nfc_gdbus_secure_element_call_get_registered_aids_sync(
1284 DEBUG_ERR_MSG("net_nfc_gdbus_secure_element_call_get_registered_aids_sync failed : %s", error->message);
1285 result = NET_NFC_IPC_FAIL;
1287 g_error_free(error);
1290 if (result == NET_NFC_OK) {
1293 g_variant_iter_init(&iter, aids);
1295 *count = g_variant_iter_n_children(&iter);
1297 g_variant_unref(aids);
1304 net_nfc_error_e net_nfc_client_se_foreach_registered_aids_sync(
1305 net_nfc_se_type_e se_type,
1306 net_nfc_card_emulation_category_t category,
1307 net_nfc_client_se_registered_aid_cb callback,
1310 net_nfc_error_e result = NET_NFC_OK;
1311 GError *error = NULL;
1312 GVariant *aids = NULL;
1314 if (callback == NULL)
1315 return NET_NFC_NULL_PARAMETER;
1317 if (se_proxy == NULL) {
1318 result = net_nfc_client_se_init();
1319 if (result != NET_NFC_OK) {
1320 DEBUG_ERR_MSG("net_nfc_client_se_init failed, [%d]", result);
1322 return NET_NFC_NOT_INITIALIZED;
1326 if (net_nfc_gdbus_secure_element_call_get_registered_aids_sync(
1334 DEBUG_ERR_MSG("net_nfc_gdbus_secure_element_call_get_registered_aids_sync failed : %s", error->message);
1335 result = NET_NFC_IPC_FAIL;
1337 g_error_free(error);
1340 if (result == NET_NFC_OK) {
1345 g_variant_iter_init(&iter, aids);
1347 while (g_variant_iter_loop(&iter, "(sb)", &aid, &manifest) == true)
1348 callback(se_type, aid, (bool)manifest, user_data);
1356 net_nfc_error_e net_nfc_client_se_register_aids_sync(net_nfc_se_type_e se_type,
1357 net_nfc_card_emulation_category_t category, const char *aid, ...)
1359 net_nfc_error_e result = NET_NFC_OK;
1360 GError *error = NULL;
1362 if (se_proxy == NULL) {
1363 result = net_nfc_client_se_init();
1364 if (result != NET_NFC_OK) {
1365 DEBUG_ERR_MSG("net_nfc_client_se_init failed, [%d]", result);
1367 return NET_NFC_NOT_INITIALIZED;
1371 if (net_nfc_gdbus_secure_element_call_register_aid_sync(
1379 DEBUG_ERR_MSG("net_nfc_gdbus_secure_element_call_register_aid_sync failed : %s", error->message);
1380 result = NET_NFC_IPC_FAIL;
1382 g_error_free(error);
1389 net_nfc_error_e net_nfc_client_se_unregister_aid_sync(net_nfc_se_type_e se_type,
1390 net_nfc_card_emulation_category_t category, const char *aid)
1392 net_nfc_error_e result = NET_NFC_OK;
1393 GError *error = NULL;
1395 if (se_proxy == NULL) {
1396 result = net_nfc_client_se_init();
1397 if (result != NET_NFC_OK) {
1398 DEBUG_ERR_MSG("net_nfc_client_se_init failed, [%d]", result);
1400 return NET_NFC_NOT_INITIALIZED;
1404 if (net_nfc_gdbus_secure_element_call_unregister_aid_sync(
1412 DEBUG_ERR_MSG("net_nfc_gdbus_secure_element_call_unregister_aid_sync failed : %s", error->message);
1413 result = NET_NFC_IPC_FAIL;
1415 g_error_free(error);
1422 net_nfc_error_e net_nfc_client_se_unregister_aids_sync(net_nfc_se_type_e se_type, net_nfc_card_emulation_category_t category)
1424 net_nfc_error_e result = NET_NFC_OK;
1425 GError *error = NULL;
1427 if (se_proxy == NULL) {
1428 result = net_nfc_client_se_init();
1429 if (result != NET_NFC_OK) {
1430 DEBUG_ERR_MSG("net_nfc_client_se_init failed, [%d]", result);
1432 return NET_NFC_NOT_INITIALIZED;
1436 if (net_nfc_gdbus_secure_element_call_unregister_aids_sync(
1443 DEBUG_ERR_MSG("net_nfc_gdbus_secure_element_call_unregister_aids_sync failed : %s", error->message);
1444 result = NET_NFC_IPC_FAIL;
1446 g_error_free(error);
1453 net_nfc_error_e net_nfc_client_se_foreach_registered_handlers_sync(
1454 net_nfc_card_emulation_category_t category,
1455 net_nfc_client_se_registered_handler_cb callback,
1458 net_nfc_error_e result = NET_NFC_OK;
1459 GError *error = NULL;
1460 GVariant *handlers = NULL;
1462 if (callback == NULL)
1463 return NET_NFC_NULL_PARAMETER;
1465 if (se_proxy == NULL) {
1466 result = net_nfc_client_se_init();
1467 if (result != NET_NFC_OK) {
1468 DEBUG_ERR_MSG("net_nfc_client_se_init failed, [%d]", result);
1470 return NET_NFC_NOT_INITIALIZED;
1474 if (net_nfc_gdbus_secure_element_call_get_registered_handlers_sync(
1481 DEBUG_ERR_MSG("net_nfc_gdbus_secure_element_call_get_registered_handlers_sync failed : %s", error->message);
1482 result = NET_NFC_IPC_FAIL;
1484 g_error_free(error);
1487 if (result == NET_NFC_OK) {
1489 const gchar *handler;
1492 g_variant_iter_init(&iter, handlers);
1494 while (g_variant_iter_loop(&iter, "(is)", &count, &handler) == true)
1495 callback(handler, count, user_data);
1502 net_nfc_error_e net_nfc_client_se_add_route_aid_sync(
1503 const char *package, net_nfc_se_type_e se_type,
1504 net_nfc_card_emulation_category_t category, const char *aid,
1505 bool unlock_required, int power)
1507 net_nfc_error_e result = NET_NFC_OK;
1508 GError *error = NULL;
1510 if (auto_start_proxy == NULL) {
1511 GError *error = NULL;
1513 auto_start_proxy = net_nfc_gdbus_secure_element_proxy_new_for_bus_sync(
1515 G_DBUS_PROXY_FLAGS_NONE,
1516 "org.tizen.NetNfcService",
1517 "/org/tizen/NetNfcService/SecureElement",
1520 if (auto_start_proxy == NULL) {
1521 DEBUG_ERR_MSG("Can not create proxy : %s", error->message);
1522 g_error_free(error);
1524 return NET_NFC_UNKNOWN_ERROR;
1528 if (net_nfc_gdbus_secure_element_call_add_route_aid_sync(
1539 DEBUG_ERR_MSG("Set Route Aid failed: %s", error->message);
1540 result = NET_NFC_IPC_FAIL;
1542 g_error_free(error);
1545 DEBUG_CLIENT_MSG("net_nfc_gdbus_secure_element_call_add_route_aid_sync end");
1551 net_nfc_error_e net_nfc_client_se_remove_route_aid_sync(
1552 const char *package, const char *aid)
1554 net_nfc_error_e result = NET_NFC_OK;
1555 GError *error = NULL;
1557 if (auto_start_proxy == NULL) {
1558 GError *error = NULL;
1560 auto_start_proxy = net_nfc_gdbus_secure_element_proxy_new_for_bus_sync(
1562 G_DBUS_PROXY_FLAGS_NONE,
1563 "org.tizen.NetNfcService",
1564 "/org/tizen/NetNfcService/SecureElement",
1567 if (auto_start_proxy == NULL) {
1568 DEBUG_ERR_MSG("Can not create proxy : %s", error->message);
1569 g_error_free(error);
1571 return NET_NFC_UNKNOWN_ERROR;
1575 if (net_nfc_gdbus_secure_element_call_remove_route_aid_sync(
1582 DEBUG_ERR_MSG("Remove Route Aid failed: %s", error->message);
1583 result = NET_NFC_IPC_FAIL;
1585 g_error_free(error);
1588 DEBUG_CLIENT_MSG("net_nfc_gdbus_hce_call_set_route_aid_sync end");
1594 net_nfc_error_e net_nfc_client_se_remove_package_aids_sync(
1595 const char *package)
1597 net_nfc_error_e result = NET_NFC_OK;
1598 GError *error = NULL;
1600 if (auto_start_proxy == NULL) {
1601 GError *error = NULL;
1603 auto_start_proxy = net_nfc_gdbus_secure_element_proxy_new_for_bus_sync(
1605 G_DBUS_PROXY_FLAGS_NONE,
1606 "org.tizen.NetNfcService",
1607 "/org/tizen/NetNfcService/SecureElement",
1610 if (auto_start_proxy == NULL) {
1611 DEBUG_ERR_MSG("Can not create proxy : %s", error->message);
1612 g_error_free(error);
1614 return NET_NFC_UNKNOWN_ERROR;
1618 if (net_nfc_gdbus_secure_element_call_remove_package_aids_sync(
1624 DEBUG_ERR_MSG("Remove Package Aid failed: %s", error->message);
1625 result = NET_NFC_IPC_FAIL;
1627 g_error_free(error);
1630 DEBUG_CLIENT_MSG("net_nfc_client_se_remove_package_aids_sync end");
1636 net_nfc_error_e net_nfc_client_se_set_preferred_handler_sync(bool state)
1638 net_nfc_error_e result = NET_NFC_OK;
1639 GError *error = NULL;
1641 if (se_proxy == NULL) {
1642 result = net_nfc_client_se_init();
1643 if (result != NET_NFC_OK) {
1644 DEBUG_ERR_MSG("net_nfc_client_se_init failed, [%d]", result);
1646 return NET_NFC_NOT_INITIALIZED;
1650 if (net_nfc_gdbus_secure_element_call_set_preferred_handler_sync(
1654 NULL, &error) == FALSE) {
1655 DEBUG_ERR_MSG("net_nfc_gdbus_secure_element_call_set_preferred_handler_sync failed : %s", error->message);
1656 result = NET_NFC_IPC_FAIL;
1658 g_error_free(error);
1665 net_nfc_error_e net_nfc_client_se_get_handler_storage_info_sync(
1666 net_nfc_card_emulation_category_t category, int *used, int *max)
1668 net_nfc_error_e result = NET_NFC_OK;
1669 GError *error = NULL;
1671 if (se_proxy == NULL) {
1672 result = net_nfc_client_se_init();
1673 if (result != NET_NFC_OK) {
1674 DEBUG_ERR_MSG("net_nfc_client_se_init failed, [%d]", result);
1676 return NET_NFC_NOT_INITIALIZED;
1680 if (net_nfc_gdbus_secure_element_call_get_handler_storage_info_sync(
1686 NULL, &error) == FALSE) {
1687 DEBUG_ERR_MSG("net_nfc_gdbus_secure_element_call_get_handler_storage_info_sync failed : %s", error->message);
1688 result = NET_NFC_IPC_FAIL;
1690 g_error_free(error);
1697 net_nfc_error_e net_nfc_client_se_get_conflict_handlers_sync(
1698 const char *package, net_nfc_card_emulation_category_t category,
1699 const char *aid, char ***handlers)
1701 net_nfc_error_e result = NET_NFC_OK;
1702 GError *error = NULL;
1703 GVariant *packages = NULL;
1705 if (se_proxy == NULL) {
1706 result = net_nfc_client_se_init();
1707 if (result != NET_NFC_OK) {
1708 DEBUG_ERR_MSG("net_nfc_client_se_init failed, [%d]", result);
1710 return NET_NFC_NOT_INITIALIZED;
1714 if (net_nfc_gdbus_secure_element_call_get_conflict_handlers_sync(
1721 NULL, &error) == true) {
1722 if (result == NET_NFC_DATA_CONFLICTED) {
1727 g_variant_iter_init(&iter, packages);
1728 len = g_variant_iter_n_children(&iter);
1730 SECURE_MSG("conflict count [%d]", len);
1736 pkgs = g_new0(gchar *, len + 1);
1738 for (i = 0; i < len; i++) {
1739 if (g_variant_iter_next(&iter, "(s)", &temp) == true) {
1740 SECURE_MSG("conflict package [%s]", temp);
1741 pkgs[i] = g_strdup(temp);
1743 DEBUG_ERR_MSG("g_variant_iter_next failed");
1751 DEBUG_ERR_MSG("net_nfc_gdbus_secure_element_call_get_conflict_handlers_sync failed : %s", error->message);
1752 result = NET_NFC_IPC_FAIL;
1754 g_error_free(error);
1760 net_nfc_error_e net_nfc_client_se_init(void)
1762 GError *error = NULL;
1765 DEBUG_CLIENT_MSG("Already initialized");
1770 se_proxy = net_nfc_gdbus_secure_element_proxy_new_for_bus_sync(
1772 G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START,
1773 "org.tizen.NetNfcService",
1774 "/org/tizen/NetNfcService/SecureElement",
1777 if (se_proxy == NULL) {
1778 DEBUG_ERR_MSG("Can not create proxy : %s", error->message);
1780 g_error_free(error);
1782 return NET_NFC_UNKNOWN_ERROR;
1785 g_signal_connect(se_proxy, "se-type-changed",
1786 G_CALLBACK(se_type_changed), NULL);
1788 g_signal_connect(se_proxy, "ese-detected",
1789 G_CALLBACK(se_ese_detected), NULL);
1791 g_signal_connect(se_proxy, "transaction-event",
1792 G_CALLBACK(se_transaction_event), NULL);
1794 g_signal_connect(se_proxy, "card-emulation-mode-changed",
1795 G_CALLBACK(se_card_emulation_mode_changed), NULL);
1797 g_signal_connect(se_proxy, "rf-detected",
1798 G_CALLBACK(se_rf_detected), NULL);
1804 void net_nfc_client_se_deinit(void)
1807 g_object_unref(se_proxy);
1811 if (auto_start_proxy) {
1812 g_object_unref(auto_start_proxy);
1813 auto_start_proxy = NULL;
1817 /* LCOV_EXCL_STOP */