From af8ecf1fb35eb946701c15aff0fcd84efebed041 Mon Sep 17 00:00:00 2001 From: Jinkun Jang Date: Wed, 13 Mar 2013 01:47:30 +0900 Subject: [PATCH] Tizen 2.1 base --- AUTHORS | 8 + CMakeLists.txt | 9 + LICENSE.Flora | 206 ++ NOTICE | 3 + TC/_export_env.sh | 8 + TC/_export_target_env.sh | 7 + TC/build.sh | 16 + TC/clean.sh | 11 + TC/config.default | 3 + TC/execute.sh | 15 + TC/testcase/Makefile | 35 + TC/testcase/tslist | 12 + TC/testcase/utc_net_nfc_client_data.c | 297 ++ TC/testcase/utc_net_nfc_client_exchanger.c | 130 + TC/testcase/utc_net_nfc_client_internal_se.c | 169 + TC/testcase/utc_net_nfc_client_ndef_message.c | 258 ++ TC/testcase/utc_net_nfc_client_ndef_record.c | 571 ++++ TC/testcase/utc_net_nfc_client_nfc.c | 161 + TC/testcase/utc_net_nfc_client_tag.c | 256 ++ TC/testcase/utc_net_nfc_client_tag_felica.c | 242 ++ TC/testcase/utc_net_nfc_client_tag_jewel.c | 185 ++ TC/testcase/utc_net_nfc_client_tag_mifare.c | 369 +++ TC/testcase/utc_net_nfc_client_target_info.c | 296 ++ TC/tet_scen | 7 + TC/tetbuild.cfg | 5 + TC/tetclean.cfg | 5 + TC/tetexec.cfg | 5 + debian/changelog | 614 ++++ debian/compat | 1 + debian/control | 42 + debian/libnfc-common-lib-0.install.in | 1 + debian/libnfc-common-lib-0.postinst.in | 8 + debian/libnfc-common-lib-dbg.install.in | 1 + debian/libnfc-common-lib-dev.install.in | 3 + debian/libnfc-manager-0.init.in | 23 + debian/libnfc-manager-0.install.in | 5 + debian/libnfc-manager-0.postinst.in | 12 + debian/libnfc-manager-dbg.install.in | 1 + debian/libnfc-manager-dev.install.in | 3 + debian/rules | 132 + doxygen/createdoc.sh | 41 + doxygen/doxygen.conf | 852 +++++ doxygen/slp_doxy.css | 699 ++++ nfc-common-lib-devel.manifest | 6 + nfc-common-lib.manifest | 6 + nfc-manager-devel.manifest | 6 + nfc-manager.manifest | 16 + packaging/libnfc-manager-0.init.in | 31 + packaging/nfc-common-lib | 206 ++ packaging/nfc-manager | 206 ++ packaging/nfc-manager.service | 10 + packaging/nfc-manager.spec | 162 + src/clientlib/CMakeLists.txt | 100 + src/clientlib/include/net_nfc.h | 381 +++ src/clientlib/include/net_nfc_apdu.h | 130 + .../include/net_nfc_client_dispatcher_private.h | 34 + src/clientlib/include/net_nfc_client_ipc_private.h | 38 + src/clientlib/include/net_nfc_client_nfc_private.h | 46 + .../include/net_nfc_client_util_private.h | 21 + src/clientlib/include/net_nfc_data.h | 144 + src/clientlib/include/net_nfc_exchanger.h | 127 + src/clientlib/include/net_nfc_exchanger_private.h | 43 + src/clientlib/include/net_nfc_internal_se.h | 141 + src/clientlib/include/net_nfc_llcp.h | 634 ++++ src/clientlib/include/net_nfc_ndef_message.h | 447 +++ .../include/net_nfc_ndef_message_handover.h | 421 +++ src/clientlib/include/net_nfc_ndef_record.h | 372 +++ src/clientlib/include/net_nfc_sign_record.h | 152 + src/clientlib/include/net_nfc_tag.h | 515 +++ src/clientlib/include/net_nfc_tag_felica.h | 237 ++ src/clientlib/include/net_nfc_tag_jewel.h | 184 ++ src/clientlib/include/net_nfc_tag_mifare.h | 354 ++ src/clientlib/include/net_nfc_target_info.h | 314 ++ src/clientlib/include/net_nfc_test.h | 41 + src/clientlib/net_nfc_client_data.c | 159 + src/clientlib/net_nfc_client_dispatcher.c | 1131 +++++++ src/clientlib/net_nfc_client_exchanger.c | 223 ++ src/clientlib/net_nfc_client_internal_se.c | 140 + src/clientlib/net_nfc_client_ipc.c | 1715 ++++++++++ src/clientlib/net_nfc_client_llcp.c | 1083 ++++++ src/clientlib/net_nfc_client_ndef_message.c | 215 ++ .../net_nfc_client_ndef_message_handover.c | 162 + src/clientlib/net_nfc_client_ndef_record.c | 292 ++ src/clientlib/net_nfc_client_nfc.c | 482 +++ src/clientlib/net_nfc_client_sign_record.c | 42 + src/clientlib/net_nfc_client_tag.c | 480 +++ src/clientlib/net_nfc_client_tag_felica.c | 491 +++ src/clientlib/net_nfc_client_tag_jewel.c | 333 ++ src/clientlib/net_nfc_client_tag_mifare.c | 947 ++++++ src/clientlib/net_nfc_client_target_info.c | 283 ++ src/clientlib/net_nfc_client_test.c | 149 + src/clientlib/net_nfc_client_util.c | 21 + src/clientlib/nfc.pc.in | 11 + src/commonlib/CMakeLists.txt | 73 + src/commonlib/include/net_nfc_debug_private.h | 148 + src/commonlib/include/net_nfc_oem_controller.h | 130 + src/commonlib/include/net_nfc_typedef.h | 527 +++ src/commonlib/include/net_nfc_typedef_private.h | 1313 ++++++++ src/commonlib/include/net_nfc_util_defines.h | 36 + src/commonlib/include/net_nfc_util_handover.h | 98 + src/commonlib/include/net_nfc_util_ipc.h | 45 + src/commonlib/include/net_nfc_util_ndef_message.h | 95 + src/commonlib/include/net_nfc_util_ndef_record.h | 58 + .../include/net_nfc_util_openssl_private.h | 65 + src/commonlib/include/net_nfc_util_private.h | 83 + src/commonlib/include/net_nfc_util_sign_record.h | 36 + src/commonlib/net_nfc_util.c | 468 +++ src/commonlib/net_nfc_util_handover.c | 1543 +++++++++ src/commonlib/net_nfc_util_ipc.c | 70 + src/commonlib/net_nfc_util_ndef_message.c | 795 +++++ src/commonlib/net_nfc_util_ndef_record.c | 387 +++ src/commonlib/net_nfc_util_openssl.c | 890 +++++ src/commonlib/net_nfc_util_sign_record.c | 377 +++ src/commonlib/nfc-common-lib.pc.in | 13 + src/manager/CMakeLists.txt | 78 + src/manager/include/net_nfc_app_util_private.h | 39 + src/manager/include/net_nfc_controller_private.h | 85 + src/manager/include/net_nfc_manager_dbus.h | 71 + src/manager/include/net_nfc_manager_util_private.h | 52 + .../include/net_nfc_server_context_private.h | 49 + .../include/net_nfc_server_dispatcher_private.h | 31 + src/manager/include/net_nfc_server_ipc_private.h | 58 + .../net_nfc_service_llcp_handover_private.h | 35 + src/manager/include/net_nfc_service_llcp_private.h | 203 ++ src/manager/include/net_nfc_service_private.h | 35 + src/manager/include/net_nfc_service_se_private.h | 52 + src/manager/include/net_nfc_service_tag_private.h | 27 + .../include/net_nfc_service_vconf_private.h | 27 + .../include/net_nfc_util_access_control_private.h | 29 + src/manager/net_nfc_app_util.c | 950 ++++++ src/manager/net_nfc_controller.c | 797 +++++ src/manager/net_nfc_manager.c | 378 +++ src/manager/net_nfc_manager_util.c | 112 + src/manager/net_nfc_server_context.c | 338 ++ src/manager/net_nfc_server_dispatcher.c | 1715 ++++++++++ src/manager/net_nfc_server_ipc.c | 825 +++++ src/manager/net_nfc_service.c | 520 +++ src/manager/net_nfc_service_llcp.c | 2549 +++++++++++++++ src/manager/net_nfc_service_llcp_handover.c | 1999 ++++++++++++ src/manager/net_nfc_service_se.c | 444 +++ src/manager/net_nfc_service_tag.c | 179 + src/manager/net_nfc_service_vconf.c | 182 ++ src/manager/net_nfc_util_access_control.c | 287 ++ src/manager/nfc-manager.service | 3 + src/manager/nfc-service.xml | 16 + src/manager/sounds/Operation_sdk.wav | Bin 0 -> 27644 bytes test_clinet_app/bt_paring/Makefile | 46 + test_clinet_app/bt_paring/bt_paring.c | 215 ++ test_clinet_app/ndef-tool/CMakeLists.txt | 51 + test_clinet_app/ndef-tool/ndef-tool-display.c | 686 ++++ test_clinet_app/ndef-tool/ndef-tool-sign.c | 69 + test_clinet_app/ndef-tool/ndef-tool-tag.c | 304 ++ test_clinet_app/ndef-tool/ndef-tool.c | 688 ++++ test_clinet_app/ndef-tool/ndef-tool.h | 58 + test_clinet_app/nfc_client/Makefile | 46 + test_clinet_app/nfc_client/main.c | 3445 ++++++++++++++++++++ test_clinet_app/nfc_client/nfc_api_test.h | 89 + 157 files changed, 44723 insertions(+) create mode 100644 AUTHORS create mode 100755 CMakeLists.txt create mode 100644 LICENSE.Flora create mode 100644 NOTICE create mode 100644 TC/_export_env.sh create mode 100755 TC/_export_target_env.sh create mode 100755 TC/build.sh create mode 100755 TC/clean.sh create mode 100644 TC/config.default create mode 100755 TC/execute.sh create mode 100644 TC/testcase/Makefile create mode 100644 TC/testcase/tslist create mode 100755 TC/testcase/utc_net_nfc_client_data.c create mode 100755 TC/testcase/utc_net_nfc_client_exchanger.c create mode 100755 TC/testcase/utc_net_nfc_client_internal_se.c create mode 100755 TC/testcase/utc_net_nfc_client_ndef_message.c create mode 100755 TC/testcase/utc_net_nfc_client_ndef_record.c create mode 100755 TC/testcase/utc_net_nfc_client_nfc.c create mode 100755 TC/testcase/utc_net_nfc_client_tag.c create mode 100755 TC/testcase/utc_net_nfc_client_tag_felica.c create mode 100755 TC/testcase/utc_net_nfc_client_tag_jewel.c create mode 100755 TC/testcase/utc_net_nfc_client_tag_mifare.c create mode 100755 TC/testcase/utc_net_nfc_client_target_info.c create mode 100755 TC/tet_scen create mode 100644 TC/tetbuild.cfg create mode 100644 TC/tetclean.cfg create mode 100644 TC/tetexec.cfg create mode 100755 debian/changelog create mode 100755 debian/compat create mode 100755 debian/control create mode 100755 debian/libnfc-common-lib-0.install.in create mode 100755 debian/libnfc-common-lib-0.postinst.in create mode 100755 debian/libnfc-common-lib-dbg.install.in create mode 100755 debian/libnfc-common-lib-dev.install.in create mode 100755 debian/libnfc-manager-0.init.in create mode 100755 debian/libnfc-manager-0.install.in create mode 100644 debian/libnfc-manager-0.postinst.in create mode 100755 debian/libnfc-manager-dbg.install.in create mode 100755 debian/libnfc-manager-dev.install.in create mode 100755 debian/rules create mode 100755 doxygen/createdoc.sh create mode 100755 doxygen/doxygen.conf create mode 100644 doxygen/slp_doxy.css create mode 100644 nfc-common-lib-devel.manifest create mode 100644 nfc-common-lib.manifest create mode 100644 nfc-manager-devel.manifest create mode 100644 nfc-manager.manifest create mode 100755 packaging/libnfc-manager-0.init.in create mode 100644 packaging/nfc-common-lib create mode 100644 packaging/nfc-manager create mode 100644 packaging/nfc-manager.service create mode 100644 packaging/nfc-manager.spec create mode 100644 src/clientlib/CMakeLists.txt create mode 100644 src/clientlib/include/net_nfc.h create mode 100755 src/clientlib/include/net_nfc_apdu.h create mode 100755 src/clientlib/include/net_nfc_client_dispatcher_private.h create mode 100755 src/clientlib/include/net_nfc_client_ipc_private.h create mode 100755 src/clientlib/include/net_nfc_client_nfc_private.h create mode 100755 src/clientlib/include/net_nfc_client_util_private.h create mode 100755 src/clientlib/include/net_nfc_data.h create mode 100755 src/clientlib/include/net_nfc_exchanger.h create mode 100755 src/clientlib/include/net_nfc_exchanger_private.h create mode 100755 src/clientlib/include/net_nfc_internal_se.h create mode 100755 src/clientlib/include/net_nfc_llcp.h create mode 100755 src/clientlib/include/net_nfc_ndef_message.h create mode 100755 src/clientlib/include/net_nfc_ndef_message_handover.h create mode 100755 src/clientlib/include/net_nfc_ndef_record.h create mode 100755 src/clientlib/include/net_nfc_sign_record.h create mode 100755 src/clientlib/include/net_nfc_tag.h create mode 100755 src/clientlib/include/net_nfc_tag_felica.h create mode 100755 src/clientlib/include/net_nfc_tag_jewel.h create mode 100755 src/clientlib/include/net_nfc_tag_mifare.h create mode 100755 src/clientlib/include/net_nfc_target_info.h create mode 100644 src/clientlib/include/net_nfc_test.h create mode 100755 src/clientlib/net_nfc_client_data.c create mode 100755 src/clientlib/net_nfc_client_dispatcher.c create mode 100755 src/clientlib/net_nfc_client_exchanger.c create mode 100755 src/clientlib/net_nfc_client_internal_se.c create mode 100755 src/clientlib/net_nfc_client_ipc.c create mode 100755 src/clientlib/net_nfc_client_llcp.c create mode 100644 src/clientlib/net_nfc_client_ndef_message.c create mode 100755 src/clientlib/net_nfc_client_ndef_message_handover.c create mode 100644 src/clientlib/net_nfc_client_ndef_record.c create mode 100755 src/clientlib/net_nfc_client_nfc.c create mode 100755 src/clientlib/net_nfc_client_sign_record.c create mode 100755 src/clientlib/net_nfc_client_tag.c create mode 100755 src/clientlib/net_nfc_client_tag_felica.c create mode 100755 src/clientlib/net_nfc_client_tag_jewel.c create mode 100755 src/clientlib/net_nfc_client_tag_mifare.c create mode 100755 src/clientlib/net_nfc_client_target_info.c create mode 100644 src/clientlib/net_nfc_client_test.c create mode 100755 src/clientlib/net_nfc_client_util.c create mode 100755 src/clientlib/nfc.pc.in create mode 100644 src/commonlib/CMakeLists.txt create mode 100755 src/commonlib/include/net_nfc_debug_private.h create mode 100644 src/commonlib/include/net_nfc_oem_controller.h create mode 100644 src/commonlib/include/net_nfc_typedef.h create mode 100755 src/commonlib/include/net_nfc_typedef_private.h create mode 100755 src/commonlib/include/net_nfc_util_defines.h create mode 100755 src/commonlib/include/net_nfc_util_handover.h create mode 100644 src/commonlib/include/net_nfc_util_ipc.h create mode 100755 src/commonlib/include/net_nfc_util_ndef_message.h create mode 100755 src/commonlib/include/net_nfc_util_ndef_record.h create mode 100644 src/commonlib/include/net_nfc_util_openssl_private.h create mode 100644 src/commonlib/include/net_nfc_util_private.h create mode 100755 src/commonlib/include/net_nfc_util_sign_record.h create mode 100644 src/commonlib/net_nfc_util.c create mode 100644 src/commonlib/net_nfc_util_handover.c create mode 100644 src/commonlib/net_nfc_util_ipc.c create mode 100755 src/commonlib/net_nfc_util_ndef_message.c create mode 100755 src/commonlib/net_nfc_util_ndef_record.c create mode 100755 src/commonlib/net_nfc_util_openssl.c create mode 100644 src/commonlib/net_nfc_util_sign_record.c create mode 100755 src/commonlib/nfc-common-lib.pc.in create mode 100644 src/manager/CMakeLists.txt create mode 100644 src/manager/include/net_nfc_app_util_private.h create mode 100644 src/manager/include/net_nfc_controller_private.h create mode 100644 src/manager/include/net_nfc_manager_dbus.h create mode 100644 src/manager/include/net_nfc_manager_util_private.h create mode 100644 src/manager/include/net_nfc_server_context_private.h create mode 100755 src/manager/include/net_nfc_server_dispatcher_private.h create mode 100755 src/manager/include/net_nfc_server_ipc_private.h create mode 100755 src/manager/include/net_nfc_service_llcp_handover_private.h create mode 100755 src/manager/include/net_nfc_service_llcp_private.h create mode 100644 src/manager/include/net_nfc_service_private.h create mode 100755 src/manager/include/net_nfc_service_se_private.h create mode 100755 src/manager/include/net_nfc_service_tag_private.h create mode 100755 src/manager/include/net_nfc_service_vconf_private.h create mode 100644 src/manager/include/net_nfc_util_access_control_private.h create mode 100644 src/manager/net_nfc_app_util.c create mode 100755 src/manager/net_nfc_controller.c create mode 100755 src/manager/net_nfc_manager.c create mode 100755 src/manager/net_nfc_manager_util.c create mode 100644 src/manager/net_nfc_server_context.c create mode 100644 src/manager/net_nfc_server_dispatcher.c create mode 100755 src/manager/net_nfc_server_ipc.c create mode 100644 src/manager/net_nfc_service.c create mode 100644 src/manager/net_nfc_service_llcp.c create mode 100644 src/manager/net_nfc_service_llcp_handover.c create mode 100755 src/manager/net_nfc_service_se.c create mode 100755 src/manager/net_nfc_service_tag.c create mode 100755 src/manager/net_nfc_service_vconf.c create mode 100644 src/manager/net_nfc_util_access_control.c create mode 100644 src/manager/nfc-manager.service create mode 100644 src/manager/nfc-service.xml create mode 100644 src/manager/sounds/Operation_sdk.wav create mode 100755 test_clinet_app/bt_paring/Makefile create mode 100755 test_clinet_app/bt_paring/bt_paring.c create mode 100644 test_clinet_app/ndef-tool/CMakeLists.txt create mode 100755 test_clinet_app/ndef-tool/ndef-tool-display.c create mode 100755 test_clinet_app/ndef-tool/ndef-tool-sign.c create mode 100755 test_clinet_app/ndef-tool/ndef-tool-tag.c create mode 100755 test_clinet_app/ndef-tool/ndef-tool.c create mode 100755 test_clinet_app/ndef-tool/ndef-tool.h create mode 100755 test_clinet_app/nfc_client/Makefile create mode 100755 test_clinet_app/nfc_client/main.c create mode 100755 test_clinet_app/nfc_client/nfc_api_test.h diff --git a/AUTHORS b/AUTHORS new file mode 100644 index 0000000..29d33cb --- /dev/null +++ b/AUTHORS @@ -0,0 +1,8 @@ +Jaejoon Seo +Lee Sangsoo +Junyong Sim +Wonkyu Kwon +Sungjae Lim +Sechang Sohn +Jinmin Chung +Jaekyun Lee diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100755 index 0000000..9d7f609 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,9 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) + +MESSAGE("build nfc-common-lib and nfc-manager") + +ADD_SUBDIRECTORY(src/commonlib) +ADD_SUBDIRECTORY(src/clientlib) +ADD_SUBDIRECTORY(src/manager) +ADD_SUBDIRECTORY(test_clinet_app/ndef-tool) + diff --git a/LICENSE.Flora b/LICENSE.Flora new file mode 100644 index 0000000..9c95663 --- /dev/null +++ b/LICENSE.Flora @@ -0,0 +1,206 @@ +Flora License + +Version 1.0, May, 2012 + +http://floralicense.org/license/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + +"License" shall mean the terms and conditions for use, reproduction, +and distribution as defined by Sections 1 through 9 of this document. + +"Licensor" shall mean the copyright owner or entity authorized by +the copyright owner that is granting the License. + +"Legal Entity" shall mean the union of the acting entity and +all other entities that control, are controlled by, or are +under common control with that entity. For the purposes of +this definition, "control" means (i) the power, direct or indirect, +to cause the direction or management of such entity, +whether by contract or otherwise, or (ii) ownership of fifty percent (50%) +or more of the outstanding shares, or (iii) beneficial ownership of +such entity. + +"You" (or "Your") shall mean an individual or Legal Entity +exercising permissions granted by this License. + +"Source" form shall mean the preferred form for making modifications, +including but not limited to software source code, documentation source, +and configuration files. + +"Object" form shall mean any form resulting from mechanical +transformation or translation of a Source form, including but +not limited to compiled object code, generated documentation, +and conversions to other media types. + +"Work" shall mean the work of authorship, whether in Source or Object form, +made available under the License, as indicated by a copyright notice +that is included in or attached to the work (an example is provided +in the Appendix below). + +"Derivative Works" shall mean any work, whether in Source or Object form, +that is based on (or derived from) the Work and for which the editorial +revisions, annotations, elaborations, or other modifications represent, +as a whole, an original work of authorship. For the purposes of this License, +Derivative Works shall not include works that remain separable from, +or merely link (or bind by name) to the interfaces of, the Work and +Derivative Works thereof. + +"Contribution" shall mean any work of authorship, including the original +version of the Work and any modifications or additions to that Work or +Derivative Works thereof, that is intentionally submitted to Licensor +for inclusion in the Work by the copyright owner or by an individual or +Legal Entity authorized to submit on behalf of the copyright owner. +For the purposes of this definition, "submitted" means any form of +electronic, verbal, or written communication sent to the Licensor or +its representatives, including but not limited to communication on +electronic mailing lists, source code control systems, and issue +tracking systems that are managed by, or on behalf of, the Licensor +for the purpose of discussing and improving the Work, but excluding +communication that is conspicuously marked or otherwise designated +in writing by the copyright owner as "Not a Contribution." + +"Contributor" shall mean Licensor and any individual or Legal Entity +on behalf of whom a Contribution has been received by Licensor and +subsequently incorporated within the Work. + +"Tizen Certified Platform" shall mean a software platform that complies +with the standards set forth in the Compatibility Definition Document +and passes the Compatibility Test Suite as defined from time to time +by the Tizen Technical Steering Group and certified by the Tizen +Association or its designated agent. + +2. Grant of Copyright License. Subject to the terms and conditions of +this License, each Contributor hereby grants to You a perpetual, +worldwide, non-exclusive, no-charge, royalty-free, irrevocable +copyright license to reproduce, prepare Derivative Works of, +publicly display, publicly perform, sublicense, and distribute the +Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. Subject to the terms and conditions of +this License, each Contributor hereby grants to You a perpetual, +worldwide, non-exclusive, no-charge, royalty-free, irrevocable +(except as stated in this section) patent license to make, have made, +use, offer to sell, sell, import, and otherwise transfer the Work +solely as incorporated into a Tizen Certified Platform, where such +license applies only to those patent claims licensable by such +Contributor that are necessarily infringed by their Contribution(s) +alone or by combination of their Contribution(s) with the Work solely +as incorporated into a Tizen Certified Platform to which such +Contribution(s) was submitted. If You institute patent litigation +against any entity (including a cross-claim or counterclaim +in a lawsuit) alleging that the Work or a Contribution incorporated +within the Work constitutes direct or contributory patent infringement, +then any patent licenses granted to You under this License for that +Work shall terminate as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the +Work or Derivative Works thereof pursuant to the copyright license +above, in any medium, with or without modifications, and in Source or +Object form, provided that You meet the following conditions: + + 1. You must give any other recipients of the Work or Derivative Works + a copy of this License; and + 2. You must cause any modified files to carry prominent notices stating + that You changed the files; and + 3. You must retain, in the Source form of any Derivative Works that + You distribute, all copyright, patent, trademark, and attribution + notices from the Source form of the Work, excluding those notices + that do not pertain to any part of the Derivative Works; and + 4. If the Work includes a "NOTICE" text file as part of its distribution, + then any Derivative Works that You distribute must include a readable + copy of the attribution notices contained within such NOTICE file, + excluding those notices that do not pertain to any part of + the Derivative Works, in at least one of the following places: + within a NOTICE text file distributed as part of the Derivative Works; + within the Source form or documentation, if provided along with the + Derivative Works; or, within a display generated by the Derivative Works, + if and wherever such third-party notices normally appear. + The contents of the NOTICE file are for informational purposes only + and do not modify the License. + +You may add Your own attribution notices within Derivative Works +that You distribute, alongside or as an addendum to the NOTICE text +from the Work, provided that such additional attribution notices +cannot be construed as modifying the License. You may add Your own +copyright statement to Your modifications and may provide additional or +different license terms and conditions for use, reproduction, or +distribution of Your modifications, or for any such Derivative Works +as a whole, provided Your use, reproduction, and distribution of +the Work otherwise complies with the conditions stated in this License. + +5. Submission of Contributions. Unless You explicitly state otherwise, +any Contribution intentionally submitted for inclusion in the Work +by You to the Licensor shall be under the terms and conditions of +this License, without any additional terms or conditions. +Notwithstanding the above, nothing herein shall supersede or modify +the terms of any separate license agreement you may have executed +with Licensor regarding such Contributions. + +6. Trademarks. This License does not grant permission to use the trade +names, trademarks, service marks, or product names of the Licensor, +except as required for reasonable and customary use in describing the +origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or +agreed to in writing, Licensor provides the Work (and each +Contributor provides its Contributions) on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +implied, including, without limitation, any warranties or conditions +of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A +PARTICULAR PURPOSE. You are solely responsible for determining the +appropriateness of using or redistributing the Work and assume any +risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, +whether in tort (including negligence), contract, or otherwise, +unless required by applicable law (such as deliberate and grossly +negligent acts) or agreed to in writing, shall any Contributor be +liable to You for damages, including any direct, indirect, special, +incidental, or consequential damages of any character arising as a +result of this License or out of the use or inability to use the +Work (including but not limited to damages for loss of goodwill, +work stoppage, computer failure or malfunction, or any and all +other commercial damages or losses), even if such Contributor +has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. While redistributing +the Work or Derivative Works thereof, You may choose to offer, +and charge a fee for, acceptance of support, warranty, indemnity, +or other liability obligations and/or rights consistent with this +License. However, in accepting such obligations, You may act only +on Your own behalf and on Your sole responsibility, not on behalf +of any other Contributor, and only if You agree to indemnify, +defend, and hold each Contributor harmless for any liability +incurred by, or claims asserted against, such Contributor by reason +of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS + +APPENDIX: How to apply the Flora License to your work + +To apply the Flora License to your work, attach the following +boilerplate notice, with the fields enclosed by brackets "[]" +replaced with your own identifying information. (Don't include +the brackets!) The text should be enclosed in the appropriate +comment syntax for the file format. We also recommend that a +file or class name and description of purpose be included on the +same "printed page" as the copyright notice for easier +identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Flora License, Version 1.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://floralicense.org/license/ + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + diff --git a/NOTICE b/NOTICE new file mode 100644 index 0000000..f788797 --- /dev/null +++ b/NOTICE @@ -0,0 +1,3 @@ +Copyright (c) Samsung Electronics Co., Ltd. All rights reserved. +Except as noted, this software is licensed under Flora License, Version 1. +Please, see the LICENSE.Flora file for Flora License terms and conditions diff --git a/TC/_export_env.sh b/TC/_export_env.sh new file mode 100644 index 0000000..bb07f7e --- /dev/null +++ b/TC/_export_env.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +. ./config +export TET_INSTALL_PATH=$TET_INSTALL_HOST_PATH +export TET_TARGET_PATH=$TET_INSTALL_PATH/tetware-target # tetware target path +export PATH=$TET_TARGET_PATH/bin:$PATH +export LD_LIBRARY_PATH=$TET_TARGET_PATH/lib/tet3:$LD_LIBRARY_PATH +export TET_ROOT=$TET_TARGET_PATH diff --git a/TC/_export_target_env.sh b/TC/_export_target_env.sh new file mode 100755 index 0000000..5ddaa53 --- /dev/null +++ b/TC/_export_target_env.sh @@ -0,0 +1,7 @@ +#!/bin/sh +. ./config +export TET_INSTALL_PATH=$TET_INSTALL_TARGET_PATH # path to path +export TET_TARGET_PATH=$TET_INSTALL_PATH/tetware-target +export PATH=$TET_TARGET_PATH/bin:$PATH +export LD_LIBRARY_PATH=$TET_TARGET_PATH/lib/tet3:$LD_LIBRARY_PATH +export TET_ROOT=$TET_TARGET_PATH diff --git a/TC/build.sh b/TC/build.sh new file mode 100755 index 0000000..72aad6c --- /dev/null +++ b/TC/build.sh @@ -0,0 +1,16 @@ +#!/bin/sh + +. ./_export_env.sh # setting environment variables + +export TET_SUITE_ROOT=`pwd` +FILE_NAME_EXTENSION=`date +%s` + +RESULT_DIR=results +HTML_RESULT=$RESULT_DIR/build-tar-result-$FILE_NAME_EXTENSION.html +JOURNAL_RESULT=$RESULT_DIR/build-tar-result-$FILE_NAME_EXTENSION.journal + +mkdir -p $RESULT_DIR + +tcc -c -p ./ +tcc -b -j $JOURNAL_RESULT -p ./ +grw -c 7 -f chtml -o $HTML_RESULT $JOURNAL_RESULT diff --git a/TC/clean.sh b/TC/clean.sh new file mode 100755 index 0000000..29743e0 --- /dev/null +++ b/TC/clean.sh @@ -0,0 +1,11 @@ +#!/bin/sh + +. ./_export_env.sh # setting environment variables + +export TET_SUITE_ROOT=`pwd` +RESULT_DIR=results + +tcc -c -p ./ # executing tcc, with clean option (-c) +rm -r $RESULT_DIR +rm -r tet_tmp_dir +rm testcase/tet_captured diff --git a/TC/config.default b/TC/config.default new file mode 100644 index 0000000..12ac1e2 --- /dev/null +++ b/TC/config.default @@ -0,0 +1,3 @@ +CAPI_PROJECT_ROOT=/home/abyss/capi +TET_INSTALL_HOST_PATH=/home/abyss/TETware +TET_INSTALL_TARGET_PATH=/mnt/nfs/TETware diff --git a/TC/execute.sh b/TC/execute.sh new file mode 100755 index 0000000..a4f6095 --- /dev/null +++ b/TC/execute.sh @@ -0,0 +1,15 @@ +#!/bin/sh + +. ./_export_target_env.sh # setting environment variables + +export TET_SUITE_ROOT=`pwd` +FILE_NAME_EXTENSION=`date +%s` + +RESULT_DIR=results +HTML_RESULT=$RESULT_DIR/exec-tar-result-$FILE_NAME_EXTENSION.html +JOURNAL_RESULT=$RESULT_DIR/exec-tar-result-$FILE_NAME_EXTENSION.journal + +mkdir -p $RESULT_DIR + +tcc -e -j $JOURNAL_RESULT -p ./ +grw -c 3 -f chtml -o $HTML_RESULT $JOURNAL_RESULT diff --git a/TC/testcase/Makefile b/TC/testcase/Makefile new file mode 100644 index 0000000..6c0560f --- /dev/null +++ b/TC/testcase/Makefile @@ -0,0 +1,35 @@ +CC ?= gcc + +C_FILES = $(shell ls *.c) + +ifeq ($(ARCH),target) + PKG_CONFIG_PATH=/usr/lib/pkgconfig + export PKG_CONFIG_PATH + CC=arm-linux-gcc -Wall + CXX=arm-linux-g++ -Wall +else + PKG_CONFIG_PATH=/usr/lib/pkgconfig + export PKG_CONFIG_PATH + CC=gcc -Wall + CXX=gcc -Wall +endif + + +LDFLAGS = `pkg-config --libs nfc nfc-common-lib glib-2.0` +LDFLAGS += $(TET_ROOT)/lib/tet3/tcm_s.o +LDFLAGS += -L$(TET_ROOT)/lib/tet3 -ltcm_s +LDFLAGS += -L$(TET_ROOT)/lib/tet3 -lapi_s + +CFLAGS = -I. `pkg-config --cflags nfc nfc-common-lib glib-2.0` +CFLAGS += -I$(TET_ROOT)/inc/tet3 +CFLAGS += -Wall + +TCS := $(shell ls -1 *.c | cut -d. -f1) + +all: $(TCS) + +%: %.c + $(CC) -o $@ $< $(CFLAGS) $(LDFLAGS) + +clean: + rm -f $(TCS) diff --git a/TC/testcase/tslist b/TC/testcase/tslist new file mode 100644 index 0000000..65c1406 --- /dev/null +++ b/TC/testcase/tslist @@ -0,0 +1,12 @@ +/testcase/utc_net_nfc_client_data +/testcase/utc_net_nfc_client_exchanger +/testcase/utc_net_nfc_client_internal_se +/testcase/utc_net_nfc_client_ndef_message +/testcase/utc_net_nfc_client_ndef_record +/testcase/utc_net_nfc_client_nfc +/testcase/utc_net_nfc_client_tag +/testcase/utc_net_nfc_client_tag_felica +/testcase/utc_net_nfc_client_tag_jewel +/testcase/utc_net_nfc_client_tag_mifare +/testcase/utc_net_nfc_client_target_info + diff --git a/TC/testcase/utc_net_nfc_client_data.c b/TC/testcase/utc_net_nfc_client_data.c new file mode 100755 index 0000000..4dbe788 --- /dev/null +++ b/TC/testcase/utc_net_nfc_client_data.c @@ -0,0 +1,297 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include +#include + +#include +#include +#include +#include + + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; +static void startup(void); +static void cleanup(void); + +void (*tet_startup)(void) = startup; +void (*tet_cleanup)(void) = cleanup; + +static void utc_net_nfc_create_data_only_p(void); +static void utc_net_nfc_create_data_only_n(void); +static void utc_net_nfc_create_data_p(void); +static void utc_net_nfc_create_data_n(void); +static void utc_net_nfc_get_data_p(void); +static void utc_net_nfc_get_data_n(void); +static void utc_net_nfc_set_data_p(void); +static void utc_net_nfc_set_data_n(void); +static void utc_net_nfc_get_data_length_p(void); +static void utc_net_nfc_get_data_length_n(void); +static void utc_net_nfc_get_data_buffer_p(void); +static void utc_net_nfc_get_data_buffer_n(void); +static void utc_net_nfc_free_data_p(void); +static void utc_net_nfc_free_data_n(void); + + + + +struct tet_testlist tet_testlist[] = { + { utc_net_nfc_create_data_only_p , POSITIVE_TC_IDX }, + { utc_net_nfc_create_data_only_n , NEGATIVE_TC_IDX }, + { utc_net_nfc_create_data_p, POSITIVE_TC_IDX }, + { utc_net_nfc_create_data_n , NEGATIVE_TC_IDX}, + { utc_net_nfc_get_data_p, 1}, + { utc_net_nfc_get_data_n, 2 }, + { utc_net_nfc_set_data_p, 1}, + { utc_net_nfc_set_data_n, 2}, + { utc_net_nfc_get_data_length_p, 1}, + { utc_net_nfc_get_data_length_n, 2}, + { utc_net_nfc_get_data_buffer_p, 1}, + { utc_net_nfc_get_data_buffer_n, 2}, + { utc_net_nfc_free_data_p, 1}, + { utc_net_nfc_free_data_n, 2}, + { NULL, 0 }, +}; + +//this method is called only once in start +static void startup(void) +{ + /* start of TC */ +} + +static void cleanup(void) +{ + /* end of TC */ +} +static void utc_net_nfc_create_data_only_p(void) +{ + int ret=0; + data_h* config = NULL; + + config = calloc(1 , sizeof(data_h)); + + ret = net_nfc_create_data_only(config); + + dts_check_eq(__func__, ret, NET_NFC_OK, "net_nfc_create_data_only is failed"); +} + +static void utc_net_nfc_create_data_only_n(void) +{ + int ret=0; + + ret = net_nfc_create_data_only(NULL); + + dts_check_ne(__func__, ret, NET_NFC_OK, "net_nfc_create_data not allow null"); +} + +static void utc_net_nfc_create_data_p(void) +{ + int ret=0; + data_h* config = NULL; + uint8_t* sec_param = NULL; + + config = calloc(1, sizeof(data_h)); + sec_param = calloc(1, sizeof(uint8_t)); + memcpy(sec_param , "U" , sizeof(uint8_t)); + + ret = net_nfc_create_data(config , sec_param/*"U"*/ , 1); + + free(config); + + dts_check_eq(__func__, ret, NET_NFC_OK, "net_nfc_create_data is failed"); +} + +static void utc_net_nfc_create_data_n(void) +{ + int ret=0; + + ret = net_nfc_create_data(NULL , NULL , 0); + + dts_check_ne(__func__, ret, NET_NFC_OK, "net_nfc_create_data_only not allow null"); +} + +static void utc_net_nfc_get_data_p(void) +{ + int ret=0; + data_h data = NULL; + uint8_t* byte = NULL; + uint32_t length; + + byte = calloc(10, sizeof(uint8_t)); + + data = calloc(1, sizeof(data_s)); + + ret = net_nfc_get_data(data , &byte , &length); + + free(data); + free(byte); + + dts_check_eq(__func__, ret, NET_NFC_OK, "net_nfc_get_data is failed"); +} + +static void utc_net_nfc_get_data_n(void) +{ + int ret=0; + + ret = net_nfc_get_data(NULL , NULL , NULL); + + dts_check_ne(__func__, ret, NET_NFC_OK, "net_nfc_get_data not allow null"); +} + +static void utc_net_nfc_set_data_p(void) +{ + int ret=0; + data_h data = NULL; + uint8_t main_record_name[] = "samsung.com:allshare"; + + data = calloc(1, sizeof(data_h)); + + ret = net_nfc_set_data (data, main_record_name, 20); + + dts_check_eq(__func__, ret, NET_NFC_OK, "net_nfc_set_data is failed"); +} + +static void utc_net_nfc_set_data_n(void) +{ + int ret=0; + + ret = net_nfc_set_data(NULL , NULL , 0); + + dts_check_ne(__func__, ret, NET_NFC_OK, "net_nfc_set_data not allow null"); +} + +static void utc_net_nfc_get_data_length_p(void) +{ + int ret=0; + int length = 0; + data_s* data = NULL; + //uint8_t temp_data[] = "www.samsung.com"; + uint32_t temp_size = 16; + + data = calloc(1, sizeof(data_s)); + + //data->buffer = temp_data; + data->length = temp_size; + + length = net_nfc_get_data_length ((data_h)data); + + if(length > 0) + { + ret = NET_NFC_OK; + } + else + { + ret = NET_NFC_UNKNOWN_ERROR; + } + + free(data); + + dts_check_eq(__func__, ret, NET_NFC_OK, "net_nfc_get_data_length is failed"); +} + +static void utc_net_nfc_get_data_length_n(void) +{ + int ret=0; + int length = 0; + + length = net_nfc_get_data_length(NULL); + + if(length > 0) + { + ret = NET_NFC_OK; + } + else + { + ret = NET_NFC_UNKNOWN_ERROR; + } + + dts_check_ne(__func__, ret, NET_NFC_OK, "net_nfc_get_data_length not allow null"); +} + +static void utc_net_nfc_get_data_buffer_p(void) +{ + int ret=0; + uint8_t* buffer = NULL; + data_s* data = NULL; + uint8_t temp_data[] = "www.samsung.com"; + int temp_size = 16; + + data = calloc(1, sizeof(data_s)); + + data->buffer = temp_data; + data->length = temp_size; + + buffer = net_nfc_get_data_buffer ((data_h)data); + + if(buffer != NULL) + { + ret = NET_NFC_OK; + } + else + { + ret = NET_NFC_UNKNOWN_ERROR; + } + + free(data); + + dts_check_eq(__func__, ret, NET_NFC_OK, "net_nfc_get_data_buffer is failed"); +} + +static void utc_net_nfc_get_data_buffer_n(void) +{ + int ret=0; + uint8_t* buffer = NULL; + + buffer = net_nfc_get_data_buffer(NULL); + + if(buffer != NULL) + { + ret = NET_NFC_OK; + } + else + { + ret = NET_NFC_UNKNOWN_ERROR; + } + + dts_check_ne(__func__, ret, NET_NFC_OK, "net_nfc_get_data_buffer not allow null"); +} + +static void utc_net_nfc_free_data_p(void) +{ + int ret=0; + data_h data = NULL; + //uint8_t temp_data[] = "www.samsung.com"; + //uint32_t temp_size = 16; + + data = calloc(1, sizeof(data_h)); + + ret = net_nfc_free_data (data); + + dts_check_eq(__func__, ret, NET_NFC_OK, "net_nfc_free_data is failed"); +} + +static void utc_net_nfc_free_data_n(void) +{ + int ret=0; + + ret = net_nfc_free_data(NULL); + + dts_check_ne(__func__, ret, NET_NFC_OK, "net_nfc_free_data not allow null"); +} diff --git a/TC/testcase/utc_net_nfc_client_exchanger.c b/TC/testcase/utc_net_nfc_client_exchanger.c new file mode 100755 index 0000000..4145834 --- /dev/null +++ b/TC/testcase/utc_net_nfc_client_exchanger.c @@ -0,0 +1,130 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include +#include +#include + +#include +#include +#include +#include + + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; +static void startup(void); +static void cleanup(void); + +void (*tet_startup)(void) = startup; +void (*tet_cleanup)(void) = cleanup; + +static void utc_net_nfc_create_exchanger_data_p(void); +static void utc_net_nfc_create_exchanger_data_n(void); +static void utc_net_nfc_free_exchanger_data_p(void); +static void utc_net_nfc_free_exchanger_data_n(void); +static void utc_net_nfc_set_exchanger_cb_p(void); +static void utc_net_nfc_set_exchanger_cb_n(void); +static void utc_net_nfc_unset_exchanger_cb_p(void); +static void utc_net_nfc_unset_exchanger_cb_n(void); + + + + + +struct tet_testlist tet_testlist[] = { + { utc_net_nfc_create_exchanger_data_p , POSITIVE_TC_IDX}, + { utc_net_nfc_create_exchanger_data_n , NEGATIVE_TC_IDX}, + { utc_net_nfc_free_exchanger_data_p, 1}, + { utc_net_nfc_free_exchanger_data_n, 2 }, + { utc_net_nfc_set_exchanger_cb_p, 1}, + { utc_net_nfc_set_exchanger_cb_n, 2}, + { utc_net_nfc_unset_exchanger_cb_p, 1}, + { utc_net_nfc_unset_exchanger_cb_n, 2}, + { NULL, 0 }, +}; + +//this method is called only once in start +static void startup(void) +{ + /* start of TC */ +} + +static void cleanup(void) +{ + /* end of TC */ +} +static void utc_net_nfc_create_exchanger_data_p(void) +{ + int ret=0; + net_nfc_exchanger_data_h* ex_data = NULL; + char temp[] = "http://www.samsung.com"; + data_s payload; + + payload.length= 23; + + payload.buffer = calloc(1 , 23*sizeof(char)); + + memcpy(payload.buffer , temp , sizeof(temp)); + + ex_data = calloc(1 , sizeof(ex_data)); + + ret = net_nfc_create_exchanger_data(ex_data , (data_h)&payload); + + dts_check_eq(__func__, ret, NET_NFC_OK, "net_nfc_create_exchanger_url_type_data is failed"); +} + +static void utc_net_nfc_create_exchanger_data_n(void) +{ + int ret=0; + + ret = net_nfc_create_exchanger_data(NULL , NULL); + + dts_check_ne(__func__, ret, NET_NFC_OK, "net_nfc_create_exchanger_url_type_data not allow null"); +} + +static void utc_net_nfc_free_exchanger_data_p(void) +{ + int ret=0; + net_nfc_exchanger_data_h ex_data = NULL; + char temp[] = "http://www.samsung.com"; + data_s payload; + + payload.length= 23; + + payload.buffer = calloc(1 , 23*sizeof(char)); + + memcpy(payload.buffer , temp , sizeof(temp)); + + net_nfc_create_exchanger_data(&ex_data , (data_h)&payload ); + + ret = net_nfc_free_exchanger_data(ex_data); + + dts_check_eq(__func__, ret, NET_NFC_OK, "utc_net_nfc_free_exchanger_data_p is failed"); +} + +static void utc_net_nfc_free_exchanger_data_n(void) +{ + int ret=0; + + ret = net_nfc_free_exchanger_data(NULL); + + dts_check_ne(__func__, ret, NET_NFC_OK, "utc_net_nfc_free_exchanger_data_p not allow null"); +} + diff --git a/TC/testcase/utc_net_nfc_client_internal_se.c b/TC/testcase/utc_net_nfc_client_internal_se.c new file mode 100755 index 0000000..736d497 --- /dev/null +++ b/TC/testcase/utc_net_nfc_client_internal_se.c @@ -0,0 +1,169 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include + +#include "net_nfc_tag.h" +#include "net_nfc_typedef_private.h" +#include "net_nfc_internal_se.h" +#include "net_nfc_util_private.h" +#include "net_nfc_data.h" + + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; +static void startup(void); +static void cleanup(void); + +void (*tet_startup)(void) = startup; +void (*tet_cleanup)(void) = cleanup; + +static void utc_net_nfc_set_secure_element_type_p(void); +static void utc_net_nfc_set_secure_element_type_n(void); +static void utc_net_nfc_get_secure_element_type_p(void); +static void utc_net_nfc_get_secure_element_type_n(void); +static void utc_net_nfc_open_internal_secure_element_p(void); +static void utc_net_nfc_open_internal_secure_element_n(void); +static void utc_net_nfc_close_internal_secure_element_p(void); +static void utc_net_nfc_close_internal_secure_element_n(void); +static void utc_net_nfc_send_apdu_p(void); +static void utc_net_nfc_send_apdu_n(void); + + + +struct tet_testlist tet_testlist[] = { + { utc_net_nfc_set_secure_element_type_p , POSITIVE_TC_IDX }, + { utc_net_nfc_set_secure_element_type_n , NEGATIVE_TC_IDX }, + { utc_net_nfc_get_secure_element_type_p, POSITIVE_TC_IDX }, + { utc_net_nfc_get_secure_element_type_n , NEGATIVE_TC_IDX}, + { utc_net_nfc_open_internal_secure_element_p, 1}, + { utc_net_nfc_open_internal_secure_element_n, 2 }, + { utc_net_nfc_close_internal_secure_element_p, 1}, + { utc_net_nfc_close_internal_secure_element_n, 2}, + { utc_net_nfc_send_apdu_p, 1}, + { utc_net_nfc_send_apdu_n, 2}, + { NULL, 0 }, +}; + +//this method is called only once in start +static void startup(void) +{ + /* start of TC */ +} + +static void cleanup(void) +{ + /* end of TC */ +} +static void utc_net_nfc_set_secure_element_type_p(void) +{ + int ret=0; + + ret = net_nfc_set_secure_element_type(NET_NFC_SE_TYPE_UICC, NULL); + + dts_pass(__func__, "PASS"); +} + +static void utc_net_nfc_set_secure_element_type_n(void) +{ + int ret=0; + + ret = net_nfc_set_secure_element_type( -1 , NULL); + + dts_pass(__func__, "PASS"); +} + +static void utc_net_nfc_get_secure_element_type_p(void) +{ + int ret=0; + + ret = net_nfc_get_secure_element_type(NULL); + + dts_pass(__func__, "PASS"); +} + +static void utc_net_nfc_get_secure_element_type_n(void) +{ + int ret=0; + + ret = net_nfc_get_secure_element_type(NULL); + + dts_pass(__func__, "PASS"); +} + +static void utc_net_nfc_open_internal_secure_element_p(void) +{ + net_nfc_open_internal_secure_element(NET_NFC_SE_TYPE_ESE, NULL); + + dts_pass(__func__, "PASS"); +} + +static void utc_net_nfc_open_internal_secure_element_n(void) +{ + int ret=0; + + ret = net_nfc_open_internal_secure_element(NET_NFC_SE_TYPE_ESE, NULL); + + dts_pass(__func__, "PASS"); +} + +static void utc_net_nfc_close_internal_secure_element_p(void) +{ + int ret=0; + void * trans_data = NULL; + + ret = net_nfc_close_internal_secure_element ((net_nfc_target_handle_h)trans_data, NULL); + + dts_pass(__func__, "PASS"); +} + +static void utc_net_nfc_close_internal_secure_element_n(void) +{ + int ret=0; + + ret = net_nfc_close_internal_secure_element(NULL , NULL); + + dts_pass(__func__, "PASS"); +} + +static void utc_net_nfc_send_apdu_p(void) +{ + int ret ; + net_nfc_target_handle_h data = NULL; + data_h apdu = NULL; + uint8_t apdu_cmd[4] = {0x00, 0xA4, 0x00, 0x0C} ; // CLA 0-> use default channel and no secure message. 0xA4 -> select instruction + + //data->connection_id = 1; + //data->connection_type = NET_NFC_SE_CONNECTION; + + net_nfc_create_data(&apdu, apdu_cmd, 4); + + ret = net_nfc_send_apdu((net_nfc_target_handle_h)(data), apdu, data); + + dts_pass(__func__, "PASS"); +} + +static void utc_net_nfc_send_apdu_n(void) +{ + int ret ; + + ret = net_nfc_send_apdu(NULL , NULL , NULL ); + + dts_pass(__func__, "PASS"); +} diff --git a/TC/testcase/utc_net_nfc_client_ndef_message.c b/TC/testcase/utc_net_nfc_client_ndef_message.c new file mode 100755 index 0000000..6b5b8f1 --- /dev/null +++ b/TC/testcase/utc_net_nfc_client_ndef_message.c @@ -0,0 +1,258 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include +#include + +#include "net_nfc_ndef_message.h" +#include "net_nfc_util_private.h" +#include "net_nfc.h" // to use net_nfc_data + + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; +static void startup(void); +static void cleanup(void); + +void (*tet_startup)(void) = startup; +void (*tet_cleanup)(void) = cleanup; + +static void utc_net_nfc_create_ndef_message_p(void); +static void utc_net_nfc_create_ndef_message_n(void); +static void utc_net_nfc_create_rawdata_from_ndef_message_p(void); +static void utc_net_nfc_create_rawdata_from_ndef_message_n(void); +static void utc_net_nfc_create_ndef_message_from_rawdata_p(void); +static void utc_net_nfc_create_ndef_message_from_rawdata_n(void); +static void utc_net_nfc_get_ndef_message_byte_length_p(void); +static void utc_net_nfc_get_ndef_message_byte_length_n(void); +static void utc_net_nfc_append_record_to_ndef_message_p(void); +static void utc_net_nfc_append_record_to_ndef_message_n(void); +static void utc_net_nfc_free_ndef_message_p(void); +static void utc_net_nfc_free_ndef_message_n(void); +static void utc_net_nfc_get_ndef_message_record_count_p(void); +static void utc_net_nfc_get_ndef_message_record_count_n(void); + + + + +struct tet_testlist tet_testlist[] = { + { utc_net_nfc_create_ndef_message_p , POSITIVE_TC_IDX }, + { utc_net_nfc_create_ndef_message_n , NEGATIVE_TC_IDX }, + { utc_net_nfc_create_rawdata_from_ndef_message_p, POSITIVE_TC_IDX }, + { utc_net_nfc_create_rawdata_from_ndef_message_n , NEGATIVE_TC_IDX}, + { utc_net_nfc_create_ndef_message_from_rawdata_p, 1}, + { utc_net_nfc_create_ndef_message_from_rawdata_n, 2 }, + { utc_net_nfc_get_ndef_message_byte_length_p, 1}, + { utc_net_nfc_get_ndef_message_byte_length_n, 2}, + { utc_net_nfc_append_record_to_ndef_message_p, 1}, + { utc_net_nfc_append_record_to_ndef_message_n, 2}, + { utc_net_nfc_free_ndef_message_p, 1}, + { utc_net_nfc_free_ndef_message_n, 2}, + { utc_net_nfc_get_ndef_message_record_count_p, 1}, + { utc_net_nfc_get_ndef_message_record_count_n, 2}, + { NULL, 0 }, +}; + +//this method is called only once in start +static void startup(void) +{ + /* start of TC */ +} + +static void cleanup(void) +{ + /* end of TC */ +} +static void utc_net_nfc_create_ndef_message_p(void) +{ + int ret ; + ndef_message_h message; + + ret = net_nfc_create_ndef_message(&message); + net_nfc_free_ndef_message(message); + + dts_check_eq(__func__, ret, NET_NFC_OK, "net_nfc_create_ndef_message is failed"); +} + +static void utc_net_nfc_create_ndef_message_n(void) +{ + int ret=0; + + ret = net_nfc_create_ndef_message( NULL); + + dts_check_ne(__func__, ret, NET_NFC_OK, "net_nfc_create_ndef_message not allow null"); +} + +static void utc_net_nfc_create_rawdata_from_ndef_message_p(void) +{ + int ret ; + char url[] = "samsung.com"; + ndef_record_h record = NULL; + ndef_message_h msg = NULL; + data_h rawdata = NULL; + + net_nfc_create_uri_type_record(&record, url, NET_NFC_SCHEMA_HTTPS_WWW); + + net_nfc_create_ndef_message(&msg); + + net_nfc_append_record_to_ndef_message(msg, record); + + ret = net_nfc_create_rawdata_from_ndef_message (msg, &rawdata); + + dts_check_eq(__func__, ret, NET_NFC_OK, "net_nfc_create_rawdata_from_ndef_message is failed"); +} + +static void utc_net_nfc_create_rawdata_from_ndef_message_n(void) +{ + int ret ; + + ret = net_nfc_create_rawdata_from_ndef_message (NULL, NULL); + + dts_check_ne(__func__, ret, NET_NFC_OK, "net_nfc_create_rawdata_from_ndef_message not allow null"); +} + +static void utc_net_nfc_create_ndef_message_from_rawdata_p(void) +{ + int ret ; + uint8_t url[] = "samsung.com"; + ndef_message_s* msg = NULL; + data_s* rawdata = NULL; + + rawdata = calloc(1, sizeof(data_s)); + msg = calloc(1, sizeof(ndef_message_s)); + + rawdata->buffer = url; + rawdata->length = 11; + + ret = net_nfc_create_ndef_message_from_rawdata ((ndef_message_h*)msg, (data_h)rawdata); + + net_nfc_free_ndef_message((ndef_message_h)msg); + + dts_check_eq(__func__, ret, NET_NFC_OK, "net_nfc_create_ndef_message_from_rawdata is failed"); +} + +static void utc_net_nfc_create_ndef_message_from_rawdata_n(void) +{ + int ret ; + + ret = net_nfc_create_ndef_message_from_rawdata (NULL, NULL); + + dts_check_ne(__func__, ret, NET_NFC_OK,"net_nfc_create_ndef_message_from_rawdata not allow null"); +} + +static void utc_net_nfc_get_ndef_message_byte_length_p(void) +{ + int ret ; + char url[] = "samsung.com"; + ndef_record_h record = NULL; + ndef_message_h msg = NULL; + int length = 0; + + net_nfc_create_uri_type_record(&record, url, NET_NFC_SCHEMA_HTTPS_WWW); + + net_nfc_create_ndef_message(&msg); + + net_nfc_append_record_to_ndef_message(msg, record); + + ret = net_nfc_get_ndef_message_byte_length( msg , &length); + + dts_check_eq(__func__, ret, NET_NFC_OK, "net_nfc_get_ndef_message_byte_length is failed"); +} + +static void utc_net_nfc_get_ndef_message_byte_length_n(void) +{ + int ret ; + + ret = net_nfc_get_ndef_message_byte_length (NULL, NULL); + + dts_check_ne(__func__, ret, NET_NFC_OK,"net_nfc_get_ndef_message_byte_length not allow null"); +} + +static void utc_net_nfc_append_record_to_ndef_message_p(void) +{ + int ret ; + char url[] = "samsung.com"; + ndef_record_h record = NULL; + ndef_message_h msg = NULL; + + net_nfc_create_uri_type_record(&record, url, NET_NFC_SCHEMA_HTTPS_WWW); + + net_nfc_create_ndef_message(&msg); + + ret = net_nfc_append_record_to_ndef_message(msg, record); + + dts_check_eq(__func__, ret, NET_NFC_OK, "net_nfc_append_record_to_ndef_message is failed"); +} + +static void utc_net_nfc_append_record_to_ndef_message_n(void) +{ + int ret ; + + ret = net_nfc_append_record_to_ndef_message (NULL, NULL); + + dts_check_ne(__func__, ret, NET_NFC_OK,"net_nfc_append_record_to_ndef_message not allow null"); +} + +static void utc_net_nfc_free_ndef_message_p(void) +{ + int ret ; + ndef_message_h message; + + net_nfc_create_ndef_message(&message); + ret = net_nfc_free_ndef_message(message); + + dts_check_eq(__func__, ret, NET_NFC_OK, "utc_net_nfc_free_ndef_message_n is failed"); +} + +static void utc_net_nfc_free_ndef_message_n(void) +{ + int ret=0; + + ret = net_nfc_free_ndef_message( NULL); + + dts_check_ne(__func__, ret, NET_NFC_OK, "utc_net_nfc_free_ndef_message_n not allow null"); +} + +static void utc_net_nfc_get_ndef_message_record_count_p(void) +{ + int ret ; + char url[] = "samsung.com"; + ndef_record_h record = NULL; + ndef_message_h msg = NULL; + int count = 0; + + net_nfc_create_uri_type_record(&record, url, NET_NFC_SCHEMA_HTTPS_WWW); + + net_nfc_create_ndef_message(&msg); + + net_nfc_append_record_to_ndef_message(msg, record); + + ret = net_nfc_get_ndef_message_record_count( msg , &count ); + + dts_check_eq(__func__, ret, NET_NFC_OK, "net_nfc_get_ndef_message_record_count is failed"); +} + +static void utc_net_nfc_get_ndef_message_record_count_n(void) +{ + int ret=0; + + ret = net_nfc_get_ndef_message_record_count( NULL , NULL); + + dts_check_ne(__func__, ret, NET_NFC_OK, "net_nfc_get_ndef_message_record_count not allow null"); +} diff --git a/TC/testcase/utc_net_nfc_client_ndef_record.c b/TC/testcase/utc_net_nfc_client_ndef_record.c new file mode 100755 index 0000000..0c0b03b --- /dev/null +++ b/TC/testcase/utc_net_nfc_client_ndef_record.c @@ -0,0 +1,571 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include "net_nfc_ndef_record.h" +#include "net_nfc_ndef_message.h" +#include "net_nfc_util_private.h" +#include "net_nfc_data.h" +//#include "net_nfc_debug_private.h" +#include "net_nfc_util_private.h" + + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; +static void startup(void); +static void cleanup(void); + +void (*tet_startup)(void) = startup; +void (*tet_cleanup)(void) = cleanup; + +static void utc_net_nfc_create_record_p(void); +static void utc_net_nfc_create_record_n(void); +static void utc_net_nfc_create_text_type_record_p(void); +static void utc_net_nfc_create_text_type_record_n(void); +static void utc_net_nfc_create_uri_type_record_p(void); +static void utc_net_nfc_create_uri_type_record_n(void); +static void utc_net_nfc_free_record_p(void); +static void utc_net_nfc_free_record_n(void); +static void utc_net_nfc_get_record_payload_p(void); +static void utc_net_nfc_get_record_payload_n(void); +static void utc_net_nfc_get_record_type_p(void); +static void utc_net_nfc_get_record_type_n(void); +static void utc_net_nfc_set_record_id_p(void); +static void utc_net_nfc_set_record_id_n(void); +static void utc_net_nfc_get_record_id_p(void); +static void utc_net_nfc_get_record_id_n(void); +static void utc_net_nfc_get_record_tnf_p(void); +static void utc_net_nfc_get_record_tnf_n(void); +static void utc_net_nfc_get_record_flags_p(void); +static void utc_net_nfc_get_record_flags_n(void); +static void utc_net_nfc_get_record_mb_p(void); +static void utc_net_nfc_get_record_mb_n(void); +static void utc_net_nfc_get_record_me_p(void); +static void utc_net_nfc_get_record_me_n(void); +static void utc_net_nfc_get_record_cf_p(void); +static void utc_net_nfc_get_record_cf_n(void); +static void utc_net_nfc_get_record_il_p(void); +static void utc_net_nfc_get_record_il_n(void); +static void utc_net_nfc_get_record_sr_p(void); +static void utc_net_nfc_get_record_sr_n(void); +static void utc_net_nfc_create_text_string_from_text_record_p(void); +static void utc_net_nfc_create_text_string_from_text_record_n(void); +static void utc_net_nfc_get_languange_code_string_from_text_record_p(void); +static void utc_net_nfc_get_languange_code_string_from_text_record_n(void); +static void utc_net_nfc_get_encoding_type_from_text_record_p(void); +static void utc_net_nfc_get_encoding_type_from_text_record_n(void); +static void utc_net_nfc_create_uri_string_from_uri_record_p(void); +static void utc_net_nfc_create_uri_string_from_uri_record_n(void); + + + + + + + +struct tet_testlist tet_testlist[] = { + { utc_net_nfc_create_record_p , POSITIVE_TC_IDX }, + { utc_net_nfc_create_record_n , NEGATIVE_TC_IDX }, + { utc_net_nfc_create_text_type_record_p, POSITIVE_TC_IDX }, + { utc_net_nfc_create_text_type_record_n , NEGATIVE_TC_IDX}, + { utc_net_nfc_create_uri_type_record_p, 1}, + { utc_net_nfc_create_uri_type_record_n, 2 }, + { utc_net_nfc_free_record_p, 1}, + { utc_net_nfc_free_record_n, 2}, + { utc_net_nfc_get_record_payload_p, 1}, + { utc_net_nfc_get_record_payload_n, 2}, + { utc_net_nfc_get_record_type_p, 1}, + { utc_net_nfc_get_record_type_n, 2}, + { utc_net_nfc_set_record_id_p, 1}, + { utc_net_nfc_set_record_id_n, 2}, + { utc_net_nfc_get_record_id_p, 1}, + { utc_net_nfc_get_record_id_n, 2}, + { utc_net_nfc_get_record_tnf_p, 1}, + { utc_net_nfc_get_record_tnf_n, 2}, + { utc_net_nfc_get_record_flags_p, 1}, + { utc_net_nfc_get_record_flags_n, 2}, + { utc_net_nfc_get_record_mb_p, 1}, + { utc_net_nfc_get_record_mb_n, 2}, + { utc_net_nfc_get_record_me_p, 1}, + { utc_net_nfc_get_record_me_n, 2}, + { utc_net_nfc_get_record_cf_p, 1}, + { utc_net_nfc_get_record_cf_n, 2}, + { utc_net_nfc_get_record_il_p, 1}, + { utc_net_nfc_get_record_il_n, 2}, + { utc_net_nfc_get_record_sr_p, 1}, + { utc_net_nfc_get_record_sr_n, 2}, + { utc_net_nfc_create_text_string_from_text_record_p, 1}, + { utc_net_nfc_create_text_string_from_text_record_n, 2}, + { utc_net_nfc_get_languange_code_string_from_text_record_p, 1}, + { utc_net_nfc_get_languange_code_string_from_text_record_n, 2}, + { utc_net_nfc_get_encoding_type_from_text_record_p, 1}, + { utc_net_nfc_get_encoding_type_from_text_record_n, 2}, + { utc_net_nfc_create_uri_string_from_uri_record_p, 1}, + { utc_net_nfc_create_uri_string_from_uri_record_n, 2}, + { NULL, 0 }, +}; + +//this method is called only once in start +static void startup(void) +{ + /* start of TC */ +} + +static void cleanup(void) +{ + /* end of TC */ +} +static void utc_net_nfc_create_record_p(void) +{ + int ret ; + ndef_record_h record = NULL; + data_s* payload = NULL; + data_s* typeName = NULL; + uint8_t url[] = "samsung.com"; + uint8_t temp[] = "U"; + + typeName = calloc(1, sizeof(data_s)); + payload = calloc(1, sizeof(data_s)); + + typeName->buffer = temp; + typeName->length = 1; + + payload->buffer = url; + payload->length = 11; + + ret = net_nfc_create_record(&record, NET_NFC_RECORD_WELL_KNOWN_TYPE, (data_h)typeName, NULL, (data_h)payload); + + net_nfc_free_record(record); + + free(payload); + free(typeName); + dts_check_eq(__func__, ret, NET_NFC_OK, "net_nfc_create_record is failed"); +} + +static void utc_net_nfc_create_record_n(void) +{ + int ret=0; + + ret = net_nfc_create_record( NULL , 0 , NULL , NULL , NULL); + + dts_check_ne(__func__, ret, NET_NFC_OK, "net_nfc_create_record not allow null"); +} + +static void utc_net_nfc_create_text_type_record_p(void) +{ + int ret ; + ndef_record_h record = NULL; + + ret = net_nfc_create_text_type_record(&record, "This is real NFC", "en-US", NET_NFC_ENCODE_UTF_8); + + net_nfc_free_record(record); + + dts_check_eq(__func__, ret, NET_NFC_OK, "net_nfc_create_text_type_record is failed"); +} + +static void utc_net_nfc_create_text_type_record_n(void) +{ + int ret=0; + + ret = net_nfc_create_text_type_record( NULL , NULL , NULL , 0 ); + + dts_check_ne(__func__, ret, NET_NFC_OK, "net_nfc_create_text_type_record not allow null"); +} + +static void utc_net_nfc_create_uri_type_record_p(void) +{ + int ret ; + ndef_record_h record = NULL; + + ret = net_nfc_create_uri_type_record(&record ,"http://www.naver.com", NET_NFC_SCHEMA_FULL_URI); + + net_nfc_free_record(record); + + dts_check_eq(__func__, ret, NET_NFC_OK, "net_nfc_create_uri_type_record is failed"); +} + +static void utc_net_nfc_create_uri_type_record_n(void) +{ + int ret=0; + + ret = net_nfc_create_uri_type_record( NULL , NULL , 0 ); + + dts_check_ne(__func__, ret, NET_NFC_OK, "net_nfc_create_uri_type_record not allow null"); +} + +static void utc_net_nfc_free_record_p(void) +{ + int ret ; + ndef_record_h record = NULL; + + net_nfc_create_uri_type_record(&record ,"http://www.naver.com", NET_NFC_SCHEMA_FULL_URI); + + ret = net_nfc_free_record(record); + + dts_check_eq(__func__, ret, NET_NFC_OK, "net_nfc_free_record is failed"); +} + +static void utc_net_nfc_free_record_n(void) +{ + int ret=0; + + ret = net_nfc_free_record(NULL); + + dts_check_ne(__func__, ret, NET_NFC_OK, "net_nfc_free_record not allow null"); +} + +static void utc_net_nfc_get_record_payload_p(void) +{ + int ret ; + ndef_record_h record = NULL; + data_h payload = NULL; + + net_nfc_create_uri_type_record(&record ,"http://www.naver.com", NET_NFC_SCHEMA_FULL_URI); + + ret = net_nfc_get_record_payload(record, &payload); + + net_nfc_free_record(record); + + dts_check_eq(__func__, ret, NET_NFC_OK, "net_nfc_get_record_payload is failed"); +} + +static void utc_net_nfc_get_record_payload_n(void) +{ + int ret=0; + + ret = net_nfc_get_record_payload(NULL, NULL); + + dts_check_ne(__func__, ret, NET_NFC_OK, "net_nfc_get_record_payload not allow null"); +} + +static void utc_net_nfc_get_record_type_p(void) +{ + int ret ; + ndef_record_h record = NULL; + data_h record_type = NULL; + + net_nfc_create_uri_type_record(&record ,"http://www.naver.com", NET_NFC_SCHEMA_FULL_URI); + + ret = net_nfc_get_record_type(record, &record_type); + + net_nfc_free_record(record); + + dts_check_eq(__func__, ret, NET_NFC_OK, "net_nfc_get_record_type is failed"); +} + +static void utc_net_nfc_get_record_type_n(void) +{ + int ret=0; + + ret = net_nfc_get_record_type(NULL, NULL); + + dts_check_ne(__func__, ret, NET_NFC_OK, "net_nfc_get_record_type not allow null"); +} + +static void utc_net_nfc_set_record_id_p(void) +{ + int ret ; + ndef_record_h record = NULL; + data_s* id = NULL; + uint8_t temp[] = "test"; + + net_nfc_create_uri_type_record(&record ,"http://www.naver.com", NET_NFC_SCHEMA_FULL_URI); + + id = calloc(1, sizeof(data_s)); + id->buffer = temp; + id->length = 4; + + ret = net_nfc_set_record_id(record, (data_h)id); + + net_nfc_free_record(record); + + dts_check_eq(__func__, ret, NET_NFC_OK, "net_nfc_set_record_id is failed"); +} + +static void utc_net_nfc_set_record_id_n(void) +{ + int ret=0; + + ret = net_nfc_set_record_id(NULL, NULL); + + dts_check_ne(__func__, ret, NET_NFC_OK, "net_nfc_set_record_id not allow null"); +} + +static void utc_net_nfc_get_record_id_p(void) +{ + int ret ; + ndef_record_h record = NULL; + data_s* id = NULL; + data_h id_data = NULL; + uint8_t temp[] = "test"; + + net_nfc_create_uri_type_record(&record ,"http://www.naver.com", NET_NFC_SCHEMA_FULL_URI); + + id = calloc(1, sizeof(data_s)); + id->buffer = temp; + id->length = 4; + + net_nfc_set_record_id(record, (data_h)id); + + ret = net_nfc_get_record_id(record, &id_data); + + net_nfc_free_record(record); + + dts_check_eq(__func__, ret, NET_NFC_OK, "net_nfc_get_record_id is failed"); +} + +static void utc_net_nfc_get_record_id_n(void) +{ + int ret=0; + + ret = net_nfc_get_record_id(NULL, NULL); + + dts_check_ne(__func__, ret, NET_NFC_OK, "net_nfc_get_record_id not allow null"); +} + +static void utc_net_nfc_get_record_tnf_p(void) +{ + int ret ; + ndef_record_h record = NULL; + net_nfc_record_tnf_e* tnf = NULL; + + record = calloc( 1 , sizeof(ndef_record_h)); + + net_nfc_create_uri_type_record(&record ,"http://www.naver.com", NET_NFC_SCHEMA_FULL_URI); + + tnf = calloc( 1 , sizeof(net_nfc_record_tnf_e)); + + ret = net_nfc_get_record_tnf(record, tnf); + + net_nfc_free_record(record); + + dts_check_eq(__func__, ret, NET_NFC_OK, "net_nfc_get_record_tnf is failed"); +} + +static void utc_net_nfc_get_record_tnf_n(void) +{ + int ret=0; + + ret = net_nfc_get_record_tnf(NULL, NULL); + + dts_check_ne(__func__, ret, NET_NFC_OK, "net_nfc_get_record_tnf not allow null"); +} + +static void utc_net_nfc_get_record_flags_p(void) +{ + net_nfc_error_e ret=0; + ndef_record_s* record = NULL; + uint8_t temp = 0x80; + + record = calloc(1, sizeof(ndef_record_s)); + + net_nfc_create_uri_type_record((ndef_record_h*)&record ,"http://www.naver.com", NET_NFC_SCHEMA_FULL_URI); + + ret = net_nfc_get_record_flags((ndef_record_h)record, &temp); + + dts_check_eq(__func__, ret, NET_NFC_OK, "net_nfc_get_record_flags is failed"); +} + +static void utc_net_nfc_get_record_flags_n(void) +{ + net_nfc_error_e ret=0; + + ret = net_nfc_get_record_flags(NULL, NULL); + + dts_check_ne(__func__, ret, NET_NFC_OK, "net_nfc_get_record_flags is failed"); +} + +static void utc_net_nfc_get_record_mb_p(void) +{ + unsigned char ret=0; + unsigned char flag = 0x80; + + ret = net_nfc_get_record_mb (flag); + + dts_pass(__func__, "PASS"); +} + +static void utc_net_nfc_get_record_mb_n(void) +{ + unsigned char ret=0; + + ret = net_nfc_get_record_mb(0x00); + + dts_pass(__func__, "PASS"); +} + +static void utc_net_nfc_get_record_me_p(void) +{ + unsigned char ret=0; + + ret = net_nfc_get_record_me(0xff); + + dts_pass(__func__, "PASS"); +} + +static void utc_net_nfc_get_record_me_n(void) +{ + unsigned char ret=0; + + ret = net_nfc_get_record_me(0xff); + + dts_pass(__func__, "PASS"); +} + +static void utc_net_nfc_get_record_cf_p(void) +{ + unsigned char ret=0; + + ret = net_nfc_get_record_cf(0xff); + + dts_pass(__func__, "PASS"); +} + +static void utc_net_nfc_get_record_cf_n(void) +{ + unsigned char ret=0; + + ret = net_nfc_get_record_cf(0xff); + + dts_pass(__func__, "PASS"); +} + +static void utc_net_nfc_get_record_il_p(void) +{ + unsigned char ret=0; + + ret = net_nfc_get_record_il(0xff); + + dts_pass(__func__, "PASS"); +} + +static void utc_net_nfc_get_record_il_n(void) +{ + unsigned char ret=0; + + ret = net_nfc_get_record_il(0xff); + + dts_pass(__func__, "PASS"); +} + +static void utc_net_nfc_get_record_sr_p(void) +{ + unsigned char ret=0; + + ret = net_nfc_get_record_sr (0xff); + + dts_pass(__func__, "PASS"); +} + +static void utc_net_nfc_get_record_sr_n(void) +{ + unsigned char ret=0; + + ret = net_nfc_get_record_sr(0xff); + + dts_pass(__func__, "PASS"); +} +static void utc_net_nfc_create_text_string_from_text_record_p(void) +{ + int ret ; + ndef_record_h record = NULL; + char *disp_text = NULL; + + net_nfc_create_text_type_record(&record, "This is real NFC", "en-US", NET_NFC_ENCODE_UTF_8); + + ret = net_nfc_create_text_string_from_text_record (record, &disp_text); + + dts_check_eq(__func__, ret, NET_NFC_OK, "net_nfc_create_text_string_from_text_record is failed"); +} + +static void utc_net_nfc_create_text_string_from_text_record_n(void) +{ + int ret ; + + ret = net_nfc_create_text_string_from_text_record (NULL, NULL); + + dts_check_ne(__func__, ret, NET_NFC_OK, "net_nfc_create_text_string_from_text_record not allow null"); +} + +static void utc_net_nfc_get_languange_code_string_from_text_record_p(void) +{ + int ret ; + ndef_record_h record = NULL; + char* language_code_str = NULL; + + net_nfc_create_text_type_record(&record, "This is real NFC", "en-US", NET_NFC_ENCODE_UTF_8); + + ret = net_nfc_get_languange_code_string_from_text_record (record, &language_code_str); + + dts_check_eq(__func__, ret, NET_NFC_OK, "net_nfc_get_languange_code_string_from_text_record is failed"); +} + +static void utc_net_nfc_get_languange_code_string_from_text_record_n(void) +{ + int ret ; + + ret = net_nfc_get_languange_code_string_from_text_record (NULL, NULL); + + dts_check_ne(__func__, ret, NET_NFC_OK, "net_nfc_get_languange_code_string_from_text_record not allow null"); +} + +static void utc_net_nfc_get_encoding_type_from_text_record_p(void) +{ + int ret ; + ndef_record_h record = NULL; + net_nfc_encode_type_e utf; + + net_nfc_create_text_type_record(&record, "This is real NFC", "en-US", NET_NFC_ENCODE_UTF_8); + + ret = net_nfc_get_encoding_type_from_text_record (record, &utf); + + dts_check_eq(__func__, ret, NET_NFC_OK, "net_nfc_get_encoding_type_from_text_record is failed"); +} + +static void utc_net_nfc_get_encoding_type_from_text_record_n(void) +{ + int ret ; + + ret = net_nfc_get_encoding_type_from_text_record (NULL, NULL); + + dts_check_ne(__func__, ret, NET_NFC_OK, "net_nfc_get_encoding_type_from_text_record not allow null"); +} + +static void utc_net_nfc_create_uri_string_from_uri_record_p(void) +{ + int ret=0; + ndef_record_h record = NULL; + char *disp_text = NULL; + + net_nfc_create_uri_type_record(&record ,"http://www.naver.com", NET_NFC_SCHEMA_FULL_URI); + + net_nfc_create_uri_string_from_uri_record(record, &disp_text); + + dts_check_eq(__func__, ret, NET_NFC_OK, "net_nfc_create_uri_string_from_uri_record is failed"); +} + +static void utc_net_nfc_create_uri_string_from_uri_record_n(void) +{ + int ret=0; + + ret = net_nfc_create_uri_string_from_uri_record(NULL, NULL); + + dts_check_ne(__func__, ret, NET_NFC_OK, "net_nfc_create_uri_string_from_uri_record is failed"); +} diff --git a/TC/testcase/utc_net_nfc_client_nfc.c b/TC/testcase/utc_net_nfc_client_nfc.c new file mode 100755 index 0000000..83c5428 --- /dev/null +++ b/TC/testcase/utc_net_nfc_client_nfc.c @@ -0,0 +1,161 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include + +#include "net_nfc.h" +#include "net_nfc_typedef.h" +#include "net_nfc_util_private.h" + +#ifdef SECURITY_SERVER +#include +#endif + + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; +static void startup(void); +static void cleanup(void); + +void (*tet_startup)(void) = startup; +void (*tet_cleanup)(void) = cleanup; + +static void utc_net_nfc_initialize_p(void); +static void utc_net_nfc_initialize_n(void); +static void utc_net_nfc_deinitialize_p(void); +static void utc_net_nfc_deinitialize_n(void); +static void utc_net_nfc_set_response_callback_p(void); +static void utc_net_nfc_set_response_callback_n(void); +static void utc_net_nfc_unset_response_callback_p(void); +static void utc_net_nfc_unset_response_callback_n(void); + +static void net_nfc_test_client_cb(net_nfc_message_e message, net_nfc_error_e result, void* data, void* user_param, void * trans_data ) +{ +}; + + + +struct tet_testlist tet_testlist[] = { + { utc_net_nfc_initialize_p , POSITIVE_TC_IDX }, + { utc_net_nfc_initialize_n , NEGATIVE_TC_IDX }, + { utc_net_nfc_deinitialize_p, POSITIVE_TC_IDX }, + { utc_net_nfc_deinitialize_n , NEGATIVE_TC_IDX}, + { utc_net_nfc_set_response_callback_p, 1}, + { utc_net_nfc_set_response_callback_n, 2 }, + { utc_net_nfc_unset_response_callback_p, 1}, + { utc_net_nfc_unset_response_callback_n, 2}, + { NULL, 0 }, +}; + +//this method is called only once in start +static void startup(void) +{ + /* start of TC */ +} + +static void cleanup(void) +{ + /* end of TC */ +} +static void utc_net_nfc_initialize_p(void) +{ + int ret ; + + ret = net_nfc_initialize(); + net_nfc_deinitialize(); + + dts_pass(__func__, "PASS"); +} + +static void utc_net_nfc_initialize_n(void) +{ + int ret=0; + + ret = net_nfc_initialize(); + net_nfc_deinitialize(); + + dts_pass(__func__, "PASS"); +} + +static void utc_net_nfc_deinitialize_p(void) +{ + int ret ; + + net_nfc_initialize(); + ret = net_nfc_deinitialize(); + + dts_check_eq(__func__, ret, NET_NFC_OK, "net_nfc_deinitialize is failed"); +} + +static void utc_net_nfc_deinitialize_n(void) +{ + int ret=0; + + ret = net_nfc_deinitialize(); + + dts_check_eq(__func__, ret, NET_NFC_OK, "net_nfc_deinitialize not allow null"); +} + +static void utc_net_nfc_set_response_callback_p(void) +{ + int ret ; + //net_nfc_response_cb cb; + + net_nfc_initialize(); + + ret = net_nfc_set_response_callback(net_nfc_test_client_cb, NULL); + + net_nfc_unset_response_callback(); + + dts_check_eq(__func__, ret, NET_NFC_OK, "net_nfc_set_response_callback is failed"); +} + +static void utc_net_nfc_set_response_callback_n(void) +{ + int ret=0; + + ret = net_nfc_set_response_callback(NULL, NULL); + + dts_check_ne(__func__, ret, NET_NFC_OK, "net_nfc_set_response_callback not allow null"); +} + +static void utc_net_nfc_unset_response_callback_p(void) +{ + int ret ; + //net_nfc_response_cb cb; + + net_nfc_initialize(); + + net_nfc_set_response_callback(net_nfc_test_client_cb, NULL); + + ret = net_nfc_unset_response_callback(); + + net_nfc_deinitialize(); + + dts_check_eq(__func__, ret, NET_NFC_OK, "net_nfc_unset_response_callback is failed"); +} + +static void utc_net_nfc_unset_response_callback_n(void) +{ + int ret=0; + + ret = net_nfc_unset_response_callback(); + + dts_check_ne(__func__, ret, NET_NFC_OK, "net_nfc_unset_response_callback not allow null"); +} diff --git a/TC/testcase/utc_net_nfc_client_tag.c b/TC/testcase/utc_net_nfc_client_tag.c new file mode 100755 index 0000000..031cef1 --- /dev/null +++ b/TC/testcase/utc_net_nfc_client_tag.c @@ -0,0 +1,256 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include +#include + +#include "net_nfc_typedef_private.h" +#include "net_nfc_util_private.h" +#include "net_nfc.h" + + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; +static void startup(void); +static void cleanup(void); + +void (*tet_startup)(void) = startup; +void (*tet_cleanup)(void) = cleanup; + +static void utc_net_nfc_format_ndef_p(void); +static void utc_net_nfc_format_ndef_n(void); +static void utc_net_nfc_set_tag_filter_p(void); +static void utc_net_nfc_set_tag_filter_n(void); +static void utc_net_nfc_get_tag_filter_p(void); +static void utc_net_nfc_get_tag_filter_n(void); +static void utc_net_nfc_transceive_p(void); +static void utc_net_nfc_transceive_n(void); +static void utc_net_nfc_read_ndef_p(void); +static void utc_net_nfc_read_ndef_n(void); +static void utc_net_nfc_write_ndef_p(void); +static void utc_net_nfc_write_ndef_n(void); +static void utc_net_nfc_make_read_only_ndef_tag_p(void); +static void utc_net_nfc_make_read_only_ndef_tag_n(void); + + +struct tet_testlist tet_testlist[] = { + { utc_net_nfc_format_ndef_p , POSITIVE_TC_IDX }, + { utc_net_nfc_format_ndef_n , NEGATIVE_TC_IDX }, + { utc_net_nfc_set_tag_filter_p, POSITIVE_TC_IDX }, + { utc_net_nfc_set_tag_filter_n , NEGATIVE_TC_IDX}, + { utc_net_nfc_get_tag_filter_p, 1}, + { utc_net_nfc_get_tag_filter_n, 2 }, + { utc_net_nfc_transceive_p, 1}, + { utc_net_nfc_transceive_n, 2}, + { utc_net_nfc_read_ndef_p, 1}, + { utc_net_nfc_read_ndef_n, 2}, + { utc_net_nfc_write_ndef_p, 1}, + { utc_net_nfc_write_ndef_n, 2}, + { utc_net_nfc_make_read_only_ndef_tag_p, 1}, + { utc_net_nfc_make_read_only_ndef_tag_n, 2}, + { NULL, 0 }, +}; + +//this method is called only once in start +static void startup(void) +{ + /* start of TC */ +} + +static void cleanup(void) +{ + /* end of TC */ +} + +static void utc_net_nfc_format_ndef_p(void) +{ + int ret=0; + data_h key; + uint8_t data [] = {0xff,0xff,0xff,0xff,0xff,0xff}; + + net_nfc_initialize(); + + net_nfc_create_data (&key, data, 6); + + ret = net_nfc_format_ndef((net_nfc_target_handle_h) 0x302023, key, NULL); + + net_nfc_deinitialize(); + + dts_pass(__func__, "PASS"); +} + +static void utc_net_nfc_format_ndef_n(void) +{ + int ret=0; + + ret = net_nfc_format_ndef(NULL, NULL, NULL); + + dts_pass(__func__, "PASS"); +} + +static void utc_net_nfc_set_tag_filter_p(void) +{ + int ret=0; + + net_nfc_initialize(); + + ret = net_nfc_set_tag_filter(NET_NFC_ISO14443A_ENABLE); + + net_nfc_deinitialize(); + + dts_pass(__func__, "PASS"); +} + +static void utc_net_nfc_set_tag_filter_n(void) +{ + int ret=0; + net_nfc_event_filter_e config = NET_NFC_ALL_ENABLE; + + ret = net_nfc_set_tag_filter(config); + + dts_pass(__func__, "PASS"); +} + +static void utc_net_nfc_get_tag_filter_p(void) +{ + net_nfc_event_filter_e ret=0; + + net_nfc_initialize(); + + net_nfc_set_tag_filter(NET_NFC_ISO14443A_ENABLE); + + ret = net_nfc_get_tag_filter(); + + net_nfc_deinitialize(); + + dts_pass(__func__, "PASS"); +} + +static void utc_net_nfc_get_tag_filter_n(void) +{ + net_nfc_event_filter_e ret=0; + + ret = net_nfc_get_tag_filter(); + + dts_pass(__func__, "PASS"); +} + +static void utc_net_nfc_transceive_p(void) +{ + int ret ; + net_nfc_target_handle_h handle = NULL; + void* trans_param = NULL; + unsigned char send_buffer[6] = {0x00, }; + + send_buffer[0] = 0x06; + send_buffer[1] = 0x00; + + // use wild card for system code + send_buffer[2] = 0xff; + send_buffer[3] = 0xff; + + send_buffer[4] = 0xff; + send_buffer[5] = 0xff; + + data_s rawdata; + + rawdata.buffer = send_buffer; + rawdata.length = 6; + + ret = net_nfc_transceive(handle, (data_h)&rawdata, trans_param); + + dts_pass(__func__, "PASS"); +} + +static void utc_net_nfc_transceive_n(void) +{ + int ret ; + + ret = net_nfc_transceive(NULL, NULL, NULL); + + dts_pass(__func__, "PASS"); +} + +static void utc_net_nfc_read_ndef_p(void) +{ + int ret ; + + ret = net_nfc_read_tag((net_nfc_target_handle_h) 0x302023, NULL); + + dts_pass(__func__, "PASS"); +} + +static void utc_net_nfc_read_ndef_n(void) +{ + int ret ; + + ret = net_nfc_read_tag(NULL, NULL); + + dts_pass(__func__, "PASS"); +} + +static void utc_net_nfc_write_ndef_p(void) +{ + int ret ; + ndef_message_h message = NULL; + ndef_record_h record = NULL; + + net_nfc_initialize(); + + net_nfc_create_ndef_message (&message); + net_nfc_create_text_type_record (&record, "abc" ,"en-US" ,NET_NFC_ENCODE_UTF_8); + net_nfc_append_record_to_ndef_message (message ,record); + + ret = net_nfc_write_ndef ((net_nfc_target_handle_h)0x302023 ,message ,NULL); + + net_nfc_deinitialize(); + + dts_pass(__func__, "PASS"); +} + +static void utc_net_nfc_write_ndef_n(void) +{ + int ret ; + + ret = net_nfc_write_ndef(NULL, NULL , NULL); + + dts_pass(__func__, "PASS"); +} + +static void utc_net_nfc_make_read_only_ndef_tag_p(void) +{ + int ret ; + + net_nfc_initialize(); + + ret = net_nfc_make_read_only_ndef_tag ((net_nfc_target_handle_h)0x302023 , NULL); + + net_nfc_deinitialize(); + + dts_pass(__func__, "PASS"); +} + +static void utc_net_nfc_make_read_only_ndef_tag_n(void) +{ + int ret; + + ret = net_nfc_make_read_only_ndef_tag(NULL , NULL); + + dts_pass(__func__, "PASS"); +} diff --git a/TC/testcase/utc_net_nfc_client_tag_felica.c b/TC/testcase/utc_net_nfc_client_tag_felica.c new file mode 100755 index 0000000..59cea7b --- /dev/null +++ b/TC/testcase/utc_net_nfc_client_tag_felica.c @@ -0,0 +1,242 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include + +#include "net_nfc_ndef_record.h" +#include "net_nfc_ndef_message.h" +#include "net_nfc_util_private.h" +#include "net_nfc_data.h" +#include "net_nfc.h" +#include "net_nfc_tag_felica.h" + + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; +static void startup(void); +static void cleanup(void); + +void (*tet_startup)(void) = startup; +void (*tet_cleanup)(void) = cleanup; + +static void utc_net_nfc_felica_poll_p(void); +static void utc_net_nfc_felica_poll_n(void); +static void utc_net_nfc_felica_request_service_p(void); +static void utc_net_nfc_felica_request_service_n(void); +static void utc_net_nfc_felica_request_response_p(void); +static void utc_net_nfc_felica_request_response_n(void); +static void utc_net_nfc_felica_read_without_encryption_p(void); +static void utc_net_nfc_felica_read_without_encryption_n(void); +static void utc_net_nfc_felica_write_without_encryption_p(void); +static void utc_net_nfc_felica_write_without_encryption_n(void); +static void utc_net_nfc_felica_request_system_code_p(void); +static void utc_net_nfc_felica_request_system_code_n(void); + + +struct tet_testlist tet_testlist[] = { + { utc_net_nfc_felica_poll_p , POSITIVE_TC_IDX }, + { utc_net_nfc_felica_poll_n , NEGATIVE_TC_IDX }, + { utc_net_nfc_felica_request_service_p, POSITIVE_TC_IDX }, + { utc_net_nfc_felica_request_service_n , NEGATIVE_TC_IDX}, + { utc_net_nfc_felica_request_response_p, 1}, + { utc_net_nfc_felica_request_response_n, 2 }, + { utc_net_nfc_felica_read_without_encryption_p, 1}, + { utc_net_nfc_felica_read_without_encryption_n, 2}, + { utc_net_nfc_felica_write_without_encryption_p, 1}, + { utc_net_nfc_felica_write_without_encryption_n, 2}, + { utc_net_nfc_felica_request_system_code_p, 1}, + { utc_net_nfc_felica_request_system_code_n, 2}, + { NULL, 0 }, +}; + +//this method is called only once in start +static void startup(void) +{ + /* start of TC */ +} + +static void cleanup(void) +{ + /* end of TC */ +} + +static void utc_net_nfc_felica_poll_p(void) +{ + int ret=0; + + net_nfc_initialize(); + + ret = net_nfc_felica_poll((net_nfc_target_handle_h) 0x302023, NET_NFC_FELICA_POLL_COMM_SPEED_REQUEST , 0x0 , NULL); + + net_nfc_deinitialize(); + + dts_pass(__func__, "PASS"); +} + +static void utc_net_nfc_felica_poll_n(void) +{ + int ret=0; + uint8_t temp[]= "a"; + + ret = net_nfc_felica_poll(NULL , NET_NFC_FELICA_POLL_NO_REQUEST , temp[0] , NULL); + + dts_pass(__func__, "PASS"); +} + +static void utc_net_nfc_felica_request_service_p(void) +{ + int ret=0; + unsigned short service_code = 0xffff; + + net_nfc_initialize(); + + net_nfc_felica_poll((net_nfc_target_handle_h) 0x302023, NET_NFC_FELICA_POLL_COMM_SPEED_REQUEST , 0x0 , NULL); + + ret = net_nfc_felica_request_service((net_nfc_target_handle_h) 0x302023 , 1 , &service_code , 1 , NULL); + + net_nfc_deinitialize(); + + dts_pass(__func__, "PASS"); +} + +static void utc_net_nfc_felica_request_service_n(void) +{ + int ret=0; + + ret = net_nfc_felica_request_service(NULL , 1 , NULL , 1, NULL); + + dts_pass(__func__, "PASS"); +} + +static void utc_net_nfc_felica_request_response_p(void) +{ + int ret=0; + + net_nfc_initialize(); + + net_nfc_felica_poll((net_nfc_target_handle_h) 0x302023, NET_NFC_FELICA_POLL_COMM_SPEED_REQUEST , 0x0 , NULL); + + ret = net_nfc_felica_request_response((net_nfc_target_handle_h) 0x302023 , NULL); + + net_nfc_deinitialize(); + + dts_pass(__func__, "PASS"); +} + +static void utc_net_nfc_felica_request_response_n(void) +{ + int ret=0; + + ret = net_nfc_felica_request_response( NULL , NULL ); + + dts_pass(__func__, "PASS"); +} + +static void utc_net_nfc_felica_read_without_encryption_p(void) +{ + int ret=0; + unsigned short service_code = 0xffff; + unsigned char blocks = 0x2; + + net_nfc_initialize(); + + net_nfc_felica_poll((net_nfc_target_handle_h) 0x302023, NET_NFC_FELICA_POLL_COMM_SPEED_REQUEST , 0x0 , NULL); + + ret = net_nfc_felica_read_without_encryption((net_nfc_target_handle_h) 0x302023, 1, &service_code, 1, &blocks, NULL); + + net_nfc_deinitialize(); + + dts_pass(__func__, "PASS"); +} + +static void utc_net_nfc_felica_read_without_encryption_n(void) +{ + int ret=0; + + ret = net_nfc_felica_read_without_encryption(NULL, 1, NULL, 1, NULL, NULL); + + dts_pass(__func__, "PASS"); +} + +static void utc_net_nfc_felica_write_without_encryption_p(void) +{ + int ret=0; + unsigned short service_code = 0xffff; + unsigned char blocks = 0x2; + unsigned char send_buffer[6] = {0x00, }; + + send_buffer[0] = 0x06; + send_buffer[1] = 0x00; + + // use wild card for system code + send_buffer[2] = 0xff; + send_buffer[3] = 0xff; + + send_buffer[4] = 0xff; + send_buffer[5] = 0xff; + + data_h rawdata = NULL; + + rawdata = calloc(1,sizeof(data_h)); + + net_nfc_initialize(); + + net_nfc_felica_poll((net_nfc_target_handle_h) 0x302023, NET_NFC_FELICA_POLL_COMM_SPEED_REQUEST , 0x0 , NULL); + + ret = net_nfc_felica_write_without_encryption((net_nfc_target_handle_h) 0x302023, 1, &service_code, 1, &blocks, rawdata , NULL); + + net_nfc_deinitialize(); + + dts_pass(__func__, "PASS"); +} + +static void utc_net_nfc_felica_write_without_encryption_n(void) +{ + int ret=0; + + ret = net_nfc_felica_write_without_encryption(NULL, 1, NULL, 1, NULL, NULL , NULL); + + dts_pass(__func__, "PASS"); +} + +static void utc_net_nfc_felica_request_system_code_p(void) +{ + int ret=0; + //unsigned short service_code = 0xffff; + //unsigned char blocks = 0x2; + + net_nfc_initialize(); + + net_nfc_felica_poll((net_nfc_target_handle_h) 0x302023, NET_NFC_FELICA_POLL_COMM_SPEED_REQUEST , 0x0 , NULL); + + ret = net_nfc_felica_request_system_code((net_nfc_target_handle_h) 0x302023 , NULL); + + net_nfc_deinitialize(); + + dts_pass(__func__, "PASS"); +} + +static void utc_net_nfc_felica_request_system_code_n(void) +{ + int ret=0; + + ret = net_nfc_felica_request_system_code(NULL, NULL); + + dts_pass(__func__, "PASS"); +} diff --git a/TC/testcase/utc_net_nfc_client_tag_jewel.c b/TC/testcase/utc_net_nfc_client_tag_jewel.c new file mode 100755 index 0000000..25a9e17 --- /dev/null +++ b/TC/testcase/utc_net_nfc_client_tag_jewel.c @@ -0,0 +1,185 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include + +#include "net_nfc_tag.h" +#include "net_nfc_typedef_private.h" +#include "net_nfc_util_private.h" +#include "net_nfc_tag_jewel.h" +#include "net_nfc_target_info.h" +#include "net_nfc.h" + +#include + + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; +static void startup(void); +static void cleanup(void); + +void (*tet_startup)(void) = startup; +void (*tet_cleanup)(void) = cleanup; + +static void utc_net_nfc_jewel_read_id_p(void); +static void utc_net_nfc_jewel_read_id_n(void); +static void utc_net_nfc_jewel_read_byte_p(void); +static void utc_net_nfc_jewel_read_byte_n(void); +static void utc_net_nfc_jewel_read_all_p(void); +static void utc_net_nfc_jewel_read_all_n(void); +static void utc_net_nfc_jewel_write_with_erase_p(void); +static void utc_net_nfc_jewel_write_with_erase_n(void); +static void utc_net_nfc_jewel_write_with_no_erase_p(void); +static void utc_net_nfc_jewel_write_with_no_erase_n(void); + + +struct tet_testlist tet_testlist[] = { + { utc_net_nfc_jewel_read_id_p , POSITIVE_TC_IDX }, + { utc_net_nfc_jewel_read_id_n , NEGATIVE_TC_IDX }, + { utc_net_nfc_jewel_read_byte_p, POSITIVE_TC_IDX }, + { utc_net_nfc_jewel_read_byte_n , NEGATIVE_TC_IDX}, + { utc_net_nfc_jewel_read_all_p, 1}, + { utc_net_nfc_jewel_read_all_n, 2 }, + { utc_net_nfc_jewel_write_with_erase_p, 1}, + { utc_net_nfc_jewel_write_with_erase_n, 2}, + { utc_net_nfc_jewel_write_with_no_erase_p, 1}, + { utc_net_nfc_jewel_write_with_no_erase_n, 2}, + { NULL, 0 }, +}; + +//this method is called only once in start +static void startup(void) +{ + /* start of TC */ +} + +static void cleanup(void) +{ + /* end of TC */ +} + +static void utc_net_nfc_jewel_read_id_p(void) +{ + int ret=0; + + net_nfc_initialize(); + + ret = net_nfc_jewel_read_id((net_nfc_target_handle_h) 0x302023, NULL); + + net_nfc_deinitialize(); + + dts_pass(__func__, "PASS"); +} + +static void utc_net_nfc_jewel_read_id_n(void) +{ + int ret=0; + + ret = net_nfc_jewel_read_id(NULL , NULL ); + + dts_pass(__func__, "PASS"); +} + +static void utc_net_nfc_jewel_read_byte_p(void) +{ + int ret=0; + + net_nfc_initialize(); + + ret = net_nfc_jewel_read_byte((net_nfc_target_handle_h) 0x302023 , 1 , 0 , NULL); + + net_nfc_deinitialize(); + + dts_pass(__func__, "PASS"); +} + +static void utc_net_nfc_jewel_read_byte_n(void) +{ + int ret=0; + + ret = net_nfc_jewel_read_byte(NULL , 0 , 0 , NULL); + + dts_pass(__func__, "PASS"); +} + +static void utc_net_nfc_jewel_read_all_p(void) +{ + int ret=0; + + net_nfc_initialize(); + + ret = net_nfc_jewel_read_all((net_nfc_target_handle_h) 0x302023 , NULL); + + net_nfc_deinitialize(); + + dts_pass(__func__, "PASS"); +} + +static void utc_net_nfc_jewel_read_all_n(void) +{ + int ret=0; + + ret = net_nfc_jewel_read_all( NULL , NULL ); + + dts_pass(__func__, "PASS"); +} + +static void utc_net_nfc_jewel_write_with_erase_p(void) +{ + int ret=0; + + net_nfc_initialize(); + + ret = net_nfc_jewel_write_with_erase((net_nfc_target_handle_h) 0x302023 , 1 , 0 , 0xff , NULL); + + net_nfc_deinitialize(); + + dts_pass(__func__, "PASS"); +} + +static void utc_net_nfc_jewel_write_with_erase_n(void) +{ + int ret=0; + + ret = net_nfc_jewel_write_with_erase(NULL, 0, 0, 0xff, NULL); + + dts_pass(__func__, "PASS"); +} + +static void utc_net_nfc_jewel_write_with_no_erase_p(void) +{ + int ret=0; + + net_nfc_initialize(); + + ret = net_nfc_jewel_write_with_no_erase((net_nfc_target_handle_h) 0x302023 , 1 , 0 , 0xff , NULL); + + net_nfc_deinitialize(); + + dts_pass(__func__, "PASS"); +} + +static void utc_net_nfc_jewel_write_with_no_erase_n(void) +{ + int ret=0; + + ret = net_nfc_jewel_write_with_no_erase(NULL, 0, 0, 0xff, NULL); + + dts_pass(__func__, "PASS"); +} diff --git a/TC/testcase/utc_net_nfc_client_tag_mifare.c b/TC/testcase/utc_net_nfc_client_tag_mifare.c new file mode 100755 index 0000000..899c20a --- /dev/null +++ b/TC/testcase/utc_net_nfc_client_tag_mifare.c @@ -0,0 +1,369 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include + +#include "net_nfc_tag.h" +#include "net_nfc_typedef_private.h" +#include "net_nfc_util_private.h" +#include "net_nfc_tag_jewel.h" +#include "net_nfc_target_info.h" +#include "net_nfc.h" + +#include + + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; +static void startup(void); +static void cleanup(void); + +void (*tet_startup)(void) = startup; +void (*tet_cleanup)(void) = cleanup; + +static void utc_net_nfc_mifare_create_default_key_p(void); +static void utc_net_nfc_mifare_create_default_key_n(void); +static void utc_net_nfc_mifare_create_application_directory_key_p(void); +static void utc_net_nfc_mifare_create_application_directory_key_n(void); +static void utc_net_nfc_mifare_create_net_nfc_forum_key_p(void); +static void utc_net_nfc_mifare_create_net_nfc_forum_key_n(void); +static void utc_net_nfc_mifare_authenticate_with_keyA_p(void); +static void utc_net_nfc_mifare_authenticate_with_keyA_n(void); +static void utc_net_nfc_mifare_authenticate_with_keyB_p(void); +static void utc_net_nfc_mifare_authenticate_with_keyB_n(void); +static void utc_net_nfc_mifare_read_p(void); +static void utc_net_nfc_mifare_read_n(void); +static void utc_net_nfc_mifare_write_block_p(void); +static void utc_net_nfc_mifare_write_block_n(void); +static void utc_net_nfc_mifare_write_page_p(void); +static void utc_net_nfc_mifare_write_page_n(void); +static void utc_net_nfc_mifare_increment_p(void); +static void utc_net_nfc_mifare_increment_n(void); +static void utc_net_nfc_mifare_decrement_p(void); +static void utc_net_nfc_mifare_decrement_n(void); +static void utc_net_nfc_mifare_transfer_p(void); +static void utc_net_nfc_mifare_transfer_n(void); +static void utc_net_nfc_mifare_restore_p(void); +static void utc_net_nfc_mifare_restore_n(void); + + + +struct tet_testlist tet_testlist[] = { + { utc_net_nfc_mifare_create_default_key_p , POSITIVE_TC_IDX }, + { utc_net_nfc_mifare_create_default_key_n , NEGATIVE_TC_IDX }, + { utc_net_nfc_mifare_create_application_directory_key_p, POSITIVE_TC_IDX }, + { utc_net_nfc_mifare_create_application_directory_key_n , NEGATIVE_TC_IDX}, + { utc_net_nfc_mifare_create_net_nfc_forum_key_p, 1}, + { utc_net_nfc_mifare_create_net_nfc_forum_key_n, 2 }, + { utc_net_nfc_mifare_authenticate_with_keyA_p, 1}, + { utc_net_nfc_mifare_authenticate_with_keyA_n, 2}, + { utc_net_nfc_mifare_authenticate_with_keyB_p, 1}, + { utc_net_nfc_mifare_authenticate_with_keyB_n, 2}, + { utc_net_nfc_mifare_read_p, 1}, + { utc_net_nfc_mifare_read_n, 2}, + { utc_net_nfc_mifare_write_block_p, 1}, + { utc_net_nfc_mifare_write_block_n, 2}, + { utc_net_nfc_mifare_write_page_p, 1}, + { utc_net_nfc_mifare_write_page_n, 2}, + { utc_net_nfc_mifare_increment_p, 1}, + { utc_net_nfc_mifare_increment_n, 2}, + { utc_net_nfc_mifare_decrement_p, 1}, + { utc_net_nfc_mifare_decrement_n, 2}, + { utc_net_nfc_mifare_transfer_p, 1}, + { utc_net_nfc_mifare_transfer_n, 2}, + { utc_net_nfc_mifare_restore_p, 1}, + { utc_net_nfc_mifare_restore_n, 2}, + { NULL, 0 }, +}; + +//this method is called only once in start +static void startup(void) +{ + /* start of TC */ +} + +static void cleanup(void) +{ + /* end of TC */ +} + +static void utc_net_nfc_mifare_create_default_key_p(void) +{ + int ret=0; + data_h default_key = NULL; + + net_nfc_initialize(); + + ret = net_nfc_mifare_create_default_key(&default_key); + + net_nfc_deinitialize(); + + dts_pass(__func__, "PASS"); +} + +static void utc_net_nfc_mifare_create_default_key_n(void) +{ + int ret=0; + + ret = net_nfc_mifare_create_default_key(NULL); + + dts_pass(__func__, "PASS"); +} + +static void utc_net_nfc_mifare_create_application_directory_key_p(void) +{ + int ret=0; + data_h mad_key = NULL; + + net_nfc_initialize(); + + ret = net_nfc_mifare_create_application_directory_key(&mad_key); + + net_nfc_deinitialize(); + + dts_pass(__func__, "PASS"); +} + +static void utc_net_nfc_mifare_create_application_directory_key_n(void) +{ + int ret=0; + + ret = net_nfc_mifare_create_application_directory_key(NULL); + + dts_pass(__func__, "PASS"); +} + +static void utc_net_nfc_mifare_create_net_nfc_forum_key_p(void) +{ + int ret=0; + data_h net_nfc_forum_key = NULL; + + net_nfc_initialize(); + + ret = net_nfc_mifare_create_net_nfc_forum_key(&net_nfc_forum_key); + + net_nfc_deinitialize(); + + dts_pass(__func__, "PASS"); +} + +static void utc_net_nfc_mifare_create_net_nfc_forum_key_n(void) +{ + int ret=0; + + ret = net_nfc_mifare_create_net_nfc_forum_key( NULL ); + + dts_pass(__func__, "PASS"); +} + +static void utc_net_nfc_mifare_authenticate_with_keyA_p(void) +{ + data_h default_key = NULL; + int sector = 1; + data_h key = NULL; + + net_nfc_initialize(); + + net_nfc_mifare_create_default_key(&default_key); + + key = default_key; + + net_nfc_mifare_authenticate_with_keyA((net_nfc_target_handle_h) 0x302023, sector, default_key, NULL); + + net_nfc_deinitialize(); + + dts_pass(__func__, "PASS"); +} + +static void utc_net_nfc_mifare_authenticate_with_keyA_n(void) +{ + int ret=0; + + ret = net_nfc_mifare_authenticate_with_keyA(NULL , 0 , NULL , NULL); + + dts_pass(__func__, "PASS"); +} + +static void utc_net_nfc_mifare_authenticate_with_keyB_p(void) +{ + data_h default_key = NULL; + int sector = 1; + data_h key = NULL; + + net_nfc_initialize(); + + net_nfc_mifare_create_default_key(&default_key); + + key = default_key; + + net_nfc_mifare_authenticate_with_keyB((net_nfc_target_handle_h) 0x302023, sector, key, NULL); + + net_nfc_deinitialize(); + + dts_pass(__func__, "PASS"); +} + +static void utc_net_nfc_mifare_authenticate_with_keyB_n(void) +{ + int ret=0; + + ret = net_nfc_mifare_authenticate_with_keyB(NULL , 0 , NULL , NULL); + + dts_pass(__func__, "PASS"); +} + +static void utc_net_nfc_mifare_read_p(void) +{ + net_nfc_initialize(); + + net_nfc_mifare_read((net_nfc_target_handle_h) 0x302023 , 5, NULL); + + net_nfc_deinitialize(); + + dts_pass(__func__, "PASS"); +} + +static void utc_net_nfc_mifare_read_n(void) +{ + int ret=0; + + ret = net_nfc_mifare_read(NULL , 0 , NULL); + + dts_pass(__func__, "PASS"); +} + +static void utc_net_nfc_mifare_write_block_p(void) +{ + net_nfc_initialize(); + + net_nfc_mifare_write_block((net_nfc_target_handle_h) 0x302023 , 5, NULL , NULL); + + net_nfc_deinitialize(); + + dts_pass(__func__, "PASS"); +} + +static void utc_net_nfc_mifare_write_block_n(void) +{ + int ret=0; + + ret = net_nfc_mifare_write_block(NULL , 0 , NULL , NULL); + + dts_pass(__func__, "PASS"); +} + +static void utc_net_nfc_mifare_write_page_p(void) +{ + net_nfc_initialize(); + + net_nfc_mifare_write_block((net_nfc_target_handle_h) 0x302023 , 5, NULL , NULL); + + net_nfc_deinitialize(); + + dts_pass(__func__, "PASS"); +} + +static void utc_net_nfc_mifare_write_page_n(void) +{ + int ret=0; + + ret = net_nfc_mifare_write_block(NULL , 0 , NULL , NULL); + + dts_pass(__func__, "PASS"); +} + +static void utc_net_nfc_mifare_increment_p(void) +{ + net_nfc_initialize(); + + net_nfc_mifare_increment((net_nfc_target_handle_h) 0x302023 , 5 , 0 , NULL); + + net_nfc_deinitialize(); + + dts_pass(__func__, "PASS"); +} + +static void utc_net_nfc_mifare_increment_n(void) +{ + int ret=0; + + ret = net_nfc_mifare_increment(NULL , 5 , 0 , NULL); + + dts_pass(__func__, "PASS"); +} + +static void utc_net_nfc_mifare_decrement_p(void) +{ + net_nfc_initialize(); + + net_nfc_mifare_decrement((net_nfc_target_handle_h) 0x302023 , 5 , 0 , NULL); + + net_nfc_deinitialize(); + + dts_pass(__func__, "PASS"); +} + +static void utc_net_nfc_mifare_decrement_n(void) +{ + int ret=0; + + ret = net_nfc_mifare_decrement(NULL , 5 , 0 , NULL); + + dts_pass(__func__, "PASS"); +} + +static void utc_net_nfc_mifare_transfer_p(void) +{ + net_nfc_initialize(); + + net_nfc_mifare_transfer((net_nfc_target_handle_h) 0x302023 , 5, NULL); + + net_nfc_deinitialize(); + + dts_pass(__func__, "PASS"); +} + +static void utc_net_nfc_mifare_transfer_n(void) +{ + int ret=0; + + ret = net_nfc_mifare_transfer(NULL , 5 , NULL); + + dts_pass(__func__, "PASS"); +} + +static void utc_net_nfc_mifare_restore_p(void) +{ + net_nfc_initialize(); + + net_nfc_mifare_restore((net_nfc_target_handle_h) 0x302023 , 5, NULL); + + net_nfc_deinitialize(); + + dts_pass(__func__, "PASS"); +} + +static void utc_net_nfc_mifare_restore_n(void) +{ + int ret=0; + + ret = net_nfc_mifare_restore(NULL , 5 , NULL); + + dts_pass(__func__, "PASS"); +} diff --git a/TC/testcase/utc_net_nfc_client_target_info.c b/TC/testcase/utc_net_nfc_client_target_info.c new file mode 100755 index 0000000..23f10c6 --- /dev/null +++ b/TC/testcase/utc_net_nfc_client_target_info.c @@ -0,0 +1,296 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include + +#include "net_nfc_typedef.h" +#include "net_nfc_typedef_private.h" +#include "net_nfc_target_info.h" +#include "net_nfc_data.h" +#include +#include "net_nfc.h" + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; +static void startup(void); +static void cleanup(void); + +void (*tet_startup)(void) = startup; +void (*tet_cleanup)(void) = cleanup; + +static void utc_net_nfc_get_tag_type_p(void); +static void utc_net_nfc_get_tag_type_n(void); +static void utc_net_nfc_get_tag_handle_p(void); +static void utc_net_nfc_get_tag_handle_n(void); +static void utc_net_nfc_get_tag_ndef_support_p(void); +static void utc_net_nfc_get_tag_ndef_support_n(void); +static void utc_net_nfc_get_tag_max_data_size_p(void); +static void utc_net_nfc_get_tag_max_data_size_n(void); +static void utc_net_nfc_get_tag_actual_data_size_p(void); +static void utc_net_nfc_get_tag_actual_data_size_n(void); +static void utc_net_nfc_get_tag_info_keys_p(void); +static void utc_net_nfc_get_tag_info_keys_n(void); +static void utc_net_nfc_get_tag_info_value_p(void); +static void utc_net_nfc_get_tag_info_value_n(void); + + +struct tet_testlist tet_testlist[] = { + { utc_net_nfc_get_tag_type_p , POSITIVE_TC_IDX }, + { utc_net_nfc_get_tag_type_n , NEGATIVE_TC_IDX }, + { utc_net_nfc_get_tag_handle_p, POSITIVE_TC_IDX }, + { utc_net_nfc_get_tag_handle_n , NEGATIVE_TC_IDX}, + { utc_net_nfc_get_tag_ndef_support_p, 1}, + { utc_net_nfc_get_tag_ndef_support_n, 2 }, + { utc_net_nfc_get_tag_max_data_size_p, 1}, + { utc_net_nfc_get_tag_max_data_size_n, 2}, + { utc_net_nfc_get_tag_actual_data_size_p, 1}, + { utc_net_nfc_get_tag_actual_data_size_n, 2}, + { utc_net_nfc_get_tag_info_keys_p, 1}, + { utc_net_nfc_get_tag_info_keys_n, 2}, + { utc_net_nfc_get_tag_info_value_p, 1}, + { utc_net_nfc_get_tag_info_value_n, 2}, + { NULL, 0 }, +}; + +//this method is called only once in start +static void startup(void) +{ + /* start of TC */ +} + +static void cleanup(void) +{ + /* end of TC */ +} + +static void utc_net_nfc_get_tag_type_p(void) +{ + int ret=0; + net_nfc_target_info_s* target_info; + net_nfc_target_type_e type; + + target_info = calloc(1, sizeof(net_nfc_target_info_s)); + + target_info->devType = NET_NFC_GENERIC_PICC; + + net_nfc_initialize(); + + ret = net_nfc_get_tag_type((net_nfc_target_info_h)target_info , &type); + + net_nfc_deinitialize(); + + free(target_info); + + dts_pass(__func__, "PASS"); +} + +static void utc_net_nfc_get_tag_type_n(void) +{ + int ret=0; + + ret = net_nfc_get_tag_type(NULL , NULL); + + dts_pass(__func__, "PASS"); +} + +static void utc_net_nfc_get_tag_handle_p(void) +{ + int ret=0; + net_nfc_target_info_s* target_info; + net_nfc_target_handle_h id; + + target_info = calloc(1, sizeof(net_nfc_target_info_s)); + + target_info->handle = (net_nfc_target_handle_s*)0x302023; + + net_nfc_initialize(); + + ret = net_nfc_get_tag_handle((net_nfc_target_info_h)target_info , &id); + + net_nfc_deinitialize(); + + dts_pass(__func__, "PASS"); +} + +static void utc_net_nfc_get_tag_handle_n(void) +{ + int ret=0; + + ret = net_nfc_get_tag_handle(NULL , NULL); + + dts_pass(__func__, "PASS"); +} + +static void utc_net_nfc_get_tag_ndef_support_p(void) +{ + int ret=0; + net_nfc_target_info_s* target_info; + bool is_ndef; + + target_info = calloc(1, sizeof(net_nfc_target_info_s)); + target_info->is_ndef_supported = 1; + + net_nfc_initialize(); + + ret = net_nfc_get_tag_ndef_support((net_nfc_target_info_h)target_info , &is_ndef); + + net_nfc_deinitialize(); + + free(target_info); + + dts_pass(__func__, "PASS"); +} + +static void utc_net_nfc_get_tag_ndef_support_n(void) +{ + int ret=0; + + ret = net_nfc_get_tag_ndef_support(NULL , NULL); + + dts_pass(__func__, "PASS"); +} + +static void utc_net_nfc_get_tag_max_data_size_p(void) +{ + int ret=0; + net_nfc_target_info_s* target_info; + net_nfc_target_type_e max_size = 0; + + target_info = calloc(1, sizeof(net_nfc_target_info_s)); + target_info->maxDataSize = 128; + + net_nfc_initialize(); + + ret = net_nfc_get_tag_max_data_size((net_nfc_target_info_h)target_info , &max_size); + + net_nfc_deinitialize(); + + free(target_info); + + dts_pass(__func__, "PASS"); +} + +static void utc_net_nfc_get_tag_max_data_size_n(void) +{ + int ret=0; + + ret = net_nfc_get_tag_max_data_size(NULL , NULL); + + dts_pass(__func__, "PASS"); +} + +static void utc_net_nfc_get_tag_actual_data_size_p(void) +{ + int ret=0; + net_nfc_target_info_s* target_info; + net_nfc_target_type_e size = 0; + + target_info = calloc(1, sizeof(net_nfc_target_info_s)); + target_info->actualDataSize = 128; + + net_nfc_initialize(); + + ret = net_nfc_get_tag_actual_data_size((net_nfc_target_info_h)target_info , &size); + + net_nfc_deinitialize(); + + free(target_info); + + dts_pass(__func__, "PASS"); +} + +static void utc_net_nfc_get_tag_actual_data_size_n(void) +{ + int ret=0; + + ret = net_nfc_get_tag_actual_data_size(NULL , NULL); + + dts_pass(__func__, "PASS"); +} + +static void utc_net_nfc_get_tag_info_keys_p(void) +{ + int ret=0; + net_nfc_target_info_s* target_info; + char** keys = NULL; + int nok = 0; + + target_info = calloc(1, sizeof(net_nfc_target_info_s)); + + net_nfc_initialize(); + + ret = net_nfc_get_tag_info_keys((net_nfc_target_info_h)target_info, &keys, &nok); + + net_nfc_deinitialize(); + + free(target_info); + + dts_pass(__func__, "PASS"); +} + +static void utc_net_nfc_get_tag_info_keys_n(void) +{ + int ret=0; + + ret = net_nfc_get_tag_info_keys(NULL , NULL , NULL); + + dts_pass(__func__, "PASS"); +} +static void utc_net_nfc_get_tag_info_value_p(void) +{ + net_nfc_target_info_s* target_info; + data_h* value = NULL; + char* keys = NULL; + + keys = calloc( 1 , sizeof(char)); + + target_info = calloc(1, sizeof(net_nfc_target_info_s)); + target_info->actualDataSize = 128; + target_info->tag_info_list = calloc(1 , sizeof(net_nfc_tag_info_s)); + + target_info->tag_info_list->key = '1'; + target_info->tag_info_list->value = calloc(1 , sizeof(data_h)); + + value = calloc(1, sizeof(data_h)); + + net_nfc_initialize(); + + //net_nfc_get_tag_info_keys((net_nfc_target_info_h)target_info, &keys, &nok); + + net_nfc_get_tag_info_value((net_nfc_target_info_h)target_info , keys , value); + + net_nfc_deinitialize(); + + free(target_info->tag_info_list->value); + free(target_info->tag_info_list); + free(target_info); + free(keys); + free(value); + + dts_pass(__func__, "PASS"); +} + +static void utc_net_nfc_get_tag_info_value_n(void) +{ + int ret=0; + + ret = net_nfc_get_tag_info_value(NULL , NULL , NULL); + + dts_pass(__func__, "PASS"); +} diff --git a/TC/tet_scen b/TC/tet_scen new file mode 100755 index 0000000..03f029a --- /dev/null +++ b/TC/tet_scen @@ -0,0 +1,7 @@ +all + ^TEST +##### Scenarios for TEST ##### + +# Test scenario +TEST + :include:/testcase/tslist diff --git a/TC/tetbuild.cfg b/TC/tetbuild.cfg new file mode 100644 index 0000000..f7eda55 --- /dev/null +++ b/TC/tetbuild.cfg @@ -0,0 +1,5 @@ +TET_OUTPUT_CAPTURE=True # capture option for build operation checking +TET_BUILD_TOOL=make # build with using make command +TET_BUILD_FILE=-f Makefile # execution file (Makefile) for build +TET_API_COMPLIANT=True # use TET API in Test Case ? +TET_PASS_TC_NAME=True # report passed TC name in Journal file? diff --git a/TC/tetclean.cfg b/TC/tetclean.cfg new file mode 100644 index 0000000..02d7030 --- /dev/null +++ b/TC/tetclean.cfg @@ -0,0 +1,5 @@ +TET_OUTPUT_CAPTURE=True # capture option +TET_CLEAN_TOOL= make clean # clean tool +TET_CLEAN_FILE= Makefile # file for clean +TET_API_COMPLIANT=True # TET API useage +TET_PASS_TC_NAME=True # showing name , passed TC diff --git a/TC/tetexec.cfg b/TC/tetexec.cfg new file mode 100644 index 0000000..ef3e452 --- /dev/null +++ b/TC/tetexec.cfg @@ -0,0 +1,5 @@ +TET_OUTPUT_CAPTURE=True # capturing execution or not +TET_EXEC_TOOL= # ex) exec : execution tool set up/ Optional +TET_EXEC_FILE= # ex) exectool : execution file/ Optional +TET_API_COMPLIANT=True # Test case or Tool usesTET API? +TET_PASS_TC_NAME=True # showing Passed TC name ? diff --git a/debian/changelog b/debian/changelog new file mode 100755 index 0000000..72e2214 --- /dev/null +++ b/debian/changelog @@ -0,0 +1,614 @@ +nfc-manager (0.0.1-77) unstable; urgency=low + + * JSR257 NDEF absoluteURI issue resolved + * Git: slp/pkgs/n/nfc-manager + * Tag: nfc-manager_0.0.1-77 + + -- Sechang Sohn Thu, 31 May 2012 10:18:24 +0900 + +nfc-manager (0.0.1-76) unstable; urgency=low + + * Add the function checking nfc feature + * Git: slp/pkgs/n/nfc-manager + * Tag: nfc-manager_0.0.1-76 + + -- Wonkyu Kwon Wed, 30 May 2012 16:24:50 +0900 + +nfc-manager (0.0.1-75) unstable; urgency=low + + * Modify the plugin check routine + * Git: slp/pkgs/n/nfc-manager + * Tag: nfc-manager_0.0.1-75 + + -- Sungjae Lim Thu, 24 May 2012 17:00:11 +0900 + +nfc-manager (0.0.1-74) unstable; urgency=low + + * Add signature RTD library and ndef-tool + * Git: slp/pkgs/n/nfc-manager + * Tag: nfc-manager_0.0.1-74 + + -- Wonkyu Kwon Mon, 21 May 2012 15:32:08 +0900 + +nfc-manager (0.0.1-73) unstable; urgency=low + + * Modify the Private vconf. + * Git: slp/pkgs/n/nfc-manager + * Tag: nfc-manager_0.0.1-73 + + -- Sungjae Lim Mon, 16 May 2012 11:00:11 +0900 + +nfc-manager (0.0.1-72) unstable; urgency=low + + * Modify the absolute uri. + * Git: slp/pkgs/n/nfc-manager + * Tag: nfc-manager_0.0.1-72 + + -- Sungjae Lim Mon, 14 May 2012 17:00:11 +0900 + +nfc-manager (0.0.1-71) unstable; urgency=low + + * Add the routine to initialize the vconf for nfc + * Git: slp/pkgs/n/nfc-manager + * Tag: nfc-manager_0.0.1-71 + + -- Junyong Sim Mon, 07 May 2012 16:37:50 +0900 + +nfc-manager (0.0.1-70) unstable; urgency=low + + * Remove unused file + * Git: slp/pkgs/n/nfc-manager + * Tag: nfc-manager_0.0.1-70 + + -- Wonkyu Kwon Fri, 04 May 2012 14:21:29 +0900 + +nfc-manager (0.0.1-69) unstable; urgency=low + + * Add the pm's lock&unlock api. + * Git: slp/pkgs/n/nfc-manager + * Tag: nfc-manager_0.0.1-69 + + -- Sungjae Lim Thu, 03 May 2012 17:00:11 +0900 + +nfc-manager (0.0.1-68) unstable; urgency=low + + * Remove the nfc-agent's daemon + * Git: slp/pkgs/n/nfc-manager + * Tag: nfc-manager_0.0.1-68 + + -- Sungjae Lim Thu, 26 Apr 2012 17:17:17 +0900 + +nfc-manager (0.0.1-67) unstable; urgency=low + + * initialize vconf value : db/nfc/feature + * Git: slp/pkgs/n/nfc-manager + * Tag: nfc-manager_0.0.1-67 + + -- Junyong Sim Tue, 24 Apr 2012 21:17:17 +0900 + +nfc-manager (0.0.1-66) unstable; urgency=low + + * apply the access control in SE transaction. + * Git: slp/pkgs/n/nfc-manager + * Tag: nfc-manager_0.0.1-66 + + -- Wonkyu Kwon Fri, 20 Apr 2012 11:00:00 +0900 + +nfc-manager (0.0.1-65) unstable; urgency=low + + * Check the state using nfc set state func + * Git: slp/pkgs/n/nfc-manager + * Tag: nfc-manager_0.0.1-65 + + -- Sungjae Lim Thu, 19 Apr 2012 13:54:15 +0900 + +nfc-manager (0.0.1-64) unstable; urgency=low + + * Modify the spec & net_nfc_set_state's return value + * Git: slp/pkgs/n/nfc-manager + * Tag: nfc-manager_0.0.1-64 + + -- Sungjae Lim Thu, 05 Apr 2012 19:32:15 +0900 + +nfc-manager (0.0.1-63) unstable; urgency=low + + * package upload + * Git: slp/pkgs/n/nfc-manager + * Tag: nfc-manager_0.0.1-63 + + -- Sungjae Lim Wed, 04 Apr 2012 16:58:15 +0900 + +nfc-manager (0.0.1-62) unstable; urgency=low + + * Check the plugin's so file for Pulic Version + * Git: slp/pkgs/n/nfc-manager + * Tag: nfc-manager_0.0.1-62 + + -- Sungjae Lim Wed, 04 Apr 2012 10:58:15 +0900 + +nfc-manager (0.0.1-61) unstable; urgency=low + + * Add the routine to check tag stage + * Git: slp/pkgs/n/nfc-manager + * Tag: nfc-manager_0.0.1-61 + + -- Junyong Sim Thu, 29 Mar 2012 14:38:15 +0900 + +nfc-manager (0.0.1-60) unstable; urgency=low + + * Modify SE event + * Git: slp/pkgs/n/nfc-manager + * Tag: nfc-manager_0.0.1-60 + + -- Sangsoo Lee Fri, 16 Mar 2012 16:11:31 +0900 + +nfc-manager (0.0.1-59) unstable; urgency=low + + * change appsvc operation + * Git: slp/pkgs/n/nfc-manager + * Tag: nfc-manager_0.0.1-59 + + -- Wonkyu Kwon Thu, 15 Mar 2012 15:30:00 +0900 + +nfc-manager (0.0.1-58) unstable; urgency=low + + * bug fix about trans param + * Git: slp/pkgs/n/nfc-manager + * Tag: nfc-manager_0.0.1-58 + + -- Sangsoo Lee Thu, 15 Mar 2012 11:06:38 +0900 + +nfc-manager (0.0.1-57) unstable; urgency=low + + * remove capi dependency + * Git: slp/pkgs/n/nfc-manager + * Tag: nfc-manager_0.0.1-57 + + -- Junyong Sim Wed, 14 Mar 2012 19:54:13 +0900 + +nfc-manager (0.0.1-56) unstable; urgency=low + + * Broadcasting enable + * Git: slp/pkgs/n/nfc-manager + * Tag: nfc-manager_0.0.1-56 + + -- Sangsoo Lee Mon, 12 Mar 2012 16:52:39 +0900 + +nfc-manager (0.0.1-55) unstable; urgency=low + + * Tag connection check api change + * Git: slp/pkgs/n/nfc-manager + * Tag: nfc-manager_0.0.1-55 + + -- Sangsoo Lee Wed, 07 Mar 2012 17:21:51 +0900 + +nfc-manager (0.0.1-54) unstable; urgency=low + + * add new client api + * Git: slp/pkgs/n/nfc-manager + * Tag: nfc-manager_0.0.1-54 + + -- Sangsoo Lee Tue, 06 Mar 2012 20:30:19 +0900 + +nfc-manager (0.0.1-53) unstable; urgency=low + + * fix the crash issue of nfc manager in emulator + * Git: slp/pkgs/n/nfc-manager + * Tag: nfc-manager_0.0.1-53 + + -- Junyong Sim Mon, 05 Mar 2012 10:02:00 +0900 + +nfc-manager (0.0.1-52) unstable; urgency=low + + * Upload package + * Git: slp/pkgs/n/nfc-manager + * Tag: nfc-manager_0.0.1-52 + + -- Wonkyu Kwon Mon, 27 Feb 2012 17:00:00 +0900 + +nfc-manager (0.0.1-51) unstable; urgency=low + + * Implement the check routin to distinguish the driver + * Git: slp/pkgs/n/nfc-manager + * Tag: nfc-manager_0.0.1-51 + + -- Sechang Sohn Tue, 21 Feb 2012 13:06:37 +0900 + +nfc-manager (0.0.1-50) unstable; urgency=low + + * Implement the check routin to distinguish the driver + * Git: slp/pkgs/n/nfc-manager + * Tag: nfc-manager_0.0.1-50 + + -- Sungjae Lim Mon, 20 Feb 2012 10:36:28 +0900 + +nfc-manager (0.0.1-49) unstable; urgency=low + + * Update changelog + * Git: slp/pkgs/n/nfc-manager + * Tag: nfc-manager_0.0.1-49 + + -- Junyong Sim Mon, 06 Feb 2012 10:36:28 +0900 + +nfc-manager (0.0.1-48) unstable; urgency=low + + * Implement the polling loop after wake-up. + * Git: slp/pkgs/n/nfc-manager + * Tag: nfc-manager_0.0.1-48 + + -- Sungjae Lim Fri, 03 Feb 2012 14:47:35 +0900 + +nfc-manager (0.0.1-47) unstable; urgency=low + + * Modify the LTO value from 10 to 100. + * Git: slp/pkgs/n/nfc-manager + * Tag: nfc-manager_0.0.1-47 + + -- Sungjae Lim Wed, 01 Feb 2012 09:23:35 +0900 + +nfc-manager (0.0.1-46) unstable; urgency=low + + * Fix build error when is using cxx compiler + * Git: slp/pkgs/n/nfc-manager + * Tag: nfc-manager_0.0.1-46 + + -- Wonkyu Kwon Thu, 26 Jan 2012 15:00:35 +0900 + +nfc-manager (0.0.1-45) unstable; urgency=low + + * Change IPC request algorithm from client to server + * Git: slp/pkgs/n/nfc-manager + * Tag: nfc-manager_0.0.1-45 + + -- Wonkyu Kwon Thu, 29 Dec 2011 13:00:35 +0900 + +nfc-manager (0.0.1-44) unstable; urgency=low + + * modify changelog + * Git: slp/pkgs/n/nfc-manager + * Tag: nfc-manager_0.0.1-44 + + -- Junyong Sim Thu, 15 Dec 2011 18:58:35 +0900 + +nfc-manager (0.0.1-43) unstable; urgency=low + + * Change ambiguous value name and option name + * Git: 165.213.180.234:slp/pkgs/n/nfc-manager + * Tag: nfc-manager_0.0.1-43 + + -- Sangsoo Lee Wed, 07 Dec 2011 12:45:19 +0900 + +nfc-manager (0.0.1-42) unstable; urgency=low + + * Clean unused code + * Git: 165.213.180.234:slp/pkgs/n/nfc-manager + * Tag: nfc-manager_0.0.1-42 + + -- Wonkyu kwon Tue, 06 Dec 2011 17:40:00 +0900 + +nfc-manager (0.0.1-41) unstable; urgency=low + + *Modify the code + *Git: 165.213.180.234:slp/pkgs/n/nfc-manager + *Tag: nfc-manager_0.0.1-41 + + -- Sungjae Lim Tue, 06 Dec 2011 12:40:45 +0900 + +nfc-manager (0.0.1-40) unstable; urgency=low + + *Change AUTHORS. + *Git: 165.213.180.234:slp/pkgs/n/nfc-manager + *Tag: nfc-manager_0.0.1-40 + + -- Junyong Sim Sat, 03 Dec 2011 13:05:45 +0900 + +nfc-manager (0.0.1-39) unstable; urgency=low + + *Package Upload. + *Git: 165.213.180.234:slp/pkgs/n/nfc-manager + *Tag: nfc-manager_0.0.1-39 + + -- sungjae.lim Fri, 02 Dec 2011 19:57:07 +0900 + +nfc-manager (0.0.1-38) unstable; urgency=low + + *Change the boilerplate. + *Git: 165.213.180.234:slp/pkgs/n/nfc-manager + *Tag: nfc-manager_0.0.1-38 + + -- sungjae.lim Fri, 02 Dec 2011 19:00:07 +0900 + +nfc-manager (0.0.1-37) unstable; urgency=low + + *Change the function name for 3rd part. + *Git: 165.213.180.234:slp/pkgs/n/nfc-manager + *Tag: nfc-manager_0.0.1-37 + + -- sungjae.lim Fri, 02 Dec 2011 11:20:07 +0900 + +nfc-manager (0.0.1-36) unstable; urgency=low + + *Bug fix. + *Git: 165.213.180.234:slp/pkgs/n/nfc-manager + *Tag: nfc-manager_0.0.1-36 + + -- constant.lee Thu, 01 Dec 2011 21:08:07 +0900 + +nfc-manager (0.0.1-35) unstable; urgency=low + + *Change the boilerplate. + *Git: 165.213.180.234:slp/pkgs/n/nfc-manager + *Tag: nfc-manager_0.0.1-35 + + -- Sungjae Lim Thu, 01 Dec 2011 15:55:42 +0900 + +nfc-manager (0.0.1-34) unstable; urgency=low + + * Package upload + * Git: 165.213.180.234:slp/pkgs/n/nfc-manager + * Tag: nfc-manager_0.0.1-34 + + -- Wonkyu Kwon Wed, 30 Nov 2011 18:00:00 +0900 + +nfc-manager (0.0.1-33) unstable; urgency=low + + *some error value change + *Git: 165.213.180.234:slp/pkgs/n/nfc-manager + *Tag: nfc-manager_0.0.1-33 + + -- Sangsoo Lee Tue, 29 Nov 2011 14:45:40 +0900 + +nfc-manager (0.0.1-32) unstable; urgency=low + + *NET_NFC_MESSSAGE_P2P_RECEIVE problem fix + *Git: 165.213.180.234:slp/pkgs/n/nfc-manager + *Tag: nfc-manager_0.0.1-32 + + -- Sangsoo Lee Tue, 29 Nov 2011 13:07:01 +0900 + +nfc-manager (0.0.1-31) unstable; urgency=low + + *p2p popup problem fix. + *Git: 165.213.180.234:slp/pkgs/n/nfc-manager + *Tag: nfc-manager_0.0.1-31 + + -- Sangsoo Lee Fri, 25 Nov 2011 15:04:48 +0900 + +nfc-manager (0.0.1-30) unstable; urgency=low + + *bug fix + *Git: 165.213.180.234:slp/pkgs/n/nfc-manager + *Tag : nfc-manager_0.0.1-30 + + -- Sangsoo Lee Fri, 18 Nov 2011 12:45:58 +0900 + +nfc-manager (0.0.1-29) unstable; urgency=low + + *LLCP problem was fixed. and some message name change. + *Git: 165.213.180.234:slp/pkgs/n/nfc-manager + *Tag: nfc-manager_0.0.1-29 + + -- Sangsoo Lee Wed, 16 Nov 2011 22:55:18 +0900 + +nfc-manager (0.0.1-28) unstable; urgency=low + + *NXP parser was seperated to net_nfc_util_ndef_parser.c + *Git: 165.213.180.234:slp/pkgs/n/nfc-manager + *Tag: nfc-manager_0.0.1-28 + + -- Sangsoo Lee Wed, 02 Nov 2011 18:30:57 +0900 + +nfc-manager (0.0.1-27) unstable; urgency=low + + *Modify app launch condition + *Git: 165.213.180.234:slp/pkgs/n/nfc-manager + *Tag: nfc-manager_0.0.1-27 + + -- Wonkyu Kwon Wed, 02 Nov 2011 13:50:00 +0900 + +nfc-manager (0.0.1-26) unstable; urgency=low + + *ndef memory problem fix + *Git: 165.213.180.234:slp/pkgs/n/nfc-manager + *Tag: nfc-manager_0.0.1-26 + + -- Sangsoo Lee Mon, 31 Oct 2011 17:54:56 +0900 + +nfc-manager (0.0.1-25) unstable; urgency=low + + *LLCP flow change. + *Git: 165.213.180.234:slp/pkgs/n/nfc-manager + *Tag: nfc-manager_0.0.1-25 + + -- Sangsoo Lee Fri, 28 Oct 2011 14:57:26 +0900 + +nfc-manager (0.0.1-24) unstable; urgency=low + + *Change the boilerplate. + *Git: 165.213.180.234:slp/pkgs/n/nfc-manager + *Tag: nfc-manager_0.0.1-24 + + -- Sungjae Lim Thu, 27 Oct 2011 14:55:42 +0900 + +nfc-manager (0.0.1-23) unstable; urgency=low + + *Add the NPP for android NFC. + *Git: 165.213.180.234:slp/pkgs/n/nfc-manager + *Tag: nfc-manager_0.0.1-23 + + -- Sungjae Lim Wed, 26 Oct 2011 17:19:02 +0900 + +nfc-manager (0.0.1-22) unstable; urgency=low + + *Modify the code for Prevent. + *Git: 165.213.180.234:slp/pkgs/n/nfc-manager + *Tag: nfc-manager_0.0.1-22 + + -- Sungjae Lim Mon, 24 Oct 2011 19:38:59 +0900 + +nfc-manager (0.0.1-21ubuntu2) unstable; urgency=low + + *add server state. + *Git: 165.213.180.234:slp/pkgs/n/nfc-manager + *Tag: nfc-manager_0.0.1-21 + + -- Sangsoo Lee Wed, 12 Oct 2011 20:10:02 +0900 + +nfc-manager (0.0.1-20ubuntu1) unstable; urgency=low + + *bug fix. when read ndef fail, data was free two times. + *Git: 165.213.180.234:slp/pkgs/n/nfc-manager + *Tag: nfc-manager_0.0.1-20 + + -- Sangsoo Lee Mon, 10 Oct 2011 18:51:42 +0900 + +nfc-manager (0.0.1-19) unstable; urgency=low + + *Add message broadcasting. and implement net_nfc_get_server_state + *Git: 165.213.180.234:slp/pkgs/n/nfc-manager + *Tag: nfc-manager_0.0.1-19 + + -- Sangsoo Lee Thu, 06 Oct 2011 16:01:59 +0900 + +nfc-manager (0.0.1-18) unstable; urgency=low + + *Add the prefix net to the NFC Manager FW + *Git: 165.213.180.234:slp/pkgs/n/nfc-manager + *Tag: nfc-manager_0.0.1-18 + + -- Sungjae Lim Thu, 22 Sep 2011 16:51:30 +0900 + +nfc-manager (0.0.1-17) unstable; urgency=low + + *Add the prefix net to the common and client lib + *Git: 165.213.180.234:slp/pkgs/n/nfc-manager + *Tag: nfc-manager_0.0.1-17 + + -- Sungjae Lim Tue, 20 Sep 2011 10:48:30 +0900 + +nfc-manager (0.0.1-16) unstable; urgency=low + + *Modify the manager for setting and exchanger + *Git: 165.213.180.234:slp/pkgs/n/nfc-manager + *Tag: nfc-manager_0.0.1-16 + + -- Sungjae Lim Wed, 7 Sep 2011 19:19:20 +0900 + +nfc-manager (0.0.1-15) unstable; urgency=low + + * add NDEF parser + * Git: 165.213.180.234:slp/pkgs/n/nfc-manager + * Tag: nfc-manager_0.0.1-15 + + -- Sangsoo Lee Wed, 24 Aug 2011 15:27:30 +0900 + +nfc-manager (0.0.1-14) unstable; urgency=low + + * change the traceive function parameter + * Git: 165.213.180.234:slp/pkgs/n/nfc-manager + * Tag: nfc-manager_0.0.1-14 + + -- root Mon, 27 Jun 2011 20:15:09 +0900 + +nfc-manager (0.0.1-13) unstable; urgency=low + + * updates package for CAPI + * Git: 165.213.180.234:slp/pkgs/n/nfc-manager + * Tag: nfc-manager_0.0.1-13 + + -- root Fri, 24 Jun 2011 18:52:20 +0900 + +nfc-manager (0.0.1-12) unstable; urgency=low + + * adding missing header file + * Git: 165.213.180.234:slp/pkgs/n/nfc-manager + * Tag: nfc-manager_0.0.1-12 + + -- root Wed, 15 Jun 2011 10:04:58 +0900 + +nfc-manager (0.0.1-11) unstable; urgency=low + + * Change llcp connection policy and sepcific API for tags + * Git: 165.213.180.234:slp/pkgs/n/nfc-manager + * Tag: nfc-manager_0.0.1-11 + + -- root Wed, 15 Jun 2011 09:47:21 +0900 + +nfc-manager (0.0.1-10) unstable; urgency=low + + * fix the compile error and add comments of exception + * Git: 165.213.180.234:slp/pkgs/n/nfc-manager + * Tag: nfc-manager_0.0.1-10 + + -- root Wed, 18 May 2011 14:31:45 +0900 + +nfc-manager (0.0.1-9) unstable; urgency=low + + * update NFC manager API and split the solution package and manger package + * Git: 165.213.180.234:slp/pkgs/n/nfc-manager + * Tag: nfc-manager_0.0.1-9 + + -- root Wed, 18 May 2011 14:27:37 +0900 + +nfc-manager (0.0.1-8) unstable; urgency=low + + * remove the dependency of bt-engine + * Git: 165.213.180.234:slp/pkgs/n/nfc-manager + * Tag: nfc-manager_0.0.1-8 + + -- Bumjoon Kim Fri, 11 Mar 2011 09:52:48 +0900 + +nfc-manager (0.0.1-7) unstable; urgency=low + + * fix the prevent issues extra + * Git: 165.213.180.234:slp/pkgs/n/nfc-manager + * Tag: nfc-manager_0.0.1-7 + + -- Bumjoon Kim Thu, 17 Feb 2011 17:12:47 +0900 + +nfc-manager (0.0.1-6) unstable; urgency=low + + * fix the prevent issues + * Git: 165.213.180.234:slp/pkgs/n/nfc-manager + * Tag: nfc-manager_0.0.1-6 + + -- Bumjoon Kim Tue, 15 Feb 2011 21:12:22 +0900 + +nfc-manager (0.0.1-5) unstable; urgency=low + + * enhance the stablity of nfc-manager + * Git: 165.213.180.234:slp/pkgs/n/nfc-manager + * Tag: nfc-manager_0.0.1-5 + + -- Bumjoon Kim Tue, 01 Feb 2011 18:21:56 +0900 + +nfc-manager (0.0.1-4) unstable; urgency=low + + * Vice President demo version + * Git: 165.213.180.234:slp/pkgs/n/nfc-manager + * Tag: nfc-manager_0.0.1-4 + + -- Bumjoon Kim Thu, 27 Jan 2011 13:49:18 +0900 + +nfc-manager (0.0.1-3) unstable; urgency=low + + * adding settup switch to enable disable nfc-manager + * Git: 165.213.180.234:slp/pkgs/n/nfc-manager + * Tag: nfc-manager_0.0.1-3 + + -- Bumjoon Kim Mon, 24 Jan 2011 16:21:44 +0900 + +nfc-manager (0.0.1-2) unstable; urgency=low + + * nfc-manager and stand alone mode is enabled + * Git: 165.213.180.234:slp/pkgs/n/nfc-manager + * Tag: nfc-manager_0.0.1-2 + + -- Bumjoon Kim Tue, 04 Jan 2011 20:21:19 +0900 + +nfc-manager (0.0.1-1) unstable; urgency=low + + * first source package for building + + -- hyogil.kim Wed, 3 Nov 2010 13:43:34 +0900 + diff --git a/debian/compat b/debian/compat new file mode 100755 index 0000000..7ed6ff8 --- /dev/null +++ b/debian/compat @@ -0,0 +1 @@ +5 diff --git a/debian/control b/debian/control new file mode 100755 index 0000000..5706b1d --- /dev/null +++ b/debian/control @@ -0,0 +1,42 @@ +Source: nfc-manager +Section: libs +Priority: extra +Maintainer: Sangsoo Lee , Sungjae Lim , Sechang Sohn +Build-Depends: debhelper (>= 5), libaul-1-dev, libglib2.0-dev, libvconf-dev, libsecurity-server-client-dev, libbluetooth-frwk-dev,libdbus-glib-1-dev, dlog-dev, libecore-dev, libslp-tapi-dev, libappsvc-dev, libcurl-dev, libheynoti-dev, libsvi-dev, libssl-dev, smartcard-service-dev, smartcard-service-common-dev, libslp-pm-dev +Standards-Version: 0.0.1 + +Package: libnfc-common-lib-0 +Section: libs +Architecture: any +Depends: ${shlibs:Depends}, ${misc:Depends} +Description: NFC Common Library + +Package: libnfc-common-lib-dev +Section: libs +Architecture: any +Depends: ${misc:Depends}, libnfc-common-lib-0 (= ${Source-Version}) +Description: NFC Common Library + +Package: libnfc-common-lib-dbg +Section: debug +Architecture: any +Depends: ${misc:Depends}, libnfc-common-lib-0 (= ${Source-Version}) +Description: NFC Common Library (unstripped) + +Package: libnfc-manager-0 +Section: libs +Architecture: any +Depends: ${shlibs:Depends}, ${misc:Depends}, libnfc-common-lib-0 (= ${Source-Version}) +Description: NFC freamework + +Package: libnfc-manager-dev +Section: libs +Architecture: any +Depends: ${misc:Depends}, libnfc-manager-0 (= ${Source-Version}) +Description: NFC freamework + +Package: libnfc-manager-dbg +Section: debug +Architecture: any +Depends: ${misc:Depends}, libnfc-manager-0 (= ${Source-Version}) +Description: NFC-manager (unstripped) diff --git a/debian/libnfc-common-lib-0.install.in b/debian/libnfc-common-lib-0.install.in new file mode 100755 index 0000000..0a7df14 --- /dev/null +++ b/debian/libnfc-common-lib-0.install.in @@ -0,0 +1 @@ +@PREFIX@/lib/libnfc-common-lib.so.* diff --git a/debian/libnfc-common-lib-0.postinst.in b/debian/libnfc-common-lib-0.postinst.in new file mode 100755 index 0000000..2993487 --- /dev/null +++ b/debian/libnfc-common-lib-0.postinst.in @@ -0,0 +1,8 @@ +#!/bin/sh +#Add boot sequence script +if [ ${USER} == "root" ] +then +vconftool set -t bool memory/private/nfc-manager/popup_disabled 0 -u 5000 +else +vconftool set -t bool memory/private/nfc-manager/popup_disabled 0 +fi diff --git a/debian/libnfc-common-lib-dbg.install.in b/debian/libnfc-common-lib-dbg.install.in new file mode 100755 index 0000000..8b13789 --- /dev/null +++ b/debian/libnfc-common-lib-dbg.install.in @@ -0,0 +1 @@ + diff --git a/debian/libnfc-common-lib-dev.install.in b/debian/libnfc-common-lib-dev.install.in new file mode 100755 index 0000000..836131f --- /dev/null +++ b/debian/libnfc-common-lib-dev.install.in @@ -0,0 +1,3 @@ +@PREFIX@/lib/pkgconfig/nfc-common-lib.pc +@PREFIX@/include/nfc-common-lib/* +@PREFIX@/lib/libnfc-common-lib.so diff --git a/debian/libnfc-manager-0.init.in b/debian/libnfc-manager-0.init.in new file mode 100755 index 0000000..c5557cc --- /dev/null +++ b/debian/libnfc-manager-0.init.in @@ -0,0 +1,23 @@ +#!/bin/sh +### BEGIN INIT INFO +# Provides: nfc-agent +# Required-Start: +# Required-Stop: +# Default-Start: 3 5 +# Default-Stop: 0 +# Short-Description: NFC agent +# Description: NFC agent +# +# +### END INIT INFO + +# Author: Wonkyu Kwon + +# PATH should only include /usr/* if it runs after the mountnfs.sh script +DAEMON=/usr/bin/nfc-manager-daemon +DAEMON_ARGS="" # Arguments to run the daemon with + +# Exit if the package is not installed +[ -x $DAEMON ] || exit 0 + +$DAEMON $DAEMON_ARGS & diff --git a/debian/libnfc-manager-0.install.in b/debian/libnfc-manager-0.install.in new file mode 100755 index 0000000..71fe461 --- /dev/null +++ b/debian/libnfc-manager-0.install.in @@ -0,0 +1,5 @@ +@PREFIX@/lib/libnfc.so.* +@PREFIX@/bin/* +/etc/init.d/* +/etc/rc.d/* + diff --git a/debian/libnfc-manager-0.postinst.in b/debian/libnfc-manager-0.postinst.in new file mode 100644 index 0000000..30520f4 --- /dev/null +++ b/debian/libnfc-manager-0.postinst.in @@ -0,0 +1,12 @@ +#!/bin/sh +#Add boot sequence script +if [ ${USER} == "root" ] +then +vconftool set -t bool db/nfc/feature 0 -u 5000 +vconftool set -t bool db/nfc/enable 0 -u 5000 +vconftool set -t bool db/nfc/sbeam 0 -u 5000 +else +vconftool set -t bool db/nfc/feature 0 +vconftool set -t bool db/nfc/enable 0 +vconftool set -t bool db/nfc/sbeam 0 +fi diff --git a/debian/libnfc-manager-dbg.install.in b/debian/libnfc-manager-dbg.install.in new file mode 100755 index 0000000..8b13789 --- /dev/null +++ b/debian/libnfc-manager-dbg.install.in @@ -0,0 +1 @@ + diff --git a/debian/libnfc-manager-dev.install.in b/debian/libnfc-manager-dev.install.in new file mode 100755 index 0000000..52e34bd --- /dev/null +++ b/debian/libnfc-manager-dev.install.in @@ -0,0 +1,3 @@ +@PREFIX@/lib/pkgconfig/nfc.pc +@PREFIX@/include/nfc/* +@PREFIX@/lib/libnfc.so diff --git a/debian/rules b/debian/rules new file mode 100755 index 0000000..22a2767 --- /dev/null +++ b/debian/rules @@ -0,0 +1,132 @@ +#!/usr/bin/make -f +# -*- makefile -*- +# Sample debian/rules that uses debhelper. +# This file was originally written by Joey Hess and Craig Small. +# As a special exception, when this file is copied by dh-make into a +# dh-make output file, you may use that output file without restriction. +# This special exception was added by Craig Small in version 0.37 of dh-make. + +# Uncomment this to turn on verbose mode. +#export DH_VERBOSE=1 + +CFLAGS ?= -Wall -g +CXXFLAGS ?= -Wall -g +LDFLAGS ?= +PREFIX ?= /usr + +ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS))) + CFLAGS += -O0 + CXXFLAGS += -O0 +else + CFLAGS += -O2 + CXXFLAGS += -O2 +endif + +LDFLAGS += -Wl,--rpath=$(PREFIX)/lib -Wl,--as-needed + +CMAKE_TMP_DIR = $(CURDIR)/cmake_tmp + + +configure: configure-stamp +configure-stamp: + dh_testdir + # Add here commands to configure the package. + mkdir -p $(CMAKE_TMP_DIR); + cd $(CMAKE_TMP_DIR); CFLAGS="$(CFLAGS)" CXXFLAGS="$(CXXFLAGS)" LDFLAGS="$(LDFLAGS)" cmake .. -DCMAKE_INSTALL_PREFIX=$(PREFIX) + + touch configure-stamp + +build: build-stamp + +build-stamp: configure-stamp + dh_testdir + + # Add here commands to compile the package. + cd $(CMAKE_TMP_DIR) && $(MAKE) + #docbook-to-man debian/wavplayer.sgml > wavplayer.1 + + for f in `find $(CURDIR)/debian/ -name "*.in"`; do \ + cat $$f > $${f%.in}; \ + sed -i -e "s#@PREFIX@#$(PREFIX)#g" $${f%.in}; \ + done + + + touch $@ + +clean: + dh_testdir + dh_testroot + rm -f build-stamp configure-stamp + + # Add here commands to clean up after the build process. + -cd $(CMAKE_TMP_DIR) && $(MAKE) clean + rm -rf $(CMAKE_TMP_DIR) + + rm -rf CMakeCache.txt + rm -rf CMakeFiles + rm -rf cmake_install.cmake + rm -rf Makefile + rm -rf install_manifest.txt + rm -rf *.so + + for f in `find $(CURDIR)/debian/ -name "*.in"`; do \ + rm -f $${f%.in}; \ + done + + dh_clean + +install: build + dh_testdir + dh_testroot + dh_clean -k + dh_installdirs + + mkdir -p $(CURDIR)/debian/tmp/etc/init.d + cp -af $(CURDIR)/debian/libnfc-manager-0.init.in $(CURDIR)/debian/tmp/etc/init.d/libnfc-manager-0 + + # Add here commands to install the package into debian/wavplayer. + cd $(CMAKE_TMP_DIR) && $(MAKE) DESTDIR=$(CURDIR)/debian/tmp install + + mkdir -p $(CURDIR)/debian/tmp/etc/rc.d/rc3.d/ + mkdir -p $(CURDIR)/debian/tmp/etc/rc.d/rc5.d/ + + ln -s /etc/init.d/libnfc-manager-0 $(CURDIR)/debian/tmp/etc/rc.d/rc3.d/S81libnfc-manager-0 + ln -s /etc/init.d/libnfc-manager-0 $(CURDIR)/debian/tmp/etc/rc.d/rc5.d/S81libnfc-manager-0 + +# Build architecture-independent files here. +binary-indep: build install +# We have nothing to do by default. + +# Build architecture-dependent files here. +binary-arch: build install + dh_testdir + dh_testroot +# dh_installchangelogs +# dh_installdocs +# dh_installexamples + dh_install --sourcedir=debian/tmp +# dh_installmenu +# dh_installdebconf +# dh_installlogrotate +# dh_installemacsen +# dh_installpam +# dh_installmime +# dh_python +# dh_installinit +# dh_installcron +# dh_installinfo +# dh_installman + dh_link + dh_strip --dbg-package=libnfc-manager-dbg --dbg-package=libnfc-common-lib-dbg + dh_compress + dh_fixperms +# dh_perl + dh_makeshlibs + dh_installdeb + dh_shlibdeps + dh_gencontrol + dh_md5sums + dh_builddeb + +binary: binary-indep binary-arch +.PHONY: build clean binary-indep binary-arch binary install configure diff --git a/doxygen/createdoc.sh b/doxygen/createdoc.sh new file mode 100755 index 0000000..42b1939 --- /dev/null +++ b/doxygen/createdoc.sh @@ -0,0 +1,41 @@ +#!/bin/bash + +# Create doxygen from debian package server +# By Jungbae Lee (yi_jungbae@samsung.com) + +#cd `dirname $0` +CWD=`pwd` + +# Use doxygen 1.7.0 +#export PATH=${PATH} +#export LD_LIBRARY_PATH=${LD_LIBRARY_PATH} + + +### Configuration +SBOX=/scratchbox/users/$USER/home/$USER +DOXYGEN_OUTPUT_DIR=$CWD/doxygen_output +DOXYGEN=doxygen +DOXY_CONF=doxygen.conf +IMAGE_DIR=images #need to change +#IMAGE_DIR=[fill your image path] + + + +####doxygen configuration :: output Directory +mkdir $DOXYGEN_OUTPUT_DIR + +echo "Doxygen running..." +if [ ! -e $CWD/doxygen_output ]; then + mkdir $CWD/doxygen_output +fi +# Run doxygen +$DOXYGEN $DOXY_CONF 2>&1 + +#image copy +if [ -d $CWD/$IMAGE_DIR ];then +cp $CWD/$IMAGE_DIR $DOXYGEN_OUTPUT_DIR/html/ -rf +fi + +echo "Finished!" +exit; + diff --git a/doxygen/doxygen.conf b/doxygen/doxygen.conf new file mode 100755 index 0000000..88ef801 --- /dev/null +++ b/doxygen/doxygen.conf @@ -0,0 +1,852 @@ +# Doxyfile 1.5.2 + +# This file describes the settings to be used by the documentation system +# doxygen (www.doxygen.org) for a project +# +# All text after a hash (#) is considered a comment and will be ignored +# The format is: +# TAG = value [value, ...] +# For lists items can also be appended using: +# TAG += value [value, ...] +# Values that contain spaces should be placed between quotes (" ") + +#--------------------------------------------------------------------------- +# Project related configuration options +#--------------------------------------------------------------------------- + +DOXYFILE_ENCODING = UTF-8 +PROJECT_NAME = SLP-Developer Library +PROJECT_NUMBER = +OUTPUT_DIRECTORY = ./doxygen_output +CREATE_SUBDIRS = NO +OUTPUT_LANGUAGE = English +BRIEF_MEMBER_DESC = YES +REPEAT_BRIEF = YES +ABBREVIATE_BRIEF = NO +ALWAYS_DETAILED_SEC = YES +INLINE_INHERITED_MEMB = NO +FULL_PATH_NAMES = NO +STRIP_FROM_PATH = +STRIP_FROM_INC_PATH = +SHORT_NAMES = YES +JAVADOC_AUTOBRIEF = NO +MULTILINE_CPP_IS_BRIEF = NO +DETAILS_AT_TOP = YES +INHERIT_DOCS = YES +SEPARATE_MEMBER_PAGES = YES +TAB_SIZE = 8 +ALIASES = +OPTIMIZE_OUTPUT_FOR_C = NO +OPTIMIZE_OUTPUT_JAVA = NO +BUILTIN_STL_SUPPORT = NO +CPP_CLI_SUPPORT = NO +DISTRIBUTE_GROUP_DOC = NO +SUBGROUPING = YES + +#--------------------------------------------------------------------------- +# Build related configuration options +#--------------------------------------------------------------------------- + +EXTRACT_ALL = YES +EXTRACT_PRIVATE = YES +EXTRACT_STATIC = YES +EXTRACT_LOCAL_CLASSES = NO +EXTRACT_LOCAL_METHODS = YES +HIDE_UNDOC_MEMBERS = YES +HIDE_UNDOC_CLASSES = YES +HIDE_FRIEND_COMPOUNDS = YES +HIDE_IN_BODY_DOCS = NO +INTERNAL_DOCS = NO +CASE_SENSE_NAMES = YES +HIDE_SCOPE_NAMES = NO +SHOW_INCLUDE_FILES = YES +INLINE_INFO = YES +SORT_MEMBER_DOCS = YES +SORT_BRIEF_DOCS = YES +SORT_BY_SCOPE_NAME = YES +SORT_GROUP_NAMES = YES +GENERATE_TODOLIST = NO +USE_INLINE_TREES = NO +SHOW_NAMESPACES = NO +HTML DYNAMIC SECTIONS = YES +GENERATE_TESTLIST = NO +GENERATE_BUGLIST = NO +GENERATE_DEPRECATEDLIST= NO +ENABLED_SECTIONS = +MAX_INITIALIZER_LINES = 30 +SHOW_USED_FILES = YES +SHOW_DIRECTORIES = NO +FILE_VERSION_FILTER = + +#--------------------------------------------------------------------------- +# configuration options related to warning and progress messages +#--------------------------------------------------------------------------- + +# The QUIET tag can be used to turn on/off the messages that are generated +# by doxygen. Possible values are YES and NO. If left blank NO is used. + +QUIET = NO + +# The WARNINGS tag can be used to turn on/off the warning messages that are +# generated by doxygen. Possible values are YES and NO. If left blank +# NO is used. + +WARNINGS = YES + +# If WARN_IF_UNDOCUMENTED is set to YES, then doxygen will generate warnings +# for undocumented members. If EXTRACT_ALL is set to YES then this flag will +# automatically be disabled. + +WARN_IF_UNDOCUMENTED = YES + +# If WARN_IF_DOC_ERROR is set to YES, doxygen will generate warnings for +# potential errors in the documentation, such as not documenting some +# parameters in a documented function, or documenting parameters that +# don't exist or using markup commands wrongly. + +WARN_IF_DOC_ERROR = YES + +# This WARN_NO_PARAMDOC option can be abled to get warnings for +# functions that are documented, but have no documentation for their parameters +# or return value. If set to NO (the default) doxygen will only warn about +# wrong or incomplete parameter documentation, but not about the absence of +# documentation. + +WARN_NO_PARAMDOC = NO + +# The WARN_FORMAT tag determines the format of the warning messages that +# doxygen can produce. The string should contain the $file, $line, and $text +# tags, which will be replaced by the file and line number from which the +# warning originated and the warning text. Optionally the format may contain +# $version, which will be replaced by the version of the file (if it could +# be obtained via FILE_VERSION_FILTER) + +WARN_FORMAT = "$file:$line: $text" + +# The WARN_LOGFILE tag can be used to specify a file to which warning +# and error messages should be written. If left blank the output is written +# to stderr. + +WARN_LOGFILE = + +#--------------------------------------------------------------------------- +# configuration options related to the input files +#--------------------------------------------------------------------------- + +# The INPUT tag can be used to specify the files and/or directories that contain +# documented source files. You may enter file names like "myfile.cpp" or +# directories like "/usr/src/myproject". Separate the files or directories +# with spaces. + +#INPUT = .. +INPUT = ../src/commonlib/include/net_nfc_typedef.h ../src/clientlib/include/net_nfc_target_info.h ../src/clientlib/include/net_nfc_llcp.h ../src/clientlib/include/net_nfc_exchanger.h ../src/clientlib/include/net_nfc_ndef_message.h ../src/clientlib/include/net_nfc_data.h ../src/clientlib/include/net_nfc_ndef_record.h ../src/clientlib/include/net_nfc_apdu.h ../src/clientlib/include/net_nfc_tag.h ../src/clientlib/include/net_nfc.h ../src/clientlib/include/net_nfc_ndef_message_handover.h ../src/clientlib/include/net_nfc_tag_felica.h ../src/clientlib/include/net_nfc_tag_jewel.h ../src/clientlib/include/net_nfc_tag_mifare.h + + +# This tag can be used to specify the character encoding of the source files that +# doxygen parses. Internally doxygen uses the UTF-8 encoding, which is also the default +# input encoding. Doxygen uses libiconv (or the iconv built into libc) for the transcoding. +# See http://www.gnu.org/software/libiconv for the list of possible encodings. + +INPUT_ENCODING = UTF-8 +FILE_PATTERNS = *.h \ + *.doxy +RECURSIVE = YES +EXCLUDE = +EXCLUDE_SYMLINKS = NO +EXCLUDE_PATTERNS = */test/* \ + */debian/* \ + */lost+found/* \ + */i386/* \ + */arm/* \ + */simulator/* \ + *test* \ + */voda3rd/* +EXCLUDE_SYMBOLS = +EXAMPLE_PATH = +EXAMPLE_PATTERNS = +EXAMPLE_RECURSIVE = NO +IMAGE_PATH = ../image +INPUT_FILTER = +FILTER_PATTERNS = +FILTER_SOURCE_FILES = NO + +#--------------------------------------------------------------------------- +# configuration options related to source browsing +#--------------------------------------------------------------------------- + +# If the SOURCE_BROWSER tag is set to YES then a list of source files will +# be generated. Documented entities will be cross-referenced with these sources. +# Note: To get rid of all source code in the generated output, make sure also +# VERBATIM_HEADERS is set to NO. + +SOURCE_BROWSER = NO + +# Setting the INLINE_SOURCES tag to YES will include the body +# of functions and classes directly in the documentation. + +INLINE_SOURCES = NO + +# Setting the STRIP_CODE_COMMENTS tag to YES (the default) will instruct +# doxygen to hide any special comment blocks from generated source code +# fragments. Normal C and C++ comments will always remain visible. + +STRIP_CODE_COMMENTS = YES + +# If the REFERENCED_BY_RELATION tag is set to YES (the default) +# then for each documented function all documented +# functions referencing it will be listed. + +REFERENCED_BY_RELATION = YES + +# If the REFERENCES_RELATION tag is set to YES (the default) +# then for each documented function all documented entities +# called/used by that function will be listed. + +REFERENCES_RELATION = YES + +# If the REFERENCES_LINK_SOURCE tag is set to YES (the default) +# and SOURCE_BROWSER tag is set to YES, then the hyperlinks from +# functions in REFERENCES_RELATION and REFERENCED_BY_RELATION lists will +# link to the source code. Otherwise they will link to the documentstion. + +REFERENCES_LINK_SOURCE = YES + +# If the USE_HTAGS tag is set to YES then the references to source code +# will point to the HTML generated by the htags(1) tool instead of doxygen +# built-in source browser. The htags tool is part of GNU's global source +# tagging system (see http://www.gnu.org/software/global/global.html). You +# will need version 4.8.6 or higher. + +USE_HTAGS = NO + +# If the VERBATIM_HEADERS tag is set to YES (the default) then Doxygen +# will generate a verbatim copy of the header file for each class for +# which an include is specified. Set to NO to disable this. + +VERBATIM_HEADERS = YES + +#--------------------------------------------------------------------------- +# configuration options related to the alphabetical class index +#--------------------------------------------------------------------------- + +# If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index +# of all compounds will be generated. Enable this if the project +# contains a lot of classes, structs, unions or interfaces. + +ALPHABETICAL_INDEX = YES +COLS_IN_ALPHA_INDEX = 10 +IGNORE_PREFIX = + +#--------------------------------------------------------------------------- +# configuration options related to the HTML output +#--------------------------------------------------------------------------- + +# If the GENERATE_HTML tag is set to YES (the default) Doxygen will +# generate HTML output. + +GENERATE_HTML = YES + +# The HTML_OUTPUT tag is used to specify where the HTML docs will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `html' will be used as the default path. + +HTML_OUTPUT = html + +# The HTML_FILE_EXTENSION tag can be used to specify the file extension for +# each generated HTML page (for example: .htm,.php,.asp). If it is left blank +# doxygen will generate files with .html extension. + +HTML_FILE_EXTENSION = .html + +# The HTML_HEADER tag can be used to specify a personal HTML header for +# each generated HTML page. If it is left blank doxygen will generate a +# standard header. + +HTML_HEADER = + +# The HTML_FOOTER tag can be used to specify a personal HTML footer for +# each generated HTML page. If it is left blank doxygen will generate a +# standard footer. + +HTML_FOOTER = + +# The HTML_STYLESHEET tag can be used to specify a user-defined cascading +# style sheet that is used by each HTML page. It can be used to +# fine-tune the look of the HTML output. If the tag is left blank doxygen +# will generate a default style sheet. Note that doxygen will try to copy +# the style sheet file to the HTML output directory, so don't put your own +# stylesheet in the HTML output directory as well, or it will be erased! + +HTML_STYLESHEET =./slp_doxy.css + +# If the HTML_ALIGN_MEMBERS tag is set to YES, the members of classes, +# files or namespaces will be aligned in HTML using tables. If set to +# NO a bullet list will be used. + +HTML_ALIGN_MEMBERS = YES + +# If the GENERATE_HTMLHELP tag is set to YES, additional index files +# will be generated that can be used as input for tools like the +# Microsoft HTML help workshop to generate a compressed HTML help file (.chm) +# of the generated HTML documentation. + +GENERATE_HTMLHELP = YES + +# If the GENERATE_HTMLHELP tag is set to YES, the CHM_FILE tag can +# be used to specify the file name of the resulting .chm file. You +# can add a path in front of the file if the result should not be +# written to the html output directory. + +CHM_FILE = + +# If the GENERATE_HTMLHELP tag is set to YES, the HHC_LOCATION tag can +# be used to specify the location (absolute path including file name) of +# the HTML help compiler (hhc.exe). If non-empty doxygen will try to run +# the HTML help compiler on the generated index.hhp. + +HHC_LOCATION = + +# If the GENERATE_HTMLHELP tag is set to YES, the GENERATE_CHI flag +# controls if a separate .chi index file is generated (YES) or that +# it should be included in the master .chm file (NO). + +GENERATE_CHI = NO + +# If the GENERATE_HTMLHELP tag is set to YES, the BINARY_TOC flag +# controls whether a binary table of contents is generated (YES) or a +# normal table of contents (NO) in the .chm file. + +BINARY_TOC = NO + +# The TOC_EXPAND flag can be set to YES to add extra items for group members +# to the contents of the HTML help documentation and to the tree view. + +TOC_EXPAND = NO + +# The DISABLE_INDEX tag can be used to turn on/off the condensed index at +# top of each HTML page. The value NO (the default) enables the index and +# the value YES disables it. + +DISABLE_INDEX = NO + +# This tag can be used to set the number of enum values (range [1..20]) +# that doxygen will group on one line in the generated HTML documentation. + +ENUM_VALUES_PER_LINE = 4 + +# If the GENERATE_TREEVIEW tag is set to YES, a side panel will be +# generated containing a tree-like index structure (just like the one that +# is generated for HTML Help). For this to work a browser that supports +# JavaScript, DHTML, CSS and frames is required (for instance Mozilla 1.0+, +# Netscape 6.0+, Internet explorer 5.0+, or Konqueror). Windows users are +# probably better off using the HTML help feature. + +GENERATE_TREEVIEW = YES + +# If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be +# used to set the initial width (in pixels) of the frame in which the tree +# is shown. + +TREEVIEW_WIDTH = 190 + +#--------------------------------------------------------------------------- +# configuration options related to the LaTeX output +#--------------------------------------------------------------------------- + +# If the GENERATE_LATEX tag is set to YES (the default) Doxygen will +# generate Latex output. + +GENERATE_LATEX = NO + +# The LATEX_OUTPUT tag is used to specify where the LaTeX docs will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `latex' will be used as the default path. + +LATEX_OUTPUT = latex + +# The LATEX_CMD_NAME tag can be used to specify the LaTeX command name to be +# invoked. If left blank `latex' will be used as the default command name. + +LATEX_CMD_NAME = latex + +# The MAKEINDEX_CMD_NAME tag can be used to specify the command name to +# generate index for LaTeX. If left blank `makeindex' will be used as the +# default command name. + +MAKEINDEX_CMD_NAME = makeindex + +# If the COMPACT_LATEX tag is set to YES Doxygen generates more compact +# LaTeX documents. This may be useful for small projects and may help to +# save some trees in general. + +COMPACT_LATEX = NO + +# The PAPER_TYPE tag can be used to set the paper type that is used +# by the printer. Possible values are: a4, a4wide, letter, legal and +# executive. If left blank a4wide will be used. + +PAPER_TYPE = a4wide + +# The EXTRA_PACKAGES tag can be to specify one or more names of LaTeX +# packages that should be included in the LaTeX output. + +EXTRA_PACKAGES = + +# The LATEX_HEADER tag can be used to specify a personal LaTeX header for +# the generated latex document. The header should contain everything until +# the first chapter. If it is left blank doxygen will generate a +# standard header. Notice: only use this tag if you know what you are doing! + +LATEX_HEADER = + +# If the PDF_HYPERLINKS tag is set to YES, the LaTeX that is generated +# is prepared for conversion to pdf (using ps2pdf). The pdf file will +# contain links (just like the HTML output) instead of page references +# This makes the output suitable for online browsing using a pdf viewer. + +PDF_HYPERLINKS = NO + +# If the USE_PDFLATEX tag is set to YES, pdflatex will be used instead of +# plain latex in the generated Makefile. Set this option to YES to get a +# higher quality PDF documentation. + +USE_PDFLATEX = NO + +# If the LATEX_BATCHMODE tag is set to YES, doxygen will add the \\batchmode. +# command to the generated LaTeX files. This will instruct LaTeX to keep +# running if errors occur, instead of asking the user for help. +# This option is also used when generating formulas in HTML. + +LATEX_BATCHMODE = NO + +# If LATEX_HIDE_INDICES is set to YES then doxygen will not +# include the index chapters (such as File Index, Compound Index, etc.) +# in the output. + +LATEX_HIDE_INDICES = NO + +#--------------------------------------------------------------------------- +# configuration options related to the RTF output +#--------------------------------------------------------------------------- + +# If the GENERATE_RTF tag is set to YES Doxygen will generate RTF output +# The RTF output is optimized for Word 97 and may not look very pretty with +# other RTF readers or editors. + +GENERATE_RTF = NO + +# The RTF_OUTPUT tag is used to specify where the RTF docs will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `rtf' will be used as the default path. + +RTF_OUTPUT = rtf + +# If the COMPACT_RTF tag is set to YES Doxygen generates more compact +# RTF documents. This may be useful for small projects and may help to +# save some trees in general. + +COMPACT_RTF = NO + +# If the RTF_HYPERLINKS tag is set to YES, the RTF that is generated +# will contain hyperlink fields. The RTF file will +# contain links (just like the HTML output) instead of page references. +# This makes the output suitable for online browsing using WORD or other +# programs which support those fields. +# Note: wordpad (write) and others do not support links. + +RTF_HYPERLINKS = NO + +# Load stylesheet definitions from file. Syntax is similar to doxygen's +# config file, i.e. a series of assignments. You only have to provide +# replacements, missing definitions are set to their default value. + +RTF_STYLESHEET_FILE = + +# Set optional variables used in the generation of an rtf document. +# Syntax is similar to doxygen's config file. + +RTF_EXTENSIONS_FILE = + +#--------------------------------------------------------------------------- +# configuration options related to the man page output +#--------------------------------------------------------------------------- + +# If the GENERATE_MAN tag is set to YES (the default) Doxygen will +# generate man pages + +GENERATE_MAN = NO + +# The MAN_OUTPUT tag is used to specify where the man pages will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `man' will be used as the default path. + +MAN_OUTPUT = man + +# The MAN_EXTENSION tag determines the extension that is added to +# the generated man pages (default is the subroutine's section .3) + +MAN_EXTENSION = .3 + +# If the MAN_LINKS tag is set to YES and Doxygen generates man output, +# then it will generate one additional man file for each entity +# documented in the real man page(s). These additional files +# only source the real man page, but without them the man command +# would be unable to find the correct page. The default is NO. + +MAN_LINKS = NO + +#--------------------------------------------------------------------------- +# configuration options related to the XML output +#--------------------------------------------------------------------------- + +# If the GENERATE_XML tag is set to YES Doxygen will +# generate an XML file that captures the structure of +# the code including all documentation. + +GENERATE_XML = NO + +# The XML_OUTPUT tag is used to specify where the XML pages will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `xml' will be used as the default path. + +XML_OUTPUT = xml + +# The XML_SCHEMA tag can be used to specify an XML schema, +# which can be used by a validating XML parser to check the +# syntax of the XML files. + +XML_SCHEMA = + +# The XML_DTD tag can be used to specify an XML DTD, +# which can be used by a validating XML parser to check the +# syntax of the XML files. + +XML_DTD = + +# If the XML_PROGRAMLISTING tag is set to YES Doxygen will +# dump the program listings (including syntax highlighting +# and cross-referencing information) to the XML output. Note that +# enabling this will significantly increase the size of the XML output. + +XML_PROGRAMLISTING = YES + +#--------------------------------------------------------------------------- +# configuration options for the AutoGen Definitions output +#--------------------------------------------------------------------------- + +# If the GENERATE_AUTOGEN_DEF tag is set to YES Doxygen will +# generate an AutoGen Definitions (see autogen.sf.net) file +# that captures the structure of the code including all +# documentation. Note that this feature is still experimental +# and incomplete at the moment. + +GENERATE_AUTOGEN_DEF = NO + +#--------------------------------------------------------------------------- +# configuration options related to the Perl module output +#--------------------------------------------------------------------------- + +# If the GENERATE_PERLMOD tag is set to YES Doxygen will +# generate a Perl module file that captures the structure of +# the code including all documentation. Note that this +# feature is still experimental and incomplete at the +# moment. + +GENERATE_PERLMOD = NO + +# If the PERLMOD_LATEX tag is set to YES Doxygen will generate +# the necessary Makefile rules, Perl scripts and LaTeX code to be able +# to generate PDF and DVI output from the Perl module output. + +PERLMOD_LATEX = YES + +# If the PERLMOD_PRETTY tag is set to YES the Perl module output will be +# nicely formatted so it can be parsed by a human reader. This is useful +# if you want to understand what is going on. On the other hand, if this +# tag is set to NO the size of the Perl module output will be much smaller +# and Perl will parse it just the same. + +PERLMOD_PRETTY = YES + +# The names of the make variables in the generated doxyrules.make file +# are prefixed with the string contained in PERLMOD_MAKEVAR_PREFIX. +# This is useful so different doxyrules.make files included by the same +# Makefile don't overwrite each other's variables. + +PERLMOD_MAKEVAR_PREFIX = + +#--------------------------------------------------------------------------- +# Configuration options related to the preprocessor +#--------------------------------------------------------------------------- + +# If the ENABLE_PREPROCESSING tag is set to YES (the default) Doxygen will +# evaluate all C-preprocessor directives found in the sources and include +# files. + +ENABLE_PREPROCESSING = YES + +# If the MACRO_EXPANSION tag is set to YES Doxygen will expand all macro +# names in the source code. If set to NO (the default) only conditional +# compilation will be performed. Macro expansion can be done in a controlled +# way by setting EXPAND_ONLY_PREDEF to YES. + +MACRO_EXPANSION = NO + +# If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES +# then the macro expansion is limited to the macros specified with the +# PREDEFINED and EXPAND_AS_DEFINED tags. + +EXPAND_ONLY_PREDEF = NO + +# If the SEARCH_INCLUDES tag is set to YES (the default) the includes files +# in the INCLUDE_PATH (see below) will be search if a #include is found. + +SEARCH_INCLUDES = YES + +# The INCLUDE_PATH tag can be used to specify one or more directories that +# contain include files that are not input files but should be processed by +# the preprocessor. + +INCLUDE_PATH = + +# You can use the INCLUDE_FILE_PATTERNS tag to specify one or more wildcard +# patterns (like *.h and *.hpp) to filter out the header-files in the +# directories. If left blank, the patterns specified with FILE_PATTERNS will +# be used. + +INCLUDE_FILE_PATTERNS = + +# The PREDEFINED tag can be used to specify one or more macro names that +# are defined before the preprocessor is started (similar to the -D option of +# gcc). The argument of the tag is a list of macros of the form: name +# or name=definition (no spaces). If the definition and the = are +# omitted =1 is assumed. To prevent a macro definition from being +# undefined via #undef or recursively expanded use the := operator +# instead of the = operator. + +PREDEFINED = + +# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then +# this tag can be used to specify a list of macro names that should be expanded. +# The macro definition that is found in the sources will be used. +# Use the PREDEFINED tag if you want to use a different macro definition. + +EXPAND_AS_DEFINED = + +# If the SKIP_FUNCTION_MACROS tag is set to YES (the default) then +# doxygen's preprocessor will remove all function-like macros that are alone +# on a line, have an all uppercase name, and do not end with a semicolon. Such +# function macros are typically used for boiler-plate code, and will confuse +# the parser if not removed. + +SKIP_FUNCTION_MACROS = YES + +#--------------------------------------------------------------------------- +# Configuration::additions related to external references +#--------------------------------------------------------------------------- + +# The TAGFILES option can be used to specify one or more tagfiles. +# Optionally an initial location of the external documentation +# can be added for each tagfile. The format of a tag file without +# this location is as follows: +# TAGFILES = file1 file2 ... +# Adding location for the tag files is done as follows: +# TAGFILES = file1=loc1 "file2 = loc2" ... +# where "loc1" and "loc2" can be relative or absolute paths or +# URLs. If a location is present for each tag, the installdox tool +# does not have to be run to correct the links. +# Note that each tag file must have a unique name +# (where the name does NOT include the path) +# If a tag file is not located in the directory in which doxygen +# is run, you must also specify the path to the tagfile here. + +TAGFILES = + +# When a file name is specified after GENERATE_TAGFILE, doxygen will create +# a tag file that is based on the input files it reads. + +GENERATE_TAGFILE = + +# If the ALLEXTERNALS tag is set to YES all external classes will be listed +# in the class index. If set to NO only the inherited external classes +# will be listed. + +ALLEXTERNALS = NO + +# If the EXTERNAL_GROUPS tag is set to YES all external groups will be listed +# in the modules index. If set to NO, only the current project's groups will +# be listed. + +EXTERNAL_GROUPS = YES + +# The PERL_PATH should be the absolute path and name of the perl script +# interpreter (i.e. the result of `which perl'). + +PERL_PATH = /usr/bin/perl + +#--------------------------------------------------------------------------- +# Configuration options related to the dot tool +#--------------------------------------------------------------------------- + +# If the CLASS_DIAGRAMS tag is set to YES (the default) Doxygen will +# generate a inheritance diagram (in HTML, RTF and LaTeX) for classes with base +# or super classes. Setting the tag to NO turns the diagrams off. Note that +# this option is superseded by the HAVE_DOT option below. This is only a +# fallback. It is recommended to install and use dot, since it yields more +# powerful graphs. + +CLASS_DIAGRAMS = NO + +# You can define message sequence charts within doxygen comments using the \msc +# command. Doxygen will then run the mscgen tool (see http://www.mcternan.me.uk/mscgen/) to +# produce the chart and insert it in the documentation. The MSCGEN_PATH tag allows you to +# specify the directory where the mscgen tool resides. If left empty the tool is assumed to +# be found in the default search path. + +MSCGEN_PATH = + +# If set to YES, the inheritance and collaboration graphs will hide +# inheritance and usage relations if the target is undocumented +# or is not a class. + +HIDE_UNDOC_RELATIONS = YES + +# If you set the HAVE_DOT tag to YES then doxygen will assume the dot tool is +# available from the path. This tool is part of Graphviz, a graph visualization +# toolkit from AT&T and Lucent Bell Labs. The other options in this section +# have no effect if this option is set to NO (the default) + +HAVE_DOT = NO + +# If the CLASS_GRAPH and HAVE_DOT tags are set to YES then doxygen +# will generate a graph for each documented class showing the direct and +# indirect inheritance relations. Setting this tag to YES will force the +# the CLASS_DIAGRAMS tag to NO. + +CLASS_GRAPH = NO + +# If the COLLABORATION_GRAPH and HAVE_DOT tags are set to YES then doxygen +# will generate a graph for each documented class showing the direct and +# indirect implementation dependencies (inheritance, containment, and +# class references variables) of the class with other documented classes. + +COLLABORATION_GRAPH = NO + +# If the GROUP_GRAPHS and HAVE_DOT tags are set to YES then doxygen +# will generate a graph for groups, showing the direct groups dependencies + +GROUP_GRAPHS = NO + +# If the UML_LOOK tag is set to YES doxygen will generate inheritance and +# collaboration diagrams in a style similar to the OMG's Unified Modeling +# Language. + +UML_LOOK = NO + +# If set to YES, the inheritance and collaboration graphs will show the +# relations between templates and their instances. + +TEMPLATE_RELATIONS = NO + +# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDE_GRAPH, and HAVE_DOT +# tags are set to YES then doxygen will generate a graph for each documented +# file showing the direct and indirect include dependencies of the file with +# other documented files. + +INCLUDE_GRAPH = NO + +# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDED_BY_GRAPH, and +# HAVE_DOT tags are set to YES then doxygen will generate a graph for each +# documented header file showing the documented files that directly or +# indirectly include this file. + +INCLUDED_BY_GRAPH = NO + +# If the CALL_GRAPH and HAVE_DOT tags are set to YES then doxygen will +# generate a call dependency graph for every global function or class method. +# Note that enabling this option will significantly increase the time of a run. +# So in most cases it will be better to enable call graphs for selected +# functions only using the \callgraph command. + +CALL_GRAPH = NO + +# If the CALLER_GRAPH and HAVE_DOT tags are set to YES then doxygen will +# generate a caller dependency graph for every global function or class method. +# Note that enabling this option will significantly increase the time of a run. +# So in most cases it will be better to enable caller graphs for selected +# functions only using the \callergraph command. + +CALLER_GRAPH = NO + +# If the GRAPHICAL_HIERARCHY and HAVE_DOT tags are set to YES then doxygen +# will graphical hierarchy of all classes instead of a textual one. + +GRAPHICAL_HIERARCHY = NO + +# If the DIRECTORY_GRAPH, SHOW_DIRECTORIES and HAVE_DOT tags are set to YES +# then doxygen will show the dependencies a directory has on other directories +# in a graphical way. The dependency relations are determined by the #include +# relations between the files in the directories. + +DIRECTORY_GRAPH = NO + +# The DOT_IMAGE_FORMAT tag can be used to set the image format of the images +# generated by dot. Possible values are png, jpg, or gif +# If left blank png will be used. + +DOT_IMAGE_FORMAT = jpg + +# The tag DOT_PATH can be used to specify the path where the dot tool can be +# found. If left blank, it is assumed the dot tool can be found in the path. + +DOT_PATH = + +# The DOTFILE_DIRS tag can be used to specify one or more directories that +# contain dot files that are included in the documentation (see the +# \dotfile command). + +DOTFILE_DIRS = + +# The MAX_DOT_GRAPH_MAX_NODES tag can be used to set the maximum number of +# nodes that will be shown in the graph. If the number of nodes in a graph +# becomes larger than this value, doxygen will truncate the graph, which is +# visualized by representing a node as a red box. Note that doxygen will always +# show the root nodes and its direct children regardless of this setting. + +DOT_GRAPH_MAX_NODES = 50 + +# Set the DOT_TRANSPARENT tag to YES to generate images with a transparent +# background. This is disabled by default, which results in a white background. +# Warning: Depending on the platform used, enabling this option may lead to +# badly anti-aliased labels on the edges of a graph (i.e. they become hard to +# read). + +DOT_TRANSPARENT = NO + +# Set the DOT_MULTI_TARGETS tag to YES allow dot to generate multiple output +# files in one run (i.e. multiple -o and -T options on the command line). This +# makes dot run faster, but since only newer versions of dot (>1.8.10) +# support this, this feature is disabled by default. + +DOT_MULTI_TARGETS = NO + +# If the GENERATE_LEGEND tag is set to YES (the default) Doxygen will +# generate a legend page explaining the meaning of the various boxes and +# arrows in the dot generated graphs. + +GENERATE_LEGEND = NO + +# If the DOT_CLEANUP tag is set to YES (the default) Doxygen will +# remove the intermediate dot files that are used to generate +# the various graphs. + +DOT_CLEANUP = NO + +#--------------------------------------------------------------------------- +# Configuration::additions related to the search engine +#--------------------------------------------------------------------------- + +# The SEARCHENGINE tag specifies whether or not a search engine should be +# used. If set to NO the values of all tags below this one will be ignored. + +SEARCHENGINE = YES diff --git a/doxygen/slp_doxy.css b/doxygen/slp_doxy.css new file mode 100644 index 0000000..12c03ac --- /dev/null +++ b/doxygen/slp_doxy.css @@ -0,0 +1,699 @@ +/* The standard CSS for doxygen */ + +body, table, div, p, dl { + font-family: Lucida Grande, Verdana, Geneva, Arial, sans-serif; + font-size: 12px; +} + +/* @group Heading Levels */ + +h1 { + font-size: 18pt; + color: #3366ED; +} + +h1.pg { + font-size: 18pt; + color: #336666; + margin-right:-0.6pt; + margin-left:0cm; + padding-top:0cm; + padding-right:0cm; + padding-bottom:1pt; + padding-left:0cm; + border-bottom-width:1.5pt; + border-bottom-color:#336666; + border-top-style:none; + border-right-style:none; + border-bottom-style:solid; + border-left-style:none; +} + +h2 { + font-size: 14pt; + color: #336666; +} +h2.pg { + font-size: 14pt; + color: #336666; + margin-right:-0.1pt; + margin-left:0cm; + padding-top:0cm; + padding-right:0cm; + padding-bottom:1pt; + padding-left:0cm; + border-bottom-width:1.2pt; + border-bottom-color:#336666; + border-top-style:none; + border-right-style:none; + border-bottom-style:solid; + border-left-style:none; +} + + +h3 { + font-size: 12pt; + color: #336666; +} +h3.pg { + font-size: 12pt; + color: #336666; +} + + + +dt { + font-weight: bold; +} + +div.multicol { + -moz-column-gap: 1em; + -webkit-column-gap: 1em; + -moz-column-count: 3; + -webkit-column-count: 3; +} + +p.startli, p.startdd, p.starttd { + margin-top: 2px; +} + +p.endli { + margin-bottom: 0px; +} + +p.enddd { + margin-bottom: 4px; +} + +p.endtd { + margin-bottom: 2px; +} + +/* @end */ + +caption { + font-weight: bold; +} + +span.legend { + font-size: 70%; + text-align: center; +} + +h3.version { + font-size: 90%; + text-align: center; +} + +div.qindex, div.navtab{ + background-color: #EBEFF6; + border: 1px solid #A3B4D7; + text-align: center; + margin: 2px; + padding: 2px; +} + +div.qindex, div.navpath { + width: 100%; + line-height: 140%; +} + +div.navtab { + margin-right: 15px; +} + +/* @group Link Styling */ + +a { + color: #3D578C; + font-weight: normal; + text-decoration: none; +} + +.contents a:visited { + color: #4665A2; +} + +a:hover { + text-decoration: underline; +} + +a.qindex { + font-weight: bold; +} + +a.qindexHL { + font-weight: bold; + background-color: #9CAFD4; + color: #ffffff; + border: 1px double #869DCA; +} + +.contents a.qindexHL:visited { + color: #ffffff; +} + +a.el { + font-weight: bold; +} + +a.elRef { +} + +a.code { + color: #4665A2; +} + +a.codeRef { + color: #4665A2; +} + +/* @end */ + +dl.el { + margin-left: -1cm; +} + +.fragment { + font-family: monospace, fixed; + font-size: 105%; +} + +pre.fragment { + border: 1px solid #C4CFE5; + background-color: #FBFCFD; + padding: 4px 6px; + margin: 4px 8px 4px 2px; + overflow: auto; + word-wrap: break-word; + font-size: 9pt; + line-height: 125%; +} + +div.ah { + background-color: black; + font-weight: bold; + color: #ffffff; + margin-bottom: 3px; + margin-top: 3px + padding: .2em; + border: solid thin #333; + border-radius: .5em; + -webkit-border-radius: .5em; + -moz-border-radius: .5em; + -webkit-box-shadow: 2px 2px 3px #999; + -moz-box-shadow: rgba(0, 0, 0, 0.15) 2px 2px 2px; + background-image: -webkit-gradient(linear, left top, left bottom, from(#eee), to(#000),color-stop(0.3, #444)); + background-image: -moz-linear-gradient(center top, #eee 0%, #444 40%, #000); +} + +div.groupHeader { + margin-left: 16px; + margin-top: 12px; + margin-bottom: 6px; + font-weight: bold; +} + +div.groupText { + margin-left: 16px; + font-style: italic; +} + +body { + background: white; + color: black; + margin: 0; +} + +div.contents { + margin-top: 10px; + margin-left: 10px; + margin-right: 10px; +} + +td.indexkey { + background-color: #EBEFF6; + font-weight: bold; + border: 1px solid #C4CFE5; + margin: 2px 0px 2px 0; + padding: 2px 10px; +} + +td.indexvalue { + background-color: #EBEFF6; + border: 1px solid #C4CFE5; + padding: 2px 10px; + margin: 2px 0px; +} + +tr.memlist { + background-color: #EEF1F7; +} + +p.formulaDsp { + text-align: center; +} + +img.formulaDsp { + +} + +img.formulaInl { + vertical-align: middle; +} + +div.center { + text-align: center; + margin-top: 0px; + margin-bottom: 0px; + padding: 0px; +} + +div.center img { + border: 0px; +} + +address.footer { + text-align: right; + padding-right: 12px; +} + +img.footer { + border: 0px; + vertical-align: middle; +} + +/* @group Code Colorization */ + +span.keyword { + color: #008000 +} + +span.keywordtype { + color: #604020 +} + +span.keywordflow { + color: #e08000 +} + +span.comment { + color: #800000 +} + +span.preprocessor { + color: #806020 +} + +span.stringliteral { + color: #002080 +} + +span.charliteral { + color: #008080 +} + +span.vhdldigit { + color: #ff00ff +} + +span.vhdlchar { + color: #000000 +} + +span.vhdlkeyword { + color: #700070 +} + +span.vhdllogic { + color: #ff0000 +} + +/* @end */ + +/* +.search { + color: #003399; + font-weight: bold; +} + +form.search { + margin-bottom: 0px; + margin-top: 0px; +} + +input.search { + font-size: 75%; + color: #000080; + font-weight: normal; + background-color: #e8eef2; +} +*/ + +td.tiny { + font-size: 75%; +} + +.dirtab { + padding: 4px; + border-collapse: collapse; + border: 1px solid #A3B4D7; +} + +th.dirtab { + background: #EBEFF6; + font-weight: bold; +} + +hr { + height: 0px; + border: none; + border-top: 1px solid #4A6AAA; +} + +hr.footer { + height: 1px; +} + +/* @group Member Descriptions */ + +table.memberdecls { + border-spacing: 0px; + padding: 0px; +} + +.mdescLeft, .mdescRight, +.memItemLeft, .memItemRight, +.memTemplItemLeft, .memTemplItemRight, .memTemplParams { + background-color: #F9FAFC; + border: none; + margin: 4px; + padding: 1px 0 0 8px; +} + +.mdescLeft, .mdescRight { + padding: 0px 8px 4px 8px; + color: #555; +} + +.memItemLeft, .memItemRight, .memTemplParams { + border-top: 1px solid #C4CFE5; +} + +.memItemLeft, .memTemplItemLeft { + white-space: nowrap; +} + +.memTemplParams { + color: #4665A2; + white-space: nowrap; +} + +/* @end */ + +/* @group Member Details */ + +/* Styles for detailed member documentation */ + +.memtemplate { + font-size: 80%; + color: #4665A2; + font-weight: normal; + margin-left: 3px; +} + +.memnav { + background-color: #EBEFF6; + border: 1px solid #A3B4D7; + text-align: center; + margin: 2px; + margin-right: 15px; + padding: 2px; +} + +.memitem { + padding: 0; + margin-bottom: 10px; +} + +.memname { + white-space: nowrap; + font-weight: bold; + margin-left: 6px; +} + +.memproto { + border-top: 1px solid #A8B8D9; + border-left: 1px solid #A8B8D9; + border-right: 1px solid #A8B8D9; + padding: 6px 0px 6px 0px; + color: #253555; + font-weight: bold; + text-shadow: 0px 1px 1px rgba(255, 255, 255, 0.9); + /* firefox specific markup */ + -moz-box-shadow: rgba(0, 0, 0, 0.15) 5px 5px 5px; + -moz-border-radius-topright: 8px; + -moz-border-radius-topleft: 8px; + /* webkit specific markup */ + -webkit-box-shadow: 5px 5px 5px rgba(0, 0, 0, 0.15); + -webkit-border-top-right-radius: 8px; + -webkit-border-top-left-radius: 8px; + background-image:url('nav_f.png'); + background-repeat:repeat-x; + background-color: #E2E8F2; + +} + +.memdoc { + border-bottom: 1px solid #A8B8D9; + border-left: 1px solid #A8B8D9; + border-right: 1px solid #A8B8D9; + padding: 2px 5px; + background-color: #FBFCFD; + border-top-width: 0; + /* firefox specific markup */ + -moz-border-radius-bottomleft: 8px; + -moz-border-radius-bottomright: 8px; + -moz-box-shadow: rgba(0, 0, 0, 0.15) 5px 5px 5px; + background-image: -moz-linear-gradient(center top, #FFFFFF 0%, #FFFFFF 60%, #F8 95%, #F0); + /* webkit specific markup */ + -webkit-border-bottom-left-radius: 8px; + -webkit-border-bottom-right-radius: 8px; + -webkit-box-shadow: 5px 5px 5px rgba(0, 0, 0, 0.15); + background-image: -webkit-gradient(linear,center top,center bottom,from(#FFFFFF), color-stop(0.6,#FFFFFF), color-stop(0.60,#FF), color-stop(0.95,#F8), to(#F0)); +} + +.paramkey { + text-align: right; +} + +.paramtype { + white-space: nowrap; +} + +.paramname { + color: #602020; + white-space: nowrap; +} +.paramname em { + font-style: normal; +} + +/* @end */ + +/* @group Directory (tree) */ + +/* for the tree view */ + +.ftvtree { + font-family: sans-serif; + margin: 0px; +} + +/* these are for tree view when used as main index */ + +.directory { + font-size: 9pt; + font-weight: bold; + margin: 5px; +} + +.directory h3 { + margin: 0px; + margin-top: 1em; + font-size: 11pt; +} + +/* +The following two styles can be used to replace the root node title +with an image of your choice. Simply uncomment the next two styles, +specify the name of your image and be sure to set 'height' to the +proper pixel height of your image. +*/ + +/* +.directory h3.swap { + height: 61px; + background-repeat: no-repeat; + background-image: url("yourimage.gif"); +} +.directory h3.swap span { + display: none; +} +*/ + +.directory > h3 { + margin-top: 0; +} + +.directory p { + margin: 0px; + white-space: nowrap; +} + +.directory div { + display: none; + margin: 0px; +} + +.directory img { + vertical-align: -30%; +} + +/* these are for tree view when not used as main index */ + +.directory-alt { + font-size: 100%; + font-weight: bold; +} + +.directory-alt h3 { + margin: 0px; + margin-top: 1em; + font-size: 11pt; +} + +.directory-alt > h3 { + margin-top: 0; +} + +.directory-alt p { + margin: 0px; + white-space: nowrap; +} + +.directory-alt div { + display: none; + margin: 0px; +} + +.directory-alt img { + vertical-align: -30%; +} + +/* @end */ + +div.dynheader { + margin-top: 8px; +} + +address { + font-style: normal; + color: #2A3D61; +} + +table.doxtable { + border-collapse:collapse; +} + +table.doxtable td, table.doxtable th { + border: 1px solid #2D4068; + padding: 3px 7px 2px; +} + +table.doxtable th { + background-color: #374F7F; + color: #FFFFFF; + font-size: 110%; + padding-bottom: 4px; + padding-top: 5px; + text-align:left; +} + +.tabsearch { + top: 0px; + left: 10px; + height: 36px; + background-image: url('tab_b.png'); + z-index: 101; + overflow: hidden; + font-size: 13px; +} + +.navpath ul +{ + font-size: 11px; + background-image:url('tab_b.png'); + background-repeat:repeat-x; + height:30px; + line-height:30px; + color:#8AA0CC; + border:solid 1px #C2CDE4; + overflow:hidden; + margin:0px; + padding:0px; +} + +.navpath li +{ + list-style-type:none; + float:left; + padding-left:10px; + padding-right: 15px; + background-image:url('bc_s.png'); + background-repeat:no-repeat; + background-position:right; + color:#364D7C; +} + +.navpath a +{ + height:32px; + display:block; + text-decoration: none; + outline: none; +} + +.navpath a:hover +{ + color:#6884BD; +} + +div.summary +{ + float: right; + font-size: 8pt; + padding-right: 5px; + width: 50%; + text-align: right; +} + +div.summary a +{ + white-space: nowrap; +} + +div.header +{ + background-image:url('nav_h.png'); + background-repeat:repeat-x; + background-color: #F9FAFC; + margin: 0px; + border-bottom: 1px solid #C4CFE5; +} + +div.headertitle +{ + padding: 5px 5px 5px 10px; +} + diff --git a/nfc-common-lib-devel.manifest b/nfc-common-lib-devel.manifest new file mode 100644 index 0000000..ca37499 --- /dev/null +++ b/nfc-common-lib-devel.manifest @@ -0,0 +1,6 @@ + + + + + + diff --git a/nfc-common-lib.manifest b/nfc-common-lib.manifest new file mode 100644 index 0000000..ca37499 --- /dev/null +++ b/nfc-common-lib.manifest @@ -0,0 +1,6 @@ + + + + + + diff --git a/nfc-manager-devel.manifest b/nfc-manager-devel.manifest new file mode 100644 index 0000000..ca37499 --- /dev/null +++ b/nfc-manager-devel.manifest @@ -0,0 +1,6 @@ + + + + + + diff --git a/nfc-manager.manifest b/nfc-manager.manifest new file mode 100644 index 0000000..ca44b95 --- /dev/null +++ b/nfc-manager.manifest @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + diff --git a/packaging/libnfc-manager-0.init.in b/packaging/libnfc-manager-0.init.in new file mode 100755 index 0000000..16c2c09 --- /dev/null +++ b/packaging/libnfc-manager-0.init.in @@ -0,0 +1,31 @@ +#!/bin/sh +### BEGIN INIT INFO +# Provides: nfc-manager-daemon +# Required-Start: +# Required-Stop: +# Default-Start: 3 5 +# Default-Stop: 0 +# Short-Description: NFC manager +# Description: NFC manager +# +# +### END INIT INFO + +# Author: Wonkyu Kwon + +# PATH should only include /usr/* if it runs after the mountnfs.sh script +DAEMON=/usr/bin/nfc-manager-daemon +DAEMON_ARGS="script" # Arguments to run the daemon with +VCONFTOOL=/usr/bin/vconftool + +# Exit if the package is not installed +[ -x $DAEMON ] || exit 0 +[ -x $VCONFTOOL ] || exit 0 + +#if vconftool get db/nfc/enable | grep -q "db/nfc/enable, value = 1 (bool)" +#then + if ! ps -f --ppid 1 | grep -q nfc-manager-daemon + then + $DAEMON $DAEMON_ARGS & + fi +#fi diff --git a/packaging/nfc-common-lib b/packaging/nfc-common-lib new file mode 100644 index 0000000..9c95663 --- /dev/null +++ b/packaging/nfc-common-lib @@ -0,0 +1,206 @@ +Flora License + +Version 1.0, May, 2012 + +http://floralicense.org/license/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + +"License" shall mean the terms and conditions for use, reproduction, +and distribution as defined by Sections 1 through 9 of this document. + +"Licensor" shall mean the copyright owner or entity authorized by +the copyright owner that is granting the License. + +"Legal Entity" shall mean the union of the acting entity and +all other entities that control, are controlled by, or are +under common control with that entity. For the purposes of +this definition, "control" means (i) the power, direct or indirect, +to cause the direction or management of such entity, +whether by contract or otherwise, or (ii) ownership of fifty percent (50%) +or more of the outstanding shares, or (iii) beneficial ownership of +such entity. + +"You" (or "Your") shall mean an individual or Legal Entity +exercising permissions granted by this License. + +"Source" form shall mean the preferred form for making modifications, +including but not limited to software source code, documentation source, +and configuration files. + +"Object" form shall mean any form resulting from mechanical +transformation or translation of a Source form, including but +not limited to compiled object code, generated documentation, +and conversions to other media types. + +"Work" shall mean the work of authorship, whether in Source or Object form, +made available under the License, as indicated by a copyright notice +that is included in or attached to the work (an example is provided +in the Appendix below). + +"Derivative Works" shall mean any work, whether in Source or Object form, +that is based on (or derived from) the Work and for which the editorial +revisions, annotations, elaborations, or other modifications represent, +as a whole, an original work of authorship. For the purposes of this License, +Derivative Works shall not include works that remain separable from, +or merely link (or bind by name) to the interfaces of, the Work and +Derivative Works thereof. + +"Contribution" shall mean any work of authorship, including the original +version of the Work and any modifications or additions to that Work or +Derivative Works thereof, that is intentionally submitted to Licensor +for inclusion in the Work by the copyright owner or by an individual or +Legal Entity authorized to submit on behalf of the copyright owner. +For the purposes of this definition, "submitted" means any form of +electronic, verbal, or written communication sent to the Licensor or +its representatives, including but not limited to communication on +electronic mailing lists, source code control systems, and issue +tracking systems that are managed by, or on behalf of, the Licensor +for the purpose of discussing and improving the Work, but excluding +communication that is conspicuously marked or otherwise designated +in writing by the copyright owner as "Not a Contribution." + +"Contributor" shall mean Licensor and any individual or Legal Entity +on behalf of whom a Contribution has been received by Licensor and +subsequently incorporated within the Work. + +"Tizen Certified Platform" shall mean a software platform that complies +with the standards set forth in the Compatibility Definition Document +and passes the Compatibility Test Suite as defined from time to time +by the Tizen Technical Steering Group and certified by the Tizen +Association or its designated agent. + +2. Grant of Copyright License. Subject to the terms and conditions of +this License, each Contributor hereby grants to You a perpetual, +worldwide, non-exclusive, no-charge, royalty-free, irrevocable +copyright license to reproduce, prepare Derivative Works of, +publicly display, publicly perform, sublicense, and distribute the +Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. Subject to the terms and conditions of +this License, each Contributor hereby grants to You a perpetual, +worldwide, non-exclusive, no-charge, royalty-free, irrevocable +(except as stated in this section) patent license to make, have made, +use, offer to sell, sell, import, and otherwise transfer the Work +solely as incorporated into a Tizen Certified Platform, where such +license applies only to those patent claims licensable by such +Contributor that are necessarily infringed by their Contribution(s) +alone or by combination of their Contribution(s) with the Work solely +as incorporated into a Tizen Certified Platform to which such +Contribution(s) was submitted. If You institute patent litigation +against any entity (including a cross-claim or counterclaim +in a lawsuit) alleging that the Work or a Contribution incorporated +within the Work constitutes direct or contributory patent infringement, +then any patent licenses granted to You under this License for that +Work shall terminate as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the +Work or Derivative Works thereof pursuant to the copyright license +above, in any medium, with or without modifications, and in Source or +Object form, provided that You meet the following conditions: + + 1. You must give any other recipients of the Work or Derivative Works + a copy of this License; and + 2. You must cause any modified files to carry prominent notices stating + that You changed the files; and + 3. You must retain, in the Source form of any Derivative Works that + You distribute, all copyright, patent, trademark, and attribution + notices from the Source form of the Work, excluding those notices + that do not pertain to any part of the Derivative Works; and + 4. If the Work includes a "NOTICE" text file as part of its distribution, + then any Derivative Works that You distribute must include a readable + copy of the attribution notices contained within such NOTICE file, + excluding those notices that do not pertain to any part of + the Derivative Works, in at least one of the following places: + within a NOTICE text file distributed as part of the Derivative Works; + within the Source form or documentation, if provided along with the + Derivative Works; or, within a display generated by the Derivative Works, + if and wherever such third-party notices normally appear. + The contents of the NOTICE file are for informational purposes only + and do not modify the License. + +You may add Your own attribution notices within Derivative Works +that You distribute, alongside or as an addendum to the NOTICE text +from the Work, provided that such additional attribution notices +cannot be construed as modifying the License. You may add Your own +copyright statement to Your modifications and may provide additional or +different license terms and conditions for use, reproduction, or +distribution of Your modifications, or for any such Derivative Works +as a whole, provided Your use, reproduction, and distribution of +the Work otherwise complies with the conditions stated in this License. + +5. Submission of Contributions. Unless You explicitly state otherwise, +any Contribution intentionally submitted for inclusion in the Work +by You to the Licensor shall be under the terms and conditions of +this License, without any additional terms or conditions. +Notwithstanding the above, nothing herein shall supersede or modify +the terms of any separate license agreement you may have executed +with Licensor regarding such Contributions. + +6. Trademarks. This License does not grant permission to use the trade +names, trademarks, service marks, or product names of the Licensor, +except as required for reasonable and customary use in describing the +origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or +agreed to in writing, Licensor provides the Work (and each +Contributor provides its Contributions) on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +implied, including, without limitation, any warranties or conditions +of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A +PARTICULAR PURPOSE. You are solely responsible for determining the +appropriateness of using or redistributing the Work and assume any +risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, +whether in tort (including negligence), contract, or otherwise, +unless required by applicable law (such as deliberate and grossly +negligent acts) or agreed to in writing, shall any Contributor be +liable to You for damages, including any direct, indirect, special, +incidental, or consequential damages of any character arising as a +result of this License or out of the use or inability to use the +Work (including but not limited to damages for loss of goodwill, +work stoppage, computer failure or malfunction, or any and all +other commercial damages or losses), even if such Contributor +has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. While redistributing +the Work or Derivative Works thereof, You may choose to offer, +and charge a fee for, acceptance of support, warranty, indemnity, +or other liability obligations and/or rights consistent with this +License. However, in accepting such obligations, You may act only +on Your own behalf and on Your sole responsibility, not on behalf +of any other Contributor, and only if You agree to indemnify, +defend, and hold each Contributor harmless for any liability +incurred by, or claims asserted against, such Contributor by reason +of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS + +APPENDIX: How to apply the Flora License to your work + +To apply the Flora License to your work, attach the following +boilerplate notice, with the fields enclosed by brackets "[]" +replaced with your own identifying information. (Don't include +the brackets!) The text should be enclosed in the appropriate +comment syntax for the file format. We also recommend that a +file or class name and description of purpose be included on the +same "printed page" as the copyright notice for easier +identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Flora License, Version 1.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://floralicense.org/license/ + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + diff --git a/packaging/nfc-manager b/packaging/nfc-manager new file mode 100644 index 0000000..9c95663 --- /dev/null +++ b/packaging/nfc-manager @@ -0,0 +1,206 @@ +Flora License + +Version 1.0, May, 2012 + +http://floralicense.org/license/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + +"License" shall mean the terms and conditions for use, reproduction, +and distribution as defined by Sections 1 through 9 of this document. + +"Licensor" shall mean the copyright owner or entity authorized by +the copyright owner that is granting the License. + +"Legal Entity" shall mean the union of the acting entity and +all other entities that control, are controlled by, or are +under common control with that entity. For the purposes of +this definition, "control" means (i) the power, direct or indirect, +to cause the direction or management of such entity, +whether by contract or otherwise, or (ii) ownership of fifty percent (50%) +or more of the outstanding shares, or (iii) beneficial ownership of +such entity. + +"You" (or "Your") shall mean an individual or Legal Entity +exercising permissions granted by this License. + +"Source" form shall mean the preferred form for making modifications, +including but not limited to software source code, documentation source, +and configuration files. + +"Object" form shall mean any form resulting from mechanical +transformation or translation of a Source form, including but +not limited to compiled object code, generated documentation, +and conversions to other media types. + +"Work" shall mean the work of authorship, whether in Source or Object form, +made available under the License, as indicated by a copyright notice +that is included in or attached to the work (an example is provided +in the Appendix below). + +"Derivative Works" shall mean any work, whether in Source or Object form, +that is based on (or derived from) the Work and for which the editorial +revisions, annotations, elaborations, or other modifications represent, +as a whole, an original work of authorship. For the purposes of this License, +Derivative Works shall not include works that remain separable from, +or merely link (or bind by name) to the interfaces of, the Work and +Derivative Works thereof. + +"Contribution" shall mean any work of authorship, including the original +version of the Work and any modifications or additions to that Work or +Derivative Works thereof, that is intentionally submitted to Licensor +for inclusion in the Work by the copyright owner or by an individual or +Legal Entity authorized to submit on behalf of the copyright owner. +For the purposes of this definition, "submitted" means any form of +electronic, verbal, or written communication sent to the Licensor or +its representatives, including but not limited to communication on +electronic mailing lists, source code control systems, and issue +tracking systems that are managed by, or on behalf of, the Licensor +for the purpose of discussing and improving the Work, but excluding +communication that is conspicuously marked or otherwise designated +in writing by the copyright owner as "Not a Contribution." + +"Contributor" shall mean Licensor and any individual or Legal Entity +on behalf of whom a Contribution has been received by Licensor and +subsequently incorporated within the Work. + +"Tizen Certified Platform" shall mean a software platform that complies +with the standards set forth in the Compatibility Definition Document +and passes the Compatibility Test Suite as defined from time to time +by the Tizen Technical Steering Group and certified by the Tizen +Association or its designated agent. + +2. Grant of Copyright License. Subject to the terms and conditions of +this License, each Contributor hereby grants to You a perpetual, +worldwide, non-exclusive, no-charge, royalty-free, irrevocable +copyright license to reproduce, prepare Derivative Works of, +publicly display, publicly perform, sublicense, and distribute the +Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. Subject to the terms and conditions of +this License, each Contributor hereby grants to You a perpetual, +worldwide, non-exclusive, no-charge, royalty-free, irrevocable +(except as stated in this section) patent license to make, have made, +use, offer to sell, sell, import, and otherwise transfer the Work +solely as incorporated into a Tizen Certified Platform, where such +license applies only to those patent claims licensable by such +Contributor that are necessarily infringed by their Contribution(s) +alone or by combination of their Contribution(s) with the Work solely +as incorporated into a Tizen Certified Platform to which such +Contribution(s) was submitted. If You institute patent litigation +against any entity (including a cross-claim or counterclaim +in a lawsuit) alleging that the Work or a Contribution incorporated +within the Work constitutes direct or contributory patent infringement, +then any patent licenses granted to You under this License for that +Work shall terminate as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the +Work or Derivative Works thereof pursuant to the copyright license +above, in any medium, with or without modifications, and in Source or +Object form, provided that You meet the following conditions: + + 1. You must give any other recipients of the Work or Derivative Works + a copy of this License; and + 2. You must cause any modified files to carry prominent notices stating + that You changed the files; and + 3. You must retain, in the Source form of any Derivative Works that + You distribute, all copyright, patent, trademark, and attribution + notices from the Source form of the Work, excluding those notices + that do not pertain to any part of the Derivative Works; and + 4. If the Work includes a "NOTICE" text file as part of its distribution, + then any Derivative Works that You distribute must include a readable + copy of the attribution notices contained within such NOTICE file, + excluding those notices that do not pertain to any part of + the Derivative Works, in at least one of the following places: + within a NOTICE text file distributed as part of the Derivative Works; + within the Source form or documentation, if provided along with the + Derivative Works; or, within a display generated by the Derivative Works, + if and wherever such third-party notices normally appear. + The contents of the NOTICE file are for informational purposes only + and do not modify the License. + +You may add Your own attribution notices within Derivative Works +that You distribute, alongside or as an addendum to the NOTICE text +from the Work, provided that such additional attribution notices +cannot be construed as modifying the License. You may add Your own +copyright statement to Your modifications and may provide additional or +different license terms and conditions for use, reproduction, or +distribution of Your modifications, or for any such Derivative Works +as a whole, provided Your use, reproduction, and distribution of +the Work otherwise complies with the conditions stated in this License. + +5. Submission of Contributions. Unless You explicitly state otherwise, +any Contribution intentionally submitted for inclusion in the Work +by You to the Licensor shall be under the terms and conditions of +this License, without any additional terms or conditions. +Notwithstanding the above, nothing herein shall supersede or modify +the terms of any separate license agreement you may have executed +with Licensor regarding such Contributions. + +6. Trademarks. This License does not grant permission to use the trade +names, trademarks, service marks, or product names of the Licensor, +except as required for reasonable and customary use in describing the +origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or +agreed to in writing, Licensor provides the Work (and each +Contributor provides its Contributions) on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +implied, including, without limitation, any warranties or conditions +of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A +PARTICULAR PURPOSE. You are solely responsible for determining the +appropriateness of using or redistributing the Work and assume any +risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, +whether in tort (including negligence), contract, or otherwise, +unless required by applicable law (such as deliberate and grossly +negligent acts) or agreed to in writing, shall any Contributor be +liable to You for damages, including any direct, indirect, special, +incidental, or consequential damages of any character arising as a +result of this License or out of the use or inability to use the +Work (including but not limited to damages for loss of goodwill, +work stoppage, computer failure or malfunction, or any and all +other commercial damages or losses), even if such Contributor +has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. While redistributing +the Work or Derivative Works thereof, You may choose to offer, +and charge a fee for, acceptance of support, warranty, indemnity, +or other liability obligations and/or rights consistent with this +License. However, in accepting such obligations, You may act only +on Your own behalf and on Your sole responsibility, not on behalf +of any other Contributor, and only if You agree to indemnify, +defend, and hold each Contributor harmless for any liability +incurred by, or claims asserted against, such Contributor by reason +of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS + +APPENDIX: How to apply the Flora License to your work + +To apply the Flora License to your work, attach the following +boilerplate notice, with the fields enclosed by brackets "[]" +replaced with your own identifying information. (Don't include +the brackets!) The text should be enclosed in the appropriate +comment syntax for the file format. We also recommend that a +file or class name and description of purpose be included on the +same "printed page" as the copyright notice for easier +identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Flora License, Version 1.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://floralicense.org/license/ + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + diff --git a/packaging/nfc-manager.service b/packaging/nfc-manager.service new file mode 100644 index 0000000..8ecbcba --- /dev/null +++ b/packaging/nfc-manager.service @@ -0,0 +1,10 @@ +[Unit] +Description=NFC manager + +[Service] +Type=simple +ExecStart=/usr/bin/nfc-manager-daemon +KillSignal=SIGKILL + +[Install] +WantedBy=multi-user.target diff --git a/packaging/nfc-manager.spec b/packaging/nfc-manager.spec new file mode 100644 index 0000000..18ad82b --- /dev/null +++ b/packaging/nfc-manager.spec @@ -0,0 +1,162 @@ +Name: nfc-manager +Summary: NFC framework manager +Version: 0.0.33 +Release: 1 +Group: libs +License: Flora Software License +Source0: %{name}-%{version}.tar.gz +Source1: libnfc-manager-0.init.in +Source2: nfc-manager.service +BuildRequires: pkgconfig(aul) +BuildRequires: pkgconfig(glib-2.0) +BuildRequires: pkgconfig(gobject-2.0) +BuildRequires: pkgconfig(security-server) +BuildRequires: pkgconfig(dbus-glib-1) +BuildRequires: pkgconfig(vconf) +BuildRequires: pkgconfig(dlog) +BuildRequires: pkgconfig(tapi) +BuildRequires: pkgconfig(ecore) +BuildRequires: pkgconfig(bluetooth-api) +BuildRequires: pkgconfig(mm-sound) +BuildRequires: pkgconfig(appsvc) +BuildRequires: pkgconfig(heynoti) +BuildRequires: pkgconfig(svi) +BuildRequires: pkgconfig(capi-media-wav-player) +BuildRequires: pkgconfig(smartcard-service) +BuildRequires: pkgconfig(smartcard-service-common) +BuildRequires: pkgconfig(libssl) +BuildRequires: pkgconfig(pmapi) +BuildRequires: pkgconfig(pkgmgr) +BuildRequires: cmake +BuildRequires: gettext-tools +Requires(post): /sbin/ldconfig +Requires(post): /usr/bin/vconftool +requires(postun): /sbin/ldconfig +%description +NFC library Manager. + +%prep +%setup -q + +%package devel +Summary: Download agent +Group: Development/Libraries +Requires: %{name} = %{version}-%{release} + +%description devel +NFC library Manager (devel) + +%package -n nfc-common-lib +Summary: NFC common library +Group: Development/Libraries +Requires: %{name} = %{version}-%{release} + +%description -n nfc-common-lib +NFC Common library. + +%package -n nfc-common-lib-devel +Summary: NFC common library (devel) +Group: libs +Requires: %{name} = %{version}-%{release} + +%description -n nfc-common-lib-devel +NFC common library (devel) + + +%build +export LDFLAGS+="-Wl,--rpath=%{_prefix}/lib -Wl,--as-needed" +mkdir cmake_tmp +cd cmake_tmp +LDFLAGS="$LDFLAGS" cmake .. -DCMAKE_INSTALL_PREFIX=%{_prefix} + +make + +%install +cd cmake_tmp +%make_install +%__mkdir -p %{buildroot}/etc/init.d/ +%__cp -af %SOURCE1 %{buildroot}/etc/init.d/libnfc-manager-0 +chmod 755 %{buildroot}/etc/init.d/libnfc-manager-0 +mkdir -p %{buildroot}/usr/share/license +cp -af %{_builddir}/%{name}-%{version}/packaging/nfc-common-lib %{buildroot}/usr/share/license/ +cp -af %{_builddir}/%{name}-%{version}/packaging/nfc-manager %{buildroot}/usr/share/license/ + +mkdir -p %{buildroot}/usr/lib/systemd/system/multi-user.target.wants +cp -af %{SOURCE2} %{buildroot}/usr/lib/systemd/system/ +ln -s ../nfc-manager.service %{buildroot}/usr/lib/systemd/system/multi-user.target.wants/nfc-manager.service + +%post +/sbin/ldconfig +vconftool set -t bool db/nfc/feature 1 -u 5000 -f +vconftool set -t bool db/nfc/enable 0 -u 5000 -f +vconftool set -t bool db/nfc/sbeam 0 -u 5000 -f +vconftool set -t int db/nfc/se_type 0 -u 5000 -f +vconftool set -t bool db/nfc/predefined_item_state 0 -u 5000 -f +vconftool set -t string db/nfc/predefined_item "None" -u 5000 -f + +vconftool set -t bool memory/private/nfc-manager/popup_disabled 0 -u 5000 -f + +ln -s /etc/init.d/libnfc-manager-0 /etc/rc.d/rc3.d/S81libnfc-manager-0 -f +ln -s /etc/init.d/libnfc-manager-0 /etc/rc.d/rc5.d/S81libnfc-manager-0 -f + +mkdir -p /opt/etc/nfc_debug +chown :5000 /opt/etc/nfc_debug +chmod 775 /opt/etc/nfc_debug + + +systemctl daemon-reload +if [ $1 == 1 ]; then + systemctl restart nfc-manager.service +fi + +%postun +/sbin/ldconfig +mkdir -p /etc/rc.d/rc3.d +mkdir -p /etc/rc.d/rc5.d +rm -f /etc/rc.d/rc3.d/S81libnfc-manager-0 +rm -f /etc/rc.d/rc5.d/S81libnfc-manager-0 + +if [ $1 == 0 ]; then + systemctl stop nfc-manager.service +fi +systemctl daemon-reload + +%post -n nfc-common-lib -p /sbin/ldconfig + +%postun -n nfc-common-lib -p /sbin/ldconfig + +%files +%manifest nfc-manager.manifest +%defattr(-,root,root,-) +%{_libdir}/libnfc.so.1 +%{_libdir}/libnfc.so.1.0.0 +%{_prefix}/bin/nfc-manager-daemon +%{_prefix}/bin/ndef-tool +/etc/init.d/libnfc-manager-0 +/usr/share/dbus-1/services/nfc-manager.service +/usr/share/license/nfc-manager +/usr/lib/systemd/system/nfc-manager.service +/usr/lib/systemd/system/multi-user.target.wants/nfc-manager.service + +%files devel +%manifest nfc-manager-devel.manifest +%defattr(-,root,root,-) +%{_libdir}/pkgconfig/nfc.pc +%{_includedir}/nfc/*.h +%{_libdir}/libnfc.so + + +%files -n nfc-common-lib +%manifest nfc-common-lib.manifest +%defattr(-,root,root,-) +%{_libdir}/libnfc-common-lib.so.1 +%{_libdir}/libnfc-common-lib.so.1.0.0 +/usr/share/license/nfc-common-lib +/usr/share/nfc-manager-daemon/sounds/* + +%files -n nfc-common-lib-devel +%manifest nfc-common-lib-devel.manifest +%defattr(-,root,root,-) +%{_libdir}/libnfc-common-lib.so +%{_libdir}/pkgconfig/nfc-common-lib.pc +%{_includedir}/nfc-common-lib/*.h diff --git a/src/clientlib/CMakeLists.txt b/src/clientlib/CMakeLists.txt new file mode 100644 index 0000000..94e0740 --- /dev/null +++ b/src/clientlib/CMakeLists.txt @@ -0,0 +1,100 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +#PROJECT(nfc C) +PROJECT(nfc-client-lib C) + +#SET(NFC_CLIENT_LIB "nfc-client-lib") +SET(NFC_CLIENT_LIB "nfc") +SET(VERSION_MAJOR 1) +SET(VERSION ${VERSION_MAJOR}.0.0) + +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../commonlib/include) +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include) +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../manager/include) + +AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} CLIENT_SRCS) + +IF("${CMAKE_BUILD_TYPE}" STREQUAL "") + SET(CMAKE_BUILD_TYPE "Release") +ENDIF("${CMAKE_BUILD_TYPE}" STREQUAL "") + +INCLUDE(FindPkgConfig) +pkg_check_modules(clientlib_pkges REQUIRED security-server dbus-glib-1 dlog ecore vconf) + +FOREACH(flag ${clientlib_pkges_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) + +MESSAGE("CHECK MODULE in MANAGER ${clientlib_pkges_LDFLAGS}") + +# this for NFC flag + +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -pipe -fomit-frame-pointer -Wall -Wno-trigraphs -Werror-implicit-function-declaration -fno-strict-aliasing -Wl,-zdefs -fvisibility=hidden") + +SET(ARM_CFLAGS "${ARM_CLAGS} -mapcs -mno-sched-prolog -mabi=aapcs-linux -Uarm -fno-common -fpic") + +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror-implicit-function-declaration") + +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}") +SET(CMAKE_C_FLAGS_DEBUG "-O0 -g") + +FIND_PROGRAM(UNAME NAMES uname) +EXEC_PROGRAM("${UNAME}" ARGS "-m" OUTPUT_VARIABLE "ARCH") +IF("${ARCH}" MATCHES "^arm.*") + ADD_DEFINITIONS("-DTARGET") + MESSAGE("add -DTARGET") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${ARM_CFLAGS}") +ENDIF() + +ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"") +#ADD_DEFINITIONS("-DSLP_DEBUG") + +ADD_DEFINITIONS("-DNFC_FIRMWARE_UPDATE") +ADD_DEFINITIONS("-DNFC_DEBUG_USE_DLOG -D_GNU_SOURCE") +ADD_DEFINITIONS("-DUSE_UNIX_DOMAIN") +ADD_DEFINITIONS("-DUSE_IPC_EPOLL -DUSE_EPOLL_TIMEOUT") +ADD_DEFINITIONS("-DLLCP_MODE") +ADD_DEFINITIONS("-DNFC_APP_SUPPORTED") +ADD_DEFINITIONS("-DSAVE_TARGET_INFO_IN_CC") +ADD_DEFINITIONS("-DSECURITY_SERVER") +#ADD_DEFINITIONS("-DG_MAIN_LOOP") +#ADD_DEFINITIONS("-DUSE_ECORE_MAIN_LOOP") +ADD_DEFINITIONS("-DUSE_GLIB_MAIN_LOOP") + +SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed") + +ADD_LIBRARY(${NFC_CLIENT_LIB} SHARED ${CLIENT_SRCS}) +SET_TARGET_PROPERTIES(${NFC_CLIENT_LIB} PROPERTIES SOVERSION ${VERSION_MAJOR}) +SET_TARGET_PROPERTIES(${NFC_CLIENT_LIB} PROPERTIES VERSION ${VERSION}) +TARGET_LINK_LIBRARIES(${NFC_CLIENT_LIB} ${clientlib_pkges_LDFLAGS} "-L${CMAKE_CURRENT_SOURCE_DIR}/../../cmake_tmp/src/commonlib/" "-lnfc-common-lib") + +SET(CLIENT_HEADER + ../commonlib/include/net_nfc_typedef.h + include/net_nfc.h + include/net_nfc_target_info.h + include/net_nfc_tag.h + include/net_nfc_tag_jewel.h + include/net_nfc_tag_mifare.h + include/net_nfc_tag_felica.h + include/net_nfc_llcp.h + include/net_nfc_ndef_record.h + include/net_nfc_ndef_message.h + include/net_nfc_ndef_message_handover.h + include/net_nfc_sign_record.h + include/net_nfc_data.h + include/net_nfc_apdu.h + include/net_nfc_exchanger.h + include/net_nfc_internal_se.h + include/net_nfc_test.h + ../manager/include/nfc-service-glue.h + ../manager/include/net_nfc_manager_dbus.h +) + +CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/nfc.pc.in ${CMAKE_CURRENT_SOURCE_DIR}/nfc.pc) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/nfc.pc DESTINATION lib/pkgconfig) + +INSTALL(TARGETS ${NFC_CLIENT_LIB} DESTINATION lib) + +FOREACH(hfile ${CLIENT_HEADER}) + INSTALL(FILES ${hfile} DESTINATION include/nfc) +ENDFOREACH(hfile) + diff --git a/src/clientlib/include/net_nfc.h b/src/clientlib/include/net_nfc.h new file mode 100644 index 0000000..4e34e4c --- /dev/null +++ b/src/clientlib/include/net_nfc.h @@ -0,0 +1,381 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +/** + NFC Manager + NFC Manager controls the nfc device with high level APIs such as SmartPoster and Connection handover. + It also support the JSR257 push handling. + this file is provide the APIs of NFC Manager + + @file net_nfc.h + modified by: + Sechang Sohn (sc.sohn@samsung.com) + Sangsoo Lee (constant.lee@samsung.com) + Sungjae Lim (neueziel.lim@samsung.com) + Junyong Sim (junyong.sim@samsung.com) + Wonkyu Kwon (wonkyu.kwon@samsung.com) + @version 0.1 + @brief This file provide the APIs of the NFC Manager + */ + + +#ifndef __NET_NFC_INTERFACE_H__ +#define __NET_NFC_INTERFACE_H__ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define NET_NFC_SERVICE_EMPTY_TYPE "http://tizen.org/appcontrol/operation/nfc/empty" +#define NET_NFC_SERVICE_WELL_KNOWN_TYPE "http://tizen.org/appcontrol/operation/nfc/wellknown" +#define NET_NFC_SERVICE_EXTERNAL_TYPE "http://tizen.org/appcontrol/operation/nfc/external" +#define NET_NFC_SERVICE_MIME_TYPE "http://tizen.org/appcontrol/operation/nfc/mime" +#define NET_NFC_SERVICE_URI_TYPE "http://tizen.org/appcontrol/operation/nfc/uri" + +/** + +@addtogroup NET_NFC_MANAGER_API +@{ + This document is for the APIs reference document + + NFC Manager defines are defined in + + @li @c #net_nfc_initialize Initialize the nfc-manager + @li @c #net_nfc_deinitialize deinitialize the nfc-manager + @li @c #net_nfc_set_response_callback register callback function for async response and detection events + @li @c #net_nfc_unset_response_callback unregister callback + +*/ + +/** + "net_nfc_intialize" initializes NFC Manager. + This function must be called before proceed any function of NFC Manager excepting net_nfc_set_exchanger_cb. + Internally it make socket connection to NFC-Manager. + When the client process crashed or exit without the deinit. nfc-manager + auto matically process deinit itself. + + In running time, application can have a only one functionality of nfc client and nfc exchanger listener + Both can not be co-existed. So, If application want to be a exchanger listener, then do not call net_nfc_initialize. if net_nfc_initialize is called before, + net_nfc_deintialize SHOULD be called first, and then net_nfc_set_exchange_cb will be available. + + \par Sync (or) Async: Sync + This is a Synchronous API + + @return return the result of calling this functions + + @exception NET_NFC_ALREADY_INITIALIZED already initialized + @exception NET_NFC_IPC_FAIL communication to server is failed + @exception NET_NFC_ALLOC_FAIL memory allocation failed + @exception NET_NFC_THREAD_CREATE_FAIL failed to create thread for main event delivery + @exception NET_NFC_NOT_ALLOWED_OPERATION exchanger_cb is already register. + +
+ + example codes + @code + int main () + { + net_nfc_error_e result; + result = net_nfc_initialize(); + if (result != NET_NFC_OK) { + printf ("initialize error: %d\n", result); + } + + return 0; + } + @endcode + +*/ +net_nfc_error_e net_nfc_initialize(void); + +/** + the net_nfc_deinitialize function free the all the resource of the NFC Manager and + disconnect session of connection from application to the Manager. + + \par Sync (or) Async: Sync + This is a Asynchronous API + + @return return the result of the calling this function + + sample codes + @code + + @exception NONE + + int main (void) + { + if(NET_NFC_OK != net_nfc_initialize()){ + // intialize is failed + return 1; + } + + if(net_nfc_deinitialize() == NET_NFC_OK){ + // deinitialize is success + } + + return 0; + } + + @endcode + +*/ +net_nfc_error_e net_nfc_deinitialize(void); + +/** + You should register callback before calling the asyn functions. + All of result comes from callback function, such as data of read operation, + Target infomation and the event of async operation completions. + you can replace callback or user_parameter any time by calling this function. + callback resgister's user_parameter is used only if the event does not have owner. + most of event gerenrated by calling async APIs, but detection event, detatch + event, and etc does not have event owner. These events return the user_param + in the callback function + if you call this function when the callback function is already registered, it replaces + the new callback and user_param. + + @param[in] cb callback function + @param[in] user_param userdata that will be delivered when the event does not have owner + + @return return the result of the calling this function + + @code + void net_nfc_cb(net_nfc_message_e message, net_nfc_error_e result, void* data , void* userContext) + { + switch(message) + { + ...... + default: + break; + } + } + + @exception NET_NFC_NULL_PARAMETER Null parameter is received + + int main() + { + + net_nfc_error_e result; + result = net_nfc_initialize(); + check_result(result); + + result = net_nfc_set_response_callback (net_nfc_cb, &user_context2); + check_result(result); + + return 0; + } + + @endcode + +*/ +net_nfc_error_e net_nfc_set_response_callback(net_nfc_response_cb cb, void *user_param); + +/** + this function unregsiters the callback function. + + @return return the result of the calling this function + + @exception NET_NFC_NOT_REGISTERED unset is requested but the callback was not registered before + + @code + int main() + { + + net_nfc_error_e result; + result = net_nfc_initialize(); + check_result(result); + + result = net_nfc_set_response_callback (net_nfc_cb, &user_context2); + check_result(result); + + net_nfc_unset_response_callback (); + return 0; + } + @endcode +*/ +net_nfc_error_e net_nfc_unset_response_callback(void); + +/** + this function enables/disables the app select popup. + If you use this function to block popup, you should allow that when your app is closed. + + @param[in] enable enable or disable + + @return return the result of the calling this function + + @code + int main() + { + net_nfc_error_e result; + result = net_nfc_initialize(); + check_result(result); + + // block app launch popup + result = net_nfc_set_launch_popup_state(FALSE); + check_result(result); + + // allow app launch popup + result = net_nfc_set_launch_popup_state(TRUE); + check_result(result); + + return 0; + } + @endcode +*/ +net_nfc_error_e net_nfc_set_launch_popup_state(int enable); + +/** + this function get state of the app select popup. + If you use this function to block popup, you should allow that when your app is closed. + + @return true on enabled, otherwise false. + + @code + int main() + { + return net_nfc_get_launch_popup_state(); + } + @endcode +*/ +net_nfc_error_e net_nfc_get_launch_popup_state(int *state); + + +/** + this function on/off the nfc module. + + @param[in] state nfc on or off + + @return return the result of the calling this function + + @code + int main() + { + net_nfc_error_e result; + + // nfc module on + result = net_nfc_set_state(TRUE); + check_result(result); + + result = net_nfc_initialize(); + check_result(result); + + // do something + + result = net_nfc_deinitialize(); + check_result(result); + + // nfc module off + result = net_nfc_set_state(FALSE); + check_result(result); + + return 0; + } + @endcode +*/ +net_nfc_error_e net_nfc_set_state(int state, net_nfc_set_activation_completed_cb callback); + +/** + this function returns the nfc module state. + + @param[out] state nfc on or off + + @return return the result of the calling this function + + @code + int main() + { + net_nfc_error_e result; + int state; + + result = net_nfc_get_state(&state); + check_result(result); + + if (state == FALSE) + { + // nfc module on + result = net_nfc_set_state(TRUE); + check_result(result); + } + + result = net_nfc_initialize(); + check_result(result); + + return 0; + } + @endcode +*/ +net_nfc_error_e net_nfc_get_state(int *state); + +/** + this function returns the nfc supported or not. + + @param[out] state nfc on or off + + @return return the result of the calling this function + + @code + int main() + { + net_nfc_error_e result; + int state; + + result = net_nfc_is_supported(&state); + check_result(result); + + if (state == FALSE) + { + // nfc module on + result = net_nfc_is_supported(TRUE); + check_result(result); + } + + + return 0; + } + @endcode +*/ +net_nfc_error_e net_nfc_is_supported(int *state); + + +/* THIS API is temp for multiple client */ + +net_nfc_error_e net_nfc_state_activate(void); +net_nfc_error_e net_nfc_state_deactivate(void); + +/** +@} */ + +#ifdef __cplusplus +} +#endif + + +#endif + diff --git a/src/clientlib/include/net_nfc_apdu.h b/src/clientlib/include/net_nfc_apdu.h new file mode 100755 index 0000000..9ca81b7 --- /dev/null +++ b/src/clientlib/include/net_nfc_apdu.h @@ -0,0 +1,130 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#ifndef __NET_NFC_APDU__ +#define __NET_NFC_APDU__ + +#include "net_nfc_typedef.h" + + +#ifdef __cplusplus + extern "C" { +#endif + + +typedef unsigned int apdu_slot_t; +typedef unsigned int apdu_channel_t; +typedef void (* net_nfc_apdu_response_cb ) (net_nfc_error_e result, apdu_channel_t channel, data_h data, void* user_data); + +/** +@addtogroup NET_NFC_MANAGER_APDU +@{ + +*/ + +/** + initialize the apdu api. the callback function will be called when the data is arrived from simcard or SE + + @param[in] callback callback function + @param[in] user_data context value that will be delivered to the callback function + + @return return the result of the calling the function +*/ +net_nfc_error_e net_nfc_register_apdu_cb (net_nfc_apdu_response_cb callback, void * user_data); + +/** + + allows to select the slot. UICC or SE + +
    +
  • slot# 0 : UICC <\li> +
  • slot# 1 : Secure Element<\li> +
+ + @param[in] slot slot for mms + + @return return the result of the calling the function +*/ +net_nfc_error_e net_nfc_select_apdu_slot (apdu_slot_t slot); + +/** + Answer to reset is the sequence of bytes output by a chip card after the card reader has electrically reset the card. + The ATR tells the reader which communication capabilities the card has. The format of the ATR is defined in ISO/IEC 7816-3.[1] + this function return ATR data if the simcard is available, or NULL will be returned + + @param[out] data ATR data will be returned if the simcard is available. + + @return return the result of the calling the function + +*/ +net_nfc_error_e net_nfc_get_apdu_answer_to_reset (data_h data); + +/** + this opens a channel to communicate with application on the simcard. + you may open the channel with + + @param[out] channel return the assined chennel + @param[in] aid application id that mached in the simcard application + + @return return the result of the calling the function + +*/ +net_nfc_error_e net_nfc_open_apdu_channel (apdu_channel_t *channel , net_nfc_string_t aid); + +/** + send the apud data to opened channel. + + @param[in] channel channel number that already opened + @param[in] data data value that will be send + + @return return the result of the calling the function +*/ +net_nfc_error_e net_nfc_send_apdu_command (apdu_channel_t channel, data_t data); + +/** + closes opened channel + + @param[in] channel channel number + + @return return the result of the calling the function +*/ +net_nfc_error_e net_nfc_close_apdu_channel (apdu_channel_t channel); + +/** + disconnect all the channel and return to original state. it stops calling callback function + + @return return the result of the calling the function + + @exception NET_NFC_NOT_REGISTERED unset is requested but the callback was not registered before +*/ +net_nfc_error_e net_nfc_unset_apdu_cb (void); + + +/** +@} +*/ + + + +#ifdef __cplusplus +} +#endif + + +#endif + + diff --git a/src/clientlib/include/net_nfc_client_dispatcher_private.h b/src/clientlib/include/net_nfc_client_dispatcher_private.h new file mode 100755 index 0000000..4583032 --- /dev/null +++ b/src/clientlib/include/net_nfc_client_dispatcher_private.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#ifndef NET_NFC_CLIENT_DISPATCHER_H +#define NET_NFC_CLIENT_DISPATCHER_H + +#include "net_nfc_typedef.h" +#include "net_nfc_typedef_private.h" + +#ifdef USE_GLIB_MAIN_LOOP +void net_nfc_client_call_dispatcher_in_g_main_loop(net_nfc_response_cb client_cb, net_nfc_response_msg_t* msg); +#elif USE_ECORE_MAIN_LOOP +void net_nfc_client_call_dispatcher_in_ecore_main_loop(net_nfc_response_cb client_cb, net_nfc_response_msg_t* msg); +#else +void net_nfc_client_call_dispatcher_in_current_context(net_nfc_response_cb client_cb, net_nfc_response_msg_t* msg); +#endif +bool net_nfc_client_dispatch_sync_response(net_nfc_response_msg_t *msg); + +#endif + diff --git a/src/clientlib/include/net_nfc_client_ipc_private.h b/src/clientlib/include/net_nfc_client_ipc_private.h new file mode 100755 index 0000000..5fef309 --- /dev/null +++ b/src/clientlib/include/net_nfc_client_ipc_private.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#ifndef NET_NFC_CLIENT_IPC_H +#define NET_NFC_CLIENT_IPC_H + +#include "net_nfc_typedef.h" +#include "net_nfc_util_ipc.h" + +net_nfc_error_e net_nfc_client_socket_initialize(); +void net_nfc_client_socket_finalize(); +bool net_nfc_client_is_connected(); + +net_nfc_error_e net_nfc_client_send_reqeust(net_nfc_request_msg_t *msg, ...); +net_nfc_error_e net_nfc_client_send_reqeust_sync(net_nfc_request_msg_t *msg, ...); + +void _net_nfc_client_set_cookies(const char * cookie, size_t size); +void _net_nfc_client_free_cookies(void); + +net_nfc_error_e _net_nfc_client_register_cb(net_nfc_response_cb cb); +net_nfc_error_e _net_nfc_client_unregister_cb(void); + +#endif + diff --git a/src/clientlib/include/net_nfc_client_nfc_private.h b/src/clientlib/include/net_nfc_client_nfc_private.h new file mode 100755 index 0000000..fb650bb --- /dev/null +++ b/src/clientlib/include/net_nfc_client_nfc_private.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#ifndef __NET_NFC_CLIENT_NET_NFC_PRIVATE_H__ +#define __NET_NFC_CLIENT_NET_NFC_PRIVATE_H__ + +#include "net_nfc_typedef_private.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +client_context_t *net_nfc_get_client_context(); +bool net_nfc_tag_is_connected(); +net_nfc_error_e net_nfc_send_init(void *context); +net_nfc_error_e net_nfc_send_deinit(void *context); + +typedef bool (*net_nfc_client_cb)(net_nfc_message_e message, net_nfc_error_e result, void* user_param); + +net_nfc_error_e net_nfc_util_release_tag_info(net_nfc_target_info_s *info); +bool net_nfc_util_check_tag_filter(net_nfc_target_type_e type); + +/** + @} */ + +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/src/clientlib/include/net_nfc_client_util_private.h b/src/clientlib/include/net_nfc_client_util_private.h new file mode 100755 index 0000000..04d179c --- /dev/null +++ b/src/clientlib/include/net_nfc_client_util_private.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __NET_NFC_CLIENT_UTIL_PRIVATE__ +#define __NET_NFC_CLIENT_UTIL_PRIVATE__ + +#endif + diff --git a/src/clientlib/include/net_nfc_data.h b/src/clientlib/include/net_nfc_data.h new file mode 100755 index 0000000..f5bec10 --- /dev/null +++ b/src/clientlib/include/net_nfc_data.h @@ -0,0 +1,144 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include + + +#ifndef __NET_NFC_DATA_H__ +#define __NET_NFC_DATA_H__ + +#ifdef __cplusplus +extern "C" { +#endif + + +/** + +@addtogroup NET_NFC_MANAGER_INFO +@{ + This document is for the APIs reference document + + NFC Manager defines are defined in + + @li @c #net_nfc_initialize Initialize the nfc device. + +*/ + +/** + create data handler only. + + @param[out] data data handler + + @return return the result of this operation + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) + @exception NET_NFC_ALLOC_FAIL memory allocation is failed +*/ + +net_nfc_error_e net_nfc_create_data_only (data_h* data); + +/** + create data handler with initial values, bytes will be copied into the data handler. + + @param[out] data data handler + @param[in] bytes binary data + @param[in] length size of binary data; + + @return return the result of this operation + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) + @exception NET_NFC_ALLOC_FAIL memory allocation is failed +*/ +net_nfc_error_e net_nfc_create_data (data_h* data, const uint8_t* bytes, const uint32_t length); + +/** + get the byes and length from data handler. data handler assume bytes may have '0x0' value. + that's why this function also provides the length. + + @param[in] data data handler + @param[out] bytes binary pointer (it returns the direct pointer of handler's data) do not free this + @param[out] length length of the binary data; + + @return return the result of this operation + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) +*/ +net_nfc_error_e net_nfc_get_data (const data_h data, uint8_t** bytes, uint32_t * length); + +/** + replace the data handler with given bytes. binary data (bytes) will be copied to data hander. + application should free or use local variable for given byte pointer. + + @param[in] data data handler + @param[in] bytes binary data + @param[in] length size of binary data + + @return return the result of this operation + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) +*/ + +net_nfc_error_e net_nfc_set_data (const data_h data, const uint8_t* bytes, const uint32_t length); + +/** + get length of data handler's bytes. + + @param[in] data data handler + + @return length of bytes length + + @exception 0 is returned if data is NULL +*/ + +uint32_t net_nfc_get_data_length (const data_h data); + +/** + get pointer of the handler's bytes (do not free this. it wll be freed when the application call "net_nfc_free_data" function + + @param[in] data data handler + + @return the pointer of bytes. + + @exception NULL is returned if data is NULL +*/ + +uint8_t * net_nfc_get_data_buffer (const data_h data); + +/** + free data handler. (it also free the copied bytes) + + @param[in] data data handler + + @return return the result of this operation + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) +*/ + +net_nfc_error_e net_nfc_free_data (data_h data); + + + +/** +@} +*/ +#ifdef __cplusplus +} +#endif + + +#endif + diff --git a/src/clientlib/include/net_nfc_exchanger.h b/src/clientlib/include/net_nfc_exchanger.h new file mode 100755 index 0000000..9017652 --- /dev/null +++ b/src/clientlib/include/net_nfc_exchanger.h @@ -0,0 +1,127 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#ifndef __SLP_NET_NFC_EXCHANGER_H__ +#define __SLP_NET_NFC_EXCHANGER_H__ + + +#include "net_nfc_typedef.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** +@addtogroup NET_NFC_MANAGER_EXCHANGE +@{ + +*/ + + +/** + create net_nfc_exchagner raw type data handler with given values + + @param[out] ex_data exchangner handler + @param[in] payload the data will be deliver (NDEF message) + + @return result of this function call + + @exception NET_NFC_ALLOC_FAIL memory allocation is failed + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illegal NULL pointer(s) +*/ +net_nfc_error_e net_nfc_create_exchanger_data(net_nfc_exchanger_data_h *ex_data, data_h payload); + +/** + this makes free exchagner data handler + + @param[in] ex_data exchagner handler + + @return result of this function call + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) +*/ + +net_nfc_error_e net_nfc_free_exchanger_data (net_nfc_exchanger_data_h ex_data); + + +net_nfc_error_e net_nfc_send_exchanger_data (net_nfc_exchanger_data_h ex_handle, net_nfc_target_handle_h target_handle, void* trans_param); + +/** + request connection handover with discovered P2P device + + @param[in] target_handle target device handle + @param[in] type specific alternative carrier type (if type is NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN, it will be selected available type of this target) + @param[in] trans_param user data + + @return result of this function call + + @exception NET_NFC_ALLOC_FAIL memory allocation is failed + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) +*/ +net_nfc_error_e net_nfc_exchanger_request_connection_handover(net_nfc_target_handle_h target_handle, net_nfc_conn_handover_carrier_type_e type); + +/** + get alternative carrier type from connection handover information handle. + + @param[in] info_handle connection handover information handle + @param[out] type alternative carrier type + + @return return the result of this operation + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) +*/ +net_nfc_error_e net_nfc_exchanger_get_alternative_carrier_type(net_nfc_connection_handover_info_h info_handle, net_nfc_conn_handover_carrier_type_e *type); + +/** + get alternative carrier dependant data from connection handover information handle. + Bluetooth : target device address + Wifi : target device ip address + + @param[in] info_handle connection handover information handle + @param[out] data alternative carrier data + + @return return the result of this operation + + @exception NET_NFC_ALLOC_FAIL memory allocation is failed + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) +*/ +net_nfc_error_e net_nfc_exchanger_get_alternative_carrier_data(net_nfc_connection_handover_info_h info_handle, data_h *data); + +/** + this makes free alternative carrier data handler + + @param[in] info_handle alternative carrier data handler + + @return result of this function call + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) +*/ +net_nfc_error_e net_nfc_exchanger_free_alternative_carrier_data(net_nfc_connection_handover_info_h info_handle); + + +/** +@} + +*/ + + +#ifdef __cplusplus +} +#endif + + +#endif diff --git a/src/clientlib/include/net_nfc_exchanger_private.h b/src/clientlib/include/net_nfc_exchanger_private.h new file mode 100755 index 0000000..ea138ea --- /dev/null +++ b/src/clientlib/include/net_nfc_exchanger_private.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#ifndef __SLP_NET_NFC_EXCHANGER_H__ +#define __SLP_NET_NFC_EXCHANGER_H__ + + +#include "net_nfc_typedef.h" +#include "net_nfc_typedef_private.h" + +#ifdef __cplusplus +extern "C" { +#endif + + +net_nfc_exchanger_cb net_nfc_get_exchanger_cb (void); + +/** +@} + +*/ + + +#ifdef __cplusplus +} +#endif + + +#endif diff --git a/src/clientlib/include/net_nfc_internal_se.h b/src/clientlib/include/net_nfc_internal_se.h new file mode 100755 index 0000000..5acab58 --- /dev/null +++ b/src/clientlib/include/net_nfc_internal_se.h @@ -0,0 +1,141 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#ifndef __NET_NFC_INTERNAL_SE_H__ +#define __NET_NFC_INTERNAL_SE_H__ + +#include "net_nfc_typedef.h" + + +#ifdef __cplusplus + extern "C" { +#endif + + +/** + +@addtogroup NET_NFC_MANAGER_SECURE_ELEMENT +@{ + This document is for the APIs reference document + + NFC Manager defines are defined in + + @li @c #net_nfc_set_secure_element_type set secure element type + @li @c #net_nfc_get_secure_element_type get current selected secure element + @li @c #net_nfc_open_internal_secure_element open selected secure element + @li @c #net_nfc_close_internal_secure_element close selected secure element + @li @c #net_nfc_send_apdu send apdu + + + +*/ + +/** + set secure element type. secure element will be a UICC or ESE. only one secure element is selected in a time. external reader can communicate with + secure element by emitting RF + + \par Sync (or) Async: Sync + This is a Asynchronous API + + @param[in] se_type secure element type + @param[in] trans_param user data that will be delivered to callback + + @return return the result of the calling the function + + @exception NET_NFC_INVALID_PARAM not supported se_type + +*/ + +net_nfc_error_e net_nfc_set_secure_element_type(net_nfc_se_type_e se_type, void* trans_param); + +/** + get current select se type. + + \par Sync (or) Async: Sync + This is a Asynchronous API + + @param[in] se_type secure element type + @param[in] trans_param user data that will be delivered to callback + + @return return the result of the calling the function + + @exception NET_NFC_INVALID_PARAM not supported se_type + +*/ + +net_nfc_error_e net_nfc_get_secure_element_type(void* trans_param); + +/** + open and intialize the type of secure element. if the type of secure element is selected, then change mode as MODE OFF to prevent to be detected by external reader + + \par Sync (or) Async: Sync + This is a Asynchronous API + + @param[in] se_type secure element type + @param[in] trans_param user data that will be delivered to callback + + @return return the result of the calling the function + + @exception NET_NFC_INVALID_PARAM not supported se_type + +*/ + +net_nfc_error_e net_nfc_open_internal_secure_element(net_nfc_se_type_e se_type, void* trans_param); + +/** + close opend secure element and change back to previous setting + + \par Sync (or) Async: Sync + This is a Asynchronous API + + @param[in] handle the handle of opend secure element + @param[in] trans_param user data that will be delivered to callback + + @return return the result of the calling the function + + @exception NET_NFC_INVALID_PARAM not supported se_type + +*/ + +net_nfc_error_e net_nfc_close_internal_secure_element(net_nfc_target_handle_h handle, void* trans_param); + +/** + send apdu to opend secure element + + \par Sync (or) Async: Sync + This is a Asynchronous API + + @param[in] handle the handle of opend secure element + @param[in] apdu apdu command to send + @param[in] trans_param user data that will be delivered to callback + + @return return the result of the calling the function + + @exception NET_NFC_INVALID_PARAM invalid + +*/ + +net_nfc_error_e net_nfc_send_apdu(net_nfc_target_handle_h handle, data_h apdu, void* trans_param); + + +#ifdef __cplusplus +} +#endif + + +#endif + diff --git a/src/clientlib/include/net_nfc_llcp.h b/src/clientlib/include/net_nfc_llcp.h new file mode 100755 index 0000000..fc091f6 --- /dev/null +++ b/src/clientlib/include/net_nfc_llcp.h @@ -0,0 +1,634 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#ifndef __NET_NFC_LLCP_H__ +#define __NET_NFC_LLCP_H__ + +#include "net_nfc_typedef.h" + +#ifdef __cplusplus + extern "C" { +#endif + +/** + +@addtogroup NET_NFC_MANAGER_LLCP +@{ + This document is for the APIs reference document + + NFC Manager defines are defined in + + @li @c #net_nfc_initialize Initialize the nfc device. + +*/ + +/** + + This function creates a socket can handle connection oriented or connectless connection. To create the socket, socket option should be specified. + The option structure has three attributes. + + \par Sync (or) Async: Async + + @param[out] socket The socket handler that generated by this function + @param[in] options This describe the socket types (MIU, RW, Connection type) please, refer the comments + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) + +*/ + +net_nfc_error_e net_nfc_create_llcp_socket (net_nfc_llcp_socket_t * socket, net_nfc_llcp_socket_option_h options); + +/** + Register socket callback, this callback should register to get socket activities + you can register callback any time just after getting socket handler. + when events is delivered before register callback, all event's will be ignored. + we recommand register callbac just after create a socket. + + @param[in] socket socket handle + @param[in] cb callback function + @param[in] user_param user parameter that will be deliver when the callback is called + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) + @exception NET_NFC_LLCP_INVALID_SOCKET invalied socket handler is recieved + +*/ + +net_nfc_error_e net_nfc_set_llcp_socket_callback (net_nfc_llcp_socket_t socket, net_nfc_llcp_socket_cb cb, void * user_param); + +/** + unregister callback from socket. + + @param[in] socket socket handle + + @return return the result of the calling the function + + @exception NET_NFC_LLCP_INVALID_SOCKET invalied socket handler is recieved + @exception NET_NFC_NOT_REGISTERED callback was not registered +*/ + +net_nfc_error_e net_nfc_unset_llcp_socket_callback (net_nfc_llcp_socket_t socket); + +/** + listen the remote connection with service name and sap number. The service name is a string. + + Please, refer SAP values range
+ - 00 ~ 15 : Identifies the Well-Known Service Access Points
+ - 16 ~ 31 : Identifies Services in the local service environment and are advertised by local SDP
+ - 32 ~ 61 : Identifies Services in the local service environment and are NOT advertised by local SDP
+ + please follow well known name prefix + well known service name should be "urn:nfc:sn:" + external service name "urn:nfc:xsn::" + + @param[in] socket socket handler + @param[in] service_name service name URI, (maxium length is 256) + @param[in] sap the sap number that will be bind + @param[in] trans_param user parameter + + @return return the result of the calling the function + + @exception NET_NFC_LLCP_INVALID_SOCKET invalied socket handler is recieved + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) + @exception NET_NFC_ALLOC_FAIL memory allocation is failed + @exception NET_NFC_INSUFFICIENT_STORAGE it reached maximum number of socket. + @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error + @exception NET_NFC_INVALID_STATE interanl error + @exception NET_NFC_ALREADY_REGISTERED SAP number is already in used + +*/ + + +net_nfc_error_e net_nfc_listen_llcp (net_nfc_llcp_socket_t socket, const char * service_name , sap_t sap, void * trans_param); + +/** + + disconnect current connection + + @param[in] socket socket handler + @param[in] trans_param user parameter + + @return return the result of the calling the function + + @exception NET_NFC_LLCP_INVALID_SOCKET invalied socket handler is recieved + @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error + @exception NET_NFC_INVALID_STATE interanl error + @exception NET_NFC_LLCP_SOCKET_DISCONNECTED socket is disconnected + +*/ + +net_nfc_error_e net_nfc_disconnect_llcp (net_nfc_llcp_socket_t socket , void * trans_param); + +/** + close the socket. if you call the this function before call disconnect, automatically, call disonnection inside socket close + + @param[in] socket socket handler + @param[in] trans_param user parameter + + @return return the result of the calling the function + + @exception NET_NFC_LLCP_INVALID_SOCKET invalied socket handler is recieved + @exception NET_NFC_INVALID_STATE interanl error + +*/ + + +net_nfc_error_e net_nfc_close_llcp_socket(net_nfc_llcp_socket_t socket , void * trans_param); + + +/** + send data to remote device. it return callback event when the sending is completed. This api is for connection oriented socket + + @param[in] socket socket handler + @param[in] data raw data to send to remote device + @param[in] trans_param user parameter + + @return return the result of the calling the function + + @exception NET_NFC_LLCP_INVALID_SOCKET invalied socket handler is recieved + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) + @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error + @exception NET_NFC_INVALID_STATE interanl error + @exception NET_NFC_LLCP_SOCKET_FRAME_REJECTED requested data is rejected + @exception NET_NFC_LLCP_SOCKET_DISCONNECTED socket is disconnected + +*/ + +net_nfc_error_e net_nfc_send_llcp (net_nfc_llcp_socket_t socket, data_h data , void * trans_param); + + +/** + recieve data from remote device, received data will be delivered in callback function, + cast the data pointer into "data_h". This api is for connection oriented socket. + + @param[in] socket socket handler + @param[in] req_length length of data will be read + @param[in] trans_param user parameter + + @return return the result of the calling the function + + @exception NET_NFC_LLCP_INVALID_SOCKET invalied socket handler is recieved + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) + @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error + @exception NET_NFC_INVALID_STATE interanl error + @exception NET_NFC_LLCP_SOCKET_FRAME_REJECTED requested data is rejected + @exception NET_NFC_LLCP_SOCKET_DISCONNECTED socket is disconnected +*/ + +net_nfc_error_e net_nfc_receive_llcp (net_nfc_llcp_socket_t socket, size_t req_length, void * trans_param); + + + +/** + send data to remote device. it return callback event when the sending is completed. + this API is for connectionless socket + + @param[in] socket socket handler + @param[in] data raw data to send to remote device + @param[in] trans_param user parameter + + @return return the result of the calling the function + + @exception NET_NFC_LLCP_INVALID_SOCKET invalied socket handler is recieved + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) + @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error + @exception NET_NFC_INVALID_STATE interanl error + @exception NET_NFC_LLCP_SOCKET_FRAME_REJECTED requested data is rejected + @exception NET_NFC_LLCP_SOCKET_DISCONNECTED socket is disconnected +*/ + +net_nfc_error_e net_nfc_send_to_llcp (net_nfc_llcp_socket_t socket,sap_t dsap, data_h data , void * trans_param); + + +/** + recieve data from remote device, received data will be delivered in callback function, + cast the data pointer into "data_h". + this API is for connectionless socket + + @param[in] socket socket handler + @param[in] req_length length of data will be read + @param[in] trans_param user parameter + + @return return the result of the calling the function + + @exception NET_NFC_LLCP_INVALID_SOCKET invalied socket handler is recieved + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) + @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error + @exception NET_NFC_INVALID_STATE interanl error + @exception NET_NFC_LLCP_SOCKET_FRAME_REJECTED requested data is rejected + @exception NET_NFC_LLCP_SOCKET_DISCONNECTED socket is disconnected + @exception NET_NFC_ALREADY_REGISTERED SAP number is already in used +*/ + +net_nfc_error_e net_nfc_receive_from_llcp (net_nfc_llcp_socket_t socket, sap_t ssap, size_t req_length, void * trans_param); + + +/** + connect to the remote device with destiantion sap number you should know the sap number (0 ~ 61) + + @param[in] socket socket handler + @param[in] sap sap (Service Access Point) of remote device + @param[in] trans_param user parameter + + @return return the result of the calling the function + + @exception NET_NFC_LLCP_INVALID_SOCKET invalied socket handler is recieved + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) + @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error + @exception NET_NFC_INVALID_STATE interanl error + @exception NET_NFC_LLCP_SOCKET_FRAME_REJECTED requested data is rejected + @exception NET_NFC_LLCP_SOCKET_DISCONNECTED socket is disconnected +*/ + +net_nfc_error_e net_nfc_connect_llcp_with_sap (net_nfc_llcp_socket_t socket, sap_t sap , void * trans_param); + + +/** + connect to the remote device's service name. + + @param[in] socket socket handler + @param[in] service_name service name of the + @param[in] trans_param user parameter + + @return return the result of the calling the function + + @exception NET_NFC_LLCP_INVALID_SOCKET invalied socket handler is recieved + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) + @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error + @exception NET_NFC_INVALID_STATE interanl error +*/ + +net_nfc_error_e net_nfc_connect_llcp (net_nfc_llcp_socket_t socket, const char * service_name , void * trans_param); + + +/** + + get local infomation of local device. the device infomation can be configurable with "net_nfc_llcp_set_configure" function + + @param[out] config configuration info + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) +*/ + +net_nfc_error_e net_nfc_get_llcp_local_configure (net_nfc_llcp_config_info_h * config); + +/** + + get local infomation of remote device. + + @param[in] handle target handle that be optained just after the target detect + @param[out] config configuration handle + + @return return the result of the calling the function + +*/ + +net_nfc_error_e net_nfc_get_llcp_remote_configure (net_nfc_target_handle_h handle, net_nfc_llcp_config_info_h * config); + +/** + + configure the local device's llcp options this function is optional if you didn't configure local device all the value will be set with default values + + @param[in] config configuration handle + @param[in] trans_param user parameter + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) + +*/ + +net_nfc_error_e net_nfc_set_llcp_local_configure (net_nfc_llcp_config_info_h config , void * trans_param); + +/** + this function return the current local socket options. if you need to know the remote connection's socket + info please call "net_nfc_llcp_get_remote_socket_option" function + + @param[in] socket socket handler + @param[out] option infomation of the socket + + @return return the result of the calling the function + + @exception NET_NFC_LLCP_INVALID_SOCKET invalied socket handler is recieved +*/ + + +net_nfc_error_e net_nfc_get_llcp_local_socket_option (net_nfc_llcp_socket_t socket, net_nfc_llcp_socket_option_h * option); + +/** + + this function return the current remote socket options. + + @param[in] socket socket handler + @param[out] option infomation of the socket + + @return return the result of the calling the function + + @exception NET_NFC_LLCP_INVALID_SOCKET invalied socket handler is recieved +*/ + +net_nfc_error_e net_nfc_get_llcp_remote_socket_option (net_nfc_llcp_socket_t socket, net_nfc_llcp_socket_option_h * option); + +/** + this function create the attribtues of socket. + + - MIU (Maximum Information Unit) : Maximum size of infomation unit of LLC PDU (you may assume a packet in network system) + An LLC SHALL NOT send any LLC PDU with an information field that is larger than the Link MIU determined for the remote LLC. + An LLC MAY discard any received LLC PDU with an information field that is larger than the local LLCs Link MIU value. + The default value is 128, and range of this value is 128 - 1152
+ - RW (Receive Window Size) : Rnage 1 -15 (default is 1), if the value is 0 it does not accept I PDU's on that data link connection. + A receive window size of one indicates that the local LLC will acknowledge every I PDU before accepting additional I PDUs.
+ - Socket types : two types of socket are connection oriented and connection less. the default value is connection oriented
+ + + @param[out] option socket option handler + @param[in] miu Maximum Information Unit + @param[in] rw Receive Window Size + @param[in] type socket type (connection oriented or connection less) + + @return return the result of the calling the function + + @exception NET_NFC_OUT_OF_BOUND given parameter is out of bound + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) +*/ + +net_nfc_error_e net_nfc_create_llcp_socket_option (net_nfc_llcp_socket_option_h * option, uint16_t miu, uint8_t rw, net_nfc_socket_type_e type); + +/** + create default socket option handler. this function create handler and set the all of the socket option with default values + @param[out] option option handler + + @return return the result of the calling the function + + @exception NET_NFC_OUT_OF_BOUND given parameter is out of bound + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) +*/ + +net_nfc_error_e net_nfc_create_llcp_socket_option_default (net_nfc_llcp_socket_option_h * option); + +/** + this function help to get miu values from socket option + + @param[in] option socket option handle + @param[out] miu maximum infomation unit + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) +*/ +net_nfc_error_e net_nfc_get_llcp_socket_option_miu (net_nfc_llcp_socket_option_h option, uint16_t * miu); + +/** + this function help to set miu value to the socket option handle + + @param[in] option socket option handle + @param[out] miu maximum infomation unit + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) +*/ +net_nfc_error_e net_nfc_set_llcp_socket_option_miu (net_nfc_llcp_socket_option_h option, uint16_t miu); + +/** + this function help to get rt value from the socket option handle + + @param[in] option socket option handle + @param[out] rt receive window size + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) +*/ +net_nfc_error_e net_nfc_get_llcp_socket_option_rw (net_nfc_llcp_socket_option_h option, uint8_t * rt); + +/** + this function help to set miu value to the socket option handle + + @param[in] option socket option handle + @param[out] rt maximum infomation unit + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) + +*/ +net_nfc_error_e net_nfc_set_llcp_socket_option_rw (net_nfc_llcp_socket_option_h option, uint8_t rt); + +/** + this function help to get socket type value from the socket option handle + + @param[in] option socket option handle + @param[out] type socket type connection oriented or connectionless + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) +*/ +net_nfc_error_e net_nfc_get_llcp_socket_option_type (net_nfc_llcp_socket_option_h option, net_nfc_socket_type_e * type); + +/** + this function help to set socket type value to the socket option handle + + @param[in] option socket option handle + @param[out] type socket type connection oriented or connectionless + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) +*/ +net_nfc_error_e net_nfc_set_llcp_socket_option_type (net_nfc_llcp_socket_option_h option, net_nfc_socket_type_e type); + +/** + free the socket option handle + + @param[in] option socket option handle + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) +*/ +net_nfc_error_e net_nfc_free_llcp_socket_option (net_nfc_llcp_socket_option_h option); + + + /** + This function create llcp_config_info handler that contains the llcp configuration. + After creating this handler and put his configuration "net_nfc_set_llcp_local_configure" function + + note: + + @param[out] config configuration handler + @param[in] miu Maximum Information Unit + @param[in] wks well knwon service (please refer the note to get detail infomation) + @param[in] lto link time out value + @param[in] option option bits that describe the service support + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) + @exception NET_NFC_ALLOC_FAIL memory allocation is failed + @exception NET_NFC_OUT_OF_BOUND given parameter is out of bound + + Note: + - The WKS parameter SHALL be encoded as a 16-bit field. The most-significant bit of the 16-bit field value SHALL signify + SAP address 0Fh and the least-significant bit SHALL signify SAP address 00h. The other bits SHALL signify SAP addresses + corresponding to their respective bit positions. A bit set to ?1? SHALL indicate that a service listener is bound to the corresponding + well-known service access point. A bit set to ?0? SHALL indicate that no service listener is bound to the corresponding well-known + service access point.
+ + - The option field contains a single 8-bit byte representing a set of flags which indicate the link service class of + the sending LLC and the support of optional features implemented by the sending LLC.
+ */ + net_nfc_error_e net_nfc_create_llcp_configure (net_nfc_llcp_config_info_h * config,uint16_t miu, uint16_t wks, uint8_t lto, uint8_t option); + + + /** + this function create config info handle with default values. + + @param[out] config configuration handler + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) + @exception NET_NFC_ALLOC_FAIL memory allocation is failed + */ + + net_nfc_error_e net_nfc_create_llcp_configure_default (net_nfc_llcp_config_info_h * config); + + /** + getting miu value from config info handle + + @param[in] config config info handle + @param[out] miu maxium information unit + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) + */ + + net_nfc_error_e net_nfc_get_llcp_configure_miu (net_nfc_llcp_config_info_h config, uint16_t * miu); + /** + getting wks value from config info handle + + @param[in] config config info handle + @param[out] wks well-known service list + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) + */ + net_nfc_error_e net_nfc_get_llcp_configure_wks (net_nfc_llcp_config_info_h config, uint16_t * wks); + /** + getting lto value from config info handle + + @param[in] config config info handle + @param[out] lto link timeout value + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) + */ + net_nfc_error_e net_nfc_get_llcp_configure_lto (net_nfc_llcp_config_info_h config, uint8_t * lto); + /** + getting miu value from config info handle + + @param[in] config config info handle + @param[out] option option of socket type supports + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) + */ + net_nfc_error_e net_nfc_get_llcp_configure_option (net_nfc_llcp_config_info_h config, uint8_t * option); + /** + setting the miu value to config info handle + + @param[in] config config info handle + @param[in] miu maxium information unit + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) + @exception NET_NFC_OUT_OF_BOUND given parameter is out of bound + */ + net_nfc_error_e net_nfc_set_llcp_configure_miu (net_nfc_llcp_config_info_h config, uint16_t miu); + /** + setting the miu value to config info handle + + @param[in] config config info handle + @param[in] wks well-known service list + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) + */ + net_nfc_error_e net_nfc_set_llcp_configure_wks (net_nfc_llcp_config_info_h config, uint16_t wks); + /** + setting the miu value to config info handle + + @param[in] config config info handle + @param[in] lto link timeout value + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) + */ + net_nfc_error_e net_nfc_set_llcp_configure_lto (net_nfc_llcp_config_info_h config, uint8_t lto); + /** + setting the miu value to config info handle + + @param[in] config config info handle + @param[in] option option of socket type supports + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) + */ + net_nfc_error_e net_nfc_set_llcp_configure_option (net_nfc_llcp_config_info_h config, uint8_t option); + /** + free the configuration info + + @param[in] config config info handle + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) + */ + net_nfc_error_e net_nfc_free_llcp_configure (net_nfc_llcp_config_info_h config); + + + net_nfc_error_e net_nfc_get_current_target_handle(void* trans_param); + net_nfc_error_e net_nfc_get_current_target_handle_sync(net_nfc_target_handle_h *handle); + + /** +@} +*/ + + +#ifdef __cplusplus + } +#endif + + +#endif + + diff --git a/src/clientlib/include/net_nfc_ndef_message.h b/src/clientlib/include/net_nfc_ndef_message.h new file mode 100755 index 0000000..bc0a296 --- /dev/null +++ b/src/clientlib/include/net_nfc_ndef_message.h @@ -0,0 +1,447 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#ifndef __NET_NFC_NDEF_MESSAGE_H__ +#define __NET_NFC_NDEF_MESSAGE_H__ + +#include "net_nfc_typedef.h" + +#ifdef __cplusplus + extern "C" { +#endif + + +/** + +@addtogroup NET_NFC_MANAGER_NDEF +@{ + This document is for the APIs reference document + + NFC Manager defines are defined in + + @li @c #net_nfc_initialize Initialize the nfc device. + +*/ + +/** + create ndef message handler. this function allocate the ndef message handler and initialize. + + \par Sync (or) Async: sync + This is a Synchronous API + + @param[out] ndef_message instance of the ndef_message is retuened + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) + @exception NET_NFC_ALLOC_FAIL memory allocation is failed + + @code + + net_nfc_error_e result = NET_NFC_OK; + ndef_message_h msg = NULL; + ndef_record_h record = NULL; + + result = net_nfc_create_ndef_message (&msg); + if (result != NET_NFC_OK) return result; + + result = net_nfc_create_uri_type_record (&record , "http://www.samsung.com" ,NET_NFC_SCHEMA_FULL_URI); + if (result != NET_NFC_OK) return result; + + result = net_nfc_append_record_to_ndef_message (msg ,record); + if (result != NET_NFC_OK) return result; + + net_nfc_write_ndef(id, msg, &user_context); + + net_nfc_free_ndef_message (msg); + + @endcode +*/ + + +net_nfc_error_e net_nfc_create_ndef_message (ndef_message_h* ndef_message); + +/** + this APIs is the getter of record counts + + \par Sync (or) Async: sync + This is a Synchronous API + + @param[in] ndef_message output structure to get the record + @param[out] count number of record count + + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) + + @code + + static void net_nfc_cb(net_nfc_message_e message, net_nfc_error_e result, void* data , void* userContext) + { + switch (message) + { + case NET_NFC_MESSAGE_READ_NDEF: + { + if(data != NULL) + { + int count = 0; + ndef_message_h ndef = (ndef_message_h)(data); + net_nfc_get_ndef_message_record_count (ndef, &count); + printf ("record count = %d\n", count); + } + } + break; + } + } + @endcode +*/ +net_nfc_error_e net_nfc_get_ndef_message_record_count (ndef_message_h ndef_message, int * count); + +/** + This function converts the NDEF Message structure to serial bytes of ndef message. + + it gets copy of the rawdata bytes from ndef_message. ndef_message has no effect after free rawdata + Application should free rawdata. + + \par Sync (or) Async: sync + This is a Synchronous API + + @param[in] ndef_message output structure to get the record + @param[out] rawdata this is the raw data that will be formed into the + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) + @exception NET_NFC_ALLOC_FAIL memory allocation is failed + @exception NET_NFC_NDEF_BUF_END_WITHOUT_ME Wrong formatted NDEF message + + @code + + net_nfc_error_e result = NET_NFC_OK; + data_h rawdata; + ndef_message_h msg = NULL; + ndef_record_h record = NULL; + int idx; + uint8_t * buffer = NULL; + + result = net_nfc_create_ndef_message (&msg); + if (result != NET_NFC_OK) return result; + + result = net_nfc_create_uri_type_record (&record , "http://www.samsung.com" ,NET_NFC_SCHEMA_FULL_URI); + if (result != NET_NFC_OK) return result; + + result = net_nfc_append_record_to_ndef_message (msg ,record); + if (result != NET_NFC_OK) return result; + + net_nfc_create_rawdata_from_ndef_message (msg, &rawdata); + + buffer = net_nfc_get_data_buffer (rawdata) ; + + for (idx = 0; idx < net_nfc_get_data_length (rawdata) ; idx++) + { + printf (" %02X", buffer[idx]); + if (idx % 16 == 0) printf ("\n"); + } + + net_nfc_free_ndef_message (msg); + + @endcode + + +*/ + +net_nfc_error_e net_nfc_create_rawdata_from_ndef_message (ndef_message_h ndef_message, data_h* rawdata); + +/** + This function return the structure of ndef_message from serial format of ndef message. + You may say create ndef handler from raw serial bytes + it cunsumes the bytes array until get the (ME==1). it retunrs error if the bytes array does not have ME flag. + if the array has two NDEF Message serially (not recursive case - like smart poster). the first NDEF message + will be converted to ndef_message handler, and other messages will be ignored. + + \par Sync (or) Async: sync + This is a Synchronous API + + @param[out] ndef_message ndef message handler that will be returned + @param[in] rawdata ndef message that formed in bytes array + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) + @exception NET_NFC_ALLOC_FAIL memory allocation is failed + @exception NET_NFC_NDEF_BUF_END_WITHOUT_ME Wrong formatted NDEF message + + @code + + static void net_nfc_cb(net_nfc_message_e message, net_nfc_error_e result, void* data , void* userContext) + { + switch (message) + { + case NET_NFC_MESSAGE_READ_NDEF: + { + if(data != NULL) + { + record_h record; + ndef_message_h url; + data_h ndef_type; + data_h payload; + + ndef_message_h ndef = (ndef_message_h)(data); + net_nfc_get_record_by_index (ndef, 0, &record); + net_nfc_get_record_type (record, &ndef_type); + if (strncmp (ndef_type.buffer, "Sp", ndef_type.length)){ + net_nfc_get_record_payload (record, &payload); + net_nfc_create_ndef_message_from_rawdata (&url, payload); + printf_ndef_massage (url); + } + } + } + break; + } + } + @endcode + +*/ + + +net_nfc_error_e net_nfc_create_ndef_message_from_rawdata (ndef_message_h* ndef_message, data_h rawdata); + +/** + it returns the total size of ndef message bytes. parse the structure data and count the bytes + to know the length of bytes required to store the NDEF message. + + it calculates the length every time application calls this function. it does not cache inside. + TODO: do we need to cache the value inside of ndef_message_h + + \par Sync (or) Async: sync + This is a Synchronous API + + @param[in] ndef_message this is the raw data that will be formed into the + @param[out] length number of bytes required to create ndef message serial format + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) + +*/ + +net_nfc_error_e net_nfc_get_ndef_message_byte_length(ndef_message_h ndef_message, int * length) ; +/** + Append a record to ndef message structure. + This API help to create NDEF message and it control Record flags to follow the NDEF forum specification + + \par Sync (or) Async: sync + This is a Synchronous API + + @param[in] ndef_message NDEF message structure + @param[in] record a record will be added into the ndef message + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) + + @code + + net_nfc_error_e result = NET_NFC_OK; + data_h rawdata; + ndef_message_h msg = NULL; + ndef_record_h record = NULL; + int idx; + uint8_t * buffer = NULL; + + result = net_nfc_create_ndef_message (&msg); + if (result != NET_NFC_OK) return result; + + result = net_nfc_create_uri_type_record (&record , "http://www.samsung.com" ,NET_NFC_SCHEMA_FULL_URI); + if (result != NET_NFC_OK) return result; + + result = net_nfc_append_record_to_ndef_message (msg ,record); + if (result != NET_NFC_OK) return result; + + net_nfc_create_rawdata_from_ndef_message (msg, &rawdata); + + buffer = net_nfc_get_data_buffer (rawdata) ; + + for (idx = 0; idx < net_nfc_get_data_length (rawdata) ; idx++) + { + printf (" %02X", buffer[idx]); + if (idx % 16 == 0) printf ("\n"); + } + + net_nfc_free_ndef_message (msg); + + @endcode + + +*/ +net_nfc_error_e net_nfc_append_record_to_ndef_message(ndef_message_h ndef_message, ndef_record_h record); + +/** + remove the record that indicated by index number. + and this deleted record will be freed. + + \par Sync (or) Async: sync + This is a Synchronous API + + @param[in] ndef_message the message wil be freed + @param[in] index index of record + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) + @exception NET_NFC_OUT_OF_BOUND index is out of bound + @exception NET_NFC_INVALID_FORMAT Wrong formatted ndef message + +*/ + +net_nfc_error_e net_nfc_remove_record_by_index (ndef_message_h ndef_message, int index); + +/** + get record by index. this function just return the pointer of record. + if you change the record value it directly affected to NDEF message + + \par Sync (or) Async: sync + This is a Synchronous API + + @param[in] ndef_message the message wil be freed + @param[in] index index of record + @param[in] record record pointer + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) + @exception NET_NFC_OUT_OF_BOUND index is out of bound + +*/ +net_nfc_error_e net_nfc_get_record_by_index (ndef_message_h ndef_message, int index, ndef_record_h* record); + +/** + Add a record by index. This API help to add record by index. MB or ME bits will automatically assained. + + \par Sync (or) Async: sync + This is a Synchronous API + + @param[in] ndef_message the message wil be freed + @param[in] index index of record + @param[in] record record pointer + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) + @exception NET_NFC_OUT_OF_BOUND index is out of bound + @exception NET_NFC_INVALID_FORMAT Wrong formatted ndef message +*/ + +net_nfc_error_e net_nfc_append_record_by_index (ndef_message_h ndef_message,int index, ndef_record_h record); + + +/** + search the specific type in the NDEF message. this function return the first record that holds the type. + if the type has "urn:nfc:wkt:" or "urn:nfc:ext:", these prefix will be removed automatically. + + @param[in] ndef_message NDEF message handler + @param[in] tnf TNF value + @param[in] type Record type , include type length + @param[out] record record handle + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) + @exception NET_NFC_NO_DATA_FOUND search is failed + @exception NET_NFC_INVALID_FORMAT Wrong formatted ndef message + + @code + + static void net_nfc_cb(net_nfc_message_e message, net_nfc_error_e result, void* data , void* userContext) + { + switch (message) + { + case NET_NFC_MESSAGE_READ_NDEF: + { + if(data != NULL) + { + date_h type; + int count = 0; + ndef_message_h ndef = (ndef_message_h)(data); + ndef_record_h record; + net_nfc_create_data (&type, "Sp", 2); + net_nfc_search_record_by_type (ndef, NET_NFC_RECORD_WELL_KNOWN_TYPE, type, &record); + } + } + break; + } + } + + @endcode + +*/ +net_nfc_error_e net_nfc_search_record_by_type (ndef_message_h ndef_message, net_nfc_record_tnf_e tnf, data_h type, ndef_record_h * record); + + +/** + this function helps to free the ndef_message_s type structure. + it has multiple ndef_record_s with linked list form and each record has own pointer. + this function free these memory in one shot! + don't worry about the record handler. these handlers also freed. + + \par Sync (or) Async: sync + This is a Synchronous API + + @param[in] ndef_message the message wil be freed + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) + +*/ + +net_nfc_error_e net_nfc_free_ndef_message(ndef_message_h ndef_message); + + +/** + retreive ndef message which is read by nfc-manager . + after reading message, it will be removed from nfc-manager storage + + \par Sync (or) Async: sync + This is a Synchronous API + + @param[in] ndef_message the message wil be retrieved + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) + @exception NET_NFC_NO_NDEF_MESSAGE No ndef message is found + @exception NET_NFC_INVALID_FORMAT Wrong formatted ndef message + @exception NET_NFC_ALLOC_FAIL memory allocation is failed + +*/ + +net_nfc_error_e net_nfc_retrieve_current_ndef_message (ndef_message_h* ndef_message); + + +/** +@} */ + + +#ifdef __cplusplus +} +#endif + + +#endif + diff --git a/src/clientlib/include/net_nfc_ndef_message_handover.h b/src/clientlib/include/net_nfc_ndef_message_handover.h new file mode 100755 index 0000000..b13e13b --- /dev/null +++ b/src/clientlib/include/net_nfc_ndef_message_handover.h @@ -0,0 +1,421 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#ifndef __NET_NFC_NDEF_RECORD_H__ +#define __NET_NFC_NDEF_RECORD_H__ + +#include "net_nfc_typedef.h" + +#ifdef __cplusplus + extern "C" { +#endif + +/** + This function create wifi configure handler instance. + + @param[out] config instance handler + @param[in] type Carrier types it would be wifi add hoc or wifi AP + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) + @exception NET_NFC_OUT_OF_BOUND type value is not enum value + @exception NET_NFC_ALLOC_FAIL allocation is failed +*/ + +net_nfc_error_e net_nfc_create_carrier_config (net_nfc_carrier_config_h * config, net_nfc_conn_handover_carrier_type_e type); + +/** + Add property key and value for configuration. + the data will be copied to config handle, you should free used data array. + + @param[in] config instance handler + @param[in] attribute attribue key for value. + @param[in] size size of value + @param[in] data value array (binary type) + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) + @exception NET_NFC_ALLOC_FAIL allocation is failed +*/ + +net_nfc_error_e net_nfc_add_carrier_config_property (net_nfc_carrier_config_h config, uint16_t attribute, uint16_t size, uint8_t * data); + +/** + Remove the key and value from configuration, you can also remove the group withe CREDENTIAL key. + The the attribute is exist then it will be removed and also freed automatically. + + @param[in] config instance handler + @param[in] attribute attribue key for value. + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) + @exception NET_NFC_NO_DATA_FOUND the given key is not found + @exception NET_NFC_ALREADY_REGISTERED the given attribute is already registered +*/ + +net_nfc_error_e net_nfc_remove_carrier_config_property (net_nfc_carrier_config_h config, uint16_t attribute); +/** + Get the property value by attribute. + + @param[in] config instance handler + @param[in] attribute attribue key for value. + @param[out] size size of value + @param[out] data value array (binary type) + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) + @exception NET_NFC_NO_DATA_FOUND The given key is not found +*/ + +net_nfc_error_e net_nfc_get_carrier_config_property (net_nfc_carrier_config_h config, uint16_t attribute, uint16_t * size, uint8_t ** data); + +/** + The group will be joined into the configure + + @param[in] config instance handler + @param[in] group group handle + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) + @exception NET_NFC_ALREADY_REGISTERED The given group is already registered +*/ + +net_nfc_error_e net_nfc_append_carrier_config_group (net_nfc_carrier_config_h config, net_nfc_property_group_h group); + +/** + Remove the group from configure handle + + @param[in] config instance handler + @param[in] group group handle + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) + @exception NET_NFC_NO_DATA_FOUND given handle pointer is not exist in the configure handle +*/ + +net_nfc_error_e net_nfc_remove_carrier_config_group (net_nfc_carrier_config_h config, net_nfc_property_group_h group); + +/** + Get the group from configure handle by index + + @param[in] config instance handler + @param[in] index index number + @param[out] group group handle + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) + @exception NET_NFC_OUT_OF_BOUND the index number is not bound of the max count + @exception NET_NFC_NO_DATA_FOUND this is should be happened if the configure handle is dammaged +*/ + +net_nfc_error_e net_nfc_get_carrier_config_group (net_nfc_carrier_config_h config, int index, net_nfc_property_group_h * group); + +/** + free the configure handle + + @param[in] config instance handler + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) +*/ + +net_nfc_error_e net_nfc_free_carrier_config (net_nfc_carrier_config_h config); + +/** + create the group handle + + @param[out] group instance group handler + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) + @exception NET_NFC_ALLOC_FAIL allocation is failed +*/ + +net_nfc_error_e net_nfc_create_carrier_config_group (net_nfc_property_group_h * group, uint16_t attribute); + +/** + add property into the group + + @param[in] group instance group handler + @param[in] attribute attribute of the property + @param[in] size size of data (value) + @param[in] data data of the property + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) + @exception NET_NFC_ALLOC_FAIL allocation is failed + @exception NET_NFC_ALREADY_REGISTERED the given key is already registered +*/ + +net_nfc_error_e net_nfc_add_carrier_config_group_property (net_nfc_property_group_h group, uint16_t attribute, uint16_t size, uint8_t * data); + +/** + get property from group handle + + @param[in] group instance group handler + @param[in] attribute attribute of the property + @param[out] size size of data (value) + @param[out] data data of the property + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) + @exception NET_NFC_NO_DATA_FOUND the attribute does not exist in the group +*/ + +net_nfc_error_e net_nfc_get_carrier_config_group_property (net_nfc_property_group_h group, uint16_t attribute, uint16_t *size, uint8_t ** data); + +/** + remove the property from the group + + @param[in] group instance group handler + @param[in] attribute attribute of the property + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) + @exception NET_NFC_NO_DATA_FOUND the attribute does not exist in the group +*/ + +net_nfc_error_e net_nfc_remove_carrier_config_group_property (net_nfc_property_group_h group, uint16_t attribute); + + +/** + free the group + + @param[in] group instance group handler + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) +*/ + +net_nfc_error_e net_nfc_free_carrier_group (net_nfc_property_group_h group); + +/** + Create record handler with config. + + @param[out] record record handler + @param[in] config the wifi configure handle + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) + @exception NET_NFC_ALLOC_FAIL allocation is failed +*/ + +net_nfc_error_e net_nfc_create_ndef_record_with_carrier_config (ndef_record_h * record, net_nfc_carrier_config_h config); + + +/** + create configure from the ndef record. the. the record must contained the configuration. + config should be freed after using + + @param[in] record record handler + @param[out] config the configure handle + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) + @exception NET_NFC_ALLOC_FAIL allocation is failed + @exception NET_NFC_INVALID_FORMAT if the record does not contained the valid format. +*/ + +net_nfc_error_e net_nfc_create_carrier_config_from_config_record (net_nfc_carrier_config_h* config, ndef_record_h record); + +/** + append record into the connection handover request for reponse message; + + @param[in] message ndef message handler + @param[in] record record handler + @param[in] power_status the power status of the current configuration + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) + @exception NET_NFC_ALLOC_FAIL allocation is failed + @exception NET_NFC_INVALID_FORMAT if the record does not contained the valid format. + @exception NET_NFC_NO_DATA_FOUND the attribute does not exist in the group +*/ +net_nfc_error_e net_nfc_append_carrier_config_record (ndef_message_h message, ndef_record_h record, net_nfc_conn_handover_carrier_state_e power_status); + +/** + append record into the connection handover request for reponse message; + + @param[in] message ndef message handler + @param[in] record record handler + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) + @exception NET_NFC_ALLOC_FAIL allocation is failed + @exception NET_NFC_INVALID_FORMAT if the record does not contained the valid format. + @exception NET_NFC_NO_DATA_FOUND Given record does not exist in the ndef message +*/ + +net_nfc_error_e net_nfc_remove_carrier_config_record (ndef_message_h message, ndef_record_h record); + +/** + get configure record from ndef message by index + + @param[in] message ndef message handler + @param[in] index + @param[out] record record handler + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) + @exception NET_NFC_ALLOC_FAIL allocation is failed + @exception NET_NFC_INVALID_FORMAT if the record does not contained the valid format. +*/ + +net_nfc_error_e net_nfc_get_carrier_config_record (ndef_message_h message, int index, ndef_record_h * record); + +/** + get randome number from the connection request message + + @param[in] message ndef message handler + @param[out] randome_number randome number + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) + @exception NET_NFC_INVALID_FORMAT if the record does not contained the valid format. +*/ + +net_nfc_error_e net_nfc_get_handover_random_number(ndef_message_h message, unsigned short* random_number); + +/** + get the count of the alternative (configuration) in the message + + @param[in] message ndef message handler + @param[out] count number configuration in the message + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) + @exception NET_NFC_INVALID_FORMAT if the record does not contained the valid format. +*/ +net_nfc_error_e net_nfc_get_alternative_carrier_record_count (ndef_message_h message, unsigned int * count); + + +/** + get power status of the given configruation + + @param[in] message ndef message handler + @param[in] index index + @param[out] power_state power state of the alternative + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) + @exception NET_NFC_INVALID_FORMAT if the record does not contained the valid format. + @exception NET_NFC_NO_DATA_FOUND there is no alternative record is found + @exception NET_NFC_OUT_OF_BOUND index number is out of message count +*/ + +net_nfc_error_e net_nfc_get_alternative_carrier_power_status (ndef_message_h message, int index, net_nfc_conn_handover_carrier_state_e * power_state); + +/** + set power status of the given configruation + + @param[in] message ndef message handler + @param[in] index index + @param[in] power_state power state of the alternative + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) + @exception NET_NFC_INVALID_FORMAT if the record does not contained the valid format. + @exception NET_NFC_NO_DATA_FOUND there is no alternative record is found + @exception NET_NFC_OUT_OF_BOUND index number is out of message count +*/ +net_nfc_error_e net_nfc_set_alternative_carrier_power_status (ndef_message_h message, int index, net_nfc_conn_handover_carrier_state_e power_status); + +/** + this function will get carrier type. + + @param[in] carrier_info connection handover carrier info handler + @param[in] carrier_type record type. it can be a NET_NFC_CONN_HANDOVER_CARRIER_BT or NET_NFC_CONN_HANDOVER_CARRIER_WIFI or NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN. + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) +*/ + +net_nfc_error_e net_nfc_get_alternative_carrier_type (ndef_message_h message, int index, net_nfc_conn_handover_carrier_type_e * power_state); + + +/** + craete the connection handover request message + + @param[in] message connection handover carrier info handler + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) + @exception NET_NFC_ALLOC_FAIL allocation is failed +*/ + +net_nfc_error_e net_nfc_create_handover_request_message (ndef_message_h * message); + +/** + craete the connection handover select message + + @param[in] message connection handover carrier info handler + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) + @exception NET_NFC_ALLOC_FAIL allocation is failed +*/ + +net_nfc_error_e net_nfc_create_handover_select_message (ndef_message_h * message); + +/** + craete the connection handover error record message + + @param[out] record connection handover carrier info handler + @param[in] reason error codes (reason) + @param[in] data extra data for each error codes + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) + @exception NET_NFC_ALLOC_FAIL allocation is failed +*/ +net_nfc_error_e net_nfc_create_handover_error_record (ndef_record_h * record, uint8_t reason, uint32_t data); + + +#ifdef __cplusplus + } +#endif + + +#endif + + diff --git a/src/clientlib/include/net_nfc_ndef_record.h b/src/clientlib/include/net_nfc_ndef_record.h new file mode 100755 index 0000000..83077c6 --- /dev/null +++ b/src/clientlib/include/net_nfc_ndef_record.h @@ -0,0 +1,372 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#ifndef __NET_NFC_NDEF_RECORD_H__ +#define __NET_NFC_NDEF_RECORD_H__ + +#include "net_nfc_typedef.h" + +#ifdef __cplusplus + extern "C" { +#endif + + +/** + +@addtogroup NET_NFC_MANAGER_RECORD +@{ + This document is for the APIs reference document + + NFC Manager defines are defined in + +*/ + + +/** + This define gives you Message Begin from the flag byte + + @param[in] flag flag that comes from "net_nfc_get_record_flags" function + @return the mb flag + + @exception NONE +*/ +uint8_t net_nfc_get_record_mb (uint8_t flag); +/** + This define gives you Message end from the flag byte + + @param[in] flag flag that comes from "net_nfc_get_record_flags" function + @return the me flag + + @exception NONE +*/ +uint8_t net_nfc_get_record_me (uint8_t flag); +/** + This define gives you Chun Flag that indicate that either the first record chunk or a middle record chunk of a chunked payload + + @param[in] flag flag that comes from "net_nfc_get_record_flags" function + @return the chunk flag + + @exception NONE +*/ +uint8_t net_nfc_get_record_cf (uint8_t flag); +/** + This define gives you ID length present flag + + @param[in] flag flag that comes from "net_nfc_get_record_flags" function + @return the il (id length flag) flag + + @exception NONE + +*/ +uint8_t net_nfc_get_record_il (uint8_t flag); +/** + This define gives you short record flag. This flag indicates that the payload length filed is a single octet + + @param[in] flag flag that comes from "net_nfc_get_record_flags" function + @return the short record flag + + @exception NONE +*/ +uint8_t net_nfc_get_record_sr (uint8_t flag); + + + +/** + creat a record with given parameter value. this function automatically set the NDEF record flags + + @param[out] record Record handler + @param[in] tnf record type (TNF value) empty, well known, mime type, URI, external, or unchanged + @param[in] typeName specify type name ex) Sp, U, or Hr ... + @param[in] id record id + @param[in] payload payload of this record + + @return return the result of the calling the function + + @exception NET_NFC_OUT_OF_BOUND tnf value is out of range + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) + @exception NET_NFC_ALLOC_FAIL memory allocation is failed + + @code + char uri[] = " yahoo.com"; + ndef_record_s uriRecord; + + data_h payload; + + net_nfc_create_data (&payload, uri, strlen (uri)); + uri[0] = 0x01; + + if((result = net_nfc_create_record( &uriRecord, NET_NFC_RECORD_WELL_KNOWN_TYPE, "U" , NULL, payload, )) != NET_NFC_OK) + { + printf("U record is failed [%d]\n", result); + } + @endcode +*/ +net_nfc_error_e net_nfc_create_record(ndef_record_h* record, net_nfc_record_tnf_e tnf, data_h typeName, data_h id, data_h payload ); + + +/** + this function helps to create text type payload + please, refer the NDEF forum specification "Text Record Type Definition" + it creates byte array payload can be used in text type record + + this function does not encode the text. The paramter "text" will be asuumed as that it is already encoded with encode type. + this function just helps to create text records. + + @param[out] record Record handler + @param[in] text encoded text (this should be text not binary) + @param[in] language_code_str language_code_str ex) en-US + @param[in] encode text concoding type such as "utf8" + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) + @exception NET_NFC_ALLOC_FAIL memory allocation is failed + + + @code + net_nfc_error_e result = NET_NFC_OK; + ndef_message_h msg = NULL; + ndef_record_h record = NULL; + + char* message = "Hello, NFC World"; + + net_nfc_create_ndef_message (&msg); + net_nfc_create_text_type_record (&record , message, "en-US", NET_NFC_ENCODE_UTF_8); + net_nfc_append_record_to_ndef_message (msg ,record); + + @endcode + +*/ +net_nfc_error_e net_nfc_create_text_type_record(ndef_record_h* record, const char* text, const char* language_code_str, net_nfc_encode_type_e encode); + +/** + this function helps to create URI type payload + please refer the NFC forum specification "URI Record type Definition" + it creates byte array payload. + + @param[out] record Record handler + @param[in] uri string uri that will be stored in the payload + @param[in] protocol_schema protocol schema that is specified in NFC Forum + + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) + @exception NET_NFC_ALLOC_FAIL memory allocation is failed + + @code + net_nfc_error_e result = NET_NFC_OK; + ndef_message_h msg = NULL; + ndef_record_h record = NULL; + + net_nfc_create_ndef_message (&msg); + net_nfc_create_uri_type_record (&record ,"http://www.samsung.com" ,NET_NFC_SCHEMA_FULL_URI); + net_nfc_append_record_to_ndef_message (msg ,record); + @endcode +*/ + +net_nfc_error_e net_nfc_create_uri_type_record(ndef_record_h* record, const char * uri, net_nfc_schema_type_e protocol_schema); + +/** + this function is getter of record payload. + this function gives you the pointer of pyaload that is contained by record. + Do not free the payload. it will be freed when the record is freed + + @param[in] record Record handler + @param[out] payload data_h type payload pointer (it gives you the pointer of payload; not copied) + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) + +*/ +net_nfc_error_e net_nfc_get_record_payload (ndef_record_h record, data_h * payload); + +/** + this function is getter of record type. + this function gives you the pointer of record type that is contained by record. + Do not free the type. it will be freed when the record is freed + + @param[in] record Record handler + @param[out] type dat_h type pointer (it gives you the pointer of type; not copied) + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) + +*/ +net_nfc_error_e net_nfc_get_record_type (ndef_record_h record, data_h * type); + +/** + this function is getter of record ID. + this function gives you the pointer of ID that is contained by record. + it may return NULL pointer if the ID is not exist + Do not free the type. it will be freed when the record is freed. + + @param[in] record Record handler + @param[out] id dat_h type ID pointer (it gives you the pointer of payload not copied) + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) +*/ +net_nfc_error_e net_nfc_get_record_id (ndef_record_h record, data_h * id); + +/** + this function is getter of record TNF value. + + @param[in] record Record handler + @param[out] tnf TNF value + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) + + +*/ +net_nfc_error_e net_nfc_get_record_tnf(ndef_record_h record, net_nfc_record_tnf_e * tnf); + +/** + this function is getter of record flags. + you can get the each flag value by using defines "RECORD_GET_XX" + + @param[in] record Record handler + @param[out] flag flag value (it gives you the pointer of payload not copied) + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) + + @code + + ndef_record_h record; + uint8_t flag; + + net_nfc_get_record_by_index (msg, 0, &record); + if (record != NULL){ + net_nfc_get_record_flags (record, &flag); + printf ("MB:%d, ME:%d, CF:%d, IL:%d, SR:%d\n", + net_nfc_get_record_mb(flag), + net_nfc_get_record_me(flag), + net_nfc_get_record_cf(flag), + net_nfc_get_record_il(flag), + net_nfc_get_record_sr(flag)); + } + + @endcode + +*/ +net_nfc_error_e net_nfc_get_record_flags (ndef_record_h record, uint8_t * flag); + + +/** + you can set record ID with this function + + @param[in] record Record handler + @param[in] id Record ID + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) + +*/ +net_nfc_error_e net_nfc_set_record_id (ndef_record_h record, data_h id); + +/** + this function free the record handler. do not use this function after appending the ndef message + + @param[in] record Record handler + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) + +*/ +net_nfc_error_e net_nfc_free_record (ndef_record_h record); + + +/** + this function get text from text record. it allocate buffer char and store the text string. you should free this string. + + @param[in] record Record handler + @param[out] buffer text string + + @return return the result of the calling the function + + @exception NET_NFC_ALLOC_FAIL memory allocation is failed + @exception NET_NFC_NDEF_RECORD_IS_NOT_EXPECTED_TYPE record is not text record + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) + +*/ + +net_nfc_error_e net_nfc_create_text_string_from_text_record(ndef_record_h record, char** buffer); + +/** + this function get language code from text record. (ex: US-en) + + @param[in] record Record handler + @param[out] lang_code_str lang code string value followed by IANA + + @return return the result of the calling the function + + @exception NET_NFC_NDEF_RECORD_IS_NOT_EXPECTED_TYPE record is not text record + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) + +*/ + +net_nfc_error_e net_nfc_get_languange_code_string_from_text_record (ndef_record_h record, char** lang_code_str); + + +/** + this function get encoding type from text record (ex: UTF-8) + + @param[in] record Record handler + @param[out] encoding encoding type + + @return return the result of the calling the function + + @exception NET_NFC_NDEF_RECORD_IS_NOT_EXPECTED_TYPE record is not text record + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) + +*/ + +net_nfc_error_e net_nfc_get_encoding_type_from_text_record(ndef_record_h record, net_nfc_encode_type_e * encoding); + + +/** + this function get URI from uri record. you should free the uri string. + + @param[in] record Record handler + @param[out] uri uri text string + + @return return the result of the calling the function + + @exception NET_NFC_NDEF_RECORD_IS_NOT_EXPECTED_TYPE record is not uri record + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) + +*/ + +net_nfc_error_e net_nfc_create_uri_string_from_uri_record(ndef_record_h record, char ** uri); + +#ifdef __cplusplus + } +#endif + + +#endif + + diff --git a/src/clientlib/include/net_nfc_sign_record.h b/src/clientlib/include/net_nfc_sign_record.h new file mode 100755 index 0000000..f0b2671 --- /dev/null +++ b/src/clientlib/include/net_nfc_sign_record.h @@ -0,0 +1,152 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#ifndef __NET_NFC_SIGN_RECORD_H +#define __NET_NFC_SIGN_RECORD_H + +#include "net_nfc_typedef.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + + +/** + +@addtogroup NET_NFC_MANAGER_RECORD +@{ + This document is for the APIs reference document + + NFC Manager defines are defined in + +*/ + +/** + this function make the signature of some continuous records + please refer the NFC forum specification "Signature Record type Definition" + + @param[in/out] msg NDEF message handler. After executing this function, a signature record will be added. + @param[in] begin_index the index of beginning record that will be signed. + @param[in] end_index the last index of record that will be signed. + @param[in] cert_file PKCS #12 type certificate file (.p12). And the file should be encoded in DER type. (NOT PEM type) + @param[in] passowrd the password of cert_file + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illegal NULL pointer(s) + @exception NET_NFC_ALLOC_FAIL memory allocation is failed + + @code + ndef_message_h msg = NULL; + + // create a ndef message and add some records + // ... + + net_nfc_sign_records(msg, 0, 1, "/tmp/cert.p12", "abcdef"); + @endcode +*/ +net_nfc_error_e net_nfc_sign_records(ndef_message_h msg, int begin_index, int end_index, char *cert_file, char *password); + +/** + this function make the signature of whole records in NDEF message + + @param[in/out] msg NDEF message handler. After executing this function, a signature record will be added. + @param[in] cert_file PKCS #12 type certificate file (.p12). And the file should be encoded in DER type. (NOT PEM type) + @param[in] passowrd the password of cert_file + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illegal NULL pointer(s) + @exception NET_NFC_ALLOC_FAIL memory allocation is failed + + @code + ndef_message_h msg = NULL; + + // create a ndef message and add some records + // ... + + net_nfc_sign_ndef_message(msg, "/tmp/cert.p12", "abcdef"); + @endcode +*/ +net_nfc_error_e net_nfc_sign_ndef_message(ndef_message_h msg, char *cert_file, char *password); + +/** + This function does verify signature of records + record MUST be continuous. + + @param[in] begin_record the handle of beginning record that will be verified + @param[in] sign_record the handle of signature record + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illegal NULL pointer(s) + @exception NET_NFC_ALLOC_FAIL memory allocation is failed + + @code + net_nfc_error_e error = NET_NFC_OK; + ndef_message_h msg = NULL; + ndef_record_h begin_record = NULL; + ndef_record_h sign_record = NULL; + + // import NDEF message including the signature record. + // ... + + net_nfc_get_record_by_index(msg, 0, &begin_record); + net_nfc_get_record_by_index(msg, 2, &sign_record); + + error = net_nfc_verify_signature_records(begin_record, sign_record); + + return (error == NET_NFC_OK); + @endcode +*/ +net_nfc_error_e net_nfc_verify_signature_records(ndef_record_h begin_record, ndef_record_h sign_record); + +/** + This function does verify signature in NDEF message + If message has 2 or more signature record, it should do verify every signatures and return result. + (Despite of failing only one signature record, this function will return error.) + + @param[in] msg NDEF message that will be verified. + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illegal NULL pointer(s) + @exception NET_NFC_ALLOC_FAIL memory allocation is failed + + @code + net_nfc_error_e error = NET_NFC_OK; + ndef_message_h msg = NULL; + + // import NDEF message including the signature record. + // ... + + error = net_nfc_verify_signature_ndef_message(msg); + + return (error == NET_NFC_OK); + @endcode +*/ +net_nfc_error_e net_nfc_verify_signature_ndef_message(ndef_message_h msg); + +#ifdef __cplusplus +} +#endif + + +#endif /* __NET_NFC_SIGN_RECORD_H */ + + diff --git a/src/clientlib/include/net_nfc_tag.h b/src/clientlib/include/net_nfc_tag.h new file mode 100755 index 0000000..d4062b5 --- /dev/null +++ b/src/clientlib/include/net_nfc_tag.h @@ -0,0 +1,515 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#ifndef __NET_NFC_TAG_H__ +#define __NET_NFC_TAG_H__ + +#include "net_nfc_typedef.h" + + +#ifdef __cplusplus + extern "C" { +#endif + +/** + +@addtogroup NET_NFC_MANAGER_TAG +@{ + This document is for the APIs reference document + + NFC Manager defines are defined in + + @li @c #net_nfc_transceive provide low level tag access + @li @c #net_nfc_format_ndef format to NDEF tag type + @li @c #net_nfc_read_tag read ndef message + @li @c #net_nfc_write_ndef write ndef message + @li @c #net_nfc_set_tag_filter set detection filter . + @li @c #net_nfc_get_tag_filter get detection filter + @li @c #net_nfc_create_transceive_info_only allocate the transceive info. + @li @c #net_nfc_create_transceive_info allocate the transeeive info and set given values + @li @c #net_nfc_set_transceive_info_command command setter from transceive info. + @li @c #net_nfc_set_transceive_info_data data setter from transceive info. + @li @c #net_nfc_set_transceive_info_address address setter from transceive info. + @li @c #net_nfc_free_transceive_info free transceive info handler + +*/ + +/** + transceive function is the only wayt to access the raw format card (not formated), + each tag type requres own command to access tags, + this API provide low level access of tag operation and you require the knowlege of each tag technology.
+ To use this API you should create transceive info with "net_nfc_create_transceive_info" API + + \par Sync (or) Async: Async + This is a Asynchronous API + + @param[in] handle target ID that has been delivered from callback + @param[in] info trnasceive infomation that has created by "net_nfc_create_transceive_info" API + @param[in] trans_param user data that will be delivered to callback + + @return return the result of the calling this function + + @exception NET_NFC_ALLOC_FAIL memory allocation is failed + @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization + @exception NET_NFC_BUSY Device is too busy to handle your request + @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error + @exception NET_NFC_RF_TIMEOUT Timeout is raised while communicate with tag + @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command + @exception NET_NFC_INVALID_HANDLE target handle is not valid + @exception NET_NFC_TAG_READ_FAILED received chunked data is not valied (damaged data is recieved) or error ack is recieved + @exception NET_NFC_TAG_WRITE_FAILED read only tag, or error ack is received from tag + + @code + + void net_nfc_cb(net_nfc_message_e message, net_nfc_error_e result, void* data , void* userContext) + { + net_nfc_target_handle_h id; + bool is_ndef; + net_nfc_target_info_h target_info = (net_nfc_target_info_h)data; + + net_nfc_get_tag_ndef_support (target_info, &is_ndef); + net_nfc_get_tag_handle (target_info, &id); + + case NET_NFC_MESSAGE_TAG_DISCOVERED: + { + net_nfc_transceive_info_h trans; + net_nfc_create_transceive_info (&trans, NET_NFC_EMIFAREREAD, 0x00, NULL); + net_nfc_transceive (id ,trans , &user_context); + net_nfc_free_transceive_info (trans); + } + break; + + case NET_NFC_MESSAGE_TRANSCEIVE: + if(result == NET_NFC_OK){ + printf("NET_NFC_MESSAGE_TRANSCEIVE is OK \n"); + if (data != NULL){ + data_h read_data = (data_h) * data; + int idx; + uint8_t * buf = net_nfc_get_data_buffer (data_read); + for (idx = 0; idx < net_nfc_get_data_length (read_data); idx ++){ + printf (" %02X", buf[idx]); + } + } + } + else{ + printf("NET_NFC_MESSAGE_TRANSCEIVE is failed %d\n", result); + } + break; + } + + int main() + { + + net_nfc_error_e result; + result = net_nfc_initialize(); + check_result(result); + + result = net_nfc_set_response_callback (net_nfc_cb, &user_context2); + check_result(result); + + sleep (100); + + return 0; + } + @endcode + +*/ + +net_nfc_error_e net_nfc_transceive (net_nfc_target_handle_h handle, data_h rawdata, void* trans_param); + +/** + This API formats the detected tag that can store NDEF message. + some tags are required authentication. if the detected target does need authentication, set NULL. + + \par Sync (or) Async: Async + This is a Asynchronous API + + @param[in] handle target ID that has been delivered from callback + @param[in] key key value that may need to format the tag + @param[in] trans_param user data that will be delivered to callback + + @return return the result of the calling this function + + @exception NET_NFC_ALLOC_FAIL memory allocation is failed + @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization + @exception NET_NFC_BUSY Device is too busy to handle your request + @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error + @exception NET_NFC_RF_TIMEOUT Timeout is raised while communicate with tag + @exception NET_NFC_INVALID_HANDLE target handle is not valid + @exception NET_NFC_TAG_WRITE_FAILED read only tag, or error ack is received from tag + @exception NET_NFC_TAG_IS_ALREADY_FORMATTED requested target is already famatted + + @code + + void net_nfc_cb(net_nfc_message_e message, net_nfc_error_e result, void* data , void* userContext) + { + case NET_NFC_MESSAGE_TAG_DISCOVERED: + + if(data != NULL){ + net_nfc_target_handle_h id; + bool is_ndef; + net_nfc_target_info_h target_info = (net_nfc_target_info_h)data; + + net_nfc_get_tag_ndef_support (target_info, &is_ndef); + net_nfc_get_tag_handle (target_info, &id); + + if (!is_ndef){ + net_nfc_format_ndef (id, NULL, NULL); + } + } + break; + + case NET_NFC_MESSAGE_FORMAT_NDEF: + printf ("ndef format is completed with %d\n", result); + break; + } + @endcode + +*/ + +net_nfc_error_e net_nfc_format_ndef(net_nfc_target_handle_h handle, data_h key, void* trans_param); + + + +/** + net_nfc_Ndef_read do read operation with NDEF format + In the callback function, return value is byte array of the NDEF message. + it need to convert to NDEF structure + + \par Sync (or) Async: Async + This is a Asynchronous API + + @param[in] handle the target ID the connection is already made + @param[in] trans_param user data + + @return return the result of the calling this function + + @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization + @exception NET_NFC_NO_NDEF_SUPPORT Tag is not support NDEF message + @exception NET_NFC_ALLOC_FAIL memory allocation is failed + @exception NET_NFC_BUSY Device is too busy to handle your request + @exception NET_NFC_RF_TIMEOUT Timeout is raised while communicate with tag + @exception NET_NFC_INVALID_HANDLE target handle is not valid + @exception NET_NFC_TAG_READ_FAILED received chunked data is not valied (damaged data is recieved) or error ack is recieved + + @code + void net_nfc_cb(net_nfc_message_e message, net_nfc_error_e result, void* data , void* userContext) + { + // ...... + switch (message) + { + case NET_NFC_MESSAGE_TAG_DISCOVERED: + { + if(data != NULL){ + net_nfc_target_handle_h id; + bool is_ndef; + net_nfc_target_info_h target_info = (net_nfc_target_info_h)data; + + net_nfc_get_tag_ndef_support (target_info, &is_ndef); + net_nfc_get_tag_handle (target_info, &id); + + if (is_ndef){ + net_nfc_read_tag (id, &user_context); + } + } + } + break; + + case NET_NFC_MESSAGE_READ_NDEF: + { + if (result != NET_NFC_OK) + { + // FAILED read NDEF message + } + ndef_message_h ndef_message = (ndef_message_h ) data; + } + break; + } + return; + } + + int main() + { + + net_nfc_error_e result; + result = net_nfc_initialize(); + check_result(result); + + result = net_nfc_set_response_callback (net_nfc_cb, &user_context2); + check_result(result); + + sleep (100); + + return 0; + } + @endcode + +*/ + + +net_nfc_error_e net_nfc_read_tag (net_nfc_target_handle_h handle, void* trans_param); + +/** + net_nfc_Ndef_write do write operation with NDEF format message + + \par Sync (or) Async: Async + This is a Asynchronous API + + @param[in] handle the target Id the connection is already made + @param[in] msg the message will be write to the target + @param[in] trans_param user data + + @return return the result of the calling the function + + @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization + @exception NET_NFC_NO_NDEF_SUPPORT Tag is not support NDEF message + @exception NET_NFC_ALLOC_FAIL memory allocation is failed + @exception NET_NFC_BUSY Device is too busy to handle your request + @exception NET_NFC_INSUFFICIENT_STORAGE Tag does not enough storage to store NDEF message + @exception NET_NFC_RF_TIMEOUT Timeout is raised while communicate with tag + @exception NET_NFC_INVALID_HANDLE target handle is not valid + @exception NET_NFC_TAG_WRITE_FAILED read only tag, or error ack is received from tag + + + @code + void net_nfc_cb(net_nfc_message_e message, net_nfc_error_e result, void* data , void* userContext) + { + // ...... + switch (message) + { + case NET_NFC_MESSAGE_TAG_DISCOVERED: + { + if(data != NULL){ + net_nfc_target_handle_h id; + bool is_ndef; + net_nfc_target_info_h target_info = (net_nfc_target_info_h)data; + + net_nfc_get_tag_ndef_support (target_info, &is_ndef); + net_nfc_get_tag_handle (target_info, &id); + + if (is_ndef){ + net_nfc_error_e result = NET_NFC_OK; + ndef_message_h bt_msg = NULL; + ndef_record_h record = NULL; + + net_nfc_create_ndef_message (&msg); + net_nfc_create_text_type_record (&record , "Hello NFC World", NET_NFC_LANG_EN_US ,NET_NFC_ENCODE_UTF_8); + net_nfc_append_record_to_ndef_message (msg ,record); + + net_nfc_write_ndef(id, msg, &user_context); + } + } + } + break; + + case NET_NFC_MESSAGE_WRITE_NDEF: + { + if (result != NET_NFC_OK) + { + // FAILED write NDEF message + } + } + break; + } + return; + } + + int main() + { + + net_nfc_error_e result; + result = net_nfc_initialize(); + check_result(result); + + result = net_nfc_set_response_callback (net_nfc_cb, &user_context2); + check_result(result); + + sleep (100); + + return 0; + } + @endcode + +*/ + +net_nfc_error_e net_nfc_write_ndef (net_nfc_target_handle_h handle, ndef_message_h msg, void* trans_param); + +/** + this API make a ndef tag read only. + + \par Sync (or) Async: Async + This is a synchronous API + + @param[in] handle the target Id the connection is already made + @param[in] trans_param user data + + @return return the result of the calling the function + + @exception NONE + + @code + + @code + void net_nfc_cb(net_nfc_message_e message, net_nfc_error_e result, void* data , void* userContext) + { + // ...... + switch (message) + { + case NET_NFC_MESSAGE_TAG_DISCOVERED: + { + if(data != NULL){ + net_nfc_target_handle_h id; + bool is_ndef; + net_nfc_target_info_h target_info = (net_nfc_target_info_h)data; + + net_nfc_get_tag_ndef_support (target_info, &is_ndef); + net_nfc_get_tag_handle (target_info, &id); + + if (is_ndef){ + + net_nfc_error_e result = NET_NFC_OK; + net_nfc_make_read_only_ndef_tag(id, &user_context); + } + } + } + break; + + case NET_NFC_MESSAGE_MAKE_READ_ONLY_NDEF: + { + if (result != NET_NFC_OK) + { + // FAILED to make read only ndef tag + } + } + break; + } + return; + } + + int main() + { + + net_nfc_error_e result; + result = net_nfc_initialize(); + check_result(result); + + result = net_nfc_set_response_callback (net_nfc_cb, &user_context2); + check_result(result); + + sleep (100); + + return 0; + } + @endcode + +*/ + + +net_nfc_error_e net_nfc_make_read_only_ndef_tag(net_nfc_target_handle_h handle, void* trans_param); + +/** + this API help to set filter of target types. + bit opertor or can be used in the config parameter (like NET_NFC_ISO14443A_ENABLE | NET_NFC_ISO14443B_ENABLE) + or you may choose "NET_NFC_ALL_ENABLE" enum value to get all result + it prevent getting tag types from RF level. + if the client api does call this function, default is always NET_NFC_ALL_ENABLE. + + \par Sync (or) Async: Sync + This is a synchronous API + + @param[in] config filter value with bits operation + + @return return the result of the calling the function + + @exception NONE + + @code + + int main() + { + + net_nfc_error_e result; + result = net_nfc_initialize(); + check_result(result); + + net_nfc_event_filter_e filter = NET_NFC_ALL_ENABLE; + net_nfc_error_e net_nfc_set_tag_filter(filter); + + result = net_nfc_set_response_callback (net_nfc_cb, &user_context2); + check_result(result); + + sleep (100); + + return 0; + } + + @endcode +*/ + +net_nfc_error_e net_nfc_set_tag_filter(net_nfc_event_filter_e config); + +/** + get current filter status. The current filter value will return filter you can call this API any time anywhere + + \par Sync (or) Async: Async + This is a asynchronous API + + @return return the filter which is set + + @exception NONE + + @code + + net_nfc_event_filter_e config = net_nfc_get_tag_filter(); + + @endcode + +*/ +net_nfc_error_e net_nfc_is_tag_connected(void *trans_param); + +/** + Check a target connected already. (Synchronous function) + + \par Sync (or) Async: Sync + This is a synchronous API + + @param[out] dev_type currently connected device type + @return return the filter which is set + + @exception NONE + + @code + + int dev_type = 0; + net_nfc_error_e result = net_nfc_is_tag_connected_sync(&dev_type); + + @endcode +*/ +net_nfc_error_e net_nfc_is_tag_connected_sync(int *dev_type); + +net_nfc_event_filter_e net_nfc_get_tag_filter(void); + +net_nfc_error_e net_nfc_get_current_tag_info(void* trans_param); +net_nfc_error_e net_nfc_get_current_tag_info_sync(net_nfc_target_info_h *info); + +#ifdef __cplusplus +} +#endif + + +#endif + diff --git a/src/clientlib/include/net_nfc_tag_felica.h b/src/clientlib/include/net_nfc_tag_felica.h new file mode 100755 index 0000000..4cd2ba2 --- /dev/null +++ b/src/clientlib/include/net_nfc_tag_felica.h @@ -0,0 +1,237 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#ifndef __NET_NFC_TAG_FELICA_H__ +#define __NET_NFC_TAG_FELICA_H__ + +#include "net_nfc_typedef.h" + + +#ifdef __cplusplus + extern "C" { +#endif + +/** + +@addtogroup NET_NFC_MANAGER_TAG +@{ + + send poll request to felica tag. + Use this command to acquire and identify a card. Acqusition of IDm and PMm is possible with this command. + By specifying a request code , you can acquire system code or communication performance of the system. + By specifying a time slot, you can designate the maximum number of time slots possible to return response. + + NET_NFC_FELICA_POLL_NO_REQUEST = 0x00 + NET_NFC_FELICA_POLL_SYSTEM_CODE_REQUEST = 0x01 + NET_NFC_FELICA_POLL_COMM_SPEED_REQUEST= 0x02 + + time slot + + Time slot Max number of slots + 0x00, 1 + 0x01, 2 + 0x03, 4 + 0x07, 8 + 0x0f, 16 + + \par Sync (or) Async: Sync + This is a Asynchronous API + + @param[in] handle target handle of detected tag + @param[in] req_code request code with this command + @param[in] time_slot time slot value + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter has illigal NULL pointer + @exception NET_NFC_ALLOC_FAIL memory allocation is failed + @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization + @exception NET_NFC_BUSY Device is too busy to handle your request + @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error + @exception NET_NFC_RF_TIMEOUT Timeout is raised while communicate with tag + @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command + @exception NET_NFC_INVALID_HANDLE target handle is not valid + @exception NET_NFC_TAG_READ_FAILED received chunked data is not valied (damaged data is recieved) or error ack is recieved + @exception NET_NFC_NO_DATA_FOUND mendantory tag info (SYSTEM_CODE, etc) is not founded + +*/ + +net_nfc_error_e net_nfc_felica_poll (net_nfc_target_handle_h handle, net_nfc_felica_poll_request_code_e req_code, uint8_t time_slote, void* trans_param); + +/** + Use this command to check for the existence of Area / Service specified by Area Code / Service Code + If the specified Area / Service exists, the card returns version information of the key known as "Key Version" (2 Bytes) + If the specified Area / Service does not exist, the card returns 0xffff as it s Key Version + + \par Sync (or) Async: Sync + This is a Asynchronous API + + @param[in] handle target handle of detected tag + @param[in] number_of_area_service the number of specified Area / Service list + @param[in] area_service_list specified Area / Service list + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter has illigal NULL pointer + @exception NET_NFC_ALLOC_FAIL memory allocation is failed + @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization + @exception NET_NFC_BUSY Device is too busy to handle your request + @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error + @exception NET_NFC_RF_TIMEOUT Timeout is raised while communicate with tag + @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command + @exception NET_NFC_INVALID_HANDLE target handle is not valid + @exception NET_NFC_TAG_READ_FAILED received chunked data is not valied (damaged data is recieved) or error ack is recieved + @exception NET_NFC_NO_DATA_FOUND mendantory tag info (IDm, etc) is not founded + @exception NET_NFC_OUT_OF_BOUND the length of IDm is not correct. number of services exceed max value + +*/ + +net_nfc_error_e net_nfc_felica_request_service (net_nfc_target_handle_h handle, uint8_t number_of_area_service, uint16_t area_service_list[], uint8_t number_of_services, void* trans_param); + +/** + Use this command to check whether a card exist + the Current mode of the card is returned. + + Mode + + 0x00 Mode0 + 0x01 Mode1 + 0x02 Mode2 + 0x03 Mode3 + + \par Sync (or) Async: Sync + This is a Asynchronous API + + @param[in] handle target handle of detected tag + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter has illigal NULL pointer + @exception NET_NFC_ALLOC_FAIL memory allocation is failed + @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization + @exception NET_NFC_BUSY Device is too busy to handle your request + @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error + @exception NET_NFC_RF_TIMEOUT Timeout is raised while communicate with tag + @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command + @exception NET_NFC_INVALID_HANDLE target handle is not valid + @exception NET_NFC_TAG_READ_FAILED received chunked data is not valied (damaged data is recieved) or error ack is recieved + @exception NET_NFC_NO_DATA_FOUND mendantory tag info (IDm, etc) is not founded + @exception NET_NFC_OUT_OF_BOUND the length of IDm is not correct + +*/ + +net_nfc_error_e net_nfc_felica_request_response (net_nfc_target_handle_h handle, void* trans_param); + +/** + Use this command to read block data from a Service that requires no authentification + + \par Sync (or) Async: Sync + This is a Asynchronous API + + @param[in] handle target handle of detected tag + @param[in] number_of_service the number of service list to read + @param[in] service_list specified Service list to read + @param[in] number_of_blocks the number of blocks to read + @param[in] block_list the blocks to read + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter has illigal NULL pointer + @exception NET_NFC_ALLOC_FAIL memory allocation is failed + @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization + @exception NET_NFC_BUSY Device is too busy to handle your request + @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error + @exception NET_NFC_RF_TIMEOUT Timeout is raised while communicate with tag + @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command + @exception NET_NFC_INVALID_HANDLE target handle is not valid + @exception NET_NFC_TAG_READ_FAILED received chunked data is not valied (damaged data is recieved) or error ack is recieved + @exception NET_NFC_NO_DATA_FOUND mendantory tag info (IDm, etc) is not founded + @exception NET_NFC_OUT_OF_BOUND the length of IDm is not correct + +*/ + +net_nfc_error_e net_nfc_felica_read_without_encryption (net_nfc_target_handle_h handle, uint8_t number_of_services, uint16_t service_list[], uint8_t number_of_blocks, uint8_t block_list[], void* trans_param); + +/** + Use this command to write block data to a Service that requires no authentification + + \par Sync (or) Async: Sync + This is a Asynchronous API + + @param[in] handle target handle of detected tag + @param[in] number_of_service the number of service list to write + @param[in] service_list specified Service list to write + @param[in] number_of_blocks the number of blocks to write + @param[in] block_list the blocks to write + @param[in] data the data to write + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter has illigal NULL pointer + @exception NET_NFC_ALLOC_FAIL memory allocation is failed + @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization + @exception NET_NFC_BUSY Device is too busy to handle your request + @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error + @exception NET_NFC_RF_TIMEOUT Timeout is raised while communicate with tag + @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command + @exception NET_NFC_INVALID_HANDLE target handle is not valid + @exception NET_NFC_TAG_READ_FAILED received chunked data is not valied (damaged data is recieved) or error ack is recieved + @exception NET_NFC_NO_DATA_FOUND mendantory tag info (IDm, etc) is not founded + @exception NET_NFC_OUT_OF_BOUND the length of IDm is not correct. number of services exceed max value, the data length to write is exceed the limitation. It should be less than number_of_blocks * 16 bytes + +*/ + +net_nfc_error_e net_nfc_felica_write_without_encryption (net_nfc_target_handle_h handle, uint8_t number_of_services, uint16_t service_list[], uint8_t number_of_blocks, uint8_t block_list[], data_h data, void* trans_param); + +/** + Use this command to acquire system code of the system located on a card + If a card is divided into mutiple system, this command acquires system code of all the system existing in the card + + \par Sync (or) Async: Sync + This is a Asynchronous API + + @param[in] handle target handle of detected tag + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter has illigal NULL pointer + @exception NET_NFC_ALLOC_FAIL memory allocation is failed + @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization + @exception NET_NFC_BUSY Device is too busy to handle your request + @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error + @exception NET_NFC_RF_TIMEOUT Timeout is raised while communicate with tag + @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command + @exception NET_NFC_INVALID_HANDLE target handle is not valid + @exception NET_NFC_TAG_READ_FAILED received chunked data is not valied (damaged data is recieved) or error ack is recieved + @exception NET_NFC_NO_DATA_FOUND mendantory tag info (IDm, etc) is not founded + @exception NET_NFC_OUT_OF_BOUND the length of IDm is not correct. + +*/ + +net_nfc_error_e net_nfc_felica_request_system_code (net_nfc_target_handle_h handle, void* trans_param); + +/** +@} */ + + +#ifdef __cplusplus +} +#endif + + +#endif + diff --git a/src/clientlib/include/net_nfc_tag_jewel.h b/src/clientlib/include/net_nfc_tag_jewel.h new file mode 100755 index 0000000..71ddfb7 --- /dev/null +++ b/src/clientlib/include/net_nfc_tag_jewel.h @@ -0,0 +1,184 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#ifndef __NET_NFC_TAG_JEWEL_H__ +#define __NET_NFC_TAG_JEWEL_H__ + +#include "net_nfc_typedef.h" + + +#ifdef __cplusplus + extern "C" { +#endif + +/** + +@addtogroup NET_NFC_MANAGER_TAG +@{ + + read uid from jewel tag. + + \par Sync (or) Async: Sync + This is a Asynchronous API + + @param[in] handle target handle of detected tag + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter has illigal NULL pointer + @exception NET_NFC_ALLOC_FAIL memory allocation is failed + @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization + @exception NET_NFC_BUSY Device is too busy to handle your request + @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error + @exception NET_NFC_RF_TIMEOUT Timeout is raised while communicate with tag + @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command + @exception NET_NFC_INVALID_HANDLE target handle is not valid + @exception NET_NFC_TAG_READ_FAILED received chunked data is not valied (damaged data is recieved) or error ack is recieved + @exception NET_NFC_NO_DATA_FOUND mendantory tag info (UID, etc) is not founded + +*/ + +net_nfc_error_e net_nfc_jewel_read_id (net_nfc_target_handle_h handle, void* trans_param); + +/** + read one byte of specific address . + + \par Sync (or) Async: Sync + This is a Asynchronous API + + @param[in] handle target handle of detected tag + @param[in] block block number. (block 0 ~ block E) + @param[in] byte byte number. Each block has 8 bytes. (byte 0 ~ byte 7) + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter has illigal NULL pointer + @exception NET_NFC_ALLOC_FAIL memory allocation is failed + @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization + @exception NET_NFC_BUSY Device is too busy to handle your request + @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error + @exception NET_NFC_RF_TIMEOUT Timeout is raised while communicate with tag + @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command + @exception NET_NFC_INVALID_HANDLE target handle is not valid + @exception NET_NFC_TAG_READ_FAILED received chunked data is not valied (damaged data is recieved) or error ack is recieved + @exception NET_NFC_NO_DATA_FOUND mendantory tag info (UID, etc) is not founded + +*/ + +net_nfc_error_e net_nfc_jewel_read_byte (net_nfc_target_handle_h handle, uint8_t block, uint8_t byte, void* trans_param); + +/** + read all byte from tag . + + \par Sync (or) Async: Sync + This is a Asynchronous API + + @param[in] handle target handle of detected tag + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter has illigal NULL pointer + @exception NET_NFC_ALLOC_FAIL memory allocation is failed + @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization + @exception NET_NFC_BUSY Device is too busy to handle your request + @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error + @exception NET_NFC_RF_TIMEOUT Timeout is raised while communicate with tag + @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command + @exception NET_NFC_INVALID_HANDLE target handle is not valid + @exception NET_NFC_TAG_READ_FAILED received chunked data is not valied (damaged data is recieved) or error ack is recieved + @exception NET_NFC_NO_DATA_FOUND mendantory tag info (UID, etc) is not founded + +*/ + + +net_nfc_error_e net_nfc_jewel_read_all (net_nfc_target_handle_h handle, void* trans_param); + + +/** + operate erase and write cycle . If any of BLOCK-0 to BLOCK-D is locked then write with erase is barred form thoes blocks. + Additionally 0, D, E blocks are automatically in the lock condition. so write with erase is always barred from thoes blocks. + + \par Sync (or) Async: Sync + This is a Asynchronous API + + @param[in] handle target handle of detected tag + @param[in] block block number. (block 0 ~ block E) + @param[in] data the data to write + @param[in] byte byte number. Each block has 8 bytes. (byte 0 ~ byte 7) + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter has illigal NULL pointer + @exception NET_NFC_ALLOC_FAIL memory allocation is failed + @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization + @exception NET_NFC_BUSY Device is too busy to handle your request + @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error + @exception NET_NFC_RF_TIMEOUT Timeout is raised while communicate with tag + @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command + @exception NET_NFC_INVALID_HANDLE target handle is not valid + @exception NET_NFC_TAG_WRITE_FAILED read only tag, or error ack is received from tag + @exception NET_NFC_NO_DATA_FOUND mendantory tag info (UID, etc) is not founded + +*/ + +net_nfc_error_e net_nfc_jewel_write_with_erase (net_nfc_target_handle_h handle, uint8_t block, uint8_t byte, uint8_t data, void* trans_param); + + +/** + operate no erase and write cycle . + + The WRITE-NE command is available for three main purposes + - Lock . to set the ��lock bit�� for a block + - OTP . to set One-Time-Programmable bits (bytes 2 . 7 of Block-E), where between one and eight OTP bits can be set with a singleWRITE-NE command + - A fast-write in order to reduce overall time to write data to memory blocks for the first time given that the original condition of memory is zero + + \par Sync (or) Async: Sync + This is a Asynchronous API + + @param[in] handle target handle of detected tag + @param[in] block block number. (block 0 ~ block E) + @param[in] data the data to write + @param[in] byte byte number. Each block has 8 bytes. (byte 0 ~ byte 7) + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter has illigal NULL pointer + @exception NET_NFC_ALLOC_FAIL memory allocation is failed + @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization + @exception NET_NFC_BUSY Device is too busy to handle your request + @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error + @exception NET_NFC_RF_TIMEOUT Timeout is raised while communicate with tag + @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command + @exception NET_NFC_INVALID_HANDLE target handle is not valid + @exception NET_NFC_TAG_WRITE_FAILED read only tag, or error ack is received from tag + @exception NET_NFC_NO_DATA_FOUND mendantory tag info (UID, etc) is not founded + +*/ + +net_nfc_error_e net_nfc_jewel_write_with_no_erase (net_nfc_target_handle_h handle, uint8_t block, uint8_t byte, uint8_t data, void* trans_param); + +/** +@} */ + + +#ifdef __cplusplus +} +#endif + + +#endif + diff --git a/src/clientlib/include/net_nfc_tag_mifare.h b/src/clientlib/include/net_nfc_tag_mifare.h new file mode 100755 index 0000000..4501803 --- /dev/null +++ b/src/clientlib/include/net_nfc_tag_mifare.h @@ -0,0 +1,354 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#ifndef __NET_NFC_TAG_MIFARE_H__ +#define __NET_NFC_TAG_MIFARE_H__ + +#include "net_nfc_typedef.h" + + +#ifdef __cplusplus + extern "C" { +#endif + +/** + +@addtogroup NET_NFC_MANAGER_TAG +@{ + Authenticate a sector with key A. I/O operation. e.g. read / write / increment / decrement will be available after successful authentication. + This API is only available for MIFARE classic + + MIFARE CLASSIC MINI + => 0 ~ 4 : 5 sector and 4 block with 16 bytes + + MIFARE CLASSIC 1K + => 0 ~ 15 : 16 sector and 4 block with 16 bytes + + MIFARE CLASSIC 4K + => 0 ~ 31 : 32 sector and 4 block with 16 bytes + => 32 ~ 39 : 8 sector and 16 block with 16 bytes + + \par Sync (or) Async: Sync + This is a Asynchronous API + + @param[in] handle target handle of detected tag + @param[in] sector sector to authenticate with key A + @param[in] auth_key 6 byte key to authenticate the sector + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter has illigal NULL pointer + @exception NET_NFC_ALLOC_FAIL memory allocation is failed + @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization + @exception NET_NFC_BUSY Device is too busy to handle your request + @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error + @exception NET_NFC_RF_TIMEOUT Timeout is raised while communicate with tag + @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command + @exception NET_NFC_INVALID_HANDLE target handle is not valid + @exception NET_NFC_NO_DATA_FOUND mendantory tag info (UID, etc) is not founded + +*/ + +net_nfc_error_e net_nfc_mifare_authenticate_with_keyA(net_nfc_target_handle_h handle, uint8_t sector, data_h auth_key, void* trans_param); + +/** + Authenticate a sector with key B. I/O operation. e.g. read / write / increment / decrement will be available after successful authentication. + This API is only available for MIFARE classic + + MIFARE CLASSIC MINI + => 0 ~ 4 : 5 sector and 4 block with 16 bytes + + MIFARE CLASSIC 1K + => 0 ~ 15 : 16 sector and 4 block with 16 bytes + + MIFARE CLASSIC 4K + => 0 ~ 31 : 32 sector and 4 block with 16 bytes + => 32 ~ 39 : 8 sector and 16 block with 16 bytes + + \par Sync (or) Async: Sync + This is a Asynchronous API + + @param[in] handle target handle of detected tag + @param[in] sector sector to authenticate with key B + @param[in] auth_key 6 byte key to authenticate the sector + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter has illigal NULL pointer + @exception NET_NFC_ALLOC_FAIL memory allocation is failed + @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization + @exception NET_NFC_BUSY Device is too busy to handle your request + @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error + @exception NET_NFC_RF_TIMEOUT Timeout is raised while communicate with tag + @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command + @exception NET_NFC_INVALID_HANDLE target handle is not valid + @exception NET_NFC_NO_DATA_FOUND mendantory tag info (UID, etc) is not founded + +*/ + + +net_nfc_error_e net_nfc_mifare_authenticate_with_keyB(net_nfc_target_handle_h handle, uint8_t sector, data_h auth_key, void* trans_param); + +/** + read block or read page. If detected card is MIFARE classic, then It will read a block (16 byte). If detected card is Ultra light, then It will read 4 page (16 block) + + \par Sync (or) Async: Sync + This is a Asynchronous API + + @param[in] handle target handle of detected tag + @param[in] addr block or starting page number + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter has illigal NULL pointer + @exception NET_NFC_ALLOC_FAIL memory allocation is failed + @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization + @exception NET_NFC_BUSY Device is too busy to handle your request + @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error + @exception NET_NFC_RF_TIMEOUT Timeout is raised while communicate with tag + @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command + @exception NET_NFC_INVALID_HANDLE target handle is not valid + @exception NET_NFC_TAG_READ_FAILED received chunked data is not valied (damaged data is recieved) or error ack is recieved + +*/ + +net_nfc_error_e net_nfc_mifare_read(net_nfc_target_handle_h handle, uint8_t addr, void* trans_param); + +/** + write block (16 byte) to addr. Only 4 bytes will be written when tag is ultra light + + \par Sync (or) Async: Sync + This is a Asynchronous API + + @param[in] handle target handle of detected tag + @param[in] addr block or starting page number + @param[in] data data to write + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter has illigal NULL pointer + @exception NET_NFC_ALLOC_FAIL memory allocation is failed + @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization + @exception NET_NFC_BUSY Device is too busy to handle your request + @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error + @exception NET_NFC_RF_TIMEOUT Timeout is raised while communicate with tag + @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command + @exception NET_NFC_INVALID_HANDLE target handle is not valid + @exception NET_NFC_TAG_WRITE_FAILED read only tag, or error ack is received from tag + +*/ + + +net_nfc_error_e net_nfc_mifare_write_block (net_nfc_target_handle_h handle, uint8_t addr, data_h data, void* trans_param); + +/** + write page (4 byte) to addr. Only 4 bytes will be written when tag is MIFARE classic + + \par Sync (or) Async: Sync + This is a Asynchronous API + + @param[in] handle target handle of detected tag + @param[in] addr block or starting page number + @param[in] data data to write + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter has illigal NULL pointer + @exception NET_NFC_ALLOC_FAIL memory allocation is failed + @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization + @exception NET_NFC_BUSY Device is too busy to handle your request + @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error + @exception NET_NFC_RF_TIMEOUT Timeout is raised while communicate with tag + @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command + @exception NET_NFC_INVALID_HANDLE target handle is not valid + @exception NET_NFC_TAG_WRITE_FAILED read only tag, or error ack is received from tag + +*/ + +net_nfc_error_e net_nfc_mifare_write_page (net_nfc_target_handle_h handle, uint8_t addr, data_h data, void* trans_param); + + +/** + Increase a value block, storing the result in the temporary block on the tag. + This API is only available for MIFARE classic + + \par Sync (or) Async: Sync + This is a Asynchronous API + + @param[in] handle target handle of detected tag + @param[in] addr block + @param[in] value index of block to increase, starting from 0 + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter has illigal NULL pointer + @exception NET_NFC_ALLOC_FAIL memory allocation is failed + @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization + @exception NET_NFC_BUSY Device is too busy to handle your request + @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error + @exception NET_NFC_RF_TIMEOUT Timeout is raised while communicate with tag + @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command + @exception NET_NFC_INVALID_HANDLE target handle is not valid + @exception NET_NFC_TAG_WRITE_FAILED read only tag, or error ack is received from tag + +*/ + +net_nfc_error_e net_nfc_mifare_increment(net_nfc_target_handle_h handle, uint8_t addr, int value, void* trans_param); + +/** + Decrease a value block, storing the result in the temporary block on the tag. + This API is only available for MIFARE classic + + \par Sync (or) Async: Sync + This is a Asynchronous API + + @param[in] handle target handle of detected tag + @param[in] addr block + @param[in] value index of block to decrease, starting from 0 + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter has illigal NULL pointer + @exception NET_NFC_ALLOC_FAIL memory allocation is failed + @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization + @exception NET_NFC_BUSY Device is too busy to handle your request + @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error + @exception NET_NFC_RF_TIMEOUT Timeout is raised while communicate with tag + @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command + @exception NET_NFC_INVALID_HANDLE target handle is not valid + @exception NET_NFC_TAG_WRITE_FAILED read only tag, or error ack is received from tag + +*/ + +net_nfc_error_e net_nfc_mifare_decrement(net_nfc_target_handle_h handle, uint8_t addr, int value, void* trans_param); + +/** + Copy from the temporary block to a value block. + This API is only available for MIFARE classic + + \par Sync (or) Async: Sync + This is a Asynchronous API + + @param[in] handle target handle of detected tag + @param[in] addr block + @param[in] value index of block to decrease, starting from 0 + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter has illigal NULL pointer + @exception NET_NFC_ALLOC_FAIL memory allocation is failed + @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization + @exception NET_NFC_BUSY Device is too busy to handle your request + @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error + @exception NET_NFC_RF_TIMEOUT Timeout is raised while communicate with tag + @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command + @exception NET_NFC_INVALID_HANDLE target handle is not valid + @exception NET_NFC_TAG_WRITE_FAILED read only tag, or error ack is received from tag + +*/ + +net_nfc_error_e net_nfc_mifare_transfer(net_nfc_target_handle_h handle, uint8_t addr, void* trans_param); + +/** + Copy from a value block to the temporary block. + This API is only available for MIFARE classic + + \par Sync (or) Async: Sync + This is a Asynchronous API + + @param[in] handle target handle of detected tag + @param[in] addr block + @param[in] value index of block to decrease, starting from 0 + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter has illigal NULL pointer + @exception NET_NFC_ALLOC_FAIL memory allocation is failed + @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization + @exception NET_NFC_BUSY Device is too busy to handle your request + @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error + @exception NET_NFC_RF_TIMEOUT Timeout is raised while communicate with tag + @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command + @exception NET_NFC_INVALID_HANDLE target handle is not valid + @exception NET_NFC_TAG_WRITE_FAILED read only tag, or error ack is received from tag + +*/ + +net_nfc_error_e net_nfc_mifare_restore(net_nfc_target_handle_h handle, uint8_t addr, void* trans_param); + +/** + create default factory key. The key is 0xff, 0xff, 0xff, 0xff, 0xff, 0xff + + \par Sync (or) Async: Sync + This is a Asynchronous API + + @param[in] key the handle to create key + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) + @exception NET_NFC_ALLOC_FAIL memory allocation is failed + +*/ + +net_nfc_error_e net_nfc_mifare_create_default_key(data_h* key); + +/** + create mifare application directory key. The key is 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5 + + \par Sync (or) Async: Sync + This is a Asynchronous API + + @param[in] key the handle to create key + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) + @exception NET_NFC_ALLOC_FAIL memory allocation is failed + +*/ + +net_nfc_error_e net_nfc_mifare_create_application_directory_key(data_h* key); + +/** + create nfc forum key. The key is 0xD3, 0xF7, 0xD3, 0xF7, 0xD3, 0xF7 + + \par Sync (or) Async: Sync + This is a Asynchronous API + + @param[in] key the handle to create key + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) + @exception NET_NFC_ALLOC_FAIL memory allocation is failed + +*/ + +net_nfc_error_e net_nfc_mifare_create_net_nfc_forum_key(data_h* key); + +/** +@} */ + + +#ifdef __cplusplus +} +#endif + + +#endif + diff --git a/src/clientlib/include/net_nfc_target_info.h b/src/clientlib/include/net_nfc_target_info.h new file mode 100755 index 0000000..61bee78 --- /dev/null +++ b/src/clientlib/include/net_nfc_target_info.h @@ -0,0 +1,314 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#ifndef __NET_NFC_TARGET_INFO_H__ +#define __NET_NFC_TARGET_INFO_H__ + +#include "net_nfc_typedef.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + +@addtogroup NET_NFC_MANAGER_INFO +@{ + This document is for the APIs reference document + + NFC Manager defines are defined in + + These APIs help to get infomation of detected target. these target info handler holds + - type of target + - target ID + - ndef message supporting + - max data size (if this tag is ndef message tag) + - actual data size (if this tag is ndef message tag) +*/ + +/** + type getter from targte info handler + + \par Sync (or) Async: Sync + This is a Synchronous API + + @param[in] target_info target info handler + @param[out] type tag type these type is one of the enum "net_nfc_target_type_e" defined + + @return return the result of calling this functions + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) + +*/ + +net_nfc_error_e net_nfc_get_tag_type (net_nfc_target_info_h target_info, net_nfc_target_type_e * type); + +/** + type getter from targte info handler + + \par Sync (or) Async: Sync + This is a Synchronous API + + @param[in] target_info target info handler + @param[out] handle target handle that is generated by nfc-manager + + @return return the result of calling this functions + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) + +*/ + +net_nfc_error_e net_nfc_get_tag_handle(net_nfc_target_info_h target_info, net_nfc_target_handle_h * handle); + +/** + this API returns the NDEF support boolean value. + The TRUE value will be returned if the detected target is support NDEF, or return FALSE + + \par Sync (or) Async: Sync + This is a Synchronous API + + @param[in] target_info target info handler + @param[out] is_support boolean value of NDEF supporting + + @return return the result of calling this functions + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) + +*/ + +net_nfc_error_e net_nfc_get_tag_ndef_support (net_nfc_target_info_h target_info, bool * is_support); + +/** + The max size getter from targte info handler. This max size indicates the maximum size of NDEF message that can be stored in this detected tag. + + \par Sync (or) Async: Sync + This is a Synchronous API + + @param[in] target_info target info handler + @param[out] max_size max size of NDEF message that can be stored in this detected tag. + + @return return the result of calling this functions + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) + +*/ + +net_nfc_error_e net_nfc_get_tag_max_data_size (net_nfc_target_info_h target_info, uint32_t * max_size); + +/** + this function return the actual NDEF message size that stored in the tag + + \par Sync (or) Async: Sync + This is a Synchronous API + + @param[in] target_info target info handler + @param[out] actual_data the actual NDEF message size that stored in the tag + + @return return the result of calling this functions + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) + +*/ + +net_nfc_error_e net_nfc_get_tag_actual_data_size (net_nfc_target_info_h target_info, uint32_t * actual_data); + + +/** + this function return keys which will be used to get a tag information + + \par Sync (or) Async: Sync + This is a Synchronous API. keys will be freed by user. + + @param[in] target_info target info handler + @param[out] keys pointer of double array. it will be array of string. + @param[out] number_of_keys length of array. + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s) + @exception NET_NFC_ALLOC_FAIL memory allocation is failed + @exception NET_NFC_NO_DATA_FOUND No data is returned + + @code + void user_cb(net_nfc_message_e message, net_nfc_error_e result, void* data, void* trans_param) + { + + switch(message) + { + case NET_NFC_MESSAGE_TAG_DISCOVERED: + { + if(info != NULL) + { + net_nfc_target_info_h target_info = (net_nfc_target_info_h)data; + + char **keys; + int keys_length; + + if(net_nfc_get_tag_info_keys(target_info, &keys, &keys_length) == true) + { + int index = 0; + for(; index < keys_length; index++) + { + char* key = keys[index]; + } + } + + free(keys); + } + } + } + + } + @endcode + + @return return the result of calling this functions + +*/ + +net_nfc_error_e net_nfc_get_tag_info_keys(net_nfc_target_info_h target_info, char ***keys, int* number_of_keys); + +/** + this function return value which is matched key + + \par Sync (or) Async: Sync + This is a Synchronous API + + @param[in] target_info target info handler + @param[in] key key to retrieve + @param[out] value value which is matched with key + + @code + void user_cb(net_nfc_message_e message, net_nfc_error_e result, void* data, void* trans_param) + { + + switch(message) + { + case NET_NFC_MESSAGE_TAG_DISCOVERED: + { + if(info != NULL) + { + net_nfc_target_info_h target_info = (net_nfc_target_info_h)data; + + char** keys; + int keys_length; + + if(net_nfc_get_tag_info_keys(target_info, &keys, &keys_length) == NET_NFC_OK) + { + int index = 0; + for(; index < keys_length; index++) + { + char* key = keys[index]; + data_h value; + net_nfc_get_tag_info_value(target_info, key, &value); + net_nfc_free_data(value); + } + } + } + } + } + + } + @endcode + + @return return the result of calling this functions + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illegal NULL pointer(s) + @exception NET_NFC_NO_DATA_FOUND No data is returned +*/ + +net_nfc_error_e net_nfc_get_tag_info_value(net_nfc_target_info_h target_info, const char* key, data_h* value); + +/** + Duplicate a handle of target information + + ** IMPORTANT : After using duplicated handle, you should release a handle returned from this function. + ** You can release a handle by net_nfc_release_tag_info function. + + \par Sync (or) Async: Sync + This is a Synchronous API + + @param[in] origin The original handle you want to duplicate + @param[out] result The result of this function. + + @code + void user_cb(net_nfc_message_e message, net_nfc_error_e result, void *data, void *trans_param) + { + switch(message) + { + case NET_NFC_MESSAGE_TAG_DISCOVERED: + { + net_nfc_target_info_h target_info = (net_nfc_target_info_h)data; + net_nfc_target_info_h handle = NULL; + + net_nfc_duplicate_target_info(target_info, &handle); + + // do something... + + net_nfc_release_tag_info(handle); + } + break; + } + + } + @endcode + + @return return the result of calling this functions + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illegal NULL pointer(s) +*/ + +net_nfc_error_e net_nfc_duplicate_target_info(net_nfc_target_info_h origin, net_nfc_target_info_h *result); + +/** + After using net_nfc_target_info_h handle, you should release its resource by this function. + + ** IMPORTANT : Never use this function in user callback you registered by net_nfc_set_response_callback function + ** This function is for the result of net_nfc_duplicate_target_info or net_nfc_get_current_tag_info_sync + + \par Sync (or) Async: Sync + This is a Synchronous API + + @param[in] target_info target info handle + + @code + net_nfc_target_info_h handle; + + net_nfc_get_current_tag_info_sync(&handle); + + // do something... + + net_nfc_release_tag_info(handle); + @endcode + + @return return the result of calling this functions + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illegal NULL pointer(s) +*/ + +net_nfc_error_e net_nfc_release_tag_info(net_nfc_target_info_h target_info); + + +/** +@} */ + + +#ifdef __cplusplus +} +#endif + + +#endif + + diff --git a/src/clientlib/include/net_nfc_test.h b/src/clientlib/include/net_nfc_test.h new file mode 100644 index 0000000..1050763 --- /dev/null +++ b/src/clientlib/include/net_nfc_test.h @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef NET_NFC_TEST_H_ +#define NET_NFC_TEST_H_ + +#ifdef __cplusplus +extern "C" +{ +#endif + +#include "net_nfc_typedef.h" + +net_nfc_error_e net_nfc_sim_test(void); +net_nfc_error_e net_nfc_prbs_test(int tech, int rate); + +net_nfc_error_e net_nfc_get_firmware_version(void); + +void net_nfc_test_read_test_cb(net_nfc_message_e message, net_nfc_error_e result, void *data, void *user_param, void *trans_data); +void net_nfc_test_sim_test_cb(net_nfc_message_e message, net_nfc_error_e result, void *data, void *user_param, void *trans_data); + +net_nfc_error_e net_nfc_set_eedata_register(int mode, int reg_id, uint8_t *data, uint32_t len); + +#ifdef __cplusplus +} +#endif + +#endif /* NET_NFC_TEST_H_ */ diff --git a/src/clientlib/net_nfc_client_data.c b/src/clientlib/net_nfc_client_data.c new file mode 100755 index 0000000..ab0b1ed --- /dev/null +++ b/src/clientlib/net_nfc_client_data.c @@ -0,0 +1,159 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include "net_nfc_data.h" +#include "net_nfc_typedef_private.h" +#include "net_nfc_util_private.h" + +#ifndef NET_NFC_EXPORT_API +#define NET_NFC_EXPORT_API __attribute__((visibility("default"))) +#endif + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_create_data_only(data_h* data) +{ + return net_nfc_create_data(data, NULL, 0); +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_create_data(data_h* data, const uint8_t* bytes, const uint32_t length) +{ + data_s *data_private = NULL; + + if (data == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + _net_nfc_util_alloc_mem(data_private, sizeof(data_s)); + if (data_private == NULL) + return NET_NFC_ALLOC_FAIL; + + if (length > 0) + { + _net_nfc_util_alloc_mem(data_private->buffer, length); + if (data_private->buffer == NULL) + { + _net_nfc_util_free_mem(data_private); + return NET_NFC_ALLOC_FAIL; + } + + data_private->length = length; + + if (bytes != NULL) + { + memcpy(data_private->buffer, bytes, length); + } + } + + *data = (data_h)data_private; + + return NET_NFC_OK; +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_data(const data_h data, uint8_t** bytes, uint32_t * length) +{ + if (data == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + data_s * data_private = (data_s *)data; + + *bytes = data_private->buffer; + *length = data_private->length; + + return NET_NFC_OK; +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_set_data(const data_h data, const uint8_t* bytes, const uint32_t length) +{ + if (data == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + data_s * data_private = (data_s *)data; + + if (data_private->buffer == bytes && data_private->length == length) + { + return NET_NFC_OK; + } + + if (data_private->buffer != NULL) + { + _net_nfc_util_free_mem(data_private->buffer); + } + + if (length <= 0) + { + data_private->buffer = NULL; + data_private->length = 0; + return NET_NFC_OK; + } + + if (length > 0) + { + _net_nfc_util_alloc_mem((data_private)->buffer, length); + } + + if (bytes != NULL) + { + memcpy(data_private->buffer, bytes, length); + } + + data_private->length = length; + + return NET_NFC_OK; +} + +NET_NFC_EXPORT_API uint32_t net_nfc_get_data_length(const data_h data) +{ + if (data == NULL) + { + return 0; + } + data_s * data_private = (data_s *)data; + + return data_private->length; +} + +NET_NFC_EXPORT_API uint8_t * net_nfc_get_data_buffer(const data_h data) +{ + if (data == NULL) + { + return NULL; + } + data_s * data_private = (data_s *)data; + + return data_private->buffer; +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_free_data(data_h data) +{ + if (data == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + data_s * data_private = (data_s *)data; + + if (data_private->buffer != NULL) + { + _net_nfc_util_free_mem(data_private->buffer); + } + _net_nfc_util_free_mem(data_private); + + return NET_NFC_OK; +} + diff --git a/src/clientlib/net_nfc_client_dispatcher.c b/src/clientlib/net_nfc_client_dispatcher.c new file mode 100755 index 0000000..4c259a8 --- /dev/null +++ b/src/clientlib/net_nfc_client_dispatcher.c @@ -0,0 +1,1131 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#ifdef USE_ECORE_MAIN_LOOP +#include "Ecore.h" +#endif + +#include "net_nfc_typedef_private.h" +#include "net_nfc_typedef.h" +#include "net_nfc_data.h" +#include "net_nfc_exchanger_private.h" +#include "net_nfc_tag.h" +#include "net_nfc_debug_private.h" +#include "net_nfc_util_defines.h" +#include "net_nfc_util_private.h" +#include "net_nfc_util_ndef_message.h" +#include "net_nfc_client_dispatcher_private.h" +#include "net_nfc_client_nfc_private.h" + + +extern unsigned int socket_handle; + +net_nfc_llcp_internal_socket_s *_find_internal_socket_info(net_nfc_llcp_socket_t socket); +net_nfc_llcp_internal_socket_s *_find_internal_socket_info_by_oal_socket(net_nfc_llcp_socket_t socket); +void _append_internal_socket(net_nfc_llcp_internal_socket_s *data); +void _remove_internal_socket(net_nfc_llcp_internal_socket_s *data); +void _net_nfc_llcp_close_all_socket(); +void _net_nfc_set_llcp_remote_configure(net_nfc_llcp_config_info_s *remote_data); + +typedef struct _client_dispatcher_param_t +{ + net_nfc_response_cb client_cb; + net_nfc_response_msg_t *msg; +} client_dispatcher_param_t; + +/* static function */ + +static net_nfc_error_e net_nfc_get_tag_info_list(data_s *values, int number_of_keys, net_nfc_tag_info_s **list); +static bool net_nfc_client_dispatch_response(client_dispatcher_param_t *param); + +///////////////////// + +void _net_nfc_set_llcp_current_target_id(net_nfc_target_handle_s *handle); + +#ifdef SAVE_TARGET_INFO_IN_CC +static void __net_nfc_clear_tag_info_cache (client_context_t *context) +{ + if (context->target_info != NULL) + { + net_nfc_target_info_s *info = context->target_info; + net_nfc_tag_info_s *list = info->tag_info_list; + + if (list != NULL) + { + + int i = 0; + net_nfc_tag_info_s *temp = list; + + while (i < info->number_of_keys) + { + if (list->key != NULL) + free(list->key); + + if (list->value != NULL) + net_nfc_free_data(list->value); + + list++; + i++; + } + + /* destroy list */ + free(temp); + } + + if (info->keylist != NULL) + { + _net_nfc_util_free_mem(info->keylist); + } + + _net_nfc_util_free_mem(context->target_info); + context->target_info = NULL; + } +} +#endif + +#ifdef USE_GLIB_MAIN_LOOP +void net_nfc_client_call_dispatcher_in_g_main_loop(net_nfc_response_cb client_cb, net_nfc_response_msg_t *msg) +{ + client_dispatcher_param_t *param = NULL; + + DEBUG_CLIENT_MSG("put message to g main loop"); + + _net_nfc_util_alloc_mem(param, sizeof(client_dispatcher_param_t)); + if (param != NULL) + { + param->client_cb = client_cb; + param->msg = msg; + + if (g_idle_add_full(G_PRIORITY_HIGH_IDLE, (GSourceFunc)net_nfc_client_dispatch_response, param, NULL)) + { + g_main_context_wakeup(g_main_context_default()); + } + } +} +#elif USE_ECORE_MAIN_LOOP +void net_nfc_client_call_dispatcher_in_ecore_main_loop(net_nfc_response_cb client_cb, net_nfc_response_msg_t *msg) +{ + client_dispatcher_param_t *param = NULL; + + DEBUG_CLIENT_MSG("put message to ecore main loop"); + + _net_nfc_util_alloc_mem(param, sizeof(client_dispatcher_param_t)); + if (param != NULL) + { + param->client_cb = client_cb; + param->msg = msg; + + if (ecore_idler_add((Ecore_Task_Cb)net_nfc_client_dispatch_response, param) != NULL) + { + g_main_context_wakeup(g_main_context_default()); + } + } +} +#else +void net_nfc_client_call_dispatcher_in_current_context(net_nfc_response_cb client_cb, net_nfc_response_msg_t *msg) +{ + client_dispatcher_param_t *param = NULL; + + DEBUG_CLIENT_MSG("invoke callback in current thread"); + + _net_nfc_util_alloc_mem(param, sizeof(client_dispatcher_param_t)); + if (param != NULL) + { + param->client_cb = client_cb; + param->msg = msg; + + net_nfc_client_dispatch_response(param); + } +} +#endif + +static bool net_nfc_client_dispatch_response(client_dispatcher_param_t *param) +{ + if (param == NULL) + return false; + + net_nfc_response_cb client_cb = param->client_cb; + net_nfc_response_msg_t *msg = param->msg; + + _net_nfc_util_free_mem(param); + + DEBUG_CLIENT_MSG("we have got message from nfc-daemon type = [%d]", msg->response_type); + + client_context_t *client_context = net_nfc_get_client_context(); + + switch (msg->response_type) + { + case NET_NFC_MESSAGE_GET_SE : + { + if (client_cb != NULL) + { + client_cb(msg->response_type, ((net_nfc_response_get_se_t *)msg->detail_message)->result, &(((net_nfc_response_get_se_t *)msg->detail_message)->se_type), client_context->register_user_param, ((net_nfc_response_get_se_t *)msg->detail_message)->trans_param); + } + } + break; + + case NET_NFC_MESSAGE_SET_SE : + { + if (client_cb != NULL) + { + client_cb(msg->response_type, ((net_nfc_response_set_se_t *)msg->detail_message)->result, &(((net_nfc_response_get_se_t *)msg->detail_message)->se_type), client_context->register_user_param, ((net_nfc_response_set_se_t *)msg->detail_message)->trans_param); + } + } + break; + + case NET_NFC_MESSAGE_SE_TYPE_CHANGED : + { + if (client_cb != NULL) + { + client_cb(msg->response_type, NET_NFC_OK, NULL, NULL, NULL); + } + } + break; + + case NET_NFC_MESSAGE_OPEN_INTERNAL_SE : + { + DEBUG_CLIENT_MSG("handle = [0x%p]", ((net_nfc_response_open_internal_se_t *)(msg->detail_message))->handle); + + if (client_cb != NULL) + { + client_cb(msg->response_type, ((net_nfc_response_open_internal_se_t *)(msg->detail_message))->result, (void *)((net_nfc_response_open_internal_se_t *)(msg->detail_message))->handle, client_context->register_user_param, ((net_nfc_response_open_internal_se_t *)(msg->detail_message))->trans_param); + } + } + break; + + case NET_NFC_MESSAGE_CLOSE_INTERNAL_SE : + { + if (client_cb != NULL) + client_cb(msg->response_type, ((net_nfc_response_close_internal_se_t *)msg->detail_message)->result, NULL, client_context->register_user_param, ((net_nfc_response_close_internal_se_t *)msg->detail_message)->trans_param); + } + break; + + case NET_NFC_MESSAGE_SEND_APDU_SE : + { + data_s *apdu = &(((net_nfc_response_send_apdu_t *)msg->detail_message)->data); + + if (apdu->length > 0) + { + if (client_cb != NULL) + client_cb(msg->response_type, ((net_nfc_response_send_apdu_t *)msg->detail_message)->result, apdu, client_context->register_user_param, ((net_nfc_response_send_apdu_t *)(msg->detail_message))->trans_param); + } + else + { + if (client_cb != NULL) + client_cb(msg->response_type, ((net_nfc_response_send_apdu_t *)msg->detail_message)->result, NULL, client_context->register_user_param, ((net_nfc_response_send_apdu_t *)(msg->detail_message))->trans_param); + } + } + break; + + case NET_NFC_MESSAGE_NOTIFY : + { + if (client_cb != NULL) + client_cb(msg->response_type, ((net_nfc_response_notify_t *)msg->detail_message)->result, NULL, client_context->register_user_param, NULL); + } + break; + + case NET_NFC_MESSAGE_TRANSCEIVE : + { + data_s *data = &(((net_nfc_response_transceive_t *)msg->detail_message)->data); + + if (data->length > 0) + { + if (client_cb != NULL) + client_cb(msg->response_type, ((net_nfc_response_transceive_t *)msg->detail_message)->result, data, client_context->register_user_param, ((net_nfc_response_transceive_t *)(msg->detail_message))->trans_param); + } + else + { + if (client_cb != NULL) + client_cb(msg->response_type, ((net_nfc_response_transceive_t *)msg->detail_message)->result, NULL, client_context->register_user_param, ((net_nfc_response_transceive_t *)(msg->detail_message))->trans_param); + } + } + break; + + case NET_NFC_MESSAGE_MAKE_READ_ONLY_NDEF : + { + if (client_cb != NULL) + client_cb(msg->response_type, ((net_nfc_response_make_read_only_ndef_t *)msg->detail_message)->result, NULL, client_context->register_user_param, ((net_nfc_response_make_read_only_ndef_t *)(msg->detail_message))->trans_param); + } + break; + + case NET_NFC_MESSAGE_IS_TAG_CONNECTED : + { + if (client_cb != NULL) + client_cb(msg->response_type, ((net_nfc_response_is_tag_connected_t *)msg->detail_message)->result, (void *)&(((net_nfc_response_is_tag_connected_t *)msg->detail_message)->devType), client_context->register_user_param, ((net_nfc_response_is_tag_connected_t *)(msg->detail_message))->trans_param); + } + break; + + case NET_NFC_MESSAGE_READ_NDEF : + { + data_s *data = &(((net_nfc_response_read_ndef_t *)msg->detail_message)->data); + ndef_message_s *ndef = NULL; + + if (net_nfc_util_create_ndef_message(&ndef) != NET_NFC_OK) + { + DEBUG_ERR_MSG("memory alloc fail.."); + break; + } + + if (data->length > 0 && net_nfc_util_convert_rawdata_to_ndef_message(data, ndef) == NET_NFC_OK) + { + if(client_cb != NULL) + client_cb(msg->response_type, ((net_nfc_response_read_ndef_t *)msg->detail_message)->result, ndef, client_context->register_user_param, ((net_nfc_response_transceive_t *)(msg->detail_message))->trans_param); + } + else + { + if(client_cb != NULL) + client_cb(msg->response_type, ((net_nfc_response_read_ndef_t *)msg->detail_message)->result, NULL, client_context->register_user_param, ((net_nfc_response_transceive_t *)(msg->detail_message))->trans_param); + } + net_nfc_util_free_ndef_message(ndef); + } + break; + + case NET_NFC_GET_SERVER_STATE : + { + if (client_cb != NULL) + client_cb(msg->response_type, ((net_nfc_response_get_server_state_t *)msg->detail_message)->result, NULL, client_context->register_user_param, (void *)((net_nfc_response_get_server_state_t *)msg->detail_message)->state); + } + break; + + case NET_NFC_MESSAGE_SIM_TEST : + { + if (client_cb != NULL) + client_cb(msg->response_type, ((net_nfc_response_get_server_state_t *)msg->detail_message)->result, NULL, client_context->register_user_param, (void *)((net_nfc_response_get_server_state_t *)msg->detail_message)->state); + } + break; + + case NET_NFC_MESSAGE_PRBS_TEST : + { + if (client_cb != NULL) + client_cb(msg->response_type, ((net_nfc_response_get_server_state_t *)msg->detail_message)->result, NULL, client_context->register_user_param, (void *)((net_nfc_response_get_server_state_t *)msg->detail_message)->state); + } + break; + + case NET_NFC_MESSAGE_SET_EEDATA : + { + if (client_cb != NULL) + client_cb(msg->response_type, ((net_nfc_response_get_server_state_t *)msg->detail_message)->result, NULL, client_context->register_user_param, (void *)((net_nfc_response_get_server_state_t *)msg->detail_message)->state); + } + break; + + case NET_NFC_MESSAGE_GET_FIRMWARE_VERSION : + { + data_s *version = &(((net_nfc_response_firmware_version_t *)msg->detail_message)->data); + + if (version->length > 0) + { + if (client_cb != NULL) + client_cb(msg->response_type, ((net_nfc_response_send_apdu_t *)msg->detail_message)->result, version, client_context->register_user_param, ((net_nfc_response_send_apdu_t *)(msg->detail_message))->trans_param); + } + else + { + if (client_cb != NULL) + client_cb(msg->response_type, ((net_nfc_response_send_apdu_t *)msg->detail_message)->result, NULL, client_context->register_user_param, ((net_nfc_response_send_apdu_t *)(msg->detail_message))->trans_param); + } + } + break; + + case NET_NFC_MESSAGE_WRITE_NDEF : + { + if (client_cb != NULL) + client_cb(msg->response_type, ((net_nfc_response_write_ndef_t *)msg->detail_message)->result, NULL, client_context->register_user_param, ((net_nfc_response_transceive_t *)(msg->detail_message))->trans_param); + } + break; + + case NET_NFC_MESSAGE_TAG_DISCOVERED : + { + net_nfc_response_tag_discovered_t *detected = (net_nfc_response_tag_discovered_t *)msg->detail_message; + + if (net_nfc_util_check_tag_filter(detected->devType) == false) + { + DEBUG_CLIENT_MSG("The detected target is filtered out"); + } + +#ifdef SAVE_TARGET_INFO_IN_CC + __net_nfc_clear_tag_info_cache(client_context); + + net_nfc_tag_info_s *list = NULL; + net_nfc_get_tag_info_list(&(detected->target_info_values), detected->number_of_keys, &list); + + net_nfc_target_info_s *info = NULL; + _net_nfc_util_alloc_mem(info, sizeof(net_nfc_target_info_s)); + if (info == NULL) + { + DEBUG_CLIENT_MSG("mem alloc is failed"); + _net_nfc_util_free_mem(list); + break; + } + + info->ndefCardState = detected->ndefCardState; + info->actualDataSize = detected->actualDataSize; + info->maxDataSize = detected->maxDataSize; + info->devType = detected->devType; + info->handle = detected->handle; + info->is_ndef_supported = detected->is_ndef_supported; + info->number_of_keys = detected->number_of_keys; + info->tag_info_list = list; + info->raw_data = detected->raw_data; + + client_context->target_info = info; + + if (client_cb != NULL) + client_cb(msg->response_type, NET_NFC_OK, info, client_context->register_user_param, NULL); +#else + net_nfc_tag_info_s *list = NULL; + net_nfc_get_tag_info_list(&(detected->target_info_values), detected->number_of_keys, &list); + + net_nfc_target_info_s info; + memset(&info, 0x00, sizeof(net_nfc_target_info_s)); + + info.ndefCardState = detected->ndefCardState; + info.actualDataSize = detected->actualDataSize; + info.maxDataSize = detected->maxDataSize; + info.devType = detected->devType; + info.handle = detected->handle; + info.is_ndef_supported = detected->is_ndef_supported; + info.number_of_keys = detected->number_of_keys; + info.tag_info_list = list; + info.raw_data = detected.raw_data; + + if (client_cb != NULL) + client_cb(msg->response_type, NET_NFC_OK, &info, client_context->register_user_param, NULL); + + net_nfc_util_release_tag_info(&info); +#endif + } + break; + + case NET_NFC_MESSAGE_GET_CURRENT_TAG_INFO : + { + net_nfc_response_get_current_tag_info_t *detected = (net_nfc_response_get_current_tag_info_t *)msg->detail_message; + + if (detected->result != NET_NFC_NOT_CONNECTED) + { + if (net_nfc_util_check_tag_filter(detected->devType) == false) + { + DEBUG_CLIENT_MSG("The detected target is filtered out"); + } + +#ifdef SAVE_TARGET_INFO_IN_CC + __net_nfc_clear_tag_info_cache(client_context); + + net_nfc_tag_info_s *list = NULL; + net_nfc_get_tag_info_list(&(detected->target_info_values), detected->number_of_keys, &list); + + net_nfc_target_info_s *info = NULL; + _net_nfc_util_alloc_mem(info, sizeof(net_nfc_target_info_s)); + if (info == NULL) + { + DEBUG_CLIENT_MSG("mem alloc is failed"); + _net_nfc_util_free_mem(list); + break; + } + + info->ndefCardState = detected->ndefCardState; + info->actualDataSize = detected->actualDataSize; + info->maxDataSize = detected->maxDataSize; + info->devType = detected->devType; + info->handle = detected->handle; + info->is_ndef_supported = detected->is_ndef_supported; + info->number_of_keys = detected->number_of_keys; + info->tag_info_list = list; + info->raw_data = detected->raw_data; + + client_context->target_info = info; + + if (client_cb != NULL) + client_cb(msg->response_type, NET_NFC_OK, info, client_context->register_user_param, detected->trans_param); +#else + net_nfc_tag_info_s *list = NULL; + net_nfc_get_tag_info_list(&(detected->target_info_values), detected->number_of_keys, &list); + + net_nfc_target_info_s info; + memset(&info, 0x00, sizeof(net_nfc_target_info_s)); + + info.ndefCardState = detected->ndefCardState; + info.actualDataSize = detected->actualDataSize; + info.maxDataSize = detected->maxDataSize; + info.devType = detected->devType; + info.handle = detected->handle; + info.is_ndef_supported = detected->is_ndef_supported; + info.number_of_keys = detected->number_of_keys; + info.tag_info_list = list; + info.raw_data = detected.raw_data; + + if (client_cb != NULL) + client_cb(msg->response_type, NET_NFC_OK, &info, client_context->register_user_param, detected->trans_param); + + net_nfc_util_release_tag_info(&info); +#endif + } + else + { + if (client_cb != NULL) + client_cb(msg->response_type, detected->result, NULL, client_context->register_user_param, detected->trans_param); + } + } + break; + + case NET_NFC_MESSAGE_GET_CURRENT_TARGET_HANDLE : + { + net_nfc_response_get_current_target_handle_t *detected = (net_nfc_response_get_current_target_handle_t *)msg->detail_message; + + if (detected->result == NET_NFC_OK) + { + if (client_cb != NULL) + client_cb(msg->response_type, detected->result, (void *)detected->handle, client_context->register_user_param, detected->trans_param); + } + else + { + if (client_cb != NULL) + client_cb(msg->response_type, detected->result, NULL, client_context->register_user_param, detected->trans_param); + } + } + break; + + case NET_NFC_MESSAGE_TAG_DETACHED : + { + net_nfc_response_target_detached_t *detached = (net_nfc_response_target_detached_t *)msg->detail_message; + + if (net_nfc_util_check_tag_filter(detached->devType) == false) + { + DEBUG_CLIENT_MSG("The detected target is filtered out"); + } + + if (client_cb != NULL) + client_cb(msg->response_type, NET_NFC_OK, (net_nfc_target_handle_h)detached->handle, client_context->register_user_param, NULL); + +#ifdef SAVE_TARGET_INFO_IN_CC + __net_nfc_clear_tag_info_cache(client_context); +#endif + } + break; + + case NET_NFC_MESSAGE_FORMAT_NDEF : + { + net_nfc_response_format_ndef_t *detail_msg = (net_nfc_response_format_ndef_t *)msg->detail_message; + + if (client_cb != NULL) + client_cb(msg->response_type, detail_msg->result, NULL, client_context->register_user_param, detail_msg->trans_param); + } + break; + + case NET_NFC_MESSAGE_SE_START_TRANSACTION : + case NET_NFC_MESSAGE_SE_END_TRANSACTION : + case NET_NFC_MESSAGE_SE_TYPE_TRANSACTION : + case NET_NFC_MESSAGE_SE_CONNECTIVITY : + case NET_NFC_MESSAGE_SE_FIELD_ON : + case NET_NFC_MESSAGE_SE_FIELD_OFF : + { + net_nfc_response_se_event_t *se_event = (net_nfc_response_se_event_t *)msg->detail_message; + net_nfc_se_event_info_s info = { { 0, }, }; + + info.aid = se_event->aid; + info.param = se_event->param; + + if (client_cb != NULL) + client_cb(msg->response_type, NET_NFC_OK, (void *)&info, client_context->register_user_param, NULL); + } + break; + + case NET_NFC_MESSAGE_LLCP_LISTEN : + { + net_nfc_response_listen_socket_t *detail_msg = (net_nfc_response_listen_socket_t *)msg->detail_message; + net_nfc_llcp_internal_socket_s *psocket_info = NULL; + + psocket_info = _find_internal_socket_info(detail_msg->client_socket); + if (psocket_info == NULL) + { + DEBUG_ERR_MSG("Wrong client socket is returned from server.."); + break; + } + psocket_info->oal_socket = detail_msg->oal_socket; + DEBUG_CLIENT_MSG ("oal socket %d", detail_msg->oal_socket); + if (psocket_info->cb != NULL) + { + psocket_info->cb(msg->response_type, detail_msg->result, NULL, psocket_info->register_param, detail_msg->trans_param); + } + } + break; + + case NET_NFC_MESSAGE_LLCP_CONNECT : + { + net_nfc_response_connect_socket_t *detail_msg = (net_nfc_response_connect_socket_t *)msg->detail_message; + net_nfc_llcp_internal_socket_s *psocket_info = NULL; + + psocket_info = _find_internal_socket_info(detail_msg->client_socket); + if (psocket_info == NULL) + { + DEBUG_ERR_MSG("Wrong client socket is returned from server.."); + break; + } + psocket_info->oal_socket = detail_msg->oal_socket; + if (psocket_info->cb != NULL) + { + psocket_info->cb(msg->response_type, detail_msg->result, NULL, psocket_info->register_param, detail_msg->trans_param); + } + } + break; + + case NET_NFC_MESSAGE_LLCP_CONNECT_SAP : + { + net_nfc_response_connect_sap_socket_t *detail_msg = (net_nfc_response_connect_sap_socket_t *)msg->detail_message; + net_nfc_llcp_internal_socket_s *psocket_info = NULL; + + psocket_info = _find_internal_socket_info(detail_msg->client_socket); + if (psocket_info == NULL) + { + DEBUG_ERR_MSG("Wrong client socket is returned from server.."); + break; + } + psocket_info->oal_socket = detail_msg->oal_socket; + if (psocket_info->cb != NULL) + { + psocket_info->cb(msg->response_type, detail_msg->result, NULL, psocket_info->register_param, detail_msg->trans_param); + } + } + break; + + case NET_NFC_MESSAGE_LLCP_SEND : + { + net_nfc_response_send_socket_t *detail_msg = (net_nfc_response_send_socket_t *)msg->detail_message; + net_nfc_llcp_internal_socket_s *psocket_info = NULL; + + psocket_info = _find_internal_socket_info(detail_msg->client_socket); + if (psocket_info == NULL) + { + DEBUG_ERR_MSG("Wrong client socket is returned from server.."); + break; + } + if (psocket_info->cb != NULL) + { + psocket_info->cb(msg->response_type, detail_msg->result, NULL, psocket_info->register_param, detail_msg->trans_param); + } + } + break; + + case NET_NFC_MESSAGE_LLCP_RECEIVE : + { + net_nfc_response_receive_socket_t *detail_msg = (net_nfc_response_receive_socket_t *)msg->detail_message; + + if (client_cb != NULL) + client_cb(msg->response_type, detail_msg->result, &(detail_msg->data), client_context->register_user_param, NULL); + } + break; + + case NET_NFC_MESSAGE_P2P_RECEIVE : + { + net_nfc_response_p2p_receive_t *detail_msg = (net_nfc_response_p2p_receive_t *)msg->detail_message; + + if (client_cb != NULL) + client_cb(msg->response_type, detail_msg->result, &(detail_msg->data), client_context->register_user_param, NULL); + } + break; + + case NET_NFC_MESSAGE_P2P_SEND : + { + net_nfc_response_p2p_send_t *detail_msg = (net_nfc_response_p2p_send_t *)msg->detail_message; + + if (client_cb != NULL) + client_cb(msg->response_type, detail_msg->result, NULL, client_context->register_user_param, NULL); + } + break; + + case NET_NFC_MESSAGE_LLCP_DISCONNECT : + { + net_nfc_response_disconnect_socket_t *detail_msg = (net_nfc_response_disconnect_socket_t *)msg->detail_message; + net_nfc_llcp_internal_socket_s *psocket_info = NULL; + + psocket_info = _find_internal_socket_info(detail_msg->client_socket); + if (psocket_info == NULL) + { + DEBUG_ERR_MSG("Wrong client socket is returned from server.."); + break; + } + if (psocket_info->cb != NULL) + { + psocket_info->cb(msg->response_type, detail_msg->result, NULL, psocket_info->register_param, detail_msg->trans_param); + } + } + break; + + case NET_NFC_MESSAGE_LLCP_CONFIG : + { + net_nfc_response_config_llcp_t *detail_msg = (net_nfc_response_config_llcp_t *)msg->detail_message; + + if (client_cb != NULL) + client_cb(msg->response_type, detail_msg->result, NULL, client_context->register_user_param, NULL); + } + break; + + case NET_NFC_MESSAGE_LLCP_ERROR : + { + net_nfc_response_llcp_socket_error_t *detail_msg = (net_nfc_response_llcp_socket_error_t *)msg->detail_message; + net_nfc_llcp_internal_socket_s *psocket_info = NULL; + + psocket_info = _find_internal_socket_info(detail_msg->client_socket); + if (psocket_info == NULL) + { + DEBUG_ERR_MSG("Wrong client socket is returned from server.."); + break; + } + if (psocket_info->cb != NULL) + { + psocket_info->cb(msg->response_type, detail_msg->error, NULL, psocket_info->register_param, NULL); + } + } + break; + + case NET_NFC_MESSAGE_LLCP_ACCEPTED : + { + net_nfc_response_incomming_llcp_t *detail_msg = (net_nfc_response_incomming_llcp_t *)msg->detail_message; + net_nfc_llcp_internal_socket_s *psocket_info = NULL; + psocket_info = _find_internal_socket_info_by_oal_socket(detail_msg->oal_socket); + if (psocket_info == NULL) + { + DEBUG_ERR_MSG("Wrong client socket is returned from server.."); + break; + } + if (psocket_info->cb != NULL) + { + net_nfc_llcp_internal_socket_s *socket_data = NULL; + _net_nfc_util_alloc_mem(socket_data, sizeof(net_nfc_llcp_internal_socket_s)); + socket_data->client_socket = socket_handle++; + socket_data->miu = detail_msg->option.miu; + socket_data->rw = detail_msg->option.rw; + socket_data->type = detail_msg->option.type; + socket_data->device_id = detail_msg->handle; + socket_data->close_requested = false; + socket_data->oal_socket = detail_msg->incomming_socket; + _append_internal_socket(socket_data); + psocket_info->cb(msg->response_type, detail_msg->result, (void *)&(socket_data->client_socket), psocket_info->register_param, NULL); + } + } + break; + + case NET_NFC_MESSAGE_LLCP_DISCOVERED : + { + net_nfc_response_llcp_discovered_t *detail_msg = (net_nfc_response_llcp_discovered_t *)msg->detail_message; + + _net_nfc_set_llcp_current_target_id(detail_msg->handle); + _net_nfc_set_llcp_remote_configure(&(detail_msg->llcp_config_info)); + + __net_nfc_clear_tag_info_cache(client_context); + + net_nfc_tag_info_s *list = NULL; + net_nfc_get_tag_info_list(&(detail_msg->target_info_values), detail_msg->number_of_keys, &list); + + net_nfc_target_info_s *info = NULL; + if ((info = calloc(1, sizeof(net_nfc_target_info_s))) == NULL) + { + DEBUG_CLIENT_MSG("mem alloc is failed"); + _net_nfc_util_free_mem(list); + break; + } + + info->actualDataSize = 0; + info->maxDataSize = 0; + info->devType = detail_msg->devType; + info->handle = detail_msg->handle; + info->is_ndef_supported = false; + info->number_of_keys = detail_msg->number_of_keys; + info->tag_info_list = list; + + client_context->target_info = info; + + if (client_cb != NULL) + { + client_cb(msg->response_type, NET_NFC_OK, (void *)info, client_context->register_user_param, NULL); + } + } + break; + + case NET_NFC_MESSAGE_P2P_DETACHED : + { + net_nfc_response_llcp_detached_t *detail_msg = (net_nfc_response_llcp_detached_t *)msg->detail_message; + + _net_nfc_set_llcp_current_target_id(NULL); + + if (client_cb != NULL) + { + client_cb(msg->response_type, detail_msg->result, NULL, client_context->register_user_param, NULL); + } + _net_nfc_llcp_close_all_socket(); + + } + break; + + case NET_NFC_MESSAGE_P2P_DISCOVERED : + { + net_nfc_response_p2p_discovered_t *detail_msg = (net_nfc_response_p2p_discovered_t *)msg->detail_message; + + if (client_cb != NULL) + { + client_cb(msg->response_type, detail_msg->result, (void *)detail_msg->handle, client_context->register_user_param, NULL); + } + } + break; + + case NET_NFC_MESSAGE_CONNECTION_HANDOVER : + { + net_nfc_response_connection_handover_t *detail_msg = (net_nfc_response_connection_handover_t *)msg->detail_message; + + if (detail_msg == NULL) + { + DEBUG_ERR_MSG("NET_NFC_MESSAGE_CONNECTION_HANDOVER detail_msg == NULL"); + break; + } + + if (client_cb != NULL) + { + net_nfc_connection_handover_info_s info = { 0, }; + + info.type = detail_msg->type; + info.data.length = detail_msg->data.length; + if (info.data.length > 0) + { + _net_nfc_util_alloc_mem(info.data.buffer, info.data.length); + if (info.data.buffer == NULL) + { + DEBUG_ERR_MSG("mem alloc is failed"); + break; + } + memcpy(info.data.buffer, detail_msg->data.buffer, info.data.length); + } + + client_cb(msg->response_type, detail_msg->event, (void *)&info, client_context->register_user_param, NULL); + + if (info.data.length > 0) + { + _net_nfc_util_free_mem(info.data.buffer); + } + } + } + break; + + case NET_NFC_MESSAGE_SERVICE_INIT : + { + net_nfc_response_test_t *detail_msg = (net_nfc_response_test_t *)msg->detail_message; + + DEBUG_CLIENT_MSG("NET_NFC_MESSAGE_SERVICE_INIT [%p]", detail_msg->trans_param); + + if (client_cb != NULL) + { + client_cb(NET_NFC_MESSAGE_INIT, detail_msg->result, NULL, client_context->register_user_param, NULL); + } + } + break; + + case NET_NFC_MESSAGE_SERVICE_DEINIT : + { + net_nfc_response_test_t *detail_msg = (net_nfc_response_test_t *)msg->detail_message; + + DEBUG_CLIENT_MSG("NET_NFC_MESSAGE_SERVICE_DEINIT [%p]", detail_msg->trans_param); + + if (client_cb != NULL) + { + client_cb(NET_NFC_MESSAGE_DEINIT, detail_msg->result, NULL, client_context->register_user_param, NULL); + } + } + break; + + default : + break; + } + + /* client callback must copy data to client area */ + net_nfc_util_mem_free_detail_msg(NET_NFC_UTIL_MSG_TYPE_RESPONSE, msg->response_type, msg->detail_message); + _net_nfc_util_free_mem(msg); + + return false; +} + +bool net_nfc_client_dispatch_sync_response(net_nfc_response_msg_t *msg) +{ +// client_context_t *client_context = NULL; + + if (msg == NULL || msg->detail_message == NULL) + return false; + + DEBUG_CLIENT_MSG("synchronous callback, message = [%d]", msg->response_type); + +// client_context = net_nfc_get_client_context(); + + switch (msg->response_type) + { + case NET_NFC_MESSAGE_GET_SE : + break; + + case NET_NFC_MESSAGE_SET_SE : + break; + + case NET_NFC_MESSAGE_SE_TYPE_CHANGED : + break; + + case NET_NFC_MESSAGE_OPEN_INTERNAL_SE : + break; + + case NET_NFC_MESSAGE_CLOSE_INTERNAL_SE : + break; + + case NET_NFC_MESSAGE_SEND_APDU_SE : + break; + + case NET_NFC_MESSAGE_NOTIFY : + break; + + case NET_NFC_MESSAGE_TRANSCEIVE : + break; + + case NET_NFC_MESSAGE_MAKE_READ_ONLY_NDEF : + break; + + case NET_NFC_MESSAGE_IS_TAG_CONNECTED : + { + net_nfc_response_is_tag_connected_t *response = (net_nfc_response_is_tag_connected_t *)msg->detail_message; + net_nfc_response_is_tag_connected_t *context = (net_nfc_response_is_tag_connected_t *)response->trans_param; + + if (context != NULL) + { + context->result = response->result; + context->devType = response->devType; + } + } + break; + + case NET_NFC_MESSAGE_READ_NDEF : + break; + + case NET_NFC_GET_SERVER_STATE : + break; + + case NET_NFC_MESSAGE_SIM_TEST : + break; + + case NET_NFC_MESSAGE_PRBS_TEST : + break; + + case NET_NFC_MESSAGE_SET_EEDATA : + break; + + case NET_NFC_MESSAGE_GET_FIRMWARE_VERSION : + break; + + case NET_NFC_MESSAGE_WRITE_NDEF : + break; + + case NET_NFC_MESSAGE_TAG_DISCOVERED : + break; + + case NET_NFC_MESSAGE_GET_CURRENT_TAG_INFO : + { + net_nfc_response_get_current_tag_info_t *response = (net_nfc_response_get_current_tag_info_t *)msg->detail_message; + net_nfc_response_get_current_tag_info_t *context = (net_nfc_response_get_current_tag_info_t *)response->trans_param; + + if (context != NULL) + { + context->result = response->result; + + if (response->result != NET_NFC_NOT_CONNECTED) + { + if (net_nfc_util_check_tag_filter(response->devType) == true) + { + net_nfc_target_info_s *info = NULL; + + _net_nfc_util_alloc_mem(info, sizeof(net_nfc_target_info_s)); + + info->ndefCardState = response->ndefCardState; + info->actualDataSize = response->actualDataSize; + info->maxDataSize = response->maxDataSize; + info->devType = response->devType; + info->handle = response->handle; + info->is_ndef_supported = response->is_ndef_supported; + info->number_of_keys = response->number_of_keys; + net_nfc_get_tag_info_list(&(response->target_info_values), response->number_of_keys, &info->tag_info_list); + if (response->raw_data.length > 0) + { + net_nfc_util_alloc_data(&info->raw_data, response->raw_data.length); + memcpy(info->raw_data.buffer, response->raw_data.buffer, info->raw_data.length); + } + + context->trans_param = info; + } + else + { + /* filtered tag */ + } + } + } + } + break; + + case NET_NFC_MESSAGE_GET_CURRENT_TARGET_HANDLE : + { + net_nfc_response_get_current_target_handle_t *response = (net_nfc_response_get_current_target_handle_t *)msg->detail_message; + net_nfc_response_get_current_target_handle_t *context = (net_nfc_response_get_current_target_handle_t *)response->trans_param; + + if (context != NULL) + { + context->handle = response->handle; + context->result = response->result; + } + } + break; + + case NET_NFC_MESSAGE_TAG_DETACHED : + break; + + case NET_NFC_MESSAGE_FORMAT_NDEF : + break; + + case NET_NFC_MESSAGE_SE_START_TRANSACTION : + case NET_NFC_MESSAGE_SE_END_TRANSACTION : + case NET_NFC_MESSAGE_SE_TYPE_TRANSACTION : + case NET_NFC_MESSAGE_SE_CONNECTIVITY : + case NET_NFC_MESSAGE_SE_FIELD_ON : + case NET_NFC_MESSAGE_SE_FIELD_OFF : + break; + + case NET_NFC_MESSAGE_LLCP_LISTEN : + break; + + case NET_NFC_MESSAGE_LLCP_CONNECT : + break; + + case NET_NFC_MESSAGE_LLCP_CONNECT_SAP : + break; + + case NET_NFC_MESSAGE_LLCP_SEND : + break; + + case NET_NFC_MESSAGE_LLCP_RECEIVE : + break; + + case NET_NFC_MESSAGE_P2P_RECEIVE : + break; + + case NET_NFC_MESSAGE_P2P_SEND : + break; + + case NET_NFC_MESSAGE_LLCP_DISCONNECT : + break; + + case NET_NFC_MESSAGE_LLCP_CONFIG : + break; + + case NET_NFC_MESSAGE_LLCP_ERROR : + break; + + case NET_NFC_MESSAGE_LLCP_ACCEPTED : + break; + + case NET_NFC_MESSAGE_LLCP_DISCOVERED : + break; + + case NET_NFC_MESSAGE_P2P_DETACHED : + break; + + case NET_NFC_MESSAGE_P2P_DISCOVERED : + break; + + case NET_NFC_MESSAGE_CONNECTION_HANDOVER : + break; + + case NET_NFC_MESSAGE_SERVICE_INIT : + break; + + case NET_NFC_MESSAGE_SERVICE_DEINIT : + break; + + default : + break; + } + + /* client callback must copy data to client area */ + net_nfc_util_mem_free_detail_msg(NET_NFC_UTIL_MSG_TYPE_RESPONSE, msg->response_type, msg->detail_message); + _net_nfc_util_free_mem(msg); + + return false; +} + +static net_nfc_error_e net_nfc_get_tag_info_list(data_s *values, int number_of_keys, net_nfc_tag_info_s **list) +{ + net_nfc_tag_info_s *temp_list = NULL; + + if (list == NULL) + return NET_NFC_NULL_PARAMETER; + + /* TODO */ + _net_nfc_util_alloc_mem(temp_list, number_of_keys * sizeof(net_nfc_tag_info_s)); + if (temp_list == NULL) + { + return NET_NFC_ALLOC_FAIL; + } + + *list = temp_list; + + /* get 1 byte :: length + * get key name + * get 1 byte :: value length + * make data_h + */ + uint8_t *pBuffer = values->buffer; + + if (pBuffer == NULL) + return NET_NFC_NULL_PARAMETER; + + int index = 0; + + while (index < number_of_keys) + { + int key_length = *pBuffer; + char *key = NULL; + + _net_nfc_util_alloc_mem(key, key_length + 1); + if (key == NULL) + return NET_NFC_ALLOC_FAIL; + pBuffer = pBuffer + 1; + + /* copy key name */ + memcpy(key, pBuffer, key_length); + pBuffer = pBuffer + key_length; + + DEBUG_CLIENT_MSG("key = [%s]", key); + + /* get values length */ + uint32_t value_length = *pBuffer; + pBuffer = pBuffer + 1; + + data_h value = NULL; + + if (value_length > 0) + { + net_nfc_create_data(&value, pBuffer, value_length); + pBuffer = pBuffer + value_length; + } + + temp_list->key = key; + temp_list->value = value; + + temp_list++; + + index++; + } + return NET_NFC_OK; +} diff --git a/src/clientlib/net_nfc_client_exchanger.c b/src/clientlib/net_nfc_client_exchanger.c new file mode 100755 index 0000000..35dd38b --- /dev/null +++ b/src/clientlib/net_nfc_client_exchanger.c @@ -0,0 +1,223 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include "net_nfc_exchanger.h" +#include "net_nfc_exchanger_private.h" +#include "net_nfc.h" +#include "net_nfc_typedef.h" +#include "net_nfc_typedef_private.h" +#include "net_nfc_util_private.h" +#include "net_nfc_debug_private.h" +#include "net_nfc_client_ipc_private.h" +#include "net_nfc_client_nfc_private.h" + +static net_nfc_exchanger_cb exchanger_cb = NULL; + +#ifndef NET_NFC_EXPORT_API +#define NET_NFC_EXPORT_API __attribute__((visibility("default"))) +#endif + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_create_exchanger_data(net_nfc_exchanger_data_h *ex_data, data_h payload) +{ + net_nfc_exchanger_data_s* tmp_ex_data = NULL; + + if (ex_data == NULL || payload == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + _net_nfc_util_alloc_mem(tmp_ex_data, sizeof(net_nfc_exchanger_data_s)); + if (tmp_ex_data == NULL) + { + return NET_NFC_ALLOC_FAIL; + } + + tmp_ex_data->type = NET_NFC_EXCHANGER_RAW; + + _net_nfc_util_alloc_mem(tmp_ex_data->binary_data.buffer, ((data_s *)payload)->length); + if (tmp_ex_data->binary_data.buffer == NULL) + { + _net_nfc_util_free_mem(tmp_ex_data); + + return NET_NFC_ALLOC_FAIL; + } + + memcpy(tmp_ex_data->binary_data.buffer, ((data_s *)payload)->buffer, ((data_s *)payload)->length); + + tmp_ex_data->binary_data.length = ((data_s *)payload)->length; + + *ex_data = (net_nfc_exchanger_data_h)tmp_ex_data; + + return NET_NFC_OK; +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_free_exchanger_data(net_nfc_exchanger_data_h ex_data) +{ + if (ex_data == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + if (((net_nfc_exchanger_data_s *)ex_data)->binary_data.buffer != NULL) + { + _net_nfc_util_free_mem(((net_nfc_exchanger_data_s *)ex_data)->binary_data.buffer); + } + + _net_nfc_util_free_mem(ex_data); + + return NET_NFC_OK; +} + +net_nfc_exchanger_cb net_nfc_get_exchanger_cb() +{ + return exchanger_cb; +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_unset_exchanger_cb() +{ + client_context_t* client_context = net_nfc_get_client_context(); + + if (exchanger_cb == NULL) + { + return NET_NFC_NOT_REGISTERED; + } + + if (client_context != NULL) + pthread_mutex_lock(&(client_context->g_client_lock)); + exchanger_cb = NULL; + if (client_context != NULL) + pthread_mutex_unlock(&(client_context->g_client_lock)); + + net_nfc_state_deactivate(); + net_nfc_deinitialize(); + + return NET_NFC_OK; +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_send_exchanger_data(net_nfc_exchanger_data_h ex_handle, net_nfc_target_handle_h target_handle, void* trans_param) +{ + net_nfc_error_e ret; + net_nfc_request_p2p_send_t *request = NULL; + uint32_t length = 0; + net_nfc_exchanger_data_s *ex_data = (net_nfc_exchanger_data_s *)ex_handle; + + DEBUG_CLIENT_MSG("send reqeust :: exchanger data = [%p] target_handle = [%p]", ex_handle, target_handle); + + length = sizeof(net_nfc_request_p2p_send_t) + ex_data->binary_data.length; + + _net_nfc_util_alloc_mem(request, length); + if (request == NULL) + { + return NET_NFC_ALLOC_FAIL; + } + + request->length = length; + request->request_type = NET_NFC_MESSAGE_P2P_SEND; + request->handle = (net_nfc_target_handle_s *)target_handle; + request->data_type = ex_data->type; + request->data.length = ex_data->binary_data.length; + request->user_param = (uint32_t)trans_param; + + memcpy(&request->data.buffer, ex_data->binary_data.buffer, request->data.length); + + ret = net_nfc_client_send_reqeust((net_nfc_request_msg_t *)request, NULL); + + _net_nfc_util_free_mem(request); + + return ret; +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_exchanger_request_connection_handover(net_nfc_target_handle_h target_handle, net_nfc_conn_handover_carrier_type_e type) +{ + net_nfc_error_e ret = NET_NFC_UNKNOWN_ERROR; + net_nfc_request_connection_handover_t *request = NULL; + uint32_t length = 0; + + if (target_handle == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + length = sizeof(net_nfc_request_p2p_send_t); + + _net_nfc_util_alloc_mem(request, length); + if (request == NULL) + { + return NET_NFC_ALLOC_FAIL; + } + + request->length = length; + request->request_type = NET_NFC_MESSAGE_CONNECTION_HANDOVER; + request->handle = (net_nfc_target_handle_s *)target_handle; + request->type = type; + + ret = net_nfc_client_send_reqeust((net_nfc_request_msg_t *)request, NULL); + + _net_nfc_util_free_mem(request); + + return ret; +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_exchanger_get_alternative_carrier_type(net_nfc_connection_handover_info_h info_handle, net_nfc_conn_handover_carrier_type_e *type) +{ + net_nfc_connection_handover_info_s *info = NULL; + + if (info_handle == NULL || type == NULL) + return NET_NFC_NULL_PARAMETER; + + info = (net_nfc_connection_handover_info_s *)info_handle; + + *type = info->type; + + return NET_NFC_OK; +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_exchanger_get_alternative_carrier_data(net_nfc_connection_handover_info_h info_handle, data_h *data) +{ + net_nfc_error_e result = NET_NFC_UNKNOWN_ERROR; + net_nfc_connection_handover_info_s *info = NULL; + + if (info_handle == NULL || data == NULL) + return NET_NFC_NULL_PARAMETER; + + info = (net_nfc_connection_handover_info_s *)info_handle; + + result = net_nfc_create_data(data, info->data.buffer, info->data.length); + + return result; +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_exchanger_free_alternative_carrier_data(net_nfc_connection_handover_info_h info_handle) +{ + net_nfc_error_e result = NET_NFC_UNKNOWN_ERROR; + net_nfc_connection_handover_info_s *info = NULL; + + if (info_handle == NULL) + return NET_NFC_NULL_PARAMETER; + + info = (net_nfc_connection_handover_info_s *)info_handle; + + if (info->data.buffer != NULL) + { + _net_nfc_util_free_mem(info->data.buffer); + } + + _net_nfc_util_free_mem(info); + + return result; +} diff --git a/src/clientlib/net_nfc_client_internal_se.c b/src/clientlib/net_nfc_client_internal_se.c new file mode 100755 index 0000000..839ee56 --- /dev/null +++ b/src/clientlib/net_nfc_client_internal_se.c @@ -0,0 +1,140 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include "net_nfc_tag.h" +#include "net_nfc_typedef_private.h" +#include "net_nfc_client_ipc_private.h" +#include "net_nfc_debug_private.h" +#include "net_nfc_util_private.h" +#include "net_nfc_client_nfc_private.h" + +#include +#include + +#ifndef NET_NFC_EXPORT_API +#define NET_NFC_EXPORT_API __attribute__((visibility("default"))) +#endif + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_set_secure_element_type(net_nfc_se_type_e se_type, void* trans_param) +{ + net_nfc_error_e ret; + net_nfc_request_set_se_t request = { 0, }; + + if (se_type < NET_NFC_SE_TYPE_NONE || se_type > NET_NFC_SE_TYPE_UICC) + { + return NET_NFC_INVALID_PARAM; + } + + request.length = sizeof(net_nfc_request_set_se_t); + request.request_type = NET_NFC_MESSAGE_SET_SE; + request.se_type = se_type; + request.trans_param = trans_param; + + ret = net_nfc_client_send_reqeust((net_nfc_request_msg_t *)&request, NULL); + + return ret; +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_secure_element_type(void* trans_param) +{ + net_nfc_error_e ret; + net_nfc_request_get_se_t request = { 0, }; + + request.length = sizeof(net_nfc_request_get_se_t); + request.request_type = NET_NFC_MESSAGE_GET_SE; + request.trans_param = trans_param; + + ret = net_nfc_client_send_reqeust((net_nfc_request_msg_t *)&request, NULL); + + return ret; +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_open_internal_secure_element(net_nfc_se_type_e se_type, void* trans_param) +{ + net_nfc_error_e ret; + net_nfc_request_open_internal_se_t request = { 0, }; + + if (se_type < NET_NFC_SE_TYPE_NONE || se_type > NET_NFC_SE_TYPE_UICC) + { + return NET_NFC_INVALID_PARAM; + } + + request.length = sizeof(net_nfc_request_open_internal_se_t); + request.request_type = NET_NFC_MESSAGE_OPEN_INTERNAL_SE; + request.se_type = se_type; + request.trans_param = trans_param; + + ret = net_nfc_client_send_reqeust((net_nfc_request_msg_t *)&request, NULL); + + return ret; +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_close_internal_secure_element(net_nfc_target_handle_h handle, void *trans_param) +{ + net_nfc_error_e ret; + net_nfc_request_close_internal_se_t request = { 0, }; + + if (handle == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + request.length = sizeof(net_nfc_request_close_internal_se_t); + request.request_type = NET_NFC_MESSAGE_CLOSE_INTERNAL_SE; + request.handle = (net_nfc_target_handle_s *)handle; + request.trans_param = trans_param; + + ret = net_nfc_client_send_reqeust((net_nfc_request_msg_t *)&request, NULL); + + return ret; +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_send_apdu(net_nfc_target_handle_h handle, data_h apdu, void* trans_param) +{ + net_nfc_error_e ret; + net_nfc_request_send_apdu_t *request = NULL; + uint32_t length = 0; + data_s *apdu_data = (data_s *)apdu; + + if (handle == NULL || apdu_data == NULL || apdu_data->buffer == NULL || apdu_data->length == 0) + { + return NET_NFC_NULL_PARAMETER; + } + + length = sizeof(net_nfc_request_send_apdu_t) + apdu_data->length; + + _net_nfc_util_alloc_mem(request, length); + if (request == NULL) + { + return NET_NFC_ALLOC_FAIL; + } + + request->length = length; + request->request_type = NET_NFC_MESSAGE_SEND_APDU_SE; + request->handle = (net_nfc_target_handle_s *)handle; + request->trans_param = trans_param; + + request->data.length = apdu_data->length; + memcpy(&request->data.buffer, apdu_data->buffer, request->data.length); + + ret = net_nfc_client_send_reqeust((net_nfc_request_msg_t *)request, NULL); + + _net_nfc_util_free_mem(request); + + return ret; +} + diff --git a/src/clientlib/net_nfc_client_ipc.c b/src/clientlib/net_nfc_client_ipc.c new file mode 100755 index 0000000..e23fa1c --- /dev/null +++ b/src/clientlib/net_nfc_client_ipc.c @@ -0,0 +1,1715 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "net_nfc_typedef_private.h" +#include "net_nfc_debug_private.h" +#include "net_nfc_util_defines.h" +#include "net_nfc_util_private.h" +#include "net_nfc_client_ipc_private.h" +#include "net_nfc_client_dispatcher_private.h" + +/* static variable */ +static int g_client_sock_fd = -1; +static pthread_mutex_t g_client_ipc_mutex = PTHREAD_MUTEX_INITIALIZER; +static pthread_cond_t g_client_ipc_cond = PTHREAD_COND_INITIALIZER; +static pthread_mutex_t cb_lock = PTHREAD_MUTEX_INITIALIZER; +static net_nfc_response_cb client_cb = NULL; + +#ifdef G_MAIN_LOOP +static GIOChannel *g_client_channel = NULL; +static uint32_t g_client_src_id = 0; +#else +#ifdef USE_IPC_EPOLL +#define EPOLL_SIZE 128 +static int g_client_poll_fd = -1; +static struct epoll_event g_client_poll_event = { 0, }; +#else +static fd_set fdset_read; +#endif +static pthread_t g_poll_thread = (pthread_t)0; +#endif + +/* static function */ +static net_nfc_response_msg_t *net_nfc_client_read_response_msg(net_nfc_error_e *result); +#ifdef G_MAIN_LOOP +gboolean net_nfc_client_ipc_callback_func(GIOChannel *channel, GIOCondition condition, gpointer data); +#else +static bool net_nfc_client_ipc_polling(net_nfc_error_e *result); +static void *net_nfc_client_ipc_thread(void *data); +#endif + +///////////////////// + +inline void net_nfc_client_ipc_lock() +{ + pthread_mutex_lock(&g_client_ipc_mutex); +} + +inline void net_nfc_client_ipc_unlock() +{ + pthread_mutex_unlock(&g_client_ipc_mutex); +} + +static void net_nfc_client_prepare_sync_call(net_nfc_request_msg_t *msg) +{ + net_nfc_client_ipc_lock(); + + NET_NFC_FLAGS_SET_SYNC_CALL(msg->flags); +} + +static net_nfc_error_e net_nfc_client_wait_sync_call(int timeout) +{ + net_nfc_error_e result = NET_NFC_OPERATION_FAIL; + + if (pthread_cond_wait(&g_client_ipc_cond, &g_client_ipc_mutex) == 0) + { + result = NET_NFC_OK; + } + + return result; +} + +static void net_nfc_client_post_sync_call() +{ + net_nfc_client_ipc_unlock(); +} + +static void net_nfc_client_recv_sync_call() +{ + net_nfc_client_ipc_lock(); +} + +static void net_nfc_client_notify_sync_call() +{ + pthread_cond_signal(&g_client_ipc_cond); + net_nfc_client_ipc_unlock(); +} + +bool net_nfc_client_is_connected() +{ +#ifdef G_MAIN_LOOP + if (g_client_sock_fd != -1 && g_client_channel != NULL && g_client_src_id != 0) +#else +#ifdef USE_IPC_EPOLL + if (g_client_sock_fd != -1 && g_client_poll_fd != -1 && g_poll_thread != (pthread_t)NULL) +#else + if (g_client_sock_fd != -1 && g_poll_thread != (pthread_t)NULL) +#endif +#endif + { + return true; + } + else + { + return false; + } +} + +static net_nfc_error_e _finalize_client_socket() +{ + net_nfc_error_e result = NET_NFC_OK; + + DEBUG_CLIENT_MSG("finalize client socket"); + + net_nfc_client_ipc_lock(); + + if (g_client_sock_fd != -1) + { +#ifdef G_MAIN_LOOP + g_io_channel_unref(g_client_channel); + g_client_channel = NULL; + + g_source_remove(g_client_src_id); + g_client_src_id = 0; +#else +#if 0 + if (g_poll_thread != (pthread_t)NULL) + { +#ifdef NET_NFC_USE_SIGTERM + /* This is dangerous because of the lock inside of the thread it creates dead lock! + * it may damage the application data or lockup, sigterm can be recieved while the application codes is executed in callback function + */ + pthread_kill(g_poll_thread, SIGTERM); +#else + DEBUG_CLIENT_MSG("join epoll_thread start"); + pthread_join(g_poll_thread, NULL); + DEBUG_CLIENT_MSG("join epoll_thread end"); +#endif + } + g_poll_thread = (pthread_t)NULL; +#endif +#ifdef USE_IPC_EPOLL + if (g_client_poll_fd != -1) + { + struct epoll_event ev; + + ev.events = EPOLLIN | EPOLLET | EPOLLRDHUP | EPOLLERR; + ev.data.fd = g_client_sock_fd; + + int ret = epoll_ctl(g_client_poll_fd, EPOLL_CTL_DEL, g_client_sock_fd, &ev); + + ret = close(g_client_poll_fd); + g_client_poll_fd = -1; + DEBUG_CLIENT_MSG("epoll close, %d", ret); + } +#else + FD_CLR(g_client_sock_fd, &fdset_read); +#endif +#endif // #ifdef G_MAIN_LOOP + close(g_client_sock_fd); + g_client_sock_fd = -1; + DEBUG_CLIENT_MSG("close socket"); + } + + net_nfc_client_ipc_unlock(); + + return result; +} + +net_nfc_error_e net_nfc_client_socket_initialize() +{ + int ret; + net_nfc_error_e result = NET_NFC_OK; + + if (net_nfc_client_is_connected() == true) + { + DEBUG_CLIENT_MSG("client is already initialized"); + return NET_NFC_ALREADY_INITIALIZED; + } + + pthread_mutexattr_t attr; + + pthread_mutexattr_init(&attr); + pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE_NP); + pthread_mutex_init(&cb_lock, &attr); + +#ifdef USE_UNIX_DOMAIN + struct sockaddr_un saddrun_rv; + socklen_t len_saddr = 0; + + memset(&saddrun_rv, 0, sizeof(struct sockaddr_un)); + + net_nfc_client_ipc_lock(); + + g_client_sock_fd = socket(AF_UNIX, SOCK_STREAM, 0); + if (g_client_sock_fd == -1) + { + DEBUG_ERR_MSG("get socket is failed"); + net_nfc_client_ipc_unlock(); + return NET_NFC_IPC_FAIL; + } + + DEBUG_CLIENT_MSG("socket is created"); + + net_nfc_util_set_non_block_socket(g_client_sock_fd); + + saddrun_rv.sun_family = AF_UNIX; + strncpy(saddrun_rv.sun_path, NET_NFC_SERVER_DOMAIN, sizeof(saddrun_rv.sun_path) - 1); + + len_saddr = sizeof(saddrun_rv.sun_family) + strlen(NET_NFC_SERVER_DOMAIN); + + if (connect(g_client_sock_fd, (struct sockaddr *)&saddrun_rv, len_saddr) < 0) + { + DEBUG_ERR_MSG("error is occured"); + result = NET_NFC_IPC_FAIL; + goto ERROR; + } +#else + struct sockaddr_in serv_addr; + memset(&serv_addr, 0x00, sizeof(struct sockaddr_in)); + + g_client_sock_fd = socket(PF_INET, SOCK_STREAM, 0); + + if (g_client_sock_fd == -1) + { + DEBUG_ERR_MSG("get socket is failed "); + net_nfc_client_ipc_unlock(); + return NET_NFC_IPC_FAIL; + } + + DEBUG_CLIENT_MSG("socket is created"); + + net_nfc_util_set_non_block_socket(g_client_sock_fd); + + serv_addr.sin_family = AF_INET; + serv_addr.sin_addr.s_addr = htonl(INADDR_ANY); + serv_addr.sin_port = htons(NET_NFC_SERVER_PORT); + + if ((connect(g_client_sock_fd, (struct sockaddr *)&serv_addr, sizeof(serv_addr))) < 0) + { + DEBUG_ERR_MSG("error is occured"); + result = NET_NFC_IPC_FAIL; + goto ERROR; + } + +#endif + +#ifdef G_MAIN_LOOP + + GIOCondition condition = (GIOCondition)(G_IO_ERR | G_IO_HUP | G_IO_IN); + + if ((g_client_channel = g_io_channel_unix_new(g_client_sock_fd)) != NULL) + { + if ((g_client_src_id = g_io_add_watch(g_client_channel, condition, net_nfc_client_ipc_callback_func, NULL)) < 1) + { + DEBUG_ERR_MSG(" g_io_add_watch is failed "); + result = NET_NFC_IPC_FAIL; + goto ERROR; + } + } + else + { + DEBUG_ERR_MSG(" g_io_channel_unix_new is failed "); + result = NET_NFC_IPC_FAIL; + goto ERROR; + } + + DEBUG_CLIENT_MSG("socket and g io channel is binded"); + +#else + +#ifdef USE_IPC_EPOLL + if ((g_client_poll_fd = epoll_create1(EPOLL_CLOEXEC)) == -1) + { + DEBUG_ERR_MSG("error is occured"); + result = NET_NFC_IPC_FAIL; + goto ERROR; + } + + memset(&g_client_poll_event, 0, sizeof(g_client_poll_event)); + + struct epoll_event ev; + + ev.events = EPOLLIN | EPOLLRDHUP | EPOLLERR; + ev.data.fd = g_client_sock_fd; + + ret = epoll_ctl(g_client_poll_fd, EPOLL_CTL_ADD, g_client_sock_fd, &ev); +#else + FD_ZERO(&fdset_read); + FD_SET(g_client_sock_fd, &fdset_read); +#endif + + /* create polling thread and go */ + pthread_attr_t thread_attr; + pthread_attr_init(&thread_attr); + pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED); + + pthread_cond_t pcond = PTHREAD_COND_INITIALIZER; + + if (pthread_create(&g_poll_thread, NULL, net_nfc_client_ipc_thread, &pcond) != 0) + { + DEBUG_ERR_MSG("error is occured"); + pthread_attr_destroy(&thread_attr); + result = NET_NFC_THREAD_CREATE_FAIL; + goto ERROR; + } + + usleep(0); + +#ifdef NET_NFC_USE_SIGTERM + pthread_cond_wait(&pcond, &g_client_ipc_mutex); +#endif + + DEBUG_CLIENT_MSG("start ipc thread = [%x]", (uint32_t)g_poll_thread); + + ////////////////////////////////// + + pthread_attr_destroy(&thread_attr); + +#endif // #ifdef G_MAIN_LOOP + net_nfc_client_ipc_unlock(); + + return NET_NFC_OK; + +ERROR : + DEBUG_ERR_MSG("error while initializing client ipc"); + + net_nfc_client_ipc_unlock(); + + _finalize_client_socket(); + + return result; +} + +#ifdef NET_NFC_USE_SIGTERM +static void thread_sig_handler(int signo) +{ + /* do nothing */ +} +#endif + +#ifndef G_MAIN_LOOP +static void *net_nfc_client_ipc_thread(void *data) +{ + DEBUG_CLIENT_MSG("net_nfc_client_ipc_thread is started = [0x%lx]", pthread_self()); + +#ifdef NET_NFC_USE_SIGTERM + + struct sigaction act; + act.sa_handler = thread_sig_handler; + sigaction(SIGTERM, &act, NULL); + + sigset_t newmask; + sigemptyset(&newmask); + sigaddset(&newmask, SIGTERM); + pthread_sigmask(SIG_UNBLOCK, &newmask, NULL); + DEBUG_CLIENT_MSG("sighandler is registered"); + +#endif + +#ifdef NET_NFC_USE_SIGTERM + net_nfc_client_ipc_lock(); + pthread_cond_signal((pthread_cond_t *)data); + net_nfc_client_ipc_unlock(); +#endif + + bool condition = true; + + while (condition == true) + { + net_nfc_error_e result = 0; + + if (net_nfc_client_ipc_polling(&result) != true) + { + switch (result) + { + case NET_NFC_OPERATION_FAIL : + DEBUG_CLIENT_MSG("shutdown request from server, stop ipc polling thread"); + _finalize_client_socket(); + condition = false; + break; + + case NET_NFC_IPC_FAIL : + DEBUG_ERR_MSG("abnormal socket close."); + _finalize_client_socket(); + condition = false; + break; + + default : + DEBUG_ERR_MSG("???"); + break; + } + } + else + { + net_nfc_response_msg_t *msg = NULL; + + DEBUG_CLIENT_MSG("message is coming from server to client"); + + msg = net_nfc_client_read_response_msg(&result); + + pthread_mutex_lock(&cb_lock); + if (msg != NULL) + { + /* TODO : need to remove */ + net_nfc_response_msg_t *temp = (net_nfc_response_msg_t *)(msg->detail_message); +; + if (NET_NFC_FLAGS_IS_SYNC_CALL(temp->flags)) + { + net_nfc_client_recv_sync_call(); + + /* call a callback in IPC thread */ + net_nfc_client_dispatch_sync_response(msg); + + /* unset sync call flag */ + net_nfc_client_notify_sync_call(); + } + else + { +#ifdef USE_GLIB_MAIN_LOOP + net_nfc_client_call_dispatcher_in_g_main_loop(client_cb, msg); +#elif USE_ECORE_MAIN_LOOP + net_nfc_client_call_dispatcher_in_ecore_main_loop(client_cb, msg); +#else + net_nfc_client_call_dispatcher_in_current_context(client_cb, msg); +#endif + } + } + else + { + /* if client is waiting for unlock signal, then unlock it. + * and send error message + * or make error response message and pass to client callback + */ + if (net_nfc_client_is_connected() == false) + { + condition = false; + } + DEBUG_ERR_MSG("cannot read response msg"); + } + pthread_mutex_unlock(&cb_lock); + } + } + + DEBUG_CLIENT_MSG("net_nfc_client_ipc_thread is terminated"); + + return (void *)NULL; +} +#endif + +#ifdef G_MAIN_LOOP +gboolean net_nfc_client_ipc_callback_func(GIOChannel *channel, GIOCondition condition, gpointer data) +{ + DEBUG_CLIENT_MSG("event is detected on client socket"); + + if(G_IO_IN & condition) + { + + int client_sock_fd = 0; + + if(channel == g_client_channel) + { + + DEBUG_CLIENT_MSG("message from server to client socket"); + + net_nfc_error_e result = NET_NFC_OK; + net_nfc_response_msg_t *msg = net_nfc_client_read_response_msg(&result); + + if(msg != NULL) + { + + net_nfc_client_call_dispatcher_in_current_context(client_cb, msg); + } + else + { + DEBUG_CLIENT_MSG("can not read response msg or callback is NULL"); + } + + } + else + { + DEBUG_CLIENT_MSG("unknown channel "); + return FALSE; + } + } + else + { + + DEBUG_CLIENT_MSG("IO ERROR. socket is closed "); + + /* clean up client context */ + net_nfc_client_socket_finalize(); + + return FALSE; + } + + return TRUE; +} +#else +bool net_nfc_client_ipc_polling(net_nfc_error_e *result) +{ + int num_of_sockets = 0; + + if (result == NULL) + { + return false; + } + + *result = NET_NFC_OK; + +#ifdef USE_IPC_EPOLL + DEBUG_CLIENT_MSG("wait event from epoll"); + + if (g_client_poll_fd == -1 || g_client_sock_fd == -1) + { + DEBUG_ERR_MSG("client is deinitialized. "); + *result = NET_NFC_IPC_FAIL; + return false; + } + + /* 0.5sec */ +#ifndef USE_EPOLL_TIMEOUT + while ((num_of_sockets = epoll_wait(g_client_poll_fd, &g_client_poll_event, 1, 300)) == 0) + { + if (g_client_poll_fd == -1) + { + DEBUG_CLIENT_MSG("client ipc thread is terminated"); + return false; + } + } +#else + num_of_sockets = epoll_wait(g_client_poll_fd, &g_client_poll_event, 1, -1); +#endif + if (num_of_sockets == 1) + { + if (g_client_poll_event.events & EPOLLRDHUP) + { + DEBUG_CLIENT_MSG("EPOLLRDHUP"); + *result = NET_NFC_OPERATION_FAIL; + return false; + } + else if (g_client_poll_event.events & EPOLLHUP) + { + DEBUG_CLIENT_MSG("EPOLLHUP"); + *result = NET_NFC_IPC_FAIL; + return false; + } + else if (g_client_poll_event.events & EPOLLERR) + { + DEBUG_CLIENT_MSG("EPOLLERR"); + *result = NET_NFC_IPC_FAIL; + return false; + } + else if (g_client_poll_event.events & EPOLLIN) + { + if (g_client_poll_event.data.fd == g_client_sock_fd) + { + return true; + } + else + { + DEBUG_ERR_MSG("unexpected socket connection"); + return false; + } + } + } + else + { + DEBUG_ERR_MSG("epoll_wait returns error"); + return false; + } +#else + DEBUG_CLIENT_MSG("wait event from select"); + + int temp = select(g_client_sock_fd + 1, &fdset_read, NULL, NULL, NULL); + + if(temp > 0) + { + if(FD_ISSET(g_client_sock_fd, &fdset_read) == true) + { + int val = 0; + int size = 0; + + if(getsockopt(g_client_sock_fd, SOL_SOCKET, SO_ERROR, &val, &size) == 0) + { + if(val != 0) + { + DEBUG_CLIENT_MSG("socket is on error"); + return false; + } + else + { + DEBUG_CLIENT_MSG("socket is readable"); + return true; + } + } + } + else + { + DEBUG_ERR_MSG("unknown error"); + *result = NET_NFC_IPC_FAIL; + return false; + } + } +#endif + + DEBUG_CLIENT_MSG("polling error"); + *result = NET_NFC_IPC_FAIL; + return false; +} +#endif + +void net_nfc_client_socket_finalize() +{ + net_nfc_client_ipc_lock(); + + if (g_client_sock_fd != -1) + { + DEBUG_CLIENT_MSG("shutdown socket, and wait EPOLLRDHUP"); + shutdown(g_client_sock_fd, SHUT_WR); + } + + net_nfc_client_ipc_unlock(); +} + +int __net_nfc_client_read_util(void **detail, size_t size) +{ + int length; + static uint8_t flushing[128]; + + if (recv(g_client_sock_fd, &length, sizeof(length), 0) != sizeof(length)) + { + return 0; + } + + *detail = NULL; + _net_nfc_util_alloc_mem(*detail, size); + + /* if the allocation is failed, this codes flush out all the buffered data */ + if (*detail == NULL) + { + size_t read_size; + int readbytes = size; + while (readbytes > 0) + { + read_size = readbytes > 128 ? 128 : readbytes; + if (recv(g_client_sock_fd, flushing, read_size, 0) <= 0) + { + return 0; + } + readbytes -= read_size; + } + return 0; + } + /* read */ + if (recv(g_client_sock_fd, *detail, size, 0) <= 0) + { + _net_nfc_util_free_mem(*detail); + return 0; + } + return 1; +} + +net_nfc_response_msg_t *net_nfc_client_read_response_msg(net_nfc_error_e *result) +{ + net_nfc_response_msg_t *resp_msg = NULL; + + _net_nfc_util_alloc_mem(resp_msg, sizeof(net_nfc_response_msg_t)); + if (resp_msg == NULL) + { + DEBUG_ERR_MSG("malloc fail"); + *result = NET_NFC_ALLOC_FAIL; + return NULL; + } + + if (recv(g_client_sock_fd, (void *)&(resp_msg->response_type), sizeof(int), 0) != sizeof(int)) + { + DEBUG_ERR_MSG("reading message is failed"); + _net_nfc_util_free_mem(resp_msg); + + return NULL; + } + +// DEBUG_MSG("<<<<< FROM SERVER <<<<< (msg [%d], length [%d])", resp_msg->response_type, length); + DEBUG_MSG("<<<<< FROM SERVER <<<<< (msg [%d])", resp_msg->response_type); + + switch (resp_msg->response_type) + { + case NET_NFC_MESSAGE_SET_SE : + { + net_nfc_response_set_se_t *resp_detail = NULL; + int res = 0; + res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_set_se_t)); + if (res != 1) + { + _net_nfc_util_free_mem(resp_msg); + return NULL; + } + resp_msg->detail_message = resp_detail; + } + break; + + case NET_NFC_MESSAGE_GET_SE : + { + net_nfc_response_get_se_t *resp_detail = NULL; + int res = 0; + res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_get_se_t)); + if (res != 1) + { + _net_nfc_util_free_mem(resp_msg); + return NULL; + } + resp_msg->detail_message = resp_detail; + } + break; + + case NET_NFC_MESSAGE_SE_TYPE_CHANGED : + { + net_nfc_response_notify_t *resp_detail = NULL; + int res = 0; + res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_notify_t)); + if (res != 1) + { + _net_nfc_util_free_mem(resp_msg); + return NULL; + } + resp_msg->detail_message = resp_detail; + } + break; + + case NET_NFC_MESSAGE_OPEN_INTERNAL_SE : + { + net_nfc_response_open_internal_se_t *resp_detail = NULL; + int res = 0; + res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_open_internal_se_t)); + if (res != 1) + { + _net_nfc_util_free_mem(resp_msg); + return NULL; + } + DEBUG_CLIENT_MSG("handle = [0x%p]", resp_detail->handle); + resp_msg->detail_message = resp_detail; + } + break; + + case NET_NFC_MESSAGE_CLOSE_INTERNAL_SE : + { + net_nfc_response_close_internal_se_t *resp_detail = NULL; + int res = 0; + res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_close_internal_se_t)); + if (res != 1) + { + _net_nfc_util_free_mem(resp_msg); + return NULL; + } + resp_msg->detail_message = resp_detail; + } + break; + + case NET_NFC_MESSAGE_SEND_APDU_SE : + { + + net_nfc_response_send_apdu_t *resp_detail = NULL; + int res = 0; + res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_send_apdu_t)); + if (res == 1) + { + if (resp_detail->data.length > 0) + { + res += __net_nfc_client_read_util((void **)&(resp_detail->data.buffer), resp_detail->data.length); + if (res == 2) + { + resp_msg->detail_message = resp_detail; + } + else + { + _net_nfc_util_free_mem(resp_detail); + res--; + } + } + else + { + resp_msg->detail_message = resp_detail; + resp_detail->data.buffer = NULL; + } + } + if (res == 0) + { + _net_nfc_util_free_mem(resp_msg); + return NULL; + } + } + break; + + case NET_NFC_MESSAGE_TAG_DISCOVERED : + { + net_nfc_response_tag_discovered_t *resp_detail = NULL; + int res = 0; + res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_tag_discovered_t)); + if (res == 1) + { + if (resp_detail->target_info_values.length > 0) + { + res += __net_nfc_client_read_util((void **)&(resp_detail->target_info_values.buffer), resp_detail->target_info_values.length); + if (res == 2) + { + if (resp_detail->raw_data.length > 0) + { + res += __net_nfc_client_read_util((void **)&(resp_detail->raw_data.buffer), resp_detail->raw_data.length); + if (res == 3) + { + resp_msg->detail_message = resp_detail; + } + else + { + _net_nfc_util_free_mem(resp_detail); + res--; + } + } + else + { + resp_msg->detail_message = resp_detail; + resp_detail->raw_data.buffer = NULL; + } + } + else + { + _net_nfc_util_free_mem(resp_detail); + res--; + } + } + else + { + resp_msg->detail_message = resp_detail; + resp_detail->target_info_values.buffer = NULL; + } + } + if (res == 0) + { + _net_nfc_util_free_mem(resp_msg); + return NULL; + } + } + break; + + case NET_NFC_MESSAGE_GET_CURRENT_TAG_INFO : + { + net_nfc_response_get_current_tag_info_t *resp_detail = NULL; + int res = 0; + res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_get_current_tag_info_t)); + if (res == 1) + { + if (resp_detail->target_info_values.length > 0) + { + res += __net_nfc_client_read_util((void **)&(resp_detail->target_info_values.buffer), resp_detail->target_info_values.length); + if (res == 2) + { + if (resp_detail->raw_data.length > 0) + { + res += __net_nfc_client_read_util((void **)&(resp_detail->raw_data.buffer), resp_detail->raw_data.length); + if (res == 3) + { + resp_msg->detail_message = resp_detail; + } + else + { + _net_nfc_util_free_mem(resp_detail); + res--; + } + } + else + { + resp_msg->detail_message = resp_detail; + resp_detail->raw_data.buffer = NULL; + } + } + else + { + _net_nfc_util_free_mem(resp_detail); + res--; + } + } + else + { + resp_msg->detail_message = resp_detail; + resp_detail->target_info_values.buffer = NULL; + } + } + if (res == 0) + { + _net_nfc_util_free_mem(resp_msg); + return NULL; + } + } + break; + + case NET_NFC_MESSAGE_SE_START_TRANSACTION : + case NET_NFC_MESSAGE_SE_END_TRANSACTION : + case NET_NFC_MESSAGE_SE_TYPE_TRANSACTION : + case NET_NFC_MESSAGE_SE_CONNECTIVITY : + case NET_NFC_MESSAGE_SE_FIELD_ON : + case NET_NFC_MESSAGE_SE_FIELD_OFF : + { + net_nfc_response_se_event_t *resp_detail = NULL; + int res = 0; + res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_se_event_t)); + if (res == 1) + { + if (resp_detail->aid.length > 0) + { + res += __net_nfc_client_read_util((void **)&(resp_detail->aid.buffer), resp_detail->aid.length); + if (res == 2) + { + if (resp_detail->param.length > 0) + { + res += __net_nfc_client_read_util((void **)&(resp_detail->param.buffer), resp_detail->param.length); + if (res == 3) + { + resp_msg->detail_message = resp_detail; + } + else + { + _net_nfc_util_free_mem(resp_detail); + res--; + } + } + else + { + resp_msg->detail_message = resp_detail; + resp_detail->param.buffer = NULL; + } + } + else + { + _net_nfc_util_free_mem(resp_detail); + res--; + } + } + else + { + resp_msg->detail_message = resp_detail; + resp_detail->aid.buffer = NULL; + } + } + if (res == 0) + { + _net_nfc_util_free_mem(resp_msg); + return NULL; + } + } + break; + + case NET_NFC_MESSAGE_TRANSCEIVE : + { + net_nfc_response_transceive_t *resp_detail = NULL; + int res = 0; + res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_transceive_t)); + if (res == 1) + { + if (resp_detail->data.length > 0) + { + res += __net_nfc_client_read_util((void **)&(resp_detail->data.buffer), resp_detail->data.length); + if (res == 2) + { + resp_msg->detail_message = resp_detail; + } + else + { + _net_nfc_util_free_mem(resp_detail); + res--; + } + } + else + { + resp_msg->detail_message = resp_detail; + resp_detail->data.buffer = NULL; + } + } + if (res == 0) + { + _net_nfc_util_free_mem(resp_msg); + return NULL; + } + } + break; + + case NET_NFC_MESSAGE_READ_NDEF : + { + + net_nfc_response_read_ndef_t *resp_detail = NULL; + int res = 0; + res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_read_ndef_t)); + if (res == 1) + { + if (resp_detail->data.length > 0) + { + res += __net_nfc_client_read_util((void **)&(resp_detail->data.buffer), resp_detail->data.length); + if (res == 2) + { + resp_msg->detail_message = resp_detail; + } + else + { + _net_nfc_util_free_mem(resp_detail); + res--; + } + } + else + { + resp_msg->detail_message = resp_detail; + resp_detail->data.buffer = NULL; + } + } + if (res == 0) + { + _net_nfc_util_free_mem(resp_msg); + return NULL; + } + } + break; + + case NET_NFC_MESSAGE_WRITE_NDEF : + { + net_nfc_response_write_ndef_t *resp_detail = NULL; + int res = 0; + res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_write_ndef_t)); + if (res != 1) + { + _net_nfc_util_free_mem(resp_msg); + return NULL; + } + resp_msg->detail_message = resp_detail; + } + break; + + case NET_NFC_MESSAGE_SIM_TEST : + { + net_nfc_response_test_t *resp_detail = NULL; + int res = 0; + + DEBUG_CLIENT_MSG("message from server NET_NFC_MESSAGE_SIM_TEST"); + + res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_test_t)); + if (res != 1) + { + _net_nfc_util_free_mem(resp_msg); + return NULL; + } + resp_msg->detail_message = resp_detail; + } + break; + + case NET_NFC_MESSAGE_PRBS_TEST : + { + net_nfc_response_test_t *resp_detail = NULL; + int res = 0; + + DEBUG_CLIENT_MSG("message from server NET_NFC_MESSAGE_PRBS_TEST"); + + res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_test_t)); + if (res != 1) + { + _net_nfc_util_free_mem(resp_msg); + return NULL; + } + resp_msg->detail_message = resp_detail; + } + break; + + case NET_NFC_MESSAGE_SET_EEDATA : + { + net_nfc_response_test_t *resp_detail = NULL; + int res = 0; + + DEBUG_CLIENT_MSG("message from server NET_NFC_MESSAGE_SET_EEDATA"); + + res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_test_t)); + if (res != 1) + { + _net_nfc_util_free_mem(resp_msg); + return NULL; + } + resp_msg->detail_message = resp_detail; + } + break; + + case NET_NFC_MESSAGE_GET_FIRMWARE_VERSION : + { + net_nfc_response_firmware_version_t *resp_detail = NULL; + + DEBUG_CLIENT_MSG("message from server NET_NFC_MESSAGE_GET_FIRMWARE_VERSION"); + + if (__net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_firmware_version_t)) > 0) + { + if (__net_nfc_client_read_util((void **)&(resp_detail->data.buffer), resp_detail->data.length) > 0) + { + resp_msg->detail_message = resp_detail; + } + else + { + _net_nfc_util_free_mem(resp_msg); + _net_nfc_util_free_mem(resp_detail); + return NULL; + } + } + else + { + _net_nfc_util_free_mem(resp_msg); + return NULL; + } + } + break; + + case NET_NFC_MESSAGE_NOTIFY : + { + net_nfc_response_notify_t *resp_detail = NULL; + int res = 0; + res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_notify_t)); + if (res != 1) + { + _net_nfc_util_free_mem(resp_msg); + return NULL; + } + resp_msg->detail_message = resp_detail; + } + break; + case NET_NFC_MESSAGE_TAG_DETACHED : + { + net_nfc_response_target_detached_t *resp_detail = NULL; + int res = 0; + res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_target_detached_t)); + if (res != 1) + { + _net_nfc_util_free_mem(resp_msg); + return NULL; + } + resp_msg->detail_message = resp_detail; + } + break; + + case NET_NFC_MESSAGE_FORMAT_NDEF : + { + + net_nfc_response_format_ndef_t *resp_detail = NULL; + int res = 0; + res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_format_ndef_t)); + if (res != 1) + { + _net_nfc_util_free_mem(resp_msg); + return NULL; + } + resp_msg->detail_message = resp_detail; + + } + break; + + case NET_NFC_MESSAGE_LLCP_DISCOVERED : + { + net_nfc_response_llcp_discovered_t *resp_detail = NULL; + int res = 0; + res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_llcp_discovered_t)); + if (res == 1) + { + if (resp_detail->target_info_values.length > 0) + { + res += __net_nfc_client_read_util((void **)&(resp_detail->target_info_values.buffer), resp_detail->target_info_values.length); + if (res == 2) + { + resp_msg->detail_message = resp_detail; + } + else + { + _net_nfc_util_free_mem(resp_detail); + res--; + } + } + else + { + resp_msg->detail_message = resp_detail; + resp_detail->target_info_values.buffer = NULL; + } + } + if (res == 0) + { + _net_nfc_util_free_mem(resp_msg); + return NULL; + } + } + break; + + case NET_NFC_MESSAGE_P2P_DETACHED : + { + net_nfc_response_llcp_detached_t *resp_detail = NULL; + int res = 0; + res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_llcp_detached_t)); + if (res != 1) + { + _net_nfc_util_free_mem(resp_msg); + return NULL; + } + resp_msg->detail_message = resp_detail; + } + break; + + case NET_NFC_MESSAGE_LLCP_LISTEN : + { + net_nfc_response_listen_socket_t *resp_detail = NULL; + int res = 0; + res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_listen_socket_t)); + if (res != 1) + { + _net_nfc_util_free_mem(resp_msg); + return NULL; + } + resp_msg->detail_message = resp_detail; + + } + break; + case NET_NFC_MESSAGE_LLCP_CONNECT : + { + net_nfc_response_connect_socket_t *resp_detail = NULL; + int res = 0; + res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_connect_socket_t)); + if (res != 1) + { + _net_nfc_util_free_mem(resp_msg); + return NULL; + } + resp_msg->detail_message = resp_detail; + + } + break; + case NET_NFC_MESSAGE_LLCP_CONNECT_SAP : + { + net_nfc_response_connect_sap_socket_t *resp_detail = NULL; + int res = 0; + res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_connect_sap_socket_t)); + if (res != 1) + { + _net_nfc_util_free_mem(resp_msg); + return NULL; + } + resp_msg->detail_message = resp_detail; + + } + break; + case NET_NFC_MESSAGE_LLCP_SEND : + { + net_nfc_response_send_socket_t *resp_detail = NULL; + int res = 0; + res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_send_socket_t)); + if (res != 1) + { + _net_nfc_util_free_mem(resp_msg); + return NULL; + } + resp_msg->detail_message = resp_detail; + } + break; + + case NET_NFC_MESSAGE_LLCP_RECEIVE : + { + net_nfc_response_receive_socket_t *resp_detail = NULL; + int res = 0; + res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_receive_socket_t)); + if (res == 1) + { + + if (resp_detail->data.length > 0) + { + res += __net_nfc_client_read_util((void **)&(resp_detail->data.buffer), resp_detail->data.length); + } + if (res == 2) + { + resp_msg->detail_message = resp_detail; + } + else + { + _net_nfc_util_free_mem(resp_detail); + res--; + } + } + else + { + resp_msg->detail_message = resp_detail; + resp_detail->data.buffer = NULL; + } + } + break; + + case NET_NFC_MESSAGE_P2P_RECEIVE : + { + net_nfc_response_p2p_receive_t *resp_detail = NULL; + int res = 0; + res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_p2p_receive_t)); + if (res == 1) + { + + if (resp_detail->data.length > 0) + { + res += __net_nfc_client_read_util((void **)&(resp_detail->data.buffer), resp_detail->data.length); + } + if (res == 2) + { + resp_msg->detail_message = resp_detail; + } + else + { + _net_nfc_util_free_mem(resp_detail); + res--; + } + } + else + { + resp_msg->detail_message = resp_detail; + resp_detail->data.buffer = NULL; + } + } + break; + + case NET_NFC_MESSAGE_SERVICE_LLCP_CLOSE : + { + net_nfc_response_close_socket_t *resp_detail = NULL; + int res = 0; + res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_close_socket_t)); + if (res != 1) + { + _net_nfc_util_free_mem(resp_msg); + return NULL; + } + resp_msg->detail_message = resp_detail; + } + break; + case NET_NFC_MESSAGE_LLCP_DISCONNECT : + { + net_nfc_response_disconnect_socket_t *resp_detail = NULL; + int res = 0; + res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_disconnect_socket_t)); + if (res != 1) + { + _net_nfc_util_free_mem(resp_msg); + return NULL; + } + resp_msg->detail_message = resp_detail; + } + break; + + case NET_NFC_MESSAGE_LLCP_CONFIG : + { + net_nfc_response_config_llcp_t *resp_detail = NULL; + int res = 0; + res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_config_llcp_t)); + if (res != 1) + { + _net_nfc_util_free_mem(resp_msg); + return NULL; + } + resp_msg->detail_message = resp_detail; + } + break; + + case NET_NFC_MESSAGE_LLCP_ERROR : + { + net_nfc_response_llcp_socket_error_t *resp_detail = NULL; + int res = 0; + res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_llcp_socket_error_t)); + if (res != 1) + { + _net_nfc_util_free_mem(resp_msg); + return NULL; + } + resp_msg->detail_message = resp_detail; + } + break; + + case NET_NFC_MESSAGE_LLCP_ACCEPTED : + { + net_nfc_response_incomming_llcp_t *resp_detail = NULL; + int res = 0; + res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_incomming_llcp_t)); + if (res != 1) + { + _net_nfc_util_free_mem(resp_msg); + return NULL; + } + resp_msg->detail_message = resp_detail; + } + break; + + case NET_NFC_MESSAGE_P2P_DISCOVERED : + { + net_nfc_response_p2p_discovered_t *resp_detail = NULL; + int res = 0; + + res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_p2p_discovered_t)); + if (res != 1) + { + _net_nfc_util_free_mem(resp_msg); + return NULL; + } + resp_msg->detail_message = resp_detail; + } + break; + + case NET_NFC_MESSAGE_P2P_SEND : + { + net_nfc_response_p2p_send_t *resp_detail = NULL; + int res = 0; + + res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_p2p_send_t)); + if (res != 1) + { + _net_nfc_util_free_mem(resp_msg); + return NULL; + } + resp_msg->detail_message = resp_detail; + } + break; + + case NET_NFC_MESSAGE_CONNECTION_HANDOVER : + { + net_nfc_response_connection_handover_t *resp_detail = NULL; + int res = 0; + + DEBUG_CLIENT_MSG("NET_NFC_MESSAGE_CONNECTION_HANDOVER"); + res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_connection_handover_t)); + + if (res == 1) + { + if (resp_detail->data.length > 0) + { + res += __net_nfc_client_read_util((void **)&(resp_detail->data.buffer), resp_detail->data.length); + if (res < 2) + { + DEBUG_ERR_MSG("__net_nfc_client_read_util failed. res [%d]", res); + _net_nfc_util_free_mem(resp_detail); + _net_nfc_util_free_mem(resp_msg); + return NULL; + } + } + } + else + { + DEBUG_ERR_MSG("__net_nfc_client_read_util failed. res [%d]", res); + _net_nfc_util_free_mem(resp_msg); + return NULL; + } + + resp_msg->detail_message = resp_detail; + } + break; + + case NET_NFC_MESSAGE_IS_TAG_CONNECTED : + { + net_nfc_response_is_tag_connected_t *resp_detail = NULL; + int res = 0; + res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_is_tag_connected_t)); + if (res != 1) + { + _net_nfc_util_free_mem(resp_msg); + return NULL; + } + resp_msg->detail_message = resp_detail; + } + break; + + case NET_NFC_MESSAGE_GET_CURRENT_TARGET_HANDLE : + { + net_nfc_response_get_current_target_handle_t *resp_detail = NULL; + int res = 0; + res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_get_current_target_handle_t)); + if (res != 1) + { + _net_nfc_util_free_mem(resp_msg); + return NULL; + } + resp_msg->detail_message = resp_detail; + + } + break; + + case NET_NFC_MESSAGE_SERVICE_INIT : + { + net_nfc_response_test_t *resp_detail = NULL; + int res = 0; + + DEBUG_CLIENT_MSG("Client Receive the NET_NFC_MESSAGE_SERVICE_INIT"); + + res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_test_t)); + if (res != 1) + { + _net_nfc_util_free_mem(resp_msg); + return NULL; + } + resp_msg->detail_message = resp_detail; + + } + break; + + case NET_NFC_MESSAGE_SERVICE_DEINIT : + { + net_nfc_response_test_t *resp_detail = NULL; + int res = 0; + + DEBUG_CLIENT_MSG("Client Receive the NET_NFC_MESSAGE_SERVICE_DEINIT"); + + res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_test_t)); + if (res != 1) + { + _net_nfc_util_free_mem(resp_msg); + return NULL; + } + resp_msg->detail_message = resp_detail; + + } + break; + + default : + { + DEBUG_CLIENT_MSG("Currently NOT supported RESP TYPE = [%d]", resp_msg->response_type); + _net_nfc_util_free_mem(resp_msg); + return NULL; + } + + } + + return resp_msg; +} + +bool __net_nfc_client_send_msg(void *message, int length) +{ + bool result = (send(g_client_sock_fd, (void *)message, length, MSG_NOSIGNAL) > 0); + + if (result == false) + { + uint8_t buf[1024] = { 0x00, }; + DEBUG_ERR_MSG("send failed : %s", strerror_r(errno, (char *)buf, sizeof(buf))); + } + + return result; +} + +static char *cookies = NULL; +static int cookies_size = 0; + +void _net_nfc_client_set_cookies(const char *cookie, size_t size) +{ + if (cookie != NULL && size > 0) + { + _net_nfc_util_alloc_mem(cookies, size); + + memcpy(cookies, cookie, size); + cookies_size = size; + } +} + +void _net_nfc_client_free_cookies(void) +{ + _net_nfc_util_free_mem(cookies); + cookies_size = 0; +} + +static net_nfc_error_e _send_request(net_nfc_request_msg_t *msg, va_list list) +{ + uint8_t *send_buffer = NULL; + int total_size = 0; + int written_size = 0; + + /* calc message length */ +#ifdef SECURITY_SERVER + total_size += (sizeof(cookies_size) + cookies_size); +#endif + total_size += msg->length; + total_size += net_nfc_util_get_va_list_length(list); + + _net_nfc_util_alloc_mem(send_buffer, total_size + sizeof(total_size)); + if (send_buffer == NULL) + { + return NET_NFC_ALLOC_FAIL; + } + + /* fill message */ + /* - total length */ + memcpy(send_buffer + written_size, &total_size, sizeof(total_size)); + written_size += sizeof(total_size); + +#ifdef SECURITY_SERVER + /* -- security server cookie */ + memcpy(send_buffer + written_size, &cookies_size, sizeof(cookies_size)); + written_size += sizeof(cookies_size); + + memcpy(send_buffer + written_size, cookies, cookies_size); + written_size += cookies_size; +#endif + + /* -- request message struct */ + memcpy(send_buffer + written_size, msg, msg->length); + written_size += msg->length; + + /* -- varient arguemts */ + written_size += net_nfc_util_fill_va_list(send_buffer + written_size, total_size + sizeof(total_size) - written_size, list); + + bool msg_result = __net_nfc_client_send_msg((void *)send_buffer, total_size + sizeof(total_size)); + + _net_nfc_util_free_mem(send_buffer); + sleep(0); + + if (msg_result) + { + DEBUG_MSG(">>>>> TO SERVER >>>>> (msg [%d], length [%d])", msg->request_type, total_size); + return NET_NFC_OK; + } + else + { + return NET_NFC_IPC_FAIL; + } +} + +net_nfc_error_e net_nfc_client_send_reqeust(net_nfc_request_msg_t *msg, ...) +{ + va_list list; + net_nfc_error_e result = NET_NFC_OK; + + va_start(list, msg); + + net_nfc_client_ipc_lock(); + + result = _send_request(msg, list); + + net_nfc_client_ipc_unlock(); + + va_end(list); + + return result; +} + +net_nfc_error_e net_nfc_client_send_reqeust_sync(net_nfc_request_msg_t *msg, ...) +{ + va_list list; + net_nfc_error_e result = NET_NFC_OK; + + net_nfc_client_prepare_sync_call(msg); + + va_start(list, msg); + + result = _send_request(msg, list); + + va_end(list); + + if (result == NET_NFC_OK) + { + result = net_nfc_client_wait_sync_call(0); + } + net_nfc_client_post_sync_call(); + + return result; +} + +net_nfc_error_e _net_nfc_client_register_cb(net_nfc_response_cb cb) +{ + if (cb == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + pthread_mutex_lock(&cb_lock); + client_cb = cb; + pthread_mutex_unlock(&cb_lock); + + return NET_NFC_OK; +} + +net_nfc_error_e _net_nfc_client_unregister_cb(void) +{ + if (client_cb == NULL) + { + return NET_NFC_NOT_REGISTERED; + } + + pthread_mutex_lock(&cb_lock); + client_cb = NULL; + pthread_mutex_unlock(&cb_lock); + + return NET_NFC_OK; +} + diff --git a/src/clientlib/net_nfc_client_llcp.c b/src/clientlib/net_nfc_client_llcp.c new file mode 100755 index 0000000..d983af9 --- /dev/null +++ b/src/clientlib/net_nfc_client_llcp.c @@ -0,0 +1,1083 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include +#include + +#include "net_nfc_llcp.h" +#include "net_nfc_typedef_private.h" +#include "net_nfc_util_private.h" +#include "net_nfc_debug_private.h" +#include "net_nfc_client_ipc_private.h" + +#ifndef NET_NFC_EXPORT_API +#define NET_NFC_EXPORT_API __attribute__((visibility("default"))) +#endif + +GList * socket_list = NULL; + +/* + Concept of the llcp_lock + 1. this lock protects only between client thread (these are calling llcp apis) and callback thread queue (=dispatcher thread) + 2. dispatcher thread is always serial it does not have to protect itself. + 3. all internal function for example __free_socket_info, __socket_equal_to are used only inside of this file + (there is no way to access from client api) thread safe. + 4. if the internal function calles from other thread (or changed to public) then you should consider use lock +*/ +static pthread_mutex_t llcp_lock = PTHREAD_MUTEX_INITIALIZER; + +/* to share client info */ +unsigned int socket_handle = 0; /* to generate client socket handle */ +static net_nfc_target_handle_s * current_target = NULL; + +static net_nfc_llcp_config_info_s local_config = { 128, 1, 10, 0 }; +static net_nfc_llcp_config_info_s remote_config = { 128, 1, 10, 0 }; + +/* =============================================================== */ +/* Socket info util */ + +static void __free_socket_info(net_nfc_llcp_internal_socket_s * data) +{ + net_nfc_llcp_internal_socket_s * socket_info = (net_nfc_llcp_internal_socket_s *)data; + + if (socket_info == NULL) + return; + _net_nfc_util_free_mem(socket_info->service_name); + _net_nfc_util_free_mem(socket_info); +} + +static int __socket_equal_to(gconstpointer key1, gconstpointer key2) +{ + net_nfc_llcp_internal_socket_s * arg1 = (net_nfc_llcp_internal_socket_s *)key1; + net_nfc_llcp_internal_socket_s * arg2 = (net_nfc_llcp_internal_socket_s *)key2; + + if (arg1->client_socket < arg2->client_socket) + { + return -1; + } + else if (arg1->client_socket > arg2->client_socket) + { + return 1; + } + else + { + return 0; + } +} + +net_nfc_llcp_internal_socket_s * _find_internal_socket_info(net_nfc_llcp_socket_t socket) +{ + net_nfc_llcp_internal_socket_s * inter_socket = NULL; + net_nfc_llcp_internal_socket_s temp = { 0 }; + GList * found = NULL; + + DEBUG_CLIENT_MSG("Socket info search requested with #[ %d ]", socket); + + temp.client_socket = socket; + + if (socket_list != NULL) + { + found = g_list_find_custom(socket_list, &temp, __socket_equal_to); + } + + if (NULL == found) + { + DEBUG_CLIENT_MSG("ERROR DATA IS NOT FOUND"); + return NULL; + } + else + { + DEBUG_CLIENT_MSG("socket_info is found address [%p]", found->data); + inter_socket = (net_nfc_llcp_internal_socket_s *)found->data; + } + + return inter_socket; +} + +static int __socket_equal_to_by_oal(gconstpointer key1, gconstpointer key2) +{ + net_nfc_llcp_internal_socket_s * arg1 = (net_nfc_llcp_internal_socket_s *)key1; + net_nfc_llcp_internal_socket_s * arg2 = (net_nfc_llcp_internal_socket_s *)key2; + + if (arg1->oal_socket < arg2->oal_socket) + { + return -1; + } + else if (arg1->oal_socket > arg2->oal_socket) + { + return 1; + } + else + { + return 0; + } +} + +static void __socket_foreach(gpointer data, gpointer user_data) +{ + __free_socket_info((net_nfc_llcp_internal_socket_s *)data); +} + +void _net_nfc_llcp_close_all_socket() +{ + pthread_mutex_lock(&llcp_lock); + + if (socket_list != NULL) + { + g_list_foreach(socket_list, __socket_foreach, NULL); + g_list_free(socket_list); + } + + socket_list = NULL; + + pthread_mutex_unlock(&llcp_lock); +} + +net_nfc_llcp_internal_socket_s * _find_internal_socket_info_by_oal_socket(net_nfc_llcp_socket_t socket) +{ + net_nfc_llcp_internal_socket_s * inter_socket = NULL; + net_nfc_llcp_internal_socket_s temp = { 0 }; + GList * found = NULL; + + temp.oal_socket = socket; + + DEBUG_CLIENT_MSG("search by oal socket is called socket[ %d ] ", socket); + + if (socket_list != NULL) + { + found = g_list_find_custom(socket_list, &temp, __socket_equal_to_by_oal); + } + + if (NULL == found) + { + DEBUG_CLIENT_MSG("ERROR DATA IS NOT FOUND"); + return NULL; + } + else + { + inter_socket = (net_nfc_llcp_internal_socket_s *)found->data; + DEBUG_CLIENT_MSG("oal socket_info is found address [%p]", inter_socket); + } + + return inter_socket; +} + +void _remove_internal_socket(net_nfc_llcp_internal_socket_s * data) +{ + pthread_mutex_lock(&llcp_lock); + + if (data == NULL) + { + pthread_mutex_unlock(&llcp_lock); + return; + } + + if (socket_list != NULL) + { + + socket_list = g_list_remove(socket_list, data); + } + __free_socket_info(data); + + pthread_mutex_unlock(&llcp_lock); +} + +void _append_internal_socket(net_nfc_llcp_internal_socket_s * data) +{ + pthread_mutex_lock(&llcp_lock); + + if (data != NULL) + { + socket_list = g_list_append(socket_list, data); + } + + pthread_mutex_unlock(&llcp_lock); +} + +/* =============================================================== */ +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_create_llcp_socket(net_nfc_llcp_socket_t * socket, net_nfc_llcp_socket_option_h options) +{ + + net_nfc_llcp_internal_socket_s * socket_data = NULL; + net_nfc_llcp_socket_option_s * strct_options = (net_nfc_llcp_socket_option_s *)options; + net_nfc_llcp_socket_option_s default_option = { + 128, 1, NET_NFC_LLCP_SOCKET_TYPE_CONNECTIONORIENTED + }; + + DEBUG_CLIENT_MSG("function %s is called", __func__); + + if (socket == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + if (options == NULL) + { + strct_options = &default_option; + } + + _net_nfc_util_alloc_mem(socket_data, sizeof(net_nfc_llcp_internal_socket_s)); + + socket_data->client_socket = socket_handle++; + socket_data->miu = strct_options->miu; + socket_data->rw = strct_options->rw; + socket_data->type = strct_options->type; + socket_data->device_id = current_target; + socket_data->close_requested = false; + + _append_internal_socket(socket_data); + + *socket = socket_data->client_socket; + + return NET_NFC_OK; + +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_set_llcp_socket_callback(net_nfc_llcp_socket_t socket, net_nfc_llcp_socket_cb cb, void * user_param) +{ + net_nfc_llcp_internal_socket_s * socket_data = NULL; + + if (cb == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + pthread_mutex_lock(&llcp_lock); + + socket_data = _find_internal_socket_info(socket); + + if (socket_data == NULL) + { + pthread_mutex_unlock(&llcp_lock); + return NET_NFC_LLCP_INVALID_SOCKET; + } + + socket_data->cb = cb; + socket_data->register_param = user_param; + + pthread_mutex_unlock(&llcp_lock); + + return NET_NFC_OK; +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_unset_llcp_socket_callback(net_nfc_llcp_socket_t socket) +{ + pthread_mutex_lock(&llcp_lock); + net_nfc_llcp_internal_socket_s * socket_data = _find_internal_socket_info(socket); + + if (socket_data == NULL) + { + pthread_mutex_unlock(&llcp_lock); + return NET_NFC_LLCP_INVALID_SOCKET; + } + + if (socket_data->cb == NULL) + { + pthread_mutex_unlock(&llcp_lock); + return NET_NFC_NOT_REGISTERED; + } + + socket_data->cb = NULL; + pthread_mutex_unlock(&llcp_lock); + + return NET_NFC_OK; +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_listen_llcp(net_nfc_llcp_socket_t socket, const char *service_name, sap_t sap, void *trans_param) +{ + net_nfc_llcp_internal_socket_s *psocket_data = NULL; + net_nfc_request_listen_socket_t *request = NULL; + net_nfc_error_e ret; + int srv_name_count = 0; + uint32_t length = 0; + + DEBUG_CLIENT_MSG("function %s is called. socket#[ %d ]", __func__, socket); + + if (service_name == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + pthread_mutex_lock(&llcp_lock); + psocket_data = _find_internal_socket_info(socket); + if (psocket_data == NULL) + { + pthread_mutex_unlock(&llcp_lock); + return NET_NFC_LLCP_INVALID_SOCKET; + } + + srv_name_count = strlen((char *)service_name) + 1; + + _net_nfc_util_alloc_mem(psocket_data->service_name, srv_name_count); + if (psocket_data->service_name == NULL) + { + pthread_mutex_unlock(&llcp_lock); + return NET_NFC_ALLOC_FAIL; + } + strncpy((char *)psocket_data->service_name, (char *)service_name, srv_name_count); + psocket_data->sap = sap; + + /* fill request message */ + length = sizeof(net_nfc_request_listen_socket_t) + srv_name_count; + + _net_nfc_util_alloc_mem(request, length); + if (request == NULL) + { + _net_nfc_util_free_mem(psocket_data->service_name); + pthread_mutex_unlock(&llcp_lock); + return NET_NFC_ALLOC_FAIL; + } + + request->length = length; + request->request_type = NET_NFC_MESSAGE_LLCP_LISTEN; + request->handle = current_target; + request->miu = psocket_data->miu; + request->oal_socket = psocket_data->oal_socket; + request->rw = psocket_data->rw; + request->sap = psocket_data->sap; + request->type = psocket_data->type; + request->client_socket = psocket_data->client_socket; + request->trans_param = trans_param; + + request->service_name.length = srv_name_count; + memcpy(&request->service_name.buffer, psocket_data->service_name, request->service_name.length); + + ret = net_nfc_client_send_reqeust((net_nfc_request_msg_t *)request, NULL); + + _net_nfc_util_free_mem(request); + + pthread_mutex_unlock(&llcp_lock); + + return ret; +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_disconnect_llcp(net_nfc_llcp_socket_t socket, void * trans_param) +{ + net_nfc_llcp_internal_socket_s *psocket_data; + net_nfc_request_disconnect_socket_t request = { 0, }; + net_nfc_error_e ret; + + DEBUG_CLIENT_MSG("function %s is called. socket#[ %d ]", __func__, socket); + + pthread_mutex_lock(&llcp_lock); + psocket_data = _find_internal_socket_info(socket); + if (psocket_data == NULL) + { + pthread_mutex_unlock(&llcp_lock); + return NET_NFC_LLCP_INVALID_SOCKET; + } + + request.length = sizeof(net_nfc_request_disconnect_socket_t); + request.request_type = NET_NFC_MESSAGE_LLCP_DISCONNECT; + request.handle = current_target; + request.oal_socket = psocket_data->oal_socket; + request.client_socket = psocket_data->client_socket; + request.trans_param = trans_param; + + ret = net_nfc_client_send_reqeust((net_nfc_request_msg_t *)&request, NULL); + + pthread_mutex_unlock(&llcp_lock); + + return ret; +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_close_llcp_socket(net_nfc_llcp_socket_t socket, void * trans_param) +{ + net_nfc_llcp_internal_socket_s *psocket_data = NULL; + net_nfc_request_close_socket_t request = { 0, }; + net_nfc_error_e ret; + + DEBUG_CLIENT_MSG("function %s is called. socket#[ %d ]", __func__, socket); + + pthread_mutex_lock(&llcp_lock); + psocket_data = _find_internal_socket_info(socket); + if (psocket_data == NULL) + { + pthread_mutex_unlock(&llcp_lock); + return NET_NFC_LLCP_INVALID_SOCKET; + } + + if (psocket_data->close_requested) + { + pthread_mutex_unlock(&llcp_lock); + return NET_NFC_OK; + } + psocket_data->close_requested = true; + + request.length = sizeof(net_nfc_request_close_socket_t); + request.request_type = NET_NFC_MESSAGE_SERVICE_LLCP_CLOSE; + request.handle = current_target; + request.oal_socket = psocket_data->oal_socket; + request.client_socket = psocket_data->client_socket; + request.trans_param = trans_param; + + ret = net_nfc_client_send_reqeust((net_nfc_request_msg_t *)&request, NULL); + + _remove_internal_socket(psocket_data); + + pthread_mutex_unlock(&llcp_lock); + + return ret; +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_send_llcp(net_nfc_llcp_socket_t socket, data_h data, void * trans_param) +{ + net_nfc_llcp_internal_socket_s *psocket_data; + net_nfc_request_send_socket_t *request = NULL; + data_s *data_private = (data_s *)data; + net_nfc_error_e ret; + uint32_t length = 0; + + if (data_private == NULL || data_private->buffer == NULL || data_private->length == 0) + { + return NET_NFC_NULL_PARAMETER; + } + + DEBUG_CLIENT_MSG("function %s is called. socket#[ %d ]", __func__, socket); + + pthread_mutex_lock(&llcp_lock); + psocket_data = _find_internal_socket_info(socket); + if (psocket_data == NULL) + { + pthread_mutex_unlock(&llcp_lock); + return NET_NFC_LLCP_INVALID_SOCKET; + } + + /* fill request message */ + length = sizeof(net_nfc_request_send_socket_t) + data_private->length; + + _net_nfc_util_alloc_mem(request, length); + if (request == NULL) + { + pthread_mutex_unlock(&llcp_lock); + return NET_NFC_ALLOC_FAIL; + } + + request->length = length; + request->request_type = NET_NFC_MESSAGE_LLCP_SEND; + request->handle = current_target; + request->oal_socket = psocket_data->oal_socket; + request->client_socket = psocket_data->client_socket; + request->trans_param = trans_param; + + request->data.length = data_private->length; + memcpy(&request->data.buffer, data_private->buffer, request->data.length); + + ret = net_nfc_client_send_reqeust((net_nfc_request_msg_t *)request, NULL); + + _net_nfc_util_free_mem(request); + + pthread_mutex_unlock(&llcp_lock); + + return ret; +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_receive_llcp(net_nfc_llcp_socket_t socket, size_t req_length, void * trans_param) +{ + net_nfc_llcp_internal_socket_s *psocket_data = NULL; + net_nfc_request_receive_socket_t request = { 0, }; + net_nfc_error_e ret; + + DEBUG_CLIENT_MSG("function %s is called. socket#[ %d ]", __func__, socket); + + pthread_mutex_lock(&llcp_lock); + + psocket_data = _find_internal_socket_info(socket); + if (psocket_data == NULL) + { + pthread_mutex_unlock(&llcp_lock); + return NET_NFC_LLCP_INVALID_SOCKET; + } + + request.length = sizeof(net_nfc_request_receive_socket_t); + request.request_type = NET_NFC_MESSAGE_LLCP_RECEIVE; + request.handle = current_target; + request.oal_socket = psocket_data->oal_socket; + request.client_socket = psocket_data->client_socket; + request.trans_param = trans_param; + request.req_length = req_length; + + ret = net_nfc_client_send_reqeust((net_nfc_request_msg_t *)&request, NULL); + + pthread_mutex_unlock(&llcp_lock); + + return ret; +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_send_to_llcp(net_nfc_llcp_socket_t socket, sap_t dsap, data_h data, void *trans_param) +{ + net_nfc_llcp_internal_socket_s *psocket_data = NULL; + net_nfc_request_send_to_socket_t *request = NULL; + data_s * data_private = (data_s *)data; + net_nfc_error_e ret; + uint32_t length = 0; + + if (data_private == NULL || data_private->buffer == NULL || data_private->length == 0) + { + return NET_NFC_NULL_PARAMETER; + } + + DEBUG_CLIENT_MSG("function %s is called. socket#[ %d ]", __func__, socket); + + pthread_mutex_lock(&llcp_lock); + psocket_data = _find_internal_socket_info(socket); + if (psocket_data == NULL) + { + pthread_mutex_unlock(&llcp_lock); + return NET_NFC_LLCP_INVALID_SOCKET; + } + + /* fill request message */ + length = sizeof(net_nfc_request_send_to_socket_t) + data_private->length; + + _net_nfc_util_alloc_mem(request, length); + if (request == NULL) + { + pthread_mutex_unlock(&llcp_lock); + return NET_NFC_ALLOC_FAIL; + } + + request->length = length; + request->request_type = NET_NFC_MESSAGE_LLCP_SEND_TO; + request->handle = current_target; + request->oal_socket = psocket_data->oal_socket; + request->client_socket = psocket_data->client_socket; + request->trans_param = trans_param; + + request->data.length = data_private->length; + memcpy(&request->data.buffer, data_private->buffer, request->data.length); + + ret = net_nfc_client_send_reqeust((net_nfc_request_msg_t *)request, NULL); + + _net_nfc_util_free_mem(request); + + pthread_mutex_unlock(&llcp_lock); + + return ret; +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_receive_from_llcp(net_nfc_llcp_socket_t socket, sap_t ssap, size_t req_length, void * trans_param) +{ + net_nfc_llcp_internal_socket_s *psocket_data = NULL; + net_nfc_request_receive_from_socket_t request = { 0, }; + net_nfc_error_e ret; + + DEBUG_CLIENT_MSG("function %s is called. socket#[ %d ]", __func__, socket); + + pthread_mutex_lock(&llcp_lock); + + psocket_data = _find_internal_socket_info(socket); + if (psocket_data == NULL) + { + pthread_mutex_unlock(&llcp_lock); + return NET_NFC_LLCP_INVALID_SOCKET; + } + + request.length = sizeof(net_nfc_request_receive_from_socket_t); + request.request_type = NET_NFC_MESSAGE_LLCP_RECEIVE_FROM; + request.handle = current_target; + request.oal_socket = psocket_data->oal_socket; + request.client_socket = psocket_data->client_socket; + request.trans_param = trans_param; + request.req_length = req_length; + + ret = net_nfc_client_send_reqeust((net_nfc_request_msg_t *)&request, NULL); + + pthread_mutex_unlock(&llcp_lock); + + return ret; +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_connect_llcp_with_sap(net_nfc_llcp_socket_t socket, sap_t sap, void * trans_param) +{ + net_nfc_llcp_internal_socket_s *psocket_data = NULL; + net_nfc_request_connect_sap_socket_t request = { 0, }; + net_nfc_error_e ret; + + DEBUG_CLIENT_MSG("function %s is called. socket#[ %d ]", __func__, socket); + + pthread_mutex_lock(&llcp_lock); + + psocket_data = _find_internal_socket_info(socket); + if (psocket_data == NULL) + { + pthread_mutex_unlock(&llcp_lock); + return NET_NFC_LLCP_INVALID_SOCKET; + } + + request.length = sizeof(net_nfc_request_connect_sap_socket_t); + request.request_type = NET_NFC_MESSAGE_LLCP_CONNECT_SAP; + request.handle = current_target; + request.oal_socket = psocket_data->oal_socket; + request.sap = sap; + request.client_socket = psocket_data->client_socket; + request.trans_param = trans_param; + request.miu = psocket_data->miu; + request.rw = psocket_data->rw; + + ret = net_nfc_client_send_reqeust((net_nfc_request_msg_t *)&request, NULL); + + pthread_mutex_unlock(&llcp_lock); + + return ret; +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_connect_llcp(net_nfc_llcp_socket_t socket, const char *service_name, void *trans_param) +{ + net_nfc_llcp_internal_socket_s *psocket_data = NULL; + net_nfc_request_connect_socket_t *request = NULL; + net_nfc_error_e ret; + uint32_t length = 0, svc_name_length = 0; + + DEBUG_CLIENT_MSG("function %s is called. socket#[ %d ]", __func__, socket); + + pthread_mutex_lock(&llcp_lock); + + psocket_data = _find_internal_socket_info(socket); + if (psocket_data == NULL) + { + pthread_mutex_unlock(&llcp_lock); + return NET_NFC_LLCP_INVALID_SOCKET; + } + + svc_name_length = strlen(service_name) + 1; + + /* fill request message */ + length = sizeof(net_nfc_request_connect_socket_t) + svc_name_length; + + _net_nfc_util_alloc_mem(request, length); + if (request == NULL) + { + pthread_mutex_unlock(&llcp_lock); + return NET_NFC_ALLOC_FAIL; + } + + request->length = length; + request->request_type = NET_NFC_MESSAGE_LLCP_CONNECT; + request->handle = current_target; + request->oal_socket = psocket_data->oal_socket; + request->client_socket = psocket_data->client_socket; + request->trans_param = trans_param; + request->miu = psocket_data->miu; + request->rw = psocket_data->rw; + + request->service_name.length = svc_name_length; + memcpy(&request->service_name.buffer, service_name, request->service_name.length); + + ret = net_nfc_client_send_reqeust((net_nfc_request_msg_t *)request, NULL); + + _net_nfc_util_free_mem(request); + + pthread_mutex_unlock(&llcp_lock); + + return ret; +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_llcp_local_configure(net_nfc_llcp_config_info_h * config) +{ + if (config == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + *config = (net_nfc_llcp_config_info_h)&local_config; + + return NET_NFC_OK; +} + +void _net_nfc_set_llcp_remote_configure(net_nfc_llcp_config_info_s * remote_data) +{ + if (remote_data == NULL) + { + DEBUG_CLIENT_MSG("recieved data is NULL"); + return; + } + remote_config.lto = remote_data->lto; + remote_config.wks = remote_data->wks; + remote_config.miu = remote_data->miu; + remote_config.option = remote_data->option; + +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_llcp_remote_configure(net_nfc_target_handle_h handle, net_nfc_llcp_config_info_h * config) +{ + if (config == NULL || handle == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + if (current_target == NULL || (net_nfc_target_handle_s*)handle != current_target) + { + return NET_NFC_INVALID_HANDLE; + } + + *config = (net_nfc_llcp_config_info_h)&remote_config; + + return NET_NFC_OK; +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_set_llcp_local_configure(net_nfc_llcp_config_info_h config, void * trans_param) +{ + net_nfc_request_config_llcp_t request = { 0, }; + net_nfc_error_e ret; + + DEBUG_CLIENT_MSG("function %s is called", __func__); + + if (config == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + request.length = sizeof(net_nfc_request_config_llcp_t); + request.request_type = NET_NFC_MESSAGE_LLCP_CONFIG; + memset(&request, 0x0, sizeof(net_nfc_request_config_llcp_t)); + memcpy(&local_config, config, sizeof(net_nfc_llcp_config_info_s)); + request.trans_param = trans_param; + memcpy(&(request.config), config, sizeof(net_nfc_llcp_config_info_s)); + + ret = net_nfc_client_send_reqeust((net_nfc_request_msg_t *)&request, NULL); + + return ret; +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_llcp_local_socket_option(net_nfc_llcp_socket_t socket, net_nfc_llcp_socket_option_h * info) +{ + net_nfc_llcp_internal_socket_s *psocket_data = NULL; + + DEBUG_CLIENT_MSG("function %s is called", __func__); + + psocket_data = _find_internal_socket_info(socket); + if (psocket_data == NULL) + return NET_NFC_LLCP_INVALID_SOCKET; + + *info = (net_nfc_llcp_socket_option_h)psocket_data; + + return NET_NFC_OK; +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_llcp_remote_socket_option(net_nfc_llcp_socket_t socket, net_nfc_llcp_socket_option_h * info) +{ + info = NULL; + return NET_NFC_OK; +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_create_llcp_socket_option(net_nfc_llcp_socket_option_h * option, uint16_t miu, uint8_t rw, net_nfc_socket_type_e type) +{ + if (option == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + if (miu < 128 || miu > 1152 || + rw < 1 || rw > 15 || + type < NET_NFC_LLCP_SOCKET_TYPE_CONNECTIONORIENTED || type > NET_NFC_LLCP_SOCKET_TYPE_CONNECTIONLESS) + { + return NET_NFC_OUT_OF_BOUND; + } + + net_nfc_llcp_socket_option_s * struct_option = NULL; + + _net_nfc_util_alloc_mem(struct_option, sizeof(net_nfc_llcp_socket_option_s)); + if (struct_option != NULL) + { + struct_option->miu = miu; + struct_option->rw = rw; + struct_option->type = type; + + *option = (net_nfc_llcp_socket_option_h)struct_option; + + return NET_NFC_OK; + } + else + { + return NET_NFC_ALLOC_FAIL; + } +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_create_llcp_socket_option_default(net_nfc_llcp_socket_option_h * option) +{ + return net_nfc_create_llcp_socket_option(option, 128, 1, NET_NFC_LLCP_SOCKET_TYPE_CONNECTIONORIENTED); +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_llcp_socket_option_miu(net_nfc_llcp_socket_option_h option, uint16_t * miu) +{ + if (option == NULL || miu == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + net_nfc_llcp_socket_option_s * struct_option = (net_nfc_llcp_socket_option_s *)option; + + *miu = struct_option->miu; + return NET_NFC_OK; +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_set_llcp_socket_option_miu(net_nfc_llcp_socket_option_h option, uint16_t miu) +{ + if (option == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + net_nfc_llcp_socket_option_s * struct_option = (net_nfc_llcp_socket_option_s *)option; + + struct_option->miu = miu; + return NET_NFC_OK; +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_llcp_socket_option_rw(net_nfc_llcp_socket_option_h option, uint8_t * rw) +{ + if (option == NULL || rw == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + net_nfc_llcp_socket_option_s * struct_option = (net_nfc_llcp_socket_option_s *)option; + + *rw = struct_option->rw; + return NET_NFC_OK; +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_set_llcp_socket_option_rw(net_nfc_llcp_socket_option_h option, uint8_t rw) +{ + if (option == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + net_nfc_llcp_socket_option_s * struct_option = (net_nfc_llcp_socket_option_s *)option; + + struct_option->rw = rw; + return NET_NFC_OK; +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_llcp_socket_option_type(net_nfc_llcp_socket_option_h option, net_nfc_socket_type_e * type) +{ + if (option == NULL || type == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + net_nfc_llcp_socket_option_s * struct_option = (net_nfc_llcp_socket_option_s *)option; + + *type = struct_option->type; + return NET_NFC_OK; +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_set_llcp_socket_option_type(net_nfc_llcp_socket_option_h option, net_nfc_socket_type_e type) +{ + if (option == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + net_nfc_llcp_socket_option_s * struct_option = (net_nfc_llcp_socket_option_s *)option; + + struct_option->type = type; + return NET_NFC_OK; +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_free_llcp_socket_option(net_nfc_llcp_socket_option_h option) +{ + if (option == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + _net_nfc_util_free_mem(option); + + return NET_NFC_OK; +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_create_llcp_configure(net_nfc_llcp_config_info_h * config, uint16_t miu, uint16_t wks, uint8_t lto, uint8_t option) +{ + if (config == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + net_nfc_llcp_config_info_s ** config_private = (net_nfc_llcp_config_info_s **)config; + + _net_nfc_util_alloc_mem(*config_private, sizeof (net_nfc_llcp_config_info_s)); + if (*config_private == NULL) + return NET_NFC_ALLOC_FAIL; + + (*config_private)->miu = miu; + (*config_private)->wks = wks; + (*config_private)->lto = lto; + (*config_private)->option = option; + + return NET_NFC_OK; +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_create_llcp_configure_default(net_nfc_llcp_config_info_h * config) +{ + return net_nfc_create_llcp_configure(config, 128, 1, 10, 0); +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_llcp_configure_miu(net_nfc_llcp_config_info_h config, uint16_t * miu) +{ + if (config == NULL || miu == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + net_nfc_llcp_config_info_s * config_private = (net_nfc_llcp_config_info_s *)config; + *miu = config_private->miu; + + return NET_NFC_OK; +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_llcp_configure_wks(net_nfc_llcp_config_info_h config, uint16_t * wks) +{ + if (config == NULL || wks == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + net_nfc_llcp_config_info_s * config_private = (net_nfc_llcp_config_info_s *)config; + *wks = config_private->wks; + + return NET_NFC_OK; +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_llcp_configure_lto(net_nfc_llcp_config_info_h config, uint8_t * lto) +{ + if (config == NULL || lto == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + net_nfc_llcp_config_info_s * config_private = (net_nfc_llcp_config_info_s *)config; + *lto = config_private->lto; + + return NET_NFC_OK; +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_llcp_configure_option(net_nfc_llcp_config_info_h config, uint8_t * option) +{ + if (config == NULL || option == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + net_nfc_llcp_config_info_s * config_private = (net_nfc_llcp_config_info_s *)config; + *option = config_private->option; + + return NET_NFC_OK; +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_set_llcp_configure_miu(net_nfc_llcp_config_info_h config, uint16_t miu) +{ + if (config == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + if (miu < 128 || miu > 1152) + { + return NET_NFC_OUT_OF_BOUND; + } + + net_nfc_llcp_config_info_s * config_private = (net_nfc_llcp_config_info_s *)config; + config_private->miu = miu; + + return NET_NFC_OK; +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_set_llcp_configure_wks(net_nfc_llcp_config_info_h config, uint16_t wks) +{ + if (config == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + net_nfc_llcp_config_info_s * config_private = (net_nfc_llcp_config_info_s *)config; + config_private->wks = wks; + + return NET_NFC_OK; +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_set_llcp_configure_lto(net_nfc_llcp_config_info_h config, uint8_t lto) +{ + if (config == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + net_nfc_llcp_config_info_s * config_private = (net_nfc_llcp_config_info_s *)config; + config_private->lto = lto; + + return NET_NFC_OK; +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_set_llcp_configure_option(net_nfc_llcp_config_info_h config, uint8_t option) +{ + if (config == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + net_nfc_llcp_config_info_s * config_private = (net_nfc_llcp_config_info_s *)config; + config_private->option = option; + + return NET_NFC_OK; +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_free_llcp_configure(net_nfc_llcp_config_info_h config) +{ + if (config == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + _net_nfc_util_free_mem(config); + return NET_NFC_OK; +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_current_target_handle(void *trans_param) +{ + net_nfc_error_e result = NET_NFC_OK; + net_nfc_request_get_current_target_handle_t request = { 0, }; + + request.length = sizeof(net_nfc_request_get_current_target_handle_t); + request.request_type = NET_NFC_MESSAGE_GET_CURRENT_TARGET_HANDLE; + request.trans_param = trans_param; + + result = net_nfc_client_send_reqeust((net_nfc_request_msg_t *)&request, NULL); + + return result; +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_current_target_handle_sync(net_nfc_target_handle_h *handle) +{ + net_nfc_error_e result = NET_NFC_OK; + net_nfc_request_get_current_target_handle_t request = { 0, }; + net_nfc_response_get_current_target_handle_t response = { 0, }; + + request.length = sizeof(net_nfc_request_get_current_target_handle_t); + request.request_type = NET_NFC_MESSAGE_GET_CURRENT_TARGET_HANDLE; + request.trans_param = (void *)&response; + + result = net_nfc_client_send_reqeust_sync((net_nfc_request_msg_t *)&request, NULL); + if (result == NET_NFC_OK) + { + *handle = (net_nfc_target_handle_h)response.handle; + result = response.result; + } + + return result; +} + +void _net_nfc_set_llcp_current_target_id(net_nfc_target_handle_s * handle) +{ + current_target = handle; +} diff --git a/src/clientlib/net_nfc_client_ndef_message.c b/src/clientlib/net_nfc_client_ndef_message.c new file mode 100644 index 0000000..74fabf9 --- /dev/null +++ b/src/clientlib/net_nfc_client_ndef_message.c @@ -0,0 +1,215 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "net_nfc_debug_private.h" +#include "net_nfc_util_private.h" +#include "net_nfc_util_ndef_message.h" + +#include "net_nfc_ndef_message.h" +#include "net_nfc.h" // to use net_nfc_data + + +#ifndef NET_NFC_MANAGER_DATA_PATH +#define NET_NFC_MANAGER_DATA_PATH "/opt/data/nfc-manager-daemon" +#endif + +#ifndef NET_NFC_MANAGER_DATA_PATH_MESSAGE +#define NET_NFC_MANAGER_DATA_PATH_MESSAGE "message" +#endif + +#ifndef NET_NFC_MANAGER_NDEF_FILE_NAME +#define NET_NFC_MANAGER_NDEF_FILE_NAME "ndef-message.txt" +#endif + + +#ifndef NET_NFC_EXPORT_API +#define NET_NFC_EXPORT_API __attribute__((visibility("default"))) +#endif + + +/* public functions */ +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_create_ndef_message (ndef_message_h* ndef_message) +{ + return net_nfc_util_create_ndef_message ((ndef_message_s **) ndef_message); +} + + + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_create_rawdata_from_ndef_message (ndef_message_h ndef_message, data_h* rawdata) +{ + if (ndef_message == NULL || rawdata == NULL){ + return NET_NFC_NULL_PARAMETER; + } + int count; + net_nfc_error_e result; + + result = net_nfc_get_ndef_message_byte_length (ndef_message,&count); + if (result != NET_NFC_OK){ + return result; + } + + result = net_nfc_create_data (rawdata ,NULL, count); + if (result != NET_NFC_OK) { + return result; + } + return net_nfc_util_convert_ndef_message_to_rawdata((ndef_message_s*)ndef_message, (data_s*)*rawdata); +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_create_ndef_message_from_rawdata (ndef_message_h* ndef_message, data_h rawdata) +{ + if (ndef_message == NULL || rawdata == NULL ){ + return NET_NFC_NULL_PARAMETER; + } + + net_nfc_error_e result; + result = net_nfc_create_ndef_message (ndef_message); + if (result != NET_NFC_OK){ + return result; + } + + return net_nfc_util_convert_rawdata_to_ndef_message((data_s*)rawdata, (ndef_message_s*)*ndef_message); +} + + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_ndef_message_byte_length(ndef_message_h ndef_message, int * length) +{ + if (ndef_message == NULL || length == NULL){ + return NET_NFC_NULL_PARAMETER; + } + + * length = net_nfc_util_get_ndef_message_length((ndef_message_s*)ndef_message); + return NET_NFC_OK; +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_append_record_to_ndef_message(ndef_message_h ndef_message, ndef_record_h record) +{ + if (ndef_message == NULL || record == NULL){ + return NET_NFC_NULL_PARAMETER; + } + + return net_nfc_util_append_record((ndef_message_s*)ndef_message, (ndef_record_s *)record); +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_free_ndef_message(ndef_message_h ndef_message) +{ + if (ndef_message == NULL){ + return NET_NFC_NULL_PARAMETER; + } + net_nfc_error_e error = net_nfc_util_free_ndef_message((ndef_message_s *)ndef_message); + if (error != NET_NFC_OK){ + return error; + } + return error; +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_ndef_message_record_count (ndef_message_h ndef_message, int * count) +{ + if (ndef_message == NULL || count == NULL){ + return NET_NFC_NULL_PARAMETER; + } + ndef_message_s * ndef_message_private = (ndef_message_s *)ndef_message; + + * count = ndef_message_private->recordCount; + + return NET_NFC_OK; +} + +NET_NFC_EXPORT_API void net_nfc_ndef_print_message (ndef_message_h ndef_message ) +{ + net_nfc_util_print_ndef_message ((ndef_message_s *)(ndef_message) ); +} + + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_search_record_by_type (ndef_message_h ndef_message, net_nfc_record_tnf_e tnf, data_h type, ndef_record_h* record) +{ + return net_nfc_util_search_record_by_type ((ndef_message_s*)ndef_message, tnf, (data_s *)type, (ndef_record_s**)record); +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_append_record_by_index (ndef_message_h ndef_message, int index, ndef_record_h record) +{ + return net_nfc_util_append_record_by_index ((ndef_message_s *) ndef_message, index, (ndef_record_s *) record); +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_record_by_index (ndef_message_h ndef_message, int index, ndef_record_h* record) +{ + return net_nfc_util_get_record_by_index ((ndef_message_s*) ndef_message, index, (ndef_record_s**) record); +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_remove_record_by_index (ndef_message_h ndef_message, int index) +{ + return net_nfc_util_remove_record_by_index ((ndef_message_s*)ndef_message, index); +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_retrieve_current_ndef_message(ndef_message_h* ndef_message) +{ + net_nfc_error_e result = NET_NFC_UNKNOWN_ERROR; + char file_path[1024] = { 0, }; + FILE *fp = NULL; + + if (ndef_message == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + snprintf(file_path, sizeof(file_path), "%s/%s/%s", NET_NFC_MANAGER_DATA_PATH, NET_NFC_MANAGER_DATA_PATH_MESSAGE, NET_NFC_MANAGER_NDEF_FILE_NAME); + + if ((fp = fopen(file_path, "r")) != NULL) + { + long int size = 0; + + /* rewind to start of file */ + fseek(fp, 0, SEEK_END); + size = ftell(fp); + fseek(fp, 0, SEEK_SET); + + DEBUG_CLIENT_MSG("message length = [%ld]", size); + + if (size > 0) + { + uint8_t *buffer = NULL; + + _net_nfc_util_alloc_mem(buffer, size); + if (buffer != NULL) + { + /* read fully */ + if ((size = fread(buffer, 1, size, fp)) > 0) + { + data_h data = NULL; + if ((result = net_nfc_create_data(&data, buffer, size)) == NET_NFC_OK) + { + result = net_nfc_create_ndef_message_from_rawdata(ndef_message, data); + + net_nfc_free_data(data); + } + } + + _net_nfc_util_free_mem(buffer); + } + } + else + { + result = NET_NFC_ALLOC_FAIL; + } + + fclose(fp); + } + else + { + result = NET_NFC_NO_NDEF_MESSAGE; + } + + return result; +} diff --git a/src/clientlib/net_nfc_client_ndef_message_handover.c b/src/clientlib/net_nfc_client_ndef_message_handover.c new file mode 100755 index 0000000..38735c0 --- /dev/null +++ b/src/clientlib/net_nfc_client_ndef_message_handover.c @@ -0,0 +1,162 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include "net_nfc_ndef_message_handover.h" + +#include "net_nfc_typedef_private.h" +#include "net_nfc_debug_private.h" +#include "net_nfc_util_private.h" +#include "net_nfc_util_handover.h" + +#ifndef NET_NFC_EXPORT_API +#define NET_NFC_EXPORT_API __attribute__((visibility("default"))) +#endif + +#include + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_create_carrier_config (net_nfc_carrier_config_h * config, net_nfc_conn_handover_carrier_type_e type) +{ + return net_nfc_util_create_carrier_config ((net_nfc_carrier_config_s **) config, type); +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_add_carrier_config_property (net_nfc_carrier_config_h config, uint16_t attribute, uint16_t size, uint8_t * data) +{ + return net_nfc_util_add_carrier_config_property ((net_nfc_carrier_config_s *) config, attribute, size, data); +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_remove_carrier_config_property (net_nfc_carrier_config_h config, uint16_t attribute) +{ + return net_nfc_util_remove_carrier_config_property ((net_nfc_carrier_config_s *) config, attribute); +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_carrier_config_property (net_nfc_carrier_config_h config, uint16_t attribute, uint16_t * size, uint8_t ** data) +{ + return net_nfc_util_get_carrier_config_property ((net_nfc_carrier_config_s *) config, attribute, size, data); +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_append_carrier_config_group (net_nfc_carrier_config_h config, net_nfc_property_group_h group) +{ + return net_nfc_util_append_carrier_config_group ((net_nfc_carrier_config_s *) config, (net_nfc_carrier_property_s *) group); +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_remove_carrier_config_group (net_nfc_carrier_config_h config, net_nfc_property_group_h group) +{ + return net_nfc_util_remove_carrier_config_group ((net_nfc_carrier_config_s *) config, (net_nfc_carrier_property_s *) group); +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_carrier_config_group (net_nfc_carrier_config_h config, int index, net_nfc_property_group_h * group) +{ + return net_nfc_util_get_carrier_config_group ((net_nfc_carrier_config_s *) config, index, (net_nfc_carrier_property_s **) group); +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_free_carrier_config (net_nfc_carrier_config_h config) +{ + return net_nfc_util_free_carrier_config ((net_nfc_carrier_config_s *) config); +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_create_carrier_config_group (net_nfc_property_group_h * group, uint16_t attribute) +{ + return net_nfc_util_create_carrier_config_group ((net_nfc_carrier_property_s **) group, attribute); +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_add_carrier_config_group_property (net_nfc_property_group_h group, uint16_t attribute, uint16_t size, uint8_t * data) +{ + return net_nfc_util_add_carrier_config_group_property ((net_nfc_carrier_property_s*) group, attribute, size, data); +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_carrier_config_group_property (net_nfc_property_group_h group, uint16_t attribute, uint16_t *size, uint8_t ** data) +{ + return net_nfc_util_get_carrier_config_group_property ((net_nfc_carrier_property_s*) group, attribute, size, data); +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_remove_carrier_config_group_property (net_nfc_property_group_h group, uint16_t attribute) +{ + return net_nfc_util_remove_carrier_config_group_property ((net_nfc_carrier_property_s*) group, attribute); +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_free_carrier_group (net_nfc_property_group_h group) +{ + return net_nfc_util_free_carrier_group ((net_nfc_carrier_property_s*) group); +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_create_ndef_record_with_carrier_config (ndef_record_h * record, net_nfc_carrier_config_h config) +{ + return net_nfc_util_create_ndef_record_with_carrier_config ((ndef_record_s**) record, (net_nfc_carrier_config_s *) config); +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_create_carrier_config_from_config_record (net_nfc_carrier_config_h * config, ndef_record_h record) +{ + return net_nfc_util_create_carrier_config_from_config_record ((net_nfc_carrier_config_s **) config, (ndef_record_s *) record); + +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_append_carrier_config_record (ndef_message_h message, ndef_record_h record, net_nfc_conn_handover_carrier_state_e power_status) +{ + return net_nfc_util_append_carrier_config_record ((ndef_message_s *) message, (ndef_record_s *) record, power_status); +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_remove_carrier_config_record (ndef_message_h message, ndef_record_h record) +{ + return net_nfc_util_remove_carrier_config_record ((ndef_message_s *) message, (ndef_record_s *) record); +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_carrier_config_record (ndef_message_h message, int index, ndef_record_h * record) +{ + return net_nfc_util_get_carrier_config_record ((ndef_message_s *) message, index, (ndef_record_s **) record); +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_handover_random_number(ndef_message_h message, unsigned short* random_number) +{ + return net_nfc_util_get_handover_random_number((ndef_message_s *) message, random_number); +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_alternative_carrier_record_count (ndef_message_h message, unsigned int * count) +{ + return net_nfc_util_get_alternative_carrier_record_count ((ndef_message_s *) message, count); +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_alternative_carrier_power_status (ndef_message_h message, int index, net_nfc_conn_handover_carrier_state_e * power_state) +{ + return net_nfc_util_get_alternative_carrier_power_status ((ndef_message_s *) message, index, power_state); +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_set_alternative_carrier_power_status (ndef_message_h message, int index, net_nfc_conn_handover_carrier_state_e power_status) +{ + return net_nfc_util_set_alternative_carrier_power_status ((ndef_message_s *) message, index, power_status); +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_alternative_carrier_type (ndef_message_h message, int index, net_nfc_conn_handover_carrier_type_e * type) +{ + return net_nfc_util_get_alternative_carrier_type ((ndef_message_s *) message, index, type); +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_create_handover_request_message (ndef_message_h * message) +{ + return net_nfc_util_create_handover_request_message ((ndef_message_s **) message); +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_create_handover_select_message (ndef_message_h * message) +{ + return net_nfc_util_create_handover_select_message((ndef_message_s **) message); +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_create_handover_error_record (ndef_record_h * record, uint8_t reason, uint32_t data) +{ + return net_nfc_util_create_handover_error_record ((ndef_record_s**) record, reason, data); +} + + diff --git a/src/clientlib/net_nfc_client_ndef_record.c b/src/clientlib/net_nfc_client_ndef_record.c new file mode 100644 index 0000000..b70731d --- /dev/null +++ b/src/clientlib/net_nfc_client_ndef_record.c @@ -0,0 +1,292 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "net_nfc_ndef_record.h" +#include "net_nfc_ndef_message.h" +#include "net_nfc_data.h" +#include "net_nfc_debug_private.h" +#include "net_nfc_util_private.h" +#include "net_nfc_util_ndef_record.h" + +#ifndef NET_NFC_EXPORT_API +#define NET_NFC_EXPORT_API __attribute__((visibility("default"))) +#endif + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_create_record(ndef_record_h* record, net_nfc_record_tnf_e tnf, data_h typeName, data_h id, data_h payload) +{ + return net_nfc_util_create_record(tnf, (data_s*)typeName, (data_s*)id, (data_s*)payload, (ndef_record_s**)record); +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_create_text_type_record(ndef_record_h* record, const char* text, const char* language_code_str, net_nfc_encode_type_e encode) +{ + return net_nfc_util_create_text_type_record(text, language_code_str, encode, (ndef_record_s**)record); +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_create_uri_type_record(ndef_record_h* record, const char* uri, net_nfc_schema_type_e protocol_schema) +{ + return net_nfc_util_create_uri_type_record(uri, protocol_schema, (ndef_record_s**)record); +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_free_record(ndef_record_h record) +{ + return net_nfc_util_free_record((ndef_record_s*)record); +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_record_payload(ndef_record_h record, data_h * payload) +{ + if (record == NULL || payload == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + ndef_record_s * struct_record = (ndef_record_s *)record; + + *payload = (data_h)&(struct_record->payload_s); + + return NET_NFC_OK; +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_record_type(ndef_record_h record, data_h * type) +{ + if (record == NULL || type == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + ndef_record_s * struct_record = (ndef_record_s *)record; + + *type = (data_h)&(struct_record->type_s); + + return NET_NFC_OK; + +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_record_id(ndef_record_h record, data_h * id) +{ + if (record == NULL || id == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + ndef_record_s * struct_record = (ndef_record_s *)record; + + *id = (data_h)&(struct_record->id_s); + + return NET_NFC_OK; + +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_record_tnf(ndef_record_h record, net_nfc_record_tnf_e * TNF) +{ + if (record == NULL || TNF == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + ndef_record_s * struct_record = (ndef_record_s *)record; + + *TNF = (net_nfc_record_tnf_e)struct_record->TNF; + + return NET_NFC_OK; +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_set_record_id(ndef_record_h record, data_h id) +{ + + ndef_record_s * record_private = (ndef_record_s *)record; + data_s * id_private = (data_s *)id; + + if (id_private == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + return net_nfc_util_set_record_id(record_private, id_private->buffer, id_private->length); +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_record_flags(ndef_record_h record, uint8_t * flag) +{ + if (record == NULL || flag == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + ndef_record_s * struct_record = (ndef_record_s *)record; + + *flag = struct_record->MB; + *flag <<= 1; + *flag += struct_record->ME; + *flag <<= 1; + *flag += struct_record->CF; + *flag <<= 1; + *flag += struct_record->SR; + *flag <<= 1; + *flag += struct_record->IL; + *flag <<= 3; + *flag += struct_record->TNF; + + return NET_NFC_OK; +} + +NET_NFC_EXPORT_API uint8_t net_nfc_get_record_mb(uint8_t flag) +{ + return (flag & 0x80) >> 7; +} + +NET_NFC_EXPORT_API uint8_t net_nfc_get_record_me(uint8_t flag) +{ + return (flag & 0x40) >> 6; +} + +NET_NFC_EXPORT_API uint8_t net_nfc_get_record_cf(uint8_t flag) +{ + return (flag & 0x20) >> 5; +} + +NET_NFC_EXPORT_API uint8_t net_nfc_get_record_il(uint8_t flag) +{ + return (flag & 0x10) >> 4; +} + +NET_NFC_EXPORT_API uint8_t net_nfc_get_record_sr(uint8_t flag) +{ + return (flag & 0x08) >> 3; +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_create_text_string_from_text_record(ndef_record_h record, char** buffer) +{ + if (record == NULL || buffer == NULL) + { + return NET_NFC_ALLOC_FAIL; + } + + data_h payload; + data_h rec_type; + + if (net_nfc_get_record_type(record, &rec_type) == NET_NFC_OK) + { + if (strncmp((char *)net_nfc_get_data_buffer(rec_type), TEXT_RECORD_TYPE, 1) != 0) + { + DEBUG_CLIENT_MSG("record type is not matched"); + return NET_NFC_NDEF_RECORD_IS_NOT_EXPECTED_TYPE; + } + } + + if (net_nfc_get_record_payload(record, &payload) == NET_NFC_OK) + { + uint8_t* buffer_temp = net_nfc_get_data_buffer(payload); + uint32_t buffer_length = net_nfc_get_data_length(payload); + + int controllbyte = buffer_temp[0]; + int lang_code_length = controllbyte & 0x3F; + int index = lang_code_length + 1; + int text_length = buffer_length - (lang_code_length + 1); + + if ((*buffer = (char *)calloc(1, text_length + 1)) != NULL) + { + memcpy(*buffer, &(buffer_temp[index]), text_length); + DEBUG_CLIENT_MSG("text = [%s]", *buffer); + } + else + { + return NET_NFC_ALLOC_FAIL; + } + } + + return NET_NFC_OK; +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_languange_code_string_from_text_record(ndef_record_h record, char** lang_code_str) +{ + if (record == NULL || lang_code_str == NULL) + { + return NET_NFC_ALLOC_FAIL; + } + + data_h payload; + data_h rec_type; + + if (net_nfc_get_record_type(record, &rec_type) == NET_NFC_OK) + { + if (strncmp((char *)net_nfc_get_data_buffer(rec_type), TEXT_RECORD_TYPE, 1) != 0) + { + DEBUG_CLIENT_MSG("record type is not matched"); + return NET_NFC_NDEF_RECORD_IS_NOT_EXPECTED_TYPE; + } + } + + if (net_nfc_get_record_payload(record, &payload) == NET_NFC_OK) + { + uint8_t* buffer_temp = net_nfc_get_data_buffer(payload); + char * buffer = NULL; + + int controllbyte = buffer_temp[0]; + int lang_code_length = controllbyte & 0x3F; + int index = 1; + + if ((buffer = (char *)calloc(1, lang_code_length + 1)) != NULL) + { + memcpy(buffer, &(buffer_temp[index]), lang_code_length); + DEBUG_CLIENT_MSG("language code = [%s]", buffer); + + *lang_code_str = buffer; + } + else + { + return NET_NFC_ALLOC_FAIL; + } + } + + return NET_NFC_OK; +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_encoding_type_from_text_record(ndef_record_h record, net_nfc_encode_type_e * encoding) +{ + if (record == NULL || encoding == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + data_h payload; + data_h rec_type; + + if (net_nfc_get_record_type(record, &rec_type) == NET_NFC_OK) + { + if (strncmp((char *)net_nfc_get_data_buffer(rec_type), TEXT_RECORD_TYPE, 1) != 0) + { + DEBUG_CLIENT_MSG("record type is not matched"); + return NET_NFC_NDEF_RECORD_IS_NOT_EXPECTED_TYPE; + } + } + + if (net_nfc_get_record_payload(record, &payload) == NET_NFC_OK) + { + uint8_t* buffer_temp = net_nfc_get_data_buffer(payload); + + int controllbyte = buffer_temp[0]; + + if ((controllbyte & 0x80) == 0x80) + { + *encoding = NET_NFC_ENCODE_UTF_16; + } + else + { + *encoding = NET_NFC_ENCODE_UTF_8; + } + } + + return NET_NFC_OK; +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_create_uri_string_from_uri_record(ndef_record_h record, char **uri) +{ + return net_nfc_util_create_uri_string_from_uri_record((ndef_record_s *)record, uri); +} diff --git a/src/clientlib/net_nfc_client_nfc.c b/src/clientlib/net_nfc_client_nfc.c new file mode 100755 index 0000000..125b0ce --- /dev/null +++ b/src/clientlib/net_nfc_client_nfc.c @@ -0,0 +1,482 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +#include "vconf.h" +#ifdef SECURITY_SERVER +#include +#endif + +#include "net_nfc.h" +#include "net_nfc_typedef.h" +#include "net_nfc_util_private.h" +#include "net_nfc_util_defines.h" +#include "net_nfc_debug_private.h" +#include "net_nfc_client_ipc_private.h" +#include "net_nfc_exchanger_private.h" +#include "net_nfc_client_nfc_private.h" +#include "net_nfc_manager_dbus.h" +#include "nfc-service-glue.h" + +#ifndef NET_NFC_EXPORT_API +#define NET_NFC_EXPORT_API __attribute__((visibility("default"))) +#endif + +#define BUFFER_LENGTH_MAX 1024 + +static client_context_t g_client_context = { NULL, NET_NFC_OK, PTHREAD_MUTEX_INITIALIZER, NET_NFC_ALL_ENABLE, NULL, false }; + +static void _net_nfc_reset_client_context() +{ + g_client_context.register_user_param = NULL; + g_client_context.result = NET_NFC_OK; + g_client_context.filter = NET_NFC_ALL_ENABLE; + g_client_context.initialized = false; +} + +static net_nfc_error_e _net_nfc_launch_daemon() +{ + net_nfc_error_e result = NET_NFC_OPERATION_FAIL; + DBusGConnection *connection = NULL; + GError *error = NULL; + + dbus_g_thread_init(); + + connection = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error); + if (error == NULL) + { + DBusGProxy *proxy = NULL; + + proxy = dbus_g_proxy_new_for_name(connection, "org.tizen.nfc_service", "/org/tizen/nfc_service", "org.tizen.nfc_service"); + if (proxy != NULL) + { + guint dbus_result = 0; + + if (org_tizen_nfc_service_launch(proxy, &dbus_result, &error) == true) + { + DEBUG_CLIENT_MSG("org_tizen_nfc_service_launch success"); + result = NET_NFC_OK; + } + else + { + DEBUG_ERR_MSG("org_tizen_nfc_service_launch failed"); + if (error != NULL) + { + DEBUG_ERR_MSG("message : [%s]", error->message); + g_error_free(error); + } + } + + g_object_unref(proxy); + } + else + { + DEBUG_ERR_MSG("dbus_g_proxy_new_for_name failed"); + } + } + else + { + DEBUG_ERR_MSG("dbus_g_bus_get failed"); + if (error != NULL) + { + DEBUG_ERR_MSG("message : [%s]", error->message); + g_error_free(error); + } + } + + return result; +} + +#if 0 +static net_nfc_error_e _net_nfc_terminate_daemon() +{ + net_nfc_error_e result = NET_NFC_OPERATION_FAIL; + DBusGConnection *connection = NULL; + GError *error = NULL; + + connection = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error); + if (error == NULL) + { + DBusGProxy *proxy = NULL; + + proxy = dbus_g_proxy_new_for_name(connection, "org.tizen.nfc_service", "/org/tizen/nfc_service", "org.tizen.nfc_service"); + if (proxy != NULL) + { + guint dbus_result = 0; + + if (org_tizen_nfc_service_terminate(proxy, &dbus_result, &error) == true) + { + DEBUG_CLIENT_MSG("org_tizen_nfc_service_terminate success"); + result = NET_NFC_OK; + } + else + { + DEBUG_ERR_MSG("org_tizen_nfc_service_terminate failed"); + if (error != NULL) + { + DEBUG_ERR_MSG("message : [%s]", error->message); + g_error_free(error); + } + } + + g_object_unref (proxy); + } + else + { + DEBUG_ERR_MSG("dbus_g_proxy_new_for_name failed"); + } + } + else + { + DEBUG_ERR_MSG("dbus_g_bus_get failed, message : [%s]", error->message); + g_error_free(error); + } + + return result; +} +#endif + +#ifdef SECURITY_SERVER +static net_nfc_error_e _net_nfc_load_cookies() +{ + net_nfc_error_e result = NET_NFC_OK; + int cookies_size; + char cookies[512] = { 0, }; + + if ((cookies_size = security_server_get_cookie_size()) > 0) + { + int error = 0; + + if ((error = security_server_request_cookie(cookies, cookies_size)) == SECURITY_SERVER_API_SUCCESS) + { +#if 0 + DEBUG_SERVER_MSG("load cookies"); + DEBUG_MSG_PRINT_BUFFER(cookies, cookies_size); +#endif + + _net_nfc_client_set_cookies(cookies, cookies_size); + + result = NET_NFC_OK; + } + else + { + DEBUG_ERR_MSG("security server request cookies error = [%d]", error); + + result = NET_NFC_SECURITY_FAIL; + } + } + else + { + DEBUG_ERR_MSG("wrong cookie length"); + + result = NET_NFC_SECURITY_FAIL; + } + + return result; +} +#endif + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_initialize() +{ + net_nfc_error_e result = NET_NFC_OK; + + if (!g_thread_supported()) + { + g_thread_init(NULL); + } + + g_type_init(); + + pthread_mutex_lock(&g_client_context.g_client_lock); + + if (g_client_context.initialized == true) + { + pthread_mutex_unlock(&g_client_context.g_client_lock); + return result; + } + + result = _net_nfc_launch_daemon(); + if (result != NET_NFC_OK) + { + pthread_mutex_unlock(&g_client_context.g_client_lock); + return result; + } + + _net_nfc_reset_client_context(); + +#ifdef SECURITY_SERVER + result = _net_nfc_load_cookies(); + if (result != NET_NFC_OK) + { + pthread_mutex_unlock(&g_client_context.g_client_lock); + return result; + } +#endif + + result = net_nfc_client_socket_initialize(); + if (result == NET_NFC_OK || result == NET_NFC_ALREADY_INITIALIZED) + { + DEBUG_CLIENT_MSG("socket is initialized"); + g_client_context.initialized = true; + } + else + { + DEBUG_ERR_MSG("socket init is failed = [%d]", result); + _net_nfc_client_free_cookies(); + } + + pthread_mutex_unlock(&g_client_context.g_client_lock); + + return result; +} + +/* this is sync call */ +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_deinitialize() +{ + net_nfc_error_e result = NET_NFC_OK; + + pthread_mutex_lock(&g_client_context.g_client_lock); + + net_nfc_client_socket_finalize(); + _net_nfc_client_free_cookies(); + _net_nfc_reset_client_context(); + +#if 0 + result = _net_nfc_terminate_daemon(); +#endif + + pthread_mutex_unlock(&g_client_context.g_client_lock); + + return result; +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_set_response_callback(net_nfc_response_cb cb, void *user_param) +{ + net_nfc_error_e result = NET_NFC_OK; + + if (cb == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + pthread_mutex_lock(&g_client_context.g_client_lock); + + g_client_context.register_user_param = user_param; + result = _net_nfc_client_register_cb(cb); + + pthread_mutex_unlock(&g_client_context.g_client_lock); + + return result; +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_unset_response_callback(void) +{ + net_nfc_error_e result = NET_NFC_OK; + + pthread_mutex_lock(&g_client_context.g_client_lock); + + g_client_context.register_user_param = NULL; + result = _net_nfc_client_unregister_cb(); + + pthread_mutex_unlock(&g_client_context.g_client_lock); + + return result; +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_set_launch_popup_state(int enable) +{ + net_nfc_error_e ret; + net_nfc_request_set_launch_state_t request = { 0, }; + + request.length = sizeof(net_nfc_request_set_launch_state_t); + request.request_type = NET_NFC_MESSAGE_SERVICE_SET_LAUNCH_STATE; + request.set_launch_popup = enable; + + ret = net_nfc_client_send_reqeust((net_nfc_request_msg_t *)&request, NULL); + + return ret; +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_launch_popup_state(int *state) +{ + net_nfc_error_e result = NET_NFC_OK; + + if (state == NULL) + return NET_NFC_NULL_PARAMETER; + + /* check state of launch popup */ + if (vconf_get_bool(NET_NFC_DISABLE_LAUNCH_POPUP_KEY, state) != 0) + { + result = NET_NFC_OPERATION_FAIL; + } + + return result; +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_set_state(int state, net_nfc_set_activation_completed_cb callback) +{ + net_nfc_error_e ret = NET_NFC_UNKNOWN_ERROR; + + DEBUG_CLIENT_MSG("net_nfc_set_state[Enter]"); + +#if 0 + if (!g_thread_supported()) + { + g_thread_init(NULL); + } + + g_type_init(); +#endif + + if (state == FALSE)/*Deinit*/ + { + ret = net_nfc_send_deinit(NULL); + + DEBUG_CLIENT_MSG("Send the deinit msg!!, result [%d]", ret); + } + else/*INIT*/ + { + ret = net_nfc_send_init(NULL); + + DEBUG_CLIENT_MSG("Send the init msg!!, result [%d]", ret); + } + + return ret; +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_is_supported(int *state) +{ + net_nfc_error_e ret; + + if (state != NULL) + { + if (vconf_get_bool(VCONFKEY_NFC_FEATURE, state) == 0) + { + ret = NET_NFC_OK; + } + else + { + ret = NET_NFC_INVALID_STATE; + } + } + else + { + ret = NET_NFC_NULL_PARAMETER; + } + + return ret; +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_state(int *state) +{ + net_nfc_error_e ret; + + if (state != NULL) + { + if (vconf_get_bool(VCONFKEY_NFC_STATE, state) == 0) + { + ret = NET_NFC_OK; + } + else + { + ret = NET_NFC_INVALID_STATE; + } + } + else + { + ret = NET_NFC_NULL_PARAMETER; + } + + return ret; +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_state_activate(void) +{ + net_nfc_error_e ret; + net_nfc_request_change_client_state_t request = { 0, }; + + request.length = sizeof(net_nfc_request_change_client_state_t); + request.request_type = NET_NFC_MESSAGE_SERVICE_CHANGE_CLIENT_STATE; + request.client_state = NET_NFC_CLIENT_ACTIVE_STATE; + + ret = net_nfc_client_send_reqeust((net_nfc_request_msg_t *)&request, NULL); + + return ret; +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_state_deactivate(void) +{ + net_nfc_error_e ret; + net_nfc_request_change_client_state_t request = { 0, }; + + request.length = sizeof(net_nfc_request_change_client_state_t); + request.request_type = NET_NFC_MESSAGE_SERVICE_CHANGE_CLIENT_STATE; + request.client_state = NET_NFC_CLIENT_INACTIVE_STATE; + + ret = net_nfc_client_send_reqeust((net_nfc_request_msg_t *)&request, NULL); + + return ret; +} + +client_context_t *net_nfc_get_client_context() +{ + return &g_client_context; +} + +bool net_nfc_tag_is_connected() +{ + bool result = false; + + pthread_mutex_lock(&g_client_context.g_client_lock); + + result = (g_client_context.target_info != NULL && g_client_context.target_info->handle != NULL); + + pthread_mutex_unlock(&g_client_context.g_client_lock); + + return result; +} + +net_nfc_error_e net_nfc_send_init(void *context) +{ + net_nfc_error_e ret; + net_nfc_request_msg_t req_msg = { 0, }; + + req_msg.length = sizeof(net_nfc_request_msg_t); + req_msg.request_type = NET_NFC_MESSAGE_SERVICE_INIT; + req_msg.user_param = (uint32_t)context; + + ret = net_nfc_client_send_reqeust((net_nfc_request_msg_t *)&req_msg, NULL); + + return ret; +} + +net_nfc_error_e net_nfc_send_deinit(void *context) +{ + net_nfc_error_e ret; + net_nfc_request_msg_t req_msg = { 0, }; + + req_msg.length = sizeof(net_nfc_request_msg_t); + req_msg.request_type = NET_NFC_MESSAGE_SERVICE_DEINIT; + req_msg.user_param = (uint32_t)context; + + ret = net_nfc_client_send_reqeust((net_nfc_request_msg_t *)&req_msg, NULL); + + return ret; +} + diff --git a/src/clientlib/net_nfc_client_sign_record.c b/src/clientlib/net_nfc_client_sign_record.c new file mode 100755 index 0000000..abb434c --- /dev/null +++ b/src/clientlib/net_nfc_client_sign_record.c @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include "net_nfc_util_sign_record.h" + +#ifndef NET_NFC_EXPORT_API +#define NET_NFC_EXPORT_API __attribute__((visibility("default"))) +#endif + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_sign_records(ndef_message_h msg, int begin_index, int end_index, char *cert_file, char *password) +{ + return net_nfc_util_sign_records((ndef_message_s *)msg, begin_index, end_index, cert_file, password); +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_sign_ndef_message(ndef_message_h msg, char *cert_file, char *password) +{ + return net_nfc_util_sign_ndef_message((ndef_message_s *)msg, cert_file, password); +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_verify_signature_ndef_message(ndef_message_h msg) +{ + return net_nfc_util_verify_signature_ndef_message((ndef_message_s *)msg); +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_verify_signature_records(ndef_record_h begin_record, ndef_record_h sign_record) +{ + return net_nfc_util_verify_signature_records((ndef_record_s *)begin_record, (ndef_record_s *)sign_record); +} diff --git a/src/clientlib/net_nfc_client_tag.c b/src/clientlib/net_nfc_client_tag.c new file mode 100755 index 0000000..7a3e74b --- /dev/null +++ b/src/clientlib/net_nfc_client_tag.c @@ -0,0 +1,480 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "net_nfc_tag.h" +#include "net_nfc_typedef_private.h" +#include "net_nfc_client_ipc_private.h" +#include "net_nfc_debug_private.h" +#include "net_nfc_util_private.h" +#include "net_nfc_util_ndef_message.h" +#include "net_nfc_client_nfc_private.h" + +#include +#include + +#ifndef NET_NFC_EXPORT_API +#define NET_NFC_EXPORT_API __attribute__((visibility("default"))) +#endif + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_format_ndef(net_nfc_target_handle_h handle, data_h key, void *trans_param) +{ + net_nfc_error_e ret; + net_nfc_request_format_ndef_t *request = NULL; + uint32_t length = 0; + data_s *struct_key = (data_s *)key; + + if (handle == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + length = sizeof(net_nfc_request_format_ndef_t); + if (struct_key != NULL) + { + length += struct_key->length; + } + + _net_nfc_util_alloc_mem(request, length); + if (request == NULL) + { + return NET_NFC_ALLOC_FAIL; + } + + request->length = length; + request->request_type = NET_NFC_MESSAGE_FORMAT_NDEF; + request->handle = (net_nfc_target_handle_s *)handle; + request->trans_param = trans_param; + + if (struct_key != NULL && struct_key->length > 0) + { + request->key.length = struct_key->length; + memcpy(&request->key.buffer, struct_key->buffer, request->key.length); + } + + ret = net_nfc_client_send_reqeust((net_nfc_request_msg_t *)request, NULL); + + _net_nfc_util_free_mem(request); + + return ret; +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_set_tag_filter(net_nfc_event_filter_e config) +{ + client_context_t *client_context = net_nfc_get_client_context(); + + pthread_mutex_lock(&(client_context->g_client_lock)); + client_context->filter = config; + pthread_mutex_unlock(&(client_context->g_client_lock)); + + return NET_NFC_OK; +} + +NET_NFC_EXPORT_API net_nfc_event_filter_e net_nfc_get_tag_filter() +{ + + client_context_t *client_context = net_nfc_get_client_context(); + + pthread_mutex_lock(&(client_context->g_client_lock)); + net_nfc_event_filter_e filter = client_context->filter; + pthread_mutex_unlock(&(client_context->g_client_lock)); + + return filter; +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_transceive(net_nfc_target_handle_h handle, data_h rawdata, void *trans_param) +{ + net_nfc_error_e ret; + net_nfc_request_transceive_t *request = NULL; + client_context_t *client_context_tmp = NULL; + net_nfc_target_info_s *target_info = NULL; + uint32_t length = 0; + data_s *data = (data_s *)rawdata; + uint8_t *send_buffer; + + DEBUG_CLIENT_MSG("send reqeust :: transceive = [%p]", handle); + + if (handle == NULL || rawdata == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + if (!net_nfc_tag_is_connected()) + { + return NET_NFC_OPERATION_FAIL; + } + + client_context_tmp = net_nfc_get_client_context(); + if (client_context_tmp == NULL || client_context_tmp->target_info == NULL) + { + return NET_NFC_NO_DATA_FOUND; + } + /* fill trans information struct */ + target_info = client_context_tmp->target_info; + + switch (target_info->devType) + { + case NET_NFC_MIFARE_MINI_PICC : + case NET_NFC_MIFARE_1K_PICC : + case NET_NFC_MIFARE_4K_PICC : + case NET_NFC_MIFARE_ULTRA_PICC : + { + length = sizeof(net_nfc_request_transceive_t) + data->length + 2; + + _net_nfc_util_alloc_mem(request, length); + if (request == NULL) + { + return NET_NFC_ALLOC_FAIL; + } + + _net_nfc_util_alloc_mem(send_buffer, data->length + 2); + if (send_buffer == NULL) + { + _net_nfc_util_free_mem(request); + return NET_NFC_ALLOC_FAIL; + } + + memcpy(send_buffer, data->buffer, data->length); + net_nfc_util_compute_CRC(CRC_A, send_buffer, data->length + 2); + + memcpy(&request->info.trans_data.buffer, send_buffer, data->length + 2); + + request->info.trans_data.length = data->length + 2; + + _net_nfc_util_free_mem(send_buffer); + } + break; + + case NET_NFC_JEWEL_PICC : + { + if (data->length > 9) + { + return NET_NFC_INVALID_PARAM; + } + + length = sizeof(net_nfc_request_transceive_t) + 9; + + _net_nfc_util_alloc_mem(request, length); + if (request == NULL) + { + return NET_NFC_ALLOC_FAIL; + } + + _net_nfc_util_alloc_mem(send_buffer, 9); + if (send_buffer == NULL) + { + _net_nfc_util_free_mem(request); + return NET_NFC_ALLOC_FAIL; + } + + memcpy(send_buffer, data->buffer, data->length); + net_nfc_util_compute_CRC(CRC_B, send_buffer, 9); + + memcpy(&request->info.trans_data.buffer, send_buffer, 9); + + request->info.trans_data.length = 9; + + _net_nfc_util_free_mem(send_buffer); + } + break; + + default : + { + length = sizeof(net_nfc_request_transceive_t) + data->length; + + _net_nfc_util_alloc_mem(request, length); + if (request == NULL) + { + return NET_NFC_ALLOC_FAIL; + } + + memcpy(&request->info.trans_data.buffer, data->buffer, data->length); + + request->info.trans_data.length = data->length; + } + break; + } + + /* fill request message */ + request->length = length; + request->request_type = NET_NFC_MESSAGE_TRANSCEIVE; + request->handle = (net_nfc_target_handle_s *)handle; + request->trans_param = trans_param; + request->info.dev_type = (uint32_t)target_info->devType; + + ret = net_nfc_client_send_reqeust((net_nfc_request_msg_t *)request, NULL); + + _net_nfc_util_free_mem(request); + + return ret; +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_read_tag(net_nfc_target_handle_h handle, void *trans_param) +{ + net_nfc_error_e ret; + net_nfc_request_read_ndef_t request = { 0, }; + + DEBUG_CLIENT_MSG("send reqeust :: read ndef = [%p]", handle); + + if (handle == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + if (!net_nfc_tag_is_connected()) + { + return NET_NFC_OPERATION_FAIL; + } + + request.length = sizeof(net_nfc_request_read_ndef_t); + request.request_type = NET_NFC_MESSAGE_READ_NDEF; + request.handle = (net_nfc_target_handle_s *)handle; + request.trans_param = trans_param; + + ret = net_nfc_client_send_reqeust((net_nfc_request_msg_t *)&request, NULL); + + return ret; +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_write_ndef(net_nfc_target_handle_h handle, ndef_message_h msg, void *trans_param) +{ + net_nfc_request_write_ndef_t *request = NULL; + net_nfc_error_e result; + data_s data; + uint32_t length = 0, ndef_length = 0; + + DEBUG_CLIENT_MSG("send reqeust :: write ndef = [%p]", handle); + + if (handle == NULL || msg == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + if (!net_nfc_tag_is_connected()) + { + return NET_NFC_OPERATION_FAIL; + } + + ndef_length = net_nfc_util_get_ndef_message_length((ndef_message_s *)msg); + if (ndef_length == 0) + { + return NET_NFC_INVALID_PARAM; + } + + length = sizeof(net_nfc_request_write_ndef_t) + ndef_length; + + _net_nfc_util_alloc_mem(request, length); + if (request == NULL) + { + return NET_NFC_ALLOC_FAIL; + } + + /* fill request message */ + request->length = length; + request->request_type = NET_NFC_MESSAGE_WRITE_NDEF; + request->handle = (net_nfc_target_handle_s *)handle; + request->trans_param = trans_param; + request->data.length = ndef_length; + + data.length = ndef_length; + data.buffer = request->data.buffer; + + result = net_nfc_util_convert_ndef_message_to_rawdata((ndef_message_s *)msg, &data); + if (result != NET_NFC_OK) + { + DEBUG_CLIENT_MSG("NDEF to rawdata is failed (reason:%d)", result); + _net_nfc_util_free_mem(request); + return result; + } + + result = net_nfc_client_send_reqeust((net_nfc_request_msg_t *)request, NULL); + + _net_nfc_util_free_mem(request); + + return result; +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_is_tag_connected(void *trans_param) +{ + net_nfc_request_is_tag_connected_t request = { 0, }; + net_nfc_error_e result; + + request.length = sizeof(net_nfc_request_is_tag_connected_t); + request.request_type = NET_NFC_MESSAGE_IS_TAG_CONNECTED; + request.trans_param = trans_param; + + result = net_nfc_client_send_reqeust((net_nfc_request_msg_t *)&request, NULL); + + return result; +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_is_tag_connected_sync(int *dev_type) +{ + net_nfc_request_is_tag_connected_t request = { 0, }; + net_nfc_response_is_tag_connected_t context = { 0, }; + net_nfc_error_e result; + + if (dev_type == NULL) + return NET_NFC_INVALID_PARAM; + + request.length = sizeof(net_nfc_request_is_tag_connected_t); + request.request_type = NET_NFC_MESSAGE_IS_TAG_CONNECTED; + request.trans_param = (void *)&context; + + result = net_nfc_client_send_reqeust_sync((net_nfc_request_msg_t *)&request, NULL); + if (result == NET_NFC_OK) + { + *dev_type = context.devType; + result = context.result; + } + + return result; +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_make_read_only_ndef_tag(net_nfc_target_handle_h handle, void *trans_param) +{ + net_nfc_error_e result; + net_nfc_request_make_read_only_ndef_t request = { 0, }; + client_context_t *tmp_client_context = NULL; + net_nfc_target_info_s *target_info = NULL; + + DEBUG_CLIENT_MSG("send reqeust :: make read only ndef tag = [%p]", handle); + + if (handle == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + if (!net_nfc_tag_is_connected()) + { + return NET_NFC_OPERATION_FAIL; + } + + tmp_client_context = net_nfc_get_client_context(); + if (tmp_client_context != NULL) + { + + target_info = tmp_client_context->target_info; + + if (target_info != NULL) + { + bool is_supported_tag = false; + + switch (target_info->devType) + { + case NET_NFC_ISO14443_A_PICC : + case NET_NFC_MIFARE_MINI_PICC : + case NET_NFC_MIFARE_1K_PICC : + case NET_NFC_MIFARE_4K_PICC : + case NET_NFC_MIFARE_ULTRA_PICC : + case NET_NFC_JEWEL_PICC : + is_supported_tag = true; + break; + default : + is_supported_tag = false; + break; + } + + if (!is_supported_tag) + { + DEBUG_MSG("not supported tag for read only ndef tag"); + return NET_NFC_NOT_SUPPORTED; + } + } + } + + request.length = sizeof(net_nfc_request_make_read_only_ndef_t); + request.request_type = NET_NFC_MESSAGE_MAKE_READ_ONLY_NDEF; + request.handle = (net_nfc_target_handle_s *)handle; + request.trans_param = trans_param; + + result = net_nfc_client_send_reqeust((net_nfc_request_msg_t *)&request, NULL); + + return result; +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_current_tag_info(void *trans_param) +{ + net_nfc_request_get_current_tag_info_t request = { 0, }; + net_nfc_error_e result = NET_NFC_OK; + + request.length = sizeof(net_nfc_request_get_current_tag_info_t); + request.request_type = NET_NFC_MESSAGE_GET_CURRENT_TAG_INFO; + request.trans_param = trans_param; + + result = net_nfc_client_send_reqeust((net_nfc_request_msg_t *)&request, NULL); + + return result; +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_current_tag_info_sync(net_nfc_target_info_h *info) +{ + net_nfc_request_get_current_tag_info_t request = { 0, }; + net_nfc_response_get_current_tag_info_t response = { 0, }; + net_nfc_error_e result = NET_NFC_OK; + + request.length = sizeof(net_nfc_request_get_current_tag_info_t); + request.request_type = NET_NFC_MESSAGE_GET_CURRENT_TAG_INFO; + request.trans_param = (void *)&response; + + result = net_nfc_client_send_reqeust_sync((net_nfc_request_msg_t *)&request, NULL); + if (result == NET_NFC_OK) + { + result = response.result; + if (response.result == NET_NFC_OK) + { + /* already allocated memory */ + *info = (net_nfc_target_info_h)response.trans_param; + } + } + + return result; +} + +bool net_nfc_util_check_tag_filter(net_nfc_target_type_e type) +{ + net_nfc_event_filter_e current_filter = net_nfc_get_tag_filter(); + net_nfc_event_filter_e converted = NET_NFC_ALL_ENABLE; + + DEBUG_CLIENT_MSG("filter = [%d]", current_filter); + + if (type >= NET_NFC_ISO14443_A_PICC && type <= NET_NFC_MIFARE_DESFIRE_PICC) + { + converted = NET_NFC_ISO14443A_ENABLE; + } + else if (type >= NET_NFC_ISO14443_B_PICC && type <= NET_NFC_ISO14443_BPRIME_PICC) + { + converted = NET_NFC_ISO14443B_ENABLE; + } + else if (type == NET_NFC_FELICA_PICC) + { + converted = NET_NFC_FELICA_ENABLE; + } + else if (type == NET_NFC_JEWEL_PICC) + { + converted = NET_NFC_FELICA_ENABLE; + } + else if (type == NET_NFC_ISO15693_PICC) + { + converted = NET_NFC_ISO15693_ENABLE; + } + + if ((converted & current_filter) == 0) + { + return false; + } + + return true; +} diff --git a/src/clientlib/net_nfc_client_tag_felica.c b/src/clientlib/net_nfc_client_tag_felica.c new file mode 100755 index 0000000..9c4a5c0 --- /dev/null +++ b/src/clientlib/net_nfc_client_tag_felica.c @@ -0,0 +1,491 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "net_nfc_tag.h" +#include "net_nfc_typedef_private.h" +#include "net_nfc_client_ipc_private.h" +#include "net_nfc_debug_private.h" +#include "net_nfc_util_private.h" +#include "net_nfc_client_nfc_private.h" +#include "net_nfc_tag_felica.h" +#include "net_nfc_target_info.h" + +#include + +#ifndef NET_NFC_EXPORT_API +#define NET_NFC_EXPORT_API __attribute__((visibility("default"))) +#endif + +#define FELICA_CMD_POLL 0x00 +#define FELICA_CMD_REQ_SERVICE 0x02 +#define FELICA_CMD_REQ_RESPONSE 0x04 +#define FELICA_CMD_READ_WITHOUT_ENC 0x06 +#define FELICA_CMD_WRITE_WITHOUT_ENC 0x08 +#define FELICA_CMD_REQ_SYSTEM_CODE 0x0C +#define FELICA_TAG_KEY "IDm" + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_felica_poll(net_nfc_target_handle_h handle, net_nfc_felica_poll_request_code_e req_code, uint8_t time_slote, void* trans_param) +{ + if (handle == NULL) + return NET_NFC_NULL_PARAMETER; + + if (!net_nfc_tag_is_connected()) + { + return NET_NFC_OPERATION_FAIL; + } + + client_context_t* client_context_tmp = net_nfc_get_client_context(); + net_nfc_target_info_s* target_info = NULL; + + if ((target_info = client_context_tmp->target_info) == NULL) + { + return NET_NFC_NO_DATA_FOUND; + } + + if (target_info->devType != NET_NFC_FELICA_PICC) + { + DEBUG_CLIENT_MSG("only felica tag is available"); + return NET_NFC_NOT_ALLOWED_OPERATION; + } + + uint8_t send_buffer[6] = { 0x00, }; + + /* total size of requet command */ + send_buffer[0] = 0x06; + send_buffer[1] = FELICA_CMD_POLL; + + /* use wild card for system code */ + send_buffer[2] = 0xff; + send_buffer[3] = 0xff; + + send_buffer[4] = req_code; + send_buffer[5] = time_slote; + + DEBUG_MSG_PRINT_BUFFER(send_buffer, 6); + + data_s rawdata; + + rawdata.buffer = send_buffer; + rawdata.length = 6; + + return net_nfc_transceive(handle, (data_h)&rawdata, trans_param); +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_felica_request_service(net_nfc_target_handle_h handle, uint8_t number_of_area_service, uint16_t area_service_list[], uint8_t number_of_services, void* trans_param) +{ + if (handle == NULL || area_service_list == NULL) + return NET_NFC_NULL_PARAMETER; + + if (!net_nfc_tag_is_connected()) + { + return NET_NFC_OPERATION_FAIL; + } + + client_context_t* client_context_tmp = net_nfc_get_client_context(); + net_nfc_target_info_s* target_info = NULL; + + if ((target_info = client_context_tmp->target_info) == NULL) + { + return NET_NFC_NO_DATA_FOUND; + } + + if (target_info->devType != NET_NFC_FELICA_PICC) + { + DEBUG_CLIENT_MSG("only Jewel tag is available"); + return NET_NFC_NOT_ALLOWED_OPERATION; + } + + data_h IDm = NULL; + + if (net_nfc_get_tag_info_value((net_nfc_target_info_h)target_info, FELICA_TAG_KEY, &IDm) != NET_NFC_OK) + { + return NET_NFC_NO_DATA_FOUND; + } + + if (((data_s*)IDm)->length != 8) + { + + return NET_NFC_OUT_OF_BOUND; + } + + if (number_of_area_service > 32) + { + return NET_NFC_OUT_OF_BOUND; + } + + uint32_t send_buffer_length = 1 + 1 + 8 + 1 + (2 * number_of_services); /* size + cmd + UID + number of service service count + service list */ + uint8_t* send_buffer = NULL; + uint8_t* temp = NULL; + + _net_nfc_util_alloc_mem(send_buffer, send_buffer_length * sizeof(uint8_t)); + if (send_buffer == NULL) + { + return NET_NFC_ALLOC_FAIL; + } + + temp = send_buffer; + + /* set cmd length */ + *send_buffer = send_buffer_length; + send_buffer++; + + /* set cmd */ + *send_buffer = FELICA_CMD_REQ_SERVICE; + send_buffer++; + + /* set IDm */ + memcpy(send_buffer, ((data_s*)IDm)->buffer, ((data_s*)IDm)->length); + send_buffer = send_buffer + ((data_s*)IDm)->length; + + /* set the number of service codes */ + *send_buffer = number_of_area_service; + send_buffer++; + + int i = 0; + + for (; i < number_of_services; i++) + { + memcpy(send_buffer, &area_service_list[i], sizeof(uint16_t)); + send_buffer = send_buffer + 2; + } + + DEBUG_MSG_PRINT_BUFFER(temp, send_buffer_length); + + data_s rawdata; + + rawdata.buffer = send_buffer; + rawdata.length = send_buffer_length; + + net_nfc_error_e result = NET_NFC_OK; + result = net_nfc_transceive(handle, (data_h)&rawdata, trans_param); + + if (temp != NULL) + _net_nfc_util_free_mem(temp); + + return result; +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_felica_request_response(net_nfc_target_handle_h handle, void* trans_param) +{ + if (handle == NULL) + return NET_NFC_NULL_PARAMETER; + + if (!net_nfc_tag_is_connected()) + { + return NET_NFC_OPERATION_FAIL; + } + + client_context_t* client_context_tmp = net_nfc_get_client_context(); + net_nfc_target_info_s* target_info = NULL; + + if ((target_info = client_context_tmp->target_info) == NULL) + { + return NET_NFC_NO_DATA_FOUND; + } + + if (target_info->devType != NET_NFC_FELICA_PICC) + { + DEBUG_CLIENT_MSG("only Jewel tag is available"); + return NET_NFC_NOT_ALLOWED_OPERATION; + } + + data_h IDm = NULL; + + if (net_nfc_get_tag_info_value((net_nfc_target_info_h)target_info, FELICA_TAG_KEY, &IDm) != NET_NFC_OK) + { + return NET_NFC_NO_DATA_FOUND; + } + + if (((data_s*)IDm)->length != 8) + { + + return NET_NFC_OUT_OF_BOUND; + } + + uint8_t send_buffer[10] = { 0x00, }; + + send_buffer[0] = 0xA; + send_buffer[1] = FELICA_CMD_REQ_RESPONSE; + + memcpy(send_buffer + 2, ((data_s*)IDm)->buffer, ((data_s*)IDm)->length); + + DEBUG_MSG_PRINT_BUFFER(send_buffer, 10); + + data_s rawdata; + + rawdata.buffer = send_buffer; + rawdata.length = 10; + + return net_nfc_transceive(handle, (data_h)&rawdata, trans_param); +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_felica_read_without_encryption(net_nfc_target_handle_h handle, uint8_t number_of_services, uint16_t service_list[], uint8_t number_of_blocks, uint8_t block_list[], void* trans_param) +{ + if (handle == NULL || service_list == NULL || block_list == NULL) + return NET_NFC_NULL_PARAMETER; + + if (!net_nfc_tag_is_connected()) + { + return NET_NFC_OPERATION_FAIL; + } + + client_context_t* client_context_tmp = net_nfc_get_client_context(); + net_nfc_target_info_s* target_info = NULL; + + if ((target_info = client_context_tmp->target_info) == NULL) + { + return NET_NFC_NO_DATA_FOUND; + } + + if (target_info->devType != NET_NFC_FELICA_PICC) + { + DEBUG_CLIENT_MSG("only Jewel tag is available"); + return NET_NFC_NOT_ALLOWED_OPERATION; + } + + data_h IDm = NULL; + + if (net_nfc_get_tag_info_value((net_nfc_target_info_h)target_info, FELICA_TAG_KEY, &IDm) != NET_NFC_OK) + { + return NET_NFC_NO_DATA_FOUND; + } + + if (((data_s*)IDm)->length != 8) + { + + return NET_NFC_OUT_OF_BOUND; + } + + if (number_of_services > 16) + { + return NET_NFC_OUT_OF_BOUND; + } + + uint32_t send_buffer_length = 1 + 1 + 8 + 1 + (2 * number_of_services) + 1 + number_of_blocks; + uint8_t* send_buffer = NULL; + uint8_t* temp = NULL; + + _net_nfc_util_alloc_mem(send_buffer, send_buffer_length * sizeof(uint8_t)); + if (send_buffer == NULL) + { + return NET_NFC_ALLOC_FAIL; + } + + temp = send_buffer; + + *send_buffer = send_buffer_length; + send_buffer++; + + *send_buffer = FELICA_CMD_READ_WITHOUT_ENC; + send_buffer++; + + memcpy(send_buffer, ((data_s*)IDm)->buffer, ((data_s*)IDm)->length); + send_buffer = send_buffer + ((data_s*)IDm)->length; + + *send_buffer = number_of_services; + send_buffer++; + + int i = 0; + for (; i < number_of_services; i++) + { + memcpy(send_buffer, &service_list[i], sizeof(uint16_t)); + send_buffer = send_buffer + 2; + } + + *send_buffer = number_of_blocks; + send_buffer++; + + for (i = 0; i < number_of_blocks; i++) + { + memcpy(send_buffer, &block_list[i], sizeof(uint8_t)); + send_buffer++; + } + + DEBUG_MSG_PRINT_BUFFER(temp, send_buffer_length); + + data_s rawdata; + + rawdata.buffer = temp; + rawdata.length = send_buffer_length; + + net_nfc_error_e result = NET_NFC_OK; + result = net_nfc_transceive(handle, (data_h)&rawdata, trans_param); + + if (temp != NULL) + _net_nfc_util_free_mem(temp); + + return result; +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_felica_write_without_encryption(net_nfc_target_handle_h handle, uint8_t number_of_services, uint16_t service_list[], uint8_t number_of_blocks, uint8_t block_list[], data_h data, void* trans_param) +{ + if (handle == NULL || service_list == NULL || block_list == NULL || data == NULL) + return NET_NFC_NULL_PARAMETER; + + if (!net_nfc_tag_is_connected()) + { + return NET_NFC_OPERATION_FAIL; + } + + client_context_t* client_context_tmp = net_nfc_get_client_context(); + net_nfc_target_info_s* target_info = NULL; + + if ((target_info = client_context_tmp->target_info) == NULL) + { + return NET_NFC_NO_DATA_FOUND; + } + + if (target_info->devType != NET_NFC_FELICA_PICC) + { + DEBUG_CLIENT_MSG("only Jewel tag is available"); + return NET_NFC_NOT_ALLOWED_OPERATION; + } + + data_h IDm = NULL; + + if (net_nfc_get_tag_info_value((net_nfc_target_info_h)target_info, FELICA_TAG_KEY, &IDm) != NET_NFC_OK) + { + return NET_NFC_NO_DATA_FOUND; + } + + if (((data_s*)IDm)->length != 8) + { + + return NET_NFC_OUT_OF_BOUND; + } + + if (number_of_services > 16) + { + return NET_NFC_OUT_OF_BOUND; + } + + if (((data_s*)data)->length > 16 * number_of_blocks) + { + return NET_NFC_OUT_OF_BOUND; + } + + uint32_t send_buffer_length = 1 + 1 + 8 + 1 + (2 * number_of_services) + 1 + number_of_blocks + ((data_s*)data)->length; + uint8_t* send_buffer = NULL; + uint8_t* temp = NULL; + + _net_nfc_util_alloc_mem(send_buffer, send_buffer_length * sizeof(uint8_t)); + if (send_buffer == NULL) + { + return NET_NFC_ALLOC_FAIL; + } + + temp = send_buffer; + + *send_buffer = send_buffer_length; + send_buffer++; + + *send_buffer = FELICA_CMD_WRITE_WITHOUT_ENC; + send_buffer++; + + memcpy(send_buffer, ((data_s*)IDm)->buffer, ((data_s*)IDm)->length); + send_buffer = send_buffer + ((data_s*)IDm)->length; + + *send_buffer = number_of_services; + send_buffer++; + + int i = 0; + for (; i < number_of_services; i++) + { + memcpy(send_buffer, &service_list[i], sizeof(uint16_t)); + send_buffer = send_buffer + 2; + } + + *send_buffer = number_of_blocks; + send_buffer++; + + for (i = 0; i < number_of_blocks; i++) + { + memcpy(send_buffer, &block_list[i], sizeof(uint8_t)); + send_buffer++; + } + + memcpy(send_buffer, ((data_s*)data)->buffer, ((data_s*)data)->length); + + DEBUG_MSG_PRINT_BUFFER(temp, send_buffer_length); + + data_s rawdata; + + rawdata.buffer = temp; + rawdata.length = send_buffer_length; + + net_nfc_error_e result = NET_NFC_OK; + + result = net_nfc_transceive(handle, (data_h)&rawdata, trans_param); + + if (temp != NULL) + _net_nfc_util_free_mem(temp); + + return result; +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_felica_request_system_code(net_nfc_target_handle_h handle, void* trans_param) +{ + if (handle == NULL) + return NET_NFC_NULL_PARAMETER; + + if (!net_nfc_tag_is_connected()) + { + return NET_NFC_OPERATION_FAIL; + } + + client_context_t* client_context_tmp = net_nfc_get_client_context(); + net_nfc_target_info_s* target_info = NULL; + + if ((target_info = client_context_tmp->target_info) == NULL) + { + return NET_NFC_NO_DATA_FOUND; + } + + if (target_info->devType != NET_NFC_FELICA_PICC) + { + DEBUG_CLIENT_MSG("only Jewel tag is available"); + return NET_NFC_NOT_ALLOWED_OPERATION; + } + + data_h IDm = NULL; + + if (net_nfc_get_tag_info_value((net_nfc_target_info_h)target_info, FELICA_TAG_KEY, &IDm) != NET_NFC_OK) + { + return NET_NFC_NO_DATA_FOUND; + } + + if (((data_s*)IDm)->length != 8) + { + + return NET_NFC_OUT_OF_BOUND; + } + + uint8_t send_buffer[10] = { 0x00, }; + + send_buffer[0] = 0xA; + send_buffer[1] = FELICA_CMD_REQ_SYSTEM_CODE; + + memcpy(send_buffer + 2, ((data_s *)IDm)->buffer, ((data_s *)IDm)->length); + + DEBUG_MSG_PRINT_BUFFER(send_buffer, 10); + + data_s rawdata; + + rawdata.buffer = send_buffer; + rawdata.length = 10; + + return net_nfc_transceive(handle, (data_h)&rawdata, trans_param); +} diff --git a/src/clientlib/net_nfc_client_tag_jewel.c b/src/clientlib/net_nfc_client_tag_jewel.c new file mode 100755 index 0000000..3674174 --- /dev/null +++ b/src/clientlib/net_nfc_client_tag_jewel.c @@ -0,0 +1,333 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "net_nfc_tag.h" +#include "net_nfc_typedef_private.h" +#include "net_nfc_client_ipc_private.h" +#include "net_nfc_debug_private.h" +#include "net_nfc_util_private.h" +#include "net_nfc_client_nfc_private.h" +#include "net_nfc_tag_jewel.h" +#include "net_nfc_target_info.h" + +#include + +#ifndef NET_NFC_EXPORT_API +#define NET_NFC_EXPORT_API __attribute__((visibility("default"))) +#endif + + + +#define JEWEL_CMD_REQA 0x26 +#define JEWEL_CMD_WUPA 0x52 +#define JEWEL_CMD_RID 0x78 +#define JEWEL_CMD_RALL 0x00 +#define JEWEL_CMD_READ 0x01 +#define JEWEL_CMD_WRITE_E 0x53 +#define JEWEL_CMD_WRITE_NE 0x1A +#define JEWEL_TAG_KEY "UID" + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_jewel_read_id (net_nfc_target_handle_h handle, void* trans_param) +{ + if(handle == NULL) + return NET_NFC_NULL_PARAMETER; + + if(!net_nfc_tag_is_connected()){ + return NET_NFC_OPERATION_FAIL; + } + + client_context_t* client_context_tmp = net_nfc_get_client_context(); + net_nfc_target_info_s* target_info = NULL; + + if((target_info = client_context_tmp->target_info) == NULL){ + return NET_NFC_NO_DATA_FOUND; + } + + if(target_info->devType != NET_NFC_JEWEL_PICC){ + DEBUG_CLIENT_MSG("only Jewel tag is available"); + return NET_NFC_NOT_ALLOWED_OPERATION; + } + + uint8_t send_buffer[9] = {0x00, }; + send_buffer[0] = JEWEL_CMD_RID; + + net_nfc_util_compute_CRC(CRC_B, send_buffer, 9); + + DEBUG_MSG_PRINT_BUFFER(send_buffer, 9); + + data_s rawdata; + + rawdata.buffer = send_buffer; + rawdata.length = 9; + + return net_nfc_transceive(handle, (data_h)&rawdata, trans_param); + + +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_jewel_read_byte (net_nfc_target_handle_h handle, uint8_t block, uint8_t byte, void* trans_param) +{ + if(handle == NULL) + return NET_NFC_NULL_PARAMETER; + + if(block > 0xE || byte > 0x7 ){ + + return NET_NFC_OUT_OF_BOUND; + } + + if(!net_nfc_tag_is_connected()){ + return NET_NFC_OPERATION_FAIL; + } + + client_context_t* client_context_tmp = net_nfc_get_client_context(); + net_nfc_target_info_s* target_info = NULL; + + if((target_info = client_context_tmp->target_info) == NULL){ + return NET_NFC_NO_DATA_FOUND; + } + + if(target_info->devType != NET_NFC_JEWEL_PICC){ + DEBUG_CLIENT_MSG("only Jewel tag is available"); + return NET_NFC_NOT_ALLOWED_OPERATION; + } + + data_h UID = NULL; + + if(net_nfc_get_tag_info_value((net_nfc_target_info_h)target_info, JEWEL_TAG_KEY, &UID) != NET_NFC_OK){ + return NET_NFC_NO_DATA_FOUND; + } + + + if(((data_s*)UID)->length != 4){ + + return NET_NFC_OUT_OF_BOUND; + } + + uint8_t send_buffer[9] = {0x00, }; + + /* command */ + send_buffer[0] = JEWEL_CMD_READ; + + /* addr */ + send_buffer[1] = (((block << 3) & 0x78) | (byte & 0x7)); + + /* data */ + send_buffer[2] = 0x00; + + /* UID0 ~ 3 */ + memcpy(&(send_buffer[3]), ((data_s*)UID)->buffer, ((data_s*)UID)->length); + + net_nfc_util_compute_CRC(CRC_B, send_buffer, 9); + + DEBUG_MSG_PRINT_BUFFER(send_buffer, 9); + + data_s rawdata; + + rawdata.buffer = send_buffer; + rawdata.length = 9; + + return net_nfc_transceive(handle, (data_h)&rawdata, trans_param); +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_jewel_read_all (net_nfc_target_handle_h handle, void* trans_param) +{ + if(handle == NULL ) + return NET_NFC_NULL_PARAMETER; + + if(!net_nfc_tag_is_connected()){ + return NET_NFC_OPERATION_FAIL; + } + + client_context_t* client_context_tmp = net_nfc_get_client_context(); + net_nfc_target_info_s* target_info = NULL; + + if((target_info = client_context_tmp->target_info) == NULL){ + return NET_NFC_NO_DATA_FOUND; + } + + if(target_info->devType != NET_NFC_JEWEL_PICC){ + DEBUG_CLIENT_MSG("only Jewel tag is available"); + return NET_NFC_NOT_ALLOWED_OPERATION; + } + + data_h UID = NULL; + + if(net_nfc_get_tag_info_value((net_nfc_target_info_h)target_info, JEWEL_TAG_KEY, &UID) != NET_NFC_OK){ + return NET_NFC_NO_DATA_FOUND; + } + + if(((data_s*)UID)->length != 4){ + + return NET_NFC_OUT_OF_BOUND; + } + + uint8_t send_buffer[9] = {0x00, }; + + /* command */ + send_buffer[0] = JEWEL_CMD_RALL; + + /* addr */ + send_buffer[1] = 0x00; + + /* data */ + send_buffer[2] = 0x00; + + /* UID0 ~ 3 */ + memcpy(&(send_buffer[3]), ((data_s*)UID)->buffer, ((data_s*)UID)->length); + + net_nfc_util_compute_CRC(CRC_B, send_buffer, 9); + + DEBUG_MSG_PRINT_BUFFER(send_buffer, 9); + + + data_s rawdata; + + rawdata.buffer = send_buffer; + rawdata.length = 9; + + return net_nfc_transceive(handle, (data_h)&rawdata, trans_param); + + +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_jewel_write_with_erase (net_nfc_target_handle_h handle, uint8_t block, uint8_t byte, uint8_t data, void* trans_param) +{ + if(handle == NULL) + return NET_NFC_NULL_PARAMETER; + + + if(block > 0xE || byte > 0x7 ){ + + return NET_NFC_OUT_OF_BOUND; + } + + if(!net_nfc_tag_is_connected()){ + return NET_NFC_OPERATION_FAIL; + } + + client_context_t* client_context_tmp = net_nfc_get_client_context(); + net_nfc_target_info_s* target_info = NULL; + + if((target_info = client_context_tmp->target_info) == NULL){ + return NET_NFC_NO_DATA_FOUND; + } + + if((target_info = client_context_tmp->target_info) == NULL){ + return NET_NFC_NO_DATA_FOUND; + } + + data_h UID = NULL; + + if(net_nfc_get_tag_info_value((net_nfc_target_info_h)target_info, JEWEL_TAG_KEY, &UID) != NET_NFC_OK){ + return NET_NFC_NO_DATA_FOUND; + } + + if(((data_s*)UID)->length != 4){ + + return NET_NFC_OUT_OF_BOUND; + } + + + uint8_t send_buffer[9] = {0x00, }; + + /* command */ + send_buffer[0] = JEWEL_CMD_WRITE_E; + + /* addr */ + send_buffer[1] = (((block << 3) & 0x78) | (byte & 0x7)); + + /* data */ + send_buffer[2] = data; + + /* UID0 ~ 3 */ + memcpy(&(send_buffer[3]), ((data_s*)UID)->buffer, ((data_s*)UID)->length); + + net_nfc_util_compute_CRC(CRC_B, send_buffer, 9); + + DEBUG_MSG_PRINT_BUFFER(send_buffer, 9); + + data_s rawdata; + + rawdata.buffer = send_buffer; + rawdata.length = 9; + + return net_nfc_transceive(handle, (data_h)&rawdata, trans_param); + +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_jewel_write_with_no_erase (net_nfc_target_handle_h handle, uint8_t block, uint8_t byte, uint8_t data, void* trans_param) +{ + if(handle == NULL) + return NET_NFC_NULL_PARAMETER; + + if(block > 0xE || byte > 0x7 ){ + + return NET_NFC_OUT_OF_BOUND; + } + + if(!net_nfc_tag_is_connected()){ + return NET_NFC_OPERATION_FAIL; + } + + client_context_t* client_context_tmp = net_nfc_get_client_context(); + net_nfc_target_info_s* target_info = NULL; + + if((target_info = client_context_tmp->target_info) == NULL){ + return NET_NFC_NO_DATA_FOUND; + } + + if(target_info->devType != NET_NFC_JEWEL_PICC){ + DEBUG_CLIENT_MSG("only Jewel tag is available"); + return NET_NFC_NOT_ALLOWED_OPERATION; + } + + data_h UID = NULL; + + if(net_nfc_get_tag_info_value((net_nfc_target_info_h)target_info, JEWEL_TAG_KEY, &UID) != NET_NFC_OK){ + return NET_NFC_NO_DATA_FOUND; + } + + if(((data_s*)UID)->length != 4){ + + return NET_NFC_OUT_OF_BOUND; + } + + uint8_t send_buffer[9] = {0x00, }; + + /* command */ + send_buffer[0] = JEWEL_CMD_WRITE_NE; + + /* addr */ + send_buffer[1] = (((block << 3) & 0x78) | (byte & 0x7)); + + /* data */ + send_buffer[2] = data; + + /* UID0 ~ 3 */ + memcpy(&(send_buffer[3]), ((data_s*)UID)->buffer, ((data_s*)UID)->length); + + net_nfc_util_compute_CRC(CRC_B, send_buffer, 9); + + DEBUG_MSG_PRINT_BUFFER(send_buffer, 9); + + data_s rawdata; + + rawdata.buffer = send_buffer; + rawdata.length = 9; + + return net_nfc_transceive(handle, (data_h)&rawdata, trans_param); +} + diff --git a/src/clientlib/net_nfc_client_tag_mifare.c b/src/clientlib/net_nfc_client_tag_mifare.c new file mode 100755 index 0000000..7549ccf --- /dev/null +++ b/src/clientlib/net_nfc_client_tag_mifare.c @@ -0,0 +1,947 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "net_nfc_tag.h" +#include "net_nfc_data.h" +#include "net_nfc_typedef_private.h" +#include "net_nfc_client_ipc_private.h" +#include "net_nfc_debug_private.h" +#include "net_nfc_client_nfc_private.h" +#include "net_nfc_tag_mifare.h" +#include "net_nfc_target_info.h" +#include "net_nfc_util_private.h" + +#include + +#ifndef NET_NFC_EXPORT_API +#define NET_NFC_EXPORT_API __attribute__((visibility("default"))) +#endif + +#define MIFARE_CMD_RAW 0x00U +#define MIFARE_CMD_AUTH_A 0x60U /**< authenticate with key A */ +#define MIFARE_CMD_AUTH_B 0x61U /**< authenticate with key B */ +#define MIFARE_CMD_READ 0x30U /**< read 16 bytes */ +#define MIFARE_CMD_WRITE_BLOCK 0xA0U /**< write 16 bytes */ +#define MIFARE_CMD_WRITE_PAGE 0xA2U /**< write 4 bytes */ +#define MIFARE_CMD_INCREMENT 0xC1U /**< Increment. */ +#define MIFARE_CMD_DECREMENT 0xC0U /**< Decrement. */ +#define MIFARE_CMD_TRANSFER 0xB0U /**< Tranfer. */ +#define MIFARE_CMD_RESTORE 0xC2U /**< Restore. */ +#define MIFARE_TAG_KEY "UID" + +#define MIFARE_CMD_READ_SECTOR 0x38U /* read sector */ +#define MIFARE_CMD_WRITE_SECTOR 0xA8U /* write sector */ + +static uint8_t default_key[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; +static uint8_t mad_key[6] = { 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5 }; +static uint8_t net_nfc_forum_key[6] = { 0xD3, 0xF7, 0xD3, 0xF7, 0xD3, 0xF7 }; + +#define MIFARE_BLOCK_4 4 +#define MIFARE_BLOCK_16 16 + +#define MIFARE_MINI_SECTORS 5 +#define MIFARE_1K_SECTORS 16 +#define MIFARE_4K_SECTORS 40 + +#define MIFARE_BLOCK_SIZE 16 /* 1 block is 16 byte */ +#define MIFARE_PAGE_SIZE 4 /* 1 page is 4 byte */ + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_mifare_authenticate_with_keyA(net_nfc_target_handle_h handle, uint8_t sector, data_h auth_key, void* trans_param) +{ + if (handle == NULL || auth_key == NULL) + return NET_NFC_NULL_PARAMETER; + + if (!net_nfc_tag_is_connected()) + { + return NET_NFC_OPERATION_FAIL; + } + + data_s* key = (data_s*)auth_key; + + if (key->length != 6) + { + return NET_NFC_OUT_OF_BOUND; + } + + client_context_t* tmp_client_context = net_nfc_get_client_context(); + + net_nfc_target_info_s* target_info = NULL; + + if (tmp_client_context != NULL) + { + + target_info = tmp_client_context->target_info; + + if (target_info != NULL) + { + + if (target_info->devType < NET_NFC_MIFARE_MINI_PICC || target_info->devType > NET_NFC_MIFARE_4K_PICC) + { + DEBUG_CLIENT_MSG("This is not MIFARE Classic TAG \n"); + return NET_NFC_NOT_SUPPORTED; + } + } + } + + data_h UID = NULL; + + if (net_nfc_get_tag_info_value((net_nfc_target_info_h)target_info, MIFARE_TAG_KEY, &UID) != NET_NFC_OK) + { + return NET_NFC_NO_DATA_FOUND; + } + + uint8_t* send_buffer = NULL; + int send_buffer_length = 0; + + uint8_t sector_to_block = 0; + + switch (target_info->devType) + { + case NET_NFC_MIFARE_MINI_PICC : + { + /* 0 ~ 4 : 5 sector and 4 block with 16 bytes */ + if (sector > MIFARE_MINI_SECTORS - 1) + { + + return NET_NFC_OUT_OF_BOUND; + } + else + { + + sector_to_block = sector * MIFARE_BLOCK_4 + 3; + } + } + break; + case NET_NFC_MIFARE_1K_PICC : + { + /* 0 ~ 15 : 16 sector and 4 block with 16 bytes */ + if (sector > MIFARE_1K_SECTORS) + { + + return NET_NFC_OUT_OF_BOUND; + } + else + { + + sector_to_block = sector * MIFARE_BLOCK_4 + 3; + } + } + break; + case NET_NFC_MIFARE_4K_PICC : + { + /* 0 ~ 31 : 32 sector and 4 block with 16 bytes + * 32 ~ 39 : 8 sector and 16 block with 16 bytes + */ + if (sector > MIFARE_4K_SECTORS) + { + + return NET_NFC_OUT_OF_BOUND; + } + else + { + + if (sector < 32) + { + + sector_to_block = sector * MIFARE_BLOCK_4 + 3; + } + else + { + + sector_to_block = (31 * MIFARE_BLOCK_4 + 3) + (sector - 32) * MIFARE_BLOCK_16 + 15; + } + } + } + break; + default : + break; + } + + uint8_t* temp = NULL; + send_buffer_length = 1 + 1 + ((data_s*)UID)->length + key->length + 2; /* cmd + addr + UID + AUTH_KEY + CRC_A */ + + _net_nfc_util_alloc_mem(send_buffer, send_buffer_length * sizeof(uint8_t)); + if (send_buffer == NULL) + { + + net_nfc_free_data(UID); + return NET_NFC_ALLOC_FAIL; + } + + temp = send_buffer; + + *temp = MIFARE_CMD_AUTH_A; + temp++; + + *temp = sector_to_block; + temp++; + + memcpy(temp, ((data_s*)UID)->buffer, ((data_s*)UID)->length); + temp = temp + ((data_s*)UID)->length; + + memcpy(temp, key->buffer, key->length); + + net_nfc_util_compute_CRC(CRC_A, send_buffer, send_buffer_length); + + data_s rawdata; + + rawdata.buffer = send_buffer; + rawdata.length = send_buffer_length; + + net_nfc_error_e result = net_nfc_transceive(handle, (data_h)&rawdata, trans_param); + + if (send_buffer != NULL) + { + + _net_nfc_util_free_mem(send_buffer); + } + + return result; + +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_mifare_authenticate_with_keyB(net_nfc_target_handle_h handle, uint8_t sector, data_h auth_key, void* trans_param) +{ + if (handle == NULL || auth_key == NULL) + return NET_NFC_NULL_PARAMETER; + + if (!net_nfc_tag_is_connected()) + { + return NET_NFC_OPERATION_FAIL; + } + + data_s* key = (data_s*)auth_key; + + if (key->length != 6) + { + return NET_NFC_OUT_OF_BOUND; + } + + client_context_t* tmp_client_context = net_nfc_get_client_context(); + + net_nfc_target_info_s* target_info = NULL; + + if (tmp_client_context != NULL) + { + + target_info = tmp_client_context->target_info; + + if (target_info != NULL) + { + + if (target_info->devType < NET_NFC_MIFARE_MINI_PICC || target_info->devType > NET_NFC_MIFARE_4K_PICC) + { + DEBUG_CLIENT_MSG("This is not MIFARE Classic TAG \n"); + return NET_NFC_NOT_SUPPORTED; + } + } + } + + data_h UID = NULL; + + if (net_nfc_get_tag_info_value((net_nfc_target_info_h)target_info, MIFARE_TAG_KEY, &UID) != NET_NFC_OK) + { + return NET_NFC_NO_DATA_FOUND; + } + + uint8_t* send_buffer = NULL; + int send_buffer_length = 0; + + uint8_t sector_to_block = 0; + + switch (target_info->devType) + { + case NET_NFC_MIFARE_MINI_PICC : + { + /* 0 ~ 4 : 5 sector and 4 block with 16 bytes */ + if (sector > MIFARE_MINI_SECTORS) + { + return NET_NFC_OUT_OF_BOUND; + } + else + { + sector_to_block = sector * MIFARE_BLOCK_4 + 3; + } + } + break; + case NET_NFC_MIFARE_1K_PICC : + { + /* 0 ~ 15 : 16 sector and 4 block with 16 bytes */ + if (sector > MIFARE_1K_SECTORS) + { + return NET_NFC_OUT_OF_BOUND; + } + else + { + sector_to_block = sector * MIFARE_BLOCK_4 + 3; + } + } + break; + case NET_NFC_MIFARE_4K_PICC : + { + /* 0 ~ 31 : 32 sector and 4 block with 16 bytes + * 32 ~ 39 : 8 sector and 16 block with 16 bytes + */ + if (sector > MIFARE_4K_SECTORS) + { + return NET_NFC_OUT_OF_BOUND; + } + else + { + if (sector < 32) + { + sector_to_block = sector * MIFARE_BLOCK_4 + 3; + } + else + { + sector_to_block = (31 * MIFARE_BLOCK_4 + 3) + (sector - 32) * MIFARE_BLOCK_16 + 15; + } + } + } + break; + default : + break; + } + + uint8_t* temp = NULL; + send_buffer_length = 1 + 1 + ((data_s*)UID)->length + key->length + 2; /* cmd + addr + UID + AUTH_KEY + CRC_A */ + + _net_nfc_util_alloc_mem(send_buffer, send_buffer_length * sizeof(uint8_t)); + if (send_buffer == NULL) + { + + net_nfc_free_data(UID); + return NET_NFC_ALLOC_FAIL; + } + + temp = send_buffer; + + *temp = MIFARE_CMD_AUTH_B; + temp++; + + *temp = sector_to_block; + temp++; + + memcpy(temp, ((data_s*)UID)->buffer, ((data_s*)UID)->length); + temp = temp + ((data_s*)UID)->length; + + memcpy(temp, key->buffer, key->length); + + net_nfc_util_compute_CRC(CRC_A, send_buffer, send_buffer_length); + + data_s rawdata; + + rawdata.buffer = send_buffer; + rawdata.length = send_buffer_length; + + net_nfc_error_e result = net_nfc_transceive(handle, (data_h)&rawdata, trans_param); + + if (send_buffer != NULL) + { + _net_nfc_util_free_mem(send_buffer); + } + + return result; + +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_mifare_read(net_nfc_target_handle_h handle, uint8_t addr, void* trans_param) +{ + if (handle == NULL) + return NET_NFC_NULL_PARAMETER; + + if (!net_nfc_tag_is_connected()) + { + return NET_NFC_OPERATION_FAIL; + } + + client_context_t* tmp_client_context = net_nfc_get_client_context(); + + net_nfc_target_info_s* target_info = NULL; + + if (tmp_client_context != NULL) + { + + target_info = tmp_client_context->target_info; + + if (target_info != NULL) + { + + if (target_info->devType < NET_NFC_MIFARE_MINI_PICC || target_info->devType > NET_NFC_MIFARE_ULTRA_PICC) + { + DEBUG_CLIENT_MSG("This is not MIFARE TAG = [%d] \n", target_info->devType); + return NET_NFC_NOT_SUPPORTED; + } + + if (target_info->devType == NET_NFC_MIFARE_ULTRA_PICC) + { + + if (addr > 7) + { + return NET_NFC_OUT_OF_BOUND; + } + } + } + } + + uint8_t send_buffer[4] = { 0 }; + + send_buffer[0] = MIFARE_CMD_READ; + send_buffer[1] = addr; + + net_nfc_util_compute_CRC(CRC_A, send_buffer, 4); + + data_s rawdata; + + rawdata.buffer = send_buffer; + rawdata.length = 4; + + return net_nfc_transceive(handle, (data_h)&rawdata, trans_param); +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_mifare_write_block(net_nfc_target_handle_h handle, uint8_t addr, data_h data, void* trans_param) +{ + if (handle == NULL) + return NET_NFC_NULL_PARAMETER; + + if (!net_nfc_tag_is_connected()) + { + return NET_NFC_OPERATION_FAIL; + } + + client_context_t* tmp_client_context = net_nfc_get_client_context(); + + net_nfc_target_info_s* target_info = NULL; + + if (tmp_client_context != NULL) + { + + target_info = tmp_client_context->target_info; + + if (target_info != NULL) + { + + if (target_info->devType < NET_NFC_MIFARE_MINI_PICC || target_info->devType > NET_NFC_MIFARE_ULTRA_PICC) + { + DEBUG_CLIENT_MSG("This is not MIFARE TAG = [%d] \n", target_info->devType); + return NET_NFC_NOT_SUPPORTED; + } + + if (target_info->devType == NET_NFC_MIFARE_ULTRA_PICC) + { + + if (addr > 7) + { + return NET_NFC_OUT_OF_BOUND; + } + } + } + else + { + return NET_NFC_NOT_INITIALIZED; + } + } + else + { + return NET_NFC_NOT_INITIALIZED; + } + + uint8_t* send_buffer = NULL; + uint32_t send_buffer_length = 0; + + if (target_info->devType == NET_NFC_MIFARE_ULTRA_PICC) + { + + if (((data_s*)data)->length > MIFARE_PAGE_SIZE) + { + + send_buffer_length = 1 + 1 + MIFARE_PAGE_SIZE + 2; /* cmd + addr + page + CRC */ + + uint8_t* temp = NULL; + _net_nfc_util_alloc_mem(send_buffer, send_buffer_length * sizeof(uint8_t)); + if (send_buffer == NULL) + return NET_NFC_ALLOC_FAIL; + + temp = send_buffer; + + *temp = MIFARE_CMD_WRITE_PAGE; + temp++; + + *temp = addr; + temp++; + + memcpy(temp, ((data_s*)data)->buffer, MIFARE_PAGE_SIZE); + + } + else + { + + send_buffer_length = 1 + 1 + ((data_s*)data)->length + 2; /* cmd + addr + page + CRC */ + + uint8_t* temp = NULL; + _net_nfc_util_alloc_mem(send_buffer, send_buffer_length * sizeof(uint8_t)); + if (send_buffer == NULL) + return NET_NFC_ALLOC_FAIL; + + temp = send_buffer; + + *temp = MIFARE_CMD_WRITE_PAGE; + temp++; + + *temp = addr; + temp++; + + memcpy(temp, ((data_s*)data)->buffer, ((data_s*)data)->length); + } + + } + else + { + + if (((data_s*)data)->length > MIFARE_BLOCK_SIZE) + { + + send_buffer_length = 1 + 1 + MIFARE_BLOCK_SIZE + 2; /* cmd + addr + page + CRC */ + + uint8_t* temp = NULL; + _net_nfc_util_alloc_mem(send_buffer, send_buffer_length * sizeof(uint8_t)); + if (send_buffer == NULL) + return NET_NFC_ALLOC_FAIL; + + temp = send_buffer; + + *temp = MIFARE_CMD_WRITE_BLOCK; + temp++; + + *temp = addr; + temp++; + + memcpy(temp, ((data_s*)data)->buffer, MIFARE_BLOCK_SIZE); + } + else + { + send_buffer_length = 1 + 1 + ((data_s*)data)->length + 2; /* cmd + addr + page + CRC */ + + uint8_t* temp = NULL; + _net_nfc_util_alloc_mem(send_buffer, send_buffer_length * sizeof(uint8_t)); + if (send_buffer == NULL) + return NET_NFC_ALLOC_FAIL; + + temp = send_buffer; + + *temp = MIFARE_CMD_WRITE_BLOCK; + temp++; + + *temp = addr; + temp++; + + memcpy(temp, ((data_s*)data)->buffer, ((data_s*)data)->length); + } + } + + net_nfc_util_compute_CRC(CRC_A, send_buffer, send_buffer_length); + + data_s rawdata; + + rawdata.buffer = send_buffer; + rawdata.length = send_buffer_length; + + net_nfc_error_e result = net_nfc_transceive(handle, (data_h)&rawdata, trans_param); + + if (send_buffer != NULL) + _net_nfc_util_free_mem(send_buffer); + + return result; +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_mifare_write_page(net_nfc_target_handle_h handle, uint8_t addr, data_h data, void* trans_param) +{ + if (handle == NULL) + return NET_NFC_NULL_PARAMETER; + + if (!net_nfc_tag_is_connected()) + { + return NET_NFC_OPERATION_FAIL; + } + + client_context_t* tmp_client_context = net_nfc_get_client_context(); + + net_nfc_target_info_s* target_info = NULL; + + if (tmp_client_context != NULL) + { + + target_info = tmp_client_context->target_info; + + if (target_info != NULL) + { + + if (target_info->devType < NET_NFC_MIFARE_MINI_PICC || target_info->devType > NET_NFC_MIFARE_ULTRA_PICC) + { + DEBUG_CLIENT_MSG("This is not MIFARE TAG = [%d] \n", target_info->devType); + return NET_NFC_NOT_SUPPORTED; + } + + if (target_info->devType == NET_NFC_MIFARE_ULTRA_PICC) + { + + if (addr > 7) + { + return NET_NFC_OUT_OF_BOUND; + } + } + } + else + { + return NET_NFC_NOT_INITIALIZED; + } + } + else + { + return NET_NFC_NOT_INITIALIZED; + } + + uint8_t* send_buffer = NULL; + uint32_t send_buffer_length = 0; + + if (target_info->devType == NET_NFC_MIFARE_ULTRA_PICC) + { + + if (((data_s*)data)->length > MIFARE_PAGE_SIZE) + { + + send_buffer_length = 1 + 1 + MIFARE_PAGE_SIZE + 2; /* cmd + addr + page + CRC */ + + uint8_t* temp = NULL; + _net_nfc_util_alloc_mem(send_buffer, send_buffer_length * sizeof(uint8_t)); + if (send_buffer == NULL) + return NET_NFC_ALLOC_FAIL; + + temp = send_buffer; + + *temp = MIFARE_CMD_WRITE_PAGE; + temp++; + + *temp = addr; + temp++; + + memcpy(temp, ((data_s*)data)->buffer, MIFARE_PAGE_SIZE); + + } + else + { + + send_buffer_length = 1 + 1 + ((data_s*)data)->length + 2; /* cmd + addr + page + CRC */ + + uint8_t* temp = NULL; + _net_nfc_util_alloc_mem(send_buffer, send_buffer_length * sizeof(uint8_t)); + if (send_buffer == NULL) + return NET_NFC_ALLOC_FAIL; + + temp = send_buffer; + + *temp = MIFARE_CMD_WRITE_PAGE; + temp++; + + *temp = addr; + temp++; + + memcpy(temp, ((data_s*)data)->buffer, ((data_s*)data)->length); + } + + } + else + { + + if (((data_s*)data)->length > MIFARE_PAGE_SIZE) + { + + send_buffer_length = 1 + 1 + MIFARE_PAGE_SIZE + 2; /* cmd + addr + page + CRC */ + + uint8_t* temp = NULL; + _net_nfc_util_alloc_mem(send_buffer, send_buffer_length * sizeof(uint8_t)); + if (send_buffer == NULL) + return NET_NFC_ALLOC_FAIL; + + temp = send_buffer; + + *temp = MIFARE_CMD_WRITE_BLOCK; + temp++; + + *temp = addr; + temp++; + + memcpy(temp, ((data_s*)data)->buffer, MIFARE_PAGE_SIZE); + + } + else + { + + send_buffer_length = 1 + 1 + ((data_s*)data)->length + 2; /* cmd + addr + page + CRC */ + + uint8_t* temp = NULL; + _net_nfc_util_alloc_mem(send_buffer, send_buffer_length * sizeof(uint8_t)); + if (send_buffer == NULL) + return NET_NFC_ALLOC_FAIL; + + temp = send_buffer; + + *temp = MIFARE_CMD_WRITE_BLOCK; + temp++; + + *temp = addr; + temp++; + + memcpy(temp, ((data_s*)data)->buffer, ((data_s*)data)->length); + } + + } + + net_nfc_util_compute_CRC(CRC_A, send_buffer, send_buffer_length); + + data_s rawdata; + + rawdata.buffer = send_buffer; + rawdata.length = send_buffer_length; + + net_nfc_error_e result = net_nfc_transceive(handle, (data_h)&rawdata, trans_param); + + if (send_buffer != NULL) + _net_nfc_util_free_mem(send_buffer); + + return result; +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_mifare_increment(net_nfc_target_handle_h handle, uint8_t addr, int value, void* trans_param) +{ + if (handle == NULL) + return NET_NFC_NULL_PARAMETER; + + if (!net_nfc_tag_is_connected()) + { + return NET_NFC_OPERATION_FAIL; + } + + client_context_t* tmp_client_context = net_nfc_get_client_context(); + + net_nfc_target_info_s* target_info = NULL; + + if (tmp_client_context != NULL) + { + + target_info = tmp_client_context->target_info; + + if (target_info != NULL) + { + + if (target_info->devType < NET_NFC_MIFARE_MINI_PICC || target_info->devType > NET_NFC_MIFARE_4K_PICC) + { + DEBUG_CLIENT_MSG("This is not MIFARE Classic TAG = [%d] \n", target_info->devType); + return NET_NFC_NOT_SUPPORTED; + } + } + } + + uint8_t send_buffer[8] = { 0 }; + + send_buffer[0] = MIFARE_CMD_INCREMENT; + send_buffer[1] = addr; + + /* little endian. little value of byte array will be saved first in memory */ + send_buffer[5] = (value & 0xFF000000) >> 24; + send_buffer[4] = (value & 0x00FF0000) >> 16; + send_buffer[3] = (value & 0x0000FF00) >> 8; + send_buffer[2] = (value & 0x000000FF); + + net_nfc_util_compute_CRC(CRC_A, send_buffer, 8); + + data_s rawdata; + + rawdata.buffer = send_buffer; + rawdata.length = 8; + + return net_nfc_transceive(handle, (data_h)&rawdata, trans_param); +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_mifare_decrement(net_nfc_target_handle_h handle, uint8_t addr, int value, void* trans_param) +{ + if (handle == NULL) + return NET_NFC_NULL_PARAMETER; + + if (!net_nfc_tag_is_connected()) + { + return NET_NFC_OPERATION_FAIL; + } + + client_context_t* tmp_client_context = net_nfc_get_client_context(); + + net_nfc_target_info_s* target_info = NULL; + + if (tmp_client_context != NULL) + { + + target_info = tmp_client_context->target_info; + + if (target_info != NULL) + { + + if (target_info->devType < NET_NFC_MIFARE_MINI_PICC || target_info->devType > NET_NFC_MIFARE_4K_PICC) + { + DEBUG_CLIENT_MSG("This is not MIFARE Classic TAG = [%d] \n", target_info->devType); + return NET_NFC_NOT_SUPPORTED; + } + } + } + + uint8_t send_buffer[8] = { 0 }; + + send_buffer[0] = MIFARE_CMD_DECREMENT; + send_buffer[1] = addr; + + // little endian. little value of byte array will be saved first in memory + send_buffer[5] = (value & 0xFF000000) >> 24; + send_buffer[4] = (value & 0x00FF0000) >> 16; + send_buffer[3] = (value & 0x0000FF00) >> 8; + send_buffer[2] = (value & 0x000000FF); + + net_nfc_util_compute_CRC(CRC_A, send_buffer, 8); + + DEBUG_MSG_PRINT_BUFFER(send_buffer, 8); + + data_s rawdata; + + rawdata.buffer = send_buffer; + rawdata.length = 8; + + return net_nfc_transceive(handle, (data_h)&rawdata, trans_param); + +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_mifare_transfer(net_nfc_target_handle_h handle, uint8_t addr, void* trans_param) +{ + if (handle == NULL) + return NET_NFC_NULL_PARAMETER; + + if (!net_nfc_tag_is_connected()) + { + return NET_NFC_OPERATION_FAIL; + } + + client_context_t* tmp_client_context = net_nfc_get_client_context(); + + net_nfc_target_info_s* target_info = NULL; + + if (tmp_client_context != NULL) + { + + target_info = tmp_client_context->target_info; + + if (target_info != NULL) + { + + if (target_info->devType < NET_NFC_MIFARE_MINI_PICC || target_info->devType > NET_NFC_MIFARE_4K_PICC) + { + DEBUG_CLIENT_MSG("This is not MIFARE Classic TAG = [%d] \n", target_info->devType); + return NET_NFC_NOT_SUPPORTED; + } + } + } + + uint8_t send_buffer[4] = { 0 }; + + send_buffer[0] = MIFARE_CMD_TRANSFER; + send_buffer[1] = addr; + + net_nfc_util_compute_CRC(CRC_A, send_buffer, 4); + + data_s rawdata; + + rawdata.buffer = send_buffer; + rawdata.length = 4; + + return net_nfc_transceive(handle, (data_h)&rawdata, trans_param); + +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_mifare_restore(net_nfc_target_handle_h handle, uint8_t addr, void* trans_param) +{ + if (handle == NULL) + return NET_NFC_NULL_PARAMETER; + + if (!net_nfc_tag_is_connected()) + { + return NET_NFC_OPERATION_FAIL; + } + + client_context_t* tmp_client_context = net_nfc_get_client_context(); + + net_nfc_target_info_s* target_info = NULL; + + if (tmp_client_context != NULL) + { + + target_info = tmp_client_context->target_info; + + if (target_info != NULL) + { + + if (target_info->devType < NET_NFC_MIFARE_MINI_PICC || target_info->devType > NET_NFC_MIFARE_4K_PICC) + { + DEBUG_CLIENT_MSG("This is not MIFARE Classic TAG = [%d] \n", target_info->devType); + return NET_NFC_NOT_SUPPORTED; + } + } + } + + uint8_t send_buffer[4] = { 0 }; + + send_buffer[0] = MIFARE_CMD_RESTORE; + send_buffer[1] = addr; + + net_nfc_util_compute_CRC(CRC_A, send_buffer, 4); + + data_s rawdata; + + rawdata.buffer = send_buffer; + rawdata.length = 4; + + return net_nfc_transceive(handle, (data_h)&rawdata, trans_param); +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_mifare_create_default_key(data_h* key) +{ + if (key == NULL) + return NET_NFC_NULL_PARAMETER; + + return net_nfc_create_data(key, default_key, 6); +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_mifare_create_application_directory_key(data_h* key) +{ + if (key == NULL) + return NET_NFC_NULL_PARAMETER; + + return net_nfc_create_data(key, mad_key, 6); +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_mifare_create_net_nfc_forum_key(data_h* key) +{ + if (key == NULL) + return NET_NFC_NULL_PARAMETER; + + return net_nfc_create_data(key, net_nfc_forum_key, 6); +} + diff --git a/src/clientlib/net_nfc_client_target_info.c b/src/clientlib/net_nfc_client_target_info.c new file mode 100755 index 0000000..fb17acf --- /dev/null +++ b/src/clientlib/net_nfc_client_target_info.c @@ -0,0 +1,283 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include "net_nfc_typedef_private.h" +#include "net_nfc_debug_private.h" +#include "net_nfc_data.h" +#include "net_nfc_target_info.h" +#include "net_nfc_util_private.h" + +#ifndef NET_NFC_EXPORT_API +#define NET_NFC_EXPORT_API __attribute__((visibility("default"))) +#endif + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_tag_type(net_nfc_target_info_h target_info, net_nfc_target_type_e * type) +{ + if (target_info == NULL || type == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + net_nfc_target_info_s * target_info_private = (net_nfc_target_info_s*)target_info; + + *type = target_info_private->devType; + return NET_NFC_OK; +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_tag_handle(net_nfc_target_info_h target_info, net_nfc_target_handle_h * handle) +{ + if (target_info == NULL || handle == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + net_nfc_target_info_s * target_info_private = (net_nfc_target_info_s*)target_info; + + *handle = (net_nfc_target_handle_h)target_info_private->handle; + return NET_NFC_OK; +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_tag_ndef_support(net_nfc_target_info_h target_info, bool * is_support) +{ + if (target_info == NULL || is_support == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + net_nfc_target_info_s * target_info_private = (net_nfc_target_info_s*)target_info; + + *is_support = (bool)target_info_private->is_ndef_supported; + return NET_NFC_OK; +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_tag_max_data_size(net_nfc_target_info_h target_info, uint32_t * max_size) +{ + if (target_info == NULL || max_size == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + net_nfc_target_info_s * target_info_private = (net_nfc_target_info_s*)target_info; + + *max_size = target_info_private->maxDataSize; + return NET_NFC_OK; +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_tag_actual_data_size(net_nfc_target_info_h target_info, uint32_t * actual_data) +{ + if (target_info == NULL || actual_data == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + net_nfc_target_info_s * target_info_private = (net_nfc_target_info_s*)target_info; + + *actual_data = target_info_private->actualDataSize; + return NET_NFC_OK; +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_tag_info_keys(net_nfc_target_info_h target_info, char ***keys, int* number_of_keys) +{ + if (keys == NULL || number_of_keys == NULL || target_info == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + net_nfc_target_info_s* handle = (net_nfc_target_info_s*)target_info; + + if (handle->tag_info_list == NULL) + { + return NET_NFC_NO_DATA_FOUND; + } + + if (handle->number_of_keys <= 0) + { + return NET_NFC_NO_DATA_FOUND; + } + + int i = 0; + + if (handle->keylist != NULL) + { + *keys = handle->keylist; + return NET_NFC_OK; + } + + _net_nfc_util_alloc_mem(*keys, handle->number_of_keys * sizeof(char *)); + if (*keys == NULL) + return NET_NFC_ALLOC_FAIL; + + net_nfc_tag_info_s* tag_info = handle->tag_info_list; + + for (; i < handle->number_of_keys; i++, tag_info++) + { + (*keys)[i] = tag_info->key; + } + + *number_of_keys = handle->number_of_keys; + + DEBUG_CLIENT_MSG("number of keys = [%d]", handle->number_of_keys); + + handle->keylist = *keys; + + return NET_NFC_OK; +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_tag_info_value(net_nfc_target_info_h target_info, const char* key, data_h* value) +{ + if (target_info == NULL || key == NULL || value == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + net_nfc_target_info_s* handle = (net_nfc_target_info_s*)target_info; + + if (handle->tag_info_list == NULL) + { + return NET_NFC_NO_DATA_FOUND; + } + + int i = 0; + + net_nfc_tag_info_s* tag_info = handle->tag_info_list; + + for (; i < handle->number_of_keys; i++, tag_info++) + { + if (strcmp(key, tag_info->key) == 0) + { + if (tag_info->value == NULL) + { + return NET_NFC_NO_DATA_FOUND; + } + else + { + *value = tag_info->value; + break; + } + } + } + + if (i == handle->number_of_keys) + return NET_NFC_NOT_SUPPORTED; + + return NET_NFC_OK; +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_duplicate_target_info(net_nfc_target_info_h origin, net_nfc_target_info_h *result) +{ + net_nfc_target_info_s *handle = (net_nfc_target_info_s *)origin; + net_nfc_target_info_s *temp = NULL; + + if (handle == NULL || result == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + _net_nfc_util_alloc_mem(temp, sizeof(net_nfc_target_info_s)); + if (temp == NULL) + { + return NET_NFC_ALLOC_FAIL; + } + + temp->ndefCardState = handle->ndefCardState; + temp->actualDataSize = handle->actualDataSize; + temp->maxDataSize = handle->maxDataSize; + temp->devType = handle->devType; + temp->handle = handle->handle; + temp->is_ndef_supported = handle->is_ndef_supported; + temp->number_of_keys = handle->number_of_keys; + + if (temp->number_of_keys > 0) + { + int i; + + _net_nfc_util_alloc_mem(temp->tag_info_list, temp->number_of_keys * sizeof(net_nfc_tag_info_s)); + if (temp->tag_info_list == NULL) + { + _net_nfc_util_free_mem(temp); + return NET_NFC_ALLOC_FAIL; + } + + for (i = 0; i < handle->number_of_keys; i++) + { + if (handle->tag_info_list[i].key != NULL) + _net_nfc_util_strdup(temp->tag_info_list[i].key, handle->tag_info_list[i].key); + + if (handle->tag_info_list[i].value != NULL) + { + data_s *data = (data_s *)handle->tag_info_list[i].value; + + net_nfc_create_data(&temp->tag_info_list[i].value, data->buffer, data->length); + } + } + } + + if (handle->raw_data.length > 0) + { + net_nfc_util_alloc_data(&temp->raw_data, handle->raw_data.length); + memcpy(temp->raw_data.buffer, handle->raw_data.buffer, temp->raw_data.length); + } + + *result = (net_nfc_target_info_h)temp; + + return NET_NFC_OK; +} + +net_nfc_error_e net_nfc_util_release_tag_info(net_nfc_target_info_s *info) +{ + net_nfc_error_e result = NET_NFC_OK; + net_nfc_tag_info_s *list = NULL; + + if (info == NULL) + return NET_NFC_NULL_PARAMETER; + + list = info->tag_info_list; + if (list != NULL) + { + int i = 0; + for (i = 0; i < info->number_of_keys; i++, list++) + { + if (list->key != NULL) + _net_nfc_util_free_mem(list->key); + + if (list->value != NULL) + net_nfc_free_data(list->value); + } + + _net_nfc_util_free_mem(info->tag_info_list); + } + + if (info->keylist != NULL) + { + _net_nfc_util_free_mem(info->keylist); + } + + net_nfc_util_free_data(&info->raw_data); + + return result; +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_release_tag_info(net_nfc_target_info_h target_info) +{ + net_nfc_error_e result = NET_NFC_OK; + net_nfc_target_info_s *info = (net_nfc_target_info_s *)target_info; + + if (info == NULL) + return NET_NFC_NULL_PARAMETER; + + net_nfc_util_release_tag_info(info); + + _net_nfc_util_free_mem(info); + + return result; +} diff --git a/src/clientlib/net_nfc_client_test.c b/src/clientlib/net_nfc_client_test.c new file mode 100644 index 0000000..1069c6b --- /dev/null +++ b/src/clientlib/net_nfc_client_test.c @@ -0,0 +1,149 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include "net_nfc.h" +#include "net_nfc_typedef.h" +#include "net_nfc_util_private.h" +#include "net_nfc_util_defines.h" +#include "net_nfc_debug_private.h" +#include "net_nfc_client_ipc_private.h" + + +#ifndef NET_NFC_EXPORT_API +#define NET_NFC_EXPORT_API __attribute__((visibility("default"))) +#endif + +NET_NFC_EXPORT_API void net_nfc_test_read_test_cb(net_nfc_message_e message, net_nfc_error_e result, void* data, void* user_param, void * trans_data) +{ + DEBUG_CLIENT_MSG("user_param = [%p] trans_param = [%p] , message[%d]", user_param, trans_data, message); + + switch (message) + { + case NET_NFC_MESSAGE_TAG_DISCOVERED : + { + if (result == NET_NFC_OK) + { + DEBUG_CLIENT_MSG("net_nfc_test_read_cb SUCCESS!!!!! [%d ]", result); + } + else + { + DEBUG_CLIENT_MSG("net_nfc_test_read_cb FAIL!!!!![%d]", result); + } + } + break; + + default : + break; + } +} + +NET_NFC_EXPORT_API void net_nfc_test_sim_test_cb(net_nfc_message_e message, net_nfc_error_e result, void* data, void* user_param, void * trans_data) +{ + DEBUG_CLIENT_MSG("user_param = [%p] trans_param = [%p] data = [%p]", user_param, trans_data, data); + + switch (message) + { + case NET_NFC_MESSAGE_SIM_TEST : + { + if (result == NET_NFC_OK) + { + DEBUG_CLIENT_MSG("net_nfc_test_sim_test_cb SUCCESS!!!!! [%d]", result); + } + else + { + DEBUG_CLIENT_MSG("net_nfc_test_sim_test_cb FAIL!!!!![%d]", result); + } + } + break; + + default : + break; + } +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_sim_test(void) +{ + net_nfc_error_e ret; + net_nfc_request_test_t request = { 0, }; + + request.length = sizeof(net_nfc_request_test_t); + request.request_type = NET_NFC_MESSAGE_SIM_TEST; + + ret = net_nfc_client_send_reqeust((net_nfc_request_msg_t *)&request, NULL); + + return ret; +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_prbs_test(int tech, int rate) +{ + net_nfc_error_e ret; + net_nfc_request_test_t request = { 0, }; + + request.length = sizeof(net_nfc_request_test_t); + request.request_type = NET_NFC_MESSAGE_PRBS_TEST;/*TEST MODE*/ + request.rate = rate; + request.tech = tech; + + ret = net_nfc_client_send_reqeust((net_nfc_request_msg_t *)&request, NULL); + + return ret; +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_firmware_version(void) +{ + net_nfc_error_e ret; + net_nfc_request_msg_t request = { 0, }; + + request.length = sizeof(net_nfc_request_msg_t); + request.request_type = NET_NFC_MESSAGE_GET_FIRMWARE_VERSION; + + ret = net_nfc_client_send_reqeust((net_nfc_request_msg_t *)&request, NULL); + + return ret; +} + +NET_NFC_EXPORT_API net_nfc_error_e net_nfc_set_eedata_register(int mode, int reg_id, uint8_t *data, uint32_t len) +{ + net_nfc_request_eedata_register_t *request = NULL; + net_nfc_error_e result; + uint32_t length = 0; + + DEBUG_CLIENT_MSG("net_nfc_set_eedata_register"); + + length = sizeof(net_nfc_request_eedata_register_t) + len; + + _net_nfc_util_alloc_mem(request, length); + if (request == NULL) + { + return NET_NFC_ALLOC_FAIL; + } + + /* fill request message */ + request->length = length; + request->request_type = NET_NFC_MESSAGE_SET_EEDATA; + request->mode = mode; + request->reg_id = reg_id; + request->data.length = len; + memcpy(request->data.buffer, data, len); + + result = net_nfc_client_send_reqeust((net_nfc_request_msg_t *)request, NULL); + + _net_nfc_util_free_mem(request); + + return result; +} + diff --git a/src/clientlib/net_nfc_client_util.c b/src/clientlib/net_nfc_client_util.c new file mode 100755 index 0000000..e7cc5ce --- /dev/null +++ b/src/clientlib/net_nfc_client_util.c @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include "net_nfc_client_util_private.h" + diff --git a/src/clientlib/nfc.pc.in b/src/clientlib/nfc.pc.in new file mode 100755 index 0000000..8731985 --- /dev/null +++ b/src/clientlib/nfc.pc.in @@ -0,0 +1,11 @@ +prefix=/usr +exec_prefix=${prefix}/bin +libdir=${prefix}/lib +includedir=${prefix}/include + +Name: nfc +Description: NFC +Version: $version +Requires: +Libs: -lnfc +Cflags: -I/usr/include/nfc \ No newline at end of file diff --git a/src/commonlib/CMakeLists.txt b/src/commonlib/CMakeLists.txt new file mode 100644 index 0000000..ab635f5 --- /dev/null +++ b/src/commonlib/CMakeLists.txt @@ -0,0 +1,73 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +PROJECT(nfc-common-lib C) + +SET(NFC_COMMON_LIB "nfc-common-lib") +SET(VERSION_MAJOR 1) +SET(VERSION ${VERSION_MAJOR}.0.0) + +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include) + +AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} COMMON_LIB_SRCS) + +IF("${CMAKE_BUILD_TYPE}" STREQUAL "") + SET(CMAKE_BUILD_TYPE "Release") +ENDIF("${CMAKE_BUILD_TYPE}" STREQUAL "") + +INCLUDE(FindPkgConfig) +pkg_check_modules(commonlib_pkges REQUIRED glib-2.0 dlog bluetooth-api libssl) + +FOREACH(flag ${commonlib_pkges_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) + +MESSAGE("CHECK MODULE in COMMON_LIB ${commonlib_pkges_LDFLAGS}") + +# this for NFC flag + +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -pipe -fomit-frame-pointer -Wall -Wno-trigraphs -Werror-implicit-function-declaration -fno-strict-aliasing -Wl,-zdefs") + +SET(ARM_CFLAGS "${ARM_CLAGS} -mapcs -mno-sched-prolog -mabi=aapcs-linux -Uarm -fno-common -fpic") + +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror-implicit-function-declaration") +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}") +SET(CMAKE_C_FLAGS_DEBUG "-O0 -g") + +FIND_PROGRAM(UNAME NAMES uname) +EXEC_PROGRAM("${UNAME}" ARGS "-m" OUTPUT_VARIABLE "ARCH") +IF("${ARCH}" MATCHES "^arm.*") + ADD_DEFINITIONS("-DTARGET") + MESSAGE("add -DTARGET") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${ARM_CFLAGS}") +ENDIF() + +ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"") +#ADD_DEFINITIONS("-DSLP_DEBUG") +ADD_DEFINITIONS("-DNFC_DEBUG_USE_DLOG -D_GNU_SOURCE") +#ADD_DEFINITIONS("-DUSE_UNIX_DOMAIN") +ADD_DEFINITIONS("-DSECURITY_SERVER") + +ADD_LIBRARY(${NFC_COMMON_LIB} SHARED ${COMMON_LIB_SRCS}) +SET_TARGET_PROPERTIES(${NFC_COMMON_LIB} PROPERTIES SOVERSION ${VERSION_MAJOR}) +SET_TARGET_PROPERTIES(${NFC_COMMON_LIB} PROPERTIES VERSION ${VERSION}) + +TARGET_LINK_LIBRARIES(${NFC_COMMON_LIB} ${commonlib_pkges_LDFLAGS}) + +SET(COMMON_LIB_HEADER + include/net_nfc_typedef.h + include/net_nfc_util_private.h + include/net_nfc_oem_controller.h + include/net_nfc_typedef_private.h + include/net_nfc_util_ndef_message.h + include/net_nfc_util_handover.h + include/net_nfc_util_ndef_record.h + include/net_nfc_util_sign_record.h +) + +CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/${NFC_COMMON_LIB}.pc.in ${CMAKE_CURRENT_SOURCE_DIR}/${NFC_COMMON_LIB}.pc) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${NFC_COMMON_LIB}.pc DESTINATION lib/pkgconfig) +INSTALL(TARGETS ${NFC_COMMON_LIB} DESTINATION lib) + +FOREACH(hfile ${COMMON_LIB_HEADER}) + INSTALL(FILES ${hfile} DESTINATION include/nfc-common-lib) +ENDFOREACH(hfile) + diff --git a/src/commonlib/include/net_nfc_debug_private.h b/src/commonlib/include/net_nfc_debug_private.h new file mode 100755 index 0000000..a394aa0 --- /dev/null +++ b/src/commonlib/include/net_nfc_debug_private.h @@ -0,0 +1,148 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __NET_NFC_DEBUG_PRIVATE_H__ +#define __NET_NFC_DEBUG_PRIVATE_H__ + +#include +#include +#include +#include +#include + +// below define should define before dlog.h +#define LOG_SERVER_TAG "NET_NFC_MANAGER" +#define LOG_CLIENT_TAG "NET_NFC_CLIENT" + +#include + +#define LOG_COLOR_RED "\033[0;31m" +#define LOG_COLOR_GREEN "\033[0;32m" +#define LOG_COLOR_BROWN "\033[0;33m" +#define LOG_COLOR_BLUE "\033[0;34m" +#define LOG_COLOR_PURPLE "\033[0;35m" +#define LOG_COLOR_CYAN "\033[0;36m" +#define LOG_COLOR_LIGHTBLUE "\033[0;37m" +#define LOG_COLOR_END "\033[0;m" + +/* nfc_log_to_file */ +extern FILE *nfc_log_file; +#define NFC_DLOG_FILE "/opt/etc/nfc_debug/nfc_mgr_dlog.txt" + +/* tag */ +const char *net_nfc_get_log_tag(); + +#define NFC_LOGD(format, arg...) (LOG_ON() ? (LOG(LOG_DEBUG, net_nfc_get_log_tag(), "%s:%s(%d)>" format, __MODULE__, __func__, __LINE__, ##arg)) : (0)) +#define NFC_LOGE(format, arg...) (LOG_ON() ? (LOG(LOG_ERROR, net_nfc_get_log_tag(), "%s:%s(%d)>" format, __MODULE__, __func__, __LINE__, ##arg)) : (0)) +#define NFC_LOGI(format, arg...) (LOG_ON() ? (LOG(LOG_INFO, net_nfc_get_log_tag(), "%s:%s(%d)>" format, __MODULE__, __func__, __LINE__, ##arg)) : (0)) + +#define DEBUG_MSG_PRINT_BUFFER(buffer, length) \ + do { \ + int i = 0, offset = 0; \ + char temp_buffer[4096] = { 0, }; \ + NFC_LOGD(LOG_COLOR_BLUE " BUFFER [%d] = {" LOG_COLOR_END, length); \ + for(; i < length && offset < sizeof(temp_buffer); i++) \ + { \ + offset += snprintf(temp_buffer + offset, sizeof(temp_buffer) - offset, " %02x", buffer[i]); \ + if (i % 16 == 15) \ + { \ + NFC_LOGD(LOG_COLOR_BLUE "\t%s" LOG_COLOR_END, temp_buffer); \ + offset = 0; \ + } \ + } \ + NFC_LOGD(LOG_COLOR_BLUE "\t%s" LOG_COLOR_END, temp_buffer); \ + NFC_LOGD(LOG_COLOR_BLUE "}" LOG_COLOR_END); \ + } while(0) + +#define DEBUG_MSG_PRINT_BUFFER_CHAR(buffer, length) \ + do { \ + int i = 0, offset = 0; \ + char temp_buffer[4096] = { 0, }; \ + NFC_LOGD(LOG_COLOR_BLUE " BUFFER [%d] = {" LOG_COLOR_END, length); \ + for(; i < length && offset < sizeof(temp_buffer); i++) \ + { \ + offset += snprintf(temp_buffer + offset, sizeof(temp_buffer) - offset, " %c", buffer[i]); \ + if (i % 16 == 15) \ + { \ + NFC_LOGD(LOG_COLOR_BLUE "\t%s" LOG_COLOR_END, temp_buffer); \ + offset = 0; \ + } \ + } \ + NFC_LOGD(LOG_COLOR_BLUE "\t%s" LOG_COLOR_END, temp_buffer); \ + NFC_LOGD(LOG_COLOR_BLUE "}" LOG_COLOR_END); \ + } while(0) + +#define DEBUG_MSG(format, args...) \ + do { \ + NFC_LOGD(LOG_COLOR_BROWN " " format "" LOG_COLOR_END, ##args); \ + if (nfc_log_file) \ + { \ + char timeBuf[50]; \ + time_t rawtime; time (&rawtime); strftime(timeBuf, sizeof(timeBuf), "%m-%d %H:%M:%S", localtime(&rawtime)); \ + fprintf(nfc_log_file, "\n%s",timeBuf); \ + fprintf(nfc_log_file, "[D][%s:%d] "format"",__func__, __LINE__, ##args); \ + }\ + } while(0) + +#define DEBUG_SERVER_MSG(format, args...) \ + do {\ + NFC_LOGD(LOG_COLOR_PURPLE " " format "" LOG_COLOR_END, ##args);\ + if (nfc_log_file) \ + { \ + char timeBuf[50]; \ + time_t rawtime; time (&rawtime); strftime(timeBuf, sizeof(timeBuf), "%m-%d %H:%M:%S", localtime(&rawtime)); \ + fprintf(nfc_log_file, "\n%s",timeBuf); \ + fprintf(nfc_log_file, "[S][%s:%d] "format"",__func__, __LINE__, ##args); \ + } \ + } while(0) + +#define DEBUG_CLIENT_MSG(format, args...) \ + do {\ + NFC_LOGD(LOG_COLOR_GREEN " " format "" LOG_COLOR_END, ##args); \ + if (nfc_log_file) \ + { \ + char timeBuf[50]; \ + time_t rawtime; time (&rawtime); strftime(timeBuf, sizeof(timeBuf), "%m-%d %H:%M:%S", localtime(&rawtime)); \ + fprintf(nfc_log_file, "\n%s",timeBuf); \ + fprintf(nfc_log_file, "[C][%s:%d] "format"",__func__, __LINE__, ##args); \ + }\ + } while(0) + +#define DEBUG_ERR_MSG(format, args...) \ + do {\ + NFC_LOGD(LOG_COLOR_RED " " format "" LOG_COLOR_END, ##args);\ + if (nfc_log_file) \ + { \ + char timeBuf[50]; \ + time_t rawtime; time (&rawtime); strftime(timeBuf, sizeof(timeBuf), "%m-%d %H:%M:%S", localtime(&rawtime)); \ + fprintf(nfc_log_file, "\n%s",timeBuf); \ + fprintf(nfc_log_file, "[ERR][%s:%d] "format"",__func__, __LINE__, ##args); \ + } \ + } while(0) + +#define PROFILING(str) \ + do{ \ + struct timeval mytime;\ + char buf[128]; = {0};\ + memset(buf, 0x00, 128);\ + gettimeofday(&mytime, NULL);\ + char time_string[128] = {0,};\ + sprintf(time_string, "%d.%4d", mytime.tv_sec, mytime.tv_usec);\ + NFC_LOGD(str); \ + NFC_LOGD("\t time = [%s]", time_string);\ + } while(0) + +#endif diff --git a/src/commonlib/include/net_nfc_oem_controller.h b/src/commonlib/include/net_nfc_oem_controller.h new file mode 100644 index 0000000..243ff4e --- /dev/null +++ b/src/commonlib/include/net_nfc_oem_controller.h @@ -0,0 +1,130 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#ifndef NET_NFC_OEM_CONTROLLER_H +#define NET_NFC_OEM_CONTROLLER_H + +#include "net_nfc_typedef_private.h" + +typedef bool (*net_nfc_oem_controller_init)(net_nfc_error_e *result); +typedef bool (*net_nfc_oem_controller_deinit)(void); +typedef bool (*net_nfc_oem_controller_register_listener)(target_detection_listener_cb target_detection_listener, se_transaction_listener_cb se_transaction_listener, llcp_event_listener_cb llcp_event_listener, net_nfc_error_e *result); +typedef bool (*net_nfc_oem_controller_unregister_listener)(void); +typedef bool (*net_nfc_oem_controller_get_firmware_version)(data_s **data, net_nfc_error_e *result); +typedef bool (*net_nfc_oem_controller_check_firmware_version)(net_nfc_error_e *result); +typedef bool (*net_nfc_oem_controller_update_firmware)(net_nfc_error_e *result); +typedef bool (*net_nfc_oem_controller_get_stack_information)(net_nfc_stack_information_s *stack_info, net_nfc_error_e *result); +typedef bool (*net_nfc_oem_controller_configure_discovery)(net_nfc_discovery_mode_e mode, net_nfc_event_filter_e config, net_nfc_error_e *result); +typedef bool (*net_nfc_oem_controller_get_secure_element_list)(net_nfc_secure_element_info_s *list, int* count, net_nfc_error_e *result); +typedef bool (*net_nfc_oem_controller_set_secure_element_mode)(net_nfc_secure_element_type_e element_type, net_nfc_secure_element_mode_e mode, net_nfc_error_e *result); +typedef bool (*net_nfc_oem_controller_check_target_presence)(net_nfc_target_handle_s *handle, net_nfc_error_e *result); +typedef bool (*net_nfc_oem_controller_connect)(net_nfc_target_handle_s *handle, net_nfc_error_e *result); +typedef bool (*net_nfc_oem_controller_disconnect)(net_nfc_target_handle_s *handle, net_nfc_error_e *result); +typedef bool (*net_nfc_oem_controller_check_ndef)(net_nfc_target_handle_s *handle, uint8_t *ndef_card_state, int *max_data_size, int *real_data_size, net_nfc_error_e *result); +typedef bool (*net_nfc_oem_controller_read_ndef)(net_nfc_target_handle_s *handle, data_s **data, net_nfc_error_e *result); +typedef bool (*net_nfc_oem_controller_write_ndef)(net_nfc_target_handle_s *handle, data_s *data, net_nfc_error_e *result); +typedef bool (*net_nfc_oem_controller_make_read_only_ndef)(net_nfc_target_handle_s *handle, net_nfc_error_e *result); +typedef bool (*net_nfc_oem_controller_format_ndef)(net_nfc_target_handle_s *handle, data_s *secure_key, net_nfc_error_e *result); +typedef bool (*net_nfc_oem_controller_transceive)(net_nfc_target_handle_s *handle, net_nfc_transceive_info_s *info, data_s **data, net_nfc_error_e *result); +typedef bool (*net_nfc_oem_controller_exception_handler)(void); +typedef bool (*net_nfc_oem_controller_is_ready)(net_nfc_error_e *result); + +// LLCP API DEFINE + +typedef bool (*net_nfc_oem_controller_llcp_config)(net_nfc_llcp_config_info_s *config, net_nfc_error_e *result); +typedef bool (*net_nfc_oem_controller_llcp_check_llcp)(net_nfc_target_handle_s *handle, net_nfc_error_e *result); +typedef bool (*net_nfc_oem_controller_llcp_activate_llcp)(net_nfc_target_handle_s *handle, net_nfc_error_e *result); +typedef bool (*net_nfc_oem_controller_llcp_create_socket)(net_nfc_llcp_socket_t *socket, net_nfc_socket_type_e socketType, uint16_t miu, uint8_t rw, net_nfc_error_e *result, void *user_param); +typedef bool (*net_nfc_oem_controller_llcp_bind)(net_nfc_llcp_socket_t socket, uint8_t service_access_point, net_nfc_error_e *result); +typedef bool (*net_nfc_oem_controller_llcp_listen)(net_nfc_target_handle_s *handle, uint8_t *service_access_name, net_nfc_llcp_socket_t socket, net_nfc_error_e *result, void *user_param); +typedef bool (*net_nfc_oem_controller_llcp_accept)(net_nfc_llcp_socket_t socket, net_nfc_error_e *result); +typedef bool (*net_nfc_oem_controller_llcp_connect_by_url)(net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, uint8_t *service_access_name, net_nfc_error_e *result, void *user_param); +typedef bool (*net_nfc_oem_controller_llcp_connect)(net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, uint8_t service_access_point, net_nfc_error_e *result, void *user_param); +typedef bool (*net_nfc_oem_controller_llcp_disconnect)(net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, net_nfc_error_e *result, void *user_param); +typedef bool (*net_nfc_oem_controller_llcp_socket_close)(net_nfc_llcp_socket_t socket, net_nfc_error_e *result); +typedef bool (*net_nfc_oem_controller_llcp_recv)(net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, data_s *data, net_nfc_error_e *result, void *user_param); +typedef bool (*net_nfc_oem_controller_llcp_send)(net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, data_s *data, net_nfc_error_e *result, void *user_param); +typedef bool (*net_nfc_oem_controller_llcp_recv_from)(net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, data_s *data, net_nfc_error_e *result, void *user_param); +typedef bool (*net_nfc_oem_controller_llcp_send_to)(net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, data_s *data, uint8_t service_access_point, net_nfc_error_e *result, void *user_param); +typedef bool (*net_nfc_oem_controller_llcp_reject)(net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, net_nfc_error_e *result); +typedef bool (*net_nfc_oem_controller_llcp_get_remote_config)(net_nfc_target_handle_s *handle, net_nfc_llcp_config_info_s *config, net_nfc_error_e *result); +typedef bool (*net_nfc_oem_controller_llcp_get_remote_socket_info)(net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, net_nfc_llcp_socket_option_s *option, net_nfc_error_e *result); + +typedef bool (*net_nfc_oem_controller_sim_test)(net_nfc_error_e *result); +typedef bool (*net_nfc_oem_controller_prbs_test)(net_nfc_error_e *result , int tech , int rate); + +typedef bool (*net_nfc_oem_controller_test_mode_on)(net_nfc_error_e *result); +typedef bool (*net_nfc_oem_controller_test_mode_off)(net_nfc_error_e *result); + +typedef bool (*net_nfc_oem_controller_support_nfc)(net_nfc_error_e *result); +typedef bool (*net_nfc_oem_controller_eedata_register_set)(net_nfc_error_e *result , uint32_t mode , uint32_t reg_id , data_s *data); + +typedef struct _net_nfc_oem_interface_s +{ + net_nfc_oem_controller_init init; + net_nfc_oem_controller_deinit deinit; + net_nfc_oem_controller_register_listener register_listener; + net_nfc_oem_controller_unregister_listener unregister_listener; + net_nfc_oem_controller_get_firmware_version get_firmware_version; + net_nfc_oem_controller_check_firmware_version check_firmware_version; + net_nfc_oem_controller_update_firmware update_firmeware; + net_nfc_oem_controller_get_stack_information get_stack_information; + net_nfc_oem_controller_configure_discovery configure_discovery; + net_nfc_oem_controller_get_secure_element_list get_secure_element_list; + net_nfc_oem_controller_set_secure_element_mode set_secure_element_mode; + net_nfc_oem_controller_connect connect; + net_nfc_oem_controller_connect disconnect; + net_nfc_oem_controller_check_ndef check_ndef; + net_nfc_oem_controller_check_target_presence check_presence; + net_nfc_oem_controller_read_ndef read_ndef; + net_nfc_oem_controller_write_ndef write_ndef; + net_nfc_oem_controller_make_read_only_ndef make_read_only_ndef; + net_nfc_oem_controller_transceive transceive; + net_nfc_oem_controller_format_ndef format_ndef; + net_nfc_oem_controller_exception_handler exception_handler; + net_nfc_oem_controller_is_ready is_ready; + + net_nfc_oem_controller_llcp_config config_llcp; + net_nfc_oem_controller_llcp_check_llcp check_llcp_status; + net_nfc_oem_controller_llcp_activate_llcp activate_llcp; + net_nfc_oem_controller_llcp_create_socket create_llcp_socket; + net_nfc_oem_controller_llcp_bind bind_llcp_socket; + net_nfc_oem_controller_llcp_listen listen_llcp_socket; + net_nfc_oem_controller_llcp_accept accept_llcp_socket; + net_nfc_oem_controller_llcp_connect_by_url connect_llcp_by_url; + net_nfc_oem_controller_llcp_connect connect_llcp; + net_nfc_oem_controller_llcp_disconnect disconnect_llcp; + net_nfc_oem_controller_llcp_socket_close close_llcp_socket; + net_nfc_oem_controller_llcp_recv recv_llcp; + net_nfc_oem_controller_llcp_send send_llcp; + net_nfc_oem_controller_llcp_recv_from recv_from_llcp; + net_nfc_oem_controller_llcp_send_to send_to_llcp; + net_nfc_oem_controller_llcp_reject reject_llcp; + net_nfc_oem_controller_llcp_get_remote_config get_remote_config; + net_nfc_oem_controller_llcp_get_remote_socket_info get_remote_socket_info; + + net_nfc_oem_controller_sim_test sim_test; + net_nfc_oem_controller_prbs_test prbs_test; + net_nfc_oem_controller_test_mode_on test_mode_on; + net_nfc_oem_controller_test_mode_off test_mode_off; + + net_nfc_oem_controller_support_nfc support_nfc; + net_nfc_oem_controller_eedata_register_set eedata_register_set; + +} net_nfc_oem_interface_s; + +#endif diff --git a/src/commonlib/include/net_nfc_typedef.h b/src/commonlib/include/net_nfc_typedef.h new file mode 100644 index 0000000..ec4d7ba --- /dev/null +++ b/src/commonlib/include/net_nfc_typedef.h @@ -0,0 +1,527 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +/** + NFC Manager + NFC Manager controls the nfc device with high level APIs such as SmartPoster and Connection handover. + It also support the JSR257 push handling. + This file describe the structure and defines of the NFC manager + + @version 0.1 + + */ + +#ifndef __NET_NFC_TYPEDEF_H__ +#define __NET_NFC_TYPEDEF_H__ + +/** + @defgroup NET_NFC_MANAGER The description of NFC Manager + @defgroup NET_NFC_TYPEDEF Defines and structures + @defgroup NET_NFC_MANAGER_API NFC Manager + @defgroup NET_NFC_MANAGER_INFO Tag Information and data APIs + @defgroup NET_NFC_MANAGER_TAG Tag Read/Write APIs + @defgroup NET_NFC_MANAGER_NDEF NDEF Message APIs + @defgroup NET_NFC_MANAGER_RECORD NDEF Record APIs + @defgroup NET_NFC_MANAGER_LLCP NFC LLCP APIs + @defgroup NET_NFC_MANAGER_APDU Internal APDU APIs + @defgroup NET_NFC_MANAGER_EXCHANGE App Exchanger APIs + + + @addtogroup NET_NFC_MANAGER + @{ +

"NFC Manager" is the framework that provide NFC APIs, + and it also provide high level services such as Smart Poster, Connection Handover, + and JSR257 push registry.

+ + NFC Manager APIs are defined in , + +

+ Memory management rules
+ depends on the the verb of each function it describe memory management roles + + 1. set: copy the parameters and used inside of nfc-manager, you should free the parameter you have used + 2. append: it is similar to "set" but, it does not make copy, you SHOULD NOT free the parameter after use it belongs to nfc-manager and it will be freed later + (example "net_nfc_append_record_to_ndef_message") the appended record will be free the at the ndef message free time. + 3. get, search : it gives original pointer to you, DO NOT free the pointer get from nfc-manager API + 4. remove: automatically free inside of the this function do not free again. + 5. create: it allocate handle, therefore, you should consider free after using (for example "net_nfc_create_rawdata_from_ndef_message(ndef_message_h ndef_message, data_h *rawdata)" + this function allocate the data_h, you should free data with the function net_nfc_free_data()) +

+ + @} + */ + +/** + @addtogroup NET_NFC_TYPEDEF + @{ + This documents provide the NFC defines + + */ +#include +#include +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + +/** + net_nfc_error_e is enum type that returned from each functions + it mostly contains the error codes and it may contains status codes. + */ +typedef enum +{ +/*000*/NET_NFC_OK = 0, /**< Status is OK */ +/*999*/NET_NFC_UNKNOWN_ERROR = -999, /**< Unknown error */ +/*998*/NET_NFC_ALLOC_FAIL, /**< Memory allocation is failed */ +/*997*/NET_NFC_THREAD_CREATE_FAIL, /**< Thread creation is failed */ +/*996*/NET_NFC_INVALID_STATE, /**< State of NFC-Manager or nfc-stack is not normal */ +/*995*/NET_NFC_IPC_FAIL, /**< Communication with ipc is failed. (from client to server)*/ +/*994*/NET_NFC_OUT_OF_BOUND, /**< Index is out of bound */ +/*993*/NET_NFC_NULL_PARAMETER, /**< Unexpected NULL parameter is received */ +/*992*/NET_NFC_BUFFER_TOO_SMALL, /**< Requested buffer is too small to store data, this error should be received */ +/*991*/NET_NFC_ALREADY_INITIALIZED, /**< You tried to initialized again without de-init */ +/*990*/NET_NFC_COMMUNICATE_WITH_CONTROLLER_FAILED, /**< Communication with Controller Chipset is failed this is Fatal Error */ +/*989*/NET_NFC_RF_TIMEOUT, /**< Timeout is raised while communicate with a tag */ +/*988*/NET_NFC_RF_ERROR, /**< Unexpected package is received from target, you may receive this error comes by the low level RF communication fault*/ +/*987*/NET_NFC_NOT_INITIALIZED, /**< Application tries to request without initialization */ +/*986*/NET_NFC_NOT_SUPPORTED, /**< Request information or command is not supported in current connected target */ +/*985*/NET_NFC_ALREADY_REGISTERED, /**< Requested SAP number is already used by other socket or data is already appended or registered */ +/*984*/NET_NFC_NOT_ALLOWED_OPERATION, /**< Requested Operation is not allowed in the situation in critical time (such as write data on target)*/ +/*983*/NET_NFC_BUSY, /**< Previous operation is not finished. don't worry to get this message, most of request will be executed in the serial queue */ +/*982*/NET_NFC_INVALID_HANDLE, /**< Requested Device in not valid device */ +/*981*/NET_NFC_TAG_READ_FAILED, /**< Tag reading is failed because of unexpected chunk data is received or error ack is received */ +/*980*/NET_NFC_TAG_WRITE_FAILED, /**< When you try to write on read only tag or error ack is received */ +/*979*/NET_NFC_NO_NDEF_SUPPORT, /**< Tag is not supported NDEF format for tag is not formatted for NDEF */ +/*978*/NET_NFC_NO_NDEF_MESSAGE, /**< No data is received after NDEF reading */ +/*977*/NET_NFC_INVALID_FORMAT, /**< Received data is not readable or it has illegal values or format */ +/*976*/NET_NFC_INSUFFICIENT_STORAGE, /**< The connected tag does not have enough information */ +/*975*/NET_NFC_OPERATION_FAIL, /**< The remote target returned error while doing a operation*/ +/*974*/NET_NFC_NOT_CONNECTED, /**< remote is not connected correctly. This can be happened when the RF does not have enough strength */ +/*973*/NET_NFC_NO_DATA_FOUND, /**< Requested data is not found in the list or properties */ +/*972*/NET_NFC_SECURITY_FAIL, /**< Authentication is failed while communication with nfc-manager server */ +/*971*/NET_NFC_TARGET_IS_MOVED_AWAY, /**< Target is lost while doing a operation */ +/*970*/NET_NFC_TAG_IS_ALREADY_FORMATTED, /** Target is already formatted */ +/*969*/NET_NFC_NOT_REGISTERED, /**< removal is requested but requested data is not registered */ +/*968*/NET_NFC_INVALID_PARAM, /**< removal is requested but requested data is not registered */ +/*499*/NET_NFC_NDEF_TYPE_LENGTH_IS_NOT_OK = -499, /**< Illegal ndef record type length */ +/*498*/NET_NFC_NDEF_PAYLOAD_LENGTH_IS_NOT_OK, /**< Illegal ndef record payload length */ +/*497*/NET_NFC_NDEF_ID_LENGTH_IS_NOT_OK, /**< Illegal ndef record id length */ +/*496*/NET_NFC_NDEF_RECORD_IS_NOT_EXPECTED_TYPE, /**< Parameter record is not expected record. for example, try to URI from text record */ +/*495*/NET_NFC_NDEF_BUF_END_WITHOUT_ME, /**< NDEF messages is terminated without ME flag */ +/*494*/NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC, /**< Current device does not support NFC feature or this manager does not found plugin library */ + +/*399*/NET_NFC_LLCP_INVALID_SOCKET = -399, /**< socket is not valid socket */ +/*398*/NET_NFC_LLCP_SOCKET_DISCONNECTED, /**< socket is disconnected */ +/*397*/NET_NFC_LLCP_SOCKET_FRAME_REJECTED, /**< send data is rejected from remote side */ + +/*299*/NET_NFC_P2P_SEND_FAIL = -299, /**< P2P data send fail */ +} net_nfc_error_e; + +/** + Enum value of the record type ( TNF value ) + */ +typedef enum +{ + NET_NFC_RECORD_EMPTY = 0x0, + NET_NFC_RECORD_WELL_KNOWN_TYPE, + NET_NFC_RECORD_MIME_TYPE, // Media type + NET_NFC_RECORD_URI, + NET_NFC_RECORD_EXTERNAL_RTD, + NET_NFC_RECORD_UNKNOWN, + NET_NFC_RECORD_UNCHAGNED, +} net_nfc_record_tnf_e; + +/** + net_nfc_message_e is identify the events comes from nfc-manager. + most of the events response event that you requested operations. + and some of the events are generated by nfc-manager. (example, NET_NFC_MESSAGE_TAG_DISCOVERED, NET_NFC_MESSAGE_TAG_DETACHED, + NET_NFC_MESSAGE_LLCP_DISCOVERED and NET_NFC_MESSAGE_LLCP_DETACHED) + + All of the events are delivered by the the callback function that registered with "net_nfc_set_response_callback" + */ + +typedef enum +{ + NET_NFC_MESSAGE_TRANSCEIVE = 0, /**< Type: Response Event,
This events is received after calling the "net_nfc_tranceive" +
if the operation is success, the data parameter should cast into data_h or it return NULL*/ + NET_NFC_MESSAGE_READ_NDEF, /**< Type: Response Event,
This events is received after calling the "net_nfc_read_tag" +
if the operation is success, the data parameter should cast into ndef_message_h or it return NULL */ + NET_NFC_MESSAGE_WRITE_NDEF, /**< Type: Response Event,
This events is received after calling the "net_nfc_write_ndef" +
data pointer always returns NULL */ + NET_NFC_MESSAGE_MAKE_READ_ONLY_NDEF, /**< Type: Response Event,
This events is received after calling the "net_nfc_make_read_only_ndef" +
data pointer always returns NULL */ + NET_NFC_MESSAGE_IS_TAG_CONNECTED, /**< Type: Response Event,
This events is received after calling the "net_nfc_is_tag_conneced" +
data pointer always returns NULL */ + NET_NFC_MESSAGE_GET_CURRENT_TAG_INFO, /**< Type: Response Event,
This events is received after calling the "net_nfc_get_current_tag_infof" +
if the operation is success, the data parameter should cast into net_nfc_target_info_h or it return NULL */ + NET_NFC_MESSAGE_GET_CURRENT_TARGET_HANDLE, /**< Type: Response Event,
This events is received after calling the "net_nfc_get_current_target_handle" +
if the operation is success, the data parameter should cast into net_nfc_target_handle_h or it return NULL */ + NET_NFC_MESSAGE_TAG_DISCOVERED, /**< Type: Notify Event,
When a tag or SE is detected, you got this event. +
The data contains the target info , need to cast to net_nfc_target_info_h*/ + NET_NFC_MESSAGE_NOTIFY, /**< This Notify Event
when the unexpected error has occurred, this event is delivered. data pointer always returns NULL */ + NET_NFC_MESSAGE_TAG_DETACHED, /**< Type: Notify Event,
When a tag or SE is disappeared, you got this event. +
The data contains the target info , need to cast to net_nfc_target_info_h but it does not have detail target info +
please, do not use "net_nfc_get_tag_info_keys" when you got this event*/ + NET_NFC_MESSAGE_FORMAT_NDEF, /**< Type: Response Event
After complete "net_nfc_format_ndef", this event is delivered */ + NET_NFC_MESSAGE_LLCP_DISCOVERED,/**< Type: Notify Event
When LLCP is discovered and remote device is support llcp, you receive this event +
data pointer contains the remote llcp configuration info. Cast to net_nfc_llcp_config_info_h*/ + NET_NFC_MESSAGE_P2P_DETACHED, /**< Type: Notify Event
When LLCP is de-activated by removing the device, you receive this event*/ + NET_NFC_MESSAGE_LLCP_CONFIG, /**< Type: Response Event.
The operation of "net_nfc_set_llcp_local_configure" is completed */ + + NET_NFC_MESSAGE_P2P_DISCOVERED, /**< Type: Notify Event
The remove device is detected and ready for transferring data to remote side */ + NET_NFC_MESSAGE_P2P_SEND, /**< Type: Response Event,
This events is received after calling the "net_nfc_send_exchanger_data" */ + NET_NFC_MESSAGE_P2P_RECEIVE, /**< Type: Notify Event,
When llcp server socket receive some data, this event is delivered. */ + + NET_NFC_MESSAGE_SE_START_TRANSACTION, /**< Type: Notify Event, indicates external reader start transaction*/ + NET_NFC_MESSAGE_SE_END_TRANSACTION, /**< Type: Notify Event, indicates external reader end transaction*/ + NET_NFC_MESSAGE_SE_TYPE_TRANSACTION, /**< Type: Notify Event, Indicates external reader trying to access secure element */ + NET_NFC_MESSAGE_SE_CONNECTIVITY, /**< Type: Notify Event, This event notifies the terminal host that it shall send a connectivity event from UICC */ + NET_NFC_MESSAGE_SE_FIELD_ON, /**< Type: Notify Event, indicates external reader field is on*/ + NET_NFC_MESSAGE_SE_FIELD_OFF, /**< Type: Notify Event, indicates external reader field is off*/ + NET_NFC_MESSAGE_SE_TYPE_CHANGED, /**< Type: Notify Event, indicates secure element type is changed*/ + + NET_NFC_MESSAGE_CONNECTION_HANDOVER, /**< Type: Response Event.
The result of connection handover. If it has been completed successfully, this event will include the information of alternative carrier. */ + + NET_NFC_MESSAGE_SET_SE, + NET_NFC_MESSAGE_GET_SE, + NET_NFC_MESSAGE_OPEN_INTERNAL_SE, + NET_NFC_MESSAGE_CLOSE_INTERNAL_SE, + NET_NFC_MESSAGE_SEND_APDU_SE, + NET_NFC_GET_SERVER_STATE, + + NET_NFC_MESSAGE_SIM_TEST, + + NET_NFC_MESSAGE_INIT,/*31*/ + NET_NFC_MESSAGE_DEINIT, + + NET_NFC_MESSAGE_PRBS_TEST, + + NET_NFC_MESSAGE_GET_FIRMWARE_VERSION, + + NET_NFC_MESSAGE_SET_EEDATA, +} net_nfc_message_e; + +typedef enum +{ + NET_NFC_UNKNOWN_TARGET = 0x00U, + + /* Specific PICC Devices */ + + NET_NFC_GENERIC_PICC, + NET_NFC_ISO14443_A_PICC, + NET_NFC_ISO14443_4A_PICC, + NET_NFC_ISO14443_3A_PICC, + NET_NFC_MIFARE_MINI_PICC, + NET_NFC_MIFARE_1K_PICC, + NET_NFC_MIFARE_4K_PICC, + NET_NFC_MIFARE_ULTRA_PICC, + NET_NFC_MIFARE_DESFIRE_PICC, + NET_NFC_ISO14443_B_PICC, + NET_NFC_ISO14443_4B_PICC, + NET_NFC_ISO14443_BPRIME_PICC, + NET_NFC_FELICA_PICC, + NET_NFC_JEWEL_PICC, + NET_NFC_ISO15693_PICC, + + /* NFC-IP1 Device Types */ + NET_NFC_NFCIP1_TARGET, + NET_NFC_NFCIP1_INITIATOR, + +} net_nfc_target_type_e; + +/** + Card states for nfc tag + */ +typedef enum +{ + NET_NFC_NDEF_CARD_INVALID = 0x00, /**< The card is not NFC forum specified tag. The ndef format will be needed. */ + NET_NFC_NDEF_CARD_INITIALISED, /**< The card is NFC forum specified tag, but It has no actual data. So, the ndef write will be needed. */ + NET_NFC_NDEF_CARD_READ_WRITE, /**< The card is NFC forum specified tag. The ndef read and write will be allowed. */ + NET_NFC_NDEF_CARD_READ_ONLY /**< The card is NFC forum specified tag, but only the ndef read will be allowed. */ +} net_nfc_ndef_card_state_e; + +/** + Encoding type for string message + */ +typedef enum +{ + NET_NFC_ENCODE_UTF_8 = 0x00, + NET_NFC_ENCODE_UTF_16, +} net_nfc_encode_type_e; + +/** + URI scheme type defined in the NFC forum "URI Record Type Definition" + */ +typedef enum +{ + NET_NFC_SCHEMA_FULL_URI = 0x00, /**< protocol is specify by payload */ + NET_NFC_SCHEMA_HTTP_WWW, /**< http://www. */ + NET_NFC_SCHEMA_HTTPS_WWW, /**< https://www. */ + NET_NFC_SCHEMA_HTTP, /**< http:// */ + NET_NFC_SCHEMA_HTTPS, /**< https:// */ + NET_NFC_SCHEMA_TEL, /**< tel: */ + NET_NFC_SCHEMA_MAILTO, /**< mailto: */ + NET_NFC_SCHEMA_FTP_ANONYMOUS, /**< ftp://anonymouse:anonymouse@ */ + NET_NFC_SCHEMA_FTP_FTP, /**< ftp://ftp. */ + NET_NFC_SCHEMA_FTPS, /**< ftps:// */ + NET_NFC_SCHEMA_SFTP, /**< sftp:// */ + NET_NFC_SCHEMA_SMB, /**< smb:// */ + NET_NFC_SCHEMA_NFS, /**< nfs:// */ + NET_NFC_SCHEMA_FTP, /**< ftp:// */ + NET_NFC_SCHEMA_DAV, /**< dav:// */ + NET_NFC_SCHEMA_NEWS, /**< news:// */ + NET_NFC_SCHEMA_TELNET, /**< telnet:// */ + NET_NFC_SCHEMA_IMAP, /**< imap: */ + NET_NFC_SCHEMA_RTSP, /**< rtsp:// */ + NET_NFC_SCHEMA_URN, /**< urn: */ + NET_NFC_SCHEMA_POP, /**< pop: */ + NET_NFC_SCHEMA_SIP, /**< sip: */ + NET_NFC_SCHEMA_SIPS, /**< sips: */ + NET_NFC_SCHEMA_TFTP, /**< tftp: */ + NET_NFC_SCHEMA_BTSPP, /**< btspp:// */ + NET_NFC_SCHEMA_BTL2CAP, /**< btl2cap:// */ + NET_NFC_SCHEMA_BTGOEP, /**< btgoep:// */ + NET_NFC_SCHEMA_TCPOBEX, /**< tcpobex:// */ + NET_NFC_SCHEMA_IRDAOBEX, /**< irdaobex:// */ + NET_NFC_SCHEMA_FILE, /**< file:// */ + NET_NFC_SCHEMA_URN_EPC_ID, /**< urn:epc:id: */ + NET_NFC_SCHEMA_URN_EPC_TAG, /**< urn:epc:tag: */ + NET_NFC_SCHEMA_URN_EPC_PAT, /**< urn:epc:pat: */ + NET_NFC_SCHEMA_URN_EPC_RAW, /**< urn:epc:raw: */ + NET_NFC_SCHEMA_URN_EPC, /**< urn:epc: */ + NET_NFC_SCHEMA_URN_NFC, /**< urn:epc:nfc: */ + NET_NFC_SCHEMA_MAX /**< -- indicating max-- */ +} net_nfc_schema_type_e; + +// this is for target detect event filter + +typedef enum +{ + NET_NFC_ALL_DISABLE = 0x0000, + NET_NFC_ISO14443A_ENABLE = 0x0001, + NET_NFC_ISO14443B_ENABLE = 0x0002, + NET_NFC_ISO15693_ENABLE = 0x0004, + NET_NFC_FELICA_ENABLE = 0x0008, + NET_NFC_JEWEL_ENABLE = 0x0010, + NET_NFC_IP_ENABLE = 0x0020, + NET_NFC_ALL_ENABLE = ~0, + +} net_nfc_event_filter_e; + +/* + ************************************** + LLCP defines + ************************************** + */ +/** + These events are delivered to the each socket callback. These events are separated events that comes from "net_nfc_set_response_callback" callback + */ +typedef enum +{ + /* start number should be larger than "net_nfc_message_e" + because to make seperate with net_nfc_message_e event it may conflict in + the dispatcher and ipc part */ + NET_NFC_MESSAGE_LLCP_LISTEN = 1000, /**< Type: Response Event
this event indicates "net_nfc_listen_llcp" requested is completed*/ + NET_NFC_MESSAGE_LLCP_ACCEPTED, /**< Type: Notify Event.
Remote socket is accepted to listening socket +
data pointer contains the remote socket info (Cast to net_nfc_llcp_socket_option_h)*/ + NET_NFC_MESSAGE_LLCP_CONNECT, /**< Type: Response Event.
"net_nfc_connect_llcp_with" request is completed and your socket is connected to remote site with url*/ + NET_NFC_MESSAGE_LLCP_CONNECT_SAP, /**< Type: Response Event.
"net_nfc_connect_llcp_with_sap" request is completed and your socket is connected to remote site with sap number*/ + NET_NFC_MESSAGE_LLCP_SEND, /**< Type: Response Event,
"net_nfc_send_llcp" operation is completed (connection mode)*/ + NET_NFC_MESSAGE_LLCP_SEND_TO, /**< Type: Response Event,
"net_nfc_send_llcp_to"operation is completed (connectionless mode)*/ + NET_NFC_MESSAGE_LLCP_RECEIVE, /**< Type: Response Event,
"net_nfc_receive_llcp" operation is completed (connection mode) +
data pointer contains received data (Cast to data_h)*/ + NET_NFC_MESSAGE_LLCP_RECEIVE_FROM, /**< Type: Response Event,
"net_nfc_receive_llcp_from" operation is completed (connectionless mode)*/ + NET_NFC_MESSAGE_LLCP_DISCONNECT, /**< Type: Response Event,
"net_nfc_disconnect_llcp" request is completed */ + NET_NFC_MESSAGE_LLCP_ERROR, /**< Type: Notify Event,
when the socket is disconnected or rejected, you may receive this event */ + +} net_nfc_llcp_message_e; + +typedef enum +{ + NET_NFC_LLCP_SOCKET_TYPE_CONNECTIONORIENTED, + NET_NFC_LLCP_SOCKET_TYPE_CONNECTIONLESS, +} net_nfc_socket_type_e; + +typedef enum +{ + NET_NFC_SNEP = 0x00, + NET_NFC_NPP, +} llcp_app_protocol_e; + +typedef struct data_s *data_h; + +typedef struct ndef_record_s *ndef_record_h; + +typedef struct ndef_message_s *ndef_message_h; + +typedef struct net_nfc_target_info_s *net_nfc_target_info_h; + +typedef uint32_t net_nfc_traceive_cmd; + +typedef struct net_nfc_llcp_config_info_s *net_nfc_llcp_config_info_h; + +typedef struct net_nfc_llcp_socket_option_s *net_nfc_llcp_socket_option_h; + +typedef struct net_nfc_target_handle_s *net_nfc_target_handle_h; + +typedef struct net_nfc_connection_handover_info_s *net_nfc_connection_handover_info_h; + +typedef uint8_t sap_t; + +typedef uint32_t net_nfc_llcp_socket_t; + +// LLCP Callback +typedef void (*net_nfc_llcp_socket_cb)(net_nfc_llcp_message_e message, net_nfc_error_e result, void *data, void *user_data, void *trans_data); + +// Main Callback +typedef void (*net_nfc_response_cb)(net_nfc_message_e message, net_nfc_error_e result, void *data, void *user_param, void *trans_data); + +typedef void (*net_nfc_internal_se_response_cb)(net_nfc_message_e message, net_nfc_error_e result, void *data, void *user_param, void *trans_data); + +typedef void (* net_nfc_set_activation_completed_cb)(net_nfc_error_e error, void *user_data); + +// for data exchanger + +typedef enum +{ + NET_NFC_EXCHANGER_DATA_REQUESTED = 0x00, + NET_NFC_EXCHANGER_TRANSFER_COMPLETED, + NET_NFC_EXCHANGER_TRANSFER_FAILED, +} net_nfc_exchanger_event_e; + +typedef enum +{ + NET_NFC_EXCHANGER_RAW, +} net_nfc_exchanger_data_type_e; + +typedef struct net_nfc_exchanger_data_s *net_nfc_exchanger_data_h; + +typedef net_nfc_exchanger_data_h (*net_nfc_exchanger_cb)(net_nfc_exchanger_event_e event, void *user_param); + +typedef enum +{ + NET_NFC_CONN_HANDOVER_CARRIER_BT = 0x00, + NET_NFC_CONN_HANDOVER_CARRIER_WIFI_BSS, /* infrastructure */ + NET_NFC_CONN_HANDOVER_CARRIER_WIFI_IBSS, /* add hoc */ + NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN, +} net_nfc_conn_handover_carrier_type_e; + +typedef enum +{ + NET_NFC_CONN_HANDOVER_CARRIER_INACTIVATE = 0x00, + NET_NFC_CONN_HANDOVER_CARRIER_ACTIVATE, + NET_NFC_CONN_HANDOVER_CARRIER_ACTIVATING, + NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN_STATUS, +} net_nfc_conn_handover_carrier_state_e; + +typedef struct net_nfc_conn_handover_carrier_info_s *net_nfc_conn_handover_carrier_info_h; +typedef struct net_nfc_conn_handover_info_s *net_nfc_conn_handover_info_h; + +#define MIFARE_KEY_DEFAULT {(uint8_t)0xFF,(uint8_t)0xFF,(uint8_t)0xFF,(uint8_t)0xFF,(uint8_t)0xFF,(uint8_t)0xFF} +#define MIFARE_KEY_APPLICATION_DIRECTORY {(uint8_t)0xA0,(uint8_t)0xA1,(uint8_t)0xA2,(uint8_t)0xA3,(uint8_t)0xA4,(uint8_t)0xA5} +#define MIFARE_KEY_NET_NFC_FORUM {(uint8_t)0xD3,(uint8_t)0xF7,(uint8_t)0xD3,(uint8_t)0xF7,(uint8_t)0xD3,(uint8_t)0xF7} +#define MIFARE_KEY_LENGTH 6 + +typedef enum +{ + NET_NFC_FELICA_POLL_NO_REQUEST = 0x00, + NET_NFC_FELICA_POLL_SYSTEM_CODE_REQUEST, + NET_NFC_FELICA_POLL_COMM_SPEED_REQUEST, + NET_NFC_FELICA_POLL_MAX = 0xFF, +} net_nfc_felica_poll_request_code_e; + +/** + WIFI configuration key enums for connection handover. + */ + +typedef enum +{ + NET_NFC_WIFI_ATTRIBUTE_VERSION = 0x104A, + NET_NFC_WIFI_ATTRIBUTE_CREDENTIAL = 0x100E, + NET_NFC_WIFI_ATTRIBUTE_NET_INDEX = 0x1026, + NET_NFC_WIFI_ATTRIBUTE_SSID = 0x1045, + NET_NFC_WIFI_ATTRIBUTE_AUTH_TYPE = 0x1003, /*< WPA2PSK 0x0020 */ + NET_NFC_WIFI_ATTRIBUTE_ENC_TYPE = 0x100F, /*< AES 0x0008 */ + NET_NFC_WIFI_ATTRIBUTE_NET_KEY = 0x1027, + NET_NFC_WIFI_ATTRIBUTE_MAC_ADDR = 0x1020, + NET_NFC_WIFI_ATTRIBUTE_CHANNEL = 0x1001, /* Channel number - based on IEEE */ + NET_NFC_WIFI_ATTRIBUTE_VEN_EXT = 0x1049, + NET_NFC_WIFI_ATTRIBUTE_VERSION2 = 0x00, +} net_nfc_carrier_wifi_attribute_e; + +typedef enum +{ + NET_NFC_BT_ATTRIBUTE_UUID16_PART = 0x02, /* More 16-bit UUIDs available */ + NET_NFC_BT_ATTRIBUTE_UUID16 = 0x03, /* Complete list of 16-bit UUIDs */ + NET_NFC_BT_ATTRIBUTE_UUID32_PART = 0x04, /* More 32-bit UUIDs available */ + NET_NFC_BT_ATTRIBUTE_UUID32 = 0x05, /* Complete list of 32-bit UUIDs */ + NET_NFC_BT_ATTRIBUTE_UUID128_PART = 0x06, /* More 128-bit UUIDs available */ + NET_NFC_BT_ATTRIBUTE_UUID128 = 0x07, /* Complete list of 128-bit UUIDs */ + NET_NFC_BT_ATTRIBUTE_NAME_PART = 0x08, /* Shortened local name */ + NET_NFC_BT_ATTRIBUTE_NAME = 0x09, /* Complete local name */ + NET_NFC_BT_ATTRIBUTE_TXPOWER = 0x0a, /* TX Power level */ + NET_NFC_BT_ATTRIBUTE_OOB_COD = 0x0d, /* SSP OOB Class of Device */ + NET_NFC_BT_ATTRIBUTE_OOB_HASH_C = 0x0e, /* SSP OOB Hash C */ + NET_NFC_BT_ATTRIBUTE_OOB_HASH_R = 0x0f, /* SSP OOB Randomizer R */ + NET_NFC_BT_ATTRIBUTE_ID = 0x10, /* Device ID */ + NET_NFC_BT_ATTRIBUTE_MANUFACTURER = 0xFF, /* Manufacturer Specific Data */ + NET_NFC_BT_ATTRIBUTE_ADDRESS = 0xF0, /* Bluetooth device Address */ +} net_nfc_handover_bt_attribute_e; + +typedef struct net_nfc_carrier_config_s *net_nfc_carrier_config_h; +typedef struct net_nfc_carrier_property_s *net_nfc_property_group_h; + +typedef enum +{ + NET_NFC_SE_TYPE_NONE = 0x00,/**< Invalid */ + NET_NFC_SE_TYPE_ESE = 0x01,/**< SmartMX */ + NET_NFC_SE_TYPE_UICC = 0x02,/**< UICC */ + NET_NFC_SE_TYPE_SDCARD = 0x03, /* SDCard type is not currently supported */ +} net_nfc_se_type_e; + +typedef enum +{ + NET_NFC_SIGN_TYPE_NO_SIGN = 0, + NET_NFC_SIGN_TYPE_PKCS_1, + NET_NFC_SIGN_TYPE_PKCS_1_V_1_5, + NET_NFC_SIGN_TYPE_DSA, + NET_NFC_SIGN_TYPE_ECDSA, + NET_NFC_MAX_SIGN_TYPE, +} net_nfc_sign_type_t; + +typedef enum +{ + NET_NFC_CERT_FORMAT_X_509 = 0, + NET_NFC_CERT_FORMAT_X9_86, + NET_NFC_MAX_CERT_FORMAT, +} net_nfc_cert_format_t; + +#ifdef __cplusplus +} +#endif + +/** + @} + */ + +#endif + diff --git a/src/commonlib/include/net_nfc_typedef_private.h b/src/commonlib/include/net_nfc_typedef_private.h new file mode 100755 index 0000000..1e5a4cf --- /dev/null +++ b/src/commonlib/include/net_nfc_typedef_private.h @@ -0,0 +1,1313 @@ +/* + * Copyright (C) 2010 NXP Semiconductors + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + + + +#ifndef __NET_NFC_INTERNAL_TYPEDEF_H__ +#define __NET_NFC_INTERNAL_TYPEDEF_H__ + +#include "net_nfc_typedef.h" + + +typedef enum +{ + NET_NFC_POLL_START = 0x01, + NET_NFC_POLL_STOP, +} net_nfc_detect_mode_e; + +/** + This structure is just data, to express bytes array + */ +typedef struct _data_s +{ + uint8_t *buffer; + uint32_t length; +} data_s; + +typedef struct _net_nfc_data_t +{ + uint32_t length; + uint8_t buffer[0]; +} net_nfc_data_s; + +typedef enum _net_nfc_connection_type_e +{ + NET_NFC_TAG_CONNECTION = 0x00, + NET_NFC_P2P_CONNECTION_TARGET, + NET_NFC_P2P_CONNECTION_INITIATOR, + NET_NFC_SE_CONNECTION +} net_nfc_connection_type_e; + +typedef struct _net_nfc_target_handle_s +{ + uint32_t connection_id; + net_nfc_connection_type_e connection_type; + /*++npp++*/ + llcp_app_protocol_e app_type; + /*--npp--*/ +} net_nfc_target_handle_s; + +typedef struct _net_nfc_current_target_info_s +{ + net_nfc_target_handle_s *handle; + uint32_t devType; + int number_of_keys; + net_nfc_data_s target_info_values; +}net_nfc_current_target_info_s; + +typedef struct _net_nfc_llcp_config_info_s +{ + uint16_t miu; /** The remote Maximum Information Unit (NOTE: this is MIU, not MIUX !)*/ + uint16_t wks; /** The remote Well-Known Services*/ + uint8_t lto; /** The remote Link TimeOut (in 1/100s)*/ + uint8_t option; /** The remote options*/ +} net_nfc_llcp_config_info_s; + +typedef struct _net_nfc_llcp_socket_option_s +{ + uint16_t miu; /** The remote Maximum Information Unit */ + uint8_t rw; /** The Receive Window size (4 bits)*/ + net_nfc_socket_type_e type; +} net_nfc_llcp_socket_option_s; + +typedef struct _net_nfc_llcp_internal_socket_s +{ + uint16_t miu; /** The remote Maximum Information Unit */ + uint8_t rw; /** The Receive Window size (4 bits)*/ + net_nfc_socket_type_e type; + net_nfc_llcp_socket_t oal_socket; + net_nfc_llcp_socket_t client_socket; + sap_t sap; + uint8_t *service_name; + net_nfc_target_handle_s *device_id; + net_nfc_llcp_socket_cb cb; + bool close_requested; + void *register_param; /* void param that has been registered in callback register time */ +} net_nfc_llcp_internal_socket_s; + +/** + ndef_record_s structure has the NDEF record data. it is only a record not a message + */ +typedef struct _record_s +{ + uint8_t MB :1; + uint8_t ME :1; + uint8_t CF :1; + uint8_t SR :1; + uint8_t IL :1; + uint8_t TNF :3; + data_s type_s; + data_s id_s; + data_s payload_s; + struct _record_s *next; +} ndef_record_s; + +/** + NDEF message it has record counts and records (linked listed form) + */ +typedef struct _ndef_message_s +{ + uint32_t recordCount; + ndef_record_s *records; // linked list +} ndef_message_s; + +/** + Enum value to stop or start the discovery mode + */ + +#define NET_NFC_MAX_UID_LENGTH 0x0AU /**< Maximum UID length expected */ +#define NET_NFC_MAX_ATR_LENGTH 0x30U /**< Maximum ATR_RES (General Bytes) */ +#define NET_NFC_ATQA_LENGTH 0x02U /**< ATQA length */ +#define NET_NFC_ATQB_LENGTH 0x0BU /**< ATQB length */ + +#define NET_NFC_PUPI_LENGTH 0x04U /**< PUPI length */ +#define NET_NFC_APP_DATA_B_LENGTH 0x04U /**< Application Data length for Type B */ +#define NET_NFC_PROT_INFO_B_LENGTH 0x03U /**< Protocol info length for Type B */ + +#define NET_NFC_MAX_ATR_LENGTH 0x30U /**< Maximum ATR_RES (General Bytes) */ +#define NET_NFC_MAX_UID_LENGTH 0x0AU /**< Maximum UID length expected */ +#define NET_NFC_FEL_ID_LEN 0x08U /**< Felica current ID Length */ +#define NET_NFC_FEL_PM_LEN 0x08U /**< Felica current PM Length */ +#define NET_NFC_FEL_SYS_CODE_LEN 0x02U /**< Felica System Code Length */ + +#define NET_NFC_15693_UID_LENGTH 0x08U /**< Length of the Inventory bytes for */ + +typedef struct _net_nfc_sIso14443AInfo_t +{ + uint8_t Uid[NET_NFC_MAX_UID_LENGTH]; /**< UID information of the TYPE A Tag Discovered */ + uint8_t UidLength; /**< UID information length, shall not be greater than NET_NFC_MAX_UID_LENGTH i.e., 10 */ + uint8_t AppData[NET_NFC_MAX_ATR_LENGTH]; /**< Application data information of the tag discovered (= Historical bytes for type A) */ + uint8_t AppDataLength; /**< Application data length */ + uint8_t Sak; /**< SAK informationof the TYPE A Tag Discovered */ + uint8_t AtqA[NET_NFC_ATQA_LENGTH]; /**< ATQA informationof the TYPE A Tag Discovered */ + uint8_t MaxDataRate; /**< Maximum data rate supported by the TYPE A Tag Discovered */ + uint8_t Fwi_Sfgt; /**< Frame waiting time and start up frame guard time as defined in ISO/IEC 14443-4[7] for type A */ +} net_nfc_sIso14443AInfo_t; + +/** \ingroup grp_hal_nfci + * + * \brief Remote Device Reader B RF Gate Information Container + * + * The Reader B structure includes the available information + * related to the discovered ISO14443B remote device. This information + * is updated for every device discovery. + * \note None. + * + */ +typedef struct _net_nfc_sIso14443BInfo_t +{ + union net_nfc_uAtqBInfo + { + struct net_nfc_sAtqBInfo + { + uint8_t Pupi[NET_NFC_PUPI_LENGTH]; /**< PUPI information of the TYPE B Tag Discovered */ + uint8_t AppData[NET_NFC_APP_DATA_B_LENGTH]; /**< Application Data of the TYPE B Tag Discovered */ + uint8_t ProtInfo[NET_NFC_PROT_INFO_B_LENGTH]; /**< Protocol Information of the TYPE B Tag Discovered */ + } AtqResInfo; + uint8_t AtqRes[NET_NFC_ATQB_LENGTH]; /**< ATQB Response Information of TYPE B Tag Discovered */ + } AtqB; + + uint8_t HiLayerResp[NET_NFC_MAX_ATR_LENGTH]; /**< Higher Layer Response information in answer to ATRRIB Command for Type B */ + uint8_t HiLayerRespLength; /**< Higher Layer Response length */ + uint8_t Afi; /**< Application Family Identifier of TYPE B Tag Discovered */ + uint8_t MaxDataRate; /**< Maximum data rate supported by the TYPE B Tag Discovered */ +} net_nfc_sIso14443BInfo_t; + +/** \ingroup grp_hal_nfci + * + * \brief Remote Device Reader B prime RF Gate Information Container + * + */ +typedef struct _net_nfc_sIso14443BPrimeInfo_t +{ + void *BPrimeCtxt; +} net_nfc_sIso14443BPrimeInfo_t; + +/** \ingroup grp_hal_nfci + * + * \brief Remote Device Jewel Reader RF Gate Information Container + * + * The Jewel Reader structure includes the available information + * related to the discovered Jewel remote device. This information + * is updated for every device discovery. + * \note None. + * + */ +typedef struct _net_nfc_sJewelInfo_t +{ + uint8_t Uid[NET_NFC_MAX_UID_LENGTH]; /**< UID information of the TYPE A Tag Discovered */ + uint8_t UidLength; /**< UID information length, shall not be greater than NET_NFC_MAX_UID_LENGTH i.e., 10 */ + uint8_t HeaderRom0; /**< Header Rom byte zero */ + uint8_t HeaderRom1; /**< Header Rom byte one */ + +} net_nfc_sJewelInfo_t; + +/** \ingroup grp_hal_nfci + * + * \brief Remote Device Felica Reader RF Gate Information Container + * + * The Felica Reader structure includes the available information + * related to the discovered Felica remote device. This information + * is updated for every device discovery. + * \note None. + * + */ +typedef struct _net_nfc_sFelicaInfo_t +{ + uint8_t IDm[(NET_NFC_FEL_ID_LEN + 2)]; /**< Current ID of Felica tag */ + uint8_t IDmLength; /**< IDm length, shall not be greater than NET_NFC_FEL_ID_LEN i.e., 8 */ + uint8_t PMm[NET_NFC_FEL_PM_LEN]; /**< Current PM of Felica tag */ + uint8_t SystemCode[NET_NFC_FEL_SYS_CODE_LEN]; /**< System code of Felica tag */ +} net_nfc_sFelicaInfo_t; + +/** \ingroup grp_hal_nfci + * + * \brief Remote Device Reader 15693 RF Gate Information Container + * + * The Reader A structure includes the available information + * related to the discovered ISO15693 remote device. This information + * is updated for every device discovery. + * \note None. + * + */ + +typedef struct _net_nfc_sIso15693Info_t +{ + uint8_t Uid[NET_NFC_15693_UID_LENGTH]; /**< UID information of the 15693 Tag Discovered */ + uint8_t UidLength; /**< UID information length, shall not be greater than NET_NFC_15693_UID_LENGTH i.e., 8 */ + uint8_t Dsfid; /**< DSF information of the 15693 Tag Discovered */ + uint8_t Flags; /**< Information about the Flags in the 15693 Tag Discovered */ + uint8_t Afi; /**< Application Family Identifier of 15693 Tag Discovered */ +} net_nfc_sIso15693Info_t; + +/** \ingroup grp_hal_nfci + * + * \brief NFC Data Rate Supported between the Reader and the Target + * + * The \ref Halnet_nfc_eDataRate enum lists all the Data Rate + * values to be used to determine the rate at which the data is transmitted + * to the target. + * + * \note None. + */ + +/** \ingroup grp_hal_nfci + * + * \brief NFCIP1 Data rates + * + */ +typedef enum net_nfc_eDataRate_t +{ + net_nfc_eDataRate_106 = 0x00U, + net_nfc_eDataRate_212, + net_nfc_eDataRate_424, + net_nfc_eDataRate_RFU +} net_nfc_eDataRate_t; + +/** \ingroup grp_hal_nfci + * + * \brief NFCIP1 Gate Information Container + * + * The NFCIP1 structure includes the available information + * related to the discovered NFCIP1 remote device. This information + * is updated for every device discovery. + * \note None. + * + */ +typedef struct _net_nfc_sNfcIPInfo_t +{ + /* Contains the random NFCID3I conveyed with the ATR_REQ. + always 10 bytes length + or contains the random NFCID3T conveyed with the ATR_RES. + always 10 bytes length */ + uint8_t NFCID[NET_NFC_MAX_UID_LENGTH]; + uint8_t NFCID_Length; + /* ATR_RES = General bytes length, Max length = 48 bytes */ + uint8_t ATRInfo[NET_NFC_MAX_ATR_LENGTH]; + uint8_t ATRInfo_Length; + /**< SAK information of the tag discovered */ + uint8_t SelRes; + /**< ATQA information of the tag discovered */ + uint8_t SenseRes[NET_NFC_ATQA_LENGTH]; + /**< Is Detection Mode of the NFCIP Target Active */ + uint8_t nfcip_Active; + /**< Maximum frame length supported by the NFCIP device */ + uint16_t MaxFrameLength; + /**< Data rate supported by the NFCIP device */ + net_nfc_eDataRate_t nfcip_Datarate; + +} net_nfc_sNfcIPInfo_t; + +typedef union net_nfc_remoteDevInfo_t +{ + net_nfc_sIso14443AInfo_t Iso14443A_Info; + net_nfc_sIso14443BInfo_t Iso14443B_Info; + net_nfc_sIso14443BPrimeInfo_t Iso14443BPrime_Info; + net_nfc_sNfcIPInfo_t NfcIP_Info; + net_nfc_sFelicaInfo_t Felica_Info; + net_nfc_sJewelInfo_t Jewel_Info; + net_nfc_sIso15693Info_t Iso15693_Info; +} net_nfc_remoteDevInfo_t; + +typedef struct _net_nfc_tag_info_s +{ + char *key; + data_h value; +} net_nfc_tag_info_s; + +typedef struct _net_nfc_target_info_s +{ + net_nfc_target_handle_s *handle; + net_nfc_target_type_e devType; + uint8_t is_ndef_supported; + uint8_t ndefCardState; + uint32_t maxDataSize; + uint32_t actualDataSize; + int number_of_keys; + net_nfc_tag_info_s *tag_info_list; + char **keylist; + data_s raw_data; +} net_nfc_target_info_s; + +typedef struct _net_nfc_se_event_info_s +{ + data_s aid; + data_s param; +}net_nfc_se_event_info_s; + +typedef struct _net_nfc_transceive_info_s +{ + uint32_t dev_type; + data_s trans_data; +} net_nfc_transceive_info_s; + +typedef struct _net_nfc_connection_handover_info_s +{ + net_nfc_conn_handover_carrier_type_e type; + data_s data; +} +net_nfc_connection_handover_info_s; + +#ifdef BROADCAST_MESSAGE +typedef struct _net_nfc_server_received_message_s +{ + int mes_type; + int client_fd; + struct _net_nfc_server_received_message_s *next; +}net_nfc_server_received_message_s; +#endif + +typedef enum _client_state_e +{ + NET_NFC_CLIENT_INACTIVE_STATE = 0x00, + NET_NFC_CLIENT_ACTIVE_STATE, +} client_state_e; + +/* server state */ +#define NET_NFC_SERVER_IDLE 0 +#define NET_NFC_SERVER_DISCOVERY (1 << 1) +#define NET_NFC_TAG_CONNECTED (1 << 2) +#define NET_NFC_SE_CONNECTED (1 << 3) +#define NET_NFC_SNEP_CLIENT_CONNECTED (1 << 4) +#define NET_NFC_NPP_CLIENT_CONNECTED (1 << 5) +#define NET_NFC_SNEP_SERVER_CONNECTED (1 << 6) +#define NET_NFC_NPP_SERVER_CONNECTED (1 << 7) + +// these are messages for request +#define NET_NFC_REQUEST_MSG_HEADER \ + /* DON'T MODIFY THIS CODE - BEGIN */ \ + uint32_t length; \ + uint32_t request_type; \ + uint32_t client_fd; \ + uint32_t flags; \ + uint32_t user_param; \ + /* DON'T MODIFY THIS CODE - END */ + +typedef struct _net_nfc_request_msg_t +{ + NET_NFC_REQUEST_MSG_HEADER +} net_nfc_request_msg_t; + +typedef struct _net_nfc_request_change_client_state_t +{ + NET_NFC_REQUEST_MSG_HEADER + + client_state_e client_state; +} net_nfc_request_change_client_state_t; + +typedef struct _net_nfc_request_set_launch_state_t +{ + NET_NFC_REQUEST_MSG_HEADER + bool set_launch_popup; +}net_nfc_request_set_launch_state_t; + +typedef struct _net_nfc_request_transceive_t +{ + NET_NFC_REQUEST_MSG_HEADER + + net_nfc_target_handle_s *handle; + void *trans_param; + struct + { + uint32_t dev_type; + net_nfc_data_s trans_data; + } info; +} net_nfc_request_transceive_t; + +typedef struct _net_nfc_request_target_t +{ + NET_NFC_REQUEST_MSG_HEADER + + net_nfc_target_handle_s *handle; + void *trans_param; + uint32_t uint_param; + net_nfc_data_s data; +} net_nfc_request_target_t; + +typedef struct _net_nfc_request_read_ndef_t +{ + NET_NFC_REQUEST_MSG_HEADER + + net_nfc_target_handle_s *handle; + void *trans_param; +} net_nfc_request_read_ndef_t; + +typedef struct _net_nfc_request_test_t +{ + NET_NFC_REQUEST_MSG_HEADER + + net_nfc_target_handle_s *handle; + void *trans_param; + uint32_t tech; + uint32_t rate; +} net_nfc_request_test_t; + +typedef struct _net_nfc_eedata_register_t +{ + NET_NFC_REQUEST_MSG_HEADER + + net_nfc_target_handle_s *handle; + void *trans_param; + uint32_t mode; + uint32_t reg_id; + net_nfc_data_s data; +} net_nfc_request_eedata_register_t; + +typedef struct _net_nfc_request_make_read_only_ndef_t +{ + NET_NFC_REQUEST_MSG_HEADER + + net_nfc_target_handle_s *handle; + void *trans_param; +} net_nfc_request_make_read_only_ndef_t; + +typedef struct _net_nfc_request_is_tag_connected_t +{ + NET_NFC_REQUEST_MSG_HEADER + + void *trans_param; +} net_nfc_request_is_tag_connected_t; + +typedef struct _net_nfc_request_write_ndef_t +{ + NET_NFC_REQUEST_MSG_HEADER + + net_nfc_target_handle_s *handle; + void *trans_param; + net_nfc_data_s data; +} net_nfc_request_write_ndef_t; + +typedef struct _net_nfc_request_format_ndef_t +{ + NET_NFC_REQUEST_MSG_HEADER + + net_nfc_target_handle_s *handle; + void *trans_param; + net_nfc_data_s key; +} net_nfc_request_format_ndef_t; + +typedef struct _net_nfc_request_terminate_t +{ + NET_NFC_REQUEST_MSG_HEADER + + void *object; +} net_nfc_request_terminate_t; + + +typedef struct _net_nfc_request_reset_mode_t +{ + NET_NFC_REQUEST_MSG_HEADER + + int mode; +} net_nfc_request_reset_mode_t; + +typedef struct _net_nfc_request_target_detected_t +{ + NET_NFC_REQUEST_MSG_HEADER + + net_nfc_target_handle_s *handle; + uint32_t devType; + int number_of_keys; + net_nfc_data_s target_info_values; +} net_nfc_request_target_detected_t; + +typedef struct _net_nfc_request_se_event_t +{ + NET_NFC_REQUEST_MSG_HEADER + + data_s aid; + data_s param; +}net_nfc_request_se_event_t; + +typedef struct _net_nfc_request_get_current_tag_info_t +{ + NET_NFC_REQUEST_MSG_HEADER + + void *trans_param; +} net_nfc_request_get_current_tag_info_t; + +typedef struct _net_nfc_request_get_current_target_handle_t +{ + NET_NFC_REQUEST_MSG_HEADER + + void *trans_param; +} net_nfc_request_get_current_target_handle_t; + +typedef struct _net_nfc_request_llcp_msg_t +{ + NET_NFC_REQUEST_MSG_HEADER + + uint32_t result; +} net_nfc_request_llcp_msg_t; + +typedef struct _net_nfc_request_p2p_send_t +{ + NET_NFC_REQUEST_MSG_HEADER + + uint32_t result; + net_nfc_target_handle_s *handle; + net_nfc_exchanger_data_type_e data_type; + net_nfc_data_s data; +} net_nfc_request_p2p_send_t; + +typedef struct _net_nfc_request_accept_socket_t +{ + NET_NFC_REQUEST_MSG_HEADER + + uint32_t result; + net_nfc_target_handle_s *handle; + net_nfc_llcp_socket_t client_socket; + net_nfc_llcp_socket_t incomming_socket; + void *trans_param; +} net_nfc_request_accept_socket_t; + +typedef struct _net_nfc_request_terminate_socket_t +{ + NET_NFC_REQUEST_MSG_HEADER + + uint32_t result; + net_nfc_target_handle_s *handle; + net_nfc_llcp_socket_t llcp_socket; +} net_nfc_request_terminate_socket_t; + +typedef struct _net_nfc_request_listen_socket_t +{ + NET_NFC_REQUEST_MSG_HEADER + + uint32_t result; + net_nfc_target_handle_s *handle; + net_nfc_llcp_socket_t client_socket; + uint16_t miu; /** The remote Maximum Information Unit */ + uint8_t rw; /** The Receive Window size (4 bits)*/ + net_nfc_socket_type_e type; + net_nfc_llcp_socket_t oal_socket; + sap_t sap; + void *trans_param; + net_nfc_data_s service_name; +} net_nfc_request_listen_socket_t; + +typedef struct _net_nfc_request_reject_socket_t +{ + NET_NFC_REQUEST_MSG_HEADER + + uint32_t result; + net_nfc_target_handle_s *handle; + net_nfc_llcp_socket_t client_socket; + net_nfc_llcp_socket_t incomming_socket; + void *trans_param; +} net_nfc_request_reject_socket_t; + +typedef struct _net_nfc_request_connect_socket_t +{ + NET_NFC_REQUEST_MSG_HEADER + + uint32_t result; + net_nfc_target_handle_s *handle; + net_nfc_llcp_socket_t client_socket; + net_nfc_llcp_socket_t oal_socket; + uint16_t miu; /** The remote Maximum Information Unit */ + uint8_t rw; /** The Receive Window size (4 bits)*/ + net_nfc_socket_type_e type; + void *trans_param; + net_nfc_data_s service_name; +} net_nfc_request_connect_socket_t; + +typedef struct _net_nfc_request_connect_sap_socket_t +{ + NET_NFC_REQUEST_MSG_HEADER + + uint32_t result; + net_nfc_target_handle_s *handle; + net_nfc_llcp_socket_t client_socket; + net_nfc_llcp_socket_t oal_socket; + uint16_t miu; /** The remote Maximum Information Unit */ + uint8_t rw; /** The Receive Window size (4 bits)*/ + net_nfc_socket_type_e type; + sap_t sap; + void *trans_param; +} net_nfc_request_connect_sap_socket_t; + +typedef struct _net_nfc_request_disconnect_socket_t +{ + NET_NFC_REQUEST_MSG_HEADER + + uint32_t result; + net_nfc_target_handle_s *handle; + net_nfc_llcp_socket_t client_socket; + net_nfc_llcp_socket_t oal_socket; + void *trans_param; +} net_nfc_request_disconnect_socket_t; + +typedef struct _net_nfc_request_send_socket_t +{ + NET_NFC_REQUEST_MSG_HEADER + + uint32_t result; + net_nfc_target_handle_s *handle; + net_nfc_llcp_socket_t client_socket; + net_nfc_llcp_socket_t oal_socket; + void *trans_param; + net_nfc_data_s data; +} net_nfc_request_send_socket_t; + +typedef struct _net_nfc_request_receive_socket_t +{ + NET_NFC_REQUEST_MSG_HEADER + + uint32_t result; + net_nfc_target_handle_s *handle; + net_nfc_llcp_socket_t client_socket; + net_nfc_llcp_socket_t oal_socket; + size_t req_length; + void *trans_param; +} net_nfc_request_receive_socket_t; + +typedef struct _net_nfc_request_send_to_socket_t +{ + NET_NFC_REQUEST_MSG_HEADER + + uint32_t result; + net_nfc_target_handle_s *handle; + net_nfc_llcp_socket_t client_socket; + net_nfc_llcp_socket_t oal_socket; + void *trans_param; + net_nfc_data_s data; +} net_nfc_request_send_to_socket_t; + +typedef struct _net_nfc_request_receive_from_socket_t +{ + NET_NFC_REQUEST_MSG_HEADER + + uint32_t result; + net_nfc_target_handle_s *handle; + net_nfc_llcp_socket_t client_socket; + net_nfc_llcp_socket_t oal_socket; + size_t req_length; + void *trans_param; +} net_nfc_request_receive_from_socket_t; + +typedef struct _net_nfc_request_close_socket_t +{ + NET_NFC_REQUEST_MSG_HEADER + + uint32_t result; + net_nfc_target_handle_s *handle; + net_nfc_llcp_socket_t client_socket; + net_nfc_llcp_socket_t oal_socket; + void *trans_param; +} net_nfc_request_close_socket_t; + +typedef struct _net_nfc_request_config_llcp_t +{ + NET_NFC_REQUEST_MSG_HEADER + + uint32_t result; + net_nfc_target_handle_s *handle; + net_nfc_llcp_config_info_s config; + void *trans_param; +} net_nfc_request_config_llcp_t; + +typedef struct _net_nfc_response_llcp_socket_error_t +{ + NET_NFC_REQUEST_MSG_HEADER + + uint32_t result; + net_nfc_target_handle_s *handle; + net_nfc_llcp_socket_t oal_socket; + net_nfc_llcp_socket_t client_socket; + net_nfc_error_e error; + void *trans_param; +} net_nfc_response_llcp_socket_error_t; + +typedef struct _net_nfc_request_watch_dog_t +{ + NET_NFC_REQUEST_MSG_HEADER + + uint32_t devType; + net_nfc_target_handle_s *handle; +} net_nfc_request_watch_dog_t; + +typedef struct _net_nfc_request_set_se_t +{ + NET_NFC_REQUEST_MSG_HEADER + + uint8_t se_type; + void *trans_param; +} net_nfc_request_set_se_t; + +typedef struct _net_nfc_request_get_se_t +{ + NET_NFC_REQUEST_MSG_HEADER + + void *trans_param; +} net_nfc_request_get_se_t; + +typedef struct _net_nfc_request_open_internal_se_t +{ + NET_NFC_REQUEST_MSG_HEADER + + uint8_t se_type; + void *trans_param; +} net_nfc_request_open_internal_se_t; + +typedef struct _net_nfc_request_close_internal_se_t +{ + NET_NFC_REQUEST_MSG_HEADER + + net_nfc_target_handle_s *handle; + void *trans_param; +} net_nfc_request_close_internal_se_t; + +typedef struct _net_nfc_request_send_apdu_t +{ + NET_NFC_REQUEST_MSG_HEADER + + net_nfc_target_handle_s *handle; + void *trans_param; + net_nfc_data_s data; +} net_nfc_request_send_apdu_t; + +typedef struct _net_nfc_request_connection_handover_t +{ + NET_NFC_REQUEST_MSG_HEADER + + uint32_t result; + net_nfc_target_handle_s *handle; + net_nfc_conn_handover_carrier_type_e type; +} +net_nfc_request_connection_handover_t; + +// these are messages for response +// + +#define NET_NFC_RESPONSE_MSG_HEADER \ + /* DON'T MODIFY THIS CODE - BEGIN */ \ + uint32_t length; \ + uint32_t response_type; \ + uint32_t flags; \ + uint32_t user_param; \ + net_nfc_error_e result; + /* DON'T MODIFY THIS CODE - END */ + +typedef struct _net_nfc_response_msg_t +{ + NET_NFC_RESPONSE_MSG_HEADER +// int response_type; /* NET_NFC_MESSAGE : this type should be int DON'T USE enum! Because two enum values are used net_nfc_llcp_message_e and net_nfc_message_e enum */ + void *detail_message; +} net_nfc_response_msg_t; + +typedef struct _net_nfc_response_test_t +{ + NET_NFC_RESPONSE_MSG_HEADER + + void *trans_param; +} net_nfc_response_test_t; + +typedef struct _net_nfc_response_notify_t +{ + NET_NFC_RESPONSE_MSG_HEADER + +} net_nfc_response_notify_t; + +typedef struct _net_nfc_response_init_t +{ + NET_NFC_RESPONSE_MSG_HEADER + +} net_nfc_response_init_t; + +typedef struct _net_nfc_response_tag_discovered_t +{ + NET_NFC_RESPONSE_MSG_HEADER + + net_nfc_target_handle_s *handle; + uint32_t devType; + uint8_t is_ndef_supported; + uint8_t ndefCardState; + uint32_t maxDataSize; + uint32_t actualDataSize; + int number_of_keys; + data_s target_info_values; + data_s raw_data; +} net_nfc_response_tag_discovered_t; + +typedef struct _net_nfc_response_se_event_t +{ + NET_NFC_RESPONSE_MSG_HEADER + + data_s aid; + data_s param; +} net_nfc_response_se_event_t; + +typedef struct _net_nfc_response_get_current_tag_info_t +{ + NET_NFC_RESPONSE_MSG_HEADER + + net_nfc_target_handle_s *handle; + uint32_t devType; + uint8_t is_ndef_supported; + uint8_t ndefCardState; + uint32_t maxDataSize; + uint32_t actualDataSize; + int number_of_keys; + data_s target_info_values; + data_s raw_data; + void *trans_param; +} net_nfc_response_get_current_tag_info_t; + +typedef struct _net_nfc_response_get_current_target_handle_t +{ + NET_NFC_RESPONSE_MSG_HEADER + + net_nfc_target_handle_s *handle; + uint32_t devType; + void *trans_param; +} net_nfc_response_get_current_target_handle_t; + +typedef struct _net_nfc_response_target_detached_t +{ + NET_NFC_RESPONSE_MSG_HEADER + + net_nfc_target_handle_s *handle; + uint32_t devType; +} net_nfc_response_target_detached_t; + +typedef struct _net_nfc_response_transceive_t +{ + NET_NFC_RESPONSE_MSG_HEADER + + void *trans_param; + data_s data; +} net_nfc_response_transceive_t; + +typedef struct _net_nfc_response_read_ndef_t +{ + NET_NFC_RESPONSE_MSG_HEADER + + void *trans_param; + data_s data; +} net_nfc_response_read_ndef_t; + +typedef struct _net_nfc_response_write_ndef_t +{ + NET_NFC_RESPONSE_MSG_HEADER + + void *trans_param; +} net_nfc_response_write_ndef_t; + +typedef struct _net_nfc_response_make_read_only_ndef_t +{ + NET_NFC_RESPONSE_MSG_HEADER + + void *trans_param; +} net_nfc_response_make_read_only_ndef_t; + +typedef struct _net_nfc_response_is_tag_connected_t +{ + NET_NFC_RESPONSE_MSG_HEADER + + void *trans_param; + net_nfc_target_type_e devType; +} net_nfc_response_is_tag_connected_t; + +typedef struct _net_nfc_response_format_ndef_t +{ + NET_NFC_RESPONSE_MSG_HEADER + + void *trans_param; +} net_nfc_response_format_ndef_t; + +typedef struct _net_nfc_response_p2p_discovered_t +{ + NET_NFC_RESPONSE_MSG_HEADER + + net_nfc_target_handle_s *handle; +} net_nfc_response_p2p_discovered_t; + +typedef struct _net_nfc_response_p2p_send_t +{ + NET_NFC_RESPONSE_MSG_HEADER + + net_nfc_target_handle_s *handle; + void *trans_param; +} net_nfc_response_p2p_send_t; + +typedef struct _net_nfc_response_llcp_discovered_t +{ + NET_NFC_RESPONSE_MSG_HEADER + + net_nfc_target_handle_s *handle; + uint32_t devType; + int number_of_keys; + data_s target_info_values; + net_nfc_llcp_config_info_s llcp_config_info; +} net_nfc_response_llcp_discovered_t; + +typedef struct _net_nfc_response_llcp_detached_t +{ + NET_NFC_RESPONSE_MSG_HEADER + +} net_nfc_response_llcp_detached_t; + +typedef struct _net_nfc_response_incomming_llcp_t +{ + NET_NFC_RESPONSE_MSG_HEADER + + net_nfc_llcp_socket_t oal_socket; + net_nfc_llcp_socket_option_s option; + net_nfc_target_handle_s *handle; + net_nfc_llcp_socket_t incomming_socket; +} net_nfc_response_incomming_llcp_t; + +typedef struct _net_nfc_response_listen_llcp_t +{ + NET_NFC_RESPONSE_MSG_HEADER + + net_nfc_llcp_socket_t client_socket; + net_nfc_llcp_socket_t oal_socket; + void *trans_param; +} net_nfc_response_listen_socket_t; + +typedef struct _net_nfc_response_connect_llcp_t +{ + NET_NFC_RESPONSE_MSG_HEADER + + net_nfc_llcp_socket_t client_socket; + net_nfc_llcp_socket_t oal_socket; + void *trans_param; +} net_nfc_response_connect_socket_t; + +typedef struct _net_nfc_response_connect_sap_llcp_t +{ + NET_NFC_RESPONSE_MSG_HEADER + + net_nfc_llcp_socket_t client_socket; + net_nfc_llcp_socket_t oal_socket; + void *trans_param; +} net_nfc_response_connect_sap_socket_t; + +typedef struct _net_nfc_response_accept_llcp_t +{ + NET_NFC_RESPONSE_MSG_HEADER + + net_nfc_llcp_socket_t client_socket; + void *trans_param; +} net_nfc_response_accept_socket_t; + +typedef struct _net_nfc_response_reject_llcp_t +{ + NET_NFC_RESPONSE_MSG_HEADER + + net_nfc_llcp_socket_t client_socket; + void *trans_param; +} net_nfc_response_reject_socket_t; + +typedef struct _net_nfc_response_send_llcp_t +{ + NET_NFC_RESPONSE_MSG_HEADER + + net_nfc_llcp_socket_t client_socket; + void *trans_param; +} net_nfc_response_send_socket_t; + +typedef struct _net_nfc_response_receive_llcp_t +{ + NET_NFC_RESPONSE_MSG_HEADER + + net_nfc_llcp_socket_t client_socket; + data_s data; + void *trans_param; +} net_nfc_response_receive_socket_t; + +typedef struct _net_nfc_response_p2p_receive_t +{ + NET_NFC_RESPONSE_MSG_HEADER + + net_nfc_llcp_socket_t client_socket; + data_s data; +} net_nfc_response_p2p_receive_t; + +typedef struct _net_nfc_response_config_llcp_t +{ + NET_NFC_RESPONSE_MSG_HEADER + + void *trans_param; +} net_nfc_response_config_llcp_t; + +typedef struct _net_nfc_response_close_llcp_t +{ + NET_NFC_RESPONSE_MSG_HEADER + + net_nfc_llcp_socket_t client_socket; + void *trans_param; +} net_nfc_response_close_socket_t; + +typedef struct _net_nfc_response_disconnect_llcp_t +{ + NET_NFC_RESPONSE_MSG_HEADER + + net_nfc_llcp_socket_t client_socket; + void *trans_param; +} net_nfc_response_disconnect_socket_t; + +typedef struct _net_nfc_response_set_se_t +{ + NET_NFC_RESPONSE_MSG_HEADER + + uint8_t se_type; + void *trans_param; +} net_nfc_response_set_se_t; + +typedef struct _net_nfc_response_get_se_t +{ + NET_NFC_RESPONSE_MSG_HEADER + + uint8_t se_type; + void *trans_param; +} net_nfc_response_get_se_t; + +typedef struct _net_nfc_response_open_internal_se_t +{ + NET_NFC_RESPONSE_MSG_HEADER + + net_nfc_target_handle_s *handle; + uint8_t se_type; + void* trans_param; +} net_nfc_response_open_internal_se_t; + +typedef struct _net_nfc_response_close_internal_se_t +{ + NET_NFC_RESPONSE_MSG_HEADER + + void *trans_param; +} net_nfc_response_close_internal_se_t; + +typedef struct _net_nfc_response_send_apdu_t +{ + NET_NFC_RESPONSE_MSG_HEADER + + data_s data; + void *trans_param; +} net_nfc_response_send_apdu_t; + +typedef struct _net_nfc_response_get_server_state_t +{ + NET_NFC_RESPONSE_MSG_HEADER + + uint32_t state; +} net_nfc_response_get_server_state_t; + +typedef struct _net_nfc_response_connection_handover +{ + NET_NFC_RESPONSE_MSG_HEADER + + net_nfc_exchanger_event_e event; + net_nfc_conn_handover_carrier_type_e type; + data_s data; +} +net_nfc_response_connection_handover_t; + +typedef struct _net_nfc_response_get_firmware_version +{ + NET_NFC_RESPONSE_MSG_HEADER + + data_s data; +} +net_nfc_response_firmware_version_t; + +typedef struct _client_context +{ + void *register_user_param; /* parameter that registed in the cb register time */ + net_nfc_error_e result; + pthread_mutex_t g_client_lock; + net_nfc_event_filter_e filter; +#ifdef SAVE_TARGET_INFO_IN_CC + net_nfc_target_info_s *target_info; +#endif + bool initialized; +} client_context_t; + +// data exchanger +typedef struct _net_nfc_exchanger_data_s +{ + net_nfc_exchanger_data_type_e type; + data_s binary_data; /* this can be binary data */ +} net_nfc_exchanger_data_s; + +// these are messages for response + +typedef void (*target_detection_listener_cb)(void *data, void *user_param); +typedef void (*se_transaction_listener_cb)(void *data, void *user_param); +typedef void (*llcp_event_listener_cb)(void *data, void *user_param); + +typedef enum _llcp_event_e +{ + LLCP_EVENT_SOCKET_ACCEPTED = 0x1, + LLCP_EVENT_SOCKET_ERROR, + LLCP_EVENT_DEACTIVATED, +} llcp_event_e; + +typedef struct _net_nfc_stack_information_s +{ + uint32_t net_nfc_supported_tagetType; + uint32_t net_nfc_fw_version; +} net_nfc_stack_information_s; + +typedef enum _net_nfc_discovery_mode_e +{ + NET_NFC_DISCOVERY_MODE_CONFIG = 0x00U, + NET_NFC_DISCOVERY_MODE_START, + NET_NFC_DISCOVERY_MODE_STOP, + NET_NFC_DISCOVERY_MODE_RESUME, +} net_nfc_discovery_mode_e; + +typedef enum _net_nfc_secure_element_type_e +{ + SECURE_ELEMENT_TYPE_INVALID = 0x00, /**< Indicates SE type is Invalid */ + SECURE_ELEMENT_TYPE_ESE = 0x01, /**< Indicates SE type is SmartMX */ + SECURE_ELEMENT_TYPE_UICC = 0x02, /** "net_nfc_close_llcp_socket" request is completed */ + NET_NFC_MESSAGE_SERVICE_CHANGE_CLIENT_STATE, + NET_NFC_MESSAGE_SERVICE_WATCH_DOG, + NET_NFC_MESSAGE_SERVICE_CLEANER, + NET_NFC_MESSAGE_SERVICE_SET_LAUNCH_STATE, +} net_nfc_message_service_e; + +typedef enum _net_nfc_se_command_e +{ + NET_NFC_SE_CMD_UICC_ON = 0, + NET_NFC_SE_CMD_ESE_ON, + NET_NFC_SE_CMD_ALL_OFF, + NET_NFC_SE_CMD_ALL_ON, +} net_nfc_se_command_e; + +/* connection handover info */ + +typedef enum +{ + NET_NFC_CONN_HANDOVER_ERR_REASON_RESERVED = 0x00, + NET_NFC_CONN_HANDOVER_ERR_REASON_TEMP_MEM_CONSTRAINT, + NET_NFC_CONN_HANDOVER_ERR_REASON_PERM_MEM_CONSTRAINT, + NET_NFC_CONN_HANDOVER_ERR_REASON_CARRIER_SPECIFIC_CONSTRAINT, +} net_nfc_conn_handover_error_reason_e; + +/* WIFI Info */ +typedef struct _net_nfc_carrier_property_s +{ + bool is_group; + uint16_t attribute; + uint16_t length; + void *data; +} net_nfc_carrier_property_s; + +typedef struct _net_nfc_carrier_config_s +{ + net_nfc_conn_handover_carrier_type_e type; + int length; + struct _GList *data; +} net_nfc_carrier_config_s; + +typedef struct _net_nfc_sub_field_s +{ + uint16_t length; + uint8_t value[0]; +} +__attribute__((packed)) net_nfc_sub_field_s; + +typedef struct _net_nfc_signature_record_s +{ + uint8_t version; + uint8_t sign_type : 7; + uint8_t uri_present : 1; + net_nfc_sub_field_s signature; +} +__attribute__((packed)) net_nfc_signature_record_s; + +typedef struct _net_nfc_certificate_chain_s +{ + uint8_t num_of_certs : 4; + uint8_t cert_format : 3; + uint8_t uri_present : 1; + uint8_t cert_store[0]; +} +__attribute__((packed)) net_nfc_certificate_chain_s; + +#define SMART_POSTER_RECORD_TYPE "Sp" +#define URI_RECORD_TYPE "U" +#define TEXT_RECORD_TYPE "T" +#define GC_RECORD_TYPE "Gc" +#define SIGNATURE_RECORD_TYPE "Sig" +#define CONN_HANDOVER_REQ_RECORD_TYPE "Hr" +#define CONN_HANDOVER_SEL_RECORD_TYPE "Hs" +#define CONN_HANDOVER_CAR_RECORD_TYPE "Hc" +#define COLLISION_DETECT_RECORD_TYPE "cr" +#define ALTERNATIVE_RECORD_TYPE "ac" +#define ERROR_RECORD_TYPE "err" + +#define URI_SCHEM_FILE "file://" + +#define UICC_TARGET_HANDLE 0xFF + + +#endif diff --git a/src/commonlib/include/net_nfc_util_defines.h b/src/commonlib/include/net_nfc_util_defines.h new file mode 100755 index 0000000..2194c03 --- /dev/null +++ b/src/commonlib/include/net_nfc_util_defines.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __NET_NFC_UTIL_DEFINES__ +#define __NET_NFC_UTIL_DEFINES__ + +#define NET_NFC_UTIL_MSG_TYPE_REQUEST 0 +#define NET_NFC_UTIL_MSG_TYPE_RESPONSE 1 + +#define CONN_HANOVER_MAJOR_VER 1 +#define CONN_HANOVER_MINOR_VER 2 + +#define CONN_HANDOVER_BT_CARRIER_MIME_NAME "application/vnd.bluetooth.ep.oob" +#define CONN_HANDOVER_WIFI_BSS_CARRIER_MIME_NAME "application/vnd.wfa.wsc" +#define CONN_HANDOVER_WIFI_IBSS_CARRIER_MIME_NAME "application/vnd.wfa.wsc;mode=ibss" + +#define BLUETOOTH_ADDRESS_LENGTH 6 +#define HIDDEN_BT_ADDR_FILE "/opt/etc/.bd_addr" + +/* define vconf key */ +#define NET_NFC_DISABLE_LAUNCH_POPUP_KEY "memory/private/nfc-manager/popup_disabled"//"memory/nfc/popup_disabled" + +#endif diff --git a/src/commonlib/include/net_nfc_util_handover.h b/src/commonlib/include/net_nfc_util_handover.h new file mode 100755 index 0000000..11cafc1 --- /dev/null +++ b/src/commonlib/include/net_nfc_util_handover.h @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#ifndef __NET_NFC_UTIL_HANDOVER__ +#define __NET_NFC_UTIL_HANDOVER__ + +#include "net_nfc_typedef_private.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +net_nfc_error_e net_nfc_util_create_carrier_config(net_nfc_carrier_config_s **config, net_nfc_conn_handover_carrier_type_e type); + +net_nfc_error_e net_nfc_util_add_carrier_config_property(net_nfc_carrier_config_s *config, uint16_t attribute, uint16_t size, uint8_t *data); + +net_nfc_error_e net_nfc_util_remove_carrier_config_property(net_nfc_carrier_config_s *config, uint16_t attribute); + +net_nfc_error_e net_nfc_util_get_carrier_config_property(net_nfc_carrier_config_s *config, uint16_t attribute, uint16_t *size, uint8_t **data); + +net_nfc_error_e net_nfc_util_append_carrier_config_group(net_nfc_carrier_config_s *config, net_nfc_carrier_property_s *group); + +net_nfc_error_e net_nfc_util_remove_carrier_config_group(net_nfc_carrier_config_s *config, net_nfc_carrier_property_s *group); + +net_nfc_error_e net_nfc_util_get_carrier_config_group(net_nfc_carrier_config_s *config, int index, net_nfc_carrier_property_s **group); + +net_nfc_error_e net_nfc_util_free_carrier_config(net_nfc_carrier_config_s *config); + +net_nfc_error_e net_nfc_util_create_carrier_config_group(net_nfc_carrier_property_s **group, uint16_t attribute); + +net_nfc_error_e net_nfc_util_add_carrier_config_group_property(net_nfc_carrier_property_s *group, uint16_t attribute, uint16_t size, uint8_t *data); + +net_nfc_error_e net_nfc_util_get_carrier_config_group_property(net_nfc_carrier_property_s *group, uint16_t attribute, uint16_t *size, uint8_t **data); + +net_nfc_error_e net_nfc_util_remove_carrier_config_group_property(net_nfc_carrier_property_s *group, uint16_t attribute); + +net_nfc_error_e net_nfc_util_free_carrier_group(net_nfc_carrier_property_s *group); + +net_nfc_error_e net_nfc_util_create_ndef_record_with_carrier_config(ndef_record_s **record, net_nfc_carrier_config_s *config); + +net_nfc_error_e net_nfc_util_create_carrier_config_from_config_record(net_nfc_carrier_config_s **config, ndef_record_s *record); + +net_nfc_error_e net_nfc_util_append_carrier_config_record(ndef_message_s *message, ndef_record_s *record, net_nfc_conn_handover_carrier_state_e power_status); + +net_nfc_error_e net_nfc_util_remove_carrier_config_record(ndef_message_s *message, ndef_record_s *record); + +net_nfc_error_e net_nfc_util_get_carrier_config_record(ndef_message_s *message, int index, ndef_record_s **record); + +net_nfc_error_e net_nfc_util_get_handover_random_number(ndef_message_s *message, unsigned short *random_number); + +net_nfc_error_e net_nfc_util_get_alternative_carrier_record_count(ndef_message_s *message, unsigned int *count); + +net_nfc_error_e net_nfc_util_get_alternative_carrier_power_status(ndef_message_s *message, int index, net_nfc_conn_handover_carrier_state_e *power_state); + +net_nfc_error_e net_nfc_util_set_alternative_carrier_power_status(ndef_message_s *message, int index, net_nfc_conn_handover_carrier_state_e power_status); + +net_nfc_error_e net_nfc_util_get_alternative_carrier_type_from_record(ndef_record_s *record, net_nfc_conn_handover_carrier_type_e *type); + +/** + this function will get carrier type. + + @param[in] carrier_info connection handover carrier info handler + @param[in] carrier_type record type. it can be a NET_NFC_CONN_HANDOVER_CARRIER_BT or NET_NFC_CONN_HANDOVER_CARRIER_WIFI or NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN. + + @return return the result of the calling the function + + @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illegal NULL pointer(s) + */ +net_nfc_error_e net_nfc_util_get_alternative_carrier_type(ndef_message_s *message, int index, net_nfc_conn_handover_carrier_type_e *power_state); + +net_nfc_error_e net_nfc_util_create_handover_request_message(ndef_message_s **message); + +net_nfc_error_e net_nfc_util_create_handover_select_message(ndef_message_s **message); + +net_nfc_error_e net_nfc_util_create_handover_error_record(ndef_record_s **record, uint8_t reason, uint32_t data); + +net_nfc_error_e net_nfc_util_get_selector_power_status(ndef_message_s *message, net_nfc_conn_handover_carrier_state_e *power_state); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/commonlib/include/net_nfc_util_ipc.h b/src/commonlib/include/net_nfc_util_ipc.h new file mode 100644 index 0000000..ff4e611 --- /dev/null +++ b/src/commonlib/include/net_nfc_util_ipc.h @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef NET_NFC_UTIL_IPC_H_ +#define NET_NFC_UTIL_IPC_H_ + +#define NET_NFC_SERVER_ADDRESS "127.0.0.1" +#define NET_NFC_SERVER_PORT 3000 +#define NET_NFC_SERVER_DOMAIN "/tmp/nfc-manager-server-domain" + +#define NET_NFC_MAX_MESSAGE_LENGTH (1024 * 512) + +#define NET_NFC_FLAGS_SYNC_CALL (1 << 0) +#define NET_NFC_FLAGS_NO_RESPONSE (1 << 1) + +#define NET_NFC_IS_FLAGS_SET(__var, __flag) (((__var) & (__flag)) == (__flag)) +#define NET_NFC_SET_FLAGS(__var, __flag) (__var) |= (__flag) +#define NET_NFC_UNSET_FLAGS(__var, __flag) (__var) &= ~(__flag) + +#define NET_NFC_FLAGS_SET_SYNC_CALL(__var) NET_NFC_SET_FLAGS(__var, NET_NFC_FLAGS_SYNC_CALL) +#define NET_NFC_FLAGS_UNSET_SYNC_CALL(__var) NET_NFC_UNSET_FLAGS(__var, NET_NFC_FLAGS_SYNC_CALL) +#define NET_NFC_FLAGS_IS_SYNC_CALL(__var) NET_NFC_IS_FLAGS_SET(__var, NET_NFC_FLAGS_SYNC_CALL) + +#define NET_NFC_FLAGS_SET_NO_RESPONSE(__var) NET_NFC_SET_FLAGS(__var, NET_NFC_FLAGS_NO_RESPONSE) +#define NET_NFC_FLAGS_UNSET_NO_RESPONSE(__var) NET_NFC_UNSET_FLAGS(__var, NET_NFC_FLAGS_NO_RESPONSE) +#define NET_NFC_FLAGS_IS_NO_RESPONSE(__var) NET_NFC_IS_FLAGS_SET(__var, NET_NFC_FLAGS_NO_RESPONSE) + +int net_nfc_util_get_va_list_length(va_list list); +int net_nfc_util_fill_va_list(uint8_t *buffer, int length, va_list list); +void net_nfc_util_set_non_block_socket(int socket); + +#endif /* NET_NFC_UTIL_IPC_H_ */ diff --git a/src/commonlib/include/net_nfc_util_ndef_message.h b/src/commonlib/include/net_nfc_util_ndef_message.h new file mode 100755 index 0000000..2aa6db3 --- /dev/null +++ b/src/commonlib/include/net_nfc_util_ndef_message.h @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#ifndef __NET_NFC_UTIL_NDEF_MESSAGE__ +#define __NET_NFC_UTIL_NDEF_MESSAGE__ + +#include "net_nfc_typedef_private.h" + +/** + * \brief These are the flags specifying the content, structure or purpose of a NDEF Record. + * \name NDEF Record Header Flags + * + * Flags of the first record byte, as defined by the NDEF specification. + * + */ +/*@{*/ +#define NET_NFC_NDEF_RECORD_MASK_MB 0x80 /**< This marks the begin of a NDEF Message. */ +#define NET_NFC_NDEF_RECORD_MASK_ME 0x40 /**< Set if the record is at the Message End. */ +#define NET_NFC_NDEF_RECORD_MASK_CF 0x20 /**< Chunk Flag: The record is a record chunk only. */ +#define NET_NFC_NDEF_RECORD_MASK_SR 0x10 /**< Short Record: Payload Length is encoded in ONE byte only. */ +#define NET_NFC_NDEF_RECORD_MASK_IL 0x08 /**< The ID Length Field is present. */ +#define NET_NFC_NDEF_RECORD_MASK_TNF 0x07 /**< Type Name Format. */ +/*@}*/ + +/* Internal: + * NDEF Record #defines for constant value + */ + +#define NET_NFC_NDEF_TNF_EMPTY 0x00 /**< Empty Record, no type, ID or payload present. */ +#define NET_NFC_NDEF_TNF_NFCWELLKNOWN 0x01 /**< NFC well-known type (RTD). */ +#define NET_NFC_NDEF_TNF_MEDIATYPE 0x02 /**< Media Type. */ +#define NET_NFC_NDEF_TNF_ABSURI 0x03 /**< Absolute URI. */ +#define NET_NFC_NDEF_TNF_NFCEXT 0x04 /**< Nfc External Type (following the RTD format). */ +#define NET_NFC_NDEF_TNF_UNKNOWN 0x05 /**< Unknown type; Contains no Type information. */ +#define NET_NFC_NDEF_TNF_UNCHANGED 0x06 /**< Unchanged: Used for Chunked Records. */ +#define NET_NFC_NDEF_TNF_RESERVED 0x07 /**< RFU, must not be used. */ + +/* + convert rawdata into ndef message structure + */ +net_nfc_error_e net_nfc_util_convert_rawdata_to_ndef_message(data_s *rawdata, ndef_message_s *ndef); + +/* + this util function converts into rawdata from ndef message structure + */ +net_nfc_error_e net_nfc_util_convert_ndef_message_to_rawdata(ndef_message_s *ndef, data_s *rawdata); + +/* + get total bytes of ndef message in serial form + */ +uint32_t net_nfc_util_get_ndef_message_length(ndef_message_s *message); + +/* + free ndef message. this function also free any defined buffer insdie structures + */ +net_nfc_error_e net_nfc_util_free_ndef_message(ndef_message_s *msg); + +/* + append record into ndef message + */ +net_nfc_error_e net_nfc_util_append_record(ndef_message_s *msg, ndef_record_s *record); + +/* + print out ndef structure value with printf function. this is for just debug purpose + */ +void net_nfc_util_print_ndef_message(ndef_message_s *msg); + +net_nfc_error_e net_nfc_util_create_ndef_message(ndef_message_s **ndef_message); + +net_nfc_error_e net_nfc_util_search_record_by_type(ndef_message_s *ndef_message, net_nfc_record_tnf_e tnf, data_s *type, ndef_record_s **record); + +net_nfc_error_e net_nfc_util_append_record_by_index(ndef_message_s *ndef_message, int index, ndef_record_s *record); + +net_nfc_error_e net_nfc_util_get_record_by_index(ndef_message_s *ndef_message, int index, ndef_record_s **record); + +net_nfc_error_e net_nfc_util_remove_record_by_index(ndef_message_s *ndef_message, int index); + +net_nfc_error_e net_nfc_util_search_record_by_id(ndef_message_s *ndef_message, data_s *id, ndef_record_s **record); + +#endif + diff --git a/src/commonlib/include/net_nfc_util_ndef_record.h b/src/commonlib/include/net_nfc_util_ndef_record.h new file mode 100755 index 0000000..be2b585 --- /dev/null +++ b/src/commonlib/include/net_nfc_util_ndef_record.h @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#ifndef __NET_NFC_UTIL_NDEF_RECORD__ +#define __NET_NFC_UTIL_NDEF_RECORD__ + +#include "net_nfc_typedef_private.h" + +/* + create record structure with basic info + */ +net_nfc_error_e net_nfc_util_create_record(net_nfc_record_tnf_e recordType, data_s *typeName, data_s *id, data_s *payload, ndef_record_s **record); + +/* + create text type record + */ +net_nfc_error_e net_nfc_util_create_text_type_record(const char *text, const char *lang_code_str, net_nfc_encode_type_e encode, ndef_record_s **record); + +/* + this utility function help to create uri type record + */ +net_nfc_error_e net_nfc_util_create_uri_type_record(const char *uri, net_nfc_schema_type_e protocol_schema, ndef_record_s **record); + +/* + free ndef record. it free all the buffered data + */ +net_nfc_error_e net_nfc_util_free_record(ndef_record_s *record); + +/* + convert schema enum value to character string. + */ +net_nfc_error_e net_nfc_util_set_record_id(ndef_record_s *record, uint8_t *data, int length); + +/* + get total bytes of ndef record in serial form + */ +uint32_t net_nfc_util_get_record_length(ndef_record_s *record); + +/* + create uri string from record + */ +net_nfc_error_e net_nfc_util_create_uri_string_from_uri_record(ndef_record_s *record, char **uri); + +#endif diff --git a/src/commonlib/include/net_nfc_util_openssl_private.h b/src/commonlib/include/net_nfc_util_openssl_private.h new file mode 100644 index 0000000..9782fc7 --- /dev/null +++ b/src/commonlib/include/net_nfc_util_openssl_private.h @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#ifndef NET_NFC_UTIL_OPENSSL_PRIVATE_H_ +#define NET_NFC_UTIL_OPENSSL_PRIVATE_H_ + +#include + +enum +{ + OPENSSL_FORMAT_UNDEF, + OPENSSL_FORMAT_ASN1, + OPENSSL_FORMAT_TEXT, + OPENSSL_FORMAT_PEM, + OPENSSL_FORMAT_NETSCAPE, + OPENSSL_FORMAT_PKCS12, + OPENSSL_FORMAT_SMIME, + OPENSSL_FORMAT_ENGINE, + OPENSSL_FORMAT_IISSGC, + OPENSSL_FORMAT_PEMRSA, + OPENSSL_FORMAT_ASN1RSA, + OPENSSL_FORMAT_MSBLOB, + OPENSSL_FORMAT_PVK, +}; + +typedef struct _net_nfc_openssl_verify_context_s +{ + X509 *signer_cert; + X509_STORE *store; + X509_STORE_CTX *store_ctx; +} +net_nfc_openssl_verify_context_s; + +typedef net_nfc_openssl_verify_context_s *net_nfc_openssl_verify_context_h; + +net_nfc_openssl_verify_context_h net_nfc_util_openssl_init_verify_certificate(void); +bool net_nfc_util_openssl_add_certificate_of_signer(net_nfc_openssl_verify_context_h context, uint8_t *buffer, uint32_t length); +bool net_nfc_util_openssl_add_certificate_of_ca(net_nfc_openssl_verify_context_h context, uint8_t *buffer, uint32_t length); +int net_nfc_util_openssl_verify_certificate(net_nfc_openssl_verify_context_h context); +void net_nfc_util_openssl_release_verify_certificate(net_nfc_openssl_verify_context_h context); + +int net_nfc_util_openssl_sign_buffer(uint32_t type, uint8_t *buffer, uint32_t length, char *key_file, char *password, uint8_t *sign, uint32_t *sign_len); +int net_nfc_util_openssl_verify_signature(uint32_t type, uint8_t *buffer, uint32_t length, uint8_t *cert, uint32_t cert_len, uint8_t *sign, uint32_t sign_len); +int net_nfc_util_get_cert_list_from_file(char *file_name, char *password, uint8_t **buffer, uint32_t *length, uint32_t *cert_count); + + +bool net_nfc_util_openssl_encode_base64(const uint8_t *buffer, const uint32_t buf_len, char *result, uint32_t max_len, bool new_line_char); +bool net_nfc_util_openssl_decode_base64(const char *buffer, uint8_t *result, uint32_t *out_len, bool new_line_char); +bool net_nfc_util_openssl_digest(const char *algorithm, const uint8_t *buffer, const uint32_t buf_len, uint8_t *result, uint32_t *out_len); + +#endif /* NET_NFC_UTIL_OPENSSL_PRIVATE_H_ */ diff --git a/src/commonlib/include/net_nfc_util_private.h b/src/commonlib/include/net_nfc_util_private.h new file mode 100644 index 0000000..08bb11c --- /dev/null +++ b/src/commonlib/include/net_nfc_util_private.h @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#ifndef __NET_NFC_UTIL_H__ +#define __NET_NFC_UTIL_H__ + +#include +#include +#include + +#include "net_nfc_typedef_private.h" + +#define NET_NFC_REVERSE_ORDER_6_BYTES(__array) \ + do \ + { \ + uint16_t __x = htons(*(uint16_t *)(__array + 4)); \ + *(uint32_t *)(__array + 2) = htonl(*(uint32_t *)(__array)); \ + *(uint16_t *)(__array) = __x; \ + } while (0); + +#define NET_NFC_REVERSE_ORDER_16_BYTES(array) \ + do \ + { \ + uint32_t __x1 = htonl(*(uint32_t *)(array + 12)); \ + uint32_t __x2 = htonl(*(uint32_t *)(array + 8)); \ + *(uint32_t *)(array + 8) = htonl(*(uint32_t *)(array + 4)); \ + *(uint32_t *)(array + 12) = htonl(*(uint32_t *)(array)); \ + *(uint32_t *)(array) = __x1; \ + *(uint32_t *)(array + 4) = __x2; \ + } while (0); + + +typedef enum +{ + CRC_A = 0x00, + CRC_B, +} CRC_type_e; + +/* Memory utils */ +/* allocation memory */ +void __net_nfc_util_alloc_mem(void **mem, int size, char *filename, unsigned int line); +#define _net_nfc_util_alloc_mem(mem,size) __net_nfc_util_alloc_mem((void **)&mem,size, basename(__FILE__), __LINE__) + +/* allocation memory */ +void __net_nfc_util_strdup(char **output, const char *origin, char *filename, unsigned int line); +#define _net_nfc_util_strdup(output, origin) __net_nfc_util_strdup(&output, origin, basename(__FILE__), __LINE__) + +/* free memory, after free given memory it set NULL. Before proceed free, this function also check NULL */ +void __net_nfc_util_free_mem(void **mem, char *filename, unsigned int line); +#define _net_nfc_util_free_mem(mem) __net_nfc_util_free_mem((void **)&mem, basename(__FILE__), __LINE__) + +bool net_nfc_util_alloc_data(data_s *data, uint32_t length); +bool net_nfc_util_duplicate_data(data_s *dest, net_nfc_data_s *src); +void net_nfc_util_free_data(data_s *data); + +void net_nfc_util_mem_free_detail_msg(int msg_type, int message, void *data); + +net_nfc_conn_handover_carrier_state_e net_nfc_util_get_cps(net_nfc_conn_handover_carrier_type_e carrier_type); + +uint8_t *net_nfc_util_get_local_bt_address(); +void net_nfc_util_enable_bluetooth(void); + +bool net_nfc_util_strip_string(char *buffer, int buffer_length); + +void net_nfc_util_compute_CRC(CRC_type_e CRC_type, uint8_t *buffer, uint32_t length); + +const char *net_nfc_util_get_schema_string(int index); + +#endif diff --git a/src/commonlib/include/net_nfc_util_sign_record.h b/src/commonlib/include/net_nfc_util_sign_record.h new file mode 100755 index 0000000..dc33ccf --- /dev/null +++ b/src/commonlib/include/net_nfc_util_sign_record.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __NET_NFC_UTIL_SIGN_RECORD_H +#define __NET_NFC_UTIL_SIGN_RECORD_H + +#include "net_nfc_typedef_private.h" + +/* + * sign ndef record and ndef message + */ +net_nfc_error_e net_nfc_util_sign_records(ndef_message_s *msg, int begin_index, int end_index, char *cert_file, char *password); +net_nfc_error_e net_nfc_util_sign_ndef_message(ndef_message_s *msg, char *cert_file, char *password); + +/* + * check validity of ndef record and ndef message + */ +net_nfc_error_e net_nfc_util_verify_signature_ndef_message(ndef_message_s *msg); +net_nfc_error_e net_nfc_util_verify_signature_records(ndef_record_s *begin_record, ndef_record_s *sign_record); + + +#endif /* __NET_NFC_UTIL_SIGN_RECORD_H */ + diff --git a/src/commonlib/net_nfc_util.c b/src/commonlib/net_nfc_util.c new file mode 100644 index 0000000..56d80a1 --- /dev/null +++ b/src/commonlib/net_nfc_util.c @@ -0,0 +1,468 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// libc header +#include +#include +#include +#include + +// platform header +#include +#include + +// nfc-manager header +#include "net_nfc_util_private.h" +#include "net_nfc_debug_private.h" +#include "net_nfc_oem_controller.h" +#include "net_nfc_util_defines.h" + +#ifndef NET_NFC_EXPORT_API +#define NET_NFC_EXPORT_API __attribute__((visibility("default"))) +#endif + +static const char *schema[] = +{ + "", + "http://www.", + "https://www.", + "http://", + "https://", + "tel:", + "mailto:", + "ftp://anonymous:anonymous@", + "ftp://ftp.", + "ftps://", + "sftp://", + "smb://", + "nfs://", + "ftp://", + "dav://", + "news:", + "telnet://", + "imap:", + "rtsp://", + "urn:", + "pop:", + "sip:", + "sips:", + "tftp:", + "btspp://", + "btl2cap://", + "btgoep://", + "tcpobex://", + "irdaobex://", + "file://", + "urn:epc:id:", + "urn:epc:tag:", + "urn:epc:pat:", + "urn:epc:raw:", + "urn:epc:", + "urn:epc:nfc:", +}; + +// defines for bluetooth api +#define USE_BLUETOOTH_API +static uint8_t *bt_addr = NULL; + +/* for log tag */ +#define NET_NFC_MANAGER_NAME "nfc-manager-daemon" +static const char *log_tag = LOG_CLIENT_TAG; +extern char *__progname; + +const char *net_nfc_get_log_tag() +{ + return log_tag; +} + +void __attribute__ ((constructor)) lib_init() +{ + if (__progname != NULL && strncmp(__progname, NET_NFC_MANAGER_NAME, strlen(NET_NFC_MANAGER_NAME)) == 0) + { + log_tag = LOG_SERVER_TAG; + } +} + +void __attribute__ ((destructor)) lib_fini() +{ +} + +NET_NFC_EXPORT_API void __net_nfc_util_free_mem(void **mem, char *filename, unsigned int line) +{ + if (mem == NULL) + { + DEBUG_MSG("FILE: %s, LINE:%d, Invalid parameter in mem free util, mem is NULL", filename, line); + return; + } + + if (*mem == NULL) + { + DEBUG_MSG("FILE: %s, LINE:%d, Invalid Parameter in mem free util, *mem is NULL", filename, line); + return; + } + + free(*mem); + *mem = NULL; +} + +NET_NFC_EXPORT_API void __net_nfc_util_alloc_mem(void **mem, int size, char *filename, unsigned int line) +{ + if (mem == NULL || size <= 0) + { + DEBUG_MSG("FILE: %s, LINE:%d, Invalid parameter in mem alloc util, mem [%p], size [%d]", filename, line, mem, size); + return; + } + + if (*mem != NULL) + { + DEBUG_MSG("FILE: %s, LINE:%d, WARNING: Pointer is not NULL, mem [%p]", filename, line, *mem); + } + + *mem = calloc(1, size); + + if (*mem == NULL) + { + DEBUG_ERR_MSG("FILE: %s, LINE:%d, Allocation is failed, size [%d]", filename, line, size); + } +} + +NET_NFC_EXPORT_API void __net_nfc_util_strdup(char **output, const char *origin, char *filename, unsigned int line) +{ + if (output == NULL || origin == NULL) + { + DEBUG_MSG("FILE: %s, LINE:%d, Invalid parameter in strdup, output [%p], origin [%p]", filename, line, output, origin); + return; + } + + if (*output != NULL) + { + DEBUG_MSG("FILE: %s, LINE:%d, WARNING: Pointer is not NULL, mem [%p]", filename, line, *output); + } + + *output = strdup(origin); + + if (*output == NULL) + { + DEBUG_ERR_MSG("FILE: %s, LINE:%d, strdup failed", filename, line); + } +} + +NET_NFC_EXPORT_API bool net_nfc_util_alloc_data(data_s *data, uint32_t length) +{ + if (data == NULL || length == 0) + return false; + + _net_nfc_util_alloc_mem(data->buffer, length); + if (data->buffer == NULL) + return false; + + data->length = length; + + return true; +} + +NET_NFC_EXPORT_API bool net_nfc_util_duplicate_data(data_s *dest, net_nfc_data_s *src) +{ + if (dest == NULL || src == NULL || src->length == 0) + return false; + + if (net_nfc_util_alloc_data(dest, src->length) == false) + return false; + + memcpy(dest->buffer, src->buffer, dest->length); + + return true; +} + +NET_NFC_EXPORT_API void net_nfc_util_free_data(data_s *data) +{ + if (data == NULL || data->buffer == NULL) + return; + + _net_nfc_util_free_mem(data->buffer); +} + +NET_NFC_EXPORT_API void net_nfc_util_mem_free_detail_msg(int msg_type, int message, void *data) +{ + if (data == NULL) + return; + + if (msg_type == NET_NFC_UTIL_MSG_TYPE_REQUEST) + { + _net_nfc_util_free_mem(data); + } + else if (msg_type == NET_NFC_UTIL_MSG_TYPE_RESPONSE) + { + switch (message) + { + case NET_NFC_MESSAGE_READ_NDEF : + { + net_nfc_response_read_ndef_t *msg = (net_nfc_response_read_ndef_t *)data; + _net_nfc_util_free_mem(msg->data.buffer); + } + break; + case NET_NFC_MESSAGE_TRANSCEIVE : + { + net_nfc_response_transceive_t *msg = (net_nfc_response_transceive_t *)data; + _net_nfc_util_free_mem(msg->data.buffer); + } + break; + case NET_NFC_MESSAGE_TAG_DISCOVERED : + { + net_nfc_response_tag_discovered_t *msg = (net_nfc_response_tag_discovered_t *)data; + _net_nfc_util_free_mem(msg->target_info_values.buffer); + _net_nfc_util_free_mem(msg->raw_data.buffer); + } + break; + + case NET_NFC_MESSAGE_LLCP_RECEIVE : + { + net_nfc_response_receive_socket_t *msg = (net_nfc_response_receive_socket_t *)data; + _net_nfc_util_free_mem(msg->data.buffer); + } + break; + + case NET_NFC_MESSAGE_P2P_RECEIVE : + { + net_nfc_response_p2p_receive_t *msg = (net_nfc_response_p2p_receive_t *)data; + _net_nfc_util_free_mem(msg->data.buffer); + } + break; + + case NET_NFC_MESSAGE_SEND_APDU_SE : + { + net_nfc_response_send_apdu_t *msg = (net_nfc_response_send_apdu_t *)data; + _net_nfc_util_free_mem(msg->data.buffer); + } + break; + + default : + break; + } + + _net_nfc_util_free_mem(data); + } + else + { + DEBUG_MSG("unknown message type"); + } +} + +net_nfc_conn_handover_carrier_state_e net_nfc_util_get_cps(net_nfc_conn_handover_carrier_type_e carrier_type) +{ + net_nfc_conn_handover_carrier_state_e cps = NET_NFC_CONN_HANDOVER_CARRIER_INACTIVATE; + + if (carrier_type == NET_NFC_CONN_HANDOVER_CARRIER_BT) + { + int ret = bluetooth_check_adapter(); + + switch (ret) + { + case BLUETOOTH_ADAPTER_ENABLED : + cps = NET_NFC_CONN_HANDOVER_CARRIER_ACTIVATE; + break; + + case BLUETOOTH_ADAPTER_CHANGING_ENABLE : + cps = NET_NFC_CONN_HANDOVER_CARRIER_ACTIVATING; + break; + + case BLUETOOTH_ADAPTER_DISABLED : + case BLUETOOTH_ADAPTER_CHANGING_DISABLE : + case BLUETOOTH_ERROR_NO_RESOURCES : + default : + cps = NET_NFC_CONN_HANDOVER_CARRIER_INACTIVATE; + break; + } + } + else if (carrier_type == NET_NFC_CONN_HANDOVER_CARRIER_WIFI_BSS) + { + int wifi_state = 0; + + vconf_get_int(VCONFKEY_WIFI_STATE, &wifi_state); + + switch (wifi_state) + { + case VCONFKEY_WIFI_UNCONNECTED : + case VCONFKEY_WIFI_CONNECTED : + case VCONFKEY_WIFI_TRANSFER : + cps = NET_NFC_CONN_HANDOVER_CARRIER_ACTIVATE; + break; + + case VCONFKEY_WIFI_OFF : + default : + cps = NET_NFC_CONN_HANDOVER_CARRIER_INACTIVATE; + break; + } + } + + return cps; +} + +uint8_t *net_nfc_util_get_local_bt_address() +{ + if (bt_addr != NULL) + { + return bt_addr; + } + + _net_nfc_util_alloc_mem(bt_addr, BLUETOOTH_ADDRESS_LENGTH); + if (bt_addr != NULL) + { + if (net_nfc_util_get_cps(NET_NFC_CONN_HANDOVER_CARRIER_BT) != NET_NFC_CONN_HANDOVER_CARRIER_ACTIVATE) + { + // bt power is off. so get bt address from configuration file. + FILE *fp = NULL; + + if ((fp = fopen(HIDDEN_BT_ADDR_FILE, "r")) != NULL) + { + unsigned char temp[BLUETOOTH_ADDRESS_LENGTH * 2] = { 0, }; + + int ch; + int count = 0; + int i = 0; + + while ((ch = fgetc(fp)) != EOF && count < BLUETOOTH_ADDRESS_LENGTH * 2) + { + if (((ch >= '0') && (ch <= '9'))) + { + temp[count++] = ch - '0'; + } + else if (((ch >= 'a') && (ch <= 'z'))) + { + temp[count++] = ch - 'a' + 10; + } + else if (((ch >= 'A') && (ch <= 'Z'))) + { + temp[count++] = ch - 'A' + 10; + } + } + + for (; i < BLUETOOTH_ADDRESS_LENGTH; i++) + { + bt_addr[i] = temp[i * 2] << 4 | temp[i * 2 + 1]; + } + + fclose(fp); + } + } + else + { + bluetooth_device_address_t local_address; + + memset(&local_address, 0x00, sizeof(bluetooth_device_address_t)); + + bluetooth_get_local_address(&local_address); + + memcpy(bt_addr, &local_address.addr, BLUETOOTH_ADDRESS_LENGTH); + } + } + + return bt_addr; +} + +void net_nfc_util_enable_bluetooth(void) +{ + bluetooth_enable_adapter(); +} + +bool net_nfc_util_strip_string(char *buffer, int buffer_length) +{ + bool result = false; + char *temp = NULL; + int i = 0; + + _net_nfc_util_alloc_mem(temp, buffer_length); + if (temp == NULL) + { + return result; + } + + for (; i < buffer_length; i++) + { + if (buffer[i] != ' ' && buffer[i] != '\t') + break; + } + + if (i < buffer_length) + { + memcpy(temp, &buffer[i], buffer_length - i); + memset(buffer, 0x00, buffer_length); + + memcpy(buffer, temp, buffer_length - i); + + result = true; + } + else + { + result = false; + } + + _net_nfc_util_free_mem(temp); + + return true; +} + +static uint16_t _net_nfc_util_update_CRC(uint8_t ch, uint16_t *lpwCrc) +{ + ch = (ch ^ (uint8_t)((*lpwCrc) & 0x00FF)); + ch = (ch ^ (ch << 4)); + *lpwCrc = (*lpwCrc >> 8) ^ ((uint16_t)ch << 8) ^ ((uint16_t)ch << 3) ^ ((uint16_t)ch >> 4); + return (*lpwCrc); +} + +void net_nfc_util_compute_CRC(CRC_type_e CRC_type, uint8_t *buffer, uint32_t length) +{ + uint8_t chBlock = 0; + int msg_length = length - 2; + uint8_t *temp = buffer; + + // default is CRC_B + uint16_t wCrc = 0xFFFF; /* ISO/IEC 13239 (formerly ISO/IEC 3309) */ + + switch (CRC_type) + { + case CRC_A : + wCrc = 0x6363; + break; + + case CRC_B : + wCrc = 0xFFFF; + break; + } + + do + { + chBlock = *buffer++; + _net_nfc_util_update_CRC(chBlock, &wCrc); + } + while (--msg_length > 0); + + if (CRC_type == CRC_B) + { + wCrc = ~wCrc; /* ISO/IEC 13239 (formerly ISO/IEC 3309) */ + } + + temp[length - 2] = (uint8_t)(wCrc & 0xFF); + temp[length - 1] = (uint8_t)((wCrc >> 8) & 0xFF); +} + +const char *net_nfc_util_get_schema_string(int index) +{ + if (index == 0 || index >= NET_NFC_SCHEMA_MAX) + return NULL; + else + return schema[index]; +} diff --git a/src/commonlib/net_nfc_util_handover.c b/src/commonlib/net_nfc_util_handover.c new file mode 100644 index 0000000..33cd490 --- /dev/null +++ b/src/commonlib/net_nfc_util_handover.c @@ -0,0 +1,1543 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include + +#include "net_nfc_typedef_private.h" +#include "net_nfc_debug_private.h" +#include "net_nfc_util_defines.h" +#include "net_nfc_util_private.h" +#include "net_nfc_util_ndef_record.h" +#include "net_nfc_util_ndef_message.h" +#include "net_nfc_util_handover.h" + +typedef struct _search_index +{ + int target; + int current; + void *found; +} search_index; + +static int __property_equal_to(gconstpointer key1, gconstpointer key2) +{ + net_nfc_carrier_property_s *arg1 = (net_nfc_carrier_property_s *)key1; + net_nfc_carrier_property_s *arg2 = (net_nfc_carrier_property_s *)key2; + + if (arg1->attribute < arg2->attribute) + { + return -1; + } + else if (arg1->attribute > arg2->attribute) + { + return 1; + } + else + { + return 0; + } +} + +static net_nfc_carrier_property_s *__find_property_by_attrubute(GList *list, uint16_t attribute) +{ + GList *found = NULL; + net_nfc_carrier_property_s temp; + + temp.attribute = attribute; + found = g_list_find_custom(list, &temp, __property_equal_to); + + if (found == NULL) + { + return NULL; + } + + return (net_nfc_carrier_property_s *)found->data; +} + +static void __find_nth_group(gpointer data, gpointer user_data) +{ + net_nfc_carrier_property_s *info = (net_nfc_carrier_property_s *)data; + search_index *nth = (search_index *)user_data; + + if (info == NULL || user_data == NULL) + return; + + if (info->is_group) + { + if (nth->current == nth->target) + { + nth->found = data; + } + nth->current++; + } +} + +static void __free_all_data(gpointer data, gpointer user_data) +{ + net_nfc_carrier_property_s *info = (net_nfc_carrier_property_s *)data; + + if (info == NULL) + return; + + if (info->is_group) + { + DEBUG_MSG("FREE: group is found"); + net_nfc_util_free_carrier_group((net_nfc_carrier_property_s *)info); + } + else + { + DEBUG_MSG("FREE: element is found ATTRIB:0x%X length:%d", info->attribute, info->length); + _net_nfc_util_free_mem(info->data); + _net_nfc_util_free_mem(info); + } +} + +static net_nfc_error_e __net_nfc_util_create_connection_handover_collsion_resolution_record(ndef_record_s **record) +{ + uint32_t state = 0; + data_s typeName = { 0 }; + data_s payload = { 0 }; + uint8_t rand_buffer[2] = { 0, 0 }; + uint16_t random_num; + + if (record == NULL) + return NET_NFC_NULL_PARAMETER; + + state = (uint32_t)time(NULL); + random_num = (unsigned short)rand_r(&state); + + typeName.buffer = (uint8_t *)COLLISION_DETECT_RECORD_TYPE; + typeName.length = strlen(COLLISION_DETECT_RECORD_TYPE); + + rand_buffer[0] = (random_num & 0xff00) >> 8; // MSB + rand_buffer[1] = (random_num & 0x00ff); // LSB + + payload.buffer = rand_buffer; + payload.length = 2; + + DEBUG_MSG("rand number = [0x%x] [0x%x] => [0x%x]", payload.buffer[0], payload.buffer[1], random_num); + + return net_nfc_util_create_record(NET_NFC_RECORD_WELL_KNOWN_TYPE, &typeName, NULL, &payload, record); +} + +static int __net_nfc_get_size_of_attribute(int attribute) +{ + switch (attribute) + { + case NET_NFC_BT_ATTRIBUTE_UUID16_PART : + case NET_NFC_BT_ATTRIBUTE_UUID16 : + case NET_NFC_BT_ATTRIBUTE_UUID32_PART : + case NET_NFC_BT_ATTRIBUTE_UUID32 : + case NET_NFC_BT_ATTRIBUTE_UUID128_PART : + case NET_NFC_BT_ATTRIBUTE_UUID128 : + case NET_NFC_BT_ATTRIBUTE_NAME_PART : + case NET_NFC_BT_ATTRIBUTE_NAME : + case NET_NFC_BT_ATTRIBUTE_TXPOWER : + case NET_NFC_BT_ATTRIBUTE_OOB_COD : + case NET_NFC_BT_ATTRIBUTE_OOB_HASH_C : + case NET_NFC_BT_ATTRIBUTE_OOB_HASH_R : + case NET_NFC_BT_ATTRIBUTE_ID : + case NET_NFC_BT_ATTRIBUTE_MANUFACTURER : + case NET_NFC_BT_ATTRIBUTE_ADDRESS : + // case NET_NFC_WIFI_ATTRIBUTE_VERSION2: + return 1; + + default : + return 2; + } +} + +net_nfc_error_e net_nfc_util_create_carrier_config(net_nfc_carrier_config_s **config, net_nfc_conn_handover_carrier_type_e type) +{ + if (config == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + if (type < 0 || type >= NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN) + { + return NET_NFC_OUT_OF_BOUND; + } + + _net_nfc_util_alloc_mem(*config, sizeof(net_nfc_carrier_config_s)); + if (*config == NULL) + { + return NET_NFC_ALLOC_FAIL; + } + + (*config)->type = type; + (*config)->length = 0; + + return NET_NFC_OK; +} + +net_nfc_error_e net_nfc_util_add_carrier_config_property(net_nfc_carrier_config_s *config, uint16_t attribute, uint16_t size, uint8_t * data) +{ + net_nfc_carrier_property_s *elem = NULL; + + DEBUG_MSG("ADD property: [ATTRIB:0x%X, SIZE:%d]", attribute, size); + + if (config == NULL || data == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + if (__find_property_by_attrubute(config->data, attribute) != NULL) + { + return NET_NFC_ALREADY_REGISTERED; + } + + _net_nfc_util_alloc_mem(elem, sizeof (net_nfc_carrier_property_s)); + if (elem == NULL) + { + return NET_NFC_ALLOC_FAIL; + } + elem->attribute = attribute; + elem->length = size; + elem->is_group = false; + _net_nfc_util_alloc_mem(elem->data, size); + + if (elem->data == NULL) + { + _net_nfc_util_free_mem(elem); + return NET_NFC_ALLOC_FAIL; + } + memcpy(elem->data, data, size); + + config->data = g_list_append(config->data, elem); + config->length += size + 2 * __net_nfc_get_size_of_attribute(attribute); + + DEBUG_MSG("ADD completed total length %d", config->length); + + return NET_NFC_OK; +} + +net_nfc_error_e net_nfc_util_remove_carrier_config_property(net_nfc_carrier_config_s *config, uint16_t attribute) +{ + net_nfc_carrier_property_s *elem = NULL; + + if (config == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + elem = __find_property_by_attrubute(config->data, attribute); + if (elem == NULL) + { + return NET_NFC_NO_DATA_FOUND; + } + + config->data = g_list_remove(config->data, elem); + config->length -= (elem->length + 2 * __net_nfc_get_size_of_attribute(attribute)); + + if (elem->is_group) + { + net_nfc_util_free_carrier_group((net_nfc_carrier_property_s *)elem); + } + else + { + _net_nfc_util_free_mem(elem->data); + _net_nfc_util_free_mem(elem); + } + + return NET_NFC_OK; +} + +net_nfc_error_e net_nfc_util_get_carrier_config_property(net_nfc_carrier_config_s *config, uint16_t attribute, uint16_t * size, uint8_t ** data) +{ + net_nfc_carrier_property_s *elem = NULL; + + if (config == NULL || size == NULL || data == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + elem = __find_property_by_attrubute(config->data, attribute); + if (elem == NULL) + { + *size = 0; + *data = NULL; + return NET_NFC_NO_DATA_FOUND; + } + + *size = elem->length; + if (elem->is_group) + { + *data = NULL; + } + else + { + *data = elem->data; + } + + return NET_NFC_OK; +} + +net_nfc_error_e net_nfc_util_append_carrier_config_group(net_nfc_carrier_config_s *config, net_nfc_carrier_property_s *group) +{ + if (config == NULL || group == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + if (g_list_find(config->data, group) != NULL) + { + return NET_NFC_ALREADY_REGISTERED; + } + + config->data = g_list_append(config->data, group); + config->length += group->length; + + return NET_NFC_OK; +} + +net_nfc_error_e net_nfc_util_remove_carrier_config_group(net_nfc_carrier_config_s *config, net_nfc_carrier_property_s *group) +{ + if (config == NULL || group == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + if (g_list_find(config->data, group) != NULL) + { + return NET_NFC_NO_DATA_FOUND; + } + + config->length -= group->length; + config->data = g_list_remove(config->data, group); + + net_nfc_util_free_carrier_group((net_nfc_carrier_property_s *)group); + + return NET_NFC_OK; +} + +net_nfc_error_e net_nfc_util_get_carrier_config_group(net_nfc_carrier_config_s *config, int index, net_nfc_carrier_property_s **group) +{ + search_index result; + + if (config == NULL || group == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + if (index < 0) + { + return NET_NFC_OUT_OF_BOUND; + } + + result.current = 0; + result.target = index; + result.found = NULL; + + g_list_foreach(config->data, __find_nth_group, &result); + + if (result.found == NULL) + { + return NET_NFC_NO_DATA_FOUND; + } + *group = (net_nfc_carrier_property_s *)result.found; + + return NET_NFC_OK; +} + +net_nfc_error_e net_nfc_util_free_carrier_config(net_nfc_carrier_config_s *config) +{ + if (config == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + g_list_foreach(config->data, __free_all_data, NULL); + g_list_free(config->data); + + _net_nfc_util_free_mem(config); + + return NET_NFC_OK; +} + +net_nfc_error_e net_nfc_util_create_carrier_config_group(net_nfc_carrier_property_s **group, uint16_t attribute) +{ + if (group == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + _net_nfc_util_alloc_mem(*group, sizeof(net_nfc_carrier_property_s)); + if (*group == NULL) + { + return NET_NFC_ALLOC_FAIL; + } + + (*group)->attribute = attribute; + (*group)->is_group = true; + + return NET_NFC_OK; +} + +net_nfc_error_e net_nfc_util_add_carrier_config_group_property(net_nfc_carrier_property_s *group, uint16_t attribute, uint16_t size, uint8_t *data) +{ + net_nfc_carrier_property_s *elem = NULL; + + DEBUG_MSG("ADD group property: [ATTRIB:0x%X, SIZE:%d]", attribute, size); + + if (group == NULL || data == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + if (__find_property_by_attrubute((GList *)group->data, attribute) != NULL) + { + return NET_NFC_ALREADY_REGISTERED; + } + + _net_nfc_util_alloc_mem(elem, sizeof (net_nfc_carrier_property_s)); + if (elem == NULL) + { + return NET_NFC_ALLOC_FAIL; + } + elem->attribute = attribute; + elem->length = size; + elem->is_group = false; + + _net_nfc_util_alloc_mem(elem->data, size); + if (elem->data == NULL) + { + _net_nfc_util_free_mem(elem); + return NET_NFC_ALLOC_FAIL; + } + memcpy(elem->data, data, size); + group->length += size + 2 * __net_nfc_get_size_of_attribute(attribute); + group->data = g_list_append((GList *)(group->data), elem); + + DEBUG_MSG("ADD group completed total length %d", group->length); + + return NET_NFC_OK; +} + +net_nfc_error_e net_nfc_util_get_carrier_config_group_property(net_nfc_carrier_property_s *group, uint16_t attribute, uint16_t *size, uint8_t ** data) +{ + net_nfc_carrier_property_s *elem = NULL; + + if (group == NULL || size == NULL || data == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + elem = __find_property_by_attrubute((GList*)(group->data), attribute); + if (elem == NULL) + { + *size = 0; + *data = NULL; + return NET_NFC_NO_DATA_FOUND; + } + + *size = elem->length; + *data = elem->data; + + return NET_NFC_OK; +} + +net_nfc_error_e net_nfc_util_remove_carrier_config_group_property(net_nfc_carrier_property_s *group, uint16_t attribute) +{ + net_nfc_carrier_property_s *elem = NULL; + + if (group == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + elem = __find_property_by_attrubute((GList*)(group->data), attribute); + if (elem == NULL) + { + return NET_NFC_NO_DATA_FOUND; + } + group->length -= elem->length; + group->data = g_list_remove((GList*)(group->data), elem); + + _net_nfc_util_free_mem(elem->data); + _net_nfc_util_free_mem(elem); + + return NET_NFC_OK; + +} + +net_nfc_error_e net_nfc_util_free_carrier_group(net_nfc_carrier_property_s *group) +{ + if (group == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + g_list_foreach((GList*)(group->data), __free_all_data, NULL); + g_list_free((GList*)(group->data)); + + _net_nfc_util_free_mem(group); + + return NET_NFC_OK; +} + +static void __make_serial_wifi(gpointer data, gpointer user_data) +{ + net_nfc_carrier_property_s *info = (net_nfc_carrier_property_s *)data; + data_s *payload = (data_s *)user_data; + uint8_t *current; + int inc = 0; + + if (info == NULL || user_data == NULL) + return; + + current = payload->buffer + payload->length; + inc = __net_nfc_get_size_of_attribute(info->attribute); + + if (info->is_group) + { + DEBUG_MSG("[WIFI]Found Group make recursive"); + *(uint16_t *)current = info->attribute; + *(uint16_t *)(current + inc) = info->length; + payload->length += (inc + inc); + g_list_foreach((GList *)info->data, __make_serial_wifi, payload); + } + else + { + DEBUG_MSG("[WIFI]Element is found attrib:0x%X length:%d current:%d", info->attribute, info->length, payload->length); + *(uint16_t *)current = info->attribute; + *(uint16_t *)(current + inc) = info->length; + memcpy(current + inc + inc, info->data, info->length); + payload->length += (inc + inc + info->length); + } +} + +static void __make_serial_bt(gpointer data, gpointer user_data) +{ + net_nfc_carrier_property_s *info = (net_nfc_carrier_property_s *)data; + data_s *payload = (data_s *)user_data; + uint8_t *current; + int inc = 0; + + if (info == NULL || user_data == NULL) + return; + + current = payload->buffer + payload->length; /* payload->length is zero */ + + if (info->is_group) + { + DEBUG_MSG("[BT]Found Group. call recursive"); + g_list_foreach((GList *)info->data, __make_serial_bt, payload); + } + else + { + if (info->attribute != NET_NFC_BT_ATTRIBUTE_ADDRESS) + { + DEBUG_MSG("[BT]Element is found attrib:0x%X length:%d current:%d", info->attribute, info->length, payload->length); + inc = __net_nfc_get_size_of_attribute(info->attribute); + *current = info->length + 1; + *(current + inc) = info->attribute; + memcpy(current + inc + inc, info->data, info->length); + payload->length += (inc + inc + info->length); + } + else + { + DEBUG_MSG("[BT]BT address is found length:%d", info->length); + memcpy(current, info->data, info->length); + payload->length += (info->length); + } + } +} + +net_nfc_error_e net_nfc_util_create_ndef_record_with_carrier_config(ndef_record_s **record, net_nfc_carrier_config_s *config) +{ + data_s payload = { NULL, 0 }; + data_s record_type = { NULL, 0 }; + + if (record == NULL || config == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + _net_nfc_util_alloc_mem(payload.buffer, config->length); + if (payload.buffer == NULL) + { + return NET_NFC_ALLOC_FAIL; + } + payload.length = 0; /* this should be zero because this will be used as current position of data written */ + + if (config->type == NET_NFC_CONN_HANDOVER_CARRIER_WIFI_BSS) + { + record_type.buffer = (uint8_t *)CONN_HANDOVER_WIFI_BSS_CARRIER_MIME_NAME; + record_type.length = strlen(CONN_HANDOVER_WIFI_BSS_CARRIER_MIME_NAME); + g_list_foreach(config->data, __make_serial_wifi, &payload); + } + else if (config->type == NET_NFC_CONN_HANDOVER_CARRIER_WIFI_IBSS) + { + record_type.buffer = (uint8_t *)CONN_HANDOVER_WIFI_IBSS_CARRIER_MIME_NAME; + record_type.length = strlen(CONN_HANDOVER_WIFI_IBSS_CARRIER_MIME_NAME); + g_list_foreach(config->data, __make_serial_wifi, &payload); + } + else if (config->type == NET_NFC_CONN_HANDOVER_CARRIER_BT) + { + record_type.buffer = (uint8_t *)CONN_HANDOVER_BT_CARRIER_MIME_NAME; + record_type.length = strlen(CONN_HANDOVER_BT_CARRIER_MIME_NAME); + payload.buffer += 2; /* OOB total length */ + g_list_foreach(config->data, __make_serial_bt, &payload); + payload.buffer -= 2; /* return to original */ + payload.length += 2; + payload.buffer[0] = payload.length & 0xFF; + payload.buffer[1] = (payload.length >> 8) & 0xFF; + } + else + { + return NET_NFC_NOT_SUPPORTED; + } + + DEBUG_MSG("payload length = %d", payload.length); + + return net_nfc_util_create_record(NET_NFC_RECORD_MIME_TYPE, &record_type, NULL, &payload, record); +} + +static net_nfc_error_e __net_nfc_get_list_from_serial_for_wifi(GList **list, uint8_t *data, uint32_t length) +{ + net_nfc_carrier_property_s *elem = NULL; + uint8_t *current = data; + uint8_t *last = current + length; + + while (current < last) + { + _net_nfc_util_alloc_mem(elem, sizeof(net_nfc_carrier_property_s)); + if (elem == NULL) + { + return NET_NFC_ALLOC_FAIL; + } + elem->attribute = *((uint16_t *)current); + elem->length = *((uint16_t *)(current + 2)); + + if (elem->attribute == NET_NFC_WIFI_ATTRIBUTE_CREDENTIAL) + { + __net_nfc_get_list_from_serial_for_wifi((GList **)&(elem->data), (current + 4), elem->length); + elem->is_group = true; + } + else + { + _net_nfc_util_alloc_mem(elem->data, elem->length); + if (elem->data == NULL) + { + _net_nfc_util_free_mem(elem); + return NET_NFC_ALLOC_FAIL; + } + memcpy(elem->data, (current + 4), elem->length); + elem->is_group = false; + } + *list = g_list_append(*list, elem); + current += (4 + elem->length); + } + + return NET_NFC_OK; +} + +net_nfc_error_e __net_nfc_get_list_from_serial_for_bt(GList **list, uint8_t *data, uint32_t length) +{ + net_nfc_carrier_property_s *elem = NULL; + uint8_t *current = data; + uint8_t *last = NULL; + + current += 2; /* remove oob data length two bytes length*/ + length -= 2; + + _net_nfc_util_alloc_mem(elem, sizeof(net_nfc_carrier_property_s)); + if (elem == NULL) + { + return NET_NFC_ALLOC_FAIL; + } + elem->attribute = (uint16_t)NET_NFC_BT_ATTRIBUTE_ADDRESS; + elem->length = 6; /* BT address length is always 6 */ + + _net_nfc_util_alloc_mem(elem->data, elem->length); + if (elem->data == NULL) + { + _net_nfc_util_free_mem(elem); + return NET_NFC_ALLOC_FAIL; + } + memcpy(elem->data, current, elem->length); + elem->is_group = false; + + current += 6; /* BT address length is always 6 */ + length -= 6; /* substracted by 6 (Address length)*/ + *list = g_list_append(*list, elem); + + last = current + length; + + while (current < last) + { + _net_nfc_util_alloc_mem(elem, sizeof(net_nfc_carrier_property_s)); + if (elem == NULL) + { + return NET_NFC_ALLOC_FAIL; + } + elem->length = *((uint8_t *)current) - 1; + elem->attribute = *((uint8_t *)(++current)); + + _net_nfc_util_alloc_mem(elem->data, elem->length); + if (elem->data == NULL) + { + _net_nfc_util_free_mem(elem); + return NET_NFC_ALLOC_FAIL; + } + memcpy(elem->data, (++current), elem->length); + elem->is_group = false; + + current += elem->length; + *list = g_list_append(*list, elem); + } + + return NET_NFC_OK; +} + +net_nfc_error_e net_nfc_util_create_carrier_config_from_config_record(net_nfc_carrier_config_s **config, ndef_record_s *record) +{ + net_nfc_error_e result = NET_NFC_OK; + net_nfc_conn_handover_carrier_type_e type; + + if (record == NULL || config == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + if (strncmp((char *)record->type_s.buffer, CONN_HANDOVER_WIFI_BSS_CARRIER_MIME_NAME, record->type_s.length) == 0) + { + type = NET_NFC_CONN_HANDOVER_CARRIER_WIFI_BSS; + } + else if (strncmp((char *)record->type_s.buffer, CONN_HANDOVER_WIFI_IBSS_CARRIER_MIME_NAME, record->type_s.length) == 0) + { + type = NET_NFC_CONN_HANDOVER_CARRIER_WIFI_IBSS; + } + else if (strncmp((char *)record->type_s.buffer, CONN_HANDOVER_BT_CARRIER_MIME_NAME, record->type_s.length) == 0) + { + type = NET_NFC_CONN_HANDOVER_CARRIER_BT; + } + else + { + DEBUG_MSG("Record type is not config type"); + return NET_NFC_INVALID_FORMAT; + } + + result = net_nfc_util_create_carrier_config(config, type); + if (*config == NULL) + { + return NET_NFC_ALLOC_FAIL; + } + + switch ((*config)->type) + { + case NET_NFC_CONN_HANDOVER_CARRIER_WIFI_BSS : + case NET_NFC_CONN_HANDOVER_CARRIER_WIFI_IBSS : + result = __net_nfc_get_list_from_serial_for_wifi((GList **)&((*config)->data), record->payload_s.buffer, record->payload_s.length); + break; + case NET_NFC_CONN_HANDOVER_CARRIER_BT : + result = __net_nfc_get_list_from_serial_for_bt((GList **)&((*config)->data), record->payload_s.buffer, record->payload_s.length); + break; + case NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN : + result = NET_NFC_NOT_SUPPORTED; + break; + } + + if (result != NET_NFC_OK) + { + net_nfc_util_free_carrier_config((net_nfc_carrier_config_s *)*config); + } + + return result; +} + +net_nfc_error_e net_nfc_util_create_handover_request_message(ndef_message_s **message) +{ + ndef_message_s *inner_message = NULL; + net_nfc_error_e error; + ndef_record_s *record = NULL; + data_s type = { NULL, 0 }; + data_s payload = { NULL, 0 }; + int size = 0; + + if (message == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + error = net_nfc_util_create_ndef_message(message); + if (error != NET_NFC_OK) + { + return error; + } + + error = net_nfc_util_create_ndef_message(&inner_message); + if (error != NET_NFC_OK) + { + net_nfc_util_free_ndef_message(*message); + *message = NULL; + + return error; + } + + __net_nfc_util_create_connection_handover_collsion_resolution_record(&record); + net_nfc_util_append_record(inner_message, record); + + size = net_nfc_util_get_ndef_message_length(inner_message) + 1; + _net_nfc_util_alloc_mem(payload.buffer, size); + if (payload.buffer == NULL) + { + net_nfc_util_free_ndef_message(inner_message); + net_nfc_util_free_ndef_message(*message); + *message = NULL; + + return NET_NFC_ALLOC_FAIL; + } + payload.length = size; + + uint8_t version = ((CONN_HANOVER_MAJOR_VER << 4) & 0xf0) | (CONN_HANOVER_MINOR_VER & 0x0f); + + (payload.buffer)[0] = version; + (payload.buffer)++; + (payload.length)--; + + error = net_nfc_util_convert_ndef_message_to_rawdata(inner_message, &payload); + if (error != NET_NFC_OK) + { + _net_nfc_util_free_mem(payload.buffer); + net_nfc_util_free_ndef_message(inner_message); + net_nfc_util_free_ndef_message(*message); + *message = NULL; + + return error; + } + + net_nfc_util_free_ndef_message(inner_message); + (payload.buffer)--; + (payload.length)++; + + type.buffer = (uint8_t *)CONN_HANDOVER_REQ_RECORD_TYPE; + type.length = strlen(CONN_HANDOVER_REQ_RECORD_TYPE); + + net_nfc_util_create_record(NET_NFC_RECORD_WELL_KNOWN_TYPE, &type, NULL, &payload, &record); + net_nfc_util_append_record(*message, record); + + _net_nfc_util_free_mem(payload.buffer); + + return NET_NFC_OK; +} + +net_nfc_error_e net_nfc_util_create_handover_select_message(ndef_message_s **message) +{ + net_nfc_error_e error = NET_NFC_OK; + ndef_record_s *record = NULL; + data_s type = { NULL, 0 }; + data_s payload = { NULL, 0 }; + + if (message == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + error = net_nfc_util_create_ndef_message(message); + if (error != NET_NFC_OK) + { + return error; + } + + _net_nfc_util_alloc_mem(payload.buffer, 1); + if (payload.buffer == NULL) + { + net_nfc_util_free_ndef_message(*message); + return NET_NFC_ALLOC_FAIL; + } + payload.length = (uint32_t)1; + + (payload.buffer)[0] = ((CONN_HANOVER_MAJOR_VER << 4) & 0xf0) | (CONN_HANOVER_MINOR_VER & 0x0f); + + type.buffer = (uint8_t*)CONN_HANDOVER_SEL_RECORD_TYPE; + type.length = strlen(CONN_HANDOVER_SEL_RECORD_TYPE); + + net_nfc_util_create_record(NET_NFC_RECORD_WELL_KNOWN_TYPE, &type, NULL, &payload, &record); + net_nfc_util_append_record(*message, record); + + _net_nfc_util_free_mem(payload.buffer); + + return NET_NFC_OK; +} + +net_nfc_error_e net_nfc_util_create_handover_error_record(ndef_record_s **record, uint8_t reason, uint32_t data) +{ + data_s type; + data_s payload; + int size = 1; + + switch (reason) + { + case 0x01 : + size += 1; + break; + case 0x02 : + size += 4; + break; + case 0x03 : + size += 1; + break; + } + + _net_nfc_util_alloc_mem(payload.buffer, size); + if (payload.buffer == NULL) + { + return NET_NFC_ALLOC_FAIL; + } + payload.length = size; + + type.buffer = (uint8_t *)ERROR_RECORD_TYPE; + type.length = strlen(ERROR_RECORD_TYPE); + + net_nfc_util_create_record(NET_NFC_RECORD_WELL_KNOWN_TYPE, &type, NULL, &payload, (ndef_record_s **)record); + + _net_nfc_util_free_mem(payload.buffer); + + return NET_NFC_OK; +} + +/* + inner_msg should be freed after using + */ + +static net_nfc_error_e __net_nfc_get_inner_message(ndef_message_s *message, ndef_message_s *inner_msg) +{ + net_nfc_error_e error; + ndef_record_s *inner_record = NULL; + + if (message == NULL || inner_msg == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + inner_record = message->records; + if (inner_record == NULL) + { + // This message is not connection handover message + return NET_NFC_INVALID_FORMAT; + } + + if (strncmp((char*)(inner_record->type_s.buffer), CONN_HANDOVER_REQ_RECORD_TYPE, (size_t)(inner_record->type_s.length)) != 0 + && strncmp((char*)(inner_record->type_s.buffer), CONN_HANDOVER_SEL_RECORD_TYPE, (size_t)(inner_record->type_s.length)) != 0) + { + // This message is not connection handover message + return NET_NFC_INVALID_FORMAT; + } + + if (inner_record->payload_s.length > 1) + { + /* There is Alternative Carrier Record or Collision Res. Rec. */ + (inner_record->payload_s.buffer)++; /* version */ + (inner_record->payload_s.length)--; + error = net_nfc_util_convert_rawdata_to_ndef_message(&(inner_record->payload_s), inner_msg); + (inner_record->payload_s.buffer)--; + (inner_record->payload_s.length)++; + } + else + { + error = NET_NFC_NO_DATA_FOUND; + } + + return error; +} + +static net_nfc_error_e __net_nfc_replace_inner_message(ndef_message_s *message, ndef_message_s *inner_msg) +{ + net_nfc_error_e error; + ndef_record_s *inner_record = NULL; + + if (message == NULL || inner_msg == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + inner_record = message->records; + if (inner_record == NULL) + { + // This message is not connection handover message + DEBUG_ERR_MSG("inner_record == NULL"); + return NET_NFC_INVALID_FORMAT; + } + + if (strncmp((char *)(inner_record->type_s.buffer), CONN_HANDOVER_REQ_RECORD_TYPE, (size_t)(inner_record->type_s.length)) != 0 + && strncmp((char *)(inner_record->type_s.buffer), CONN_HANDOVER_SEL_RECORD_TYPE, (size_t)(inner_record->type_s.length)) != 0) + { + // This message is not connection handover message + DEBUG_ERR_MSG("unknown type [%s]", inner_record->type_s.buffer); + return NET_NFC_INVALID_FORMAT; + } + + if (inner_record->payload_s.length >= 1) + { + /* There is Alternative Carrier Record or Collision Res. Rec. */ + data_s tdata = { NULL, 0 }; + int inner_length; + + inner_length = net_nfc_util_get_ndef_message_length(inner_msg); + + _net_nfc_util_alloc_mem(tdata.buffer, inner_length + 1); + if (tdata.buffer == NULL) + { + return NET_NFC_ALLOC_FAIL; + } + + (tdata.buffer)++; + tdata.length = inner_length; + error = net_nfc_util_convert_ndef_message_to_rawdata(inner_msg, &tdata); + if (error == NET_NFC_OK) + { + (tdata.buffer)--; + (tdata.length)++; + (tdata.buffer)[0] = (inner_record->payload_s.buffer)[0]; + _net_nfc_util_free_mem(inner_record->payload_s.buffer); + inner_record->payload_s.buffer = tdata.buffer; + inner_record->payload_s.length = tdata.length; + } + else + { + DEBUG_ERR_MSG("net_nfc_util_convert_ndef_message_to_rawdata failed [%d]", error); + _net_nfc_util_free_mem(tdata.buffer); + } + } + else + { + DEBUG_ERR_MSG("inner_record->payload_s.length(%d) < 1 ", inner_record->payload_s.length); + error = NET_NFC_INVALID_FORMAT; + } + + return error; +} + +net_nfc_error_e net_nfc_util_append_carrier_config_record(ndef_message_s *message, ndef_record_s *record, net_nfc_conn_handover_carrier_state_e power_status) +{ + ndef_message_s *inner_msg = NULL; + ndef_record_s *carrier_rec = NULL; + data_s payload = { NULL, 0 }; + data_s type = { NULL, 0 }; + int config_ref_count = 0; + net_nfc_error_e error; + char buffer[256] = { 0, }; + + if (message == NULL || record == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + if ((error = net_nfc_util_create_ndef_message(&inner_msg)) != NET_NFC_OK) + { + DEBUG_MSG("net_nfc_util_create_ndef_message failed [%d]", error); + + return error; + } + + if ((error = __net_nfc_get_inner_message(message, inner_msg)) == NET_NFC_OK) + { + int idx = 1; + ndef_record_s *last_rec = inner_msg->records; + + for (; idx < inner_msg->recordCount; idx++) + { + last_rec = last_rec->next; + } + + if (strncmp((char *)last_rec->type_s.buffer, COLLISION_DETECT_RECORD_TYPE, (size_t)last_rec->type_s.length) == 0) + { + config_ref_count = 0; + } + else if (strncmp((char *)last_rec->type_s.buffer, ALTERNATIVE_RECORD_TYPE, (size_t)last_rec->type_s.length) == 0) + { + strncpy(buffer, (char *)((last_rec->payload_s.buffer) + 2), (size_t)(last_rec->payload_s.buffer[1])); + config_ref_count = atoi(buffer); + } + } + else + { + /* selector record type can include empty inner message. so that case, we will continue */ + if (memcmp((char *)message->records->type_s.buffer, CONN_HANDOVER_SEL_RECORD_TYPE, (size_t)message->records->type_s.length) != 0) + { + DEBUG_ERR_MSG("ERROR [%d]", error); + + net_nfc_util_free_ndef_message(inner_msg); + + return error; + } + } + + type.buffer = (uint8_t *)ALTERNATIVE_RECORD_TYPE; + type.length = strlen(ALTERNATIVE_RECORD_TYPE); + + config_ref_count++; + snprintf(buffer, sizeof(buffer), " %d ", config_ref_count); /* total size of payload is generally greater than 4. this is a trick :)*/ + + payload.length = strlen(buffer); + payload.buffer = (uint8_t *)buffer; + payload.buffer[0] = (uint8_t)(power_status & 0x3); /* first byte, power status */ + payload.buffer[1] = (uint8_t)payload.length - 2; /* payload length except 2 bytes (power status and itself) */ + + error = net_nfc_util_create_record(NET_NFC_RECORD_WELL_KNOWN_TYPE, &type, NULL, &payload, &carrier_rec); + if (error != NET_NFC_OK) + { + DEBUG_ERR_MSG("net_nfc_util_create_record failed [%d]", error); + + net_nfc_util_free_ndef_message(inner_msg); + + return error; + } + + error = net_nfc_util_append_record(inner_msg, carrier_rec); + if (error != NET_NFC_OK) + { + DEBUG_ERR_MSG("net_nfc_util_create_record failed [%d]", error); + + net_nfc_util_free_record(carrier_rec); + net_nfc_util_free_ndef_message(inner_msg); + + return error; + } + + error = __net_nfc_replace_inner_message(message, inner_msg); + net_nfc_util_free_ndef_message(inner_msg); + if (error != NET_NFC_OK) + { + DEBUG_ERR_MSG("__net_nfc_replace_inner_message failed [%d]", error); + + return error; + } + + /* set record id to record that will be appended to ndef message */ + error = net_nfc_util_set_record_id((ndef_record_s *)record, (uint8_t *)(buffer + 2), payload.length - 2); + if (error != NET_NFC_OK) + { + DEBUG_ERR_MSG("net_nfc_util_set_record_id failed [%d]", error); + + return error; + } + + error = net_nfc_util_append_record(message, (ndef_record_s *)record); + if (error != NET_NFC_OK) + { + DEBUG_ERR_MSG("net_nfc_util_append_record failed [%d]", error); + + return error; + } + + return NET_NFC_OK; +} + +net_nfc_error_e net_nfc_util_remove_carrier_config_record(ndef_message_s *message, ndef_record_s *record) +{ + ndef_message_s *inner_msg = NULL; + int idx = 0; + int saved_idx = 0; + net_nfc_error_e error; + ndef_record_s *current = NULL; + ndef_record_s *record_priv = (ndef_record_s *)record; + + if (message == NULL || record == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + current = message->records; + + for (idx = 0; idx < message->recordCount; idx++) + { + if (current == record) + { + break; + } + current = current->next; + } + + if (current == NULL || idx == message->recordCount) + { + DEBUG_MSG("The reference is not found in config records"); + + return NET_NFC_NO_DATA_FOUND; + } + saved_idx = idx; + + if ((error = net_nfc_util_create_ndef_message(&inner_msg)) != NET_NFC_OK) + { + DEBUG_MSG("net_nfc_util_create_ndef_message failed [%d]", error); + + return error; + } + + if ((error = __net_nfc_get_inner_message(message, inner_msg)) == NET_NFC_OK) + { + current = inner_msg->records; + + for (idx = 0; idx < inner_msg->recordCount; idx++, current = current->next) + { + if (strncmp((char *)current->type_s.buffer, ALTERNATIVE_RECORD_TYPE, (size_t)current->type_s.length) == 0) + { + if ((uint32_t)(current->payload_s.buffer[1]) == record_priv->id_s.length && + strncmp((char *)(current->payload_s.buffer + 2), (char*)(record_priv->id_s.buffer), (size_t)current->payload_s.buffer[1]) == 0) + { + // comparing the instance + break; + } + } + } + + if (current == NULL || idx == message->recordCount) + { + DEBUG_MSG("The reference is not found in inner message"); + + error = NET_NFC_NO_DATA_FOUND; + } + else + { + net_nfc_util_remove_record_by_index(inner_msg, idx); + __net_nfc_replace_inner_message(message, inner_msg); + + // remove the record only if the inner record is found. + net_nfc_util_remove_record_by_index(message, saved_idx); + } + } + + net_nfc_util_free_ndef_message(inner_msg); + + return error; +} + +net_nfc_error_e net_nfc_util_get_carrier_config_record(ndef_message_s *message, int index, ndef_record_s** record) +{ + ndef_message_s *inner_msg = NULL; + data_s id; + net_nfc_error_e error; + ndef_record_s *current = NULL; + int idx = 0; + int current_idx = 0; + + if (message == NULL || record == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + if ((error = net_nfc_util_create_ndef_message(&inner_msg)) != NET_NFC_OK) + { + DEBUG_MSG("net_nfc_util_create_ndef_message failed [%d]", error); + + return error; + } + + if ((error = __net_nfc_get_inner_message(message, inner_msg)) == NET_NFC_OK) + { + current = inner_msg->records; + for (idx = 0; idx < inner_msg->recordCount; idx++) + { + if (strncmp((char*)current->type_s.buffer, ALTERNATIVE_RECORD_TYPE, (size_t)current->type_s.length) == 0) + { + if (current_idx == index) + break; + current_idx++; + } + current = current->next; + } + + if (current == NULL || idx == message->recordCount) + { + DEBUG_MSG("The reference is not found in inner message"); + + error = NET_NFC_NO_DATA_FOUND; + } + else + { + id.buffer = (current->payload_s.buffer) + 2; + id.length = current->payload_s.buffer[1]; + + error = net_nfc_util_search_record_by_id(message, &id, record); + } + } + + net_nfc_util_free_ndef_message(inner_msg); + + return error; +} + +net_nfc_error_e net_nfc_util_get_handover_random_number(ndef_message_s *message, unsigned short *random_number) +{ + net_nfc_error_e error; + ndef_message_s *inner_msg = NULL; + ndef_record_s *cr_record = NULL; + + if (message == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + if ((error = net_nfc_util_create_ndef_message(&inner_msg)) != NET_NFC_OK) + { + DEBUG_MSG("net_nfc_util_create_ndef_message failed [%d]", error); + + return error; + } + + if ((error = __net_nfc_get_inner_message(message, inner_msg)) == NET_NFC_OK) + { + cr_record = inner_msg->records; + if (strncmp((char*)cr_record->type_s.buffer, COLLISION_DETECT_RECORD_TYPE, (size_t)cr_record->type_s.length) != 0 + || cr_record->payload_s.length < 2) + { + DEBUG_MSG("There is no Collision resolution record"); + + error = NET_NFC_INVALID_FORMAT; + } + else + { + *random_number = ((unsigned short)cr_record->payload_s.buffer[0] << 8) | (unsigned short)(cr_record->payload_s.buffer[1]); + } + } + + net_nfc_util_free_ndef_message(inner_msg); + + return error; +} + +net_nfc_error_e net_nfc_util_get_alternative_carrier_record_count(ndef_message_s *message, unsigned int *count) +{ + net_nfc_error_e error; + ndef_message_s *inner_msg = NULL; + ndef_record_s *current = NULL; + int idx; + + if (message == NULL || count == 0) + { + return NET_NFC_NULL_PARAMETER; + } + + if ((error = net_nfc_util_create_ndef_message(&inner_msg)) != NET_NFC_OK) + { + DEBUG_MSG("net_nfc_util_create_ndef_message failed [%d]", error); + + return error; + } + + *count = 0; + + if ((error = __net_nfc_get_inner_message(message, inner_msg)) == NET_NFC_OK) + { + current = inner_msg->records; + for (idx = 0; idx < inner_msg->recordCount; idx++) + { + if (strncmp((char *)current->type_s.buffer, ALTERNATIVE_RECORD_TYPE, (size_t)current->type_s.length) == 0) + { + (*count)++; + } + current = current->next; + } + } + + net_nfc_util_free_ndef_message(inner_msg); + + return error; +} + +net_nfc_error_e net_nfc_util_get_alternative_carrier_power_status(ndef_message_s *message, int index, net_nfc_conn_handover_carrier_state_e *power_state) +{ + net_nfc_error_e error; + ndef_message_s *inner_msg = NULL; + ndef_record_s *current = NULL; + int idx; + int idx_count = 0; + + if (message == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + if (index < 0) + { + return NET_NFC_OUT_OF_BOUND; + } + + if ((error = net_nfc_util_create_ndef_message(&inner_msg)) != NET_NFC_OK) + { + DEBUG_MSG("net_nfc_util_create_ndef_message failed [%d]", error); + + return error; + } + + if ((error = __net_nfc_get_inner_message(message, inner_msg)) == NET_NFC_OK) + { + error = NET_NFC_OUT_OF_BOUND; + current = inner_msg->records; + for (idx = 0; idx < inner_msg->recordCount; idx++) + { + if (strncmp((char *)current->type_s.buffer, ALTERNATIVE_RECORD_TYPE, (size_t)current->type_s.length) == 0) + { + if (idx_count == index) + { + *power_state = current->payload_s.buffer[0] & 0x3; + error = NET_NFC_OK; + break; + } + idx_count++; + } + current = current->next; + } + } + + net_nfc_util_free_ndef_message(inner_msg); + + return error; +} + +net_nfc_error_e net_nfc_util_set_alternative_carrier_power_status(ndef_message_s *message, int index, net_nfc_conn_handover_carrier_state_e power_status) +{ + net_nfc_error_e error; + ndef_message_s *inner_msg = NULL; + + if (message == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + if (index < 0) + { + return NET_NFC_OUT_OF_BOUND; + } + + if ((error = net_nfc_util_create_ndef_message(&inner_msg)) != NET_NFC_OK) + { + DEBUG_MSG("net_nfc_util_create_ndef_message failed [%d]", error); + + return error; + } + + if ((error = __net_nfc_get_inner_message(message, inner_msg)) == NET_NFC_OK) + { + int idx; + int idx_count = 0; + ndef_record_s *current = inner_msg->records; + + error = NET_NFC_OUT_OF_BOUND; + for (idx = 0; idx < inner_msg->recordCount; idx++, current = current->next) + { + if (strncmp((char *)current->type_s.buffer, ALTERNATIVE_RECORD_TYPE, (size_t)current->type_s.length) == 0) + { + if (idx_count == index) + { + current->payload_s.buffer[0] = (power_status & 0x3) | (current->payload_s.buffer[0] & 0xFC); + + __net_nfc_replace_inner_message(message, inner_msg); + error = NET_NFC_OK; + break; + } + idx_count++; + } + } + } + + net_nfc_util_free_ndef_message(inner_msg); + + return error; +} + +net_nfc_error_e net_nfc_util_get_alternative_carrier_type_from_record(ndef_record_s *record, net_nfc_conn_handover_carrier_type_e *type) +{ + if (strncmp((char *)record->type_s.buffer, CONN_HANDOVER_BT_CARRIER_MIME_NAME, (size_t)record->type_s.length) == 0) + { + *type = NET_NFC_CONN_HANDOVER_CARRIER_BT; + } + else if (strncmp((char *)record->type_s.buffer, CONN_HANDOVER_WIFI_BSS_CARRIER_MIME_NAME, (size_t)record->type_s.length) == 0) + { + *type = NET_NFC_CONN_HANDOVER_CARRIER_WIFI_BSS; + } + else if (strncmp((char *)record->type_s.buffer, CONN_HANDOVER_WIFI_IBSS_CARRIER_MIME_NAME, (size_t)record->type_s.length) == 0) + { + *type = NET_NFC_CONN_HANDOVER_CARRIER_WIFI_IBSS; + } + else + { + *type = NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN; + } + + return NET_NFC_OK; +} + +net_nfc_error_e net_nfc_util_get_alternative_carrier_type(ndef_message_s *message, int index, net_nfc_conn_handover_carrier_type_e *type) +{ + ndef_record_s *record = NULL; + net_nfc_error_e error; + + error = net_nfc_util_get_carrier_config_record(message, index, (ndef_record_s **)&record); + if (error != NET_NFC_OK) + { + return error; + } + + return net_nfc_util_get_alternative_carrier_type_from_record(record, type); +} + +net_nfc_error_e net_nfc_util_get_selector_power_status(ndef_message_s *message, net_nfc_conn_handover_carrier_state_e *power_state) +{ + net_nfc_error_e error; + ndef_message_s *inner_msg = NULL; + ndef_record_s *current = NULL; + int idx; + net_nfc_conn_handover_carrier_state_e selector_state = NET_NFC_CONN_HANDOVER_CARRIER_INACTIVATE; + + if (message == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + if ((error = net_nfc_util_create_ndef_message(&inner_msg)) == NET_NFC_OK) + { + if ((error = __net_nfc_get_inner_message(message, inner_msg)) == NET_NFC_OK) + { + if (inner_msg->recordCount > 1) + { + current = inner_msg->records; + for (idx = 0; idx < inner_msg->recordCount; idx++) + { + if (strncmp((char *)current->type_s.buffer, ALTERNATIVE_RECORD_TYPE, (size_t)current->type_s.length) == 0) + { + if (((current->payload_s.buffer[0] & 0x3) == NET_NFC_CONN_HANDOVER_CARRIER_ACTIVATE) || ((current->payload_s.buffer[0] & 0x3) == NET_NFC_CONN_HANDOVER_CARRIER_ACTIVATING)) + { + selector_state = NET_NFC_CONN_HANDOVER_CARRIER_ACTIVATE; + break; + } + } + current = current->next; + } + } + else + { + /* always activate when ac is only one */ + selector_state = NET_NFC_CONN_HANDOVER_CARRIER_ACTIVATE; + } + + *power_state = selector_state; + } + else + { + DEBUG_ERR_MSG("_net_nfc_util_create_ndef_message failed [%d]", error); + } + + net_nfc_util_free_ndef_message(inner_msg); + } + else + { + DEBUG_ERR_MSG("_net_nfc_util_create_ndef_message failed [%d]", error); + error = NET_NFC_ALLOC_FAIL; + } + + return error; +} + diff --git a/src/commonlib/net_nfc_util_ipc.c b/src/commonlib/net_nfc_util_ipc.c new file mode 100644 index 0000000..0d7a65c --- /dev/null +++ b/src/commonlib/net_nfc_util_ipc.c @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include + +#include "net_nfc_debug_private.h" + +int net_nfc_util_get_va_list_length(va_list list) +{ + int length = 0; + + while (va_arg(list, void *) != 0) + { + length += (sizeof(int) + va_arg(list, int)); + } + + return length; +} + +int net_nfc_util_fill_va_list(uint8_t *buffer, int length, va_list list) +{ + uint8_t *data = NULL; + int len = 0; + int current = 0; + + while (current < length && (data = va_arg(list, void *)) != NULL) + { + if ((len = va_arg(list, int)) > 0) + { + memcpy(buffer + current, &len, sizeof(len)); + current += sizeof(len); + + memcpy(buffer + current, data, len); + current += len; + } + } + + return current; +} + +void net_nfc_util_set_non_block_socket(int socket) +{ + DEBUG_SERVER_MSG("set non block socket"); + + int flags = fcntl(socket, F_GETFL); + flags |= O_NONBLOCK; + + if (fcntl(socket, F_SETFL, flags) < 0) + { + DEBUG_ERR_MSG("fcntl, executing nonblock error"); + } +} diff --git a/src/commonlib/net_nfc_util_ndef_message.c b/src/commonlib/net_nfc_util_ndef_message.c new file mode 100755 index 0000000..5ccb9f3 --- /dev/null +++ b/src/commonlib/net_nfc_util_ndef_message.c @@ -0,0 +1,795 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include "net_nfc_debug_private.h" +#include "net_nfc_util_defines.h" +#include "net_nfc_util_private.h" +#include "net_nfc_util_ndef_message.h" +#include "net_nfc_util_ndef_record.h" + +static net_nfc_error_e __net_nfc_repair_record_flags(ndef_message_s *ndef_message); + +net_nfc_error_e net_nfc_util_convert_rawdata_to_ndef_message(data_s *rawdata, ndef_message_s *ndef) +{ + ndef_record_s *newRec = NULL; + ndef_record_s *prevRec = NULL; + uint8_t *current = NULL; + uint8_t *last = NULL; + uint8_t ndef_header = 0; + net_nfc_error_e result = NET_NFC_OK; + + if (rawdata == NULL || ndef == NULL) + return NET_NFC_NULL_PARAMETER; + + current = rawdata->buffer; + last = current + rawdata->length; + + if(rawdata->length < 3) + return NET_NFC_INVALID_FORMAT; + + for(ndef->recordCount = 0; current < last; ndef->recordCount++) + { + ndef_header = *current++; + + if(ndef->recordCount == 0) + { + /* first record has MB field */ + if((ndef_header & NET_NFC_NDEF_RECORD_MASK_MB) == 0) + return NET_NFC_INVALID_FORMAT; + + /* first record should not be a chunked record */ + if((ndef_header & NET_NFC_NDEF_RECORD_MASK_TNF) == NET_NFC_NDEF_TNF_UNCHANGED) + return NET_NFC_INVALID_FORMAT; + } + + _net_nfc_util_alloc_mem(newRec, sizeof(ndef_record_s)); + if (newRec == NULL) + { + result = NET_NFC_ALLOC_FAIL; + goto error; + } + + /* ndef header set */ + if (ndef_header & NET_NFC_NDEF_RECORD_MASK_MB) + { + newRec->MB = 1; + } + if (ndef_header & NET_NFC_NDEF_RECORD_MASK_ME) + { + newRec->ME = 1; + } + if (ndef_header & NET_NFC_NDEF_RECORD_MASK_CF) + { + newRec->CF = 1; + } + if (ndef_header & NET_NFC_NDEF_RECORD_MASK_SR) + { + newRec->SR = 1; + } + if (ndef_header & NET_NFC_NDEF_RECORD_MASK_IL) + { + newRec->IL = 1; + } + + newRec->TNF = ndef_header & NET_NFC_NDEF_RECORD_MASK_TNF; + + newRec->type_s.length = *current++; + + /* SR = 1 -> payload is 1 byte, SR = 0 -> payload is 4 bytes */ + if(ndef_header & NET_NFC_NDEF_RECORD_MASK_SR) + { + newRec->payload_s.length = *current++; + } + else + { + newRec->payload_s.length = (uint32_t)((*current) << 24); + current++; + + newRec->payload_s.length += (uint32_t)((*current) << 16); + current++; + + newRec->payload_s.length += (uint32_t)((*current) << 8); + current++; + + newRec->payload_s.length += (uint32_t)((*current)); + current++; + } + + /* ID length check */ + if(ndef_header & NET_NFC_NDEF_RECORD_MASK_IL) + { + newRec->id_s.length = *current++; + } + else + { + newRec->id_s.length = 0; + } + + /* to do : chunked record */ + + + /* empty record check */ + if((ndef_header & NET_NFC_NDEF_RECORD_MASK_TNF) == NET_NFC_NDEF_TNF_EMPTY) + { + if(newRec->type_s.length != 0 || newRec->id_s.length != 0 || newRec->payload_s.length != 0) + { + result = NET_NFC_INVALID_FORMAT; + goto error; + } + } + + if((ndef_header & NET_NFC_NDEF_RECORD_MASK_TNF) == NET_NFC_NDEF_TNF_UNKNOWN) + { + if(newRec->type_s.length != 0) + { + result = NET_NFC_INVALID_FORMAT; + goto error; + } + } + + /* put Type buffer */ + if(newRec->type_s.length > 0) + { + _net_nfc_util_alloc_mem(newRec->type_s.buffer, newRec->type_s.length); + if (newRec->type_s.buffer == NULL) + { + result = NET_NFC_ALLOC_FAIL; + goto error; + } + + memcpy(newRec->type_s.buffer, current, newRec->type_s.length); + current += newRec->type_s.length; + } + else + { + newRec->type_s.buffer = NULL; + } + + /* put ID buffer */ + if(newRec->id_s.length > 0) + { + _net_nfc_util_alloc_mem(newRec->id_s.buffer, newRec->id_s.length); + if (newRec->id_s.buffer == NULL) + { + result = NET_NFC_ALLOC_FAIL; + goto error; + } + + memcpy(newRec->id_s.buffer, current, newRec->id_s.length); + current += newRec->id_s.length; + } + else + { + newRec->id_s.buffer = NULL; + } + + /* put Payload buffer */ + if(newRec->payload_s.length > 0) + { + _net_nfc_util_alloc_mem(newRec->payload_s.buffer, newRec->payload_s.length); + if (newRec->payload_s.buffer == NULL) + { + result = NET_NFC_ALLOC_FAIL; + goto error; + } + + memcpy(newRec->payload_s.buffer, current, newRec->payload_s.length); + current += newRec->payload_s.length; + } + else + { + newRec->payload_s.buffer = NULL; + } + + if (ndef->recordCount == 0) + ndef->records = newRec; + else + prevRec->next = newRec; + + prevRec = newRec; + newRec = NULL; + + if(ndef_header & NET_NFC_NDEF_RECORD_MASK_ME) + { + break; + } + } + + ndef->recordCount++; + + if((current != last) || ((ndef_header & NET_NFC_NDEF_RECORD_MASK_ME) == 0)) + { + result = NET_NFC_INVALID_FORMAT; + goto error; + } + + return NET_NFC_OK; + +error: + + DEBUG_ERR_MSG("parser error"); + + if (newRec) + { + _net_nfc_util_free_mem(newRec->type_s.buffer); + _net_nfc_util_free_mem(newRec->id_s.buffer); + _net_nfc_util_free_mem(newRec->payload_s.buffer); + _net_nfc_util_free_mem(newRec); + } + + prevRec = ndef->records; + + while(prevRec) + { + ndef_record_s *tmpRec = NULL; + + _net_nfc_util_free_mem(prevRec->type_s.buffer); + _net_nfc_util_free_mem(prevRec->id_s.buffer); + _net_nfc_util_free_mem(prevRec->payload_s.buffer); + + tmpRec = prevRec->next; + _net_nfc_util_free_mem(prevRec); + prevRec = tmpRec; + } + + ndef->records = NULL; + + return result; +} + +net_nfc_error_e net_nfc_util_convert_ndef_message_to_rawdata(ndef_message_s *ndef, data_s *rawdata) +{ + ndef_record_s *record = NULL; + uint8_t *current = NULL; + uint8_t ndef_header; + + if (rawdata == NULL || ndef == NULL) + return NET_NFC_NULL_PARAMETER; + + record = ndef->records; + current = rawdata->buffer; + + while(record) + { + ndef_header = 0x00; + + if(record->MB) + ndef_header |= NET_NFC_NDEF_RECORD_MASK_MB; + if(record->ME) + ndef_header |= NET_NFC_NDEF_RECORD_MASK_ME; + if(record->CF) + ndef_header |= NET_NFC_NDEF_RECORD_MASK_CF; + if(record->SR) + ndef_header |= NET_NFC_NDEF_RECORD_MASK_SR; + if(record->IL) + ndef_header |= NET_NFC_NDEF_RECORD_MASK_IL; + + ndef_header |= record->TNF; + + *current++ = ndef_header; + + /* check empty record */ + if(record->TNF == NET_NFC_NDEF_TNF_EMPTY) + { + /* set type length to zero */ + *current++ = 0x00; + + /* set payload length to zero */ + *current++ = 0x00; + + /* set ID length to zero */ + if(record->IL) + { + *current++ = 0x00; + } + + record = record->next; + + continue; + } + + /* set type length */ + if(record->TNF == NET_NFC_NDEF_TNF_UNKNOWN || record->TNF == NET_NFC_NDEF_TNF_UNCHANGED) + { + *current++ = 0x00; + } + else + { + *current++ = record->type_s.length; + } + + /* set payload length */ + if(record->SR) + { + *current++ = (uint8_t)(record->payload_s.length & 0x000000FF); + } + else + { + *current++ = (uint8_t)((record->payload_s.length & 0xFF000000) >> 24); + *current++ = (uint8_t)((record->payload_s.length & 0x00FF0000) >> 16); + *current++ = (uint8_t)((record->payload_s.length & 0x0000FF00) >> 8); + *current++ = (uint8_t)(record->payload_s.length & 0x000000FF) ; + } + + /* set ID length */ + if(record->IL) + { + *current++ = record->id_s.length; + } + + /* set type buffer */ + if((record->TNF != NET_NFC_NDEF_TNF_UNKNOWN) && (record->TNF != NET_NFC_NDEF_TNF_UNCHANGED)) + { + memcpy(current, record->type_s.buffer, record->type_s.length); + current += record->type_s.length; + } + + /* set ID buffer */ + memcpy(current, record->id_s.buffer, record->id_s.length); + current += record->id_s.length; + + /* set payload buffer */ + memcpy(current, record->payload_s.buffer, record->payload_s.length); + current += record->payload_s.length; + + record = record->next; + } + + return NET_NFC_OK; +} + +net_nfc_error_e net_nfc_util_append_record(ndef_message_s *msg, ndef_record_s *record) +{ + if (msg == NULL || record == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + if (msg->recordCount == 0) + { + // set short message and append + record->MB = 1; + record->ME = 1; + record->next = NULL; + + msg->records = record; + + msg->recordCount++; + + DEBUG_MSG("record is added to NDEF message :: count [%d]", msg->recordCount); + } + else + { + ndef_record_s *current = NULL; + ndef_record_s *prev = NULL; + + // set flag :: this record is FIRST + current = msg->records; + + if (current != NULL) + { + // first node + current->MB = 1; + current->ME = 0; + + prev = current; + + // second node + current = current->next; + + while (current != NULL) + { + current->MB = 0; + current->ME = 0; + prev = current; + current = current->next; + } + + // set flag :: this record is END + record->MB = 0; + record->ME = 1; + + prev->next = record; + msg->recordCount++; + } + + } + + return NET_NFC_OK; +} + +uint32_t net_nfc_util_get_ndef_message_length(ndef_message_s *message) +{ + ndef_record_s *current; + int total = 0; + + if (message == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + current = message->records; + + while (current != NULL) + { + total += net_nfc_util_get_record_length(current); + current = current->next; + } + + DEBUG_MSG("total byte length = [%d]", total); + + return total; +} + +void net_nfc_util_print_ndef_message(ndef_message_s *msg) +{ + int idx = 0, idx2 = 0; + ndef_record_s *current = NULL; + char buffer[1024]; + + if (msg == NULL) + { + return; + } + + // 123456789012345678901234567890123456789012345678901234567890 + DEBUG_MSG("========== NDEF Message ====================================\n"); + DEBUG_MSG("Total NDEF Records count: %d\n", msg->recordCount); + current = msg->records; + for (idx = 0; idx < msg->recordCount; idx++) + { + if (current == NULL) + { + DEBUG_ERR_MSG("Message Record is NULL!! unexpected error"); + DEBUG_MSG("============================================================\n"); + return; + } + DEBUG_MSG("---------- Record -----------------------------------------\n"); + DEBUG_MSG("MB:%d ME:%d CF:%d SR:%d IL:%d TNF:0x%02X\n", + current->MB, current->ME, current->CF, current->SR, current->IL, current->TNF); + DEBUG_MSG("TypeLength:%d PayloadLength:%d IDLength:%d\n", + current->type_s.length, current->payload_s.length, current->id_s.length); + if (current->type_s.buffer != NULL) + { + memcpy(buffer, current->type_s.buffer, current->type_s.length); + buffer[current->type_s.length] = '\0'; + DEBUG_MSG("Type: %s\n", buffer); + } + if (current->id_s.buffer != NULL) + { + memcpy(buffer, current->id_s.buffer, current->id_s.length); + buffer[current->id_s.length] = '\0'; + DEBUG_MSG("ID: %s\n", buffer); + } + if (current->payload_s.buffer != NULL) + { + DEBUG_MSG("Payload: "); + for (idx2 = 0; idx2 < current->payload_s.length; idx2++) + { + if (idx2 % 16 == 0) + DEBUG_MSG("\n\t"); + DEBUG_MSG("%02X ", current->payload_s.buffer[idx2]); + } + DEBUG_MSG("\n"); + } + current = current->next; + } + // 123456789012345678901234567890123456789012345678901234567890 + DEBUG_MSG("============================================================\n"); + +} + +net_nfc_error_e net_nfc_util_free_ndef_message(ndef_message_s *msg) +{ + int idx = 0; + ndef_record_s *prev, *current; + + if (msg == NULL) + return NET_NFC_NULL_PARAMETER; + + current = msg->records; + + for (idx = 0; idx < msg->recordCount; idx++) + { + if (current == NULL) + break; + + prev = current; + current = current->next; + + net_nfc_util_free_record(prev); + } + + _net_nfc_util_free_mem(msg); + + return NET_NFC_OK; +} + +net_nfc_error_e net_nfc_util_create_ndef_message(ndef_message_s **ndef_message) +{ + if (ndef_message == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + _net_nfc_util_alloc_mem(*ndef_message, sizeof(ndef_message_s)); + + return NET_NFC_OK; +} + +net_nfc_error_e net_nfc_util_remove_record_by_index(ndef_message_s *ndef_message, int index) +{ + int current_idx = 0; + ndef_record_s *prev; + ndef_record_s *next; + ndef_record_s *current; + + if (ndef_message == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + if (index < 0 || index >= ndef_message->recordCount) + { + return NET_NFC_OUT_OF_BOUND; + } + + if (index == 0) + { + current = ndef_message->records; + next = ndef_message->records->next; + ndef_message->records = next; + } + else + { + prev = ndef_message->records; + for (; current_idx < index - 1; current_idx++) + { + prev = prev->next; + if (prev == NULL) + { + return NET_NFC_INVALID_FORMAT; + } + } + current = prev->next; + if (current == NULL) + { + return NET_NFC_INVALID_FORMAT; + } + next = current->next; + prev->next = next; + } + + net_nfc_util_free_record(current); + (ndef_message->recordCount)--; + + return __net_nfc_repair_record_flags(ndef_message); +} + +net_nfc_error_e net_nfc_util_get_record_by_index(ndef_message_s *ndef_message, int index, ndef_record_s **record) +{ + ndef_record_s *current; + int idx = 0; + + if (ndef_message == NULL || record == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + if (index < 0 || index >= ndef_message->recordCount) + { + return NET_NFC_OUT_OF_BOUND; + } + + current = ndef_message->records; + + for (; current != NULL && idx < index; idx++) + { + current = current->next; + } + + *record = current; + + return NET_NFC_OK; +} + +net_nfc_error_e net_nfc_util_append_record_by_index(ndef_message_s *ndef_message, int index, ndef_record_s *record) +{ + int idx = 0; + ndef_record_s *prev; + ndef_record_s *next; + + if (ndef_message == NULL || record == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + if (index < 0 || index > ndef_message->recordCount) + { + return NET_NFC_OUT_OF_BOUND; + } + + prev = ndef_message->records; + + if (index == 0) + { + ndef_message->records = record; + record->next = prev; + } + else + { + for (; idx < index - 1; idx++) + { + prev = prev->next; + if (prev == NULL) + { + return NET_NFC_INVALID_FORMAT; + } + } + next = prev->next; + prev->next = record; + record->next = next; + } + (ndef_message->recordCount)++; + + return __net_nfc_repair_record_flags(ndef_message); +} + +net_nfc_error_e net_nfc_util_search_record_by_type(ndef_message_s *ndef_message, net_nfc_record_tnf_e tnf, data_s *type, ndef_record_s **record) +{ + int idx = 0; + ndef_record_s *record_private; + uint32_t type_length; + uint8_t *buf; + + if (ndef_message == NULL || type == NULL || record == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + type_length = type->length; + buf = type->buffer; + + /* remove prefix of nfc specific urn */ + if (type_length > 12) + { + if (memcmp(buf, "urn:nfc:ext:", 12) == 0 || + memcmp(buf, "urn:nfc:wkt:", 12) == 0) + { + buf += 12; + type_length -= 12; + } + } + + record_private = ndef_message->records; + + for (; idx < ndef_message->recordCount; idx++) + { + if (record_private == NULL) + { + *record = NULL; + + return NET_NFC_INVALID_FORMAT; + } + + if (record_private->TNF == tnf && + type_length == record_private->type_s.length && + memcmp(buf, record_private->type_s.buffer, type_length) == 0) + { + *record = record_private; + + return NET_NFC_OK; + } + + record_private = record_private->next; + } + + return NET_NFC_NO_DATA_FOUND; +} + +net_nfc_error_e net_nfc_util_search_record_by_id(ndef_message_s *ndef_message, data_s *id, ndef_record_s **record) +{ + int idx = 0; + ndef_record_s *record_in_msg; + uint32_t id_length; + uint8_t *buf; + + if (ndef_message == NULL || id == NULL || record == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + id_length = id->length; + buf = id->buffer; + + record_in_msg = ndef_message->records; + + for (; idx < ndef_message->recordCount; idx++) + { + if (record_in_msg == NULL) + { + *record = NULL; + + return NET_NFC_INVALID_FORMAT; + } + if (id_length == record_in_msg->id_s.length && + memcmp(buf, record_in_msg->id_s.buffer, id_length) == 0) + { + *record = record_in_msg; + + return NET_NFC_OK; + } + + record_in_msg = record_in_msg->next; + } + + return NET_NFC_NO_DATA_FOUND; +} + +static net_nfc_error_e __net_nfc_repair_record_flags(ndef_message_s *ndef_message) +{ + int idx = 0; + ndef_record_s *record; + + if (ndef_message == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + record = ndef_message->records; + + if (ndef_message->recordCount == 1) + { + if (record == NULL) + { + return NET_NFC_INVALID_FORMAT; + } + + record->MB = 1; + record->ME = 1; + + return NET_NFC_OK; + } + + for (idx = 0; idx < ndef_message->recordCount; idx++) + { + if (record == NULL) + { + return NET_NFC_INVALID_FORMAT; + } + + if (idx == 0) + { + record->MB = 1; + record->ME = 0; + } + else if (idx == ndef_message->recordCount - 1) + { + record->MB = 0; + record->ME = 1; + } + else + { + record->MB = 0; + record->ME = 0; + } + record = record->next; + } + + return NET_NFC_OK; +} + diff --git a/src/commonlib/net_nfc_util_ndef_record.c b/src/commonlib/net_nfc_util_ndef_record.c new file mode 100755 index 0000000..ac202bb --- /dev/null +++ b/src/commonlib/net_nfc_util_ndef_record.c @@ -0,0 +1,387 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "net_nfc_debug_private.h" +#include "net_nfc_util_defines.h" +#include "net_nfc_util_private.h" +#include "net_nfc_util_ndef_message.h" +#include "net_nfc_util_ndef_record.h" + +net_nfc_error_e net_nfc_util_free_record(ndef_record_s *record) +{ + if (record == NULL) + return NET_NFC_NULL_PARAMETER; + + if (record->type_s.buffer != NULL) + _net_nfc_util_free_mem(record->type_s.buffer); + if (record->id_s.buffer != NULL) + _net_nfc_util_free_mem(record->id_s.buffer); + if (record->payload_s.buffer != NULL) + _net_nfc_util_free_mem(record->payload_s.buffer); + + _net_nfc_util_free_mem(record); + + return NET_NFC_OK; +} + +net_nfc_error_e net_nfc_util_create_record(net_nfc_record_tnf_e recordType, data_s *typeName, data_s *id, data_s *payload, ndef_record_s **record) +{ + ndef_record_s *record_temp = NULL; + + if (typeName == NULL || payload == NULL || record == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + if (recordType < NET_NFC_RECORD_EMPTY || recordType > NET_NFC_RECORD_UNCHAGNED) + { + return NET_NFC_OUT_OF_BOUND; + } + + /* empty_tag */ + if (recordType == NET_NFC_RECORD_EMPTY) + { + if ((typeName->buffer != NULL) || (payload->buffer != NULL) || (id->buffer != NULL) || (typeName->length != 0) || (payload->length != 0) || (id->length != 0)) + return NET_NFC_NULL_PARAMETER; + } + + _net_nfc_util_alloc_mem(record_temp, sizeof(ndef_record_s)); + if (record_temp == NULL) + { + return NET_NFC_ALLOC_FAIL; + } + + // set type name and length and TNF field + record_temp->TNF = recordType; + record_temp->type_s.length = typeName->length; + + if(record_temp->type_s.length > 0) + { + _net_nfc_util_alloc_mem(record_temp->type_s.buffer, record_temp->type_s.length); + if (record_temp->type_s.buffer == NULL) + { + _net_nfc_util_free_mem(record_temp); + + return NET_NFC_ALLOC_FAIL; + } + + memcpy(record_temp->type_s.buffer, typeName->buffer, record_temp->type_s.length); + } + else + { + record_temp->type_s.buffer = NULL; + record_temp->type_s.length = 0; + } + + // set payload + record_temp->payload_s.length = payload->length; + if(payload->length >0) + { + _net_nfc_util_alloc_mem(record_temp->payload_s.buffer, record_temp->payload_s.length); + if (record_temp->payload_s.buffer == NULL) + { + _net_nfc_util_free_mem(record_temp->type_s.buffer); + _net_nfc_util_free_mem(record_temp); + + return NET_NFC_ALLOC_FAIL; + } + + memcpy(record_temp->payload_s.buffer, payload->buffer, record_temp->payload_s.length); + } + else + { + record_temp->payload_s.buffer = NULL; + record_temp->payload_s.length = 0; + } + + if (payload->length < 256) + { + record_temp->SR = 1; + } + else + { + record_temp->SR = 0; + } + + // set id and id length and IL field + if (id != NULL && id->buffer != NULL && id->length > 0) + { + record_temp->id_s.length = id->length; + _net_nfc_util_alloc_mem(record_temp->id_s.buffer, record_temp->id_s.length); + if (record_temp->id_s.buffer == NULL) + { + _net_nfc_util_free_mem(record_temp->payload_s.buffer); + _net_nfc_util_free_mem(record_temp->type_s.buffer); + _net_nfc_util_free_mem(record_temp); + + return NET_NFC_ALLOC_FAIL; + } + + memcpy(record_temp->id_s.buffer, id->buffer, record_temp->id_s.length); + record_temp->IL = 1; + } + else + { + record_temp->IL = 0; + record_temp->id_s.buffer = NULL; + record_temp->id_s.length = 0; + } + + // this is default value + record_temp->MB = 1; + record_temp->ME = 1; + + record_temp->next = NULL; + + *record = record_temp; + + return NET_NFC_OK; +} + +net_nfc_error_e net_nfc_util_create_uri_type_record(const char *uri, net_nfc_schema_type_e protocol_schema, ndef_record_s **record) +{ + net_nfc_error_e error; + data_s type_data; + data_s payload_data = { NULL, 0 }; + + if (uri == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + payload_data.length = strlen((char *)uri) + 1; + if (payload_data.length == 1) + { + return NET_NFC_INVALID_PARAM; + } + + _net_nfc_util_alloc_mem(payload_data.buffer, payload_data.length); + if (payload_data.buffer == NULL) + { + return NET_NFC_ALLOC_FAIL; + } + + payload_data.buffer[0] = protocol_schema; /* first byte of payload is protocol scheme */ + memcpy(payload_data.buffer + 1, uri, payload_data.length - 1); + + type_data.length = 1; + type_data.buffer = (uint8_t *)URI_RECORD_TYPE; + + error = net_nfc_util_create_record(NET_NFC_RECORD_WELL_KNOWN_TYPE, &type_data, NULL, &payload_data, record); + + _net_nfc_util_free_mem(payload_data.buffer); + + return error; +} + +net_nfc_error_e net_nfc_util_create_text_type_record(const char *text, const char *lang_code_str, net_nfc_encode_type_e encode, ndef_record_s **record) +{ + data_s type_data; + data_s payload_data; + int controll_byte; + int offset = 0; + + if (text == NULL || lang_code_str == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + if ((encode < NET_NFC_ENCODE_UTF_8 || encode > NET_NFC_ENCODE_UTF_16)) + { + return NET_NFC_OUT_OF_BOUND; + } + + payload_data.length = strlen((char *)text) + strlen(lang_code_str) + 1; + + _net_nfc_util_alloc_mem(payload_data.buffer, payload_data.length); + if (payload_data.buffer == NULL) + { + return NET_NFC_ALLOC_FAIL; + } + + controll_byte = strlen(lang_code_str) & 0x3F; + if (encode == NET_NFC_ENCODE_UTF_16) + { + controll_byte = controll_byte | 0x80; + } + + payload_data.buffer[0] = controll_byte; + + offset = 1; + memcpy(payload_data.buffer + offset, lang_code_str, strlen(lang_code_str)); + + offset = offset + strlen(lang_code_str); + memcpy(payload_data.buffer + offset, (char *)text, strlen((char *)text)); + + type_data.length = 1; + type_data.buffer = (uint8_t *)TEXT_RECORD_TYPE; + + net_nfc_util_create_record(NET_NFC_RECORD_WELL_KNOWN_TYPE, &type_data, NULL, &payload_data, record); + + _net_nfc_util_free_mem(payload_data.buffer); + + return NET_NFC_OK; +} + +net_nfc_error_e net_nfc_util_set_record_id(ndef_record_s *record, uint8_t *data, int length) +{ + if (record == NULL || data == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + if (length < 1) + { + return NET_NFC_OUT_OF_BOUND; + } + + if (record->id_s.buffer != NULL && record->id_s.length > 0) + { + _net_nfc_util_free_mem(record->id_s.buffer); + } + + _net_nfc_util_alloc_mem(record->id_s.buffer, length); + if (record->id_s.buffer == NULL) + { + return NET_NFC_ALLOC_FAIL; + } + memcpy(record->id_s.buffer, data, length); + record->id_s.length = length; + record->IL = 1; + + return NET_NFC_OK; +} + +uint32_t net_nfc_util_get_record_length(ndef_record_s *Record) +{ + uint32_t RecordLength = 1; + + /* Type length is present only for following TNF + NET_NFC_TNF_NFCWELLKNOWN + NET_NFC_TNF_MEDIATYPE + SLP_FRINET_NFC_NDEFRECORD_TNF_ABSURI + SLP_FRINET_NFC_NDEFRECORD_TNF_NFCEXT + */ + + /* ++ is for the Type Length Byte */ + RecordLength++; + if (Record->TNF != NET_NFC_NDEF_TNF_EMPTY && + Record->TNF != NET_NFC_NDEF_TNF_UNKNOWN && + Record->TNF != NET_NFC_NDEF_TNF_UNCHANGED) + { + RecordLength += Record->type_s.length; + } + + /* to check if payloadlength is 8bit or 32bit*/ + if (Record->SR != 0) + { + /* ++ is for the Payload Length Byte */ + RecordLength++;/* for short record*/ + } + else + { + /* + NET_NFC_NDEF_NORMAL_RECORD_BYTE is for the Payload Length Byte */ + RecordLength += 4; + } + + /* for non empty record */ + if (Record->TNF != NET_NFC_NDEF_TNF_EMPTY) + { + RecordLength += Record->payload_s.length; + } + + /* ID and IDlength are present only if IL flag is set*/ + if (Record->IL != 0) + { + RecordLength += Record->id_s.length; + /* ++ is for the ID Length Byte */ + RecordLength++; + } + + return RecordLength; +} + +net_nfc_error_e net_nfc_util_create_uri_string_from_uri_record(ndef_record_s *record, char **uri) +{ + net_nfc_error_e result = NET_NFC_OK; + + if (record == NULL || uri == NULL) + { + return NET_NFC_INVALID_PARAM; + } + + *uri = NULL; + + if (record->TNF == NET_NFC_RECORD_WELL_KNOWN_TYPE && + (record->type_s.length == 1 && record->type_s.buffer[0] == 'U')) + { + data_s *payload = &record->payload_s; + + if (payload->length > 0) + { + int length = 0; + const char *scheme = NULL; + + /* buffer length include a schema byte. + * so it does not need to allocate one more byte for string. */ + if ((scheme = net_nfc_util_get_schema_string(payload->buffer[0])) != NULL) + { + length = strlen(scheme); + } + + *uri = (char *)calloc(1, length + payload->length); + if (*uri != NULL) + { + if (length > 0) + memcpy(*uri, scheme, length); + memcpy(*uri + length, payload->buffer + 1, payload->length - 1); + } + else + { + result = NET_NFC_ALLOC_FAIL; + } + } + else + { + DEBUG_ERR_MSG("invalid payload in record"); + } + } + else if (record->TNF == NET_NFC_RECORD_URI) + { + data_s *type = &record->type_s; + + if (type->length > 0) + { + *uri = (char *)calloc(1, type->length + 1); + + if (*uri != NULL) + { + memcpy(*uri, type->buffer, type->length); + } + else + { + result = NET_NFC_ALLOC_FAIL; + } + } + } + else + { + DEBUG_ERR_MSG("no uri record"); + result = NET_NFC_NDEF_RECORD_IS_NOT_EXPECTED_TYPE; + } + + return result; +} diff --git a/src/commonlib/net_nfc_util_openssl.c b/src/commonlib/net_nfc_util_openssl.c new file mode 100755 index 0000000..b80ecf4 --- /dev/null +++ b/src/commonlib/net_nfc_util_openssl.c @@ -0,0 +1,890 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include +#include +#include +#include + +#include "net_nfc_typedef_private.h" +#include "net_nfc_debug_private.h" +#include "net_nfc_util_private.h" +#include "net_nfc_util_openssl_private.h" + + /* nfc_log_to_file */ +#include + +FILE* nfc_log_file; + +//static X509 *_load_certificate_from_file(const char *file) +//{ +// X509 *x509 = NULL; +// BIO *cert = NULL; +// +// cert = BIO_new(BIO_s_file()); +// if (cert != NULL) +// { +// if (BIO_read_filename(cert, file) > 0) +// { +// x509 = PEM_read_bio_X509_AUX(cert, NULL, NULL, NULL); +// } +// +// BIO_free(cert); +// } +// +// return x509; +//} + +static X509 *_load_certificate_from_mem(int format, uint8_t *buffer, uint32_t length, char *password) +{ + X509 *x509 = NULL; + BIO *mem = NULL; + + mem = BIO_new_mem_buf(buffer, length); + if (mem != NULL) + { + switch (format) + { + case 0 : + x509 = d2i_X509_bio(mem, NULL); + break; + + case 1 : + x509 = PEM_read_bio_X509(mem, NULL, NULL, NULL); + break; + + case 2 : + { + PKCS12 *p12 = d2i_PKCS12_bio(mem, NULL); + PKCS12_parse(p12, password, NULL, &x509, NULL); + PKCS12_free(p12); + } + break; + } + + BIO_free(mem); + } + else + { + DEBUG_ERR_MSG("X509_LOOKUP_load_file failed"); + } + + return x509; +} + +//int net_nfc_util_openssl_verify_certificate(const char* certfile, const char* CAfile) +//{ +// int ret = 0; +// X509_STORE *cert_ctx = NULL; +// X509_LOOKUP *lookup = NULL; +// +// cert_ctx = X509_STORE_new(); +// if (cert_ctx != NULL) +// { +// OpenSSL_add_all_algorithms(); +// +// lookup = X509_STORE_add_lookup(cert_ctx, X509_LOOKUP_file()); +// if (lookup != NULL) +// { +// if (X509_LOOKUP_load_file(lookup, CAfile, X509_FILETYPE_PEM) == true) +// { +// lookup = X509_STORE_add_lookup(cert_ctx, X509_LOOKUP_hash_dir()); +// if (lookup != NULL) +// { +// X509_LOOKUP_add_dir(lookup, NULL, X509_FILETYPE_DEFAULT); +// +// ret = _verify_certificate_file(cert_ctx, certfile); +// } +// else +// { +// DEBUG_ERR_MSG("X509_STORE_add_lookup failed"); +// } +// } +// else +// { +// DEBUG_ERR_MSG("X509_LOOKUP_load_file failed"); +// } +// } +// else +// { +// DEBUG_ERR_MSG("X509_STORE_add_lookup failed"); +// } +// +// X509_STORE_free(cert_ctx); +// } +// else +// { +// DEBUG_ERR_MSG("X509_STORE_new failed"); +// } +// +// return ret; +//} + +net_nfc_openssl_verify_context_s *net_nfc_util_openssl_init_verify_certificate(void) +{ + net_nfc_openssl_verify_context_s *result = NULL; + + _net_nfc_util_alloc_mem(result, sizeof(net_nfc_openssl_verify_context_s)); + if (result != NULL) + { + result->store = X509_STORE_new(); + if (result->store != NULL) + { + OpenSSL_add_all_algorithms(); + } + else + { + DEBUG_ERR_MSG("X509_STORE_new failed"); + } + } + else + { + DEBUG_ERR_MSG("alloc failed [%d]", sizeof(net_nfc_openssl_verify_context_s)); + } + + return result; +} + +void net_nfc_util_openssl_release_verify_certificate(net_nfc_openssl_verify_context_s *context) +{ + if (context != NULL) + { + if (context->signer_cert != NULL) + X509_free(context->signer_cert); + + if (context->store != NULL) + X509_STORE_free(context->store); + + _net_nfc_util_free_mem(context); + } +} + +bool net_nfc_util_openssl_add_certificate_of_signer(net_nfc_openssl_verify_context_s *context, uint8_t *buffer, uint32_t length) +{ + bool result = false; + + if (context->signer_cert != NULL) + { + X509_free(context->signer_cert); + context->signer_cert = NULL; + } + + context->signer_cert = _load_certificate_from_mem(1, buffer, length, NULL); + if (context->signer_cert != NULL) + result = true; + + return result; +} + +bool net_nfc_util_openssl_add_certificate_of_ca(net_nfc_openssl_verify_context_s *context, uint8_t *buffer, uint32_t length) +{ + bool result = false; + X509 *x509 = NULL; + + x509 = _load_certificate_from_mem(1, buffer, length, NULL); + if (x509 != NULL) + { + if (X509_STORE_add_cert(context->store, x509)) + { + result = true; + } + } + + return result; +} + +int net_nfc_util_openssl_verify_certificate(net_nfc_openssl_verify_context_s *context) +{ + int result = 0; + X509_STORE_CTX *store_ctx = NULL; + + store_ctx = X509_STORE_CTX_new(); + if (store_ctx != NULL) + { + X509_STORE_set_flags(context->store, 0); + if (X509_STORE_CTX_init(store_ctx, context->store, context->signer_cert, 0) == true) + { + result = X509_verify_cert(store_ctx); + } + else + { + DEBUG_ERR_MSG("X509_STORE_CTX_init failed"); + } + + X509_STORE_CTX_free(store_ctx); + } + else + { + DEBUG_ERR_MSG("X509_STORE_CTX_new failed"); + } + + return result; +} + +int _password_callback(char *buf, int bufsiz, int verify, void *data) +{ + int res = 0; + const char *password = (char *)data; + + if (password) + { + res = strlen(password); + if (res > bufsiz) + res = bufsiz; + memcpy(buf, password, res); + return res; + } + + return res; +} + +static int _load_pkcs12(BIO *in, const char *password, EVP_PKEY **pkey, X509 **cert, STACK_OF(X509) **ca) +{ + int ret = 0; + PKCS12 *p12 = NULL; + + if ((p12 = d2i_PKCS12_bio(in, NULL)) != NULL) + { + if (PKCS12_verify_mac(p12, password, strlen(password)) == true) + { + ret = PKCS12_parse(p12, password, pkey, cert, ca); + } + else + { + DEBUG_ERR_MSG("Mac verify error (wrong password?) in PKCS12 file"); + } + + PKCS12_free(p12); + } + else + { + DEBUG_ERR_MSG("Error loading PKCS12 file"); + } + + return ret; +} + +EVP_PKEY *_load_key(const char *file, int format, const char *pass, ENGINE *e) +{ + BIO *key = NULL; + EVP_PKEY *pkey = NULL; + + if (file == NULL) + { + DEBUG_ERR_MSG("no keyfile specified\n"); + return pkey; + } + + if (format == OPENSSL_FORMAT_ENGINE) + { + if (e != NULL) + { + pkey = ENGINE_load_private_key(e, file, NULL/*ui_method*/, (void *)pass); + if (!pkey) + { + DEBUG_ERR_MSG("cannot load key from engine"); + } + } + else + { + DEBUG_ERR_MSG("no engine specified"); + } + } + else + { + if ((key = BIO_new(BIO_s_file())) != NULL) + { + if (BIO_read_filename(key,file) > 0) + { + switch (format) + { + case OPENSSL_FORMAT_ASN1 : + pkey = d2i_PrivateKey_bio(key, NULL); + break; + + case OPENSSL_FORMAT_PEM : + pkey = PEM_read_bio_PrivateKey(key, NULL, (pem_password_cb *)_password_callback, (void *)pass); + break; + + case OPENSSL_FORMAT_PKCS12 : + if (_load_pkcs12(key, pass, &pkey, NULL, NULL) == false) + { + DEBUG_ERR_MSG("_load_pkcs12 failed"); + } + break; + + case OPENSSL_FORMAT_MSBLOB : + pkey = b2i_PrivateKey_bio(key); + break; + + case OPENSSL_FORMAT_PVK : + pkey = b2i_PVK_bio(key, (pem_password_cb *)_password_callback, (void *)pass); + break; + + default : + DEBUG_ERR_MSG("bad input format specified for key file"); + break; + } + } + else + { + DEBUG_ERR_MSG("Error opening %s", file); + } + + BIO_free(key); + } + else + { + DEBUG_ERR_MSG("BIO_new failed"); + } + } + + return pkey; +} + +EVP_PKEY *_load_pubkey(const char *file, int format, const char *pass, ENGINE *e, const char *key_descrip) +{ + BIO *key = NULL; + EVP_PKEY *pkey = NULL; + + if (file == NULL) + { + DEBUG_ERR_MSG("no keyfile specified"); + return pkey; + } + + if (format == OPENSSL_FORMAT_ENGINE) + { + if (e != NULL) + { + pkey = ENGINE_load_public_key(e, file, NULL/*ui_method*/, (void *)pass); + } + else + { + DEBUG_ERR_MSG("no engine specified"); + } + } + else + { + if ((key = BIO_new(BIO_s_file())) != NULL) + { + if (BIO_read_filename(key,file) <= 0) + { + switch (format) + { + case OPENSSL_FORMAT_ASN1 : + pkey = d2i_PUBKEY_bio(key, NULL); + break; + + case OPENSSL_FORMAT_ASN1RSA : + { + RSA *rsa; + rsa = d2i_RSAPublicKey_bio(key, NULL); + if (rsa) + { + pkey = EVP_PKEY_new(); + if (pkey) + EVP_PKEY_set1_RSA(pkey, rsa); + RSA_free(rsa); + } + else + pkey = NULL; + } + break; + + case OPENSSL_FORMAT_PEMRSA : + { + RSA *rsa; + rsa = PEM_read_bio_RSAPublicKey(key, NULL, (pem_password_cb *)_password_callback, (void *)pass); + if (rsa) + { + pkey = EVP_PKEY_new(); + if (pkey) + EVP_PKEY_set1_RSA(pkey, rsa); + RSA_free(rsa); + } + else + pkey = NULL; + } + break; + + case OPENSSL_FORMAT_PEM : + pkey = PEM_read_bio_PUBKEY(key, NULL, (pem_password_cb *)_password_callback, (void *)pass); + break; + + case OPENSSL_FORMAT_MSBLOB : + pkey = b2i_PublicKey_bio(key); + break; + + default : + DEBUG_ERR_MSG("bad input format specified for key file"); + break; + } + } + else + { + DEBUG_ERR_MSG("Error opening %s %s", key_descrip, file); + } + + BIO_free(key); + } + else + { + DEBUG_ERR_MSG("BIO_new failed"); + } + } + + return pkey; +} + +int net_nfc_util_openssl_sign_buffer(uint32_t type, uint8_t *buffer, uint32_t length, char *key_file, char *password, uint8_t *sign, uint32_t *sign_len) +{ + int result = 0; + const EVP_MD *md = NULL; + ENGINE *engine; + EVP_PKEY *pkey; + + OpenSSL_add_all_algorithms(); + + /* md context */ + EVP_MD_CTX ctx = { 0, }; + EVP_PKEY_CTX *pctx = NULL; + + switch (type) + { + case 0 : + result = 0; + return result; + + /* RSASSA-PSS, RSASSA-PKCS1-v1_5 */ + case 1 : + case 2 : + /* md */ + md = EVP_get_digestbyname("sha1"); + + /* engine */ + engine = ENGINE_get_default_RSA(); + break; + + /* DSA */ + case 3 : + /* md */ + //md = EVP_get_digestbyname("sha1"); + /* engine */ + engine = ENGINE_get_default_DSA(); + break; + + /* ECDSA */ + case 4 : + /* md */ + md = EVP_get_digestbyname("sha1"); + + /* engine */ + engine = ENGINE_get_default_ECDSA(); + break; + + default : + result = -1; + return result; + } + + /* pkey */ + pkey = _load_key(key_file, OPENSSL_FORMAT_PKCS12, password, NULL); + + EVP_DigestSignInit(&ctx, &pctx, md, engine, pkey); + EVP_DigestSignUpdate(&ctx, buffer, length); + EVP_DigestSignFinal(&ctx, sign, sign_len); + + return result; +} + +int net_nfc_util_openssl_verify_signature(uint32_t type, uint8_t *buffer, uint32_t length, uint8_t *cert, uint32_t cert_len, uint8_t *sign, uint32_t sign_len) +{ + int result = 0; + const EVP_MD *md = NULL; + ENGINE *engine; + EVP_PKEY *pkey; + + OpenSSL_add_all_algorithms(); + + /* md context */ + EVP_MD_CTX ctx = { 0, }; + EVP_PKEY_CTX *pctx = NULL; + + switch (type) + { + case 0 : + result = 0; + return result; + + /* RSASSA-PSS, RSASSA-PKCS1-v1_5 */ + case 1 : + case 2 : + /* md */ + md = EVP_get_digestbyname("sha1"); + + /* engine */ + engine = ENGINE_get_default_RSA(); + break; + + /* DSA */ + case 3 : + /* md */ + //md = EVP_get_digestbyname("sha1"); + /* engine */ + engine = ENGINE_get_default_DSA(); + break; + + /* ECDSA */ + case 4 : + /* md */ + md = EVP_get_digestbyname("sha1"); + + /* engine */ + engine = ENGINE_get_default_ECDSA(); + break; + + default : + result = -1; + return result; + } + + /* pkey */ + X509 *x509 = _load_certificate_from_mem(0, cert, cert_len, NULL); + pkey = X509_PUBKEY_get(X509_get_X509_PUBKEY(x509)); + X509_free(x509); + + EVP_DigestVerifyInit(&ctx, &pctx, md, engine, pkey); + EVP_DigestVerifyUpdate(&ctx, buffer, length); + result = EVP_DigestVerifyFinal(&ctx, sign, sign_len); + + DEBUG_MSG("EVP_DigestVerifyFinal returns %d", result); + + return result; +} + +#if 0 +int net_nfc_util_get_cert_list_from_file(char *file_name, char *password, uint8_t **buffer, uint32_t *length, uint32_t *cert_count) +{ + int result = 0; + BIO *bio = NULL; + + bio = BIO_new(BIO_s_file()); + if (bio != NULL) + { + if (BIO_read_filename(bio, file_name) > 0) + { + STACK_OF(X509_INFO) *xis = NULL; + + if ((xis = PEM_X509_INFO_read_bio(bio, NULL, (pem_password_cb *)_password_callback, password)) != NULL) + { + X509_INFO *xi; + int i; + uint32_t temp_len = 0; + uint8_t *temp_buf = NULL; + uint32_t offset = 0; + uint32_t count = 0; + + for (i = 0; i < sk_X509_INFO_num(xis); i++) + { + xi = sk_X509_INFO_value(xis, i); + if (xi->x509) + { + int32_t ret = 0; + + if ((ret = i2d_X509(xi->x509, NULL)) > 0) + { + temp_len += (ret + 2); + } + } + } + + DEBUG_MSG("count = %d, length = %d", sk_X509_INFO_num(xis), temp_len); + *length = temp_len; + _net_nfc_util_alloc_mem(*buffer, temp_len); + + for (i = 0; i < sk_X509_INFO_num(xis); i++) + { + xi = sk_X509_INFO_value(xis, i); + if (xi->x509) + { + temp_buf = NULL; + + if ((temp_len = i2d_X509(xi->x509, &temp_buf)) > 0) + { + *(uint16_t *)(*buffer + offset) = temp_len; + offset += sizeof(uint16_t); + + memcpy(*buffer + offset, temp_buf, temp_len); + offset += temp_len; + + count++; + } + } + } + + *cert_count = count; + + sk_X509_INFO_pop_free(xis, X509_INFO_free); + } + else + { + DEBUG_ERR_MSG("PEM_X509_INFO_read_bio failed"); + } + } + + BIO_free(bio); + } + + return result; +} +#endif + +/* TODO : DER?? PEM?? */ +int net_nfc_util_get_cert_list_from_file(char *file_name, char *password, uint8_t **buffer, uint32_t *length, uint32_t *cert_count) +{ + int result = 0; + BIO *bio = NULL; + + bio = BIO_new(BIO_s_file()); + if (bio != NULL) + { + if (BIO_read_filename(bio, file_name) > 0) + { + EVP_PKEY *pkey = NULL; + X509 *x509 = NULL; + STACK_OF(X509) *ca = NULL; + + if (_load_pkcs12(bio, password, &pkey, &x509, &ca) != 0) + { + X509 *temp_x509; + int i; + uint32_t temp_len = 0; + uint8_t *temp_buf = NULL; + uint32_t offset = 0; + uint32_t count = 0; + int32_t ret = 0; + + if ((ret = i2d_X509(x509, NULL)) > 0) + { + temp_len += (ret + 2); + } + + for (i = 0; i < sk_X509_num(ca); i++) + { + temp_x509 = sk_X509_value(ca, i); + if (temp_x509) + { + if ((ret = i2d_X509(temp_x509, NULL)) > 0) + { + temp_len += (ret + 2); + } + } + } + + DEBUG_MSG("count = %d, length = %d", sk_X509_num(ca) + 1, temp_len); + *length = temp_len; + _net_nfc_util_alloc_mem(*buffer, temp_len); + + if ((temp_len = i2d_X509(x509, &temp_buf)) > 0) + { + *(uint16_t *)(*buffer + offset) = temp_len; + offset += sizeof(uint16_t); + + memcpy(*buffer + offset, temp_buf, temp_len); + offset += temp_len; + + count++; + } + + for (i = 0; i < sk_X509_num(ca); i++) + { + temp_x509 = sk_X509_value(ca, i); + if (temp_x509) + { + temp_buf = NULL; + + if ((temp_len = i2d_X509(temp_x509, &temp_buf)) > 0) + { + *(uint16_t *)(*buffer + offset) = temp_len; + offset += sizeof(uint16_t); + + memcpy(*buffer + offset, temp_buf, temp_len); + offset += temp_len; + + count++; + } + } + } + + *cert_count = count; + + sk_X509_pop_free(ca, X509_free); + } + else + { + DEBUG_ERR_MSG("PEM_X509_INFO_read_bio failed"); + } + } + + BIO_free(bio); + } + + return result; +} + +bool net_nfc_util_openssl_encode_base64(const uint8_t *buffer, const uint32_t buf_len, char *result, uint32_t max_len, bool new_line_char) +{ + bool ret = false; + BUF_MEM *bptr; + BIO *b64, *bmem; + + if (buffer == NULL || buf_len == 0) + { + return ret; + } + + b64 = BIO_new(BIO_f_base64()); + bmem = BIO_new(BIO_s_mem()); + + if (new_line_char == false) + BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL); + + b64 = BIO_push(b64, bmem); + + BIO_write(b64, buffer, buf_len); + BIO_flush(b64); + BIO_get_mem_ptr(b64, &bptr); + + if (max_len >= bptr->length) + { + memcpy(result, bptr->data, bptr->length); + result[bptr->length] = 0; + ret = true; + } + else + { + DEBUG_ERR_MSG("not enough result buffer"); + } + + BIO_free_all(b64); + + return ret; +} + +bool net_nfc_util_openssl_decode_base64(const char *buffer, uint8_t *result, uint32_t *out_len, bool new_line_char) +{ + bool ret = false; + unsigned int length = 0; + char *temp; + + if (buffer == NULL || (length = strlen(buffer)) == 0) + { + return ret; + } + + _net_nfc_util_alloc_mem(temp, length); + if (temp != NULL) + { + BIO *b64, *bmem; + + b64 = BIO_new(BIO_f_base64()); + bmem = BIO_new_mem_buf((void *)buffer, length); + if (new_line_char == false) + BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL); + bmem = BIO_push(b64, bmem); + + length = BIO_read(bmem, temp, length); + + BIO_free_all(bmem); + + if (*out_len > length) + { + *out_len = length; + memcpy(result, temp, *out_len); + ret = true; + } + else + { + DEBUG_ERR_MSG("not enough result buffer"); + } + + _net_nfc_util_free_mem(temp); + } + else + { + DEBUG_ERR_MSG("alloc failed"); + } + + return ret; +} + +bool net_nfc_util_openssl_digest(const char *algorithm, const uint8_t *buffer, const uint32_t buf_len, uint8_t *result, uint32_t *out_len) +{ + const EVP_MD *md; + unsigned char *temp; + bool ret = false; + + if (algorithm == NULL || buffer == NULL || buf_len == 0) + { + return ret; + } + + OpenSSL_add_all_digests(); + + if ((md = EVP_get_digestbyname(algorithm)) != NULL) + { + _net_nfc_util_alloc_mem(temp, EVP_MAX_MD_SIZE); + if (temp != NULL) + { + EVP_MD_CTX mdCtx; + unsigned int resultLen = 0; + + memset(temp, 0, EVP_MAX_MD_SIZE); + + EVP_DigestInit(&mdCtx, md); + if (EVP_DigestUpdate(&mdCtx, buffer, buf_len) != 0) + { + DEBUG_ERR_MSG("EVP_DigestUpdate failed"); + } + EVP_DigestFinal(&mdCtx, temp, &resultLen); + + if (*out_len >= resultLen) + { + *out_len = resultLen; + memcpy(result, temp, *out_len); + ret = true; + } + else + { + DEBUG_ERR_MSG("not enough result buffer"); + } + + _net_nfc_util_free_mem(temp); + } + else + { + DEBUG_ERR_MSG("alloc failed"); + } + } + else + { + DEBUG_ERR_MSG("EVP_get_digestbyname(\"%s\") returns NULL", algorithm); + } + + return ret; +} diff --git a/src/commonlib/net_nfc_util_sign_record.c b/src/commonlib/net_nfc_util_sign_record.c new file mode 100644 index 0000000..db6c121 --- /dev/null +++ b/src/commonlib/net_nfc_util_sign_record.c @@ -0,0 +1,377 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include + +#include "net_nfc_debug_private.h" +#include "net_nfc_util_defines.h" +#include "net_nfc_util_private.h" +#include "net_nfc_util_ndef_message.h" +#include "net_nfc_util_ndef_record.h" +#include "net_nfc_util_openssl_private.h" +#include "net_nfc_util_sign_record.h" + +#define IS_SIGN_RECORD(__x) \ + (((__x)->TNF == NET_NFC_RECORD_WELL_KNOWN_TYPE) && \ + ((__x)->type_s.length == 3) && \ + (memcmp((__x)->type_s.buffer, "Sig", 3) == 0)) + +#define IS_EMPTY_RECORD(__x) \ + ((__x->TNF == NET_NFC_RECORD_EMPTY)) + +#define __FILL_SUB_FIELD(__dst, __buf, __len) \ + (__dst)->length = (__len); \ + memcpy((__dst)->value, (__buf), (__dst)->length); + +#define __NEXT_SUB_FIELD(__dst) ((__dst)->value + (__dst)->length) + +bool _get_records_data_buffer(ndef_record_s *begin_record, ndef_record_s *end_record, uint8_t **buffer, uint32_t *length) +{ + bool result = false; + uint32_t len = 0; + ndef_record_s *current_record = NULL; + + if (begin_record == NULL || begin_record == end_record) + return result; + + /* count total buffer length */ + current_record = begin_record; + len = 0; + + while (current_record != NULL && current_record != end_record) + { + /* type length */ + if (current_record->type_s.buffer != NULL && current_record->type_s.length > 0) + len += current_record->type_s.length; + + /* ID length */ + if (current_record->id_s.buffer != NULL && current_record->id_s.length > 0) + len += current_record->id_s.length; + + /* payload length */ + if (current_record->payload_s.buffer != NULL && current_record->payload_s.length > 0) + len += current_record->payload_s.length; + + current_record = current_record->next; + } + + if (len > 0) + { + uint8_t *buf = NULL; + + _net_nfc_util_alloc_mem(buf, len); + if (buf != NULL) + { + uint32_t offset = 0; + + current_record = begin_record; + + while (offset < len && current_record != NULL && current_record != end_record) + { + /* type length */ + if (current_record->type_s.buffer != NULL && current_record->type_s.length > 0) + { + memcpy(buf + offset, current_record->type_s.buffer, MIN(current_record->type_s.length, len - offset)); + offset += MIN(current_record->type_s.length, len - offset); + } + + /* ID length */ + if (current_record->id_s.buffer != NULL && current_record->id_s.length > 0) + { + memcpy(buf + offset, current_record->id_s.buffer, MIN(current_record->id_s.length, len - offset)); + offset += MIN(current_record->id_s.length, len - offset); + } + + /* payload length */ + if (current_record->payload_s.buffer != NULL && current_record->payload_s.length > 0) + { + memcpy(buf + offset, current_record->payload_s.buffer, MIN(current_record->payload_s.length, len - offset)); + offset += MIN(current_record->payload_s.length, len - offset); + } + + current_record = current_record->next; + } + + *buffer = buf; + *length = offset; + + result = true; + } + } + + return result; +} + +net_nfc_error_e net_nfc_util_verify_signature_records(ndef_record_s *begin_record, ndef_record_s *sign_record) +{ + net_nfc_error_e result = NET_NFC_UNKNOWN_ERROR; + uint8_t *buffer = NULL; + uint32_t length = 0; + + if (begin_record == NULL || sign_record == NULL || begin_record == sign_record) + return NET_NFC_INVALID_PARAM; + + /* get signed data */ + if (_get_records_data_buffer(begin_record, sign_record, &buffer, &length) == true) + { + uint8_t *signature = NULL; + uint32_t sign_len = 0; + net_nfc_signature_record_s *sign_info = NULL; + net_nfc_certificate_chain_s *chain_info = NULL; + + /* parse signature info */ + sign_info = (net_nfc_signature_record_s *)sign_record->payload_s.buffer; + + DEBUG_MSG("record version : %d", sign_info->version); + DEBUG_MSG("signature URI present? : %s", sign_info->uri_present ? "true" : "false"); + DEBUG_MSG("signature type : %d", sign_info->sign_type); + DEBUG_MSG("signature length : %d", sign_info->signature.length); + + if (sign_info->uri_present == true) + { + /* TODO */ + /* receive the signature data directed by uri */ + DEBUG_ERR_MSG("NOT IMPLEMENTED (sign_info->uri_present == true)"); + _net_nfc_util_free_mem(buffer); + return result; + } + else + { + signature = sign_info->signature.value; + sign_len = sign_info->signature.length; + } + + /* parse certificate chain info */ + chain_info = (net_nfc_certificate_chain_s *)__NEXT_SUB_FIELD(&(sign_info->signature)); + + DEBUG_MSG("certificate URI present? : %s", chain_info->uri_present ? "true" : "false"); + DEBUG_MSG("certificate format : %d", chain_info->cert_format); + DEBUG_MSG("number of certificates : %d", chain_info->num_of_certs); + + if (chain_info->num_of_certs > 0) + { + net_nfc_sub_field_s *data_info = NULL; + + data_info = (net_nfc_sub_field_s *)chain_info->cert_store; + DEBUG_MSG("certficate length : %d", data_info->length); + + // DEBUG_MSG_PRINT_BUFFER(data_info->value, data_info->length); + + /* the first certificate is signer's one + * verify signature of content */ + if (net_nfc_util_openssl_verify_signature(sign_info->sign_type, buffer, length, data_info->value, data_info->length, sign_info->signature.value, sign_info->signature.length) == true) + { + if (chain_info->num_of_certs > 1) + { + int32_t i = 0; + net_nfc_openssl_verify_context_h context = NULL; + + /* initialize context of verifying certificate */ + context = net_nfc_util_openssl_init_verify_certificate(); + + /* add signer's certificate */ + net_nfc_util_openssl_add_certificate_of_signer(context, data_info->value, data_info->length); + + /* verify certificate using certificate chain */ + for (i = 1, data_info = (net_nfc_sub_field_s *)__NEXT_SUB_FIELD(data_info); + i < chain_info->num_of_certs; + i++, data_info = (net_nfc_sub_field_s *)__NEXT_SUB_FIELD(data_info)) + { + DEBUG_MSG("certficate length : %d", data_info->length); +// DEBUG_MSG_PRINT_BUFFER(data_info->value, data_info->length); + + net_nfc_util_openssl_add_certificate_of_ca(context, data_info->value, data_info->length); + } + + /* if the CA_Uri is present, continue adding certificate from uri */ + if (chain_info->uri_present == true) + { + /* TODO : Need to implement */ + DEBUG_ERR_MSG("NOT IMPLEMENTED (found_root == false && chain_info->uri_present == true)"); + net_nfc_util_openssl_release_verify_certificate(context); + _net_nfc_util_free_mem(buffer); + return result; + +// DEBUG_MSG("certficate length : %d", data_info->length); +// DEBUG_MSG_PRINT_BUFFER(data_info->value, data_info->length); + } + + /* verify buffer with cert chain and signature bytes */ + if (net_nfc_util_openssl_verify_certificate(context) == true) + result = NET_NFC_OK; + + net_nfc_util_openssl_release_verify_certificate(context); + } + else + { + /* TODO : test certificate??? */ + result = NET_NFC_OK; + } + + DEBUG_MSG("verifying signature %d", result); + } + else + { + DEBUG_ERR_MSG("verifying signature failed"); + } + } + else + { + DEBUG_ERR_MSG("certificate not found"); + } + + _net_nfc_util_free_mem(buffer); + } + else + { + DEBUG_ERR_MSG("_get_records_data_buffer failed"); + } + + return result; +} + +net_nfc_error_e net_nfc_util_verify_signature_ndef_message(ndef_message_s *msg) +{ + net_nfc_error_e result = NET_NFC_UNKNOWN_ERROR; + ndef_record_s *begin_record = NULL; + ndef_record_s *current_record = NULL; + + begin_record = msg->records; + current_record = msg->records; + + while (current_record != NULL) + { + if (begin_record == NULL) + { + begin_record = current_record; + } + + if (IS_EMPTY_RECORD(current_record)) + { + begin_record = NULL; + } + else if (IS_SIGN_RECORD(current_record)) + { + result = net_nfc_util_verify_signature_records(begin_record, current_record); + + begin_record = NULL; + } + + current_record = current_record->next; + } + + return result; +} + +/* + * sign method + */ +net_nfc_error_e net_nfc_util_sign_records(ndef_message_s *msg, int begin_index, int end_index, char *cert_file, char *password) +{ + net_nfc_error_e result = NET_NFC_UNKNOWN_ERROR; + ndef_record_s *begin_record = NULL, *end_record = NULL, *record = NULL; + data_s payload = { NULL, 0 }; + uint8_t *data_buffer = NULL; + uint32_t data_len = 0; + uint8_t signature[1024] = { 0, }; + uint32_t sign_len = sizeof(signature); + uint8_t *cert_buffer = NULL; + uint32_t cert_len = 0; + uint32_t cert_count = 0; + + net_nfc_util_get_record_by_index(msg, begin_index, &begin_record); + net_nfc_util_get_record_by_index(msg, end_index, &end_record); + + DEBUG_MSG("total record count : %d, begin_index : %d, end_index : %d", msg->recordCount, begin_index, end_index); + + /* get target data */ + _get_records_data_buffer(begin_record, end_record->next, &data_buffer, &data_len); + + DEBUG_MSG_PRINT_BUFFER(data_buffer, data_len); + + net_nfc_util_openssl_sign_buffer(NET_NFC_SIGN_TYPE_PKCS_1, data_buffer, data_len, cert_file, password, signature, &sign_len); + + /* get cert chain */ + net_nfc_util_get_cert_list_from_file(cert_file, password, &cert_buffer, &cert_len, &cert_count); + + /* create payload */ + payload.length = sizeof(net_nfc_signature_record_s) + sign_len + sizeof(net_nfc_certificate_chain_s) + cert_len; + + _net_nfc_util_alloc_mem(payload.buffer, payload.length); + + net_nfc_signature_record_s *sign_record = (net_nfc_signature_record_s *)payload.buffer; + sign_record->version = 1; + sign_record->uri_present = 0; + sign_record->sign_type = NET_NFC_SIGN_TYPE_PKCS_1; + + if (sign_record->uri_present) + { + /* TODO */ + } + else + { + __FILL_SUB_FIELD(&(sign_record->signature), signature, sign_len); + } + + net_nfc_certificate_chain_s *chain = (net_nfc_certificate_chain_s *)__NEXT_SUB_FIELD(&(sign_record->signature)); + if (cert_count < 16) + { + chain->uri_present = 0; + } + else + { + chain->uri_present = 1; + } + + chain->cert_format = NET_NFC_CERT_FORMAT_X_509; + chain->num_of_certs = cert_count; + memcpy(chain->cert_store, cert_buffer, cert_len); + + if (chain->uri_present) + { + /* TODO */ + DEBUG_ERR_MSG("num_of_certs is greater than 15 [%d]", cert_count); + } + + /* create record */ + data_s type = { (uint8_t *)"Sig", 3 }; + + net_nfc_util_create_record(NET_NFC_RECORD_WELL_KNOWN_TYPE, &type, NULL, &payload, &record); + + /* get last record index */ + net_nfc_util_append_record_by_index(msg, end_index + 1, record); + + _net_nfc_util_free_mem(payload.buffer); + _net_nfc_util_free_mem(cert_buffer); + _net_nfc_util_free_mem(data_buffer); + + return result; +} + +net_nfc_error_e net_nfc_util_sign_ndef_message(ndef_message_s *msg, char *cert_file, char *password) +{ + net_nfc_error_e result = NET_NFC_UNKNOWN_ERROR; + + if (msg->recordCount > 0) + { + net_nfc_util_sign_records(msg, 0, msg->recordCount - 1, cert_file, password); + + result = NET_NFC_OK; + } + + return result; +} diff --git a/src/commonlib/nfc-common-lib.pc.in b/src/commonlib/nfc-common-lib.pc.in new file mode 100755 index 0000000..1df1eee --- /dev/null +++ b/src/commonlib/nfc-common-lib.pc.in @@ -0,0 +1,13 @@ +# Package Information for pkg-config + +prefix=/usr +exec_prefix=/usr/bin +libdir=/usr/lib +includedir=/usr/include/nfc-common-lib + +Name: nfc-common-lib +Description: NFC Common Library +Version: 1.0 +Requires: +Libs: -L/usr/lib -lnfc-common-lib +Cflags: -I/usr/include/nfc-common-lib diff --git a/src/manager/CMakeLists.txt b/src/manager/CMakeLists.txt new file mode 100644 index 0000000..43baaf0 --- /dev/null +++ b/src/manager/CMakeLists.txt @@ -0,0 +1,78 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +#PROJECT(nfc C) +PROJECT(nfc-manager-daemon C) + +SET(NFC_MANAGER_DAEMON "nfc-manager-daemon") + +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../commonlib/include) +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include) + +AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/ MANAGER_SRCS) + +IF("${CMAKE_BUILD_TYPE}" STREQUAL "") + SET(CMAKE_BUILD_TYPE "Release") +ENDIF("${CMAKE_BUILD_TYPE}" STREQUAL "") + +INCLUDE(FindPkgConfig) +pkg_check_modules(manager_pkges REQUIRED aul glib-2.0 gobject-2.0 security-server dbus-glib-1 vconf dlog tapi appsvc libcurl bluetooth-api heynoti smartcard-service smartcard-service-common libssl pmapi svi capi-media-wav-player pkgmgr) + +FOREACH(flag ${manager_pkges_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) + +MESSAGE("CHECK MODULE in MANAGER ${manager_pkges_LDFLAGS}") + +# this for NFC flag + +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -pipe -fomit-frame-pointer -Wall -Wno-trigraphs -Werror-implicit-function-declaration -fno-strict-aliasing -Wl,-zdefs -fvisibility=hidden") + +SET(ARM_CFLAGS "${ARM_CLAGS} -mapcs -mno-sched-prolog -mabi=aapcs-linux -Uarm -fno-common -fpic") + +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror-implicit-function-declaration") + +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}") +SET(CMAKE_C_FLAGS_DEBUG "-O0 -g") + +FIND_PROGRAM(UNAME NAMES uname) +EXEC_PROGRAM("${UNAME}" ARGS "-m" OUTPUT_VARIABLE "ARCH") +IF("${ARCH}" MATCHES "^arm.*") + ADD_DEFINITIONS("-DTARGET") + MESSAGE("add -DTARGET") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${ARM_CFLAGS}") +ENDIF() + +ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"") +#ADD_DEFINITIONS("-DSLP_DEBUG") +ADD_DEFINITIONS("-DCLIENT_IPC_THREAD") + +ADD_DEFINITIONS("-DNFC_FIRMWARE_UPDATE") +ADD_DEFINITIONS("-DNFC_DEBUG_USE_DLOG -D_GNU_SOURCE") +ADD_DEFINITIONS("-DUSE_UNIX_DOMAIN") +ADD_DEFINITIONS("-DUSE_IPC_EPOLL -DUSE_EPOLL_TIMEOUT") +ADD_DEFINITIONS("-DLLCP_MODE") +ADD_DEFINITIONS("-DNFC_APP_SUPPORTED") +ADD_DEFINITIONS("-DBROADCAST_MESSAGE") +ADD_DEFINITIONS("-DSAVE_TARGET_INFO_IN_CC") +ADD_DEFINITIONS("-DSECURITY_SERVER") +#ADD_DEFINITIONS("-DG_MAIN_LOOP") +#ADD_DEFINITIONS("-DUSE_ECORE_MAIN_LOOP") +ADD_DEFINITIONS("-DUSE_GLIB_MAIN_LOOP") +ADD_DEFINITIONS("-DUSE_FULL_URI") +# add temporary +ADD_DEFINITIONS("-D_TIZEN_OPEN") + +SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed") +FIND_PROGRAM(DBUS_BINDING_TOOL NAMES dbus-binding-tool) +EXEC_PROGRAM("${DBUS_BINDING_TOOL}" ARGS "--prefix=nfc_service ${CMAKE_CURRENT_SOURCE_DIR}/nfc-service.xml --mode=glib-client --output=${CMAKE_CURRENT_SOURCE_DIR}/include/nfc-service-glue.h") +EXEC_PROGRAM("${DBUS_BINDING_TOOL}" ARGS "--prefix=nfc_service ${CMAKE_CURRENT_SOURCE_DIR}/nfc-service.xml --mode=glib-server --output=${CMAKE_CURRENT_SOURCE_DIR}/include/nfc-service-binding.h") + +ADD_EXECUTABLE(${NFC_MANAGER_DAEMON} ${MANAGER_SRCS}) + + +TARGET_LINK_LIBRARIES(${NFC_MANAGER_DAEMON} ${manager_pkges_LDFLAGS} "-lpthread -lrt -pie -ldl -L${CMAKE_CURRENT_SOURCE_DIR}/../../cmake_tmp/src/commonlib/ -lnfc-common-lib -L${CMAKE_CURRENT_SOURCE_DIR}/../../cmake_tmp/src/clientlib/ -lnfc") + +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/nfc-manager.service DESTINATION share/dbus-1/services) +INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/sounds DESTINATION /usr/share/nfc-manager-daemon) +INSTALL(TARGETS ${NFC_MANAGER_DAEMON} DESTINATION bin) + + diff --git a/src/manager/include/net_nfc_app_util_private.h b/src/manager/include/net_nfc_app_util_private.h new file mode 100644 index 0000000..cd7f3b9 --- /dev/null +++ b/src/manager/include/net_nfc_app_util_private.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#ifndef NET_NFC_APP_UTIL_H +#define NET_NFC_APP_UTIL_H + +#include "net_nfc_typedef.h" +#include "net_nfc_typedef_private.h" +#include + +#ifndef MESSAGE_STORAGE +#define MESSAGE_STORAGE "/opt/share/service/nfc-manager" +#endif + +net_nfc_error_e net_nfc_app_util_store_ndef_message(data_s *data); +net_nfc_error_e net_nfc_app_util_process_ndef(data_s *data); +void net_nfc_app_util_aul_launch_app(char* package_name, bundle* kb); +void net_nfc_app_util_clean_storage(char* src_path); +bool net_nfc_app_util_is_dir(const char* path_name); +int net_nfc_app_util_appsvc_launch(const char *operation, const char *uri, const char *mime, const char *data); +int net_nfc_app_util_launch_se_transaction_app(uint8_t *aid, uint32_t aid_len, uint8_t *param, uint32_t param_len); +int net_nfc_app_util_encode_base64(uint8_t *buffer, uint32_t buf_len, char *result, uint32_t max_result); +int net_nfc_app_util_decode_base64(const char *buffer, uint32_t buf_len, uint8_t *result, uint32_t *res_len); + +#endif diff --git a/src/manager/include/net_nfc_controller_private.h b/src/manager/include/net_nfc_controller_private.h new file mode 100644 index 0000000..37a9c81 --- /dev/null +++ b/src/manager/include/net_nfc_controller_private.h @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#ifndef NET_NFC_CONTROLLER_H +#define NET_NFC_CONTROLLER_H + +#include "net_nfc_typedef.h" +#include "net_nfc_typedef_private.h" + +void* net_nfc_controller_onload(void); +bool net_nfc_controller_unload(void* handle); +bool net_nfc_controller_init (net_nfc_error_e* result); +bool net_nfc_controller_deinit (void); +bool net_nfc_controller_register_listener(target_detection_listener_cb target_detection_listener, se_transaction_listener_cb se_transaction_listener, llcp_event_listener_cb llcp_event_listener, net_nfc_error_e* result); +bool net_nfc_controller_unregister_listener(void); +bool net_nfc_controller_get_firmware_version(data_s **data, net_nfc_error_e *result); +bool net_nfc_controller_check_firmware_version(net_nfc_error_e* result); +bool net_nfc_controller_update_firmware(net_nfc_error_e* result); +bool net_nfc_controller_get_stack_information(net_nfc_stack_information_s* stack_info, net_nfc_error_e* result); +bool net_nfc_controller_confiure_discovery (net_nfc_discovery_mode_e mode, net_nfc_event_filter_e config, net_nfc_error_e* result); +bool net_nfc_controller_get_secure_element_list(net_nfc_secure_element_info_s* list, int* count, net_nfc_error_e* result); +bool net_nfc_controller_set_secure_element_mode(net_nfc_secure_element_type_e element_type, net_nfc_secure_element_mode_e mode, net_nfc_error_e* result); +bool net_nfc_controller_check_target_presence(net_nfc_target_handle_s* handle, net_nfc_error_e* result); +bool net_nfc_controller_connect(net_nfc_target_handle_s* handle, net_nfc_error_e* result); +bool net_nfc_controller_disconnect(net_nfc_target_handle_s* handle, net_nfc_error_e* result); +bool net_nfc_controller_check_ndef(net_nfc_target_handle_s* handle, uint8_t *ndef_card_state, int* max_data_size, int* real_data_size, net_nfc_error_e* result); +bool net_nfc_controller_read_ndef(net_nfc_target_handle_s* handle, data_s** data, net_nfc_error_e* result); +bool net_nfc_controller_write_ndef(net_nfc_target_handle_s* handle, data_s* data, net_nfc_error_e* result); +bool net_nfc_controller_make_read_only_ndef(net_nfc_target_handle_s* handle, net_nfc_error_e* result); +bool net_nfc_controller_format_ndef(net_nfc_target_handle_s* handle, data_s* secure_key, net_nfc_error_e* result); +bool net_nfc_controller_transceive (net_nfc_target_handle_s* handle, net_nfc_transceive_info_s* info, data_s** data, net_nfc_error_e* result); +bool net_nfc_controller_exception_handler(void); +bool net_nfc_controller_is_ready(net_nfc_error_e* result); + +// LLCP API DEFINE + +bool net_nfc_controller_llcp_config(net_nfc_llcp_config_info_s * config, net_nfc_error_e * result); +bool net_nfc_controller_llcp_check_llcp(net_nfc_target_handle_s* handle, net_nfc_error_e* result); +bool net_nfc_controller_llcp_activate_llcp(net_nfc_target_handle_s * handle, net_nfc_error_e* result); +bool net_nfc_controller_llcp_create_socket(net_nfc_llcp_socket_t* socket, net_nfc_socket_type_e socketType, uint16_t miu, uint8_t rw, net_nfc_error_e* result, void * user_param); +bool net_nfc_controller_llcp_bind(net_nfc_llcp_socket_t socket, uint8_t service_access_point, net_nfc_error_e* result); +bool net_nfc_controller_llcp_listen(net_nfc_target_handle_s* handle, uint8_t* service_access_name, net_nfc_llcp_socket_t socket, net_nfc_error_e* result, void * user_param); +bool net_nfc_controller_llcp_accept(net_nfc_llcp_socket_t socket, net_nfc_error_e* result); +bool net_nfc_controller_llcp_connect_by_url(net_nfc_target_handle_s * handle, net_nfc_llcp_socket_t socket, uint8_t* service_access_name, net_nfc_error_e* result, void * user_param); +bool net_nfc_controller_llcp_connect(net_nfc_target_handle_s * handle, net_nfc_llcp_socket_t socket, uint8_t service_access_point, net_nfc_error_e* result, void * user_param); +bool net_nfc_controller_llcp_disconnect(net_nfc_target_handle_s * handle, net_nfc_llcp_socket_t socket, net_nfc_error_e* result, void * user_param); +bool net_nfc_controller_llcp_socket_close(net_nfc_llcp_socket_t socket, net_nfc_error_e* result); +bool net_nfc_controller_llcp_recv(net_nfc_target_handle_s* handle, net_nfc_llcp_socket_t socket, data_s* data, net_nfc_error_e* result, void * user_param); +bool net_nfc_controller_llcp_send(net_nfc_target_handle_s* handle, net_nfc_llcp_socket_t socket, data_s* data, net_nfc_error_e* result, void * user_param); +bool net_nfc_controller_llcp_recv_from(net_nfc_target_handle_s* handle, net_nfc_llcp_socket_t socket, data_s* data, net_nfc_error_e* result, void * user_param); +bool net_nfc_controller_llcp_send_to(net_nfc_target_handle_s* handle, net_nfc_llcp_socket_t socket, data_s* data, uint8_t service_access_point, net_nfc_error_e* result, void * user_param); +bool net_nfc_controller_llcp_reject(net_nfc_target_handle_s* handle, net_nfc_llcp_socket_t socket, net_nfc_error_e* result); +bool net_nfc_controller_llcp_get_remote_config (net_nfc_target_handle_s* handle, net_nfc_llcp_config_info_s *config, net_nfc_error_e* result); +bool net_nfc_controller_llcp_get_remote_socket_info (net_nfc_target_handle_s* handle, net_nfc_llcp_socket_t socket, net_nfc_llcp_socket_option_s * option, net_nfc_error_e* result); + + + +// LLCP API DEFINE + +bool net_nfc_controller_sim_test(net_nfc_error_e* result); +bool net_nfc_controller_prbs_test(net_nfc_error_e* result , uint32_t tech , uint32_t rate); + +bool net_nfc_controller_test_mode_on(net_nfc_error_e* result); +bool net_nfc_controller_test_mode_off(net_nfc_error_e* result); +bool net_nfc_test_sim(void); + +bool net_nfc_controller_support_nfc(net_nfc_error_e* result); + +bool net_nfc_controller_eedata_register_set(net_nfc_error_e *result , uint32_t mode , uint32_t reg_id , data_s *data); +#endif + diff --git a/src/manager/include/net_nfc_manager_dbus.h b/src/manager/include/net_nfc_manager_dbus.h new file mode 100644 index 0000000..c3bae22 --- /dev/null +++ b/src/manager/include/net_nfc_manager_dbus.h @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef MANAGERDBUS_H_ +#define MANAGERDBUS_H_ + +/* standard library header */ +#include + +/* SLP library header */ + +/* local header */ + +typedef struct _Nfc_Service Nfc_Service; +typedef struct _Nfc_ServiceClass Nfc_ServiceClass; + +#define NFC_SERVICE_NAME "org.tizen.nfc_service" +#define NFC_SERVICE_PATH "/org/tizen/nfc_service" + +GType nfc_service_get_type(void); + +struct _Nfc_Service +{ + GObject parent; + int status; +}; + +struct _Nfc_ServiceClass +{ + GObjectClass parent; +}; + +#define NFC_SERVICE_TYPE (nfc_service_get_type ()) +#define NFC_SERVICE(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), NFC_SERVICE_TYPE, Nfc_Service)) +#define NFC_SERVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NFC_SERVICE_TYPE, Nfc_Service_Class)) +#define IS_NFC_SERVICE(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), NFC_SERVICE_TYPE)) +#define IS_NFC_SERVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NFC_SERVICE_TYPE)) +#define NFC_SERVICE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NFC_SERVICE_TYPE, Nfc_Service_Class)) + +typedef enum +{ + NFC_SERVICE_ERROR_INVALID_PRAM +} Nfc_Service_Error; + +GQuark nfc_service_error_quark(void); +#define NFC_SERVICE_ERROR nfc_service_error_quark () + + + +/** + * launch the nfc-manager + */ + gboolean nfc_service_launch (Nfc_Service *nfc_service, guint *result_val, GError **error); + + gboolean nfc_service_terminate (Nfc_Service *nfc_service, guint *result_val, GError **error); + + +#endif /* MANAGERDBUS_H_ */ diff --git a/src/manager/include/net_nfc_manager_util_private.h b/src/manager/include/net_nfc_manager_util_private.h new file mode 100644 index 0000000..2f78d77 --- /dev/null +++ b/src/manager/include/net_nfc_manager_util_private.h @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __NET_NFC_MANAGER_UTIL_PRIVATE__ +#define __NET_NFC_MANAGER_UTIL_PRIVATE__ + +#define NET_NFC_MANAGER_DATA_PATH "/opt/data/nfc-manager-daemon" +#define NET_NFC_MANAGER_DATA_PATH_MESSAGE "message" +#define NET_NFC_MANAGER_DATA_PATH_CONFIG "config" +#define NET_NFC_MANAGER_NDEF_FILE_NAME "ndef-message.txt" +#define NET_NFC_MANAGER_LLCP_CONFIG_FILE_NAME "nfc-manager-config.txt" + +#ifdef _TIZEN_OPEN +#define NET_NFC_MANAGER_SOUND_PATH_TASK_START "/usr/share/nfc-manager-daemon/sounds/Operation_sdk.wav" +#define NET_NFC_MANAGER_SOUND_PATH_TASK_END "/usr/share/nfc-manager-daemon/sounds/Operation_sdk.wav" +#define NET_NFC_MANAGER_SOUND_PATH_TASK_ERROR "/usr/share/nfc-manager-daemon/sounds/Operation_sdk.wav" +#else +#define NET_NFC_MANAGER_SOUND_PATH_TASK_START "/usr/share/nfc-manager-daemon/sounds/NFC_start.wav" +#define NET_NFC_MANAGER_SOUND_PATH_TASK_END "/usr/share/nfc-manager-daemon/sounds/NFC_end.wav" +#define NET_NFC_MANAGER_SOUND_PATH_TASK_ERROR "/usr/share/nfc-manager-daemon/sounds/NFC_error.wav" +#endif + +#define BUFFER_LENGTH_MAX 1024 + +#define READ_BUFFER_LENGTH_MAX BUFFER_LENGTH_MAX +#define WRITE_BUFFER_LENGTH_MAX BUFFER_LENGTH_MAX +#define NET_NFC_MAX_LLCP_SOCKET_BUFFER BUFFER_LENGTH_MAX + +typedef enum +{ + NET_NFC_TASK_START = 0x00, + NET_NFC_TASK_END, + NET_NFC_TASK_ERROR +} net_nfc_sound_type_e; + +void net_nfc_manager_util_play_sound(net_nfc_sound_type_e sound_type); + +#endif + diff --git a/src/manager/include/net_nfc_server_context_private.h b/src/manager/include/net_nfc_server_context_private.h new file mode 100644 index 0000000..6f8fe16 --- /dev/null +++ b/src/manager/include/net_nfc_server_context_private.h @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef NET_NFC_SERVER_CONTEXT_H +#define NET_NFC_SERVER_CONTEXT_H + +#include "net_nfc_typedef_private.h" + +/* define */ +typedef struct _net_nfc_client_info_t +{ + int socket; + GIOChannel *channel; + uint32_t src_id; + client_state_e state; + //client_type_e client_type; + bool is_set_launch_popup; + net_nfc_target_handle_s *target_handle; +} net_nfc_client_info_t; + +typedef void (*net_nfc_server_for_each_client_cb)(net_nfc_client_info_t *client, void *user_param); + +void net_nfc_server_deinit_client_context(); +void net_nfc_server_add_client_context(int socket, GIOChannel* channel, uint32_t src_id, client_state_e state); +void net_nfc_server_cleanup_client_context(int socket); +net_nfc_client_info_t *net_nfc_server_get_client_context(int socket); +int net_nfc_server_get_client_count(); +void net_nfc_server_for_each_client_context(net_nfc_server_for_each_client_cb cb, void *user_param); + +bool net_nfc_server_check_client_is_running(int socket); +client_state_e net_nfc_server_get_client_state(int socket); +void net_nfc_server_set_client_state(int socket, client_state_e state); +bool net_nfc_server_is_set_launch_state(); +void net_nfc_server_set_launch_state(int socket, bool enable); + +#endif /* NET_NFC_SERVER_CONTEXT_H */ diff --git a/src/manager/include/net_nfc_server_dispatcher_private.h b/src/manager/include/net_nfc_server_dispatcher_private.h new file mode 100755 index 0000000..2194d3e --- /dev/null +++ b/src/manager/include/net_nfc_server_dispatcher_private.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#ifndef __NET_NFC_SERVER_DISPATCHER__ +#define __NET_NFC_SERVER_DISPATCHER__ + +#include "net_nfc_typedef_private.h" + +void net_nfc_dispatcher_queue_push(net_nfc_request_msg_t* req_msg); +bool net_nfc_dispatcher_start_thread(); +void net_nfc_dispatcher_cleanup_queue(void); +void net_nfc_dispatcher_put_cleaner(void); + + +#endif + + diff --git a/src/manager/include/net_nfc_server_ipc_private.h b/src/manager/include/net_nfc_server_ipc_private.h new file mode 100755 index 0000000..10a6bd7 --- /dev/null +++ b/src/manager/include/net_nfc_server_ipc_private.h @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef NET_NFC_SERVER_IPC_H +#define NET_NFC_SERVER_IPC_H + +#include + +#include "net_nfc_typedef_private.h" + +#ifdef SECURITY_SERVER +#define NET_NFC_MANAGER_OBJECT "nfc-manager" +#endif +#define NET_NFC_CLIENT_MAX 10 + +typedef struct net_nfc_server_info_t +{ + uint32_t server_src_id ; + GIOChannel *server_channel ; + int server_sock_fd ; + uint32_t state; + net_nfc_current_target_info_s *target_info; +}net_nfc_server_info_t; + +bool net_nfc_server_ipc_initialize(); +void net_nfc_server_ipc_finalize(); + +bool net_nfc_server_set_server_state(uint32_t state); +bool net_nfc_server_unset_server_state(uint32_t state); +uint32_t net_nfc_server_get_server_state(); + +int net_nfc_server_recv_message_from_client(int client_sock_fd, void* message, int length); +#ifdef BROADCAST_MESSAGE +bool net_nfc_broadcast_response_msg(int msg_type, ...); +bool net_nfc_send_response_msg(int socket, int msg_type, ...); +#else +bool net_nfc_send_response_msg(int msg_type, ...); +#endif +void net_nfc_server_set_tag_info(void *info); +bool net_nfc_server_is_target_connected(void *handle); +net_nfc_current_target_info_s *net_nfc_server_get_tag_info(); +void net_nfc_server_free_current_tag_info(); + +#endif + diff --git a/src/manager/include/net_nfc_service_llcp_handover_private.h b/src/manager/include/net_nfc_service_llcp_handover_private.h new file mode 100755 index 0000000..ed84c89 --- /dev/null +++ b/src/manager/include/net_nfc_service_llcp_handover_private.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#ifndef NET_NFC_SERVICE_LLCP_HANDOVER_PRVIATE_H_ +#define NET_NFC_SERVICE_LLCP_HANDOVER_PRVIATE_H_ + +#include "net_nfc_typedef_private.h" + +typedef struct _carrier_record +{ + ndef_record_s *record; + net_nfc_conn_handover_carrier_type_e type; + net_nfc_conn_handover_carrier_state_e state; +} carrier_record_s; + +net_nfc_error_e net_nfc_service_llcp_handover_send_request_msg(net_nfc_request_connection_handover_t *msg); + +bool net_nfc_service_llcp_connection_handover_selector(net_nfc_llcp_state_t *state, net_nfc_error_e *result); +bool net_nfc_service_llcp_connection_handover_requester(net_nfc_llcp_state_t *state, net_nfc_error_e *result); + +#endif /* NET_NFC_SERVICE_LLCP_HANDOVER_PRVIATE_H_ */ diff --git a/src/manager/include/net_nfc_service_llcp_private.h b/src/manager/include/net_nfc_service_llcp_private.h new file mode 100755 index 0000000..3125b32 --- /dev/null +++ b/src/manager/include/net_nfc_service_llcp_private.h @@ -0,0 +1,203 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#ifndef NET_NFC_SERVICE_LLCP_PRIVATE_H +#define NET_NFC_SERVICE_LLCP_PRIVATE_H + +#include "net_nfc_typedef_private.h" + +/* define */ +/* Service Name should be followed naming rule. */ +// service access name + +#define SDP_SAN "urn:nfc:sn:sdp" +#define IP_SAN "urn:nfc:sn:ip" +#define SNEP_SAN "urn:nfc:sn:snep" +#define OBEX_SAN "urn:nfc:sn:obex" + +#define CONN_HANDOVER_SAN "urn:nfc:sn:handover" + +#define NPP_SAN "com.android.npp" +#define NPP_SAP 0x10 + +#define SDP_SAP 1 /* service discovery protocol service access point */ +#define IP_SAP 2 /* Internet protocol service access point */ +#define OBEX_SAP 3 /* ojbect exchange service access point */ +#define SNEP_SAP 4 /* simple ndef exchange protocol service access point */ + +#define CONN_HANDOVER_SAP 5 /* connection handover service access point */ + +#define SNEP_MAJOR_VER 1 +#define SNEP_MINOR_VER 0 + + +#define NPP_MAJOR_VER 0 +#define NPP_MINOR_VER 1 + +#define NPP_NDEF_ENTRY 0x00000001 + +#define NPP_ACTION_CODE 0x01 + +#define SNEP_MAX_BUFFER 128 /* simple NDEF exchange protocol */ +#define CH_MAX_BUFFER 128 /* connection handover */ + +typedef enum{ + NPP_REQ_CONTINUE = 0x00, + NPP_REQ_REJECT, + NPP_RESP_CONT, + NPP_RESP_SUCCESS, + NPP_RESP_NOT_FOUND, + NPP_RESP_EXCESS_DATA, + NPP_RESP_BAD_REQ, + NPP_RESP_NOT_IMPLEMEN, + NPP_RESP_UNSUPPORTED_VER, + NPP_RESP_REJECT, +}npp_command_field_e; + +typedef enum{ + SNEP_REQ_CONTINUE = 0x00, + SNEP_REQ_GET = 0x01, + SNEP_REQ_PUT = 0x02, + SNEP_REQ_REJECT = 0x7F, + SNEP_RESP_CONT = 0x80, + SNEP_RESP_SUCCESS = 0x81, + SNEP_RESP_NOT_FOUND = 0xC0, + SNEP_RESP_EXCESS_DATA = 0xC1, + SNEP_RESP_BAD_REQ = 0xC2, + SNEP_RESP_NOT_IMPLEMENT = 0xE0, + SNEP_RESP_UNSUPPORTED_VER = 0xE1, + SNEP_RESP_REJECT = 0xFF, +}snep_command_field_e; + +/* static variable */ + +typedef enum { + NET_NFC_STATE_EXCHANGER_SERVER = 0x00, + NET_NFC_STATE_EXCHANGER_SERVER_NPP, + + NET_NFC_STATE_EXCHANGER_CLIENT, + NET_NFC_STATE_CONN_HANDOVER_REQUEST, + NET_NFC_STATE_CONN_HANDOVER_SELECT, +} llcp_state_e; + +typedef enum { + NET_NFC_LLCP_STEP_01 = 0xFFFF, + NET_NFC_LLCP_STEP_02, + NET_NFC_LLCP_STEP_03, + NET_NFC_LLCP_STEP_04, + NET_NFC_LLCP_STEP_05, + NET_NFC_LLCP_STEP_06, + NET_NFC_LLCP_STEP_07, + NET_NFC_LLCP_STEP_08, + NET_NFC_LLCP_STEP_09, + NET_NFC_LLCP_STEP_10, + NET_NFC_LLCP_STEP_11, + NET_NFC_LLCP_STEP_12, + NET_NFC_LLCP_STEP_13, + NET_NFC_LLCP_STEP_14, + NET_NFC_LLCP_STEP_15, + NET_NFC_LLCP_STEP_16, + NET_NFC_LLCP_STEP_17, + NET_NFC_LLCP_STEP_18, + NET_NFC_LLCP_STEP_19, + NET_NFC_LLCP_STEP_20, + NET_NFC_LLCP_STEP_RETURN, + NET_NFC_STATE_SOCKET_ERROR, + NET_NFC_STATE_ERROR, +} net_nfc_state_e; + +typedef struct _net_nfc_llcp_state_t{ + int client_fd; + unsigned int step; + unsigned int fragment_offset; + llcp_state_e state; + net_nfc_llcp_socket_t socket; + uint16_t max_capability; + net_nfc_target_handle_s * handle; + net_nfc_error_e prev_result; + net_nfc_llcp_socket_t incomming_socket; + ndef_message_s *requester; + ndef_message_s *selector; + bool low_power; + void * user_data; + void * payload; + + llcp_app_protocol_e type_app_protocol; + net_nfc_conn_handover_carrier_type_e type; + +} net_nfc_llcp_state_t; + + +typedef struct _net_nfc_llcp_npp_t{ + uint8_t npp_version; + uint32_t npp_ndef_entry; + uint8_t npp_action_code; + uint32_t npp_ndef_length; +} __attribute__((packed))net_nfc_llcp_npp_t; + +#define NET_NFC_COMMON_HANDOVER_CONTEXT unsigned int step;\ + net_nfc_llcp_state_t *llcp_state;\ + void *user_data;\ + net_nfc_error_e result;\ + net_nfc_conn_handover_carrier_type_e request_type;\ + void *data;\ + bool is_requester; + +typedef struct _net_nfc_handover_context_t +{ + NET_NFC_COMMON_HANDOVER_CONTEXT; +} +net_nfc_handover_context_t; + +typedef struct _net_nfc_handover_create_config_context_t +{ + NET_NFC_COMMON_HANDOVER_CONTEXT; + + net_nfc_conn_handover_carrier_type_e current_type; + ndef_message_s *ndef_message; + ndef_message_s *requester; /* for low power selector */ + bool is_low_power; +} +net_nfc_handover_create_config_context_t; + +typedef struct _net_nfc_handover_process_config_context_t +{ + NET_NFC_COMMON_HANDOVER_CONTEXT; + + net_nfc_carrier_config_s *config; +} +net_nfc_handover_process_config_context_t; + +bool net_nfc_service_llcp_process_accept(net_nfc_request_msg_t* msg); +bool net_nfc_service_llcp_terminate_connection(net_nfc_request_msg_t* msg); +bool net_nfc_service_llcp_disconnect_target(net_nfc_request_msg_t* msg); +bool net_nfc_service_llcp_process_socket_error(net_nfc_request_msg_t* msg); +bool net_nfc_service_llcp_process_accepted_socket_error(net_nfc_request_msg_t* msg); +bool net_nfc_service_llcp_process_send_to_socket(net_nfc_request_msg_t* msg); +bool net_nfc_service_llcp_process_send_socket(net_nfc_request_msg_t* msg); +bool net_nfc_service_llcp_process_receive_socket(net_nfc_request_msg_t* msg); +bool net_nfc_service_llcp_process_receive_from_socket(net_nfc_request_msg_t* msg); +bool net_nfc_service_llcp_process_connect_socket(net_nfc_request_msg_t* msg); +bool net_nfc_service_llcp_process_connect_sap_socket(net_nfc_request_msg_t* msg); +bool net_nfc_service_llcp_process_disconnect_socket(net_nfc_request_msg_t* msg); +net_nfc_error_e net_nfc_service_send_exchanger_msg(net_nfc_request_p2p_send_t* msg); +bool net_nfc_service_llcp_process(net_nfc_target_handle_s* handle, int devType, net_nfc_error_e* result); + +void net_nfc_service_llcp_remove_state (net_nfc_llcp_state_t * state); +void net_nfc_service_llcp_add_state (net_nfc_llcp_state_t * state); + +#endif diff --git a/src/manager/include/net_nfc_service_private.h b/src/manager/include/net_nfc_service_private.h new file mode 100644 index 0000000..628e7ff --- /dev/null +++ b/src/manager/include/net_nfc_service_private.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#ifndef NET_NFC_SERVICE_PRIVATE_H +#define NET_NFC_SERVICE_PRIVATE_H + +#include "net_nfc_typedef_private.h" + +bool net_nfc_service_slave_mode_target_detected(net_nfc_request_msg_t* msg); +#ifndef BROADCAST_MESSAGE +bool net_nfc_service_standalone_mode_target_detected(net_nfc_request_msg_t* msg); +#endif +bool net_nfc_service_termination (net_nfc_request_msg_t* msg); + +void net_nfc_service_target_detected_cb(void* info, void* user_context); +void net_nfc_service_se_transaction_cb(void* info, void* user_context); +void net_nfc_service_llcp_event_cb(void* info, void* user_context); + +void net_nfc_service_msg_processing(data_s* data); + +#endif diff --git a/src/manager/include/net_nfc_service_se_private.h b/src/manager/include/net_nfc_service_se_private.h new file mode 100755 index 0000000..3a39827 --- /dev/null +++ b/src/manager/include/net_nfc_service_se_private.h @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef NET_NFC_SERVICE_SE_PRIVATE_H +#define NET_NFC_SERVICE_SE_PRIVATE_H + +#include "net_nfc_typedef_private.h" + +typedef struct _se_setting_t +{ + net_nfc_target_handle_s *current_ese_handle; + void *open_request_trans_param; + uint8_t type; + uint8_t mode; +} +net_nfc_se_setting_t; + +net_nfc_se_setting_t *net_nfc_service_se_get_se_setting(); +net_nfc_target_handle_s *net_nfc_service_se_get_current_ese_handle(); +void net_nfc_service_se_set_current_ese_handle(net_nfc_target_handle_s *handle); +uint8_t net_nfc_service_se_get_se_type(); +void net_nfc_service_se_set_se_type(uint8_t type); +uint8_t net_nfc_service_se_get_se_mode(); +void net_nfc_service_se_set_se_mode(uint8_t mode); + +net_nfc_error_e net_nfc_service_se_change_se(uint8_t type); + +void net_nfc_service_se_detected(net_nfc_request_msg_t *req_msg); +net_nfc_error_e net_nfc_service_se_close_ese(); + +/* TAPI SIM API */ + +bool net_nfc_service_tapi_init(void); +void net_nfc_service_tapi_deinit(void); +bool net_nfc_service_transfer_apdu(int client_fd, data_s *apdu, void *trans_param); +bool net_nfc_service_request_atr(int client_fd, void *trans_param); +bool net_nfc_service_se_transaction_receive(net_nfc_request_msg_t* msg); + +#endif diff --git a/src/manager/include/net_nfc_service_tag_private.h b/src/manager/include/net_nfc_service_tag_private.h new file mode 100755 index 0000000..aa23369 --- /dev/null +++ b/src/manager/include/net_nfc_service_tag_private.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#ifndef NET_NFC_SERVICE_TAG_PRIVATE_H +#define NET_NFC_SERVICE_TAG_PRIVATE_H + +#include "net_nfc_typedef_private.h" + +data_s* net_nfc_service_tag_process(net_nfc_target_handle_s* handle, int devType, net_nfc_error_e* result); +void net_nfc_service_clean_tag_context(net_nfc_request_target_detected_t* stand_alone, net_nfc_error_e result); +void net_nfc_service_watch_dog(net_nfc_request_msg_t* req_msg); + +#endif diff --git a/src/manager/include/net_nfc_service_vconf_private.h b/src/manager/include/net_nfc_service_vconf_private.h new file mode 100755 index 0000000..151e560 --- /dev/null +++ b/src/manager/include/net_nfc_service_vconf_private.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#ifndef NET_NFC_SERVICE_VCONF_H +#define NET_NFC_SERVICE_VCONF_H + +void net_nfc_service_vconf_register_notify_listener(); +void net_nfc_service_vconf_unregister_notify_listener(); +bool _net_nfc_check_pprom_is_completed (); +void _net_nfc_set_pprom_is_completed (); + + +#endif diff --git a/src/manager/include/net_nfc_util_access_control_private.h b/src/manager/include/net_nfc_util_access_control_private.h new file mode 100644 index 0000000..54845ca --- /dev/null +++ b/src/manager/include/net_nfc_util_access_control_private.h @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#ifndef NET_NFC_UTIL_ACCESS_CONTROL_PRIVATE_H +#define NET_NFC_UTIL_ACCESS_CONTROL_PRIVATE_H + +#include "net_nfc_typedef_private.h" + +bool net_nfc_util_access_control_is_initialized(void); +void net_nfc_util_access_control_initialize(void); +void net_nfc_util_access_control_update_list(void); +bool net_nfc_util_access_control_is_authorized_package(const char* pkg_name, uint8_t *aid, uint32_t length); +void net_nfc_util_access_control_release(void); + +#endif diff --git a/src/manager/net_nfc_app_util.c b/src/manager/net_nfc_app_util.c new file mode 100644 index 0000000..7610e7b --- /dev/null +++ b/src/manager/net_nfc_app_util.c @@ -0,0 +1,950 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "appsvc.h" +#include "aul.h" +#include "vconf.h" + +#include "net_nfc_typedef.h" +#include "net_nfc_typedef_private.h" +#include "net_nfc_debug_private.h" +#include "net_nfc_util_defines.h" +#include "net_nfc_util_private.h" +#include "net_nfc_util_ndef_message.h" +#include "net_nfc_util_ndef_record.h" +#include "net_nfc_manager_util_private.h" +#include "net_nfc_app_util_private.h" +#include "net_nfc_util_access_control_private.h" +//#include "syspopup_caller.h" + +static bool _net_nfc_app_util_get_operation_from_record(ndef_record_s *record, char *operation, size_t length); +static bool _net_nfc_app_util_get_mime_from_record(ndef_record_s *record, char *mime, size_t length); +#ifdef USE_FULL_URI +static bool _net_nfc_app_util_get_uri_from_record(ndef_record_s *record, char *uri, size_t length); +#endif +static bool _net_nfc_app_util_get_data_from_record(ndef_record_s *record, char *data, size_t length); + +static const char *sbeam_mime_type[] = +{ + "text/DirectShareGallery", + "text/DirectShareMusic", + "text/DirectShareVideos", + "text/DirectShareFile", + "text/DirectSharePolarisViewer", + "text/DirectSharePolarisEditor", + "text/DirectShareDefault", + "text/DirectShareError", + NULL +}; + +net_nfc_error_e net_nfc_app_util_process_ndef(data_s *data) +{ + net_nfc_error_e result = NET_NFC_UNKNOWN_ERROR; + ndef_message_s *msg = NULL; + char operation[2048] = { 0, }; + char mime[2048] = { 0, }; + char text[2048] = { 0, }; +#ifdef USE_FULL_URI + char uri[2048] = { 0, }; +#endif + int ret = 0; + int disable = 0; + + if (data == NULL || data->buffer == NULL || data->length == 0) + { + DEBUG_ERR_MSG("net_nfc_app_util_process_ndef NET_NFC_NULL_PARAMETER"); + return NET_NFC_NULL_PARAMETER; + } + + /* create file */ + if ((result = net_nfc_app_util_store_ndef_message(data)) != NET_NFC_OK) + { + DEBUG_ERR_MSG("net_nfc_app_util_store_ndef_message failed [%d]", result); + return result; + } + + /* check state of launch popup */ + if (vconf_get_bool(NET_NFC_DISABLE_LAUNCH_POPUP_KEY, &disable) == 0 && disable == FALSE) + { + DEBUG_SERVER_MSG("skip launch popup!!!"); + result = NET_NFC_OK; + return result; + } + + if (net_nfc_util_create_ndef_message(&msg) != NET_NFC_OK) + { + DEBUG_ERR_MSG("memory alloc fail.."); + return NET_NFC_ALLOC_FAIL; + } + + /* parse ndef message and fill appsvc data */ + if ((result = net_nfc_util_convert_rawdata_to_ndef_message(data, msg)) != NET_NFC_OK) + { + DEBUG_ERR_MSG("net_nfc_app_util_store_ndef_message failed [%d]", result); + goto ERROR; + } + + if (_net_nfc_app_util_get_operation_from_record(msg->records, operation, sizeof(operation)) == FALSE) + { + DEBUG_ERR_MSG("_net_nfc_app_util_get_operation_from_record failed [%d]", result); + result = NET_NFC_UNKNOWN_ERROR; + goto ERROR; + } + + if (_net_nfc_app_util_get_mime_from_record(msg->records, mime, sizeof(mime)) == FALSE) + { + DEBUG_ERR_MSG("_net_nfc_app_util_get_mime_from_record failed [%d]", result); + result = NET_NFC_UNKNOWN_ERROR; + goto ERROR; + } +#ifdef USE_FULL_URI + if (_net_nfc_app_util_get_uri_from_record(msg->records, uri, sizeof(uri)) == FALSE) + { + DEBUG_ERR_MSG("_net_nfc_app_util_get_uri_from_record failed [%d]", result); + result = NET_NFC_UNKNOWN_ERROR; + goto ERROR; + } +#endif + /* launch appsvc */ + if (_net_nfc_app_util_get_data_from_record(msg->records, text, sizeof(text)) == FALSE) + { + DEBUG_ERR_MSG("_net_nfc_app_util_get_data_from_record failed [%d]", result); + result = NET_NFC_UNKNOWN_ERROR; + goto ERROR; + } + + ret = net_nfc_app_util_appsvc_launch(operation, uri, mime, text); +#if 0 + if (ret == APPSVC_RET_ENOMATCH) + { + /* TODO : check again */ + ret = net_nfc_app_util_appsvc_launch(operation, uri, mime, text); + } +#endif + + DEBUG_SERVER_MSG("net_nfc_app_util_appsvc_launch return %d", ret); + + result = NET_NFC_OK; + +ERROR : + net_nfc_util_free_ndef_message(msg); + + return result; +} + +bool _net_nfc_app_util_change_file_owner_permission(FILE *file) +{ + char *buffer = NULL; + size_t buffer_len = 0; + struct passwd pwd = { 0, }; + struct passwd *pw_inhouse = NULL; + struct group grp = { 0, }; + struct group *gr_inhouse = NULL; + + if (file == NULL) + return false; + + /* change permission */ + fchmod(fileno(file), 0777); + + /* change owner */ + /* get passwd id */ + buffer_len = sysconf(_SC_GETPW_R_SIZE_MAX); + if (buffer_len == -1) + { + buffer_len = 16384; + } + + _net_nfc_util_alloc_mem(buffer, buffer_len); + if (buffer == NULL) + return false; + + getpwnam_r("inhouse", &pwd, buffer, buffer_len, &pw_inhouse); + _net_nfc_util_free_mem(buffer); + + /* get group id */ + buffer_len = sysconf(_SC_GETGR_R_SIZE_MAX); + if (buffer_len == -1) + { + buffer_len = 16384; + } + + _net_nfc_util_alloc_mem(buffer, buffer_len); + if (buffer == NULL) + return false; + + getgrnam_r("inhouse", &grp, buffer, buffer_len, &gr_inhouse); + _net_nfc_util_free_mem(buffer); + + if ((pw_inhouse != NULL) && (gr_inhouse != NULL)) + { + if (fchown(fileno(file), pw_inhouse->pw_uid, gr_inhouse->gr_gid) < 0) + { + DEBUG_ERR_MSG("failed to change owner"); + } + } + + return true; +} + +net_nfc_error_e net_nfc_app_util_store_ndef_message(data_s *data) +{ + net_nfc_error_e result = NET_NFC_UNKNOWN_ERROR; + char file_name[1024] = { 0, }; + struct stat st; + FILE *fp = NULL; + + if (data == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + /* check and make directory */ + snprintf(file_name, sizeof(file_name), "%s/%s", NET_NFC_MANAGER_DATA_PATH, + NET_NFC_MANAGER_DATA_PATH_MESSAGE); + + if (stat(file_name, &st) == -1) + { + int result; + char command[1024]; + + DEBUG_SERVER_MSG("path doesn't exist, do mkdir : %s", file_name); + + snprintf(command, sizeof(command), "mkdir -p -m 755 %s", file_name); + + result = system(command); + + if (stat(file_name, &st) == -1) + { + DEBUG_ERR_MSG("mkdir failed"); + return NET_NFC_UNKNOWN_ERROR; + } + } + + /* create file */ + snprintf(file_name, sizeof(file_name), "%s/%s/%s", NET_NFC_MANAGER_DATA_PATH, + NET_NFC_MANAGER_DATA_PATH_MESSAGE, NET_NFC_MANAGER_NDEF_FILE_NAME); + DEBUG_SERVER_MSG("file path : %s", file_name); + + unlink(file_name); + + if ((fp = fopen(file_name, "w")) != NULL) + { + int length = 0; + + if ((length = fwrite(data->buffer, 1, data->length, fp)) > 0) + { + DEBUG_SERVER_MSG("[%d] bytes is written", length); + + _net_nfc_app_util_change_file_owner_permission(fp); + + fflush(fp); + fsync(fileno(fp)); + + result = NET_NFC_OK; + } + else + { + DEBUG_ERR_MSG("write is failed = [%d]", data->length); + result = NET_NFC_UNKNOWN_ERROR; + } + + fclose(fp); + } + + return result; +} + +bool net_nfc_app_util_is_dir(const char* path_name) +{ + struct stat statbuf = { 0 }; + + if (stat(path_name, &statbuf) == -1) + { + return false; + } + + if (S_ISDIR(statbuf.st_mode) != 0) + { + return true; + } + else + { + return false; + } +} + +void net_nfc_app_util_clean_storage(char* src_path) +{ + struct dirent* ent = NULL; + DIR* dir = NULL; + + char path[1024] = { 0 }; + + if ((dir = opendir(src_path)) == NULL) + { + return; + } + + while ((ent = readdir(dir)) != NULL) + { + if (strncmp(ent->d_name, ".", 1) == 0 || strncmp(ent->d_name, "..", 2) == 0) + { + continue; + } + else + { + snprintf(path, 1024, "%s/%s", src_path, ent->d_name); + + if (net_nfc_app_util_is_dir(path) != false) + { + net_nfc_app_util_clean_storage(path); + rmdir(path); + } + else + { + unlink(path); + } + } + } + + closedir(dir); + + rmdir(src_path); +} + +static bool __check_is_sbeam_record(ndef_record_s *record) +{ + data_s *type_s = &record->type_s; + int index = 0; + + if (type_s->buffer == NULL || type_s->length == 0) + { + return FALSE; + } + + DEBUG_SERVER_MSG("mime : %s", type_s->buffer); + + while (sbeam_mime_type[index] != NULL) + { + if (strncasecmp((char *)type_s->buffer, sbeam_mime_type[index], + MIN(type_s->length, strlen(sbeam_mime_type[index]))) == 0) + { + return TRUE; + } + index++; + } + + return FALSE; +} + +static void _to_lower_utf_8(char *str) +{ + while (*str != 0) + { + if (*str >= 'A' && *str <= 'Z') + *str += ('a' - 'A'); + + str++; + } +} + +static void _to_lower(int type, char *str) +{ + _to_lower_utf_8(str); +} + +static bool _net_nfc_app_util_get_operation_from_record(ndef_record_s *record, char *operation, size_t length) +{ + bool result = false; + char *op_text = NULL; + + if (record == NULL || operation == NULL || length == 0) + { + return result; + } + + switch (record->TNF) + { + case NET_NFC_RECORD_WELL_KNOWN_TYPE : + op_text = "http://tizen.org/appcontrol/operation/nfc/wellknown"; + break; + + case NET_NFC_RECORD_MIME_TYPE : + { + if (__check_is_sbeam_record(record)) + op_text = "http://tizen.org/appcontrol/operation/nfc_sbeam_receive"; + else + op_text = "http://tizen.org/appcontrol/operation/nfc/mime"; + } + break; + + case NET_NFC_RECORD_URI : /* Absolute URI */ + op_text = "http://tizen.org/appcontrol/operation/nfc/uri"; + break; + + case NET_NFC_RECORD_EXTERNAL_RTD : /* external type */ + op_text = "http://tizen.org/appcontrol/operation/nfc/external"; + break; + + case NET_NFC_RECORD_EMPTY : /* empty_tag */ + op_text = "http://tizen.org/appcontrol/operation/nfc/empty"; + break; + + case NET_NFC_RECORD_UNKNOWN : /* unknown msg. discard it */ + case NET_NFC_RECORD_UNCHAGNED : /* RFU msg. discard it */ + default : + break; + } + + if (op_text != NULL) + { + snprintf(operation, length, "%s", op_text); + result = TRUE; + } + + return result; +} + +static bool _net_nfc_app_util_get_mime_from_record(ndef_record_s *record, char *mime, size_t length) +{ + bool result = false; + + if (record == NULL || mime == NULL || length == 0) + { + return result; + } + + switch (record->TNF) + { + case NET_NFC_RECORD_WELL_KNOWN_TYPE : + { + if (record->type_s.buffer == NULL || record->type_s.length == 0 || + record->payload_s.buffer == NULL || record->payload_s.length == 0) + { + DEBUG_ERR_MSG("Broken NDEF Message [NET_NFC_RECORD_WELL_KNOWN_TYPE]"); + break; + } + + if (record->type_s.length == 1 && record->type_s.buffer[0] == 'U') + { + snprintf(mime, length, "U/0x%02x", record->payload_s.buffer[0]); + } + else + { + memcpy(mime, record->type_s.buffer, record->type_s.length); + mime[record->type_s.length] = '\0'; + + strncat(mime, "/*", 2); + mime[record->type_s.length + 2] = '\0'; + } + + //DEBUG_SERVER_MSG("mime [%s]", mime); + + result = true; + } + break; + + case NET_NFC_RECORD_MIME_TYPE : + { + char *token = NULL; + char *buffer = NULL; + int len = 0; + + if (record->type_s.buffer == NULL || record->type_s.length == 0) + { + DEBUG_ERR_MSG("Broken NDEF Message [NET_NFC_RECORD_MIME_TYPE]"); + break; + } + + /* get mime type */ + _net_nfc_util_alloc_mem(buffer, record->type_s.length + 1); + if (buffer == NULL) + { + DEBUG_ERR_MSG("_net_nfc_manager_util_alloc_mem return NULL"); + break; + } + memcpy(buffer, record->type_s.buffer, record->type_s.length); + + //DEBUG_SERVER_MSG("NET_NFC_RECORD_MIME_TYPE type [%s]", buffer); + + token = strchr(buffer, ';'); + if (token != NULL) + { + //DEBUG_SERVER_MSG("token = strchr(buffer, ';') != NULL, len [%d]", token - buffer); + len = MIN(token - buffer, length - 1); + } + else + { + len = MIN(strlen(buffer), length - 1); + } + + //DEBUG_SERVER_MSG("len [%d]", len); + + strncpy(mime, buffer, len); + mime[len] = '\0'; + + _to_lower(0, mime); + + //DEBUG_SERVER_MSG("mime [%s]", mime); + + _net_nfc_util_free_mem(buffer); + + result = true; + } + break; + + case NET_NFC_RECORD_URI : /* Absolute URI */ + case NET_NFC_RECORD_EXTERNAL_RTD : /* external type */ + case NET_NFC_RECORD_EMPTY : /* empty_tag */ + result = true; + break; + + case NET_NFC_RECORD_UNKNOWN : /* unknown msg. discard it */ + case NET_NFC_RECORD_UNCHAGNED : /* RFU msg. discard it */ + default : + break; + } + + return result; +} + +#ifdef USE_FULL_URI +static bool _net_nfc_app_util_get_uri_from_record(ndef_record_s *record, char *data, size_t length) +{ + bool result = false; + + if (record == NULL || data == NULL || length == 0) + { + return result; + } + + switch (record->TNF) + { + case NET_NFC_RECORD_WELL_KNOWN_TYPE : + case NET_NFC_RECORD_URI : /* Absolute URI */ + { + char *uri = NULL; + + if (net_nfc_util_create_uri_string_from_uri_record(record, &uri) == NET_NFC_OK && + uri != NULL) + { + //DEBUG_SERVER_MSG("uri record : %s", uri); + snprintf(data, length, "%s", uri); + + _net_nfc_util_free_mem(uri); + } + result = true; + } + break; + + case NET_NFC_RECORD_EXTERNAL_RTD : /* external type */ + { + data_s *type = &record->type_s; + + if (type->length > 0) + { +#if 0 + char *buffer = NULL; + int len = strlen(NET_NFC_UTIL_EXTERNAL_TYPE_SCHEME); + + _net_nfc_util_alloc_mem(buffer, type->length + len + 1); + if (buffer != NULL) + { + memcpy(buffer, NET_NFC_UTIL_EXTERNAL_TYPE_SCHEME, len); + memcpy(buffer + len, type->buffer, type->length); + + /* to lower case!! */ + strlwr(buffer); + + DEBUG_SERVER_MSG("uri record : %s", buffer); + snprintf(data, length, "%s", buffer); + + _net_nfc_util_free_mem(buffer); + } +#else + int len = MIN(type->length, length - 1); + memcpy(data, type->buffer, len); + data[len] = 0; + + /* to lower case!! */ + _to_lower(0, data); + + //DEBUG_SERVER_MSG("uri record : %s", data); + result = true; +#endif + } + } + break; + + case NET_NFC_RECORD_MIME_TYPE : + case NET_NFC_RECORD_EMPTY : /* empy msg. discard it */ + result = true; + break; + + case NET_NFC_RECORD_UNKNOWN : /* unknown msg. discard it */ + case NET_NFC_RECORD_UNCHAGNED : /* RFU msg. discard it */ + default : + break; + } + + return result; +} +#endif + +static bool _net_nfc_app_util_get_data_from_record(ndef_record_s *record, char *data, size_t length) +{ + bool result = false; + + if (record == NULL || data == NULL || length == 0) + { + return result; + } + + switch (record->TNF) + { + case NET_NFC_RECORD_WELL_KNOWN_TYPE : + { + if (record->type_s.buffer == NULL || record->type_s.length == 0 + || record->payload_s.buffer == NULL || record->payload_s.length == 0) + { + DEBUG_ERR_MSG("Broken NDEF Message [NET_NFC_RECORD_WELL_KNOWN_TYPE]"); + break; + } + + if (record->type_s.length == 1 && record->type_s.buffer[0] == 'T') + { + uint8_t *buffer_temp = record->payload_s.buffer; + uint32_t buffer_length = record->payload_s.length; + + int index = (buffer_temp[0] & 0x3F) + 1; + int text_length = buffer_length - index; + + memcpy(data, &(buffer_temp[index]), MIN(text_length, length)); + } + + //DEBUG_SERVER_MSG("data [%s]", data); + + result = true; + } + break; + + case NET_NFC_RECORD_MIME_TYPE : + case NET_NFC_RECORD_URI : /* Absolute URI */ + case NET_NFC_RECORD_EXTERNAL_RTD : /* external type */ + case NET_NFC_RECORD_EMPTY : /* empy msg. discard it */ + result = true; + break; + + case NET_NFC_RECORD_UNKNOWN : /* unknown msg. discard it */ + case NET_NFC_RECORD_UNCHAGNED : /* RFU msg. discard it */ + default : + break; + } + + return result; +} + +void net_nfc_app_util_aul_launch_app(char* package_name, bundle* kb) +{ + int result = 0; + if((result = aul_launch_app(package_name, kb)) < 0) + { + switch(result) + { + case AUL_R_EINVAL: + DEBUG_SERVER_MSG("aul launch error : AUL_R_EINVAL"); + break; + case AUL_R_ECOMM: + DEBUG_SERVER_MSG("aul launch error : AUL_R_ECOM"); + break; + case AUL_R_ERROR: + DEBUG_SERVER_MSG("aul launch error : AUL_R_ERROR"); + break; + default: + DEBUG_SERVER_MSG("aul launch error : unknown ERROR"); + break; + } + } + else + { + DEBUG_SERVER_MSG("success to launch [%s]", package_name); + } +} + +int net_nfc_app_util_appsvc_launch(const char *operation, const char *uri, const char *mime, const char *data) +{ + int result = -1; + + bundle *bd = NULL; + + bd = bundle_create(); + if (bd == NULL) + return result; + + if (operation != NULL && strlen(operation) > 0) + { + DEBUG_SERVER_MSG("operation : %s", operation); + appsvc_set_operation(bd, operation); + } + + if (uri != NULL && strlen(uri) > 0) + { + DEBUG_SERVER_MSG("uri : %s", uri); + appsvc_set_uri(bd, uri); + } + + if (mime != NULL && strlen(mime) > 0) + { + DEBUG_SERVER_MSG("mime : %s", mime); + appsvc_set_mime(bd, mime); + } + + if (data != NULL && strlen(data) > 0) + { + DEBUG_SERVER_MSG("data : %s", data); + appsvc_add_data(bd, "data", data); + } + + result = appsvc_run_service(bd, 0, NULL, NULL); + + bundle_free(bd); + + return result; +} + +void _binary_to_string(uint8_t *buffer, uint32_t len, char *out_buf, uint32_t max_len) +{ + int current = 0; + + if (buffer == NULL || len == 0 || out_buf == NULL || max_len == 0) + return; + + while (len > 0 && current < max_len) + { + current += snprintf(out_buf + current, max_len - current, "%02X", *(buffer++)); + len--; + } +} + +void _string_to_binary(const char *input, uint8_t *output, uint32_t *length) +{ + int current = 0; + int temp; + + if (input == NULL || *length == 0 || output == NULL) + return; + + DEBUG_SERVER_MSG("_string_to_binary "); + + /* strlen("nfc://secure/aid/") = 17 */ + + input += 17; + + while (*input && (current < *length)) + { + temp = (*input++) - '0'; + + if(temp > 9) + temp -= 7; + + if(current % 2) + { + output[current / 2] += temp; + } + else + { + output[current / 2] = temp << 4; + } + + current++; + } + + *length = current / 2; +} + +static int _pkglist_iter_fn(const char* pkg_name, void *data) +{ + int result = 0; + const char *aid_string = NULL; + uint8_t aid[1024] = { 0, }; + uint32_t length = sizeof(aid); + + aid_string = appsvc_get_uri((bundle *)data); + DEBUG_SERVER_MSG("package name : %s, aid_string : %s", pkg_name, aid_string); + + /* convert aid string to aid */ + _string_to_binary(aid_string, aid, &length); + + if (net_nfc_util_access_control_is_authorized_package(pkg_name, aid, length) == true) + { + DEBUG_SERVER_MSG("allowed package : %s", pkg_name); + + /* launch */ + aul_launch_app(pkg_name, NULL); + + result = 1; /* break iterator */ + } + else + { + DEBUG_SERVER_MSG("not allowed package : %s", pkg_name); + } + + return result; +} + +gboolean _invoke_get_list(gpointer data) +{ + bundle *bd = (bundle *)data; + + appsvc_get_list(bd, _pkglist_iter_fn, (bundle *)bd); + + bundle_free(bd); + + return 0; +} + +int net_nfc_app_util_launch_se_transaction_app(uint8_t *aid, uint32_t aid_len, uint8_t *param, uint32_t param_len) +{ + bundle *bd = NULL; + +#if 0 + /* initialize and make list */ + if (net_nfc_util_access_control_is_initialized() == false) + { + net_nfc_util_access_control_initialize(); + } +#endif + + net_nfc_util_access_control_update_list(); + + /* launch */ + bd = bundle_create(); + + appsvc_set_operation(bd, "http://tizen.org/appcontrol/operation/nfc_se_transaction"); + + /* convert aid to aid string */ + if (aid != NULL && aid_len > 0) + { + char temp_string[1024] = { 0, }; + char aid_string[1024] = { 0, }; + + _binary_to_string(aid, aid_len, temp_string, sizeof(temp_string)); + snprintf(aid_string, sizeof(aid_string), "nfc://secure/aid/%s", temp_string); + DEBUG_SERVER_MSG("aid_string : %s", aid_string); + appsvc_set_uri(bd, aid_string); + } + + if (param != NULL && param_len > 0) + { + char param_string[1024] = { 0, }; + + _binary_to_string(param, param_len, param_string, sizeof(param_string)); + DEBUG_SERVER_MSG("param_string : %s", param_string); + appsvc_add_data(bd, "data", param_string); + } + + appsvc_get_list(bd, _pkglist_iter_fn, (bundle *)bd); + + bundle_free(bd); + + return 0; +} + +int net_nfc_app_util_encode_base64(uint8_t *buffer, uint32_t buf_len, char *result, uint32_t max_result) +{ + int ret = -1; + BUF_MEM *bptr; + BIO *b64, *bmem; + + if (buffer == NULL || buf_len == 0 || result == NULL || max_result == 0) + return ret; + + /* base 64 */ + b64 = BIO_new(BIO_f_base64()); + BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL); + bmem = BIO_new(BIO_s_mem()); + b64 = BIO_push(b64, bmem); + + BIO_write(b64, buffer, buf_len); + BIO_flush(b64); + BIO_get_mem_ptr(b64, &bptr); + + memset(result, 0, max_result); + memcpy(result, bptr->data, MIN(bptr->length, max_result - 1)); + + BIO_free_all(b64); + + ret = 0; + + return ret; +} + +int net_nfc_app_util_decode_base64(const char *buffer, uint32_t buf_len, uint8_t *result, uint32_t *res_len) +{ + int ret = -1; + char *temp = NULL; + + if (buffer == NULL || buf_len == 0 || result == NULL || res_len == NULL || *res_len == 0) + return ret; + + _net_nfc_util_alloc_mem(temp, buf_len); + if (temp != NULL) + { + BIO *b64, *bmem; + uint32_t temp_len; + + b64 = BIO_new(BIO_f_base64()); + BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL); + bmem = BIO_new_mem_buf((void *)buffer, buf_len); + bmem = BIO_push(b64, bmem); + + temp_len = BIO_read(bmem, temp, buf_len); + + BIO_free_all(bmem); + + memset(result, 0, *res_len); + memcpy(result, temp, MIN(temp_len, *res_len)); + + *res_len = MIN(temp_len, *res_len); + + _net_nfc_util_free_mem(temp); + + ret = 0; + } + else + { + DEBUG_ERR_MSG("alloc failed"); + } + + return ret; +} diff --git a/src/manager/net_nfc_controller.c b/src/manager/net_nfc_controller.c new file mode 100755 index 0000000..e314684 --- /dev/null +++ b/src/manager/net_nfc_controller.c @@ -0,0 +1,797 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +#include /*for pm lock*/ + +#include "net_nfc_oem_controller.h" +#include "net_nfc_controller_private.h" +#include "net_nfc_util_private.h" +#include "net_nfc_debug_private.h" +#include "net_nfc_server_ipc_private.h" +#include "net_nfc_server_dispatcher_private.h" + +#define NET_NFC_OEM_LIBRARY_PATH "/usr/lib/libnfc-plugin.so" + +static net_nfc_oem_interface_s g_interface; + +void *net_nfc_controller_onload() +{ + void* handle = NULL; + bool (*onload)(net_nfc_oem_interface_s *interfaces); + + FILE *fp; + char cpuinfo_buffer[1024] = { 0, }; + size_t bytes_read; + char *match_revision; + int revision; + char *token; + char *token_cpuinfo[10]; + int i = 0; + const char *library_path; + + fp = fopen("/proc/cpuinfo", "r"); + bytes_read = fread(cpuinfo_buffer, 1, sizeof(cpuinfo_buffer) - 1, fp);/* Read the cpuinfo to bytes_read */ + fclose(fp); + + match_revision = strstr(cpuinfo_buffer, "Hardware"); + if (match_revision != NULL) + { + token = strtok(match_revision, " :\n"); + + while (token != NULL && i < 5) + { + i++; + DEBUG_SERVER_MSG("token = %s", token); + + token = strtok(NULL, " :\n"); + + token_cpuinfo[i] = token; + DEBUG_SERVER_MSG("temp[%d]'s value = %s", i, token_cpuinfo[i]); + } + + revision = strtol(token_cpuinfo[3], 0, 16); + DEBUG_SERVER_MSG("revision = %d", revision); + + if ((!(strncmp(token_cpuinfo[1], "SLP_PQ", 6)) && (revision >= 7))) //|| !(strncmp(token_cpuinfo[1] , "REDWOOD" , 7))) + { + DEBUG_SERVER_MSG("It's SLP_PQ && Revision 7!! || REDWOOD revC."); + library_path = "/usr/lib/libnfc-plugin-65nxp.so"; + + } + else if (!(strncmp(token_cpuinfo[1], "REDWOOD", 7))) + { + DEBUG_SERVER_MSG("It's REDWOOD revC."); + library_path = "/usr/lib/libnfc-plugin-lsi.so"; + } + else + { + DEBUG_SERVER_MSG("It's NOT!!!! SLP_PQ && Revision 7!!"); + library_path = "/usr/lib/libnfc-plugin.so"; + } + } + else + { + DEBUG_SERVER_MSG("It doesn't have Hardware info!!"); + library_path = "/usr/lib/libnfc-plugin.so"; + } + + if ((handle = dlopen(library_path/*NET_NFC_OEM_LIBRARY_PATH*/, RTLD_LAZY)) != NULL) + { + if ((onload = dlsym(handle, "onload")) != NULL) + { + if (onload(&g_interface) == true) + { + DEBUG_SERVER_MSG("success to load library"); + return handle; + } + else + { + DEBUG_ERR_MSG("failed to load library"); + } + } + else + { + DEBUG_ERR_MSG("can not find symbol onload"); + } + + dlclose(handle); + handle = NULL; + } + else + { + DEBUG_ERR_MSG("dlopen is failed"); + } + + return handle; +} + +bool net_nfc_controller_unload(void* handle) +{ + memset(&g_interface, 0x00, sizeof(net_nfc_oem_interface_s)); + + if (handle != NULL) + { + dlclose(handle); + handle = NULL; + } + return true; +} + +bool net_nfc_controller_init(net_nfc_error_e* result) +{ + if (g_interface.init != NULL) + { + return g_interface.init(result); + } + else + { + *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC; + DEBUG_SERVER_MSG("interface is null"); + return false; + } +} + +bool net_nfc_controller_deinit(void) +{ + if (g_interface.deinit != NULL) + { + return g_interface.deinit(); + } + else + { + DEBUG_SERVER_MSG("interface is null"); + return false; + } +} + +bool net_nfc_controller_register_listener(target_detection_listener_cb target_detection_listener, + se_transaction_listener_cb se_transaction_listener, llcp_event_listener_cb llcp_event_listener, net_nfc_error_e* result) +{ + if (g_interface.register_listener != NULL) + { + return g_interface.register_listener(target_detection_listener, se_transaction_listener, llcp_event_listener, result); + } + else + { + *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC; + DEBUG_SERVER_MSG("interface is null"); + return false; + } +} + +bool net_nfc_controller_unregister_listener() +{ + if (g_interface.unregister_listener != NULL) + { + return g_interface.unregister_listener(); + } + else + { + DEBUG_SERVER_MSG("interface is null"); + return false; + } +} + +bool net_nfc_controller_get_firmware_version(data_s **data, net_nfc_error_e *result) +{ + if (g_interface.get_firmware_version != NULL) + { + return g_interface.get_firmware_version(data, result); + } + else + { + *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC; + DEBUG_SERVER_MSG("interface is null"); + return false; + } +} + +bool net_nfc_controller_check_firmware_version(net_nfc_error_e* result) +{ + if (g_interface.check_firmware_version != NULL) + { + return g_interface.check_firmware_version(result); + } + else + { + *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC; + DEBUG_SERVER_MSG("interface is null"); + return false; + } +} + +bool net_nfc_controller_update_firmware(net_nfc_error_e* result) +{ + if (g_interface.update_firmeware != NULL) + { + return g_interface.update_firmeware(result); + } + else + { + *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC; + DEBUG_SERVER_MSG("interface is null"); + return false; + } +} + +bool net_nfc_controller_get_stack_information(net_nfc_stack_information_s* stack_info, net_nfc_error_e* result) +{ + if (g_interface.get_stack_information != NULL) + { + return g_interface.get_stack_information(stack_info, result); + } + else + { + *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC; + DEBUG_SERVER_MSG("interface is null"); + return false; + } +} + +bool net_nfc_controller_confiure_discovery(net_nfc_discovery_mode_e mode, net_nfc_event_filter_e config, net_nfc_error_e* result) +{ + if (g_interface.configure_discovery != NULL) + { + return g_interface.configure_discovery(mode, config, result); + } + else + { + *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC; + DEBUG_SERVER_MSG("interface is null"); + return false; + } +} + +bool net_nfc_controller_get_secure_element_list(net_nfc_secure_element_info_s* list, int* count, net_nfc_error_e* result) +{ + if (g_interface.get_secure_element_list != NULL) + { + return g_interface.get_secure_element_list(list, count, result); + } + else + { + *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC; + DEBUG_SERVER_MSG("interface is null"); + return false; + } +} + +bool net_nfc_controller_set_secure_element_mode(net_nfc_secure_element_type_e element_type, net_nfc_secure_element_mode_e mode, net_nfc_error_e* result) +{ + if (g_interface.set_secure_element_mode != NULL) + { + return g_interface.set_secure_element_mode(element_type, mode, result); + } + else + { + *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC; + DEBUG_SERVER_MSG("interface is null"); + return false; + } +} + +bool net_nfc_controller_check_target_presence(net_nfc_target_handle_s* handle, net_nfc_error_e* result) +{ + if (g_interface.check_presence != NULL) + { + return g_interface.check_presence(handle, result); + } + else + { + *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC; + DEBUG_SERVER_MSG("interface is null"); + return false; + } +} + +bool net_nfc_controller_connect(net_nfc_target_handle_s* handle, net_nfc_error_e* result) +{ + int ret_val = 0; + + ret_val = pm_lock_state(LCD_NORMAL, GOTO_STATE_NOW, 0); + + DEBUG_SERVER_MSG("net_nfc_controller_connect pm_lock_state [%d]!!", ret_val); + + if (g_interface.connect != NULL) + { + return g_interface.connect(handle, result); + } + else + { + *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC; + DEBUG_SERVER_MSG("interface is null"); + return false; + } +} + +bool net_nfc_controller_disconnect(net_nfc_target_handle_s* handle, net_nfc_error_e* result) +{ + int ret_val = 0; + + ret_val = pm_unlock_state(LCD_NORMAL, PM_RESET_TIMER); + + DEBUG_ERR_MSG("net_nfc_controller_disconnect pm_lock_state [%d]!!", ret_val); + + if (g_interface.disconnect != NULL) + { + net_nfc_server_free_current_tag_info(); + + return g_interface.disconnect(handle, result); + } + else + { + *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC; + DEBUG_SERVER_MSG("interface is null"); + return false; + } +} + +bool net_nfc_controller_check_ndef(net_nfc_target_handle_s* handle, uint8_t *ndef_card_state, int* max_data_size, int* real_data_size, net_nfc_error_e* result) +{ + if (g_interface.check_ndef != NULL) + { + return g_interface.check_ndef(handle, ndef_card_state, max_data_size, real_data_size, result); + } + else + { + *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC; + DEBUG_SERVER_MSG("interface is null"); + return false; + } +} + +bool net_nfc_controller_read_ndef(net_nfc_target_handle_s* handle, data_s** data, net_nfc_error_e* result) +{ + if (g_interface.read_ndef != NULL) + { + return g_interface.read_ndef(handle, data, result); + } + else + { + *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC; + DEBUG_SERVER_MSG("interface is null"); + return false; + } +} + +bool net_nfc_controller_write_ndef(net_nfc_target_handle_s* handle, data_s* data, net_nfc_error_e* result) +{ + if (g_interface.write_ndef != NULL) + { + return g_interface.write_ndef(handle, data, result); + } + else + { + *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC; + DEBUG_SERVER_MSG("interface is null"); + return false; + } +} + +bool net_nfc_controller_make_read_only_ndef(net_nfc_target_handle_s* handle, net_nfc_error_e* result) +{ + if (g_interface.make_read_only_ndef != NULL) + { + return g_interface.make_read_only_ndef(handle, result); + } + else + { + *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC; + DEBUG_SERVER_MSG("interface is null"); + return false; + } +} + +bool net_nfc_controller_format_ndef(net_nfc_target_handle_s* handle, data_s* secure_key, net_nfc_error_e* result) +{ + if (g_interface.format_ndef != NULL) + { + return g_interface.format_ndef(handle, secure_key, result); + } + else + { + *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC; + DEBUG_SERVER_MSG("interface is null"); + return false; + } +} + +bool net_nfc_controller_transceive(net_nfc_target_handle_s* handle, net_nfc_transceive_info_s* info, data_s** data, net_nfc_error_e* result) +{ + if (g_interface.transceive != NULL) + { + return g_interface.transceive(handle, info, data, result); + } + else + { + *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC; + DEBUG_SERVER_MSG("interface is null"); + return false; + } +} + +bool net_nfc_controller_exception_handler() +{ + if (g_interface.exception_handler != NULL) + { + return g_interface.exception_handler(); + } + else + { + DEBUG_SERVER_MSG("interface is null"); + return false; + } +} + +bool net_nfc_controller_is_ready(net_nfc_error_e* result) +{ + if (g_interface.is_ready != NULL) + { + return g_interface.is_ready(result); + } + else + { + *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC; + DEBUG_SERVER_MSG("interface is null"); + return false; + } +} + +bool net_nfc_controller_llcp_config(net_nfc_llcp_config_info_s * config, net_nfc_error_e* result) +{ + if (g_interface.config_llcp != NULL) + { + return g_interface.config_llcp(config, result); + } + else + { + *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC; + DEBUG_SERVER_MSG("interface is null"); + return false; + } +} +bool net_nfc_controller_llcp_check_llcp(net_nfc_target_handle_s* handle, net_nfc_error_e* result) +{ + if (g_interface.check_llcp_status != NULL) + { + return g_interface.check_llcp_status(handle, result); + } + else + { + *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC; + DEBUG_SERVER_MSG("interface is null"); + return false; + } +} +bool net_nfc_controller_llcp_activate_llcp(net_nfc_target_handle_s* handle, net_nfc_error_e* result) +{ + if (g_interface.activate_llcp != NULL) + { + return g_interface.activate_llcp(handle, result); + } + else + { + *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC; + DEBUG_SERVER_MSG("interface is null"); + return false; + } +} +bool net_nfc_controller_llcp_create_socket(net_nfc_llcp_socket_t* socket, net_nfc_socket_type_e socketType, uint16_t miu, uint8_t rw, net_nfc_error_e* result, void * user_param) +{ + if (g_interface.create_llcp_socket != NULL) + { + return g_interface.create_llcp_socket(socket, socketType, miu, rw, result, user_param); + } + else + { + *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC; + DEBUG_SERVER_MSG("interface is null"); + return false; + } +} +bool net_nfc_controller_llcp_bind(net_nfc_llcp_socket_t socket, uint8_t service_access_point, net_nfc_error_e* result) +{ + if (g_interface.bind_llcp_socket != NULL) + { + return g_interface.bind_llcp_socket(socket, service_access_point, result); + } + else + { + *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC; + DEBUG_SERVER_MSG("interface is null"); + return false; + } +} +bool net_nfc_controller_llcp_listen(net_nfc_target_handle_s* handle, uint8_t* service_access_name, net_nfc_llcp_socket_t socket, net_nfc_error_e* result, void * user_param) +{ + if (g_interface.listen_llcp_socket != NULL) + { + return g_interface.listen_llcp_socket(handle, service_access_name, socket, result, user_param); + } + else + { + *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC; + DEBUG_SERVER_MSG("interface is null"); + return false; + } +} +bool net_nfc_controller_llcp_accept(net_nfc_llcp_socket_t socket, net_nfc_error_e* result) +{ + if (g_interface.accept_llcp_socket != NULL) + { + return g_interface.accept_llcp_socket(socket, result); + } + else + { + *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC; + DEBUG_SERVER_MSG("interface is null"); + return false; + } +} + +bool net_nfc_controller_llcp_reject(net_nfc_target_handle_s* handle, net_nfc_llcp_socket_t socket, net_nfc_error_e* result) +{ + if (g_interface.reject_llcp != NULL) + { + return g_interface.reject_llcp(handle, socket, result); + } + else + { + *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC; + DEBUG_SERVER_MSG("interface is null"); + return false; + } +} + +bool net_nfc_controller_llcp_connect_by_url(net_nfc_target_handle_s * handle, net_nfc_llcp_socket_t socket, uint8_t* service_access_name, net_nfc_error_e* result, void * user_param) +{ + int ret_val = 0; + + ret_val = pm_lock_state(LCD_NORMAL, GOTO_STATE_NOW, 0); + + DEBUG_SERVER_MSG("net_nfc_controller_llcp_connect_by_url pm_lock_state [%d]!!", ret_val); + + if (g_interface.connect_llcp_by_url != NULL) + { + return g_interface.connect_llcp_by_url(handle, socket, service_access_name, result, user_param); + } + else + { + *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC; + DEBUG_SERVER_MSG("interface is null"); + return false; + } +} +bool net_nfc_controller_llcp_connect(net_nfc_target_handle_s* handle, net_nfc_llcp_socket_t socket, uint8_t service_access_point, net_nfc_error_e* result, void * user_param) +{ + int ret_val = 0; + + ret_val = pm_lock_state(LCD_NORMAL, GOTO_STATE_NOW, 0); + + DEBUG_SERVER_MSG("net_nfc_controller_llcp_connect pm_lock_state [%d]!!", ret_val); + + if (g_interface.connect_llcp != NULL) + { + return g_interface.connect_llcp(handle, socket, service_access_point, result, user_param); + } + else + { + *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC; + DEBUG_SERVER_MSG("interface is null"); + return false; + } +} +bool net_nfc_controller_llcp_disconnect(net_nfc_target_handle_s* handle, net_nfc_llcp_socket_t socket, net_nfc_error_e* result, void * user_param) +{ + int ret_val = 0; + + ret_val = pm_unlock_state(LCD_NORMAL, PM_RESET_TIMER); + + DEBUG_SERVER_MSG("net_nfc_controller_llcp_disconnect pm_lock_state [%d]!!", ret_val); + + if (g_interface.disconnect_llcp != NULL) + { + return g_interface.disconnect_llcp(handle, socket, result, user_param); + } + else + { + *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC; + DEBUG_SERVER_MSG("interface is null"); + return false; + } +} +bool net_nfc_controller_llcp_socket_close(net_nfc_llcp_socket_t socket, net_nfc_error_e* result) +{ + if (g_interface.close_llcp_socket != NULL) + { + return g_interface.close_llcp_socket(socket, result); + } + else + { + *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC; + DEBUG_SERVER_MSG("interface is null"); + return false; + } +} +bool net_nfc_controller_llcp_recv(net_nfc_target_handle_s* handle, net_nfc_llcp_socket_t socket, data_s* data, net_nfc_error_e* result, void * user_param) +{ + if (g_interface.recv_llcp != NULL) + { + return g_interface.recv_llcp(handle, socket, data, result, user_param); + } + else + { + *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC; + DEBUG_SERVER_MSG("interface is null"); + return false; + } +} +bool net_nfc_controller_llcp_send(net_nfc_target_handle_s* handle, net_nfc_llcp_socket_t socket, data_s* data, net_nfc_error_e* result, void * user_param) +{ + if (g_interface.send_llcp != NULL) + { + return g_interface.send_llcp(handle, socket, data, result, user_param); + } + else + { + *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC; + DEBUG_SERVER_MSG("interface is null"); + return false; + } +} +bool net_nfc_controller_llcp_recv_from(net_nfc_target_handle_s* handle, net_nfc_llcp_socket_t socket, data_s* data, net_nfc_error_e* result, void * user_param) +{ + if (g_interface.recv_from_llcp != NULL) + { + return g_interface.recv_from_llcp(handle, socket, data, result, user_param); + } + else + { + *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC; + DEBUG_SERVER_MSG("interface is null"); + return false; + } +} +bool net_nfc_controller_llcp_send_to(net_nfc_target_handle_s* handle, net_nfc_llcp_socket_t socket, data_s* data, uint8_t service_access_point, net_nfc_error_e* result, void * user_param) +{ + if (g_interface.send_to_llcp != NULL) + { + return g_interface.send_to_llcp(handle, socket, data, service_access_point, result, user_param); + } + else + { + *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC; + DEBUG_SERVER_MSG("interface is null"); + return false; + } +} + +bool net_nfc_controller_llcp_get_remote_config(net_nfc_target_handle_s* handle, net_nfc_llcp_config_info_s *config, net_nfc_error_e* result) +{ + if (g_interface.get_remote_config != NULL) + { + return g_interface.get_remote_config(handle, config, result); + } + else + { + *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC; + DEBUG_SERVER_MSG("interface is null"); + return false; + } +} +bool net_nfc_controller_llcp_get_remote_socket_info(net_nfc_target_handle_s* handle, net_nfc_llcp_socket_t socket, net_nfc_llcp_socket_option_s * option, net_nfc_error_e* result) +{ + if (g_interface.get_remote_socket_info != NULL) + { + return g_interface.get_remote_socket_info(handle, socket, option, result); + } + else + { + *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC; + DEBUG_SERVER_MSG("interface is null"); + return false; + } + +} + +bool net_nfc_controller_sim_test(net_nfc_error_e* result) +{ + if (g_interface.sim_test != NULL) + { + return g_interface.sim_test(result); + } + else + { + *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC; + DEBUG_SERVER_MSG("interface is null"); + return false; + } +} + +bool net_nfc_controller_prbs_test(net_nfc_error_e* result, uint32_t tech, uint32_t rate) +{ + if (g_interface.prbs_test != NULL) + { + return g_interface.prbs_test(result, tech, rate); + } + else + { + *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC; + DEBUG_SERVER_MSG("interface is null"); + return false; + } +} + +bool net_nfc_controller_test_mode_on(net_nfc_error_e* result) +{ + if (g_interface.test_mode_on != NULL) + { + return g_interface.test_mode_on(result); + } + else + { + *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC; + DEBUG_SERVER_MSG("interface is null"); + return false; + } +} + +bool net_nfc_controller_test_mode_off(net_nfc_error_e* result) +{ + if (g_interface.test_mode_off != NULL) + { + return g_interface.test_mode_off(result); + } + else + { + *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC; + DEBUG_SERVER_MSG("interface is null"); + return false; + } +} + +bool net_nfc_controller_support_nfc(net_nfc_error_e* result) +{ + if (g_interface.support_nfc != NULL) + { + return g_interface.support_nfc(result); + } + else + { + *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC; + DEBUG_SERVER_MSG("interface is null"); + return false; + } +} + +bool net_nfc_controller_eedata_register_set(net_nfc_error_e *result, uint32_t mode, uint32_t reg_id, data_s *data) +{ + if (g_interface.eedata_register_set != NULL) + { + return g_interface.eedata_register_set(result, mode, reg_id, data); + } + else + { + *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC; + DEBUG_SERVER_MSG("interface is null"); + return false; + } +} + diff --git a/src/manager/net_nfc_manager.c b/src/manager/net_nfc_manager.c new file mode 100755 index 0000000..5315fee --- /dev/null +++ b/src/manager/net_nfc_manager.c @@ -0,0 +1,378 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include + +#include "heynoti.h" +#include "vconf.h" + +#include "net_nfc_server_ipc_private.h" +#include "net_nfc_debug_private.h" +#include "net_nfc_service_private.h" +#include "net_nfc_typedef_private.h" +#include "net_nfc_service_vconf_private.h" +#include "net_nfc_app_util_private.h" +#include "net_nfc_controller_private.h" +#include "net_nfc_util_private.h" +#include "net_nfc_util_defines.h" +#include "net_nfc_server_dispatcher_private.h" +#include "net_nfc_server_context_private.h" +#include "net_nfc_manager_dbus.h" +#include "nfc-service-binding.h" + +static GMainLoop *loop = NULL; +static GObject *object = NULL; +static DBusGConnection *connection = NULL; +static pid_t launch_by_client = 0; + +static void __net_nfc_discovery_polling_cb(keynode_t *node, void *user_data); +static bool Check_Redwood(); + +G_DEFINE_TYPE(Nfc_Service, nfc_service, G_TYPE_OBJECT) + +/* Just Check the assert and set the error message */ +#define __G_ASSERT(test, return_val, error, domain, error_code)\ + G_STMT_START\ + {\ + if G_LIKELY (!(test)) { \ + g_set_error (error, domain, error_code, #test); \ + return (return_val); \ + }\ + }\ + G_STMT_END + +GQuark nfc_service_error_quark(void) +{ + DEBUG_MSG("nfc_service_error_quark entered"); + + return g_quark_from_static_string("nfc_service_error"); +} + +static void nfc_service_init(Nfc_Service *nfc_service) +{ + DEBUG_MSG("nfc_service_init entered"); +} + +static void nfc_service_class_init(Nfc_ServiceClass *nfc_service_class) +{ + DEBUG_MSG("nfc_service_class_init entered"); + + dbus_g_object_type_install_info(NFC_SERVICE_TYPE, &dbus_glib_nfc_service_object_info); +} + +gboolean nfc_service_launch(Nfc_Service *nfc_service, guint *result_val, GError **error) +{ + DEBUG_MSG("nfc_service_launch entered"); + + DEBUG_SERVER_MSG("nfc_service_launch NFC MANAGER PID=[%d]", getpid()); + DEBUG_SERVER_MSG("nfc_service_launch NFC MANAGER TID=[%lx]", pthread_self()); + + launch_by_client = getpid(); + + return TRUE; +} + +gboolean nfc_service_terminate(Nfc_Service *nfc_service, guint *result_val, GError **error) +{ + int result, state; + + DEBUG_MSG("nfc_service_terminate entered, remain client [%d]", net_nfc_server_get_client_count()); + + result = vconf_get_bool(VCONFKEY_NFC_STATE, &state); + if (result != 0) + { + DEBUG_MSG("VCONFKEY_NFC_STATE is not exist: %d ", result); + return false; + } + + /*TEMP CODE*/ + //if ((g_server_info.connected_client_count <=1) && (state == false)) + if (state == false) + { + g_main_loop_quit(loop); + + if (vconf_set_bool(VCONFKEY_NFC_STATE, FALSE) != 0) + { + DEBUG_ERR_MSG("vconf_set_bool failed"); + } + + DEBUG_MSG("Real nfc_service_terminate end"); + } + else + { + DEBUG_MSG("Fake nfc_service_terminate end"); + } + + return TRUE; +} + +static void _net_nfc_intialize_dbus_connection() +{ + GError *error = NULL; + DBusGProxy *proxy = NULL; + guint ret = 0; + + g_type_init(); + + connection = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error); + if (error == NULL) + { + object = (GObject *)g_object_new(NFC_SERVICE_TYPE, NULL); + dbus_g_connection_register_g_object(connection, NFC_SERVICE_PATH, object); + + /* register service */ + proxy = dbus_g_proxy_new_for_name(connection, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS); + if (proxy != NULL) + { + if (!org_freedesktop_DBus_request_name(proxy, NFC_SERVICE_NAME, 0, &ret, &error)) + { + DEBUG_MSG("Unable to register service: %s", error->message); + g_error_free(error); + } + + g_object_unref(proxy); + } + else + { + DEBUG_MSG("dbus_g_proxy_new_for_name failed"); + } + } + else + { + DEBUG_MSG("ERROR: Can't get on system bus [%s]", error->message); + g_error_free(error); + } +} + +#if 0 +static void _net_nfc_deintialize_dbus_connection() +{ + dbus_g_connection_unregister_g_object(connection, object); + g_object_unref(object); +} +#endif + +int main(int check, char* argv[]) +{ + int result = 0; + void *handle = NULL; + int state = 0; + + DEBUG_SERVER_MSG("start nfc manager"); + DEBUG_SERVER_MSG("argv0 = %s", argv[0]); + DEBUG_SERVER_MSG("argv1 = %s", argv[1]); + + /* nfc_log_to_file */ + nfc_log_file = fopen(NFC_DLOG_FILE, "w+"); + if (nfc_log_file == NULL) + { + fprintf(stderr, "\n\nfopen error\n\n"); + } + + net_nfc_app_util_clean_storage(MESSAGE_STORAGE); + + if (!g_thread_supported()) + { + g_thread_init(NULL); + } + + g_type_init(); + + handle = net_nfc_controller_onload(); + if (handle == NULL) + { + DEBUG_ERR_MSG("load plugin library is failed"); + return 0; + } + + if (net_nfc_controller_support_nfc(&result) == true) + { + DEBUG_SERVER_MSG("NFC Support"); + vconf_set_bool(VCONFKEY_NFC_FEATURE, VCONFKEY_NFC_FEATURE_ON); + } + else + { + DEBUG_ERR_MSG("NFC doesn't support"); + + vconf_set_bool(VCONFKEY_NFC_FEATURE, VCONFKEY_NFC_FEATURE_OFF); + vconf_set_bool(VCONFKEY_NFC_STATE, FALSE); + + net_nfc_controller_unload(handle); + + //return(0); + } + + result = vconf_get_bool(VCONFKEY_NFC_STATE, &state); + if (result != 0) + { + DEBUG_MSG("VCONFKEY_NFC_STATE is not exist: %d ", result); + return false; + } + + DEBUG_MSG("vconf state value [%d]", state); + + if (argv[1] != NULL) + { + if (state == FALSE && !(strncmp(argv[1], "script", 6))) + { + DEBUG_ERR_MSG("Init Script execute nfc manager. But State is false."); + return (0); + } + } + + if (net_nfc_server_ipc_initialize() != true) + { + DEBUG_ERR_MSG("nfc server ipc initialization is failed"); + + net_nfc_controller_unload(handle); + + return 0; + } + + DEBUG_SERVER_MSG("nfc server ipc init is ok"); + + _net_nfc_intialize_dbus_connection(); + +#if 0 + int fd = 0; + + fd = heynoti_init(); + DEBUG_MSG("Noti init: %d", fd); + if (fd == -1) + return 0; + + /*Power Manager send the system_wakeup noti to subscriber*/ + result = heynoti_subscribe(fd, "system_wakeup", __net_nfc_discovery_polling_cb, (void *)fd); + DEBUG_MSG("noti add: %d", result); + + if (result == -1) + return 0; + + result = heynoti_attach_handler(fd); + DEBUG_MSG("attach handler : %d", result); + + if (result == -1) + return 0; +#endif + vconf_notify_key_changed("memory/pm/state", __net_nfc_discovery_polling_cb, NULL); + + net_nfc_service_vconf_register_notify_listener(); + + loop = g_main_new(TRUE); + g_main_loop_run(loop); + + net_nfc_service_vconf_unregister_notify_listener(); + net_nfc_server_ipc_finalize(); + net_nfc_controller_unload(handle); + + return 0; +} + +static void __net_nfc_discovery_polling_cb(keynode_t *node, void *user_data) +{ + int state; + int pm_state = 0; + net_nfc_error_e result; + + result = vconf_get_bool(VCONFKEY_NFC_STATE, &state); + if (result != 0) + { + DEBUG_MSG("VCONFKEY_NFC_STATE is not exist: %d ", result); + } + + result = vconf_get_int("memory/pm/state", &pm_state); + DEBUG_MSG("PM STATE : %d ", pm_state); + + DEBUG_MSG("__net_nfc_discovery_polling_cb[Enter]"); +#if 0 + if(state == TRUE) + { + net_nfc_request_msg_t *req_msg = NULL; + + _net_nfc_util_alloc_mem(req_msg, sizeof(net_nfc_request_msg_t)); + + if (req_msg == NULL) + { + DEBUG_MSG("_net_nfc_util_alloc_mem[NULL]"); + return; + } + + req_msg->length = sizeof(net_nfc_request_msg_t); + req_msg->request_type = NET_NFC_MESSAGE_SERVICE_RESTART_POLLING_LOOP; + + net_nfc_dispatcher_queue_push(req_msg); + } + else + { + DEBUG_SERVER_MSG("Don't need to wake up. NFC is OFF!!"); + } +#endif + + if ((pm_state == 1) || (pm_state == 3))/*Screen On*/ + { + net_nfc_request_msg_t *req_msg = NULL; + + _net_nfc_util_alloc_mem(req_msg, sizeof(net_nfc_request_msg_t)); + + if (req_msg == NULL) + { + DEBUG_MSG("_net_nfc_util_alloc_mem[NULL]"); + return; + } + + req_msg->length = sizeof(net_nfc_request_msg_t); + req_msg->user_param = pm_state; + req_msg->request_type = NET_NFC_MESSAGE_SERVICE_RESTART_POLLING_LOOP; + + net_nfc_dispatcher_queue_push(req_msg); + } + else + { + DEBUG_MSG("Do not anything!!"); + } + + DEBUG_MSG("__net_nfc_discovery_polling_cb[Out]"); +} + +static bool Check_Redwood() +{ + struct utsname hwinfo; + + int ret = uname(&hwinfo); + DEBUG_MSG("uname returned %d", ret); + DEBUG_MSG("sysname::%s", hwinfo.sysname); + DEBUG_MSG("release::%s", hwinfo.release); + DEBUG_MSG("version::%s", hwinfo.version); + DEBUG_MSG("machine::%s", hwinfo.machine); + DEBUG_MSG("nodename::%s", hwinfo.nodename); + + if (strstr(hwinfo.nodename, "REDWOOD")) + { + DEBUG_MSG("REDWOOD hardware"); + return true; + } + else + { + DEBUG_MSG("except REDWOOD"); + return false; + } +} diff --git a/src/manager/net_nfc_manager_util.c b/src/manager/net_nfc_manager_util.c new file mode 100755 index 0000000..aceef9c --- /dev/null +++ b/src/manager/net_nfc_manager_util.c @@ -0,0 +1,112 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include "vconf.h" +#include "svi.h" +#include "wav_player.h" + +#include "net_nfc_debug_private.h" +#include "net_nfc_util_private.h" +#include "net_nfc_manager_util_private.h" + +static void _play_sound_callback(int id, void *data) +{ + DEBUG_MSG("_play_sound_callback"); + + if (WAV_PLAYER_ERROR_NONE != wav_player_stop(id)) + { + DEBUG_MSG("wav_player_stop failed"); + } +} + +void net_nfc_manager_util_play_sound(net_nfc_sound_type_e sound_type) +{ + int bSoundOn = 0; + int bVibrationOn = 0; + + if (vconf_get_bool(VCONFKEY_SETAPPL_SOUND_STATUS_BOOL, &bSoundOn) != 0) + { + DEBUG_MSG("vconf_get_bool failed for Sound"); + return; + } + + if (vconf_get_bool(VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL, &bVibrationOn) != 0) + { + DEBUG_MSG("vconf_get_bool failed for Vibration"); + return; + } + + if ((sound_type > NET_NFC_TASK_ERROR) || (sound_type < NET_NFC_TASK_START)) + { + DEBUG_MSG("Invalid Sound Type"); + return; + } + + if (bVibrationOn) + { + int svi_handle = -1; + + DEBUG_MSG("Play Vibration"); + + if (SVI_SUCCESS == svi_init(&svi_handle)) + { + if (SVI_SUCCESS == svi_play_vib(svi_handle, SVI_VIB_TOUCH_SIP)) + { + DEBUG_MSG("svi_play_vib success"); + } + + svi_fini(svi_handle); + } + } + + if (bSoundOn) + { + char *sound_path = NULL; + + DEBUG_MSG("Play Sound"); + + switch (sound_type) + { + case NET_NFC_TASK_START : + sound_path = strdup(NET_NFC_MANAGER_SOUND_PATH_TASK_START); + break; + case NET_NFC_TASK_END : + sound_path = strdup(NET_NFC_MANAGER_SOUND_PATH_TASK_END); + break; + case NET_NFC_TASK_ERROR : + sound_path = strdup(NET_NFC_MANAGER_SOUND_PATH_TASK_ERROR); + break; + } + + if (sound_path != NULL) + { + if (WAV_PLAYER_ERROR_NONE == wav_player_start(sound_path, SOUND_TYPE_MEDIA, _play_sound_callback, NULL, NULL)) + { + DEBUG_MSG("wav_player_start success"); + } + + _net_nfc_util_free_mem(sound_path); + } + else + { + DEBUG_ERR_MSG("Invalid Sound Path"); + } + } +} + diff --git a/src/manager/net_nfc_server_context.c b/src/manager/net_nfc_server_context.c new file mode 100644 index 0000000..98059a5 --- /dev/null +++ b/src/manager/net_nfc_server_context.c @@ -0,0 +1,338 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include "vconf.h" + +#include "net_nfc_debug_private.h" +#include "net_nfc_util_private.h" +#include "net_nfc_util_defines.h" +#include "net_nfc_server_context_private.h" + +static GList *g_client_contexts = NULL; +static pthread_mutex_t g_client_context_lock = PTHREAD_MUTEX_INITIALIZER; + +static gint _client_context_compare_func(gconstpointer a, gconstpointer b) +{ + gint result = -1; + net_nfc_client_info_t *info = (net_nfc_client_info_t *)a; + + if (info->socket == (int)b) + result = 0; + else if (info->socket > (int)b) + result = 1; + + return result; +} + +static void _cleanup_client_context(gpointer data) +{ + net_nfc_client_info_t *info = data; + + if (info != NULL) + { + if (info->channel != NULL) + { + g_io_channel_unref(info->channel); + } + + /* need to check . is it necessary to remove g_source_id */ + if (info->src_id > 0) + { + g_source_remove(info->src_id); + } + + if (info->socket > 0) + { + shutdown(info->socket, SHUT_RDWR); + close(info->socket); + } + + if (vconf_set_bool(NET_NFC_DISABLE_LAUNCH_POPUP_KEY, net_nfc_server_is_set_launch_state()) != 0) + DEBUG_ERR_MSG("SERVER :set launch vconf fail"); + + DEBUG_SERVER_MSG("cleanup success : client [%d]", info->socket); + + _net_nfc_util_free_mem(info); + } +} + +void net_nfc_server_deinit_client_context() +{ + pthread_mutex_lock(&g_client_context_lock); + + g_list_free_full(g_client_contexts, _cleanup_client_context); + + pthread_mutex_unlock(&g_client_context_lock); +} + +int net_nfc_server_get_client_count() +{ + int result = 0; + + pthread_mutex_lock(&g_client_context_lock); + + result = g_list_length(g_client_contexts); + + pthread_mutex_unlock(&g_client_context_lock); + + return result; +} + +net_nfc_client_info_t *net_nfc_server_get_client_context(int socket) +{ + net_nfc_client_info_t *result = NULL; + GList *item = NULL; + + pthread_mutex_lock(&g_client_context_lock); + + item = g_list_find_custom(g_client_contexts, (gconstpointer)socket, _client_context_compare_func); + if (item != NULL) + { + result = item->data; + } + + pthread_mutex_unlock(&g_client_context_lock); + + return result; +} + +void net_nfc_server_add_client_context(int socket, GIOChannel* channel, uint32_t src_id, client_state_e state) +{ + DEBUG_SERVER_MSG("add client context"); + + if (net_nfc_server_get_client_context(socket) == NULL) + { + net_nfc_client_info_t *info = NULL; + + pthread_mutex_lock(&g_client_context_lock); + + _net_nfc_util_alloc_mem(info, sizeof(net_nfc_client_info_t)); + if (info != NULL) + { + info->socket = socket; + info->channel = channel; + info->src_id = src_id; + info->state = state; + info->is_set_launch_popup = TRUE; + + g_client_contexts = g_list_append(g_client_contexts, info); + } + else + { + DEBUG_ERR_MSG("alloc failed"); + } + + pthread_mutex_unlock(&g_client_context_lock); + } + else + { + DEBUG_ERR_MSG("client exists already [%d]", socket); + } + + DEBUG_SERVER_MSG("current client count = [%d]", g_list_length(g_client_contexts)); +} + +void net_nfc_server_cleanup_client_context(int socket) +{ + GList *item = NULL; + + DEBUG_SERVER_MSG("clean up client context"); + + pthread_mutex_lock(&g_client_context_lock); + + item = g_list_find_custom(g_client_contexts, (gconstpointer)socket, _client_context_compare_func); + if (item != NULL) + { + _cleanup_client_context(item->data); + + g_client_contexts = g_list_delete_link(g_client_contexts, item); + } + + pthread_mutex_unlock(&g_client_context_lock); + + DEBUG_SERVER_MSG("current client count = [%d]", g_list_length(g_client_contexts)); +} + +void net_nfc_server_for_each_client_context(net_nfc_server_for_each_client_cb cb, void *user_param) +{ + GList *item = NULL; + + pthread_mutex_lock(&g_client_context_lock); + item = g_list_first(g_client_contexts); + while (item != NULL) + { + if (cb != NULL) + { + cb(item->data, user_param); + } + item = g_list_next(item); + } + pthread_mutex_unlock(&g_client_context_lock); +} + +#ifndef BROADCAST_MESSAGE +net_nfc_target_handle_s* net_nfc_server_get_current_client_target_handle(int socket_fd) +{ + int i = 0; + + pthread_mutex_lock(&g_server_socket_lock); + + net_nfc_target_handle_s* handle = NULL; + + for(; i < NET_NFC_CLIENT_MAX; i++) + { + if(g_client_info[i].socket == socket_fd) + { + handle = g_client_info[i].target_handle; + break; + } + } + + pthread_mutex_unlock(&g_server_socket_lock); + + return handle; +} + +bool net_nfc_server_set_current_client_target_handle(int socket_fd, net_nfc_target_handle_s* handle) +{ + int i = 0; + + pthread_mutex_lock(&g_server_socket_lock); + + for(; i < NET_NFC_CLIENT_MAX; i++) + { + if(g_client_info[i].socket == socket_fd) + { + g_client_info[i].target_handle = handle; + pthread_mutex_unlock(&g_server_socket_lock); + return true; + } + } + + pthread_mutex_unlock(&g_server_socket_lock); + return false; +} +#endif + +bool net_nfc_server_check_client_is_running(int socket) +{ +#ifdef BROADCAST_MESSAGE + return (net_nfc_server_get_client_context(socket) != NULL); +#else + int client_fd = *((int *)client_context); + + if(client_fd > 0) + return true; + else + return false; +#endif +} + +client_state_e net_nfc_server_get_client_state(int socket) +{ + GList *item = NULL; + client_state_e state = NET_NFC_CLIENT_INACTIVE_STATE; + + pthread_mutex_lock(&g_client_context_lock); + + item = g_list_find_custom(g_client_contexts, (gconstpointer)socket, _client_context_compare_func); + if (item != NULL) + { + state = ((net_nfc_client_info_t *)item->data)->state; + } + + pthread_mutex_unlock(&g_client_context_lock); + + return state; +} + +void net_nfc_server_set_client_state(int socket, client_state_e state) +{ + GList *item = NULL; + + pthread_mutex_lock(&g_client_context_lock); + + item = g_list_find_custom(g_client_contexts, (gconstpointer)socket, _client_context_compare_func); + if (item != NULL) + { + ((net_nfc_client_info_t *)item->data)->state = state; + } + + pthread_mutex_unlock(&g_client_context_lock); +} + +static void _enable_launch_state(gpointer data, gpointer user_data) +{ + net_nfc_client_info_t *info = (net_nfc_client_info_t *)data; + + if (info != NULL) + { + info->state = (bool)user_data; + } +} + +static gint _check_launch_state(gconstpointer a, gconstpointer b) +{ + gint result = 1; + net_nfc_client_info_t *info = (net_nfc_client_info_t *)a; + + if (info->is_set_launch_popup == false) + result = 0; + + return result; +} + +void net_nfc_server_set_launch_state(int socket, bool enable) +{ + if (vconf_set_bool(NET_NFC_DISABLE_LAUNCH_POPUP_KEY, enable) != 0) + { + DEBUG_ERR_MSG("SERVER : launch state set vconf fail"); + } + + if (enable == true) + { + pthread_mutex_lock(&g_client_context_lock); + g_list_foreach(g_client_contexts, _enable_launch_state, (gpointer)true); + pthread_mutex_unlock(&g_client_context_lock); + } + else + { + net_nfc_client_info_t *context = net_nfc_server_get_client_context(socket); + pthread_mutex_lock(&g_client_context_lock); + if (context != NULL) + { + context->state = enable; + } + pthread_mutex_unlock(&g_client_context_lock); + } +} + +bool net_nfc_server_is_set_launch_state() +{ + bool result = true; + GList *item = NULL; + + item = g_list_find_custom(g_client_contexts, NULL, _check_launch_state); + if (item != NULL) + { + result = false; + } + + return result; +} diff --git a/src/manager/net_nfc_server_dispatcher.c b/src/manager/net_nfc_server_dispatcher.c new file mode 100644 index 0000000..cb3d0f0 --- /dev/null +++ b/src/manager/net_nfc_server_dispatcher.c @@ -0,0 +1,1715 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include + +#include "vconf.h" + +#include "net_nfc_server_dispatcher_private.h" +#include "net_nfc_typedef_private.h" +#include "net_nfc_controller_private.h" +#include "net_nfc_server_ipc_private.h" +#include "net_nfc_debug_private.h" +#include "net_nfc_util_private.h" +#include "net_nfc_util_defines.h" +#include "net_nfc_controller_private.h" +#include "net_nfc_service_private.h" +#include "net_nfc_service_llcp_private.h" +#include "net_nfc_service_llcp_handover_private.h" +#include "net_nfc_service_tag_private.h" +#include "net_nfc_manager_util_private.h" +#include "net_nfc_service_se_private.h" +#include "net_nfc_util_access_control_private.h" +#include "net_nfc_server_context_private.h" + +static GQueue *g_dispatcher_queue; +static pthread_cond_t g_dispatcher_queue_cond = PTHREAD_COND_INITIALIZER; +static pthread_mutex_t g_dispatcher_queue_lock = PTHREAD_MUTEX_INITIALIZER; +static pthread_t g_dispatcher_thread; + +static uint8_t g_se_prev_type = SECURE_ELEMENT_TYPE_INVALID; +static uint8_t g_se_prev_mode = SECURE_ELEMENT_OFF_MODE; + +static void *_net_nfc_dispatcher_thread_func(void *data); +static net_nfc_request_msg_t *_net_nfc_dispatcher_queue_pop(); + +static net_nfc_request_msg_t *_net_nfc_dispatcher_queue_pop() +{ + net_nfc_request_msg_t *msg = NULL; + msg = g_queue_pop_head(g_dispatcher_queue); + return msg; +} + +void net_nfc_dispatcher_queue_push(net_nfc_request_msg_t *req_msg) +{ + pthread_mutex_lock(&g_dispatcher_queue_lock); + g_queue_push_tail(g_dispatcher_queue, req_msg); + pthread_cond_signal(&g_dispatcher_queue_cond); + pthread_mutex_unlock(&g_dispatcher_queue_lock); +} + +void net_nfc_dispatcher_cleanup_queue(void) +{ + net_nfc_request_msg_t *req_msg = NULL; + + pthread_mutex_lock(&g_dispatcher_queue_lock); + + DEBUG_SERVER_MSG("cleanup dispatcher Q start"); + + while ((req_msg = _net_nfc_dispatcher_queue_pop()) != NULL) + { + DEBUG_MSG("abandon request : %d", req_msg->request_type); + _net_nfc_util_free_mem(req_msg); + } + + DEBUG_SERVER_MSG("cleanup dispatcher Q end"); + + pthread_mutex_unlock(&g_dispatcher_queue_lock); +} + +void net_nfc_dispatcher_put_cleaner(void) +{ + net_nfc_request_msg_t *req_msg = NULL; + + _net_nfc_util_alloc_mem(req_msg, sizeof(net_nfc_request_msg_t)); + if (req_msg != NULL) + { + DEBUG_SERVER_MSG("put cleaner request"); + + req_msg->length = sizeof(net_nfc_request_msg_t); + req_msg->request_type = NET_NFC_MESSAGE_SERVICE_CLEANER; + net_nfc_dispatcher_queue_push(req_msg); + } +} + +static void *_net_nfc_dispatcher_copy_message(void *msg) +{ + net_nfc_request_msg_t *origin = (net_nfc_request_msg_t *)msg; + net_nfc_request_msg_t *result = NULL; + + if (origin == NULL || origin->length == 0) + { + return result; + } + + _net_nfc_util_alloc_mem(result, origin->length); + if (result != NULL) + { + memcpy(result, origin, origin->length); + } + + return result; +} + +bool net_nfc_dispatcher_start_thread() +{ + net_nfc_request_msg_t *req_msg = NULL; + pthread_attr_t attr; + int result, state; + + DEBUG_SERVER_MSG("init queue"); + + g_dispatcher_queue = g_queue_new(); + + pthread_attr_init(&attr); + pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); + + result = vconf_get_bool(VCONFKEY_NFC_STATE, &state); + if (result != 0) + { + DEBUG_SERVER_MSG("VCONFKEY_NFC_STATE is not exist: %d ", result); + return false; + } + + DEBUG_SERVER_MSG("net_nfc_dispatcher_start_thread vconf state value [%d]", state); + + if (state == TRUE) + { + _net_nfc_util_alloc_mem(req_msg, sizeof(net_nfc_request_msg_t)); + if (req_msg == NULL) + { + DEBUG_ERR_MSG("alloc failed"); + return false; + } + + req_msg->length = sizeof(net_nfc_request_msg_t); + req_msg->request_type = NET_NFC_MESSAGE_SERVICE_INIT; + + DEBUG_SERVER_MSG("put controller init request"); + net_nfc_dispatcher_queue_push(req_msg); + } + else + { + /*Don't need to initialize the stack!!*/ + } + + if (pthread_create(&g_dispatcher_thread, &attr, _net_nfc_dispatcher_thread_func, NULL) != 0) + { + net_nfc_dispatcher_cleanup_queue(); + DEBUG_ERR_MSG("pthread_create failed"); + return false; + } + + usleep(0); /* switch to new thread */ + return true; +} + +static void *_net_nfc_dispatcher_thread_func(void *data) +{ + net_nfc_request_msg_t *req_msg = NULL; + + DEBUG_SERVER_MSG("net_nfc_controller_thread is created "); + + while (1) + { + pthread_mutex_lock(&g_dispatcher_queue_lock); + if ((req_msg = _net_nfc_dispatcher_queue_pop()) == NULL) + { + pthread_cond_wait(&g_dispatcher_queue_cond, &g_dispatcher_queue_lock); + pthread_mutex_unlock(&g_dispatcher_queue_lock); + continue; + } + pthread_mutex_unlock(&g_dispatcher_queue_lock); + +// DEBUG_SERVER_MSG("net_nfc_controller get command = [%d]", req_msg->request_type); + + switch (req_msg->request_type) + { + case NET_NFC_MESSAGE_SERVICE_CLEANER : + { + DEBUG_SERVER_MSG("client is terminated abnormally"); + + if (g_se_prev_type == SECURE_ELEMENT_TYPE_ESE) + { + net_nfc_error_e result = NET_NFC_OK; + net_nfc_target_handle_s *ese_handle = net_nfc_service_se_get_current_ese_handle(); + + if (ese_handle != NULL) + { + DEBUG_SERVER_MSG("ese_handle was not freed and disconnected"); + + net_nfc_service_se_close_ese(); +#ifdef BROADCAST_MESSAGE + net_nfc_server_set_server_state(NET_NFC_SERVER_IDLE); +#endif + } + + if ((g_se_prev_type != net_nfc_service_se_get_se_type()) || (g_se_prev_mode != net_nfc_service_se_get_se_mode())) + { + net_nfc_controller_set_secure_element_mode(g_se_prev_type, g_se_prev_mode, &result); + + net_nfc_service_se_set_se_type(g_se_prev_type); + net_nfc_service_se_set_se_mode(g_se_prev_mode); + } + } + else if (g_se_prev_type == SECURE_ELEMENT_TYPE_UICC) + { + net_nfc_service_tapi_deinit(); + } + else + { + DEBUG_SERVER_MSG("SE type is not valid"); + } + } + break; + + case NET_NFC_MESSAGE_SEND_APDU_SE : + { + net_nfc_request_send_apdu_t *detail = (net_nfc_request_send_apdu_t *)req_msg; + + if (detail->handle == (net_nfc_target_handle_s *)UICC_TARGET_HANDLE) + { + data_s apdu_data = { NULL, 0 }; + + if (net_nfc_util_duplicate_data(&apdu_data, &detail->data) == false) + break; + + net_nfc_service_transfer_apdu(req_msg->client_fd, &apdu_data, detail->trans_param); + + net_nfc_util_free_data(&apdu_data); + } + else if (detail->handle == net_nfc_service_se_get_current_ese_handle()) + { + data_s *data = NULL; + net_nfc_error_e result = NET_NFC_OK; + net_nfc_transceive_info_s info; + bool success = true; + + info.dev_type = NET_NFC_ISO14443_A_PICC; + if (net_nfc_util_duplicate_data(&info.trans_data, &detail->data) == false) + { + DEBUG_ERR_MSG("alloc failed"); + break; + } + + if ((success = net_nfc_controller_transceive(detail->handle, &info, &data, &result)) == true) + { + if (data != NULL) + { + DEBUG_SERVER_MSG("trasceive data recieved [%d], Success = %d", data->length, success); + } + } + else + { + DEBUG_SERVER_MSG("trasceive is failed = [%d]", result); + } + net_nfc_util_free_data(&info.trans_data); + + if (net_nfc_server_check_client_is_running(req_msg->client_fd)) + { + net_nfc_response_send_apdu_t resp = { 0 }; + + resp.length = sizeof(net_nfc_response_send_apdu_t); + resp.flags = detail->flags; + resp.trans_param = detail->trans_param; + resp.result = result; + + if (success && data != NULL) + { + DEBUG_MSG("send response send apdu msg"); + resp.data.length = data->length; + net_nfc_send_response_msg(req_msg->client_fd, req_msg->request_type, (void *)&resp, sizeof(net_nfc_response_send_apdu_t), + data->buffer, data->length, NULL); + } + else + { + DEBUG_MSG("send response send apdu msg"); + net_nfc_send_response_msg(req_msg->client_fd, req_msg->request_type, (void *)&resp, sizeof(net_nfc_response_send_apdu_t), NULL); + } + } + } + else + { + DEBUG_SERVER_MSG("invalid se handle"); + + if (net_nfc_server_check_client_is_running(req_msg->client_fd)) + { + net_nfc_response_send_apdu_t resp = { 0 }; + + resp.length = sizeof(net_nfc_response_send_apdu_t); + resp.flags = detail->flags; + resp.trans_param = detail->trans_param; + resp.result = NET_NFC_INVALID_PARAM; + + net_nfc_send_response_msg(req_msg->client_fd, req_msg->request_type, (void *)&resp, sizeof(net_nfc_response_send_apdu_t), NULL); + } + } + } + break; + + case NET_NFC_MESSAGE_CLOSE_INTERNAL_SE : + { + net_nfc_request_close_internal_se_t *detail = (net_nfc_request_close_internal_se_t *)req_msg; + net_nfc_error_e result = NET_NFC_OK; + + if (detail->handle == (net_nfc_target_handle_s *)UICC_TARGET_HANDLE) + { + /*deinit TAPI*/ + DEBUG_SERVER_MSG("UICC is current secure element"); + net_nfc_service_tapi_deinit(); + + } + else if (detail->handle == net_nfc_service_se_get_current_ese_handle()) + { + result = net_nfc_service_se_close_ese(); +#ifdef BROADCAST_MESSAGE + net_nfc_server_unset_server_state(NET_NFC_SE_CONNECTED); +#endif + } + else + { + DEBUG_ERR_MSG("invalid se handle received handle = [0x%p] and current handle = [0x%p]", detail->handle, net_nfc_service_se_get_current_ese_handle()); + } + + if ((g_se_prev_type != net_nfc_service_se_get_se_type()) || (g_se_prev_mode != net_nfc_service_se_get_se_mode())) + { + /*return back se mode*/ + net_nfc_controller_set_secure_element_mode(g_se_prev_type, g_se_prev_mode, &result); + + net_nfc_service_se_set_se_type(g_se_prev_type); + net_nfc_service_se_set_se_mode(g_se_prev_mode); + } + + if (net_nfc_server_check_client_is_running(req_msg->client_fd)) + { + net_nfc_response_close_internal_se_t resp = { 0 }; + + resp.length = sizeof(net_nfc_response_close_internal_se_t); + resp.flags = detail->flags; + resp.trans_param = detail->trans_param; + resp.result = result; + + net_nfc_send_response_msg(req_msg->client_fd, req_msg->request_type, (void *)&resp, sizeof(net_nfc_response_close_internal_se_t), NULL); + } + } + break; + + case NET_NFC_MESSAGE_OPEN_INTERNAL_SE : + { + net_nfc_request_open_internal_se_t *detail = (net_nfc_request_open_internal_se_t *)req_msg; + net_nfc_target_handle_s *handle = NULL; + net_nfc_error_e result = NET_NFC_OK; + + g_se_prev_type = net_nfc_service_se_get_se_type(); + g_se_prev_mode = net_nfc_service_se_get_se_mode(); + + if (detail->se_type == SECURE_ELEMENT_TYPE_UICC) + { + /*off ESE*/ + net_nfc_controller_set_secure_element_mode(SECURE_ELEMENT_TYPE_ESE, SECURE_ELEMENT_OFF_MODE, &result); + + /*Off UICC. UICC SHOULD not be detected by external reader when being communicated in internal process*/ + net_nfc_controller_set_secure_element_mode(SECURE_ELEMENT_TYPE_UICC, SECURE_ELEMENT_OFF_MODE, &result); + + net_nfc_service_se_set_se_type(SECURE_ELEMENT_TYPE_UICC); + net_nfc_service_se_set_se_mode(SECURE_ELEMENT_OFF_MODE); + + /*Init tapi api and return back response*/ + if (net_nfc_service_tapi_init() != true) + { + net_nfc_service_tapi_deinit(); + result = NET_NFC_INVALID_STATE; + handle = NULL; + } + else + { + result = NET_NFC_OK; + handle = (net_nfc_target_handle_s *)UICC_TARGET_HANDLE; + } + } + else if (detail->se_type == SECURE_ELEMENT_TYPE_ESE) + { + /*Connect NFC-WI to ESE*/ + net_nfc_controller_set_secure_element_mode(SECURE_ELEMENT_TYPE_ESE, SECURE_ELEMENT_WIRED_MODE, &result); + + /*off UICC*/ + net_nfc_controller_set_secure_element_mode(SECURE_ELEMENT_TYPE_UICC, SECURE_ELEMENT_OFF_MODE, &result); + + net_nfc_service_se_set_se_type(SECURE_ELEMENT_TYPE_ESE); + net_nfc_service_se_set_se_mode(SECURE_ELEMENT_WIRED_MODE); + net_nfc_service_se_get_se_setting()->open_request_trans_param = detail->trans_param; + + result = NET_NFC_OK; + handle = (net_nfc_target_handle_s *)1; + } + else + { + result = NET_NFC_INVALID_STATE; + handle = NULL; + } + + if (net_nfc_server_check_client_is_running(req_msg->client_fd)) + { + net_nfc_response_open_internal_se_t resp = { 0 }; + + resp.length = sizeof(net_nfc_response_open_internal_se_t); + resp.flags = detail->flags; + resp.trans_param = detail->trans_param; + resp.result = result; + resp.se_type = detail->se_type; + resp.handle = handle; + + net_nfc_send_response_msg(req_msg->client_fd, req_msg->request_type, (void *)&resp, sizeof(net_nfc_response_set_se_t), NULL); + } + } + break; + + case NET_NFC_MESSAGE_SET_SE : + { + net_nfc_request_set_se_t *detail = (net_nfc_request_set_se_t *)req_msg; + net_nfc_error_e result = NET_NFC_OK; + bool isTypeChange = false; + + if (detail->se_type != net_nfc_service_se_get_se_type()) + { + result = net_nfc_service_se_change_se(detail->se_type); + isTypeChange = true; + } + + if (net_nfc_server_check_client_is_running(req_msg->client_fd)) + { + net_nfc_response_set_se_t resp = { 0 }; + + resp.length = sizeof(net_nfc_response_set_se_t); + resp.flags = detail->flags; + resp.trans_param = detail->trans_param; + resp.se_type = detail->se_type; + resp.result = result; + + net_nfc_send_response_msg(req_msg->client_fd, req_msg->request_type, (void *)&resp, sizeof(net_nfc_response_set_se_t), NULL); + } + + if (isTypeChange) + { + net_nfc_response_notify_t noti_se = { 0, }; + + net_nfc_broadcast_response_msg(NET_NFC_MESSAGE_SE_TYPE_CHANGED, (void *)¬i_se, sizeof(net_nfc_response_notify_t), NULL); + } + } + break; + + case NET_NFC_MESSAGE_GET_SE : + { + net_nfc_request_get_se_t *detail = (net_nfc_request_get_se_t *)req_msg; + + if (net_nfc_server_check_client_is_running(req_msg->client_fd)) + { + net_nfc_response_get_se_t resp = { 0 }; + + resp.length = sizeof(net_nfc_request_get_se_t); + resp.flags = detail->flags; + resp.trans_param = detail->trans_param; + resp.result = NET_NFC_OK; + resp.se_type = net_nfc_service_se_get_se_type(); + + net_nfc_send_response_msg(req_msg->client_fd, req_msg->request_type, (void *)&resp, sizeof(net_nfc_response_get_se_t), NULL); + } + } + break; + + case NET_NFC_MESSAGE_P2P_SEND : + { + net_nfc_request_p2p_send_t *exchanger = (net_nfc_request_p2p_send_t *)req_msg; + + if (net_nfc_server_is_target_connected(exchanger->handle)) + { + if (net_nfc_service_send_exchanger_msg(exchanger) != NET_NFC_OK) + { + DEBUG_SERVER_MSG("net_nfc_service_send_exchanger_msg is failed"); + + /*send result to client*/ + net_nfc_response_p2p_send_t resp_msg = { 0, }; + + resp_msg.handle = exchanger->handle; + resp_msg.result = NET_NFC_P2P_SEND_FAIL; + resp_msg.trans_param = (void *)exchanger->user_param; + + if (net_nfc_send_response_msg(req_msg->client_fd, req_msg->request_type, &resp_msg, sizeof(net_nfc_response_p2p_send_t), NULL) == true) + { + DEBUG_SERVER_MSG("send exchange failed message to client"); + } + } + } + else + { + net_nfc_response_p2p_send_t resp_msg = { 0, }; + + resp_msg.handle = exchanger->handle; + resp_msg.result = NET_NFC_TARGET_IS_MOVED_AWAY; + resp_msg.trans_param = (void *)exchanger->user_param; + + net_nfc_send_response_msg(req_msg->client_fd, req_msg->request_type, &resp_msg, sizeof(net_nfc_response_p2p_send_t), NULL); + } + } + break; + + case NET_NFC_MESSAGE_TRANSCEIVE : + { + net_nfc_request_transceive_t *detail = (net_nfc_request_transceive_t *)req_msg; + net_nfc_error_e result = NET_NFC_OK; + data_s *data = NULL; + + if (net_nfc_server_is_target_connected(detail->handle)) + { + net_nfc_transceive_info_s info; + + if (net_nfc_util_duplicate_data(&info.trans_data, &detail->info.trans_data) == true) + { + bool success; + + DEBUG_MSG("call transceive"); + if ((success = net_nfc_controller_transceive(detail->handle, &info, &data, &result)) == true) + { + if (data != NULL) + DEBUG_SERVER_MSG("trasceive data recieved [%d], Success = %d", data->length, success); + } + else + { + DEBUG_SERVER_MSG("trasceive is failed = [%d]", result); + } + net_nfc_util_free_data(&info.trans_data); + } + } + else + { + result = NET_NFC_TARGET_IS_MOVED_AWAY; + } + + if (net_nfc_server_check_client_is_running(req_msg->client_fd)) + { + net_nfc_response_transceive_t resp = { 0, }; + + resp.length = sizeof(net_nfc_response_transceive_t); + resp.flags = detail->flags; + resp.trans_param = detail->trans_param; + resp.result = result; + + if (result == NET_NFC_OK && data != NULL) + { + resp.data.length = data->length; + + DEBUG_SERVER_MSG("send response trans msg"); + net_nfc_send_response_msg(req_msg->client_fd, req_msg->request_type, (void *)&resp, sizeof(net_nfc_response_transceive_t), + data->buffer, data->length, NULL); + } + else + { + net_nfc_send_response_msg(req_msg->client_fd, req_msg->request_type, (void *)&resp, sizeof(net_nfc_response_transceive_t), NULL); + } + } + + if (data != NULL) + { + net_nfc_util_free_data(data); + _net_nfc_util_free_mem(data); + } + } + break; + + case NET_NFC_MESSAGE_MAKE_READ_ONLY_NDEF : + { + net_nfc_request_make_read_only_ndef_t *detail = (net_nfc_request_make_read_only_ndef_t *)req_msg; + net_nfc_error_e result = NET_NFC_OK; + + if (net_nfc_server_is_target_connected(detail->handle)) + { + net_nfc_controller_make_read_only_ndef(detail->handle, &result); + } + else + { + result = NET_NFC_TARGET_IS_MOVED_AWAY; + } + + if (net_nfc_server_check_client_is_running(req_msg->client_fd)) + { + net_nfc_response_make_read_only_ndef_t resp = { 0, }; + + resp.length = sizeof(net_nfc_response_make_read_only_ndef_t); + resp.flags = detail->flags; + resp.result = result; + resp.trans_param = detail->trans_param; + + net_nfc_send_response_msg(req_msg->client_fd, req_msg->request_type, (void *)&resp, sizeof(net_nfc_response_write_ndef_t), NULL); + } + } + break; + + case NET_NFC_MESSAGE_IS_TAG_CONNECTED : + { + net_nfc_request_is_tag_connected_t *detail = (net_nfc_request_is_tag_connected_t *)req_msg; + net_nfc_current_target_info_s* target_info = NULL; + + target_info = net_nfc_server_get_tag_info(); + if (net_nfc_server_check_client_is_running(req_msg->client_fd)) + { + net_nfc_response_is_tag_connected_t resp = { 0, }; + + resp.length = sizeof(net_nfc_response_is_tag_connected_t); + resp.flags = detail->flags; + resp.trans_param = detail->trans_param; + + if (target_info != NULL) + { + resp.result = NET_NFC_OK; + resp.devType = target_info->devType; + } + else + { + resp.result = NET_NFC_NOT_CONNECTED; + resp.devType = NET_NFC_UNKNOWN_TARGET; + } + + net_nfc_send_response_msg(req_msg->client_fd, req_msg->request_type, (void *)&resp, sizeof(net_nfc_response_is_tag_connected_t), NULL); + } + } + break; + + case NET_NFC_MESSAGE_GET_CURRENT_TAG_INFO : + { + net_nfc_response_get_current_tag_info_t resp = { 0, }; + net_nfc_request_get_current_tag_info_t *detail = (net_nfc_request_get_current_tag_info_t *)req_msg; + net_nfc_current_target_info_s *target_info = NULL; + net_nfc_error_e result = NET_NFC_OK; + + resp.length = sizeof(net_nfc_response_get_current_tag_info_t); + resp.flags = detail->flags; + resp.trans_param = detail->trans_param; + + target_info = net_nfc_server_get_tag_info(); + + if (target_info != NULL) + { + bool success = true; + data_s* recv_data = NULL; + + if (target_info->devType != NET_NFC_NFCIP1_TARGET && target_info->devType != NET_NFC_NFCIP1_INITIATOR) + { +#ifdef BROADCAST_MESSAGE + net_nfc_server_set_server_state(NET_NFC_TAG_CONNECTED); +#endif + DEBUG_SERVER_MSG("tag is connected"); + + uint8_t ndef_card_state = 0; + int max_data_size = 0; + int real_data_size = 0; + + if (net_nfc_controller_check_ndef(target_info->handle, &ndef_card_state, &max_data_size, &real_data_size, &result) == true) + { + resp.ndefCardState = ndef_card_state; + resp.maxDataSize = max_data_size; + resp.actualDataSize = real_data_size; + resp.is_ndef_supported = 1; + } + + resp.devType = target_info->devType; + resp.handle = target_info->handle; + resp.number_of_keys = target_info->number_of_keys; + + net_nfc_util_duplicate_data(&resp.target_info_values, &target_info->target_info_values); + + if (resp.is_ndef_supported) + { + if (net_nfc_controller_read_ndef(target_info->handle, &recv_data, &(resp.result)) == true) + { + DEBUG_SERVER_MSG("net_nfc_controller_read_ndef is success"); + + resp.raw_data.length = recv_data->length; + + success = net_nfc_send_response_msg(req_msg->client_fd, req_msg->request_type, (void *)&resp, sizeof(net_nfc_response_get_current_tag_info_t), + (void *)(resp.target_info_values.buffer), resp.target_info_values.length, + (void *)(recv_data->buffer), recv_data->length, NULL); + } + else + { + DEBUG_SERVER_MSG("net_nfc_controller_read_ndef is fail"); + + resp.raw_data.length = 0; + + success = net_nfc_send_response_msg(req_msg->client_fd, req_msg->request_type, (void *)&resp, sizeof(net_nfc_response_get_current_tag_info_t), + (void *)(resp.target_info_values.buffer), resp.target_info_values.length, NULL); + } + } + else + { + resp.raw_data.length = 0; + + success = net_nfc_send_response_msg(req_msg->client_fd, req_msg->request_type, (void *)&resp, sizeof(net_nfc_response_get_current_tag_info_t), + (void *)(resp.target_info_values.buffer), resp.target_info_values.length, NULL); + } + + net_nfc_util_free_data(&resp.target_info_values); + } + } + else + { + resp.result = NET_NFC_NOT_CONNECTED; + net_nfc_send_response_msg(req_msg->client_fd, req_msg->request_type, (void *)&resp, sizeof(net_nfc_response_get_current_tag_info_t), NULL); + } + } + break; + + case NET_NFC_MESSAGE_GET_CURRENT_TARGET_HANDLE : + { + net_nfc_request_get_current_target_handle_t *detail = (net_nfc_request_get_current_target_handle_t *)req_msg; + net_nfc_current_target_info_s *target_info = NULL; + + target_info = net_nfc_server_get_tag_info(); + if (net_nfc_server_check_client_is_running(req_msg->client_fd)) + { + net_nfc_response_get_current_target_handle_t resp = { 0, }; + + resp.length = sizeof(net_nfc_response_get_current_target_handle_t); + resp.flags = detail->flags; + resp.trans_param = detail->trans_param; + + if (target_info != NULL) + { + resp.handle = target_info->handle; + resp.devType = target_info->devType; + resp.result = NET_NFC_OK; + } + else + { + resp.result = NET_NFC_NOT_CONNECTED; + } + + net_nfc_send_response_msg(req_msg->client_fd, req_msg->request_type, (void *)&resp, sizeof(net_nfc_response_get_current_target_handle_t), NULL); + } + } + break; + + case NET_NFC_GET_SERVER_STATE : + { + if (net_nfc_server_check_client_is_running(req_msg->client_fd)) + { + net_nfc_response_get_server_state_t resp = { 0, }; + + resp.length = sizeof(net_nfc_response_get_server_state_t); + resp.flags = req_msg->flags; + resp.state = net_nfc_server_get_server_state(); + resp.result = NET_NFC_OK; + + net_nfc_send_response_msg(req_msg->client_fd, req_msg->request_type, (void *)&resp, sizeof(net_nfc_response_get_server_state_t), NULL); + } + } + break; + + case NET_NFC_MESSAGE_READ_NDEF : + { + net_nfc_request_read_ndef_t *detail = (net_nfc_request_read_ndef_t*)req_msg; + net_nfc_error_e result = NET_NFC_OK; + data_s *data = NULL; + bool success = false; + + if (net_nfc_server_is_target_connected(detail->handle)) + { + success = net_nfc_controller_read_ndef(detail->handle, &data, &result); + } + else + { + result = NET_NFC_TARGET_IS_MOVED_AWAY; + } + + if (net_nfc_server_check_client_is_running(req_msg->client_fd)) + { + net_nfc_response_read_ndef_t resp = { 0, }; + + resp.length = sizeof(net_nfc_response_read_ndef_t); + resp.flags = detail->flags; + resp.result = result; + resp.trans_param = detail->trans_param; + + if (success) + { + resp.data.length = data->length; + net_nfc_send_response_msg(req_msg->client_fd, req_msg->request_type, (void *)&resp, sizeof(net_nfc_response_read_ndef_t), + data->buffer, data->length, NULL); + } + else + { + resp.data.length = 0; + resp.data.buffer = NULL; + net_nfc_send_response_msg(req_msg->client_fd, req_msg->request_type, (void *)&resp, sizeof(net_nfc_response_read_ndef_t), NULL); + } + } + + if (data != NULL) + { + net_nfc_util_free_data(data); + _net_nfc_util_free_mem(data); + } + } + break; + + case NET_NFC_MESSAGE_WRITE_NDEF : + { + net_nfc_request_write_ndef_t *detail = (net_nfc_request_write_ndef_t *)req_msg; + net_nfc_error_e result = NET_NFC_OK; + + if (net_nfc_server_is_target_connected(detail->handle)) + { + data_s data = { NULL, 0 }; + + if (net_nfc_util_duplicate_data(&data, &detail->data) == true) + { + net_nfc_controller_write_ndef(detail->handle, &data, &result); + + net_nfc_util_free_data(&data); + } + else + { + result = NET_NFC_ALLOC_FAIL; + } + } + else + { + result = NET_NFC_TARGET_IS_MOVED_AWAY; + } + + if (net_nfc_server_check_client_is_running(req_msg->client_fd)) + { + net_nfc_response_write_ndef_t resp = { 0, }; + + resp.length = sizeof(net_nfc_response_write_ndef_t); + resp.flags = detail->flags; + resp.result = result; + resp.trans_param = detail->trans_param; + + net_nfc_send_response_msg(req_msg->client_fd, req_msg->request_type, (void *)&resp, sizeof(net_nfc_response_write_ndef_t), NULL); + } + } + break; + + case NET_NFC_MESSAGE_FORMAT_NDEF : + { + net_nfc_request_format_ndef_t *detail = (net_nfc_request_format_ndef_t *)req_msg; + net_nfc_error_e result = NET_NFC_OK; + + if (net_nfc_server_is_target_connected(detail->handle)) + { + data_s data = { NULL, 0 }; + + if (net_nfc_util_duplicate_data(&data, &detail->key) == true) + { + net_nfc_controller_format_ndef(detail->handle, &data, &result); + net_nfc_util_free_data(&data); + } + else + { + result = NET_NFC_ALLOC_FAIL; + } + } + else + { + result = NET_NFC_TARGET_IS_MOVED_AWAY; + } + + if (net_nfc_server_check_client_is_running(req_msg->client_fd)) + { + net_nfc_response_format_ndef_t resp = { 0 }; + + resp.length = sizeof(net_nfc_response_format_ndef_t); + resp.flags = detail->flags; + resp.result = result; + resp.trans_param = detail->trans_param; + + net_nfc_send_response_msg(req_msg->client_fd, req_msg->request_type, (void *)&resp, sizeof(net_nfc_response_format_ndef_t), NULL); + } + } + break; + + case NET_NFC_MESSAGE_SIM_TEST : + { + net_nfc_request_test_t *detail = (net_nfc_request_test_t *)req_msg; + net_nfc_error_e result = NET_NFC_OK; + + if (net_nfc_controller_sim_test(&result) == true) + { + DEBUG_SERVER_MSG("net_nfc_controller_sim_test Result [SUCCESS]"); + } + else + { + DEBUG_SERVER_MSG("net_nfc_controller_sim_test Result [ERROR1]"); + } + + if (net_nfc_server_check_client_is_running(req_msg->client_fd)) + { + net_nfc_response_test_t resp = { 0, }; + + resp.length = sizeof(net_nfc_response_test_t); + resp.flags = detail->flags; + resp.result = result; + resp.trans_param = detail->trans_param; + + DEBUG_SERVER_MSG("SEND RESPONSE!!"); + net_nfc_send_response_msg(req_msg->client_fd, req_msg->request_type, (void *)&resp, sizeof(net_nfc_response_test_t), NULL); + } + } + break; + + case NET_NFC_MESSAGE_GET_FIRMWARE_VERSION : + { + net_nfc_error_e result = NET_NFC_OK; + data_s *data = NULL; + + if (net_nfc_controller_get_firmware_version(&data, &result) == true) + { + DEBUG_SERVER_MSG("net_nfc_controller_update_firmware Result [SUCCESS]"); + + } + else + { + DEBUG_ERR_MSG("net_nfc_controller_update_firmware Result [ERROR3]"); + } + + if (net_nfc_server_check_client_is_running(req_msg->client_fd)) + { + net_nfc_response_firmware_version_t resp = { 0, }; + + resp.length = sizeof(net_nfc_response_firmware_version_t); + resp.flags = req_msg->flags; + resp.result = result; + resp.data.length = data->length; + + net_nfc_send_response_msg(req_msg->client_fd, req_msg->request_type, (void *)&resp, sizeof(net_nfc_response_firmware_version_t), (void *)data->buffer, resp.data.length, NULL); + } + + net_nfc_util_free_data(data); + } + break; + + case NET_NFC_MESSAGE_PRBS_TEST : + { + net_nfc_request_test_t *detail = (net_nfc_request_test_t *)req_msg; + net_nfc_error_e result = NET_NFC_OK; + uint32_t local_tech = 0; + uint32_t local_rate = 0; + + local_tech = detail->tech; + local_rate = detail->rate; + + DEBUG_SERVER_MSG("NET_NFC_MESSAGE_PRBS_TEST local_tech [%d]\n", local_tech); + DEBUG_SERVER_MSG("NET_NFC_MESSAGE_PRBS_TEST local_rate [%d]\n", local_rate); + + if (net_nfc_controller_prbs_test(&result, local_tech, local_rate) == true) + { + DEBUG_SERVER_MSG("net_nfc_controller_prbs_test Result [SUCCESS]"); + } + else + { + DEBUG_ERR_MSG("net_nfc_controller_prbs_test Result [ERROR3]"); + } + + if (net_nfc_server_check_client_is_running(req_msg->client_fd)) + { + net_nfc_response_test_t resp = { 0, }; + + resp.length = sizeof(net_nfc_response_test_t); + resp.flags = detail->flags; + resp.result = result; + resp.trans_param = detail->trans_param; + + DEBUG_SERVER_MSG("SEND RESPONSE!!"); + net_nfc_send_response_msg(req_msg->client_fd, req_msg->request_type, (void *)&resp, sizeof(net_nfc_response_test_t), NULL); + } + } + break; + + case NET_NFC_MESSAGE_SET_EEDATA : + { + net_nfc_request_eedata_register_t *detail = (net_nfc_request_eedata_register_t *)req_msg; + net_nfc_error_e result = NET_NFC_OK; + uint32_t local_mode = 0; + uint32_t local_reg_id = 0; + data_s data = { NULL, 0 }; + + local_mode = detail->mode; + local_reg_id = detail->reg_id; + + DEBUG_SERVER_MSG("NET_NFC_MESSAGE_SET_EEDATA local_mode [%d]\n", local_mode); + DEBUG_SERVER_MSG("NET_NFC_MESSAGE_SET_EEDATA local_reg_id [%d]\n", local_reg_id); + + if (net_nfc_util_duplicate_data(&data, &detail->data) == true) + { + if (net_nfc_controller_eedata_register_set(&result, local_mode, local_reg_id, &data) == true) + { + DEBUG_SERVER_MSG("net_nfc_controller_eedata_register_set Result [SUCCESS]"); + } + else + { + DEBUG_ERR_MSG("net_nfc_controller_eedata_register_set Result [ERROR3]"); + } + net_nfc_util_free_data(&data); + + if (net_nfc_server_check_client_is_running(req_msg->client_fd)) + { + net_nfc_response_test_t resp = { 0, }; + + resp.length = sizeof(net_nfc_response_test_t); + resp.flags = detail->flags; + resp.result = result; + resp.trans_param = detail->trans_param; + + DEBUG_SERVER_MSG("SEND RESPONSE!!"); + net_nfc_send_response_msg(req_msg->client_fd, req_msg->request_type, (void *)&resp, sizeof(net_nfc_response_test_t), NULL); + } + } + } + break; + + case NET_NFC_MESSAGE_SERVICE_DEINIT : + { + net_nfc_error_e result; + + result = net_nfc_service_se_change_se(SECURE_ELEMENT_TYPE_INVALID); + + /* release access control instance */ + net_nfc_util_access_control_release(); + + net_nfc_server_free_current_tag_info(); + + if (net_nfc_controller_deinit() == TRUE) + { + DEBUG_SERVER_MSG("net_nfc_controller_deinit success [%d]", result); + + /*vconf off*/ + if (vconf_set_bool(VCONFKEY_NFC_STATE, FALSE) != 0) + { + DEBUG_ERR_MSG("vconf_set_bool failed"); + } + + net_nfc_response_test_t resp = { 0, }; + + resp.length = sizeof(net_nfc_response_test_t); + resp.flags = req_msg->flags; + resp.result = NET_NFC_OK; + resp.trans_param = (void *)req_msg->user_param; + + net_nfc_broadcast_response_msg(req_msg->request_type, (void *)&resp, sizeof(net_nfc_response_test_t), NULL); + } + else + { + DEBUG_SERVER_MSG("net_nfc_controller_deinit failed"); + + if (net_nfc_server_check_client_is_running(req_msg->client_fd)) + { + net_nfc_response_test_t resp = { 0, }; + + resp.length = sizeof(net_nfc_response_test_t); + resp.flags = req_msg->flags; + resp.result = NET_NFC_UNKNOWN_ERROR; + resp.trans_param = (void *)req_msg->user_param; + + net_nfc_send_response_msg(req_msg->client_fd, req_msg->request_type, (void *)&resp, sizeof(net_nfc_response_test_t), NULL); + } + } + } + break; + + case NET_NFC_MESSAGE_SERVICE_INIT : + { + net_nfc_error_e result; + + if (net_nfc_controller_init(&result) == true) + { + net_nfc_llcp_config_info_s config = { 128, 1, 100, 0 }; + + if (net_nfc_controller_register_listener(net_nfc_service_target_detected_cb, net_nfc_service_se_transaction_cb, net_nfc_service_llcp_event_cb, &result) == true) + { + DEBUG_SERVER_MSG("net_nfc_controller_register_listener Success!!"); + } + else + { + DEBUG_ERR_MSG("net_nfc_controller_register_listener failed [%d]", result); + } + + if (net_nfc_controller_llcp_config(&config, &result) == true) + { + /*We need to check the stack that supports the llcp or not.*/ + DEBUG_SERVER_MSG("llcp is enabled"); + } + else + { + DEBUG_ERR_MSG("net_nfc_controller_llcp_config failed [%d]", result); + } + + result = net_nfc_service_se_change_se(SECURE_ELEMENT_TYPE_UICC); + + if (net_nfc_controller_confiure_discovery(NET_NFC_DISCOVERY_MODE_CONFIG, NET_NFC_ALL_ENABLE, &result) == true) + { + DEBUG_SERVER_MSG("now, nfc is ready"); + } + else + { + DEBUG_ERR_MSG("net_nfc_controller_confiure_discovery failed [%d]", result); + } + + /* initialize access control instance */ + net_nfc_util_access_control_initialize(); + + /*Send the Init Success Response Msg*/ + { + net_nfc_response_test_t resp = { 0, }; + + DEBUG_SERVER_MSG("net_nfc_controller_init success [%d]", result); + + resp.length = sizeof(net_nfc_response_test_t); + resp.flags = req_msg->flags; + resp.result = NET_NFC_OK; + resp.trans_param = (void *)req_msg->user_param; + + /*vconf on*/ + if (vconf_set_bool(VCONFKEY_NFC_STATE, TRUE) != 0) + { + DEBUG_ERR_MSG("vconf_set_bool failed"); + } + + net_nfc_broadcast_response_msg(req_msg->request_type, (void *)&resp, sizeof(net_nfc_response_test_t), NULL); + } + } + else + { + DEBUG_ERR_MSG("net_nfc_controller_init failed [%d]", result); + + if (net_nfc_server_check_client_is_running(req_msg->client_fd)) + { + net_nfc_response_test_t resp = { 0, }; + + resp.length = sizeof(net_nfc_response_test_t); + resp.flags = req_msg->flags; + resp.result = result; + resp.trans_param = (void *)req_msg->user_param; + + net_nfc_send_response_msg(req_msg->client_fd, req_msg->request_type, (void *)&resp, sizeof(net_nfc_response_test_t), NULL); + } + } + } + break; + + case NET_NFC_MESSAGE_SERVICE_STANDALONE_TARGET_DETECTED : + { +#ifndef BROADCAST_MESSAGE + net_nfc_service_standalone_mode_target_detected(req_msg); +#endif + } + break; + + case NET_NFC_MESSAGE_SERVICE_RESTART_POLLING_LOOP : + { + net_nfc_error_e result = NET_NFC_OK; + int pm_state = 0; + int set_config = 0; + net_nfc_request_msg_t *discovery_req = (net_nfc_request_msg_t *)req_msg; + + pm_state = discovery_req->user_param; + + DEBUG_SERVER_MSG("NET_NFC_MESSAGE_SERVICE_RESTART_POLLING_LOOP PM State = [%d]", pm_state); + + if (pm_state == 1) + { + set_config = NET_NFC_ALL_ENABLE; + } + else if (pm_state == 3) + { + set_config = NET_NFC_ALL_DISABLE; + } + else + { + DEBUG_SERVER_MSG("Do not anything!!"); + } + + //if (net_nfc_controller_confiure_discovery(NET_NFC_DISCOVERY_MODE_RESUME, NET_NFC_ALL_ENABLE, &result) == true) + if (net_nfc_controller_confiure_discovery(NET_NFC_DISCOVERY_MODE_CONFIG, set_config, &result) == true) + { + DEBUG_SERVER_MSG("now, nfc polling loop is running again"); + } + } + break; + + case NET_NFC_MESSAGE_SE_START_TRANSACTION : + { + net_nfc_service_se_transaction_receive(req_msg); + } + break; + + case NET_NFC_MESSAGE_SERVICE_LLCP_ACCEPT : + { + net_nfc_service_llcp_process_accept(req_msg); + } + break; + + case NET_NFC_MESSAGE_SERVICE_LLCP_DEACTIVATED : + { + net_nfc_service_llcp_disconnect_target(req_msg); + } + break; + + case NET_NFC_MESSAGE_SERVICE_LLCP_SOCKET_ERROR : + { + net_nfc_service_llcp_process_socket_error(req_msg); + } + break; + + case NET_NFC_MESSAGE_SERVICE_LLCP_SOCKET_ACCEPTED_ERROR : + { + net_nfc_service_llcp_process_accepted_socket_error(req_msg); + } + break; + + case NET_NFC_MESSAGE_SERVICE_LLCP_SEND : + { + net_nfc_service_llcp_process_send_socket(req_msg); + } + break; + + case NET_NFC_MESSAGE_SERVICE_LLCP_SEND_TO : + { + net_nfc_service_llcp_process_send_to_socket(req_msg); + } + break; + + case NET_NFC_MESSAGE_SERVICE_LLCP_RECEIVE : + { + net_nfc_service_llcp_process_receive_socket(req_msg); + } + break; + + case NET_NFC_MESSAGE_SERVICE_LLCP_RECEIVE_FROM : + { + net_nfc_service_llcp_process_receive_from_socket(req_msg); + } + break; + + case NET_NFC_MESSAGE_SERVICE_LLCP_CONNECT : + { + net_nfc_service_llcp_process_connect_socket(req_msg); + } + break; + + case NET_NFC_MESSAGE_SERVICE_LLCP_CONNECT_SAP : + { + net_nfc_service_llcp_process_connect_sap_socket(req_msg); + } + break; + + case NET_NFC_MESSAGE_SERVICE_LLCP_DISCONNECT : + { + net_nfc_service_llcp_process_disconnect_socket(req_msg); + } + break; + + case NET_NFC_MESSAGE_SERVICE_SE : + { + net_nfc_request_set_se_t *detail = (net_nfc_request_set_se_t *)req_msg; + net_nfc_error_e result = NET_NFC_OK; + int mode; + + mode = (int)detail->se_type; + + if (mode == NET_NFC_SE_CMD_UICC_ON) + { + /*turn on UICC*/ + net_nfc_controller_set_secure_element_mode(SECURE_ELEMENT_TYPE_UICC, SECURE_ELEMENT_VIRTUAL_MODE, &result); + + /*turn off ESE*/ + net_nfc_controller_set_secure_element_mode(SECURE_ELEMENT_TYPE_ESE, SECURE_ELEMENT_OFF_MODE, &result); + } + else if (mode == NET_NFC_SE_CMD_ESE_ON) + { + /*turn off UICC*/ + net_nfc_controller_set_secure_element_mode(SECURE_ELEMENT_TYPE_UICC, SECURE_ELEMENT_OFF_MODE, &result); + + /*turn on ESE*/ + net_nfc_controller_set_secure_element_mode(SECURE_ELEMENT_TYPE_ESE, SECURE_ELEMENT_VIRTUAL_MODE, &result); + } + else if (mode == NET_NFC_SE_CMD_ALL_OFF) + { + /*turn off both*/ + net_nfc_controller_set_secure_element_mode(SECURE_ELEMENT_TYPE_UICC, SECURE_ELEMENT_OFF_MODE, &result); + + /*turn on ESE*/ + net_nfc_controller_set_secure_element_mode(SECURE_ELEMENT_TYPE_ESE, SECURE_ELEMENT_OFF_MODE, &result); + } + else + { + /*turn off both*/ + net_nfc_controller_set_secure_element_mode(SECURE_ELEMENT_TYPE_UICC, SECURE_ELEMENT_VIRTUAL_MODE, &result); + + /*turn on ESE*/ + net_nfc_controller_set_secure_element_mode(SECURE_ELEMENT_TYPE_ESE, SECURE_ELEMENT_VIRTUAL_MODE, &result); + } + } + break; + + case NET_NFC_MESSAGE_SERVICE_TERMINATION : + { + net_nfc_service_termination(req_msg); + } + break; + + case NET_NFC_MESSAGE_SERVICE_SLAVE_TARGET_DETECTED : + { + net_nfc_service_slave_mode_target_detected(req_msg); + } + break; + + case NET_NFC_MESSAGE_SERVICE_SLAVE_ESE_DETECTED : + { + net_nfc_service_se_detected(req_msg); + } + break; + + case NET_NFC_MESSAGE_LLCP_LISTEN : + { + net_nfc_request_listen_socket_t *detail = (net_nfc_request_listen_socket_t *)req_msg; + net_nfc_response_llcp_socket_error_t *error = NULL; + net_nfc_error_e result = NET_NFC_OK; + bool success = false; + + _net_nfc_util_alloc_mem(error, sizeof (net_nfc_response_llcp_socket_error_t)); + if (error == NULL) + { + DEBUG_SERVER_MSG("ERROR: allocation is failed"); + break; + } + + error->length = sizeof(net_nfc_response_llcp_socket_error_t); + error->client_socket = detail->client_socket; + error->handle = detail->handle; + + success = net_nfc_controller_llcp_create_socket(&(detail->oal_socket), detail->type, detail->miu, detail->rw, &result, error); + if (success == true) + { + error->oal_socket = detail->oal_socket; + success = net_nfc_controller_llcp_bind(detail->oal_socket, detail->sap, &result); + } + else + { + _net_nfc_util_free_mem(error); + } + + if (success == true) + { + DEBUG_SERVER_MSG("OAL socket in Listen :%d", detail->oal_socket); + success = net_nfc_controller_llcp_listen(detail->handle, detail->service_name.buffer, detail->oal_socket, &result, error); + } + + if (net_nfc_server_check_client_is_running(req_msg->client_fd)) + { + net_nfc_response_listen_socket_t resp = { 0 }; + + resp.length = sizeof(net_nfc_response_listen_socket_t); + resp.flags = detail->flags; + resp.result = result; + resp.oal_socket = detail->oal_socket; + resp.client_socket = detail->client_socket; + resp.trans_param = detail->trans_param; + + net_nfc_send_response_msg(req_msg->client_fd, req_msg->request_type, (void *)&resp, sizeof(net_nfc_response_listen_socket_t), NULL); + } + } + break; + + case NET_NFC_MESSAGE_LLCP_CONNECT : + { + net_nfc_request_connect_socket_t *detail = (net_nfc_request_connect_socket_t *)req_msg; + net_nfc_response_connect_socket_t *resp = NULL; + net_nfc_response_llcp_socket_error_t *error = NULL; + bool success = false; + + _net_nfc_util_alloc_mem(error, sizeof (net_nfc_response_llcp_socket_error_t)); + if (error == NULL) + { + DEBUG_SERVER_MSG("ERROR: invalid detail info or allocation is failed"); + break; + } + + _net_nfc_util_alloc_mem(resp, sizeof (net_nfc_response_connect_socket_t)); + if (resp == NULL) + { + DEBUG_SERVER_MSG("ERROR: invalid detail info or allocation is failed"); + _net_nfc_util_free_mem(error); + break; + } + + error->length = sizeof(net_nfc_response_llcp_socket_error_t); + error->client_socket = detail->client_socket; + error->handle = detail->handle; + + resp->length = sizeof(net_nfc_response_connect_socket_t); + resp->flags = detail->flags; + resp->result = NET_NFC_IPC_FAIL; + + success = net_nfc_controller_llcp_create_socket(&(detail->oal_socket), detail->type, detail->miu, detail->rw, &(resp->result), error); + if (success == true) + { + error->oal_socket = resp->oal_socket = detail->oal_socket; + DEBUG_SERVER_MSG("connect client socket [%d]", detail->client_socket); + resp->client_socket = detail->client_socket; + resp->trans_param = detail->trans_param; + + success = net_nfc_controller_llcp_connect_by_url(detail->handle, detail->oal_socket, detail->service_name.buffer, &(resp->result), resp); + if (success == false) + { + DEBUG_ERR_MSG("connect client socket is failed"); + + net_nfc_controller_llcp_socket_close(resp->oal_socket, &(resp->result)); + + if (net_nfc_server_check_client_is_running(req_msg->client_fd)) + { + net_nfc_send_response_msg(req_msg->client_fd, req_msg->request_type, (void *)resp, sizeof(net_nfc_response_connect_socket_t), NULL); + } + _net_nfc_util_free_mem(resp); + } + } + else + { + if (net_nfc_server_check_client_is_running(req_msg->client_fd)) + { + net_nfc_send_response_msg(req_msg->client_fd, req_msg->request_type, (void *)resp, sizeof(net_nfc_response_connect_socket_t), NULL); + } + + _net_nfc_util_free_mem(error); + _net_nfc_util_free_mem(resp); + } + } + break; + + case NET_NFC_MESSAGE_LLCP_CONNECT_SAP : + { + net_nfc_request_connect_sap_socket_t *detail = (net_nfc_request_connect_sap_socket_t *)req_msg; + net_nfc_response_connect_sap_socket_t *resp = NULL; + bool success = false; + + _net_nfc_util_alloc_mem(resp, sizeof(net_nfc_response_connect_sap_socket_t)); + if (resp == NULL) + { + DEBUG_SERVER_MSG("ERROR: allocation is failed"); + break; + } + + resp->length = sizeof(net_nfc_response_connect_sap_socket_t); + resp->flags = detail->flags; + resp->result = NET_NFC_IPC_FAIL; + + success = net_nfc_controller_llcp_create_socket(&(detail->oal_socket), detail->type, detail->miu, detail->rw, &(resp->result), NULL); + if (success == true) + { + resp->oal_socket = detail->oal_socket; + resp->client_socket = detail->client_socket; + resp->trans_param = detail->trans_param; + + success = net_nfc_controller_llcp_connect(detail->handle, detail->oal_socket, detail->sap, &(resp->result), resp); + } + + if (success == false) + { + if (net_nfc_server_check_client_is_running(req_msg->client_fd)) + { + net_nfc_send_response_msg(req_msg->client_fd, req_msg->request_type, (void *)resp, sizeof(net_nfc_response_connect_sap_socket_t), NULL); + } + _net_nfc_util_free_mem(resp); + } + } + break; + + case NET_NFC_MESSAGE_LLCP_SEND : + { + net_nfc_request_send_socket_t *detail = (net_nfc_request_send_socket_t *)req_msg; + data_s data = { NULL, 0 }; + + if (net_nfc_util_duplicate_data(&data, &detail->data) == true) + { + net_nfc_response_send_socket_t *resp = NULL; + + _net_nfc_util_alloc_mem(resp, sizeof (net_nfc_response_send_socket_t)); + if (resp != NULL) + { + resp->length = sizeof(net_nfc_response_send_socket_t); + resp->flags = detail->flags; + resp->result = NET_NFC_IPC_FAIL; + resp->client_socket = detail->client_socket; + resp->trans_param = detail->trans_param; + + if (net_nfc_controller_llcp_send(detail->handle, detail->oal_socket, &data, &(resp->result), resp) == false) + { + if (net_nfc_server_check_client_is_running(req_msg->client_fd)) + { + net_nfc_send_response_msg(req_msg->client_fd, req_msg->request_type, (void *)resp, sizeof(net_nfc_response_send_socket_t), NULL); + } + _net_nfc_util_free_mem(resp); + } + } + + net_nfc_util_free_data(&data); + } + } + break; + + case NET_NFC_MESSAGE_LLCP_RECEIVE : + { + net_nfc_request_receive_socket_t *detail = (net_nfc_request_receive_socket_t *)req_msg; + net_nfc_response_receive_socket_t *resp = NULL; + + _net_nfc_util_alloc_mem(resp, sizeof (net_nfc_response_receive_socket_t)); + if (resp == NULL) + { + DEBUG_SERVER_MSG("ERROR: allocation is failed"); + break; + } + + resp->length = sizeof(net_nfc_response_receive_socket_t); + resp->flags = detail->flags; + resp->result = NET_NFC_IPC_FAIL; + resp->client_socket = detail->client_socket; + resp->trans_param = detail->trans_param; + resp->data.length = detail->req_length; + _net_nfc_util_alloc_mem(resp->data.buffer, detail->req_length); + if (resp->data.buffer == NULL) + { + DEBUG_SERVER_MSG("ERROR: allocation is failed"); + _net_nfc_util_free_mem(resp); + break; + } + + if (net_nfc_controller_llcp_recv(detail->handle, detail->oal_socket, &(resp->data), &(resp->result), resp) == false) + { + if (net_nfc_server_check_client_is_running(req_msg->client_fd)) + { + net_nfc_send_response_msg(req_msg->client_fd, req_msg->request_type, (void *)resp, sizeof(net_nfc_response_receive_socket_t), NULL); + } + _net_nfc_util_free_mem(resp->data.buffer); + _net_nfc_util_free_mem(resp); + } + } + break; + + case NET_NFC_MESSAGE_SERVICE_LLCP_CLOSE : + { + net_nfc_request_close_socket_t *detail = (net_nfc_request_close_socket_t *)req_msg; + net_nfc_error_e result = NET_NFC_OK; + + DEBUG_SERVER_MSG("socket close :: NET_NFC_MESSAGE_SERVICE_LLCP_CLOSE"); + net_nfc_controller_llcp_socket_close(detail->oal_socket, &result); + + if (net_nfc_server_check_client_is_running(req_msg->client_fd)) + { + net_nfc_response_close_socket_t resp = { 0, }; + + resp.length = sizeof(net_nfc_response_close_socket_t); + resp.flags = detail->flags; + resp.result = result; + resp.client_socket = detail->client_socket; + resp.trans_param = detail->trans_param; + + net_nfc_send_response_msg(req_msg->client_fd, req_msg->request_type, (void *)&resp, sizeof(net_nfc_response_close_socket_t), NULL); + } + } + break; + + case NET_NFC_MESSAGE_LLCP_DISCONNECT : /* change resp to local variable. if there is some problem, check this first. */ + { + net_nfc_request_disconnect_socket_t *detail = (net_nfc_request_disconnect_socket_t *)req_msg; + net_nfc_request_disconnect_socket_t *context = NULL; + net_nfc_error_e result = NET_NFC_OK; + + context = _net_nfc_dispatcher_copy_message(detail); + if (context == NULL) + { + DEBUG_ERR_MSG("alloc failed"); + break; + } + + if (net_nfc_controller_llcp_disconnect(detail->handle, detail->oal_socket, &result, &context) == false) + { + if (net_nfc_server_check_client_is_running(req_msg->client_fd)) + { + net_nfc_response_disconnect_socket_t resp = { 0, }; + + resp.length = sizeof(net_nfc_response_disconnect_socket_t); + resp.flags = detail->flags; + resp.result = result; + resp.client_socket = detail->client_socket; + resp.trans_param = detail->trans_param; + + net_nfc_send_response_msg(req_msg->client_fd, req_msg->request_type, (void *)&resp, sizeof(net_nfc_response_disconnect_socket_t), NULL); + } + + _net_nfc_util_free_mem(context); + } + + } + break; + + case NET_NFC_MESSAGE_LLCP_ACCEPTED : + { + net_nfc_request_accept_socket_t *detail = (net_nfc_request_accept_socket_t *)req_msg; + net_nfc_error_e result = NET_NFC_OK; + + net_nfc_controller_llcp_accept(detail->incomming_socket, &result); + + if (net_nfc_server_check_client_is_running(req_msg->client_fd)) + { + net_nfc_response_accept_socket_t resp = { 0, }; + + resp.length = sizeof(net_nfc_response_accept_socket_t); + resp.flags = detail->flags; + resp.trans_param = detail->trans_param; + resp.result = result; + resp.client_socket = detail->client_socket; + + net_nfc_send_response_msg(req_msg->client_fd, req_msg->request_type, (void *)&resp, sizeof(net_nfc_response_accept_socket_t), NULL); + } + } + break; + + case NET_NFC_MESSAGE_LLCP_CONFIG : + { + net_nfc_request_config_llcp_t *detail = (net_nfc_request_config_llcp_t *)req_msg; + net_nfc_error_e result = NET_NFC_OK; + + net_nfc_controller_llcp_config(&(detail->config), &result); + + if (net_nfc_server_check_client_is_running(detail->client_fd)) + { + net_nfc_response_config_llcp_t resp = { 0, }; + + resp.length = sizeof(net_nfc_response_config_llcp_t); + resp.flags = detail->flags; + resp.trans_param = detail->trans_param; + resp.result = result; + + net_nfc_send_response_msg(req_msg->client_fd, req_msg->request_type, (void *)&resp, sizeof(net_nfc_response_config_llcp_t), NULL); + } + } + break; + + case NET_NFC_MESSAGE_CONNECTION_HANDOVER : + { + net_nfc_request_connection_handover_t *detail = (net_nfc_request_connection_handover_t *)req_msg; + net_nfc_error_e result = NET_NFC_OK; + + net_nfc_request_msg_t *param = NULL; + + if ((param = _net_nfc_dispatcher_copy_message(detail)) == NULL) + { + DEBUG_ERR_MSG("alloc failed"); + break; + } + + if ((result = net_nfc_service_llcp_handover_send_request_msg((net_nfc_request_connection_handover_t *)param)) != NET_NFC_OK) + { + if (net_nfc_server_check_client_is_running(req_msg->client_fd)) + { + net_nfc_response_connection_handover_t resp = { 0, }; + + resp.length = sizeof(net_nfc_response_connection_handover_t); + resp.flags = detail->flags; + resp.user_param = detail->user_param; + resp.result = result; + resp.event = NET_NFC_OPERATION_FAIL; + resp.type = NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN; + + net_nfc_send_response_msg(req_msg->client_fd, req_msg->request_type, (void *)&resp, sizeof(net_nfc_response_connection_handover_t), NULL); + } + } + + _net_nfc_util_free_mem(param); + } + break; + + case NET_NFC_MESSAGE_SERVICE_WATCH_DOG : + { + net_nfc_service_watch_dog(req_msg); + continue; + } + break; + + default : + break; + } + + /*need to free req_msg*/ + _net_nfc_util_free_mem(req_msg); + } + + return (void *)NULL; +} diff --git a/src/manager/net_nfc_server_ipc.c b/src/manager/net_nfc_server_ipc.c new file mode 100755 index 0000000..fb8a607 --- /dev/null +++ b/src/manager/net_nfc_server_ipc.c @@ -0,0 +1,825 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "vconf.h" +#ifdef SECURITY_SERVER +#include +#endif + +#include "net_nfc_typedef_private.h" +#include "net_nfc_debug_private.h" +#include "net_nfc_util_defines.h" +#include "net_nfc_util_private.h" +#include "net_nfc_util_ipc.h" +#include "net_nfc_server_ipc_private.h" +#include "net_nfc_server_dispatcher_private.h" +#include "net_nfc_controller_private.h" +#include "net_nfc_manager_util_private.h" +#include "net_nfc_server_context_private.h" + +///////////////////////////// + +/* static variable */ +#ifdef SECURITY_SERVER +static char *cookies = NULL; +static int cookies_size = 0; +static gid_t gid = 0; +#endif + +static pthread_mutex_t g_server_socket_lock = PTHREAD_MUTEX_INITIALIZER; +static net_nfc_server_info_t g_server_info = { 0, }; + +///////////////// + +/*define static function*/ + +static gboolean net_nfc_server_ipc_callback_func(GIOChannel* channel, GIOCondition condition, gpointer data); +static bool net_nfc_server_read_client_request(int client_sock_fd, net_nfc_error_e* result); +static bool net_nfc_server_process_client_connect_request(); + +///////////////////////// + +bool net_nfc_server_set_server_state(uint32_t state) +{ + pthread_mutex_lock(&g_server_socket_lock); + + if (state == NET_NFC_SERVER_IDLE) + g_server_info.state &= NET_NFC_SERVER_IDLE; + else + g_server_info.state |= state; + + pthread_mutex_unlock(&g_server_socket_lock); + + return true; +} + +bool net_nfc_server_unset_server_state(uint32_t state) +{ + pthread_mutex_lock(&g_server_socket_lock); + + g_server_info.state &= ~state; + + pthread_mutex_unlock(&g_server_socket_lock); + + return true; +} + +uint32_t net_nfc_server_get_server_state() +{ + return g_server_info.state; +} + +bool net_nfc_server_ipc_initialize() +{ + int result = 0; + + /* initialize server context */ + g_server_info.server_src_id = 0; + g_server_info.server_channel = (GIOChannel *)NULL; + g_server_info.server_sock_fd = -1; + g_server_info.state = NET_NFC_SERVER_IDLE; + g_server_info.target_info = NULL; + /////////////////////////////// + +#ifdef USE_UNIX_DOMAIN + struct sockaddr_un saddrun_rv; + + g_server_info.server_sock_fd = socket(AF_UNIX, SOCK_STREAM, 0); + if (g_server_info.server_sock_fd == -1) + { + DEBUG_SERVER_MSG("get socket is failed"); + return false; + } + + net_nfc_util_set_non_block_socket(g_server_info.server_sock_fd); + + result = remove(NET_NFC_SERVER_DOMAIN); + + memset(&saddrun_rv, 0, sizeof(struct sockaddr_un)); + saddrun_rv.sun_family = AF_UNIX; + strncpy(saddrun_rv.sun_path, NET_NFC_SERVER_DOMAIN, sizeof(saddrun_rv.sun_path) - 1); + + if ((result = bind(g_server_info.server_sock_fd, (struct sockaddr *)&saddrun_rv, sizeof(saddrun_rv))) < 0) + { + DEBUG_ERR_MSG("bind is failed"); + goto ERROR; + } + + if ((result = chmod(NET_NFC_SERVER_DOMAIN, 0777)) < 0) + { + DEBUG_ERR_MSG("can not change permission of UNIX DOMAIN file"); + goto ERROR; + } + +#else + struct sockaddr_in serv_addr; + + g_server_info.server_sock_fd = socket(PF_INET, SOCK_STREAM, 0); + if (g_server_info.server_sock_fd == -1) + { + DEBUG_SERVER_MSG("get socket is failed"); + return false; + } + + net_nfc_util_set_non_block_socket(g_server_info.server_sock_fd); + + memset(&serv_addr, 0x00, sizeof(struct sockaddr_in)); + serv_addr.sin_family = AF_INET; + serv_addr.sin_addr.s_addr = htonl(INADDR_ANY); + serv_addr.sin_port = htons(NET_NFC_SERVER_PORT); + + int val = 1; + + if (setsockopt(g_server_info.server_sock_fd, SOL_SOCKET, SO_REUSEADDR, (char *)&val, sizeof(val)) == 0) + { + DEBUG_SERVER_MSG("reuse address"); + } + + if (bind(g_server_info.server_sock_fd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) + { + DEBUG_ERR_MSG("bind is failed"); + goto ERROR; + } +#endif + + if ((result = listen(g_server_info.server_sock_fd, NET_NFC_CLIENT_MAX)) < 0) + { + DEBUG_ERR_MSG("listen is failed"); + goto ERROR; + } + + GIOCondition condition = (GIOCondition)(G_IO_ERR | G_IO_HUP | G_IO_IN); + + if ((g_server_info.server_channel = g_io_channel_unix_new(g_server_info.server_sock_fd)) != NULL) + { + if ((g_server_info.server_src_id = g_io_add_watch(g_server_info.server_channel, condition, net_nfc_server_ipc_callback_func, NULL)) < 1) + { + DEBUG_ERR_MSG(" g_io_add_watch is failed"); + goto ERROR; + } + } + else + { + DEBUG_ERR_MSG(" g_io_channel_unix_new is failed"); + goto ERROR; + } + +#ifdef SECURITY_SERVER + gid = security_server_get_gid(NET_NFC_MANAGER_OBJECT); + if (gid == 0) + { + DEBUG_ERR_MSG("get gid from security server is failed. this object is not allowed by security server"); + goto ERROR; + } + + if ((cookies_size = security_server_get_cookie_size()) > 0) + { + _net_nfc_util_alloc_mem(cookies, cookies_size); + if (cookies == NULL) + { + DEBUG_ERR_MSG("alloc failed"); + goto ERROR; + } + } + else + { + DEBUG_ERR_MSG("security_server_get_cookie_size failed"); + goto ERROR; + } +#endif + + net_nfc_dispatcher_start_thread(); + DEBUG_SERVER_MSG("server ipc is initialized"); + + if (vconf_set_bool(NET_NFC_DISABLE_LAUNCH_POPUP_KEY, TRUE) != 0) + DEBUG_ERR_MSG("SERVER : launch state set vconf fail"); + + return true; + +ERROR : +#ifdef SECURITY_SERVER + if (cookies == NULL) + { + _net_nfc_util_free_mem(cookies); + } +#endif + + if (g_server_info.server_src_id > 0) + { + g_source_remove(g_server_info.server_src_id); + g_server_info.server_src_id = 0; + } + + if (g_server_info.server_channel != NULL) + { + g_io_channel_unref(g_server_info.server_channel); + g_server_info.server_channel = NULL; + } + + if (g_server_info.server_sock_fd != -1) + { + shutdown(g_server_info.server_sock_fd, SHUT_RDWR); + close(g_server_info.server_sock_fd); + g_server_info.server_sock_fd = -1; + } + + return false; +} + +void net_nfc_server_ipc_finalize() +{ + /* cleanup client */ + net_nfc_server_deinit_client_context(); + +#ifdef SECURITY_SERVER + if (cookies == NULL) + { + _net_nfc_util_free_mem(cookies); + } +#endif + + if (g_server_info.server_src_id > 0) + { + g_source_remove(g_server_info.server_src_id); + g_server_info.server_src_id = 0; + } + + if (g_server_info.server_channel != NULL) + { + g_io_channel_unref(g_server_info.server_channel); + g_server_info.server_channel = NULL; + } + + if (g_server_info.server_sock_fd != -1) + { + shutdown(g_server_info.server_sock_fd, SHUT_RDWR); + close(g_server_info.server_sock_fd); + g_server_info.server_sock_fd = -1; + } +} + +gboolean net_nfc_server_ipc_callback_func(GIOChannel *channel, GIOCondition condition, gpointer data) +{ + gboolean result = TRUE; + int sock_fd = g_io_channel_unix_get_fd(channel); + + if ((G_IO_ERR & condition) || (G_IO_HUP & condition)) + { + DEBUG_ERR_MSG("G_IO_ERR"); + if (sock_fd > 0) + { + if (sock_fd == g_server_info.server_sock_fd) + { + DEBUG_SERVER_MSG("server socket is closed"); + + net_nfc_dispatcher_cleanup_queue(); + net_nfc_server_ipc_finalize(); + } + else + { + DEBUG_SERVER_MSG("client socket is closed, socket [%d]", sock_fd); + + net_nfc_server_cleanup_client_context(sock_fd); + } + } + + result = FALSE; + } + else if (G_IO_NVAL & condition) + { + DEBUG_ERR_MSG("INVALID socket"); + result = FALSE; + } + else if (G_IO_IN & condition) + { + if (sock_fd > 0) + { + if (sock_fd == g_server_info.server_sock_fd) + { + /* client connect request */ + net_nfc_server_process_client_connect_request(); + } + else + { + net_nfc_error_e result = NET_NFC_OK; + + if (net_nfc_server_read_client_request(sock_fd, &result) == false) + { + switch (result) + { + case NET_NFC_OPERATION_FAIL : + DEBUG_SERVER_MSG("clear context and shutdown socket"); + net_nfc_server_cleanup_client_context(sock_fd); + result = FALSE; + break; + + default : + DEBUG_ERR_MSG("read client request is failed = [0x%x]", result); + net_nfc_server_cleanup_client_context(sock_fd); + result = FALSE; + break; + } + } + } + } + } + + return result; +} + +bool net_nfc_server_process_client_connect_request() +{ + socklen_t addrlen = 0; + int client_sock_fd = 0; + GIOChannel* client_channel = NULL; + uint32_t client_src_id; + + DEBUG_SERVER_MSG("client is trying to connect to server"); + + if (net_nfc_server_get_client_count() >= NET_NFC_CLIENT_MAX) + { + DEBUG_SERVER_MSG("client is fully served. no more capa is remained."); + return false; + } + + if ((client_sock_fd = accept(g_server_info.server_sock_fd, NULL, &addrlen)) < 0) + { + DEBUG_ERR_MSG("can not accept client"); + return false; + } + + DEBUG_SERVER_MSG("client is accepted by server, socket[%d]", client_sock_fd); + + GIOCondition condition = (GIOCondition)(G_IO_ERR | G_IO_HUP | G_IO_IN); + + if ((client_channel = g_io_channel_unix_new(client_sock_fd)) != NULL) + { + if ((client_src_id = g_io_add_watch(client_channel, condition, net_nfc_server_ipc_callback_func, NULL)) < 1) + { + DEBUG_ERR_MSG("add io callback is failed"); + goto ERROR; + } + } + else + { + DEBUG_ERR_MSG("create new g io channel is failed"); + goto ERROR; + } + + DEBUG_SERVER_MSG("client socket is bond with g_io_channel"); + + net_nfc_server_add_client_context(client_sock_fd, client_channel, client_src_id, NET_NFC_CLIENT_ACTIVE_STATE); + + return true; + +ERROR : + if (client_src_id > 0) + { + g_source_remove(client_src_id); + client_src_id = 0; + } + + if (client_channel != NULL) + { + g_io_channel_unref(client_channel); + client_channel = NULL; + } + + if (client_sock_fd != -1) + { + shutdown(client_sock_fd, SHUT_RDWR); + close(client_sock_fd); + client_sock_fd = -1; + } + + return false; +} + +int __net_nfc_server_read_util(int client_sock_fd, void **detail, size_t size) +{ + static uint8_t flushing[128]; + + *detail = NULL; + _net_nfc_util_alloc_mem(*detail, size); + + if (*detail == NULL) + { + size_t read_size; + int readbyes = size; + + while (readbyes > 0) + { + read_size = readbyes > 128 ? 128 : readbyes; + if (net_nfc_server_recv_message_from_client(client_sock_fd, flushing, read_size) < 0) + { + return false; + } + readbyes -= read_size; + } + return false; + } + + if (net_nfc_server_recv_message_from_client(client_sock_fd, *detail, size) < 0) + { + _net_nfc_util_free_mem(*detail); + return false; + } + return true; +} + +bool net_nfc_server_read_client_request(int client_sock_fd, net_nfc_error_e *result) +{ + int read = 0; + uint32_t offset = 0; + uint32_t length = 0; + uint8_t *buffer = NULL; + net_nfc_request_msg_t *req_msg = NULL; + + if ((read = net_nfc_server_recv_message_from_client(client_sock_fd, (void *)&length, sizeof(length))) <= 0) + { + DEBUG_ERR_MSG("shutdown request from client"); + *result = NET_NFC_OPERATION_FAIL; + return false; + } + + if (read != sizeof(length)) + { + DEBUG_ERR_MSG("failed to read message length [%d]", read); + *result = NET_NFC_IPC_FAIL; + return false; + } + + if (length > NET_NFC_MAX_MESSAGE_LENGTH) + { + DEBUG_ERR_MSG("too long message [%d]", length); + *result = NET_NFC_IPC_FAIL; + return false; + } + + _net_nfc_util_alloc_mem(buffer, length); + if (buffer == NULL) + { + *result = NET_NFC_ALLOC_FAIL; + return false; + } + + memset(buffer, 0, length); + + if ((read = net_nfc_server_recv_message_from_client(client_sock_fd, (void *)buffer, length)) != length) + { + DEBUG_ERR_MSG("failed to read message [%d]", read); + _net_nfc_util_free_mem(buffer); + *result = NET_NFC_IPC_FAIL; + return false; + } + +#ifdef SECURITY_SERVER + uint32_t cookie_len = *(uint32_t *)(buffer + offset); + offset += sizeof(cookie_len); + + if (cookie_len == cookies_size && (length - offset) > cookies_size) + { + int error = 0; + + /* copy cookie */ + memcpy(cookies, buffer + offset, cookies_size); + offset += cookies_size; + + /* for debug */ +#if 0 + DEBUG_SERVER_MSG("recevied cookies"); + DEBUG_MSG_PRINT_BUFFER(cookies, cookie_len); +#endif + + /* check cookie */ + if ((error = security_server_check_privilege(cookies, gid)) < 0) + { + DEBUG_ERR_MSG("failed to authentificate client [%d]", error); + _net_nfc_util_free_mem(buffer); + *result = NET_NFC_SECURITY_FAIL; + return false; + } + } + else + { + DEBUG_ERR_MSG("there is no cookie or invalid in message"); + _net_nfc_util_free_mem(buffer); + *result = NET_NFC_SECURITY_FAIL; + return false; + } +#endif + + if (length > offset) + { + _net_nfc_util_alloc_mem(req_msg, length - offset); + if (req_msg != NULL) + { + memcpy(req_msg, buffer + offset, length - offset); + } + else + { + _net_nfc_util_free_mem(buffer); + *result = NET_NFC_ALLOC_FAIL; + return false; + } + } + else + { + _net_nfc_util_free_mem(buffer); + *result = NET_NFC_IPC_FAIL; + return false; + } + + _net_nfc_util_free_mem(buffer); + + DEBUG_MSG("<<<<< FROM CLIENT [%d] <<<<< (msg [%d], length [%d])", client_sock_fd, req_msg->request_type, length); + +#ifdef BROADCAST_MESSAGE + /* set client socket descriptor */ + req_msg->client_fd = client_sock_fd; +#endif + + /* process exceptional case of request type */ + switch (req_msg->request_type) + { + case NET_NFC_MESSAGE_SERVICE_CHANGE_CLIENT_STATE : + { + net_nfc_request_change_client_state_t *detail = (net_nfc_request_change_client_state_t *)req_msg; + + net_nfc_server_set_client_state(client_sock_fd, detail->client_state); + DEBUG_SERVER_MSG("net_nfc_server_read_client_request is finished"); + + _net_nfc_util_free_mem(req_msg); + + return true; + } + break; + + case NET_NFC_MESSAGE_SERVICE_SET_LAUNCH_STATE : + { + net_nfc_request_set_launch_state_t *detail = (net_nfc_request_set_launch_state_t *)req_msg; + + net_nfc_server_set_launch_state(client_sock_fd, detail->set_launch_popup); + + _net_nfc_util_free_mem(req_msg); + + return true; + } + break; + + default : + break; + } + +#ifdef BROADCAST_MESSAGE + net_nfc_dispatcher_queue_push(req_msg); +#else + /* check current client context is activated. */ + if (net_nfc_server_get_client_state(client_sock_fd) == NET_NFC_CLIENT_ACTIVE_STATE) + { + DEBUG_SERVER_MSG("client is activated"); + net_nfc_dispatcher_queue_push(req_msg); + DEBUG_SERVER_MSG("net_nfc_server_read_client_request is finished"); + break; + } + else + { + DEBUG_SERVER_MSG("client is deactivated"); + + /* free req_msg */ + _net_nfc_util_free_mem(req_msg); + + DEBUG_SERVER_MSG("net_nfc_server_read_client_request is finished"); + return false; + } +#endif + + return true; +} + +#ifdef BROADCAST_MESSAGE +bool net_nfc_server_send_message_to_client(int socket, void *message, int length) +{ + int len = 0; + bool result = true; + + pthread_mutex_lock(&g_server_socket_lock); + len = send(socket, (void *)message, length, MSG_NOSIGNAL); + pthread_mutex_unlock(&g_server_socket_lock); + + if (len <= 0) + { + uint8_t buf[1024] = { 0x00, }; + + DEBUG_ERR_MSG("send failed : socket [%d], length [%d], [%s]", socket, length, strerror_r(errno, (char *)buf, sizeof(buf))); + if (errno == EPIPE) + { + abort(); + } + result = false; + } + + return result; +} +#else +bool net_nfc_server_send_message_to_client(void* message, int length) +{ + pthread_mutex_lock(&g_server_socket_lock); + int leng = send(g_server_info.client_sock_fd, (void *)message, length, 0); + pthread_mutex_unlock(&g_server_socket_lock); + + if(leng > 0) + { + return true; + } + else + { + DEBUG_ERR_MSG("failed to send message, socket = [%d], msg_length = [%d]", g_server_info.client_sock_fd, length); + return false; + } +} +#endif + +int net_nfc_server_recv_message_from_client(int client_sock_fd, void* message, int length) +{ + int leng = recv(client_sock_fd, message, length, 0); + + return leng; +} + +static void _net_nfc_for_each_cb(net_nfc_client_info_t *client, void *user_param) +{ + if (user_param != NULL) + { + int length = *(int *)user_param; + uint8_t *send_buffer = ((uint8_t *)user_param) + sizeof(int); + + if (net_nfc_server_send_message_to_client(client->socket, send_buffer, length) == true) + { +// DEBUG_MSG(">>>>> TO CLIENT [%d] >>>>> (msg [%d], length [%d])", client->socket, msg_type, length); + DEBUG_MSG(">>>>> TO CLIENT [%d] >>>>> (length [%d])", client->socket, length); + } + } +} + +#ifdef BROADCAST_MESSAGE +bool net_nfc_broadcast_response_msg(int msg_type, ...) +{ + va_list list; + int total_size = 0; + int written_size = 0; + uint8_t *send_buffer = NULL; + + va_start(list, msg_type); + + /* total length */ + total_size += sizeof(msg_type); + total_size += net_nfc_util_get_va_list_length(list); + + _net_nfc_util_alloc_mem(send_buffer, total_size + sizeof(total_size)); + + memcpy(send_buffer + written_size, &(total_size), sizeof(total_size)); + written_size += sizeof(total_size); + + memcpy(send_buffer + written_size, &(msg_type), sizeof(msg_type)); + written_size += sizeof(msg_type); + + written_size += net_nfc_util_fill_va_list(send_buffer + written_size, total_size + sizeof(total_size) - written_size, list); + + va_end(list); + + net_nfc_server_for_each_client_context(_net_nfc_for_each_cb, send_buffer); + + _net_nfc_util_free_mem(send_buffer); + + return true; +} + +bool net_nfc_send_response_msg(int socket, int msg_type, ...) +#else +bool net_nfc_send_response_msg(int msg_type, ...) +#endif +{ + va_list list; + int total_size = 0; + int written_size = 0; + uint8_t *send_buffer = NULL; + + va_start(list, msg_type); + + total_size += sizeof(msg_type); + total_size += net_nfc_util_get_va_list_length(list); + + _net_nfc_util_alloc_mem(send_buffer, total_size + sizeof(total_size)); + +// memcpy(send_buffer + written_size, &(total_size), sizeof(total_size)); +// written_size += sizeof(total_size); + + memcpy(send_buffer + written_size, &(msg_type), sizeof(msg_type)); + written_size += sizeof(msg_type); + +// written_size += net_nfc_util_fill_va_list(send_buffer + written_size, total_size + sizeof(total_size) - written_size, list); + written_size += net_nfc_util_fill_va_list(send_buffer + written_size, total_size - written_size, list); + + va_end(list); + + if (net_nfc_server_get_client_context(socket) != NULL) + { +#ifdef BROADCAST_MESSAGE + if (net_nfc_server_send_message_to_client(socket, (void *)send_buffer, total_size) == true) +#else + if (net_nfc_server_send_message_to_client((void *)send_buffer, total_size) == true) +#endif + { + DEBUG_MSG(">>>>> TO CLIENT [%d] >>>>> (msg [%d], length [%d])", socket, msg_type, total_size - sizeof(total_size)); + } + } + else + { + DEBUG_ERR_MSG("Client not found : socket [%d], length [%d]", socket, total_size + sizeof(total_size)); + } + + _net_nfc_util_free_mem(send_buffer); + + return true; +} + +void net_nfc_server_set_tag_info(void *info) +{ + net_nfc_request_target_detected_t *detail = (net_nfc_request_target_detected_t *)info; + net_nfc_current_target_info_s *target_info = NULL; + + pthread_mutex_lock(&g_server_socket_lock); + + if (g_server_info.target_info != NULL) + _net_nfc_util_free_mem(g_server_info.target_info); + + _net_nfc_util_alloc_mem(target_info, sizeof(net_nfc_current_target_info_s) + detail->target_info_values.length); + if (target_info != NULL) + { + target_info->handle = detail->handle; + target_info->devType = detail->devType; + + if (target_info->devType != NET_NFC_NFCIP1_INITIATOR && target_info->devType != NET_NFC_NFCIP1_TARGET) + { + target_info->number_of_keys = detail->number_of_keys; + target_info->target_info_values.length = detail->target_info_values.length; + memcpy(&target_info->target_info_values, &detail->target_info_values, target_info->target_info_values.length); + } + + g_server_info.target_info = target_info; + } + + pthread_mutex_unlock(&g_server_socket_lock); +} + +bool net_nfc_server_is_target_connected(void *handle) +{ + bool result = false; + + if (g_server_info.target_info != NULL && g_server_info.target_info->handle == handle) + result = true; + + return result; +} + +net_nfc_current_target_info_s *net_nfc_server_get_tag_info() +{ + return g_server_info.target_info; +} + +void net_nfc_server_free_current_tag_info() +{ + pthread_mutex_lock(&g_server_socket_lock); + + _net_nfc_util_free_mem(g_server_info.target_info); + + pthread_mutex_unlock(&g_server_socket_lock); +} diff --git a/src/manager/net_nfc_service.c b/src/manager/net_nfc_service.c new file mode 100644 index 0000000..b06b502 --- /dev/null +++ b/src/manager/net_nfc_service.c @@ -0,0 +1,520 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include "net_nfc_controller_private.h" +#include "net_nfc_util_private.h" +#include "net_nfc_typedef.h" +#include "net_nfc_debug_private.h" +#include "net_nfc_service_private.h" +#include "net_nfc_service_se_private.h" +#include "net_nfc_app_util_private.h" +#include "net_nfc_server_ipc_private.h" +#include "net_nfc_server_dispatcher_private.h" +#include "net_nfc_manager_util_private.h" +#include "net_nfc_service_tag_private.h" +#include "net_nfc_service_llcp_private.h" +#include "net_nfc_util_ndef_message.h" +#include "net_nfc_util_ndef_record.h" +#include "net_nfc_util_access_control_private.h" + +/* static variable */ + +/* static callback function */ + +/* static function */ + +#ifndef BROADCAST_MESSAGE +extern uint8_t g_se_cur_type; +extern uint8_t g_se_cur_mode; + +static bool _net_nfc_service_check_internal_ese_detected() +{ + if (g_se_cur_type == SECURE_ELEMENT_TYPE_ESE && g_se_cur_mode == SECURE_ELEMENT_WIRED_MODE) + { + return true; + } + + return false; +} +#endif + +static void _net_nfc_service_show_exception_msg(char* msg); + +////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +void net_nfc_service_target_detected_cb(void *info, void *user_context) +{ + net_nfc_request_msg_t *req_msg = (net_nfc_request_msg_t *)info; + + if (info == NULL) + return; + + if (req_msg->request_type == NET_NFC_MESSAGE_SERVICE_RESTART_POLLING_LOOP) + { + net_nfc_dispatcher_queue_push(req_msg); + } +#ifdef BROADCAST_MESSAGE + else + { + net_nfc_server_set_tag_info(info); + + req_msg->request_type = NET_NFC_MESSAGE_SERVICE_SLAVE_TARGET_DETECTED; + net_nfc_dispatcher_queue_push(req_msg); + } +#else + else if (net_nfc_server_get_current_client_context(&client_context) == true && + net_nfc_server_check_client_is_running(&client_context) == true) + { + net_nfc_request_target_detected_t *detail = (net_nfc_request_target_detected_t *)req_msg; + + /* If target detected, sound should be played. */ + net_nfc_manager_util_play_sound(NET_NFC_TASK_START); + + net_nfc_server_set_tag_info(info); + + if (!_net_nfc_service_check_internal_ese_detected()) + { + req_msg->request_type = NET_NFC_MESSAGE_SERVICE_SLAVE_TARGET_DETECTED; + } + else + { + req_msg->request_type = NET_NFC_MESSAGE_SERVICE_SLAVE_ESE_DETECTED; + + (detail->handle)->connection_type = NET_NFC_SE_CONNECTION; + } + + net_nfc_server_set_current_client_target_handle(client_context, detail->handle); + + net_nfc_dispatcher_queue_push(req_msg); + + DEBUG_SERVER_MSG("current client is listener. stand alone mode will be activated"); + } + else + { + /* If target detected, sound should be played. */ + net_nfc_manager_util_play_sound(NET_NFC_TASK_START); + + req_msg->request_type = NET_NFC_MESSAGE_SERVICE_STANDALONE_TARGET_DETECTED; + net_nfc_dispatcher_queue_push(req_msg); + } +#endif +} + +void net_nfc_service_se_transaction_cb(void *info, void *user_context) +{ + net_nfc_request_se_event_t *req_msg = (net_nfc_request_se_event_t *)info; + + DEBUG_SERVER_MSG("se event [%d]", req_msg->request_type); + + net_nfc_dispatcher_queue_push((net_nfc_request_msg_t *)req_msg); +} + +void net_nfc_service_llcp_event_cb(void* info, void* user_context) +{ + net_nfc_request_llcp_msg_t *req_msg = (net_nfc_request_llcp_msg_t *)info; + + if (req_msg == NULL) + { + DEBUG_SERVER_MSG("req msg is null"); + return; + } + + if (req_msg->request_type == NET_NFC_MESSAGE_SERVICE_LLCP_ACCEPT) + { + net_nfc_request_accept_socket_t *detail = (net_nfc_request_accept_socket_t *)req_msg; + detail->trans_param = user_context; + } + + req_msg->user_param = (uint32_t)user_context; + + net_nfc_dispatcher_queue_push((net_nfc_request_msg_t *)req_msg); +} + +static bool _is_isp_dep_ndef_formatable(net_nfc_target_handle_s *handle, int dev_type) +{ + bool result = false; + uint8_t cmd[] = { 0x90, 0x60, 0x00, 0x00, 0x00 }; + net_nfc_transceive_info_s info; + data_s *response = NULL; + net_nfc_error_e error = NET_NFC_OK; + + info.dev_type = dev_type; + info.trans_data.buffer = cmd; + info.trans_data.length = sizeof(cmd); + + if (net_nfc_controller_transceive(handle, &info, &response, &error) == true) + { + if (response != NULL) + { + if (response->length == 9 && response->buffer[7] == (uint8_t)0x91 && + response->buffer[8] == (uint8_t)0xAF) + { + result = true; + } + else + { + DEBUG_ERR_MSG("Unknown response...."); + DEBUG_MSG_PRINT_BUFFER(response->buffer, response->length); + } + } + else + { + DEBUG_ERR_MSG("net_nfc_controller_transceive response is null"); + } + } + else + { + DEBUG_ERR_MSG("net_nfc_controller_transceive is failed, [%d]", result); + } + + return result; +} + +static net_nfc_error_e _read_ndef_message(net_nfc_target_handle_s *handle, int dev_type, data_s **read_ndef) +{ + net_nfc_error_e result = NET_NFC_OK; + data_s *temp = NULL; + + if (handle == NULL || read_ndef == NULL) + return NET_NFC_INVALID_PARAM; + + *read_ndef = NULL; + + /* Desfire */ + if (dev_type == NET_NFC_MIFARE_DESFIRE_PICC) + { + DEBUG_SERVER_MSG("DESFIRE : check ISO-DEP ndef formatable"); + + if (_is_isp_dep_ndef_formatable(handle, dev_type) == true) + { + DEBUG_SERVER_MSG("DESFIRE : ISO-DEP ndef formatable"); + + if (!net_nfc_controller_connect(handle, &result)) + { + DEBUG_ERR_MSG("net_nfc_controller_connect failed & Retry Polling!!"); + + if (net_nfc_controller_confiure_discovery(NET_NFC_DISCOVERY_MODE_RESUME, + NET_NFC_ALL_ENABLE, &result) == false) + { + net_nfc_controller_exception_handler(); + } + + return NET_NFC_TAG_READ_FAILED; + } + } + else + { + DEBUG_ERR_MSG("DESFIRE : ISO-DEP ndef not formatable"); + + return NET_NFC_TAG_READ_FAILED; + } + } + + if (net_nfc_controller_read_ndef(handle, &temp, &result) == true) + { + DEBUG_SERVER_MSG("net_nfc_controller_read_ndef success"); + + if (dev_type == NET_NFC_MIFARE_DESFIRE_PICC) + { + if (!net_nfc_controller_connect(handle, &result)) + { + DEBUG_ERR_MSG("net_nfc_controller_connect failed & Retry Polling!!"); + + if (net_nfc_controller_confiure_discovery(NET_NFC_DISCOVERY_MODE_RESUME, NET_NFC_ALL_ENABLE, &result) == false) + { + net_nfc_controller_exception_handler(); + } + + net_nfc_util_free_data(temp); + _net_nfc_util_free_mem(temp); + + return NET_NFC_TAG_READ_FAILED; + } + } + + *read_ndef = temp; + } + else + { + DEBUG_ERR_MSG("net_nfc_controller_read_ndef failed [%d]", result); + } + + return result; +} + +#ifndef BROADCAST_MESSAGE +bool net_nfc_service_standalone_mode_target_detected(net_nfc_request_msg_t* msg) +{ + net_nfc_request_target_detected_t* stand_alone = (net_nfc_request_target_detected_t *)msg; + net_nfc_error_e error_status = NET_NFC_OK; + + data_s *recv_data = NULL; + + DEBUG_SERVER_MSG("*** Detected! type [0x%X)] ***", stand_alone->devType); + + switch (stand_alone->devType) + { + case NET_NFC_NFCIP1_TARGET : + case NET_NFC_NFCIP1_INITIATOR : + { + DEBUG_SERVER_MSG(" LLCP is detected"); + + net_nfc_service_llcp_process(stand_alone->handle, stand_alone->devType, &error_status); + + malloc_trim(0); + return true; + } + break; + + default : + { + DEBUG_SERVER_MSG(" PICC or PCD is detectd."); + recv_data = net_nfc_service_tag_process(stand_alone->handle, stand_alone->devType, &error_status); + } + break; + } + + if (recv_data != NULL) + { + net_nfc_service_msg_processing(recv_data); + } + else + { + if (((stand_alone->devType == NET_NFC_NFCIP1_INITIATOR) || (stand_alone->devType == NET_NFC_NFCIP1_TARGET))) + { + DEBUG_SERVER_MSG("p2p operation. recv data is NULL"); + } + else + { + if (error_status == NET_NFC_NO_NDEF_SUPPORT) + { + DEBUG_SERVER_MSG("device type = [%d], it has null data", stand_alone->devType); + + /* launch empty tag */ + uint8_t empty[] = { 0xd0, 0x00, 0x00 }; /* raw-data of empty ndef-message */ + data_s rawdata = { &empty, sizeof(empty) }; + + net_nfc_service_msg_processing(&rawdata); + } + else + { + _net_nfc_service_show_exception_msg("Try again"); + } + } + } + + if (stand_alone->devType != NET_NFC_NFCIP1_INITIATOR && stand_alone->devType != NET_NFC_NFCIP1_TARGET) + { + net_nfc_request_watch_dog_t* watch_dog_msg = NULL; + + _net_nfc_util_alloc_mem(watch_dog_msg, sizeof(net_nfc_request_watch_dog_t)); + + if (watch_dog_msg != NULL) + { + watch_dog_msg->length = sizeof(net_nfc_request_watch_dog_t); + watch_dog_msg->request_type = NET_NFC_MESSAGE_SERVICE_WATCH_DOG; + watch_dog_msg->devType = stand_alone->devType; + watch_dog_msg->handle = stand_alone->handle; + + net_nfc_dispatcher_queue_push((net_nfc_request_msg_t *)watch_dog_msg); + } + } + + DEBUG_SERVER_MSG("stand alone mode is end"); + malloc_trim(0); + + return true; +} +#endif + +bool net_nfc_service_slave_mode_target_detected(net_nfc_request_msg_t *msg) +{ + net_nfc_request_target_detected_t *detail_msg = (net_nfc_request_target_detected_t *)msg; + net_nfc_error_e result = NET_NFC_OK; + bool success = true; + + DEBUG_SERVER_MSG("target detected callback for client, device type = [%d]", detail_msg->devType); + + if (detail_msg == NULL) + { + return false; + } + + if (detail_msg->devType != NET_NFC_NFCIP1_TARGET && detail_msg->devType != NET_NFC_NFCIP1_INITIATOR) + { + net_nfc_response_tag_discovered_t resp_msg = { 0, }; + int request_type = NET_NFC_MESSAGE_TAG_DISCOVERED; + data_s *recv_data = NULL; + + if (!net_nfc_controller_connect(detail_msg->handle, &result)) + { + DEBUG_ERR_MSG("connect failed & Retry Polling!!"); + + if (net_nfc_controller_confiure_discovery(NET_NFC_DISCOVERY_MODE_RESUME, NET_NFC_ALL_ENABLE, &result) == false) + { + net_nfc_controller_exception_handler(); + } + return false; + } + +#ifdef BROADCAST_MESSAGE + net_nfc_server_set_server_state(NET_NFC_TAG_CONNECTED); +#endif + DEBUG_SERVER_MSG("tag is connected"); + + uint8_t ndef_card_state = 0; + int max_data_size = 0; + int real_data_size = 0; + + if (net_nfc_controller_check_ndef(detail_msg->handle, &ndef_card_state, &max_data_size, &real_data_size, &result) == true) + { + resp_msg.ndefCardState = ndef_card_state; + resp_msg.maxDataSize = max_data_size; + resp_msg.actualDataSize = real_data_size; + resp_msg.is_ndef_supported = 1; + } + + resp_msg.devType = detail_msg->devType; + resp_msg.handle = detail_msg->handle; + resp_msg.number_of_keys = detail_msg->number_of_keys; + resp_msg.raw_data.length = 0; + + net_nfc_util_duplicate_data(&resp_msg.target_info_values, &detail_msg->target_info_values); + + if (resp_msg.is_ndef_supported) + { + DEBUG_SERVER_MSG("support NDEF"); + + if ((result = _read_ndef_message(detail_msg->handle, detail_msg->devType, &recv_data)) == NET_NFC_OK && + recv_data != NULL) + { + DEBUG_SERVER_MSG("net_nfc_controller_read_ndef success"); +#ifdef BROADCAST_MESSAGE + net_nfc_service_msg_processing(recv_data); +#endif + resp_msg.raw_data.length = recv_data->length; + success = net_nfc_broadcast_response_msg(request_type, (void *)&resp_msg, sizeof(net_nfc_response_tag_discovered_t), + (void *)(resp_msg.target_info_values.buffer), resp_msg.target_info_values.length, + (void *)(recv_data->buffer), recv_data->length, NULL); + + net_nfc_util_free_data(recv_data); + _net_nfc_util_free_mem(recv_data); + } + else + { + DEBUG_ERR_MSG("net_nfc_controller_read_ndef failed"); + + success = net_nfc_broadcast_response_msg(request_type, (void *)&resp_msg, sizeof(net_nfc_response_tag_discovered_t), + (void *)(resp_msg.target_info_values.buffer), resp_msg.target_info_values.length, NULL); + } + } + else + { + DEBUG_SERVER_MSG("not support NDEF"); +#ifdef BROADCAST_MESSAGE + /* launch empty tag */ + uint8_t empty[] = { 0xd0, 0x00, 0x00 }; /* raw-data of empty ndef-message */ + data_s rawdata = { empty, sizeof(empty) }; + + net_nfc_service_msg_processing(&rawdata); +#endif + success = net_nfc_broadcast_response_msg(request_type, (void *)&resp_msg, sizeof(net_nfc_response_tag_discovered_t), + (void *)(resp_msg.target_info_values.buffer), resp_msg.target_info_values.length, NULL); + } + + net_nfc_util_free_data(&resp_msg.target_info_values); + + DEBUG_SERVER_MSG("turn on watch dog"); + + net_nfc_request_watch_dog_t* watch_dog_msg = NULL; + + _net_nfc_util_alloc_mem(watch_dog_msg, sizeof(net_nfc_request_watch_dog_t)); + if (watch_dog_msg != NULL) + { + watch_dog_msg->length = sizeof(net_nfc_request_watch_dog_t); + watch_dog_msg->request_type = NET_NFC_MESSAGE_SERVICE_WATCH_DOG; + watch_dog_msg->devType = detail_msg->devType; + watch_dog_msg->handle = detail_msg->handle; + + net_nfc_dispatcher_queue_push((net_nfc_request_msg_t *)watch_dog_msg); + } + } + else /* LLCP */ + { + net_nfc_error_e error_status = NET_NFC_OK; + + net_nfc_service_llcp_process(detail_msg->handle, detail_msg->devType, &error_status); + } + + /* If target detected, sound should be played. */ + net_nfc_manager_util_play_sound(NET_NFC_TASK_START); + + return success; +} + +bool net_nfc_service_termination(net_nfc_request_msg_t* msg) +{ + net_nfc_error_e result; + + if (net_nfc_controller_is_ready(&result) == true) + { + } + else + { + DEBUG_SERVER_MSG("Not initialized"); + net_nfc_controller_init(&result); + } + + if (net_nfc_controller_confiure_discovery(NET_NFC_DISCOVERY_MODE_CONFIG, NET_NFC_ALL_DISABLE, &result) != true) + { + DEBUG_SERVER_MSG("failed to discover off %d", result); + } + + if (net_nfc_controller_set_secure_element_mode(NET_NFC_SE_CMD_UICC_ON, SECURE_ELEMENT_VIRTUAL_MODE, &result) != true) + { + DEBUG_SERVER_MSG("failed to set se mode to default mode: %d", result); + } + + return true; +} + +void net_nfc_service_msg_processing(data_s* data) +{ + if (data != NULL) + { + net_nfc_app_util_process_ndef(data); + } + else + { + _net_nfc_service_show_exception_msg("unknown type tag"); + } +} + +static void _net_nfc_service_show_exception_msg(char* msg) +{ + bundle *kb = NULL; + + kb = bundle_create(); + bundle_add(kb, "type", "default"); + bundle_add(kb, "text", msg); + + net_nfc_app_util_aul_launch_app("com.samsung.nfc-app", kb); /* empty_tag */ + + bundle_free(kb); +} diff --git a/src/manager/net_nfc_service_llcp.c b/src/manager/net_nfc_service_llcp.c new file mode 100644 index 0000000..6419001 --- /dev/null +++ b/src/manager/net_nfc_service_llcp.c @@ -0,0 +1,2549 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +#include "net_nfc_controller_private.h" +#include "net_nfc_util_private.h" +#include "net_nfc_typedef.h" +#include "net_nfc_debug_private.h" +#include "net_nfc_service_private.h" +#include "net_nfc_app_util_private.h" +#include "net_nfc_server_ipc_private.h" +#include "net_nfc_server_dispatcher_private.h" +#include "net_nfc_manager_util_private.h" +#include "net_nfc_service_llcp_private.h" +#include "net_nfc_service_llcp_handover_private.h" +#include "net_nfc_server_context_private.h" + +static uint8_t snep_server_buffer[SNEP_MAX_BUFFER] = { 0, }; +static uint8_t snep_client_buffer[SNEP_MAX_BUFFER] = { 0, }; + +static data_s snep_server_data = { snep_server_buffer, SNEP_MAX_BUFFER }; +static data_s snep_client_data = { snep_client_buffer, SNEP_MAX_BUFFER }; + +static net_nfc_llcp_state_t current_llcp_client_state; +static net_nfc_llcp_state_t current_llcp_server_state; + +/* static callback function */ + +#if 0 +net_nfc_error_e _net_nfc_service_llcp_get_server_configuration_value(char* service_name, char* attr_name, char* attr_value); +#endif +static bool _net_nfc_service_llcp_state_process(net_nfc_request_msg_t *msg); + +static bool _net_nfc_service_llcp_snep_server(net_nfc_llcp_state_t * state, net_nfc_error_e* result); +static bool _net_nfc_service_llcp_client(net_nfc_llcp_state_t * state, net_nfc_error_e* result); +static data_s* _net_nfc_service_llcp_snep_create_msg(snep_command_field_e resp_field, data_s* information); +static net_nfc_error_e _net_nfc_service_llcp_snep_check_req_msg(data_s* snep_msg, uint8_t* resp_code); +static net_nfc_error_e _net_nfc_service_llcp_snep_get_code(data_s* snep_msg, uint8_t* code); +static net_nfc_error_e _net_nfc_service_llcp_snep_get_information_length(data_s* snep_msg, uint32_t* length); +static net_nfc_error_e _net_nfc_service_llcp_snep_check_resp_msg(data_s* snep_msg); + +static bool _net_nfc_service_llcp_npp_server(net_nfc_llcp_state_t * state, net_nfc_error_e* result); +static data_s* _net_nfc_service_llcp_npp_create_msg(data_s* information); +static net_nfc_error_e _net_nfc_service_llcp_npp_check_req_msg(data_s* npp_msg, uint8_t* resp_code); +static net_nfc_error_e _net_nfc_service_llcp_npp_get_information_length(data_s* npp_msg, uint32_t* length); + +////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +GList * state_list = NULL; +static bool net_nfc_service_llcp_is_valid_state(net_nfc_llcp_state_t * state) +{ + if (g_list_find(state_list, state) != NULL) + { + return true; + } + return false; +} +void net_nfc_service_llcp_remove_state(net_nfc_llcp_state_t * state) +{ + if (state != NULL) + { + state_list = g_list_remove(state_list, state); + } +} +void net_nfc_service_llcp_add_state(net_nfc_llcp_state_t * state) +{ + if (state != NULL) + { + state_list = g_list_append(state_list, state); + } +} + +bool net_nfc_service_llcp_process(net_nfc_target_handle_s* handle, int devType, net_nfc_error_e* result) +{ + *result = NET_NFC_OK; + + DEBUG_SERVER_MSG("connection type = [%d]", handle->connection_type); + + if (devType == NET_NFC_NFCIP1_TARGET) + { + DEBUG_SERVER_MSG("trying to connect to tag = [0x%p]", handle); + + if (net_nfc_controller_connect(handle, result) != true) + { + DEBUG_SERVER_MSG("connect failed"); + + if (net_nfc_controller_confiure_discovery(NET_NFC_DISCOVERY_MODE_RESUME, NET_NFC_ALL_ENABLE, result) == false) + { + net_nfc_controller_exception_handler(); + + } + + return false; + } + } + + DEBUG_SERVER_MSG("check LLCP"); + + if (net_nfc_controller_llcp_check_llcp(handle, result) == true) + { + DEBUG_SERVER_MSG("activate LLCP"); + if (net_nfc_controller_llcp_activate_llcp(handle, result) == true) + { +#ifdef SUPPORT_CONFIG_FILE + char value[64] = + { 0,}; + if (net_nfc_service_get_configuration_value("service", "exchange_service", value) == NET_NFC_OK) + { + if (strcmp(value, "true") == 0) + { + net_nfc_llcp_state_t * exchange_state_server = NULL; + _net_nfc_util_alloc_mem(exchange_state_server, sizeof (net_nfc_llcp_state_t)); + + exchange_state_server->handle = handle; + exchange_state_server->state = NET_NFC_STATE_EXCHANGER_SERVER; + exchange_state_server->step = NET_NFC_LLCP_STEP_01; + exchange_state_server->user_data = NULL; + + net_nfc_service_llcp_add_state(exchange_state_server); + + if (_net_nfc_service_llcp_snep_server(exchange_state_server, result) == false) + { + return false; + } + + handle->app_type = exchange_state_server->type_app_protocol; + DEBUG_SERVER_MSG("handle->app_type = [%d]", handle->app_type); + } + else + { + DEBUG_SERVER_MSG("llcp exchange service is trunned off"); + } + } + else + { + net_nfc_llcp_state_t * exchange_state_server = NULL; + _net_nfc_util_alloc_mem(exchange_state_server, sizeof (net_nfc_llcp_state_t)); + + exchange_state_server->handle = handle; + exchange_state_server->state = NET_NFC_STATE_EXCHANGER_SERVER; + exchange_state_server->step = NET_NFC_LLCP_STEP_01; + exchange_state_server->user_data = NULL; + + net_nfc_service_llcp_add_state(exchange_state_server); + + if (_net_nfc_service_llcp_npp_server(exchange_state_server, result) == false) + { + DEBUG_SERVER_MSG("ERROR!!!!!!!!!!!!!!!"); + return false; + } + else + { + handle->app_type = exchange_state_server->type_app_protocol; + DEBUG_SERVER_MSG("handle->app_type = [%d]", handle->app_type); + } + } + + memset(value, 0x00, 64); + + if (net_nfc_service_get_configuration_value("service", "connection_handover", value) == NET_NFC_OK) + { + if (strcmp(value, "true") == 0) + { + net_nfc_llcp_state_t * conn_handover_selector = NULL; + _net_nfc_util_alloc_mem(conn_handover_selector, sizeof (net_nfc_llcp_state_t)); + + conn_handover_selector->handle = handle; + conn_handover_selector->state = NET_NFC_STATE_CONN_HANDOVER_SELECT; + conn_handover_selector->step = NET_NFC_LLCP_STEP_01; + conn_handover_selector->user_data = NULL; + + net_nfc_service_llcp_add_state(conn_handover_selector); + + if (_net_nfc_service_llcp_stand_alone_conn_handover_selector(conn_handover_selector, result) == false) + { + return false; + } + } + else + { + DEBUG_SERVER_MSG("llcp connection handover is trunned off"); + } + } +#else/* Use the NPP & the SNEP FOR LLCP , Handover*/ + /* NPP */ + net_nfc_llcp_state_t * exchange_state_server_NPP = NULL; + _net_nfc_util_alloc_mem(exchange_state_server_NPP, sizeof (net_nfc_llcp_state_t)); + exchange_state_server_NPP->handle = handle; + exchange_state_server_NPP->state = NET_NFC_STATE_EXCHANGER_SERVER_NPP; + exchange_state_server_NPP->step = NET_NFC_LLCP_STEP_01; + exchange_state_server_NPP->user_data = NULL; + + net_nfc_service_llcp_add_state(exchange_state_server_NPP); + + if (_net_nfc_service_llcp_npp_server(exchange_state_server_NPP, result) == false) + { + return false; + } + + /* SNEP */ + net_nfc_llcp_state_t * exchange_state_server_SNEP = NULL; + _net_nfc_util_alloc_mem(exchange_state_server_SNEP, sizeof (net_nfc_llcp_state_t)); + exchange_state_server_SNEP->handle = handle; + exchange_state_server_SNEP->state = NET_NFC_STATE_EXCHANGER_SERVER; + exchange_state_server_SNEP->step = NET_NFC_LLCP_STEP_01; + exchange_state_server_SNEP->user_data = NULL; + + net_nfc_service_llcp_add_state(exchange_state_server_SNEP); + + if (_net_nfc_service_llcp_snep_server(exchange_state_server_SNEP, result) == false) + { + return false; + } + + net_nfc_llcp_state_t * conn_handover_selector = NULL; + _net_nfc_util_alloc_mem(conn_handover_selector, sizeof (net_nfc_llcp_state_t)); + conn_handover_selector->handle = handle; + conn_handover_selector->state = NET_NFC_STATE_CONN_HANDOVER_SELECT; + conn_handover_selector->step = NET_NFC_LLCP_STEP_01; + conn_handover_selector->user_data = NULL; + + net_nfc_service_llcp_add_state(conn_handover_selector); + + if (net_nfc_service_llcp_connection_handover_selector(conn_handover_selector, result) == false) + { + return false; + } +#endif + } + } + + DEBUG_SERVER_MSG("handle->app_type = [%d]", handle->app_type); + + { + net_nfc_response_p2p_discovered_t req_msg = { 0, }; + req_msg.handle = handle; + req_msg.result = NET_NFC_OK; + + net_nfc_broadcast_response_msg(NET_NFC_MESSAGE_P2P_DISCOVERED, &req_msg, sizeof(net_nfc_response_p2p_discovered_t), NULL); + } + + DEBUG_SERVER_MSG("stand alone llcp service is finished"); + + return false; +} + +static bool _net_nfc_service_llcp_state_process(net_nfc_request_msg_t *msg) +{ + net_nfc_request_llcp_msg_t *llcp_msg = (net_nfc_request_llcp_msg_t *)msg; + net_nfc_llcp_state_t *state = NULL; + bool result; + net_nfc_error_e error; + + DEBUG_SERVER_MSG("llcp service by nfc-manager"); + + if (msg == NULL) + { + DEBUG_SERVER_MSG("msg is NULL"); + return false; + } + + state = (net_nfc_llcp_state_t *)(llcp_msg->user_param); + + if (state == NULL || !net_nfc_service_llcp_is_valid_state(state)) + { + DEBUG_SERVER_MSG("state is NULL"); + return false; + } + + switch (msg->request_type) + { + case NET_NFC_MESSAGE_SERVICE_LLCP_SOCKET_ACCEPTED_ERROR : + case NET_NFC_MESSAGE_SERVICE_LLCP_SOCKET_ERROR : + state->step = NET_NFC_STATE_SOCKET_ERROR; + break; + + default : + break; + } + + state->prev_result = llcp_msg->result; + + DEBUG_SERVER_MSG("service type = [%d]", state->state); + + switch (state->state) + { + case NET_NFC_STATE_EXCHANGER_SERVER : + DEBUG_SERVER_MSG("exchanger server service"); + net_nfc_server_set_server_state(NET_NFC_SNEP_SERVER_CONNECTED); + result = _net_nfc_service_llcp_snep_server(state, &error); + break; + + case NET_NFC_STATE_EXCHANGER_CLIENT : + DEBUG_SERVER_MSG("exchanger client service"); + memcpy(¤t_llcp_client_state, state, sizeof(net_nfc_llcp_state_t)); + result = _net_nfc_service_llcp_client(state, &error); + break; + + case NET_NFC_STATE_EXCHANGER_SERVER_NPP : + DEBUG_SERVER_MSG("exchanger sesrver npp"); + net_nfc_server_set_server_state(NET_NFC_SNEP_SERVER_CONNECTED); + result = _net_nfc_service_llcp_npp_server(state, &error); + break; + + case NET_NFC_STATE_CONN_HANDOVER_REQUEST : + DEBUG_SERVER_MSG("NET_NFC_STATE_CONN_HANDOVER_REQUEST"); + result = net_nfc_service_llcp_connection_handover_requester(state, &error); + break; + + case NET_NFC_STATE_CONN_HANDOVER_SELECT : + DEBUG_SERVER_MSG("NET_NFC_STATE_CONN_HANDOVER_SELECT"); + result = net_nfc_service_llcp_connection_handover_selector(state, &error); + break; + + default : + DEBUG_SERVER_MSG("Unkown state state name: %d", state->state); + return false; + } + + return result; +} + +bool net_nfc_service_llcp_process_accept(net_nfc_request_msg_t *msg) +{ + bool res = false; + net_nfc_request_accept_socket_t *accept = (net_nfc_request_accept_socket_t *)msg; + net_nfc_llcp_state_t *state = NULL; + + if (accept == NULL || (void *)accept->user_param == NULL) + { + return false; + } + + if (msg->request_type == NET_NFC_MESSAGE_SERVICE_LLCP_ACCEPT) + { + state = (net_nfc_llcp_state_t *)accept->user_param; + + state->incomming_socket = accept->incomming_socket; + + DEBUG_SERVER_MSG("Incomming socket : %X", state->incomming_socket); + + res = _net_nfc_service_llcp_state_process(msg); + } + + return res; +} + +bool net_nfc_service_llcp_disconnect_target(net_nfc_request_msg_t *msg) +{ + net_nfc_request_llcp_msg_t *llcp_msg = (net_nfc_request_llcp_msg_t *)msg; + net_nfc_target_handle_s *handle = NULL; + + DEBUG_SERVER_MSG("llcp disconnect target"); + + if (llcp_msg == NULL) + return false; + + handle = (net_nfc_target_handle_s *)llcp_msg->user_param; + if (handle != NULL) + { + net_nfc_error_e result = NET_NFC_OK; + + if (net_nfc_controller_disconnect(handle, &result) == false) + { + if (result != NET_NFC_NOT_CONNECTED) + { + net_nfc_controller_exception_handler(); + } + else + { + DEBUG_SERVER_MSG("target was not connected."); + } + } + net_nfc_server_set_server_state(NET_NFC_SERVER_IDLE); + } + else + { + DEBUG_SERVER_MSG("the target ID = [0x%p] was not connected before. current device may be a TARGET", handle); + } + + { + net_nfc_response_llcp_detached_t message = { 0, }; + message.result = NET_NFC_OK; + net_nfc_broadcast_response_msg(NET_NFC_MESSAGE_P2P_DETACHED, &message, sizeof(net_nfc_response_llcp_detached_t), NULL); + } + + llcp_msg->user_param = 0; /*detail message should be NULL, because the handle is already freed in disconnect function */ + + return true; +} + +bool net_nfc_service_llcp_process_socket_error(net_nfc_request_msg_t *msg) +{ + net_nfc_request_llcp_msg_t *llcp_msg = (net_nfc_request_llcp_msg_t *)msg; + bool res = false; + + if (msg == NULL) + return false; + + if (net_nfc_server_check_client_is_running(llcp_msg->client_fd)) + { + /* in case of slave mode */ + net_nfc_response_llcp_socket_error_t *error = (net_nfc_response_llcp_socket_error_t *)llcp_msg->user_param; + + error->error = llcp_msg->result; + DEBUG_SERVER_MSG("Socket error returned [%d]", error->error); + return net_nfc_send_response_msg(llcp_msg->client_fd, NET_NFC_MESSAGE_LLCP_ERROR, error, sizeof(net_nfc_response_llcp_socket_error_t), NULL); + } + + res = _net_nfc_service_llcp_state_process(msg); + + llcp_msg->user_param = 0; + + return res; +} + +bool net_nfc_service_llcp_process_accepted_socket_error(net_nfc_request_msg_t *msg) +{ + net_nfc_request_llcp_msg_t *llcp_msg = (net_nfc_request_llcp_msg_t *)msg; + bool res = false; + + if (msg == NULL) + return false; + + if (net_nfc_server_check_client_is_running(llcp_msg->client_fd)) + { + /* in case of slave mode the error message will be deliver to client stub*/ + net_nfc_response_llcp_socket_error_t *error = (net_nfc_response_llcp_socket_error_t *)llcp_msg->user_param; + error->error = llcp_msg->result; + return net_nfc_send_response_msg(llcp_msg->client_fd, NET_NFC_MESSAGE_LLCP_ERROR, error, sizeof(net_nfc_response_llcp_socket_error_t), NULL); + } + + res = _net_nfc_service_llcp_state_process(msg); + + llcp_msg->user_param = 0; + + return res; +} + +bool net_nfc_service_llcp_process_connect_socket(net_nfc_request_msg_t *msg) +{ + net_nfc_request_msg_t *llcp_msg = (net_nfc_request_msg_t *)msg; + bool res = false; + + if (msg == NULL) + return false; + + res = _net_nfc_service_llcp_state_process(msg); + + llcp_msg->user_param = 0; + + return res; +} + +bool net_nfc_service_llcp_process_connect_sap_socket(net_nfc_request_msg_t *msg) +{ + net_nfc_request_llcp_msg_t *llcp_msg = (net_nfc_request_llcp_msg_t *)msg; + bool res = false; + + if (msg == NULL) + return false; + + if (net_nfc_server_check_client_is_running(llcp_msg->client_fd)) + { + net_nfc_response_connect_sap_socket_t *detail = (net_nfc_response_connect_sap_socket_t *)llcp_msg->user_param; + detail->result = llcp_msg->result; + return net_nfc_send_response_msg(llcp_msg->client_fd, NET_NFC_MESSAGE_LLCP_CONNECT_SAP, detail, sizeof(net_nfc_response_connect_sap_socket_t), NULL); + } + res = _net_nfc_service_llcp_state_process(msg); + + llcp_msg->user_param = 0; + + return res; +} + +bool net_nfc_service_llcp_process_send_socket(net_nfc_request_msg_t *msg) +{ + net_nfc_request_msg_t *llcp_msg = (net_nfc_request_msg_t *)msg; + bool res = false; + + if (msg == NULL) + return false; + + res = _net_nfc_service_llcp_state_process(msg); + + llcp_msg->user_param = 0; + + return res; +} + +bool net_nfc_service_llcp_process_send_to_socket(net_nfc_request_msg_t* msg) +{ + net_nfc_request_llcp_msg_t *llcp_msg = (net_nfc_request_llcp_msg_t *)msg; + bool res = false; + + if (msg == NULL) + return false; + + if (net_nfc_server_check_client_is_running(llcp_msg->client_fd)) + { + /* in case of slave mode the error message will be deliver to client stub*/ + net_nfc_response_send_socket_t *detail = (net_nfc_response_send_socket_t *)llcp_msg->user_param; + detail->result = llcp_msg->result; + return net_nfc_send_response_msg(llcp_msg->client_fd, NET_NFC_MESSAGE_LLCP_SEND_TO, detail, sizeof(net_nfc_response_send_socket_t), NULL); + } + res = _net_nfc_service_llcp_state_process(msg); + + llcp_msg->user_param = 0; + + return res; +} + +bool net_nfc_service_llcp_process_receive_socket(net_nfc_request_msg_t *msg) +{ + net_nfc_request_msg_t *llcp_msg = (net_nfc_request_msg_t *)msg; + bool res = false; + + if (msg == NULL) + return false; + + res = _net_nfc_service_llcp_state_process(msg); + + llcp_msg->user_param = 0; + + return res; +} + +bool net_nfc_service_llcp_process_receive_from_socket(net_nfc_request_msg_t *msg) +{ + net_nfc_request_llcp_msg_t *llcp_msg = (net_nfc_request_llcp_msg_t *)msg; + bool res = false; + + if (msg == NULL) + return false; + + if (net_nfc_server_check_client_is_running(llcp_msg->client_fd)) + { + net_nfc_response_receive_socket_t *detail = (net_nfc_response_receive_socket_t *)llcp_msg->user_param; + detail->result = llcp_msg->result; + return net_nfc_send_response_msg(llcp_msg->client_fd, NET_NFC_MESSAGE_LLCP_RECEIVE_FROM, detail, sizeof(net_nfc_response_receive_socket_t), + detail->data.buffer, detail->data.length, NULL); + } + res = _net_nfc_service_llcp_state_process(msg); + + llcp_msg->user_param = 0; + + return res; +} + +bool net_nfc_service_llcp_process_disconnect_socket(net_nfc_request_msg_t *msg) +{ + net_nfc_request_llcp_msg_t *llcp_msg = (net_nfc_request_llcp_msg_t *)msg; + bool res = false; + + if (msg == NULL) + return false; + + if (net_nfc_server_check_client_is_running(llcp_msg->client_fd)) + { + net_nfc_response_disconnect_socket_t *detail = (net_nfc_response_disconnect_socket_t *)llcp_msg->user_param; + detail->result = llcp_msg->result; + return net_nfc_broadcast_response_msg(NET_NFC_MESSAGE_LLCP_DISCONNECT, detail, sizeof(net_nfc_response_disconnect_socket_t), NULL); + } + + res = _net_nfc_service_llcp_state_process(msg); + + llcp_msg->user_param = 0; + + return res; +} + +net_nfc_error_e net_nfc_service_send_exchanger_msg(net_nfc_request_p2p_send_t *msg) +{ + net_nfc_error_e error = NET_NFC_OK; + data_s *ex_data = NULL; + net_nfc_llcp_state_t * exchange_state_client = NULL; + + DEBUG_SERVER_MSG("send exchanger msg to remote client"); + + if (msg == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + if (msg->handle == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + _net_nfc_util_alloc_mem(ex_data, sizeof(data_s)); + if (ex_data == NULL) + { + DEBUG_SERVER_MSG(" alocation is failed"); + return NET_NFC_ALLOC_FAIL; + } + ex_data->length = msg->data.length; + + _net_nfc_util_alloc_mem(ex_data->buffer, ex_data->length); + if (ex_data->buffer == NULL) + { + DEBUG_SERVER_MSG(" alocation is failed"); + _net_nfc_util_free_mem(ex_data); + return NET_NFC_ALLOC_FAIL; + } + memcpy(ex_data->buffer, &msg->data.buffer, msg->data.length); + + _net_nfc_util_alloc_mem(exchange_state_client, sizeof(net_nfc_llcp_state_t)); + if (exchange_state_client == NULL) + { + DEBUG_SERVER_MSG(" alocation is failed"); + _net_nfc_util_free_mem(ex_data); + _net_nfc_util_free_mem(ex_data->buffer); + return NET_NFC_ALLOC_FAIL; + } + + exchange_state_client->client_fd = msg->client_fd; + exchange_state_client->handle = msg->handle; + exchange_state_client->state = NET_NFC_STATE_EXCHANGER_CLIENT; + exchange_state_client->step = NET_NFC_LLCP_STEP_01; + exchange_state_client->payload = ex_data; + exchange_state_client->user_data = (void *)msg->user_param; + + net_nfc_service_llcp_add_state(exchange_state_client); + + if (_net_nfc_service_llcp_client(exchange_state_client, &error) == true) + { + return NET_NFC_OK; + } + else + { + DEBUG_SERVER_MSG("exchange client operation is failed"); + return NET_NFC_OPERATION_FAIL; + } +} + +#if 0 +net_nfc_error_e _net_nfc_service_llcp_get_server_configuration_value(char* service_name, char* attr_name, char* attr_value) +{ + if (service_name == NULL || attr_name == NULL || attr_value == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + FILE* fp = NULL; + char file_path[512] = { 0, }; + + snprintf(file_path, 512, "%s/%s/%s", NET_NFC_MANAGER_DATA_PATH, NET_NFC_MANAGER_DATA_PATH_CONFIG, NET_NFC_MANAGER_LLCP_CONFIG_FILE_NAME); + + if ((fp = fopen(file_path, "r")) == NULL) + { + return NET_NFC_UNKNOWN_ERROR; + } + + char temp[128] = { 0, }; + while (fgets(temp, sizeof(temp), fp) != NULL) + { + net_nfc_util_strip_string(temp, 128); + char service_name_temp[128] = { 0, }; + + if (temp[0] == '#') + continue; + + if (temp[0] == '[') + { + int i = 0; + char ch = 0; + + while (i < sizeof(temp) && (ch = temp[i++]) != '\n') + { + if (ch == ']') + { + memcpy(service_name_temp, &temp[1], i - 2); + break; + } + } + + if (strlen(service_name_temp) != 0) + { + DEBUG_SERVER_MSG("[%s] is found", service_name_temp); + if (strcmp(service_name_temp, service_name) == 0) + { + DEBUG_SERVER_MSG("[%s] and [%s] are matched", service_name_temp, service_name); + + while (fgets(temp, sizeof(temp), fp) != NULL) + { + if (strcmp(temp, "\n") == 0) + break; + + net_nfc_util_strip_string(temp, 128); + + char* pos = NULL; + + if ((pos = strstr(temp, "=")) != NULL) + { + char attr_name_temp[64] = { 0, }; + + memcpy(attr_name_temp, temp, pos - temp); + + DEBUG_SERVER_MSG("attr_name = [%s]", attr_name); + + if (strcmp(attr_name, attr_name_temp) == 0) + { + memcpy(attr_value, pos + 1, strlen(pos + 1) - 1); + DEBUG_SERVER_MSG("attr_value = [%s]", attr_value); + + if (fp != NULL) + fclose(fp); + + return NET_NFC_OK; + } + + } + else + break; + + } + } + } + } + } + + if (fp != NULL) + fclose(fp); + + return NET_NFC_NO_DATA_FOUND; + +} +#endif + +static bool _net_nfc_service_llcp_snep_server(net_nfc_llcp_state_t *state, net_nfc_error_e* result) +{ + bool need_clean_up = false; + + if (result == NULL) + { + DEBUG_SERVER_MSG("result is NULL"); + return false; + } + + *result = NET_NFC_OK; + + switch (state->step) + { + case NET_NFC_LLCP_STEP_01 : + { + DEBUG_SERVER_MSG("step 1"); + + if (net_nfc_controller_llcp_create_socket(&(state->socket), NET_NFC_LLCP_SOCKET_TYPE_CONNECTIONORIENTED, SNEP_MAX_BUFFER, 1, result, state) == false) + { + state->step = NET_NFC_STATE_ERROR; + break; + } + + DEBUG_SERVER_MSG("bind server socket with service acess point = [0x%x]", SNEP_SAP); + if (net_nfc_controller_llcp_bind(state->socket, SNEP_SAP, result) == false) + { + state->step = NET_NFC_STATE_ERROR; + break; + } + + DEBUG_SERVER_MSG("listen server socket with service access name = [%s]", SNEP_SAN); + state->step = NET_NFC_LLCP_STEP_02; + if (net_nfc_controller_llcp_listen(state->handle, (uint8_t *)SNEP_SAN, state->socket, result, state) == false) + { + state->step = NET_NFC_STATE_ERROR; + break; + } + + state->type_app_protocol = NET_NFC_SNEP; + } + break; + + case NET_NFC_LLCP_STEP_02 : + { + DEBUG_SERVER_MSG("step 2"); + + if (state->prev_result != NET_NFC_OK) + { + DEBUG_SERVER_MSG("snep: listen is failed..."); + state->step = NET_NFC_STATE_ERROR; + break; + } + + net_nfc_llcp_state_t * new_client = NULL; + _net_nfc_util_alloc_mem(new_client, sizeof (net_nfc_llcp_state_t)); + + new_client->handle = state->handle; + new_client->state = state->state; + new_client->socket = state->incomming_socket; + new_client->step = NET_NFC_LLCP_STEP_03; + new_client->user_data = NULL; + + memset(snep_server_data.buffer, 0x00, SNEP_MAX_BUFFER); + snep_server_data.length = SNEP_MAX_BUFFER; + + current_llcp_server_state.handle = state->handle; + current_llcp_server_state.socket = state->incomming_socket; + + net_nfc_service_llcp_add_state(new_client); + + if (net_nfc_controller_llcp_recv(new_client->handle, new_client->socket, &snep_server_data, result, new_client) == false) + { + state->step = NET_NFC_STATE_ERROR; + break; + } + } + break; + + case NET_NFC_LLCP_STEP_03 : + { + DEBUG_SERVER_MSG("step 3"); + DEBUG_SERVER_MSG("receive request msg from snep client"); + + state->step = NET_NFC_LLCP_STEP_04; + + if (state->prev_result != NET_NFC_OK) + { + DEBUG_SERVER_MSG("snep : recevie is failed..."); + state->step = NET_NFC_STATE_ERROR; + break; + } + + uint8_t resp_code = 0; + data_s* resp_msg = NULL; + + if (_net_nfc_service_llcp_snep_check_req_msg(&snep_server_data, &resp_code) != NET_NFC_OK) + { + DEBUG_SERVER_MSG("Not valid request msg = [0x%X]", resp_code); + resp_msg = _net_nfc_service_llcp_snep_create_msg(resp_code, NULL); + + if (net_nfc_controller_llcp_send(state->handle, state->socket, resp_msg, result, state) == false) + { + _net_nfc_util_free_mem(resp_msg->buffer); + _net_nfc_util_free_mem(resp_msg); + } + } + else + { + uint32_t information_length = 0; + if (_net_nfc_service_llcp_snep_get_information_length(&snep_server_data, &information_length) == NET_NFC_OK) + { + DEBUG_SERVER_MSG("MAX capa of server is = [%d] and received byte is = [%d]", SNEP_MAX_BUFFER, snep_server_data.length); + + /* msg = header(fixed 6 byte) + information(changable) */ + if (information_length + 6 > SNEP_MAX_BUFFER) + { + DEBUG_SERVER_MSG("request msg length is too long to receive at a time"); + DEBUG_SERVER_MSG("total msg length is = [%d]", information_length + 6); + + data_s* fragment = NULL; + + _net_nfc_util_alloc_mem(fragment, sizeof(data_s)); + if (fragment == NULL) + { + state->step = NET_NFC_STATE_ERROR; + break; + } + + _net_nfc_util_alloc_mem(fragment->buffer, (information_length + 6) * sizeof(uint8_t)); + if (fragment->buffer == NULL) + { + state->step = NET_NFC_STATE_ERROR; + _net_nfc_util_free_mem(fragment); + break; + } + + state->step = NET_NFC_LLCP_STEP_05; + + fragment->length = information_length + 6; + state->payload = fragment; + + memcpy(fragment->buffer, snep_server_data.buffer, snep_server_data.length); + + /* set zero. this is first time */ + state->fragment_offset = 0; + state->fragment_offset += snep_server_data.length; + + resp_msg = _net_nfc_service_llcp_snep_create_msg(SNEP_RESP_CONT, NULL); + + DEBUG_SERVER_MSG("send continue response msg"); + + if (net_nfc_controller_llcp_send(state->handle, state->socket, resp_msg, result, state) == false) + { + _net_nfc_util_free_mem(resp_msg->buffer); + _net_nfc_util_free_mem(resp_msg); + } + } + else + { + resp_msg = _net_nfc_service_llcp_snep_create_msg(SNEP_RESP_SUCCESS, NULL); + + DEBUG_SERVER_MSG("send success response msg"); + + if (net_nfc_controller_llcp_send(state->handle, state->socket, resp_msg, result, state) == false) + { + _net_nfc_util_free_mem(resp_msg->buffer); + _net_nfc_util_free_mem(resp_msg); + } + + net_nfc_manager_util_play_sound(NET_NFC_TASK_END); + + data_s temp = { NULL, 0 }; + + /* version, command, information_length are head. */ + temp.buffer = snep_server_data.buffer + sizeof(uint8_t) + sizeof(uint8_t) + sizeof(uint32_t); + if ((_net_nfc_service_llcp_snep_get_information_length(&snep_server_data, &(temp.length))) == NET_NFC_OK) + { + net_nfc_response_p2p_receive_t resp = { 0 }; + data_s data; + + DEBUG_SERVER_MSG("process received msg"); + + _net_nfc_util_alloc_mem(data.buffer, temp.length); + + memcpy(data.buffer, temp.buffer, temp.length); + + resp.data.length = temp.length; + resp.result = NET_NFC_OK; + + net_nfc_broadcast_response_msg(NET_NFC_MESSAGE_P2P_RECEIVE, (void*)&resp, sizeof(net_nfc_response_p2p_receive_t), + data.buffer, resp.data.length, NULL); + + net_nfc_service_msg_processing(&temp); + } + } + } + } + } + break; + + case NET_NFC_LLCP_STEP_04 : + { + DEBUG_SERVER_MSG("step 4"); + + if (state->prev_result != NET_NFC_OK) + { + DEBUG_SERVER_MSG("snep : sending is failed..."); + state->step = NET_NFC_STATE_ERROR; + break; + } + else + { + net_nfc_error_e error; + + DEBUG_SERVER_MSG("snep : sending response is success..."); + state->step = NET_NFC_LLCP_STEP_02; + state->handle = current_llcp_server_state.handle; + state->incomming_socket = current_llcp_server_state.socket; + + _net_nfc_service_llcp_snep_server(state, &error); + } + } + break; + + case NET_NFC_LLCP_STEP_05 : + { + DEBUG_SERVER_MSG("step 5"); + + if (state->prev_result != NET_NFC_OK) + { + DEBUG_SERVER_MSG("snep: sending CONT response is failed..."); + state->step = NET_NFC_STATE_ERROR; + break; + } + + state->step = NET_NFC_LLCP_STEP_06; + + memset(snep_server_data.buffer, 0x00, SNEP_MAX_BUFFER); + snep_server_data.length = SNEP_MAX_BUFFER; + + if (net_nfc_controller_llcp_recv(state->handle, state->socket, &snep_server_data, result, state) == false) + { + state->step = NET_NFC_STATE_ERROR; + break; + } + } + break; + + case NET_NFC_LLCP_STEP_06 : + { + DEBUG_SERVER_MSG("step 6"); + + if (state->prev_result != NET_NFC_OK) + { + DEBUG_SERVER_MSG("snep: recv is failed..."); + state->step = NET_NFC_STATE_ERROR; + break; + } + + if (((data_s*)state->payload)->length > (snep_server_data.length + state->fragment_offset)) + { + /* receive more */ + /* copy fragment to buffer. */ + data_s* fragment = state->payload; + if (fragment != NULL) + { + memcpy(fragment->buffer + state->fragment_offset, snep_server_data.buffer, snep_server_data.length); + state->fragment_offset += snep_server_data.length; + } + + state->step = NET_NFC_LLCP_STEP_06; + + memset(snep_server_data.buffer, 0x00, SNEP_MAX_BUFFER); + snep_server_data.length = SNEP_MAX_BUFFER; + + if (net_nfc_controller_llcp_recv(state->handle, state->socket, &snep_server_data, result, state) == false) + { + state->step = NET_NFC_STATE_ERROR; + break; + } + } + else if (((data_s*)state->payload)->length == (snep_server_data.length + state->fragment_offset)) + { + /* receving is completed */ + DEBUG_SERVER_MSG("recv is completed"); + + data_s* fragment = state->payload; + + if (fragment != NULL) + { + memcpy(fragment->buffer + state->fragment_offset, snep_server_data.buffer, snep_server_data.length); + state->fragment_offset += snep_server_data.length; + } + + data_s* resp_msg = _net_nfc_service_llcp_snep_create_msg(SNEP_RESP_SUCCESS, NULL); + + if (resp_msg != NULL) + { + if (net_nfc_controller_llcp_send(state->handle, state->socket, resp_msg, result, state) == false) + { + + _net_nfc_util_free_mem(resp_msg->buffer); + _net_nfc_util_free_mem(resp_msg); + } + } + + net_nfc_manager_util_play_sound(NET_NFC_TASK_END); + + data_s temp = { NULL, 0 }; + + /* version, command, information_length are head. */ + temp.buffer = ((data_s*)(state->payload))->buffer + sizeof(uint8_t) + sizeof(uint8_t) + sizeof(uint32_t); + if ((_net_nfc_service_llcp_snep_get_information_length(((data_s*)(state->payload)), &(temp.length))) == NET_NFC_OK) + { + net_nfc_response_p2p_receive_t resp = { 0 }; + data_s data; + + _net_nfc_util_alloc_mem(data.buffer, temp.length); + + memcpy(data.buffer, temp.buffer, temp.length); + + resp.data.length = temp.length; + resp.result = NET_NFC_OK; + + net_nfc_broadcast_response_msg(NET_NFC_MESSAGE_P2P_RECEIVE, (void*)&resp, sizeof(net_nfc_response_p2p_receive_t), + data.buffer, resp.data.length, NULL); + + net_nfc_service_msg_processing(&temp); + } + + _net_nfc_util_free_mem(((data_s*)(state->payload))->buffer); + _net_nfc_util_free_mem(state->payload); + state->payload = NULL; + state->step = 0; + } + else + { + DEBUG_SERVER_MSG("msg length is not matched. we have got more message"); + + data_s* resp_msg = _net_nfc_service_llcp_snep_create_msg(SNEP_RESP_BAD_REQ, NULL); + + if (resp_msg != NULL) + { + if (net_nfc_controller_llcp_send(state->handle, state->socket, resp_msg, result, state) == false) + { + + _net_nfc_util_free_mem(resp_msg->buffer); + _net_nfc_util_free_mem(resp_msg); + } + } + _net_nfc_util_free_mem(((data_s*)(state->payload))->buffer); + _net_nfc_util_free_mem(state->payload); + state->payload = NULL; + state->step = 0; + } + } + break; + + case NET_NFC_STATE_SOCKET_ERROR : + { + DEBUG_SERVER_MSG("snep : socket error is received %d", state->prev_result); + need_clean_up = true; + } + break; + + default : + { + DEBUG_SERVER_MSG("unknown step = [%d]", state->step); + need_clean_up = true; + } + break; + + } + + if (state->step == NET_NFC_STATE_ERROR) + { + net_nfc_manager_util_play_sound(NET_NFC_TASK_ERROR); + DEBUG_SERVER_MSG("nfc state error"); + state->step = 0; + } + + if (need_clean_up == true) + { + DEBUG_SERVER_MSG("socket close :: snep server"); + + net_nfc_server_unset_server_state(NET_NFC_SNEP_SERVER_CONNECTED); + + net_nfc_controller_llcp_socket_close(state->socket, result); + net_nfc_service_llcp_remove_state(state); + _net_nfc_util_free_mem(state); + } + + if (*result != NET_NFC_OK) + { + return false; + } + return true; +} + +static bool _net_nfc_service_llcp_npp_server(net_nfc_llcp_state_t * state, net_nfc_error_e* result) +{ + bool need_clean_up = false; + + DEBUG_SERVER_MSG("_net_nfc_service_llcp_npp_server"); + + if (result == NULL) + { + DEBUG_SERVER_MSG("result is NULL"); + return false; + } + *result = NET_NFC_OK; + + switch (state->step) + { + case NET_NFC_LLCP_STEP_01 : + { + DEBUG_SERVER_MSG("NPP step 1"); + + if (net_nfc_controller_llcp_create_socket(&(state->socket), NET_NFC_LLCP_SOCKET_TYPE_CONNECTIONORIENTED, SNEP_MAX_BUFFER, 1, result, state) == false) + { + DEBUG_SERVER_MSG("creaete socket for npp FAIL"); + state->step = NET_NFC_STATE_ERROR; + break; + } + + if (net_nfc_controller_llcp_bind(state->socket, NPP_SAP, result) == false) + { + DEBUG_SERVER_MSG("bind socket for npp FAIL"); + state->step = NET_NFC_STATE_ERROR; + break; + } + + state->step = NET_NFC_LLCP_STEP_02; + if (net_nfc_controller_llcp_listen(state->handle, (uint8_t *)NPP_SAN, state->socket, result, state) == false) + { + DEBUG_SERVER_MSG("listen socket for npp FAIL"); + state->step = NET_NFC_STATE_ERROR; + break; + } + state->type_app_protocol = NET_NFC_NPP; + } + break; + + case NET_NFC_LLCP_STEP_02 : + { + DEBUG_SERVER_MSG("step 2"); + + if (state->prev_result != NET_NFC_OK) + { + DEBUG_SERVER_MSG("NPP: listen is failed..."); + state->step = NET_NFC_STATE_ERROR; + break; + } + + net_nfc_llcp_state_t * new_client = NULL; + _net_nfc_util_alloc_mem(new_client, sizeof (net_nfc_llcp_state_t)); + + new_client->handle = state->handle; + new_client->state = state->state; + new_client->socket = state->incomming_socket; + new_client->step = NET_NFC_LLCP_STEP_03; + new_client->user_data = NULL; + + memset(snep_server_data.buffer, 0x00, SNEP_MAX_BUFFER); + snep_server_data.length = SNEP_MAX_BUFFER; + + current_llcp_server_state.handle = state->handle; + current_llcp_server_state.socket = state->incomming_socket; + net_nfc_service_llcp_add_state(new_client); + + if (net_nfc_controller_llcp_recv(new_client->handle, new_client->socket, &snep_server_data, result, new_client) == false) + { + state->step = NET_NFC_STATE_ERROR; + break; + } + } + break; + + case NET_NFC_LLCP_STEP_03 : + { + /* send back success response */ + DEBUG_SERVER_MSG("step 3"); + DEBUG_SERVER_MSG("receive request msg from snep client"); + + state->step = NET_NFC_LLCP_STEP_04; + + if (state->prev_result != NET_NFC_OK) + { + DEBUG_SERVER_MSG("snep : recevie is failed..."); + state->step = NET_NFC_STATE_ERROR; + break; + } + + uint8_t resp_code = 0; + data_s* resp_msg = NULL; + + if (_net_nfc_service_llcp_npp_check_req_msg(&snep_server_data, &resp_code) != NET_NFC_OK) + { + DEBUG_SERVER_MSG("Not valid request msg = [0x%X]", resp_code); + state->step = NET_NFC_STATE_ERROR; + break; + } + else + { + uint32_t information_length = 0; + if (_net_nfc_service_llcp_npp_get_information_length(&snep_server_data, &information_length) == NET_NFC_OK) + { + DEBUG_SERVER_MSG("MAX capa of server is = [%d] and received byte is = [%d]", SNEP_MAX_BUFFER, snep_server_data.length); + + /* msg = header(fixed 10 byte) + information(changable) */ + if (information_length + 10 > SNEP_MAX_BUFFER) + { + DEBUG_SERVER_MSG("request msg length is too long to receive at a time"); + + DEBUG_SERVER_MSG("total msg length is = [%d]", information_length + 10); + + data_s* fragment = NULL; + + _net_nfc_util_alloc_mem(fragment, sizeof(data_s)); + if (fragment == NULL) + { + state->step = NET_NFC_STATE_ERROR; + break; + } + + _net_nfc_util_alloc_mem(fragment->buffer, (information_length + 10) * sizeof(uint8_t)); + if (fragment->buffer == NULL) + { + state->step = NET_NFC_STATE_ERROR; + _net_nfc_util_free_mem(fragment); + break; + } + + state->step = NET_NFC_LLCP_STEP_05; + + fragment->length = information_length + 10; + state->payload = fragment; + + memcpy(fragment->buffer, snep_server_data.buffer, snep_server_data.length); + + /* set zero. this is first time */ + state->fragment_offset = 0; + state->fragment_offset += snep_server_data.length; + + resp_msg = _net_nfc_service_llcp_snep_create_msg(SNEP_RESP_CONT, NULL); + + DEBUG_SERVER_MSG("send continue response msg"); + + if (net_nfc_controller_llcp_send(state->handle, state->socket, resp_msg, result, state) == false) + { + + _net_nfc_util_free_mem(resp_msg->buffer); + _net_nfc_util_free_mem(resp_msg); + } + } + else /*the size of the ndef is smaller than the max size*/ + { + DEBUG_SERVER_MSG("Success to receive the msg"); + + net_nfc_manager_util_play_sound(NET_NFC_TASK_END); + + data_s temp = { NULL, 0 }; + + /* version, command, information_length are head. */ + temp.buffer = snep_server_data.buffer + sizeof(uint8_t) + sizeof(uint8_t) + sizeof(uint32_t) + sizeof(uint32_t); + DEBUG_SERVER_MSG("check the string = [%s]", temp.buffer); + if ((_net_nfc_service_llcp_npp_get_information_length(&snep_server_data, &(temp.length))) == NET_NFC_OK) + { + net_nfc_response_p2p_receive_t resp = { 0 }; + data_s data; + + DEBUG_SERVER_MSG("process received msg"); + + _net_nfc_util_alloc_mem(data.buffer, temp.length); + + memcpy(data.buffer, temp.buffer, temp.length); + + resp.data.length = temp.length; + resp.result = NET_NFC_OK; + + net_nfc_broadcast_response_msg(NET_NFC_MESSAGE_P2P_RECEIVE, (void*)&resp, sizeof(net_nfc_response_p2p_receive_t), + data.buffer, resp.data.length, NULL); + + net_nfc_service_msg_processing(&temp); + } + } + } + } + } + break; + + case NET_NFC_LLCP_STEP_04 : + { + DEBUG_SERVER_MSG("step 4"); + + if (state->prev_result != NET_NFC_OK) + { + DEBUG_SERVER_MSG("NPP : sending is failed..."); + state->step = NET_NFC_STATE_ERROR; + break; + } + else + { + net_nfc_error_e error; + + DEBUG_SERVER_MSG("NPP : Receiving the message is success..."); + state->step = NET_NFC_LLCP_STEP_02; + state->handle = current_llcp_server_state.handle; + state->incomming_socket = current_llcp_server_state.socket; + _net_nfc_service_llcp_npp_server(state, &error); + } + } + break; + + case NET_NFC_LLCP_STEP_05 : + { + DEBUG_SERVER_MSG("step 5"); + + if (state->prev_result != NET_NFC_OK) + { + DEBUG_SERVER_MSG("NPP: sending CONT response is failed..."); + state->step = NET_NFC_STATE_ERROR; + break; + } + + state->step = NET_NFC_LLCP_STEP_06; + + memset(snep_server_data.buffer, 0x00, SNEP_MAX_BUFFER); + snep_server_data.length = SNEP_MAX_BUFFER; + + if (net_nfc_controller_llcp_recv(state->handle, state->socket, &snep_server_data, result, state) == false) + { + state->step = NET_NFC_STATE_ERROR; + break; + } + } + break; + + case NET_NFC_LLCP_STEP_06 : + { + DEBUG_SERVER_MSG("step 6"); + + if (state->prev_result != NET_NFC_OK) + { + DEBUG_SERVER_MSG("snep: recv is failed..."); + state->step = NET_NFC_STATE_ERROR; + break; + } + + if (((data_s*)state->payload)->length > (snep_server_data.length + state->fragment_offset)) + { + /* receive more */ + /* copy fragment to buffer. */ + data_s* fragment = state->payload; + if (fragment != NULL) + { + memcpy(fragment->buffer + state->fragment_offset, snep_server_data.buffer, snep_server_data.length); + state->fragment_offset += snep_server_data.length; + } + + state->step = NET_NFC_LLCP_STEP_06; + + memset(snep_server_data.buffer, 0x00, SNEP_MAX_BUFFER); + snep_server_data.length = SNEP_MAX_BUFFER; + + if (net_nfc_controller_llcp_recv(state->handle, state->socket, &snep_server_data, result, state) == false) + { + state->step = NET_NFC_STATE_ERROR; + break; + } + } + else if (((data_s*)state->payload)->length == (snep_server_data.length + state->fragment_offset)) + { + /* receving is completed */ + DEBUG_SERVER_MSG("recv is completed"); + data_s* fragment = state->payload; + if (fragment != NULL) + { + memcpy(fragment->buffer + state->fragment_offset, snep_server_data.buffer, snep_server_data.length); + state->fragment_offset += snep_server_data.length; + } + + data_s* resp_msg = _net_nfc_service_llcp_snep_create_msg(SNEP_RESP_SUCCESS, NULL); + + if (resp_msg != NULL) + { + if (net_nfc_controller_llcp_send(state->handle, state->socket, resp_msg, result, state) == false) + { + _net_nfc_util_free_mem(resp_msg->buffer); + _net_nfc_util_free_mem(resp_msg); + } + } + + net_nfc_manager_util_play_sound(NET_NFC_TASK_END); + + data_s temp = { NULL, 0 }; + + /* version, command, information_length are head. */ + temp.buffer = ((data_s*)(state->payload))->buffer + sizeof(uint8_t) + sizeof(uint8_t) + sizeof(uint32_t); + if ((_net_nfc_service_llcp_snep_get_information_length(((data_s*)(state->payload)), &(temp.length))) == NET_NFC_OK) + { + net_nfc_response_p2p_receive_t resp = { 0 }; + data_s data; + + _net_nfc_util_alloc_mem(data.buffer, temp.length); + + memcpy(data.buffer, temp.buffer, temp.length); + + resp.data.length = temp.length; + resp.result = NET_NFC_OK; + + net_nfc_broadcast_response_msg(NET_NFC_MESSAGE_P2P_RECEIVE, (void*)&resp, sizeof(net_nfc_response_p2p_receive_t), + data.buffer, resp.data.length, NULL); + + net_nfc_service_msg_processing(&temp); + } + + _net_nfc_util_free_mem(((data_s*)(state->payload))->buffer); + _net_nfc_util_free_mem(state->payload); + state->payload = NULL; + state->step = 0; + } + else + { + DEBUG_SERVER_MSG("msg length is not matched. we have got more message"); + + data_s* resp_msg = _net_nfc_service_llcp_snep_create_msg(SNEP_RESP_BAD_REQ, NULL); + + if (resp_msg != NULL) + { + if (net_nfc_controller_llcp_send(state->handle, state->socket, resp_msg, result, state) == false) + { + _net_nfc_util_free_mem(resp_msg->buffer); + _net_nfc_util_free_mem(resp_msg); + } + } + + _net_nfc_util_free_mem(((data_s*)(state->payload))->buffer); + _net_nfc_util_free_mem(state->payload); + state->payload = NULL; + state->step = 0; + } + + net_nfc_error_e error; + + state->step = NET_NFC_LLCP_STEP_02; + state->handle = current_llcp_server_state.handle; + state->incomming_socket = current_llcp_server_state.socket; + _net_nfc_service_llcp_npp_server(state, &error); + } + break; + + case NET_NFC_STATE_SOCKET_ERROR : + { + DEBUG_SERVER_MSG("snep : socket error is received %d", state->prev_result); + need_clean_up = true; + } + break; + + default : + { + DEBUG_SERVER_MSG("unknown step = [%d]", state->step); + need_clean_up = true; + } + break; + } + + if (state->step == NET_NFC_STATE_ERROR) + { + /* server should not notify exchanger result to client application. it MUST be handled in nfc-manager side */ + net_nfc_manager_util_play_sound(NET_NFC_TASK_ERROR); + DEBUG_SERVER_MSG("nfc state error"); + state->step = 0; + } + + if (need_clean_up == true) + { + DEBUG_SERVER_MSG("socket close :: NPP server"); + + net_nfc_server_unset_server_state(NET_NFC_NPP_SERVER_CONNECTED); + + net_nfc_controller_llcp_socket_close(state->socket, result); + net_nfc_service_llcp_remove_state(state); + _net_nfc_util_free_mem(state); + } + + if (*result != NET_NFC_OK) + { + return false; + } + return true; +} + +static bool _net_nfc_service_llcp_client(net_nfc_llcp_state_t * state, net_nfc_error_e* result) +{ + bool need_clean_up = false; + + DEBUG_SERVER_MSG("_net_nfc_service_llcp_client [%d]", state->step); + + if (result == NULL) + { + DEBUG_SERVER_MSG("result is NULL"); + return false; + } + + *result = NET_NFC_OK; + + if (((net_nfc_server_get_server_state() & NET_NFC_SNEP_CLIENT_CONNECTED) || (net_nfc_server_get_server_state() & NET_NFC_NPP_CLIENT_CONNECTED)) + && state->step == NET_NFC_LLCP_STEP_01) + { + state->socket = current_llcp_client_state.socket; + state->type_app_protocol = current_llcp_client_state.type_app_protocol; + state->step = NET_NFC_LLCP_STEP_02; + } + + switch (state->step) + { + case NET_NFC_LLCP_STEP_01 : + { + DEBUG_SERVER_MSG("step 1"); + + if (net_nfc_controller_llcp_create_socket(&(state->socket), NET_NFC_LLCP_SOCKET_TYPE_CONNECTIONORIENTED, SNEP_MAX_BUFFER, 1, result, state) == false) + { + state->step = NET_NFC_STATE_ERROR; + DEBUG_SERVER_MSG(" Fail to Create socket for SNEP in client."); + break; + } + + DEBUG_SERVER_MSG("connect to remote server with socket = [0x%x]", state->socket); + + state->step = NET_NFC_LLCP_STEP_02; + + if (net_nfc_controller_llcp_connect_by_url(state->handle, state->socket, (uint8_t *)SNEP_SAN, result, state) == true) + { + DEBUG_SERVER_MSG("Success to connect by url for SNEP in client."); + net_nfc_server_set_server_state(NET_NFC_SNEP_CLIENT_CONNECTED); + state->type_app_protocol = NET_NFC_SNEP; + break; + } + else + { + state->step = NET_NFC_STATE_ERROR; + DEBUG_SERVER_MSG("Fail to connect to socket for snep & npp in client."); + break; + } + } + break; + + case NET_NFC_LLCP_STEP_02 : + { + DEBUG_SERVER_MSG("step 2"); + + if (state->prev_result != NET_NFC_OK) + { + DEBUG_SERVER_MSG("snep client: connect is failed [%d]", state->prev_result); + + if (NET_NFC_OPERATION_FAIL == state->prev_result) + { + if (net_nfc_controller_llcp_connect_by_url(state->handle, state->socket, (uint8_t *)"com.android.npp", result, state) == true) + { + DEBUG_SERVER_MSG("Success to connect by url for NPP in client."); + state->type_app_protocol = NET_NFC_NPP; + state->step = NET_NFC_LLCP_STEP_02; + net_nfc_server_set_server_state(NET_NFC_NPP_CLIENT_CONNECTED); + + break; + } + } + else + { + state->step = NET_NFC_STATE_ERROR; + } + break; + } + + if (state->payload == NULL) + { + DEBUG_SERVER_MSG("no data to send to server. just terminate client thread"); + state->step = NET_NFC_STATE_ERROR; + break; + } + + net_nfc_llcp_socket_option_s retmoe_socket_info = { 0, 0, 0 }; + if (net_nfc_controller_llcp_get_remote_socket_info(state->handle, state->socket, &retmoe_socket_info, result) == true) + { + state->max_capability = retmoe_socket_info.miu; + DEBUG_SERVER_MSG("SERVER MIU = [%d]", state->max_capability); + } + else + { + state->max_capability = SNEP_MAX_BUFFER; + DEBUG_SERVER_MSG("SERVER MIU = [%d]", state->max_capability); + } + + data_s* req_msg = NULL; + + if (state->type_app_protocol == NET_NFC_SNEP) + { + req_msg = _net_nfc_service_llcp_snep_create_msg(SNEP_REQ_PUT, (data_s *)state->payload); + } + else + { + req_msg = _net_nfc_service_llcp_npp_create_msg((data_s *)state->payload); + } + + _net_nfc_util_free_mem(((data_s *)state->payload)->buffer); + _net_nfc_util_free_mem(state->payload); + + state->payload = NULL; + + if (req_msg == NULL) + { + DEBUG_SERVER_MSG("failed to create req msg"); + state->step = NET_NFC_STATE_ERROR; + break; + } + + state->step = NET_NFC_LLCP_STEP_03; + + if (req_msg->length <= state->max_capability) + { + DEBUG_SERVER_MSG("send req data"); + + if (net_nfc_controller_llcp_send(state->handle, state->socket, req_msg, result, state) == false) + { + DEBUG_SERVER_MSG("failed to send req msg"); + _net_nfc_util_free_mem(req_msg->buffer); + _net_nfc_util_free_mem(req_msg); + state->step = NET_NFC_STATE_ERROR; + break; + } + else + { + _net_nfc_util_free_mem(req_msg->buffer); + _net_nfc_util_free_mem(req_msg); + } + } + else + { + /* send first fragment */ + DEBUG_SERVER_MSG("send first fragment"); + + data_s fragment = { NULL, 0 }; + + _net_nfc_util_alloc_mem(fragment.buffer, state->max_capability * sizeof(uint8_t)); + if (fragment.buffer == NULL) + { + _net_nfc_util_free_mem(req_msg->buffer); + _net_nfc_util_free_mem(req_msg); + state->payload = NULL; + state->step = NET_NFC_STATE_ERROR; + break; + } + + memcpy(fragment.buffer, req_msg->buffer, state->max_capability); + fragment.length = state->max_capability; + + data_s* extra_msg = NULL; + + _net_nfc_util_alloc_mem(extra_msg, sizeof(data_s)); + if (extra_msg == NULL) + { + _net_nfc_util_free_mem(req_msg->buffer); + _net_nfc_util_free_mem(req_msg); + _net_nfc_util_free_mem(fragment.buffer); + state->payload = NULL; + state->step = NET_NFC_STATE_ERROR; + break; + } + + _net_nfc_util_alloc_mem(extra_msg->buffer, (req_msg->length - state->max_capability) * sizeof(uint8_t)); + if (extra_msg->buffer == NULL) + { + _net_nfc_util_free_mem(req_msg->buffer); + _net_nfc_util_free_mem(req_msg); + _net_nfc_util_free_mem(extra_msg); + _net_nfc_util_free_mem(fragment.buffer); + state->payload = NULL; + state->step = NET_NFC_STATE_ERROR; + break; + } + + extra_msg->length = req_msg->length - state->max_capability; + memcpy(extra_msg->buffer, req_msg->buffer + state->max_capability, extra_msg->length); + + state->payload = extra_msg; + + net_nfc_controller_llcp_send(state->handle, state->socket, &fragment, result, state); + + _net_nfc_util_free_mem(req_msg->buffer); + _net_nfc_util_free_mem(req_msg); + _net_nfc_util_free_mem(fragment.buffer); + } + } + break; + + case NET_NFC_LLCP_STEP_03 : + { + DEBUG_SERVER_MSG("step 3"); + + if (state->prev_result != NET_NFC_OK) + { + DEBUG_SERVER_MSG("snep client: llcp send is failed [%d]", state->prev_result); + state->step = NET_NFC_STATE_ERROR; + break; + } + + state->step = NET_NFC_LLCP_STEP_04; + + if (state->type_app_protocol == NET_NFC_SNEP) + { + memset(snep_client_data.buffer, 0x00, SNEP_MAX_BUFFER); + snep_client_data.length = SNEP_MAX_BUFFER; + + DEBUG_SERVER_MSG("try to recv server response"); + + if (net_nfc_controller_llcp_recv(state->handle, state->socket, &snep_client_data, result, state) == false) + { + DEBUG_SERVER_MSG("recv operation is failed"); + state->step = NET_NFC_STATE_ERROR; + break; + } + } + else + { + DEBUG_SERVER_MSG("NET_NFC_NPP. Don't use the response message. So we skip it!"); + } + } + break; + + case NET_NFC_LLCP_STEP_04 : + { + DEBUG_SERVER_MSG("step 4"); + + if (state->prev_result != NET_NFC_OK) + { + DEBUG_SERVER_MSG("snep client: llcp recv is failed [%d]", state->prev_result); + state->step = NET_NFC_STATE_ERROR; + break; + } + + if (state->type_app_protocol == NET_NFC_NPP) + { + net_nfc_response_p2p_send_t req_msg = { 0, }; + + DEBUG_SERVER_MSG("It's NET_NFC_NPP. Send completed event to client!"); + net_nfc_manager_util_play_sound(NET_NFC_TASK_END); + + req_msg.handle = state->handle; + req_msg.result = NET_NFC_OK; + req_msg.trans_param = state->user_data; + + net_nfc_send_response_msg(state->client_fd, NET_NFC_MESSAGE_P2P_SEND, &req_msg, sizeof(net_nfc_response_p2p_send_t), NULL); + break; + } + + uint8_t code = 0; + + if (_net_nfc_service_llcp_snep_check_resp_msg(&snep_client_data) == NET_NFC_OK) + { + if (_net_nfc_service_llcp_snep_get_code(&snep_client_data, &code) == NET_NFC_OK) + { + if (code == SNEP_RESP_SUCCESS) + { + DEBUG_SERVER_MSG("success response"); + net_nfc_manager_util_play_sound(NET_NFC_TASK_END); + + net_nfc_response_p2p_send_t req_msg = { 0, }; + + req_msg.handle = state->handle; + req_msg.result = NET_NFC_OK; + req_msg.trans_param = state->user_data; + + net_nfc_send_response_msg(state->client_fd, NET_NFC_MESSAGE_P2P_SEND, &req_msg, sizeof(net_nfc_response_p2p_send_t), NULL); + } + else if (code == SNEP_RESP_CONT) + { + DEBUG_SERVER_MSG("continue response"); + + data_s* msg = state->payload; + + if (msg == NULL) + { + state->step = NET_NFC_STATE_ERROR; + break; + } + + if (msg->length > state->max_capability) + { + state->step = NET_NFC_LLCP_STEP_05; + + data_s fragment = { NULL, 0 }; + data_s* extra_msg = NULL; + + _net_nfc_util_alloc_mem(fragment.buffer, state->max_capability * sizeof(uint8_t)); + if (fragment.buffer == NULL) + { + _net_nfc_util_free_mem(msg->buffer); + _net_nfc_util_free_mem(msg); + state->payload = NULL; + state->step = NET_NFC_STATE_ERROR; + break; + } + + fragment.length = state->max_capability; + memcpy(fragment.buffer, msg->buffer, state->max_capability); + + _net_nfc_util_alloc_mem(extra_msg, sizeof(data_s)); + if (extra_msg == NULL) + { + _net_nfc_util_free_mem(fragment.buffer); + _net_nfc_util_free_mem(msg->buffer); + _net_nfc_util_free_mem(msg); + state->step = NET_NFC_STATE_ERROR; + state->payload = NULL; + break; + } + + _net_nfc_util_alloc_mem(extra_msg->buffer, (msg->length - state->max_capability) * sizeof(uint8_t)); + if (extra_msg->buffer == NULL) + { + _net_nfc_util_free_mem(extra_msg); + _net_nfc_util_free_mem(fragment.buffer); + _net_nfc_util_free_mem(msg->buffer); + _net_nfc_util_free_mem(msg); + state->step = NET_NFC_STATE_ERROR; + state->payload = NULL; + break; + } + + extra_msg->length = msg->length - state->max_capability; + memcpy(extra_msg->buffer, msg->buffer + state->max_capability, msg->length - state->max_capability); + + state->payload = extra_msg; + + DEBUG_SERVER_MSG("send next fragment msg"); + net_nfc_controller_llcp_send(state->handle, state->socket, &fragment, result, state); + + _net_nfc_util_free_mem(fragment.buffer); + _net_nfc_util_free_mem(msg->buffer); + _net_nfc_util_free_mem(msg); + } + else + { + DEBUG_SERVER_MSG("send last fragment msg"); + + state->step = NET_NFC_LLCP_STEP_06; + + net_nfc_controller_llcp_send(state->handle, state->socket, msg, result, state); + + _net_nfc_util_free_mem(msg->buffer); + _net_nfc_util_free_mem(msg); + + state->payload = NULL; + } + } + else + { + DEBUG_SERVER_MSG("error response = [%d] from server", code); + } + } + } + else + { + DEBUG_SERVER_MSG("we have got error response"); + } + } + break; + + case NET_NFC_LLCP_STEP_05 : + { + if (state->prev_result != NET_NFC_OK) + { + DEBUG_SERVER_MSG("snep client: llcp send is failed [%d]", state->prev_result); + state->step = NET_NFC_STATE_ERROR; + break; + } + + /* check extra data */ + if (state->payload == NULL) + { + state->step = NET_NFC_STATE_ERROR; + break; + } + + data_s* msg = state->payload; + + if (msg->length > state->max_capability) + { + state->step = NET_NFC_LLCP_STEP_05; + + data_s fragment = { NULL, 0 }; + data_s* extra_msg = NULL; + + _net_nfc_util_alloc_mem(fragment.buffer, state->max_capability * sizeof(uint8_t)); + fragment.length = state->max_capability; + memcpy(fragment.buffer, msg->buffer, state->max_capability); + + _net_nfc_util_alloc_mem(extra_msg, sizeof(data_s)); + + _net_nfc_util_alloc_mem(extra_msg->buffer, (msg->length - state->max_capability) * sizeof(uint8_t)); + extra_msg->length = msg->length - state->max_capability; + memcpy(extra_msg->buffer, msg->buffer + state->max_capability, msg->length - state->max_capability); + + state->payload = extra_msg; + + DEBUG_SERVER_MSG("send next fragment msg"); + net_nfc_controller_llcp_send(state->handle, state->socket, &fragment, result, state); + + _net_nfc_util_free_mem(fragment.buffer); + _net_nfc_util_free_mem(msg->buffer); + _net_nfc_util_free_mem(msg); + } + else + { + state->step = NET_NFC_LLCP_STEP_06; + + DEBUG_SERVER_MSG("send last fragment msg"); + + net_nfc_controller_llcp_send(state->handle, state->socket, msg, result, state); + + _net_nfc_util_free_mem(msg->buffer); + _net_nfc_util_free_mem(msg); + + state->payload = NULL; + } + } + break; + + case NET_NFC_LLCP_STEP_06 : + { + net_nfc_response_p2p_send_t req_msg = { 0, }; + + req_msg.handle = state->handle; + + if (state->prev_result != NET_NFC_OK) + { + DEBUG_SERVER_MSG("snep client: llcp send is failed [%d]", state->prev_result); + + req_msg.result = NET_NFC_P2P_SEND_FAIL; + req_msg.trans_param = state->user_data; + + net_nfc_send_response_msg(state->client_fd, NET_NFC_MESSAGE_P2P_SEND, &req_msg, sizeof(net_nfc_response_p2p_send_t), NULL); + state->step = NET_NFC_STATE_ERROR; + break; + } + else + { + net_nfc_manager_util_play_sound(NET_NFC_TASK_END); + + req_msg.result = NET_NFC_OK; + req_msg.trans_param = state->user_data; + + net_nfc_send_response_msg(state->client_fd, NET_NFC_MESSAGE_P2P_SEND, &req_msg, sizeof(net_nfc_response_p2p_send_t), NULL); + } + + DEBUG_SERVER_MSG("sending last fragment msg is ok"); + } + break; + + case NET_NFC_STATE_SOCKET_ERROR : + { + DEBUG_SERVER_MSG("snep client: socket error is received [%d]", state->prev_result); + need_clean_up = true; + } + break; + + default : + need_clean_up = true; + break; + } + + if (state->step == NET_NFC_STATE_ERROR) + { + net_nfc_response_p2p_send_t req_msg = { 0, }; + + req_msg.handle = state->handle; + req_msg.result = NET_NFC_P2P_SEND_FAIL; + req_msg.trans_param = state->user_data; + + net_nfc_manager_util_play_sound(NET_NFC_TASK_ERROR); + net_nfc_send_response_msg(state->client_fd, NET_NFC_MESSAGE_P2P_SEND, &req_msg, sizeof(net_nfc_response_p2p_send_t), NULL); + + net_nfc_server_unset_server_state(NET_NFC_SNEP_CLIENT_CONNECTED | NET_NFC_NPP_CLIENT_CONNECTED); + + need_clean_up = true; + } + + if (need_clean_up == true) + { + DEBUG_SERVER_MSG("socket close :: LLCP client"); + + net_nfc_controller_llcp_socket_close(state->socket, result); + net_nfc_service_llcp_remove_state(state); + _net_nfc_util_free_mem(state); + + net_nfc_server_unset_server_state(NET_NFC_SNEP_CLIENT_CONNECTED | NET_NFC_NPP_CLIENT_CONNECTED); + } + + if (*result != NET_NFC_OK && *result != NET_NFC_BUSY) + { + DEBUG_SERVER_MSG("error = [%d]", *result); + return false; + } + + return true; +} + +static data_s* _net_nfc_service_llcp_snep_create_msg(snep_command_field_e resp_field, data_s* information) +{ + uint8_t response = (uint8_t)resp_field; + uint8_t version = 0; + uint32_t length_field = 0; + + version = SNEP_MAJOR_VER; + version = (((version << 4) & 0xf0) | (SNEP_MINOR_VER & 0x0f)); + + data_s* snep_msg = NULL; + + if (information == NULL) + { + length_field = 0; + + _net_nfc_util_alloc_mem(snep_msg, sizeof(data_s)); + if (snep_msg == NULL) + { + return NULL; + } + + snep_msg->length = sizeof(uint8_t) + sizeof(uint8_t) + sizeof(uint32_t); + _net_nfc_util_alloc_mem(snep_msg->buffer, snep_msg->length * sizeof(uint8_t)); + if (snep_msg->buffer == NULL) + { + + _net_nfc_util_free_mem(snep_msg); + return NULL; + } + + uint8_t* temp = snep_msg->buffer; + + /* copy version */ + *temp = version; + temp++; + + /* copy response */ + *temp = response; + temp++; + } + else + { + _net_nfc_util_alloc_mem(snep_msg, sizeof(data_s)); + if (snep_msg == NULL) + { + return NULL; + } + /* version response length payload*/ + snep_msg->length = sizeof(uint8_t) + sizeof(uint8_t) + sizeof(uint32_t) + information->length; + + _net_nfc_util_alloc_mem(snep_msg->buffer, snep_msg->length * sizeof(uint8_t)); + if (snep_msg->buffer == NULL) + { + _net_nfc_util_free_mem(snep_msg); + return NULL; + } + + memset(snep_msg->buffer, 0x00, snep_msg->length); + + uint8_t* temp = snep_msg->buffer; + + /* copy version */ + *temp = version; + temp++; + + /* copy response */ + *temp = response; + temp++; + + DEBUG_SERVER_MSG("information->length[%d]", information->length); + /* change the length data as network order for compatibility with android */ + length_field = htonl(information->length); + + /* length will be se 0. so we don't need to copy value */ + memcpy(temp, &length_field, sizeof(uint32_t)); + temp += sizeof(uint32_t); + + /* copy ndef information to response msg */ + memcpy(temp, information->buffer, information->length); + } + return snep_msg; +} + +static data_s* _net_nfc_service_llcp_npp_create_msg(data_s* information) +{ + uint8_t version; + uint32_t length_field = 0; + uint32_t npp_ndef_entry = NPP_NDEF_ENTRY; + uint32_t big_endian_npp_ndef_entry = 0; + + version = NPP_MAJOR_VER; + version = (((version << 4) & 0xf0) | (NPP_MINOR_VER & 0x0f)); + + data_s* npp_msg = NULL; + + if (information == NULL) + { + length_field = 0; + + _net_nfc_util_alloc_mem(npp_msg, sizeof(data_s)); + if (npp_msg == NULL) + { + return NULL; + } + /* version ndef entry action code message length*/ + npp_msg->length = sizeof(uint8_t) + sizeof(uint32_t) + sizeof(uint8_t) + sizeof(uint32_t); + _net_nfc_util_alloc_mem(npp_msg->buffer, npp_msg->length * sizeof(uint8_t)); + if (npp_msg->buffer == NULL) + { + + _net_nfc_util_free_mem(npp_msg); + return NULL; + } + + uint8_t* temp = npp_msg->buffer; + + /* copy version */ + *temp = version; + temp++; + + /* copy npp ndef entry */ + big_endian_npp_ndef_entry = htonl(npp_ndef_entry); + memcpy((void *)temp, (void *)&big_endian_npp_ndef_entry, sizeof(uint32_t)); + temp += sizeof(uint32_t); + } + else + { + + /*Make the npp header*/ + net_nfc_llcp_npp_t npp_header_buffer; + + npp_header_buffer.npp_version = version; + npp_header_buffer.npp_ndef_entry = htonl(NPP_NDEF_ENTRY); + npp_header_buffer.npp_action_code = NPP_ACTION_CODE; + npp_header_buffer.npp_ndef_length = htonl(information->length); + + /*Make the npp message*/ + _net_nfc_util_alloc_mem(npp_msg, sizeof(data_s)); + if (npp_msg == NULL) + { + return NULL; + } + + npp_msg->length = sizeof(net_nfc_llcp_npp_t) + information->length; + + _net_nfc_util_alloc_mem(npp_msg->buffer, npp_msg->length * sizeof(uint8_t)); + if (npp_msg->buffer == NULL) + { + _net_nfc_util_free_mem(npp_msg); + return NULL; + } + + memset(npp_msg->buffer, 0x00, npp_msg->length); + + memcpy(npp_msg->buffer, &npp_header_buffer, sizeof(net_nfc_llcp_npp_t)); + + memcpy((npp_msg->buffer) + sizeof(net_nfc_llcp_npp_t), information->buffer, information->length); + + } + + return npp_msg; +} + +static net_nfc_error_e _net_nfc_service_llcp_snep_check_req_msg(data_s* snep_msg, uint8_t* resp_code) +{ + /* version check */ + /* command check */ + + if (snep_msg == NULL || snep_msg->buffer == NULL || resp_code == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + *resp_code = 0; + + uint8_t* temp = NULL; + uint8_t version = 0; + bool is_supported_req = false; + uint8_t req = 0; + + temp = snep_msg->buffer; + + /* get vesrion. and compare it with ours */ + version = *temp; + + if (version == 0) + { + DEBUG_SERVER_MSG("no version is set"); + *resp_code = SNEP_RESP_UNSUPPORTED_VER; + return NET_NFC_UNKNOWN_ERROR; + } + else + { + uint8_t major = (version & 0xf0) >> 4; + uint8_t minor = (version & 0x0f); + + DEBUG_SERVER_MSG("major = [%d], minor = [%d]", major, minor); + + if (major != SNEP_MAJOR_VER || minor > SNEP_MINOR_VER) + { + DEBUG_SERVER_MSG("version is not matched"); + *resp_code = SNEP_RESP_UNSUPPORTED_VER; + return NET_NFC_UNKNOWN_ERROR; + } + } + + temp++; + + /* get command */ + req = *temp; + temp++; + + switch (req) + { + case SNEP_REQ_CONTINUE : + case SNEP_REQ_PUT : + case SNEP_REQ_REJECT : + is_supported_req = true; + break; + + case SNEP_REQ_GET : + default : + is_supported_req = false; + break; + + } + + if (is_supported_req == false) + { + + DEBUG_SERVER_MSG("not supported req command"); + *resp_code = SNEP_RESP_NOT_IMPLEMENT; + return NET_NFC_UNKNOWN_ERROR; + } + + uint32_t information_length = 0; + + memcpy(&information_length, temp, sizeof(uint32_t)); + + if (req == SNEP_REQ_PUT && information_length == 0) + { + + DEBUG_SERVER_MSG("no information data is exist"); + *resp_code = SNEP_RESP_BAD_REQ; + return NET_NFC_UNKNOWN_ERROR; + } + + return NET_NFC_OK; +} + +static net_nfc_error_e _net_nfc_service_llcp_npp_check_req_msg(data_s* npp_msg, uint8_t* resp_code) +{ + /* version check */ + /* action code check */ + + if (npp_msg == NULL || npp_msg->buffer == NULL || resp_code == NULL) + { + + return NET_NFC_NULL_PARAMETER; + } + + *resp_code = 0; + + uint8_t* temp = NULL; + uint8_t version = 0; + bool is_supported_req = false; + uint32_t ndef_entry_number = 0; + uint8_t action_codes = 0; + + temp = npp_msg->buffer; + + /* get vesrion. and compare it with ours */ + version = *temp; + + if (version == 0) + { + DEBUG_SERVER_MSG("no version is set"); + *resp_code = NPP_RESP_UNSUPPORTED_VER; + return NET_NFC_UNKNOWN_ERROR; + } + else + { + uint8_t major = (version & 0xf0) >> 4; + uint8_t minor = (version & 0x0f); + + DEBUG_SERVER_MSG("major = [%d], minor = [%d]", major, minor); + + if (major != 0x00 || minor > 0x01) + { + DEBUG_SERVER_MSG("version is not matched"); + *resp_code = NPP_RESP_UNSUPPORTED_VER; + return NET_NFC_UNKNOWN_ERROR; + } + + } + + /*Increase the address. Because we already get the version of the npp. so we have to get the "number of ndef entry" */ + temp++; + + /* get command */ + ndef_entry_number = ntohl(*((uint32_t *)(temp))); + + DEBUG_SERVER_MSG("check the number of ndef entry = [%d]", ndef_entry_number); + temp += 4; + + /* action code*/ + memcpy(&action_codes, temp, sizeof(uint8_t)); + + DEBUG_SERVER_MSG("check the action_codes = [%d]", action_codes); + + switch (action_codes) + { + case 0x01 : + is_supported_req = true; + break; + default : + is_supported_req = false; + break; + + } + + if (is_supported_req == false) + { + + DEBUG_SERVER_MSG("not supported action codes"); + *resp_code = NPP_RESP_NOT_IMPLEMEN; + return NET_NFC_UNKNOWN_ERROR; + } + + temp++; + + uint32_t information_length = 0; + + memcpy(&information_length, temp, sizeof(uint32_t)); + + if (action_codes != 0x01 || information_length == 0) + { + + DEBUG_SERVER_MSG("no information data is exist"); + *resp_code = NPP_RESP_UNSUPPORTED_VER; + return NET_NFC_UNKNOWN_ERROR; + } + return NET_NFC_OK; +} + +static net_nfc_error_e _net_nfc_service_llcp_snep_get_code(data_s* snep_msg, uint8_t* code) +{ + if (snep_msg == NULL || snep_msg->buffer == NULL || code == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + uint8_t* temp = NULL; + + temp = snep_msg->buffer; + + temp++; + + *code = *temp; + + return NET_NFC_OK; +} + +static net_nfc_error_e _net_nfc_service_llcp_snep_get_information_length(data_s* snep_msg, uint32_t* length) +{ + if (snep_msg == NULL || snep_msg->buffer == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + uint8_t* temp = NULL; + uint32_t temp_length = 0; + + temp = snep_msg->buffer; + temp += 2; + + /* change the length data as host order for compatibility with android */ + temp_length = ntohl(*((uint32_t *)(temp))); + memcpy(length, &temp_length, sizeof(uint32_t)); + + DEBUG_SERVER_MSG("check the snep ndef length [%d]", *length); + + return NET_NFC_OK; +} + +static net_nfc_error_e _net_nfc_service_llcp_npp_get_information_length(data_s* npp_msg, uint32_t* length) +{ + if (npp_msg == NULL || npp_msg->buffer == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + uint8_t* temp = NULL; + uint32_t temp_length = 0; + + temp = npp_msg->buffer; + temp += 6; + + DEBUG_SERVER_MSG("check the npp ndef length address= [%p]", temp); + + temp_length = ntohl(*((uint32_t *)(temp))); + memcpy(length, &temp_length, sizeof(uint32_t)); + + DEBUG_SERVER_MSG("check the npp ndef temp_length= [%d]", temp_length); + + DEBUG_SERVER_MSG("check the npp ndef length= [%d]", *length); + + return NET_NFC_OK; +} + +static net_nfc_error_e _net_nfc_service_llcp_snep_check_resp_msg(data_s* snep_msg) +{ + /* version check */ + /* command check */ + + if (snep_msg == NULL || snep_msg->buffer == NULL) + { + + return NET_NFC_NULL_PARAMETER; + } + + uint8_t* temp = NULL; + uint8_t version = 0; + bool is_supported_resp = false; + uint8_t resp = 0; + + temp = snep_msg->buffer; + + /* get vesrion. and compare it with ours */ + version = *temp; + + if (version == 0) + { + DEBUG_SERVER_MSG("version is wrong"); + return NET_NFC_UNKNOWN_ERROR; + } + else + { + uint8_t major = (version & 0xf0) >> 4; + uint8_t minor = (version & 0x0f); + + DEBUG_SERVER_MSG("major[%d], minor[%d]", major, minor); + + if (major != SNEP_MAJOR_VER || minor > SNEP_MINOR_VER) + { + DEBUG_SERVER_MSG("version is not matched"); + return NET_NFC_UNKNOWN_ERROR; + } + + } + + temp++; + + /* get command */ + resp = *temp; + temp++; + + DEBUG_SERVER_MSG("result = [%d]", resp); + + switch (resp) + { + case SNEP_RESP_CONT : + case SNEP_RESP_SUCCESS : + case SNEP_RESP_NOT_FOUND : + case SNEP_RESP_EXCESS_DATA : + case SNEP_RESP_BAD_REQ : + case SNEP_RESP_NOT_IMPLEMENT : + case SNEP_RESP_UNSUPPORTED_VER : + case SNEP_RESP_REJECT : + is_supported_resp = true; + break; + default : + is_supported_resp = false; + break; + + } + + if (is_supported_resp == false) + { + DEBUG_SERVER_MSG("not supported resp command = [%d]", resp); + return NET_NFC_UNKNOWN_ERROR; + } + + uint32_t information_length = 0; + + memcpy(&information_length, temp, sizeof(uint32_t)); + + if (resp != SNEP_RESP_SUCCESS && information_length != 0) + { + DEBUG_SERVER_MSG("error response should not have any information data"); + return NET_NFC_UNKNOWN_ERROR; + } + + return NET_NFC_OK; +} diff --git a/src/manager/net_nfc_service_llcp_handover.c b/src/manager/net_nfc_service_llcp_handover.c new file mode 100644 index 0000000..30bb127 --- /dev/null +++ b/src/manager/net_nfc_service_llcp_handover.c @@ -0,0 +1,1999 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include "net_nfc_debug_private.h" +#include "net_nfc_util_private.h" +#include "net_nfc_util_ndef_message.h" +#include "net_nfc_util_ndef_record.h" +#include "net_nfc_util_handover.h" + +#include "net_nfc_manager_util_private.h" +#include "net_nfc_controller_private.h" +#include "net_nfc_service_private.h" +#include "net_nfc_service_llcp_private.h" +#include "net_nfc_service_llcp_handover_private.h" +#include "net_nfc_server_ipc_private.h" +#include "net_nfc_server_context_private.h" + +#include "bluetooth-api.h" + +static uint8_t conn_handover_req_buffer[CH_MAX_BUFFER] = {0,}; +static uint8_t conn_handover_sel_buffer[CH_MAX_BUFFER] = {0,}; + +static data_s conn_handover_req_data = {conn_handover_req_buffer, CH_MAX_BUFFER}; +static data_s conn_handover_sel_data = {conn_handover_sel_buffer, CH_MAX_BUFFER}; + +static bool _net_nfc_service_llcp_check_hr_record_validation(ndef_message_s * message); +static bool _net_nfc_service_llcp_check_hs_record_validation(ndef_message_s * message); + +net_nfc_error_e _net_nfc_service_llcp_create_low_power_selector_message(ndef_message_s *request_msg, ndef_message_s *select_msg); +net_nfc_error_e net_nfc_service_llcp_handover_get_oob_data(net_nfc_carrier_config_s *config, bt_oob_data_t *oob); + +net_nfc_error_e net_nfc_service_llcp_handover_create_carrier_configs(ndef_message_s *msg, net_nfc_conn_handover_carrier_type_e type, bool requester, net_nfc_llcp_state_t *state, int next_step); +int net_nfc_service_llcp_handover_append_bt_carrier_config(net_nfc_handover_create_config_context_t *context); +int net_nfc_service_llcp_handover_append_wifi_carrier_config(net_nfc_handover_create_config_context_t *context); +int net_nfc_service_llcp_handover_iterate_carrier_configs(net_nfc_handover_create_config_context_t *context); +int net_nfc_service_llcp_handover_go_to_next_config(net_nfc_handover_create_config_context_t *context); +static void _net_nfc_service_llcp_bt_create_config_cb(int event, bluetooth_event_param_t *param, void *user_data); + +net_nfc_error_e net_nfc_service_llcp_handover_process_carrier_config(net_nfc_carrier_config_s *config, bool requester, net_nfc_llcp_state_t *state, int next_step); +int net_nfc_service_llcp_handover_process_bt_config(net_nfc_handover_process_config_context_t *context); + +int net_nfc_service_llcp_handover_return_to_step(net_nfc_handover_context_t *context); +net_nfc_error_e net_nfc_service_llcp_handover_bt_change_data_order(net_nfc_carrier_config_s *config); + +net_nfc_error_e net_nfc_service_llcp_handover_send_request_msg(net_nfc_request_connection_handover_t *msg) +{ + net_nfc_error_e error = NET_NFC_OK; + + DEBUG_SERVER_MSG("start"); + + if (msg == NULL || msg->handle == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + net_nfc_llcp_state_t *conn_handover_requester = NULL; + _net_nfc_util_alloc_mem(conn_handover_requester, sizeof(net_nfc_llcp_state_t)); + if (conn_handover_requester == NULL) + { + DEBUG_SERVER_MSG("conn_handover_requester is NULL"); + return NET_NFC_ALLOC_FAIL; + } + + conn_handover_requester->client_fd = msg->client_fd; + conn_handover_requester->handle = msg->handle; + conn_handover_requester->state = NET_NFC_STATE_CONN_HANDOVER_REQUEST; + conn_handover_requester->step = NET_NFC_LLCP_STEP_01; + conn_handover_requester->type = msg->type; + + net_nfc_service_llcp_add_state(conn_handover_requester); + + if (net_nfc_service_llcp_connection_handover_requester(conn_handover_requester, &error) == true) + { + error = NET_NFC_OK; + } + else + { + DEBUG_SERVER_MSG("connection handover request is failed = [%d]", error); + error = NET_NFC_OPERATION_FAIL; + } + + return error; +} + +bool net_nfc_service_llcp_create_server_socket(net_nfc_llcp_state_t *state, net_nfc_socket_type_e socket_type, uint16_t miu, uint8_t rw, int sap, char *san, net_nfc_error_e *result) +{ + bool ret = false; + + if (result == NULL) + { + return ret; + } + + if (state == NULL || san == NULL) + { + *result = NET_NFC_NULL_PARAMETER; + return ret; + } + + DEBUG_SERVER_MSG("begin net_nfc_service_llcp_create_server_socket"); + + if ((ret = net_nfc_controller_llcp_create_socket(&(state->socket), socket_type, miu, rw, result, state)) == true) + { + DEBUG_SERVER_MSG("bind server socket with service acess point = [0x%x]", sap); + + if ((ret = net_nfc_controller_llcp_bind(state->socket, sap, result)) == true) + { + DEBUG_SERVER_MSG("listen server socket with service access name = [%s]", san); + + if ((ret = net_nfc_controller_llcp_listen(state->handle, (uint8_t *)san, state->socket, result, state)) == true) + { + DEBUG_SERVER_MSG("net_nfc_controller_llcp_listen success!!"); + } + else + { + DEBUG_ERR_MSG("net_nfc_controller_llcp_listen failed [%d]", *result); + net_nfc_controller_llcp_socket_close(state->socket, result); + state->socket = 0; + } + } + else + { + DEBUG_ERR_MSG("net_nfc_controller_llcp_bind failed [%d]", *result); + net_nfc_controller_llcp_socket_close(state->socket, result); + state->socket = 0; + } + } + else + { + DEBUG_ERR_MSG("net_nfc_controller_llcp_create_socket failed [%d]", *result); + } + + return ret; +} + +static net_nfc_llcp_state_t *_net_nfc_service_llcp_add_new_state(int client_fd, net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, llcp_state_e state, unsigned int step, void *user_data) +{ + net_nfc_llcp_state_t *context = NULL; + + LOGD("[%s] START", __func__); + + if (handle == NULL) + { + return context; + } + + _net_nfc_util_alloc_mem(context, sizeof(net_nfc_llcp_state_t)); + if (context != NULL) + { + context->client_fd = client_fd; + context->handle = handle; + context->socket = socket; + context->state = state; + context->step = step; + context->user_data = user_data; + + net_nfc_service_llcp_add_state(context); + } + + LOGD("[%s] END", __func__); + + return context; +} + +static void _net_nfc_service_llcp_handover_send_response(int socket, net_nfc_exchanger_event_e event, net_nfc_conn_handover_carrier_type_e type, data_s *data) +{ + LOGD("[%s] START", __func__); + + if (net_nfc_server_check_client_is_running(socket) == true) + { + net_nfc_response_connection_handover_t resp_msg = { 0, }; + + resp_msg.result = NET_NFC_OK; + resp_msg.event = event; + + resp_msg.type = type; + if (data != NULL && data->buffer != NULL && data->length != 0) + { + resp_msg.data.length = data->length; + if (net_nfc_send_response_msg(socket, NET_NFC_MESSAGE_CONNECTION_HANDOVER, &resp_msg, sizeof(net_nfc_response_connection_handover_t), data->buffer, data->length, NULL) == true) + { + DEBUG_SERVER_MSG("send exchange message to client"); + } + } + else + { + if (net_nfc_send_response_msg(socket, NET_NFC_MESSAGE_CONNECTION_HANDOVER, &resp_msg, sizeof(net_nfc_response_connection_handover_t), NULL) == true) + { + DEBUG_SERVER_MSG("send exchange message to client"); + } + } + } + + LOGD("[%s] END", __func__); +} + +static bool _net_nfc_service_llcp_send_ndef_message(net_nfc_llcp_state_t *state, ndef_message_s *msg, net_nfc_error_e *result) +{ + bool ret = false; + data_s send_data = { NULL, 0 }; + + LOGD("[%s] START", __func__); + + if (result == NULL) + { + return ret; + } + + if (state == NULL || msg == NULL) + { + *result = NET_NFC_NULL_PARAMETER; + return ret; + } + + send_data.length = net_nfc_util_get_ndef_message_length(msg); + + if (send_data.length > 0) + { + _net_nfc_util_alloc_mem(send_data.buffer, send_data.length); + if (send_data.buffer != NULL) + { + if ((*result =net_nfc_util_convert_ndef_message_to_rawdata(msg, &send_data)) == NET_NFC_OK) + { + if ((ret = net_nfc_controller_llcp_send(state->handle, state->socket, &send_data, result, state)) == true) + { + DEBUG_SERVER_MSG("net_nfc_controller_llcp_send success!!"); + } + else + { + DEBUG_ERR_MSG("net_nfc_controller_llcp_send failed [%d]", *result); + } + } + else + { + DEBUG_ERR_MSG("_net_nfc_ndef_to_rawdata failed [%d]", *result); + } + + _net_nfc_util_free_mem(send_data.buffer); + } + else + { + *result = NET_NFC_ALLOC_FAIL; + } + } + else + { + *result = NET_NFC_INVALID_PARAM; + } + + LOGD("[%s] END", __func__); + + return ret; +} + +net_nfc_error_e _net_nfc_service_llcp_get_carrier_record_by_priority_order(ndef_message_s *request_msg, ndef_record_s **record) +{ + net_nfc_error_e result = NET_NFC_INVALID_PARAM; + unsigned int carrier_count = 0; + + LOGD("[%s] START", __func__); + + if (request_msg == NULL || record == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + if ((result = net_nfc_util_get_alternative_carrier_record_count(request_msg, &carrier_count)) == NET_NFC_OK) + { + int idx, priority; + net_nfc_conn_handover_carrier_type_e carrier_type = NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN; + + /* apply priority (order NET_NFC_CONN_HANDOVER_CARRIER_BT ~ NET_NFC_CONN_HANDOVER_CARRIER_WIFI_IBSS) */ + for (priority = NET_NFC_CONN_HANDOVER_CARRIER_BT; *record == NULL && priority < NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN; priority++) + { + /* check each carrier record and create matched record */ + for (idx = 0; idx < carrier_count; idx++) + { + if ((net_nfc_util_get_alternative_carrier_type(request_msg, idx, &carrier_type) == NET_NFC_OK) && (carrier_type == priority)) + { + DEBUG_SERVER_MSG("selected carrier type = [%d]", carrier_type); + net_nfc_util_get_carrier_config_record(request_msg, idx, record); + result = NET_NFC_OK; + break; + } + } + } + } + else + { + DEBUG_ERR_MSG("net_nfc_util_get_alternative_carrier_record_count failed"); + } + + LOGD("[%s] END", __func__); + + return result; +} + +static net_nfc_error_e _net_nfc_service_handover_create_requester_message_from_rawdata(ndef_message_s **request_msg, data_s *data) +{ + net_nfc_error_e result; + + if ((result = net_nfc_util_create_ndef_message(request_msg)) == NET_NFC_OK) + { + if ((result = net_nfc_util_convert_rawdata_to_ndef_message(data, *request_msg)) == NET_NFC_OK) + { + if (_net_nfc_service_llcp_check_hr_record_validation(*request_msg) == true) + { + result = NET_NFC_OK; + } + else + { + DEBUG_ERR_MSG("record is not valid or is not available"); + result = NET_NFC_INVALID_PARAM; + } + } + else + { + DEBUG_ERR_MSG("_net_nfc_ndef_rawdata_to_ndef failed [%d]", result); + } + } + else + { + DEBUG_ERR_MSG("_net_nfc_util_create_ndef_message failed [%d]", result); + } + + return result; +} + +bool net_nfc_service_llcp_connection_handover_selector(net_nfc_llcp_state_t *state, net_nfc_error_e *result) +{ + bool need_clean_up = false; + + LOGD("[%s] START", __func__); + + if (result == NULL) + { + DEBUG_SERVER_MSG("result is NULL"); + return false; + } + + *result = NET_NFC_OK; + + switch (state->step) + { + case NET_NFC_LLCP_STEP_01 : + { + DEBUG_SERVER_MSG("step 1"); + + if (net_nfc_service_llcp_create_server_socket(state, NET_NFC_LLCP_SOCKET_TYPE_CONNECTIONORIENTED, CH_MAX_BUFFER, 1, CONN_HANDOVER_SAP, CONN_HANDOVER_SAN, result) == true) + { + state->step = NET_NFC_LLCP_STEP_02; + } + else + { + state->step = NET_NFC_STATE_ERROR; + } + } + break; + + case NET_NFC_LLCP_STEP_02 : + { + DEBUG_SERVER_MSG("step 2"); + + if (state->prev_result != NET_NFC_OK) + { + DEBUG_SERVER_MSG("handover selector: listen is failed..."); + state->step = NET_NFC_STATE_ERROR; + break; + } + + net_nfc_llcp_state_t *new_client = _net_nfc_service_llcp_add_new_state(state->client_fd, state->handle, state->incomming_socket, state->state, NET_NFC_LLCP_STEP_03, NULL); + if (new_client != NULL) + { + memset(conn_handover_sel_data.buffer, 0x00, CH_MAX_BUFFER); + conn_handover_sel_data.length = CH_MAX_BUFFER; + + if (net_nfc_controller_llcp_recv(new_client->handle, new_client->socket, &conn_handover_sel_data, result, new_client) == false) + { + DEBUG_ERR_MSG("net_nfc_controller_llcp_recv failed [%d]", *result); + state->step = NET_NFC_STATE_ERROR; + } + } + else + { + DEBUG_ERR_MSG("_net_nfc_service_llcp_add_new_state returns NULL"); + state->step = NET_NFC_STATE_ERROR; + } + } + break; + + case NET_NFC_LLCP_STEP_03 : + { + DEBUG_SERVER_MSG("step 3"); + + if (state->prev_result != NET_NFC_OK) + { + DEBUG_SERVER_MSG("handover selector : receive is failed..."); + state->step = NET_NFC_STATE_ERROR; + break; + } + + DEBUG_SERVER_MSG("handover selector : receiving is successful"); + net_nfc_manager_util_play_sound(NET_NFC_TASK_END); + + /* process and send message */ + /* get requester message */ + if ((*result = _net_nfc_service_handover_create_requester_message_from_rawdata(&state->requester, &conn_handover_sel_data)) == NET_NFC_OK) + { + unsigned int count = 0; + + if ((*result = net_nfc_util_get_alternative_carrier_record_count(state->requester, &count)) == NET_NFC_OK) + { + /* create selector message */ + if ((*result = net_nfc_util_create_handover_select_message(&state->selector)) == NET_NFC_OK) + { + if (1/* power state */ || count == 1) + { + ndef_record_s *record = NULL; + + /* fill alternative carrier information */ + if ((*result = _net_nfc_service_llcp_get_carrier_record_by_priority_order(state->requester, &record)) == NET_NFC_OK) + { + net_nfc_conn_handover_carrier_type_e type = NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN; + + if ((*result = net_nfc_util_get_alternative_carrier_type_from_record(record, &type)) == NET_NFC_OK) + { + if ((*result = net_nfc_service_llcp_handover_create_carrier_configs(state->selector, type, false, state, NET_NFC_LLCP_STEP_04)) != NET_NFC_OK) + { + state->step = NET_NFC_STATE_ERROR; + DEBUG_ERR_MSG("net_nfc_service_llcp_handover_create_carrier_configs failed [%d]", *result); + } + } + else + { + state->step = NET_NFC_STATE_ERROR; + DEBUG_ERR_MSG("net_nfc_util_get_alternative_carrier_type_from_record failed [%d]", *result); + } + } + else + { + state->step = NET_NFC_STATE_ERROR; + DEBUG_ERR_MSG("_net_nfc_service_llcp_get_carrier_record_by_priority_order failed [%d]", *result); + } + } + else /* low power && count > 1 */ + { + state->low_power = true; + + if ((*result = _net_nfc_service_llcp_create_low_power_selector_message(state->requester, state->selector)) == NET_NFC_OK) + { + state->step = NET_NFC_LLCP_STEP_06; + net_nfc_service_llcp_connection_handover_selector(state, result); + } + else + { + state->step = NET_NFC_STATE_ERROR; + DEBUG_ERR_MSG("_net_nfc_service_llcp_create_low_power_selector_message failed [%d]", *result); + } + } + } + else + { + state->step = NET_NFC_STATE_ERROR; + DEBUG_ERR_MSG("net_nfc_util_create_handover_select_message failed [%d]", *result); + } + } + else + { + state->step = NET_NFC_STATE_ERROR; + DEBUG_ERR_MSG("net_nfc_util_get_alternative_carrier_record_count failed [%d]", *result); + } + } + else + { + state->step = NET_NFC_STATE_ERROR; + DEBUG_ERR_MSG("_net_nfc_service_handover_create_requester_message_from_rawdata failed [%d]", *result); + } + } + break; + + case NET_NFC_LLCP_STEP_04 : + { + ndef_record_s *record = NULL; + + DEBUG_SERVER_MSG("step 4"); + + if (state->prev_result != NET_NFC_OK) + { + DEBUG_SERVER_MSG("handover selector : recevie is failed..."); + state->step = NET_NFC_STATE_ERROR; + break; + } + + /* fill alternative carrier information */ + if ((*result = _net_nfc_service_llcp_get_carrier_record_by_priority_order(state->requester, &record)) == NET_NFC_OK) + { + net_nfc_conn_handover_carrier_type_e type = NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN; + + DEBUG_SERVER_MSG("record [%p]", record); + + if ((*result = net_nfc_util_get_alternative_carrier_type_from_record(record, &type)) == NET_NFC_OK) + { + net_nfc_carrier_config_s *config = NULL; + + DEBUG_SERVER_MSG("type [%d]", type); + + *result = net_nfc_util_create_carrier_config_from_config_record(&config, record); + + DEBUG_SERVER_MSG("config [%p]", config); + + *result = net_nfc_service_llcp_handover_process_carrier_config(config, false, state, NET_NFC_LLCP_STEP_05); + + if (*result != NET_NFC_OK && *result != NET_NFC_BUSY) + { + DEBUG_ERR_MSG("net_nfc_service_llcp_handover_process_carrier_config failed [%d]", *result); + state->step = NET_NFC_STATE_ERROR; + } + + DEBUG_SERVER_MSG("after net_nfc_service_llcp_handover_process_carrier_config"); + } + else + { + state->step = NET_NFC_STATE_ERROR; + DEBUG_ERR_MSG("net_nfc_util_get_alternative_carrier_type_from_record failed [%d]", *result); + } + } + else + { + state->step = NET_NFC_STATE_ERROR; + DEBUG_ERR_MSG("_net_nfc_service_llcp_get_carrier_record_by_priority_order failed [%d]", *result); + } + } + break; + + case NET_NFC_LLCP_STEP_05 : + { + DEBUG_SERVER_MSG("step 5"); + + if (state->prev_result != NET_NFC_OK) + { + DEBUG_SERVER_MSG("handover selector : recevie is failed..."); + state->step = NET_NFC_STATE_ERROR; + break; + } + + /* send ndef message via llcp */ + if (_net_nfc_service_llcp_send_ndef_message(state, state->selector, result) == true) + { + DEBUG_SERVER_MSG("handover selector : sending select msg is success"); + + if (state->low_power == true) + { + DEBUG_SERVER_MSG("activate_forced == false, next step is NET_NFC_LLCP_STEP_02"); + state->step = NET_NFC_LLCP_STEP_02; + } + else + { + DEBUG_SERVER_MSG("next step is NET_NFC_LLCP_STEP_06"); + state->step = NET_NFC_LLCP_STEP_06; + } + } + else + { + DEBUG_ERR_MSG("handover selector : sending select msg is failed [%d]", *result); + } + + if (*result == NET_NFC_OK || *result == NET_NFC_BUSY) + { + } + else + { + DEBUG_ERR_MSG("_net_nfc_service_llcp_send_selector_ndef_message failed [%d]", *result); + state->step = NET_NFC_STATE_ERROR; + } + } + break; + + case NET_NFC_LLCP_STEP_06 : + { + DEBUG_SERVER_MSG("step 6"); + + if (state->prev_result != NET_NFC_OK) + { + DEBUG_SERVER_MSG("handover selector : send ndef failed..."); + state->step = NET_NFC_STATE_ERROR; + break; + } + + net_nfc_util_free_ndef_message(state->requester); + net_nfc_util_free_ndef_message(state->selector); + + state->step = 0; + } + break; + + case NET_NFC_STATE_SOCKET_ERROR : + { + DEBUG_SERVER_MSG("conn handover selector : socket error is received %d", state->prev_result); + need_clean_up = true; + } + break; + + default : + { + DEBUG_SERVER_MSG("unknown step"); + need_clean_up = true; + } + break; + } + + if (state->step == NET_NFC_STATE_ERROR) + { + net_nfc_manager_util_play_sound(NET_NFC_TASK_ERROR); + state->step = 0; + } + + if (need_clean_up == true) + { + net_nfc_controller_llcp_socket_close(state->socket, result); + net_nfc_service_llcp_remove_state(state); + _net_nfc_util_free_mem(state); + } + + if (*result != NET_NFC_BUSY && *result != NET_NFC_OK) + { + return false; + } + + LOGD("[%s] END", __func__); + + return true; +} + +net_nfc_error_e _net_nfc_service_llcp_create_requester_ndef_message(net_nfc_llcp_state_t *state) +{ + net_nfc_error_e result = NET_NFC_UNKNOWN_ERROR; + net_nfc_conn_handover_carrier_type_e carrier_type; + + LOGD("[%s] START", __func__); + + if (state->requester == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + carrier_type = state->type; + + if (state->selector != NULL) + { + /* selector is low power state... so request one alternative carrier */ + if ((result = net_nfc_util_get_alternative_carrier_type(state->selector, 0, &carrier_type)) == NET_NFC_OK) + { + DEBUG_SERVER_MSG("select_msg 0 carrier type [%d]", carrier_type); + } + } + + if ((result = net_nfc_service_llcp_handover_create_carrier_configs(state->requester, carrier_type, true, state, NET_NFC_LLCP_STEP_03)) != NET_NFC_OK) + { + DEBUG_ERR_MSG("net_nfc_service_llcp_handover_create_carrier_configs failed [%d]", result); + } + + LOGD("[%s] END", __func__); + + return result; +} + +net_nfc_error_e _net_nfc_service_llcp_get_carrier_record(ndef_message_s *select_msg, ndef_record_s **carrier_record) +{ + net_nfc_error_e result = NET_NFC_UNKNOWN_ERROR; + unsigned int carrier_count; + + LOGD("[%s] START", __func__); + + if (select_msg == NULL || carrier_record == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + /* connect selected carrier... :) */ + if ((result = net_nfc_util_get_alternative_carrier_record_count(select_msg, &carrier_count)) == NET_NFC_OK) + { + int idx; + net_nfc_conn_handover_carrier_type_e carrier_type; + + for (idx = 0; idx < carrier_count; idx++) + { + if ((result = net_nfc_util_get_alternative_carrier_type(select_msg, idx, &carrier_type)) == NET_NFC_OK) + { + net_nfc_conn_handover_carrier_state_e cps; + + cps = net_nfc_util_get_cps(carrier_type); + + switch (carrier_type) + { + case NET_NFC_CONN_HANDOVER_CARRIER_BT : + DEBUG_SERVER_MSG("if bt is off, then turn on"); + if (cps != NET_NFC_CONN_HANDOVER_CARRIER_ACTIVATE && cps != NET_NFC_CONN_HANDOVER_CARRIER_ACTIVATING) + { + DEBUG_SERVER_MSG("turn on bt"); + net_nfc_util_enable_bluetooth(); + } + + net_nfc_util_get_carrier_config_record(select_msg, idx, carrier_record); + break; + + default : + continue; + } + + if (*carrier_record != NULL) + { + result = NET_NFC_OK; + break; + } + } + else + { + DEBUG_ERR_MSG("net_nfc_util_get_alternative_carrier_type failed [%d]", result); + } + } + } + else + { + DEBUG_ERR_MSG("net_nfc_util_get_alternative_carrier_record_count failed [%d]", result); + } + + LOGD("[%s] END", __func__); + + return result; +} + +static net_nfc_error_e _net_nfc_service_handover_create_selector_message_from_rawdata(ndef_message_s **select_msg, data_s *data) +{ + net_nfc_error_e result; + + if (select_msg == NULL) + return NET_NFC_NULL_PARAMETER; + + if ((result = net_nfc_util_create_ndef_message(select_msg)) == NET_NFC_OK) + { + if ((result = net_nfc_util_convert_rawdata_to_ndef_message(data, *select_msg)) == NET_NFC_OK) + { + /* if record is not Hs record, then */ + if (_net_nfc_service_llcp_check_hs_record_validation(*select_msg) == true) + { + result = NET_NFC_OK; + } + else + { + DEBUG_ERR_MSG("record is not valid or is not available"); + result = NET_NFC_INVALID_PARAM; + } + } + else + { + DEBUG_ERR_MSG("_net_nfc_ndef_rawdata_to_ndef failed [%d]", result); + } + } + else + { + DEBUG_ERR_MSG("_net_nfc_util_create_ndef_message failed [%d]", result); + } + + return result; +} + +bool net_nfc_service_llcp_connection_handover_requester(net_nfc_llcp_state_t *state, net_nfc_error_e *result) +{ + bool need_clean_up = false; + + LOGD("[%s] START", __func__); + + if (state == NULL || result == NULL) + { + DEBUG_SERVER_MSG("state/result is NULL"); + return false; + } + + *result = NET_NFC_OK; + + switch (state->step) + { + case NET_NFC_LLCP_STEP_01 : + { + DEBUG_SERVER_MSG("step 1"); + + if (net_nfc_controller_llcp_create_socket(&(state->socket), NET_NFC_LLCP_SOCKET_TYPE_CONNECTIONORIENTED, CH_MAX_BUFFER, 1, result, state) == false) + { + DEBUG_SERVER_MSG("creating socket is failed"); + state->step = NET_NFC_STATE_ERROR; + break; + } + + DEBUG_SERVER_MSG("connect to remote server with socket = [0x%x]", state->socket); + + state->step = NET_NFC_LLCP_STEP_02; + + if (net_nfc_controller_llcp_connect_by_url(state->handle, state->socket, (uint8_t *)CONN_HANDOVER_SAN, result, state) == false) + { + DEBUG_SERVER_MSG("making connection is failed"); + state->step = NET_NFC_STATE_ERROR; + break; + } + } + break; + + case NET_NFC_LLCP_STEP_02 : + { + DEBUG_SERVER_MSG("step 2"); + + if (state->prev_result != NET_NFC_OK) + { + DEBUG_SERVER_MSG("handover requester : connect is failed..."); + state->step = NET_NFC_STATE_ERROR; + break; + } + + state->step = NET_NFC_LLCP_STEP_03; + + if ((*result = net_nfc_util_create_handover_request_message(&state->requester)) == NET_NFC_OK) + { + net_nfc_conn_handover_carrier_type_e carrier_type; + + if (state->selector != NULL) + { + /* selector is low power state... so request one alternative carrier */ + if ((*result = net_nfc_util_get_alternative_carrier_type(state->selector, 0, &carrier_type)) == NET_NFC_OK) + { + DEBUG_SERVER_MSG("select_msg 0 carrier type [%d]", carrier_type); + } + else + { + DEBUG_SERVER_MSG("select_msg 0 carrier type failed [%d]", *result); + + carrier_type = NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN; + } + + net_nfc_util_free_ndef_message(state->selector); + state->selector = NULL; + } + else + { + carrier_type = NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN; + } + + if ((*result = net_nfc_service_llcp_handover_create_carrier_configs(state->requester, carrier_type, true, state, NET_NFC_LLCP_STEP_03)) != NET_NFC_OK) + { + DEBUG_ERR_MSG("net_nfc_service_llcp_handover_create_carrier_configs failed [%d]", *result); + } + } + else + { + DEBUG_ERR_MSG("handover requester : sending select msg is failed [%d]", *result); + state->step = NET_NFC_STATE_ERROR; + } + } + break; + + case NET_NFC_LLCP_STEP_03 : + { + DEBUG_SERVER_MSG("step 3"); + + if (state->prev_result != NET_NFC_OK) + { + DEBUG_SERVER_MSG("handover requester : connect is failed..."); + state->step = NET_NFC_STATE_ERROR; + break; + } + + state->step = NET_NFC_LLCP_STEP_04; + + /* send ndef message via llcp */ + if (_net_nfc_service_llcp_send_ndef_message(state, state->requester, result) == true) + { + DEBUG_SERVER_MSG("handover requester : sending request msg is success"); + } + else + { + DEBUG_ERR_MSG("handover requester : sending request msg is failed [%d]", *result); + state->step = NET_NFC_STATE_ERROR; + } + + net_nfc_util_free_ndef_message(state->requester); + state->requester = NULL; + } + break; + + case NET_NFC_LLCP_STEP_04 : + { + DEBUG_SERVER_MSG("step 4"); + + if (state->prev_result != NET_NFC_OK) + { + DEBUG_SERVER_MSG("handover requester : connect is failed..."); + state->step = NET_NFC_STATE_ERROR; + break; + } + + state->step = NET_NFC_LLCP_STEP_05; + + memset(conn_handover_req_data.buffer, 0x00, CH_MAX_BUFFER); + conn_handover_req_data.length = CH_MAX_BUFFER; + + if (net_nfc_controller_llcp_recv(state->handle, state->socket, &conn_handover_req_data, result, state) == false) + { + state->step = NET_NFC_STATE_ERROR; + break; + } + } + break; + + case NET_NFC_LLCP_STEP_05 : + { + DEBUG_SERVER_MSG("step 5"); + + if (state->prev_result != NET_NFC_OK) + { + DEBUG_SERVER_MSG("handover requester : receiving is failed..."); + state->step = NET_NFC_STATE_ERROR; + break; + } + + DEBUG_SERVER_MSG("handover requster : receiving is successful"); + net_nfc_manager_util_play_sound(NET_NFC_TASK_END); + + if ((*result = _net_nfc_service_handover_create_selector_message_from_rawdata(&state->selector, &conn_handover_req_data)) == NET_NFC_OK) + { + net_nfc_conn_handover_carrier_state_e power_state = NET_NFC_CONN_HANDOVER_CARRIER_ACTIVATE; + + /* check selector power state */ + if ((*result = net_nfc_util_get_selector_power_status(state->selector, &power_state)) == NET_NFC_OK) + { + DEBUG_MSG("power_state == %d", power_state); + + if (power_state == NET_NFC_CONN_HANDOVER_CARRIER_ACTIVATE || power_state == NET_NFC_CONN_HANDOVER_CARRIER_ACTIVATING) + { + ndef_record_s *carrier_record = NULL; + + if ((*result = _net_nfc_service_llcp_get_carrier_record(state->selector, &carrier_record)) == NET_NFC_OK) + { + net_nfc_carrier_config_s *handover_config = NULL; + + if ((*result = net_nfc_util_create_carrier_config_from_config_record(&handover_config, carrier_record)) == NET_NFC_OK) + { + net_nfc_service_llcp_handover_process_carrier_config(handover_config, true, state, NET_NFC_LLCP_STEP_06); + } + else + { + DEBUG_ERR_MSG("net_nfc_util_create_carrier_config_from_config_record failed [%d]", *result); + state->step = NET_NFC_STATE_ERROR; + } + } + else + { + DEBUG_ERR_MSG("net_nfc_util_get_alternative_carrier_record_count failed [%d]", *result); + state->step = NET_NFC_STATE_ERROR; + } + } + else + { + /* go to step 2 */ + state->step = NET_NFC_LLCP_STEP_02; + net_nfc_service_llcp_connection_handover_requester(state, result); + } + } + else + { + DEBUG_ERR_MSG("net_nfc_util_get_selector_power_status failed [%d]", *result); + state->step = NET_NFC_STATE_ERROR; + } + } + else + { + DEBUG_ERR_MSG("_net_nfc_service_handover_create_selector_message_from_rawdata failed [%d]", *result); + state->step = NET_NFC_STATE_ERROR; + } + } + break; + + case NET_NFC_LLCP_STEP_06 : + { + DEBUG_SERVER_MSG("step 6"); + + if (state->prev_result != NET_NFC_OK) + { + DEBUG_SERVER_MSG("handover requester : processing failed"); + state->step = NET_NFC_STATE_ERROR; + break; + } + + net_nfc_util_free_ndef_message(state->requester); + net_nfc_util_free_ndef_message(state->selector); + + state->step = 0; + } + break; + + case NET_NFC_STATE_SOCKET_ERROR : + { + DEBUG_SERVER_MSG("exchange server: socket error is received %d", state->prev_result); + need_clean_up = true; + } + break; + + default : + { + DEBUG_SERVER_MSG("unknown step"); + need_clean_up = true; + } + break; + + } + + if (state->step == NET_NFC_STATE_ERROR) + { + net_nfc_manager_util_play_sound(NET_NFC_TASK_ERROR); + _net_nfc_service_llcp_handover_send_response(state->client_fd, NET_NFC_OPERATION_FAIL, NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN, NULL); + net_nfc_util_free_ndef_message(state->requester); + net_nfc_util_free_ndef_message(state->selector); + state->step = 0; + } + + if (need_clean_up == true) + { + net_nfc_util_free_ndef_message(state->requester); + net_nfc_util_free_ndef_message(state->selector); + net_nfc_controller_llcp_socket_close(state->socket, result); + net_nfc_service_llcp_remove_state(state); + _net_nfc_util_free_mem(state); + } + + if (*result != NET_NFC_BUSY && *result != NET_NFC_OK) + { + DEBUG_SERVER_MSG("result is = [%d]", *result); + return false; + } + + LOGD("[%s] END", __func__); + + return true; +} + +static bool _net_nfc_service_llcp_check_hr_record_validation(ndef_message_s *message) +{ + unsigned int count; + ndef_record_s *rec; + + LOGD("[%s] START", __func__); + + if (message == NULL) + return false; + + rec = (ndef_record_s *)message->records; + + if (memcmp(rec->type_s.buffer, CONN_HANDOVER_REQ_RECORD_TYPE, rec->type_s.length) != 0) + { + DEBUG_SERVER_MSG("This is not connection handover request message"); + return false; + } + + if (rec->payload_s.buffer[0] != 0x12) + { + DEBUG_SERVER_MSG("connection handover version is not matched"); + return false; + } + + if (net_nfc_util_get_alternative_carrier_record_count(message, &count) != NET_NFC_OK || count == 0) + { + DEBUG_SERVER_MSG("there is no carrrier reference"); + return false; + } + + LOGD("[%s] END", __func__); + + return true; +} + +static bool _net_nfc_service_llcp_check_hs_record_validation(ndef_message_s *message) +{ + unsigned int count; + ndef_record_s *rec; + + LOGD("[%s] START", __func__); + + if (message == NULL) + return false; + + rec = (ndef_record_s *)message->records; + + if (memcmp(rec->type_s.buffer, CONN_HANDOVER_SEL_RECORD_TYPE, rec->type_s.length) != 0) + { + DEBUG_SERVER_MSG("This is not connection handover request message"); + return false; + } + + if (net_nfc_util_get_alternative_carrier_record_count(message, &count) != NET_NFC_OK || count == 0) + { + DEBUG_SERVER_MSG("there is no carrrier reference"); + return false; + } + + /* Contant should be replaced to get api */ + if (rec->payload_s.buffer[0] != 0x12) + { + DEBUG_SERVER_MSG("connection handover version is not matched"); + return false; + } + + LOGD("[%s] END", __func__); + + return true; +} + +static bool _net_nfc_service_llcp_handover_check_bond_device(bluetooth_device_address_t *address) +{ + bool result = false; + int i, ret; + GPtrArray *devinfo = NULL; + bluetooth_device_info_t *ptr; + + LOGD("[%s] START", __func__); + + /* allocate the g_pointer_array */ + devinfo = g_ptr_array_new(); + + ret = bluetooth_get_bonded_device_list(&devinfo); + if (ret != BLUETOOTH_ERROR_NONE) + { + DEBUG_ERR_MSG("bluetooth_get_bonded_device_list failed with [%d]", ret); + } + else + { + DEBUG_SERVER_MSG("g pointer arrary count : [%d]", devinfo->len); + for (i = 0; i < devinfo->len; i++) + { + ptr = g_ptr_array_index(devinfo, i); + if (ptr != NULL) + { + DEBUG_SERVER_MSG("Name [%s]", ptr->device_name.name); + DEBUG_SERVER_MSG("Major Class [%d]", ptr->device_class.major_class); + DEBUG_SERVER_MSG("Minor Class [%d]", ptr->device_class.minor_class); + DEBUG_SERVER_MSG("Service Class [%d]", ptr->device_class.service_class); + DEBUG_SERVER_MSG("%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X", + ptr->device_address.addr[0], + ptr->device_address.addr[1], ptr->device_address.addr[2], + ptr->device_address.addr[3], + ptr->device_address.addr[4], ptr->device_address.addr[5]); + + /* compare selector address */ + if (memcmp(&(ptr->device_address), address, sizeof(ptr->device_address)) == 0) + { + DEBUG_SERVER_MSG("Found!!!"); + result = true; + break; + } + } + } + } + + /* free g_pointer_array */ + g_ptr_array_free(devinfo, TRUE); + + LOGD("[%s] END", __func__); + + return result; +} + +static void _net_nfc_service_llcp_bt_create_config_cb(int event, bluetooth_event_param_t *param, void *user_data) +{ + net_nfc_handover_create_config_context_t *context = (net_nfc_handover_create_config_context_t *)user_data; + + LOGD("[%s] START", __func__); + + if (context == NULL) + { + DEBUG_SERVER_MSG("user_data is null"); + LOGD("[%s] END", __func__); + return; + } + + switch (event) + { + case BLUETOOTH_EVENT_ENABLED : + DEBUG_SERVER_MSG("BLUETOOTH_EVENT_ENABLED"); + if (context->step == NET_NFC_LLCP_STEP_02) + { + net_nfc_service_llcp_handover_append_bt_carrier_config(context); + } + else + { + DEBUG_SERVER_MSG("step is incorrect"); + } + break; + + case BLUETOOTH_EVENT_DISABLED : + DEBUG_SERVER_MSG("BLUETOOTH_EVENT_DISABLED"); + break; + + default : + DEBUG_SERVER_MSG("unhandled bt event [%d], [0x%04x]", event, param->result); + break; + } + + LOGD("[%s] END", __func__); +} + +int net_nfc_service_llcp_handover_return_to_step(net_nfc_handover_context_t *context) +{ + LOGD("[%s:%d] START", __func__, __LINE__); + + if (context != NULL) + { + net_nfc_llcp_state_t *state = context->llcp_state; + net_nfc_error_e error = NET_NFC_OK; + bool requester = context->is_requester; + + DEBUG_MSG("free context [%p]", context); + _net_nfc_util_free_mem(context); + + if (requester) + { + net_nfc_service_llcp_connection_handover_requester(state, &error); + } + else + { + net_nfc_service_llcp_connection_handover_selector(state, &error); + } + } + else + { + DEBUG_ERR_MSG("null param"); + } + + LOGD("[%s:%d] END", __func__, __LINE__); + + return 0; +} + +int net_nfc_service_llcp_handover_go_to_next_config(net_nfc_handover_create_config_context_t *context) +{ + LOGD("[%s:%d] START", __func__, __LINE__); + + if (context->result == NET_NFC_OK || context->result == NET_NFC_BUSY) + { + if (context->request_type == NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN) + { + if (context->current_type < NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN) + { + context->current_type++; + } + } + else + { + context->current_type = NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN; + } + + g_idle_add((GSourceFunc)net_nfc_service_llcp_handover_iterate_carrier_configs, (gpointer)context); + } + else + { + DEBUG_ERR_MSG("context->result is error [%d]", context->result); + + g_idle_add((GSourceFunc)net_nfc_service_llcp_handover_return_to_step, (gpointer)context); + } + + LOGD("[%s:%d] END", __func__, __LINE__); + + return 0; +} + +int net_nfc_service_llcp_handover_iterate_carrier_configs(net_nfc_handover_create_config_context_t *context) +{ + LOGD("[%s:%d] START", __func__, __LINE__); + + switch (context->current_type) + { + case NET_NFC_CONN_HANDOVER_CARRIER_BT : + DEBUG_MSG("[NET_NFC_CONN_HANDOVER_CARRIER_BT]"); + g_idle_add((GSourceFunc)net_nfc_service_llcp_handover_append_bt_carrier_config, (gpointer)context); + break; + +// case NET_NFC_CONN_HANDOVER_CARRIER_WIFI_BSS : +// DEBUG_MSG("[NET_NFC_CONN_HANDOVER_CARRIER_WIFI_BSS]"); +// g_idle_add((GSourceFunc)net_nfc_service_llcp_handover_append_wifi_carrier_config, context); +// break; +// +// case NET_NFC_CONN_HANDOVER_CARRIER_WIFI_IBSS : +// DEBUG_MSG("[NET_NFC_CONN_HANDOVER_CARRIER_WIFI_BSS]"); +// g_idle_add((GSourceFunc)net_nfc_service_llcp_handover_append_wifi_carrier_config, context); +// break; +// + case NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN : + DEBUG_MSG("[NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN]"); + g_idle_add((GSourceFunc)net_nfc_service_llcp_handover_return_to_step, (gpointer)context); + break; + + default : + DEBUG_MSG("[unknown : %d]", context->current_type); + g_idle_add((GSourceFunc)net_nfc_service_llcp_handover_go_to_next_config, (gpointer)context); + break; + } + + LOGD("[%s:%d] END", __func__, __LINE__); + + return 0; +} + +net_nfc_error_e net_nfc_service_llcp_handover_create_carrier_configs(ndef_message_s *msg, net_nfc_conn_handover_carrier_type_e type, bool requester, net_nfc_llcp_state_t *state, int next_step) +{ + net_nfc_error_e result = NET_NFC_OK; + net_nfc_handover_create_config_context_t *context = NULL; + + LOGD("[%s:%d] START", __func__, __LINE__); + + _net_nfc_util_alloc_mem(context, sizeof(net_nfc_handover_create_config_context_t)); + if (context != NULL) + { + state->step = next_step; + + context->request_type = type; + context->current_type = context->request_type; + if (context->request_type == NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN) + context->current_type = NET_NFC_CONN_HANDOVER_CARRIER_BT; + context->is_requester = requester; + context->llcp_state = state; + context->step = NET_NFC_LLCP_STEP_01; + context->ndef_message = msg; + + /* append carrier record */ + g_idle_add((GSourceFunc)net_nfc_service_llcp_handover_iterate_carrier_configs, (gpointer)context); + } + else + { + DEBUG_ERR_MSG("alloc failed"); + result = NET_NFC_ALLOC_FAIL; + } + + LOGD("[%s:%d] END", __func__, __LINE__); + + return result; +} + +int net_nfc_service_llcp_handover_append_bt_carrier_config(net_nfc_handover_create_config_context_t *context) +{ + LOGD("[%s:%d] START", __func__, __LINE__); + + if (context->result != NET_NFC_OK && context->result != NET_NFC_BUSY) + { + DEBUG_ERR_MSG("context->result is error [%d]", context->result); + + context->step = NET_NFC_LLCP_STEP_RETURN; + } + + switch (context->step) + { + case NET_NFC_LLCP_STEP_01 : + DEBUG_MSG("STEP [1]"); + + if (bluetooth_register_callback(_net_nfc_service_llcp_bt_create_config_cb, context) >= BLUETOOTH_ERROR_NONE) + { + context->step = NET_NFC_LLCP_STEP_02; + context->result = NET_NFC_OK; + + if (bluetooth_check_adapter() != BLUETOOTH_ADAPTER_ENABLED) + { + bluetooth_enable_adapter(); + } + else + { + DEBUG_MSG("bluetooth is enabled already"); + + /* do next step */ + g_idle_add((GSourceFunc)net_nfc_service_llcp_handover_append_bt_carrier_config, (gpointer)context); + } + } + else + { + DEBUG_ERR_MSG("bluetooth_register_callback failed"); + + context->step = NET_NFC_LLCP_STEP_RETURN; + context->result = NET_NFC_OPERATION_FAIL; + g_idle_add((GSourceFunc)net_nfc_service_llcp_handover_append_bt_carrier_config, (gpointer)context); + } + break; + + case NET_NFC_LLCP_STEP_02 : + { + net_nfc_error_e result = NET_NFC_UNKNOWN_ERROR; + net_nfc_carrier_config_s *config = NULL; + ndef_record_s *record = NULL; + bluetooth_device_address_t bt_addr = { { 0, } }; + + DEBUG_MSG("STEP [2]"); + + context->step = NET_NFC_LLCP_STEP_RETURN; + + /* append config to ndef message */ + if ((result = bluetooth_get_local_address(&bt_addr)) == BLUETOOTH_ERROR_NONE) + { + if ((result = net_nfc_util_create_carrier_config(&config, NET_NFC_CONN_HANDOVER_CARRIER_BT)) == NET_NFC_OK) + { + bt_oob_data_t oob = { { 0 }, }; + + if ((result = net_nfc_util_add_carrier_config_property(config, NET_NFC_BT_ATTRIBUTE_ADDRESS, sizeof(bt_addr.addr), bt_addr.addr)) != NET_NFC_OK) + { + DEBUG_ERR_MSG("net_nfc_util_add_carrier_config_property failed [%d]", result); + } + + /* get oob data */ + bluetooth_oob_read_local_data(&oob); + + if (oob.hash_len == 16) + { + DEBUG_SERVER_MSG("oob.hash_len [%d]", oob.hash_len); + + if ((result = net_nfc_util_add_carrier_config_property(config, NET_NFC_BT_ATTRIBUTE_OOB_HASH_C, oob.hash_len, oob.hash)) != NET_NFC_OK) + { + DEBUG_ERR_MSG("net_nfc_util_add_carrier_config_property failed [%d]", result); + } + } + + if (oob.randomizer_len == 16) + { + DEBUG_SERVER_MSG("oob.randomizer_len [%d]", oob.randomizer_len); + + if ((result = net_nfc_util_add_carrier_config_property(config, NET_NFC_BT_ATTRIBUTE_OOB_HASH_R, oob.randomizer_len, oob.randomizer)) != NET_NFC_OK) + { + DEBUG_ERR_MSG("net_nfc_util_add_carrier_config_property failed [%d]", result); + } + } + + net_nfc_service_llcp_handover_bt_change_data_order(config); + + if ((result = net_nfc_util_create_ndef_record_with_carrier_config(&record, config)) == NET_NFC_OK) + { + if ((result = net_nfc_util_append_carrier_config_record(context->ndef_message, record, 0)) == NET_NFC_OK) + { + DEBUG_SERVER_MSG("net_nfc_util_append_carrier_config_record success"); + + context->result = result; + } + else + { + DEBUG_ERR_MSG("net_nfc_util_append_carrier_config_record failed [%d]", result); + + net_nfc_util_free_record(record); + context->result = result; + } + } + else + { + DEBUG_ERR_MSG("net_nfc_util_create_ndef_record_with_carrier_config failed [%d]", result); + context->result = NET_NFC_OPERATION_FAIL; + } + + net_nfc_util_free_carrier_config(config); + } + else + { + DEBUG_ERR_MSG("net_nfc_util_create_carrier_config failed [%d]", result); + context->result = NET_NFC_OPERATION_FAIL; + } + } + else + { + DEBUG_ERR_MSG("bluetooth_get_local_address failed [%d]", result); + context->result = NET_NFC_OPERATION_FAIL; + } + + /* complete and return to upper step */ + g_idle_add((GSourceFunc)net_nfc_service_llcp_handover_append_bt_carrier_config, (gpointer)context); + } + break; + + case NET_NFC_LLCP_STEP_RETURN : + DEBUG_MSG("STEP return"); + + /* unregister current callback */ + bluetooth_unregister_callback(); + + /* complete and return to upper step */ + g_idle_add((GSourceFunc)net_nfc_service_llcp_handover_go_to_next_config, (gpointer)context); + break; + + default : + break; + } + + LOGD("[%s:%d] END", __func__, __LINE__); + + return 0; +} + +int net_nfc_service_llcp_handover_append_wifi_carrier_config(net_nfc_handover_create_config_context_t *context) +{ + LOGD("[%s:%d] START", __func__, __LINE__); + + switch (context->step) + { + case NET_NFC_LLCP_STEP_01 : + DEBUG_MSG("STEP [1]"); + + context->step = NET_NFC_LLCP_STEP_02; + break; + + case NET_NFC_LLCP_STEP_02 : + DEBUG_MSG("STEP [2]"); + + context->step = NET_NFC_LLCP_STEP_03; + break; + + case NET_NFC_LLCP_STEP_03 : + DEBUG_MSG("STEP [3]"); + + context->step = NET_NFC_LLCP_STEP_RETURN; + break; + + case NET_NFC_LLCP_STEP_RETURN : + DEBUG_MSG("STEP return"); + + /* complete and return to upper step */ + g_idle_add((GSourceFunc)net_nfc_service_llcp_handover_go_to_next_config, (gpointer)context); + break; + + default : + break; + } + + LOGD("[%s:%d] END", __func__, __LINE__); + + return 0; +} + +net_nfc_error_e _net_nfc_service_llcp_create_low_power_selector_message(ndef_message_s *request_msg, ndef_message_s *select_msg) +{ + net_nfc_error_e result = NET_NFC_UNKNOWN_ERROR; + unsigned int carrier_count = 0; + + LOGD("[%s] START", __func__); + + if (request_msg == NULL || select_msg == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + if ((result = net_nfc_util_get_alternative_carrier_record_count(request_msg, &carrier_count)) == NET_NFC_OK) + { + int idx; + ndef_record_s *carrier_record = NULL; + net_nfc_conn_handover_carrier_type_e carrier_type = NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN; + + /* check each carrier record and create matched record */ + for (idx = 0; idx < carrier_count; idx++) + { + if ((net_nfc_util_get_alternative_carrier_type(request_msg, idx, &carrier_type) != NET_NFC_OK) || + (carrier_type == NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN)) + { + DEBUG_ERR_MSG("net_nfc_util_get_alternative_carrier_type failed or unknown"); + continue; + } + + DEBUG_SERVER_MSG("carrier type = [%d]", carrier_type); + + /* add temporary config record */ + { + net_nfc_carrier_config_s *config = NULL; + + if ((result = net_nfc_util_create_carrier_config(&config, carrier_type)) == NET_NFC_OK) + { + if ((result = net_nfc_util_create_ndef_record_with_carrier_config(&carrier_record, config)) == NET_NFC_OK) + { + DEBUG_SERVER_MSG("_net_nfc_service_llcp_create_bt_configuration success"); + } + else + { + DEBUG_ERR_MSG("net_nfc_util_create_ndef_record_with_carrier_config failed [%d]", result); + net_nfc_util_free_carrier_config(config); + continue; + } + + net_nfc_util_free_carrier_config(config); + } + else + { + DEBUG_ERR_MSG("net_nfc_util_get_local_bt_address return NULL"); + continue; + } + } + + /* append carrier configure record to selector message */ + if ((result = net_nfc_util_append_carrier_config_record(select_msg, carrier_record, NET_NFC_CONN_HANDOVER_CARRIER_INACTIVATE)) == NET_NFC_OK) + { + DEBUG_SERVER_MSG("net_nfc_util_append_carrier_config_record success!!"); + } + else + { + DEBUG_ERR_MSG("net_nfc_util_append_carrier_config_record failed [%d]", result); + + net_nfc_util_free_record(carrier_record); + } + } + + result = NET_NFC_OK; + } + else + { + DEBUG_ERR_MSG("net_nfc_util_get_alternative_carrier_record_count failed"); + } + + LOGD("[%s] END", __func__); + + return result; +} + +static void _net_nfc_service_llcp_process_bt_config_cb(int event, bluetooth_event_param_t *param, void *user_data) +{ + net_nfc_handover_process_config_context_t *context = (net_nfc_handover_process_config_context_t *)user_data; + + LOGD("[%s] START", __func__); + + if (context == NULL) + { + DEBUG_SERVER_MSG("user_data is null"); + LOGD("[%s] END", __func__); + return; + } + + switch (event) + { + case BLUETOOTH_EVENT_ENABLED : + DEBUG_SERVER_MSG("BLUETOOTH_EVENT_ENABLED"); + if (context->step == NET_NFC_LLCP_STEP_02) + { + net_nfc_service_llcp_handover_process_bt_config(context); + } + else + { + DEBUG_SERVER_MSG("step is incorrect"); + } + break; + + case BLUETOOTH_EVENT_DISABLED : + DEBUG_SERVER_MSG("BLUETOOTH_EVENT_DISABLED"); + break; + + case BLUETOOTH_EVENT_BONDING_FINISHED : + DEBUG_SERVER_MSG("BLUETOOTH_EVENT_BONDING_FINISHED, result [0x%04x]", param->result); + if (context->step == NET_NFC_LLCP_STEP_03) + { + if (param->result < BLUETOOTH_ERROR_NONE) + { + DEBUG_ERR_MSG("bond failed"); + context->result = NET_NFC_OPERATION_FAIL; + } + + net_nfc_service_llcp_handover_process_bt_config(context); + } + else + { + DEBUG_SERVER_MSG("step is incorrect"); + } + break; + + default : + DEBUG_SERVER_MSG("unhandled bt event [%d], [0x%04x]", event, param->result); + break; + } + + LOGD("[%s] END", __func__); +} + +net_nfc_error_e net_nfc_service_llcp_handover_process_carrier_config(net_nfc_carrier_config_s *config, bool requester, net_nfc_llcp_state_t *state, int next_step) +{ + net_nfc_error_e result = NET_NFC_OK; + net_nfc_handover_process_config_context_t *context = NULL; + + LOGD("[%s:%d] START", __func__, __LINE__); + + _net_nfc_util_alloc_mem(context, sizeof(net_nfc_handover_process_config_context_t)); + if (context != NULL) + { + state->step = next_step; + + context->request_type = config->type; + context->is_requester = requester; + context->llcp_state = state; + context->step = NET_NFC_LLCP_STEP_01; + context->config = config; + + /* append carrier record */ + switch (config->type) + { + case NET_NFC_CONN_HANDOVER_CARRIER_BT : + DEBUG_MSG("[NET_NFC_CONN_HANDOVER_CARRIER_BT]"); + net_nfc_service_llcp_handover_bt_change_data_order(context->config); + g_idle_add((GSourceFunc)net_nfc_service_llcp_handover_process_bt_config, (gpointer)context); + break; + + case NET_NFC_CONN_HANDOVER_CARRIER_WIFI_BSS : + DEBUG_MSG("[NET_NFC_CONN_HANDOVER_CARRIER_WIFI_BSS]"); + _net_nfc_util_free_mem(context); + break; + + case NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN : + DEBUG_MSG("[NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN]"); + _net_nfc_util_free_mem(context); + break; + + default : + DEBUG_MSG("[unknown]"); + _net_nfc_util_free_mem(context); + break; + } + } + else + { + DEBUG_ERR_MSG("alloc failed"); + result = NET_NFC_ALLOC_FAIL; + } + + LOGD("[%s:%d] END", __func__, __LINE__); + + return result; +} + +int net_nfc_service_llcp_handover_process_bt_config(net_nfc_handover_process_config_context_t *context) +{ + LOGD("[%s:%d] START", __func__, __LINE__); + + if (context->result != NET_NFC_OK && context->result != NET_NFC_BUSY) + { + DEBUG_ERR_MSG("context->result is error [%d]", context->result); + context->step = NET_NFC_LLCP_STEP_RETURN; + } + + switch (context->step) + { + case NET_NFC_LLCP_STEP_01 : + DEBUG_MSG("STEP [1]"); + + if (bluetooth_register_callback(_net_nfc_service_llcp_process_bt_config_cb, context) >= BLUETOOTH_ERROR_NONE) + { + /* next step */ + context->step = NET_NFC_LLCP_STEP_02; + + if (bluetooth_check_adapter() != BLUETOOTH_ADAPTER_ENABLED) + { + context->result = NET_NFC_OK; + bluetooth_enable_adapter(); + } + else + { + /* do next step */ + DEBUG_MSG("BT is enabled already, go next step"); + + context->result = NET_NFC_OK; + g_idle_add((GSourceFunc)net_nfc_service_llcp_handover_process_bt_config, (gpointer)context); + } + } + else + { + DEBUG_ERR_MSG("bluetooth_register_callback failed"); + context->result = NET_NFC_OPERATION_FAIL; + g_idle_add((GSourceFunc)net_nfc_service_llcp_handover_process_bt_config, (gpointer)context); + } + break; + + case NET_NFC_LLCP_STEP_02 : + { + bluetooth_device_address_t address = { { 0, } }; + data_s temp = { NULL, 0 }; + + DEBUG_MSG("STEP [2]"); + + net_nfc_util_get_carrier_config_property(context->config, NET_NFC_BT_ATTRIBUTE_ADDRESS, (uint16_t *)&temp.length, &temp.buffer); + if (temp.length == 6) + { + memcpy(address.addr, temp.buffer, MIN(sizeof(address.addr), temp.length)); + + if (_net_nfc_service_llcp_handover_check_bond_device(&address) == true) + { + DEBUG_SERVER_MSG("already paired with [%02x:%02x:%02x:%02x:%02x:%02x]", address.addr[0], address.addr[1], address.addr[2], address.addr[3], address.addr[4], address.addr[5]); + + if (context->is_requester) + { + /* next step */ + context->step = NET_NFC_LLCP_STEP_03; + } + else + { + /* return */ + context->step = NET_NFC_LLCP_STEP_RETURN; + } + + context->result = NET_NFC_OK; + g_idle_add((GSourceFunc)net_nfc_service_llcp_handover_process_bt_config, (gpointer)context); + } + else + { + bt_oob_data_t oob = { { 0 } , }; + + if (net_nfc_service_llcp_handover_get_oob_data(context->config, &oob) == NET_NFC_OK) + { + /* set oob data */ + bluetooth_oob_add_remote_data(&address, &oob); + } + + context->result = NET_NFC_OK; + + if (context->is_requester) + { + /* pair and send reponse */ + context->step = NET_NFC_LLCP_STEP_03; + + bluetooth_bond_device(&address); + } + else + { + /* return */ + context->step = NET_NFC_LLCP_STEP_RETURN; + g_idle_add((GSourceFunc)net_nfc_service_llcp_handover_process_bt_config, (gpointer)context); + } + } + } + else + { + DEBUG_ERR_MSG("bluetooth address is invalid. [%d] bytes", temp.length); + + context->step = NET_NFC_LLCP_STEP_RETURN; + context->result = NET_NFC_OPERATION_FAIL; + g_idle_add((GSourceFunc)net_nfc_service_llcp_handover_process_bt_config, (gpointer)context); + } + } + break; + + case NET_NFC_LLCP_STEP_03 : + { + data_s data = {NULL, 0}; + + DEBUG_MSG("STEP [3]"); + + context->step++; + + net_nfc_util_get_carrier_config_property(context->config, NET_NFC_BT_ATTRIBUTE_ADDRESS, (uint16_t *)&data.length, &data.buffer); + if (data.length == 6) + { + /* send handover success message to client */ + _net_nfc_service_llcp_handover_send_response(context->llcp_state->client_fd, NET_NFC_OK, NET_NFC_CONN_HANDOVER_CARRIER_BT, &data); + + context->step = NET_NFC_LLCP_STEP_RETURN; + context->result = NET_NFC_OK; + } + else + { + DEBUG_ERR_MSG("bluetooth address is invalid. [%d] bytes", data.length); + + context->step = NET_NFC_LLCP_STEP_RETURN; + context->result = NET_NFC_OPERATION_FAIL; + } + + g_idle_add((GSourceFunc)net_nfc_service_llcp_handover_process_bt_config, (gpointer)context); + } + break; + + case NET_NFC_LLCP_STEP_RETURN : + DEBUG_MSG("STEP return"); + + /* unregister bluetooth callback */ + bluetooth_unregister_callback(); + + g_idle_add((GSourceFunc)net_nfc_service_llcp_handover_return_to_step, (gpointer)context); + break; + + default : + break; + } + + LOGD("[%s:%d] END", __func__, __LINE__); + + return 0; +} + +net_nfc_error_e net_nfc_service_llcp_handover_get_oob_data(net_nfc_carrier_config_s *config, bt_oob_data_t *oob) +{ + net_nfc_error_e result = NET_NFC_UNKNOWN_ERROR; + data_s hash = { NULL, 0 }; + data_s randomizer = { NULL, 0 }; + + LOGD("[%s:%d] START", __func__, __LINE__); + + if (config == NULL || oob == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + memset(oob, 0, sizeof(bt_oob_data_t)); + + if ((result = net_nfc_util_get_carrier_config_property(config, NET_NFC_BT_ATTRIBUTE_OOB_HASH_C, (uint16_t *)&hash.length, &hash.buffer)) == NET_NFC_OK) + { + if ((result = net_nfc_util_get_carrier_config_property(config, NET_NFC_BT_ATTRIBUTE_OOB_HASH_R, (uint16_t *)&randomizer.length, &randomizer.buffer)) == NET_NFC_OK) + { + if (hash.length == 16) + { + DEBUG_MSG("hash.length == 16"); + + oob->hash_len = MIN(sizeof(oob->hash), hash.length); + memcpy(oob->hash, hash.buffer, oob->hash_len); + } + else + { + DEBUG_ERR_MSG("hash.length error : [%d] bytes", hash.length); + } + + if (randomizer.length == 16) + { + DEBUG_MSG("randomizer.length == 16"); + + oob->randomizer_len = MIN(sizeof(oob->randomizer), randomizer.length); + memcpy(oob->randomizer, randomizer.buffer, oob->randomizer_len); + } + else + { + DEBUG_ERR_MSG("randomizer.length error : [%d] bytes", randomizer.length); + } + } + } + + LOGD("[%s:%d] END", __func__, __LINE__); + + return result; +} + +net_nfc_error_e net_nfc_service_llcp_handover_bt_change_data_order(net_nfc_carrier_config_s *config) +{ + uint8_t *buffer = NULL; + uint16_t len = 0; + net_nfc_error_e result = NET_NFC_UNKNOWN_ERROR; + + LOGD("[%s:%d] START", __func__, __LINE__); + + if (config == NULL) + { + return NET_NFC_NULL_PARAMETER; + } + + if ((result = net_nfc_util_get_carrier_config_property(config, NET_NFC_BT_ATTRIBUTE_ADDRESS, &len, &buffer)) == NET_NFC_OK) + { + if (len == 6) + { + NET_NFC_REVERSE_ORDER_6_BYTES(buffer); + } + else + { + DEBUG_ERR_MSG("NET_NFC_BT_ATTRIBUTE_ADDRESS len error : [%d] bytes", len); + } + } + + if ((result = net_nfc_util_get_carrier_config_property(config, NET_NFC_BT_ATTRIBUTE_OOB_HASH_C, &len, &buffer)) == NET_NFC_OK) + { + if (len == 16) + { + NET_NFC_REVERSE_ORDER_16_BYTES(buffer); + } + else + { + DEBUG_ERR_MSG("NET_NFC_BT_ATTRIBUTE_OOB_HASH_C len error : [%d] bytes", len); + } + } + + if ((result = net_nfc_util_get_carrier_config_property(config, NET_NFC_BT_ATTRIBUTE_OOB_HASH_R, &len, &buffer)) == NET_NFC_OK) + { + if (len == 16) + { + NET_NFC_REVERSE_ORDER_16_BYTES(buffer); + } + else + { + DEBUG_ERR_MSG("NET_NFC_BT_ATTRIBUTE_OOB_HASH_R error : [%d] bytes", len); + } + } + + LOGD("[%s:%d] END", __func__, __LINE__); + + return result; +} diff --git a/src/manager/net_nfc_service_se.c b/src/manager/net_nfc_service_se.c new file mode 100755 index 0000000..a7b3aa5 --- /dev/null +++ b/src/manager/net_nfc_service_se.c @@ -0,0 +1,444 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +#include "vconf.h" +#include "tapi_common.h" +#include "ITapiSim.h" + +#include "net_nfc_controller_private.h" +#include "net_nfc_util_private.h" +#include "net_nfc_typedef.h" +#include "net_nfc_debug_private.h" +#include "net_nfc_service_private.h" +#include "net_nfc_app_util_private.h" +#include "net_nfc_server_ipc_private.h" +#include "net_nfc_server_dispatcher_private.h" +#include "net_nfc_service_se_private.h" + +/* define */ +/* For ESE*/ +static net_nfc_se_setting_t g_se_setting; + +/* For UICC */ +static struct tapi_handle *uicc_handle = NULL; +static bool net_nfc_service_check_sim_state(void); +static void _uicc_transmit_apdu_cb(TapiHandle *handle, int result, void *data, void *user_data); +static void _uicc_get_atr_cb(TapiHandle *handle, int result, void *data, void *user_data); +static void _uicc_status_noti_cb(TapiHandle *handle, const char *noti_id, void *data, void *user_data); + +net_nfc_se_setting_t *net_nfc_service_se_get_se_setting() +{ + return &g_se_setting; +} + +net_nfc_target_handle_s *net_nfc_service_se_get_current_ese_handle() +{ + return g_se_setting.current_ese_handle; +} + +void net_nfc_service_se_set_current_ese_handle(net_nfc_target_handle_s *handle) +{ + g_se_setting.current_ese_handle = handle; +} + +uint8_t net_nfc_service_se_get_se_type() +{ + return g_se_setting.type; +} + +void net_nfc_service_se_set_se_type(uint8_t type) +{ + g_se_setting.type = type; +} + +uint8_t net_nfc_service_se_get_se_mode() +{ + return g_se_setting.mode; +} + +void net_nfc_service_se_set_se_mode(uint8_t mode) +{ + g_se_setting.mode = mode; +} + +net_nfc_error_e net_nfc_service_se_change_se(uint8_t type) +{ + net_nfc_error_e result = NET_NFC_OK; + + switch (type) + { + case SECURE_ELEMENT_TYPE_UICC : + /*turn off ESE*/ + net_nfc_controller_set_secure_element_mode(SECURE_ELEMENT_TYPE_ESE, SECURE_ELEMENT_OFF_MODE, &result); + + /*turn on UICC*/ + net_nfc_controller_set_secure_element_mode(SECURE_ELEMENT_TYPE_UICC, SECURE_ELEMENT_VIRTUAL_MODE, &result); + if (result == NET_NFC_OK) + { + DEBUG_SERVER_MSG("changed to SECURE_ELEMENT_TYPE_UICC"); + + net_nfc_service_se_set_se_type(SECURE_ELEMENT_TYPE_UICC); + net_nfc_service_se_set_se_mode(SECURE_ELEMENT_VIRTUAL_MODE); + + if (vconf_set_int(VCONFKEY_NFC_SE_TYPE, VCONFKEY_NFC_SE_TYPE_UICC) != 0) + { + DEBUG_ERR_MSG("vconf_set_int failed"); + } + } + else + { + DEBUG_ERR_MSG("SECURE_ELEMENT_TYPE_UICC, SECURE_ELEMENT_VIRTUAL_MODE failed [%d]", result); + } + break; + + case SECURE_ELEMENT_TYPE_ESE : + /*turn off UICC*/ + net_nfc_controller_set_secure_element_mode(SECURE_ELEMENT_TYPE_UICC, SECURE_ELEMENT_OFF_MODE, &result); + + /*turn on ESE*/ + net_nfc_controller_set_secure_element_mode(SECURE_ELEMENT_TYPE_ESE, SECURE_ELEMENT_VIRTUAL_MODE, &result); + if (result == NET_NFC_OK) + { + DEBUG_SERVER_MSG("changed to SECURE_ELEMENT_TYPE_ESE"); + + net_nfc_service_se_set_se_type(SECURE_ELEMENT_TYPE_ESE); + net_nfc_service_se_set_se_mode(SECURE_ELEMENT_VIRTUAL_MODE); + + if (vconf_set_int(VCONFKEY_NFC_SE_TYPE, VCONFKEY_NFC_SE_TYPE_ESE) != 0) + { + DEBUG_ERR_MSG("vconf_set_int failed"); + } + } + else + { + DEBUG_ERR_MSG("SECURE_ELEMENT_TYPE_ESE, SECURE_ELEMENT_VIRTUAL_MODE failed [%d]", result); + } + break; + + default : + { + net_nfc_error_e result_ese, result_uicc; + + net_nfc_service_se_set_se_type(SECURE_ELEMENT_TYPE_INVALID); + net_nfc_service_se_set_se_mode(SECURE_ELEMENT_OFF_MODE); + + /*turn off ESE*/ + net_nfc_controller_set_secure_element_mode(SECURE_ELEMENT_TYPE_ESE, SECURE_ELEMENT_OFF_MODE, &result_ese); + + /*turn off UICC*/ + net_nfc_controller_set_secure_element_mode(SECURE_ELEMENT_TYPE_UICC, SECURE_ELEMENT_OFF_MODE, &result_uicc); + if (result_ese != NET_NFC_INVALID_HANDLE && result_uicc != NET_NFC_INVALID_HANDLE) + { + DEBUG_SERVER_MSG("SE off all"); + if (vconf_set_int(VCONFKEY_NFC_SE_TYPE, VCONFKEY_NFC_SE_TYPE_NONE) != 0) + { + DEBUG_ERR_MSG("vconf_set_int failed"); + } + result = NET_NFC_OK; + } + else + { + DEBUG_ERR_MSG("ALL OFF failed, ese [%d], uicc [%d]", result_ese, result_uicc); + result = NET_NFC_INVALID_HANDLE; + } + } + break; + } + + return result; +} + +void net_nfc_service_se_detected(net_nfc_request_msg_t *msg) +{ + net_nfc_request_target_detected_t *detail_msg = (net_nfc_request_target_detected_t *)(msg); + net_nfc_target_handle_s *handle = NULL; + net_nfc_error_e state = NET_NFC_OK; + net_nfc_response_open_internal_se_t resp = { 0 }; + + if (detail_msg == NULL) + { + return; + } + + handle = detail_msg->handle; + g_se_setting.current_ese_handle = handle; + + DEBUG_SERVER_MSG("trying to connect to ESE = [0x%p]", handle); + + if (!net_nfc_controller_connect(handle, &state)) + { + DEBUG_SERVER_MSG("connect failed = [%d]", state); + resp.result = state; + } + +#ifdef BROADCAST_MESSAGE + net_nfc_server_set_server_state(NET_NFC_SE_CONNECTED); +#endif + + resp.handle = handle; + resp.trans_param = g_se_setting.open_request_trans_param; + resp.se_type = SECURE_ELEMENT_TYPE_ESE; + + DEBUG_SERVER_MSG("trans param = [%p]", resp.trans_param); + + net_nfc_send_response_msg(detail_msg->client_fd, NET_NFC_MESSAGE_OPEN_INTERNAL_SE, &resp, sizeof(net_nfc_response_open_internal_se_t), NULL); + + g_se_setting.open_request_trans_param = NULL; +} + +net_nfc_error_e net_nfc_service_se_close_ese() +{ + net_nfc_error_e result = NET_NFC_OK; + + if (g_se_setting.current_ese_handle != NULL) + { + if (net_nfc_controller_disconnect(g_se_setting.current_ese_handle, &result) == false) + { + net_nfc_controller_exception_handler(); + } + net_nfc_service_se_set_current_ese_handle(NULL); + } + + return result; +} + +bool net_nfc_service_tapi_init(void) +{ + char **cpList = NULL; + + DEBUG_SERVER_MSG("tapi init"); + + cpList = tel_get_cp_name_list(); + + uicc_handle = tel_init(cpList[0]); + if (uicc_handle == NULL) + { + int error; + + error = tel_register_noti_event(uicc_handle, TAPI_NOTI_SIM_STATUS, _uicc_status_noti_cb, NULL); + } + else + { + DEBUG_SERVER_MSG("tel_init() failed"); + return false; + } + + DEBUG_SERVER_MSG("tel_init() is success"); + + return net_nfc_service_check_sim_state(); +} + +void net_nfc_service_tapi_deinit(void) +{ + DEBUG_SERVER_MSG("deinit tapi"); + + tel_deregister_noti_event(uicc_handle, TAPI_NOTI_SIM_STATUS); + + tel_deinit(uicc_handle); +} + +bool net_nfc_service_transfer_apdu(int client_fd, data_s *apdu, void *trans_param) +{ + net_nfc_request_msg_t *param = NULL; + TelSimApdu_t apdu_data = { 0 }; + int result; + + DEBUG_SERVER_MSG("tranfer apdu"); + + if (apdu == NULL) + return false; + + apdu_data.apdu = apdu->buffer; + apdu_data.apdu_len = apdu->length; + + /* make param */ + _net_nfc_util_alloc_mem(param, sizeof(net_nfc_request_msg_t)); + if (param != NULL) + { + param->client_fd = client_fd; + param->user_param = (uint32_t)trans_param; + + result = tel_req_sim_apdu(uicc_handle, &apdu_data, _uicc_transmit_apdu_cb, param); + if (result == 0) + { + DEBUG_SERVER_MSG("sim apdu request is success"); + } + else + { + DEBUG_ERR_MSG("request sim apdu is failed with error = [%d]", result); + return false; + } + } + else + { + DEBUG_ERR_MSG("_net_nfc_util_alloc_mem failed"); + return false; + } + + return true; +} + +bool net_nfc_service_request_atr(int client_fd, void *trans_param) +{ + int result; + net_nfc_request_msg_t *param = NULL; + + /* make param */ + _net_nfc_util_alloc_mem(param, sizeof(net_nfc_request_msg_t)); + if (param != NULL) + { + param->client_fd = client_fd; + param->user_param = (uint32_t)trans_param; + + result = tel_req_sim_atr(uicc_handle, _uicc_get_atr_cb, param); + if (result == 0) + { + DEBUG_SERVER_MSG("request is success"); + } + else + { + DEBUG_SERVER_MSG("failed to request ATR = [%d]", result); + return false; + } + } + else + { + DEBUG_ERR_MSG("_net_nfc_manager_util_alloc_mem failed"); + return false; + } + + return true; +} + +static bool net_nfc_service_check_sim_state(void) +{ + TelSimCardStatus_t state = (TelSimCardStatus_t)0; + int b_card_changed = 0; + int error; + + DEBUG_SERVER_MSG("check sim state"); + + error = tel_get_sim_init_info(uicc_handle, &state, &b_card_changed); + + DEBUG_SERVER_MSG("current sim init state = [%d]", state); + + if (error != 0) + { + DEBUG_SERVER_MSG("error = [%d]", error); + return false; + } + else if (state == TAPI_SIM_STATUS_SIM_INIT_COMPLETED || state == TAPI_SIM_STATUS_SIM_INITIALIZING) + { + DEBUG_SERVER_MSG("sim is initialized"); + } + else + { + DEBUG_SERVER_MSG("sim is not initialized"); + return false; + } + + return true; +} + +void _uicc_transmit_apdu_cb(TapiHandle *handle, int result, void *data, void *user_data) +{ + TelSimApduResp_t *apdu = (TelSimApduResp_t *)data; + net_nfc_response_send_apdu_t resp = { 0 }; + net_nfc_request_msg_t *param = (net_nfc_request_msg_t *)user_data; + + DEBUG_SERVER_MSG("_uicc_transmit_apdu_cb"); + + if (result == 0) + { + resp.result = NET_NFC_OK; + } + else + { + resp.result = NET_NFC_OPERATION_FAIL; + } + + resp.trans_param = (void *)param->user_param; + + if (apdu != NULL && apdu->apdu_resp_len > 0) + { + resp.data.length = apdu->apdu_resp_len; + + DEBUG_MSG("send response send apdu msg"); + net_nfc_send_response_msg(param->client_fd, NET_NFC_MESSAGE_SEND_APDU_SE, (void *)&resp, sizeof(net_nfc_response_send_apdu_t), apdu->apdu_resp, apdu->apdu_resp_len, NULL); + } + else + { + DEBUG_MSG("send response send apdu msg"); + net_nfc_send_response_msg(param->client_fd, NET_NFC_MESSAGE_SEND_APDU_SE, (void *)&resp, sizeof(net_nfc_response_send_apdu_t), NULL); + } + + _net_nfc_util_free_mem(param); +} + +void _uicc_get_atr_cb(TapiHandle *handle, int result, void *data, void *user_data) +{ + net_nfc_request_msg_t *param = (net_nfc_request_msg_t *)user_data; + + /* TODO : response message */ + + DEBUG_SERVER_MSG("_uicc_get_atr_cb"); + + _net_nfc_util_free_mem(param); +} + +void _uicc_status_noti_cb(TapiHandle *handle, const char *noti_id, void *data, void *user_data) +{ + TelSimCardStatus_t *status = (TelSimCardStatus_t *)data; + + /* TODO : */ + DEBUG_SERVER_MSG("_uicc_status_noti_cb"); + + switch (*status) + { + case TAPI_SIM_STATUS_SIM_INIT_COMPLETED : + DEBUG_SERVER_MSG("TAPI_SIM_STATUS_SIM_INIT_COMPLETED"); + break; + + case TAPI_SIM_STATUS_CARD_REMOVED : + DEBUG_SERVER_MSG("TAPI_SIM_STATUS_CARD_REMOVED"); + break; + + default : + DEBUG_SERVER_MSG("unknown status [%d]", *status); + break; + } +} + +bool net_nfc_service_se_transaction_receive(net_nfc_request_msg_t* msg) +{ + bool res = true; + net_nfc_request_se_event_t *se_event = (net_nfc_request_se_event_t *)msg; + + if (se_event->request_type == NET_NFC_MESSAGE_SE_START_TRANSACTION) + { + DEBUG_SERVER_MSG("launch se app"); + + net_nfc_app_util_launch_se_transaction_app(se_event->aid.buffer, se_event->aid.length, se_event->param.buffer, se_event->param.length); + + DEBUG_SERVER_MSG("launch se app end"); + } + + return res; +} diff --git a/src/manager/net_nfc_service_tag.c b/src/manager/net_nfc_service_tag.c new file mode 100755 index 0000000..890d59d --- /dev/null +++ b/src/manager/net_nfc_service_tag.c @@ -0,0 +1,179 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +#include "net_nfc_controller_private.h" +#include "net_nfc_util_private.h" +#include "net_nfc_typedef.h" +#include "net_nfc_debug_private.h" +#include "net_nfc_service_private.h" +#include "net_nfc_app_util_private.h" +#include "net_nfc_server_ipc_private.h" +#include "net_nfc_server_dispatcher_private.h" +#include "net_nfc_manager_util_private.h" + +/* define */ + +/* static variable */ + +/* static callback function */ + +////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +void net_nfc_service_watch_dog(net_nfc_request_msg_t* req_msg) +{ + net_nfc_request_watch_dog_t *detail_msg = NULL; + net_nfc_error_e result = NET_NFC_OK; + bool isPresentTarget = true; + + if (req_msg == NULL) + { + return; + } + + detail_msg = (net_nfc_request_watch_dog_t *)req_msg; + + //DEBUG_SERVER_MSG("connection type = [%d]", detail_msg->handle->connection_type); + + /* IMPORTANT, TEMPORARY : switching context to another thread for give CPU time */ + usleep(10000); + + if ((detail_msg->handle->connection_type == NET_NFC_P2P_CONNECTION_TARGET) || (detail_msg->handle->connection_type == NET_NFC_TAG_CONNECTION)) + { + isPresentTarget = net_nfc_controller_check_target_presence(detail_msg->handle, &result); + } + else + { + isPresentTarget = false; + } + + if (isPresentTarget == true) + { + /* put message again */ + net_nfc_dispatcher_queue_push(req_msg); + } + else + { + //DEBUG_SERVER_MSG("try to disconnect target = [%d]", detail_msg->handle); + + if ((NET_NFC_NOT_INITIALIZED != result) && (NET_NFC_INVALID_HANDLE != result)) + { + if (net_nfc_controller_disconnect(detail_msg->handle, &result) == false) + { + + DEBUG_SERVER_MSG("try to disconnect result = [%d]", result); + net_nfc_controller_exception_handler(); + } + } +#ifdef BROADCAST_MESSAGE + net_nfc_server_set_server_state(NET_NFC_SERVER_IDLE); +#endif + + { + net_nfc_response_target_detached_t target_detached = { 0, }; + memset(&target_detached, 0x00, sizeof(net_nfc_response_target_detached_t)); + + target_detached.devType = detail_msg->devType; + target_detached.handle = detail_msg->handle; + + net_nfc_broadcast_response_msg(NET_NFC_MESSAGE_TAG_DETACHED, (void*)&target_detached, sizeof(net_nfc_response_target_detached_t), NULL); + } + + _net_nfc_util_free_mem(req_msg); + } +} + +void net_nfc_service_clean_tag_context(net_nfc_request_target_detected_t* stand_alone, net_nfc_error_e result) +{ + if (result == NET_NFC_OK) + { + bool isPresentTarget = true; + net_nfc_error_e result = NET_NFC_OK; + + while (isPresentTarget) + { + isPresentTarget = net_nfc_controller_check_target_presence(stand_alone->handle, &result); + } + + if (net_nfc_controller_disconnect(stand_alone->handle, &result) == false) + { + net_nfc_controller_exception_handler(); + } + } + else + { + net_nfc_error_e result = NET_NFC_OK; + + if (result != NET_NFC_TARGET_IS_MOVED_AWAY && result != NET_NFC_OPERATION_FAIL) + { + bool isPresentTarget = true; + + while (isPresentTarget) + { + isPresentTarget = net_nfc_controller_check_target_presence(stand_alone->handle, &result); + } + } + + DEBUG_SERVER_MSG("try to disconnect target = [%d]", stand_alone->handle->connection_id); + + if (net_nfc_controller_disconnect(stand_alone->handle, &result) == false) + { + net_nfc_controller_exception_handler(); + } + } + +#ifdef BROADCAST_MESSAGE + net_nfc_server_set_server_state(NET_NFC_SERVER_IDLE); +#endif +} + +#ifndef BROADCAST_MESSAGE +data_s* net_nfc_service_tag_process(net_nfc_target_handle_s* handle, int devType, net_nfc_error_e* result) +{ + net_nfc_error_e status = NET_NFC_OK; + data_s* recv_data = NULL; + *result = NET_NFC_OK; + + DEBUG_SERVER_MSG("trying to connect to tag = [0x%p]", handle); + + if (!net_nfc_controller_connect (handle, &status)) + { + DEBUG_SERVER_MSG("connect failed"); + *result = status; + return NULL; + } + +#ifdef BROADCAST_MESSAGE + net_nfc_server_set_server_state(NET_NFC_TAG_CONNECTED); +#endif + + DEBUG_SERVER_MSG("read ndef from tag"); + + if(net_nfc_controller_read_ndef (handle, &recv_data, &status) == true) + { + return recv_data; + } + else + { + DEBUG_SERVER_MSG("can not read card"); + *result = status; + return NULL; + } + +} +#endif diff --git a/src/manager/net_nfc_service_vconf.c b/src/manager/net_nfc_service_vconf.c new file mode 100755 index 0000000..1dae7ff --- /dev/null +++ b/src/manager/net_nfc_service_vconf.c @@ -0,0 +1,182 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include +#include +#include +#include "net_nfc_typedef_private.h" +#include "net_nfc_debug_private.h" +#include "net_nfc_controller_private.h" +#include "net_nfc_util_private.h" +#include "net_nfc_server_dispatcher_private.h" +#include "net_nfc_app_util_private.h" +#include "aul.h" + + + +///////////////////////////////////////////////////////////////////////// + +static void net_nfc_service_airplane_mode_cb(keynode_t* key, void* data) +{ + int flight_mode = 0; + int nfc_state, sbeam_state, predefined_state = 0; + static gboolean powered_off_by_flightmode = FALSE; + int result; + + if ((result= vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, &flight_mode)) == 0) + { + DEBUG_SERVER_MSG("vconf_get_bool success \n"); + } + else + { + DEBUG_ERR_MSG("vconf_get_bool failed \n"); + } + if ((result= vconf_get_bool(VCONFKEY_NFC_STATE, &nfc_state)) == 0) + { + DEBUG_SERVER_MSG("vconf_get_bool success \n"); + } + else + { + DEBUG_ERR_MSG("vconf_get_bool failed \n"); + } + if ((result= vconf_get_bool(VCONFKEY_NFC_SBEAM, &sbeam_state)) == 0) + { + DEBUG_SERVER_MSG("vconf_get_bool success \n"); + } + else + { + DEBUG_ERR_MSG("vconf_get_bool failed \n"); + } + if ((result= vconf_get_bool(VCONFKEY_NFC_PREDEFINED_ITEM_STATE, &predefined_state)) == 0) + { + DEBUG_SERVER_MSG("vconf_get_bool success \n"); + } + else + { + DEBUG_ERR_MSG("vconf_get_bool failed \n"); + } + + DEBUG_SERVER_MSG("flight mode %s \n", flight_mode > 0 ? "ON" : "OFF"); + DEBUG_SERVER_MSG("nfc_state %d, sbeam_state %d, predefined_state %d NFC was off by flight mode %s \n", + nfc_state, sbeam_state, predefined_state, powered_off_by_flightmode == TRUE ? "Yes" : "No"); + + if (flight_mode > 0) /* turn flight mode on */ + { + /* flight mode enabled */ + if (nfc_state == VCONFKEY_NFC_STATE_OFF) + return; + + DEBUG_SERVER_MSG("Turning NFC off \n"); + + /* nfc off */ + net_nfc_request_msg_t *req_msg = NULL; + + _net_nfc_util_alloc_mem(req_msg, sizeof(net_nfc_request_msg_t)); + if (req_msg == NULL) + return; + + req_msg->length = sizeof(net_nfc_request_msg_t); + req_msg->request_type = NET_NFC_MESSAGE_SERVICE_DEINIT; + + net_nfc_dispatcher_queue_push(req_msg); + + /* set internal flag */ + powered_off_by_flightmode = TRUE; + + /* sbeam off */ + if ((result = vconf_set_bool(VCONFKEY_NFC_SBEAM, FALSE)) == 0) + { + DEBUG_SERVER_MSG("vconf_set_bool success \n"); + } + else + { + DEBUG_ERR_MSG("vconf_set_bool failed \n"); + } + + /* predefined item off */ + if ((result = vconf_set_bool(VCONFKEY_NFC_PREDEFINED_ITEM_STATE, FALSE)) == 0) + { + DEBUG_SERVER_MSG("vconf_set_bool success \n"); + } + else + { + DEBUG_ERR_MSG("vconf_set_bool failed \n"); + } + } + else if (flight_mode == 0) /* turn flight mode off */ + { + /* flight mode disabled */ + if (nfc_state > VCONFKEY_NFC_STATE_OFF) + return; + + if (powered_off_by_flightmode != TRUE) + return; + + DEBUG_SERVER_MSG("Turning NFC on \n"); + + /* nfc on */ + net_nfc_request_msg_t *req_msg = NULL; + + _net_nfc_util_alloc_mem(req_msg, sizeof(net_nfc_request_msg_t)); + if (req_msg == NULL) + return; + + req_msg->length = sizeof(net_nfc_request_msg_t); + req_msg->request_type = NET_NFC_MESSAGE_SERVICE_INIT; + + net_nfc_dispatcher_queue_push(req_msg); + + /* unset internal flag */ + powered_off_by_flightmode = FALSE; + + /* sbeam on */ + if ((result = vconf_set_bool(VCONFKEY_NFC_SBEAM, TRUE)) == 0) + { + DEBUG_SERVER_MSG("vconf_set_bool success \n"); + } + else + { + DEBUG_ERR_MSG("vconf_set_bool failed \n"); + } + + /* predefined item on */ + if ((result = vconf_set_bool(VCONFKEY_NFC_PREDEFINED_ITEM_STATE, TRUE)) == 0) + { + DEBUG_SERVER_MSG("vconf_set_bool success \n"); + } + else + { + DEBUG_ERR_MSG("vconf_set_bool failed \n"); + } + } + else + { + DEBUG_SERVER_MSG("Invalid Vconf value \n"); + } +} + + + +void net_nfc_service_vconf_register_notify_listener() +{ + vconf_notify_key_changed(VCONFKEY_TELEPHONY_FLIGHT_MODE, net_nfc_service_airplane_mode_cb, NULL); +} + +void net_nfc_service_vconf_unregister_notify_listener() +{ + vconf_ignore_key_changed(VCONFKEY_TELEPHONY_FLIGHT_MODE, net_nfc_service_airplane_mode_cb); +} diff --git a/src/manager/net_nfc_util_access_control.c b/src/manager/net_nfc_util_access_control.c new file mode 100644 index 0000000..6f9ad73 --- /dev/null +++ b/src/manager/net_nfc_util_access_control.c @@ -0,0 +1,287 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include +#include +#include +#include +#include +#include +#include + +#include "package-manager.h" +#include "SEService.h" +#include "Reader.h" +#include "Session.h" +#include "ClientChannel.h" +#include "GPSEACL.h" + +#include "net_nfc_debug_private.h" +#include "net_nfc_util_private.h" +#include "net_nfc_manager_util_private.h" +#include "net_nfc_util_openssl_private.h" + +static bool initialized = false; +static se_service_h se_service = NULL; +static pthread_mutex_t g_access_control_lock = PTHREAD_MUTEX_INITIALIZER; +static pthread_cond_t g_access_control_cond = PTHREAD_COND_INITIALIZER; + +#if 0 +static reader_h readers[10] = { NULL, }; +static session_h sessions[10] = { NULL, }; +static channel_h channels[10] = { NULL, }; +static gp_se_acl_h acls[10] = { NULL, }; +#endif + +static void _se_service_connected_cb(se_service_h handle, void *data) +{ + if (handle != NULL) + { + se_service = handle; + initialized = true; + } + else + { + DEBUG_ERR_MSG("invalid handle"); + } + pthread_cond_signal(&g_access_control_cond); +} + +bool net_nfc_util_access_control_is_initialized(void) +{ + return initialized; +} + +void net_nfc_util_access_control_initialize(void) +{ + struct timeval now; + struct timespec ts; + + if (net_nfc_util_access_control_is_initialized() == false) + { + pthread_mutex_lock(&g_access_control_lock); + if (se_service_create_instance((void *)1, _se_service_connected_cb) == NULL) + { + DEBUG_ERR_MSG("se_service_create_instance failed"); + pthread_mutex_unlock(&g_access_control_lock); + return; + } + gettimeofday(&now, NULL); + ts.tv_sec = now.tv_sec + 1; + ts.tv_nsec = now.tv_usec * 1000; + + pthread_cond_timedwait(&g_access_control_cond, &g_access_control_lock, &ts); + pthread_mutex_unlock(&g_access_control_lock); + } +} + +void net_nfc_util_access_control_update_list(void) +{ +#if 0 + int i; + + if (net_nfc_util_access_control_is_initialized() == true) + { + for (i = 0; i < (sizeof(acls) / sizeof(gp_se_acl_h)); i++) + { + if (acls[i] != NULL) + { + gp_se_acl_update_acl(acls[i]); + } + } + } +#endif +} + +static gp_se_acl_h _get_acl(reader_h reader) +{ + gp_se_acl_h result = NULL; + session_h session = NULL; + + session = reader_open_session_sync(reader); + if (session != NULL) + { + unsigned char aid[] = { 0xA0, 0x00, 0x00, 0x00, 0x63, 0x50, 0x4B, 0x43, 0x53, 0x2D, 0x31, 0x35 }; + channel_h channel = NULL; + + channel = session_open_basic_channel_sync(session, aid, sizeof(aid)); + if (channel != NULL) + { + result = gp_se_acl_create_instance(channel); + if (result != NULL) + { + gp_se_acl_update_acl(result, channel); + } + channel_close_sync(channel); + } + session_close_sync(session); + } + + return result; +} + +static bool _is_authorized_package(gp_se_acl_h acl, const char *value, uint8_t *aid, uint32_t aid_len) +{ + bool result = false; + uint32_t decoded_len; + uint8_t *decoded = NULL; + + if (value == NULL) + { + return result; + } + + decoded_len = strlen(value); + + if (decoded_len == 0) + { + return result; + } + + _net_nfc_util_alloc_mem(decoded, decoded_len); + if (decoded != NULL) + { + if (net_nfc_util_openssl_decode_base64(value, decoded, &decoded_len, false) == true) + { + uint8_t hash[128]; + uint32_t hash_len = sizeof(hash); + + if (net_nfc_util_openssl_digest("sha1", decoded, decoded_len, hash, &hash_len) == true) + { + DEBUG_MSG_PRINT_BUFFER(hash, hash_len); + result = gp_se_acl_is_authorized_access(acl, aid, aid_len, hash, hash_len); + } + } + + _net_nfc_util_free_mem(decoded); + } + else + { + DEBUG_ERR_MSG("alloc failed"); + } + + return result; +} + +static pkgmgr_certinfo_h _get_cert_info(const char *pkg_name) +{ + int ret = 0; + pkgmgr_certinfo_h handle = NULL; + + DEBUG_MSG("package name : %s", pkg_name); + + if ((ret = pkgmgr_pkginfo_create_certinfo(&handle)) == 0) + { + if ((ret = pkgmgr_pkginfo_load_certinfo(pkg_name, handle)) == 0) + { + } + else + { + DEBUG_ERR_MSG("pkgmgr_pkginfo_load_certinfo failed [%d]", ret); + pkgmgr_pkginfo_destroy_certinfo(handle); + handle = NULL; + } + } + else + { + DEBUG_ERR_MSG("pkgmgr_pkginfo_create_certinfo failed [%d]", ret); + } + + return handle; +} + +bool net_nfc_util_access_control_is_authorized_package(const char *pkg_name, uint8_t *aid, uint32_t length) +{ + bool result = false; + + DEBUG_SERVER_MSG("aid : { %02X %02X %02X %02X ... }", aid[0], aid[1], aid[2], aid[3]); + + net_nfc_util_access_control_initialize(); + { + pkgmgr_certinfo_h cert_info = NULL; + + cert_info = _get_cert_info(pkg_name); + if (cert_info != NULL) + { + int i; + reader_h readers[10] = { NULL, }; + int count = (sizeof(readers) / sizeof(reader_h)); + + se_service_get_readers(se_service, readers, &count); + + for (i = 0; i < count && result == false; i++) + { + gp_se_acl_h acl = NULL; + + acl = _get_acl(readers[i]); + if (acl != NULL) + { + int j; + const char *value = NULL; + + for (j = (int)PM_AUTHOR_ROOT_CERT; + j <= (int)PM_DISTRIBUTOR2_SIGNER_CERT && result == false; + j++) + { + pkgmgr_pkginfo_get_cert_value(cert_info, (pkgmgr_cert_type)j, &value); + result = _is_authorized_package(acl, value, aid, length); + } + gp_se_acl_destroy_instance(acl); + } + } + + pkgmgr_pkginfo_destroy_certinfo(cert_info); + } + else + { + /* hash not found */ + DEBUG_ERR_MSG("hash doesn't exist : %s", pkg_name); + } + } + + DEBUG_ERR_MSG("net_nfc_util_access_control_is_authorized_package end [%d]", result); + + return result; +} + +void net_nfc_util_access_control_release(void) +{ +#if 0 + int i; + + for (i = 0; i < (sizeof(acls) / sizeof(gp_se_acl_h)); i++) + { + if (acls[i] != NULL) + { + gp_se_acl_destroy_instance(acls[i]); + acls[i] = NULL; + } + } +#endif + if (se_service != NULL) + { + se_service_destroy_instance(se_service); + se_service = NULL; +#if 0 + memset(readers, 0, sizeof(readers)); + memset(sessions, 0, sizeof(sessions)); + memset(channels, 0, sizeof(channels)); +#endif + } + + initialized = false; +} diff --git a/src/manager/nfc-manager.service b/src/manager/nfc-manager.service new file mode 100644 index 0000000..a9696a8 --- /dev/null +++ b/src/manager/nfc-manager.service @@ -0,0 +1,3 @@ +[D-BUS Service] +Name=org.tizen.nfc_service +Exec=/usr/bin/nfc-manager-daemon diff --git a/src/manager/nfc-service.xml b/src/manager/nfc-service.xml new file mode 100644 index 0000000..902f5c2 --- /dev/null +++ b/src/manager/nfc-service.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + diff --git a/src/manager/sounds/Operation_sdk.wav b/src/manager/sounds/Operation_sdk.wav new file mode 100644 index 0000000000000000000000000000000000000000..5383bdf6605da34f2e0b4886b2a7abf900e03edd GIT binary patch literal 27644 zcmeHvca&7c_HLcnadH9%1<65j6i_5e6eJ5MK`;P{S3!`V2!bS0P(c9&xe_D@BS{1$ zm;eRIS#X9lId(d+eqYV;yq@7+eQ&+B-e0eKuRgJMsBhPquIkxe_v_xZt8Y9ZgF6iB z^6ZO~s>TvRI7sKMgv=kp5uU`7F{37pT8lQ3R|J6w0uclv2t*KwAP_+yfbS|22&X3^N@cI0s!n?xHLarc)Rm5T92C+bVKx!h@l_cq~I8|&W<_YVC zp@K))&yVAi_ygQ1PUbejY61O_wxn0hx6E4R31hNR)%abXr8m>Fw0~=(w3=GBx=Wp- z4p1AYE;UCvuN+bKC~3+LGuC`e*Yaj|$*BvLbJq_kN2S~?}= zN<@y4Q{}3VR5@1W@-rR0HWyBai=u`E^dakxbds%C(N!kTVuIsdcpx=+R}ZvOZehrmK24;}av#=wz-oeP%DZiE?Bh*+!h) z2yPD-g-q<=iO@?}E?g7t6Nif*izh@XHjoBO)1^bvTD>IxixqyDaDs=QW5dqSJ7?bdR% zTKX{k6a6f5G|Jdu6c|m+*UcZzXgZj#p?7Fa@;uo>3P^MA6>cY2$Ti|8@c-to@yWvD z!W%-GkRim29mVnDa&fLfiTb(J2LYD)=HP`oH^6{jOdapDExeW8aS zW8}TU*Wk}^Z*k4IEV735#fblz&cx`;H`kkE%m>Wd#+SxRMl(axPwK1niFzmfe%;V6 zYWuX++5+u0ZLBs->jUYbb=10PgSCm;d~K_CPK(lq=sWc!jNTe%Dy@viXDip8KghQc zI*F^L&t%?_Eic9x8Ykr=>hVGm*Piq@r|L7+)xk%7Ba2cB+T?A@shgdUbtAKS*4nHE z+52)j=G7?ZP_(inIdC+zMq6mU$9*Jz?0Cc7JBq}<7XN+XvE=tEaFvo%ucSU&xp!rM zYRA+zmCjbElX8F35ApS4yGM0)yB(W^_T*RnS;ZSTU;KN4KX+7id}if4GjBD$**)X? z^fl=>(-&r}ylLDzaOcO&N;$jprWH;uSrqtQ5sVJxO<}FP&NbB=8#6I(TEas~o01Qw z%&U-5A+y4=3V)_tPJSinNW#&$r7^Xl-gf`sNEbs~46Um_sjLckeA|oOElA5t$UT;Q zE~{0Rni-Y#W>)v?2|2fOzsTQIm{~m9A04`=?l(4*b;5Fas;i?nBYJS$M+xsIbxqk; z;Yh`qm2OnJQ)xk^3l)!57?ZLsX=}o`xVzDfy?tH1rc;s z=q0i9Ep0p=R^Wgpd zpNrQO?#qwM+nMu4_T8+RS>v*{XZ6T#l`}b)+y~;bj_U5i z-c~U);@(Nyb?F-3E8Qy#3bgowpypbN}6enSW$$&-o!Qv2bN^4}WS%(o`dl zToLxlueqYUlcU$ieiYw6aaGcW>EnHhnk>gj;#>N?SacE3nv~NjqUg6w=VfnA*oy>hT_vzfFx!%0r@=oM?3+EO!Es62R z2U{qwX!{K(8O*N{&&qkuZ1+L$*ysx}v2oGy$KyLDyq@qvLPElf`1Nt`#de4}7!~bp z=5FCkmGgwX+*`D_QA3MUl7sF1i%R6;uM3wK?9PwN-8E4qf6!ohzZ)My3{2?hB0!9Q6$?sZ<tbd|3qvpA9B=l{mZ?~v%uRgDktiR=(iz{N8gF+9rd>Nea|F! zbJsb?F!`j|SeVcKNgpy-=#n;1sT#TzNb~RTT`p-@va|TP;-1ALi@zvNDcM&t*Y~=A zS>V@T6=kvN)|VSK=nm4BKPWVlmdTeLyvyy*b#L&r@_y<)@4e>T>wUqSKWof=Yu~7F9zjM-_YJrE9ImzO>LzK`c-|u zvDTbNpC{e88hi=A3;hzL_as3cDQ}X`%D3g~^7rywxutws8Y2BJwh-SFuJg6|7r4!s zl{Kd`&C^ChV}%~0FV`Ar*VI+&M0JQdP<>8atp2FRXyfq7*F*nJe-bm2x6Nwwdpdw* zlQ%dgzmVsI@xm`cqS#NIC4Poa;!WaGae~-VEE3iV9WY;dp3lP!GKV}z?qH^rX}*j} z@d~4zk*TlKU(&nk_4F!wH68ub=jh+*ywL}<1i^gHJZZM3>uD^ROsQ4EAx1Fy4E|ewKK}$C%OB-ta1FT2WDa?dT%n6;dm1oznN!VbJ%M@FSjY%&Aom#8 zl&i#XTn0Hz){>cIC}~ZSNswNphv-(iiY}tF=<9S6eU-jOr_;AF|6D~k(%tkZy$s8K z%9AL}6RVIKqzX&-C{(-HIqL_LRoK>v*>eubZ6Dk0K(q#fx+hGAwl2{z}F1!NIfjO|=9 zi%cOe!p9)eowOwl(5G0esr*=zT&HKy-y`$@{RXyn(_MJ)#n}<`@C3bp`*&y|)+-bq z+~|J-Ng@?UMMw&;Ou!X4Rv;9sq5#%5IcS|hZvf%T^b%0IM6b|m^iO&lYoVf2D-L*0 z!D^)rX$Vx>kcUZo(t&h>bRdr)wpOGGsZVMGhZL-QM51Fol?96z>F=d+epedjF8VcO z7b5+Z9;813gER1SljhMNR#h$%k6hIN9!-()cBS?^1KrN>@+i(*<9dDEzYl%!!iRy_ z3*hA@dV3jtK1)y0ljuE@lQ=$$YgchEgWkm&t_ZC)c#+^I8lIAXMJjAnL9Z;Sg0srF zYT@I-3QxppjY3O-Zg_o|g;n7l*kr52Y*@~R?P82OwmLN7frFj{UOX6w*2*v*{%ncG zwJ5~zMhhpR5lVfql`C7{hJb`0YfT?4mX#7*@#7v_uPSJ1t$sOZV{wJqwzVE*Yf@&F zz1gZ$g0MbtSaY(Kb$H#YB2FIHv8XAvA)*}<)}FmBVfWY?-m<_Jt{6~dR@&A&ovp^h z!hEnbyvdrDzW!S9mRhmb|K-0Ku+LaLc8jo2Tfgj{t^KX_zjb8$vi6pLduzpGM-`5Y z*<)Uq_p&I2`_E7)ivY9E^vixf!M;~u-%HrvR#@LnFmG0TwtWj-8ChY%vSW+o&%)Zy zl;y+z#zR5Q!(#bj-+sg9Bb{Kh{XFdc%C!68`nWeEf0vJNM#^TL zMO#*^vB+B3I9X%L9{0>!d9m&@gu*XN|3A0k7XSUo@@e_DBPid}j>g`zSXgZLzRGKb zBe9>gvi&UU$+A+kN$F{A%-?he!asP0Rno9Q-ezeP3T zMS2UhYhF|aHbvE72hs!b1bG}sjp5IUdf4lz)H{oI*U>H-wU&2CC9W0Mp6d!WNitV~ zyGDkP12l?uHP;#G`iojMb%D}KsjswAHYm;1QEDyivVPdyNe=M8i>O(5o_4A3y`EI> zeco?8y8E_kzVntWNg98J95mPJ>(tYshQX`;bG|0N{E}$j`@WI>_XE+PbINa8y5S;m ze1hnZ4>;PP@_K;hnuqtE^tAHybtkwMI!;O#h2OcK=?3FNElp8^GXs77Q+&Lyprobm zrZ3a~NH9HgNIk0GFhe8>wcW9N>^bde;H~5R(W9Zp`6cHe`IdN&-$z!Ov-BzI zXCZfRxBq}I)pw)B>09KR>farB7)5>|Ey1ip+VhW#_2k=*A+9&v{XD;UGCiMpOt;|P z>wM7hj5J<&h8sj5Hri=pltaO>fj<6~zAnBVzFod4{-psWxL%p5%`#Td72LH%70N2uNk^lQTTF;`Nssd1{*1P z>Sg_ed6<01uNMc(*BuR9HQi_3^*l8^N8L&8WY=j&cX^q(mp?(WO@bQ!8HzJ>B9P(l z<#+q*`#<%M3QP_j3yoAO>57p}4{%F_{?cu^y>p1Go_n+Vw0ncQq5DZ!3un4KKw2&w z;QpYz*-)RR7KPRZKL}j#Pw@Bmf8?(d@CF|aZBROEu|}4;k9@!n7ZvGc$9m^d*F)}i z+;iNG+;6*#3XFgNf^pkJ_3sIf9jEz}koP3Up*Jg*32rA_iq$8^Ng*44;$*4Yw0YAff8 zvxO3FFgaMxH{M~)J}Ou{a$Nn95siKvs`~+kC-PJ@(IT< z=Vs?V=L~1a(HyZPNc)5V{AtpKUNt7_l{H-UQa_cKq@ zrrc+INT?&VmZKe;93E!_r_1?;!|7-$*OF8rjem?wr%TLcMwa%AdP?yqvqH^7HABNf zr$cYT$_v^WAk&Tho7~{43w^}?QbYNa+`%!)F~QNuu>+i~dQw%<;D6-aB)zE1Jf$De zj;lnSpm>!$l(}|MepP0xL$wk5o5nWtE=}ax^Mi!P#RsJ;(hzxrykA}+ca{%HF;ZKx zthoF~y|(d?*^zc3L%FB9q8+Q~*BP3}H3DmiwG+qnpj0#;>}f4bV=iuc^HuGu3PANX@BV(GM7D=2p6# zyvNPt9~WHWItGGhQ(JQ~U+wc>WZ>K&TBnCE#_|k~GxxHy2k5clb(tE3QA8Mn3}2F<0-R@78*1 zUd^X^u-~FJ1`FYH;}!F1+731JH@GeQli-LB6}O9*#51rlRLlk|bTglgzoG5OYxGO= zG8mxm=&||^ZKgI}dtE!AJ)p1ATN;_h7V~x5k@(3j?m6Dz-w>_}_ls@BCSt7kqwtjQ z2j7AJgv&(b_cVIZY+!=yEfe~PU6F3gcga$?vqnk0!_|Aw2Tj9Fd8=o4T z$SQDQpXI*gIKCx6oPUuY&p*jG<01uNh#eF)6jo1`AJKI0B?XSiFC-?%hxA=ihC=YA$r@hMh9*V2B}Nl%&| zf(h}s+1~76_A$qrOU%QjVm?A=;FHWn`jC&v4U&w{r5Cw5+=tvJ+ybyD`*F3n0wxCDJ+=K)wMrsv`H8@i5uMpuI8@ILqltLP`-K&%H7V-KqH z&!W;lKxKRy*DYl{JdPZVgp39+`6=)ldcsd5eCm6NhFQcFe9C`EcL3YZVevC;zeG*{ z0eT!Wi(FLmMxkW`Fao-f{@^VPCnK=!2OAw=y9VYMJnt3K z1#FBtkZG8cjKa0Hu;9d~y9oUaK=K_hT&E%*)971ZlY9;a#tF=I2&n{L%)-mipARO- zA}~2#M^2t39f4yaQPAondcF=e=F-{p4P<&gEUWI4==2XHo8 zA%a@yV?1n7c*;dA*U+QWkl*n>htYBcv%_1+bRlMaI@mNaaEpZo<4aUQWDg*Z)v&FO zOsAr^$(VC`G5;h$m$6AKM#d#Xa^^2NUpnW^Kz55tEqYv|C>=qTcOl1YKKT_8K7<}#LUculi)FeAde;?C<{&Z{44NUBS@tL$Db-=c z;{2S&=-&^tHv^+hKxsSXr$=Dl_!Hv8$1xN;3W^&yTJ@J8xlcKZ;lbOux9QN+{&e=V!Swil=bG1E>*)Tc4R zkC)0xjNfae3>_8v(csM72TbcirxEp<1#wx&rzW_E*<~GKDdg&VAI`+3fW@yxO{ zfE#fnB9e-*lv*l`E0hG3J-Ewbv@mvxAEP3-R2cIm4{!F{2#lGcV$3lVrp zcxbaKL4-Fadd^laj6K8jy|CbhWs8r) ztSHc7EE&d&DS?d=NT8I%z?d;?O~e=kjH|%3SWGMeixTm@r>nRu{7A0^_gMHa>&Gv+lq+w**dZ! z3)jDgE28b**paYv%cG@ZvqP8{#?=r@^T!xS3@;hcu-;hQ9;@b==`kx-t}MO=!=Ckq zU1N9cI&2F+>zu_eA(u>IFfO7>M+f6mS-E8yV|q3_fVF48y1`b<8b%D`X|Z4VVB^l> zY$>>7d9X9YMj-16TT8Q1$oN`p%bo)^4lO*b3^Gs52gBJKDPg`)DbQs$R$W z7rSbWh_d&?#}-i`Hru;ta#r9bKK0Etw zp31kf^USQ-$Ke)s&zU9bW!tpc*cxT`<)dL*VeP++;L5%F)(Ex7DYF-T*;@a7ACBAN zda)5vR>HO{eS4(Yd+Vwlk8SN<3sw)UR`HME>El>aV`j#g<4(lvD z4$8(Jjw$T3{86|?S-pFYZI9)3%b$fU{pV<~M@ZQ=b{_uTiq)FMVp%M&UG~fx+hwmr zjw1*}5QrcUK_G%a1c3+w5dsZ0{?pidUfwVpbnaKf4pm-?j8CK gaN)TBs25+I{L*u!S3C4By)yZkXU4wzD!$D4AG+@=P5=M^ literal 0 HcmV?d00001 diff --git a/test_clinet_app/bt_paring/Makefile b/test_clinet_app/bt_paring/Makefile new file mode 100755 index 0000000..b29816b --- /dev/null +++ b/test_clinet_app/bt_paring/Makefile @@ -0,0 +1,46 @@ +LOCAL_PATH=. + +#phLibNfc + +export PKG_CONFIG_PATH=/usr/lib/pkgconfig/ + +#sources + +SRCS = $(LOCAL_PATH)/bt_paring.c + +#includes + +USER_HEADER =`pkg-config --cflags nfc bluetooth-api` + +LOCAL_CFLAGS = $(USER_HEADER) + +CC = arm-linux-gnueabi-gcc + +TARGET = bt_paring + + +CFLAGS = $(LOCAL_CFLAGS) -g +LDFLAGS = -lpthread `pkg-config --libs nfc bluetooth-api` + + +SRC = $(SRCS) +OBJS = $(SRC:.c=.o) +RM = rm + + +.SUFFIXES: .c .o + +.c.o: + $(CC) -c $(CFLAGS) -o $*.o $< + +all: $(TARGET) + +$(TARGET): $(OBJS) + $(CC) -o $@ $(OBJS) $(LDFLAGS) -g + +run: all + $(TARGET) + +clean: + $(RM) -f $(OBJS) $(TARGET) + diff --git a/test_clinet_app/bt_paring/bt_paring.c b/test_clinet_app/bt_paring/bt_paring.c new file mode 100755 index 0000000..5a89803 --- /dev/null +++ b/test_clinet_app/bt_paring/bt_paring.c @@ -0,0 +1,215 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include +#include + +#include +#include + +#include + +#include + +void bt_event_callback(int event, bluetooth_event_param_t* param, void *user_data); +void bt_test_bond_device(bluetooth_device_address_t* bt_address); +GMainLoop* main_loop = NULL; + +void initialize() +{ + if(!g_thread_supported()) + { + g_thread_init(NULL); + } + + dbus_g_thread_init(); + g_type_init(); +} + + +int main() +{ + initialize(); + + //bluetooth_enable_adapter(); + + //main_loop = g_main_loop_new(NULL, FALSE); + //g_main_loop_run(main_loop); + +#if 1 + + ndef_message_h ndef_message = NULL; + net_nfc_conn_handover_info_h conn_handover_info = NULL; + + + if(net_nfc_retrieve_current_ndef_message(&ndef_message) == NET_NFC_OK) + { + printf("retrieve ndef message from nfc storage \n"); + + int count = 0; + + net_nfc_get_ndef_message_record_count(ndef_message, &count); + + int i = 0; + while(i < count){ + + ndef_record_h record = NULL; + net_nfc_get_record_by_index(ndef_message, i++, &record); + + if(record != NULL){ + + net_nfc_record_tnf_e TNF = NET_NFC_RECORD_EMPTY; + data_h record_type = NULL; + + if((net_nfc_get_record_tnf(record, &TNF) == NET_NFC_OK) && (net_nfc_get_record_type(record, &record_type) == NET_NFC_OK ) ){ + + uint8_t* buffer = net_nfc_get_data_buffer(record_type); + int buffer_length = net_nfc_get_data_length(record_type); + + // record is WTK and Hs + if((TNF == NET_NFC_RECORD_WELL_KNOWN_TYPE) && (buffer != NULL) && (buffer_length > 1) && (buffer[0] == 'H') && (buffer[1] == 's')){ + printf("record is found \n"); + net_nfc_parse_connection_handover_ndef_message(ndef_message, &conn_handover_info); + + if(conn_handover_info != NULL){ + uint8_t carrier_count = 0; + net_nfc_get_connection_handover_alternative_carrier_count(conn_handover_info, &carrier_count); + + int j = 0; + while(j < carrier_count){ + + net_nfc_conn_handover_carrier_info_h carrier_info = NULL; + net_nfc_get_connection_handover_carrier_handle_by_index(conn_handover_info, j++, &carrier_info); + + if(carrier_info != NULL){ + data_h configuration = NULL; + net_nfc_get_carrier_configuration(carrier_info, &configuration); + + if(configuration != NULL) + { + uint8_t* buffer = net_nfc_get_data_buffer(configuration); + if(buffer != NULL) + { + printf("bt addr [%X][%X][%X][%X][%X][%X] \n", buffer[2], buffer[3], buffer[4], buffer[5], buffer[6], buffer[7]); + bluetooth_device_address_t bt_address = {{buffer[2], buffer[3], buffer[4], buffer[5], buffer[6], buffer[7]}}; + bt_test_bond_device(&bt_address); + } + else + printf("buffer is NULL"); + } + } + + } + } + } + } + } + } + + } + +#endif + return 0; +} + +void bt_test_bond_device(bluetooth_device_address_t* bt_address) +{ + int ret_val; + + ret_val = bluetooth_register_callback(bt_event_callback, NULL); + + if (ret_val >= BLUETOOTH_ERROR_NONE) + { + printf("bluetooth_register_callback returned Success"); + } + else + { + printf("bluetooth_register_callback returned failiure [0x%04x]", ret_val); + return ; + } + + ret_val = bluetooth_check_adapter(); + + if (ret_val < BLUETOOTH_ERROR_NONE) + { + printf("bluetooth_check_adapter returned failiure [0x%04x]", ret_val); + } + else + { + printf("BT state [0x%04x]", ret_val); + } + + int error = 0; + + if((error = bluetooth_bond_device(bt_address)) < 0) + { + printf("Api failed: %d", error); + } + else + { + main_loop = g_main_loop_new(NULL, FALSE); + g_main_loop_run(main_loop); + } + +} + +void bt_event_callback(int event, bluetooth_event_param_t* param, void *user_data) +{ + switch(event) + { + case BLUETOOTH_EVENT_ENABLED: + printf("BLUETOOTH_EVENT_ENABLED:\n"); + break; + case BLUETOOTH_EVENT_DISABLED: + printf("BLUETOOTH_EVENT_DISABLED:\n"); + break; + case BLUETOOTH_EVENT_LOCAL_NAME_CHANGED: + printf("BLUETOOTH_EVENT_LOCAL_NAME_CHANGED:\n"); + break; + case BLUETOOTH_EVENT_DISCOVERY_STARTED: + printf("BLUETOOTH_EVENT_DISCOVERY_STARTED:\n"); + break; + case BLUETOOTH_EVENT_REMOTE_DEVICE_FOUND: + printf("BLUETOOTH_EVENT_REMOTE_DEVICE_FOUND:\n"); + break; + case BLUETOOTH_EVENT_REMOTE_DEVICE_NAME_UPDATED: + printf("BLUETOOTH_EVENT_REMOTE_DEVICE_NAME_UPDATED:\n"); + break; + case BLUETOOTH_EVENT_DISCOVERY_FINISHED: + printf("BLUETOOTH_EVENT_DISCOVERY_FINISHED:\n"); + break; + case BLUETOOTH_EVENT_BONDING_FINISHED: + printf("BLUETOOTH_EVENT_BONDING_FINISHED:\n"); + + if (param->result >= BLUETOOTH_ERROR_NONE) + { + bluetooth_device_info_t *device_info = NULL; + device_info = (bluetooth_device_info_t *)param->param_data; + printf("dev [%s] [%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X] mjr[%#x] min[%#x] srv[%#x] \n", device_info->device_name.name, \ + device_info->device_address.addr[0], device_info->device_address.addr[1], device_info->device_address.addr[2], \ + device_info->device_address.addr[3], device_info->device_address.addr[4], device_info->device_address.addr[5], \ + device_info->device_class.major_class, device_info->device_class.minor_class, device_info->device_class.service_class); + } + + g_main_loop_quit (main_loop); + + break; + default: + printf("BLUETOOTH_EVENT = [%d]:\n", event); + break; + } +} diff --git a/test_clinet_app/ndef-tool/CMakeLists.txt b/test_clinet_app/ndef-tool/CMakeLists.txt new file mode 100644 index 0000000..7396407 --- /dev/null +++ b/test_clinet_app/ndef-tool/CMakeLists.txt @@ -0,0 +1,51 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +PROJECT(ndef-tool C) + +SET(NDEF_TOOL "ndef-tool") + +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../src/commonlib/include) +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../src/clientlib/include) +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include) + +AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/ TOOL_SRC) + +IF("${CMAKE_BUILD_TYPE}" STREQUAL "") + SET(CMAKE_BUILD_TYPE "Release") +ENDIF("${CMAKE_BUILD_TYPE}" STREQUAL "") + +INCLUDE(FindPkgConfig) +pkg_check_modules(tool_pkgs REQUIRED glib-2.0 gobject-2.0) + +FOREACH(flag ${tool_pkgs_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) + +# this for NFC flag + +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -pipe -fomit-frame-pointer -Wall -Wno-trigraphs -Werror-implicit-function-declaration -fno-strict-aliasing -Wl,-zdefs -fvisibility=hidden") + +SET(ARM_CFLAGS "${ARM_CLAGS} -mapcs -mno-sched-prolog -mabi=aapcs-linux -Uarm -fno-common -fpic") + +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}") +SET(CMAKE_C_FLAGS_DEBUG "-O0 -g") + +FIND_PROGRAM(UNAME NAMES uname) +EXEC_PROGRAM("${UNAME}" ARGS "-m" OUTPUT_VARIABLE "ARCH") +IF("${ARCH}" MATCHES "^arm.*") + ADD_DEFINITIONS("-DTARGET") + MESSAGE("add -DTARGET") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${ARM_CFLAGS}") +ENDIF() + +ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"") + +SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed") + +ADD_EXECUTABLE(${NDEF_TOOL} ${TOOL_SRC}) + +TARGET_LINK_LIBRARIES(${NDEF_TOOL} ${tool_pkgs_LDFLAGS} "-lpthread -lrt -pie -ldl" "-L${CMAKE_CURRENT_SOURCE_DIR}/../../cmake_tmp/src/clientlib -L${CMAKE_CURRENT_SOURCE_DIR}/../../cmake_tmp/src/commonlib" "-lnfc" "-lnfc-common-lib") + + +INSTALL(TARGETS ${NDEF_TOOL} DESTINATION bin) + + diff --git a/test_clinet_app/ndef-tool/ndef-tool-display.c b/test_clinet_app/ndef-tool/ndef-tool-display.c new file mode 100755 index 0000000..5cdeb47 --- /dev/null +++ b/test_clinet_app/ndef-tool/ndef-tool-display.c @@ -0,0 +1,686 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include +#include +#include +#include +#include +#include + +#include "net_nfc.h" +#include "net_nfc_sign_record.h" +#include "ndef-tool.h" + +typedef struct _net_nfc_sub_field_s +{ + uint16_t length; + uint8_t value[0]; +} +__attribute__((packed)) net_nfc_sub_field_s; + +typedef struct _net_nfc_signature_record_s +{ + uint8_t version; + uint8_t sign_type : 7; + uint8_t uri_present : 1; + net_nfc_sub_field_s signature; +} +__attribute__((packed)) net_nfc_signature_record_s; + +typedef struct _net_nfc_certificate_chain_s +{ + uint8_t num_of_certs : 4; + uint8_t cert_format : 3; + uint8_t uri_present : 1; + uint8_t cert_store[0]; +} +__attribute__((packed)) net_nfc_certificate_chain_s; + +static void _display_buffer(char *title, uint8_t *buffer, uint32_t length) +{ + int32_t i; + + if (length > 0) + { + fprintf(stdout, " %s[%d] = {", title, length); + + for (i = 0; i < length; i++) + { + if ((i % 16) == 0) + fprintf(stdout, "\n"); + + if ((i % 8) == 0) + fprintf(stdout, " "); + + fprintf(stdout, "%02X ", buffer[i]); + } + + fprintf(stdout, "\n };\n"); + } + else + { + fprintf(stdout, " %s[%d] = Empty", title, length); + } +} + +static void _display_id(ndef_record_h record) +{ + data_h data = NULL; + + net_nfc_get_record_id(record, &data); + if (net_nfc_get_data_length(data) > 0) + { + char temp_buffer[1024] = { 0, }; + + memcpy(temp_buffer, (void *)net_nfc_get_data_buffer(data), net_nfc_get_data_length(data)); + fprintf(stdout, " ID string : %s\n", temp_buffer); + } +} + +static void _display_signature(ndef_record_h record) +{ + data_h data = NULL; + + _display_id(record); + + net_nfc_get_record_payload(record, &data); + if (net_nfc_get_data_length(data) > 0) + { + int32_t i; + char temp_buffer[1024]; + net_nfc_signature_record_s *sign = (net_nfc_signature_record_s *)net_nfc_get_data_buffer(data); + + fprintf(stdout, " Version : %d\n", sign->version); + fprintf(stdout, " Signature URI present : %s\n", sign->uri_present ? "present" : "not present"); + + switch (sign->sign_type) + { + case NET_NFC_SIGN_TYPE_NO_SIGN : + fprintf(stdout, " Signing method : Not signed (%d)\n", sign->sign_type); + break; + + case NET_NFC_SIGN_TYPE_PKCS_1 : + fprintf(stdout, " Signing method : RSASSA-PSS with SHA1 (%d)\n", sign->sign_type); + break; + + case NET_NFC_SIGN_TYPE_PKCS_1_V_1_5 : + fprintf(stdout, " Signing method : PKCS #1 v1.5 with SHA1 (%d)\n", sign->sign_type); + break; + + case NET_NFC_SIGN_TYPE_DSA : + fprintf(stdout, " Signing method : DSA (%d)\n", sign->sign_type); + break; + + case NET_NFC_SIGN_TYPE_ECDSA : + fprintf(stdout, " Signing method : ECDSA (%d)\n", sign->sign_type); + break; + + default : + fprintf(stdout, " Signing method : Unknown (%d)\n", sign->sign_type); + break; + } + + if (sign->uri_present) + { + memset(temp_buffer, 0, sizeof(temp_buffer)); + memcpy(temp_buffer, sign->signature.value, sign->signature.length); + fprintf(stdout, " URI : %s\n", temp_buffer); + } + else + { + _display_buffer("Signature", sign->signature.value, sign->signature.length); + } + + net_nfc_certificate_chain_s *chain = (net_nfc_certificate_chain_s *)(sign->signature.value + sign->signature.length); + fprintf(stdout, " Cert. URI : %s\n", chain->uri_present ? "present" : "not present"); + + switch (chain->cert_format) + { + case NET_NFC_CERT_FORMAT_X_509 : + fprintf(stdout, " Cert. format : X.509 (%d)\n", chain->cert_format); + break; + + case NET_NFC_CERT_FORMAT_X9_86 : + fprintf(stdout, " Cert. format : X9.86 (%d)\n", chain->cert_format); + break; + + default : + fprintf(stdout, " Cert. format : Unknown (%d)\n", chain->cert_format); + break; + } + + fprintf(stdout, " Cert. count : %d\n", chain->num_of_certs); + + net_nfc_sub_field_s *field = NULL; + + for (i = 0, field = (net_nfc_sub_field_s *)chain->cert_store; i < chain->num_of_certs; i++, field = (net_nfc_sub_field_s *)(field->value + field->length)) + { + memset(temp_buffer, 0, sizeof(temp_buffer)); + snprintf(temp_buffer, sizeof(temp_buffer), "Certificate %d", i); + _display_buffer(temp_buffer, field->value, field->length); + } + + if (chain->uri_present) + { + memset(temp_buffer, 0, sizeof(temp_buffer)); + memcpy(temp_buffer, field->value, field->length); + fprintf(stdout, " URI : %s\n", temp_buffer); + } + } +} + +static void _display_smart_poster(ndef_record_h record) +{ + data_h data = NULL; + + _display_id(record); + + net_nfc_get_record_payload(record, &data); + if (net_nfc_get_data_length(data) > 0) + { + char temp_buffer[1024] = { 0, }; + + memcpy(temp_buffer, (void *)net_nfc_get_data_buffer(data), net_nfc_get_data_length(data)); + fprintf(stdout, " Type string : %s (Signature)\n", temp_buffer); + } +} + +static void _display_text(ndef_record_h record) +{ + data_h data = NULL; + net_nfc_encode_type_e encoding = 0; + + _display_id(record); + + net_nfc_get_encoding_type_from_text_record(record, &encoding); + switch (encoding) + { + case NET_NFC_ENCODE_UTF_8 : + fprintf(stdout, " Encoding : UTF-8\n"); + break; + + case NET_NFC_ENCODE_UTF_16 : + fprintf(stdout, " Encoding : UTF-16\n"); + break; + } + + net_nfc_get_record_payload(record, &data); + if (net_nfc_get_data_length(data) > 0) + { + uint8_t *buffer = net_nfc_get_data_buffer(data); + uint32_t length = net_nfc_get_data_length(data); + char temp_buffer[1024] = { 0, }; + int code_length = buffer[0] & 0x3F; + + memcpy(temp_buffer, buffer + 1, code_length); + fprintf(stdout, " Language code[%d] : %s\n", code_length, temp_buffer); + + memset(temp_buffer, 0, sizeof(temp_buffer)); + + memcpy(temp_buffer, buffer + code_length + 1, length - code_length - 1); + fprintf(stdout, " Text[%d] : %s\n", length - code_length - 1, temp_buffer); + } +} + +static void _display_uri(ndef_record_h record) +{ + data_h data = NULL; + + _display_id(record); + + net_nfc_get_record_payload(record, &data); + if (net_nfc_get_data_length(data) > 0) + { + uint8_t *buffer = net_nfc_get_data_buffer(data); + uint32_t length = net_nfc_get_data_length(data); + char temp_buffer[1024] = { 0, }; + char *uri = NULL; + + fprintf(stdout, " URI scheme : 0x%02X\n", buffer[0]); + + memcpy(temp_buffer, buffer + 1, length - 1); + fprintf(stdout, " Raw URI payload[%d] : %s\n", length - 1, temp_buffer); + + net_nfc_create_uri_string_from_uri_record(record, &uri); + if (uri != NULL) + { + fprintf(stdout, " Resolved URI[%d] : %s\n", strlen(uri), uri); + free(uri); + } + } +} + +static void _display_well_known(ndef_record_h record) +{ + data_h data = NULL; + + net_nfc_get_record_type(record, &data); + if (net_nfc_get_data_length(data) > 0) + { + uint8_t *buffer = net_nfc_get_data_buffer(data); + uint32_t length = net_nfc_get_data_length(data); + char temp_buffer[1024] = { 0, }; + + memcpy(temp_buffer, buffer, length); + + if (strncmp(temp_buffer, "Sig", 3) == 0) + { + fprintf(stdout, " Type string[%d] : %s (Signature)\n", length, temp_buffer); + _display_signature(record); + } + else if (strncmp(temp_buffer, "Sp", 2) == 0) + { + fprintf(stdout, " Type string[%d] : %s (Smart poster)\n", length, temp_buffer); + _display_smart_poster(record); + } + else if (strncmp(temp_buffer, "Gc", 2) == 0) + { + fprintf(stdout, " Type string[%d] : %s (General control)\n", length, temp_buffer); + } + else if (strncmp(temp_buffer, "U", 1) == 0) + { + fprintf(stdout, " Type string[%d] : %s (URI)\n", length, temp_buffer); + _display_uri(record); + } + else if (strncmp(temp_buffer, "T", 1) == 0) + { + fprintf(stdout, " Type string[%d] : %s (Text)\n", length, temp_buffer); + _display_text(record); + } + else + { + fprintf(stdout, " Type string[%d] : %s (Unknown)\n", length, temp_buffer); + } + } +} + +static void _display_general_record(ndef_record_h record) +{ + data_h data = NULL; + + net_nfc_get_record_type(record, &data); + if (net_nfc_get_data_length(data) > 0) + { + uint8_t *buffer = net_nfc_get_data_buffer(data); + uint32_t length = net_nfc_get_data_length(data); + char temp_buffer[1024] = { 0, }; + + memcpy(temp_buffer, buffer, length); + + fprintf(stdout, " Type string[%d] : %s\n", length, temp_buffer); + } + + _display_id(record); + + net_nfc_get_record_payload(record, &data); + if (net_nfc_get_data_length(data) > 0) + { + uint32_t length = net_nfc_get_data_length(data); + uint8_t temp_buffer[512] = { 0, }; + + if (length > sizeof(temp_buffer)) + { + memcpy(temp_buffer, net_nfc_get_data_buffer(data), sizeof(temp_buffer)); + + fprintf(stdout, " Real payload length : %d\n", length); + _display_buffer("Abb. payload", temp_buffer, sizeof(temp_buffer)); + } + else + { + _display_buffer("Payload", net_nfc_get_data_buffer(data), length); + } + } +} + +static void _display_absolute_uri(ndef_record_h record) +{ + data_h data = NULL; + + _display_id(record); + + net_nfc_get_record_type(record, &data); + if (net_nfc_get_data_length(data) > 0) + { + uint8_t *buffer = net_nfc_get_data_buffer(data); + uint32_t length = net_nfc_get_data_length(data); + char temp_buffer[2048] = { 0, }; + + memcpy(temp_buffer, buffer, length); + + fprintf(stdout, " URI[%d] : %s\n", length, temp_buffer); + } +#if 0 + nfc_ndef_record_get_payload(record, &buffer, &length); + if (length > 0) + { + char temp_buffer[512] = { 0, }; + + if (length > sizeof(temp_buffer)) + { + memcpy(temp_buffer, buffer, sizeof(temp_buffer)); + + fprintf(stdout, " Real payload length : %d\n", length); + _display_buffer("Abb. payload", temp_buffer, sizeof(temp_buffer)); + } + else + { + _display_buffer("Payload", temp_buffer, length); + } + } +#endif +} + +static void _display_tnf(ndef_record_h record) +{ + net_nfc_record_tnf_e tnf = NET_NFC_RECORD_UNKNOWN; + + net_nfc_get_record_tnf(record, &tnf); + + switch (tnf) + { + case NET_NFC_RECORD_EMPTY : + fprintf(stdout, " TNF : Empty (%d)\n", tnf); + break; + + case NET_NFC_RECORD_WELL_KNOWN_TYPE : + fprintf(stdout, " TNF : Well-known (%d)\n", tnf); + _display_well_known(record); + break; + + case NET_NFC_RECORD_MIME_TYPE : + fprintf(stdout, " TNF : MIME (%d)\n", tnf); + _display_general_record(record); + break; + + case NET_NFC_RECORD_URI : + fprintf(stdout, " TNF : Absolute URI (%d)\n", tnf); + _display_absolute_uri(record); + break; + + case NET_NFC_RECORD_EXTERNAL_RTD : + fprintf(stdout, " TNF : External (%d)\n", tnf); + _display_general_record(record); + break; + + case NET_NFC_RECORD_UNKNOWN : + fprintf(stdout, " TNF : Unknown (%d)\n", tnf); + _display_general_record(record); + break; + + case NET_NFC_RECORD_UNCHAGNED : + fprintf(stdout, " TNF : Unchanged (%d)\n", tnf); + _display_general_record(record); + break; + + default : + fprintf(stdout, " Invalid TNF\n"); + break; + } +} + +static void _display_record_length(ndef_record_h record) +{ + int length = 1; + + net_nfc_record_tnf_e tnf = NET_NFC_RECORD_UNKNOWN; + + net_nfc_get_record_tnf(record, &tnf); + if (tnf != NET_NFC_RECORD_EMPTY && + tnf != NET_NFC_RECORD_UNKNOWN && + tnf != NET_NFC_RECORD_UNCHAGNED) + { + data_h data; + + net_nfc_get_record_type(record, &data); + length += net_nfc_get_data_length(data); + } + + uint8_t header; + + net_nfc_get_record_flags(record, &header); + /* to check if payloadlength is 8bit or 32bit*/ + if (net_nfc_get_record_sr(header) == 1) + { + /* ++ is for the Payload Length Byte */ + length++;/* for short record*/ + } + else + { + /* + NET_NFC_NDEF_NORMAL_RECORD_BYTE is for the Payload Length Byte */ + length += 4;/* for normal record*/ + } + + /* for non empty record */ + if (tnf != NET_NFC_RECORD_EMPTY) + { + data_h data; + + net_nfc_get_record_payload(record, &data); + length += net_nfc_get_data_length(data); + } + + /* ID and IDlength are present only if IL flag is set*/ + if (net_nfc_get_record_il(header) == 1) + { + data_h data; + + /* ++ is for the ID Length Byte */ + length++; + + net_nfc_get_record_id(record, &data); + length += net_nfc_get_data_length(data); + } + + fprintf(stdout, " Length : %d\n", length); +} + +static void _display_record(ndef_record_h record, int index) +{ + uint8_t header; + + fprintf(stdout, "------------------ ndef record %02d ------------------\n", index); + + _display_record_length(record); + + net_nfc_get_record_flags(record, &header); + + fprintf(stdout, " MB[%d], ME[%d], CF[%d], SR[%d], IL[%d]\n", net_nfc_get_record_mb(header), net_nfc_get_record_me(header), + net_nfc_get_record_cf(header), net_nfc_get_record_sr(header), net_nfc_get_record_il(header)); + + _display_tnf(record); + + fprintf(stdout, "----------------------------------------------------\n"); +} + +void ndef_tool_display_ndef_message_from_file(const char *file_name) +{ + int length = 0; + ndef_message_h msg = NULL; + + if ((length = ndef_tool_read_ndef_message_from_file(file_name, &msg)) > 0) + { + int32_t count = 0; + int32_t i = 0; + ndef_record_h record = NULL; + + net_nfc_get_ndef_message_record_count(msg, &count); + + fprintf(stdout, "\n================ ndef message begin ================\n"); + fprintf(stdout, "Length : %d\n", length); + + for (i = 0; i < count; i++) + { + net_nfc_get_record_by_index(msg, i, &record); + + _display_record(record, i); + } + + fprintf(stdout, "================= ndef message end =================\n\n"); + + net_nfc_free_ndef_message(msg); + } + else + { + fprintf(stdout, "No file exists : %s\n\n", file_name); + } +} + +void _display_target_type(net_nfc_target_type_e type) +{ + char *text = NULL; + + switch (type) + { + case NET_NFC_GENERIC_PICC : + text = "Generic"; + break; + + case NET_NFC_ISO14443_A_PICC : + text = "ISO 14443 A"; + break; + + case NET_NFC_ISO14443_4A_PICC : + text = "ISO 14443 4A"; + break; + + case NET_NFC_ISO14443_3A_PICC : + text = "ISO 14443 3A"; + break; + + case NET_NFC_MIFARE_MINI_PICC : + text = "Mifare Mini"; + break; + + case NET_NFC_MIFARE_1K_PICC : + text = "Mifare 1k"; + break; + + case NET_NFC_MIFARE_4K_PICC : + text = "Mifare 4k"; + break; + + case NET_NFC_MIFARE_ULTRA_PICC : + text = "Mifare Ultralight"; + break; + + case NET_NFC_MIFARE_DESFIRE_PICC : + text = "Mifare Desfire"; + break; + + case NET_NFC_ISO14443_B_PICC : + text = "ISO 14443 B"; + break; + + case NET_NFC_ISO14443_4B_PICC : + text = "ISO 14443 4B"; + break; + + case NET_NFC_ISO14443_BPRIME_PICC : + text = "ISO 14443 B Prime"; + break; + + case NET_NFC_FELICA_PICC : + text = "Felica"; + break; + + case NET_NFC_JEWEL_PICC : + text = "Jewel"; + break; + + case NET_NFC_ISO15693_PICC : + text = "ISO 15693"; + break; + + case NET_NFC_NFCIP1_TARGET : + text = "P2P Target (NFCIP1)"; + break; + + case NET_NFC_NFCIP1_INITIATOR : + text = "P2P Initiator (NFCIP1)"; + break; + + default : + text = "Unknown"; + break; + } + + fprintf(stdout, "Target Type : %s (%d)\n", text, type); +} + +void _display_tag_info(net_nfc_target_info_h target) +{ + int count, i; + char **keys; + data_h data; + + fprintf(stdout, "Target information\n"); + net_nfc_get_tag_info_keys(target, &keys, &count); + for (i = 0; i < count; i++) + { + if (keys[i] != NULL) + { + if (net_nfc_get_tag_info_value(target, keys[i], &data) == 0) + { + _display_buffer(keys[i], net_nfc_get_data_buffer(data), net_nfc_get_data_length(data)); + } + } + } +} + +void ndef_tool_display_discovered_tag(net_nfc_target_info_h target) +{ + net_nfc_target_type_e type; + bool is_ndef; + uint32_t size; + + if (target == NULL) + { + return; + } + + fprintf(stdout, "\n************* Tag discovered *************\n"); + + net_nfc_get_tag_type(target, &type); + _display_target_type(type); + + net_nfc_get_tag_ndef_support(target, &is_ndef); + fprintf(stdout, "Including NDEF? : %s\n", is_ndef ? "Yes" : "No"); + + net_nfc_get_tag_max_data_size(target, &size); + fprintf(stdout, "Maximum size : %d\n", size); + + net_nfc_get_tag_actual_data_size(target, &size); + fprintf(stdout, "Actual size : %d\n", size); + + _display_tag_info(target); + + fprintf(stdout, "******************************************\n"); +} + +void ndef_tool_display_discovered_target(net_nfc_target_handle_h handle) +{ + if (handle == NULL) + { + return; + } + + fprintf(stdout, "\n************* Target discovered *************\n"); + fprintf(stdout, "Target Type : P2P Target (NFCIP1) (%d)\n", NET_NFC_NFCIP1_TARGET); + fprintf(stdout, "*********************************************\n"); +} + diff --git a/test_clinet_app/ndef-tool/ndef-tool-sign.c b/test_clinet_app/ndef-tool/ndef-tool-sign.c new file mode 100755 index 0000000..69f0357 --- /dev/null +++ b/test_clinet_app/ndef-tool/ndef-tool-sign.c @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include +#include +#include +#include +#include +#include + +#include "net_nfc.h" +#include "net_nfc_sign_record.h" +#include "ndef-tool.h" + +bool ndef_tool_sign_message_from_file(const char *file_name, int begin_index, int end_index, char *cert_file, char *password) +{ + bool result = false; + ndef_message_h msg = NULL; + int32_t count = 0; + + if (ndef_tool_read_ndef_message_from_file(file_name, &msg) > 0) + { + net_nfc_get_ndef_message_record_count(msg, &count); + + if (count > end_index) + { + fprintf(stdout, "count : %d\n", count); + + net_nfc_sign_records(msg, begin_index, end_index, cert_file, password); + + ndef_tool_write_ndef_message_to_file(file_name, msg); + + result = true; + } + + net_nfc_free_ndef_message(msg); + } + + return result; +} + +bool ndef_tool_verify_message_from_file(const char *file_name) +{ + bool result = false; + ndef_message_h msg = NULL; + + if (ndef_tool_read_ndef_message_from_file(file_name, &msg) > 0) + { + result = (net_nfc_verify_signature_ndef_message(msg) == 0); + + net_nfc_free_ndef_message(msg); + } + + return result; +} diff --git a/test_clinet_app/ndef-tool/ndef-tool-tag.c b/test_clinet_app/ndef-tool/ndef-tool-tag.c new file mode 100755 index 0000000..7436a47 --- /dev/null +++ b/test_clinet_app/ndef-tool/ndef-tool-tag.c @@ -0,0 +1,304 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include +#include +#include +#include +#include +#include +#include + +#include "net_nfc.h" +#include "net_nfc_exchanger.h" +#include "ndef-tool.h" + +typedef struct _response_context_t +{ + int type; + void *user_param; +} response_context_t; + +static GMainLoop *main_loop = NULL; +static response_context_t response_context = { 0, }; + +static void _tag_read_completed_cb(ndef_message_h msg, void *user_data) +{ + response_context_t *context = (response_context_t *)user_data; + + fprintf(stdout, "read complete!!!\n"); + if (msg != NULL) + { + ndef_tool_write_ndef_message_to_file((char *)context->user_param, msg); + + ndef_tool_display_ndef_message_from_file((char *)context->user_param); + } + + g_main_loop_quit(main_loop); +} + +static void _tag_read_cb(net_nfc_target_handle_h handle, void *user_data) +{ + fprintf(stdout, "\nreading...\n\n"); + + net_nfc_read_tag(handle, user_data); +} + +static void _tag_write_completed_cb(net_nfc_error_e result, void *user_data) +{ + if (result == NET_NFC_OK) + fprintf(stdout, "write success!!!\n\n"); + else + fprintf(stdout, "write failed.\n\n"); + + g_main_loop_quit(main_loop); +} + +static void _tag_write_cb(net_nfc_target_handle_h handle, void *user_data) +{ + response_context_t *context = (response_context_t *)user_data; + + fprintf(stdout, "\nwriting...\n\n"); + + net_nfc_write_ndef(handle, (ndef_message_h)context->user_param, user_data); +} + +static void _p2p_receive_completed_cb(data_h data, void *user_data) +{ + response_context_t *context = (response_context_t *)user_data; + + fprintf(stdout, "\np2p receive complete!!!\n\n"); + if (data != NULL) + { + ndef_message_h msg; + + net_nfc_create_ndef_message_from_rawdata(&msg, data); + + ndef_tool_write_ndef_message_to_file((char *)context->user_param, msg); + + net_nfc_free_ndef_message(msg); + + ndef_tool_display_ndef_message_from_file((char *)context->user_param); + } + + g_main_loop_quit(main_loop); +} + +static void _p2p_send_completed_cb(net_nfc_error_e result, void *user_data) +{ + if (result == NET_NFC_OK) + fprintf(stdout, "send success!!!\n\n"); + else + fprintf(stdout, "send failed.\n\n"); + + g_main_loop_quit(main_loop); +} + +static void _p2p_send_cb(net_nfc_target_handle_h handle, void *user_data) +{ + response_context_t *context = (response_context_t *)user_data; + + fprintf(stdout, "\nsending...\n\n"); + + net_nfc_exchanger_data_h data_handle; + data_h rawdata; + + net_nfc_create_rawdata_from_ndef_message((ndef_message_h)context->user_param, &rawdata); + net_nfc_create_exchanger_data(&data_handle, rawdata); + net_nfc_free_data(rawdata); + + net_nfc_send_exchanger_data(data_handle, handle, user_data); + net_nfc_free_exchanger_data(data_handle); +} + +void _nfc_response_cb(net_nfc_message_e message, net_nfc_error_e result, void *data, void *user_param, void *trans_data) +{ + response_context_t *context = (response_context_t *)user_param; + + switch (message) + { + case NET_NFC_MESSAGE_TAG_DISCOVERED : + { + net_nfc_target_handle_h handle = NULL; + bool is_ndef = false; + + net_nfc_get_tag_handle((net_nfc_target_info_h)data, &handle); + net_nfc_get_tag_ndef_support((net_nfc_target_info_h)data, &is_ndef); + + ndef_tool_display_discovered_tag(data); + + if (is_ndef == true) + { + if (context->type == 0) /* read */ + { + _tag_read_cb(handle, user_param); + } + else + { + _tag_write_cb(handle, user_param); + } + } + else + { + fprintf(stdout, "No NDEF tag.. read failed.\n\n"); + g_main_loop_quit(main_loop); + } + } + break; + + case NET_NFC_MESSAGE_READ_NDEF : + _tag_read_completed_cb((ndef_message_h)data, user_param); + break; + + case NET_NFC_MESSAGE_WRITE_NDEF : + _tag_write_completed_cb(result, user_param); + break; + + case NET_NFC_MESSAGE_P2P_DISCOVERED : + + ndef_tool_display_discovered_target(data); + + if (context->type == 1) /* receive */ + { + _p2p_send_cb((net_nfc_target_handle_h)data, user_param); + } + break; + + case NET_NFC_MESSAGE_P2P_SEND : + _p2p_send_completed_cb(result, user_param); + break; + + case NET_NFC_MESSAGE_P2P_RECEIVE : + _p2p_receive_completed_cb(data, user_param); + break; + + default : + break; + } +} + +static void _initialize_tag_context(response_context_t *context) +{ + if(!g_thread_supported()) + { + g_thread_init(NULL); + } + +// g_type_init(); + + net_nfc_initialize(); + + net_nfc_set_response_callback(_nfc_response_cb, (void *)context); +} + +static void _run_tag_action() +{ + main_loop = g_main_new(TRUE); + g_main_loop_run(main_loop); +} + +static void _release_tag_context(void) +{ + net_nfc_unset_response_callback(); + + net_nfc_deinitialize(); +} + +int ndef_tool_read_ndef_from_tag(const char *file) +{ + int result = 0; + + response_context.type = 0; + response_context.user_param = (void *)file; + + _initialize_tag_context(&response_context); + + fprintf(stdout, "Contact a tag to device.....\n"); + + _run_tag_action(); + + _release_tag_context(); + + return result; +} + +int ndef_tool_receive_ndef_via_p2p(const char *file) +{ + int result = 0; + + response_context.type = 0; + response_context.user_param = (void *)file; + + _initialize_tag_context(&response_context); + + fprintf(stdout, "Contact a target to device.....\n"); + + _run_tag_action(); + + _release_tag_context(); + + return result; +} + +int ndef_tool_write_ndef_to_tag(const char *file) +{ + int result = 0; + ndef_message_h msg = NULL; + + if (ndef_tool_read_ndef_message_from_file(file, &msg) > 0) + { + response_context.type = 1; + response_context.user_param = (void *)msg; + + _initialize_tag_context(&response_context); + + fprintf(stdout, "Contact a tag to device.....\n"); + + _run_tag_action(); + + net_nfc_free_ndef_message(msg); + + _release_tag_context(); + } + + return result; +} + +int ndef_tool_send_ndef_via_p2p(const char *file) +{ + int result = 0; + ndef_message_h msg = NULL; + + if (ndef_tool_read_ndef_message_from_file(file, &msg) > 0) + { + response_context.type = 1; + response_context.user_param = (void *)msg; + + _initialize_tag_context(&response_context); + + fprintf(stdout, "Contact a tag to device.....\n"); + + _run_tag_action(); + + net_nfc_free_ndef_message(msg); + + _release_tag_context(); + } + + return result; +} + diff --git a/test_clinet_app/ndef-tool/ndef-tool.c b/test_clinet_app/ndef-tool/ndef-tool.c new file mode 100755 index 0000000..05462df --- /dev/null +++ b/test_clinet_app/ndef-tool/ndef-tool.c @@ -0,0 +1,688 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include +#include +#include +#include +#include +#include +#include + +#include "net_nfc.h" +#include "ndef-tool.h" + +static GMainLoop *main_loop = NULL; + +void _activation_complete_cb(net_nfc_message_e message, net_nfc_error_e result, void *data, void *user_param, void *trans_data) +{ + switch (message) + { + case NET_NFC_MESSAGE_INIT : + if (result == NET_NFC_OK) + fprintf(stdout, "power on success\n\n"); + else + fprintf(stdout, "failed to power on (%d)\n\n", result); + + net_nfc_unset_response_callback(); + net_nfc_deinitialize(); + g_main_loop_quit(main_loop); + break; + + case NET_NFC_MESSAGE_DEINIT : + if (result == NET_NFC_OK) + fprintf(stdout, "power off success\n\n"); + else + fprintf(stdout, "failed to power off (%d)\n\n", result); + + net_nfc_unset_response_callback(); + net_nfc_deinitialize(); + g_main_loop_quit(main_loop); + break; + + default : + break; + } +} + +int ndef_tool_read_ndef_message_from_file(const char *file_name, ndef_message_h *msg) +{ + int result = -1; + FILE *file = NULL; + + file = fopen(file_name, "rb"); + if (file != NULL) + { + long int file_size = 0; + size_t read = 0; + + fseek(file, 0, SEEK_END); + file_size = ftell(file); + fseek(file, 0, SEEK_SET); + + if (file_size > 0) + { + data_h data; + + net_nfc_create_data(&data, NULL, file_size); + if (data != NULL) + { + read = fread((void *)net_nfc_get_data_buffer(data), 1, file_size, file); + + net_nfc_create_ndef_message_from_rawdata(msg, data); + + net_nfc_free_data(data); + + result = file_size; + } + } + + fclose(file); + } + + return result; +} + +int ndef_tool_write_ndef_message_to_file(const char *file_name, ndef_message_h msg) +{ + int result = -1; + FILE *file = NULL; + data_h data = NULL; + + net_nfc_create_rawdata_from_ndef_message(msg, &data); + if (data != NULL) + { + file = fopen(file_name, "wb"); + if (file != NULL) + { + fwrite((void *)net_nfc_get_data_buffer(data), 1, net_nfc_get_data_length(data), file); + fflush(file); + fclose(file); + + result = 0; + } + + net_nfc_free_data(data); + } + + return result; +} + +static void print_usage(char *file_name) +{ + fprintf(stdout, "Usage : %s OPERATION [OPTION]... FILE\n", file_name); + fprintf(stdout, "\n"); + fprintf(stdout, " Operation\n"); + fprintf(stdout, " -a, --append-record Append a record to file\n"); + fprintf(stdout, " Options\n"); + fprintf(stdout, " -t, --tnf tnf Input TNF value\n"); + fprintf(stdout, " (WKT : Well-known, EXT : External, \n"); + fprintf(stdout, " MIME : MIME-type, URI : Absolute-URI)\n"); + fprintf(stdout, " -T, --type-data data Input Type-field data\n"); + fprintf(stdout, " -I, --id-data data Input ID-field data\n"); + fprintf(stdout, " -P, --payload-data data Input Payload-field data. You can input hexa-style data using '%%' prefix\n"); + fprintf(stdout, " ex) (0x20)abc : %%20abc\n"); + fprintf(stdout, " it is possible to input '%%' by using '%%%%'\n"); + fprintf(stdout, " ex) 120%%20 : 120%%%%20\n"); + fprintf(stdout, " --payload-file file Input Payload-field data from binary file\n"); + fprintf(stdout, " -E, --encoding data Input encoding method of Well-known Text type record\n"); + fprintf(stdout, "\n"); + fprintf(stdout, " -r, --remove-record Remove a specific record from file\n"); + fprintf(stdout, " Options\n"); + fprintf(stdout, " -i, --index value Input a record index\n"); + fprintf(stdout, "\n"); + fprintf(stdout, " -d, --display Display all records in file\n"); + fprintf(stdout, " -s, --sign-records Sign some continuous records in file\n"); + fprintf(stdout, " Options\n"); + fprintf(stdout, " -b, --begin-index value Input a beginning record index\n"); + fprintf(stdout, " -e, --end-index value Input a last record index\n"); + fprintf(stdout, " -c, --cert-file file Input a PKCS #12 certificate file (DER file, not PEM file)\n"); + fprintf(stdout, " -p, --password pass Input a password of PKCS #12 certificate file\n"); + fprintf(stdout, "\n"); + fprintf(stdout, " -v, --verify-signed-records Verify signature in file\n"); + fprintf(stdout, " --read-tag Read a ndef from tag and store to file\n"); + fprintf(stdout, " --write-tag Write a ndef file to tag\n"); + fprintf(stdout, " --receive-ndef Receive a ndef from target device and store to file\n"); + fprintf(stdout, " --send-ndef Send a ndef file to target device\n"); + fprintf(stdout, "\n"); + fprintf(stdout, " -h, --help Show this help messages\n"); + fprintf(stdout, "\n"); +} + +static net_nfc_record_tnf_e _parse_tnf_string(const char *tnf) +{ + net_nfc_record_tnf_e result = -1; + + if (tnf == NULL) + return result; + + if (strncasecmp(tnf, "EMT", 3) == 0) + { + result = NET_NFC_RECORD_EMPTY; + } + else if (strncasecmp(tnf, "WKT", 3) == 0) + { + result = NET_NFC_RECORD_WELL_KNOWN_TYPE; + } + else if (strncasecmp(tnf, "MIME", 4) == 0) + { + result = NET_NFC_RECORD_MIME_TYPE; + } + else if (strncasecmp(tnf, "URI", 3) == 0) + { + result = NET_NFC_RECORD_URI; + } + else if (strncasecmp(tnf, "EXT", 3) == 0) + { + result = NET_NFC_RECORD_EXTERNAL_RTD; + } + else if (strncasecmp(tnf, "UNK", 3) == 0) + { + result = NET_NFC_RECORD_UNKNOWN; + } + else if (strncasecmp(tnf, "UNC", 3) == 0) + { + result = NET_NFC_RECORD_UNCHAGNED; + } + + return result; +} + +static int _append_record_to_file(const char *file_name, ndef_record_h record) +{ + int result = -1; + ndef_message_h msg = NULL; + + if (ndef_tool_read_ndef_message_from_file(file_name, &msg) <= 0) + { + net_nfc_create_ndef_message(&msg); + } + + net_nfc_append_record_to_ndef_message(msg, record); + + ndef_tool_write_ndef_message_to_file(file_name, msg); + + net_nfc_free_ndef_message(msg); + + result = 0; + + return result; +} + +ndef_record_h _create_record(net_nfc_record_tnf_e tnf, data_h type, data_h id , data_h payload, char *encoding) +{ + ndef_record_h result = NULL; + + switch (tnf) + { + case NET_NFC_RECORD_WELL_KNOWN_TYPE : + if (net_nfc_get_data_length(type) == 1 && memcmp((void *)net_nfc_get_data_buffer(type), "T", 1) == 0) + { + if (encoding == NULL) + { + fprintf(stdout, "encoding type is not present.\n"); + return result; + } + + char *temp_str = calloc(1, net_nfc_get_data_length(payload) + 1); + memcpy(temp_str, (void *)net_nfc_get_data_buffer(payload), net_nfc_get_data_length(payload)); + + net_nfc_create_text_type_record(&result, temp_str, encoding, NET_NFC_ENCODE_UTF_8); + free(temp_str); + + if (id != NULL) + { + net_nfc_set_record_id(result, id); + } + } + else if (net_nfc_get_data_length(type) == 1 && memcmp((void *)net_nfc_get_data_buffer(type), "U", 1) == 0) + { + char *temp_str = calloc(1, net_nfc_get_data_length(payload) + 1); + memcpy(temp_str, (void *)net_nfc_get_data_buffer(payload), net_nfc_get_data_length(payload)); + + net_nfc_create_uri_type_record(&result, temp_str, 0); + free(temp_str); + + if (id != NULL) + { + net_nfc_set_record_id(result, id); + } + } + else + { + net_nfc_create_record(&result, tnf, type, id, payload); + } + break; + + default : + net_nfc_create_record(&result, tnf, type, id, payload); + break; + } + + return result; +} + +bool _remove_record_from_file(const char *file_name, int index) +{ + bool result = false; + ndef_message_h msg = NULL; + + if (ndef_tool_read_ndef_message_from_file(file_name, &msg) > 0) + { + net_nfc_remove_record_by_index(msg, index); + + ndef_tool_write_ndef_message_to_file(file_name, msg); + + net_nfc_free_ndef_message(msg); + + result = true; + } + + return result; +} + +#define __IS_SHORT_OPTION(__dst) ((strlen(__dst) == 2) && ((__dst)[0] == '-')) +#define __IS_LONG_OPTION(__dst) ((strlen(__dst) > 2) && ((__dst)[0] == '-') && ((__dst)[1] == '-')) +#define __IS_OPTION(__dst) (__IS_SHORT_OPTION(__dst) || __IS_LONG_OPTION(__dst)) + +#define __COMPARE_OPTION(__dst, __s, __l) \ + ((__IS_SHORT_OPTION(__dst) && ((__dst)[1] == (__s))) || \ + (__IS_LONG_OPTION(__dst) && (strcmp((__dst) + 2, (__l)) == 0))) + +#define __DO_NEXT_ARG \ + if (++i >= argc || __IS_OPTION(argv[i]) == true) \ + { \ + operation = OPERATION_ERROR; \ + break; \ + } + +int main(int argc, char *argv[]) +{ + int remove_index = -1; + int begin_index = -1; + int end_index = -1; + int operation = OPERATION_ERROR; + net_nfc_record_tnf_e tnf = -1; + data_h type = NULL; + data_h id = NULL; + data_h payload = NULL; + char *file_name = NULL; + char *cert_file = NULL; + char *password = NULL; + char *encoding = NULL; + ndef_record_h record = NULL; + + int i = 1; + int len = 0; + + for (i = 1; i < argc; i++) + { + if (__COMPARE_OPTION(argv[i], 'a', "append-record")) + { + operation = OPERATION_APPEND; + } + else if (__COMPARE_OPTION(argv[i], 's', "sign-records")) + { + operation = OPERATION_SIGN; + } + else if (__COMPARE_OPTION(argv[i], 'd', "display-record")) + { + operation = OPERATION_DISPLAY; + } + else if (__COMPARE_OPTION(argv[i], 'v', "verify-signed-records")) + { + operation = OPERATION_VERIFY; + } + else if (__COMPARE_OPTION(argv[i], 'r', "remove-record")) + { + operation = OPERATION_REMOVE; + } + else if (__COMPARE_OPTION(argv[i], 0, "read-tag")) + { + operation = OPERATION_READ_TAG; + } + else if (__COMPARE_OPTION(argv[i], 0, "write-tag")) + { + operation = OPERATION_WRITE_TAG; + } + else if (__COMPARE_OPTION(argv[i], 0, "receive-ndef")) + { + operation = OPERATION_RECEIVE_NDEF; + } + else if (__COMPARE_OPTION(argv[i], 0, "send-ndef")) + { + operation = OPERATION_SEND_NDEF; + } + else if (__COMPARE_OPTION(argv[i], 0, "off")) /* hidden operation */ + { + operation = OPERATION_OFF; + } + else if (__COMPARE_OPTION(argv[i], 0, "on")) /* hidden operation */ + { + operation = OPERATION_ON; + } + else if (__COMPARE_OPTION(argv[i], 'i', "record-index")) + { + __DO_NEXT_ARG; + remove_index = atoi(argv[i]); + } + else if (__COMPARE_OPTION(argv[i], 'c', "cert-file")) + { + __DO_NEXT_ARG; + cert_file = strdup(argv[i]); + } + else if (__COMPARE_OPTION(argv[i], 'p', "password")) + { + __DO_NEXT_ARG; + password = strdup(argv[i]); + } + else if (__COMPARE_OPTION(argv[i], 'b', "begin-index")) + { + __DO_NEXT_ARG; + begin_index = atoi(argv[i]); + } + else if (__COMPARE_OPTION(argv[i], 'e', "end-index")) + { + __DO_NEXT_ARG; + end_index = atoi(argv[i]); + } + else if (__COMPARE_OPTION(argv[i], 't', "tnf")) + { + __DO_NEXT_ARG; + tnf = _parse_tnf_string(argv[i]); + } + else if (__COMPARE_OPTION(argv[i], 'T', "type-data")) + { + __DO_NEXT_ARG; + len = strlen(argv[i]); + if (len > 0) + { + net_nfc_create_data(&type, (const uint8_t *)argv[i], len); + } + } + else if (__COMPARE_OPTION(argv[i], 'I', "id-data")) + { + __DO_NEXT_ARG; + len = strlen(argv[i]); + if (len > 0) + { + net_nfc_create_data(&id, (const uint8_t *)argv[i], len); + } + } + else if (__COMPARE_OPTION(argv[i], 'P', "payload-data")) + { + __DO_NEXT_ARG; + len = strlen(argv[i]); + if (len > 0) + { + uint8_t *buffer = NULL; + + buffer = calloc(1, len); + if (buffer != NULL) + { + int j, current = 0; + + for (j = 0; j < len; j++) + { + if (argv[i][j] == '%') + { + if (j + 2 < len) + { + if (argv[i][j + 1] != '%') + { + char temp[3] = { 0, }; + + temp[0] = argv[i][j + 1]; + temp[1] = argv[i][j + 2]; + + buffer[current++] = (uint8_t)strtol(temp, NULL, 16); + j += 2; + } + else + { + buffer[current++] = '%'; + j++; + } + } + else if (j + 1 < len) + { + if (argv[i][j + 1] == '%') + { + buffer[current++] = '%'; + j++; + } + else + { + buffer[current++] = argv[i][j]; + } + } + else + { + /* invalid param. error? */ + } + } + else + { + buffer[current++] = argv[i][j]; + } + } + + net_nfc_create_data(&payload, buffer, current); + + free(buffer); + } + } + } + else if (__COMPARE_OPTION(argv[i], 0, "payload-file")) + { + __DO_NEXT_ARG; + len = strlen(argv[i]); + if (len > 0) + { + FILE *file = NULL; + + file = fopen(argv[i], "rb"); + if (file != NULL) + { + long int file_size = 0; + size_t read = 0; + + fseek(file, 0, SEEK_END); + file_size = ftell(file); + fseek(file, 0, SEEK_SET); + + if (file_size > 0) + { + uint8_t *buffer = NULL; + + buffer = calloc(1, file_size); + if (buffer != NULL) + { + read = fread(buffer, 1, file_size, file); + + net_nfc_create_data(&payload, buffer, read); + + free(buffer); + } + } + + fclose(file); + } + } + } + else if (__COMPARE_OPTION(argv[i], 'E', "encoding")) + { + __DO_NEXT_ARG; + encoding = strdup(argv[i]); + } + else if (__COMPARE_OPTION(argv[i], 'h', "help")) + { + operation = OPERATION_ERROR; + break; + } + else + { + if (file_name == NULL) + { + file_name = strdup(argv[i]); + } + else + { + operation = OPERATION_ERROR; + break; + } + } + } + + if (operation != OPERATION_ON && operation != OPERATION_OFF && file_name == NULL) + operation = OPERATION_ERROR; + + switch (operation) + { + case OPERATION_DISPLAY : + ndef_tool_display_ndef_message_from_file(file_name); + break; + + case OPERATION_APPEND : + if (tnf >= 0 && type != NULL) + { + record = _create_record(tnf, type, id, payload, encoding); + + if (record != NULL) + { + _append_record_to_file(file_name, record); + + ndef_tool_display_ndef_message_from_file(file_name); + } + else + { + print_usage(argv[0]); + } + } + else + { + print_usage(argv[0]); + } + break; + + case OPERATION_REMOVE : + _remove_record_from_file(file_name, remove_index); + ndef_tool_display_ndef_message_from_file(file_name); + break; + + case OPERATION_SIGN : + if (begin_index < 0 || end_index < 0 || begin_index > end_index || cert_file == NULL || password == NULL) + { + print_usage(argv[0]); + } + else + { + fprintf(stdout, "file : %s\ncert file : %s\npassword : %s\nbegin index : %d\nend index : %d\n", file_name, cert_file, password, begin_index, end_index); + ndef_tool_sign_message_from_file(file_name, begin_index, end_index, cert_file, password); + ndef_tool_display_ndef_message_from_file(file_name); + } + break; + + case OPERATION_VERIFY : + fprintf(stdout, "verify %s\n", ndef_tool_verify_message_from_file(file_name) ? "success" : "failed"); + break; + + case OPERATION_READ_TAG : + ndef_tool_read_ndef_from_tag(file_name); + break; + + case OPERATION_WRITE_TAG : + ndef_tool_write_ndef_to_tag(file_name); + break; + + case OPERATION_RECEIVE_NDEF : + ndef_tool_receive_ndef_via_p2p(file_name); + break; + + case OPERATION_SEND_NDEF : + ndef_tool_send_ndef_via_p2p(file_name); + break; + + case OPERATION_ON : + { + int state = 0; + + net_nfc_get_state(&state); + + if (state == 0) + { + fprintf(stdout, "Power on....\n\n"); + + if(!g_thread_supported()) + { + g_thread_init(NULL); + } + + main_loop = g_main_new(true); + + net_nfc_initialize(); + net_nfc_set_response_callback(_activation_complete_cb, NULL); + net_nfc_set_state(true, NULL); + + g_main_loop_run(main_loop); + } + else + { + fprintf(stdout, "Already power is on.\n\n"); + } + } + break; + + case OPERATION_OFF : + { + int state = 0; + + net_nfc_get_state(&state); + + if (state == 1) + { + fprintf(stdout, "Power off....\n\n"); + + if(!g_thread_supported()) + { + g_thread_init(NULL); + } + + main_loop = g_main_new(true); + + net_nfc_initialize(); + net_nfc_set_response_callback(_activation_complete_cb, NULL); + net_nfc_set_state(false, NULL); + + g_main_loop_run(main_loop); + } + else + { + fprintf(stdout, "Already power is off.\n\n"); + } + } + break; + + case OPERATION_ERROR : + default : + print_usage(argv[0]); + break; + } + + return 0; +} + diff --git a/test_clinet_app/ndef-tool/ndef-tool.h b/test_clinet_app/ndef-tool/ndef-tool.h new file mode 100755 index 0000000..e3b81eb --- /dev/null +++ b/test_clinet_app/ndef-tool/ndef-tool.h @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#ifndef __NDEF_TOOL_H +#define __NDEF_TOOL_H + +#include "net_nfc_typedef.h" + +enum +{ + OPERATION_ERROR, + OPERATION_DISPLAY, + OPERATION_APPEND, + OPERATION_REMOVE, + OPERATION_SIGN, + OPERATION_VERIFY, + OPERATION_READ_TAG, + OPERATION_WRITE_TAG, + OPERATION_RECEIVE_NDEF, + OPERATION_SEND_NDEF, + OPERATION_ON, /* hidden operation */ + OPERATION_OFF, /* hidden operation */ +}; + +int ndef_tool_read_ndef_message_from_file(const char *file_name, ndef_message_h *msg); +int ndef_tool_write_ndef_message_to_file(const char *file_name, ndef_message_h msg); + +void ndef_tool_display_ndef_message_from_file(const char *file_name); +void ndef_tool_display_discovered_tag(net_nfc_target_info_h target); +void ndef_tool_display_discovered_target(net_nfc_target_handle_h handle); + +bool ndef_tool_sign_message_from_file(const char *file_name, int begin_index, int end_index, char *cert_file, char *password); +bool ndef_tool_verify_message_from_file(const char *file_name); + +int ndef_tool_read_ndef_from_tag(const char *file); +int ndef_tool_write_ndef_to_tag(const char *file); +int ndef_tool_receive_ndef_via_p2p(const char *file); +int ndef_tool_send_ndef_via_p2p(const char *file); + + + + +#endif /* __NDEF_TOOL_H */ + diff --git a/test_clinet_app/nfc_client/Makefile b/test_clinet_app/nfc_client/Makefile new file mode 100755 index 0000000..82a1825 --- /dev/null +++ b/test_clinet_app/nfc_client/Makefile @@ -0,0 +1,46 @@ +LOCAL_PATH=. + +#phLibNfc + +export PKG_CONFIG_PATH=/usr/lib/pkgconfig/ + +#sources + +SRCS = $(LOCAL_PATH)/main.c + +#includes + +USER_HEADER =`pkg-config --cflags nfc glib-2.0 gobject-2.0` + +LOCAL_CFLAGS = $(USER_HEADER) + +CC = arm-linux-gnueabi-gcc + +TARGET = nfc-test + + +CFLAGS = $(LOCAL_CFLAGS) -g +LDFLAGS = -lpthread `pkg-config --libs nfc glib-2.0 gobject-2.0` + + +SRC = $(SRCS) +OBJS = $(SRC:.c=.o) +RM = rm + + +.SUFFIXES: .c .o + +.c.o: + $(CC) -c $(CFLAGS) -o $*.o $< + +all: $(TARGET) + +$(TARGET): $(OBJS) + $(CC) -o $@ $(OBJS) $(LDFLAGS) + +run: all + $(TARGET) + +clean: + $(RM) -f $(OBJS) $(TARGET) + diff --git a/test_clinet_app/nfc_client/main.c b/test_clinet_app/nfc_client/main.c new file mode 100755 index 0000000..0a2d803 --- /dev/null +++ b/test_clinet_app/nfc_client/main.c @@ -0,0 +1,3445 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include +#include +#include +#include +#include + +#include +#include "nfc_api_test.h" + +#include + +/* Function definition list*/ +int nfcTestClientInit(uint8_t testNumber,void* arg_ptr2); +int nfcTestNdefParser(uint8_t testNumber,void* arg_ptr2); +int nfcTestWriteMode(uint8_t testNumber,void* arg_ptr2); +int nfcTestReaderMode(uint8_t testNumber,void* arg_ptr2); +int nfcTestTransceive(uint8_t testNumber,void* arg_ptr2); +int nfcTestAPIBasicTest1(uint8_t testNumber,void* arg_ptr2); +int nfcTestAPIBasicTest2(uint8_t testNumber,void* arg_ptr2); +int nfcTestAPIBasicTest3(uint8_t testNumber,void* arg_ptr2); +int nfcTestReadWriteMode(uint8_t testNumber,void* arg_ptr2); +int nfcTestAPIMultipleRequest(uint8_t testNumber,void* arg_ptr2); +int nfcTestLLCP(uint8_t testNumber,void* arg_ptr2); +int nfcTestStressLLCP(uint8_t testNumber,void* arg_ptr2); +int nfcTestExchanger(uint8_t testNumber,void* arg_ptr2); +int nfcConnHandover(uint8_t testNumber,void* arg_ptr2); +int nfcTestAPIException (uint8_t testNumber,void* arg_ptr); +int nfcTestAPIException_tagAPI (uint8_t testNumber,void* arg_ptr); +int nfcTestAPIException_targetInfo (uint8_t testNumber,void* arg_ptr); +int nfcConnHandoverMessageTest (uint8_t testNumber,void* arg_ptr); +int nfcTestFormatNdef(uint8_t testNumber,void* arg_ptr2); +int nfcTestInternalSe(uint8_t testNumber,void* arg_ptr2); +int nfcTestSnep(uint8_t testNumber,void* arg_ptr); + + +void print_test_result (char * str, net_nfc_test_result_e result); + +#define NET_NFC_TAG_DISCOVERED 1 +#define NET_NFC_TAG_CONNECT (1 << 1) +#define NET_NFC_TAG_CHECK_NDEF (1 << 2) +#define NET_NFC_TAG_NDEF_READ (1 << 3) +#define NET_NFC_TAG_NDEF_WRITE (1 << 4) +#define NET_NFC_TAG_NDEF_READ_BIG (1 << 5) +#define NET_NFC_TAG_NDEF_WRITE_BIG (1 << 6) +#define NET_NFC_TAG_DISCONNECT (1 << 7) +#define NET_NFC_MAX_TAG_TYPE 20 + +static nfcTestType nfcTestMatrix[] = +{ +// {"API STRESS_WRITE_READ TEST", nfcTestReadWriteMode, NET_NFC_TEST_NOT_YET}, // OK +// {"Remove tag while writing", nfcTestWriteMode, NET_NFC_TEST_NOT_YET}, //OK +// {"Remove tag while reading", nfcTestAPIBasicTest2, NET_NFC_TEST_NOT_YET}, // OK + //{"API BASIC TEST3", nfcTestAPIBasicTest3, NET_NFC_TEST_NOT_YET}, +// {"API MUTIPLE REQUEST", nfcTestAPIMultipleRequest, NET_NFC_TEST_NOT_YET}, // OK +// {"API BASIC TEST1", nfcTestAPIBasicTest1, NET_NFC_TEST_NOT_YET}, // OK +// {"Check NDEF message", nfcTestNdefParser, NET_NFC_TEST_NOT_YET}, // OK +// {"write mode", nfcTestWriteMode, NET_NFC_TEST_NOT_YET}, +// {"reader mode", nfcTestReaderMode, NET_NFC_TEST_NOT_YET}, +// {"format ndef", nfcTestFormatNdef, NET_NFC_TEST_NOT_YET}, +// {"internal_se_test", nfcTestInternalSe, NET_NFC_TEST_NOT_YET}, +// {"exchange mode", nfcTestExchanger, NET_NFC_TEST_NOT_YET}, +// {"Transceive Test", nfcTestTransceive, NET_NFC_TEST_NOT_YET}, +// {"LLCP Test", nfcTestLLCP, NET_NFC_TEST_NOT_YET}, +// {"connection handover msg test", nfcConnHandover, NET_NFC_TEST_NOT_YET}, +// {"API Exception Test", nfcTestAPIException, NET_NFC_TEST_NOT_YET}, +// {"API Exception Test2", nfcTestAPIException_tagAPI, NET_NFC_TEST_NOT_YET}, +/// {"API Exception Test3", nfcTestAPIException_targetInfo, NET_NFC_TEST_NOT_YET}, +// {"LLCP Test", nfcTestLLCP, NET_NFC_TEST_NOT_YET}, +// {"LLCP Test", nfcTestStressLLCP, NET_NFC_TEST_NOT_YET}, +// {"Handover Message", nfcConnHandoverMessageTest , NET_NFC_TEST_NOT_YET}, + {"snep test", nfcTestSnep, NET_NFC_TEST_NOT_YET}, + {NULL, NULL, NET_NFC_TEST_NOT_YET}, +}; + +static uint32_t testDevType = 0; +static uint32_t testCardMaxNdefLength = 0; +static uint8_t tagTestResult[NET_NFC_MAX_TAG_TYPE]; + +static int read_count = 0; +static int write_count = 0; +static int detect_count = 0; + +static net_nfc_target_handle_h tag_handle = NULL; +static int test_count = 0; + + + +/* Below smart poster data can has problem or parser has some problem. + Need to check */ +uint8_t nfcTestSpHex[]= {0xD1,0x02,0x37,0x53,0x70,0x91,0x01,0x18,0x54,0x04, + 0x74,0x65,0x73,0x74,0x53,0x6D,0x61,0x72,0x74,0x70, + 0x6F,0x73,0x74,0x65,0x72,0x20,0x45,0x78,0x61,0x6D, + 0x70,0x6C,0x65,0x11,0x03,0x01,0x61,0x63,0x74,0x00, + 0x51,0x01,0x10,0x55,0x00,0x77,0x77,0x77,0x2E,0x73, + 0x61,0x6D,0x73,0x75,0x6E,0x67,0x2E,0x63,0x6F,0x6D}; + +/* +uint8_t nfcTestSp[]={0xD1,0x02,0x24,0x53,0x70,0x91,0x01,0x14,0x54 + ,0x00,0x53,0x6D,0x61,0x72,0x74,0x70,0x6F,0x73 + ,0x74,0x65,0x72,0x20,0x45,0x78,0x61,0x6D,0x70 + ,0x6C,0x65,0x11,0x03,0x01,0x61,0x63,0x74,0x00 + ,0x51,0x01,0x01,0x55,0x00}; +*/ + +// test Text "Samsung Linux Platform NFC TEST" +uint8_t nfcTestTextHex[]= {0xD1,0x01,0x20,0x54,0x00,0x53,0x61,0x6D,0x73,0x75 + ,0x6E,0x67,0x20,0x4C,0x69,0x6E,0x75,0x78,0x20,0x50 + ,0x6C,0x61,0x74,0x66,0x6F,0x72,0x6D,0x20,0x4E,0x46 + ,0x43,0x20,0x54,0x45,0x53,0x54}; + + +// test URI "http://www.samsunglinuxplatform.nfctest.com" +uint8_t nfcTestUriHex[]={0xD1,0x01,0x2C,0x55,0x00,0x68,0x74,0x74,0x70,0x3A + ,0x2F,0x2F,0x77,0x77,0x77,0x2E,0x73,0x61,0x6D,0x73 + ,0x75,0x6E,0x67,0x6C,0x69,0x6E,0x75,0x78,0x70,0x6C + ,0x61,0x74,0x66,0x6F,0x72,0x6D,0x2E,0x6E,0x66,0x63 + ,0x74,0x65,0x73,0x74,0x2E,0x63,0x6F,0x6D}; + +uint8_t nfcTestText[] = "payload http://www.samsunglinuxplatform.nfctest.com"; +uint8_t nfcTestUri[] = {0xD1,0x01,0x13,0x55,0x1,0x73,0x61,0x6D,0x73,0x75,0x6E,0x67,0x6D,0x6F,0x62,0x69,0x6C,0x65,0x2E,0x63,0x6F,0x6D,0x2F}; + + + +static pthread_cond_t pcond = PTHREAD_COND_INITIALIZER; +static pthread_mutex_t plock = PTHREAD_MUTEX_INITIALIZER; + +static gboolean test_process_func(gpointer data) +{ + uint8_t i, testNumber; + int count = 0; + + while (nfcTestMatrix[count].testName != NULL){ + count ++; + } + + for(i=0; i use default channel and no secure message. 0xA4 -> select instruction + net_nfc_create_data(&apdu, apdu_cmd, 4); + net_nfc_send_apdu((net_nfc_target_handle_h)(data), apdu, data); + + } + break; + case NET_NFC_MESSAGE_SEND_APDU_SE: + { + PRINT_INFO("NET_NFC_MESSAGE_SEND_APDU_SE result = [%d]", result); + + if(data != NULL) + { + uint8_t * r_buffer = net_nfc_get_data_buffer (data); + uint32_t r_buffer_length = net_nfc_get_data_length (data); + + PRINT_INFO ("Received data [size:%d] \n", net_nfc_get_data_length (data)); + + int idx = 0; + for (idx = 0; idx < r_buffer_length; idx++){ + printf (" %02X", r_buffer[idx]); + }printf ("\n"); + } + + net_nfc_close_internal_secure_element((net_nfc_target_handle_h)trans_data, NULL); + } + break; + case NET_NFC_MESSAGE_CLOSE_INTERNAL_SE : + { + + PRINT_INFO("NET_NFC_MESSAGE_CLOSE_INTERNAL_SE result = [%d]", result); + } + break; + default: + break; + } + + PRINT_INFO("user_param = [%d] trans_param = [%d]", user_param, trans_data); +} + +/*=================================================================================*/ +static void net_nfc_test_static_handover_cb(net_nfc_message_e message, net_nfc_error_e result, void* data, void* user_param, void * trans_data) +{ + int user_context; + switch(message) + { + case NET_NFC_MESSAGE_TAG_DISCOVERED:{ + net_nfc_target_type_e type; + net_nfc_target_handle_h id; + bool is_ndef; + net_nfc_target_info_h target_info = (net_nfc_target_info_h)data; + net_nfc_carrier_config_h * config; + ndef_record_h record; + + net_nfc_get_tag_type (target_info, &type); + net_nfc_get_tag_handle(target_info, &id); + net_nfc_get_tag_ndef_support (target_info, &is_ndef); + PRINT_INFO("target type: %d\n", type); + PRINT_INFO("target id: %X\n", id); + PRINT_INFO("Is NDEF supoort: %d\n", is_ndef); + + if (is_ndef){ + + ndef_message_h ndef = NULL; + data_h bt_config = NULL; + net_nfc_create_data_only(&bt_config); + + // 2byte :: OOB length, 6byte :: bt addr + uint8_t temp[8] = {0x00, 0x08, 0x00, 0x02, 0x78, 0xDD, 0xC4, 0x8A}; + net_nfc_create_carrier_config (&config,NET_NFC_CONN_HANDOVER_CARRIER_BT ); + net_nfc_add_carrier_config_property (config ,NET_NFC_BT_ATTRIBUTE_ADDRESS ,8 ,temp); + net_nfc_create_ndef_record_with_carrier_config (&record, config); + net_nfc_create_handover_select_message (&ndef); + net_nfc_append_carrier_config_record (message,record,NET_NFC_CONN_HANDOVER_CARRIER_ACTIVATE); + + net_nfc_write_ndef(id, ndef, NULL); + + } + else{ + PRINT_INSTRUCT("Please use NDEF formated tag!!"); + test_case_result = NET_NFC_TEST_FAIL; + } + break; + } + case NET_NFC_MESSAGE_WRITE_NDEF:{ + + if(result == NET_NFC_OK){ + PRINT_INFO("write ndef message is ok"); + test_case_result = NET_NFC_TEST_OK; + } + + pthread_mutex_lock (&plock); + pthread_cond_signal (&pcond); + pthread_mutex_unlock (&plock); + break; + } + default: + break; + } +} + +int nfcConnHandover(uint8_t testNumber,void* arg_ptr2) +{ + int user_context = 0; + net_nfc_error_e result; +#if 1 + test_case_result = NET_NFC_TEST_FAIL; + + result = net_nfc_initialize(); + + net_nfc_state_activate(1); + + CHECK_RESULT(result); + result = net_nfc_set_response_callback (net_nfc_test_static_handover_cb, NULL); + CHECK_RESULT(result); + + PRINT_INSTRUCT("Please close a tag to device!!"); + + //pthread_cond_wait (&pcond,&plock ); + /* + PRINT_INFO("operation is end"); + + result = net_nfc_unset_response_callback (); + + CHECK_RESULT(result); + result = net_nfc_deinitialize (); + CHECK_RESULT(result); + */ +#else + +/* + ndef_message_h ndef = NULL; + + if(net_nfc_retrieve_current_ndef_message(&ndef) == NET_NFC_OK){ + PRINT_INFO("retrieve is ok"); + } + else{ + PRINT_INFO("retrieve is failed"); + return NET_NFC_TEST_FAIL; + } +*/ + ndef_message_h ndef = NULL; + data_h bt_config = NULL; + net_nfc_create_data_only(&bt_config); + + // 2byte :: OOB length, 6byte :: bt addr + uint8_t temp[8] = {0x00, 0x08, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05}; + + net_nfc_set_data(bt_config, temp, 8); + net_nfc_create_static_connection_handover_select_message(&ndef, bt_config, NULL); + + net_nfc_conn_handover_info_h handover_info = NULL; + + if(net_nfc_parse_connection_handover_ndef_message(ndef, &handover_info) == NET_NFC_OK){ + PRINT_INFO("parsing is ok"); + + uint8_t version = 0; + + if((result = net_nfc_get_connection_handover_version(handover_info, &version)) == NET_NFC_OK){ + PRINT_INFO("version = [%d]", version); + } + else{ + PRINT_INFO("get version is failed = [%d]", result); + } + + + unsigned short random_number = 0; + if((result = net_nfc_get_connection_handover_random_number(handover_info, &random_number)) == NET_NFC_OK) + { + PRINT_INFO("random_number = [%d]", random_number); + } + else + { + PRINT_INFO("get random_number is failed = [%d]", result); + } + + data_h record_type = NULL; + net_nfc_get_connection_handover_record_type(handover_info, &record_type); + PRINT_INFO("record type = [%c] [%c]", (net_nfc_get_data_buffer(record_type))[0], (net_nfc_get_data_buffer(record_type))[1]); + + uint8_t carrier_count = 0; + net_nfc_get_connection_handover_alternative_carrier_count(handover_info, &carrier_count); + + int i = 0; + for(; i < carrier_count; i++) + { + net_nfc_conn_handover_carrier_info_h carrier_info = NULL; + net_nfc_get_connection_handover_carrier_handle_by_index(handover_info, i, &carrier_info); + + if(carrier_info != NULL){ + net_nfc_conn_handover_carrier_type_e carrier_type = 0; + net_nfc_get_carrier_type(carrier_info, &carrier_type); + + if(carrier_type == NET_NFC_CONN_HANDOVER_CARRIER_BT) + { + PRINT_INFO("carrier is BT"); + } + else if(carrier_type == NET_NFC_CONN_HANDOVER_CARRIER_WIFI) + { + PRINT_INFO("carrier is WIFI"); + } + else + { + PRINT_INFO("carrier is unknown"); + } + + data_h id = NULL; + net_nfc_get_carrier_id(carrier_info, &id); + + PRINT_INFO("id = [0x%x]", (net_nfc_get_data_buffer(id))[0]); + + net_nfc_conn_handover_carrier_state_e carrier_state = 0; + net_nfc_get_carrier_power_state(carrier_info, &carrier_state); + + PRINT_INFO("cps is = [0x%x]", carrier_state); + + data_h config = NULL; + if((result = net_nfc_get_carrier_configuration(carrier_info, &config)) == NET_NFC_OK) + { + PRINT_INFO("good to get config"); + } + else + { + PRINT_INFO("failed to get config = [%d]", result); + } + + uint8_t* buffer = NULL; + if((buffer = net_nfc_get_data_buffer(config)) != NULL) + { + unsigned short size = ( buffer[0] << 8 ) |buffer[1]; + PRINT_INFO("size is = [%d]", size); + + if(size == 8) + { + PRINT_INFO("carrier addr is [0x%x]", buffer[2]); + PRINT_INFO("carrier addr is [0x%x]", buffer[3]); + PRINT_INFO("carrier addr is [0x%x]", buffer[4]); + PRINT_INFO("carrier addr is [0x%x]", buffer[5]); + PRINT_INFO("carrier addr is [0x%x]", buffer[6]); + PRINT_INFO("carrier addr is [0x%x]", buffer[7]); + } + else + { + PRINT_INFO("more data -_-;; "); + } + } + else + { + PRINT_INFO("failed to buffer"); + } + } + + } + } + else{ + + PRINT_INFO("parsing is failed"); + + return NET_NFC_TEST_FAIL; + } + + + if(handover_info != NULL){ + if((net_nfc_free_connection_handover_info(handover_info)) == NET_NFC_OK){ + PRINT_INFO("free is good"); + } + else{ + PRINT_INFO("free is failed"); + } + } +#endif + + return test_case_result; +} + +int nfcTestFormatNdef(uint8_t testNumber,void* arg_ptr2) +{ + PRINT_INFO("%s is start", __func__); + + int user_context = 0; + net_nfc_error_e result; + test_case_result = NET_NFC_TEST_FAIL; + + result = net_nfc_initialize(); + + net_nfc_state_activate(1); + + CHECK_RESULT(result); + result = net_nfc_set_response_callback (net_nfc_test_format_cb, (void *)1); + CHECK_RESULT(result); + + PRINT_INSTRUCT("Please close a tag to device!!"); + + //pthread_cond_wait (&pcond,&plock ); + +/* + PRINT_INFO("operation is end"); + + result = net_nfc_unset_response_callback (); + + CHECK_RESULT(result); + result = net_nfc_deinitialize (); + CHECK_RESULT(result); + +*/ + + return test_case_result; +} + +int nfcTestInternalSe(uint8_t testNumber,void* arg_ptr2) +{ + PRINT_INFO("%s is start", __func__); + + int user_context = 0; + net_nfc_error_e result; + test_case_result = NET_NFC_TEST_FAIL; + + result = net_nfc_initialize(); + + net_nfc_state_activate(1); + + CHECK_RESULT(result); + result = net_nfc_set_response_callback (net_nfc_test_se_cb, (void *)1); + CHECK_RESULT(result); + + net_nfc_get_secure_element_type(NULL); + + PRINT_INSTRUCT("Please close a tag to device!!"); + + return test_case_result; +} + + + +int nfcTestReaderMode(uint8_t testNumber,void* arg_ptr2) +{ + PRINT_INFO("%s is start", __func__); + + int user_context = 0; + net_nfc_error_e result; + test_case_result = NET_NFC_TEST_FAIL; + + result = net_nfc_initialize(); + + net_nfc_state_activate(1); + + CHECK_RESULT(result); + result = net_nfc_set_response_callback (net_nfc_test_reader_cb, (void *)1); + CHECK_RESULT(result); + + PRINT_INSTRUCT("Please close a tag to device!!"); + + //pthread_cond_wait (&pcond,&plock ); + +/* + PRINT_INFO("operation is end"); + + result = net_nfc_unset_response_callback (); + + CHECK_RESULT(result); + result = net_nfc_deinitialize (); + CHECK_RESULT(result); + +*/ + + return test_case_result; +} + + +/*=================================================================================*/ + +static void net_nfc_test_write_cb(net_nfc_message_e message, net_nfc_error_e result, void* data, void* user_param, void * trans_data) +{ + int user_context; + + switch(message) + { + case NET_NFC_MESSAGE_TAG_DISCOVERED:{ + net_nfc_target_type_e type; + net_nfc_target_handle_h handle; + bool is_ndef; + net_nfc_target_info_h target_info = (net_nfc_target_info_h)data; + + net_nfc_get_tag_type (target_info, &type); + net_nfc_get_tag_handle (target_info, &handle); + net_nfc_get_tag_ndef_support (target_info, &is_ndef); + PRINT_INFO("target type: %d\n", type); + PRINT_INFO("target id: %X\n", handle); + PRINT_INFO("Is NDEF supoort: %d\n", is_ndef); + + tag_handle = handle; + + if (is_ndef){ + + net_nfc_error_e error = NET_NFC_OK; + ndef_message_h msg = NULL; + ndef_record_h record = NULL; + + if( (error = net_nfc_create_uri_type_record(&record, "http://www.naver.com", NET_NFC_SCHEMA_FULL_URI)) == NET_NFC_OK) + { + if( (error = net_nfc_create_ndef_message(&msg)) == NET_NFC_OK) + { + if( (error = net_nfc_append_record_to_ndef_message(msg, record)) == NET_NFC_OK) + { + ////net_nfc_ndef_print_message(msg); + net_nfc_write_ndef(tag_handle, msg, &user_context); + net_nfc_free_ndef_message(msg); + } + else + { + PRINT_INFO("failed to append ndef message = [%d]", error); + net_nfc_free_record(record); + net_nfc_free_ndef_message(msg); + + pthread_mutex_lock (&plock); + pthread_cond_signal (&pcond); + pthread_mutex_unlock (&plock); + } + } + else + { + PRINT_INFO("failed to create ndef msg"); + net_nfc_free_record(record); + + pthread_mutex_lock (&plock); + pthread_cond_signal (&pcond); + pthread_mutex_unlock (&plock); + } + } + else + { + PRINT_INFO("failed to create text type record"); + + pthread_mutex_lock (&plock); + pthread_cond_signal (&pcond); + pthread_mutex_unlock (&plock); + } + } + else{ + PRINT_INSTRUCT("Please use NDEF formated tag!!"); + break; + } + + break; + } + case NET_NFC_MESSAGE_TAG_DETACHED: + { + if (write_count++ >= 20) { + test_case_result = NET_NFC_TEST_OK; + pthread_mutex_lock (&plock); + pthread_cond_signal (&pcond); + pthread_mutex_unlock (&plock); + } + else { + PRINT_INSTRUCT("Please close a tag to device again!!"); + } + } + break; + + case NET_NFC_MESSAGE_WRITE_NDEF: + { + /*if (result == NET_NFC_OK) { + test_case_result = NET_NFC_TEST_OK; + } + else { + PRINT_INFO("received error: %d\n", result); + test_case_result = NET_NFC_TEST_FAIL; + } + */ + + /* pthread_mutex_lock (&plock); + pthread_cond_signal (&pcond); + pthread_mutex_unlock (&plock); + */ + + if(write_count++ == 20) + { + + PRINT_INSTRUCT("completed, please remove tag"); + } + + { + + net_nfc_error_e error = NET_NFC_OK; + ndef_message_h msg = NULL; + ndef_record_h record = NULL; + + if( (error = net_nfc_create_text_type_record(&record, "This is real NFC", "en-US", NET_NFC_ENCODE_UTF_8)) == NET_NFC_OK) + { + if( (error = net_nfc_create_ndef_message(&msg)) == NET_NFC_OK) + { + if( (error = net_nfc_append_record_to_ndef_message(msg, record)) == NET_NFC_OK) + { + ////net_nfc_ndef_print_message(msg); + net_nfc_write_ndef(tag_handle, msg, &user_context); + net_nfc_free_ndef_message(msg); + } + else + { + PRINT_INFO("failed to append ndef message = [%d]", error); + net_nfc_free_record(record); + net_nfc_free_ndef_message(msg); + test_case_result = NET_NFC_TEST_FAIL; + + pthread_mutex_lock (&plock); + pthread_cond_signal (&pcond); + pthread_mutex_unlock (&plock); + } + } + else + { + PRINT_INFO("failed to create ndef msg"); + net_nfc_free_record(record); + test_case_result = NET_NFC_TEST_FAIL; + + pthread_mutex_lock (&plock); + pthread_cond_signal (&pcond); + pthread_mutex_unlock (&plock); + } + } + else + { + PRINT_INFO("failed to create text type record"); + test_case_result = NET_NFC_TEST_FAIL; + + pthread_mutex_lock (&plock); + pthread_cond_signal (&pcond); + pthread_mutex_unlock (&plock); + + } + } + + break; + } + default: + break; + } +} + + +int nfcTestWriteMode(uint8_t testNumber,void* arg_ptr2) +{ + int user_context = 0; + net_nfc_error_e result; + test_case_result = NET_NFC_TEST_FAIL; + + result = net_nfc_initialize(); + CHECK_RESULT(result); + + net_nfc_state_activate(1); + + result = net_nfc_set_response_callback (net_nfc_test_write_cb, NULL); + CHECK_RESULT(result); + + write_count = 0; + PRINT_INSTRUCT("TEST: remove tag while write"); + PRINT_INSTRUCT("Please close a tag to device!!"); + + //pthread_cond_wait (&pcond,&plock ); + +/* + result = net_nfc_unset_response_callback (); + CHECK_RESULT(result); + result = net_nfc_deinitialize (); + CHECK_RESULT(result); +*/ + return test_case_result; + +} + + +int nfcTestReadWriteMode(uint8_t testNumber,void* arg_ptr2) +{ + int user_context = 0; + net_nfc_error_e result; + test_case_result = NET_NFC_TEST_FAIL; + + read_count = 0; + write_count = 0; + + result = net_nfc_initialize(); + CHECK_RESULT(result); + + net_nfc_state_activate(1); + + result = net_nfc_set_response_callback (net_nfc_test_read_write_cb, NULL); + CHECK_RESULT(result); + + PRINT_INSTRUCT("Testing (50 each) read and write test"); + PRINT_INSTRUCT("Please close a tag to device!!"); + + //pthread_cond_wait (&pcond,&plock ); +/* + result = net_nfc_unset_response_callback (); + CHECK_RESULT(result); + result = net_nfc_deinitialize (); + CHECK_RESULT(result); +*/ + + + return test_case_result; + +} + +/*=================================================================================*/ + +static void net_nfc_test_transceive_cb(net_nfc_message_e message, net_nfc_error_e result, void* data, void* user_param, void * trans_data) +{ + int user_context; + + printf ("callback is called with message %d\n", message); + switch(message) + { + case NET_NFC_MESSAGE_TAG_DISCOVERED:{ + net_nfc_target_type_e type; + net_nfc_target_handle_h id; + bool is_ndef; + net_nfc_target_info_h target_info = (net_nfc_target_info_h)data; + net_nfc_error_e result = NET_NFC_OK; + + net_nfc_get_tag_type (target_info, &type); + net_nfc_get_tag_handle (target_info, &id); + net_nfc_get_tag_ndef_support (target_info, &is_ndef); + PRINT_INFO("target type: %d\n", type); + PRINT_INFO("target id: %X\n", id); + PRINT_INFO("Is NDEF supoort: %d\n", is_ndef); + + tag_handle = id; + + if(type == NET_NFC_MIFARE_ULTRA_PICC){ + + if((result = net_nfc_mifare_read(tag_handle, 0, NULL)) != NET_NFC_OK){ + PRINT_INFO("failed to read = [%d]", result); + } + } + + else if(type >= NET_NFC_MIFARE_MINI_PICC && type <= NET_NFC_MIFARE_4K_PICC){ + + data_h mad_key = NULL; + data_h net_nfc_forum_key = NULL; + data_h default_key = NULL; + + net_nfc_mifare_create_application_directory_key(&mad_key); + net_nfc_mifare_create_net_nfc_forum_key(&net_nfc_forum_key); + net_nfc_mifare_create_default_key(&default_key); + + int sector = 1; + + data_h key = NULL; + test_count = 4; + + if(sector == 0){ + key = mad_key; + } + else{ + key = default_key; +// key = net_nfc_forum_key; + } + +// if(net_nfc_mifare_authenticate_with_keyB(id, sector, key, NULL) != NET_NFC_OK){ + if(net_nfc_mifare_authenticate_with_keyA(id, sector, default_key, NULL) != NET_NFC_OK){ + PRINT_INFO("failed to authenticate sector"); + + } + else{ + + int nBlocks = 0; + + if(type == NET_NFC_MIFARE_4K_PICC && sector > 31){ + + nBlocks = 16; + } + else{ + nBlocks = 4; + } + + +/* + int j = 0; + + for(; j < nBlocks; j++){ + if((result = net_nfc_mifare_read(tag_handle, sector * 4 + j, NULL)) != NET_NFC_OK){ + PRINT_INFO("failed to read = [%d]", result); + }else{ + PRINT_INFO("block [%d] is read", sector * 4 + j); + } + } +*/ +/* + data_h write_block = NULL; + uint8_t buffer[16] = {0x00,}; + uint8_t* temp = buffer; + + int value = 1000; + int value_comp = 1 + ~value; + uint8_t addr = 5; + uint8_t addr_comp = 1 + ~addr; + + + // read block 5 and write block 5 and read again + if((result = net_nfc_mifare_read(tag_handle, addr, NULL)) != NET_NFC_OK){ + PRINT_INFO("failed to read = [%d]", result); + }else{ + PRINT_INFO("block 5 is read"); + } + + // read block 5 and write block 5 and read again + + memcpy(temp, &value, sizeof(int)); + temp = temp + sizeof(int); + + memcpy(temp, &value_comp, sizeof(int)); + temp = temp + sizeof(int); + + memcpy(temp, &value, sizeof(int)); + temp = temp + sizeof(int); + + *temp = addr; + temp = temp + 1; + + *temp = addr_comp; + temp = temp + 1; + + *temp = addr; + temp = temp + 1; + + *temp = addr_comp; + + net_nfc_create_data(&write_block, buffer, 16); + + if((result = net_nfc_mifare_write_block(tag_handle, addr, write_block,NULL)) != NET_NFC_OK){ + PRINT_INFO("failed to write = [%d]", result); + }else{ + PRINT_INFO("block 5 is written"); + } + + if((result = net_nfc_mifare_read(tag_handle, addr, NULL)) != NET_NFC_OK){ + PRINT_INFO("failed to read = [%d]", result); + }else{ + PRINT_INFO("block 5 is read"); + } +*/ + + // read block 6 and decrease 6 and read again + +/* + if((result = net_nfc_mifare_read(tag_handle, 7, NULL)) != NET_NFC_OK){ + PRINT_INFO("failed to read = [%d]", result); + }else{ + PRINT_INFO("read sector trailor of sector 1. it will be a block 7 th"); + } +*/ + +/* + data_h write_block = NULL; + uint8_t buffer[16] = {0x00, 0x00, 0x03, 0xE8, 0xFF, 0xFF, 0xFC, 0x18, 0x00, 0x00, 0x03, 0xE8, 0x05, 0xFB, 0x05, 0xFB}; + + net_nfc_create_data(&write_block, buffer, 16); + + if((result = net_nfc_mifare_write_block(tag_handle, 5, write_block, NULL)) != NET_NFC_OK){ + PRINT_INFO("failed to write = [%d]", result); + }else{ + PRINT_INFO("block 5 is written"); + } + + + if((result = net_nfc_mifare_read(tag_handle, 5, NULL)) != NET_NFC_OK){ + PRINT_INFO("failed to read = [%d]", result); + }else{ + PRINT_INFO("block 5 is read"); + } +*/ + + + if((result = net_nfc_mifare_read(tag_handle, 5, NULL)) != NET_NFC_OK){ + PRINT_INFO("failed to read = [%d]", result); + } + + + int decrease_amount = 10; // 10 won + + if((result = net_nfc_mifare_decrement(tag_handle, 5, decrease_amount, NULL)) != NET_NFC_OK){ + PRINT_INFO("failed to decrease = [%d]", result); + }else{ + PRINT_INFO("block 5 is decreased"); + } + + if((result = net_nfc_mifare_transfer(tag_handle, 5, NULL)) != NET_NFC_OK){ + PRINT_INFO("failed to transfer = [%d]", result); + }else{ + PRINT_INFO("internal register is transfered to block 5"); + } + +/* + if((result = net_nfc_mifare_read(tag_handle, 5, NULL)) != NET_NFC_OK){ + PRINT_INFO("failed to read = [%d]", result); + } +*/ + + net_nfc_free_data(mad_key); + net_nfc_free_data(default_key); + net_nfc_free_data(net_nfc_forum_key); + + } + + + } + else if(type == NET_NFC_JEWEL_PICC){ + + if(net_nfc_jewel_read_id(id, NULL) != NET_NFC_OK){ + PRINT_INFO("failed to read ID"); + } + + test_count = 0; + + }else if(type == NET_NFC_FELICA_PICC){ + + test_count = 4; + net_nfc_error_e result = NET_NFC_OK; + +/* + if((result = net_nfc_felica_poll(id, NET_NFC_FELICA_POLL_COMM_SPEED_REQUEST, 0x0, NULL)) != NET_NFC_OK){ + PRINT_INFO("can not execute cmd felica poll"); + } + else{ + PRINT_INFO("send poll req cmd is success"); + } + + if((result = net_nfc_felica_request_system_code(id, NULL)) != NET_NFC_OK){ + PRINT_INFO("can not execute cmd felica request system code"); + } + else{ + PRINT_INFO("send request system req cmd is success"); + } + + if((result = net_nfc_felica_request_response(id, NULL)) != NET_NFC_OK){ + PRINT_INFO("can not execute cmd felica request response"); + } + else{ + PRINT_INFO("send request response cmd is success"); + } + + uint16_t service_code = 0xffff; + if((result = net_nfc_felica_request_service(id, 1, &service_code, 1, NULL)) != NET_NFC_OK){ + PRINT_INFO("can not execute cmd felica request response"); + } + else{ + PRINT_INFO("send request response cmd is success"); + } +*/ + + uint16_t service_code = 0xffff; + uint8_t blocks = 0x2; + + if((result = net_nfc_felica_read_without_encryption(id, 1, &service_code, 1, &blocks, NULL)) != NET_NFC_OK){ + PRINT_INFO("can not execute cmd felica request response"); + } + else{ + PRINT_INFO("send request response cmd is success"); + } + } + + break; + } + case NET_NFC_MESSAGE_TRANSCEIVE:{ + if (result == NET_NFC_OK) { + + if(test_count == 0){ + int idx; + data_h r_data = (data_h) data; + + uint8_t * r_buffer = net_nfc_get_data_buffer (r_data); + uint32_t r_buffer_length = net_nfc_get_data_length (r_data); + + PRINT_INFO ("read uid is ok. format is = > [HeadRom0][HeadRom1][UID0][UID1][UID2][UID3]"); + PRINT_INFO ("Received data [size:%d] \n", net_nfc_get_data_length (r_data)); + + for (idx = 0; idx < r_buffer_length; idx++){ + printf (" %02X", r_buffer[idx]); + }printf ("\n"); + + PRINT_INFO("READ ALL DATA"); + if((result = net_nfc_jewel_read_all(tag_handle, NULL)) != NET_NFC_OK){ + PRINT_INFO("failed to read all jewel tag = [%d]", result); + } + + test_count = 1; + } + else if(test_count == 1){ + int idx; + data_h r_data = (data_h) data; + + uint8_t * r_buffer = net_nfc_get_data_buffer (r_data); + uint32_t r_buffer_length = net_nfc_get_data_length (r_data); + + PRINT_INFO ("Received data [size:%d] \n", net_nfc_get_data_length (r_data)); + + for (idx = 0; idx < r_buffer_length; idx++){ + printf (" %02X", r_buffer[idx]); + }printf ("\n"); + + test_case_result = NET_NFC_TEST_OK; + + // read UID0 + + PRINT_INFO("READ one byte. addr is the first byte of block 0"); + if((result = net_nfc_jewel_read_byte(tag_handle, 0, 0, NULL)) != NET_NFC_OK){ + PRINT_INFO("failed to read all jewel tag = [%d]", result); + } + + test_count = 2; + + } + else if(test_count == 2){ + int idx; + data_h r_data = (data_h) data; + + uint8_t * r_buffer = net_nfc_get_data_buffer (r_data); + uint32_t r_buffer_length = net_nfc_get_data_length (r_data); + + PRINT_INFO ("Received data [size:%d] \n", net_nfc_get_data_length (r_data)); + + for (idx = 0; idx < r_buffer_length; idx++){ + printf (" %02X", r_buffer[idx]); + }printf ("\n"); + + test_case_result = NET_NFC_TEST_OK; + + // read UID0 + PRINT_INFO("erase and write data 0xff . addr is the first byte of block 1"); + if((result = net_nfc_jewel_write_with_erase(tag_handle, 1, 0, 0xff, NULL)) != NET_NFC_OK){ + PRINT_INFO("failed to read all jewel tag = [%d]", result); + } + + test_count = 3; + } + else if(test_count == 3){ + int idx; + data_h r_data = (data_h) data; + + uint8_t * r_buffer = net_nfc_get_data_buffer (r_data); + uint32_t r_buffer_length = net_nfc_get_data_length (r_data); + + PRINT_INFO ("Received data [size:%d] \n", net_nfc_get_data_length (r_data)); + + for (idx = 0; idx < r_buffer_length; idx++){ + printf (" %02X", r_buffer[idx]); + }printf ("\n"); + + test_case_result = NET_NFC_TEST_OK; + + // read UID0 + PRINT_INFO("read one byte . addr is the first byte of block 1"); + if((result = net_nfc_jewel_read_byte(tag_handle, 1, 0, NULL)) != NET_NFC_OK){ + PRINT_INFO("failed to read all jewel tag = [%d]", result); + } + + test_count = 4; + } + else if(test_count == 4){ + + int idx; + data_h r_data = (data_h) data; + + uint8_t * r_buffer = net_nfc_get_data_buffer (r_data); + uint32_t r_buffer_length = net_nfc_get_data_length (r_data); + + PRINT_INFO ("Received data [size:%d] \n", net_nfc_get_data_length (r_data)); + + for (idx = 0; idx < r_buffer_length; idx++){ + printf (" %02X", r_buffer[idx]); + }printf ("\n"); + } + else if(test_count == 5){ + PRINT_INFO("auth key A is success = [%d]", result); + test_case_result = NET_NFC_TEST_OK; + net_nfc_error_e result = NET_NFC_OK; + /* + if((result = net_nfc_mifare_read(tag_handle, 0, NULL)) != NET_NFC_OK){ + + PRINT_INFO("failed to read = [%d]", result); + }else{ + PRINT_INFO("calling read is ok"); + } + + test_count = 4; + */ + } + } + else { + + PRINT_INFO("trancecive is failed with %d\n", result); + test_case_result = NET_NFC_TEST_FAIL; + + //pthread_mutex_lock (&plock); + //pthread_cond_signal (&pcond); + //pthread_mutex_unlock (&plock); + } + } + + default: + break; + } +} + + +#define NUM_OF_THREAD 10 +#define REQUEST_PER_THREAD 5 + +static number_of_read_completed = 0; + +static void* net_nfc_read_ndef_test(void* handle) +{ + net_nfc_target_handle_h target_handle = (net_nfc_target_handle_h)handle; + int count = 0; + + for (count = 0; count < REQUEST_PER_THREAD ; count ++) + { + if(net_nfc_read_tag(target_handle, NULL) == NET_NFC_OK) + { + PRINT_INFO("send request is success"); + } + else + { + PRINT_INFO("send request is failed"); + } + } + + return (void *)NULL; +} +static void net_nfc_test_multiple_request_cb(net_nfc_message_e message, net_nfc_error_e result, void* data, void* user_param, void * trans_data) +{ + int user_context; + + printf ("callback is called with message %d\n", message); + + switch(message) + { + case NET_NFC_MESSAGE_TAG_DISCOVERED: + { + net_nfc_target_type_e type; + net_nfc_target_handle_h handle; + bool is_ndef; + net_nfc_target_info_h target_info = (net_nfc_target_info_h)data; + + net_nfc_get_tag_type (target_info, &type); + net_nfc_get_tag_handle (target_info, &handle); + net_nfc_get_tag_ndef_support (target_info, &is_ndef); + PRINT_INFO("target type: %d\n", type); + PRINT_INFO("target handle: %X\n", handle); + PRINT_INFO("Is NDEF supoort: %d\n", is_ndef); + + test_case_result = NET_NFC_TEST_OK; + number_of_read_completed = 0; + + pthread_t read_thread[NUM_OF_THREAD]; + pthread_attr_t attr; + pthread_attr_init(&attr); + pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); + + int i =0; + for(; i < NUM_OF_THREAD; i++) + { + pthread_create(&read_thread[i], &attr, net_nfc_read_ndef_test, handle); + } + + } + break; + + case NET_NFC_MESSAGE_READ_NDEF: + { + PRINT_INFO("NET_NFC_MESSAGE_READ_NDEF result = [%d]\n", result); + + if(data != NULL) + { + PRINT_INFO("read ndef msg"); + number_of_read_completed ++; + + ndef_message_h ndef = (ndef_message_h)(data); + + ////net_nfc_ndef_print_message(ndef); + + if (number_of_read_completed == NUM_OF_THREAD * REQUEST_PER_THREAD) + { + test_case_result = NET_NFC_TEST_OK; + PRINT_INSTRUCT("Test is completed. please remove the tag !!"); + } + } + } + break; + + case NET_NFC_MESSAGE_TAG_DETACHED: + { + PRINT_INFO("NET_NFC_MESSAGE_TAG_DETACHED \n"); + + pthread_mutex_lock (&plock); + pthread_cond_signal (&pcond); + pthread_mutex_unlock (&plock); + } + break; + + case NET_NFC_MESSAGE_NOTIFY: + { + PRINT_INFO("NET_NFC_MESSAGE_NOTIFY \n"); + } + break; + + default: + break; + } +} + +#define NUM_OF_DETECT_TRY 10 + +static void net_nfc_test_detected_cb(net_nfc_message_e message, net_nfc_error_e result, void* data, void* user_param, void * trans_data) +{ + int user_context; + + printf ("callback is called with message %d\n", message); + + switch(message) + { + case NET_NFC_MESSAGE_TAG_DISCOVERED: + { + net_nfc_target_type_e type; + net_nfc_target_handle_h id; + bool is_ndef; + net_nfc_target_info_h target_info = (net_nfc_target_info_h)data; + + net_nfc_get_tag_type (target_info, &type); + net_nfc_get_tag_handle (target_info, &id); + net_nfc_get_tag_ndef_support (target_info, &is_ndef); + + PRINT_INFO("target type: %d\n", type); + PRINT_INFO("target handle: %X\n", id); + PRINT_INFO("Is NDEF supoort: %d\n", is_ndef); + + char** keys = NULL; + int nok = 0; // number of keys + net_nfc_error_e error = NET_NFC_OK; + + if((error = net_nfc_get_tag_info_keys(target_info, &keys, &nok)) == NET_NFC_OK) + { + int i = 0; + for(; i < nok; i++) + { + PRINT_INFO("key [%s]", keys[i]); + + data_h value = NULL; + if((error = net_nfc_get_tag_info_value(target_info, keys[i], &value)) == NET_NFC_OK) + { + int index = 0; + uint32_t data_length = net_nfc_get_data_length(value); + uint8_t* data_buffer = net_nfc_get_data_buffer(value); + + PRINT_INFO("\n key >> ", keys[i]); + if(data_length > 1) + { + for(; index < data_length; index++) + { + printf(" [0x%x] ", data_buffer[index]); + } + } + else + { + printf(" [0x%x] ", *data_buffer); + } + + + PRINT_INFO("<< \n"); + } + else + { + PRINT_INFO("get value is failed = [0x%x]", error); + } + } + } + else + { + PRINT_INFO("failed to get keys = [%d]", error); + } + + free(keys); + + + detect_count++; + + PRINT_INFO("TAG is detected = [%d]", detect_count); + PRINT_INSTRUCT("please remove the tag !! Test left [%d] times", NUM_OF_DETECT_TRY - detect_count); + + } + break; + + case NET_NFC_MESSAGE_TAG_DETACHED: + { + PRINT_INSTRUCT("please close the tag again!!"); + + //pthread_mutex_lock (&plock); + //pthread_cond_signal (&pcond); + //pthread_mutex_unlock (&plock); + + if(detect_count >= NUM_OF_DETECT_TRY) + { + test_case_result = NET_NFC_TEST_OK; + pthread_mutex_lock (&plock); + pthread_cond_signal (&pcond); + pthread_mutex_unlock (&plock); + } + } + break; + + case NET_NFC_MESSAGE_NOTIFY: + { + PRINT_INFO("NET_NFC_MESSAGE_NOTIFY \n"); + } + break; + + default: + break; + } +} + + +static void* net_nfc_read_stress_ndef_test(void* handle) +{ + net_nfc_target_handle_h target_handle = (net_nfc_target_handle_h)handle; + int count = 0; + + for (count = 0; count < 200 ; count ++) + { + if(net_nfc_read_tag(target_handle, NULL) == NET_NFC_OK) + { + } + else + { + PRINT_INFO("send request is failed"); + } + } + + PRINT_INFO("send request is completed"); + + return (void *)NULL; +} + +static void net_nfc_test_read_cb(net_nfc_message_e message, net_nfc_error_e result, void* data, void* user_param, void * trans_data) +{ + int user_context; + + switch(message) + { + case NET_NFC_MESSAGE_TAG_DISCOVERED: + { + net_nfc_target_type_e type; + net_nfc_target_handle_h handle; + bool is_ndef; + net_nfc_target_info_h target_info = (net_nfc_target_info_h)data; + + net_nfc_get_tag_type (target_info, &type); + net_nfc_get_tag_handle (target_info, &handle); + net_nfc_get_tag_ndef_support (target_info, &is_ndef); + PRINT_INFO("target type: %d\n", type); + PRINT_INFO("target handle: %X\n", handle); + PRINT_INFO("Is NDEF supoort: %d\n", is_ndef); + + if(is_ndef) + { + pthread_t read_thread; + pthread_attr_t attr; + pthread_attr_init(&attr); + pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); + + pthread_create(&read_thread, &attr, net_nfc_read_stress_ndef_test, handle); + } + else + { + PRINT_INFO("non ndef tag."); + + test_case_result = NET_NFC_TEST_FAIL; + + pthread_mutex_lock (&plock); + pthread_cond_signal (&pcond); + pthread_mutex_unlock (&plock); + } + + } + break; + + case NET_NFC_MESSAGE_READ_NDEF: + { + if(data != NULL){ + + ndef_message_h ndef = (ndef_message_h)(data); + + ////net_nfc_ndef_print_message(ndef); + + test_case_result = NET_NFC_TEST_OK; + + read_count++; + } + + if(read_count == 20) + { + PRINT_INSTRUCT("please remove the tag !!"); + } + + break; + } + break; + + case NET_NFC_MESSAGE_TAG_DETACHED: + { + PRINT_INFO("NET_NFC_MESSAGE_TAG_DETACHED \n"); + + if (read_count >= 20 && read_count < 200){ + test_case_result = NET_NFC_TEST_OK; + pthread_mutex_lock (&plock); + pthread_cond_signal (&pcond); + pthread_mutex_unlock (&plock); + } + else { + PRINT_INSTRUCT("please close the tag again !!"); + } + + + } + break; + + case NET_NFC_MESSAGE_NOTIFY: + { + PRINT_INFO("NET_NFC_MESSAGE_NOTIFY \n"); + } + break; + + default: + break; + } +} + + +static void net_nfc_test_read_write_cb(net_nfc_message_e message, net_nfc_error_e result, void* data, void* user_param, void * trans_data) +{ + int user_context; + + printf ("callback is called with message %d\n", message); + + switch(message) + { + case NET_NFC_MESSAGE_TAG_DISCOVERED: + { + net_nfc_target_type_e type; + net_nfc_target_handle_h handle; + bool is_ndef; + net_nfc_target_info_h target_info = (net_nfc_target_info_h)data; + + net_nfc_get_tag_type (target_info, &type); + net_nfc_get_tag_handle (target_info, &handle); + net_nfc_get_tag_ndef_support (target_info, &is_ndef); + PRINT_INFO("target type: %d\n", type); + PRINT_INFO("target handle: %X\n", handle); + PRINT_INFO("Is NDEF supoort: %d\n", is_ndef); + + if(is_ndef) + { + tag_handle = handle; + if(net_nfc_read_tag(handle, user_param) == NET_NFC_OK) + { + PRINT_INFO("try to read ndef"); + } + } + else + { + PRINT_INFO("non ndef tag."); + + test_case_result = NET_NFC_TEST_FAIL; + + pthread_mutex_lock (&plock); + pthread_cond_signal (&pcond); + pthread_mutex_unlock (&plock); + } + + } + break; + + case NET_NFC_MESSAGE_READ_NDEF: + { + if (write_count >= 50){ + PRINT_INSTRUCT("Test is finished. Please remove the tag from device!!"); + test_case_result = NET_NFC_TEST_OK; + break; + } + if(data != NULL){ + + ndef_message_h ndef = (ndef_message_h)(data); + + ////net_nfc_ndef_print_message(ndef); + + test_case_result = NET_NFC_TEST_OK; + + net_nfc_error_e error = NET_NFC_OK; + ndef_message_h msg = NULL; + ndef_record_h record = NULL; + + if( (error = net_nfc_create_text_type_record(&record, "This is real NFC", "en-US", NET_NFC_ENCODE_UTF_8)) == NET_NFC_OK) + { + if( (error = net_nfc_create_ndef_message(&msg)) == NET_NFC_OK) + { + if( (error = net_nfc_append_record_to_ndef_message(msg, record)) == NET_NFC_OK) + { + ////net_nfc_ndef_print_message(msg); + + if(net_nfc_write_ndef(tag_handle, msg, &user_context) == NET_NFC_OK) + { + PRINT_INFO("write count = [%d] \n", write_count++); + PRINT_INFO("write ndef msg"); + } + net_nfc_free_ndef_message(msg); + } + else + { + PRINT_INFO("failed to append ndef message = [%d]", error); + net_nfc_free_record(record); + net_nfc_free_ndef_message(msg); + + pthread_mutex_lock (&plock); + pthread_cond_signal (&pcond); + pthread_mutex_unlock (&plock); + } + } + else + { + PRINT_INFO("failed to create ndef msg"); + net_nfc_free_record(record); + + pthread_mutex_lock (&plock); + pthread_cond_signal (&pcond); + pthread_mutex_unlock (&plock); + } + } + else + { + PRINT_INFO("failed to create text type record"); + + pthread_mutex_lock (&plock); + pthread_cond_signal (&pcond); + pthread_mutex_unlock (&plock); + + } + + } + else + { + test_case_result = NET_NFC_TEST_FAIL; + + pthread_mutex_lock (&plock); + pthread_cond_signal (&pcond); + pthread_mutex_unlock (&plock); + + break; + } + + //net_nfc_read_ndef(tag_handle, user_param); + + break; + } + break; + + case NET_NFC_MESSAGE_WRITE_NDEF: + { + if (result == NET_NFC_OK) { + + test_case_result = NET_NFC_TEST_OK; + + if(net_nfc_read_tag(tag_handle, user_param) == NET_NFC_OK) + { + PRINT_INFO("read count = [%d] \n", read_count++); + PRINT_INFO("try to read ndef"); + } + } + else { + PRINT_INFO("received error: %d\n", result); + test_case_result = NET_NFC_TEST_FAIL; + + pthread_mutex_lock (&plock); + pthread_cond_signal (&pcond); + pthread_mutex_unlock (&plock); + } + } + break; + + case NET_NFC_MESSAGE_TAG_DETACHED: + { + PRINT_INFO("NET_NFC_MESSAGE_TAG_DETACHED \n"); + + pthread_mutex_lock (&plock); + pthread_cond_signal (&pcond); + pthread_mutex_unlock (&plock); + } + break; + + case NET_NFC_MESSAGE_NOTIFY: + { + PRINT_INFO("NET_NFC_MESSAGE_NOTIFY \n"); + } + break; + + default: + break; + } +} + + +int nfcTestAPIMultipleRequest(uint8_t testNumber,void* arg_ptr2) +{ + int user_context = 0; + net_nfc_error_e result; + test_case_result = NET_NFC_TEST_FAIL; + + result = net_nfc_initialize(); + CHECK_RESULT(result); + + net_nfc_state_activate(1); + + result = net_nfc_set_response_callback (net_nfc_test_multiple_request_cb, NULL); + CHECK_RESULT(result); + + PRINT_INSTRUCT("Please close a tag to device for a while!!"); + + //pthread_cond_wait (&pcond,&plock ); +/* + result = net_nfc_unset_response_callback (); + CHECK_RESULT(result); + + result = net_nfc_deinitialize (); + CHECK_RESULT(result); +*/ + return test_case_result; +} + + +int nfcTestAPIBasicTest1(uint8_t testNumber,void* arg_ptr2) +{ + int user_context = 0; + net_nfc_error_e result; + test_case_result = NET_NFC_TEST_FAIL; + + int length = 0; + +/* + char** keys = NULL; + + int i = 0; + + for(i; i < NET_NFC_NFCIP1_INITIATOR; i++) + { + if(net_nfc_get_tag_info_keys(i, &keys, &length) == NET_NFC_OK) + { + int index = 0; + + PRINT_INFO("############################\n") ; + for(; index < length; index++) + { + PRINT_INFO("supported key = [%s] \n", keys[index]); + } + PRINT_INFO("############################\n") ; + + test_case_result = NET_NFC_TEST_OK; + } + } +*/ + + result = net_nfc_initialize(); + CHECK_RESULT(result); + + net_nfc_state_activate(1); + + result = net_nfc_set_response_callback (net_nfc_test_detected_cb, NULL); + +// net_nfc_set_tag_filter(NET_NFC_ALL_DISABLE); +// net_nfc_set_tag_filter(NET_NFC_ISO14443A_ENABLE); +// net_nfc_set_tag_filter(NET_NFC_ISO14443B_ENABLE); +// net_nfc_set_tag_filter(NET_NFC_ISO15693_ENABLE ); +// net_nfc_set_tag_filter(NET_NFC_FELICA_ENABLE ); +// net_nfc_set_tag_filter(NET_NFC_JEWEL_ENABLE ); +// net_nfc_set_tag_filter(NET_NFC_ALL_ENABLE ); + + + CHECK_RESULT(result); + + //PRINT_INSTRUCT("Please close a tag to device!!"); + + //pthread_cond_wait (&pcond,&plock ); + +/* + result = net_nfc_unset_response_callback (); + CHECK_RESULT(result); + + result = net_nfc_deinitialize (); + + sleep(1000); + + CHECK_RESULT(result); +*/ + + return test_case_result; +} + +int nfcTestAPIBasicTest2(uint8_t testNumber,void* arg_ptr2) +{ + int user_context = 0; + net_nfc_error_e result; + test_case_result = NET_NFC_TEST_FAIL; + + result = net_nfc_initialize(); + CHECK_RESULT(result); + + net_nfc_state_activate(1); + + read_count = 0; + + result = net_nfc_set_response_callback (net_nfc_test_read_cb, NULL); + CHECK_RESULT(result); + + PRINT_INSTRUCT("remove tag while reading operation !!"); + PRINT_INSTRUCT("Please close a tag to device!!"); + +/* + pthread_cond_wait (&pcond,&plock ); + + result = net_nfc_unset_response_callback (); + CHECK_RESULT(result); + + result = net_nfc_deinitialize (); + CHECK_RESULT(result); +*/ + return test_case_result; +} + +int nfcTestAPIBasicTest3(uint8_t testNumber,void* arg_ptr2) +{ + int user_context = 0; + net_nfc_error_e result; + test_case_result = NET_NFC_TEST_FAIL; + + ndef_message_h ndef_message = NULL; + + if(net_nfc_retrieve_current_ndef_message(&ndef_message) == NET_NFC_OK) + { + int count = 0; + if(net_nfc_get_ndef_message_record_count(ndef_message, &count) == NET_NFC_OK) + { + int i = 0; + for(; i < count; i++) + { + ndef_record_h record = NULL; + if(net_nfc_get_record_by_index(ndef_message, i, &record) == NET_NFC_OK) + { + net_nfc_record_tnf_e tnf; + if(net_nfc_get_record_tnf(record, &tnf) == NET_NFC_OK) + { + switch(tnf) + { + case NET_NFC_RECORD_WELL_KNOWN_TYPE: + { + data_h type = NULL; + data_h payload = NULL; + + if(net_nfc_get_record_type(record, &type) == NET_NFC_OK && net_nfc_get_record_payload(record, &payload) == NET_NFC_OK) + { + if(strcmp(net_nfc_get_data_buffer(type), "Sp") == 0) + { + + } + else if(strcmp(net_nfc_get_data_buffer(type), "T") == 0) + { + + net_nfc_encode_type_e utf; + uint32_t utf_length = 0; + uint32_t lang_length = 0; + char* text = NULL; + uint32_t text_length = 0; + char* language_code_str = NULL; + + if(net_nfc_get_encoding_type_from_text_record(record, &utf) == NET_NFC_OK) + { + PRINT_INFO("utf = [%s]", utf); + } + else + { + PRINT_INFO("failed to get utf"); + } + + if(net_nfc_get_languange_code_string_from_text_record(record, &language_code_str) == NET_NFC_OK) + { + PRINT_INFO("language_code = [%s]", language_code_str); + } + else + { + PRINT_INFO("failed to get language code"); + } + + if(net_nfc_create_text_string_from_text_record(record, &text) == NET_NFC_OK) + { + PRINT_INFO("text = [%s]", text); + } + else + { + PRINT_INFO("failed to get text"); + } + + if(text != NULL) + free(text); +/* + uint8_t* utf = NULL; + uint8_t* language_code = NULL; + uint8_t* text = NULL; + int index = 0; + + uint8_t* buffer = net_nfc_get_data_buffer(payload); + uint32_t buffer_length = net_nfc_get_data_length(payload); + + PRINT_INFO("\n from file >>>"); + + for(; index < buffer_length; index++) + { + printf(" [%d] ", buffer[index]); + } + + PRINT_INFO("\n from file <<<"); + + index = 0; + + int controllbyte = buffer[0]; + + if((controllbyte & 0x80)== 1) + { + PRINT_INFO("UTF-16"); + utf = (uint8_t*)"UTF-16"; + } + else + { + PRINT_INFO("UTF-8"); + utf = (uint8_t*)"UTF-8"; + } + + int lang_code_length = controllbyte & 0x3F; + + index = 1; + + language_code = (uint8_t *)malloc(lang_code_length + 1); + + memset(language_code, 0x00, lang_code_length + 1); + memcpy(language_code, &(buffer[index]), lang_code_length); + + PRINT_INFO("lang_code = [%s]", language_code); + + index = lang_code_length + 1; + + int text_length = buffer_length - (lang_code_length + 1); // payload length - (lang code length + control byte) + + PRINT_INFO("buffer length = [%d]", buffer_length); + PRINT_INFO("lang_code_length = [%d]", lang_code_length); + PRINT_INFO("text_length = [%d]", text_length); + + text = (uint8_t *)malloc(text_length + 1); + + memset(text, 0x00, text_length + 1); + memcpy(text, &(buffer[index]), text_length); + + PRINT_INFO("encoding type = [%s]", utf); + PRINT_INFO("lang_code = [%s]", language_code); + PRINT_INFO("text = [%s]", text); + test_case_result = NET_NFC_TEST_OK; +*/ + } + else if(strcmp(net_nfc_get_data_buffer(type), "U") == 0) + { + + } + else + { + + } + } + + } + break; + + default: + PRINT_INFO("unknow type"); + break; + } + } + } + } + } + } + + + CHECK_RESULT(result); + + return test_case_result; +} + +int nfcTestTransceive(uint8_t testNumber,void* arg_ptr2) +{ + int user_context = 0; + net_nfc_error_e result; + test_case_result = NET_NFC_TEST_FAIL; + + result = net_nfc_initialize(); + CHECK_RESULT(result); + + net_nfc_state_activate(1); + + result = net_nfc_set_response_callback (net_nfc_test_transceive_cb, NULL); + CHECK_RESULT(result); + + PRINT_INSTRUCT("Please close a tag to device!!"); + + //pthread_cond_wait (&pcond,&plock ); + /* + result = net_nfc_unset_response_callback (); + CHECK_RESULT(result); + result = net_nfc_deinitialize (); + CHECK_RESULT(result); + */ + + return test_case_result; +} + +/*=================================================================================*/ + + +int nfcTestNdefParser(uint8_t testNumber,void* arg_ptr2) +{ + net_nfc_error_e result; + + ndef_message_h uriMsg = NULL; + ndef_message_h spMsg = NULL; + ndef_record_h uriRecord = NULL; + ndef_record_h spRecord = NULL; + data_h type_data = NULL; + data_h raw_data = NULL; + char smart_poster_type[] = "Sp"; + ndef_record_h record = NULL; + test_case_result = NET_NFC_TEST_OK; + + result = net_nfc_create_ndef_message (&uriMsg); + CHECK_RESULT(result); + + result = net_nfc_create_uri_type_record (&record ,"http://www.naver.com", NET_NFC_SCHEMA_FULL_URI); + CHECK_RESULT(result); + + result = net_nfc_append_record_to_ndef_message (uriMsg, record); + CHECK_RESULT(result); + + uriRecord = record; + + result = net_nfc_create_text_type_record (&record ,"This is the URI Test" ,"en-US" ,NET_NFC_ENCODE_UTF_8); + CHECK_RESULT(result); + + result = net_nfc_append_record_to_ndef_message (uriMsg, record); + CHECK_RESULT(result); + + result = net_nfc_create_text_type_record (&record ,"Hello World" ,"en-US" ,NET_NFC_ENCODE_UTF_8); + CHECK_RESULT(result); + + result = net_nfc_append_record_by_index (uriMsg,0 ,record); + CHECK_RESULT(result); + + result = net_nfc_create_text_type_record (&record ,"TEST1" ,"en-US" ,NET_NFC_ENCODE_UTF_8); + CHECK_RESULT(result); + + result = net_nfc_append_record_by_index (uriMsg,1 ,record); + CHECK_RESULT(result); + + result = net_nfc_create_text_type_record (&record ,"TEST2" ,"en-US" ,NET_NFC_ENCODE_UTF_8); + CHECK_RESULT(result); + + result = net_nfc_append_record_by_index (uriMsg,2 ,record); + CHECK_RESULT(result); + + result = net_nfc_create_text_type_record (&record ,"TEST3" ,"en-US" ,NET_NFC_ENCODE_UTF_8); + CHECK_RESULT(result); + + int position; + result = net_nfc_get_ndef_message_record_count (uriMsg,&position); + CHECK_RESULT(result); + + result = net_nfc_append_record_by_index (uriMsg, position ,record); + CHECK_RESULT(result); + + //_//net_nfc_ndef_print_message (uriMsg); + + result = net_nfc_create_data (&type_data ,"U", 1); + CHECK_RESULT(result); + + result = net_nfc_search_record_by_type (uriMsg ,NET_NFC_RECORD_WELL_KNOWN_TYPE ,type_data ,&record); + CHECK_RESULT(result); + if (record != uriRecord){ + PRINT_RESULT_FAIL("Record search result does not matched"); + return NET_NFC_TEST_FAIL; + } + + result = net_nfc_remove_record_by_index (uriMsg ,1); + CHECK_RESULT(result); + + result = net_nfc_remove_record_by_index (uriMsg ,0); + CHECK_RESULT(result); + + result = net_nfc_get_ndef_message_record_count (uriMsg,&position); + CHECK_RESULT(result); + + result = net_nfc_remove_record_by_index (uriMsg, position - 1); + CHECK_RESULT(result); + + result = net_nfc_remove_record_by_index (uriMsg ,2); + CHECK_RESULT(result); + + //_//net_nfc_ndef_print_message (uriMsg); + + result = net_nfc_create_rawdata_from_ndef_message (uriMsg, &raw_data); + CHECK_RESULT(result); + + result = net_nfc_create_data (&type_data, smart_poster_type, strlen (smart_poster_type)); + CHECK_RESULT(result); + + result = net_nfc_create_record (&spRecord, NET_NFC_RECORD_WELL_KNOWN_TYPE,type_data , NULL, raw_data); + CHECK_RESULT(result); + + result = net_nfc_create_ndef_message (&spMsg); + CHECK_RESULT(result); + + result = net_nfc_append_record_to_ndef_message (spMsg, spRecord); + CHECK_RESULT(result); + + net_nfc_free_data (type_data); + net_nfc_free_data (raw_data); + + return test_case_result; +} + +/*=================================================================================*/ + +net_nfc_llcp_socket_t server_socket; +net_nfc_llcp_socket_t accepted_socket; +net_nfc_llcp_socket_t client_socket; + +static void net_nfc_client_socket_cb (net_nfc_llcp_message_e message, net_nfc_error_e result, void * data, void * user_data, void * trans_data) +{ + PRINT_INFO ("\nCLIENT callback is called MESSAGE[%d]", message); + int x; + switch (message) + { + case NET_NFC_MESSAGE_LLCP_LISTEN: + break; + case NET_NFC_MESSAGE_LLCP_ACCEPTED: + break; + case NET_NFC_MESSAGE_LLCP_CONNECT: + { + PRINT_INFO ("LLCP connect is completed with error code %d", result); + data_h data; + char * str = "Client message: Hello, server!"; + net_nfc_create_data (&data, str ,strlen (str) + 1); + net_nfc_send_llcp (client_socket, data, NULL); + } + break; + case NET_NFC_MESSAGE_LLCP_CONNECT_SAP: + break; + case NET_NFC_MESSAGE_LLCP_SEND: + { + PRINT_INFO ("LLCP send is completed with error code %d", result); + net_nfc_receive_llcp (client_socket, 512 ,NULL); + } + break; + + case NET_NFC_MESSAGE_LLCP_RECEIVE: + PRINT_INFO ("LLCP receive is completed with error code %d", result); + data_h received_data = (data_h) data; + PRINT_INFO ("Server --> Client : %s" , net_nfc_get_data_buffer (received_data)); + + net_nfc_disconnect_llcp (client_socket ,NULL); + break; + case NET_NFC_MESSAGE_LLCP_DISCONNECT: + { + PRINT_INFO ("LLCP disconnect is completed with error code %d", result); + net_nfc_close_llcp_socket (client_socket, NULL); + } + break; + case NET_NFC_MESSAGE_LLCP_ERROR: + PRINT_INFO ("LLCP socket error is completed with error code %d", result); + net_nfc_close_llcp_socket (client_socket, NULL); + break; + default: + break; + } + +} + + +static void net_nfc_server_socket_cb (net_nfc_llcp_message_e message, net_nfc_error_e result, void * data, void * user_data, void * trans_data) +{ + PRINT_INFO ("\nSERVER callback is called MESSAGE[%d]", message); + switch (message) + { + case NET_NFC_MESSAGE_LLCP_LISTEN: + { + PRINT_INFO ("LLCP Listen is completed with error code %d", result); + } + break; + + case NET_NFC_MESSAGE_LLCP_ACCEPTED: + { + PRINT_INFO ("LLCP accept is completed with error code %d", result); + accepted_socket = *(net_nfc_llcp_socket_t *)(data); + net_nfc_set_llcp_socket_callback (accepted_socket, net_nfc_server_socket_cb, NULL); + net_nfc_receive_llcp (accepted_socket, 512 ,NULL); + } + break; + case NET_NFC_MESSAGE_LLCP_CONNECT: + break; + case NET_NFC_MESSAGE_LLCP_CONNECT_SAP: + break; + case NET_NFC_MESSAGE_LLCP_SEND: + { + PRINT_INFO ("LLCP send is completed with error code %d", result); + net_nfc_disconnect_llcp (accepted_socket ,NULL); + } + break; + + case NET_NFC_MESSAGE_LLCP_RECEIVE: + { + PRINT_INFO ("LLCP receive is completed with error code %d", result); + data_h received_data = (data_h) data; + PRINT_INFO ("Server <-- Client : %s" , net_nfc_get_data_buffer (received_data)); + + data_h data; + char * str = "Server message: Welcome NFC llcp world!"; + net_nfc_create_data (&data, str ,strlen (str) + 1); + net_nfc_send_llcp (accepted_socket, data, NULL); + } + break; + + case NET_NFC_MESSAGE_LLCP_DISCONNECT: + { + PRINT_INFO ("LLCP disconnect is completed with error code %d", result); + net_nfc_close_llcp_socket (accepted_socket, NULL); + } + break; + case NET_NFC_MESSAGE_LLCP_ERROR: + { + PRINT_INFO ("LLCP socket error is received with code %d", result); + net_nfc_close_llcp_socket (accepted_socket, NULL); + net_nfc_close_llcp_socket (server_socket, NULL); + } + break; + default: + break; + } +} + +net_nfc_target_handle_h snep_handle; +net_nfc_exchanger_data_h snep_ex_data = NULL; +int temp_count; + +static void net_nfc_test_snep_cb(net_nfc_message_e message, net_nfc_error_e result, void* data, void* user_param, void * trans_data) +{ + PRINT_INFO ("client message received [%d]", message); + + switch (message) { +#if 0 + case NET_NFC_MESSAGE_P2P_DISCOVERED: + { + snep_handle = (net_nfc_target_handle_h) data; + //= (net_nfc_target_handle_h) target_info->handle; + /* Fill the data to send. */ + + if(NET_NFC_OK == net_nfc_create_exchanger_data(&snep_ex_data, nfcTestUri)) + { + if(net_nfc_send_exchanger_data(snep_ex_data, snep_handle) == NET_NFC_OK) + { + PRINT_INFO ("exchanger data send success"); + } + else + { + PRINT_INFO ("exchanger data send fail"); + } + } + else + { + PRINT_INFO ("create exchanger data fail"); + } + + } + break; +#endif + case NET_NFC_MESSAGE_P2P_SEND: + { + PRINT_INFO ("NET_NFC_MESSAGE_P2P_SEND result [%d]", result); + + } + break; + + case NET_NFC_MESSAGE_P2P_DETACHED: + { + PRINT_INFO ("Target disconnected."); + temp_count = 0; + } + break; + + case NET_NFC_MESSAGE_P2P_RECEIVE: + { +// int i; +// data_h received_data = (data_h)data; + +// PRINT_INFO ("NET_NFC_MESSAGE_P2P_RECEIVE [%s]", net_nfc_get_data_buffer(received_data)); +// PRINT_INFO (" length [%d]", net_nfc_get_data_length(received_data)); + } + break; + + default: + break; + } +} + +static void net_nfc_test_llcp_cb(net_nfc_message_e message, net_nfc_error_e result, void* data, void* user_param, void * trans_data) +{ + // do nothing + switch (message) { + case NET_NFC_MESSAGE_LLCP_DISCOVERED: + { + net_nfc_llcp_config_info_h config = (net_nfc_llcp_config_info_h) data; + uint8_t lto, option; + uint16_t wks, miu; + net_nfc_get_llcp_configure_lto (config , <o); + net_nfc_get_llcp_configure_wks (config , &wks); + net_nfc_get_llcp_configure_miu (config , &miu); + net_nfc_get_llcp_configure_option (config , &option); + + PRINT_INFO ("Remote Device llcp info:\n \tlto: %d, \twks: %d, \tmiu: %d, \toption: %d", lto, wks, miu, option); + + net_nfc_create_llcp_socket (&server_socket, NULL); + net_nfc_set_llcp_socket_callback (server_socket, net_nfc_server_socket_cb, NULL); + net_nfc_listen_llcp (server_socket, "urn:nfc:xsn:samsung.com:testllcp" ,16 ,NULL); + + net_nfc_create_llcp_socket (&client_socket, NULL); + net_nfc_set_llcp_socket_callback (client_socket, net_nfc_client_socket_cb, NULL); + net_nfc_connect_llcp (client_socket,"urn:nfc:xsn:samsung.com:testllcp",NULL); + } + break; + + case NET_NFC_MESSAGE_LLCP_CONFIG: + { + PRINT_INFO ("LLCP llcp local config is completed with error code %d", result); + } + break; + + case NET_NFC_MESSAGE_P2P_DETACHED: + { + PRINT_INFO ("LLCP NET_NFC_MESSAGE_P2P_DETACHED %d", result); + } + break; + + default: + break; + } +} + +int nfcTestSnep(uint8_t testNumber,void* arg_ptr) +{ + net_nfc_error_e result; + + result = net_nfc_initialize(); + CHECK_RESULT(result); + net_nfc_state_activate (1); + result = net_nfc_set_response_callback (net_nfc_test_snep_cb, NULL); + + PRINT_INSTRUCT("START SNEP test !!"); + return NET_NFC_TEST_OK; +} + +int nfcTestLLCP(uint8_t testNumber,void* arg_ptr2) +{ + net_nfc_error_e result; + net_nfc_llcp_config_info_h config; + result = net_nfc_initialize(); + CHECK_RESULT(result); + net_nfc_state_activate (1); + result = net_nfc_set_response_callback (net_nfc_test_llcp_cb, NULL); + CHECK_RESULT(result); + result = net_nfc_create_llcp_configure_default (&config); + CHECK_RESULT(result); + result = net_nfc_set_llcp_local_configure (config ,NULL); + + PRINT_INSTRUCT("Please start P2P communicate!!"); + +/* + pthread_cond_wait (&pcond,&plock ); + + result = net_nfc_unset_response_callback (); + CHECK_RESULT(result); + result = net_nfc_deinitialize (); + CHECK_RESULT(result); +*/ + + return NET_NFC_TEST_OK; +} + +/*=================================================================================*/ + +/* LLCP Stress Test */ + +net_nfc_llcp_socket_t server_socket; +net_nfc_llcp_socket_t client_socket; + +static void net_nfc_client_stress_socket_cb (net_nfc_llcp_message_e message, net_nfc_error_e result, void * data, void * user_data, void * trans_data) +{ + PRINT_INFO ("\nCLIENT callback is called MESSAGE[%d]", message); + int x; + switch (message) + { + case NET_NFC_MESSAGE_LLCP_LISTEN: + break; + case NET_NFC_MESSAGE_LLCP_ACCEPTED: + break; + case NET_NFC_MESSAGE_LLCP_CONNECT: + { + PRINT_INFO ("LLCP connect is completed with error code %d", result); + data_h data; + char * str = "Client message: Hello, server!"; + net_nfc_create_data (&data, str ,strlen (str) + 1); + net_nfc_send_llcp (client_socket, data, NULL); + } + break; + case NET_NFC_MESSAGE_LLCP_CONNECT_SAP: + break; + case NET_NFC_MESSAGE_LLCP_SEND: + { + PRINT_INFO ("LLCP send is completed with error code %d", result); + net_nfc_receive_llcp (client_socket, 512 ,NULL); + } + break; + + case NET_NFC_MESSAGE_LLCP_RECEIVE: + PRINT_INFO ("LLCP receive is completed with error code %d", result); + data_h received_data = (data_h) data; + PRINT_INFO ("Server --> Client : %s" , net_nfc_get_data_buffer (received_data)); + + net_nfc_disconnect_llcp (client_socket ,NULL); + break; + case NET_NFC_MESSAGE_LLCP_DISCONNECT: + { + PRINT_INFO ("LLCP disconnect is completed with error code %d", result); + net_nfc_close_llcp_socket (client_socket, NULL); + } + break; + case NET_NFC_MESSAGE_LLCP_ERROR: + PRINT_INFO ("LLCP socket error is completed with error code %d", result); + net_nfc_close_llcp_socket (client_socket, NULL); + break; + default: + break; + } + +} + + +static void net_nfc_server_stress_socket_cb (net_nfc_llcp_message_e message, net_nfc_error_e result, void * data, void * user_data, void * trans_data) +{ + PRINT_INFO ("\nSERVER callback is called MESSAGE[%d]", message); + switch (message) + { + case NET_NFC_MESSAGE_LLCP_LISTEN: + { + PRINT_INFO ("LLCP Listen is completed with error code %d", result); + } + break; + + case NET_NFC_MESSAGE_LLCP_ACCEPTED: + { + PRINT_INFO ("LLCP accept is completed with error code %d", result); + net_nfc_receive_llcp (server_socket, 512 ,NULL); + } + break; + case NET_NFC_MESSAGE_LLCP_CONNECT: + break; + case NET_NFC_MESSAGE_LLCP_CONNECT_SAP: + break; + case NET_NFC_MESSAGE_LLCP_SEND: + { + PRINT_INFO ("LLCP send is completed with error code %d", result); + net_nfc_disconnect_llcp (server_socket ,NULL); + } + break; + + case NET_NFC_MESSAGE_LLCP_RECEIVE: + { + PRINT_INFO ("LLCP receive is completed with error code %d", result); + data_h received_data = (data_h) data; + PRINT_INFO ("Server <-- Client : %s" , net_nfc_get_data_buffer (received_data)); + + data_h data; + char * str = "Server message: Welcome NFC llcp world!"; + net_nfc_create_data (&data, str ,strlen (str) + 1); + net_nfc_send_llcp (server_socket, data, NULL); + } + break; + + case NET_NFC_MESSAGE_LLCP_DISCONNECT: + { + PRINT_INFO ("LLCP disconnect is completed with error code %d", result); + net_nfc_close_llcp_socket (server_socket, NULL); + } + break; + + case NET_NFC_MESSAGE_LLCP_ERROR: + { + PRINT_INFO ("LLCP socket error is received with code %d", result); + net_nfc_close_llcp_socket (server_socket, NULL); + } + break; + default: + break; + } +} + +static void net_nfc_test_llcp_stress_cb(net_nfc_message_e message, net_nfc_error_e result, void* data, void* user_param, void * trans_data) +{ + // do nothing + switch (message) { + case NET_NFC_MESSAGE_LLCP_DISCOVERED: + { + net_nfc_llcp_config_info_h config = (net_nfc_llcp_config_info_h) data; + uint8_t lto, option; + uint16_t wks, miu; + net_nfc_get_llcp_configure_lto (config , <o); + net_nfc_get_llcp_configure_wks (config , &wks); + net_nfc_get_llcp_configure_miu (config , &miu); + net_nfc_get_llcp_configure_option (config , &option); + + PRINT_INFO ("Remote Device llcp info:\n \tlto: %d, \twks: %d, \tmiu: %d, \toption: %d", lto, wks, miu, option); + + net_nfc_create_llcp_socket (&server_socket, NULL); + net_nfc_set_llcp_socket_callback (server_socket, net_nfc_server_stress_socket_cb, NULL); + net_nfc_listen_llcp (server_socket, "urn:nfc:xsn:samsung.com:testllcp" ,16 ,NULL); + + net_nfc_create_llcp_socket (&client_socket, NULL); + net_nfc_set_llcp_socket_callback (client_socket, net_nfc_client_stress_socket_cb, NULL); + net_nfc_connect_llcp (client_socket,"urn:nfc:xsn:samsung.com:testllcp",NULL); + } + break; + + case NET_NFC_MESSAGE_LLCP_CONFIG: + { + PRINT_INFO ("LLCP llcp local config is completed with error code %d", result); + } + break; + + case NET_NFC_MESSAGE_P2P_DETACHED: + { + PRINT_INFO ("LLCP NET_NFC_MESSAGE_P2P_DETACHED %d", result); + } + break; + + default: + break; + } +} + +int nfcTestStressLLCP(uint8_t testNumber,void* arg_ptr2) +{ + net_nfc_error_e result; + net_nfc_llcp_config_info_h config; + result = net_nfc_initialize(); + CHECK_RESULT(result); + net_nfc_state_activate (1); + result = net_nfc_set_response_callback (net_nfc_test_llcp_stress_cb, NULL); + CHECK_RESULT(result); + result = net_nfc_create_llcp_configure_default (&config); + CHECK_RESULT(result); + result = net_nfc_set_llcp_local_configure (config ,NULL); + + PRINT_INSTRUCT("Please start P2P communicate!!"); +/* + pthread_cond_wait (&pcond,&plock ); + + result = net_nfc_unset_response_callback (); + CHECK_RESULT(result); + result = net_nfc_deinitialize (); + CHECK_RESULT(result); +*/ + + return NET_NFC_TEST_OK; +} + +/*=================================================================================*/ + + +static void net_nfc_test_API_exception_cb1(net_nfc_message_e message, net_nfc_error_e result, void* data, void* user_param, void * trans_data) +{ + PRINT_INFO ("Message is received 1 %d", result); + test_case_result = NET_NFC_TEST_FAIL; + pthread_mutex_lock (&plock); + pthread_cond_signal (&pcond); + pthread_mutex_unlock (&plock); +} + +static void net_nfc_test_API_exception_cb2(net_nfc_message_e message, net_nfc_error_e result, void* data, void* user_param, void * trans_data) +{ + PRINT_INFO ("Message is received 2 %d", result); + test_case_result = NET_NFC_TEST_FAIL; + pthread_mutex_lock (&plock); + pthread_cond_signal (&pcond); + pthread_mutex_unlock (&plock); +} + +static void net_nfc_test_API_exception_cb3(net_nfc_message_e message, net_nfc_error_e result, void* data, void* user_param, void * trans_data) +{ + PRINT_INFO ("Message is received 3 %d", result); + test_case_result = NET_NFC_TEST_OK; + pthread_mutex_lock (&plock); + pthread_cond_signal (&pcond); + pthread_mutex_unlock (&plock); +} + + + + +int nfcTestAPIException (uint8_t testNumber,void* arg_ptr) +{ + net_nfc_error_e result; + test_case_result = NET_NFC_TEST_FAIL; + + CHECK_ASSULT(net_nfc_initialize() == NET_NFC_OK); + CHECK_ASSULT(net_nfc_initialize() == NET_NFC_ALREADY_INITIALIZED); + CHECK_ASSULT(net_nfc_deinitialize () == NET_NFC_OK); + + int count_try = 0; + for (count_try = 0; count_try < 20; count_try ++) + { + CHECK_ASSULT(net_nfc_initialize() == NET_NFC_OK); + CHECK_ASSULT(net_nfc_deinitialize () == NET_NFC_OK); + } + + CHECK_ASSULT(net_nfc_deinitialize () == NET_NFC_NOT_INITIALIZED); + CHECK_ASSULT(net_nfc_deinitialize () == NET_NFC_NOT_INITIALIZED); + + + CHECK_ASSULT(net_nfc_initialize() == NET_NFC_OK); + + CHECK_ASSULT (NET_NFC_OK == net_nfc_set_response_callback (net_nfc_test_API_exception_cb1, NULL)); + CHECK_ASSULT (NET_NFC_OK == net_nfc_set_response_callback (net_nfc_test_API_exception_cb2, NULL)); + CHECK_ASSULT (NET_NFC_OK == net_nfc_set_response_callback (net_nfc_test_API_exception_cb3, NULL)); + net_nfc_state_activate (1); + + PRINT_INSTRUCT("Please close a tag to device!!"); + + pthread_cond_wait (&pcond,&plock ); + if (!test_case_result) return test_case_result; + + PRINT_INSTRUCT("Please remove the tag from device!!"); + pthread_cond_wait (&pcond,&plock ); + + CHECK_ASSULT (NET_NFC_OK == net_nfc_set_response_callback (net_nfc_test_API_exception_cb2, NULL)); + CHECK_ASSULT (NET_NFC_OK != net_nfc_set_response_callback (NULL, NULL)); + + CHECK_ASSULT (NET_NFC_OK == net_nfc_set_response_callback (net_nfc_test_API_exception_cb2, NULL)); + CHECK_ASSULT (NET_NFC_OK == net_nfc_unset_response_callback ()); + + PRINT_INSTRUCT("Please close a tag to device!! in 10 sec"); + + int idx = 0; + for (idx = 10 ;idx > 0 ; idx --) + { + PRINT_INSTRUCT("count down [%d]", idx); + sleep (1); + } + if (!test_case_result) return test_case_result; + + PRINT_INSTRUCT("Please remove the tag from device!!"); + sleep (2); + + CHECK_ASSULT (NET_NFC_OK == net_nfc_set_response_callback (net_nfc_test_API_exception_cb3, NULL)); + net_nfc_state_activate (1); + net_nfc_state_activate (1); + net_nfc_state_activate (1); + + PRINT_INSTRUCT("Please close a tag to device!!"); + + pthread_cond_wait (&pcond,&plock ); + if (!test_case_result) return test_case_result; + PRINT_INSTRUCT("Please remove the tag from device!!"); + pthread_cond_wait (&pcond,&plock ); + + net_nfc_state_deactivate (); + PRINT_INSTRUCT("Please close a tag to device!! in 10 sec"); + + for (idx = 10 ;idx > 0 ; idx --) + { + PRINT_INSTRUCT("count down [%d]", idx); + sleep (1); + } + if (!test_case_result) return test_case_result; + PRINT_INSTRUCT("Please remove the tag from device!!"); + sleep (2); + + net_nfc_state_activate (1); + CHECK_ASSULT(net_nfc_deinitialize () == NET_NFC_OK); + + PRINT_INSTRUCT("Please close a tag to device!! in 10 sec"); + + + for (idx = 10 ;idx > 0 ; idx --) + { + PRINT_INSTRUCT("count down [%d]", idx); + sleep (1); + } + if (!test_case_result) return test_case_result; + + PRINT_INSTRUCT("Please remove the tag from device!!"); + sleep (2); + + CHECK_ASSULT(net_nfc_initialize() == NET_NFC_OK); + CHECK_ASSULT (NET_NFC_OK == net_nfc_set_response_callback (net_nfc_test_API_exception_cb3, NULL)); + net_nfc_state_activate (1); + + PRINT_INSTRUCT("Please close a tag to device!!"); + + pthread_cond_wait (&pcond,&plock ); + if (!test_case_result) return test_case_result; + + return NET_NFC_TEST_OK; +} + +/*=================================================================================*/ + + +static void net_nfc_test_API_exception_tagAPI(net_nfc_message_e message, net_nfc_error_e result, void* data, void* user_param, void * trans_data) +{ + PRINT_INFO ("Message is received 3 %d", result); + test_case_result = NET_NFC_TEST_OK; + + switch(message) + { + case NET_NFC_MESSAGE_TAG_DISCOVERED: + { + switch (*(int*) user_param) + { + case 0: // transceive + { + net_nfc_target_type_e type; + net_nfc_target_handle_h id; + bool is_ndef; + net_nfc_target_info_h target_info = (net_nfc_target_info_h)data; + net_nfc_error_e e_ret ; + + net_nfc_get_tag_type (target_info, &type); + net_nfc_get_tag_handle (target_info, &id); + net_nfc_get_tag_ndef_support (target_info, &is_ndef); + PRINT_INFO("target type: %d\n", type); + PRINT_INFO("target id: %X\n", id); + PRINT_INFO("Is NDEF supoort: %d\n", is_ndef); + + net_nfc_deinitialize (); // Before calling transceive + + } + break; + case 1: + { + net_nfc_target_info_h target_info = (net_nfc_target_info_h)data; + net_nfc_target_handle_h id; + net_nfc_get_tag_handle (target_info, &id); + net_nfc_deinitialize(); + if (NET_NFC_OK == net_nfc_read_tag (id ,NULL)){ + test_case_result = NET_NFC_TEST_FAIL; + } + } + break; + case 2: + { + net_nfc_target_info_h target_info = (net_nfc_target_info_h)data; + net_nfc_target_handle_h id; + ndef_message_h message = NULL; + ndef_record_h record = NULL; + + net_nfc_get_tag_handle (target_info, &id); + net_nfc_deinitialize(); + + net_nfc_create_ndef_message (&message); + net_nfc_create_text_type_record (&record, "abc" ,"en-US" ,NET_NFC_ENCODE_UTF_8); + net_nfc_append_record_to_ndef_message (message ,record); + if (NET_NFC_OK == net_nfc_write_ndef (id ,message ,NULL)){ + test_case_result = NET_NFC_TEST_FAIL; + } + + } + break; + case 3: + { + net_nfc_target_info_h target_info = (net_nfc_target_info_h)data; + net_nfc_target_handle_h id; + data_h key; + char data [] = {0xff,0xff,0xff,0xff,0xff,0xff}; + net_nfc_create_data (&key, data, 6); + net_nfc_get_tag_handle (target_info, &id); + net_nfc_deinitialize(); + if (NET_NFC_OK == net_nfc_format_ndef(id, key, NULL)){ + test_case_result = NET_NFC_TEST_FAIL; + } + } + break; + } + + pthread_mutex_lock (&plock); + pthread_cond_signal (&pcond); + pthread_mutex_unlock (&plock); + } + break; + } +} + + +int nfcTestAPIException_tagAPI (uint8_t testNumber,void* arg_ptr) +{ + int test_case = 0; + + /* Call API before initailize */ + + data_h key; + char data [] = {0xff,0xff,0xff,0xff,0xff,0xff}; + net_nfc_create_data (&key, data, 6); + CHECK_ASSULT (NET_NFC_OK != net_nfc_format_ndef((net_nfc_target_handle_h) 0x302023, key, NULL)); + CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_format_ndef(NULL, key, NULL)); + CHECK_ASSULT (NET_NFC_OK != net_nfc_format_ndef((net_nfc_target_handle_h) 0x302023, NULL, NULL)); + + CHECK_ASSULT (NET_NFC_OK != net_nfc_read_tag ((net_nfc_target_handle_h) 0x302023 ,NULL)); + CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_read_tag (NULL ,NULL)); + + ndef_message_h message = NULL; + ndef_record_h record = NULL; + net_nfc_create_ndef_message (&message); + net_nfc_create_text_type_record (&record, "abc" ,"en-US" ,NET_NFC_ENCODE_UTF_8); + net_nfc_append_record_to_ndef_message (message ,record); + CHECK_ASSULT (NET_NFC_OK != net_nfc_write_ndef ((net_nfc_target_handle_h)0x302023 ,message,NULL)); + CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_write_ndef (NULL ,message,NULL)); + CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_write_ndef ((net_nfc_target_handle_h)0x302023 ,NULL,NULL)); + net_nfc_free_ndef_message (message); + + + for (test_case = 0 ; test_case < 4; test_case++){ + CHECK_ASSULT(net_nfc_initialize() == NET_NFC_OK); + net_nfc_state_activate (1); + PRINT_INSTRUCT("Please close a tag to device!!"); + CHECK_ASSULT (NET_NFC_OK == net_nfc_set_response_callback (net_nfc_test_API_exception_tagAPI, &test_case)); + pthread_cond_wait (&pcond,&plock ); + if (test_case_result == NET_NFC_TEST_FAIL) return test_case_result; + PRINT_INSTRUCT("Please remoe the tag from device!!"); + sleep(2); + } + + CHECK_ASSULT(net_nfc_deinitialize () != NET_NFC_OK); + + return NET_NFC_TEST_OK; +} +/*=================================================================================*/ + + +static void net_nfc_test_API_exception_targetInfo(net_nfc_message_e message, net_nfc_error_e result, void* data, void* user_param, void * trans_data) +{ + PRINT_INFO ("Message is received 3 %d", result); + test_case_result = NET_NFC_TEST_OK; + + char **keys; + int length; + data_h value; + + switch(message) + { + case NET_NFC_MESSAGE_TAG_DISCOVERED: + { + + if (NET_NFC_OK != net_nfc_get_tag_info_keys((net_nfc_target_info_h)data, &keys, &length)){ + test_case_result = NET_NFC_TEST_FAIL; + return; + } + + if (NET_NFC_OK == net_nfc_get_tag_info_value ((net_nfc_target_info_h)data, "abc", &value)){ + test_case_result = NET_NFC_TEST_FAIL; + return; + } + PRINT_INSTRUCT("Please remove the tag from device!!"); + + } + break; + case NET_NFC_MESSAGE_TAG_DETACHED: + + if (NET_NFC_OK == net_nfc_get_tag_info_keys((net_nfc_target_info_h)data, &keys, &length)){ + test_case_result = NET_NFC_TEST_FAIL; + return; + } + + pthread_mutex_lock (&plock); + pthread_cond_signal (&pcond); + pthread_mutex_unlock (&plock); + + + break; + } +} + +int nfcTestAPIException_targetInfo (uint8_t testNumber,void* arg_ptr) +{ + net_nfc_target_type_e target_type; + net_nfc_target_handle_h target_id; + bool is_support; + unsigned int size; + CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_get_tag_type ((net_nfc_target_info_h)0x302023, NULL)); + CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_get_tag_type (NULL, &target_type)); + + CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_get_tag_handle((net_nfc_target_info_h)0x302023, NULL)); + CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_get_tag_handle(NULL, &target_id)); + + CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_get_tag_ndef_support ((net_nfc_target_info_h)0x302023, NULL)); + CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_get_tag_ndef_support (NULL, &is_support)); + + CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_get_tag_max_data_size ((net_nfc_target_info_h)0x302023, NULL)); + CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_get_tag_max_data_size (NULL, &size)); + + CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_get_tag_actual_data_size ((net_nfc_target_info_h)0x302023, NULL)); + CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_get_tag_actual_data_size (NULL, &size)); + + char **keys; + int length; + CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_get_tag_info_keys((net_nfc_target_info_h)0x302023, NULL, &length)); + CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_get_tag_info_keys((net_nfc_target_info_h)0x302023, &keys, NULL)); + CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_get_tag_info_keys(NULL, &keys, &length)); + + const char* key = "hello"; + data_h value; + + CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_get_tag_info_value((net_nfc_target_info_h)0x302023, key , NULL)); + CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_get_tag_info_value((net_nfc_target_info_h)0x302023, NULL, &value)); + CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_get_tag_info_value(NULL, key, &value)); + + CHECK_ASSULT(net_nfc_initialize() == NET_NFC_OK); + net_nfc_state_activate (1); + CHECK_ASSULT (NET_NFC_OK == net_nfc_set_response_callback (net_nfc_test_API_exception_targetInfo, NULL)); + PRINT_INSTRUCT("Please close a tag to device!!"); + + pthread_cond_wait (&pcond,&plock ); + + CHECK_ASSULT(net_nfc_deinitialize() == NET_NFC_OK); + return NET_NFC_TEST_OK; +} + +/*=================================================================================*/ + + +int nfcConnHandoverMessageTest (uint8_t testNumber,void* arg_ptr) +{ + net_nfc_carrier_config_h carrier; + net_nfc_property_group_h group; + ndef_record_h carrier_record; + ndef_message_h message; + uint8_t buffer[256] = {0,}; + uint8_t * pdata; + int length = 0; + net_nfc_error_e result; + char SSID[] = "HomeWLAN"; + char dev_name[] = "DeviceName"; + uint8_t btdev_addr[] = {0x01, 0x07, 0x80, 0x80, 0xBF, 0xA1}; + + result = net_nfc_create_carrier_config (&carrier ,NET_NFC_CONN_HANDOVER_CARRIER_WIFI_BSS); + CHECK_RESULT(result); + + buffer[0] = 0x10; + result = net_nfc_add_carrier_config_property (carrier, NET_NFC_WIFI_ATTRIBUTE_VERSION, 1, buffer); + CHECK_RESULT(result); + result = net_nfc_create_carrier_config_group (&group, NET_NFC_WIFI_ATTRIBUTE_CREDENTIAL); + CHECK_RESULT(result); + + buffer[0] = 0x1; + result = net_nfc_add_carrier_config_group_property (group, NET_NFC_WIFI_ATTRIBUTE_NET_INDEX, 1, buffer); + CHECK_RESULT(result); + + length = sprintf (buffer, "%s", SSID); + result = net_nfc_add_carrier_config_group_property (group, NET_NFC_WIFI_ATTRIBUTE_SSID, length, buffer); + CHECK_RESULT(result); + + *((uint16_t*) buffer ) = 0x20; + result = net_nfc_add_carrier_config_group_property (group, NET_NFC_WIFI_ATTRIBUTE_AUTH_TYPE, 2, buffer); + CHECK_RESULT(result); + + *((uint16_t*) buffer ) = 0x0008; + result = net_nfc_add_carrier_config_group_property (group, NET_NFC_WIFI_ATTRIBUTE_ENC_TYPE, 2, buffer); + CHECK_RESULT(result); + + length = sprintf (buffer, "MyPreSharedKey"); + result = net_nfc_add_carrier_config_group_property (group, NET_NFC_WIFI_ATTRIBUTE_NET_KEY, length, buffer); + CHECK_RESULT(result); + + buffer[0] = 0x00; + buffer[1] = 0x07; + buffer[2] = 0xE9; + buffer[3] = 0x4C; + buffer[4] = 0xA8; + buffer[5] = 0x1C; + result = net_nfc_add_carrier_config_group_property (group, NET_NFC_WIFI_ATTRIBUTE_MAC_ADDR, 6, buffer); + CHECK_RESULT(result); + + + *((uint16_t*) buffer ) = 0x0001; + result = net_nfc_add_carrier_config_group_property (group, NET_NFC_WIFI_ATTRIBUTE_CHANNEL, 2, buffer); + CHECK_RESULT(result); + + buffer[0] = 0x00; + buffer[1] = 0x37; + buffer[2] = 0x2A; + result = net_nfc_add_carrier_config_group_property (group, NET_NFC_WIFI_ATTRIBUTE_VEN_EXT, 3, buffer); + CHECK_RESULT(result); + + result = net_nfc_append_carrier_config_group (carrier, group); + CHECK_RESULT(result); + + buffer[0] = 0x20; + result = net_nfc_add_carrier_config_property (carrier, NET_NFC_WIFI_ATTRIBUTE_VERSION2, 1, buffer); + CHECK_RESULT(result); + + result = net_nfc_create_ndef_record_with_carrier_config (&carrier_record ,carrier); + CHECK_RESULT(result); + + result = net_nfc_free_carrier_config (carrier); /* this free all data include group */ + CHECK_RESULT(result); + + result = net_nfc_create_handover_request_message (&message); + CHECK_RESULT(result); + + //net_nfc_ndef_print_message (message); + + result = net_nfc_append_carrier_config_record (message, carrier_record, NET_NFC_CONN_HANDOVER_CARRIER_ACTIVATE); + CHECK_RESULT(result); + + //net_nfc_ndef_print_message (message); + + + // Create BT config + result = net_nfc_create_carrier_config (&carrier ,NET_NFC_CONN_HANDOVER_CARRIER_BT); + CHECK_RESULT(result); + + buffer[0] = btdev_addr[0]; + buffer[1] = btdev_addr[1]; + buffer[2] = btdev_addr[2]; + buffer[3] = btdev_addr[3]; + buffer[4] = btdev_addr[4]; + buffer[5] = btdev_addr[5]; + result = net_nfc_add_carrier_config_property (carrier ,NET_NFC_BT_ATTRIBUTE_ADDRESS ,6 ,buffer); + CHECK_RESULT(result); + + buffer[0] = 0x08; + buffer[1] = 0x06; + buffer[2] = 0x20; + result = net_nfc_add_carrier_config_property (carrier ,NET_NFC_BT_ATTRIBUTE_OOB_COD ,3 ,buffer); + CHECK_RESULT(result); + + + result = net_nfc_add_carrier_config_property (carrier ,NET_NFC_BT_ATTRIBUTE_OOB_HASH_C ,16 ,buffer); + CHECK_RESULT(result); + + result = net_nfc_add_carrier_config_property (carrier ,NET_NFC_BT_ATTRIBUTE_OOB_HASH_R ,16 ,buffer); + CHECK_RESULT(result); + + buffer[0] = 0x06; + buffer[1] = 0x11; + buffer[2] = 0x20; + buffer[3] = 0x11; + result = net_nfc_add_carrier_config_property (carrier ,NET_NFC_BT_ATTRIBUTE_UUID16 ,4 ,buffer); + CHECK_RESULT(result); + + length = sprintf (buffer, "%s", dev_name); + result = net_nfc_add_carrier_config_property (carrier ,NET_NFC_BT_ATTRIBUTE_NAME ,length ,buffer); + CHECK_RESULT(result); + + result = net_nfc_create_ndef_record_with_carrier_config (&carrier_record ,carrier); + CHECK_RESULT(result); + + result = net_nfc_append_carrier_config_record (message, carrier_record, NET_NFC_CONN_HANDOVER_CARRIER_ACTIVATING); + CHECK_RESULT(result); + + //net_nfc_ndef_print_message (message); + + result = net_nfc_free_carrier_config (carrier); + CHECK_RESULT(result); + + result = net_nfc_get_carrier_config_record (message,0 ,&carrier_record); + CHECK_RESULT(result); + + result = net_nfc_create_carrier_config_from_config_record (&carrier ,carrier_record); + CHECK_RESULT(result); + + result = net_nfc_get_carrier_config_property (carrier ,NET_NFC_WIFI_ATTRIBUTE_VERSION , &length, &pdata); + CHECK_RESULT(result); + if (pdata[0] != 0x10){ + PRINT_RESULT_FAIL("FILE:%s, LINE:%d, value %d",__FILE__,__LINE__, pdata[0]); + return NET_NFC_TEST_FAIL; + } + + result = net_nfc_get_carrier_config_group (carrier ,0 , &group); + CHECK_RESULT(result); + + result = net_nfc_get_carrier_config_group_property (group ,NET_NFC_WIFI_ATTRIBUTE_SSID, &length, &pdata); + CHECK_RESULT(result); + if (memcmp (pdata, SSID, length) != 0){ + PRINT_RESULT_FAIL("FILE:%s, LINE:%d,",__FILE__,__LINE__); + return NET_NFC_TEST_FAIL; + } + + result = net_nfc_remove_carrier_config_group_property (group,NET_NFC_WIFI_ATTRIBUTE_VEN_EXT); + CHECK_RESULT(result); + + result = net_nfc_get_carrier_config_record (message,1 ,&carrier_record); + CHECK_RESULT(result); + + result = net_nfc_create_carrier_config_from_config_record (&carrier ,carrier_record); + CHECK_RESULT(result); + + result = net_nfc_get_carrier_config_property (carrier ,NET_NFC_BT_ATTRIBUTE_ADDRESS , &length, &pdata); + CHECK_RESULT(result); + if (memcmp (pdata, btdev_addr, length) != 0) { + PRINT_RESULT_FAIL("FILE:%s, LINE:%d,",__FILE__,__LINE__); + return NET_NFC_TEST_FAIL; + } + + result = net_nfc_get_carrier_config_property (carrier ,NET_NFC_BT_ATTRIBUTE_NAME , &length, &pdata); + CHECK_RESULT(result); + if (memcmp (pdata, dev_name, length) != 0){ + PRINT_RESULT_FAIL("FILE:%s, LINE:%d,",__FILE__,__LINE__); + return NET_NFC_TEST_FAIL; + } + + result = net_nfc_get_alternative_carrier_record_count (message, &length); + CHECK_RESULT(result); + + if (length != 2) { + PRINT_RESULT_FAIL("FILE:%s, LINE:%d, count = %d",__FILE__,__LINE__, length); + return NET_NFC_TEST_FAIL; + } + + net_nfc_conn_handover_carrier_state_e power_state; + result = net_nfc_get_alternative_carrier_power_status (message,0 ,&power_state); + CHECK_RESULT(result); + + if (power_state != NET_NFC_CONN_HANDOVER_CARRIER_ACTIVATE){ + PRINT_RESULT_FAIL("FILE:%s, LINE:%d,",__FILE__,__LINE__); + return NET_NFC_TEST_FAIL; + } + result = net_nfc_set_alternative_carrier_power_status (message,1 ,NET_NFC_CONN_HANDOVER_CARRIER_INACTIVATE); + CHECK_RESULT(result); + + result = net_nfc_get_alternative_carrier_power_status (message,1 ,&power_state); + CHECK_RESULT(result); + + if (power_state != NET_NFC_CONN_HANDOVER_CARRIER_INACTIVATE){ + PRINT_RESULT_FAIL("FILE:%s, LINE:%d, status = %d",__FILE__,__LINE__, power_state); + return NET_NFC_TEST_FAIL; + } + + net_nfc_conn_handover_carrier_type_e ctype; + result = net_nfc_get_alternative_carrier_type (message, 0 , &ctype); + + if (ctype != NET_NFC_CONN_HANDOVER_CARRIER_WIFI_BSS){ + PRINT_RESULT_FAIL("FILE:%s, LINE:%d,",__FILE__,__LINE__); + return NET_NFC_TEST_FAIL; + } + + unsigned short r_num; + result = net_nfc_get_handover_random_number (message, &r_num); + + result = net_nfc_get_carrier_config_record (message,0 ,&carrier_record); + CHECK_RESULT(result); + + result = net_nfc_remove_carrier_config_record (message, carrier_record); + CHECK_RESULT(result); + + result = net_nfc_get_carrier_config_record (message,0 ,&carrier_record); + CHECK_RESULT(result); + + result = net_nfc_create_carrier_config_from_config_record (&carrier ,carrier_record); + CHECK_RESULT(result); + + result = net_nfc_get_carrier_config_property (carrier ,NET_NFC_BT_ATTRIBUTE_ADDRESS , &length, &pdata); + CHECK_RESULT(result); + if (memcmp (pdata, btdev_addr, length) != 0) { + PRINT_RESULT_FAIL("FILE:%s, LINE:%d,",__FILE__,__LINE__); + return NET_NFC_TEST_FAIL; + } + + result = net_nfc_get_carrier_config_property (carrier ,NET_NFC_BT_ATTRIBUTE_NAME , &length, &pdata); + CHECK_RESULT(result); + if (memcmp (pdata, dev_name, length) != 0){ + PRINT_RESULT_FAIL("FILE:%s, LINE:%d,",__FILE__,__LINE__); + return NET_NFC_TEST_FAIL; + } + + result = net_nfc_get_alternative_carrier_record_count (message, &length); + CHECK_RESULT(result); + + if (length != 1) { + PRINT_RESULT_FAIL("FILE:%s, LINE:%d,",__FILE__,__LINE__); + return NET_NFC_TEST_FAIL; + } + + result = net_nfc_get_alternative_carrier_power_status (message,0 ,&power_state); + CHECK_RESULT(result); + + if (power_state != NET_NFC_CONN_HANDOVER_CARRIER_INACTIVATE){ + PRINT_RESULT_FAIL("FILE:%s, LINE:%d,",__FILE__,__LINE__); + return NET_NFC_TEST_FAIL; + } + + result = net_nfc_get_alternative_carrier_type (message, 0 , &ctype); + + if (ctype != NET_NFC_CONN_HANDOVER_CARRIER_BT){ + PRINT_RESULT_FAIL("FILE:%s, LINE:%d,",__FILE__,__LINE__); + return NET_NFC_TEST_FAIL; + } + + //net_nfc_ndef_print_message (message); + + return NET_NFC_TEST_OK; + +} + +/*=================================================================================*/ + + diff --git a/test_clinet_app/nfc_client/nfc_api_test.h b/test_clinet_app/nfc_client/nfc_api_test.h new file mode 100755 index 0000000..b669780 --- /dev/null +++ b/test_clinet_app/nfc_client/nfc_api_test.h @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#ifndef __NET_NFC_TEST_H__ +#define __NET_NFC_TEST_H__ + +typedef enum { + NET_NFC_TEST_NOT_YET, + NET_NFC_TEST_OK, + NET_NFC_TEST_FAIL, +}net_nfc_test_result_e; + + +#define LOG_COLOR_RED "\033[0;31m" +#define LOG_COLOR_GREEN "\033[0;32m" +#define LOG_COLOR_BROWN "\033[0;33m" +#define LOG_COLOR_BLUE "\033[0;34m" +#define LOG_COLOR_PURPLE "\033[0;35m" +#define LOG_COLOR_CYAN "\033[0;36m" +#define LOG_COLOR_LIGHTBLUE "\033[0;37m" +#define LOG_COLOR_END "\033[0;m" + +#define PRINT_INSTRUCT(format,args...) \ +do {\ + printf(LOG_COLOR_BLUE""format""LOG_COLOR_END"\n", ##args);\ +}while(0); + +#define PRINT_RESULT_FAIL(format,args...) \ +do {\ + printf(LOG_COLOR_RED""format""LOG_COLOR_END"\n", ##args);\ +}while(0); + +#define PRINT_RESULT_SUCCESS(format,args...) \ +do {\ + printf(LOG_COLOR_GREEN""format""LOG_COLOR_END"\n", ##args);\ +}while(0); + +#define PRINT_INFO(format,args...) \ +do {\ + printf(format"\n", ##args);\ +}while(0); + + +#define CHECK_RESULT(X)\ + do{\ + if(X!=NET_NFC_OK){\ + PRINT_RESULT_FAIL("FILE:%s, LINE:%d, RESULT:%d",__FILE__,__LINE__,X);\ + return NET_NFC_TEST_FAIL;\ + }\ + }while(0) + + +#define CHECK_ASSULT(X)\ + do{\ + if(!(X)){\ + PRINT_RESULT_FAIL("FILE:%s, LINE:%d, RESULT:%d",__FILE__,__LINE__,X);\ + return NET_NFC_TEST_FAIL;\ + }\ + }while(0) + +/* struct defines */ +typedef int nfcTestStartFn_t(uint8_t testNumber,void* arg_ptr2); + +typedef struct +{ + char* testName; + nfcTestStartFn_t* testFn; + uint8_t testResult; +} nfcTestType; + + + + +#endif + -- 2.7.4