2 * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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 <glib-object.h>
23 #include "net_nfc_test_client.h"
24 #include "net_nfc_test_llcp.h"
25 #include "net_nfc_test_snep.h"
26 #include "net_nfc_test_manager.h"
27 #include "net_nfc_test_tag.h"
28 #include "net_nfc_test_ndef.h"
29 #include "net_nfc_test_p2p.h"
30 #include "net_nfc_test_handover.h"
31 #include "net_nfc_test_transceive.h"
32 #include "net_nfc_test_jewel.h"
33 #include "net_nfc_test_tag_mifare.h"
34 #include "net_nfc_test_tag_felica.h"
35 #include "net_nfc_test_se.h"
36 #include "net_nfc_test_sys_handler.h"
39 typedef struct _TestData TestData;
50 static TestData test_data[] = {
54 net_nfc_test_manager_set_active,
55 net_nfc_test_manager_set_active_sync,
62 net_nfc_test_manager_get_server_state,
63 net_nfc_test_manager_get_server_state_sync,
70 net_nfc_test_initialize,
72 "Start Client Initialization"
78 net_nfc_test_deinitialize,
80 "Start Client Deinitialization"
85 "ClientIsNfcSupported",
86 net_nfc_test_is_nfc_supported,
88 "Get is nfc supported"
94 net_nfc_test_get_nfc_state,
102 net_nfc_test_tag_is_tag_connected,
103 net_nfc_test_tag_is_tag_connected_sync,
104 "Get is tag connected"
109 net_nfc_test_tag_get_current_tag_info,
110 net_nfc_test_tag_get_current_tag_info_sync,
111 "Get current tag info"
116 "GetCurrentTargetHandle",
117 net_nfc_test_tag_get_current_target_handle,
118 net_nfc_test_tag_get_current_target_handle_sync,
119 "Get current target handle id"
124 "TagDiscovered", /* waiting for signal */
125 net_nfc_test_tag_set_tag_discovered,
127 "Waiting for TagDiscoved signal"
133 net_nfc_test_tag_set_filter,
141 net_nfc_test_tag_get_filter,
149 "TagDetached", /* waiting for signal */
150 net_nfc_test_tag_set_tag_detached,
152 "Waiting for TagDetached signal"
158 net_nfc_test_ndef_read,
159 net_nfc_test_ndef_read_sync,
166 net_nfc_test_ndef_write,
167 net_nfc_test_ndef_write_sync,
174 net_nfc_test_ndef_format,
175 net_nfc_test_ndef_format_sync,
182 net_nfc_test_ndef_make_read_only,
183 net_nfc_test_ndef_make_read_only_sync,
190 net_nfc_test_p2p_send,
191 net_nfc_test_p2p_send_sync,
198 "Discovered", /* waiting for signal*/
199 net_nfc_test_p2p_set_device_discovered,
201 "Waiting for Device Discovered Signal"
206 "Detached", /* waiting for signal*/
207 net_nfc_test_p2p_set_device_detached,
209 "Waiting for Device Detached Signal"
214 "Received", /* waiting for signal*/
215 net_nfc_test_p2p_set_data_received,
217 "Waiting for Device Data Received Signal"
223 net_nfc_test_transceive_data,
224 net_nfc_test_transceive_data_sync,
225 "Tansceive data method call "
231 net_nfc_test_transceive,
232 net_nfc_test_transceive_sync,
233 "Tansceive method call"
239 net_nfc_test_p2p_connection_handover_with_BT,
240 net_nfc_test_p2p_connection_handover_with_BT_sync,
241 "Handover Request Call"
248 net_nfc_test_p2p_connection_handover_with_WIFI,
249 net_nfc_test_p2p_connection_handover_with_WIFI_sync,
250 "Handover Request Call"
257 net_nfc_test_handover_get_alternative_carrier_type,
259 "Get Handover Carrier Type"
266 net_nfc_test_handover_handle_alternative_carrier_data,
268 "Create/Free Handover Carrier Data"
275 net_nfc_test_tag_jewel_read_id,
284 net_nfc_test_tag_jewel_read_byte,
293 net_nfc_test_tag_jewel_read_all,
302 net_nfc_test_tag_jewel_write_with_erase,
304 "Jewel Write With Erase"
311 net_nfc_test_tag_jewel_write_with_no_erase,
313 "Jewel Write With No Erase"
320 net_nfc_test_tag_mifare_read,
328 net_nfc_test_tag_mifare_write_block,
336 net_nfc_test_tag_mifare_write_page,
344 net_nfc_test_tag_mifare_increment,
346 "Increment block value"
352 net_nfc_test_tag_mifare_decrement,
354 "Decrement block value"
360 net_nfc_test_tag_mifare_transfer,
368 net_nfc_test_tag_mifare_restore,
376 net_nfc_test_tag_mifare_authenticate_with_keyA,
378 "Authenticate with key A"
384 net_nfc_test_tag_mifare_authenticate_with_keyB,
386 "Authenticate with key B"
392 net_nfc_test_felica_poll,
399 "FelicaRequestService",
400 net_nfc_test_felica_request_service,
402 "Felica Request Service"
407 "FelicaRequestResponse",
408 net_nfc_test_felica_request_response,
410 "Felica Request Response"
415 "FelicaReadWithoutEncryption",
416 net_nfc_test_felica_read_without_encryption,
418 "Felica Read Without Encryption"
423 "FelicaWriteWithoutEncryption",
424 net_nfc_test_felica_write_without_encryption,
426 "Felica Write Without Encryption"
431 "FelicaRequestSystemCode",
432 net_nfc_test_felica_request_system_code,
434 "Felica Request System Code"
440 net_nfc_test_llcp_get_config_wks,
442 "Get the Config of WKS"
449 net_nfc_test_llcp_get_config_lto,
451 "Get the Config of LTO"
458 net_nfc_test_llcp_get_config_miu,
460 "Get the Config of MIU"
466 net_nfc_test_llcp_get_config_option,
468 "Get the Config Option Type"
474 net_nfc_test_llcp_set_config_wks,
476 "Set the Config for WKS"
483 net_nfc_test_llcp_set_config_lto,
485 "Set the Config for LTO"
492 net_nfc_test_llcp_set_config_miu,
494 "Set the Config for MIU"
500 net_nfc_test_llcp_set_config_option,
502 "Set the Config Option Type"
508 net_nfc_test_llcp_free_config,
510 "Clear the llcp configuration options"
516 "CreateCustomSocketOption",
517 net_nfc_test_llcp_create_custom_socket_option,
519 "Create Custom Socket Option"
524 "CreateDefaultSocketOption",
525 net_nfc_test_llcp_create_default_socket_option,
527 "Create Default Socket Option"
533 "GetLocalSocketOption",
534 net_nfc_test_llcp_get_local_socket_option,
536 "Get Local Socket Option"
543 net_nfc_test_llcp_get_socket_option_miu,
545 "Get Local Socket MIU"
552 net_nfc_test_llcp_get_socket_option_rw,
554 "Get Local Socket RW"
560 "GetLocalSocketOptionType",
561 net_nfc_test_llcp_get_socket_option_type,
563 "Get Local Socket Option Type"
569 net_nfc_test_llcp_set_socket_option_miu,
571 "Set Local Socket MIU"
578 net_nfc_test_llcp_set_socket_option_rw,
580 "Set Local Socket RW"
586 "SetLocalSocketOptionType",
587 net_nfc_test_llcp_set_socket_option_type,
589 "Set Local Socket Option Type"
595 net_nfc_test_llcp_free_socket_option,
603 net_nfc_test_llcp_listen,
604 net_nfc_test_llcp_listen_sync,
605 "Listen To Server Socket"
611 net_nfc_test_llcp_receive,
612 net_nfc_test_llcp_receive_sync,
613 "Receive data from socket "
619 net_nfc_test_llcp_receive_from,
620 net_nfc_test_llcp_receive_from_sync,
621 "Receive data from socket (sap data also included)"
627 net_nfc_test_llcp_connect,
628 net_nfc_test_llcp_connect_sync,
629 "Connect to a socket"
634 "ConnectToSapSocket",
635 net_nfc_test_llcp_connect_sap,
636 net_nfc_test_llcp_connect_sap_sync,
637 "Connect to a specific SAP on the socket"
643 net_nfc_test_llcp_send,
644 net_nfc_test_llcp_send_sync,
645 "Send Data to a socket"
651 net_nfc_test_llcp_send_to,
652 net_nfc_test_llcp_send_to_sync,
653 "Send data to a specific SAP on the socket"
659 net_nfc_test_llcp_disconnect,
660 net_nfc_test_llcp_disconnect_sync,
661 "Disconnects the client socket"
666 "DisconnectOtherSockets",
667 net_nfc_test_llcp_disconnect_server,
669 "Disconnects the Server and Accepted sockets"
675 net_nfc_test_snep_set_tag_discovered,
677 "Discovers the tag/target before starting SNEP operation"
682 "SNEPP2PDeviceDiscovery",
683 net_nfc_test_snep_set_p2p_device_discovered,
685 "Discover the P2P device for snep operation"
691 net_nfc_test_snep_start_server,
692 net_nfc_test_snep_start_server_sync,
693 "Starts the SNEP server"
699 net_nfc_test_snep_start_client,
701 "Starts the SNEP client"
707 net_nfc_test_snep_send_client_request,
709 "Sends the SNEP client Request"
715 net_nfc_test_snep_register_server,
717 "Registers the SNEP server"
723 net_nfc_test_snep_unregister_server,
725 "UnRegisters the SNEP server"
730 "ServerRegisterUnregister",
731 net_nfc_test_snep_register_unregister_server,
733 "Registers and UnRegisters the SNEP server"
739 net_nfc_test_snep_stop_service_sync,
741 "Registers and UnRegisters the SNEP server"
747 net_nfc_test_se_send_apdu,
748 net_nfc_test_se_send_apdu_sync,
749 "Secure element send apdu data"
755 net_nfc_test_se_set_secure_element_type,
756 net_nfc_test_se_set_secure_element_type_sync,
757 "Set secure element type"
763 net_nfc_test_se_open_internal_secure_element,
764 net_nfc_test_se_open_internal_secure_element_sync,
765 "Open internal secure element"
771 net_nfc_test_se_close_internal_secure_element,
772 net_nfc_test_se_close_internal_secure_element_sync,
773 "Close internal secure element"
779 net_nfc_test_se_get_atr,
780 net_nfc_test_se_get_atr_sync,
781 "Get secure element attribute"
787 net_nfc_test_se_set_event_cb,
794 "UnsetEventCallback",
795 net_nfc_test_se_unset_event_cb,
797 "Unset event callback"
802 "SetDetectionCallback",
803 net_nfc_test_se_set_ese_detection_cb,
805 "Set detection callback"
810 "UnsetDetectionCallback",
811 net_nfc_test_se_unset_ese_detection_cb,
813 "Unset detection callback"
818 "SetTransactionCallback",
819 net_nfc_test_se_set_transaction_event_cb,
821 "Set transaction callback"
826 "UnsetTransactionCallback",
827 net_nfc_test_se_unset_transaction_event_cb,
829 "Unset transaction callback"
835 net_nfc_test_sys_handler_set_launch_popup_state,
836 net_nfc_test_sys_handler_set_launch_popup_state_sync,
837 "Set launch popup state"
842 "SetLaunchPopStateForce",
843 net_nfc_test_sys_handler_set_launch_popup_state_force,
844 net_nfc_test_sys_handler_set_launch_popup_state_force_sync,
845 "Set launch popup state"
851 net_nfc_test_sys_handler_get_launch_popup_state,
853 "Get launch popup state"
860 static GMainLoop *loop = NULL;
862 static GList *pos = NULL;
864 static void test_string_free(gpointer data);
866 static void run_test(void);
868 static void test_string_free(gpointer data)
879 static void run_test(void)
889 for (i = 0; test_data[i].interface != NULL; i++)
897 if ((strcmp(strv[0], test_data[i].interface) == 0) &&
898 (strcmp(strv[1], test_data[i].name) == 0))
903 if (strv[2] && strcmp(strv[2], "Sync") == 0)
905 g_print("run %s.%s(Sync)\n", strv[0], strv[1]);
906 test_data[i].func_sync(NULL,
911 g_print("run %s.%s\n", strv[0], strv[1]);
912 test_data[i].func(NULL,
921 int main(int argc, char *argv[])
925 if (argc == 2 && strcmp(argv[1], "--help") == 0)
927 g_print("nfc-client-test: nfc-client-test [inteface.name]\n");
930 for (i = 0; i < G_N_ELEMENTS(test_data) - 1; i++)
932 g_print("\t%s - %s : %s\n", test_data[i].interface,
934 test_data[i].comment);
939 for (i = 1 ; i < argc ; i++)
943 strv = g_strsplit(argv[i], ".", 3);
944 pos = g_list_append(pos, strv);
951 strv = g_strsplit("Manager.SetActive", ".", 3);
952 pos = g_list_append(pos, strv);
960 if (strcmp(strv[0], "Manager") != 0 ||
961 strcmp(strv[1], "SetActive") != 0)
963 gchar **manager_strv;
965 manager_strv = g_strsplit("Manager.SetActive", ".", 3);
966 pos = g_list_prepend(pos, manager_strv);
970 net_nfc_client_initialize();
974 loop = g_main_loop_new(NULL, FALSE);
976 g_main_loop_run(loop);
978 net_nfc_client_deinitialize();
981 g_list_free_full(pos, test_string_free);