Fix doxygen
[platform/core/api/nfc.git] / src / nfc_manager.c
1 /*
2 * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
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 #include "nfc_common.h"
18
19 bool nfc_manager_is_supported(void)
20 {
21         bool nfc_supported = false;
22
23         LOG_BEGIN();
24
25         nfc_supported = nfc_common_is_supported(NFC_FEATURE);
26
27         if (nfc_supported == true)
28                 set_last_result(NFC_ERROR_NONE);
29         else
30                 set_last_result(NFC_ERROR_NOT_SUPPORTED); // LCOV_EXCL_LINE
31
32         return nfc_supported;
33 }
34
35 /* LCOV_EXCL_START */
36 static void _activation_changed_cb(net_nfc_error_e result, void *user_data)
37 {
38         nfc_activation_data_s *data = user_data;
39
40         LOG_BEGIN();
41
42         if (user_data == NULL) {
43                 LOG_ERR("user_data is NULL");
44                 return;
45         }
46
47         if (data->callback != NULL)
48                 data->callback(nfc_common_convert_error_code(__func__, result), data->user_data);
49
50         free(data);
51 }
52 /* LCOV_EXCL_STOP */
53
54 int nfc_manager_set_activation(bool activation,
55         nfc_activation_completed_cb callback,
56         void *user_data)
57 {
58         int ret;
59
60         LOG_BEGIN();
61
62         CHECK_SUPPORTED(NFC_FEATURE);
63
64         /* LCOV_EXCL_START */
65         CHECK_INIT();
66
67         if (nfc_manager_is_activated() == activation) {
68                 if (activation)
69                         ret = NFC_ERROR_ALREADY_ACTIVATED;
70                 else
71                         ret = NFC_ERROR_ALREADY_DEACTIVATED;
72         } else {
73                 nfc_activation_data_s *data = NULL;
74
75                 data = (nfc_activation_data_s *)malloc(sizeof(nfc_activation_data_s));
76
77                 if (data != NULL) {
78                         data->callback = callback;
79                         data->user_data = user_data;
80                         ret = net_nfc_client_manager_set_active(activation,
81                                 _activation_changed_cb,
82                                 data);
83                         if (ret != NET_NFC_OK) {
84                                 LOG_ERR("net_nfc_client_manager_set_active fail");
85
86                                 free(data);
87                         }
88                 } else {
89                         ret = NET_NFC_ALLOC_FAIL;
90                 }
91
92                 ret = nfc_common_convert_error_code(__func__, ret);
93         }
94
95         return ret;
96         /* LCOV_EXCL_STOP */
97 }
98
99 int nfc_manager_configure_discovery(int mode)
100 {
101         int ret;
102
103         LOG_BEGIN();
104
105         CHECK_SUPPORTED(NFC_FEATURE);
106
107         /* LCOV_EXCL_START */
108         CHECK_INIT();
109         CHECK_ACTIVATED();
110
111         ret = net_nfc_client_manager_configure_discovery_sync(mode);
112
113         return nfc_common_convert_error_code(__func__, ret);
114         /* LCOV_EXCL_STOP */
115 }
116
117 int nfc_manager_test_mode_on(void)
118 {
119         int ret;
120
121         LOG_BEGIN();
122
123         CHECK_SUPPORTED(NFC_FEATURE);
124
125         /* LCOV_EXCL_START */
126         CHECK_INIT();
127         CHECK_ACTIVATED();
128
129         ret = net_nfc_client_test_test_mode_on_sync();
130
131         return nfc_common_convert_error_code(__func__, ret);
132         /* LCOV_EXCL_STOP */
133 }
134
135 int nfc_manager_test_mode_off(void)
136 {
137         int ret;
138
139         LOG_BEGIN();
140
141         CHECK_SUPPORTED(NFC_FEATURE);
142
143         /* LCOV_EXCL_START */
144         CHECK_INIT();
145         CHECK_ACTIVATED();
146
147         ret = net_nfc_client_test_test_mode_off_sync();
148
149         return nfc_common_convert_error_code(__func__, ret);
150         /* LCOV_EXCL_STOP */
151 }
152
153 bool nfc_manager_is_activated(void)
154 {
155         int ret;
156         int activated = 0;
157
158         LOG_BEGIN();
159
160         if (nfc_common_is_supported(NFC_FEATURE) == false) {
161                 set_last_result(NFC_ERROR_NOT_SUPPORTED);
162                 return false;
163         }
164
165         /* LCOV_EXCL_START */
166         ret = net_nfc_client_get_nfc_state(&activated);
167
168         set_last_result(nfc_common_convert_error_code(__func__, ret));
169
170         return (!!activated);
171         /* LCOV_EXCL_STOP */
172 }
173
174 int nfc_manager_set_activation_changed_cb(nfc_activation_changed_cb callback,
175         void *user_data)
176 {
177         LOG_BEGIN();
178
179         CHECK_SUPPORTED(NFC_FEATURE);
180
181         /* LCOV_EXCL_START */
182         CHECK_INIT();
183         CHECK_INVALID(callback == NULL);
184
185         net_nfc_client_manager_set_activated(callback, user_data);
186
187         return NFC_ERROR_NONE;
188         /* LCOV_EXCL_STOP */
189 }
190
191 void nfc_manager_unset_activation_changed_cb(void)
192 {
193         LOG_BEGIN();
194
195         if (nfc_common_is_supported(NFC_FEATURE) == false) {
196                 /* LCOV_EXCL_START */
197                 LOG_ERR("NFC not supported");
198                 set_last_result(NFC_ERROR_NOT_SUPPORTED);
199                 return;
200                 /* LCOV_EXCL_END */
201         }
202
203         /* LCOV_EXCL_START */
204         if (nfc_common_is_initialized() == false) {
205                 LOG_ERR("NFC not initialized");
206                 set_last_result(NFC_ERROR_NOT_INITIALIZED);
207                 return;
208         }
209
210         net_nfc_client_manager_unset_activated();
211
212         set_last_result(NFC_ERROR_NONE);
213         /* LCOV_EXCL_STOP */
214 }
215
216 int nfc_manager_initialize(void)
217 {
218         int ret = NET_NFC_OK;
219
220         LOG_BEGIN();
221
222         CHECK_SUPPORTED(NFC_FEATURE);
223
224         /* LCOV_EXCL_START */
225         if (!nfc_common_is_initialized()) {
226                 ret = net_nfc_client_initialize();
227                 if (ret != NET_NFC_OK)
228                         return nfc_common_convert_error_code(__func__, ret);
229
230                 memset(&gdbus_nfc_context, 0, sizeof(gdbus_nfc_context));
231
232                 gdbus_nfc_context.initialized = true;
233         }
234
235         return nfc_common_convert_error_code(__func__, ret);
236         /* LCOV_EXCL_STOP */
237 }
238
239 int nfc_manager_deinitialize(void)
240 {
241         int ret = NET_NFC_OK;
242
243         LOG_BEGIN();
244
245         CHECK_SUPPORTED(NFC_FEATURE);
246
247         /* LCOV_EXCL_START */
248         if (nfc_common_is_initialized()) {
249                 net_nfc_client_se_unset_event_cb();
250
251                 net_nfc_client_p2p_unset_device_discovered();
252                 net_nfc_client_p2p_unset_device_detached();
253
254                 net_nfc_client_tag_unset_tag_discovered();
255                 net_nfc_client_tag_unset_tag_detached();
256
257                 ret = net_nfc_client_deinitialize();
258
259                 gdbus_nfc_context.initialized = false;
260         }
261
262         return nfc_common_convert_error_code(__func__, ret);
263         /* LCOV_EXCL_STOP */
264 }
265
266 /* LCOV_EXCL_START */
267 static void _tag_discovered_cb(net_nfc_target_info_h info, void *user_data)
268 {
269         LOG_BEGIN();
270
271         gdbus_nfc_context.current_tag = info;
272
273         if (gdbus_nfc_context.on_tag_discovered_cb != NULL) {
274                 gdbus_nfc_context.on_tag_discovered_cb(
275                         NFC_DISCOVERED_TYPE_ATTACHED,
276                         (nfc_tag_h)gdbus_nfc_context.current_tag,
277                         gdbus_nfc_context.on_tag_discovered_user_data);
278         }
279
280         /* ndef discovered cb */
281         if (gdbus_nfc_context.on_ndef_discovered_cb) {
282                 ndef_message_h ndef_message = NULL;
283
284                 if (net_nfc_get_tag_ndef_message((net_nfc_target_info_h)info,
285                         &ndef_message) == NET_NFC_OK) {
286                         gdbus_nfc_context.on_ndef_discovered_cb(ndef_message,
287                                 gdbus_nfc_context.on_ndef_discovered_user_data);
288
289                         net_nfc_free_ndef_message(ndef_message);
290                 }
291         }
292 }
293
294 static void _tag_detached_cb(void *user_data)
295 {
296         LOG_BEGIN();
297
298         if (gdbus_nfc_context.on_tag_discovered_cb != NULL) {
299                 gdbus_nfc_context.on_tag_discovered_cb(
300                         NFC_DISCOVERED_TYPE_DETACHED,
301                         (nfc_tag_h)gdbus_nfc_context.current_tag,
302                         gdbus_nfc_context.on_tag_discovered_user_data);
303         }
304
305         gdbus_nfc_context.current_tag = NULL;
306 }
307 /* LCOV_EXCL_STOP */
308
309 int nfc_manager_set_ndef_discovered_cb(
310         nfc_ndef_discovered_cb callback,
311         void *user_data)
312 {
313         LOG_BEGIN();
314
315         CHECK_SUPPORTED(NFC_FEATURE);
316
317         /* LCOV_EXCL_START */
318         CHECK_INIT();
319         CHECK_INVALID(callback == NULL);
320
321         net_nfc_client_tag_set_tag_discovered(_tag_discovered_cb, NULL);
322         net_nfc_client_tag_set_tag_detached(_tag_detached_cb, NULL);
323
324         gdbus_nfc_context.on_ndef_discovered_cb = callback;
325         gdbus_nfc_context.on_ndef_discovered_user_data = user_data;
326
327         return NFC_ERROR_NONE;
328         /* LCOV_EXCL_STOP */
329 }
330
331 void nfc_manager_unset_ndef_discovered_cb(void)
332 {
333         LOG_BEGIN();
334
335         if (nfc_common_is_supported(NFC_FEATURE) == false) {
336                 /* LCOV_EXCL_START */
337                 LOG_ERR("NFC not supported");
338                 set_last_result(NFC_ERROR_NOT_SUPPORTED);
339                 return;
340                 /* LCOV_EXCL_STOP */
341         }
342
343         /* LCOV_EXCL_START */
344         if (nfc_common_is_initialized() == false) {
345                 LOG_ERR("NFC not initialized");
346                 set_last_result(NFC_ERROR_NOT_INITIALIZED);
347                 return;
348         }
349
350         gdbus_nfc_context.on_ndef_discovered_cb = NULL;
351         gdbus_nfc_context.on_ndef_discovered_user_data = NULL;
352
353         set_last_result(NFC_ERROR_NONE);
354         /* LCOV_EXCL_STOP */
355 }
356
357 void nfc_manager_set_tag_filter(int filter)
358 {
359         LOG_BEGIN();
360
361         if (nfc_common_is_supported(NFC_TAG_FEATURE) == false) {
362                 LOG_ERR("NFC not supported");
363                 set_last_result(NFC_ERROR_NOT_SUPPORTED);
364                 return;
365         }
366
367         /* LCOV_EXCL_START */
368         if (nfc_common_is_initialized() == false) {
369                 LOG_ERR("NFC not initialized");
370                 set_last_result(NFC_ERROR_NOT_INITIALIZED);
371                 return;
372         }
373
374         if (filter < NET_NFC_ALL_ENABLE) {
375                 LOG_ERR("Invalid parameter");
376                 set_last_result(NFC_ERROR_INVALID_PARAMETER);
377                 return;
378         }
379
380         net_nfc_client_tag_set_filter(filter);
381
382         set_last_result(NFC_ERROR_NONE);
383         /* LCOV_EXCL_STOP */
384 }
385
386 int nfc_manager_get_tag_filter(void)
387 {
388         LOG_BEGIN();
389
390         if (nfc_common_is_supported(NFC_TAG_FEATURE) == false) {
391                 LOG_ERR("NFC not supported");
392                 set_last_result(NFC_ERROR_NOT_SUPPORTED);
393                 return 0;
394         }
395
396         /* LCOV_EXCL_START */
397         if (nfc_common_is_initialized() == false) {
398                 LOG_ERR("NFC not initialized");
399                 set_last_result(NFC_ERROR_NOT_INITIALIZED);
400                 return 0;
401         }
402
403         set_last_result(NFC_ERROR_NONE);
404
405         return net_nfc_client_tag_get_filter();
406         /* LCOV_EXCL_STOP */
407 }
408
409 int nfc_manager_get_connected_tag(nfc_tag_h *tag)
410 {
411         int ret;
412         net_nfc_target_info_h result = NULL;
413
414         LOG_BEGIN();
415
416         CHECK_SUPPORTED(NFC_TAG_FEATURE);
417
418         /* LCOV_EXCL_START */
419         CHECK_INIT();
420         CHECK_INVALID(tag == NULL);
421
422         *tag = NULL;
423
424         net_nfc_client_tag_set_tag_discovered(_tag_discovered_cb, NULL);
425         net_nfc_client_tag_set_tag_detached(_tag_detached_cb, NULL);
426
427
428         if (gdbus_nfc_context.current_tag == NULL) {
429                 ret = net_nfc_client_tag_get_current_tag_info_sync(&result);
430                 if (ret == NET_NFC_OK)
431                         *tag = (nfc_tag_h)result;
432         } else {
433                 /* FIXME ??? */
434                 *tag = gdbus_nfc_context.current_tag;
435
436                 ret = NET_NFC_OK;
437         }
438
439         return nfc_common_convert_error_code(__func__, ret);
440         /* LCOV_EXCL_STOP */
441 }
442
443 int nfc_manager_get_connected_target(nfc_p2p_target_h *target)
444 {
445         int ret;
446         net_nfc_target_handle_h result = NULL;
447
448         LOG_BEGIN();
449
450         CHECK_SUPPORTED(NFC_P2P_FEATURE);
451
452         /* LCOV_EXCL_START */
453         CHECK_INIT();
454         CHECK_INVALID(target == NULL);
455
456         *target = NULL;
457
458         net_nfc_client_tag_set_tag_discovered(_tag_discovered_cb, NULL);
459         net_nfc_client_tag_set_tag_detached(_tag_detached_cb, NULL);
460
461         if (gdbus_nfc_context.current_target == NULL) {
462                 ret = net_nfc_client_tag_get_current_target_handle_sync(&result);
463                 if (ret == NET_NFC_OK) {
464                         gdbus_nfc_context.current_target = result;
465
466                         *target = gdbus_nfc_context.current_target;
467                 }
468         } else {
469                 /* FIXME ??? */
470                 *target = gdbus_nfc_context.current_target;
471
472                 ret = NET_NFC_OK;
473         }
474
475         return nfc_common_convert_error_code(__func__, ret);
476         /* LCOV_EXCL_STOP */
477 }
478
479 int nfc_manager_set_tag_discovered_cb(nfc_tag_discovered_cb callback,
480         void *user_data)
481 {
482         LOG_BEGIN();
483
484         CHECK_SUPPORTED(NFC_TAG_FEATURE);
485
486         /* LCOV_EXCL_START */
487         CHECK_INIT();
488         CHECK_INVALID(callback == NULL);
489
490         net_nfc_client_tag_set_tag_discovered(_tag_discovered_cb, NULL);
491         net_nfc_client_tag_set_tag_detached(_tag_detached_cb, NULL);
492
493         gdbus_nfc_context.on_tag_discovered_cb = callback;
494         gdbus_nfc_context.on_tag_discovered_user_data = user_data;
495
496         return NFC_ERROR_NONE;
497         /* LCOV_EXCL_STOP */
498 }
499
500 void nfc_manager_unset_tag_discovered_cb(void)
501 {
502         LOG_BEGIN();
503
504         if (nfc_common_is_supported(NFC_TAG_FEATURE) == false) {
505                 LOG_ERR("NFC not supported");
506                 set_last_result(NFC_ERROR_NOT_SUPPORTED);
507                 return;
508         }
509
510         /* LCOV_EXCL_START */
511         if (nfc_common_is_initialized() == false) {
512                 LOG_ERR("NFC not initialized");
513                 set_last_result(NFC_ERROR_NOT_INITIALIZED);
514                 return;
515         }
516
517         gdbus_nfc_context.on_tag_discovered_cb = NULL;
518         gdbus_nfc_context.on_tag_discovered_user_data = NULL;
519
520         set_last_result(NFC_ERROR_NONE);
521         /* LCOV_EXCL_STOP */
522 }
523
524 /* LCOV_EXCL_START */
525 static void _p2p_discovered_cb(
526         net_nfc_target_handle_h handle_info,
527         void *user_data)
528 {
529         LOG_BEGIN();
530
531         gdbus_nfc_context.current_target = handle_info;
532
533         if (gdbus_nfc_context.on_p2p_target_discovered_cb != NULL) {
534                 gdbus_nfc_context.on_p2p_target_discovered_cb(
535                         NFC_DISCOVERED_TYPE_ATTACHED,
536                         (nfc_p2p_target_h)gdbus_nfc_context.current_target,
537                         gdbus_nfc_context.on_p2p_target_discovered_user_data);
538         }
539 }
540
541 static void _p2p_detached_cb(void *user_data)
542 {
543         nfc_p2p_target_h handle =
544                 (nfc_p2p_target_h)gdbus_nfc_context.current_target;
545
546         LOG_BEGIN();
547
548         if (gdbus_nfc_context.on_p2p_target_discovered_cb != NULL) {
549                 gdbus_nfc_context.on_p2p_target_discovered_cb(
550                         NFC_DISCOVERED_TYPE_DETACHED,
551                         handle,
552                         gdbus_nfc_context.on_p2p_target_discovered_user_data);
553         }
554
555         /* unset data_received callback */
556         nfc_p2p_unset_data_received_cb(handle);
557
558         gdbus_nfc_context.current_target = NULL;
559 }
560 /* LCOV_EXCL_STOP */
561
562 int nfc_manager_set_p2p_target_discovered_cb(
563         nfc_p2p_target_discovered_cb callback,
564         void *user_data)
565 {
566         LOG_BEGIN();
567
568         CHECK_SUPPORTED(NFC_P2P_FEATURE);
569
570         /* LCOV_EXCL_START */
571         CHECK_INIT();
572         CHECK_INVALID(callback == NULL);
573
574         net_nfc_client_p2p_set_device_discovered(_p2p_discovered_cb, NULL);
575         net_nfc_client_p2p_set_device_detached(_p2p_detached_cb, NULL);
576
577         gdbus_nfc_context.on_p2p_target_discovered_cb = callback;
578         gdbus_nfc_context.on_p2p_target_discovered_user_data = user_data;
579
580         return NFC_ERROR_NONE;
581         /* LCOV_EXCL_STOP */
582 }
583
584 void nfc_manager_unset_p2p_target_discovered_cb(void)
585 {
586         LOG_BEGIN();
587
588         if (nfc_common_is_supported(NFC_P2P_FEATURE) == false) {
589                 LOG_ERR("NFC not supported");
590                 set_last_result(NFC_ERROR_NOT_SUPPORTED);
591                 return;
592         }
593
594         /* LCOV_EXCL_START */
595         if (nfc_common_is_initialized() == false) {
596                 LOG_ERR("NFC not initialized");
597                 set_last_result(NFC_ERROR_NOT_INITIALIZED);
598                 return;
599         }
600
601         gdbus_nfc_context.on_p2p_target_discovered_cb = NULL;
602         gdbus_nfc_context.on_p2p_target_discovered_user_data = NULL;
603
604         set_last_result(NFC_ERROR_NONE);
605         /* LCOV_EXCL_STOP */
606 }
607
608 int nfc_manager_set_system_handler_enable(bool enable)
609 {
610         int ret;
611         int state;
612
613         LOG_BEGIN();
614
615         CHECK_SUPPORTED(NFC_FEATURE);
616
617         /* LCOV_EXCL_START */
618         CHECK_INIT();
619
620         if (enable == true)
621                 state = 0;
622         else
623                 state = 1;
624
625         ret = net_nfc_client_sys_handler_set_launch_popup_state(state);
626
627         return nfc_common_convert_error_code(__func__, ret);
628         /* LCOV_EXCL_STOP */
629 }
630
631 int nfc_manager_set_system_handler_enable_force(bool enable)
632 {
633         int ret;
634         int state;
635
636         LOG_BEGIN();
637
638         CHECK_SUPPORTED(NFC_FEATURE);
639
640         /* LCOV_EXCL_START */
641         CHECK_INIT();
642
643         if (enable == true)
644                 state = 0;
645         else
646                 state = 1;
647
648         ret = net_nfc_client_sys_handler_set_launch_popup_state_force(state);
649
650         return nfc_common_convert_error_code(__func__, ret);
651         /* LCOV_EXCL_STOP */
652 }
653
654 bool nfc_manager_is_system_handler_enabled(void)
655 {
656         int ret;
657         int state = 0;
658
659         LOG_BEGIN();
660
661         if (nfc_common_is_supported(NFC_FEATURE) == false) {
662                 /* LCOV_EXCL_START */
663                 LOG_ERR("NFC not supported");
664                 set_last_result(NFC_ERROR_NOT_SUPPORTED);
665                 return false;
666                 /* LCOV_EXCL_STOP */
667         }
668
669         /* LCOV_EXCL_START */
670         if (nfc_common_is_initialized() == false) {
671                 LOG_ERR("NFC not initialized");
672                 set_last_result(NFC_ERROR_NOT_INITIALIZED);
673                 return false;
674         }
675
676         ret = net_nfc_client_sys_handler_get_launch_popup_state(&state);
677
678         set_last_result(nfc_common_convert_error_code(__func__, ret));
679
680         return (state == 0);
681         /* LCOV_EXCL_STOP */
682 }
683
684 int nfc_manager_get_cached_message(nfc_ndef_message_h *ndef_message)
685 {
686         int ret;
687
688         LOG_BEGIN();
689
690         CHECK_SUPPORTED(NFC_FEATURE);
691
692         /* LCOV_EXCL_START */
693         CHECK_INIT();
694         CHECK_INVALID(ndef_message == NULL);
695
696         ret = net_nfc_retrieve_current_ndef_message(ndef_message);
697
698         return nfc_common_convert_error_code(__func__, ret);
699         /* LCOV_EXCL_STOP */
700 }
701
702 /* LCOV_EXCL_START */
703 static void _se_event_cb(net_nfc_message_e message, void *user_data)
704 {
705         LOG_BEGIN();
706
707         if (gdbus_nfc_context.on_se_event_cb != NULL) {
708                 if (message == NET_NFC_MESSAGE_SE_CARD_EMULATION_CHANGED)
709                         gdbus_nfc_context.on_se_event_cb(
710                                 NFC_SE_EVENT_CARD_EMULATION_CHANGED,
711                                 gdbus_nfc_context.on_se_event_user_data);
712
713                 else if (message == NET_NFC_MESSAGE_SE_TYPE_CHANGED)
714                         gdbus_nfc_context.on_se_event_cb(
715                                 NFC_SE_EVENT_SE_TYPE_CHANGED,
716                                 gdbus_nfc_context.on_se_event_user_data);
717                 else if (message == NET_NFC_MESSAGE_SE_FIELD_ON)
718                         gdbus_nfc_context.on_se_event_cb(
719                                 NFC_SE_EVENT_FIELD_ON,
720                                 gdbus_nfc_context.on_se_event_user_data);
721         }
722 }
723 /* LCOV_EXCL_STOP */
724
725 int nfc_manager_set_se_event_cb(nfc_se_event_cb callback, void *user_data)
726 {
727         LOG_BEGIN();
728
729         CHECK_SUPPORTED(NFC_CE_FEATURE);
730
731         /* LCOV_EXCL_START */
732         CHECK_INIT();
733         CHECK_INVALID(callback == NULL);
734
735         net_nfc_client_se_set_event_cb(_se_event_cb, NULL);
736
737         gdbus_nfc_context.on_se_event_cb = callback;
738         gdbus_nfc_context.on_se_event_user_data = user_data;
739
740         return NFC_ERROR_NONE;
741         /* LCOV_EXCL_STOP */
742 }
743
744 void nfc_manager_unset_se_event_cb(void)
745 {
746         LOG_BEGIN();
747
748         if (nfc_common_is_supported(NFC_CE_FEATURE) == false) {
749                 /* LCOV_EXCL_START */
750                 LOG_ERR("NFC not supported");
751                 set_last_result(NFC_ERROR_NOT_SUPPORTED);
752                 return;
753                 /* LCOV_EXCL_STOP */
754         }
755
756         /* LCOV_EXCL_START */
757         if (nfc_common_is_initialized() == false) {
758                 LOG_ERR("NFC not initialized");
759                 set_last_result(NFC_ERROR_NOT_INITIALIZED);
760                 return;
761         }
762
763         gdbus_nfc_context.on_se_event_cb = NULL;
764         gdbus_nfc_context.on_se_event_user_data = NULL;
765
766         set_last_result(NFC_ERROR_NONE);
767         /* LCOV_EXCL_STOP */
768 }
769
770 /* LCOV_EXCL_START */
771 static void _se_transaction_event_cb(net_nfc_se_type_e se_type, data_h aid,
772         data_h param, void *user_data)
773 {
774         LOG_BEGIN();
775
776         if (gdbus_nfc_context.on_se_transaction_event_cb != NULL) {
777                 gdbus_nfc_context.on_se_transaction_event_cb(
778                         se_type,
779                         net_nfc_get_data_buffer(aid),
780                         net_nfc_get_data_length(aid),
781                         net_nfc_get_data_buffer(param),
782                         net_nfc_get_data_length(param),
783                         gdbus_nfc_context.on_se_transaction_event_user_data);
784         }
785 }
786 /* LCOV_EXCL_STOP */
787
788 int nfc_manager_set_se_transaction_event_cb(
789         nfc_se_type_e se_type,
790         nfc_se_transaction_event_cb callback,
791         void *user_data)
792 {
793         net_nfc_se_type_e type = NET_NFC_SE_TYPE_NONE;
794
795         LOG_BEGIN();
796
797         CHECK_SUPPORTED(NFC_CE_FEATURE);
798
799         /* LCOV_EXCL_START */
800         CHECK_INIT();
801         CHECK_INVALID(callback == NULL);
802
803         gdbus_nfc_context.on_se_transaction_event_cb = callback;
804         gdbus_nfc_context.on_se_transaction_event_user_data = user_data;
805
806         switch (se_type) {
807         case NFC_SE_TYPE_ESE:
808                 type = NET_NFC_SE_TYPE_ESE;
809                 break;
810
811         case NFC_SE_TYPE_UICC:
812                 type = NET_NFC_SE_TYPE_UICC;
813                 break;
814         case NET_NFC_SE_TYPE_HCE:
815                 type = NET_NFC_SE_TYPE_HCE;
816                 break;
817         default:
818                 return NFC_ERROR_INVALID_PARAMETER;
819                 break;
820         }
821
822         net_nfc_client_se_set_transaction_event_cb(type, _se_transaction_event_cb, user_data);
823
824         return NFC_ERROR_NONE;
825         /* LCOV_EXCL_STOP */
826 }
827
828 void nfc_manager_unset_se_transaction_event_cb(nfc_se_type_e se_type)
829 {
830         net_nfc_se_type_e type = NET_NFC_SE_TYPE_NONE;
831
832         LOG_BEGIN();
833
834         if (nfc_common_is_supported(NFC_CE_FEATURE) == false) {
835                 /* LCOV_EXCL_START */
836                 LOG_ERR("NFC not supported");
837                 set_last_result(NFC_ERROR_NOT_SUPPORTED);
838                 return;
839                 /* LCOV_EXCL_STOP */
840         }
841
842         /* LCOV_EXCL_START */
843         if (nfc_common_is_initialized() == false) {
844                 LOG_ERR("NFC not initialized");
845                 set_last_result(NFC_ERROR_NOT_INITIALIZED);
846                 return;
847         }
848
849         switch (se_type) {
850         case NFC_SE_TYPE_ESE:
851                 type = NET_NFC_SE_TYPE_ESE;
852                 break;
853
854         case NFC_SE_TYPE_UICC:
855                 type = NET_NFC_SE_TYPE_UICC;
856                 break;
857         default:
858                 type = NET_NFC_SE_TYPE_NONE;
859                 break;
860         }
861
862         net_nfc_client_se_unset_transaction_event_cb(type);
863
864         set_last_result(NFC_ERROR_NONE);
865         /* LCOV_EXCL_STOP */
866 }
867
868 int nfc_manager_enable_transaction_fg_dispatch()
869 {
870         net_nfc_error_e result;
871
872         LOG_BEGIN();
873
874         CHECK_SUPPORTED(NFC_CE_FEATURE);
875
876         /* LCOV_EXCL_START */
877         CHECK_INIT();
878
879         result = net_nfc_client_se_set_transaction_fg_dispatch(true);
880
881         return nfc_common_convert_error_code(__func__, result);
882         /* LCOV_EXCL_STOP */
883 }
884
885 int nfc_manager_disable_transaction_fg_dispatch()
886 {
887         net_nfc_error_e result;
888
889         CHECK_SUPPORTED(NFC_CE_FEATURE);
890
891         /* LCOV_EXCL_START */
892         CHECK_INIT();
893
894         result = net_nfc_client_se_set_transaction_fg_dispatch(false);
895
896         return nfc_common_convert_error_code(__func__, result);
897         /* LCOV_EXCL_STOP */
898 }
899
900 int nfc_manager_set_se_type(nfc_se_type_e type)
901 {
902         int ret;
903         net_nfc_se_type_e se_type = NET_NFC_SE_TYPE_NONE;
904
905         LOG_BEGIN();
906
907         CHECK_SUPPORTED(NFC_CE_FEATURE);
908
909         /* LCOV_EXCL_START */
910         CHECK_INIT();
911         CHECK_INVALID(type < NFC_SE_TYPE_DISABLE);
912         CHECK_INVALID(type > NFC_SE_TYPE_HCE);
913
914         switch (type) {
915         case NFC_SE_TYPE_ESE:
916                 se_type = NET_NFC_SE_TYPE_ESE;
917                 break;
918         case NFC_SE_TYPE_UICC:
919                 se_type = NET_NFC_SE_TYPE_UICC;
920                 break;
921         case NFC_SE_TYPE_SDCARD:
922                 se_type = NET_NFC_SE_TYPE_SDCARD;
923                 break;
924         case NFC_SE_TYPE_HCE:
925                 se_type = NET_NFC_SE_TYPE_HCE;
926                 break;
927         default:
928                 se_type = NET_NFC_SE_TYPE_NONE;
929                 break;
930         }
931
932         ret = net_nfc_client_se_set_secure_element_type_sync(se_type);
933
934         return nfc_common_convert_error_code(__func__, ret);
935         /* LCOV_EXCL_STOP */
936 }
937
938 int nfc_manager_get_se_type(nfc_se_type_e *type)
939 {
940         int ret;
941         net_nfc_se_type_e se_type = NET_NFC_SE_TYPE_NONE;
942
943         LOG_BEGIN();
944
945         CHECK_SUPPORTED(NFC_CE_FEATURE);
946
947         /* LCOV_EXCL_START */
948         CHECK_INIT();
949         CHECK_INVALID(type == NULL);
950
951         ret = net_nfc_client_se_get_secure_element_type_sync(&se_type);
952
953         switch (se_type) {
954         case NET_NFC_SE_TYPE_ESE:
955                 *type = NFC_SE_TYPE_ESE;
956                 break;
957         case NET_NFC_SE_TYPE_UICC:
958                 *type = NFC_SE_TYPE_UICC;
959                 break;
960         case NET_NFC_SE_TYPE_SDCARD:
961                 *type = NFC_SE_TYPE_SDCARD;
962                 break;
963         case NET_NFC_SE_TYPE_HCE:
964                 *type = NFC_SE_TYPE_HCE;
965                 break;
966         default:
967                 *type = NFC_SE_TYPE_DISABLE;
968                 break;
969         }
970
971         return nfc_common_convert_error_code(__func__, ret);
972         /* LCOV_EXCL_STOP */
973 }
974
975 /* LCOV_EXCL_START */
976 static void _hce_event_cb(net_nfc_target_handle_h handle,
977                 net_nfc_hce_event_t event, data_h apdu, void *user_data)
978 {
979         LOG_BEGIN();
980
981         if (gdbus_nfc_context.on_hce_event_cb != NULL) {
982                 gdbus_nfc_context.on_hce_event_cb(
983                         (nfc_se_h)handle,
984                         (nfc_hce_event_type_e)event,
985                         net_nfc_get_data_buffer(apdu),
986                         net_nfc_get_data_length(apdu),
987                         gdbus_nfc_context.on_hce_event_user_data);
988         }
989 }
990 /* LCOV_EXCL_STOP */
991
992 int nfc_manager_set_hce_event_cb(nfc_hce_event_cb callback, void *user_data)
993 {
994         net_nfc_error_e result;
995         LOG_BEGIN();
996
997         CHECK_SUPPORTED(NFC_CE_HCE_FEATURE);
998
999         /* LCOV_EXCL_START */
1000         CHECK_INIT();
1001         CHECK_INVALID(callback == NULL);
1002
1003         gdbus_nfc_context.on_hce_event_cb = callback;
1004         gdbus_nfc_context.on_hce_event_user_data = user_data;
1005
1006         result = net_nfc_client_hce_set_event_received_cb(_hce_event_cb, user_data);
1007
1008         return nfc_common_convert_error_code(__func__, result);
1009         /* LCOV_EXCL_STOP */
1010 }
1011
1012 void nfc_manager_unset_hce_event_cb(void)
1013 {
1014         LOG_BEGIN();
1015
1016         if (nfc_common_is_supported(NFC_CE_HCE_FEATURE) == false) {
1017                 /* LCOV_EXCL_START */
1018                 LOG_ERR("NFC not supported");
1019                 set_last_result(NFC_ERROR_NOT_SUPPORTED);
1020                 return;
1021                 /* LCOV_EXCL_STOP */
1022         }
1023
1024         /* LCOV_EXCL_START */
1025         if (nfc_common_is_initialized() == false) {
1026                 LOG_ERR("NFC not initialized");
1027                 set_last_result(NFC_ERROR_NOT_INITIALIZED);
1028                 return;
1029         }
1030
1031         net_nfc_client_hce_unset_event_received_cb();
1032
1033         set_last_result(NFC_ERROR_NONE);
1034         /* LCOV_EXCL_STOP */
1035 }
1036