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.
17 #include "net_nfc_debug_internal.h"
18 #include "net_nfc_util_gdbus_internal.h"
19 #include "net_nfc_gdbus.h"
20 #include "net_nfc_client.h"
21 #include "net_nfc_client_util_internal.h"
22 #include "net_nfc_client_manager.h"
23 #include "net_nfc_client_test.h"
25 #ifndef NET_NFC_EXPORT_API
26 #define NET_NFC_EXPORT_API __attribute__((visibility("default")))
31 static void test_call_sim_test_callback(GObject *source_object,
35 static void test_call_prbs_test_callback(GObject *source_object,
39 static void test_call_get_firmware_version_callback(GObject *source_object,
43 static void test_call_set_ee_data_callback(GObject *source_object,
47 static void test_call_ese_test_callback(GObject *source_object,
51 static NetNfcGDbusTest *test_proxy = NULL;
54 static void test_call_sim_test_callback(GObject *source_object,
58 NetNfcCallback *func_data = (NetNfcCallback *)user_data;
59 net_nfc_error_e out_result;
62 g_assert(user_data != NULL);
64 if (net_nfc_gdbus_test_call_sim_test_finish(
65 NET_NFC_GDBUS_TEST(source_object),
70 DEBUG_ERR_MSG("Can not finish sim_test: %s", error->message);
74 out_result = NET_NFC_IPC_FAIL;
77 if (func_data->callback != NULL) {
78 net_nfc_client_test_sim_test_completed callback =
79 (net_nfc_client_test_sim_test_completed)func_data->callback;
81 callback(out_result, func_data->user_data);
87 static void test_call_prbs_test_callback(GObject *source_object,
91 NetNfcCallback *func_data = (NetNfcCallback *)user_data;
92 net_nfc_error_e out_result;
95 g_assert(user_data != NULL);
97 if (net_nfc_gdbus_test_call_prbs_test_finish(
98 NET_NFC_GDBUS_TEST(source_object),
103 DEBUG_ERR_MSG("Can not finish prbs test: %s", error->message);
107 out_result = NET_NFC_IPC_FAIL;
110 if (func_data->callback != NULL) {
111 net_nfc_client_test_prbs_test_completed callback =
112 (net_nfc_client_test_prbs_test_completed)func_data->callback;
114 callback(out_result, func_data->user_data);
120 static void test_call_get_firmware_version_callback(GObject *source_object,
124 NetNfcCallback *func_data = (NetNfcCallback *)user_data;
125 net_nfc_error_e out_result;
126 gchar *out_version = NULL;
127 GError *error = NULL;
129 g_assert(user_data != NULL);
131 if (net_nfc_gdbus_test_call_get_firmware_version_finish(
132 NET_NFC_GDBUS_TEST(source_object),
138 DEBUG_ERR_MSG("Can not finish get_firmware_version: %s", error->message);
142 out_result = NET_NFC_IPC_FAIL;
145 if (func_data->callback != NULL) {
146 net_nfc_client_test_get_firmware_version_completed callback =
147 (net_nfc_client_test_get_firmware_version_completed)func_data->callback;
149 callback(out_result, out_version, func_data->user_data);
156 static void test_call_set_ee_data_callback(GObject *source_object,
160 NetNfcCallback *func_data = (NetNfcCallback *)user_data;
161 net_nfc_error_e out_result;
162 GError *error = NULL;
164 g_assert(user_data != NULL);
166 if (net_nfc_gdbus_test_call_set_ee_data_finish(
167 NET_NFC_GDBUS_TEST(source_object),
172 DEBUG_ERR_MSG("Can not finish set_ee_data: %s", error->message);
176 out_result = NET_NFC_IPC_FAIL;
179 if (func_data->callback != NULL) {
180 net_nfc_client_test_set_ee_data_completed callback =
181 (net_nfc_client_test_set_ee_data_completed)func_data->callback;
183 callback(out_result, func_data->user_data);
189 static void test_call_ese_test_callback(GObject *source_object,
193 NetNfcCallback *func_data = (NetNfcCallback *)user_data;
194 net_nfc_error_e out_result;
195 GError *error = NULL;
197 g_assert(user_data != NULL);
199 if (net_nfc_gdbus_test_call_ese_test_finish(
200 NET_NFC_GDBUS_TEST(source_object),
205 DEBUG_ERR_MSG("Can not finish sim_test: %s", error->message);
209 out_result = NET_NFC_IPC_FAIL;
212 if (func_data->callback != NULL) {
213 net_nfc_client_test_ese_test_completed callback =
214 (net_nfc_client_test_ese_test_completed)func_data->callback;
216 callback(out_result, func_data->user_data);
224 net_nfc_error_e net_nfc_client_test_sim_test(
225 net_nfc_client_test_sim_test_completed callback,
228 NetNfcCallback *func_data;
230 if (test_proxy == NULL) {
231 if (net_nfc_client_test_init() != NET_NFC_OK) {
232 DEBUG_ERR_MSG("test_proxy fail");
233 return NET_NFC_NOT_INITIALIZED;
237 /* prevent executing daemon when nfc is off */
238 if (net_nfc_client_manager_is_activated() == false)
239 return NET_NFC_NOT_ACTIVATED;
241 func_data = g_try_new0(NetNfcCallback, 1);
242 if (func_data == NULL)
243 return NET_NFC_ALLOC_FAIL;
245 func_data->callback = (gpointer)callback;
246 func_data->user_data = user_data;
248 net_nfc_gdbus_test_call_sim_test(test_proxy,
250 test_call_sim_test_callback,
257 net_nfc_error_e net_nfc_client_test_sim_test_sync(void)
259 net_nfc_error_e out_result = NET_NFC_OK;
260 GError *error = NULL;
262 if (test_proxy == NULL) {
263 if (net_nfc_client_test_init() != NET_NFC_OK) {
264 DEBUG_ERR_MSG("test_proxy fail");
265 return NET_NFC_NOT_INITIALIZED;
269 /* prevent executing daemon when nfc is off */
270 if (net_nfc_client_manager_is_activated() == false)
271 return NET_NFC_NOT_ACTIVATED;
273 if (net_nfc_gdbus_test_call_sim_test_sync(test_proxy,
278 DEBUG_ERR_MSG("can not call SimTest: %s", error->message);
282 out_result = NET_NFC_IPC_FAIL;
289 net_nfc_error_e net_nfc_client_test_prbs_test(uint32_t tech,
291 net_nfc_client_test_prbs_test_completed callback,
294 NetNfcCallback *func_data;
296 if (test_proxy == NULL) {
297 if (net_nfc_client_test_init() != NET_NFC_OK) {
298 DEBUG_ERR_MSG("test_proxy fail");
299 return NET_NFC_NOT_INITIALIZED;
303 /* prevent executing daemon when nfc is off */
304 if (net_nfc_client_manager_is_activated() == false)
305 return NET_NFC_NOT_ACTIVATED;
307 func_data = g_try_new0(NetNfcCallback, 1);
308 if (func_data == NULL)
309 return NET_NFC_ALLOC_FAIL;
311 func_data->callback = (gpointer)callback;
312 func_data->user_data = user_data;
314 net_nfc_gdbus_test_call_prbs_test(test_proxy,
318 test_call_prbs_test_callback,
325 net_nfc_error_e net_nfc_client_test_prbs_test_sync(uint32_t tech,
328 net_nfc_error_e out_result = NET_NFC_OK;
329 GError *error = NULL;
331 if (test_proxy == NULL) {
332 if (net_nfc_client_test_init() != NET_NFC_OK) {
333 DEBUG_ERR_MSG("test_proxy fail");
334 return NET_NFC_NOT_INITIALIZED;
338 /* prevent executing daemon when nfc is off */
339 if (net_nfc_client_manager_is_activated() == false)
340 return NET_NFC_NOT_ACTIVATED;
342 if (net_nfc_gdbus_test_call_prbs_test_sync(test_proxy,
349 DEBUG_ERR_MSG("can not call PrbsTest: %s", error->message);
353 out_result = NET_NFC_IPC_FAIL;
360 net_nfc_error_e net_nfc_client_test_get_firmware_version(
361 net_nfc_client_test_get_firmware_version_completed callback,
364 NetNfcCallback *func_data;
366 if (test_proxy == NULL) {
367 if (net_nfc_client_test_init() != NET_NFC_OK) {
368 DEBUG_ERR_MSG("test_proxy fail");
369 return NET_NFC_NOT_INITIALIZED;
373 /* prevent executing daemon when nfc is off */
374 if (net_nfc_client_manager_is_activated() == false)
375 return NET_NFC_NOT_ACTIVATED;
377 func_data = g_try_new0(NetNfcCallback, 1);
378 if (func_data == NULL)
379 return NET_NFC_ALLOC_FAIL;
381 func_data->callback = (gpointer)callback;
382 func_data->user_data = user_data;
384 net_nfc_gdbus_test_call_get_firmware_version(test_proxy,
386 test_call_get_firmware_version_callback,
393 net_nfc_error_e net_nfc_client_test_get_firmware_version_sync(char **version)
395 net_nfc_error_e out_result = NET_NFC_OK;
396 gchar *out_version = NULL;
397 GError *error = NULL;
400 return NET_NFC_NULL_PARAMETER;
404 if (test_proxy == NULL) {
405 if (net_nfc_client_test_init() != NET_NFC_OK) {
406 DEBUG_ERR_MSG("test_proxy fail");
407 return NET_NFC_NOT_INITIALIZED;
411 /* prevent executing daemon when nfc is off */
412 if (net_nfc_client_manager_is_activated() == false)
413 return NET_NFC_NOT_ACTIVATED;
415 if (net_nfc_gdbus_test_call_get_firmware_version_sync(test_proxy,
420 *version = out_version;
423 DEBUG_ERR_MSG("can not call Get Firmware version: %s", error->message);
427 out_result = NET_NFC_IPC_FAIL;
434 net_nfc_error_e net_nfc_client_test_set_ee_data(int mode,
437 net_nfc_client_test_set_ee_data_completed callback,
440 NetNfcCallback *func_data;
443 if (test_proxy == NULL) {
444 if (net_nfc_client_test_init() != NET_NFC_OK) {
445 DEBUG_ERR_MSG("test_proxy fail");
446 return NET_NFC_NOT_INITIALIZED;
450 /* prevent executing daemon when nfc is off */
451 if (net_nfc_client_manager_is_activated() == false)
452 return NET_NFC_NOT_ACTIVATED;
454 func_data = g_try_new0(NetNfcCallback, 1);
455 if (func_data == NULL)
456 return NET_NFC_ALLOC_FAIL;
458 func_data->callback = (gpointer)callback;
459 func_data->user_data = user_data;
461 variant = net_nfc_util_gdbus_data_to_variant((data_s *)data);
463 net_nfc_gdbus_test_call_set_ee_data(test_proxy,
468 test_call_set_ee_data_callback,
475 net_nfc_error_e net_nfc_client_test_set_ee_data_sync(int mode,
479 net_nfc_error_e out_result = NET_NFC_OK;
480 GVariant *variant = NULL;
481 GError *error = NULL;
483 if (test_proxy == NULL) {
484 if (net_nfc_client_test_init() != NET_NFC_OK) {
485 DEBUG_ERR_MSG("test_proxy fail");
486 return NET_NFC_NOT_INITIALIZED;
490 /* prevent executing daemon when nfc is off */
491 if (net_nfc_client_manager_is_activated() == false)
492 return NET_NFC_NOT_ACTIVATED;
494 variant = net_nfc_util_gdbus_data_to_variant((data_s *)data);
496 if (net_nfc_gdbus_test_call_set_ee_data_sync(test_proxy,
504 DEBUG_ERR_MSG("can not call SetEeTest: %s", error->message);
508 out_result = NET_NFC_IPC_FAIL;
515 net_nfc_error_e net_nfc_client_test_test_mode_on_sync(void)
517 net_nfc_error_e out_result = NET_NFC_OK;
518 GError *error = NULL;
520 DEBUG_CLIENT_MSG("NFC Test Mode ON SYNC!!!!");
522 if (test_proxy == NULL) {
523 if (net_nfc_client_test_init() != NET_NFC_OK) {
524 DEBUG_ERR_MSG("test_proxy fail");
525 return NET_NFC_NOT_INITIALIZED;
529 /* prevent executing daemon when nfc is off */
530 if (net_nfc_client_manager_is_activated() == false)
531 return NET_NFC_NOT_ACTIVATED;
533 if (net_nfc_gdbus_test_call_test_mode_on_sync(test_proxy,
538 DEBUG_ERR_MSG("can not call Test Mode On: %s", error->message);
542 out_result = NET_NFC_IPC_FAIL;
549 net_nfc_error_e net_nfc_client_test_test_mode_off_sync(void)
551 net_nfc_error_e out_result = NET_NFC_OK;
552 GError *error = NULL;
554 DEBUG_CLIENT_MSG("NFC Test Mode Off SYNC!!!!");
556 if (test_proxy == NULL) {
557 if (net_nfc_client_test_init() != NET_NFC_OK) {
558 DEBUG_ERR_MSG("test_proxy fail");
559 return NET_NFC_NOT_INITIALIZED;
563 /* prevent executing daemon when nfc is off */
564 if (net_nfc_client_manager_is_activated() == false)
565 return NET_NFC_NOT_ACTIVATED;
567 if (net_nfc_gdbus_test_call_test_mode_off_sync(test_proxy,
572 DEBUG_ERR_MSG("can not call Test Mode Off: %s", error->message);
576 out_result = NET_NFC_IPC_FAIL;
584 net_nfc_error_e net_nfc_client_test_ese_test(
585 net_nfc_client_test_ese_test_completed callback,
588 NetNfcCallback *func_data;
590 DEBUG_CLIENT_MSG("NFC ESE Test!!!!");
592 if (test_proxy == NULL) {
593 if (net_nfc_client_test_init() != NET_NFC_OK) {
594 DEBUG_ERR_MSG("test_proxy fail");
595 return NET_NFC_NOT_INITIALIZED;
599 /* prevent executing daemon when nfc is off */
600 if (net_nfc_client_manager_is_activated() == false)
601 return NET_NFC_NOT_ACTIVATED;
603 func_data = g_try_new0(NetNfcCallback, 1);
604 if (func_data == NULL)
605 return NET_NFC_ALLOC_FAIL;
607 func_data->callback = (gpointer)callback;
608 func_data->user_data = user_data;
610 net_nfc_gdbus_test_call_ese_test(test_proxy,
612 test_call_ese_test_callback,
619 net_nfc_error_e net_nfc_client_test_ese_test_sync(void)
621 net_nfc_error_e out_result = NET_NFC_OK;
622 GError *error = NULL;
624 DEBUG_CLIENT_MSG("NFC ESE Test SYNC!!!!");
626 if (test_proxy == NULL) {
627 if (net_nfc_client_test_init() != NET_NFC_OK) {
628 DEBUG_ERR_MSG("test_proxy fail");
629 return NET_NFC_NOT_INITIALIZED;
633 /* prevent executing daemon when nfc is off */
634 if (net_nfc_client_manager_is_activated() == false)
635 return NET_NFC_NOT_ACTIVATED;
637 if (net_nfc_gdbus_test_call_ese_test_sync(test_proxy,
642 DEBUG_ERR_MSG("can not call ESE Test: %s", error->message);
646 out_result = NET_NFC_IPC_FAIL;
653 net_nfc_error_e net_nfc_client_test_set_se_tech_type_sync(
654 net_nfc_se_type_e type, int tech)
656 net_nfc_error_e out_result = NET_NFC_OK;
657 GError *error = NULL;
659 if (test_proxy == NULL) {
660 if (net_nfc_client_test_init() != NET_NFC_OK) {
661 DEBUG_ERR_MSG("test_proxy fail");
662 return NET_NFC_NOT_INITIALIZED;
666 /* prevent executing daemon when nfc is off */
667 if (net_nfc_client_manager_is_activated() == false)
668 return NET_NFC_NOT_ACTIVATED;
670 if (net_nfc_gdbus_test_call_set_se_tech_type_sync(test_proxy,
677 DEBUG_ERR_MSG("can not call SetSeTechType: %s", error->message);
681 out_result = NET_NFC_IPC_FAIL;
688 net_nfc_error_e net_nfc_client_test_set_listen_tech_mask_sync(uint32_t tech)
690 net_nfc_error_e result = NET_NFC_OK;
691 GError *error = NULL;
693 DEBUG_CLIENT_MSG("net_nfc_client_test_set_listen_tech_mask_sync start");
695 if (test_proxy == NULL) {
696 if (net_nfc_client_test_init() != NET_NFC_OK) {
697 DEBUG_ERR_MSG("test_proxy fail");
698 return NET_NFC_NOT_INITIALIZED;
702 /* prevent executing daemon when nfc is off */
703 if (net_nfc_client_manager_is_activated() == false)
704 return NET_NFC_NOT_ACTIVATED;
706 if (net_nfc_gdbus_test_call_set_listen_tech_mask_sync(test_proxy,
712 DEBUG_ERR_MSG("can not call listen tech mask: %s", error->message);
716 result = NET_NFC_IPC_FAIL;
723 net_nfc_error_e net_nfc_client_test_init(void)
725 GError *error = NULL;
728 DEBUG_CLIENT_MSG("Already initialized");
733 test_proxy = net_nfc_gdbus_test_proxy_new_for_bus_sync(
735 G_DBUS_PROXY_FLAGS_NONE,
736 "org.tizen.NetNfcService",
737 "/org/tizen/NetNfcService/Test",
740 if (test_proxy == NULL) {
742 DEBUG_ERR_MSG("Can not create proxy : %s", error->message);
746 return NET_NFC_UNKNOWN_ERROR;
752 void net_nfc_client_test_deinit(void)
755 g_object_unref(test_proxy);