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")))
35 typedef struct _SeFuncData SeFuncData;
43 typedef struct _SeEventHandler SeEventHandler;
45 struct _SeEventHandler
47 net_nfc_client_se_event se_event_cb;
48 gpointer se_event_data;
51 typedef struct _SeTransEventHandler SeTransEventHandler;
53 struct _SeTransEventHandler
55 net_nfc_client_se_transaction_event transaction_event_cb;
56 gpointer transaction_event_data;
59 typedef struct _SeESEDetectedHandler SeESEDetectedHandler;
61 struct _SeESEDetectedHandler
63 net_nfc_client_se_ese_detected_event se_ese_detected_cb;
64 gpointer se_ese_detected_data;
68 static NetNfcGDbusSecureElement *se_proxy = NULL;
69 static NetNfcGDbusSecureElement *auto_start_proxy = NULL;
71 static SeEventHandler se_eventhandler;
72 static SeTransEventHandler uicc_transactionEventHandler;
73 static SeTransEventHandler ese_transactionEventHandler;
74 static SeESEDetectedHandler se_esedetecthandler;
76 static void se_ese_detected(GObject *source_object,
81 static void se_type_changed(GObject *source_object,
84 static void set_secure_element(GObject *source_object,
88 static void open_secure_element(GObject *source_object,
92 static void close_secure_element(GObject *source_object,
96 static void send_apdu_secure_element(GObject *source_object,
100 static void get_atr_secure_element(GObject *source_object,
104 static void se_rf_detected(GObject *source_object,
109 static void se_ese_detected(GObject *source_object,
114 INFO_MSG(">>> SIGNAL arrived");
116 if (se_esedetecthandler.se_ese_detected_cb != NULL) {
117 data_s buffer_data = { NULL, 0 };
118 net_nfc_client_se_ese_detected_event callback =
119 (net_nfc_client_se_ese_detected_event)se_esedetecthandler.se_ese_detected_cb;
121 net_nfc_util_gdbus_variant_to_data_s(arg_data, &buffer_data);
123 callback((net_nfc_target_handle_h)GUINT_TO_POINTER(arg_handle),
124 arg_se_type, &buffer_data,
125 se_esedetecthandler.se_ese_detected_data);
127 net_nfc_util_clear_data(&buffer_data);
131 static void se_rf_detected(GObject *source_object,
136 INFO_MSG(">>> SIGNAL arrived");
138 if (se_eventhandler.se_event_cb != NULL)
140 net_nfc_client_se_event callback =
141 (net_nfc_client_se_event)se_eventhandler.se_event_cb;
143 callback((net_nfc_message_e)NET_NFC_MESSAGE_SE_FIELD_ON,
144 se_eventhandler.se_event_data);
149 static void se_type_changed(GObject *source_object,
152 INFO_MSG(">>> SIGNAL arrived");
154 if (se_eventhandler.se_event_cb != NULL)
156 net_nfc_client_se_event callback =
157 (net_nfc_client_se_event)se_eventhandler.se_event_cb;
159 callback((net_nfc_message_e)NET_NFC_MESSAGE_SE_TYPE_CHANGED,
160 se_eventhandler.se_event_data);
165 static void se_transaction_event(GObject *source_object,
172 void *user_data = NULL;
173 net_nfc_client_se_transaction_event callback = NULL;
174 pid_t mypid = getpid();
176 INFO_MSG(">>> SIGNAL arrived");
178 if (fg_dispatch == true && focus_app_pid != getpgid(mypid)) {
179 SECURE_MSG("skip transaction event, fg_dispatch [%d], focus_app_pid [%d]", fg_dispatch, focus_app_pid);
182 #ifdef CHECK_NFC_ACCESS_FOR_ESE
183 if (net_nfc_gdbus_secure_element_call_check_transaction_permission_sync(
184 NET_NFC_GDBUS_SECURE_ELEMENT(source_object),
189 DEBUG_ERR_MSG("net_nfc_gdbus_secure_element_call_check_transaction_permission_sync failed : %s", error->message);
194 if (result != NET_NFC_OK) {
195 DEBUG_ERR_MSG("not allowed process [%d]", result);
201 case NET_NFC_SE_TYPE_UICC :
202 if (uicc_transactionEventHandler.transaction_event_cb != NULL)
204 callback = uicc_transactionEventHandler.transaction_event_cb;
205 user_data = uicc_transactionEventHandler.transaction_event_data;
209 case NET_NFC_SE_TYPE_ESE :
210 if (ese_transactionEventHandler.transaction_event_cb != NULL)
212 callback = ese_transactionEventHandler.transaction_event_cb;
213 user_data = ese_transactionEventHandler.transaction_event_data;
218 DEBUG_ERR_MSG("Transaction event SE type wrong [%d]", arg_se_type);
222 if (callback != NULL) {
223 data_s aid = { NULL, 0 };
224 data_s param = { NULL, 0 };
226 net_nfc_util_gdbus_variant_to_data_s(arg_aid, &aid);
227 net_nfc_util_gdbus_variant_to_data_s(arg_param, ¶m);
229 callback(arg_se_type, &aid, ¶m, user_data);
231 net_nfc_util_clear_data(¶m);
232 net_nfc_util_clear_data(&aid);
236 static void se_card_emulation_mode_changed(GObject *source_object,
239 INFO_MSG(">>> SIGNAL arrived");
241 if (se_eventhandler.se_event_cb != NULL)
243 net_nfc_client_se_event callback =
244 (net_nfc_client_se_event)se_eventhandler.se_event_cb;
246 callback((net_nfc_message_e)NET_NFC_MESSAGE_SE_CARD_EMULATION_CHANGED,
247 se_eventhandler.se_event_data);
251 static void set_secure_element(GObject *source_object,
255 SeFuncData *func_data = (SeFuncData *)user_data;
256 net_nfc_error_e result;
257 GError *error = NULL;
259 g_assert(user_data != NULL);
261 if (net_nfc_gdbus_secure_element_call_set_finish(se_proxy,
267 DEBUG_ERR_MSG("Could not set secure element: %s",
269 result = NET_NFC_IPC_FAIL;
274 if (func_data->se_callback != NULL)
276 net_nfc_se_set_se_cb se_callback =
277 (net_nfc_se_set_se_cb)func_data->se_callback;
279 se_callback(result, func_data->se_data);
285 static void open_secure_element(GObject *source_object,
289 SeFuncData *func_data = (SeFuncData *)user_data;
290 net_nfc_error_e result;
291 guint out_handle = 0;
292 GError *error = NULL;
294 g_assert(user_data != NULL);
296 if (net_nfc_gdbus_secure_element_call_open_secure_element_finish(
304 DEBUG_ERR_MSG("Could not open secure element: %s",
306 result = NET_NFC_IPC_FAIL;
311 if (func_data->se_callback != NULL)
313 net_nfc_se_open_se_cb se_callback =
314 (net_nfc_se_open_se_cb)func_data->se_callback;
317 (net_nfc_target_handle_h)GUINT_TO_POINTER(out_handle),
325 static void close_secure_element(GObject *source_object,
329 SeFuncData *func_data = (SeFuncData *)user_data;
330 net_nfc_error_e result;
331 GError *error = NULL;
333 g_assert(user_data != NULL);
335 if (net_nfc_gdbus_secure_element_call_close_secure_element_finish(
341 DEBUG_ERR_MSG("Could not close secure element: %s", error->message);
342 result = NET_NFC_IPC_FAIL;
347 if (func_data->se_callback != NULL)
349 net_nfc_se_close_se_cb se_callback =
350 (net_nfc_se_close_se_cb)func_data->se_callback;
352 se_callback(result, func_data->se_data);
359 static void send_apdu_secure_element(GObject *source_object,
363 SeFuncData *func_data = (SeFuncData *)user_data;
364 net_nfc_error_e result;
365 GVariant *out_response = NULL;
366 GError *error = NULL;
368 g_assert(user_data != NULL);
370 if (net_nfc_gdbus_secure_element_call_send_apdu_finish(
377 DEBUG_ERR_MSG("Could not send apdu: %s", error->message);
378 result = NET_NFC_IPC_FAIL;
383 if (func_data->se_callback != NULL)
385 net_nfc_se_send_apdu_cb se_callback =
386 (net_nfc_se_send_apdu_cb)func_data->se_callback;
387 data_s data = { NULL, };
389 net_nfc_util_gdbus_variant_to_data_s(out_response, &data);
391 se_callback(result, &data, func_data->se_data);
393 net_nfc_util_clear_data(&data);
400 static void get_atr_secure_element(GObject *source_object,
404 SeFuncData *func_data = (SeFuncData *)user_data;
405 net_nfc_error_e result;
406 GVariant *out_atr = NULL;
407 GError *error = NULL;
409 g_assert(user_data != NULL);
411 if (net_nfc_gdbus_secure_element_call_get_atr_finish(
418 DEBUG_ERR_MSG("Could not get atr: %s", error->message);
419 result = NET_NFC_IPC_FAIL;
424 if (func_data->se_callback != NULL)
426 net_nfc_se_get_atr_cb se_callback =
427 (net_nfc_se_get_atr_cb)func_data->se_callback;
428 data_s data = { NULL, };
430 net_nfc_util_gdbus_variant_to_data_s(out_atr, &data);
432 se_callback(result, &data, func_data->se_data);
434 net_nfc_util_clear_data(&data);
442 net_nfc_error_e net_nfc_client_se_set_secure_element_type(
443 net_nfc_se_type_e se_type,
444 net_nfc_se_set_se_cb callback,
447 SeFuncData *func_data;
449 if (se_proxy == NULL)
451 if (net_nfc_client_se_init() != NET_NFC_OK)
453 DEBUG_ERR_MSG("se_proxy fail");
454 /* FIXME : return result of this error */
455 return NET_NFC_NOT_INITIALIZED;
459 /* prevent executing daemon when nfc is off */
460 if (net_nfc_client_manager_is_activated() == false) {
461 return NET_NFC_NOT_ACTIVATED;
464 func_data = g_try_new0(SeFuncData, 1);
465 if (func_data == NULL)
466 return NET_NFC_ALLOC_FAIL;
468 func_data->se_callback = (gpointer)callback;
469 func_data->se_data = user_data;
471 net_nfc_gdbus_secure_element_call_set(
483 net_nfc_error_e net_nfc_client_se_set_secure_element_type_sync(
484 net_nfc_se_type_e se_type)
486 net_nfc_error_e result = NET_NFC_OK;
487 GError *error = NULL;
489 if (se_proxy == NULL)
491 if (net_nfc_client_se_init() != NET_NFC_OK)
493 DEBUG_ERR_MSG("se_proxy fail");
494 return NET_NFC_NOT_INITIALIZED;
498 /* prevent executing daemon when nfc is off */
499 if (net_nfc_client_manager_is_activated() == false) {
500 return NET_NFC_NOT_ACTIVATED;
503 if (net_nfc_gdbus_secure_element_call_set_sync(
510 DEBUG_ERR_MSG("Set secure element failed: %s", error->message);
511 result = NET_NFC_IPC_FAIL;
520 net_nfc_error_e net_nfc_client_se_get_secure_element_type_sync(
521 net_nfc_se_type_e *se_type)
523 net_nfc_error_e result = NET_NFC_OK;
526 GError *error = NULL;
528 if (se_proxy == NULL)
530 if (net_nfc_client_se_init() != NET_NFC_OK)
532 DEBUG_ERR_MSG("se_proxy fail");
533 return NET_NFC_NOT_INITIALIZED;
537 /* prevent executing daemon when nfc is off */
538 if (net_nfc_client_manager_is_activated() == false) {
539 return NET_NFC_NOT_ACTIVATED;
542 if (vconf_get_int(VCONFKEY_NFC_SE_TYPE, &type) == 0) {
545 result = NET_NFC_OPERATION_FAIL;
548 if (net_nfc_gdbus_secure_element_call_get_sync(
555 SECURE_MSG("type [%d]", type);
558 DEBUG_ERR_MSG("get secure element failed: %s", error->message);
562 result = NET_NFC_IPC_FAIL;
569 net_nfc_error_e net_nfc_set_card_emulation_mode_sync(
570 net_nfc_card_emulation_mode_t mode)
572 net_nfc_error_e result = NET_NFC_OK;
573 GError *error = NULL;
575 if (se_proxy == NULL)
577 if (net_nfc_client_se_init() != NET_NFC_OK)
579 DEBUG_ERR_MSG("se_proxy fail");
580 return NET_NFC_NOT_INITIALIZED;
584 /* prevent executing daemon when nfc is off */
585 if (net_nfc_client_manager_is_activated() == false) {
586 return NET_NFC_NOT_ACTIVATED;
589 if (net_nfc_gdbus_secure_element_call_set_card_emulation_sync(
596 DEBUG_ERR_MSG("Set card emulation failed: %s", error->message);
597 result = NET_NFC_IPC_FAIL;
606 net_nfc_error_e net_nfc_get_card_emulation_mode_sync(
607 net_nfc_card_emulation_mode_t *se_type)
609 net_nfc_error_e result = NET_NFC_OK;
611 GError *error = NULL;
613 if (se_proxy == NULL)
615 if (net_nfc_client_se_init() != NET_NFC_OK)
617 DEBUG_ERR_MSG("se_proxy fail");
618 return NET_NFC_NOT_INITIALIZED;
622 /* prevent executing daemon when nfc is off */
623 if (net_nfc_client_manager_is_activated() == false) {
624 return NET_NFC_NOT_ACTIVATED;
627 if (net_nfc_gdbus_secure_element_call_get_card_emulation_sync(
635 DEBUG_ERR_MSG("get secure element failed: %s", error->message);
639 result = NET_NFC_IPC_FAIL;
646 net_nfc_error_e net_nfc_client_se_open_internal_secure_element(
647 net_nfc_se_type_e se_type,
648 net_nfc_se_open_se_cb callback,
651 SeFuncData *func_data;
653 if (auto_start_proxy == NULL)
655 GError *error = NULL;
657 auto_start_proxy = net_nfc_gdbus_secure_element_proxy_new_for_bus_sync(
659 G_DBUS_PROXY_FLAGS_NONE,
660 "org.tizen.NetNfcService",
661 "/org/tizen/NetNfcService/SecureElement",
664 if (auto_start_proxy == NULL)
666 DEBUG_ERR_MSG("Can not create proxy : %s", error->message);
669 return NET_NFC_UNKNOWN_ERROR;
673 /* allow this function even nfc is off */
675 func_data = g_try_new0(SeFuncData, 1);
676 if (func_data == NULL)
677 return NET_NFC_ALLOC_FAIL;
679 func_data->se_callback = (gpointer)callback;
680 func_data->se_data = user_data;
682 net_nfc_gdbus_secure_element_call_open_secure_element(
694 net_nfc_error_e net_nfc_client_se_open_internal_secure_element_sync(
695 net_nfc_se_type_e se_type,
696 net_nfc_target_handle_h *handle)
698 net_nfc_error_e result = NET_NFC_OK;
699 guint out_handle = 0;
700 GError *error = NULL;
702 if (handle == NULL) {
703 return NET_NFC_NULL_PARAMETER;
706 if (auto_start_proxy == NULL)
708 GError *error = NULL;
710 auto_start_proxy = net_nfc_gdbus_secure_element_proxy_new_for_bus_sync(
712 G_DBUS_PROXY_FLAGS_NONE,
713 "org.tizen.NetNfcService",
714 "/org/tizen/NetNfcService/SecureElement",
717 if (auto_start_proxy == NULL)
719 DEBUG_ERR_MSG("Can not create proxy : %s", error->message);
722 return NET_NFC_UNKNOWN_ERROR;
726 /* allow this function even nfc is off */
728 if (net_nfc_gdbus_secure_element_call_open_secure_element_sync(
735 *handle = GUINT_TO_POINTER(out_handle);
737 DEBUG_ERR_MSG("Open internal secure element failed: %s",
739 result = NET_NFC_IPC_FAIL;
749 net_nfc_error_e net_nfc_client_se_close_internal_secure_element(
750 net_nfc_target_handle_h handle,
751 net_nfc_se_close_se_cb callback,
754 SeFuncData *func_data;
756 if (auto_start_proxy == NULL)
758 GError *error = NULL;
760 auto_start_proxy = net_nfc_gdbus_secure_element_proxy_new_for_bus_sync(
762 G_DBUS_PROXY_FLAGS_NONE,
763 "org.tizen.NetNfcService",
764 "/org/tizen/NetNfcService/SecureElement",
767 if (auto_start_proxy == NULL)
769 DEBUG_ERR_MSG("Can not create proxy : %s", error->message);
772 return NET_NFC_UNKNOWN_ERROR;
776 /* allow this function even nfc is off */
778 func_data = g_try_new0(SeFuncData, 1);
779 if (func_data == NULL)
780 return NET_NFC_ALLOC_FAIL;
782 func_data->se_callback = (gpointer)callback;
783 func_data->se_data = user_data;
785 net_nfc_gdbus_secure_element_call_close_secure_element(
787 GPOINTER_TO_UINT(handle),
789 close_secure_element,
797 net_nfc_error_e net_nfc_client_se_close_internal_secure_element_sync(
798 net_nfc_target_handle_h handle)
800 net_nfc_error_e result = NET_NFC_OK;
801 GError *error = NULL;
803 if (auto_start_proxy == NULL)
805 GError *error = NULL;
807 auto_start_proxy = net_nfc_gdbus_secure_element_proxy_new_for_bus_sync(
809 G_DBUS_PROXY_FLAGS_NONE,
810 "org.tizen.NetNfcService",
811 "/org/tizen/NetNfcService/SecureElement",
814 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 if (net_nfc_gdbus_secure_element_call_close_secure_element_sync(
827 GPOINTER_TO_UINT(handle),
832 DEBUG_ERR_MSG("close internal secure element failed: %s",
834 result = NET_NFC_IPC_FAIL;
844 net_nfc_error_e net_nfc_client_se_get_atr(
845 net_nfc_target_handle_h handle,
846 net_nfc_se_get_atr_cb callback,
849 SeFuncData *func_data;
851 if (auto_start_proxy == NULL)
853 GError *error = NULL;
855 auto_start_proxy = net_nfc_gdbus_secure_element_proxy_new_for_bus_sync(
857 G_DBUS_PROXY_FLAGS_NONE,
858 "org.tizen.NetNfcService",
859 "/org/tizen/NetNfcService/SecureElement",
862 if (auto_start_proxy == NULL)
864 DEBUG_ERR_MSG("Can not create proxy : %s", error->message);
867 return NET_NFC_UNKNOWN_ERROR;
871 /* allow this function even nfc is off */
873 func_data = g_try_new0(SeFuncData, 1);
874 if (func_data == NULL)
875 return NET_NFC_ALLOC_FAIL;
877 func_data->se_callback = (gpointer)callback;
878 func_data->se_data = user_data;
880 net_nfc_gdbus_secure_element_call_get_atr(
882 GPOINTER_TO_UINT(handle),
884 get_atr_secure_element,
892 net_nfc_error_e net_nfc_client_se_get_atr_sync(
893 net_nfc_target_handle_h handle,
896 net_nfc_error_e result = NET_NFC_OK;
897 GVariant *out_atr = NULL;
898 GError *error = NULL;
901 return NET_NFC_NULL_PARAMETER;
906 if (auto_start_proxy == NULL)
908 GError *error = NULL;
910 auto_start_proxy = net_nfc_gdbus_secure_element_proxy_new_for_bus_sync(
912 G_DBUS_PROXY_FLAGS_NONE,
913 "org.tizen.NetNfcService",
914 "/org/tizen/NetNfcService/SecureElement",
917 if (auto_start_proxy == NULL)
919 DEBUG_ERR_MSG("Can not create proxy : %s", error->message);
922 return NET_NFC_UNKNOWN_ERROR;
926 /* allow this function even nfc is off */
928 if (net_nfc_gdbus_secure_element_call_get_atr_sync(
930 GPOINTER_TO_UINT(handle),
935 *atr = net_nfc_util_gdbus_variant_to_data(out_atr);
937 DEBUG_ERR_MSG("Get attributes failed: %s", error->message);
938 result = NET_NFC_IPC_FAIL;
948 net_nfc_error_e net_nfc_client_se_send_apdu(
949 net_nfc_target_handle_h handle,
951 net_nfc_se_send_apdu_cb callback,
954 SeFuncData *func_data;
957 if (auto_start_proxy == NULL)
959 GError *error = NULL;
961 auto_start_proxy = net_nfc_gdbus_secure_element_proxy_new_for_bus_sync(
963 G_DBUS_PROXY_FLAGS_NONE,
964 "org.tizen.NetNfcService",
965 "/org/tizen/NetNfcService/SecureElement",
968 if (auto_start_proxy == NULL)
970 DEBUG_ERR_MSG("Can not create proxy : %s", error->message);
973 return NET_NFC_UNKNOWN_ERROR;
977 /* allow this function even nfc is off */
979 arg_data = net_nfc_util_gdbus_data_to_variant((data_s *)apdu_data);
980 if (arg_data == NULL)
981 return NET_NFC_INVALID_PARAM;
983 func_data = g_try_new0(SeFuncData, 1);
984 if (func_data == NULL) {
985 g_variant_unref(arg_data);
987 return NET_NFC_ALLOC_FAIL;
990 func_data->se_callback = (gpointer)callback;
991 func_data->se_data = user_data;
993 net_nfc_gdbus_secure_element_call_send_apdu(
995 GPOINTER_TO_UINT(handle),
998 send_apdu_secure_element,
1006 net_nfc_error_e net_nfc_client_se_send_apdu_sync(
1007 net_nfc_target_handle_h handle,
1011 net_nfc_error_e result = NET_NFC_OK;
1012 GVariant *out_data = NULL;
1013 GError *error = NULL;
1016 if (response == NULL) {
1017 return NET_NFC_NULL_PARAMETER;
1022 if (auto_start_proxy == NULL)
1024 GError *error = NULL;
1026 auto_start_proxy = net_nfc_gdbus_secure_element_proxy_new_for_bus_sync(
1028 G_DBUS_PROXY_FLAGS_NONE,
1029 "org.tizen.NetNfcService",
1030 "/org/tizen/NetNfcService/SecureElement",
1033 if (auto_start_proxy == NULL)
1035 DEBUG_ERR_MSG("Can not create proxy : %s", error->message);
1036 g_error_free(error);
1038 return NET_NFC_UNKNOWN_ERROR;
1042 /* allow this function even nfc is off */
1044 arg_data = net_nfc_util_gdbus_data_to_variant((data_s *)apdu_data);
1045 if (arg_data == NULL)
1046 return NET_NFC_INVALID_PARAM;
1048 if (net_nfc_gdbus_secure_element_call_send_apdu_sync(
1050 GPOINTER_TO_UINT(handle),
1056 *response = net_nfc_util_gdbus_variant_to_data(out_data);
1058 DEBUG_ERR_MSG("Send APDU failed: %s", error->message);
1059 result = NET_NFC_IPC_FAIL;
1061 g_error_free(error);
1069 void net_nfc_client_se_set_ese_detection_cb(
1070 net_nfc_client_se_ese_detected_event callback,
1073 if (se_proxy == NULL)
1075 if (net_nfc_client_se_init() != NET_NFC_OK)
1077 DEBUG_ERR_MSG("se_proxy fail");
1078 /* FIXME : return result of this error */
1083 se_esedetecthandler.se_ese_detected_cb = callback;
1084 se_esedetecthandler.se_ese_detected_data = user_data;
1089 void net_nfc_client_se_unset_ese_detection_cb(void)
1091 se_esedetecthandler.se_ese_detected_cb = NULL;
1092 se_esedetecthandler.se_ese_detected_data = NULL;
1097 void net_nfc_client_se_set_transaction_event_cb(
1098 net_nfc_se_type_e se_type,
1099 net_nfc_client_se_transaction_event callback,
1102 if (se_proxy == NULL)
1104 if (net_nfc_client_se_init() != NET_NFC_OK)
1106 DEBUG_ERR_MSG("se_proxy fail");
1107 /* FIXME : return result of this error */
1112 if (se_type == NET_NFC_SE_TYPE_ESE)
1114 ese_transactionEventHandler.transaction_event_cb = callback;
1115 ese_transactionEventHandler.transaction_event_data = user_data;
1117 else if (se_type == NET_NFC_SE_TYPE_UICC)
1119 uicc_transactionEventHandler.transaction_event_cb = callback;
1120 uicc_transactionEventHandler.transaction_event_data = user_data;
1126 void net_nfc_client_se_unset_transaction_event_cb(net_nfc_se_type_e type)
1128 if (type == NET_NFC_SE_TYPE_ESE)
1130 ese_transactionEventHandler.transaction_event_cb = NULL;
1131 ese_transactionEventHandler.transaction_event_data = NULL;
1133 else if (type == NET_NFC_SE_TYPE_UICC)
1135 uicc_transactionEventHandler.transaction_event_cb = NULL;
1136 uicc_transactionEventHandler.transaction_event_data = NULL;
1141 void net_nfc_client_se_set_event_cb(net_nfc_client_se_event callback,
1144 if (se_proxy == NULL)
1146 if (net_nfc_client_se_init() != NET_NFC_OK)
1148 DEBUG_ERR_MSG("se_proxy fail");
1149 /* FIXME : return result of this error */
1154 se_eventhandler.se_event_cb = callback;
1155 se_eventhandler.se_event_data = user_data;
1160 void net_nfc_client_se_unset_event_cb(void)
1162 se_eventhandler.se_event_cb = NULL;
1163 se_eventhandler.se_event_data = NULL;
1167 net_nfc_error_e net_nfc_client_se_set_transaction_fg_dispatch(int mode)
1169 net_nfc_error_e result = NET_NFC_OK;
1170 GError *error = NULL;
1172 if (auto_start_proxy == NULL)
1174 GError *error = NULL;
1176 auto_start_proxy = net_nfc_gdbus_secure_element_proxy_new_for_bus_sync(
1178 G_DBUS_PROXY_FLAGS_NONE,
1179 "org.tizen.NetNfcService",
1180 "/org/tizen/NetNfcService/SecureElement",
1183 if (auto_start_proxy == NULL)
1185 DEBUG_ERR_MSG("Can not create proxy : %s", error->message);
1186 g_error_free(error);
1188 return NET_NFC_UNKNOWN_ERROR;
1192 if (net_nfc_gdbus_secure_element_call_set_transaction_fg_dispatch_sync(
1199 DEBUG_ERR_MSG("set transaction fg dispatch failed: %s", error->message);
1200 result = NET_NFC_IPC_FAIL;
1202 g_error_free(error);
1209 net_nfc_error_e net_nfc_client_se_set_default_route_sync(
1210 net_nfc_se_type_e switch_on,
1211 net_nfc_se_type_e switch_off,
1212 net_nfc_se_type_e battery_off)
1214 net_nfc_error_e result = NET_NFC_OK;
1215 GError *error = NULL;
1217 if (se_proxy == NULL)
1219 result = net_nfc_client_se_init();
1220 if (result != NET_NFC_OK)
1222 DEBUG_ERR_MSG("net_nfc_client_se_init failed, [%d]", result);
1224 return NET_NFC_NOT_INITIALIZED;
1228 if (net_nfc_gdbus_secure_element_call_set_default_route_sync(
1237 DEBUG_ERR_MSG("Set Route Aid failed: %s", error->message);
1238 result = NET_NFC_IPC_FAIL;
1240 g_error_free(error);
1243 DEBUG_CLIENT_MSG("net_nfc_gdbus_secure_element_call_set_default_route_sync end");
1249 net_nfc_error_e net_nfc_client_se_is_activated_aid_handler_sync(
1250 net_nfc_se_type_e se_type, const char *aid, bool *activated)
1252 net_nfc_error_e result = NET_NFC_OK;
1253 GError *error = NULL;
1254 gboolean ret = false;
1256 if (activated == NULL) {
1257 return NET_NFC_NULL_PARAMETER;
1260 if (se_proxy == NULL) {
1261 result = net_nfc_client_se_init();
1262 if (result != NET_NFC_OK) {
1263 DEBUG_ERR_MSG("net_nfc_client_se_init failed, [%d]", result);
1265 return NET_NFC_NOT_INITIALIZED;
1269 if (net_nfc_gdbus_secure_element_call_is_activated_aid_handler_sync(
1279 DEBUG_ERR_MSG("net_nfc_gdbus_secure_element_call_is_activated_aid_handler_sync failed : %s", error->message);
1280 result = NET_NFC_IPC_FAIL;
1282 g_error_free(error);
1289 net_nfc_error_e net_nfc_client_se_is_activated_category_handler_sync(
1290 net_nfc_se_type_e se_type,
1291 net_nfc_card_emulation_category_t category, bool *activated)
1293 net_nfc_error_e result = NET_NFC_OK;
1294 GError *error = NULL;
1295 gboolean ret = false;
1297 if (activated == NULL) {
1298 return NET_NFC_NULL_PARAMETER;
1301 if (se_proxy == NULL) {
1302 result = net_nfc_client_se_init();
1303 if (result != NET_NFC_OK) {
1304 DEBUG_ERR_MSG("net_nfc_client_se_init failed, [%d]", result);
1306 return NET_NFC_NOT_INITIALIZED;
1310 if (net_nfc_gdbus_secure_element_call_is_activated_category_handler_sync(
1320 DEBUG_ERR_MSG("net_nfc_gdbus_secure_element_call_is_activated_category_handler_sync failed : %s", error->message);
1321 result = NET_NFC_IPC_FAIL;
1323 g_error_free(error);
1330 net_nfc_error_e net_nfc_client_se_get_registered_aids_count_sync(
1331 net_nfc_se_type_e se_type,
1332 net_nfc_card_emulation_category_t category,
1335 net_nfc_error_e result = NET_NFC_OK;
1336 GError *error = NULL;
1337 GVariant *aids = NULL;
1339 if (count == NULL) {
1340 return NET_NFC_NULL_PARAMETER;
1343 if (se_proxy == NULL) {
1344 result = net_nfc_client_se_init();
1345 if (result != NET_NFC_OK) {
1346 DEBUG_ERR_MSG("net_nfc_client_se_init failed, [%d]", result);
1348 return NET_NFC_NOT_INITIALIZED;
1352 if (net_nfc_gdbus_secure_element_call_get_registered_aids_sync(
1361 DEBUG_ERR_MSG("net_nfc_gdbus_secure_element_call_get_registered_aids_sync failed : %s", error->message);
1362 result = NET_NFC_IPC_FAIL;
1364 g_error_free(error);
1367 if (result == NET_NFC_OK) {
1370 g_variant_iter_init(&iter, aids);
1372 *count = g_variant_iter_n_children(&iter);
1374 g_variant_unref(aids);
1381 net_nfc_error_e net_nfc_client_se_foreach_registered_aids_sync(
1382 net_nfc_se_type_e se_type,
1383 net_nfc_card_emulation_category_t category,
1384 net_nfc_client_se_registered_aid_cb callback,
1387 net_nfc_error_e result = NET_NFC_OK;
1388 GError *error = NULL;
1389 GVariant *aids = NULL;
1391 if (callback == NULL) {
1392 return NET_NFC_NULL_PARAMETER;
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_get_registered_aids_sync(
1413 DEBUG_ERR_MSG("net_nfc_gdbus_secure_element_call_get_registered_aids_sync failed : %s", error->message);
1414 result = NET_NFC_IPC_FAIL;
1416 g_error_free(error);
1419 if (result == NET_NFC_OK) {
1424 g_variant_iter_init(&iter, aids);
1426 while (g_variant_iter_loop(&iter, "(sb)", &aid, &manifest) == true) {
1427 callback(se_type, aid, (bool)manifest, user_data);
1436 net_nfc_error_e net_nfc_client_se_register_aids_sync(net_nfc_se_type_e se_type,
1437 net_nfc_card_emulation_category_t category, const char *aid, ...)
1439 net_nfc_error_e result = NET_NFC_OK;
1440 GError *error = NULL;
1442 if (se_proxy == NULL) {
1443 result = net_nfc_client_se_init();
1444 if (result != NET_NFC_OK) {
1445 DEBUG_ERR_MSG("net_nfc_client_se_init failed, [%d]", result);
1447 return NET_NFC_NOT_INITIALIZED;
1451 if (net_nfc_gdbus_secure_element_call_register_aid_sync(
1460 DEBUG_ERR_MSG("net_nfc_gdbus_secure_element_call_register_aid_sync failed : %s", error->message);
1461 result = NET_NFC_IPC_FAIL;
1463 g_error_free(error);
1470 net_nfc_error_e net_nfc_client_se_unregister_aid_sync(net_nfc_se_type_e se_type,
1471 net_nfc_card_emulation_category_t category, const char *aid)
1473 net_nfc_error_e result = NET_NFC_OK;
1474 GError *error = NULL;
1476 if (se_proxy == NULL) {
1477 result = net_nfc_client_se_init();
1478 if (result != NET_NFC_OK) {
1479 DEBUG_ERR_MSG("net_nfc_client_se_init failed, [%d]", result);
1481 return NET_NFC_NOT_INITIALIZED;
1485 if (net_nfc_gdbus_secure_element_call_unregister_aid_sync(
1494 DEBUG_ERR_MSG("net_nfc_gdbus_secure_element_call_unregister_aid_sync failed : %s", error->message);
1495 result = NET_NFC_IPC_FAIL;
1497 g_error_free(error);
1504 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)
1506 net_nfc_error_e result = NET_NFC_OK;
1507 GError *error = NULL;
1509 if (se_proxy == NULL) {
1510 result = net_nfc_client_se_init();
1511 if (result != NET_NFC_OK) {
1512 DEBUG_ERR_MSG("net_nfc_client_se_init failed, [%d]", result);
1514 return NET_NFC_NOT_INITIALIZED;
1518 if (net_nfc_gdbus_secure_element_call_unregister_aids_sync(
1526 DEBUG_ERR_MSG("net_nfc_gdbus_secure_element_call_unregister_aids_sync failed : %s", error->message);
1527 result = NET_NFC_IPC_FAIL;
1529 g_error_free(error);
1536 net_nfc_error_e net_nfc_client_se_foreach_registered_handlers_sync(
1537 net_nfc_card_emulation_category_t category,
1538 net_nfc_client_se_registered_handler_cb callback,
1541 net_nfc_error_e result = NET_NFC_OK;
1542 GError *error = NULL;
1543 GVariant *handlers = NULL;
1545 if (callback == NULL) {
1546 return NET_NFC_NULL_PARAMETER;
1549 if (se_proxy == NULL) {
1550 result = net_nfc_client_se_init();
1551 if (result != NET_NFC_OK) {
1552 DEBUG_ERR_MSG("net_nfc_client_se_init failed, [%d]", result);
1554 return NET_NFC_NOT_INITIALIZED;
1558 if (net_nfc_gdbus_secure_element_call_get_registered_handlers_sync(
1566 DEBUG_ERR_MSG("net_nfc_gdbus_secure_element_call_get_registered_handlers_sync failed : %s", error->message);
1567 result = NET_NFC_IPC_FAIL;
1569 g_error_free(error);
1572 if (result == NET_NFC_OK) {
1574 const gchar *handler;
1577 g_variant_iter_init(&iter, handlers);
1579 while (g_variant_iter_loop(&iter, "(is)", &count, &handler) == true) {
1580 callback(handler, count, user_data);
1588 net_nfc_error_e net_nfc_client_se_add_route_aid_sync(
1589 const char *package, net_nfc_se_type_e se_type,
1590 net_nfc_card_emulation_category_t category, const char *aid,
1591 bool unlock_required, int power)
1593 net_nfc_error_e result = NET_NFC_OK;
1594 GError *error = NULL;
1596 if (auto_start_proxy == NULL)
1598 GError *error = NULL;
1600 auto_start_proxy = net_nfc_gdbus_secure_element_proxy_new_for_bus_sync(
1602 G_DBUS_PROXY_FLAGS_NONE,
1603 "org.tizen.NetNfcService",
1604 "/org/tizen/NetNfcService/SecureElement",
1607 if (auto_start_proxy == NULL)
1609 DEBUG_ERR_MSG("Can not create proxy : %s", error->message);
1610 g_error_free(error);
1612 return NET_NFC_UNKNOWN_ERROR;
1616 if (net_nfc_gdbus_secure_element_call_add_route_aid_sync(
1628 DEBUG_ERR_MSG("Set Route Aid failed: %s", error->message);
1629 result = NET_NFC_IPC_FAIL;
1631 g_error_free(error);
1634 DEBUG_CLIENT_MSG("net_nfc_gdbus_secure_element_call_add_route_aid_sync end");
1640 net_nfc_error_e net_nfc_client_se_remove_route_aid_sync(
1641 const char *package, const char *aid)
1643 net_nfc_error_e result = NET_NFC_OK;
1644 GError *error = NULL;
1646 if (auto_start_proxy == NULL)
1648 GError *error = NULL;
1650 auto_start_proxy = net_nfc_gdbus_secure_element_proxy_new_for_bus_sync(
1652 G_DBUS_PROXY_FLAGS_NONE,
1653 "org.tizen.NetNfcService",
1654 "/org/tizen/NetNfcService/SecureElement",
1657 if (auto_start_proxy == NULL)
1659 DEBUG_ERR_MSG("Can not create proxy : %s", error->message);
1660 g_error_free(error);
1662 return NET_NFC_UNKNOWN_ERROR;
1666 if (net_nfc_gdbus_secure_element_call_remove_route_aid_sync(
1674 DEBUG_ERR_MSG("Remove Route Aid failed: %s", error->message);
1675 result = NET_NFC_IPC_FAIL;
1677 g_error_free(error);
1680 DEBUG_CLIENT_MSG("net_nfc_gdbus_hce_call_set_route_aid_sync end");
1686 net_nfc_error_e net_nfc_client_se_remove_package_aids_sync(
1687 const char *package)
1689 net_nfc_error_e result = NET_NFC_OK;
1690 GError *error = NULL;
1692 if (auto_start_proxy == NULL)
1694 GError *error = NULL;
1696 auto_start_proxy = net_nfc_gdbus_secure_element_proxy_new_for_bus_sync(
1698 G_DBUS_PROXY_FLAGS_NONE,
1699 "org.tizen.NetNfcService",
1700 "/org/tizen/NetNfcService/SecureElement",
1703 if (auto_start_proxy == NULL)
1705 DEBUG_ERR_MSG("Can not create proxy : %s", error->message);
1706 g_error_free(error);
1708 return NET_NFC_UNKNOWN_ERROR;
1712 if (net_nfc_gdbus_secure_element_call_remove_package_aids_sync(
1719 DEBUG_ERR_MSG("Remove Package Aid failed: %s", error->message);
1720 result = NET_NFC_IPC_FAIL;
1722 g_error_free(error);
1725 DEBUG_CLIENT_MSG("net_nfc_client_se_remove_package_aids_sync end");
1731 net_nfc_error_e net_nfc_client_se_set_preferred_handler_sync(bool state)
1733 net_nfc_error_e result = NET_NFC_OK;
1734 GError *error = NULL;
1736 if (se_proxy == NULL) {
1737 result = net_nfc_client_se_init();
1738 if (result != NET_NFC_OK) {
1739 DEBUG_ERR_MSG("net_nfc_client_se_init failed, [%d]", result);
1741 return NET_NFC_NOT_INITIALIZED;
1745 if (net_nfc_gdbus_secure_element_call_set_preferred_handler_sync(
1749 NULL, &error) == FALSE) {
1750 DEBUG_ERR_MSG("net_nfc_gdbus_secure_element_call_set_preferred_handler_sync failed : %s", error->message);
1751 result = NET_NFC_IPC_FAIL;
1753 g_error_free(error);
1760 net_nfc_error_e net_nfc_client_se_get_handler_storage_info_sync(
1761 net_nfc_card_emulation_category_t category, int *used, int *max)
1763 net_nfc_error_e result = NET_NFC_OK;
1764 GError *error = NULL;
1766 if (se_proxy == NULL) {
1767 result = net_nfc_client_se_init();
1768 if (result != NET_NFC_OK) {
1769 DEBUG_ERR_MSG("net_nfc_client_se_init failed, [%d]", result);
1771 return NET_NFC_NOT_INITIALIZED;
1775 if (net_nfc_gdbus_secure_element_call_get_handler_storage_info_sync(
1781 NULL, &error) == FALSE) {
1782 DEBUG_ERR_MSG("net_nfc_gdbus_secure_element_call_get_handler_storage_info_sync failed : %s", error->message);
1783 result = NET_NFC_IPC_FAIL;
1785 g_error_free(error);
1792 net_nfc_error_e net_nfc_client_se_get_conflict_handlers_sync(
1793 const char *package, net_nfc_card_emulation_category_t category,
1794 const char *aid, char ***handlers)
1796 net_nfc_error_e result = NET_NFC_OK;
1797 GError *error = NULL;
1798 GVariant *packages = NULL;
1800 if (se_proxy == NULL) {
1801 result = net_nfc_client_se_init();
1802 if (result != NET_NFC_OK) {
1803 DEBUG_ERR_MSG("net_nfc_client_se_init failed, [%d]", result);
1805 return NET_NFC_NOT_INITIALIZED;
1809 if (net_nfc_gdbus_secure_element_call_get_conflict_handlers_sync(
1816 NULL, &error) == true) {
1817 if (result == NET_NFC_DATA_CONFLICTED) {
1822 g_variant_iter_init(&iter, packages);
1823 len = g_variant_iter_n_children(&iter);
1825 SECURE_MSG("conflict count [%d]", len);
1831 pkgs = g_new0(gchar *, len + 1);
1833 for (i = 0; i < len; i++) {
1834 if (g_variant_iter_next(&iter, "(s)", &temp) == true) {
1835 SECURE_MSG("conflict package [%s]", temp);
1836 pkgs[i] = g_strdup(temp);
1838 DEBUG_ERR_MSG("g_variant_iter_next failed");
1846 DEBUG_ERR_MSG("net_nfc_gdbus_secure_element_call_get_conflict_handlers_sync failed : %s", error->message);
1847 result = NET_NFC_IPC_FAIL;
1849 g_error_free(error);
1855 net_nfc_error_e net_nfc_client_se_init(void)
1857 GError *error = NULL;
1861 DEBUG_CLIENT_MSG("Already initialized");
1866 se_proxy = net_nfc_gdbus_secure_element_proxy_new_for_bus_sync(
1868 G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START,
1869 "org.tizen.NetNfcService",
1870 "/org/tizen/NetNfcService/SecureElement",
1873 if (se_proxy == NULL)
1875 DEBUG_ERR_MSG("Can not create proxy : %s", error->message);
1877 g_error_free(error);
1879 return NET_NFC_UNKNOWN_ERROR;
1882 g_signal_connect(se_proxy, "se-type-changed",
1883 G_CALLBACK(se_type_changed), NULL);
1885 g_signal_connect(se_proxy, "ese-detected",
1886 G_CALLBACK(se_ese_detected), NULL);
1888 g_signal_connect(se_proxy, "transaction-event",
1889 G_CALLBACK(se_transaction_event), NULL);
1891 g_signal_connect(se_proxy, "card-emulation-mode-changed",
1892 G_CALLBACK(se_card_emulation_mode_changed), NULL);
1894 g_signal_connect(se_proxy, "rf-detected",
1895 G_CALLBACK(se_rf_detected), NULL);
1901 void net_nfc_client_se_deinit(void)
1905 g_object_unref(se_proxy);
1909 if (auto_start_proxy)
1911 g_object_unref(auto_start_proxy);
1912 auto_start_proxy = NULL;