apply FSL(Flora Software License)
authorKim Kibum <kb0929.kim@samsung.com>
Fri, 8 Jun 2012 05:54:09 +0000 (14:54 +0900)
committerKim Kibum <kb0929.kim@samsung.com>
Fri, 8 Jun 2012 05:54:09 +0000 (14:54 +0900)
138 files changed:
AUTHORS [new file with mode: 0644]
CMakeLists.txt [new file with mode: 0755]
LICENSE [new file with mode: 0644]
TC/_export_env.sh [new file with mode: 0644]
TC/_export_target_env.sh [new file with mode: 0644]
TC/build.sh [new file with mode: 0644]
TC/clean.sh [new file with mode: 0644]
TC/config.default [new file with mode: 0644]
TC/execute.sh [new file with mode: 0644]
TC/testcase/Makefile [new file with mode: 0644]
TC/testcase/tslist [new file with mode: 0644]
TC/testcase/utc_net_nfc_client_data.c [new file with mode: 0644]
TC/testcase/utc_net_nfc_client_exchanger.c [new file with mode: 0644]
TC/testcase/utc_net_nfc_client_internal_se.c [new file with mode: 0644]
TC/testcase/utc_net_nfc_client_ndef_message.c [new file with mode: 0644]
TC/testcase/utc_net_nfc_client_ndef_record.c [new file with mode: 0644]
TC/testcase/utc_net_nfc_client_nfc.c [new file with mode: 0644]
TC/testcase/utc_net_nfc_client_tag.c [new file with mode: 0644]
TC/testcase/utc_net_nfc_client_tag_felica.c [new file with mode: 0644]
TC/testcase/utc_net_nfc_client_tag_jewel.c [new file with mode: 0644]
TC/testcase/utc_net_nfc_client_tag_mifare.c [new file with mode: 0644]
TC/testcase/utc_net_nfc_client_target_info.c [new file with mode: 0644]
TC/tet_scen [new file with mode: 0644]
TC/tetbuild.cfg [new file with mode: 0644]
TC/tetclean.cfg [new file with mode: 0644]
TC/tetexec.cfg [new file with mode: 0644]
debian/changelog [new file with mode: 0644]
debian/compat [new file with mode: 0755]
debian/control [new file with mode: 0644]
debian/libnfc-common-lib-0.install.in [new file with mode: 0755]
debian/libnfc-common-lib-dbg.install.in [new file with mode: 0755]
debian/libnfc-common-lib-dev.install.in [new file with mode: 0755]
debian/libnfc-manager-0.init.in [new file with mode: 0755]
debian/libnfc-manager-0.install.in [new file with mode: 0755]
debian/libnfc-manager-0.postinst.in [new file with mode: 0644]
debian/libnfc-manager-dbg.install.in [new file with mode: 0755]
debian/libnfc-manager-dev.install.in [new file with mode: 0755]
debian/rules [new file with mode: 0755]
doxygen/createdoc.sh [new file with mode: 0755]
doxygen/doxygen.conf [new file with mode: 0644]
doxygen/slp_doxy.css [new file with mode: 0644]
packaging/libnfc-manager-0.init.in [new file with mode: 0644]
packaging/nfc-manager.spec [new file with mode: 0644]
src/agent/CMakeLists.txt [new file with mode: 0644]
src/agent/include/net_nfc_agent_private.h [new file with mode: 0644]
src/agent/include/net_nfc_dbus_agent_obj_private.h [new file with mode: 0644]
src/agent/net_nfc_agent.c [new file with mode: 0644]
src/agent/net_nfc_dbus_agent_obj.c [new file with mode: 0644]
src/agent/resource/com.samsung.slp.nfc.agent.service [new file with mode: 0644]
src/agent/resource/dbus_agent.xml [new file with mode: 0644]
src/clientlib/CMakeLists.txt [new file with mode: 0644]
src/clientlib/include/net_nfc.h [new file with mode: 0644]
src/clientlib/include/net_nfc_apdu.h [new file with mode: 0644]
src/clientlib/include/net_nfc_client_dispatcher_private.h [new file with mode: 0644]
src/clientlib/include/net_nfc_client_ipc_private.h [new file with mode: 0644]
src/clientlib/include/net_nfc_client_nfc_private.h [new file with mode: 0644]
src/clientlib/include/net_nfc_client_util_private.h [new file with mode: 0644]
src/clientlib/include/net_nfc_data.h [new file with mode: 0644]
src/clientlib/include/net_nfc_exchanger.h [new file with mode: 0644]
src/clientlib/include/net_nfc_exchanger_private.h [new file with mode: 0644]
src/clientlib/include/net_nfc_internal_se.h [new file with mode: 0644]
src/clientlib/include/net_nfc_llcp.h [new file with mode: 0644]
src/clientlib/include/net_nfc_ndef_message.h [new file with mode: 0644]
src/clientlib/include/net_nfc_ndef_message_handover.h [new file with mode: 0644]
src/clientlib/include/net_nfc_ndef_record.h [new file with mode: 0644]
src/clientlib/include/net_nfc_tag.h [new file with mode: 0644]
src/clientlib/include/net_nfc_tag_felica.h [new file with mode: 0644]
src/clientlib/include/net_nfc_tag_jewel.h [new file with mode: 0644]
src/clientlib/include/net_nfc_tag_mifare.h [new file with mode: 0644]
src/clientlib/include/net_nfc_target_info.h [new file with mode: 0644]
src/clientlib/net_nfc_client_data.c [new file with mode: 0644]
src/clientlib/net_nfc_client_dispatcher.c [new file with mode: 0644]
src/clientlib/net_nfc_client_exchanger.c [new file with mode: 0644]
src/clientlib/net_nfc_client_internal_se.c [new file with mode: 0644]
src/clientlib/net_nfc_client_ipc.c [new file with mode: 0644]
src/clientlib/net_nfc_client_llcp.c [new file with mode: 0644]
src/clientlib/net_nfc_client_ndef_message.c [new file with mode: 0644]
src/clientlib/net_nfc_client_ndef_message_handover.c [new file with mode: 0644]
src/clientlib/net_nfc_client_ndef_record.c [new file with mode: 0644]
src/clientlib/net_nfc_client_nfc.c [new file with mode: 0644]
src/clientlib/net_nfc_client_tag.c [new file with mode: 0644]
src/clientlib/net_nfc_client_tag_felica.c [new file with mode: 0644]
src/clientlib/net_nfc_client_tag_jewel.c [new file with mode: 0644]
src/clientlib/net_nfc_client_tag_mifare.c [new file with mode: 0644]
src/clientlib/net_nfc_client_target_info.c [new file with mode: 0644]
src/clientlib/net_nfc_client_test.c [new file with mode: 0644]
src/clientlib/net_nfc_client_util.c [new file with mode: 0644]
src/clientlib/nfc.pc.in [new file with mode: 0755]
src/commonlib/CMakeLists.txt [new file with mode: 0644]
src/commonlib/include/net_nfc_debug_private.h [new file with mode: 0644]
src/commonlib/include/net_nfc_oem_controller.h [new file with mode: 0644]
src/commonlib/include/net_nfc_typedef.h [new file with mode: 0644]
src/commonlib/include/net_nfc_typedef_private.h [new file with mode: 0644]
src/commonlib/include/net_nfc_util_defines.h [new file with mode: 0644]
src/commonlib/include/net_nfc_util_handover.h [new file with mode: 0644]
src/commonlib/include/net_nfc_util_ndef_message.h [new file with mode: 0644]
src/commonlib/include/net_nfc_util_ndef_parser.h [new file with mode: 0644]
src/commonlib/include/net_nfc_util_ndef_record.h [new file with mode: 0644]
src/commonlib/include/net_nfc_util_private.h [new file with mode: 0644]
src/commonlib/net_nfc_util.c [new file with mode: 0644]
src/commonlib/net_nfc_util_handover.c [new file with mode: 0644]
src/commonlib/net_nfc_util_ndef_message.c [new file with mode: 0644]
src/commonlib/net_nfc_util_ndef_parser.c [new file with mode: 0644]
src/commonlib/net_nfc_util_ndef_record.c [new file with mode: 0644]
src/commonlib/nfc-common-lib.pc.in [new file with mode: 0755]
src/manager/CMakeLists.txt [new file with mode: 0644]
src/manager/include/net_nfc_app_util_private.h [new file with mode: 0644]
src/manager/include/net_nfc_controller_private.h [new file with mode: 0644]
src/manager/include/net_nfc_dbus_service_obj_private.h [new file with mode: 0644]
src/manager/include/net_nfc_manager_util_private.h [new file with mode: 0644]
src/manager/include/net_nfc_server_dispatcher_private.h [new file with mode: 0644]
src/manager/include/net_nfc_server_ipc_private.h [new file with mode: 0644]
src/manager/include/net_nfc_service_llcp_handover_private.h [new file with mode: 0644]
src/manager/include/net_nfc_service_llcp_private.h [new file with mode: 0644]
src/manager/include/net_nfc_service_private.h [new file with mode: 0644]
src/manager/include/net_nfc_service_se_private.h [new file with mode: 0644]
src/manager/include/net_nfc_service_tag_private.h [new file with mode: 0644]
src/manager/include/net_nfc_service_vconf_private.h [new file with mode: 0644]
src/manager/net_nfc_app_util.c [new file with mode: 0644]
src/manager/net_nfc_controller.c [new file with mode: 0644]
src/manager/net_nfc_dbus_service_obj.c [new file with mode: 0644]
src/manager/net_nfc_manager.c [new file with mode: 0644]
src/manager/net_nfc_manager_util.c [new file with mode: 0644]
src/manager/net_nfc_server_dispatcher.c [new file with mode: 0644]
src/manager/net_nfc_server_ipc.c [new file with mode: 0644]
src/manager/net_nfc_service.c [new file with mode: 0644]
src/manager/net_nfc_service_llcp.c [new file with mode: 0644]
src/manager/net_nfc_service_llcp_handover.c [new file with mode: 0644]
src/manager/net_nfc_service_se.c [new file with mode: 0644]
src/manager/net_nfc_service_tag.c [new file with mode: 0644]
src/manager/net_nfc_service_vconf.c [new file with mode: 0644]
src/manager/resource/dbus_service.xml [new file with mode: 0644]
src/manager/resource/nfc-manager-config.txt.in [new file with mode: 0644]
test_clinet_app/bt_paring/Makefile [new file with mode: 0755]
test_clinet_app/bt_paring/bt_paring.c [new file with mode: 0644]
test_clinet_app/nfc_client/Makefile [new file with mode: 0755]
test_clinet_app/nfc_client/main.c [new file with mode: 0644]
test_clinet_app/nfc_client/nfc_api_test.h [new file with mode: 0644]

diff --git a/AUTHORS b/AUTHORS
new file mode 100644 (file)
index 0000000..84afc7c
--- /dev/null
+++ b/AUTHORS
@@ -0,0 +1,6 @@
+Jaejoon Seo (jaejoon.seo@samsung.com)
+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)
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100755 (executable)
index 0000000..3c8cf7b
--- /dev/null
@@ -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/manager)
+ADD_SUBDIRECTORY(src/agent)
+ADD_SUBDIRECTORY(src/clientlib)
+
diff --git a/LICENSE b/LICENSE
new file mode 100644 (file)
index 0000000..feb3e74
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,98 @@
+
+The NFC manager subdirectory is a collection of software from several sources.
+Each file may have its own copyright/license that is embedded in the source 
+file. Unless otherwise noted in the body of the source file(s), the following 
+copyright notices will apply to the contents of the NFC manager subdirectory:
+
+(1) Apache
+
+Copyright (C) 2010 NXP Semiconductors
+Copyright (C) 2012 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.
+
+(2) Flora License
+
+Version 1.0, May, 2012
+
+http://www.tizenopensource.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://www.tizenopensource.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/TC/_export_env.sh b/TC/_export_env.sh
new file mode 100644 (file)
index 0000000..bb07f7e
--- /dev/null
@@ -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 100644 (file)
index 0000000..5ddaa53
--- /dev/null
@@ -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 100644 (file)
index 0000000..72aad6c
--- /dev/null
@@ -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 100644 (file)
index 0000000..29743e0
--- /dev/null
@@ -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 (file)
index 0000000..12ac1e2
--- /dev/null
@@ -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 100644 (file)
index 0000000..a4f6095
--- /dev/null
@@ -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 (file)
index 0000000..6c0560f
--- /dev/null
@@ -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 (file)
index 0000000..65c1406
--- /dev/null
@@ -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 100644 (file)
index 0000000..70e4a29
--- /dev/null
@@ -0,0 +1,296 @@
+/*
+  * Copyright 2012  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://www.tizenopensource.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 <tet_api.h>
+#include <stdint.h>
+
+#include <net_nfc_data.h>
+#include <net_nfc_typedef.h>
+#include <net_nfc_typedef_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_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 100644 (file)
index 0000000..fb9d3b4
--- /dev/null
@@ -0,0 +1,164 @@
+/*
+  * Copyright 2012  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://www.tizenopensource.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 <tet_api.h>
+#include <net_nfc_data.h>
+#include <stdint.h>
+
+#include <net_nfc_exchanger.h>
+#include <net_nfc_typedef.h>
+#include <net_nfc_typedef_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_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");
+}
+
+static void utc_net_nfc_set_exchanger_cb_p(void)
+{
+       net_nfc_exchanger_cb callback = NULL;
+
+       net_nfc_set_exchanger_cb (callback, NULL);
+
+       dts_pass(__func__, "PASS");
+}
+
+static void utc_net_nfc_set_exchanger_cb_n(void)
+{
+       net_nfc_error_e ret=0;
+
+       ret = net_nfc_set_exchanger_cb(NULL , NULL);
+
+       dts_pass(__func__, "PASS");
+}
+
+static void utc_net_nfc_unset_exchanger_cb_p(void)
+{
+       net_nfc_error_e ret=0;
+
+       ret = net_nfc_unset_exchanger_cb();
+
+       dts_pass(__func__, "PASS");
+}
+
+static void utc_net_nfc_unset_exchanger_cb_n(void)
+{
+       net_nfc_error_e ret=0;
+
+       ret = net_nfc_unset_exchanger_cb();
+
+       dts_pass(__func__, "PASS");
+}
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 100644 (file)
index 0000000..ae897b8
--- /dev/null
@@ -0,0 +1,168 @@
+/*
+  * Copyright 2012  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://www.tizenopensource.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 <tet_api.h>
+
+#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 100644 (file)
index 0000000..581353f
--- /dev/null
@@ -0,0 +1,257 @@
+/*
+  * Copyright 2012  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://www.tizenopensource.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 <tet_api.h>
+#include <stdint.h>
+
+#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 100644 (file)
index 0000000..78a7d05
--- /dev/null
@@ -0,0 +1,571 @@
+/*
+  * Copyright 2012  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://www.tizenopensource.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 <tet_api.h>
+#include <stdint.h>
+
+#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 100644 (file)
index 0000000..fa72b08
--- /dev/null
@@ -0,0 +1,160 @@
+/*
+  * Copyright 2012  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://www.tizenopensource.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 <tet_api.h>
+
+#include "net_nfc.h"
+#include "net_nfc_typedef.h"
+#include "net_nfc_util_private.h"
+
+#ifdef SECURITY_SERVER
+#include <security-server.h>
+#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 100644 (file)
index 0000000..bf326a3
--- /dev/null
@@ -0,0 +1,255 @@
+/*
+  * Copyright 2012  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://www.tizenopensource.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 <tet_api.h>
+#include <stdint.h>
+
+#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 100644 (file)
index 0000000..71062a0
--- /dev/null
@@ -0,0 +1,241 @@
+/*
+  * Copyright 2012  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://www.tizenopensource.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 <tet_api.h>
+
+#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 100644 (file)
index 0000000..88b5a26
--- /dev/null
@@ -0,0 +1,184 @@
+/*
+  * Copyright 2012  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://www.tizenopensource.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 <tet_api.h>
+
+#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 <string.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_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 100644 (file)
index 0000000..fcb2718
--- /dev/null
@@ -0,0 +1,368 @@
+/*
+  * Copyright 2012  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://www.tizenopensource.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 <tet_api.h>
+
+#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 <string.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_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 100644 (file)
index 0000000..1307f6d
--- /dev/null
@@ -0,0 +1,295 @@
+/*
+  * Copyright 2012  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://www.tizenopensource.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 <tet_api.h>
+
+#include "net_nfc_typedef.h"
+#include "net_nfc_typedef_private.h"
+#include "net_nfc_target_info.h"
+#include "net_nfc_data.h"
+#include <stdbool.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_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 100644 (file)
index 0000000..03f029a
--- /dev/null
@@ -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 (file)
index 0000000..f7eda55
--- /dev/null
@@ -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 (file)
index 0000000..02d7030
--- /dev/null
@@ -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 (file)
index 0000000..ef3e452
--- /dev/null
@@ -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 100644 (file)
index 0000000..515721c
--- /dev/null
@@ -0,0 +1,7 @@
+nfc-manager (0.0.1-64) unstable; urgency=low
+
+  * change spec file
+  * Git: pkgs/n/nfc-manager
+  * Tag: nfc-manager_0.0.1-64
+
+ -- Junyong Sim <junyong.sim@samsung.com>  Mon, 23 Apr 2012 01:53:06 +0900
diff --git a/debian/compat b/debian/compat
new file mode 100755 (executable)
index 0000000..7ed6ff8
--- /dev/null
@@ -0,0 +1 @@
+5
diff --git a/debian/control b/debian/control
new file mode 100644 (file)
index 0000000..ee6d135
--- /dev/null
@@ -0,0 +1,42 @@
+Source: nfc-manager
+Section: libs
+Priority: extra
+Maintainer: Sangsoo Lee <constant.lee@samsung.com>, Sungjae Lim <sungjae.lim@samsung.com>, Sechang Sohn <sc.sohn@samsung.com>
+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
+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 (executable)
index 0000000..0a7df14
--- /dev/null
@@ -0,0 +1 @@
+@PREFIX@/lib/libnfc-common-lib.so.*
diff --git a/debian/libnfc-common-lib-dbg.install.in b/debian/libnfc-common-lib-dbg.install.in
new file mode 100755 (executable)
index 0000000..8b13789
--- /dev/null
@@ -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 (executable)
index 0000000..836131f
--- /dev/null
@@ -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 (executable)
index 0000000..9520480
--- /dev/null
@@ -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 <wonkyu.kwon@samsung.com>
+
+# PATH should only include /usr/* if it runs after the mountnfs.sh script
+DAEMON=/usr/bin/nfc-agent # Introduce the server's location here
+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 (executable)
index 0000000..cfbbd96
--- /dev/null
@@ -0,0 +1,7 @@
+@DATADIR@/data/nfc-manager-daemon/config/nfc-manager-config.txt
+@PREFIX@/lib/libnfc.so.*
+@PREFIX@/bin/*
+@PREFIX@/share/dbus-1/services/*
+/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 (file)
index 0000000..89c187d
--- /dev/null
@@ -0,0 +1,8 @@
+#!/bin/sh
+#Add boot sequence script
+if [ ${USER} == "root" ]
+then
+vconftool set -t bool db/nfc/feature 0 -u 5000
+else
+vconftool set -t bool db/nfc/feature 0
+fi
diff --git a/debian/libnfc-manager-dbg.install.in b/debian/libnfc-manager-dbg.install.in
new file mode 100755 (executable)
index 0000000..8b13789
--- /dev/null
@@ -0,0 +1 @@
+
diff --git a/debian/libnfc-manager-dev.install.in b/debian/libnfc-manager-dev.install.in
new file mode 100755 (executable)
index 0000000..52e34bd
--- /dev/null
@@ -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 (executable)
index 0000000..9565f36
--- /dev/null
@@ -0,0 +1,136 @@
+#!/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
+DATADIR ?= /opt
+
+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}; \
+               sed -i -e "s#@DATADIR@#$(DATADIR)#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/opt/data/nfc-manager-daemon/config
+       cp -af $(CURDIR)/src/manager/resource/nfc-manager-config.txt.in $(CURDIR)/debian/tmp/opt/data/nfc-manager-daemon/config/nfc-manager-config.txt
+       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 (executable)
index 0000000..42b1939
--- /dev/null
@@ -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 100644 (file)
index 0000000..88ef801
--- /dev/null
@@ -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 (file)
index 0000000..12c03ac
--- /dev/null
@@ -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/packaging/libnfc-manager-0.init.in b/packaging/libnfc-manager-0.init.in
new file mode 100644 (file)
index 0000000..a471b96
--- /dev/null
@@ -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 <wonkyu.kwon@samsung.com>
+
+# PATH should only include /usr/* if it runs after the mountnfs.sh script
+DAEMON=/usr/bin/nfc-agent # Introduce the server's location here
+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/packaging/nfc-manager.spec b/packaging/nfc-manager.spec
new file mode 100644 (file)
index 0000000..efc844d
--- /dev/null
@@ -0,0 +1,124 @@
+#sbs-git:slp/pkgs/n/nfc-manager nfc-manager 0.0.1 7e42d204f11700974e83188adca03dcd1b0f0e9c
+Name:       nfc-manager
+Summary:    NFC framework manager
+Version: 0.0.1
+Release:    1
+Group:      libs
+License:    Flora Software License
+Source0:    %{name}-%{version}.tar.gz
+Source1:    libnfc-manager-0.init.in
+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: 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
+
+%post
+/sbin/ldconfig
+#vconftool set -t string memory/nfc/client/deb.com.samsung.gallery "" -g 6517 -i
+#vconftool set -t string memory/nfc/client/deb.com.samsung.browser "" -g 6517 -i
+#vconftool set -t string memory/nfc/client/deb.com.samsung.contacts "" -g 6517 -i
+#vconftool set -t string memory/nfc/client/deb.com.samsung.video-player "" -g 6517 -i
+#vconftool set -t string memory/nfc/client/eeprom "" -g 6517 -i
+vconftool set -t bool db/nfc/feature 0 -u 5000
+
+ln -s /etc/rc.d/init.d/libnfc-manager-0 /etc/rc.d/rc3.d/S81libnfc-manager-0
+ln -s /etc/rc.d/init.d/libnfc-manager-0 /etc/rc.d/rc5.d/S81libnfc-manager-0
+
+%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
+
+%post -n nfc-common-lib -p /sbin/ldconfig
+
+%postun -n nfc-common-lib -p /sbin/ldconfig
+
+%files
+%defattr(-,root,root,-)
+#@DATADIR@/data/nfc-manager-daemon/config/nfc-manager-config.txt
+%{_libdir}/libnfc.so.1
+%{_libdir}/libnfc.so.1.0.0
+%{_prefix}/bin/nfc-agent
+%{_prefix}/bin/nfc-manager-daemon
+%{_prefix}/share/dbus-1/services/com.samsung.slp.nfc.agent.service
+/etc/init.d/libnfc-manager-0
+
+%files devel
+%defattr(-,root,root,-)
+%{_libdir}/pkgconfig/nfc.pc
+%{_includedir}/nfc/*.h
+%{_libdir}/libnfc.so
+
+
+%files -n nfc-common-lib
+%defattr(-,root,root,-)
+%{_libdir}/libnfc-common-lib.so.1
+%{_libdir}/libnfc-common-lib.so.1.0.0
+
+%files -n nfc-common-lib-devel
+%defattr(-,root,root,-)
+%{_libdir}/libnfc-common-lib.so
+%{_libdir}/pkgconfig/nfc-common-lib.pc
+%{_includedir}/nfc-common-lib/*.h
diff --git a/src/agent/CMakeLists.txt b/src/agent/CMakeLists.txt
new file mode 100644 (file)
index 0000000..7707819
--- /dev/null
@@ -0,0 +1,82 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+PROJECT(nfc C)
+
+SET(AGENT_DAEMON "nfc-agent")
+
+SET(AGENT_SRCS
+       ${CMAKE_CURRENT_SOURCE_DIR}/net_nfc_agent.c
+       ${CMAKE_CURRENT_SOURCE_DIR}/net_nfc_dbus_agent_obj.c
+)
+
+include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
+include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../commonlib/include)
+include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../manager/include)
+
+IF("${CMAKE_BUILD_TYPE}" STREQUAL "")
+       SET(CMAKE_BUILD_TYPE "Release")
+ENDIF("${CMAKE_BUILD_TYPE}" STREQUAL "")
+
+INCLUDE(FindPkgConfig)
+
+MESSAGE("CHECK MODULE in MANAGER ${agent_pkges_LDFLAGS}")
+
+pkg_check_modules(agent_pkges REQUIRED glib-2.0 gobject-2.0 vconf dlog dbus-glib-1)
+
+FOREACH(flag ${agent_pkges_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")
+
+SET(ARM_CFALGS "${ARM_CFLAGS} -mapcs -mno-sched-prolog -mabi=aapcs-linux -mno-thumb-interwork -msoft-float -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("-fpie")
+
+#ADD_DEFINITIONS("-DSECURITY_SERVER")
+
+SET (DBUS_AUTO_ACTIVE 
+       ${CMAKE_CURRENT_SOURCE_DIR}/resource/com.samsung.slp.nfc.agent.service
+)
+
+SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed")
+
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+
+ADD_EXECUTABLE(${AGENT_DAEMON} ${AGENT_SRCS})
+
+TARGET_LINK_LIBRARIES(${AGENT_DAEMON} "-pie")
+TARGET_LINK_LIBRARIES(${AGENT_DAEMON} ${agent_pkges_LDFLAGS})
+
+ADD_CUSTOM_TARGET(dbus_agent_glue_private.h
+               COMMAND dbus-binding-tool --prefix=dbus_agent ${CMAKE_CURRENT_SOURCE_DIR}/resource/dbus_agent.xml 
+               --mode=glib-server --output=${CMAKE_CURRENT_SOURCE_DIR}/include/dbus_agent_glue_private.h
+               DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/resource/dbus_agent.xml
+)
+ADD_DEPENDENCIES(${AGENT_DAEMON} dbus_agent_glue_private.h)
+
+ADD_CUSTOM_TARGET(dbus_agent_binding_private.h
+               COMMAND dbus-binding-tool --prefix=dbus_agent ${CMAKE_CURRENT_SOURCE_DIR}/resource/dbus_agent.xml 
+               --mode=glib-client --output=${CMAKE_CURRENT_SOURCE_DIR}/include/dbus_agent_binding_private.h
+               DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/resource/dbus_agent.xml
+)
+ADD_DEPENDENCIES(${AGENT_DAEMON} dbus_agent_binding_private.h)
+
+INSTALL(TARGETS ${AGENT_DAEMON} DESTINATION bin)
+INSTALL(FILES ${DBUS_AUTO_ACTIVE} DESTINATION share/dbus-1/services/)
+
diff --git a/src/agent/include/net_nfc_agent_private.h b/src/agent/include/net_nfc_agent_private.h
new file mode 100644 (file)
index 0000000..fc89918
--- /dev/null
@@ -0,0 +1,26 @@
+/*\r
+  * Copyright 2012  Samsung Electronics Co., Ltd\r
+  *\r
+  * Licensed under the Flora License, Version 1.0 (the "License");\r
+  * you may not use this file except in compliance with the License.\r
+  * You may obtain a copy of the License at\r
+\r
+  *     http://www.tizenopensource.org/license\r
+  *\r
+  * Unless required by applicable law or agreed to in writing, software\r
+  * distributed under the License is distributed on an "AS IS" BASIS,\r
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+  * See the License for the specific language governing permissions and\r
+  * limitations under the License.\r
+  */\r
+\r
+#ifndef __NET_NFC_AGENT__\r
+#define __NET_NFC_AGENT__\r
+\r
+\r
+int _net_nfc_launch_net_nfc_manager ();\r
+int _net_nfc_terminate_net_nfc_manager ();\r
+int _net_nfc_is_terminated ();\r
+\r
+\r
+#endif\r
diff --git a/src/agent/include/net_nfc_dbus_agent_obj_private.h b/src/agent/include/net_nfc_dbus_agent_obj_private.h
new file mode 100644 (file)
index 0000000..b067c39
--- /dev/null
@@ -0,0 +1,64 @@
+/*
+  * Copyright 2012  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://www.tizenopensource.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 <glib-object.h>
+#include <dbus/dbus-glib-bindings.h>
+
+
+typedef struct _Dbus_Agent Dbus_Agent;
+typedef struct _Dbus_AgentClass Dbus_AgentClass;
+
+#define DBUS_AGENT_NAME "com.samsung.slp.nfc.agent"
+#define DBUS_AGENT_PATH "/com/samsung/slp/nfc/agent"
+
+
+GType dbus_agent_get_type (void);
+
+struct _Dbus_Agent
+{
+  GObject parent;
+  int status;
+  DBusGConnection *connection;
+};
+
+struct _Dbus_AgentClass
+{
+  GObjectClass parent;
+};
+
+#define DBUS_AGENT_TYPE                                (dbus_agent_get_type ())
+#define DBUS_AGENT(object)                     (G_TYPE_CHECK_INSTANCE_CAST ((object), DBUS_AGENT_TYPE, Dbus_Agent))
+#define DBUS_AGENT_CLASS(klass)                (G_TYPE_CHECK_CLASS_CAST ((klass), DBUS_AGENT_TYPE, Dbus_AgentClass))
+#define IS_DBUS_AGENT(object)                  (G_TYPE_CHECK_INSTANCE_TYPE ((object), DBUS_AGENT_TYPE))
+#define IS_DBUS_AGENT_CLASS(klass)     (G_TYPE_CHECK_CLASS_TYPE ((klass), DBUS_AGENT_TYPE))
+#define DBUS_AGENT_GET_CLASS(obj)              (G_TYPE_INSTANCE_GET_CLASS ((obj), DBUS_AGENT_TYPE, Dbus_AgentClass))
+
+typedef enum
+{
+  DBUS_AGENT_ERROR_INVALID_PRAM
+} Dbus_Agent_Error;
+
+GQuark dbus_agent_error_quark (void);
+#define DBUS_AGENT_ERROR dbus_agent_error_quark ()
+
+/**
+ *     launch the nfc-manager
+ */
+gboolean dbus_agent_launch (Dbus_Agent *dbus_agent, guint *result_val, GError **error);
+
+gboolean dbus_agent_terminate (Dbus_Agent *dbus_agent, guint *result_val, GError **error);
+
+
diff --git a/src/agent/net_nfc_agent.c b/src/agent/net_nfc_agent.c
new file mode 100644 (file)
index 0000000..1ef939d
--- /dev/null
@@ -0,0 +1,308 @@
+/*\r
+  * Copyright 2012  Samsung Electronics Co., Ltd\r
+  *\r
+  * Licensed under the Flora License, Version 1.0 (the "License");\r
+  * you may not use this file except in compliance with the License.\r
+  * You may obtain a copy of the License at\r
+\r
+  *     http://www.tizenopensource.org/license\r
+  *\r
+  * Unless required by applicable law or agreed to in writing, software\r
+  * distributed under the License is distributed on an "AS IS" BASIS,\r
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+  * See the License for the specific language governing permissions and\r
+  * limitations under the License.\r
+  */\r
+\r
+#include <stdlib.h>\r
+#include <string.h>\r
+#include <unistd.h>\r
+#include <pthread.h>\r
+#include <stdio.h>\r
+#include <sys/types.h>\r
+#include <sys/wait.h>\r
+\r
+#include <glib-object.h>\r
+#include <glib.h>\r
+#include <sys/utsname.h>\r
+#include "vconf.h"\r
+#include "vconf-keys.h"\r
+\r
+#include "net_nfc_debug_private.h"\r
+#include "net_nfc_util_defines.h"\r
+#include "net_nfc_dbus_agent_obj_private.h"\r
+#include "net_nfc_agent_private.h"\r
+\r
+const char *net_nfc_daemon = "/usr/bin/nfc-manager-daemon";\r
+\r
+#define VCONF_FALSE 0\r
+#define VCONF_TRUE 1\r
+\r
+#ifndef NET_NFC_SETUP_ENABLE\r
+#define NET_NFC_SETUP_DEFAULT VCONF_FALSE\r
+#endif\r
+\r
+static pthread_mutex_t g_queue_lock = PTHREAD_MUTEX_INITIALIZER;\r
+static pid_t manager_pid = 0;\r
+static int child_status = 0;\r
+\r
+\r
+#define device_file_path_plugin "/usr/lib/libnfc-plugin.so"\r
+#define device_file_path_plugin_65 "/usr/lib/libnfc-plugin-65nxp.so"\r
+\r
+int __net_nfc_intialize_dbus_connection();\r
+int __net_nfc_register_child_sig_handler();\r
+void __net_nfc_sig_child_cb(int signo);\r
+void *__net_nfc_fork_thread(void *data);\r
+\r
+int main(int argc, char **argv)\r
+{\r
+       int progress = 0;\r
+       GMainLoop *event_loop;\r
+       FILE *fp = NULL;\r
+\r
+       if (!g_thread_supported())\r
+       {\r
+               g_thread_init(NULL);\r
+       }\r
+       dbus_g_thread_init();\r
+       g_type_init();\r
+\r
+       /* reset progress key */\r
+       if (vconf_get_int(NET_NFC_VCONF_KEY_PROGRESS, &progress) == 0)\r
+       {\r
+               DEBUG_MSG("==========================================");\r
+               DEBUG_MSG("Old NET_NFC_VCONF_KEY_PROGRESS value is %d", progress);\r
+               DEBUG_MSG("==========================================");\r
+       }\r
+\r
+       if (vconf_set_int(NET_NFC_VCONF_KEY_PROGRESS, 0) != 0)\r
+       {\r
+               DEBUG_ERR_MSG("vconf_set_int failed");\r
+       }\r
+\r
+       /* run manager first */\r
+       __net_nfc_fork_thread(NULL);\r
+\r
+       if (__net_nfc_intialize_dbus_connection() != VCONF_TRUE)\r
+       {\r
+               DEBUG_ERR_MSG("DBUS: intialize dbus is failed");\r
+       }\r
+       if (__net_nfc_register_child_sig_handler() != VCONF_TRUE)\r
+       {\r
+               DEBUG_ERR_MSG("SIGCHLD: registering sig child is failed");\r
+       }\r
+\r
+       /* to check H/W which dose not support NFC */\r
+\r
+       fp = fopen(device_file_path_plugin, "r");\r
+       if(fp == NULL)\r
+       {\r
+               fp = fopen(device_file_path_plugin_65, "r");\r
+               if(fp == NULL)\r
+               {\r
+                       vconf_set_bool(VCONFKEY_NFC_FEATURE, VCONFKEY_NFC_FEATURE_OFF);\r
+                       vconf_set_bool(VCONFKEY_NFC_STATE, FALSE);\r
+                       DEBUG_ERR_MSG("There is NO plugin");\r
+               }\r
+               else\r
+               {\r
+                       vconf_set_bool(VCONFKEY_NFC_FEATURE, VCONFKEY_NFC_FEATURE_ON);\r
+                       DEBUG_ERR_MSG("There is device_file_path_plugin_65");\r
+                       fclose(fp);\r
+               }\r
+       }\r
+       else\r
+       {\r
+               vconf_set_bool(VCONFKEY_NFC_FEATURE, VCONFKEY_NFC_FEATURE_ON);\r
+               DEBUG_ERR_MSG("There is  device_file_path_plugin ");\r
+\r
+               fclose(fp);\r
+       }\r
+\r
+\r
+       event_loop = g_main_loop_new(NULL, FALSE);\r
+       g_main_loop_run(event_loop);\r
+\r
+       return 0;\r
+}\r
+\r
+int __net_nfc_register_child_sig_handler()\r
+{\r
+       struct sigaction act;\r
+\r
+       act.sa_handler = __net_nfc_sig_child_cb;\r
+       sigemptyset(&act.sa_mask);\r
+       act.sa_flags = SA_NOCLDSTOP;\r
+\r
+       if (sigaction(SIGCHLD, &act, NULL) < 0)\r
+       {\r
+               return VCONF_FALSE;\r
+       }\r
+       return VCONF_TRUE;\r
+}\r
+\r
+void *__net_nfc_fork_thread(void *data)\r
+{\r
+       int state, progress;\r
+       int result;\r
+\r
+       if (data != NULL)\r
+       {\r
+               DEBUG_MSG("child process is terminated with: %d ", *((int *)data));\r
+       }\r
+\r
+       result = vconf_get_bool(VCONFKEY_NFC_STATE, &state);\r
+       if (result != 0)\r
+       {\r
+               DEBUG_MSG("VCONFKEY_NFC_STATE is not exist: %d ", result);\r
+               return NULL;\r
+       }\r
+\r
+       result = vconf_get_int(NET_NFC_VCONF_KEY_PROGRESS, &progress);\r
+       if (result != 0)\r
+       {\r
+               DEBUG_MSG("NET_NFC_VCONF_KEY_PROGRESS is not exist: %d ", result);\r
+\r
+               progress = 0;\r
+               result = vconf_set_int(NET_NFC_VCONF_KEY_PROGRESS, progress);\r
+               if (result != 0)\r
+               {\r
+                       DEBUG_ERR_MSG("vconf_set_int failed");\r
+                       return NULL;\r
+               }\r
+       }\r
+\r
+       if (progress != 0)\r
+       {\r
+               DEBUG_ERR_MSG("Error occur in progress [%d]", progress);\r
+\r
+               /* off */\r
+               result = vconf_set_bool(VCONFKEY_NFC_STATE, 0);\r
+               if (result != 0)\r
+               {\r
+                       DEBUG_MSG("vconf_set_int failed", result);\r
+               }\r
+               return NULL;\r
+       }\r
+\r
+       if (state == TRUE)\r
+       {\r
+               DEBUG_MSG("Vconf value is true");\r
+               if (_net_nfc_launch_net_nfc_manager() == VCONF_FALSE)\r
+               {\r
+                       DEBUG_ERR_MSG("sigchild is called");\r
+               }\r
+       }\r
+\r
+       return NULL;\r
+}\r
+\r
+void __net_nfc_sig_child_cb(int signo)\r
+{\r
+\r
+       pthread_attr_t attr;\r
+       pthread_attr_init(&attr);\r
+       pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);\r
+       pthread_t sig_thread;\r
+       pid_t child_pid;\r
+       int status;\r
+\r
+       child_pid = waitpid(-1, &status, 0);\r
+\r
+       child_status = status;\r
+\r
+       // do not use lock here!\r
+       manager_pid = 0;\r
+\r
+       pthread_create(&sig_thread, &attr, __net_nfc_fork_thread, &child_status);\r
+}\r
+\r
+int _net_nfc_is_terminated()\r
+{\r
+       return (manager_pid == 0);\r
+}\r
+\r
+int _net_nfc_launch_net_nfc_manager()\r
+{\r
+       pthread_mutex_lock(&g_queue_lock);\r
+       if (manager_pid == 0)\r
+       {\r
+               manager_pid = fork();\r
+               if (manager_pid == 0)\r
+               {\r
+                       if (-1 == execl(net_nfc_daemon, net_nfc_daemon, NULL))\r
+                       {\r
+                               exit(0);\r
+                       }\r
+               }\r
+       }\r
+       else\r
+       {\r
+               DEBUG_MSG("NFC-manager is already running");\r
+               pthread_mutex_unlock(&g_queue_lock);\r
+               return VCONF_FALSE;\r
+       }\r
+       DEBUG_MSG("NFC-manager's PID %d", manager_pid);\r
+       pthread_mutex_unlock(&g_queue_lock);\r
+       return VCONF_TRUE;\r
+}\r
+\r
+int _net_nfc_terminate_net_nfc_manager()\r
+{\r
+       int status;\r
+\r
+       pthread_mutex_lock(&g_queue_lock);\r
+       if (manager_pid)\r
+       {\r
+               DEBUG_MSG("NFC-manager's PID %d", manager_pid);\r
+               kill(manager_pid, SIGKILL);\r
+               wait(&status);\r
+               manager_pid = 0;\r
+               pthread_mutex_unlock(&g_queue_lock);\r
+               return VCONF_TRUE;\r
+       }\r
+       pthread_mutex_unlock(&g_queue_lock);\r
+       return VCONF_FALSE;\r
+}\r
+\r
+int __net_nfc_intialize_dbus_connection()\r
+{\r
+       GError *error = NULL;\r
+       DBusGProxy *proxy;\r
+       GObject *object = NULL;\r
+       guint32 name;\r
+       DBusGConnection *connection;\r
+\r
+       connection = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);\r
+       if (connection == NULL)\r
+       {\r
+               DEBUG_ERR_MSG("DBUS: getting dbus connection is failed [%s]", error->message);\r
+               g_error_free(error);\r
+\r
+               return VCONF_FALSE;\r
+       }\r
+\r
+       object = g_object_new(DBUS_AGENT_TYPE, NULL);\r
+\r
+       dbus_g_connection_register_g_object(connection, DBUS_AGENT_PATH, object);\r
+\r
+       proxy = dbus_g_proxy_new_for_name(connection, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS);\r
+\r
+       // Make sure getting name is correct version or not\r
+       if (!org_freedesktop_DBus_request_name(proxy, DBUS_AGENT_NAME, 0, &name, &error))\r
+       {\r
+               DEBUG_ERR_MSG("DBUS: getting dbus proxy is failed [%s]", error->message);\r
+               g_error_free(error);\r
+\r
+               return VCONF_FALSE;\r
+       }\r
+\r
+       if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != name)\r
+       {\r
+               DEBUG_MSG("Requested name is: %d", name);\r
+       }\r
+\r
+       return VCONF_TRUE;\r
+}\r
+\r
diff --git a/src/agent/net_nfc_dbus_agent_obj.c b/src/agent/net_nfc_dbus_agent_obj.c
new file mode 100644 (file)
index 0000000..185ddc6
--- /dev/null
@@ -0,0 +1,137 @@
+/*
+  * Copyright 2012  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://www.tizenopensource.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 <stdlib.h>
+#include <glib-object.h>
+#include <dbus/dbus-glib-bindings.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <pthread.h>
+
+#include "net_nfc_typedef_private.h"
+#include "net_nfc_debug_private.h"
+#include "net_nfc_agent_private.h"
+#include "net_nfc_dbus_agent_obj_private.h"
+#include "dbus_agent_glue_private.h"
+#include "dbus_service_binding_private.h"
+
+G_DEFINE_TYPE(Dbus_Agent, dbus_agent, 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 dbus_agent_error_quark(void)
+{
+       return g_quark_from_static_string("dbus_agent_error");
+}
+
+static void dbus_agent_init(Dbus_Agent *dbus_agent)
+{
+       GError *error = NULL;
+
+       dbus_agent->connection = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
+       if (dbus_agent->connection == NULL)
+       {
+               DEBUG_MSG("failed to get dbus connection");
+       }
+}
+
+static void dbus_agent_class_init(Dbus_AgentClass *dbus_agent_class)
+{
+       dbus_g_object_type_install_info(DBUS_AGENT_TYPE, &dbus_glib_dbus_agent_object_info);
+}
+
+gboolean dbus_agent_launch(Dbus_Agent *dbus_agent, guint *result_val, GError **error)
+{
+       DBusGProxy *proxy;
+       guint status;
+       GError *inter_error = NULL;
+       int count = 0;
+
+       DEBUG_MSG("---- dbus_agent_launch is called -----");
+
+       proxy = dbus_g_proxy_new_for_name_owner(dbus_agent->connection, "com.samsung.slp.nfc.manager",
+               "/com/samsung/slp/nfc/manager", "com.samsung.slp.nfc.manager", &inter_error);
+       if (proxy != NULL)
+       {
+               DEBUG_MSG("Posting terminate again");
+               com_samsung_slp_nfc_manager_terminate(proxy, &status, &inter_error);
+       }
+       else
+       {
+               _net_nfc_terminate_net_nfc_manager();
+       }
+
+       DEBUG_MSG("Posting terminate success");
+
+       count = 0;
+       while (_net_nfc_is_terminated() == FALSE)
+       {
+               usleep(30000);
+               if (++count % 30)
+               {
+                       _net_nfc_terminate_net_nfc_manager();
+               }
+       }
+
+       if (_net_nfc_launch_net_nfc_manager() == FALSE)
+       {
+               return FALSE;
+       }
+
+       DEBUG_MSG("---- dbus_agent_launch is completed -----");
+
+       return TRUE;
+}
+
+gboolean dbus_agent_terminate(Dbus_Agent *dbus_agent, guint *result_val, GError **error)
+{
+       DBusGProxy *proxy;
+       guint status;
+       GError *inter_error = NULL;
+
+       DEBUG_MSG("---- dbus_agent_terminate is called -----");
+
+       proxy = dbus_g_proxy_new_for_name_owner(dbus_agent->connection, "com.samsung.slp.nfc.manager",
+               "/com/samsung/slp/nfc/manager", "com.samsung.slp.nfc.manager", &inter_error);
+
+       if (proxy == NULL)
+       {
+               _net_nfc_terminate_net_nfc_manager();
+       }
+       else
+       {
+               if (!com_samsung_slp_nfc_manager_se_only(proxy, &status, &inter_error))
+               {
+                       DEBUG_MSG("Termination is failed: %d", status);
+
+                       return FALSE;
+               }
+       }
+
+       DEBUG_MSG("---- dbus_agent_terminate is completed -----");
+
+       return TRUE;
+}
+
diff --git a/src/agent/resource/com.samsung.slp.nfc.agent.service b/src/agent/resource/com.samsung.slp.nfc.agent.service
new file mode 100644 (file)
index 0000000..63fe4ec
--- /dev/null
@@ -0,0 +1,3 @@
+[D-BUS Service]
+Name=com.samsung.slp.nfc.agent
+Exec=/usr/bin/nfc-agent
diff --git a/src/agent/resource/dbus_agent.xml b/src/agent/resource/dbus_agent.xml
new file mode 100644 (file)
index 0000000..6da63c0
--- /dev/null
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<node name="/com/samsung/slp/nfc/agent">
+
+  <interface name="com.samsung.slp.nfc.agent">
+
+    <method name="Launch">
+      <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="dbus_agent_launch"/>
+      <arg type="u" name="result_val" direction="out"/>
+    </method>
+
+    <method name="Terminate">
+      <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="dbus_agent_terminate"/>
+      <arg type="u" name="result_val" direction="out"/>
+    </method>
+
+  </interface>
+</node>
diff --git a/src/clientlib/CMakeLists.txt b/src/clientlib/CMakeLists.txt
new file mode 100644 (file)
index 0000000..e948d7b
--- /dev/null
@@ -0,0 +1,96 @@
+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)
+
+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 -mno-thumb-interwork -msoft-float -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("-fpie")
+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_data.h
+       include/net_nfc_apdu.h
+       include/net_nfc_exchanger.h
+       include/net_nfc_internal_se.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 (file)
index 0000000..c8ee8cf
--- /dev/null
@@ -0,0 +1,387 @@
+/*
+  * Copyright 2012  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://www.tizenopensource.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 ans 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 <net_nfc_typedef.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_target_info.h>
+#include <net_nfc_ndef_message.h>
+#include <net_nfc_ndef_record.h>
+#include <net_nfc_data.h>
+#include <net_nfc_ndef_message_handover.h>
+#include <net_nfc_internal_se.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define NET_NFC_SERVICE_EMPTY_TYPE "http://tizen.org/appsvc/operation/nfc_empty_type"
+#define NET_NFC_SERVICE_WELL_KNOWN_TYPE "http://tizen.org/appsvc/operation/nfc_well_known_type"
+#define NET_NFC_SERVICE_EXTERNAL_TYPE "http://tizen.org/appsvc/operation/nfc_external_type"
+#define NET_NFC_SERVICE_MIME_TYPE "http://tizen.org/appsvc/operation/nfc_mime_type"
+#define NET_NFC_SERVICE_URI_TYPE "http://tizen.org/appsvc/operation/nfc_uri_type"
+
+/**
+
+@addtogroup NET_NFC_MANAGER_API
+@{
+       This document is for the APIs reference document
+
+        NFC Manager defines are defined in <net_nfc_typedef.h>
+
+        @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.
+
+       <br>
+
+       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
+*/
+bool net_nfc_get_launch_popup_state(void);
+
+
+/**
+       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(int client_type);
+
+net_nfc_error_e net_nfc_state_deactivate(void);
+
+net_nfc_error_e net_nfc_sim_test(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);
+
+/**
+@} */
+
+#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 100644 (file)
index 0000000..7671c9e
--- /dev/null
@@ -0,0 +1,129 @@
+/*\r
+  * Copyright 2012  Samsung Electronics Co., Ltd\r
+  *\r
+  * Licensed under the Flora License, Version 1.0 (the "License");\r
+  * you may not use this file except in compliance with the License.\r
+  * You may obtain a copy of the License at\r
+\r
+  *     http://www.tizenopensource.org/license\r
+  *\r
+  * Unless required by applicable law or agreed to in writing, software\r
+  * distributed under the License is distributed on an "AS IS" BASIS,\r
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+  * See the License for the specific language governing permissions and\r
+  * limitations under the License.\r
+  */\r
+\r
+#ifndef __NET_NFC_APDU__\r
+#define __NET_NFC_APDU__\r
+\r
+#include "net_nfc_typedef.h"\r
+\r
+\r
+#ifdef __cplusplus\r
+ extern "C" {\r
+#endif\r
+\r
+\r
+typedef unsigned int apdu_slot_t;\r
+typedef unsigned int apdu_channel_t;\r
+typedef void (* net_nfc_apdu_response_cb ) (net_nfc_error_e result, apdu_channel_t channel, data_h data, void* user_data);\r
+\r
+/**\r
+@addtogroup NET_NFC_MANAGER_APDU\r
+@{\r
+\r
+*/\r
+\r
+/**\r
+       initialize the apdu api. the callback function will be called when the data is arrived from simcard or SE\r
+\r
+       @param[in]              callback                callback function\r
+       @param[in]              user_data       context value that will be delivered to the callback function\r
+\r
+       @return         return the result of the calling the function\r
+*/\r
+net_nfc_error_e net_nfc_register_apdu_cb (net_nfc_apdu_response_cb callback, void * user_data);\r
+\r
+/**\r
+\r
+       allows to select the slot. UICC or SE\r
+\r
+       <ul>\r
+       <li> slot# 0 : UICC     <\li>\r
+       <li> slot# 1 : Secure Element<\li>\r
+       </ul>\r
+\r
+       @param[in]              slot            slot for mms\r
+\r
+       @return         return the result of the calling the function\r
+*/\r
+net_nfc_error_e net_nfc_select_apdu_slot (apdu_slot_t slot);\r
+\r
+/**\r
+       Answer to reset  is the sequence of bytes output by a chip card after the card reader has electrically reset the card.\r
+       The ATR tells the reader which communication capabilities the card has. The format of the ATR is defined in ISO/IEC 7816-3.[1]\r
+       this function return ATR data if the simcard is available, or NULL will be returned\r
+\r
+       @param[out]             data            ATR data will be returned if the simcard is available.\r
+\r
+       @return         return the result of the calling the function\r
+\r
+*/\r
+net_nfc_error_e net_nfc_get_apdu_answer_to_reset (data_h  data);\r
+\r
+/**\r
+       this opens a channel to communicate with application on the simcard.\r
+       you may open the channel with\r
+\r
+       @param[out]             channel         return the assined chennel\r
+       @param[in]              aid                     application id that mached in the simcard application\r
+\r
+       @return         return the result of the calling the function\r
+\r
+*/\r
+net_nfc_error_e net_nfc_open_apdu_channel (apdu_channel_t *channel , net_nfc_string_t aid);\r
+\r
+/**\r
+       send the apud data to opened channel.\r
+\r
+       @param[in]              channel                 channel number that already opened\r
+       @param[in]              data                    data value that will be send\r
+\r
+       @return         return the result of the calling the function\r
+*/\r
+net_nfc_error_e net_nfc_send_apdu_command (apdu_channel_t channel, data_t data);\r
+\r
+/**\r
+       closes opened channel\r
+\r
+       @param[in]              channel                 channel number\r
+\r
+       @return         return the result of the calling the function\r
+*/\r
+net_nfc_error_e net_nfc_close_apdu_channel (apdu_channel_t channel);\r
+\r
+/**\r
+       disconnect all the channel and return to original state. it stops calling callback function\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception NET_NFC_NOT_REGISTERED       unset is requested but the callback was not registered before\r
+*/\r
+net_nfc_error_e net_nfc_unset_apdu_cb (void);\r
+\r
+\r
+/**\r
+@}\r
+*/\r
+\r
+\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+\r
+\r
+#endif\r
+\r
+\r
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 100644 (file)
index 0000000..685316d
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+  * Copyright 2012  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://www.tizenopensource.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"
+
+void net_nfc_client_call_dispatcher_in_ecore_main_loop(net_nfc_response_cb client_cb, net_nfc_response_msg_t* msg);
+void net_nfc_client_call_dispatcher_in_g_main_loop(net_nfc_response_cb client_cb, net_nfc_response_msg_t* msg);
+void net_nfc_client_call_dispatcher_in_current_context(net_nfc_response_cb client_cb, 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 100644 (file)
index 0000000..330ecb9
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+  * Copyright 2012  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://www.tizenopensource.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"
+
+net_nfc_error_e _net_nfc_client_send_reqeust(net_nfc_request_msg_t *msg, ...);
+
+bool net_nfc_client_is_connected();
+net_nfc_error_e net_nfc_client_socket_initialize();
+net_nfc_error_e net_nfc_client_socket_finalize();
+
+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 100644 (file)
index 0000000..9fff083
--- /dev/null
@@ -0,0 +1,38 @@
+/*\r
+  * Copyright 2012  Samsung Electronics Co., Ltd\r
+  *\r
+  * Licensed under the Flora License, Version 1.0 (the "License");\r
+  * you may not use this file except in compliance with the License.\r
+  * You may obtain a copy of the License at\r
+\r
+  *     http://www.tizenopensource.org/license\r
+  *\r
+  * Unless required by applicable law or agreed to in writing, software\r
+  * distributed under the License is distributed on an "AS IS" BASIS,\r
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+  * See the License for the specific language governing permissions and\r
+  * limitations under the License.\r
+  */\r
+\r
+#ifndef __NET_NFC_CLIENT_NET_NFC_PRIVATE_H__\r
+#define __NET_NFC_CLIENT_NET_NFC_PRIVATE_H__\r
+\r
+#include "net_nfc_typedef_private.h"\r
+\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+client_context_t* net_nfc_get_client_context();\r
+bool net_nfc_tag_is_connected();\r
+\r
+/**\r
+@} */\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+\r
+\r
+#endif\r
+\r
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 100644 (file)
index 0000000..0928c11
--- /dev/null
@@ -0,0 +1,31 @@
+/*\r
+  * Copyright 2012  Samsung Electronics Co., Ltd\r
+  *\r
+  * Licensed under the Flora License, Version 1.0 (the "License");\r
+  * you may not use this file except in compliance with the License.\r
+  * You may obtain a copy of the License at\r
+\r
+  *     http://www.tizenopensource.org/license\r
+  *\r
+  * Unless required by applicable law or agreed to in writing, software\r
+  * distributed under the License is distributed on an "AS IS" BASIS,\r
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+  * See the License for the specific language governing permissions and\r
+  * limitations under the License.\r
+  */\r
+\r
+#ifndef __NET_NFC_CLIENT_UTIL_PRIVATE__\r
+#define __NET_NFC_CLENT_UTIL_PRIVATE__\r
+\r
+/* Memory utils */\r
+/* free memory, after free given memory it set NULL. Before proceed free, this function also check NULL */\r
+void __net_nfc_client_util_free_mem(void** mem, char * filename, unsigned int line);\r
+/* allocation memory */\r
+void __net_nfc_client_util_alloc_mem(void** mem, int size, char * filename, unsigned int line);\r
+#define         _net_nfc_client_util_alloc_mem(mem,size) __net_nfc_client_util_alloc_mem((void **)&mem,size,__FILE__, __LINE__)\r
+#define         _net_nfc_client_util_free_mem(mem) __net_nfc_client_util_free_mem((void **)&mem,__FILE__, __LINE__)\r
+\r
+\r
+\r
+#endif\r
+\r
diff --git a/src/clientlib/include/net_nfc_data.h b/src/clientlib/include/net_nfc_data.h
new file mode 100644 (file)
index 0000000..0e834c7
--- /dev/null
@@ -0,0 +1,143 @@
+/*\r
+  * Copyright 2012  Samsung Electronics Co., Ltd\r
+  *\r
+  * Licensed under the Flora License, Version 1.0 (the "License");\r
+  * you may not use this file except in compliance with the License.\r
+  * You may obtain a copy of the License at\r
+\r
+  *     http://www.tizenopensource.org/license\r
+  *\r
+  * Unless required by applicable law or agreed to in writing, software\r
+  * distributed under the License is distributed on an "AS IS" BASIS,\r
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+  * See the License for the specific language governing permissions and\r
+  * limitations under the License.\r
+  */\r
+\r
+#include <net_nfc_typedef.h>\r
+\r
+\r
+#ifndef __NET_NFC_DATA_H__\r
+#define __NET_NFC_DATA_H__\r
+\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+\r
+/**\r
+\r
+@addtogroup NET_NFC_MANAGER_INFO\r
+@{\r
+       This document is for the APIs reference document\r
+\r
+        NFC Manager defines are defined in <nfc-manager-def.h>\r
+\r
+        @li @c #net_nfc_initialize                  Initialize the nfc device.\r
+\r
+*/\r
+\r
+/**\r
+       create data handler only.\r
+\r
+       @param[out]     data            data handler\r
+\r
+       @return         return the result of this operation\r
+\r
+       @exception NET_NFC_NULL_PARAMETER               parameter(s) has(have) illigal NULL pointer(s)\r
+       @exception NET_NFC_ALLOC_FAIL                   memory allocation is failed\r
+*/\r
+\r
+net_nfc_error_e net_nfc_create_data_only (data_h* data);\r
+\r
+/**\r
+       create data handler with initial values, bytes will be copied into the data handler.\r
+\r
+       @param[out]     data            data handler\r
+       @param[in]      bytes   binary data\r
+       @param[in]      length  size of binary data;\r
+\r
+       @return         return the result of this operation\r
+\r
+       @exception NET_NFC_NULL_PARAMETER               parameter(s) has(have) illigal NULL pointer(s)\r
+       @exception NET_NFC_ALLOC_FAIL                   memory allocation is failed\r
+*/\r
+net_nfc_error_e net_nfc_create_data (data_h* data, const uint8_t* bytes, const uint32_t length);\r
+\r
+/**\r
+       get the byes and length from data handler. data handler assume bytes may have '0x0' value.\r
+       that's why this function also provides the length.\r
+\r
+       @param[in]      data            data handler\r
+       @param[out]     bytes   binary pointer (it returns the direct pointer of handler's data) do not free this\r
+       @param[out]     length  length of the binary data;\r
+\r
+       @return         return the result of this operation\r
+\r
+       @exception NET_NFC_NULL_PARAMETER               parameter(s) has(have) illigal NULL pointer(s)\r
+*/\r
+net_nfc_error_e net_nfc_get_data (const data_h data, uint8_t** bytes, uint32_t * length);\r
+\r
+/**\r
+       replace the data handler with given bytes. binary data (bytes) will be copied to data hander.\r
+       application should free or use local variable for given byte pointer.\r
+\r
+       @param[in]      data            data handler\r
+       @param[in]      bytes   binary data\r
+       @param[in]      length  size of binary data\r
+\r
+       @return         return the result of this operation\r
+\r
+       @exception NET_NFC_NULL_PARAMETER               parameter(s) has(have) illigal NULL pointer(s)\r
+*/\r
+\r
+net_nfc_error_e net_nfc_set_data (const data_h data, const uint8_t* bytes, const uint32_t length);\r
+\r
+/**\r
+       get length of data handler's bytes.\r
+\r
+       @param[in]      data            data handler\r
+\r
+       @return         length of bytes length\r
+\r
+       @exception      0 is returned if data is NULL\r
+*/\r
+\r
+uint32_t net_nfc_get_data_length (const data_h data);\r
+\r
+/**\r
+       get pointer of the handler's bytes (do not free this. it wll be freed when the application call "net_nfc_free_data" function\r
+\r
+       @param[in]      data            data handler\r
+\r
+       @return         the pointer of bytes.\r
+\r
+       @exception      NULL is returned if data is NULL\r
+*/\r
+\r
+uint8_t * net_nfc_get_data_buffer (const data_h data);\r
+\r
+/**\r
+       free data handler. (it also free the copied bytes)\r
+\r
+       @param[in]      data            data handler\r
+\r
+       @return         return the result of this operation\r
+\r
+       @exception NET_NFC_NULL_PARAMETER               parameter(s) has(have) illigal NULL pointer(s)\r
+*/\r
+\r
+net_nfc_error_e net_nfc_free_data (data_h data);\r
+\r
+\r
+\r
+/**\r
+@}\r
+*/\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+\r
+\r
+#endif\r
+\r
diff --git a/src/clientlib/include/net_nfc_exchanger.h b/src/clientlib/include/net_nfc_exchanger.h
new file mode 100644 (file)
index 0000000..4ea65b8
--- /dev/null
@@ -0,0 +1,163 @@
+/*\r
+  * Copyright 2012  Samsung Electronics Co., Ltd\r
+  *\r
+  * Licensed under the Flora License, Version 1.0 (the "License");\r
+  * you may not use this file except in compliance with the License.\r
+  * You may obtain a copy of the License at\r
+\r
+  *     http://www.tizenopensource.org/license\r
+  *\r
+  * Unless required by applicable law or agreed to in writing, software\r
+  * distributed under the License is distributed on an "AS IS" BASIS,\r
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+  * See the License for the specific language governing permissions and\r
+  * limitations under the License.\r
+  */\r
+\r
+#ifndef __SLP_NET_NFC_EXCHANGER_H__\r
+#define __SLP_NET_NFC_EXCHANGER_H__\r
+\r
+\r
+#include "net_nfc_typedef.h"\r
+\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+/**\r
+@addtogroup NET_NFC_MANAGER_EXCHANGE\r
+@{\r
+\r
+*/\r
+\r
+\r
+/**\r
+       create net_nfc_exchagner raw type data handler with given values\r
+\r
+       @param[out]     ex_data                 exchangner handler\r
+       @param[in]      payload         the data will be deliver (NDEF message)\r
+\r
+       @return                 result of this function call\r
+\r
+       @exception NET_NFC_ALLOC_FAIL                   memory allocation is failed\r
+       @exception NET_NFC_NULL_PARAMETER               parameter(s) has(have) illegal NULL pointer(s)\r
+*/\r
+net_nfc_error_e net_nfc_create_exchanger_data(net_nfc_exchanger_data_h *ex_data, data_h payload);\r
+\r
+/**\r
+       this makes free exchagner data handler\r
+\r
+       @param[in]      ex_data                 exchagner handler\r
+\r
+       @return                 result of this function call\r
+\r
+       @exception NET_NFC_NULL_PARAMETER               parameter(s) has(have) illigal NULL pointer(s)\r
+*/\r
+\r
+net_nfc_error_e net_nfc_free_exchanger_data (net_nfc_exchanger_data_h ex_data);\r
+\r
+/**\r
+\r
+       register callback function and initialize the exchange API. this function also make connection to the NFC-manager\r
+       only one functionality of net_nfc_initialize and net_nfc_set_exchanger_cb is permitted in a running time.\r
+       So, call net_nfc_deinitailze if net_nfc_initialize is called before when you want to register exchanger callback.\r
+\r
+\r
+       @param[in]              callback                callback function will be used in event\r
+       @param[in]              user_param      this data will be deliver to callback function\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception      NET_NFC_NOT_ALLOWED_OPERATION           net_nfc_initailzed is called before. so call net_nfc_deinitialize first.\r
+\r
+*/\r
+net_nfc_error_e net_nfc_set_exchanger_cb (net_nfc_exchanger_cb callback, void * user_param);\r
+\r
+/**\r
+       disconnect the connection from nfc-manager server and stop calling the callback function\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception NET_NFC_NOT_REGISTERED       unset is requested but the callback was not registered before\r
+*/\r
+\r
+net_nfc_error_e net_nfc_unset_exchanger_cb (void);\r
+\r
+/**\r
+       discovered P2P device and send the NET_NFC_MESSAGE_P2P_SEND message to server  from client.\r
+\r
+\r
+       @param[in]      ex_data                        exchangner handler\r
+       @param[in]      target_handle           target device handle\r
+\r
+       @return               return the result of the calling the function\r
+\r
+       @exception NET_NFC_ALLOC_FAIL   memory allocation is failed\r
+*/\r
+\r
+net_nfc_error_e net_nfc_send_exchanger_data (net_nfc_exchanger_data_h ex_handle, net_nfc_target_handle_h target_handle);\r
+\r
+/**\r
+       request connection handover with discovered P2P device\r
+\r
+       @param[in]      target_handle           target device handle\r
+       @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)\r
+\r
+       @return                 result of this function call\r
+\r
+       @exception NET_NFC_ALLOC_FAIL                   memory allocation is failed\r
+       @exception NET_NFC_NULL_PARAMETER               parameter(s) has(have) illigal NULL pointer(s)\r
+*/\r
+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);\r
+\r
+/**\r
+       get alternative carrier type from connection handover information handle.\r
+\r
+       @param[in]      info_handle             connection handover information handle\r
+       @param[out]     type    alternative carrier type\r
+\r
+       @return         return the result of this operation\r
+\r
+       @exception NET_NFC_NULL_PARAMETER               parameter(s) has(have) illigal NULL pointer(s)\r
+*/\r
+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);\r
+\r
+/**\r
+       get alternative carrier dependant data from connection handover information handle.\r
+       Bluetooth : target device address\r
+       Wifi : target device ip address\r
+\r
+       @param[in]      info_handle             connection handover information handle\r
+       @param[out]     data    alternative carrier data\r
+\r
+       @return         return the result of this operation\r
+\r
+       @exception NET_NFC_ALLOC_FAIL                   memory allocation is failed\r
+       @exception NET_NFC_NULL_PARAMETER               parameter(s) has(have) illigal NULL pointer(s)\r
+*/\r
+net_nfc_error_e net_nfc_exchanger_get_alternative_carrier_data(net_nfc_connection_handover_info_h info_handle, data_h *data);\r
+\r
+/**\r
+       this makes free alternative carrier data handler\r
+\r
+       @param[in]      info_handle             alternative carrier data handler\r
+\r
+       @return                 result of this function call\r
+\r
+       @exception NET_NFC_NULL_PARAMETER               parameter(s) has(have) illigal NULL pointer(s)\r
+*/\r
+net_nfc_error_e net_nfc_exchanger_free_alternative_carrier_data(net_nfc_connection_handover_info_h  info_handle);\r
+\r
+\r
+/**\r
+@}\r
+\r
+*/\r
+\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+\r
+\r
+#endif\r
diff --git a/src/clientlib/include/net_nfc_exchanger_private.h b/src/clientlib/include/net_nfc_exchanger_private.h
new file mode 100644 (file)
index 0000000..e39c606
--- /dev/null
@@ -0,0 +1,42 @@
+/*\r
+  * Copyright 2012  Samsung Electronics Co., Ltd\r
+  *\r
+  * Licensed under the Flora License, Version 1.0 (the "License");\r
+  * you may not use this file except in compliance with the License.\r
+  * You may obtain a copy of the License at\r
+\r
+  *     http://www.tizenopensource.org/license\r
+  *\r
+  * Unless required by applicable law or agreed to in writing, software\r
+  * distributed under the License is distributed on an "AS IS" BASIS,\r
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+  * See the License for the specific language governing permissions and\r
+  * limitations under the License.\r
+  */\r
+\r
+#ifndef __SLP_NET_NFC_EXCHANGER_H__\r
+#define __SLP_NET_NFC_EXCHANGER_H__\r
+\r
+\r
+#include "net_nfc_typedef.h"\r
+#include "net_nfc_typedef_private.h"\r
+\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+\r
+net_nfc_exchanger_cb net_nfc_get_exchanger_cb (void);\r
+\r
+/**\r
+@}\r
+\r
+*/\r
+\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+\r
+\r
+#endif\r
diff --git a/src/clientlib/include/net_nfc_internal_se.h b/src/clientlib/include/net_nfc_internal_se.h
new file mode 100644 (file)
index 0000000..2d6730d
--- /dev/null
@@ -0,0 +1,140 @@
+/*\r
+  * Copyright 2012  Samsung Electronics Co., Ltd\r
+  *\r
+  * Licensed under the Flora License, Version 1.0 (the "License");\r
+  * you may not use this file except in compliance with the License.\r
+  * You may obtain a copy of the License at\r
+\r
+  *     http://www.tizenopensource.org/license\r
+  *\r
+  * Unless required by applicable law or agreed to in writing, software\r
+  * distributed under the License is distributed on an "AS IS" BASIS,\r
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+  * See the License for the specific language governing permissions and\r
+  * limitations under the License.\r
+  */\r
+\r
+#ifndef __NET_NFC_INTERNAL_SE_H__\r
+#define __NET_NFC_INTERNAL_SE_H__\r
+\r
+#include "net_nfc_typedef.h"\r
+\r
+\r
+#ifdef __cplusplus\r
+ extern "C" {\r
+#endif\r
+\r
+\r
+/**\r
+\r
+@addtogroup NET_NFC_MANAGER_SECURE_ELEMENT\r
+@{\r
+       This document is for the APIs reference document\r
+\r
+        NFC Manager defines are defined in <net_nfc_typedef.h>\r
+\r
+        @li @c #net_nfc_set_secure_element_type                set secure element type\r
+        @li @c #net_nfc_get_secure_element_type                get current selected secure element\r
+        @li @c #net_nfc_open_internal_secure_element   open selected secure element\r
+        @li @c #net_nfc_close_internal_secure_element  close selected secure element\r
+        @li @c #net_nfc_send_apdu                                              send apdu\r
+\r
+\r
+\r
+*/\r
+\r
+/**\r
+       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\r
+       secure element by emitting RF\r
+\r
+       \par Sync (or) Async: Sync\r
+       This is a Asynchronous API\r
+\r
+       @param[in]      se_type                 secure element type\r
+       @param[in]      trans_param             user data that will be delivered to callback\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception NET_NFC_INVALID_PARAM        not supported se_type\r
+\r
+*/\r
+\r
+net_nfc_error_e net_nfc_set_secure_element_type(net_nfc_se_type_e se_type, void* trans_param);\r
+\r
+/**\r
+       get current select se type.\r
+\r
+       \par Sync (or) Async: Sync\r
+       This is a Asynchronous API\r
+\r
+       @param[in]      se_type                 secure element type\r
+       @param[in]      trans_param             user data that will be delivered to callback\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception NET_NFC_INVALID_PARAM        not supported se_type\r
+\r
+*/\r
+\r
+net_nfc_error_e net_nfc_get_secure_element_type(void* trans_param);\r
+\r
+/**\r
+       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\r
+\r
+       \par Sync (or) Async: Sync\r
+       This is a Asynchronous API\r
+\r
+       @param[in]      se_type                 secure element type\r
+       @param[in]      trans_param             user data that will be delivered to callback\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception NET_NFC_INVALID_PARAM        not supported se_type\r
+\r
+*/\r
+\r
+net_nfc_error_e net_nfc_open_internal_secure_element(net_nfc_se_type_e se_type, void* trans_param);\r
+\r
+/**\r
+       close opend secure element and change back to previous setting\r
+\r
+       \par Sync (or) Async: Sync\r
+       This is a Asynchronous API\r
+\r
+       @param[in]      handle                  the handle of opend secure element\r
+       @param[in]      trans_param             user data that will be delivered to callback\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception NET_NFC_INVALID_PARAM        not supported se_type\r
+\r
+*/\r
+\r
+net_nfc_error_e net_nfc_close_internal_secure_element(net_nfc_target_handle_h handle, void* trans_param);\r
+\r
+/**\r
+       send apdu to opend secure element\r
+\r
+       \par Sync (or) Async: Sync\r
+       This is a Asynchronous API\r
+\r
+       @param[in]      handle                  the handle of opend secure element\r
+       @param[in]      apdu                    apdu command to send\r
+       @param[in]      trans_param             user data that will be delivered to callback\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception NET_NFC_INVALID_PARAM        invalid\r
+\r
+*/\r
+\r
+net_nfc_error_e net_nfc_send_apdu(net_nfc_target_handle_h handle, data_h apdu, void* trans_param);\r
+\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+\r
+\r
+#endif\r
+\r
diff --git a/src/clientlib/include/net_nfc_llcp.h b/src/clientlib/include/net_nfc_llcp.h
new file mode 100644 (file)
index 0000000..d6e456f
--- /dev/null
@@ -0,0 +1,631 @@
+/*\r
+  * Copyright 2012  Samsung Electronics Co., Ltd\r
+  *\r
+  * Licensed under the Flora License, Version 1.0 (the "License");\r
+  * you may not use this file except in compliance with the License.\r
+  * You may obtain a copy of the License at\r
+\r
+  *     http://www.tizenopensource.org/license\r
+  *\r
+  * Unless required by applicable law or agreed to in writing, software\r
+  * distributed under the License is distributed on an "AS IS" BASIS,\r
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+  * See the License for the specific language governing permissions and\r
+  * limitations under the License.\r
+  */\r
+\r
+#ifndef __NET_NFC_LLCP_H__\r
+#define __NET_NFC_LLCP_H__\r
+\r
+#include "net_nfc_typedef.h"\r
+\r
+#ifdef __cplusplus\r
+  extern "C" {\r
+#endif\r
+\r
+/**\r
+\r
+@addtogroup NET_NFC_MANAGER_LLCP\r
+@{\r
+       This document is for the APIs reference document\r
+\r
+        NFC Manager defines are defined in <nfc-manager-def.h>\r
+\r
+        @li @c #net_nfc_initialize                  Initialize the nfc device.\r
+\r
+*/\r
+\r
+/**\r
+\r
+       This function creates a socket can handle connection oriented or connectless connection. To create the socket, socket option should be specified.\r
+       The option structure has three attributes.\r
+\r
+       \par Sync (or) Async: Async\r
+\r
+       @param[out]             socket          The socket handler that generated by this function\r
+       @param[in]              options         This describe the socket types (MIU, RW, Connection type) please, refer the comments\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception NET_NFC_NULL_PARAMETER       parameter(s) has(have) illigal NULL pointer(s)\r
+\r
+*/\r
+\r
+net_nfc_error_e net_nfc_create_llcp_socket (net_nfc_llcp_socket_t * socket, net_nfc_llcp_socket_option_h options);\r
+\r
+/**\r
+       Register socket callback, this callback should register to get socket activities\r
+       you can register callback any time just after getting socket handler.\r
+       when events is delivered before register callback, all event's will be ignored.\r
+       we recommand register callbac just after create a socket.\r
+\r
+       @param[in]              socket          socket handle\r
+       @param[in]              cb                      callback function\r
+       @param[in]              user_param      user parameter that will be deliver when the callback is called\r
+\r
+       @return                 return the result of the calling the function\r
+\r
+       @exception NET_NFC_NULL_PARAMETER               parameter(s) has(have) illigal NULL pointer(s)\r
+       @exception NET_NFC_LLCP_INVALID_SOCKET  invalied socket handler is recieved\r
+\r
+*/\r
+\r
+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);\r
+\r
+/**\r
+       unregister callback from socket.\r
+\r
+       @param[in]              socket          socket handle\r
+\r
+       @return                 return the result of the calling the function\r
+\r
+       @exception NET_NFC_LLCP_INVALID_SOCKET  invalied socket handler is recieved\r
+       @exception NET_NFC_NOT_REGISTERED       callback was not registered\r
+*/\r
+\r
+net_nfc_error_e net_nfc_unset_llcp_socket_callback (net_nfc_llcp_socket_t socket);\r
+\r
+/**\r
+       listen the remote connection with service name and sap number. The service name is a string.\r
+\r
+       Please, refer SAP values range <br>\r
+       - 00 ~ 15 : Identifies the Well-Known Service Access Points <br>\r
+       - 16 ~ 31 : Identifies Services in the local service environment and are advertised by local SDP <br>\r
+       - 32 ~ 61 : Identifies Services in the local service environment and are NOT advertised by local SDP <br>\r
+\r
+       please follow well known name prefix\r
+       well known service name should be "urn:nfc:sn:<servicename>"\r
+       external service name "urn:nfc:xsn:<domain>:<servicename>"\r
+\r
+       @param[in]              socket          socket handler\r
+       @param[in]              service_name    service name URI, (maxium length is 256)\r
+       @param[in]              sap                     the sap number that will be bind\r
+       @param[in]              trans_param     user parameter\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception NET_NFC_LLCP_INVALID_SOCKET  invalied socket handler is recieved\r
+       @exception NET_NFC_NULL_PARAMETER               parameter(s) has(have) illigal NULL pointer(s)\r
+       @exception NET_NFC_ALLOC_FAIL                   memory allocation is failed\r
+       @exception NET_NFC_INSUFFICIENT_STORAGE it reached maximum number of socket.\r
+       @exception NET_NFC_OPERATION_FAIL       Operation is failed because of the internal oal error\r
+       @exception NET_NFC_INVALID_STATE                interanl error\r
+       @exception NET_NFC_ALREADY_REGISTERED   SAP number is already in used\r
+\r
+*/\r
+\r
+\r
+net_nfc_error_e net_nfc_listen_llcp (net_nfc_llcp_socket_t socket, const char * service_name , sap_t sap, void * trans_param);\r
+\r
+/**\r
+\r
+       disconnect current connection\r
+\r
+       @param[in]              socket          socket handler\r
+       @param[in]              trans_param     user parameter\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception NET_NFC_LLCP_INVALID_SOCKET  invalied socket handler is recieved\r
+       @exception NET_NFC_OPERATION_FAIL       Operation is failed because of the internal oal error\r
+       @exception NET_NFC_INVALID_STATE                interanl error\r
+       @exception NET_NFC_LLCP_SOCKET_DISCONNECTED             socket is disconnected\r
+\r
+*/\r
+\r
+net_nfc_error_e net_nfc_disconnect_llcp (net_nfc_llcp_socket_t socket , void * trans_param);\r
+\r
+/**\r
+       close the socket. if you call the this function before call disconnect, automatically, call disonnection inside socket close\r
+\r
+       @param[in]              socket          socket handler\r
+       @param[in]              trans_param     user parameter\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception NET_NFC_LLCP_INVALID_SOCKET  invalied socket handler is recieved\r
+       @exception NET_NFC_INVALID_STATE                interanl error\r
+\r
+*/\r
+\r
+\r
+net_nfc_error_e net_nfc_close_llcp_socket(net_nfc_llcp_socket_t socket , void * trans_param);\r
+\r
+\r
+/**\r
+       send data to remote device. it return callback event when the sending is completed. This api is for connection oriented socket\r
+\r
+       @param[in]              socket          socket handler\r
+       @param[in]              data                    raw data to send to remote device\r
+       @param[in]              trans_param     user parameter\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception NET_NFC_LLCP_INVALID_SOCKET  invalied socket handler is recieved\r
+       @exception NET_NFC_NULL_PARAMETER               parameter(s) has(have) illigal NULL pointer(s)\r
+       @exception NET_NFC_OPERATION_FAIL       Operation is failed because of the internal oal error\r
+       @exception NET_NFC_INVALID_STATE                interanl error\r
+       @exception NET_NFC_LLCP_SOCKET_FRAME_REJECTED   requested data is rejected\r
+       @exception NET_NFC_LLCP_SOCKET_DISCONNECTED             socket is disconnected\r
+\r
+*/\r
+\r
+net_nfc_error_e net_nfc_send_llcp (net_nfc_llcp_socket_t socket, data_h  data , void * trans_param);\r
+\r
+\r
+/**\r
+       recieve data from remote device, received data will be delivered in callback function,\r
+       cast the data pointer into "data_h". This api is for connection oriented socket.\r
+\r
+       @param[in]              socket          socket handler\r
+       @param[in]              req_length      length of data will be read\r
+       @param[in]              trans_param     user parameter\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception NET_NFC_LLCP_INVALID_SOCKET  invalied socket handler is recieved\r
+       @exception NET_NFC_NULL_PARAMETER               parameter(s) has(have) illigal NULL pointer(s)\r
+       @exception NET_NFC_OPERATION_FAIL       Operation is failed because of the internal oal error\r
+       @exception NET_NFC_INVALID_STATE                interanl error\r
+       @exception NET_NFC_LLCP_SOCKET_FRAME_REJECTED   requested data is rejected\r
+       @exception NET_NFC_LLCP_SOCKET_DISCONNECTED             socket is disconnected\r
+*/\r
+\r
+net_nfc_error_e net_nfc_receive_llcp (net_nfc_llcp_socket_t socket, size_t req_length, void * trans_param);\r
+\r
+\r
+\r
+/**\r
+       send data to remote device. it return callback event when the sending is completed.\r
+       this API is for connectionless socket\r
+\r
+       @param[in]              socket          socket handler\r
+       @param[in]              data                    raw data to send to remote device\r
+       @param[in]              trans_param     user parameter\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception NET_NFC_LLCP_INVALID_SOCKET  invalied socket handler is recieved\r
+       @exception NET_NFC_NULL_PARAMETER               parameter(s) has(have) illigal NULL pointer(s)\r
+       @exception NET_NFC_OPERATION_FAIL       Operation is failed because of the internal oal error\r
+       @exception NET_NFC_INVALID_STATE                interanl error\r
+       @exception NET_NFC_LLCP_SOCKET_FRAME_REJECTED   requested data is rejected\r
+       @exception NET_NFC_LLCP_SOCKET_DISCONNECTED             socket is disconnected\r
+*/\r
+\r
+net_nfc_error_e net_nfc_send_to_llcp (net_nfc_llcp_socket_t socket,sap_t dsap, data_h  data , void * trans_param);\r
+\r
+\r
+/**\r
+       recieve data from remote device, received data will be delivered in callback function,\r
+       cast the data pointer into "data_h".\r
+       this API is for connectionless socket\r
+\r
+       @param[in]              socket          socket handler\r
+       @param[in]              req_length      length of data will be read\r
+       @param[in]              trans_param     user parameter\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception NET_NFC_LLCP_INVALID_SOCKET  invalied socket handler is recieved\r
+       @exception NET_NFC_NULL_PARAMETER               parameter(s) has(have) illigal NULL pointer(s)\r
+       @exception NET_NFC_OPERATION_FAIL       Operation is failed because of the internal oal error\r
+       @exception NET_NFC_INVALID_STATE                interanl error\r
+       @exception NET_NFC_LLCP_SOCKET_FRAME_REJECTED   requested data is rejected\r
+       @exception NET_NFC_LLCP_SOCKET_DISCONNECTED             socket is disconnected\r
+       @exception NET_NFC_ALREADY_REGISTERED   SAP number is already in used\r
+*/\r
+\r
+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);\r
+\r
+\r
+/**\r
+       connect to the remote device with destiantion sap number you should know the sap number (0 ~ 61)\r
+\r
+       @param[in]              socket          socket handler\r
+       @param[in]              sap                     sap (Service Access Point) of remote device\r
+       @param[in]              trans_param     user parameter\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception NET_NFC_LLCP_INVALID_SOCKET  invalied socket handler is recieved\r
+       @exception NET_NFC_NULL_PARAMETER               parameter(s) has(have) illigal NULL pointer(s)\r
+       @exception NET_NFC_OPERATION_FAIL       Operation is failed because of the internal oal error\r
+       @exception NET_NFC_INVALID_STATE                interanl error\r
+       @exception NET_NFC_LLCP_SOCKET_FRAME_REJECTED   requested data is rejected\r
+       @exception NET_NFC_LLCP_SOCKET_DISCONNECTED             socket is disconnected\r
+*/\r
+\r
+net_nfc_error_e net_nfc_connect_llcp_with_sap (net_nfc_llcp_socket_t socket, sap_t sap , void * trans_param);\r
+\r
+\r
+/**\r
+       connect to the remote device's service name.\r
+\r
+       @param[in]              socket          socket handler\r
+       @param[in]              service_name    service name of the\r
+       @param[in]              trans_param     user parameter\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception NET_NFC_LLCP_INVALID_SOCKET  invalied socket handler is recieved\r
+       @exception NET_NFC_NULL_PARAMETER               parameter(s) has(have) illigal NULL pointer(s)\r
+       @exception NET_NFC_OPERATION_FAIL       Operation is failed because of the internal oal error\r
+       @exception NET_NFC_INVALID_STATE                interanl error\r
+*/\r
+\r
+net_nfc_error_e net_nfc_connect_llcp (net_nfc_llcp_socket_t socket, const char * service_name , void * trans_param);\r
+\r
+\r
+/**\r
+\r
+       get local infomation of local device. the device infomation can be configurable with "net_nfc_llcp_set_configure" function\r
+\r
+       @param[out]             config          configuration info\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception NET_NFC_NULL_PARAMETER               parameter(s) has(have) illigal NULL pointer(s)\r
+*/\r
+\r
+net_nfc_error_e net_nfc_get_llcp_local_configure (net_nfc_llcp_config_info_h * config);\r
+\r
+/**\r
+\r
+       get local infomation of remote device.\r
+\r
+       @param[in]              handle          target handle that be optained just after the target detect\r
+       @param[out]             config          configuration handle\r
+\r
+       @return         return the result of the calling the function\r
+\r
+*/\r
+\r
+net_nfc_error_e net_nfc_get_llcp_remote_configure (net_nfc_target_handle_h handle, net_nfc_llcp_config_info_h * config);\r
+\r
+/**\r
+\r
+       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\r
+\r
+       @param[in]              config          configuration handle\r
+       @param[in]              trans_param     user parameter\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception NET_NFC_NULL_PARAMETER               parameter(s) has(have) illigal NULL pointer(s)\r
+\r
+*/\r
+\r
+net_nfc_error_e net_nfc_set_llcp_local_configure (net_nfc_llcp_config_info_h config , void * trans_param);\r
+\r
+/**\r
+       this function return the current local socket options. if you need to know the remote connection's socket\r
+       info please call "net_nfc_llcp_get_remote_socket_option" function\r
+\r
+       @param[in]              socket          socket handler\r
+       @param[out]             option          infomation of the socket\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception NET_NFC_LLCP_INVALID_SOCKET  invalied socket handler is recieved\r
+*/\r
+\r
+\r
+net_nfc_error_e net_nfc_get_llcp_local_socket_option (net_nfc_llcp_socket_t socket, net_nfc_llcp_socket_option_h * option);\r
+\r
+/**\r
+\r
+       this function return the current remote  socket options.\r
+\r
+       @param[in]              socket          socket handler\r
+       @param[out]             option          infomation of the socket\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception NET_NFC_LLCP_INVALID_SOCKET  invalied socket handler is recieved\r
+*/\r
+\r
+net_nfc_error_e net_nfc_get_llcp_remote_socket_option (net_nfc_llcp_socket_t socket, net_nfc_llcp_socket_option_h * option);\r
+\r
+/**\r
+       this function create the attribtues of socket.\r
+\r
+       - MIU (Maximum Information Unit) : Maximum size of infomation unit of LLC PDU (you may assume a packet in network system)\r
+               An LLC SHALL NOT send any LLC PDU with an information field that is larger than the Link MIU determined for the remote LLC.\r
+               An LLC MAY discard any received LLC PDU with an information field that is larger than the local LLCs Link MIU value.\r
+               The default value is 128, and range of this value is 128 - 1152 <br>\r
+       - 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.\r
+       A receive window size of one indicates that the local LLC will acknowledge every I PDU before accepting additional I PDUs.<br>\r
+       - Socket types :  two types of socket are connection oriented and connection less. the default value is connection oriented <br>\r
+\r
+\r
+       @param[out]             option          socket option handler\r
+       @param[in]              miu                     Maximum Information Unit\r
+       @param[in]              rw                      Receive Window Size\r
+       @param[in]              type                    socket type (connection oriented or connection less)\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception      NET_NFC_OUT_OF_BOUND    given parameter is out of bound\r
+       @exception      NET_NFC_NULL_PARAMETER          parameter(s) has(have) illigal NULL pointer(s)\r
+*/\r
+\r
+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);\r
+\r
+/**\r
+       create default socket option handler. this function create handler and set the all of the socket option with default values\r
+       @param[out]             option          option handler\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception      NET_NFC_OUT_OF_BOUND    given parameter is out of bound\r
+       @exception      NET_NFC_NULL_PARAMETER          parameter(s) has(have) illigal NULL pointer(s)\r
+*/\r
+\r
+net_nfc_error_e net_nfc_create_llcp_socket_option_default (net_nfc_llcp_socket_option_h * option);\r
+\r
+/**\r
+       this function help to get miu values from socket option\r
+\r
+       @param[in]              option          socket option handle\r
+       @param[out]             miu                     maximum infomation unit\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception      NET_NFC_NULL_PARAMETER          parameter(s) has(have) illigal NULL pointer(s)\r
+*/\r
+net_nfc_error_e net_nfc_get_llcp_socket_option_miu (net_nfc_llcp_socket_option_h option, uint16_t * miu);\r
+\r
+/**\r
+       this function help to set miu value to the socket option handle\r
+\r
+       @param[in]              option          socket option handle\r
+       @param[out]             miu                     maximum infomation unit\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception      NET_NFC_NULL_PARAMETER          parameter(s) has(have) illigal NULL pointer(s)\r
+*/\r
+net_nfc_error_e net_nfc_set_llcp_socket_option_miu (net_nfc_llcp_socket_option_h option, uint16_t miu);\r
+\r
+/**\r
+       this function help to get rt value from the socket option handle\r
+\r
+       @param[in]              option          socket option handle\r
+       @param[out]             rt                      receive window size\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception      NET_NFC_NULL_PARAMETER          parameter(s) has(have) illigal NULL pointer(s)\r
+*/\r
+net_nfc_error_e net_nfc_get_llcp_socket_option_rw (net_nfc_llcp_socket_option_h option, uint8_t * rt);\r
+\r
+/**\r
+       this function help to set miu value to the socket option handle\r
+\r
+       @param[in]              option          socket option handle\r
+       @param[out]             rt                      maximum infomation unit\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception      NET_NFC_NULL_PARAMETER          parameter(s) has(have) illigal NULL pointer(s)\r
+\r
+*/\r
+net_nfc_error_e net_nfc_set_llcp_socket_option_rw (net_nfc_llcp_socket_option_h option, uint8_t rt);\r
+\r
+/**\r
+       this function help to get socket type value from the socket option handle\r
+\r
+       @param[in]              option          socket option handle\r
+       @param[out]             type                    socket type connection oriented or connectionless\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception      NET_NFC_NULL_PARAMETER          parameter(s) has(have) illigal NULL pointer(s)\r
+*/\r
+net_nfc_error_e net_nfc_get_llcp_socket_option_type (net_nfc_llcp_socket_option_h option, net_nfc_socket_type_e * type);\r
+\r
+/**\r
+       this function help to set socket type value to the socket option handle\r
+\r
+       @param[in]              option          socket option handle\r
+       @param[out]             type                    socket type connection oriented or connectionless\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception      NET_NFC_NULL_PARAMETER          parameter(s) has(have) illigal NULL pointer(s)\r
+*/\r
+net_nfc_error_e net_nfc_set_llcp_socket_option_type (net_nfc_llcp_socket_option_h option, net_nfc_socket_type_e type);\r
+\r
+/**\r
+       free the socket option handle\r
+\r
+       @param[in]              option          socket option handle\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception      NET_NFC_NULL_PARAMETER          parameter(s) has(have) illigal NULL pointer(s)\r
+*/\r
+net_nfc_error_e net_nfc_free_llcp_socket_option (net_nfc_llcp_socket_option_h  option);\r
+\r
+\r
+ /**\r
+       This function create llcp_config_info handler that contains the llcp configuration.\r
+       After creating this handler and put his configuration "net_nfc_set_llcp_local_configure" function\r
+\r
+       note:\r
+\r
+       @param[out]     config          configuration handler\r
+       @param[in]      miu                     Maximum Information Unit\r
+       @param[in]      wks                     well knwon service (please refer the note to get detail infomation)\r
+       @param[in]      lto                     link time out value\r
+       @param[in]      option          option bits that describe the service support\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception      NET_NFC_NULL_PARAMETER          parameter(s) has(have) illigal NULL pointer(s)\r
+       @exception      NET_NFC_ALLOC_FAIL                      memory allocation is failed\r
+       @exception      NET_NFC_OUT_OF_BOUND    given parameter is out of bound\r
+\r
+       Note:\r
+       - The WKS parameter SHALL be encoded as a 16-bit field. The most-significant bit of the 16-bit field value SHALL signify\r
+       SAP address 0Fh and the least-significant bit SHALL signify SAP address 00h. The other bits SHALL signify SAP addresses\r
+       corresponding to their respective bit positions. A bit set to ?1? SHALL indicate that a service listener is bound to the corresponding\r
+       well-known service access point. A bit set to ?0? SHALL indicate that no service listener is bound to the corresponding well-known\r
+       service access point.<br>\r
+\r
+       - The option field contains a single 8-bit byte representing a set of flags which indicate the link service class of\r
+       the sending LLC and the support of optional features implemented by the sending LLC.<br>\r
+ */\r
+ 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);\r
+\r
+\r
+ /**\r
+       this function create config info handle with default values.\r
+\r
+       @param[out]     config          configuration handler\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception      NET_NFC_NULL_PARAMETER          parameter(s) has(have) illigal NULL pointer(s)\r
+       @exception      NET_NFC_ALLOC_FAIL                      memory allocation is failed\r
+ */\r
+\r
+ net_nfc_error_e net_nfc_create_llcp_configure_default (net_nfc_llcp_config_info_h * config);\r
+\r
+ /**\r
+       getting miu value from config info handle\r
+\r
+       @param[in]              config  config info handle\r
+       @param[out]             miu             maxium information unit\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception      NET_NFC_NULL_PARAMETER          parameter(s) has(have) illigal NULL pointer(s)\r
+ */\r
+\r
+ net_nfc_error_e net_nfc_get_llcp_configure_miu (net_nfc_llcp_config_info_h config, uint16_t * miu);\r
+ /**\r
+       getting wks value from config info handle\r
+\r
+       @param[in]              config  config info handle\r
+       @param[out]             wks             well-known service list\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception      NET_NFC_NULL_PARAMETER          parameter(s) has(have) illigal NULL pointer(s)\r
+ */\r
+ net_nfc_error_e net_nfc_get_llcp_configure_wks (net_nfc_llcp_config_info_h config, uint16_t * wks);\r
+ /**\r
+       getting lto value from config info handle\r
+\r
+       @param[in]              config  config info handle\r
+       @param[out]             lto             link timeout value\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception      NET_NFC_NULL_PARAMETER          parameter(s) has(have) illigal NULL pointer(s)\r
+ */\r
+ net_nfc_error_e net_nfc_get_llcp_configure_lto (net_nfc_llcp_config_info_h config, uint8_t * lto);\r
+ /**\r
+       getting miu value from config info handle\r
+\r
+       @param[in]              config  config info handle\r
+       @param[out]             option  option of socket type supports\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception      NET_NFC_NULL_PARAMETER          parameter(s) has(have) illigal NULL pointer(s)\r
+ */\r
+ net_nfc_error_e net_nfc_get_llcp_configure_option (net_nfc_llcp_config_info_h config, uint8_t * option);\r
+ /**\r
+       setting the miu value to config info handle\r
+\r
+       @param[in]              config  config info handle\r
+       @param[in]              miu             maxium information unit\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception      NET_NFC_NULL_PARAMETER          parameter(s) has(have) illigal NULL pointer(s)\r
+       @exception      NET_NFC_OUT_OF_BOUND    given parameter is out of bound\r
+ */\r
+ net_nfc_error_e net_nfc_set_llcp_configure_miu (net_nfc_llcp_config_info_h config, uint16_t  miu);\r
+ /**\r
+       setting the miu value to config info handle\r
+\r
+       @param[in]              config  config info handle\r
+       @param[in]              wks             well-known service list\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception      NET_NFC_NULL_PARAMETER          parameter(s) has(have) illigal NULL pointer(s)\r
+ */\r
+ net_nfc_error_e net_nfc_set_llcp_configure_wks (net_nfc_llcp_config_info_h config, uint16_t  wks);\r
+ /**\r
+       setting the miu value to config info handle\r
+\r
+       @param[in]              config  config info handle\r
+       @param[in]              lto             link timeout value\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception      NET_NFC_NULL_PARAMETER          parameter(s) has(have) illigal NULL pointer(s)\r
+ */\r
+ net_nfc_error_e net_nfc_set_llcp_configure_lto (net_nfc_llcp_config_info_h config, uint8_t  lto);\r
+ /**\r
+       setting the miu value to config info handle\r
+\r
+       @param[in]              config  config info handle\r
+       @param[in]              option  option of socket type supports\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception      NET_NFC_NULL_PARAMETER          parameter(s) has(have) illigal NULL pointer(s)\r
+ */\r
+ net_nfc_error_e net_nfc_set_llcp_configure_option (net_nfc_llcp_config_info_h config, uint8_t option);\r
+ /**\r
+       free the configuration info\r
+\r
+       @param[in]              config  config info handle\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception      NET_NFC_NULL_PARAMETER          parameter(s) has(have) illigal NULL pointer(s)\r
+ */\r
+ net_nfc_error_e net_nfc_free_llcp_configure (net_nfc_llcp_config_info_h config);\r
+\r
+\r
+ /**\r
+@}\r
+*/\r
+\r
+net_nfc_error_e net_nfc_get_current_target_handle(void* trans_param);\r
+\r
+#ifdef __cplusplus\r
+ }\r
+#endif\r
+\r
+\r
+#endif\r
+\r
+\r
diff --git a/src/clientlib/include/net_nfc_ndef_message.h b/src/clientlib/include/net_nfc_ndef_message.h
new file mode 100644 (file)
index 0000000..6d73c40
--- /dev/null
@@ -0,0 +1,446 @@
+/*\r
+  * Copyright 2012  Samsung Electronics Co., Ltd\r
+  *\r
+  * Licensed under the Flora License, Version 1.0 (the "License");\r
+  * you may not use this file except in compliance with the License.\r
+  * You may obtain a copy of the License at\r
+\r
+  *     http://www.tizenopensource.org/license\r
+  *\r
+  * Unless required by applicable law or agreed to in writing, software\r
+  * distributed under the License is distributed on an "AS IS" BASIS,\r
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+  * See the License for the specific language governing permissions and\r
+  * limitations under the License.\r
+  */\r
+\r
+#ifndef __NET_NFC_NDEF_MESSAGE_H__\r
+#define __NET_NFC_NDEF_MESSAGE_H__\r
+\r
+#include "net_nfc_typedef.h"\r
+\r
+#ifdef __cplusplus\r
+ extern "C" {\r
+#endif\r
+\r
+\r
+/**\r
+\r
+@addtogroup NET_NFC_MANAGER_NDEF\r
+@{\r
+       This document is for the APIs reference document\r
+\r
+        NFC Manager defines are defined in <nfc-manager-def.h>\r
+\r
+        @li @c #net_nfc_initialize                  Initialize the nfc device.\r
+\r
+*/\r
+\r
+/**\r
+       create ndef message handler. this function allocate the ndef message handler and initialize.\r
+\r
+       \par Sync (or) Async: sync\r
+       This is a Synchronous API\r
+\r
+       @param[out]     ndef_message            instance of the ndef_message is retuened\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception NET_NFC_NULL_PARAMETER               parameter(s) has(have) illigal NULL pointer(s)\r
+       @exception NET_NFC_ALLOC_FAIL                   memory allocation is failed\r
+\r
+       @code\r
+\r
+       net_nfc_error_e result = NET_NFC_OK;\r
+       ndef_message_h msg = NULL;\r
+       ndef_record_h record = NULL;\r
+\r
+       result = net_nfc_create_ndef_message (&msg);\r
+       if (result != NET_NFC_OK) return result;\r
+\r
+       result = net_nfc_create_uri_type_record (&record , "http://www.samsung.com" ,NET_NFC_SCHEMA_FULL_URI);\r
+       if (result != NET_NFC_OK) return result;\r
+\r
+       result = net_nfc_append_record_to_ndef_message (msg ,record);\r
+       if (result != NET_NFC_OK) return result;\r
+\r
+       net_nfc_write_ndef(id, msg, &user_context);\r
+\r
+       net_nfc_free_ndef_message (msg);\r
+\r
+       @endcode\r
+*/\r
+\r
+\r
+net_nfc_error_e net_nfc_create_ndef_message (ndef_message_h* ndef_message);\r
+\r
+/**\r
+       this APIs is the getter of  record counts\r
+\r
+       \par Sync (or) Async: sync\r
+       This is a Synchronous API\r
+\r
+       @param[in]      ndef_message    output structure to get the record\r
+       @param[out]     count                   number of record count\r
+\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception NET_NFC_NULL_PARAMETER               parameter(s) has(have) illigal NULL pointer(s)\r
+\r
+       @code\r
+\r
+       static void net_nfc_cb(net_nfc_message_e message, net_nfc_error_e result, void* data , void* userContext)\r
+       {\r
+               switch (message)\r
+               {\r
+                       case NET_NFC_MESSAGE_READ_NDEF:\r
+                               {\r
+                                       if(data != NULL)\r
+                                       {\r
+                                               int count = 0;\r
+                                               ndef_message_h ndef = (ndef_message_h)(data);\r
+                                               net_nfc_get_ndef_message_record_count (ndef, &count);\r
+                                               printf ("record count = %d\n", count);\r
+                                       }\r
+                               }\r
+                       break;\r
+               }\r
+       }\r
+       @endcode\r
+*/\r
+net_nfc_error_e net_nfc_get_ndef_message_record_count (ndef_message_h ndef_message, int * count);\r
+\r
+/**\r
+       This function converts the NDEF Message structure to serial bytes of ndef message.\r
+\r
+       it gets copy of the rawdata bytes from ndef_message. ndef_message has no effect after free rawdata\r
+       Application should free rawdata.\r
+\r
+       \par Sync (or) Async: sync\r
+       This is a Synchronous API\r
+\r
+       @param[in]      ndef_message    output structure to get the record\r
+       @param[out]     rawdata                 this is the raw data that will be formed into the\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception NET_NFC_NULL_PARAMETER               parameter(s) has(have) illigal NULL pointer(s)\r
+       @exception NET_NFC_ALLOC_FAIL                   memory allocation is failed\r
+       @exception NET_NFC_NDEF_BUF_END_WITHOUT_ME      Wrong formatted NDEF message\r
+\r
+       @code\r
+\r
+       net_nfc_error_e result = NET_NFC_OK;\r
+       data_h rawdata;\r
+       ndef_message_h msg = NULL;\r
+       ndef_record_h record = NULL;\r
+       int idx;\r
+       uint8_t * buffer = NULL;\r
+\r
+       result = net_nfc_create_ndef_message (&msg);\r
+       if (result != NET_NFC_OK) return result;\r
+\r
+       result = net_nfc_create_uri_type_record (&record , "http://www.samsung.com" ,NET_NFC_SCHEMA_FULL_URI);\r
+       if (result != NET_NFC_OK) return result;\r
+\r
+       result = net_nfc_append_record_to_ndef_message (msg ,record);\r
+       if (result != NET_NFC_OK) return result;\r
+\r
+       net_nfc_create_rawdata_from_ndef_message (msg, &rawdata);\r
+\r
+       buffer = net_nfc_get_data_buffer (rawdata) ;\r
+\r
+       for (idx = 0; idx < net_nfc_get_data_length (rawdata) ; idx++)\r
+       {\r
+               printf (" %02X", buffer[idx]);\r
+               if (idx % 16 == 0) printf ("\n");\r
+       }\r
+\r
+       net_nfc_free_ndef_message (msg);\r
+\r
+       @endcode\r
+\r
+\r
+*/\r
+\r
+net_nfc_error_e net_nfc_create_rawdata_from_ndef_message (ndef_message_h ndef_message, data_h* rawdata);\r
+\r
+/**\r
+       This function return the structure of ndef_message from serial format of ndef message.\r
+       You may say create ndef handler from raw serial bytes\r
+       it cunsumes the bytes array until get the (ME==1). it retunrs error if the bytes array does not have ME flag.\r
+       if the array has two NDEF Message serially (not recursive case - like smart poster). the first NDEF message\r
+       will be converted to ndef_message handler, and other messages will be ignored.\r
+\r
+       \par Sync (or) Async: sync\r
+       This is a Synchronous API\r
+\r
+       @param[out]     ndef_message            ndef message handler that will be returned\r
+       @param[in]      rawdata                         ndef message that formed in bytes array\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception NET_NFC_NULL_PARAMETER               parameter(s) has(have) illigal NULL pointer(s)\r
+       @exception NET_NFC_ALLOC_FAIL                   memory allocation is failed\r
+       @exception NET_NFC_NDEF_BUF_END_WITHOUT_ME      Wrong formatted NDEF message\r
+\r
+       @code\r
+\r
+       static void net_nfc_cb(net_nfc_message_e message, net_nfc_error_e result, void* data , void* userContext)\r
+       {\r
+               switch (message)\r
+               {\r
+                       case NET_NFC_MESSAGE_READ_NDEF:\r
+                               {\r
+                                       if(data != NULL)\r
+                                       {\r
+                                               record_h record;\r
+                                               ndef_message_h url;\r
+                                               data_h ndef_type;\r
+                                               data_h payload;\r
+\r
+                                               ndef_message_h ndef = (ndef_message_h)(data);\r
+                                               net_nfc_get_record_by_index (ndef, 0, &record);\r
+                                               net_nfc_get_record_type (record, &ndef_type);\r
+                                               if (strncmp (ndef_type.buffer, "Sp", ndef_type.length)){\r
+                                                       net_nfc_get_record_payload (record, &payload);\r
+                                                       net_nfc_create_ndef_message_from_rawdata (&url, payload);\r
+                                                       printf_ndef_massage (url);\r
+                                               }\r
+                                       }\r
+                               }\r
+                       break;\r
+               }\r
+       }\r
+       @endcode\r
+\r
+*/\r
+\r
+\r
+net_nfc_error_e net_nfc_create_ndef_message_from_rawdata (ndef_message_h* ndef_message, data_h  rawdata);\r
+\r
+/**\r
+       it returns the total size of ndef message bytes. parse the structure data and count the bytes\r
+       to know the length of bytes required to store the NDEF message.\r
+\r
+       it calculates the length every time application calls this function. it does not cache inside.\r
+       TODO: do we need to cache the value inside of ndef_message_h\r
+\r
+       \par Sync (or) Async: sync\r
+       This is a Synchronous API\r
+\r
+       @param[in]      ndef_message            this is the raw data that will be formed into the\r
+       @param[out]     length                  number of bytes required to create ndef message serial format\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception NET_NFC_NULL_PARAMETER               parameter(s) has(have) illigal NULL pointer(s)\r
+\r
+*/\r
+\r
+net_nfc_error_e net_nfc_get_ndef_message_byte_length(ndef_message_h ndef_message, int * length) ;\r
+/**\r
+       Append a record to ndef message structure.\r
+       This API help to create NDEF message and it control Record flags to follow the NDEF forum specification\r
+\r
+       \par Sync (or) Async: sync\r
+       This is a Synchronous API\r
+\r
+       @param[in]      ndef_message            NDEF message structure\r
+       @param[in]      record                  a record will be added into the ndef message\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception NET_NFC_NULL_PARAMETER               parameter(s) has(have) illigal NULL pointer(s)\r
+\r
+       @code\r
+\r
+       net_nfc_error_e result = NET_NFC_OK;\r
+       data_h rawdata;\r
+       ndef_message_h msg = NULL;\r
+       ndef_record_h record = NULL;\r
+       int idx;\r
+       uint8_t * buffer = NULL;\r
+\r
+       result = net_nfc_create_ndef_message (&msg);\r
+       if (result != NET_NFC_OK) return result;\r
+\r
+       result = net_nfc_create_uri_type_record (&record , "http://www.samsung.com" ,NET_NFC_SCHEMA_FULL_URI);\r
+       if (result != NET_NFC_OK) return result;\r
+\r
+       result = net_nfc_append_record_to_ndef_message (msg ,record);\r
+       if (result != NET_NFC_OK) return result;\r
+\r
+       net_nfc_create_rawdata_from_ndef_message (msg, &rawdata);\r
+\r
+       buffer = net_nfc_get_data_buffer (rawdata) ;\r
+\r
+       for (idx = 0; idx < net_nfc_get_data_length (rawdata) ; idx++)\r
+       {\r
+               printf (" %02X", buffer[idx]);\r
+               if (idx % 16 == 0) printf ("\n");\r
+       }\r
+\r
+       net_nfc_free_ndef_message (msg);\r
+\r
+       @endcode\r
+\r
+\r
+*/\r
+net_nfc_error_e net_nfc_append_record_to_ndef_message(ndef_message_h ndef_message, ndef_record_h record);\r
+\r
+/**\r
+       remove the record that indicated by index number.\r
+       and this deleted record will be freed.\r
+\r
+       \par Sync (or) Async: sync\r
+       This is a Synchronous API\r
+\r
+       @param[in]      ndef_message    the message wil be freed\r
+       @param[in]      index                   index of record\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception NET_NFC_NULL_PARAMETER               parameter(s) has(have) illigal NULL pointer(s)\r
+       @exception NET_NFC_OUT_OF_BOUND                 index is out of bound\r
+       @exception NET_NFC_INVALID_FORMAT               Wrong formatted ndef message\r
+\r
+*/\r
+\r
+net_nfc_error_e net_nfc_remove_record_by_index (ndef_message_h ndef_message, int index);\r
+\r
+/**\r
+       get record by index. this function just return the pointer of record.\r
+       if you change the record value it directly affected to NDEF message\r
+\r
+       \par Sync (or) Async: sync\r
+       This is a Synchronous API\r
+\r
+       @param[in]      ndef_message            the message wil be freed\r
+       @param[in]      index                   index of record\r
+       @param[in]      record                  record pointer\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception NET_NFC_NULL_PARAMETER               parameter(s) has(have) illigal NULL pointer(s)\r
+       @exception NET_NFC_OUT_OF_BOUND                 index is out of bound\r
+\r
+*/\r
+net_nfc_error_e net_nfc_get_record_by_index (ndef_message_h ndef_message, int index, ndef_record_h*  record);\r
+\r
+/**\r
+       Add a record by index. This API help to add record by index. MB or ME bits will automatically assained.\r
+\r
+       \par Sync (or) Async: sync\r
+       This is a Synchronous API\r
+\r
+       @param[in]      ndef_message            the message wil be freed\r
+       @param[in]      index                   index of record\r
+       @param[in]      record                  record pointer\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception NET_NFC_NULL_PARAMETER               parameter(s) has(have) illigal NULL pointer(s)\r
+       @exception NET_NFC_OUT_OF_BOUND                 index is out of bound\r
+       @exception NET_NFC_INVALID_FORMAT               Wrong formatted ndef message\r
+*/\r
+\r
+net_nfc_error_e net_nfc_append_record_by_index (ndef_message_h ndef_message,int index, ndef_record_h  record);\r
+\r
+\r
+/**\r
+       search the specific type in the NDEF message. this function return the first record that holds the type.\r
+       if the type has "urn:nfc:wkt:" or "urn:nfc:ext:", these prefix will be removed automatically.\r
+\r
+       @param[in]              ndef_message            NDEF message handler\r
+       @param[in]              tnf                             TNF value\r
+       @param[in]              type                            Record type , include type length\r
+       @param[out]             record                  record handle\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception NET_NFC_NULL_PARAMETER               parameter(s) has(have) illigal NULL pointer(s)\r
+       @exception NET_NFC_NO_DATA_FOUND                        search is failed\r
+       @exception NET_NFC_INVALID_FORMAT               Wrong formatted ndef message\r
+\r
+       @code\r
+\r
+       static void net_nfc_cb(net_nfc_message_e message, net_nfc_error_e result, void* data , void* userContext)\r
+       {\r
+               switch (message)\r
+               {\r
+                       case NET_NFC_MESSAGE_READ_NDEF:\r
+                               {\r
+                                       if(data != NULL)\r
+                                       {\r
+                                               date_h type;\r
+                                               int count = 0;\r
+                                               ndef_message_h ndef = (ndef_message_h)(data);\r
+                                               ndef_record_h record;\r
+                                               net_nfc_create_data (&type, "Sp", 2);\r
+                                               net_nfc_search_record_by_type (ndef, NET_NFC_RECORD_WELL_KNOWN_TYPE, type, &record);\r
+                                       }\r
+                               }\r
+                       break;\r
+               }\r
+       }\r
+\r
+       @endcode\r
+\r
+*/\r
+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);\r
+\r
+\r
+/**\r
+       this function helps to free the ndef_message_s type structure.\r
+       it has multiple ndef_record_s with linked list form and each record has own pointer.\r
+       this function free these memory in one shot!\r
+       don't worry about the record handler. these handlers also freed.\r
+\r
+       \par Sync (or) Async: sync\r
+       This is a Synchronous API\r
+\r
+       @param[in]      ndef_message            the message wil be freed\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception NET_NFC_NULL_PARAMETER               parameter(s) has(have) illigal NULL pointer(s)\r
+\r
+*/\r
+\r
+net_nfc_error_e net_nfc_free_ndef_message(ndef_message_h ndef_message);\r
+\r
+\r
+/**\r
+       retreive ndef message which is read by nfc-manager .\r
+       after reading message, it will be removed from nfc-manager storage\r
+\r
+       \par Sync (or) Async: sync\r
+       This is a Synchronous API\r
+\r
+       @param[in]      ndef_message            the message wil be retrieved\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception NET_NFC_NULL_PARAMETER               parameter(s) has(have) illigal NULL pointer(s)\r
+       @exception NET_NFC_NO_NDEF_MESSAGE              No ndef message is found\r
+       @exception NET_NFC_INVALID_FORMAT               Wrong formatted ndef message\r
+       @exception NET_NFC_ALLOC_FAIL                   memory allocation is failed\r
+\r
+*/\r
+\r
+net_nfc_error_e net_nfc_retrieve_current_ndef_message (ndef_message_h* ndef_message);\r
+\r
+\r
+/**\r
+@} */\r
+\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+\r
+\r
+#endif\r
+\r
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 100644 (file)
index 0000000..04f4381
--- /dev/null
@@ -0,0 +1,420 @@
+/*\r
+  * Copyright 2012  Samsung Electronics Co., Ltd\r
+  *\r
+  * Licensed under the Flora License, Version 1.0 (the "License");\r
+  * you may not use this file except in compliance with the License.\r
+  * You may obtain a copy of the License at\r
+\r
+  *     http://www.tizenopensource.org/license\r
+  *\r
+  * Unless required by applicable law or agreed to in writing, software\r
+  * distributed under the License is distributed on an "AS IS" BASIS,\r
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+  * See the License for the specific language governing permissions and\r
+  * limitations under the License.\r
+  */\r
+\r
+#ifndef __NET_NFC_NDEF_RECORD_H__\r
+#define __NET_NFC_NDEF_RECORD_H__\r
+\r
+#include "net_nfc_typedef.h"\r
+\r
+#ifdef __cplusplus\r
+  extern "C" {\r
+#endif\r
+\r
+/**\r
+       This function create wifi configure handler instance.\r
+\r
+       @param[out]     config          instance handler\r
+       @param[in]      type                            Carrier types it would be wifi add hoc or wifi AP\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception NET_NFC_NULL_PARAMETER               parameter(s) has(have) illigal NULL pointer(s)\r
+       @exception NET_NFC_OUT_OF_BOUND                 type value is not enum value\r
+       @exception NET_NFC_ALLOC_FAIL                   allocation is failed\r
+*/\r
+\r
+net_nfc_error_e net_nfc_create_carrier_config (net_nfc_carrier_config_h * config, net_nfc_conn_handover_carrier_type_e type);\r
+\r
+/**\r
+       Add property key and value for configuration.\r
+       the data will be copied to config handle, you should free used data array.\r
+\r
+       @param[in]      config          instance handler\r
+       @param[in]      attribute                               attribue key for value.\r
+       @param[in]      size                                    size of value\r
+       @param[in]      data                                    value array (binary type)\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception NET_NFC_NULL_PARAMETER               parameter(s) has(have) illigal NULL pointer(s)\r
+       @exception NET_NFC_ALLOC_FAIL                   allocation is failed\r
+*/\r
+\r
+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);\r
+\r
+/**\r
+       Remove the key and value from configuration, you can also remove the group  withe CREDENTIAL key.\r
+       The the attribute is exist then it will be removed and also freed automatically.\r
+\r
+       @param[in]      config          instance handler\r
+       @param[in]      attribute                               attribue key for value.\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception NET_NFC_NULL_PARAMETER               parameter(s) has(have) illigal NULL pointer(s)\r
+       @exception NET_NFC_NO_DATA_FOUND                the given key is not found\r
+       @exception NET_NFC_ALREADY_REGISTERED   the given attribute is already registered\r
+*/\r
+\r
+net_nfc_error_e net_nfc_remove_carrier_config_property (net_nfc_carrier_config_h config, uint16_t attribute);\r
+/**\r
+       Get the property value by attribute.\r
+\r
+       @param[in]      config          instance handler\r
+       @param[in]      attribute                               attribue key for value.\r
+       @param[out]     size                                    size of value\r
+       @param[out]     data                                    value array (binary type)\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception NET_NFC_NULL_PARAMETER               parameter(s) has(have) illigal NULL pointer(s)\r
+       @exception NET_NFC_NO_DATA_FOUND                The given key is not found\r
+*/\r
+\r
+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);\r
+\r
+/**\r
+       The group will be joined into the configure\r
+\r
+       @param[in]      config          instance handler\r
+       @param[in]      group                           group handle\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception NET_NFC_NULL_PARAMETER               parameter(s) has(have) illigal NULL pointer(s)\r
+       @exception NET_NFC_ALREADY_REGISTERED   The given group is already registered\r
+*/\r
+\r
+net_nfc_error_e net_nfc_append_carrier_config_group (net_nfc_carrier_config_h config, net_nfc_property_group_h group);\r
+\r
+/**\r
+       Remove the group from configure handle\r
+\r
+       @param[in]      config          instance handler\r
+       @param[in]      group                           group handle\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception NET_NFC_NULL_PARAMETER               parameter(s) has(have) illigal NULL pointer(s)\r
+       @exception NET_NFC_NO_DATA_FOUND                given handle pointer is not exist in the configure handle\r
+*/\r
+\r
+net_nfc_error_e net_nfc_remove_carrier_config_group (net_nfc_carrier_config_h config, net_nfc_property_group_h group);\r
+\r
+/**\r
+       Get the group from configure handle by index\r
+\r
+       @param[in]      config          instance handler\r
+       @param[in]      index                           index number\r
+       @param[out]     group                           group handle\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception NET_NFC_NULL_PARAMETER               parameter(s) has(have) illigal NULL pointer(s)\r
+       @exception NET_NFC_OUT_OF_BOUND                 the index number is not bound of the max count\r
+       @exception NET_NFC_NO_DATA_FOUND                this is should be happened if the configure handle is dammaged\r
+*/\r
+\r
+net_nfc_error_e net_nfc_get_carrier_config_group (net_nfc_carrier_config_h config, int index, net_nfc_property_group_h * group);\r
+\r
+/**\r
+       free the configure handle\r
+\r
+       @param[in]      config          instance handler\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception NET_NFC_NULL_PARAMETER               parameter(s) has(have) illigal NULL pointer(s)\r
+*/\r
+\r
+net_nfc_error_e net_nfc_free_carrier_config (net_nfc_carrier_config_h config);\r
+\r
+/**\r
+       create the group handle\r
+\r
+       @param[out]     group           instance group handler\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception NET_NFC_NULL_PARAMETER               parameter(s) has(have) illigal NULL pointer(s)\r
+       @exception NET_NFC_ALLOC_FAIL                   allocation is failed\r
+*/\r
+\r
+net_nfc_error_e net_nfc_create_carrier_config_group (net_nfc_property_group_h * group, uint16_t attribute);\r
+\r
+/**\r
+       add property into the group\r
+\r
+       @param[in]      group           instance group handler\r
+       @param[in]      attribute               attribute of the property\r
+       @param[in]      size                    size of data (value)\r
+       @param[in]      data                    data of the property\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception NET_NFC_NULL_PARAMETER               parameter(s) has(have) illigal NULL pointer(s)\r
+       @exception NET_NFC_ALLOC_FAIL                   allocation is failed\r
+       @exception NET_NFC_ALREADY_REGISTERED   the given key is already registered\r
+*/\r
+\r
+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);\r
+\r
+/**\r
+       get property from group handle\r
+\r
+       @param[in]      group           instance group handler\r
+       @param[in]      attribute               attribute of the property\r
+       @param[out]     size                    size of data (value)\r
+       @param[out]     data                    data of the property\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception NET_NFC_NULL_PARAMETER               parameter(s) has(have) illigal NULL pointer(s)\r
+       @exception NET_NFC_NO_DATA_FOUND                the attribute does not exist in the group\r
+*/\r
+\r
+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);\r
+\r
+/**\r
+       remove the property from the group\r
+\r
+       @param[in]      group           instance group handler\r
+       @param[in]      attribute               attribute of the property\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception NET_NFC_NULL_PARAMETER               parameter(s) has(have) illigal NULL pointer(s)\r
+       @exception NET_NFC_NO_DATA_FOUND                the attribute does not exist in the group\r
+*/\r
+\r
+net_nfc_error_e net_nfc_remove_carrier_config_group_property (net_nfc_property_group_h group, uint16_t attribute);\r
+\r
+\r
+/**\r
+       free the group\r
+\r
+       @param[in]      group           instance group handler\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception NET_NFC_NULL_PARAMETER               parameter(s) has(have) illigal NULL pointer(s)\r
+*/\r
+\r
+net_nfc_error_e net_nfc_free_carrier_group (net_nfc_property_group_h group);\r
+\r
+/**\r
+       Create record handler with config.\r
+\r
+       @param[out]     record          record handler\r
+       @param[in]      config  the wifi configure handle\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception NET_NFC_NULL_PARAMETER               parameter(s) has(have) illigal NULL pointer(s)\r
+       @exception NET_NFC_ALLOC_FAIL                   allocation is failed\r
+*/\r
+\r
+net_nfc_error_e net_nfc_create_ndef_record_with_carrier_config (ndef_record_h * record, net_nfc_carrier_config_h config);\r
+\r
+\r
+/**\r
+       create configure from the ndef record. the. the record must contained the configuration.\r
+       config should be freed after using\r
+\r
+       @param[in]      record          record handler\r
+       @param[out]     config  the configure handle\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception NET_NFC_NULL_PARAMETER               parameter(s) has(have) illigal NULL pointer(s)\r
+       @exception NET_NFC_ALLOC_FAIL                   allocation is failed\r
+       @exception NET_NFC_INVALID_FORMAT               if the record does not contained the valid format.\r
+*/\r
+\r
+net_nfc_error_e net_nfc_create_carrier_config_from_config_record (net_nfc_carrier_config_h* config, ndef_record_h record);\r
+\r
+/**\r
+       append record into the connection handover request for reponse message;\r
+\r
+       @param[in]      message                 ndef message handler\r
+       @param[in]      record          record handler\r
+       @param[in]      power_status    the power status of the current configuration\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception NET_NFC_NULL_PARAMETER               parameter(s) has(have) illigal NULL pointer(s)\r
+       @exception NET_NFC_ALLOC_FAIL                   allocation is failed\r
+       @exception NET_NFC_INVALID_FORMAT               if the record does not contained the valid format.\r
+       @exception NET_NFC_NO_DATA_FOUND                the attribute does not exist in the group\r
+*/\r
+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);\r
+\r
+/**\r
+       append record into the connection handover request for reponse message;\r
+\r
+       @param[in]      message                 ndef message handler\r
+       @param[in]      record          record handler\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception NET_NFC_NULL_PARAMETER               parameter(s) has(have) illigal NULL pointer(s)\r
+       @exception NET_NFC_ALLOC_FAIL                   allocation is failed\r
+       @exception NET_NFC_INVALID_FORMAT               if the record does not contained the valid format.\r
+       @exception NET_NFC_NO_DATA_FOUND                Given record does not exist in the ndef message\r
+*/\r
+\r
+net_nfc_error_e net_nfc_remove_carrier_config_record (ndef_message_h message, ndef_record_h record);\r
+\r
+/**\r
+       get configure record from ndef message by index\r
+\r
+       @param[in]      message                 ndef message handler\r
+       @param[in]      index\r
+       @param[out]     record          record handler\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception NET_NFC_NULL_PARAMETER               parameter(s) has(have) illigal NULL pointer(s)\r
+       @exception NET_NFC_ALLOC_FAIL                   allocation is failed\r
+       @exception NET_NFC_INVALID_FORMAT               if the record does not contained the valid format.\r
+*/\r
+\r
+net_nfc_error_e net_nfc_get_carrier_config_record (ndef_message_h message, int index, ndef_record_h * record);\r
+\r
+/**\r
+       get randome number from the connection request message\r
+\r
+       @param[in]      message                         ndef message handler\r
+       @param[out]     randome_number  randome number\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception NET_NFC_NULL_PARAMETER               parameter(s) has(have) illigal NULL pointer(s)\r
+       @exception NET_NFC_INVALID_FORMAT               if the record does not contained the valid format.\r
+*/\r
+\r
+net_nfc_error_e net_nfc_get_handover_random_number(ndef_message_h message, unsigned short* random_number);\r
+\r
+/**\r
+       get the count of the alternative (configuration) in the message\r
+\r
+       @param[in]      message                 ndef message handler\r
+       @param[out]     count           number configuration in the message\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception NET_NFC_NULL_PARAMETER               parameter(s) has(have) illigal NULL pointer(s)\r
+       @exception NET_NFC_INVALID_FORMAT               if the record does not contained the valid format.\r
+*/\r
+net_nfc_error_e net_nfc_get_alternative_carrier_record_count (ndef_message_h message,  unsigned int * count);\r
+\r
+\r
+/**\r
+       get power status of the given configruation\r
+\r
+       @param[in]      message                 ndef message handler\r
+       @param[in]      index           index\r
+       @param[out]     power_state     power state of the alternative\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception NET_NFC_NULL_PARAMETER               parameter(s) has(have) illigal NULL pointer(s)\r
+       @exception NET_NFC_INVALID_FORMAT               if the record does not contained the valid format.\r
+       @exception NET_NFC_NO_DATA_FOUND                there is no alternative record is found\r
+       @exception NET_NFC_OUT_OF_BOUND                 index number is out of message count\r
+*/\r
+\r
+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);\r
+\r
+/**\r
+       set power status of the given configruation\r
+\r
+       @param[in]      message                 ndef message handler\r
+       @param[in]      index           index\r
+       @param[in]      power_state     power state of the alternative\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception NET_NFC_NULL_PARAMETER               parameter(s) has(have) illigal NULL pointer(s)\r
+       @exception NET_NFC_INVALID_FORMAT               if the record does not contained the valid format.\r
+       @exception NET_NFC_NO_DATA_FOUND                there is no alternative record is found\r
+       @exception NET_NFC_OUT_OF_BOUND                 index number is out of message count\r
+*/\r
+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);\r
+\r
+/**\r
+       this function will get carrier type.\r
+\r
+       @param[in]      carrier_info                    connection handover carrier info handler\r
+       @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.\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception NET_NFC_NULL_PARAMETER               parameter(s) has(have) illigal NULL pointer(s)\r
+*/\r
+\r
+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);\r
+\r
+\r
+/**\r
+       craete the connection handover request message\r
+\r
+       @param[in]      message                         connection handover carrier info handler\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception NET_NFC_NULL_PARAMETER               parameter(s) has(have) illigal NULL pointer(s)\r
+       @exception NET_NFC_ALLOC_FAIL                   allocation is failed\r
+*/\r
+\r
+net_nfc_error_e net_nfc_create_handover_request_message (ndef_message_h * message);\r
+\r
+/**\r
+       craete the connection handover select message\r
+\r
+       @param[in]      message                         connection handover carrier info handler\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception NET_NFC_NULL_PARAMETER               parameter(s) has(have) illigal NULL pointer(s)\r
+       @exception NET_NFC_ALLOC_FAIL                   allocation is failed\r
+*/\r
+\r
+net_nfc_error_e net_nfc_create_handover_select_message (ndef_message_h * message);\r
+\r
+/**\r
+       craete the connection handover error record message\r
+\r
+       @param[out]     record                  connection handover carrier info handler\r
+       @param[in]      reason                  error codes (reason)\r
+       @param[in]      data                            extra data for each error codes\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception NET_NFC_NULL_PARAMETER               parameter(s) has(have) illigal NULL pointer(s)\r
+       @exception NET_NFC_ALLOC_FAIL                   allocation is failed\r
+*/\r
+net_nfc_error_e net_nfc_create_handover_error_record (ndef_record_h * record, uint8_t reason, uint32_t data);\r
+\r
+\r
+#ifdef __cplusplus\r
+ }\r
+#endif\r
+\r
+\r
+#endif\r
+\r
+\r
diff --git a/src/clientlib/include/net_nfc_ndef_record.h b/src/clientlib/include/net_nfc_ndef_record.h
new file mode 100644 (file)
index 0000000..c1a9ab1
--- /dev/null
@@ -0,0 +1,371 @@
+/*\r
+  * Copyright 2012  Samsung Electronics Co., Ltd\r
+  *\r
+  * Licensed under the Flora License, Version 1.0 (the "License");\r
+  * you may not use this file except in compliance with the License.\r
+  * You may obtain a copy of the License at\r
+\r
+  *     http://www.tizenopensource.org/license\r
+  *\r
+  * Unless required by applicable law or agreed to in writing, software\r
+  * distributed under the License is distributed on an "AS IS" BASIS,\r
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+  * See the License for the specific language governing permissions and\r
+  * limitations under the License.\r
+  */\r
+\r
+#ifndef __NET_NFC_NDEF_RECORD_H__\r
+#define __NET_NFC_NDEF_RECORD_H__\r
+\r
+#include "net_nfc_typedef.h"\r
+\r
+#ifdef __cplusplus\r
+  extern "C" {\r
+#endif\r
+\r
+\r
+/**\r
+\r
+@addtogroup NET_NFC_MANAGER_RECORD\r
+@{\r
+       This document is for the APIs reference document\r
+\r
+        NFC Manager defines are defined in <nfc-typedef.h>\r
+\r
+*/\r
+\r
+\r
+/**\r
+       This define gives you Message Begin from the flag byte\r
+\r
+       @param[in]      flag            flag that comes from "net_nfc_get_record_flags" function\r
+       @return                 the mb flag\r
+\r
+       @exception NONE\r
+*/\r
+uint8_t net_nfc_get_record_mb (uint8_t flag);\r
+/**\r
+       This define gives you Message end from the flag byte\r
+\r
+       @param[in]      flag            flag that comes from "net_nfc_get_record_flags" function\r
+       @return                 the me flag\r
+\r
+       @exception NONE\r
+*/\r
+uint8_t net_nfc_get_record_me (uint8_t flag);\r
+/**\r
+       This define gives you Chun Flag  that indicate that either the first record chunk or a middle record chunk of a chunked payload\r
+\r
+       @param[in]      flag            flag that comes from "net_nfc_get_record_flags" function\r
+       @return                 the chunk flag\r
+\r
+       @exception NONE\r
+*/\r
+uint8_t net_nfc_get_record_cf (uint8_t flag);\r
+/**\r
+       This define gives you ID length present flag\r
+\r
+       @param[in]      flag            flag that comes from "net_nfc_get_record_flags" function\r
+       @return                 the  il (id length flag) flag\r
+\r
+       @exception NONE\r
+\r
+*/\r
+uint8_t net_nfc_get_record_il (uint8_t flag);\r
+/**\r
+       This define gives you short record flag. This flag indicates that the payload length filed is a single octet\r
+\r
+       @param[in]      flag            flag that comes from "net_nfc_get_record_flags" function\r
+       @return                 the short record flag\r
+\r
+       @exception NONE\r
+*/\r
+uint8_t net_nfc_get_record_sr (uint8_t flag);\r
+\r
+\r
+\r
+/**\r
+       creat a record with given parameter value. this function automatically set the NDEF record flags\r
+\r
+       @param[out]     record                  Record handler\r
+       @param[in]      tnf                             record type (TNF value) empty, well known, mime type, URI, external, or unchanged\r
+       @param[in]      typeName                specify type name ex) Sp, U, or Hr ...\r
+       @param[in]      id                              record id\r
+       @param[in]      payload                         payload of this record\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception NET_NFC_OUT_OF_BOUND                 tnf value is out of range\r
+       @exception NET_NFC_NULL_PARAMETER               parameter(s) has(have) illigal NULL pointer(s)\r
+       @exception NET_NFC_ALLOC_FAIL                   memory allocation is failed\r
+\r
+       @code\r
+               char uri[] = " yahoo.com";\r
+               ndef_record_s uriRecord;\r
+\r
+               data_h payload;\r
+\r
+               net_nfc_create_data (&payload, uri, strlen (uri));\r
+               uri[0] = 0x01;\r
+\r
+               if((result = net_nfc_create_record( &uriRecord, NET_NFC_RECORD_WELL_KNOWN_TYPE, "U" , NULL, payload, )) != NET_NFC_OK)\r
+               {\r
+                       printf("U record is failed [%d]\n", result);\r
+               }\r
+       @endcode\r
+*/\r
+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 );\r
+\r
+\r
+/**\r
+       this function helps to create text type payload\r
+       please, refer the NDEF forum specification "Text Record Type Definition"\r
+       it creates byte array payload can be used in text type record\r
+\r
+       this function does not encode the text. The paramter "text" will be asuumed as that it is already encoded with encode type.\r
+       this function  just helps to create text records.\r
+\r
+       @param[out]     record                          Record handler\r
+       @param[in]      text                                    encoded text (this should be text not binary)\r
+       @param[in]      language_code_str               language_code_str ex) en-US\r
+       @param[in]      encode                          text concoding type such as "utf8"\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception NET_NFC_NULL_PARAMETER               parameter(s) has(have) illigal NULL pointer(s)\r
+       @exception NET_NFC_ALLOC_FAIL                   memory allocation is failed\r
+\r
+\r
+       @code\r
+               net_nfc_error_e result = NET_NFC_OK;\r
+               ndef_message_h msg = NULL;\r
+               ndef_record_h record = NULL;\r
+\r
+               char* message = "Hello, NFC World";\r
+\r
+               net_nfc_create_ndef_message (&msg);\r
+               net_nfc_create_text_type_record (&record , message, "en-US", NET_NFC_ENCODE_UTF_8);\r
+               net_nfc_append_record_to_ndef_message (msg ,record);\r
+\r
+       @endcode\r
+\r
+*/\r
+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);\r
+\r
+/**\r
+       this function helps to create URI type payload\r
+       please refer the NFC forum specification "URI Record type Definition"\r
+       it creates byte array payload.\r
+\r
+       @param[out]     record                          Record handler\r
+       @param[in]      uri                                     string uri that will be stored in the payload\r
+       @param[in]      protocol_schema         protocol schema that is specified in NFC Forum\r
+\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception NET_NFC_NULL_PARAMETER               parameter(s) has(have) illigal NULL pointer(s)\r
+       @exception NET_NFC_ALLOC_FAIL                   memory allocation is failed\r
+\r
+       @code\r
+               net_nfc_error_e result = NET_NFC_OK;\r
+               ndef_message_h msg = NULL;\r
+               ndef_record_h record = NULL;\r
+\r
+               net_nfc_create_ndef_message (&msg);\r
+               net_nfc_create_uri_type_record (&record ,"http://www.samsung.com" ,NET_NFC_SCHEMA_FULL_URI);\r
+               net_nfc_append_record_to_ndef_message (msg ,record);\r
+       @endcode\r
+*/\r
+\r
+net_nfc_error_e net_nfc_create_uri_type_record(ndef_record_h* record, const char * uri, net_nfc_schema_type_e protocol_schema);\r
+\r
+/**\r
+       this function is getter of record payload.\r
+       this function gives you  the pointer of pyaload that is contained by record.\r
+       Do not free the payload. it will be freed when the record is freed\r
+\r
+       @param[in]      record          Record handler\r
+       @param[out]     payload         data_h type payload pointer (it gives you the pointer of payload; not copied)\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception NET_NFC_NULL_PARAMETER               parameter(s) has(have) illigal NULL pointer(s)\r
+\r
+*/\r
+net_nfc_error_e net_nfc_get_record_payload (ndef_record_h record, data_h * payload);\r
+\r
+/**\r
+       this function is getter of record type.\r
+       this function gives you  the pointer of record type that is contained by record.\r
+       Do not free the type. it will be freed when the record is freed\r
+\r
+       @param[in]      record          Record handler\r
+       @param[out]     type                    dat_h type pointer (it gives you the pointer of type; not copied)\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception NET_NFC_NULL_PARAMETER               parameter(s) has(have) illigal NULL pointer(s)\r
+\r
+*/\r
+net_nfc_error_e net_nfc_get_record_type (ndef_record_h record, data_h * type);\r
+\r
+/**\r
+       this function is getter of record ID.\r
+       this function gives you  the pointer of ID that is contained by record.\r
+       it may return NULL pointer if the ID is not exist\r
+       Do not free the type. it will be freed when the record is freed.\r
+\r
+       @param[in]      record          Record handler\r
+       @param[out]     id                      dat_h type ID pointer (it gives you the pointer of payload not copied)\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception NET_NFC_NULL_PARAMETER               parameter(s) has(have) illigal NULL pointer(s)\r
+*/\r
+net_nfc_error_e net_nfc_get_record_id (ndef_record_h record, data_h * id);\r
+\r
+/**\r
+       this function is getter of record TNF value.\r
+\r
+       @param[in]      record          Record handler\r
+       @param[out]     tnf                     TNF value\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception NET_NFC_NULL_PARAMETER               parameter(s) has(have) illigal NULL pointer(s)\r
+\r
+\r
+*/\r
+net_nfc_error_e net_nfc_get_record_tnf(ndef_record_h record, net_nfc_record_tnf_e * tnf);\r
+\r
+/**\r
+       this function is getter of record flags.\r
+       you can get the each flag value by using defines "RECORD_GET_XX"\r
+\r
+       @param[in]      record          Record handler\r
+       @param[out]     flag                    flag value (it gives you the pointer of payload not copied)\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception NET_NFC_NULL_PARAMETER               parameter(s) has(have) illigal NULL pointer(s)\r
+\r
+       @code\r
+\r
+               ndef_record_h    record;\r
+               uint8_t flag;\r
+\r
+               net_nfc_get_record_by_index (msg, 0, &record);\r
+               if (record != NULL){\r
+                       net_nfc_get_record_flags (record, &flag);\r
+                       printf ("MB:%d, ME:%d, CF:%d, IL:%d, SR:%d\n",\r
+                               net_nfc_get_record_mb(flag),\r
+                               net_nfc_get_record_me(flag),\r
+                               net_nfc_get_record_cf(flag),\r
+                               net_nfc_get_record_il(flag),\r
+                               net_nfc_get_record_sr(flag));\r
+               }\r
+\r
+       @endcode\r
+\r
+*/\r
+net_nfc_error_e net_nfc_get_record_flags (ndef_record_h record, uint8_t * flag);\r
+\r
+\r
+/**\r
+       you can set record ID with this function\r
+\r
+       @param[in]      record          Record handler\r
+       @param[in]      id                      Record ID\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception NET_NFC_NULL_PARAMETER               parameter(s) has(have) illigal NULL pointer(s)\r
+\r
+*/\r
+net_nfc_error_e net_nfc_set_record_id (ndef_record_h record, data_h id);\r
+\r
+/**\r
+       this function free the record handler. do not use this function after appending the ndef message\r
+\r
+       @param[in]      record          Record handler\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception NET_NFC_NULL_PARAMETER               parameter(s) has(have) illigal NULL pointer(s)\r
+\r
+*/\r
+net_nfc_error_e net_nfc_free_record (ndef_record_h record);\r
+\r
+\r
+/**\r
+       this function get text from text record. it allocate buffer char and store the text string. you should free this string.\r
+\r
+       @param[in]      record          Record handler\r
+       @param[out]     buffer          text string\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception NET_NFC_ALLOC_FAIL                   memory allocation is failed\r
+       @exception NET_NFC_NDEF_RECORD_IS_NOT_EXPECTED_TYPE             record is not text record\r
+       @exception NET_NFC_NULL_PARAMETER               parameter(s) has(have) illigal NULL pointer(s)\r
+\r
+*/\r
+\r
+net_nfc_error_e net_nfc_create_text_string_from_text_record(ndef_record_h record, char** buffer);\r
+\r
+/**\r
+       this function get language code from text record. (ex: US-en)\r
+\r
+       @param[in]      record                  Record handler\r
+       @param[out]     lang_code_str   lang code string value followed by IANA\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception NET_NFC_NDEF_RECORD_IS_NOT_EXPECTED_TYPE             record is not text record\r
+       @exception NET_NFC_NULL_PARAMETER               parameter(s) has(have) illigal NULL pointer(s)\r
+\r
+*/\r
+\r
+net_nfc_error_e net_nfc_get_languange_code_string_from_text_record (ndef_record_h record, char** lang_code_str);\r
+\r
+\r
+/**\r
+       this function get encoding type from text record (ex: UTF-8)\r
+\r
+       @param[in]      record          Record handler\r
+       @param[out]     encoding        encoding type\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception NET_NFC_NDEF_RECORD_IS_NOT_EXPECTED_TYPE             record is not text record\r
+       @exception NET_NFC_NULL_PARAMETER               parameter(s) has(have) illigal NULL pointer(s)\r
+\r
+*/\r
+\r
+net_nfc_error_e net_nfc_get_encoding_type_from_text_record(ndef_record_h record, net_nfc_encode_type_e * encoding);\r
+\r
+\r
+/**\r
+       this function get URI from uri record. you should free the uri string.\r
+\r
+       @param[in]      record          Record handler\r
+       @param[out]     uri                     uri text string\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception NET_NFC_NDEF_RECORD_IS_NOT_EXPECTED_TYPE             record is not uri record\r
+       @exception NET_NFC_NULL_PARAMETER               parameter(s) has(have) illigal NULL pointer(s)\r
+\r
+*/\r
+\r
+net_nfc_error_e net_nfc_create_uri_string_from_uri_record(ndef_record_h record, char ** uri);\r
+\r
+#ifdef __cplusplus\r
+ }\r
+#endif\r
+\r
+\r
+#endif\r
+\r
+\r
diff --git a/src/clientlib/include/net_nfc_tag.h b/src/clientlib/include/net_nfc_tag.h
new file mode 100644 (file)
index 0000000..7a3262d
--- /dev/null
@@ -0,0 +1,493 @@
+/*\r
+  * Copyright 2012  Samsung Electronics Co., Ltd\r
+  *\r
+  * Licensed under the Flora License, Version 1.0 (the "License");\r
+  * you may not use this file except in compliance with the License.\r
+  * You may obtain a copy of the License at\r
+\r
+  *     http://www.tizenopensource.org/license\r
+  *\r
+  * Unless required by applicable law or agreed to in writing, software\r
+  * distributed under the License is distributed on an "AS IS" BASIS,\r
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+  * See the License for the specific language governing permissions and\r
+  * limitations under the License.\r
+  */\r
+\r
+#ifndef __NET_NFC_TAG_H__\r
+#define __NET_NFC_TAG_H__\r
+\r
+#include "net_nfc_typedef.h"\r
+\r
+\r
+#ifdef __cplusplus\r
+ extern "C" {\r
+#endif\r
+\r
+/**\r
+\r
+@addtogroup NET_NFC_MANAGER_TAG\r
+@{\r
+       This document is for the APIs reference document\r
+\r
+        NFC Manager defines are defined in <net_nfc_typedef.h>\r
+\r
+        @li @c #net_nfc_transceive                                     provide low level tag access\r
+        @li @c #net_nfc_format_ndef                                    format to NDEF tag type\r
+        @li @c #net_nfc_read_tag                                               read ndef message\r
+        @li @c #net_nfc_write_ndef                                     write ndef message\r
+        @li @c #net_nfc_set_tag_filter                                 set detection filter .\r
+        @li @c #net_nfc_get_tag_filter                                 get detection filter\r
+        @li @c #net_nfc_create_transceive_info_only            allocate the transceive info.\r
+        @li @c #net_nfc_create_transceive_info                 allocate the transeeive info and set given values\r
+        @li @c #net_nfc_set_transceive_info_command    command setter from transceive info.\r
+        @li @c #net_nfc_set_transceive_info_data               data setter from transceive info.\r
+        @li @c #net_nfc_set_transceive_info_address            address setter from transceive info.\r
+        @li @c #net_nfc_free_transceive_info                   free transceive info handler\r
+\r
+*/\r
+\r
+/**\r
+       transceive function is the only wayt to access the raw format card (not formated),\r
+       each tag type requres own command to access tags,\r
+       this API provide low level access of tag operation and you require the knowlege of each tag technology. <BR>\r
+       To use this API you should create transceive info with "net_nfc_create_transceive_info" API\r
+\r
+       \par Sync (or) Async: Async\r
+       This is a Asynchronous API\r
+\r
+       @param[in]      handle          target ID that has been delivered from callback\r
+       @param[in]      info                    trnasceive infomation that has created by "net_nfc_create_transceive_info" API\r
+       @param[in]      trans_param     user data that will be delivered to callback\r
+\r
+       @return return the result of the calling this function\r
+\r
+       @exception NET_NFC_ALLOC_FAIL   memory allocation is failed\r
+       @exception NET_NFC_NOT_INITIALIZED      Try to operate without initialization\r
+       @exception NET_NFC_BUSY                         Device is too busy to handle your request\r
+       @exception NET_NFC_OPERATION_FAIL       Operation is failed because of the internal oal error\r
+       @exception NET_NFC_RF_TIMEOUT   Timeout is raised while communicate with tag\r
+       @exception NET_NFC_NOT_SUPPORTED        you may recieve this error if you request not supported command\r
+       @exception NET_NFC_INVALID_HANDLE               target handle is not valid\r
+       @exception NET_NFC_TAG_READ_FAILED      received chunked data is not valied (damaged data is recieved) or error ack is recieved\r
+       @exception NET_NFC_TAG_WRITE_FAILED     read only tag, or error ack is received from tag\r
+\r
+       @code\r
+\r
+       void net_nfc_cb(net_nfc_message_e message, net_nfc_error_e result, void* data , void* userContext)\r
+       {\r
+               net_nfc_target_handle_h id;\r
+               bool is_ndef;\r
+               net_nfc_target_info_h target_info = (net_nfc_target_info_h)data;\r
+\r
+               net_nfc_get_tag_ndef_support (target_info, &is_ndef);\r
+               net_nfc_get_tag_handle (target_info, &id);\r
+\r
+               case NET_NFC_MESSAGE_TAG_DISCOVERED:\r
+               {\r
+                       net_nfc_transceive_info_h trans;\r
+                       net_nfc_create_transceive_info (&trans, NET_NFC_EMIFAREREAD, 0x00, NULL);\r
+                       net_nfc_transceive (id ,trans , &user_context);\r
+                       net_nfc_free_transceive_info (trans);\r
+               }\r
+               break;\r
+\r
+               case NET_NFC_MESSAGE_TRANSCEIVE:\r
+                       if(result == NET_NFC_OK){\r
+                               printf("NET_NFC_MESSAGE_TRANSCEIVE is OK \n");\r
+                               if (data != NULL){\r
+                                       data_h read_data = (data_h) * data;\r
+                                       int idx;\r
+                                       uint8_t * buf = net_nfc_get_data_buffer (data_read);\r
+                                       for (idx = 0; idx < net_nfc_get_data_length (read_data); idx ++){\r
+                                               printf (" %02X", buf[idx]);\r
+                                       }\r
+                               }\r
+                       }\r
+                       else{\r
+                               printf("NET_NFC_MESSAGE_TRANSCEIVE is failed %d\n", result);\r
+                       }\r
+               break;\r
+       }\r
+\r
+       int main()\r
+       {
+\r
+               net_nfc_error_e result;\r
+               result = net_nfc_initialize();\r
+               check_result(result);
+\r
+               result = net_nfc_set_response_callback (net_nfc_cb, &user_context2);\r
+               check_result(result);\r
+\r
+               sleep (100);\r
+
+               return 0;
+       }\r
+       @endcode\r
+\r
+*/\r
+\r
+net_nfc_error_e net_nfc_transceive (net_nfc_target_handle_h handle, data_h rawdata, void* trans_param);\r
+\r
+/**\r
+       This API formats the detected tag that can store NDEF message.\r
+       some tags are required authentication. if the detected target does need authentication, set NULL.\r
+\r
+       \par Sync (or) Async: Async\r
+       This is a Asynchronous API\r
+\r
+       @param[in]      handle          target ID that has been delivered from callback\r
+       @param[in]      key                     key value that may need to format the tag\r
+       @param[in]      trans_param     user data that will be delivered to callback\r
+\r
+       @return return the result of the calling this function\r
+\r
+       @exception NET_NFC_ALLOC_FAIL   memory allocation is failed\r
+       @exception NET_NFC_NOT_INITIALIZED      Try to operate without initialization\r
+       @exception NET_NFC_BUSY                         Device is too busy to handle your request\r
+       @exception NET_NFC_OPERATION_FAIL       Operation is failed because of the internal oal error\r
+       @exception NET_NFC_RF_TIMEOUT   Timeout is raised while communicate with tag\r
+       @exception NET_NFC_INVALID_HANDLE               target handle is not valid\r
+       @exception NET_NFC_TAG_WRITE_FAILED     read only tag, or error ack is received from tag\r
+       @exception NET_NFC_TAG_IS_ALREADY_FORMATTED     requested target is already famatted\r
+\r
+       @code\r
+\r
+       void net_nfc_cb(net_nfc_message_e message, net_nfc_error_e result, void* data , void* userContext)\r
+       {\r
+               case NET_NFC_MESSAGE_TAG_DISCOVERED:\r
+\r
+               if(data != NULL){\r
+                       net_nfc_target_handle_h id;\r
+                       bool is_ndef;\r
+                       net_nfc_target_info_h target_info = (net_nfc_target_info_h)data;\r
+\r
+                       net_nfc_get_tag_ndef_support (target_info, &is_ndef);\r
+                       net_nfc_get_tag_handle (target_info, &id);\r
+\r
+                       if (!is_ndef){\r
+                               net_nfc_format_ndef (id, NULL, NULL);\r
+                       }\r
+               }\r
+               break;\r
+\r
+               case NET_NFC_MESSAGE_FORMAT_NDEF:\r
+                       printf ("ndef format is completed with %d\n", result);\r
+               break;\r
+       }\r
+       @endcode\r
+\r
+*/\r
+\r
+net_nfc_error_e net_nfc_format_ndef(net_nfc_target_handle_h handle, data_h key, void* trans_param);\r
+\r
+\r
+\r
+/**\r
+       net_nfc_Ndef_read do read operation with NDEF format\r
+       In the callback function, return value is byte array of the NDEF message.\r
+       it need to convert to NDEF structure\r
+\r
+       \par Sync (or) Async: Async\r
+       This is a Asynchronous API\r
+\r
+       @param[in]      handle          the target ID the connection is already made\r
+       @param[in]      trans_param     user data\r
+\r
+       @return         return the result of the calling this function\r
+\r
+       @exception NET_NFC_NOT_INITIALIZED      Try to operate without initialization\r
+       @exception NET_NFC_NO_NDEF_SUPPORT      Tag is not support NDEF message\r
+       @exception NET_NFC_ALLOC_FAIL   memory allocation is failed\r
+       @exception NET_NFC_BUSY         Device is too busy to handle your request\r
+       @exception NET_NFC_RF_TIMEOUT   Timeout is raised while communicate with tag\r
+       @exception NET_NFC_INVALID_HANDLE               target handle is not valid\r
+       @exception NET_NFC_TAG_READ_FAILED      received chunked data is not valied (damaged data is recieved) or error ack is recieved\r
+\r
+       @code\r
+       void net_nfc_cb(net_nfc_message_e message, net_nfc_error_e result, void* data , void* userContext)\r
+       {\r
+               // ......\r
+               switch (message)\r
+               {\r
+                       case NET_NFC_MESSAGE_TAG_DISCOVERED:\r
+                       {\r
+                               if(data != NULL){\r
+                                       net_nfc_target_handle_h id;\r
+                                       bool is_ndef;\r
+                                       net_nfc_target_info_h target_info = (net_nfc_target_info_h)data;\r
+\r
+                                       net_nfc_get_tag_ndef_support (target_info, &is_ndef);\r
+                                       net_nfc_get_tag_handle (target_info, &id);\r
+\r
+                                       if (is_ndef){\r
+                                               net_nfc_read_tag (id, &user_context);\r
+                                       }\r
+                               }\r
+                       }\r
+                       break;\r
+\r
+                       case NET_NFC_MESSAGE_READ_NDEF:\r
+                       {\r
+                               if (result != NET_NFC_OK)\r
+                               {\r
+                                       // FAILED read NDEF message\r
+                               }\r
+                               ndef_message_h ndef_message = (ndef_message_h ) data;\r
+                       }\r
+                       break;\r
+               }\r
+               return;\r
+       }\r
+\r
+       int main()\r
+       {
+\r
+               net_nfc_error_e result;\r
+               result = net_nfc_initialize();\r
+               check_result(result);
+\r
+               result = net_nfc_set_response_callback (net_nfc_cb, &user_context2);\r
+               check_result(result);\r
+\r
+               sleep (100);\r
+
+               return 0;
+       }\r
+       @endcode\r
+\r
+*/\r
+\r
+\r
+net_nfc_error_e net_nfc_read_tag (net_nfc_target_handle_h handle, void* trans_param);\r
+\r
+/**\r
+       net_nfc_Ndef_write do write operation with NDEF format message\r
+\r
+       \par Sync (or) Async: Async\r
+       This is a Asynchronous API\r
+\r
+       @param[in]      handle          the target Id the connection is already made\r
+       @param[in]      msg                     the message will be write to the target\r
+       @param[in]      trans_param     user data\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception NET_NFC_NOT_INITIALIZED      Try to operate without initialization\r
+       @exception NET_NFC_NO_NDEF_SUPPORT      Tag is not support NDEF message\r
+       @exception NET_NFC_ALLOC_FAIL   memory allocation is failed\r
+       @exception NET_NFC_BUSY         Device is too busy to handle your request\r
+       @exception NET_NFC_INSUFFICIENT_STORAGE  Tag does not enough storage to store NDEF message\r
+       @exception NET_NFC_RF_TIMEOUT   Timeout is raised while communicate with tag\r
+       @exception NET_NFC_INVALID_HANDLE               target handle is not valid\r
+       @exception NET_NFC_TAG_WRITE_FAILED     read only tag, or error ack is received from tag\r
+\r
+\r
+       @code\r
+       void net_nfc_cb(net_nfc_message_e message, net_nfc_error_e result, void* data , void* userContext)\r
+       {\r
+               // ......\r
+               switch (message)\r
+               {\r
+                       case NET_NFC_MESSAGE_TAG_DISCOVERED:\r
+                       {\r
+                               if(data != NULL){\r
+                                       net_nfc_target_handle_h id;\r
+                                       bool is_ndef;\r
+                                       net_nfc_target_info_h target_info = (net_nfc_target_info_h)data;\r
+\r
+                                       net_nfc_get_tag_ndef_support (target_info, &is_ndef);\r
+                                       net_nfc_get_tag_handle (target_info, &id);\r
+\r
+                                       if (is_ndef){\r
+                                               net_nfc_error_e result = NET_NFC_OK;\r
+                                               ndef_message_h bt_msg = NULL;\r
+                                               ndef_record_h record = NULL;\r
+\r
+                                               net_nfc_create_ndef_message (&msg);\r
+                                               net_nfc_create_text_type_record (&record , "Hello NFC World", NET_NFC_LANG_EN_US ,NET_NFC_ENCODE_UTF_8);\r
+                                               net_nfc_append_record_to_ndef_message (msg ,record);\r
+\r
+                                               net_nfc_write_ndef(id, msg, &user_context);\r
+                                       }\r
+                               }\r
+                       }\r
+                       break;\r
+\r
+                       case NET_NFC_MESSAGE_WRITE_NDEF:\r
+                       {\r
+                               if (result != NET_NFC_OK)\r
+                               {\r
+                                       // FAILED write NDEF message\r
+                               }\r
+                       }\r
+                       break;\r
+               }\r
+               return;\r
+       }\r
+\r
+       int main()\r
+       {
+\r
+               net_nfc_error_e result;\r
+               result = net_nfc_initialize();\r
+               check_result(result);
+\r
+               result = net_nfc_set_response_callback (net_nfc_cb, &user_context2);\r
+               check_result(result);\r
+\r
+               sleep (100);\r
+
+               return 0;
+       }\r
+       @endcode\r
+\r
+*/\r
+\r
+net_nfc_error_e net_nfc_write_ndef (net_nfc_target_handle_h handle, ndef_message_h msg, void* trans_param);\r
+\r
+/**\r
+       this API make a ndef tag read only.\r
+\r
+       \par Sync (or) Async: Async\r
+       This is a synchronous API\r
+\r
+       @param[in]      handle          the target Id the connection is already made\r
+       @param[in]      trans_param     user data\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception NONE\r
+\r
+       @code\r
+\r
+       @code\r
+       void net_nfc_cb(net_nfc_message_e message, net_nfc_error_e result, void* data , void* userContext)\r
+       {\r
+               // ......\r
+               switch (message)\r
+               {\r
+                       case NET_NFC_MESSAGE_TAG_DISCOVERED:\r
+                       {\r
+                               if(data != NULL){\r
+                                       net_nfc_target_handle_h id;\r
+                                       bool is_ndef;\r
+                                       net_nfc_target_info_h target_info = (net_nfc_target_info_h)data;\r
+\r
+                                       net_nfc_get_tag_ndef_support (target_info, &is_ndef);\r
+                                       net_nfc_get_tag_handle (target_info, &id);\r
+\r
+                                       if (is_ndef){\r
+\r
+                                               net_nfc_error_e result = NET_NFC_OK;\r
+                                               net_nfc_make_read_only_ndef_tag(id, &user_context);\r
+                                       }\r
+                               }\r
+                       }\r
+                       break;\r
+\r
+                       case NET_NFC_MESSAGE_MAKE_READ_ONLY_NDEF:\r
+                       {\r
+                               if (result != NET_NFC_OK)\r
+                               {\r
+                                       // FAILED to make read only ndef tag\r
+                               }\r
+                       }\r
+                       break;\r
+               }\r
+               return;\r
+       }\r
+\r
+       int main()\r
+       {
+\r
+               net_nfc_error_e result;\r
+               result = net_nfc_initialize();\r
+               check_result(result);
+\r
+               result = net_nfc_set_response_callback (net_nfc_cb, &user_context2);\r
+               check_result(result);\r
+\r
+               sleep (100);\r
+
+               return 0;
+       }\r
+       @endcode\r
+\r
+*/\r
+\r
+\r
+net_nfc_error_e net_nfc_make_read_only_ndef_tag(net_nfc_target_handle_h handle, void* trans_param);\r
+\r
+/**\r
+       this API help to set filter of target types.\r
+       bit opertor or can be used in the config parameter (like  NET_NFC_ISO14443A_ENABLE | NET_NFC_ISO14443B_ENABLE)\r
+       or you may choose "NET_NFC_ALL_ENABLE" enum value to get all result\r
+       it prevent getting tag types from RF level.\r
+       if the client api does call this function, default is always NET_NFC_ALL_ENABLE.\r
+\r
+       \par Sync (or) Async: Async\r
+       This is a synchronous API\r
+\r
+       @param[in]      config          filter value with bits operation\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception NONE\r
+\r
+       @code\r
+\r
+       int main()\r
+       {
+\r
+               net_nfc_error_e result;\r
+               result = net_nfc_initialize();\r
+               check_result(result);
+\r
+               net_nfc_event_filter_e filter = NET_NFC_ALL_ENABLE;\r
+               net_nfc_error_e net_nfc_set_tag_filter(filter);\r
+\r
+               result = net_nfc_set_response_callback (net_nfc_cb, &user_context2);\r
+               check_result(result);\r
+\r
+               sleep (100);\r
+
+               return 0;
+       }\r
+\r
+       @endcode\r
+*/\r
+\r
+net_nfc_error_e net_nfc_set_tag_filter(net_nfc_event_filter_e config);\r
+\r
+/**\r
+       get current filter status. The current filter value will return filter you can call this API any time anywhere\r
+\r
+       \par Sync (or) Async: Async\r
+       This is a synchronous API\r
+\r
+       @return         return the filter which is set\r
+\r
+       @exception NONE\r
+\r
+       @code\r
+\r
+       net_nfc_event_filter_e config = net_nfc_get_tag_filter();\r
+\r
+       @endcode\r
+\r
+*/\r
+net_nfc_error_e net_nfc_is_tag_connected(void* trans_param);\r
+\r
+net_nfc_event_filter_e net_nfc_get_tag_filter(void);\r
+\r
+net_nfc_error_e net_nfc_get_current_tag_info(void* trans_param);\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+\r
+\r
+#endif\r
+\r
diff --git a/src/clientlib/include/net_nfc_tag_felica.h b/src/clientlib/include/net_nfc_tag_felica.h
new file mode 100644 (file)
index 0000000..cedfb34
--- /dev/null
@@ -0,0 +1,236 @@
+/*\r
+  * Copyright 2012  Samsung Electronics Co., Ltd\r
+  *\r
+  * Licensed under the Flora License, Version 1.0 (the "License");\r
+  * you may not use this file except in compliance with the License.\r
+  * You may obtain a copy of the License at\r
+\r
+  *     http://www.tizenopensource.org/license\r
+  *\r
+  * Unless required by applicable law or agreed to in writing, software\r
+  * distributed under the License is distributed on an "AS IS" BASIS,\r
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+  * See the License for the specific language governing permissions and\r
+  * limitations under the License.\r
+  */\r
+\r
+#ifndef __NET_NFC_TAG_FELICA_H__\r
+#define __NET_NFC_TAG_FELICA_H__\r
+\r
+#include "net_nfc_typedef.h"\r
+\r
+\r
+#ifdef __cplusplus\r
+ extern "C" {\r
+#endif\r
+\r
+/**\r
+\r
+@addtogroup NET_NFC_MANAGER_TAG\r
+@{\r
+\r
+       send poll request to felica tag.\r
+       Use this command to acquire and identify a card. Acqusition of IDm and PMm is possible with this command.\r
+       By specifying a request code , you can acquire system code or communication performance of the system.\r
+       By specifying a time slot, you can designate the maximum number of time slots possible to return response.\r
+\r
+       NET_NFC_FELICA_POLL_NO_REQUEST = 0x00\r
+       NET_NFC_FELICA_POLL_SYSTEM_CODE_REQUEST = 0x01\r
+       NET_NFC_FELICA_POLL_COMM_SPEED_REQUEST= 0x02\r
+\r
+       time slot\r
+\r
+       Time slot               Max number of slots\r
+       0x00,           1\r
+       0x01,           2\r
+       0x03,           4\r
+       0x07,           8\r
+       0x0f,           16\r
+\r
+       \par Sync (or) Async: Sync\r
+       This is a Asynchronous API\r
+\r
+       @param[in]      handle          target handle of detected tag\r
+       @param[in]      req_code                request code with this command\r
+       @param[in]      time_slot               time slot value\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception NET_NFC_NULL_PARAMETER       parameter has illigal NULL pointer\r
+       @exception NET_NFC_ALLOC_FAIL   memory allocation is failed\r
+       @exception NET_NFC_NOT_INITIALIZED      Try to operate without initialization\r
+       @exception NET_NFC_BUSY         Device is too busy to handle your request\r
+       @exception NET_NFC_OPERATION_FAIL       Operation is failed because of the internal oal error\r
+       @exception NET_NFC_RF_TIMEOUT   Timeout is raised while communicate with tag\r
+       @exception NET_NFC_NOT_SUPPORTED        you may recieve this error if you request not supported command\r
+       @exception NET_NFC_INVALID_HANDLE       target handle is not valid\r
+       @exception NET_NFC_TAG_READ_FAILED      received chunked data is not valied (damaged data is recieved) or error ack is recieved\r
+       @exception NET_NFC_NO_DATA_FOUND        mendantory tag info (SYSTEM_CODE, etc) is not founded\r
+\r
+*/\r
+\r
+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);\r
+\r
+/**\r
+       Use this command to check for the existence of Area / Service specified by Area Code / Service Code\r
+       If the specified Area / Service exists, the card returns version information of the key known as "Key Version" (2 Bytes)\r
+       If the specified Area / Service does not exist, the card returns 0xffff as it s Key Version\r
+\r
+       \par Sync (or) Async: Sync\r
+       This is a Asynchronous API\r
+\r
+       @param[in]      handle                                          target handle of detected tag\r
+       @param[in]      number_of_area_service          the number of specified Area / Service list\r
+       @param[in]      area_service_list                               specified Area / Service list\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception NET_NFC_NULL_PARAMETER       parameter has illigal NULL pointer\r
+       @exception NET_NFC_ALLOC_FAIL   memory allocation is failed\r
+       @exception NET_NFC_NOT_INITIALIZED      Try to operate without initialization\r
+       @exception NET_NFC_BUSY         Device is too busy to handle your request\r
+       @exception NET_NFC_OPERATION_FAIL       Operation is failed because of the internal oal error\r
+       @exception NET_NFC_RF_TIMEOUT   Timeout is raised while communicate with tag\r
+       @exception NET_NFC_NOT_SUPPORTED        you may recieve this error if you request not supported command\r
+       @exception NET_NFC_INVALID_HANDLE       target handle is not valid\r
+       @exception NET_NFC_TAG_READ_FAILED      received chunked data is not valied (damaged data is recieved) or error ack is recieved\r
+       @exception NET_NFC_NO_DATA_FOUND        mendantory tag info (IDm, etc) is not founded\r
+       @exception NET_NFC_OUT_OF_BOUND         the length of IDm is not correct. number of services exceed max value\r
+\r
+*/\r
+\r
+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);\r
+\r
+/**\r
+       Use this command to check whether a card exist\r
+       the Current mode of the card is returned.\r
+\r
+       Mode\r
+\r
+       0x00    Mode0\r
+       0x01    Mode1\r
+       0x02    Mode2\r
+       0x03    Mode3\r
+\r
+       \par Sync (or) Async: Sync\r
+       This is a Asynchronous API\r
+\r
+       @param[in]      handle                                          target handle of detected tag\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception NET_NFC_NULL_PARAMETER       parameter has illigal NULL pointer\r
+       @exception NET_NFC_ALLOC_FAIL   memory allocation is failed\r
+       @exception NET_NFC_NOT_INITIALIZED      Try to operate without initialization\r
+       @exception NET_NFC_BUSY         Device is too busy to handle your request\r
+       @exception NET_NFC_OPERATION_FAIL       Operation is failed because of the internal oal error\r
+       @exception NET_NFC_RF_TIMEOUT   Timeout is raised while communicate with tag\r
+       @exception NET_NFC_NOT_SUPPORTED        you may recieve this error if you request not supported command\r
+       @exception NET_NFC_INVALID_HANDLE       target handle is not valid\r
+       @exception NET_NFC_TAG_READ_FAILED      received chunked data is not valied (damaged data is recieved) or error ack is recieved\r
+       @exception NET_NFC_NO_DATA_FOUND        mendantory tag info (IDm, etc) is not founded\r
+       @exception NET_NFC_OUT_OF_BOUND         the length of IDm is not correct\r
+\r
+*/\r
+\r
+net_nfc_error_e net_nfc_felica_request_response (net_nfc_target_handle_h handle, void* trans_param);\r
+\r
+/**\r
+       Use this command to read block data from a Service that requires no authentification\r
+\r
+       \par Sync (or) Async: Sync\r
+       This is a Asynchronous API\r
+\r
+       @param[in]      handle                                  target handle of detected tag\r
+       @param[in]      number_of_service                       the number of service list to read\r
+       @param[in]      service_list                            specified Service list to read\r
+       @param[in]      number_of_blocks                        the number of blocks to read\r
+       @param[in]      block_list                                      the blocks to read\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception NET_NFC_NULL_PARAMETER       parameter has illigal NULL pointer\r
+       @exception NET_NFC_ALLOC_FAIL   memory allocation is failed\r
+       @exception NET_NFC_NOT_INITIALIZED      Try to operate without initialization\r
+       @exception NET_NFC_BUSY         Device is too busy to handle your request\r
+       @exception NET_NFC_OPERATION_FAIL       Operation is failed because of the internal oal error\r
+       @exception NET_NFC_RF_TIMEOUT   Timeout is raised while communicate with tag\r
+       @exception NET_NFC_NOT_SUPPORTED        you may recieve this error if you request not supported command\r
+       @exception NET_NFC_INVALID_HANDLE       target handle is not valid\r
+       @exception NET_NFC_TAG_READ_FAILED      received chunked data is not valied (damaged data is recieved) or error ack is recieved\r
+       @exception NET_NFC_NO_DATA_FOUND        mendantory tag info (IDm, etc) is not founded\r
+       @exception NET_NFC_OUT_OF_BOUND         the length of IDm is not correct\r
+\r
+*/\r
+\r
+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);\r
+\r
+/**\r
+       Use this command to write block data to a Service that requires no authentification\r
+\r
+       \par Sync (or) Async: Sync\r
+       This is a Asynchronous API\r
+\r
+       @param[in]      handle                                  target handle of detected tag\r
+       @param[in]      number_of_service                       the number of service list to write\r
+       @param[in]      service_list                            specified Service list to write\r
+       @param[in]      number_of_blocks                        the number of blocks to write\r
+       @param[in]      block_list                                      the blocks to write\r
+       @param[in]      data                                            the data to write\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception NET_NFC_NULL_PARAMETER       parameter has illigal NULL pointer\r
+       @exception NET_NFC_ALLOC_FAIL   memory allocation is failed\r
+       @exception NET_NFC_NOT_INITIALIZED      Try to operate without initialization\r
+       @exception NET_NFC_BUSY         Device is too busy to handle your request\r
+       @exception NET_NFC_OPERATION_FAIL       Operation is failed because of the internal oal error\r
+       @exception NET_NFC_RF_TIMEOUT   Timeout is raised while communicate with tag\r
+       @exception NET_NFC_NOT_SUPPORTED        you may recieve this error if you request not supported command\r
+       @exception NET_NFC_INVALID_HANDLE       target handle is not valid\r
+       @exception NET_NFC_TAG_READ_FAILED      received chunked data is not valied (damaged data is recieved) or error ack is recieved\r
+       @exception NET_NFC_NO_DATA_FOUND        mendantory tag info (IDm, etc) is not founded\r
+       @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\r
+\r
+*/\r
+\r
+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);\r
+\r
+/**\r
+       Use this command to acquire system code of the system located on a card\r
+       If a card is divided into mutiple system, this command acquires system code of all the system existing in the card\r
+\r
+       \par Sync (or) Async: Sync\r
+       This is a Asynchronous API\r
+\r
+       @param[in]      handle                                  target handle of detected tag\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception NET_NFC_NULL_PARAMETER       parameter has illigal NULL pointer\r
+       @exception NET_NFC_ALLOC_FAIL   memory allocation is failed\r
+       @exception NET_NFC_NOT_INITIALIZED      Try to operate without initialization\r
+       @exception NET_NFC_BUSY         Device is too busy to handle your request\r
+       @exception NET_NFC_OPERATION_FAIL       Operation is failed because of the internal oal error\r
+       @exception NET_NFC_RF_TIMEOUT   Timeout is raised while communicate with tag\r
+       @exception NET_NFC_NOT_SUPPORTED        you may recieve this error if you request not supported command\r
+       @exception NET_NFC_INVALID_HANDLE       target handle is not valid\r
+       @exception NET_NFC_TAG_READ_FAILED      received chunked data is not valied (damaged data is recieved) or error ack is recieved\r
+       @exception NET_NFC_NO_DATA_FOUND        mendantory tag info (IDm, etc) is not founded\r
+       @exception NET_NFC_OUT_OF_BOUND         the length of IDm is not correct.\r
+\r
+*/\r
+\r
+net_nfc_error_e net_nfc_felica_request_system_code (net_nfc_target_handle_h handle, void* trans_param);\r
+\r
+/**\r
+@} */\r
+\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+\r
+\r
+#endif\r
+\r
diff --git a/src/clientlib/include/net_nfc_tag_jewel.h b/src/clientlib/include/net_nfc_tag_jewel.h
new file mode 100644 (file)
index 0000000..36c611a
--- /dev/null
@@ -0,0 +1,183 @@
+/*\r
+  * Copyright 2012  Samsung Electronics Co., Ltd\r
+  *\r
+  * Licensed under the Flora License, Version 1.0 (the "License");\r
+  * you may not use this file except in compliance with the License.\r
+  * You may obtain a copy of the License at\r
+\r
+  *     http://www.tizenopensource.org/license\r
+  *\r
+  * Unless required by applicable law or agreed to in writing, software\r
+  * distributed under the License is distributed on an "AS IS" BASIS,\r
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+  * See the License for the specific language governing permissions and\r
+  * limitations under the License.\r
+  */\r
+\r
+#ifndef __NET_NFC_TAG_JEWEL_H__\r
+#define __NET_NFC_TAG_JEWEL_H__\r
+\r
+#include "net_nfc_typedef.h"\r
+\r
+\r
+#ifdef __cplusplus\r
+ extern "C" {\r
+#endif\r
+\r
+/**\r
+\r
+@addtogroup NET_NFC_MANAGER_TAG\r
+@{\r
+\r
+       read uid from jewel tag.\r
+\r
+       \par Sync (or) Async: Sync\r
+       This is a Asynchronous API\r
+\r
+       @param[in]      handle          target handle of detected tag\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception NET_NFC_NULL_PARAMETER       parameter has illigal NULL pointer\r
+       @exception NET_NFC_ALLOC_FAIL   memory allocation is failed\r
+       @exception NET_NFC_NOT_INITIALIZED      Try to operate without initialization\r
+       @exception NET_NFC_BUSY         Device is too busy to handle your request\r
+       @exception NET_NFC_OPERATION_FAIL       Operation is failed because of the internal oal error\r
+       @exception NET_NFC_RF_TIMEOUT   Timeout is raised while communicate with tag\r
+       @exception NET_NFC_NOT_SUPPORTED        you may recieve this error if you request not supported command\r
+       @exception NET_NFC_INVALID_HANDLE       target handle is not valid\r
+       @exception NET_NFC_TAG_READ_FAILED      received chunked data is not valied (damaged data is recieved) or error ack is recieved\r
+       @exception NET_NFC_NO_DATA_FOUND        mendantory tag info (UID, etc) is not founded\r
+\r
+*/\r
+\r
+net_nfc_error_e net_nfc_jewel_read_id (net_nfc_target_handle_h handle, void* trans_param);\r
+\r
+/**\r
+       read one byte of specific address .\r
+\r
+       \par Sync (or) Async: Sync\r
+       This is a Asynchronous API\r
+\r
+       @param[in]      handle          target handle of detected tag\r
+       @param[in]      block           block number. (block 0 ~ block E)\r
+       @param[in]      byte                    byte number. Each block has 8 bytes. (byte 0 ~ byte 7)\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception NET_NFC_NULL_PARAMETER       parameter has illigal NULL pointer\r
+       @exception NET_NFC_ALLOC_FAIL   memory allocation is failed\r
+       @exception NET_NFC_NOT_INITIALIZED      Try to operate without initialization\r
+       @exception NET_NFC_BUSY         Device is too busy to handle your request\r
+       @exception NET_NFC_OPERATION_FAIL       Operation is failed because of the internal oal error\r
+       @exception NET_NFC_RF_TIMEOUT   Timeout is raised while communicate with tag\r
+       @exception NET_NFC_NOT_SUPPORTED        you may recieve this error if you request not supported command\r
+       @exception NET_NFC_INVALID_HANDLE       target handle is not valid\r
+       @exception NET_NFC_TAG_READ_FAILED      received chunked data is not valied (damaged data is recieved) or error ack is recieved\r
+       @exception NET_NFC_NO_DATA_FOUND        mendantory tag info (UID, etc) is not founded\r
+\r
+*/\r
+\r
+net_nfc_error_e net_nfc_jewel_read_byte (net_nfc_target_handle_h handle, uint8_t block, uint8_t byte, void* trans_param);\r
+\r
+/**\r
+       read all byte from tag .\r
+\r
+       \par Sync (or) Async: Sync\r
+       This is a Asynchronous API\r
+\r
+       @param[in]      handle          target handle of detected tag\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception NET_NFC_NULL_PARAMETER       parameter has illigal NULL pointer\r
+       @exception NET_NFC_ALLOC_FAIL   memory allocation is failed\r
+       @exception NET_NFC_NOT_INITIALIZED      Try to operate without initialization\r
+       @exception NET_NFC_BUSY         Device is too busy to handle your request\r
+       @exception NET_NFC_OPERATION_FAIL       Operation is failed because of the internal oal error\r
+       @exception NET_NFC_RF_TIMEOUT   Timeout is raised while communicate with tag\r
+       @exception NET_NFC_NOT_SUPPORTED        you may recieve this error if you request not supported command\r
+       @exception NET_NFC_INVALID_HANDLE       target handle is not valid\r
+       @exception NET_NFC_TAG_READ_FAILED      received chunked data is not valied (damaged data is recieved) or error ack is recieved\r
+       @exception NET_NFC_NO_DATA_FOUND        mendantory tag info (UID, etc) is not founded\r
+\r
+*/\r
+\r
+\r
+net_nfc_error_e net_nfc_jewel_read_all (net_nfc_target_handle_h handle, void* trans_param);\r
+\r
+\r
+/**\r
+       operate erase and write cycle . If any of BLOCK-0 to BLOCK-D is locked then write with erase is barred form thoes blocks.\r
+       Additionally 0, D, E blocks are automatically in the lock condition. so write with erase is always barred from thoes blocks.\r
+\r
+       \par Sync (or) Async: Sync\r
+       This is a Asynchronous API\r
+\r
+       @param[in]      handle          target handle of detected tag\r
+       @param[in]      block           block number. (block 0 ~ block E)\r
+       @param[in]      data                    the data to write\r
+       @param[in]      byte                    byte number. Each block has 8 bytes. (byte 0 ~ byte 7)\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception NET_NFC_NULL_PARAMETER       parameter has illigal NULL pointer\r
+       @exception NET_NFC_ALLOC_FAIL   memory allocation is failed\r
+       @exception NET_NFC_NOT_INITIALIZED      Try to operate without initialization\r
+       @exception NET_NFC_BUSY         Device is too busy to handle your request\r
+       @exception NET_NFC_OPERATION_FAIL       Operation is failed because of the internal oal error\r
+       @exception NET_NFC_RF_TIMEOUT   Timeout is raised while communicate with tag\r
+       @exception NET_NFC_NOT_SUPPORTED        you may recieve this error if you request not supported command\r
+       @exception NET_NFC_INVALID_HANDLE       target handle is not valid\r
+       @exception NET_NFC_TAG_WRITE_FAILED     read only tag, or error ack is received from tag\r
+       @exception NET_NFC_NO_DATA_FOUND        mendantory tag info (UID, etc) is not founded\r
+\r
+*/\r
+\r
+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);\r
+\r
+\r
+/**\r
+       operate no erase and write cycle .\r
+\r
+       The WRITE-NE command is available for three main purposes\r
+               - Lock . to set the ï¿½ï¿½lock bit�� for a block\r
+               - 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\r
+               - 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\r
+\r
+       \par Sync (or) Async: Sync\r
+       This is a Asynchronous API\r
+\r
+       @param[in]      handle          target handle of detected tag\r
+       @param[in]      block           block number. (block 0 ~ block E)\r
+       @param[in]      data                    the data to write\r
+       @param[in]      byte                    byte number. Each block has 8 bytes. (byte 0 ~ byte 7)\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception NET_NFC_NULL_PARAMETER       parameter has illigal NULL pointer\r
+       @exception NET_NFC_ALLOC_FAIL   memory allocation is failed\r
+       @exception NET_NFC_NOT_INITIALIZED      Try to operate without initialization\r
+       @exception NET_NFC_BUSY         Device is too busy to handle your request\r
+       @exception NET_NFC_OPERATION_FAIL       Operation is failed because of the internal oal error\r
+       @exception NET_NFC_RF_TIMEOUT   Timeout is raised while communicate with tag\r
+       @exception NET_NFC_NOT_SUPPORTED        you may recieve this error if you request not supported command\r
+       @exception NET_NFC_INVALID_HANDLE       target handle is not valid\r
+       @exception NET_NFC_TAG_WRITE_FAILED     read only tag, or error ack is received from tag\r
+       @exception NET_NFC_NO_DATA_FOUND        mendantory tag info (UID, etc) is not founded\r
+\r
+*/\r
+\r
+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);\r
+\r
+/**\r
+@} */\r
+\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+\r
+\r
+#endif\r
+\r
diff --git a/src/clientlib/include/net_nfc_tag_mifare.h b/src/clientlib/include/net_nfc_tag_mifare.h
new file mode 100644 (file)
index 0000000..df0cbf1
--- /dev/null
@@ -0,0 +1,353 @@
+/*\r
+  * Copyright 2012  Samsung Electronics Co., Ltd\r
+  *\r
+  * Licensed under the Flora License, Version 1.0 (the "License");\r
+  * you may not use this file except in compliance with the License.\r
+  * You may obtain a copy of the License at\r
+\r
+  *     http://www.tizenopensource.org/license\r
+  *\r
+  * Unless required by applicable law or agreed to in writing, software\r
+  * distributed under the License is distributed on an "AS IS" BASIS,\r
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+  * See the License for the specific language governing permissions and\r
+  * limitations under the License.\r
+  */\r
+\r
+#ifndef __NET_NFC_TAG_MIFARE_H__\r
+#define __NET_NFC_TAG_MIFARE_H__\r
+\r
+#include "net_nfc_typedef.h"\r
+\r
+\r
+#ifdef __cplusplus\r
+ extern "C" {\r
+#endif\r
+\r
+/**\r
+\r
+@addtogroup NET_NFC_MANAGER_TAG\r
+@{\r
+       Authenticate a sector with key A. I/O operation. e.g. read / write / increment / decrement will be available after successful authentication.\r
+       This API is only available for MIFARE classic\r
+\r
+       MIFARE CLASSIC MINI\r
+               => 0 ~ 4 : 5 sector and 4 block with 16 bytes\r
+\r
+       MIFARE CLASSIC 1K\r
+               => 0 ~ 15 : 16 sector and 4 block with 16 bytes\r
+\r
+       MIFARE CLASSIC 4K\r
+               => 0 ~ 31 : 32 sector and 4 block with 16 bytes\r
+               => 32 ~ 39 : 8 sector and 16 block with 16 bytes\r
+\r
+       \par Sync (or) Async: Sync\r
+       This is a Asynchronous API\r
+\r
+       @param[in]      handle          target handle of detected tag\r
+       @param[in]      sector          sector to authenticate with key A\r
+       @param[in]      auth_key                6 byte key to authenticate the sector\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception NET_NFC_NULL_PARAMETER       parameter has illigal NULL pointer\r
+       @exception NET_NFC_ALLOC_FAIL   memory allocation is failed\r
+       @exception NET_NFC_NOT_INITIALIZED      Try to operate without initialization\r
+       @exception NET_NFC_BUSY         Device is too busy to handle your request\r
+       @exception NET_NFC_OPERATION_FAIL       Operation is failed because of the internal oal error\r
+       @exception NET_NFC_RF_TIMEOUT   Timeout is raised while communicate with tag\r
+       @exception NET_NFC_NOT_SUPPORTED        you may recieve this error if you request not supported command\r
+       @exception NET_NFC_INVALID_HANDLE       target handle is not valid\r
+       @exception NET_NFC_NO_DATA_FOUND        mendantory tag info (UID, etc) is not founded\r
+\r
+*/\r
+\r
+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);\r
+\r
+/**\r
+       Authenticate a sector with key B. I/O operation. e.g. read / write / increment / decrement will be available after successful authentication.\r
+       This API is only available for MIFARE classic\r
+\r
+       MIFARE CLASSIC MINI\r
+               => 0 ~ 4 : 5 sector and 4 block with 16 bytes\r
+\r
+       MIFARE CLASSIC 1K\r
+               => 0 ~ 15 : 16 sector and 4 block with 16 bytes\r
+\r
+       MIFARE CLASSIC 4K\r
+               => 0 ~ 31 : 32 sector and 4 block with 16 bytes\r
+               => 32 ~ 39 : 8 sector and 16 block with 16 bytes\r
+\r
+       \par Sync (or) Async: Sync\r
+       This is a Asynchronous API\r
+\r
+       @param[in]      handle          target handle of detected tag\r
+       @param[in]      sector          sector to authenticate with key B\r
+       @param[in]      auth_key                6 byte key to authenticate the sector\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception NET_NFC_NULL_PARAMETER       parameter has illigal NULL pointer\r
+       @exception NET_NFC_ALLOC_FAIL   memory allocation is failed\r
+       @exception NET_NFC_NOT_INITIALIZED      Try to operate without initialization\r
+       @exception NET_NFC_BUSY         Device is too busy to handle your request\r
+       @exception NET_NFC_OPERATION_FAIL       Operation is failed because of the internal oal error\r
+       @exception NET_NFC_RF_TIMEOUT   Timeout is raised while communicate with tag\r
+       @exception NET_NFC_NOT_SUPPORTED        you may recieve this error if you request not supported command\r
+       @exception NET_NFC_INVALID_HANDLE       target handle is not valid\r
+       @exception NET_NFC_NO_DATA_FOUND        mendantory tag info (UID, etc) is not founded\r
+\r
+*/\r
+\r
+\r
+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);\r
+\r
+/**\r
+       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)\r
+\r
+       \par Sync (or) Async: Sync\r
+       This is a Asynchronous API\r
+\r
+       @param[in]      handle          target handle of detected tag\r
+       @param[in]      addr                    block or starting page number\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception NET_NFC_NULL_PARAMETER       parameter has illigal NULL pointer\r
+       @exception NET_NFC_ALLOC_FAIL   memory allocation is failed\r
+       @exception NET_NFC_NOT_INITIALIZED      Try to operate without initialization\r
+       @exception NET_NFC_BUSY         Device is too busy to handle your request\r
+       @exception NET_NFC_OPERATION_FAIL       Operation is failed because of the internal oal error\r
+       @exception NET_NFC_RF_TIMEOUT   Timeout is raised while communicate with tag\r
+       @exception NET_NFC_NOT_SUPPORTED        you may recieve this error if you request not supported command\r
+       @exception NET_NFC_INVALID_HANDLE       target handle is not valid\r
+       @exception NET_NFC_TAG_READ_FAILED      received chunked data is not valied (damaged data is recieved) or error ack is recieved\r
+\r
+*/\r
+\r
+net_nfc_error_e net_nfc_mifare_read(net_nfc_target_handle_h handle, uint8_t addr, void* trans_param);\r
+\r
+/**\r
+       write block (16 byte) to addr. Only 4 bytes will be written when tag is ultra light\r
+\r
+       \par Sync (or) Async: Sync\r
+       This is a Asynchronous API\r
+\r
+       @param[in]      handle          target handle of detected tag\r
+       @param[in]      addr                    block or starting page number\r
+       @param[in]      data                    data to write\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception NET_NFC_NULL_PARAMETER       parameter has illigal NULL pointer\r
+       @exception NET_NFC_ALLOC_FAIL   memory allocation is failed\r
+       @exception NET_NFC_NOT_INITIALIZED      Try to operate without initialization\r
+       @exception NET_NFC_BUSY         Device is too busy to handle your request\r
+       @exception NET_NFC_OPERATION_FAIL       Operation is failed because of the internal oal error\r
+       @exception NET_NFC_RF_TIMEOUT   Timeout is raised while communicate with tag\r
+       @exception NET_NFC_NOT_SUPPORTED        you may recieve this error if you request not supported command\r
+       @exception NET_NFC_INVALID_HANDLE       target handle is not valid\r
+       @exception NET_NFC_TAG_WRITE_FAILED     read only tag, or error ack is received from tag\r
+\r
+*/\r
+\r
+\r
+net_nfc_error_e net_nfc_mifare_write_block (net_nfc_target_handle_h handle, uint8_t addr, data_h data, void* trans_param);\r
+\r
+/**\r
+       write page (4 byte) to addr. Only 4 bytes will be written when tag is MIFARE classic\r
+\r
+       \par Sync (or) Async: Sync\r
+       This is a Asynchronous API\r
+\r
+       @param[in]      handle          target handle of detected tag\r
+       @param[in]      addr                    block or starting page number\r
+       @param[in]      data                    data to write\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception NET_NFC_NULL_PARAMETER       parameter has illigal NULL pointer\r
+       @exception NET_NFC_ALLOC_FAIL   memory allocation is failed\r
+       @exception NET_NFC_NOT_INITIALIZED      Try to operate without initialization\r
+       @exception NET_NFC_BUSY         Device is too busy to handle your request\r
+       @exception NET_NFC_OPERATION_FAIL       Operation is failed because of the internal oal error\r
+       @exception NET_NFC_RF_TIMEOUT   Timeout is raised while communicate with tag\r
+       @exception NET_NFC_NOT_SUPPORTED        you may recieve this error if you request not supported command\r
+       @exception NET_NFC_INVALID_HANDLE       target handle is not valid\r
+       @exception NET_NFC_TAG_WRITE_FAILED     read only tag, or error ack is received from tag\r
+\r
+*/\r
+\r
+net_nfc_error_e net_nfc_mifare_write_page (net_nfc_target_handle_h handle, uint8_t addr, data_h data, void* trans_param);\r
+\r
+\r
+/**\r
+       Increase a value block, storing the result in the temporary block on the tag.\r
+       This API is only available for MIFARE classic\r
+\r
+       \par Sync (or) Async: Sync\r
+       This is a Asynchronous API\r
+\r
+       @param[in]      handle          target handle of detected tag\r
+       @param[in]      addr                    block\r
+       @param[in]      value           index of block to increase, starting from 0\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception NET_NFC_NULL_PARAMETER       parameter has illigal NULL pointer\r
+       @exception NET_NFC_ALLOC_FAIL   memory allocation is failed\r
+       @exception NET_NFC_NOT_INITIALIZED      Try to operate without initialization\r
+       @exception NET_NFC_BUSY         Device is too busy to handle your request\r
+       @exception NET_NFC_OPERATION_FAIL       Operation is failed because of the internal oal error\r
+       @exception NET_NFC_RF_TIMEOUT   Timeout is raised while communicate with tag\r
+       @exception NET_NFC_NOT_SUPPORTED        you may recieve this error if you request not supported command\r
+       @exception NET_NFC_INVALID_HANDLE       target handle is not valid\r
+       @exception NET_NFC_TAG_WRITE_FAILED     read only tag, or error ack is received from tag\r
+\r
+*/\r
+\r
+net_nfc_error_e net_nfc_mifare_increment(net_nfc_target_handle_h handle, uint8_t addr, int value, void* trans_param);\r
+\r
+/**\r
+       Decrease a value block, storing the result in the temporary block on the tag.\r
+       This API is only available for MIFARE classic\r
+\r
+       \par Sync (or) Async: Sync\r
+       This is a Asynchronous API\r
+\r
+       @param[in]      handle          target handle of detected tag\r
+       @param[in]      addr                    block\r
+       @param[in]      value           index of block to decrease, starting from 0\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception NET_NFC_NULL_PARAMETER       parameter has illigal NULL pointer\r
+       @exception NET_NFC_ALLOC_FAIL   memory allocation is failed\r
+       @exception NET_NFC_NOT_INITIALIZED      Try to operate without initialization\r
+       @exception NET_NFC_BUSY         Device is too busy to handle your request\r
+       @exception NET_NFC_OPERATION_FAIL       Operation is failed because of the internal oal error\r
+       @exception NET_NFC_RF_TIMEOUT   Timeout is raised while communicate with tag\r
+       @exception NET_NFC_NOT_SUPPORTED        you may recieve this error if you request not supported command\r
+       @exception NET_NFC_INVALID_HANDLE       target handle is not valid\r
+       @exception NET_NFC_TAG_WRITE_FAILED     read only tag, or error ack is received from tag\r
+\r
+*/\r
+\r
+net_nfc_error_e net_nfc_mifare_decrement(net_nfc_target_handle_h handle, uint8_t addr, int value, void* trans_param);\r
+\r
+/**\r
+       Copy from the temporary block to a value block.\r
+       This API is only available for MIFARE classic\r
+\r
+       \par Sync (or) Async: Sync\r
+       This is a Asynchronous API\r
+\r
+       @param[in]      handle          target handle of detected tag\r
+       @param[in]      addr                    block\r
+       @param[in]      value           index of block to decrease, starting from 0\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception NET_NFC_NULL_PARAMETER       parameter has illigal NULL pointer\r
+       @exception NET_NFC_ALLOC_FAIL   memory allocation is failed\r
+       @exception NET_NFC_NOT_INITIALIZED      Try to operate without initialization\r
+       @exception NET_NFC_BUSY         Device is too busy to handle your request\r
+       @exception NET_NFC_OPERATION_FAIL       Operation is failed because of the internal oal error\r
+       @exception NET_NFC_RF_TIMEOUT   Timeout is raised while communicate with tag\r
+       @exception NET_NFC_NOT_SUPPORTED        you may recieve this error if you request not supported command\r
+       @exception NET_NFC_INVALID_HANDLE       target handle is not valid\r
+       @exception NET_NFC_TAG_WRITE_FAILED     read only tag, or error ack is received from tag\r
+\r
+*/\r
+\r
+net_nfc_error_e net_nfc_mifare_transfer(net_nfc_target_handle_h handle, uint8_t addr, void* trans_param);\r
+\r
+/**\r
+       Copy from a value block to the temporary block.\r
+       This API is only available for MIFARE classic\r
+\r
+       \par Sync (or) Async: Sync\r
+       This is a Asynchronous API\r
+\r
+       @param[in]      handle          target handle of detected tag\r
+       @param[in]      addr                    block\r
+       @param[in]      value           index of block to decrease, starting from 0\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception NET_NFC_NULL_PARAMETER       parameter has illigal NULL pointer\r
+       @exception NET_NFC_ALLOC_FAIL   memory allocation is failed\r
+       @exception NET_NFC_NOT_INITIALIZED      Try to operate without initialization\r
+       @exception NET_NFC_BUSY         Device is too busy to handle your request\r
+       @exception NET_NFC_OPERATION_FAIL       Operation is failed because of the internal oal error\r
+       @exception NET_NFC_RF_TIMEOUT   Timeout is raised while communicate with tag\r
+       @exception NET_NFC_NOT_SUPPORTED        you may recieve this error if you request not supported command\r
+       @exception NET_NFC_INVALID_HANDLE       target handle is not valid\r
+       @exception NET_NFC_TAG_WRITE_FAILED     read only tag, or error ack is received from tag\r
+\r
+*/\r
+\r
+net_nfc_error_e net_nfc_mifare_restore(net_nfc_target_handle_h handle, uint8_t addr, void* trans_param);\r
+\r
+/**\r
+       create default factory key. The key is 0xff, 0xff, 0xff, 0xff, 0xff, 0xff\r
+\r
+       \par Sync (or) Async: Sync\r
+       This is a Asynchronous API\r
+\r
+       @param[in]      key                     the handle to create key\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception NET_NFC_NULL_PARAMETER               parameter(s) has(have) illigal NULL pointer(s)\r
+       @exception NET_NFC_ALLOC_FAIL                   memory allocation is failed\r
+\r
+*/\r
+\r
+net_nfc_error_e net_nfc_mifare_create_default_key(data_h* key);\r
+\r
+/**\r
+       create mifare application directory key. The key is 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5\r
+\r
+       \par Sync (or) Async: Sync\r
+       This is a Asynchronous API\r
+\r
+       @param[in]      key                     the handle to create key\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception NET_NFC_NULL_PARAMETER               parameter(s) has(have) illigal NULL pointer(s)\r
+       @exception NET_NFC_ALLOC_FAIL                   memory allocation is failed\r
+\r
+*/\r
+\r
+net_nfc_error_e net_nfc_mifare_create_application_directory_key(data_h* key);\r
+\r
+/**\r
+       create nfc forum key. The key is 0xD3, 0xF7, 0xD3, 0xF7, 0xD3, 0xF7\r
+\r
+       \par Sync (or) Async: Sync\r
+       This is a Asynchronous API\r
+\r
+       @param[in]      key                     the handle to create key\r
+\r
+       @return         return the result of the calling the function\r
+\r
+       @exception NET_NFC_NULL_PARAMETER               parameter(s) has(have) illigal NULL pointer(s)\r
+       @exception NET_NFC_ALLOC_FAIL                   memory allocation is failed\r
+\r
+*/\r
+\r
+net_nfc_error_e net_nfc_mifare_create_net_nfc_forum_key(data_h* key);\r
+\r
+/**\r
+@} */\r
+\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+\r
+\r
+#endif\r
+\r
diff --git a/src/clientlib/include/net_nfc_target_info.h b/src/clientlib/include/net_nfc_target_info.h
new file mode 100644 (file)
index 0000000..18fb5c5
--- /dev/null
@@ -0,0 +1,242 @@
+/*\r
+  * Copyright 2012  Samsung Electronics Co., Ltd\r
+  *\r
+  * Licensed under the Flora License, Version 1.0 (the "License");\r
+  * you may not use this file except in compliance with the License.\r
+  * You may obtain a copy of the License at\r
+\r
+  *     http://www.tizenopensource.org/license\r
+  *\r
+  * Unless required by applicable law or agreed to in writing, software\r
+  * distributed under the License is distributed on an "AS IS" BASIS,\r
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+  * See the License for the specific language governing permissions and\r
+  * limitations under the License.\r
+  */\r
+\r
+#ifndef __NET_NFC_TARGET_INFO_H__\r
+#define __NET_NFC_TARGET_INFO_H__\r
+\r
+#include "net_nfc_typedef.h"\r
+\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+/**\r
+\r
+@addtogroup NET_NFC_MANAGER_INFO\r
+@{\r
+       This document is for the APIs reference document\r
+\r
+        NFC Manager defines are defined in <nfc-typedef.h>\r
+\r
+        These APIs help to get infomation of detected target. these target info handler holds\r
+        - type of target\r
+        - target ID\r
+        - ndef message supporting\r
+        - max data size  (if this tag is ndef message tag)\r
+        - actual data size (if this tag is ndef message tag)\r
+*/\r
+\r
+/**\r
+       type getter from targte info handler\r
+\r
+       \par Sync (or) Async: Sync\r
+       This is a Synchronous API\r
+\r
+       @param[in]      target_info     target info handler\r
+       @param[out]     type                    tag type these type is one of the enum "net_nfc_target_type_e" defined\r
+
+       @return         return the result of calling this functions\r
+\r
+       @exception      NET_NFC_NULL_PARAMETER          parameter(s) has(have) illigal NULL pointer(s)\r
+\r
+*/\r
+\r
+net_nfc_error_e net_nfc_get_tag_type (net_nfc_target_info_h target_info, net_nfc_target_type_e * type);\r
+\r
+/**\r
+       type getter from targte info handler\r
+\r
+       \par Sync (or) Async: Sync\r
+       This is a Synchronous API\r
+\r
+       @param[in]      target_info     target info handler\r
+       @param[out]     handle          target handle  that is generated by nfc-manager\r
+\r
+       @return         return the result of calling this functions\r
+\r
+       @exception      NET_NFC_NULL_PARAMETER          parameter(s) has(have) illigal NULL pointer(s)\r
+\r
+*/\r
+\r
+net_nfc_error_e net_nfc_get_tag_handle(net_nfc_target_info_h target_info, net_nfc_target_handle_h * handle);\r
+\r
+/**\r
+       this API returns the NDEF support boolean value.\r
+       The TRUE value will be returned if the detected target is support NDEF, or return FALSE\r
+\r
+       \par Sync (or) Async: Sync\r
+       This is a Synchronous API\r
+\r
+       @param[in]      target_info     target info handler\r
+       @param[out]     is_support      boolean value of NDEF supporting\r
+\r
+       @return         return the result of calling this functions\r
+\r
+       @exception      NET_NFC_NULL_PARAMETER          parameter(s) has(have) illigal NULL pointer(s)\r
+\r
+*/\r
+\r
+net_nfc_error_e net_nfc_get_tag_ndef_support (net_nfc_target_info_h target_info, bool * is_support);\r
+\r
+/**\r
+       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.\r
+\r
+       \par Sync (or) Async: Sync\r
+       This is a Synchronous API\r
+\r
+       @param[in]      target_info     target info handler\r
+       @param[out]     max_size                max size of NDEF message that can be stored in this detected tag.\r
+\r
+       @return         return the result of calling this functions\r
+\r
+       @exception      NET_NFC_NULL_PARAMETER          parameter(s) has(have) illigal NULL pointer(s)\r
+\r
+*/\r
+\r
+net_nfc_error_e net_nfc_get_tag_max_data_size (net_nfc_target_info_h target_info, uint32_t * max_size);\r
+\r
+/**\r
+       this function return the actual NDEF message size that stored in the tag\r
+\r
+       \par Sync (or) Async: Sync\r
+       This is a Synchronous API\r
+\r
+       @param[in]      target_info             target info handler\r
+       @param[out]     actual_data             the actual NDEF message size that stored in the tag\r
+\r
+       @return         return the result of calling this functions\r
+\r
+       @exception      NET_NFC_NULL_PARAMETER          parameter(s) has(have) illigal NULL pointer(s)\r
+\r
+*/\r
+\r
+net_nfc_error_e net_nfc_get_tag_actual_data_size (net_nfc_target_info_h target_info, uint32_t * actual_data);\r
+\r
+\r
+/**\r
+       this function return keys which will be used to get a tag information\r
+\r
+       \par Sync (or) Async: Sync\r
+       This is a Synchronous API. keys will be freed by user.\r
+\r
+       @param[in]      target_info             target info handler\r
+       @param[out]     keys                    pointer of double array. it will be array of string.\r
+       @param[out]     number_of_keys  length of array.\r
+\r
+       @exception      NET_NFC_NULL_PARAMETER          parameter(s) has(have) illigal NULL pointer(s)\r
+       @exception      NET_NFC_ALLOC_FAIL                      memory allocation is failed\r
+       @exception      NET_NFC_NO_DATA_FOUND           No data is returned\r
+\r
+       @code\r
+       viod    user_cb(net_nfc_message_e message, net_nfc_error_e result, void* data, void* trans_param)\r
+       {\r
+\r
+               switch(message)\r
+               {\r
+                       case NET_NFC_MESSAGE_TAG_DISCOVERED:\r
+                       {\r
+                               if(info != NULL)\r
+                               {\r
+                                       net_nfc_target_info_h target_info = (net_nfc_target_info_h)data;\r
+\r
+                                       char** keys;\r
+                                       int keys_length;\r
+\r
+                                       if(net_nfc_get_tag_info_keys(target_info, &keys, &keys_length) == true)\r
+                                       {\r
+                                               int index = 0;\r
+                                               for(; index < keys_length; index++)\r
+                                               {\r
+                                                       char* key = keys[index];\r
+                                               }\r
+                                       }\r
+\r
+                                       free(keys);\r
+                               }\r
+                       }\r
+               }\r
+\r
+       }\r
+       @endcode\r
+\r
+       @return         return the result of calling this functions\r
+\r
+*/\r
+\r
+net_nfc_error_e net_nfc_get_tag_info_keys(net_nfc_target_info_h target_info, char** keys[], int* number_of_keys);\r
+\r
+/**\r
+       this function return value which is matched key\r
+\r
+       \par Sync (or) Async: Sync\r
+       This is a Synchronous API\r
+\r
+       @param[in]      target_info             target info handler\r
+       @param[in]      key                             key to retrieve\r
+       @param[out]     value                   value which is matched with key\r
+\r
+       viod    user_cb(net_nfc_message_e message, net_nfc_error_e result, void* data, void* trans_param)\r
+       {\r
+\r
+               switch(message)\r
+               {\r
+                       case NET_NFC_MESSAGE_TAG_DISCOVERED:\r
+                       {\r
+                               if(info != NULL)\r
+                               {\r
+                                       net_nfc_target_info_h target_info = (net_nfc_target_info_h)data;\r
+\r
+                                       char** keys;\r
+                                       int keys_length;\r
+\r
+                                       if(net_nfc_get_tag_info_keys(target_info, &keys, &keys_length) == NET_NFC_OK)\r
+                                       {\r
+                                               int index = 0;\r
+                                               for(; index < keys_length; index++)\r
+                                               {\r
+                                                       char* key = keys[index];\r
+                                                       data_h value;\r
+                                                       net_nfc_get_tag_info_value(target_info, key, &value);\r
+                                                       net_nfc_free_data(value);\r
+                                               }\r
+                                       }\r
+                               }\r
+                       }\r
+               }\r
+\r
+       }\r
+\r
+       @return         return the result of calling this functions\r
+\r
+       @exception      NET_NFC_NULL_PARAMETER          parameter(s) has(have) illigal NULL pointer(s)\r
+       @exception      NET_NFC_NO_DATA_FOUND           No data is returned\r
+*/\r
+\r
+net_nfc_error_e net_nfc_get_tag_info_value(net_nfc_target_info_h target_info, const char* key, data_h* value);\r
+\r
+\r
+/**\r
+@} */\r
+\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+\r
+\r
+#endif\r
+\r
+\r
diff --git a/src/clientlib/net_nfc_client_data.c b/src/clientlib/net_nfc_client_data.c
new file mode 100644 (file)
index 0000000..58df115
--- /dev/null
@@ -0,0 +1,146 @@
+/*\r
+  * Copyright 2012  Samsung Electronics Co., Ltd\r
+  *\r
+  * Licensed under the Flora License, Version 1.0 (the "License");\r
+  * you may not use this file except in compliance with the License.\r
+  * You may obtain a copy of the License at\r
+\r
+  *     http://www.tizenopensource.org/license\r
+  *\r
+  * Unless required by applicable law or agreed to in writing, software\r
+  * distributed under the License is distributed on an "AS IS" BASIS,\r
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+  * See the License for the specific language governing permissions and\r
+  * limitations under the License.\r
+  */\r
+\r
+#include "net_nfc_data.h"\r
+#include "net_nfc_typedef_private.h"\r
+#include "net_nfc_util_private.h"\r
+#include "net_nfc_client_util_private.h"\r
+\r
+#include <string.h>\r
+\r
+#ifndef NET_NFC_EXPORT_API\r
+#define NET_NFC_EXPORT_API __attribute__((visibility("default")))\r
+#endif\r
+\r
+NET_NFC_EXPORT_API net_nfc_error_e net_nfc_create_data_only (data_h* data)\r
+{\r
+       return net_nfc_create_data (data, NULL, 0);\r
+}\r
+\r
+\r
+NET_NFC_EXPORT_API net_nfc_error_e net_nfc_create_data (data_h* data, const uint8_t* bytes, const uint32_t length)\r
+{\r
+       if (data == NULL) {\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+       data_s ** data_private = (data_s**)data;\r
+\r
+       _net_nfc_client_util_alloc_mem (*data_private,sizeof (data_s));\r
+\r
+       if (*data_private == NULL) return NET_NFC_ALLOC_FAIL;\r
+\r
+       if (length <= 0){\r
+               return NET_NFC_OK;\r
+       }\r
+\r
+       _net_nfc_client_util_alloc_mem ((*data_private)->buffer, length);\r
+       if ((*data_private)->buffer == NULL )return NET_NFC_ALLOC_FAIL;\r
+\r
+       if (bytes != NULL){\r
+               memcpy ((*data_private)->buffer, bytes, length);\r
+       }\r
+       (*data_private)->length = length;\r
+\r
+\r
+       return NET_NFC_OK;\r
+}\r
+\r
+NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_data (const data_h data, uint8_t** bytes, uint32_t * length)\r
+{\r
+       if (data == NULL) {\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+       data_s * data_private = (data_s *) data;\r
+\r
+       *bytes = data_private->buffer;\r
+       *length = data_private->length;\r
+\r
+       return NET_NFC_OK;\r
+}\r
+\r
+NET_NFC_EXPORT_API net_nfc_error_e net_nfc_set_data (const data_h data, const uint8_t* bytes, const uint32_t length)\r
+{\r
+       if (data == NULL) {\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+       data_s * data_private = (data_s *) data;\r
+\r
+       if (data_private->buffer == bytes && data_private->length == length){\r
+               return NET_NFC_OK;\r
+       }\r
+\r
+       if (data_private->buffer != NULL) {\r
+               _net_nfc_client_util_free_mem (data_private->buffer);\r
+       }\r
+\r
+       if (length <=0)\r
+       {\r
+               data_private->buffer = NULL;\r
+               data_private->length = 0;\r
+               return NET_NFC_OK;\r
+       }\r
+\r
+       if (length > 0){\r
+               _net_nfc_client_util_alloc_mem ((data_private)->buffer, length);\r
+       }\r
+\r
+       if (bytes != NULL) {\r
+               memcpy (data_private->buffer, bytes, length);\r
+       }\r
+\r
+       data_private->length = length;\r
+\r
+       return NET_NFC_OK;\r
+}\r
+\r
+NET_NFC_EXPORT_API uint32_t net_nfc_get_data_length (const data_h data)\r
+{\r
+       if (data == NULL){\r
+               return 0;\r
+       }\r
+       data_s * data_private = (data_s *) data;\r
+\r
+       return data_private->length;\r
+}\r
+\r
+NET_NFC_EXPORT_API uint8_t * net_nfc_get_data_buffer (const data_h data)\r
+{\r
+       if (data == NULL){\r
+               return NULL;\r
+       }\r
+       data_s * data_private = (data_s *) data;\r
+\r
+       return data_private->buffer;\r
+}\r
+\r
+\r
+NET_NFC_EXPORT_API net_nfc_error_e net_nfc_free_data (data_h data)\r
+{\r
+       if (data == NULL){\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+       data_s * data_private = (data_s *) data;\r
+\r
+       if (data_private->buffer != NULL) {\r
+                       _net_nfc_client_util_free_mem (data_private->buffer);\r
+       }\r
+       _net_nfc_client_util_free_mem (data_private);\r
+\r
+       return NET_NFC_OK;\r
+}\r
+\r
+\r
+\r
diff --git a/src/clientlib/net_nfc_client_dispatcher.c b/src/clientlib/net_nfc_client_dispatcher.c
new file mode 100644 (file)
index 0000000..85557fb
--- /dev/null
@@ -0,0 +1,935 @@
+/*
+  * Copyright 2012  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://www.tizenopensource.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 <stdio.h>
+#include <glib.h>
+
+#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"
+#include "net_nfc_client_util_private.h"
+
+#include "Ecore.h"
+
+
+
+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);
+
+extern unsigned int socket_handle ;
+
+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_client_util_free_mem (info->keylist);
+               }
+
+               _net_nfc_client_util_free_mem(context->target_info);
+               context->target_info = NULL;
+
+       }
+}
+#endif
+
+void net_nfc_client_call_dispatcher_in_ecore_main_loop(net_nfc_response_cb client_cb, net_nfc_response_msg_t* msg)
+{
+       DEBUG_CLIENT_MSG("put message to ecore main loop");
+
+       client_dispatcher_param_t* param = calloc(1, 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()) ;
+               }
+       }
+}
+
+void net_nfc_client_call_dispatcher_in_g_main_loop(net_nfc_response_cb client_cb, net_nfc_response_msg_t* msg)
+{
+       DEBUG_CLIENT_MSG("put message to g main loop");
+
+       client_dispatcher_param_t* param = calloc(1, 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()) ;
+               }
+
+       }
+}
+
+void net_nfc_client_call_dispatcher_in_current_context(net_nfc_response_cb client_cb, net_nfc_response_msg_t* msg)
+{
+       DEBUG_CLIENT_MSG("put message to g main loop");
+
+       client_dispatcher_param_t* param = calloc(1, sizeof(client_dispatcher_param_t));
+
+       if(param != NULL)       {
+
+               param->client_cb = client_cb;
+               param->msg = msg;
+
+               net_nfc_client_dispatch_response(param);
+
+       }
+}
+
+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;
+
+       free(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_OPEN_INTERNAL_SE:
+               {
+                       DEBUG_CLIENT_MSG("handle = [0x%x]", ((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);
+                               net_nfc_util_free_ndef_message(ndef);
+                       }
+                       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);
+                       }
+
+               }
+               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_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;
+
+                       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(detected->devType >= NET_NFC_ISO14443_A_PICC && detected->devType <= NET_NFC_MIFARE_DESFIRE_PICC){
+                               converted = NET_NFC_ISO14443A_ENABLE;
+                       }
+                       else if(detected->devType >= NET_NFC_ISO14443_B_PICC && detected->devType <= NET_NFC_ISO14443_BPRIME_PICC){
+                               converted = NET_NFC_ISO14443B_ENABLE;
+                       }
+                       else if(detected->devType == NET_NFC_FELICA_PICC){
+                               converted = NET_NFC_FELICA_ENABLE;
+                       }
+                       else if (detected->devType == NET_NFC_JEWEL_PICC){
+                               converted = NET_NFC_FELICA_ENABLE;
+                       }
+                       else if(detected->devType == NET_NFC_ISO15693_PICC){
+                               converted = NET_NFC_ISO15693_ENABLE;
+                       }
+
+                       if ((converted & current_filter) == 0 ){
+                               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;
+                       if((info = calloc(1, sizeof(net_nfc_target_info_s))) == NULL){
+                               DEBUG_CLIENT_MSG("mem alloc is failed");
+                               _net_nfc_client_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);
+
+                       /* free net_nfc_tag_info_s* 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++;
+                               }
+
+                               free(temp);
+                       }
+                       if (info.keylist != NULL){
+                               _net_nfc_client_util_free_mem (info.keylist);
+                       }
+#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_OK)
+                       {
+                               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(detected->devType >= NET_NFC_ISO14443_A_PICC && detected->devType <= NET_NFC_MIFARE_DESFIRE_PICC){
+                                       converted = NET_NFC_ISO14443A_ENABLE;
+                               }
+                               else if(detected->devType >= NET_NFC_ISO14443_B_PICC && detected->devType <= NET_NFC_ISO14443_BPRIME_PICC){
+                                       converted = NET_NFC_ISO14443B_ENABLE;
+                               }
+                               else if(detected->devType == NET_NFC_FELICA_PICC){
+                                       converted = NET_NFC_FELICA_ENABLE;
+                               }
+                               else if (detected->devType == NET_NFC_JEWEL_PICC){
+                                       converted = NET_NFC_FELICA_ENABLE;
+                               }
+                               else if(detected->devType == NET_NFC_ISO15693_PICC){
+                                       converted = NET_NFC_ISO15693_ENABLE;
+                               }
+
+                               if ((converted & current_filter) == 0 ){
+                                       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;
+                               if((info = calloc(1, sizeof(net_nfc_target_info_s))) == NULL){
+                                       DEBUG_CLIENT_MSG("mem alloc is failed");
+                                       _net_nfc_client_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);
+
+                               /* free net_nfc_tag_info_s* 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++;
+                                       }
+
+                                       free(temp);
+                               }
+                               if (info.keylist != NULL){
+                                       _net_nfc_client_util_free_mem (info.keylist);
+                               }
+#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;
+
+                       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(detached->devType >= NET_NFC_ISO14443_A_PICC && detached->devType <= NET_NFC_MIFARE_DESFIRE_PICC){
+                               converted = NET_NFC_ISO14443A_ENABLE;
+                       }
+                       else if(detached->devType >= NET_NFC_ISO14443_B_PICC && detached->devType <= NET_NFC_ISO14443_BPRIME_PICC){
+                               converted = NET_NFC_ISO14443B_ENABLE;
+                       }
+                       else if(detached->devType == NET_NFC_FELICA_PICC){
+                               converted = NET_NFC_FELICA_ENABLE;
+                       }
+                       else if (detached->devType == NET_NFC_JEWEL_PICC){
+                               converted = NET_NFC_FELICA_ENABLE;
+                       }
+                       else if(detached->devType == NET_NFC_ISO15693_PICC){
+                               converted = NET_NFC_ISO15693_ENABLE;
+                       }
+
+                       if ((converted & current_filter) == 0 ){
+                               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;
+
+                       memset(&info, 0x00, sizeof(net_nfc_se_event_info_s));
+
+                       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 ("BJDEBUG: 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_client_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_client_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 = NULL;
+
+                               _net_nfc_client_util_alloc_mem(info, sizeof(net_nfc_connection_handover_info_s));
+                               if (info == NULL)
+                               {
+                                       DEBUG_ERR_MSG("mem alloc is failed");
+                                       break;
+                               }
+
+                               info->type = detail_msg->type;
+                               info->data.length = detail_msg->data.length;
+                               if (info->data.length > 0)
+                               {
+                                       _net_nfc_client_util_alloc_mem(info->data.buffer, info->data.length);
+                                       if (info->data.buffer == NULL)
+                                       {
+                                               DEBUG_ERR_MSG("mem alloc is failed");
+                                               _net_nfc_client_util_free_mem(info);
+                                               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);
+                       }
+               }
+               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_client_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)
+{
+       if(list == NULL)
+               return NET_NFC_NULL_PARAMETER;
+
+       net_nfc_tag_info_s* temp_list = (net_nfc_tag_info_s *)calloc(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 = (char *)calloc(1, 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] \n", 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 100644 (file)
index 0000000..1b599eb
--- /dev/null
@@ -0,0 +1,255 @@
+/*\r
+  * Copyright 2012  Samsung Electronics Co., Ltd\r
+  *\r
+  * Licensed under the Flora License, Version 1.0 (the "License");\r
+  * you may not use this file except in compliance with the License.\r
+  * You may obtain a copy of the License at\r
+\r
+  *     http://www.tizenopensource.org/license\r
+  *\r
+  * Unless required by applicable law or agreed to in writing, software\r
+  * distributed under the License is distributed on an "AS IS" BASIS,\r
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+  * See the License for the specific language governing permissions and\r
+  * limitations under the License.\r
+  */\r
+\r
+#include "net_nfc_exchanger.h"\r
+#include "net_nfc_exchanger_private.h"\r
+#include "net_nfc.h"\r
+#include "net_nfc_typedef.h"\r
+#include "net_nfc_typedef_private.h"\r
+#include "net_nfc_util_private.h"\r
+#include "net_nfc_debug_private.h"\r
+#include "net_nfc_client_ipc_private.h"\r
+#include "net_nfc_client_nfc_private.h"\r
+#include "net_nfc_client_util_private.h"\r
+\r
+#include <pthread.h>\r
+\r
+static net_nfc_exchanger_cb exchanger_cb = NULL;\r
+\r
+#ifndef NET_NFC_EXPORT_API\r
+#define NET_NFC_EXPORT_API __attribute__((visibility("default")))\r
+#endif\r
+\r
+NET_NFC_EXPORT_API net_nfc_error_e net_nfc_create_exchanger_data(net_nfc_exchanger_data_h *ex_data, data_h payload)\r
+{\r
+       net_nfc_exchanger_data_s* tmp_ex_data = NULL;\r
+\r
+       if (ex_data == NULL || payload == NULL)\r
+       {\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+\r
+       _net_nfc_client_util_alloc_mem(tmp_ex_data, sizeof(net_nfc_exchanger_data_s));\r
+       if (tmp_ex_data == NULL)\r
+       {\r
+               return NET_NFC_ALLOC_FAIL;\r
+       }\r
+\r
+       tmp_ex_data->type = NET_NFC_EXCHANGER_RAW;\r
+\r
+       _net_nfc_client_util_alloc_mem(tmp_ex_data->binary_data.buffer, ((data_s *)payload)->length);\r
+       if (tmp_ex_data->binary_data.buffer == NULL)\r
+       {\r
+               _net_nfc_client_util_free_mem(tmp_ex_data);\r
+\r
+               return NET_NFC_ALLOC_FAIL;\r
+       }\r
+\r
+       memcpy(tmp_ex_data->binary_data.buffer, ((data_s *)payload)->buffer, ((data_s *)payload)->length);\r
+\r
+       tmp_ex_data->binary_data.length = ((data_s *)payload)->length;\r
+\r
+       *ex_data = (net_nfc_exchanger_data_h)tmp_ex_data;\r
+\r
+       return NET_NFC_OK;\r
+}\r
+\r
+NET_NFC_EXPORT_API net_nfc_error_e net_nfc_free_exchanger_data(net_nfc_exchanger_data_h ex_data)\r
+{\r
+       if (ex_data == NULL)\r
+       {\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+\r
+       if (((net_nfc_exchanger_data_s *)ex_data)->binary_data.buffer != NULL)\r
+       {\r
+               _net_nfc_client_util_free_mem(((net_nfc_exchanger_data_s *)ex_data)->binary_data.buffer);\r
+       }\r
+\r
+       _net_nfc_client_util_free_mem(ex_data);\r
+\r
+       return NET_NFC_OK;\r
+}\r
+\r
+NET_NFC_EXPORT_API net_nfc_error_e net_nfc_set_exchanger_cb(net_nfc_exchanger_cb callback, void * user_param)\r
+{\r
+       client_context_t* client_context = net_nfc_get_client_context();\r
+\r
+       pthread_mutex_lock(&(client_context->g_client_lock));\r
+\r
+       if (client_context->initialized == true && exchanger_cb == NULL)\r
+       {\r
+               /* client is master mode */\r
+               pthread_mutex_unlock(&(client_context->g_client_lock));\r
+               return NET_NFC_NOT_ALLOWED_OPERATION;\r
+       }\r
+       else if (client_context->initialized == true && exchanger_cb != NULL)\r
+       {\r
+               /* just change callback and user_param value */\r
+               exchanger_cb = callback;\r
+               client_context->register_user_param = user_param;\r
+               pthread_mutex_unlock(&(client_context->g_client_lock));\r
+               return NET_NFC_OK;\r
+       }\r
+       else\r
+       {\r
+               pthread_mutex_unlock(&(client_context->g_client_lock));\r
+\r
+               if (net_nfc_initialize() == NET_NFC_OK)\r
+               {\r
+                       if (net_nfc_state_activate(NET_NFC_CLIENT_TYPE_LISTENER) == NET_NFC_OK)\r
+                       {\r
+                               pthread_mutex_lock(&(client_context->g_client_lock));\r
+                               exchanger_cb = callback;\r
+                               client_context->register_user_param = user_param;\r
+                               pthread_mutex_unlock(&(client_context->g_client_lock));\r
+\r
+                               return NET_NFC_OK;\r
+                       }\r
+               }\r
+       }\r
+\r
+       return NET_NFC_NOT_ALLOWED_OPERATION;\r
+}\r
+\r
+net_nfc_exchanger_cb net_nfc_get_exchanger_cb()\r
+{\r
+       return exchanger_cb;\r
+}\r
+\r
+NET_NFC_EXPORT_API net_nfc_error_e net_nfc_unset_exchanger_cb()\r
+{\r
+       if (exchanger_cb == NULL)\r
+       {\r
+               return NET_NFC_NOT_REGISTERED;\r
+       }\r
+\r
+       net_nfc_state_deactivate();\r
+       net_nfc_deinitialize();\r
+\r
+       exchanger_cb = NULL;\r
+\r
+       return NET_NFC_OK;\r
+}\r
+\r
+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)\r
+{\r
+       net_nfc_error_e ret;\r
+       net_nfc_request_p2p_send_t *request = NULL;\r
+       uint32_t length = 0;\r
+       net_nfc_exchanger_data_s *ex_data = (net_nfc_exchanger_data_s *)ex_handle;\r
+\r
+       DEBUG_CLIENT_MSG("send reqeust :: exchanger data = [%x] target_handle = [%x]", ex_handle, target_handle);\r
+\r
+       length = sizeof(net_nfc_request_p2p_send_t) + ex_data->binary_data.length;\r
+\r
+       _net_nfc_client_util_alloc_mem(request, length);\r
+       if (request == NULL)\r
+       {\r
+               return NET_NFC_ALLOC_FAIL;\r
+       }\r
+\r
+       request->length = length;\r
+       request->request_type = NET_NFC_MESSAGE_P2P_SEND;\r
+       request->handle = (net_nfc_target_handle_s *)target_handle;\r
+       request->data_type = ex_data->type;\r
+       request->data.length = ex_data->binary_data.length;\r
+\r
+       memcpy(&request->data.buffer, ex_data->binary_data.buffer, request->data.length);\r
+\r
+       ret = _net_nfc_client_send_reqeust((net_nfc_request_msg_t *)request, NULL);\r
+\r
+       _net_nfc_client_util_free_mem(request);\r
+\r
+       return ret;\r
+}\r
+\r
+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)\r
+{\r
+       net_nfc_error_e ret = NET_NFC_UNKNOWN_ERROR;\r
+       net_nfc_request_connection_handover_t *request = NULL;\r
+       uint32_t length = 0;\r
+\r
+       if (target_handle == NULL)\r
+       {\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+\r
+       length = sizeof(net_nfc_request_p2p_send_t);\r
+\r
+       _net_nfc_client_util_alloc_mem(request, length);\r
+       if (request == NULL)\r
+       {\r
+               return NET_NFC_ALLOC_FAIL;\r
+       }\r
+\r
+       request->length = length;\r
+       request->request_type = NET_NFC_MESSAGE_CONNECTION_HANDOVER;\r
+       request->handle = (net_nfc_target_handle_s *)target_handle;\r
+       request->type = type;\r
+\r
+       ret = _net_nfc_client_send_reqeust((net_nfc_request_msg_t *)request, NULL);\r
+\r
+       _net_nfc_client_util_free_mem(request);\r
+\r
+       return ret;\r
+}\r
+\r
+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)\r
+{\r
+       net_nfc_connection_handover_info_s *info = NULL;\r
+\r
+       if (info_handle == NULL || type == NULL)\r
+               return NET_NFC_NULL_PARAMETER;\r
+\r
+       info = (net_nfc_connection_handover_info_s *)info_handle;\r
+\r
+       *type = info->type;\r
+\r
+       return NET_NFC_OK;\r
+}\r
+\r
+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)\r
+{\r
+       net_nfc_error_e result = NET_NFC_UNKNOWN_ERROR;\r
+       net_nfc_connection_handover_info_s *info = NULL;\r
+\r
+       if (info_handle == NULL || data == NULL)\r
+               return NET_NFC_NULL_PARAMETER;\r
+\r
+       info = (net_nfc_connection_handover_info_s *)info_handle;\r
+\r
+       result = net_nfc_create_data(data, info->data.buffer, info->data.length);\r
+\r
+       return result;\r
+}\r
+\r
+NET_NFC_EXPORT_API net_nfc_error_e net_nfc_exchanger_free_alternative_carrier_data(net_nfc_connection_handover_info_h  info_handle)\r
+{\r
+       net_nfc_error_e result = NET_NFC_UNKNOWN_ERROR;\r
+\r
+       if (info_handle == NULL)\r
+               return NET_NFC_NULL_PARAMETER;\r
+\r
+       if (((net_nfc_connection_handover_info_s *)info_handle)->data.buffer != NULL)\r
+       {\r
+               _net_nfc_client_util_free_mem(((net_nfc_connection_handover_info_s *)info_handle)->data.buffer);\r
+       }\r
+\r
+       _net_nfc_client_util_free_mem(info_handle);\r
+\r
+       return result;\r
+}\r
diff --git a/src/clientlib/net_nfc_client_internal_se.c b/src/clientlib/net_nfc_client_internal_se.c
new file mode 100644 (file)
index 0000000..601e2dd
--- /dev/null
@@ -0,0 +1,140 @@
+/*\r
+  * Copyright 2012  Samsung Electronics Co., Ltd\r
+  *\r
+  * Licensed under the Flora License, Version 1.0 (the "License");\r
+  * you may not use this file except in compliance with the License.\r
+  * You may obtain a copy of the License at\r
+\r
+  *     http://www.tizenopensource.org/license\r
+  *\r
+  * Unless required by applicable law or agreed to in writing, software\r
+  * distributed under the License is distributed on an "AS IS" BASIS,\r
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+  * See the License for the specific language governing permissions and\r
+  * limitations under the License.\r
+  */\r
+\r
+#include "net_nfc_tag.h"\r
+#include "net_nfc_typedef_private.h"\r
+#include "net_nfc_client_ipc_private.h"\r
+#include "net_nfc_debug_private.h"\r
+#include "net_nfc_util_private.h"\r
+#include "net_nfc_client_nfc_private.h"\r
+#include "net_nfc_client_util_private.h"\r
+\r
+#include <string.h>\r
+#include <pthread.h>\r
+\r
+#ifndef NET_NFC_EXPORT_API\r
+#define NET_NFC_EXPORT_API __attribute__((visibility("default")))\r
+#endif\r
+\r
+NET_NFC_EXPORT_API net_nfc_error_e net_nfc_set_secure_element_type(net_nfc_se_type_e se_type, void* trans_param)\r
+{\r
+       net_nfc_error_e ret;\r
+       net_nfc_request_set_se_t request = { 0, };\r
+\r
+       if (se_type < NET_NFC_SE_TYPE_NONE || se_type > NET_NFC_SE_TYPE_UICC)\r
+       {\r
+               return NET_NFC_INVALID_PARAM;\r
+       }\r
+\r
+       request.length = sizeof(net_nfc_request_set_se_t);\r
+       request.request_type = NET_NFC_MESSAGE_SET_SE;\r
+       request.se_type = se_type;\r
+       request.trans_param = trans_param;\r
+\r
+       ret = _net_nfc_client_send_reqeust((net_nfc_request_msg_t *)&request, NULL);\r
+\r
+       return ret;\r
+}\r
+\r
+NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_secure_element_type(void* trans_param)\r
+{\r
+       net_nfc_error_e ret;\r
+       net_nfc_request_get_se_t request = { 0, };\r
+\r
+       request.length = sizeof(net_nfc_request_get_se_t);\r
+       request.request_type = NET_NFC_MESSAGE_GET_SE;\r
+       request.trans_param = trans_param;\r
+\r
+       ret = _net_nfc_client_send_reqeust((net_nfc_request_msg_t *)&request, NULL);\r
+\r
+       return ret;\r
+}\r
+\r
+NET_NFC_EXPORT_API net_nfc_error_e net_nfc_open_internal_secure_element(net_nfc_se_type_e se_type, void* trans_param)\r
+{\r
+       net_nfc_error_e ret;\r
+       net_nfc_request_open_internal_se_t request = { 0, };\r
+\r
+       if (se_type < NET_NFC_SE_TYPE_NONE || se_type > NET_NFC_SE_TYPE_UICC)\r
+       {\r
+               return NET_NFC_INVALID_PARAM;\r
+       }\r
+\r
+       request.length = sizeof(net_nfc_request_open_internal_se_t);\r
+       request.request_type = NET_NFC_MESSAGE_OPEN_INTERNAL_SE;\r
+       request.se_type = se_type;\r
+       request.trans_param = trans_param;\r
+\r
+       ret = _net_nfc_client_send_reqeust((net_nfc_request_msg_t *)&request, NULL);\r
+\r
+       return ret;\r
+}\r
+\r
+NET_NFC_EXPORT_API net_nfc_error_e net_nfc_close_internal_secure_element(net_nfc_target_handle_h handle, void *trans_param)\r
+{\r
+       net_nfc_error_e ret;\r
+       net_nfc_request_close_internal_se_t request = { 0, };\r
+\r
+       if (handle == NULL)\r
+       {\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+\r
+       request.length = sizeof(net_nfc_request_close_internal_se_t);\r
+       request.request_type = NET_NFC_MESSAGE_CLOSE_INTERNAL_SE;\r
+       request.handle = (net_nfc_target_handle_s *)handle;\r
+       request.trans_param = trans_param;\r
+\r
+       ret = _net_nfc_client_send_reqeust((net_nfc_request_msg_t *)&request, NULL);\r
+\r
+       return ret;\r
+}\r
+\r
+NET_NFC_EXPORT_API net_nfc_error_e net_nfc_send_apdu(net_nfc_target_handle_h handle, data_h apdu, void* trans_param)\r
+{\r
+       net_nfc_error_e ret;\r
+       net_nfc_request_send_apdu_t *request = NULL;\r
+       uint32_t length = 0;\r
+       data_s *apdu_data = (data_s *)apdu;\r
+\r
+       if (handle == NULL || apdu_data == NULL || apdu_data->buffer == NULL || apdu_data->length == 0)\r
+       {\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+\r
+       length = sizeof(net_nfc_request_send_apdu_t) + apdu_data->length;\r
+\r
+       _net_nfc_client_util_alloc_mem(request, length);\r
+       if (request == NULL)\r
+       {\r
+               return NET_NFC_ALLOC_FAIL;\r
+       }\r
+\r
+       request->length = length;\r
+       request->request_type = NET_NFC_MESSAGE_SEND_APDU_SE;\r
+       request->handle = (net_nfc_target_handle_s *)handle;\r
+       request->trans_param = trans_param;\r
+\r
+       request->data.length = apdu_data->length;\r
+       memcpy(&request->data.buffer, apdu_data->buffer, request->data.length);\r
+\r
+       ret = _net_nfc_client_send_reqeust((net_nfc_request_msg_t *)request, NULL);\r
+\r
+       _net_nfc_client_util_free_mem(request);\r
+\r
+       return ret;\r
+}\r
+\r
diff --git a/src/clientlib/net_nfc_client_ipc.c b/src/clientlib/net_nfc_client_ipc.c
new file mode 100644 (file)
index 0000000..97b8d60
--- /dev/null
@@ -0,0 +1,1511 @@
+/*
+  * Copyright 2012  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://www.tizenopensource.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 <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <sys/un.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <sys/epoll.h>
+#include <unistd.h>
+#include <string.h>
+#include <stdlib.h>
+#include <pthread.h>
+#include <errno.h>
+#include <sys/time.h>
+#include <stdarg.h>
+#include <signal.h>
+#include <glib-object.h>
+
+#include "net_nfc_typedef_private.h"
+#include "net_nfc_client_ipc_private.h"
+#include "net_nfc_client_dispatcher_private.h"
+#include "net_nfc_util_private.h"
+#include "net_nfc_debug_private.h"
+#include "net_nfc_client_util_private.h"
+
+/* static variable */
+static int g_client_sock_fd = -1;
+
+static pthread_mutex_t g_client_lock = PTHREAD_MUTEX_INITIALIZER;
+static pthread_mutex_t cb_lock = PTHREAD_MUTEX_INITIALIZER;
+
+
+#ifndef NET_NFC_SERVER_ADDRESS
+#define NET_NFC_SERVER_ADDRESS "127.0.0.1"
+#endif
+
+#ifndef NET_NFC_SERVER_PORT
+#define NET_NFC_SERVER_PORT 3000
+#endif
+
+#ifndef NET_NFC_SERVER_DOMAIN
+#define NET_NFC_SERVER_DOMAIN "/tmp/nfc-manager-server-domain"
+#endif
+
+#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_events = NULL;
+#else
+static fd_set fdset_read;
+#endif
+
+static pthread_t g_poll_thread = (pthread_t)0;
+
+#endif
+
+/////////////////////
+
+static net_nfc_response_cb client_cb = NULL;
+bool being_cb_called = false;
+
+
+
+/* static function */
+static net_nfc_response_msg_t* net_nfc_client_read_response_msg(net_nfc_error_e* result);
+static void net_nfc_client_set_non_block_socket(int socket);
+
+#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
+
+
+static void net_nfc_client_set_non_block_socket(int socket)
+{
+       DEBUG_CLIENT_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");
+
+       }
+}
+
+/////////////////////
+
+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;
+       }
+}
+
+net_nfc_error_e net_nfc_client_socket_initialize()
+{
+       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));
+
+       pthread_mutex_lock(&g_client_lock);
+
+       g_client_sock_fd = socket(AF_UNIX, SOCK_STREAM, 0);
+
+       if(g_client_sock_fd == -1)
+       {
+               DEBUG_ERR_MSG("get socket is failed \n");
+               pthread_mutex_unlock(&g_client_lock);
+               return NET_NFC_IPC_FAIL;
+       }
+
+       DEBUG_CLIENT_MSG("socket is created");
+
+       net_nfc_client_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 \n");
+               pthread_mutex_unlock(&g_client_lock);
+               return NET_NFC_IPC_FAIL;
+       }
+
+       DEBUG_CLIENT_MSG("socket is created");
+
+       net_nfc_client_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 \n");
+                       result = NET_NFC_IPC_FAIL;
+                       goto ERROR;
+               }
+       }
+       else
+       {
+               DEBUG_ERR_MSG(" g_io_channel_unix_new is failed \n");
+               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;
+       }
+
+       if((g_client_poll_events = (struct epoll_event *)calloc(1, sizeof(struct epoll_event) * EPOLL_SIZE)) == NULL)
+       {
+               DEBUG_ERR_MSG("error is occured");
+               result = NET_NFC_ALLOC_FAIL;
+               goto ERROR;
+       }
+
+       struct epoll_event ev;
+
+       ev.events = EPOLLIN | EPOLLET | EPOLLHUP | EPOLLERR;
+       ev.data.fd = g_client_sock_fd;
+
+       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;
+       }
+
+#ifdef NET_NFC_USE_SIGTERM
+       pthread_cond_wait (&pcond, &g_client_lock);
+#endif
+
+       DEBUG_CLIENT_MSG("start ipc thread = [%x]", (uint32_t )g_poll_thread);
+
+       //////////////////////////////////
+
+       pthread_attr_destroy(&thread_attr);
+
+#endif // #ifdef G_MAIN_LOOP
+
+       pthread_mutex_unlock(&g_client_lock);
+
+       return NET_NFC_OK;
+
+ERROR:
+
+
+       DEBUG_ERR_MSG("error while initializing client ipc");
+
+       if(g_client_sock_fd != -1)
+       {
+               shutdown(g_client_sock_fd, SHUT_RDWR);
+               close(g_client_sock_fd);
+       }
+
+#ifdef G_MAIN_LOOP
+
+       if(g_client_channel != NULL)
+               g_io_channel_unref(g_client_channel);
+
+       if(g_client_src_id != 0)
+               g_source_remove(g_client_src_id);
+
+#else
+
+#ifdef USE_IPC_EPOLL
+       if(g_client_poll_fd != -1)
+       {
+               close(g_client_poll_fd);
+       }
+
+       ev.events = EPOLLIN | EPOLLET | EPOLLHUP | EPOLLERR;
+       ev.data.fd = g_client_sock_fd;
+       epoll_ctl(g_client_poll_fd, EPOLL_CTL_DEL, g_client_sock_fd, &ev);
+       g_client_poll_fd = -1;
+
+       _net_nfc_client_util_free_mem (g_client_poll_events);
+
+#else
+       FD_CLR(g_client_sock_fd, &fdset_read);
+#endif
+
+
+#endif // #ifdef G_MAIN_LOOP
+
+       g_client_sock_fd = -1;
+
+       pthread_mutex_unlock(&g_client_lock);
+
+       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%x]", 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
+       pthread_mutex_lock(&g_client_lock);
+       pthread_cond_signal ((pthread_cond_t *) data);
+       pthread_mutex_unlock(&g_client_lock);
+
+#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_IPC_FAIL:
+                                       DEBUG_CLIENT_MSG("stop ipc polling thread");
+                                       condition = false;
+                                       break;
+                               default:
+                                       break;
+                       }
+               }
+               else
+               {
+                       net_nfc_error_e result = NET_NFC_OK;
+
+                       DEBUG_CLIENT_MSG("message is coming from server to client");
+
+                       net_nfc_response_msg_t* msg = net_nfc_client_read_response_msg(&result);
+
+                       pthread_mutex_lock(&cb_lock);
+
+                       if(msg != NULL)
+                       {
+
+#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 wating for unlock signal, then unlock it.
+                                * and send error message
+                                * or make error reponse message and pass to client cb
+                                */
+                               if (net_nfc_client_is_connected () == false){
+                                       condition = false;
+                               }
+                               DEBUG_CLIENT_MSG("can not read response msg or callback is NULL");
+                       }
+
+                       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 \n");
+                       return FALSE;
+               }
+       }
+       else{
+
+               DEBUG_CLIENT_MSG("IO ERROR. socket is closed \n");
+
+               /* 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;
+       int index = 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_CLIENT_MSG("client is deinitialized. ");
+               *result = NET_NFC_IPC_FAIL;
+               return false;
+       }
+
+       /* 0.5sec */
+#ifdef USE_EPOLL_TIMEOUT
+
+       while((num_of_sockets = epoll_wait(g_client_poll_fd, g_client_poll_events, EPOLL_SIZE, 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_events, EPOLL_SIZE, -1);
+
+#endif
+
+       for(index = 0; index < num_of_sockets; index++)
+       {
+               if( (g_client_poll_events[index].events & (EPOLLHUP)) || (g_client_poll_events[index].events & (EPOLLERR)))
+               {
+                       DEBUG_ERR_MSG("connection is closed");
+                       *result = NET_NFC_IPC_FAIL;
+                       return false;
+               }
+               else if(g_client_poll_events[index].events & EPOLLIN)
+               {
+                       if(g_client_poll_events[index].data.fd == g_client_sock_fd)
+                       {
+                               return true;
+                       }
+                       else
+                       {
+                               DEBUG_ERR_MSG("not expected socket connection");
+                               return false;
+                       }
+               }
+               else
+               {
+                       if(num_of_sockets == index)
+                       {
+                               DEBUG_ERR_MSG("unknown event");
+                               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
+net_nfc_error_e net_nfc_client_socket_finalize()
+{
+       DEBUG_CLIENT_MSG("finalize client socket");
+
+       net_nfc_error_e result = NET_NFC_OK;
+
+
+       pthread_mutex_lock(&g_client_lock);
+
+       if(g_client_sock_fd != -1)
+       {
+               shutdown(g_client_sock_fd, SHUT_RDWR);
+               DEBUG_CLIENT_MSG("close client socket");
+               close(g_client_sock_fd);
+       }
+
+#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;
+
+       pthread_mutex_unlock(&g_client_lock);
+
+#else
+
+#ifdef USE_IPC_EPOLL
+       if(g_client_poll_fd != -1)
+       {
+               int ret = close(g_client_poll_fd);
+               DEBUG_CLIENT_MSG("close returned %d", ret);
+       }
+#endif
+
+       pthread_mutex_unlock(&g_client_lock);
+
+
+#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
+*/
+       if(g_poll_thread != (pthread_t)NULL)
+               pthread_kill(g_poll_thread, SIGTERM);
+#endif
+
+       if(g_poll_thread != (pthread_t)NULL){
+               DEBUG_CLIENT_MSG("join epoll_thread start");
+               pthread_join (g_poll_thread, NULL);
+               DEBUG_CLIENT_MSG("join epoll_thread end");
+       }
+
+
+#ifdef USE_IPC_EPOLL
+
+       struct epoll_event ev;
+       ev.events = EPOLLIN | EPOLLET | EPOLLHUP | EPOLLERR;
+       ev.data.fd = g_client_sock_fd;
+
+       epoll_ctl(g_client_poll_fd, EPOLL_CTL_DEL, g_client_sock_fd, &ev);
+       g_client_poll_fd = -1;
+
+#else
+
+       FD_CLR(g_client_sock_fd, &fdset_read);
+
+#endif
+
+       g_poll_thread = (pthread_t)NULL;
+
+#endif // #ifdef G_MAIN_LOOP
+
+       g_client_sock_fd = -1;
+
+       return result;
+}
+
+
+
+int __net_nfc_client_read_util (void ** detail, size_t size)
+{
+       static uint8_t flushing[128];
+
+       *detail  = NULL;
+       _net_nfc_client_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_client_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;
+
+       if( (resp_msg = calloc(1, sizeof(net_nfc_response_msg_t))) == NULL)
+       {
+               DEBUG_ERR_MSG("malloc fail");
+               *result = NET_NFC_ALLOC_FAIL;
+               return NULL;
+       }
+
+       int length = recv(g_client_sock_fd, (void *)&(resp_msg->response_type), sizeof(int), 0);
+
+       DEBUG_CLIENT_MSG("message from server = [%d]. reading lengths = [%d]", resp_msg->response_type, length);
+
+       if(length < 1)
+       {
+               DEBUG_ERR_MSG("reading message is failed");
+               _net_nfc_client_util_free_mem(resp_msg);
+
+               return NULL;
+       }
+
+       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_client_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_client_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_client_util_free_mem(resp_msg);
+                               return NULL;
+                       }
+                       DEBUG_CLIENT_MSG("handle = [0x%x]", 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_client_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_client_util_free_mem (resp_detail);
+                                               res --;
+                                       }
+                               }
+                               else {
+                                       resp_msg->detail_message = resp_detail;
+                                       resp_detail->data.buffer = NULL;
+                               }
+                       }
+                       if (res == 0){
+                               _net_nfc_client_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_client_util_free_mem (resp_detail);
+                                                               res --;
+                                                       }
+                                               }
+                                               else {
+                                                       resp_msg->detail_message = resp_detail;
+                                                       resp_detail->raw_data.buffer = NULL;
+                                               }
+                                       }
+                                       else{
+                                               _net_nfc_client_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_client_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_client_util_free_mem (resp_detail);
+                                                               res --;
+                                                       }
+                                               }
+                                               else {
+                                                       resp_msg->detail_message = resp_detail;
+                                                       resp_detail->raw_data.buffer = NULL;
+                                               }
+                                       }
+                                       else{
+                                               _net_nfc_client_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_client_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_client_util_free_mem (resp_detail);
+                                                               res --;
+                                                       }
+                                               }
+                                               else {
+                                                       resp_msg->detail_message = resp_detail;
+                                                       resp_detail->param.buffer = NULL;
+                                               }
+                                       }
+                                       else{
+                                               _net_nfc_client_util_free_mem (resp_detail);
+                                               res --;
+                                       }
+                               }
+                               else {
+                                       resp_msg->detail_message = resp_detail;
+                                       resp_detail->aid.buffer = NULL;
+                               }
+                       }
+                       if (res == 0){
+                               _net_nfc_client_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_client_util_free_mem (resp_detail);
+                                               res --;
+                                       }
+                               }
+                               else {
+                                       resp_msg->detail_message = resp_detail;
+                                       resp_detail->data.buffer = NULL;
+                               }
+                       }
+                       if (res == 0){
+                               _net_nfc_client_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_client_util_free_mem (resp_detail);
+                                               res --;
+                                       }
+                               }
+                               else {
+                                       resp_msg->detail_message = resp_detail;
+                                       resp_detail->data.buffer = NULL;
+                               }
+                       }
+                       if (res == 0){
+                               _net_nfc_client_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_client_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_client_util_free_mem(resp_msg);
+                               return NULL;
+                       }
+                       resp_msg->detail_message = resp_detail;
+               }
+               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_client_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_client_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_client_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_client_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_client_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_client_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_client_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_client_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_client_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_client_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_client_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_client_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_client_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_client_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_client_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_client_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_client_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_client_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_client_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_client_util_free_mem(resp_detail);
+                                               _net_nfc_client_util_free_mem(resp_msg);
+                                               return NULL;
+                                       }
+                               }
+                       }
+                       else
+                       {
+                               DEBUG_ERR_MSG("__net_nfc_client_read_util failed. res [%d]", res);
+                               _net_nfc_client_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_client_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_client_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_client_util_free_mem(resp_msg);
+                       return NULL;
+               }
+
+       }
+
+       return resp_msg;
+}
+
+
+bool __net_nfc_client_send_msg(void* message, int length)
+{
+       DEBUG_CLIENT_MSG("sending message to server [%d]", g_client_sock_fd);
+
+       int ret = send(g_client_sock_fd, (void *)message, length, 0);
+       uint8_t  buf[1024] = {0x00,};
+
+       if(ret > 0)
+       {
+               return true;
+       }
+       else
+       {
+               DEBUG_ERR_MSG("sending message is failed");
+               DEBUG_CLIENT_MSG ("Returned : %s", strerror_r (ret , (char *)buf , sizeof(buf)));
+               return false;
+       }
+}
+
+
+static char* cookies = NULL;
+static int cookies_size = 0;
+
+
+void _net_nfc_client_set_cookies (const char * cookie , size_t size)
+{
+       cookies = (char*) cookie;
+       cookies_size = size;
+
+}
+
+void _net_nfc_client_free_cookies (void)
+{
+       _net_nfc_client_util_free_mem (cookies);
+       cookies_size = 0;
+}
+
+net_nfc_error_e _net_nfc_client_send_reqeust(net_nfc_request_msg_t *msg, ...)
+{
+       va_list args;
+       int total_size = 0;
+       int size = 0;
+       int written_size = 0;
+       void * data;
+       uint8_t* send_buffer = NULL;
+
+       pthread_mutex_lock(&g_client_lock);
+
+       total_size += msg->length;
+
+       va_start(args, msg);
+       if (va_arg (args, void *) != NULL)
+       {
+               while ((size = va_arg(args, int)) != 0)
+               {
+
+                       total_size += size;
+
+                       if (va_arg (args, void *) == NULL)
+                       {
+                               break;
+                       }
+               }
+       }
+       va_end(args);
+
+#ifdef SECURITY_SERVER
+       total_size += cookies_size;
+#endif
+
+       _net_nfc_client_util_alloc_mem(send_buffer, total_size);
+       if (send_buffer == NULL)
+       {
+               /*  prevent :: unlock mutex before returing */
+               pthread_mutex_unlock(&g_client_lock);
+               return NET_NFC_ALLOC_FAIL;
+       }
+
+#ifdef SECURITY_SERVER
+       memcpy(send_buffer, cookies, cookies_size);
+       written_size += cookies_size;
+#endif
+
+       memcpy(send_buffer + written_size, msg, msg->length);
+       written_size += msg->length;
+
+       va_start(args, msg);
+       while ((data = va_arg(args, void *)) != NULL)
+       {
+               size = va_arg (args, int);
+               if (size == 0)
+                       continue;
+               memcpy(send_buffer + written_size, data, size);
+               written_size += size;
+       }
+       va_end(args);
+
+       bool msg_result = __net_nfc_client_send_msg((void *)send_buffer, total_size);
+       pthread_mutex_unlock(&g_client_lock);
+
+       if (!msg_result)
+       {
+               /* Sending is failed */
+               return NET_NFC_IPC_FAIL;
+       }
+
+       DEBUG_CLIENT_MSG("sending request = [%d] is ok", msg->request_type);
+       _net_nfc_client_util_free_mem(send_buffer);
+
+       return NET_NFC_OK;
+}
+
+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 100644 (file)
index 0000000..c4efa8b
--- /dev/null
@@ -0,0 +1,1067 @@
+/*\r
+  * Copyright 2012  Samsung Electronics Co., Ltd\r
+  *\r
+  * Licensed under the Flora License, Version 1.0 (the "License");\r
+  * you may not use this file except in compliance with the License.\r
+  * You may obtain a copy of the License at\r
+\r
+  *     http://www.tizenopensource.org/license\r
+  *\r
+  * Unless required by applicable law or agreed to in writing, software\r
+  * distributed under the License is distributed on an "AS IS" BASIS,\r
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+  * See the License for the specific language governing permissions and\r
+  * limitations under the License.\r
+  */\r
+\r
+#include <glib.h>\r
+#include <pthread.h>\r
+\r
+#include "net_nfc_llcp.h"\r
+#include "net_nfc_typedef_private.h"\r
+#include "net_nfc_util_private.h"\r
+#include "net_nfc_debug_private.h"\r
+#include "net_nfc_client_ipc_private.h"\r
+#include "net_nfc_client_util_private.h"\r
+\r
+#ifndef NET_NFC_EXPORT_API\r
+#define NET_NFC_EXPORT_API __attribute__((visibility("default")))\r
+#endif\r
+\r
+GList * socket_list = NULL;\r
+\r
+/*\r
+       Concept of the llcp_lock\r
+       1. this lock protects only between client thread (these are calling llcp apis) and callback thread queue (=dispatcher thread)\r
+       2. dispatcher thread is always serial it does not have to protect itself.\r
+       3. all internal function for example __free_socket_info, __socket_equal_to are used only inside of this file\r
+       (there is no way to access from client api) thread safe.\r
+       4. if the internal function calles from other thread (or changed to public) then you should consider use lock\r
+*/\r
+static pthread_mutex_t llcp_lock = PTHREAD_MUTEX_INITIALIZER;\r
+\r
+/* to share client info */\r
+unsigned int socket_handle = 0; /* to generate client socket handle */\r
+static net_nfc_target_handle_s * current_target = NULL;\r
+\r
+static net_nfc_llcp_config_info_s local_config = { 128, 1, 10, 0 };\r
+static net_nfc_llcp_config_info_s remote_config = { 128, 1, 10, 0 };\r
+\r
+/* =============================================================== */\r
+/* Socket info util */\r
+\r
+static void __free_socket_info(net_nfc_llcp_internal_socket_s * data)\r
+{\r
+       net_nfc_llcp_internal_socket_s * socket_info = (net_nfc_llcp_internal_socket_s *)data;\r
+\r
+       if (socket_info == NULL)\r
+               return;\r
+       _net_nfc_client_util_free_mem(socket_info->service_name);\r
+       _net_nfc_client_util_free_mem(socket_info);\r
+}\r
+\r
+static int __socket_equal_to(gconstpointer key1, gconstpointer key2)\r
+{\r
+       net_nfc_llcp_internal_socket_s * arg1 = (net_nfc_llcp_internal_socket_s *)key1;\r
+       net_nfc_llcp_internal_socket_s * arg2 = (net_nfc_llcp_internal_socket_s *)key2;\r
+\r
+       if (arg1->client_socket < arg2->client_socket)\r
+       {\r
+               return -1;\r
+       }\r
+       else if (arg1->client_socket > arg2->client_socket)\r
+       {\r
+               return 1;\r
+       }\r
+       else\r
+       {\r
+               return 0;\r
+       }\r
+}\r
+\r
+net_nfc_llcp_internal_socket_s * _find_internal_socket_info(net_nfc_llcp_socket_t socket)\r
+{\r
+       net_nfc_llcp_internal_socket_s * inter_socket = NULL;\r
+       net_nfc_llcp_internal_socket_s temp = { 0 };\r
+       GList * found = NULL;\r
+\r
+       DEBUG_CLIENT_MSG("Socket info search requested with #[ %d ]", socket);\r
+\r
+       temp.client_socket = socket;\r
+\r
+       if (socket_list != NULL)\r
+       {\r
+               found = g_list_find_custom(socket_list, &temp, __socket_equal_to);\r
+       }\r
+\r
+       if (NULL == found)\r
+       {\r
+               DEBUG_CLIENT_MSG("ERROR DATA IS NOT FOUND");\r
+               return NULL;\r
+       }\r
+       else\r
+       {\r
+               DEBUG_CLIENT_MSG("socket_info is found address [%X]", found->data);\r
+               inter_socket = (net_nfc_llcp_internal_socket_s *)found->data;\r
+       }\r
+\r
+       return inter_socket;\r
+}\r
+\r
+static int __socket_equal_to_by_oal(gconstpointer key1, gconstpointer key2)\r
+{\r
+       net_nfc_llcp_internal_socket_s * arg1 = (net_nfc_llcp_internal_socket_s *)key1;\r
+       net_nfc_llcp_internal_socket_s * arg2 = (net_nfc_llcp_internal_socket_s *)key2;\r
+\r
+       if (arg1->oal_socket < arg2->oal_socket)\r
+       {\r
+               return -1;\r
+       }\r
+       else if (arg1->oal_socket > arg2->oal_socket)\r
+       {\r
+               return 1;\r
+       }\r
+       else\r
+       {\r
+               return 0;\r
+       }\r
+}\r
+\r
+static void __socket_foreach(gpointer data, gpointer user_data)\r
+{\r
+       __free_socket_info((net_nfc_llcp_internal_socket_s *)data);\r
+}\r
+\r
+void _net_nfc_llcp_close_all_socket()\r
+{\r
+       pthread_mutex_lock(&llcp_lock);\r
+\r
+       if (socket_list != NULL)\r
+       {\r
+               g_list_foreach(socket_list, __socket_foreach, NULL);\r
+               g_list_free(socket_list);\r
+       }\r
+\r
+       socket_list = NULL;\r
+\r
+       pthread_mutex_unlock(&llcp_lock);\r
+}\r
+\r
+net_nfc_llcp_internal_socket_s * _find_internal_socket_info_by_oal_socket(net_nfc_llcp_socket_t socket)\r
+{\r
+       net_nfc_llcp_internal_socket_s * inter_socket = NULL;\r
+       net_nfc_llcp_internal_socket_s temp = { 0 };\r
+       GList * found = NULL;\r
+\r
+       temp.oal_socket = socket;\r
+\r
+       DEBUG_CLIENT_MSG("search by oal socket is called socket[ %d ] ", socket);\r
+\r
+       if (socket_list != NULL)\r
+       {\r
+               found = g_list_find_custom(socket_list, &temp, __socket_equal_to_by_oal);\r
+       }\r
+\r
+       if (NULL == found)\r
+       {\r
+               DEBUG_CLIENT_MSG("ERROR DATA IS NOT FOUND");\r
+               return NULL;\r
+       }\r
+       else\r
+       {\r
+               inter_socket = (net_nfc_llcp_internal_socket_s *)found->data;\r
+               DEBUG_CLIENT_MSG("oal socket_info is found address [%X]", inter_socket);\r
+       }\r
+\r
+       return inter_socket;\r
+}\r
+\r
+void _remove_internal_socket(net_nfc_llcp_internal_socket_s * data)\r
+{\r
+       pthread_mutex_lock(&llcp_lock);\r
+\r
+       if (data == NULL)\r
+       {\r
+               pthread_mutex_unlock(&llcp_lock);\r
+               return;\r
+       }\r
+\r
+       if (socket_list != NULL)\r
+       {\r
+\r
+               socket_list = g_list_remove(socket_list, data);\r
+       }\r
+       __free_socket_info(data);\r
+\r
+       pthread_mutex_unlock(&llcp_lock);\r
+}\r
+\r
+void _append_internal_socket(net_nfc_llcp_internal_socket_s * data)\r
+{\r
+       pthread_mutex_lock(&llcp_lock);\r
+\r
+       if (data != NULL)\r
+       {\r
+               socket_list = g_list_append(socket_list, data);\r
+       }\r
+\r
+       pthread_mutex_unlock(&llcp_lock);\r
+}\r
+\r
+/* =============================================================== */\r
+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)\r
+{\r
+\r
+       net_nfc_llcp_internal_socket_s * socket_data = NULL;\r
+       net_nfc_llcp_socket_option_s * strct_options = (net_nfc_llcp_socket_option_s *)options;\r
+       net_nfc_llcp_socket_option_s default_option = {\r
+               128, 1, NET_NFC_LLCP_SOCKET_TYPE_CONNECTIONORIENTED\r
+       };\r
+\r
+       DEBUG_CLIENT_MSG("function %s is called", __func__);\r
+\r
+       if (socket == NULL)\r
+       {\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+\r
+       if (options == NULL)\r
+       {\r
+               strct_options = &default_option;\r
+       }\r
+\r
+       _net_nfc_client_util_alloc_mem(socket_data, sizeof(net_nfc_llcp_internal_socket_s));\r
+\r
+       socket_data->client_socket = socket_handle++;\r
+       socket_data->miu = strct_options->miu;\r
+       socket_data->rw = strct_options->rw;\r
+       socket_data->type = strct_options->type;\r
+       socket_data->device_id = current_target;\r
+       socket_data->close_requested = false;\r
+\r
+       _append_internal_socket(socket_data);\r
+\r
+       *socket = socket_data->client_socket;\r
+\r
+       return NET_NFC_OK;\r
+\r
+}\r
+\r
+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)\r
+{\r
+       net_nfc_llcp_internal_socket_s * socket_data = NULL;\r
+\r
+       if (cb == NULL)\r
+       {\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+\r
+       pthread_mutex_lock(&llcp_lock);\r
+\r
+       socket_data = _find_internal_socket_info(socket);\r
+\r
+       if (socket_data == NULL)\r
+       {\r
+               pthread_mutex_unlock(&llcp_lock);\r
+               return NET_NFC_LLCP_INVALID_SOCKET;\r
+       }\r
+\r
+       socket_data->cb = cb;\r
+       socket_data->register_param = user_param;\r
+\r
+       pthread_mutex_unlock(&llcp_lock);\r
+\r
+       return NET_NFC_OK;\r
+}\r
+\r
+NET_NFC_EXPORT_API net_nfc_error_e net_nfc_unset_llcp_socket_callback(net_nfc_llcp_socket_t socket)\r
+{\r
+       pthread_mutex_lock(&llcp_lock);\r
+       net_nfc_llcp_internal_socket_s * socket_data = _find_internal_socket_info(socket);\r
+\r
+       if (socket_data == NULL)\r
+       {\r
+               pthread_mutex_unlock(&llcp_lock);\r
+               return NET_NFC_LLCP_INVALID_SOCKET;\r
+       }\r
+\r
+       if (socket_data->cb == NULL)\r
+       {\r
+               pthread_mutex_unlock(&llcp_lock);\r
+               return NET_NFC_NOT_REGISTERED;\r
+       }\r
+\r
+       socket_data->cb = NULL;\r
+       pthread_mutex_unlock(&llcp_lock);\r
+\r
+       return NET_NFC_OK;\r
+}\r
+\r
+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)\r
+{\r
+       net_nfc_llcp_internal_socket_s *psocket_data = NULL;\r
+       net_nfc_request_listen_socket_t *request = NULL;\r
+       net_nfc_error_e ret;\r
+       int srv_name_count = 0;\r
+       uint32_t length = 0;\r
+\r
+       DEBUG_CLIENT_MSG("function %s is called. socket#[ %d ]", __func__, socket);\r
+\r
+       if (service_name == NULL)\r
+       {\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+\r
+       pthread_mutex_lock(&llcp_lock);\r
+       psocket_data = _find_internal_socket_info(socket);\r
+       if (psocket_data == NULL)\r
+       {\r
+               pthread_mutex_unlock(&llcp_lock);\r
+               return NET_NFC_LLCP_INVALID_SOCKET;\r
+       }\r
+\r
+       srv_name_count = strlen((char *)service_name) + 1;\r
+\r
+       _net_nfc_client_util_alloc_mem(psocket_data->service_name, srv_name_count);\r
+       if (psocket_data->service_name == NULL)\r
+       {\r
+               pthread_mutex_unlock(&llcp_lock);\r
+               return NET_NFC_ALLOC_FAIL;\r
+       }\r
+       strncpy((char *)psocket_data->service_name, (char *)service_name, srv_name_count);\r
+       psocket_data->sap = sap;\r
+\r
+       /* fill request message */\r
+       length = sizeof(net_nfc_request_listen_socket_t) + srv_name_count;\r
+\r
+       _net_nfc_client_util_alloc_mem(request, length);\r
+       if (request == NULL)\r
+       {\r
+               _net_nfc_client_util_free_mem(psocket_data->service_name);\r
+               pthread_mutex_unlock(&llcp_lock);\r
+               return NET_NFC_ALLOC_FAIL;\r
+       }\r
+\r
+       request->length = length;\r
+       request->request_type = NET_NFC_MESSAGE_LLCP_LISTEN;\r
+       request->handle = current_target;\r
+       request->miu = psocket_data->miu;\r
+       request->oal_socket = psocket_data->oal_socket;\r
+       request->rw = psocket_data->rw;\r
+       request->sap = psocket_data->sap;\r
+       request->type = psocket_data->type;\r
+       request->client_socket = psocket_data->client_socket;\r
+       request->trans_param = trans_param;\r
+\r
+       request->service_name.length = srv_name_count;\r
+       memcpy(&request->service_name.buffer, psocket_data->service_name, request->service_name.length);\r
+\r
+       ret = _net_nfc_client_send_reqeust((net_nfc_request_msg_t *)request, NULL);\r
+\r
+       _net_nfc_client_util_free_mem(request);\r
+\r
+       pthread_mutex_unlock(&llcp_lock);\r
+\r
+       return ret;\r
+}\r
+\r
+NET_NFC_EXPORT_API net_nfc_error_e net_nfc_disconnect_llcp(net_nfc_llcp_socket_t socket, void * trans_param)\r
+{\r
+       net_nfc_llcp_internal_socket_s *psocket_data;\r
+       net_nfc_request_disconnect_socket_t request = { 0, };\r
+       net_nfc_error_e ret;\r
+\r
+       DEBUG_CLIENT_MSG("function %s is called. socket#[ %d ]", __func__, socket);\r
+\r
+       pthread_mutex_lock(&llcp_lock);\r
+       psocket_data = _find_internal_socket_info(socket);\r
+       if (psocket_data == NULL)\r
+       {\r
+               pthread_mutex_unlock(&llcp_lock);\r
+               return NET_NFC_LLCP_INVALID_SOCKET;\r
+       }\r
+\r
+       request.length = sizeof(net_nfc_request_disconnect_socket_t);\r
+       request.request_type = NET_NFC_MESSAGE_LLCP_DISCONNECT;\r
+       request.handle = current_target;\r
+       request.oal_socket = psocket_data->oal_socket;\r
+       request.client_socket = psocket_data->client_socket;\r
+       request.trans_param = trans_param;\r
+\r
+       ret = _net_nfc_client_send_reqeust((net_nfc_request_msg_t *)&request, NULL);\r
+\r
+       pthread_mutex_unlock(&llcp_lock);\r
+\r
+       return ret;\r
+}\r
+\r
+NET_NFC_EXPORT_API net_nfc_error_e net_nfc_close_llcp_socket(net_nfc_llcp_socket_t socket, void * trans_param)\r
+{\r
+       net_nfc_llcp_internal_socket_s *psocket_data = NULL;\r
+       net_nfc_request_close_socket_t request = { 0, };\r
+       net_nfc_error_e ret;\r
+\r
+       DEBUG_CLIENT_MSG("function %s is called. socket#[ %d ]", __func__, socket);\r
+\r
+       pthread_mutex_lock(&llcp_lock);\r
+       psocket_data = _find_internal_socket_info(socket);\r
+       if (psocket_data == NULL)\r
+       {\r
+               pthread_mutex_unlock(&llcp_lock);\r
+               return NET_NFC_LLCP_INVALID_SOCKET;\r
+       }\r
+\r
+       if (psocket_data->close_requested)\r
+       {\r
+               pthread_mutex_unlock(&llcp_lock);\r
+               return NET_NFC_OK;\r
+       }\r
+       psocket_data->close_requested = true;\r
+\r
+       request.length = sizeof(net_nfc_request_close_socket_t);\r
+       request.request_type = NET_NFC_MESSAGE_SERVICE_LLCP_CLOSE;\r
+       request.handle = current_target;\r
+       request.oal_socket = psocket_data->oal_socket;\r
+       request.client_socket = psocket_data->client_socket;\r
+       request.trans_param = trans_param;\r
+\r
+       ret = _net_nfc_client_send_reqeust((net_nfc_request_msg_t *)&request, NULL);\r
+\r
+       _remove_internal_socket(psocket_data);\r
+\r
+       pthread_mutex_unlock(&llcp_lock);\r
+\r
+       return ret;\r
+}\r
+\r
+NET_NFC_EXPORT_API net_nfc_error_e net_nfc_send_llcp(net_nfc_llcp_socket_t socket, data_h data, void * trans_param)\r
+{\r
+       net_nfc_llcp_internal_socket_s *psocket_data;\r
+       net_nfc_request_send_socket_t *request = NULL;\r
+       data_s *data_private = (data_s *)data;\r
+       net_nfc_error_e ret;\r
+       uint32_t length = 0;\r
+\r
+       if (data_private == NULL || data_private->buffer == NULL || data_private->length == 0)\r
+       {\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+\r
+       DEBUG_CLIENT_MSG("function %s is called. socket#[ %d ]", __func__, socket);\r
+\r
+       pthread_mutex_lock(&llcp_lock);\r
+       psocket_data = _find_internal_socket_info(socket);\r
+       if (psocket_data == NULL)\r
+       {\r
+               pthread_mutex_unlock(&llcp_lock);\r
+               return NET_NFC_LLCP_INVALID_SOCKET;\r
+       }\r
+\r
+       /* fill request message */\r
+       length = sizeof(net_nfc_request_send_socket_t) + data_private->length;\r
+\r
+       _net_nfc_client_util_alloc_mem(request, length);\r
+       if (request == NULL)\r
+       {\r
+               pthread_mutex_unlock(&llcp_lock);\r
+               return NET_NFC_ALLOC_FAIL;\r
+       }\r
+\r
+       request->length = length;\r
+       request->request_type = NET_NFC_MESSAGE_LLCP_SEND;\r
+       request->handle = current_target;\r
+       request->oal_socket = psocket_data->oal_socket;\r
+       request->client_socket = psocket_data->client_socket;\r
+       request->trans_param = trans_param;\r
+\r
+       request->data.length = data_private->length;\r
+       memcpy(&request->data.buffer, data_private->buffer, request->data.length);\r
+\r
+       ret = _net_nfc_client_send_reqeust((net_nfc_request_msg_t *)request, NULL);\r
+\r
+       _net_nfc_client_util_free_mem(request);\r
+\r
+       pthread_mutex_unlock(&llcp_lock);\r
+\r
+       return ret;\r
+}\r
+\r
+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)\r
+{\r
+       net_nfc_llcp_internal_socket_s *psocket_data = NULL;\r
+       net_nfc_request_receive_socket_t request = { 0, };\r
+       net_nfc_error_e ret;\r
+\r
+       DEBUG_CLIENT_MSG("function %s is called. socket#[ %d ]", __func__, socket);\r
+\r
+       pthread_mutex_lock(&llcp_lock);\r
+\r
+       psocket_data = _find_internal_socket_info(socket);\r
+       if (psocket_data == NULL)\r
+       {\r
+               pthread_mutex_unlock(&llcp_lock);\r
+               return NET_NFC_LLCP_INVALID_SOCKET;\r
+       }\r
+\r
+       request.length = sizeof(net_nfc_request_receive_socket_t);\r
+       request.request_type = NET_NFC_MESSAGE_LLCP_RECEIVE;\r
+       request.handle = current_target;\r
+       request.oal_socket = psocket_data->oal_socket;\r
+       request.client_socket = psocket_data->client_socket;\r
+       request.trans_param = trans_param;\r
+       request.req_length = req_length;\r
+\r
+       ret = _net_nfc_client_send_reqeust((net_nfc_request_msg_t *)&request, NULL);\r
+\r
+       pthread_mutex_unlock(&llcp_lock);\r
+\r
+       return ret;\r
+}\r
+\r
+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)\r
+{\r
+       net_nfc_llcp_internal_socket_s *psocket_data = NULL;\r
+       net_nfc_request_send_to_socket_t *request = NULL;\r
+       data_s * data_private = (data_s *)data;\r
+       net_nfc_error_e ret;\r
+       uint32_t length = 0;\r
+\r
+       if (data_private == NULL || data_private->buffer == NULL || data_private->length == 0)\r
+       {\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+\r
+       DEBUG_CLIENT_MSG("function %s is called. socket#[ %d ]", __func__, socket);\r
+\r
+       pthread_mutex_lock(&llcp_lock);\r
+       psocket_data = _find_internal_socket_info(socket);\r
+       if (psocket_data == NULL)\r
+       {\r
+               pthread_mutex_unlock(&llcp_lock);\r
+               return NET_NFC_LLCP_INVALID_SOCKET;\r
+       }\r
+\r
+       /* fill request message */\r
+       length = sizeof(net_nfc_request_send_to_socket_t) + data_private->length;\r
+\r
+       _net_nfc_client_util_alloc_mem(request, length);\r
+       if (request == NULL)\r
+       {\r
+               pthread_mutex_unlock(&llcp_lock);\r
+               return NET_NFC_ALLOC_FAIL;\r
+       }\r
+\r
+       request->length = length;\r
+       request->request_type = NET_NFC_MESSAGE_LLCP_SEND_TO;\r
+       request->handle = current_target;\r
+       request->oal_socket = psocket_data->oal_socket;\r
+       request->client_socket = psocket_data->client_socket;\r
+       request->trans_param = trans_param;\r
+\r
+       request->data.length = data_private->length;\r
+       memcpy(&request->data.buffer, data_private->buffer, request->data.length);\r
+\r
+       ret = _net_nfc_client_send_reqeust((net_nfc_request_msg_t *)request, NULL);\r
+\r
+       _net_nfc_client_util_free_mem(request);\r
+\r
+       pthread_mutex_unlock(&llcp_lock);\r
+\r
+       return ret;\r
+}\r
+\r
+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)\r
+{\r
+       net_nfc_llcp_internal_socket_s *psocket_data = NULL;\r
+       net_nfc_request_receive_from_socket_t request = { 0, };\r
+       net_nfc_error_e ret;\r
+\r
+       DEBUG_CLIENT_MSG("function %s is called. socket#[ %d ]", __func__, socket);\r
+\r
+       pthread_mutex_lock(&llcp_lock);\r
+\r
+       psocket_data = _find_internal_socket_info(socket);\r
+       if (psocket_data == NULL)\r
+       {\r
+               pthread_mutex_unlock(&llcp_lock);\r
+               return NET_NFC_LLCP_INVALID_SOCKET;\r
+       }\r
+\r
+       request.length = sizeof(net_nfc_request_receive_from_socket_t);\r
+       request.request_type = NET_NFC_MESSAGE_LLCP_RECEIVE_FROM;\r
+       request.handle = current_target;\r
+       request.oal_socket = psocket_data->oal_socket;\r
+       request.client_socket = psocket_data->client_socket;\r
+       request.trans_param = trans_param;\r
+       request.req_length = req_length;\r
+\r
+       ret = _net_nfc_client_send_reqeust((net_nfc_request_msg_t *)&request, NULL);\r
+\r
+       pthread_mutex_unlock(&llcp_lock);\r
+\r
+       return ret;\r
+}\r
+\r
+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)\r
+{\r
+       net_nfc_llcp_internal_socket_s *psocket_data = NULL;\r
+       net_nfc_request_connect_sap_socket_t request = { 0, };\r
+       net_nfc_error_e ret;\r
+\r
+       DEBUG_CLIENT_MSG("function %s is called. socket#[ %d ]", __func__, socket);\r
+\r
+       pthread_mutex_lock(&llcp_lock);\r
+\r
+       psocket_data = _find_internal_socket_info(socket);\r
+       if (psocket_data == NULL)\r
+       {\r
+               pthread_mutex_unlock(&llcp_lock);\r
+               return NET_NFC_LLCP_INVALID_SOCKET;\r
+       }\r
+\r
+       request.length = sizeof(net_nfc_request_connect_sap_socket_t);\r
+       request.request_type = NET_NFC_MESSAGE_LLCP_CONNECT_SAP;\r
+       request.handle = current_target;\r
+       request.oal_socket = psocket_data->oal_socket;\r
+       request.sap = sap;\r
+       request.client_socket = psocket_data->client_socket;\r
+       request.trans_param = trans_param;\r
+       request.miu = psocket_data->miu;\r
+       request.rw = psocket_data->rw;\r
+\r
+       ret = _net_nfc_client_send_reqeust((net_nfc_request_msg_t *)&request, NULL);\r
+\r
+       pthread_mutex_unlock(&llcp_lock);\r
+\r
+       return ret;\r
+}\r
+\r
+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)\r
+{\r
+       net_nfc_llcp_internal_socket_s *psocket_data = NULL;\r
+       net_nfc_request_connect_socket_t *request = NULL;\r
+       net_nfc_error_e ret;\r
+       uint32_t length = 0, svc_name_length = 0;\r
+\r
+       DEBUG_CLIENT_MSG("function %s is called. socket#[ %d ]", __func__, socket);\r
+\r
+       pthread_mutex_lock(&llcp_lock);\r
+\r
+       psocket_data = _find_internal_socket_info(socket);\r
+       if (psocket_data == NULL)\r
+       {\r
+               pthread_mutex_unlock(&llcp_lock);\r
+               return NET_NFC_LLCP_INVALID_SOCKET;\r
+       }\r
+\r
+       svc_name_length = strlen(service_name) + 1;\r
+\r
+       /* fill request message */\r
+       length = sizeof(net_nfc_request_connect_socket_t) + svc_name_length;\r
+\r
+       _net_nfc_client_util_alloc_mem(request, length);\r
+       if (request == NULL)\r
+       {\r
+               pthread_mutex_unlock(&llcp_lock);\r
+               return NET_NFC_ALLOC_FAIL;\r
+       }\r
+\r
+       request->length = length;\r
+       request->request_type = NET_NFC_MESSAGE_LLCP_CONNECT;\r
+       request->handle = current_target;\r
+       request->oal_socket = psocket_data->oal_socket;\r
+       request->client_socket = psocket_data->client_socket;\r
+       request->trans_param = trans_param;\r
+       request->miu = psocket_data->miu;\r
+       request->rw = psocket_data->rw;\r
+\r
+       request->service_name.length = svc_name_length;\r
+       memcpy(&request->service_name.buffer, service_name, request->service_name.length);\r
+\r
+       ret = _net_nfc_client_send_reqeust((net_nfc_request_msg_t *)request, NULL);\r
+\r
+       _net_nfc_client_util_free_mem(request);\r
+\r
+       pthread_mutex_unlock(&llcp_lock);\r
+\r
+       return ret;\r
+}\r
+\r
+NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_llcp_local_configure(net_nfc_llcp_config_info_h * config)\r
+{\r
+       if (config == NULL)\r
+       {\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+\r
+       *config = (net_nfc_llcp_config_info_h)&local_config;\r
+\r
+       return NET_NFC_OK;\r
+}\r
+\r
+void _net_nfc_set_llcp_remote_configure(net_nfc_llcp_config_info_s * remote_data)\r
+{\r
+       if (remote_data == NULL)\r
+       {\r
+               DEBUG_CLIENT_MSG("recieved data is NULL");\r
+               return;\r
+       }\r
+       remote_config.lto = remote_data->lto;\r
+       remote_config.wks = remote_data->wks;\r
+       remote_config.miu = remote_data->miu;\r
+       remote_config.option = remote_data->option;\r
+\r
+}\r
+\r
+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)\r
+{\r
+       if (config == NULL || handle == NULL)\r
+       {\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+\r
+       if (current_target == NULL || (net_nfc_target_handle_s*)handle != current_target)\r
+       {\r
+               return NET_NFC_INVALID_HANDLE;\r
+       }\r
+\r
+       *config = (net_nfc_llcp_config_info_h)&remote_config;\r
+\r
+       return NET_NFC_OK;\r
+}\r
+\r
+NET_NFC_EXPORT_API net_nfc_error_e net_nfc_set_llcp_local_configure(net_nfc_llcp_config_info_h config, void * trans_param)\r
+{\r
+       net_nfc_request_config_llcp_t request = { 0, };\r
+       net_nfc_error_e ret;\r
+\r
+       DEBUG_CLIENT_MSG("function %s is called", __func__);\r
+\r
+       if (config == NULL)\r
+       {\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+\r
+       request.length = sizeof(net_nfc_request_config_llcp_t);\r
+       request.request_type = NET_NFC_MESSAGE_LLCP_CONFIG;\r
+       memset(&request, 0x0, sizeof(net_nfc_request_config_llcp_t));\r
+       memcpy(&local_config, config, sizeof(net_nfc_llcp_config_info_s));\r
+       request.trans_param = trans_param;\r
+       memcpy(&(request.config), config, sizeof(net_nfc_llcp_config_info_s));\r
+\r
+       ret = _net_nfc_client_send_reqeust((net_nfc_request_msg_t *)&request, NULL);\r
+\r
+       return ret;\r
+}\r
+\r
+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)\r
+{\r
+       net_nfc_llcp_internal_socket_s *psocket_data = NULL;\r
+\r
+       DEBUG_CLIENT_MSG("function %s is called", __func__);\r
+\r
+       psocket_data = _find_internal_socket_info(socket);\r
+       if (psocket_data == NULL)\r
+               return NET_NFC_LLCP_INVALID_SOCKET;\r
+\r
+       *info = (net_nfc_llcp_socket_option_h)psocket_data;\r
+\r
+       return NET_NFC_OK;\r
+}\r
+\r
+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)\r
+{\r
+       info = NULL;\r
+       return NET_NFC_OK;\r
+}\r
+\r
+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)\r
+{\r
+       if (option == NULL)\r
+       {\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+\r
+       if (miu < 128 || miu > 1152 ||\r
+               rw < 1 || rw > 15 ||\r
+               type < NET_NFC_LLCP_SOCKET_TYPE_CONNECTIONORIENTED || type > NET_NFC_LLCP_SOCKET_TYPE_CONNECTIONLESS)\r
+       {\r
+\r
+               return NET_NFC_OUT_OF_BOUND;\r
+       }\r
+\r
+       net_nfc_llcp_socket_option_s * struct_option = NULL;\r
+\r
+       if ((struct_option = calloc(1, sizeof(net_nfc_llcp_socket_option_s))) != NULL)\r
+       {\r
+\r
+               struct_option->miu = miu;\r
+               struct_option->rw = rw;\r
+               struct_option->type = type;\r
+\r
+               *option = (net_nfc_llcp_socket_option_h)struct_option;\r
+\r
+               return NET_NFC_OK;\r
+       }\r
+       else\r
+       {\r
+               return NET_NFC_ALLOC_FAIL;\r
+       }\r
+\r
+}\r
+\r
+NET_NFC_EXPORT_API net_nfc_error_e net_nfc_create_llcp_socket_option_default(net_nfc_llcp_socket_option_h * option)\r
+{\r
+       return net_nfc_create_llcp_socket_option(option, 128, 1, NET_NFC_LLCP_SOCKET_TYPE_CONNECTIONORIENTED);\r
+}\r
+\r
+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)\r
+{\r
+       if (option == NULL || miu == NULL)\r
+       {\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+       net_nfc_llcp_socket_option_s * struct_option = (net_nfc_llcp_socket_option_s *)option;\r
+\r
+       *miu = struct_option->miu;\r
+       return NET_NFC_OK;\r
+\r
+}\r
+\r
+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)\r
+{\r
+       if (option == NULL)\r
+       {\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+       net_nfc_llcp_socket_option_s * struct_option = (net_nfc_llcp_socket_option_s *)option;\r
+\r
+       struct_option->miu = miu;\r
+       return NET_NFC_OK;\r
+\r
+}\r
+\r
+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)\r
+{\r
+       if (option == NULL || rw == NULL)\r
+       {\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+       net_nfc_llcp_socket_option_s * struct_option = (net_nfc_llcp_socket_option_s *)option;\r
+\r
+       *rw = struct_option->rw;\r
+       return NET_NFC_OK;\r
+}\r
+\r
+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)\r
+{\r
+       if (option == NULL)\r
+       {\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+       net_nfc_llcp_socket_option_s * struct_option = (net_nfc_llcp_socket_option_s *)option;\r
+\r
+       struct_option->rw = rw;\r
+       return NET_NFC_OK;\r
+}\r
+\r
+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)\r
+{\r
+       if (option == NULL || type == NULL)\r
+       {\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+       net_nfc_llcp_socket_option_s * struct_option = (net_nfc_llcp_socket_option_s *)option;\r
+\r
+       *type = struct_option->type;\r
+       return NET_NFC_OK;\r
+}\r
+\r
+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)\r
+{\r
+       if (option == NULL)\r
+       {\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+       net_nfc_llcp_socket_option_s * struct_option = (net_nfc_llcp_socket_option_s *)option;\r
+\r
+       struct_option->type = type;\r
+       return NET_NFC_OK;\r
+}\r
+\r
+NET_NFC_EXPORT_API net_nfc_error_e net_nfc_free_llcp_socket_option(net_nfc_llcp_socket_option_h option)\r
+{\r
+       if (option == NULL)\r
+       {\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+\r
+       _net_nfc_client_util_free_mem(option);\r
+\r
+       return NET_NFC_OK;\r
+}\r
+\r
+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)\r
+{\r
+       if (config == NULL)\r
+       {\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+\r
+       net_nfc_llcp_config_info_s ** config_private = (net_nfc_llcp_config_info_s **)config;\r
+\r
+       _net_nfc_client_util_alloc_mem(*config_private, sizeof (net_nfc_llcp_config_info_s));\r
+       if (*config_private == NULL)\r
+               return NET_NFC_ALLOC_FAIL;\r
+\r
+       (*config_private)->miu = miu;\r
+       (*config_private)->wks = wks;\r
+       (*config_private)->lto = lto;\r
+       (*config_private)->option = option;\r
+\r
+       return NET_NFC_OK;\r
+}\r
+\r
+NET_NFC_EXPORT_API net_nfc_error_e net_nfc_create_llcp_configure_default(net_nfc_llcp_config_info_h * config)\r
+{\r
+       return net_nfc_create_llcp_configure(config, 128, 1, 10, 0);\r
+}\r
+\r
+NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_llcp_configure_miu(net_nfc_llcp_config_info_h config, uint16_t * miu)\r
+{\r
+       if (config == NULL || miu == NULL)\r
+       {\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+\r
+       net_nfc_llcp_config_info_s * config_private = (net_nfc_llcp_config_info_s *)config;\r
+       *miu = config_private->miu;\r
+\r
+       return NET_NFC_OK;\r
+}\r
+\r
+NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_llcp_configure_wks(net_nfc_llcp_config_info_h config, uint16_t * wks)\r
+{\r
+       if (config == NULL || wks == NULL)\r
+       {\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+\r
+       net_nfc_llcp_config_info_s * config_private = (net_nfc_llcp_config_info_s *)config;\r
+       *wks = config_private->wks;\r
+\r
+       return NET_NFC_OK;\r
+}\r
+\r
+NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_llcp_configure_lto(net_nfc_llcp_config_info_h config, uint8_t * lto)\r
+{\r
+       if (config == NULL || lto == NULL)\r
+       {\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+\r
+       net_nfc_llcp_config_info_s * config_private = (net_nfc_llcp_config_info_s *)config;\r
+       *lto = config_private->lto;\r
+\r
+       return NET_NFC_OK;\r
+}\r
+\r
+NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_llcp_configure_option(net_nfc_llcp_config_info_h config, uint8_t * option)\r
+{\r
+       if (config == NULL || option == NULL)\r
+       {\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+\r
+       net_nfc_llcp_config_info_s * config_private = (net_nfc_llcp_config_info_s *)config;\r
+       *option = config_private->option;\r
+\r
+       return NET_NFC_OK;\r
+}\r
+\r
+NET_NFC_EXPORT_API net_nfc_error_e net_nfc_set_llcp_configure_miu(net_nfc_llcp_config_info_h config, uint16_t miu)\r
+{\r
+       if (config == NULL)\r
+       {\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+\r
+       if (miu < 128 || miu > 1152)\r
+       {\r
+               return NET_NFC_OUT_OF_BOUND;\r
+       }\r
+\r
+       net_nfc_llcp_config_info_s * config_private = (net_nfc_llcp_config_info_s *)config;\r
+       config_private->miu = miu;\r
+\r
+       return NET_NFC_OK;\r
+}\r
+\r
+NET_NFC_EXPORT_API net_nfc_error_e net_nfc_set_llcp_configure_wks(net_nfc_llcp_config_info_h config, uint16_t wks)\r
+{\r
+       if (config == NULL)\r
+       {\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+\r
+       net_nfc_llcp_config_info_s * config_private = (net_nfc_llcp_config_info_s *)config;\r
+       config_private->wks = wks;\r
+\r
+       return NET_NFC_OK;\r
+}\r
+\r
+NET_NFC_EXPORT_API net_nfc_error_e net_nfc_set_llcp_configure_lto(net_nfc_llcp_config_info_h config, uint8_t lto)\r
+{\r
+       if (config == NULL)\r
+       {\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+\r
+       net_nfc_llcp_config_info_s * config_private = (net_nfc_llcp_config_info_s *)config;\r
+       config_private->lto = lto;\r
+\r
+       return NET_NFC_OK;\r
+}\r
+\r
+NET_NFC_EXPORT_API net_nfc_error_e net_nfc_set_llcp_configure_option(net_nfc_llcp_config_info_h config, uint8_t option)\r
+{\r
+       if (config == NULL)\r
+       {\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+\r
+       net_nfc_llcp_config_info_s * config_private = (net_nfc_llcp_config_info_s *)config;\r
+       config_private->option = option;\r
+\r
+       return NET_NFC_OK;\r
+}\r
+\r
+NET_NFC_EXPORT_API net_nfc_error_e net_nfc_free_llcp_configure(net_nfc_llcp_config_info_h config)\r
+{\r
+       if (config == NULL)\r
+       {\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+\r
+       _net_nfc_client_util_free_mem(config);\r
+       return NET_NFC_OK;\r
+}\r
+\r
+NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_current_target_handle(void* trans_param)\r
+{\r
+       net_nfc_error_e result = NET_NFC_OK;\r
+       net_nfc_request_get_current_target_handle_t request = { 0, };\r
+\r
+       request.length = sizeof(net_nfc_request_get_current_target_handle_t);\r
+       request.request_type = NET_NFC_MESSAGE_GET_CURRENT_TARGET_HANDLE;\r
+       request.trans_param = trans_param;\r
+\r
+       result = _net_nfc_client_send_reqeust((net_nfc_request_msg_t *)&request, NULL);\r
+\r
+       return result;\r
+}\r
+\r
+void _net_nfc_set_llcp_current_target_id(net_nfc_target_handle_s * handle)\r
+{\r
+       current_target = handle;\r
+}\r
diff --git a/src/clientlib/net_nfc_client_ndef_message.c b/src/clientlib/net_nfc_client_ndef_message.c
new file mode 100644 (file)
index 0000000..23ff2d6
--- /dev/null
@@ -0,0 +1,212 @@
+/*\r
+  * Copyright 2012  Samsung Electronics Co., Ltd\r
+  *\r
+  * Licensed under the Flora License, Version 1.0 (the "License");\r
+  * you may not use this file except in compliance with the License.\r
+  * You may obtain a copy of the License at\r
+\r
+  *     http://www.tizenopensource.org/license\r
+  *\r
+  * Unless required by applicable law or agreed to in writing, software\r
+  * distributed under the License is distributed on an "AS IS" BASIS,\r
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+  * See the License for the specific language governing permissions and\r
+  * limitations under the License.\r
+  */\r
+\r
+#include "net_nfc_debug_private.h"\r
+#include "net_nfc_util_private.h"\r
+#include "net_nfc_util_ndef_message.h"\r
+\r
+#include "net_nfc_ndef_message.h"\r
+#include "net_nfc.h" // to use net_nfc_data\r
+\r
+\r
+#ifndef NET_NFC_MANAGER_DATA_PATH\r
+#define NET_NFC_MANAGER_DATA_PATH                              "/opt/data/nfc-manager-daemon"\r
+#endif\r
+\r
+#ifndef NET_NFC_MANAGER_DATA_PATH_MESSAGE\r
+#define NET_NFC_MANAGER_DATA_PATH_MESSAGE              "message"\r
+#endif\r
+\r
+#ifndef NET_NFC_MANAGER_NDEF_FILE_NAME\r
+#define NET_NFC_MANAGER_NDEF_FILE_NAME                 "ndef-message.txt"\r
+#endif\r
+\r
+\r
+#ifndef NET_NFC_EXPORT_API\r
+#define NET_NFC_EXPORT_API __attribute__((visibility("default")))\r
+#endif\r
+\r
+\r
+/* public functions */\r
+NET_NFC_EXPORT_API net_nfc_error_e net_nfc_create_ndef_message (ndef_message_h* ndef_message)\r
+{\r
+       return net_nfc_util_create_ndef_message ((ndef_message_s **) ndef_message);\r
+}\r
+\r
+\r
+\r
+NET_NFC_EXPORT_API net_nfc_error_e net_nfc_create_rawdata_from_ndef_message (ndef_message_h ndef_message, data_h* rawdata)\r
+{\r
+       if (ndef_message == NULL || rawdata == NULL){\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+       int count;\r
+       net_nfc_error_e result;\r
+\r
+       result = net_nfc_get_ndef_message_byte_length (ndef_message,&count);\r
+       if (result  != NET_NFC_OK){\r
+               return result;\r
+       }\r
+\r
+       result = net_nfc_create_data (rawdata ,NULL, count);\r
+       if (result != NET_NFC_OK) {\r
+               return result;\r
+       }\r
+       return net_nfc_util_convert_ndef_message_to_rawdata((ndef_message_s*)ndef_message, (data_s*)*rawdata);\r
+}\r
+\r
+NET_NFC_EXPORT_API net_nfc_error_e net_nfc_create_ndef_message_from_rawdata (ndef_message_h* ndef_message, data_h  rawdata)\r
+{\r
+       if (ndef_message == NULL || rawdata == NULL ){\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+\r
+       net_nfc_error_e result;\r
+       result = net_nfc_create_ndef_message (ndef_message);\r
+       if (result  != NET_NFC_OK){\r
+               return result;\r
+       }\r
+\r
+       return net_nfc_util_convert_rawdata_to_ndef_message((data_s*)rawdata, (ndef_message_s*)*ndef_message);\r
+}\r
+\r
+\r
+NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_ndef_message_byte_length(ndef_message_h ndef_message, int * length)\r
+{\r
+       if (ndef_message == NULL || length == NULL){\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+\r
+       * length = net_nfc_util_get_ndef_message_length((ndef_message_s*)ndef_message);\r
+       return NET_NFC_OK;\r
+}\r
+\r
+NET_NFC_EXPORT_API net_nfc_error_e net_nfc_append_record_to_ndef_message(ndef_message_h ndef_message, ndef_record_h  record)\r
+{\r
+       if (ndef_message == NULL || record == NULL){\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+\r
+       return net_nfc_util_append_record((ndef_message_s*)ndef_message, (ndef_record_s *)record);\r
+}\r
+\r
+NET_NFC_EXPORT_API net_nfc_error_e net_nfc_free_ndef_message(ndef_message_h ndef_message)\r
+{\r
+       if (ndef_message == NULL){\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+       net_nfc_error_e error = net_nfc_util_free_ndef_message((ndef_message_s *)ndef_message);\r
+       if (error != NET_NFC_OK){\r
+               return error;\r
+       }\r
+       return error;\r
+}\r
+\r
+NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_ndef_message_record_count (ndef_message_h ndef_message, int * count)\r
+{\r
+       if (ndef_message == NULL || count == NULL){\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+       ndef_message_s * ndef_message_private = (ndef_message_s *)ndef_message;\r
+\r
+       * count = ndef_message_private->recordCount;\r
+\r
+       return NET_NFC_OK;\r
+}\r
+\r
+NET_NFC_EXPORT_API void net_nfc_ndef_print_message (ndef_message_h ndef_message )\r
+{\r
+       net_nfc_util_print_ndef_message ((ndef_message_s *)(ndef_message) );\r
+}\r
+\r
+\r
+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)\r
+{\r
+       return net_nfc_util_search_record_by_type ((ndef_message_s*)ndef_message, tnf, (data_s *)type, (ndef_record_s**)record);\r
+}\r
+\r
+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)\r
+{\r
+       return net_nfc_util_append_record_by_index ((ndef_message_s *) ndef_message, index, (ndef_record_s *) record);\r
+}\r
+\r
+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)\r
+{\r
+       return net_nfc_util_get_record_by_index ((ndef_message_s*) ndef_message, index, (ndef_record_s**) record);\r
+}\r
+\r
+NET_NFC_EXPORT_API net_nfc_error_e net_nfc_remove_record_by_index (ndef_message_h ndef_message, int index)\r
+{\r
+       return net_nfc_util_remove_record_by_index ((ndef_message_s*)ndef_message, index);\r
+}\r
+\r
+NET_NFC_EXPORT_API net_nfc_error_e net_nfc_retrieve_current_ndef_message(ndef_message_h* ndef_message)\r
+{\r
+       net_nfc_error_e result = NET_NFC_UNKNOWN_ERROR;\r
+       char file_path[1024] = { 0, };\r
+       FILE *fp = NULL;\r
+\r
+       if (ndef_message == NULL)\r
+       {\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+\r
+       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);\r
+\r
+       if ((fp = fopen(file_path, "r")) != NULL)\r
+       {\r
+               uint8_t *buffer = NULL;\r
+               long int size = 0;\r
+\r
+               /* rewind to start of file */\r
+               fseek(fp, 0, SEEK_END);\r
+               size = ftell(fp);\r
+               fseek(fp, 0, SEEK_SET);\r
+\r
+               DEBUG_CLIENT_MSG("message length = [%d] \n", size);\r
+\r
+               if ((buffer = (uint8_t *)calloc(1, size)) != NULL)\r
+               {\r
+                       /* read fully */\r
+                       if ((size = fread(buffer, 1, size, fp)) > 0)\r
+                       {\r
+                               data_h data = NULL;\r
+                               if ((result = net_nfc_create_data(&data, buffer, size)) == NET_NFC_OK)\r
+                               {\r
+                                       result = net_nfc_create_ndef_message_from_rawdata(ndef_message, data);\r
+\r
+                                       net_nfc_free_data(data);\r
+                               }\r
+                       }\r
+\r
+                       free(buffer);\r
+               }\r
+               else\r
+               {\r
+                       result = NET_NFC_ALLOC_FAIL;\r
+               }\r
+\r
+               fclose(fp);\r
+       }\r
+       else\r
+       {\r
+               result = NET_NFC_NO_NDEF_MESSAGE;\r
+       }\r
+\r
+       return result;\r
+}\r
+\r
+\r
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 100644 (file)
index 0000000..7d0b518
--- /dev/null
@@ -0,0 +1,161 @@
+/*\r
+  * Copyright 2012  Samsung Electronics Co., Ltd\r
+  *\r
+  * Licensed under the Flora License, Version 1.0 (the "License");\r
+  * you may not use this file except in compliance with the License.\r
+  * You may obtain a copy of the License at\r
+\r
+  *     http://www.tizenopensource.org/license\r
+  *\r
+  * Unless required by applicable law or agreed to in writing, software\r
+  * distributed under the License is distributed on an "AS IS" BASIS,\r
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+  * See the License for the specific language governing permissions and\r
+  * limitations under the License.\r
+  */\r
+\r
+#include "net_nfc_ndef_message_handover.h"\r
+\r
+#include "net_nfc_typedef_private.h"\r
+#include "net_nfc_debug_private.h"\r
+#include "net_nfc_util_private.h"\r
+#include "net_nfc_util_handover.h"\r
+\r
+#ifndef NET_NFC_EXPORT_API\r
+#define NET_NFC_EXPORT_API __attribute__((visibility("default")))\r
+#endif\r
+\r
+#include <glib.h>\r
+\r
+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)\r
+{\r
+       return  net_nfc_util_create_carrier_config ((net_nfc_carrier_config_s **) config, type);\r
+}\r
+\r
+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)\r
+{\r
+       return net_nfc_util_add_carrier_config_property ((net_nfc_carrier_config_s *) config, attribute, size, data);\r
+}\r
+\r
+NET_NFC_EXPORT_API net_nfc_error_e net_nfc_remove_carrier_config_property (net_nfc_carrier_config_h config, uint16_t attribute)\r
+{\r
+       return net_nfc_util_remove_carrier_config_property ((net_nfc_carrier_config_s *) config, attribute);\r
+}\r
+\r
+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)\r
+{\r
+       return net_nfc_util_get_carrier_config_property ((net_nfc_carrier_config_s *) config, attribute, size, data);\r
+}\r
+\r
+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)\r
+{\r
+       return net_nfc_util_append_carrier_config_group ((net_nfc_carrier_config_s *) config, (net_nfc_carrier_property_s *) group);\r
+}\r
+\r
+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)\r
+{\r
+       return net_nfc_util_remove_carrier_config_group ((net_nfc_carrier_config_s *) config, (net_nfc_carrier_property_s *) group);\r
+}\r
+\r
+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)\r
+{\r
+       return net_nfc_util_get_carrier_config_group ((net_nfc_carrier_config_s *) config, index, (net_nfc_carrier_property_s **) group);\r
+}\r
+\r
+NET_NFC_EXPORT_API net_nfc_error_e net_nfc_free_carrier_config (net_nfc_carrier_config_h config)\r
+{\r
+       return net_nfc_util_free_carrier_config ((net_nfc_carrier_config_s *) config);\r
+}\r
+\r
+NET_NFC_EXPORT_API net_nfc_error_e net_nfc_create_carrier_config_group (net_nfc_property_group_h * group, uint16_t attribute)\r
+{\r
+       return net_nfc_util_create_carrier_config_group ((net_nfc_carrier_property_s **) group, attribute);\r
+}\r
+\r
+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)\r
+{\r
+       return net_nfc_util_add_carrier_config_group_property ((net_nfc_carrier_property_s*) group, attribute, size, data);\r
+}\r
+\r
+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)\r
+{\r
+       return net_nfc_util_get_carrier_config_group_property ((net_nfc_carrier_property_s*) group, attribute, size, data);\r
+}\r
+\r
+NET_NFC_EXPORT_API net_nfc_error_e net_nfc_remove_carrier_config_group_property (net_nfc_property_group_h group, uint16_t attribute)\r
+{\r
+       return net_nfc_util_remove_carrier_config_group_property ((net_nfc_carrier_property_s*) group, attribute);\r
+}\r
+\r
+NET_NFC_EXPORT_API net_nfc_error_e net_nfc_free_carrier_group (net_nfc_property_group_h group)\r
+{\r
+       return net_nfc_util_free_carrier_group ((net_nfc_carrier_property_s*) group);\r
+}\r
+\r
+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)\r
+{\r
+       return net_nfc_util_create_ndef_record_with_carrier_config ((ndef_record_s**) record, (net_nfc_carrier_config_s *) config);\r
+}\r
+\r
+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)\r
+{\r
+       return  net_nfc_util_create_carrier_config_from_config_record ((net_nfc_carrier_config_s **) config, (ndef_record_s *) record);\r
+\r
+}\r
+\r
+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)\r
+{\r
+       return net_nfc_util_append_carrier_config_record ((ndef_message_s *) message, (ndef_record_s *) record, power_status);\r
+}\r
+\r
+NET_NFC_EXPORT_API net_nfc_error_e net_nfc_remove_carrier_config_record (ndef_message_h message, ndef_record_h record)\r
+{\r
+       return net_nfc_util_remove_carrier_config_record ((ndef_message_s *) message, (ndef_record_s *) record);\r
+}\r
+\r
+NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_carrier_config_record (ndef_message_h message, int index, ndef_record_h * record)\r
+{\r
+       return net_nfc_util_get_carrier_config_record ((ndef_message_s *) message, index, (ndef_record_s **) record);\r
+}\r
+\r
+NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_handover_random_number(ndef_message_h message, unsigned short* random_number)\r
+{\r
+       return net_nfc_util_get_handover_random_number((ndef_message_s *) message,  random_number);\r
+}\r
+\r
+NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_alternative_carrier_record_count (ndef_message_h message,  unsigned int * count)\r
+{\r
+       return net_nfc_util_get_alternative_carrier_record_count ((ndef_message_s *) message,  count);\r
+}\r
+\r
+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)\r
+{\r
+       return net_nfc_util_get_alternative_carrier_power_status ((ndef_message_s *) message, index, power_state);\r
+}\r
+\r
+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)\r
+{\r
+       return net_nfc_util_set_alternative_carrier_power_status ((ndef_message_s *) message, index, power_status);\r
+}\r
+\r
+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)\r
+{\r
+       return net_nfc_util_get_alternative_carrier_type ((ndef_message_s *) message,  index, type);\r
+}\r
+\r
+NET_NFC_EXPORT_API net_nfc_error_e net_nfc_create_handover_request_message (ndef_message_h * message)\r
+{\r
+       return net_nfc_util_create_handover_request_message ((ndef_message_s **) message);\r
+}\r
+\r
+NET_NFC_EXPORT_API net_nfc_error_e net_nfc_create_handover_select_message (ndef_message_h * message)\r
+{\r
+       return net_nfc_util_create_handover_select_message((ndef_message_s **) message);\r
+}\r
+\r
+NET_NFC_EXPORT_API net_nfc_error_e net_nfc_create_handover_error_record (ndef_record_h * record, uint8_t reason, uint32_t data)\r
+{\r
+       return net_nfc_util_create_handover_error_record ((ndef_record_s**) record, reason, data);\r
+}\r
+\r
+\r
diff --git a/src/clientlib/net_nfc_client_ndef_record.c b/src/clientlib/net_nfc_client_ndef_record.c
new file mode 100644 (file)
index 0000000..40a4aad
--- /dev/null
@@ -0,0 +1,368 @@
+/*\r
+  * Copyright 2012  Samsung Electronics Co., Ltd\r
+  *\r
+  * Licensed under the Flora License, Version 1.0 (the "License");\r
+  * you may not use this file except in compliance with the License.\r
+  * You may obtain a copy of the License at\r
+\r
+  *     http://www.tizenopensource.org/license\r
+  *\r
+  * Unless required by applicable law or agreed to in writing, software\r
+  * distributed under the License is distributed on an "AS IS" BASIS,\r
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+  * See the License for the specific language governing permissions and\r
+  * limitations under the License.\r
+  */\r
+\r
+#include "net_nfc_ndef_record.h"\r
+#include "net_nfc_ndef_message.h"\r
+#include "net_nfc_data.h"\r
+#include "net_nfc_debug_private.h"\r
+#include "net_nfc_util_private.h"\r
+#include "net_nfc_util_ndef_record.h"\r
+\r
+#ifndef NET_NFC_EXPORT_API\r
+#define NET_NFC_EXPORT_API __attribute__((visibility("default")))\r
+#endif\r
+\r
+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)\r
+{\r
+       return net_nfc_util_create_record(tnf, (data_s*) typeName,(data_s*) id,(data_s*) payload, (ndef_record_s**) record);\r
+}\r
+\r
+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 )\r
+{\r
+       return net_nfc_util_create_text_type_record(text, language_code_str, encode, (ndef_record_s**)record);\r
+}\r
+\r
+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)\r
+{\r
+       return net_nfc_util_create_uri_type_record (uri, protocol_schema,(ndef_record_s**) record);\r
+}\r
+\r
+NET_NFC_EXPORT_API net_nfc_error_e net_nfc_free_record (ndef_record_h record)\r
+{\r
+       return net_nfc_util_free_record ((ndef_record_s*)record);\r
+}\r
+\r
+\r
+NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_record_payload (ndef_record_h record, data_h * payload)\r
+{\r
+       if (record == NULL || payload == NULL){\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+       ndef_record_s * struct_record = (ndef_record_s *) record;\r
+\r
+       *payload = (data_h) &(struct_record->payload_s);\r
+\r
+       return NET_NFC_OK;\r
+}\r
+\r
+NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_record_type (ndef_record_h record, data_h * type)\r
+{\r
+       if (record == NULL || type == NULL){\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+       ndef_record_s * struct_record = (ndef_record_s *) record;\r
+\r
+       *type = (data_h) &(struct_record->type_s);\r
+\r
+       return NET_NFC_OK;\r
+\r
+}\r
+\r
+NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_record_id (ndef_record_h record, data_h * id)\r
+{\r
+       if (record == NULL || id == NULL){\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+       ndef_record_s * struct_record = (ndef_record_s *) record;\r
+\r
+       *id = (data_h) &(struct_record->id_s);\r
+\r
+       return NET_NFC_OK;\r
+\r
+}\r
+\r
+NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_record_tnf (ndef_record_h record, net_nfc_record_tnf_e * TNF)\r
+{\r
+       if (record == NULL || TNF == NULL){\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+       ndef_record_s * struct_record = (ndef_record_s *) record;\r
+\r
+       *TNF = (net_nfc_record_tnf_e) struct_record->TNF;\r
+\r
+       return NET_NFC_OK;\r
+}\r
+\r
+NET_NFC_EXPORT_API net_nfc_error_e net_nfc_set_record_id (ndef_record_h record, data_h id)\r
+{\r
+\r
+       ndef_record_s * record_private = (ndef_record_s *) record;\r
+       data_s * id_private = (data_s *) id;\r
+\r
+       if (id_private == NULL){\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+       return net_nfc_util_set_record_id (record_private, id_private->buffer, id_private->length);\r
+}\r
+\r
+\r
+NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_record_flags (ndef_record_h record, uint8_t * flag)\r
+{\r
+       if (record == NULL || flag == NULL){\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+\r
+       ndef_record_s * struct_record = (ndef_record_s *) record;\r
+\r
+       *flag = struct_record->MB;\r
+       *flag<<=1;\r
+       *flag+= struct_record->ME;\r
+       *flag<<=1;\r
+       *flag+= struct_record->CF;\r
+       *flag<<=1;\r
+       *flag+= struct_record->SR;\r
+       *flag<<=1;\r
+       *flag+= struct_record->IL;\r
+       *flag<<=3;\r
+       *flag+= struct_record->TNF;\r
+\r
+       return NET_NFC_OK;\r
+}\r
+\r
+\r
+NET_NFC_EXPORT_API uint8_t net_nfc_get_record_mb (uint8_t flag)\r
+{\r
+       return (flag&0x80)>>7;\r
+}\r
+\r
+NET_NFC_EXPORT_API uint8_t net_nfc_get_record_me (uint8_t flag)\r
+{\r
+       return (flag&0x40)>>6;\r
+}\r
+\r
+NET_NFC_EXPORT_API uint8_t net_nfc_get_record_cf (uint8_t flag)\r
+{\r
+       return (flag&0x20)>>5;\r
+}\r
+\r
+NET_NFC_EXPORT_API uint8_t net_nfc_get_record_il (uint8_t flag)\r
+{\r
+       return (flag&0x10)>>4;\r
+}\r
+\r
+NET_NFC_EXPORT_API uint8_t net_nfc_get_record_sr (uint8_t flag)\r
+{\r
+       return (flag&0x08)>>3;\r
+}\r
+\r
+NET_NFC_EXPORT_API net_nfc_error_e net_nfc_create_text_string_from_text_record(ndef_record_h record, char** buffer)\r
+{\r
+       if(record == NULL || buffer == NULL)\r
+       {\r
+               return NET_NFC_ALLOC_FAIL;\r
+       }\r
+\r
+       data_h payload ;\r
+       data_h rec_type ;\r
+\r
+       if(net_nfc_get_record_type(record, &rec_type) == NET_NFC_OK)\r
+       {\r
+               if(strncmp((char *)net_nfc_get_data_buffer(rec_type), TEXT_RECORD_TYPE, 1) != 0)\r
+               {\r
+                       DEBUG_CLIENT_MSG("record type is not matched");\r
+                       return NET_NFC_NDEF_RECORD_IS_NOT_EXPECTED_TYPE;\r
+               }\r
+       }\r
+\r
+       if(net_nfc_get_record_payload(record, &payload) == NET_NFC_OK)\r
+       {\r
+               uint8_t* buffer_temp = net_nfc_get_data_buffer(payload);\r
+               uint32_t buffer_length = net_nfc_get_data_length(payload);\r
+\r
+               int controllbyte = buffer_temp[0];\r
+               int lang_code_length = controllbyte & 0x3F;\r
+               int index = lang_code_length + 1;\r
+               int text_length = buffer_length - (lang_code_length + 1);\r
+\r
+               if((*buffer = (char *)calloc(1, text_length + 1)) != NULL)\r
+               {\r
+                       memcpy(*buffer, &(buffer_temp[index]), text_length);\r
+                       DEBUG_CLIENT_MSG("text = [%s]", *buffer);\r
+               }\r
+               else\r
+               {\r
+                       return NET_NFC_ALLOC_FAIL;\r
+               }\r
+       }\r
+\r
+       return NET_NFC_OK;\r
+}\r
+\r
+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)\r
+{\r
+       if(record == NULL || lang_code_str == NULL)\r
+       {\r
+               return NET_NFC_ALLOC_FAIL;\r
+       }\r
+\r
+       data_h payload ;\r
+       data_h rec_type ;\r
+\r
+       if(net_nfc_get_record_type(record, &rec_type) == NET_NFC_OK)\r
+       {\r
+               if(strncmp((char *)net_nfc_get_data_buffer(rec_type), TEXT_RECORD_TYPE, 1) != 0)\r
+               {\r
+                       DEBUG_CLIENT_MSG("record type is not matched");\r
+                       return NET_NFC_NDEF_RECORD_IS_NOT_EXPECTED_TYPE;\r
+               }\r
+       }\r
+\r
+       if(net_nfc_get_record_payload(record, &payload) == NET_NFC_OK)\r
+       {\r
+               uint8_t* buffer_temp = net_nfc_get_data_buffer(payload);\r
+               char * buffer = NULL;\r
+\r
+               int controllbyte = buffer_temp[0];\r
+               int lang_code_length = controllbyte & 0x3F;\r
+               int index = 1;\r
+\r
+               if((buffer = (char *)calloc(1, lang_code_length + 1)) != NULL)\r
+               {\r
+                       memcpy(buffer, &(buffer_temp[index]), lang_code_length);\r
+                       DEBUG_CLIENT_MSG("language code = [%s]", buffer);\r
+\r
+                       *lang_code_str = buffer;\r
+\r
+               }\r
+               else\r
+               {\r
+                       return NET_NFC_ALLOC_FAIL;\r
+               }\r
+\r
+       }\r
+\r
+       return NET_NFC_OK;\r
+}\r
+\r
+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)\r
+{\r
+       if(record == NULL || encoding == NULL)\r
+       {\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+\r
+       data_h payload ;\r
+       data_h rec_type ;\r
+\r
+       if(net_nfc_get_record_type(record, &rec_type) == NET_NFC_OK)\r
+       {\r
+               if(strncmp((char *)net_nfc_get_data_buffer(rec_type), TEXT_RECORD_TYPE, 1) != 0)\r
+               {\r
+                       DEBUG_CLIENT_MSG("record type is not matched");\r
+                       return NET_NFC_NDEF_RECORD_IS_NOT_EXPECTED_TYPE;\r
+               }\r
+       }\r
+\r
+       if(net_nfc_get_record_payload(record, &payload) == NET_NFC_OK)\r
+       {\r
+               uint8_t* buffer_temp = net_nfc_get_data_buffer(payload);\r
+\r
+               int controllbyte = buffer_temp[0];\r
+\r
+               if((controllbyte & 0x80) == 0x80)\r
+               {\r
+                       * encoding = NET_NFC_ENCODE_UTF_16;\r
+               }\r
+               else\r
+               {\r
+                       * encoding = NET_NFC_ENCODE_UTF_8;\r
+               }\r
+       }\r
+\r
+       return NET_NFC_OK;\r
+\r
+}\r
+\r
+NET_NFC_EXPORT_API net_nfc_error_e net_nfc_create_uri_string_from_uri_record(ndef_record_h record, char ** uri)\r
+{\r
+\r
+       if(record == NULL || uri == NULL)\r
+       {\r
+               return NET_NFC_ALLOC_FAIL;\r
+       }\r
+\r
+       data_h payload ;\r
+       data_h rec_type ;\r
+\r
+       if(net_nfc_get_record_type(record, &rec_type) == NET_NFC_OK)\r
+       {\r
+               if(((data_s *)rec_type)->length > 0)\r
+               {\r
+                       if(strncmp((char *)net_nfc_get_data_buffer(rec_type), URI_RECORD_TYPE , 1) != 0)\r
+                       {\r
+                               DEBUG_CLIENT_MSG("record type is not matched");\r
+                               return NET_NFC_NDEF_RECORD_IS_NOT_EXPECTED_TYPE;\r
+                       }\r
+               }\r
+       }\r
+\r
+       DEBUG_CLIENT_MSG("this is URL type");\r
+\r
+       if(net_nfc_get_record_payload(record, &payload) == NET_NFC_OK)\r
+       {\r
+               uint8_t* buffer_temp = net_nfc_get_data_buffer(payload);\r
+               uint32_t buffer_length = net_nfc_get_data_length(payload);\r
+\r
+               if(buffer_temp[0] == 0x00)\r
+               {\r
+                       *uri = (char *)calloc(1, buffer_length); /* buffer length include a schema byte. so it does not need to allocate one more byte for string. */\r
+\r
+                       if(*uri != NULL)\r
+                       {\r
+                               memcpy(*uri, &buffer_temp[1], buffer_length - 1);\r
+                               DEBUG_CLIENT_MSG("the uri to open is = [%s]", *uri);\r
+                       }\r
+                       else\r
+                       {\r
+                               return NET_NFC_ALLOC_FAIL;\r
+                       }\r
+\r
+               }\r
+               else\r
+               {\r
+                       if(buffer_temp[0] >= NET_NFC_SCHEMA_MAX)\r
+                       {\r
+                               DEBUG_CLIENT_MSG("unknow schema. abandon \n");\r
+                       }\r
+                       else\r
+                       {\r
+                               DEBUG_CLIENT_MSG("uri schema is %s", net_nfc_util_get_schema_string(buffer_temp[0]));\r
+\r
+                               int uri_schema_length = strlen(net_nfc_util_get_schema_string(buffer_temp[0]));\r
+                               int uri_buffer_length = uri_schema_length + buffer_length;\r
+\r
+                               *uri = (char *)calloc(1, uri_buffer_length);\r
+\r
+                               if(*uri != NULL)\r
+                               {\r
+                                       memcpy(*uri, net_nfc_util_get_schema_string(buffer_temp[0]), uri_schema_length);\r
+                                       memcpy(*uri + uri_schema_length, &buffer_temp[1], buffer_length - 1);\r
+\r
+                                       DEBUG_CLIENT_MSG("the url to launch = [%s]", *uri);\r
+                               }\r
+                               else\r
+                               {\r
+                                       return NET_NFC_ALLOC_FAIL;\r
+                               }\r
+                       }\r
+\r
+               }\r
+       }\r
+\r
+       return NET_NFC_OK;\r
+\r
+}\r
+\r
diff --git a/src/clientlib/net_nfc_client_nfc.c b/src/clientlib/net_nfc_client_nfc.c
new file mode 100644 (file)
index 0000000..e929cfa
--- /dev/null
@@ -0,0 +1,415 @@
+/*
+  * Copyright 2012  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://www.tizenopensource.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"
+#include "net_nfc_exchanger_private.h"
+#include "net_nfc_client_util_private.h"
+#include "net_nfc_client_nfc_private.h"
+#include "../agent/include/dbus_agent_binding_private.h"
+
+#include <pthread.h>
+#include <glib.h>
+#include <dbus/dbus-glib.h>
+#include <dbus/dbus-glib-bindings.h>
+
+#include "vconf.h"
+
+#ifdef SECURITY_SERVER
+#include <security-server.h>
+#endif
+
+#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 net_nfc_set_activation_completed_cb g_net_nfc_set_activation_completed_cb = NULL;
+
+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;
+}
+
+NET_NFC_EXPORT_API net_nfc_error_e net_nfc_initialize ()
+{
+       int cookies_size;
+       char * cookies = NULL;
+       net_nfc_error_e result = NET_NFC_OK;
+
+       if(!g_thread_supported())
+       {
+               g_thread_init(NULL);
+       }
+
+       dbus_g_thread_init();
+
+       g_type_init();
+
+       pthread_mutex_lock(&g_client_context.g_client_lock);
+
+       if(g_client_context.initialized == true){
+
+               if(net_nfc_get_exchanger_cb() != NULL){
+
+                       result = NET_NFC_NOT_ALLOWED_OPERATION;
+               }
+
+               pthread_mutex_unlock(&g_client_context.g_client_lock);
+               return result;
+       }
+
+       _net_nfc_reset_client_context();
+
+#ifdef SECURITY_SERVER
+       if((cookies_size = security_server_get_cookie_size()) != 0)
+       {
+               _net_nfc_client_util_alloc_mem (cookies,cookies_size);
+               int error = 0;
+               if((error = security_server_request_cookie(cookies, cookies_size)) != SECURITY_SERVER_API_SUCCESS)
+               {
+                       DEBUG_CLIENT_MSG("security server request cookies error = [%d]", error);
+                       _net_nfc_client_util_free_mem(cookies);
+               }
+               else
+               {
+                       char printf_buff[BUFFER_LENGTH_MAX] = {0,};
+                       int buff_count = BUFFER_LENGTH_MAX;
+                       int i = 0;
+
+                       for(; i < cookies_size; i++)
+                       {
+                               buff_count -= snprintf ((char *)(printf_buff + BUFFER_LENGTH_MAX - buff_count), buff_count, " %02X", cookies[i]);
+                       }
+                       DEBUG_CLIENT_MSG ("client send cookies >>>> %s \n", printf_buff);
+
+                       _net_nfc_client_set_cookies (cookies, cookies_size);
+               }
+       }
+#endif
+
+       result = net_nfc_client_socket_initialize();
+
+       if(result != NET_NFC_OK){
+               DEBUG_CLIENT_MSG("socket init is failed = [%d]", result);
+               _net_nfc_client_free_cookies ();
+       }
+       else{
+               DEBUG_CLIENT_MSG("socket is initialized");
+               g_client_context.initialized = true;
+       }
+
+       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 ()
+{
+       pthread_mutex_lock(&g_client_context.g_client_lock);
+
+       net_nfc_error_e result = NET_NFC_OK;
+       result = net_nfc_client_socket_finalize();
+
+       _net_nfc_client_free_cookies ();
+       _net_nfc_reset_client_context();
+
+       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)
+{
+       if (cb == NULL) {
+               return NET_NFC_NULL_PARAMETER;
+       }
+       net_nfc_error_e result = NET_NFC_OK;
+
+       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 result = NET_NFC_OK;
+
+       pthread_mutex_lock(&g_client_context.g_client_lock);
+
+       if (vconf_set_bool(NET_NFC_DISABLE_LAUNCH_POPUP_KEY, enable ? 0 : 1) != 0)
+       {
+               result = NET_NFC_UNKNOWN_ERROR;
+       }
+
+       pthread_mutex_unlock(&g_client_context.g_client_lock);
+
+       return result;
+}
+
+NET_NFC_EXPORT_API bool net_nfc_get_launch_popup_state(void)
+{
+       int disable = 0;
+
+       /* check state of launch popup */
+       if (vconf_get_bool(NET_NFC_DISABLE_LAUNCH_POPUP_KEY, &disable) == 0 && disable == TRUE)
+       {
+               DEBUG_MSG("skip launch popup");
+               return false;
+       }
+
+       return true;
+}
+
+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;;
+       uint32_t status;
+       GError *error = NULL;
+       DBusGConnection *connection = NULL;
+       DBusGProxy *proxy = NULL;
+
+       g_net_nfc_set_activation_completed_cb = callback;
+
+       if(!g_thread_supported())
+       {
+               g_thread_init(NULL);
+       }
+
+       dbus_g_thread_init();
+       g_type_init();
+
+       connection = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
+       if (connection != NULL)
+       {
+               proxy = dbus_g_proxy_new_for_name(connection, "com.samsung.slp.nfc.agent", "/com/samsung/slp/nfc/agent", "com.samsung.slp.nfc.agent");
+               if (proxy != NULL)
+               {
+                       if (state == FALSE)
+                       {
+                               if (!com_samsung_slp_nfc_agent_terminate(proxy, &status, &error))
+                               {
+                                       DEBUG_ERR_MSG("Termination is failed: %d", status);
+                                       DEBUG_ERR_MSG("error : %s", error->message);
+                                       g_error_free(error);
+                               }
+                               else
+                               {
+                                       DEBUG_CLIENT_MSG("terminate is completed");
+
+                                       if (vconf_set_bool(VCONFKEY_NFC_STATE, FALSE) != 0)
+                                       {
+                                               DEBUG_ERR_MSG("vconf_set_bool failed");
+                                       }
+
+                                       ret = NET_NFC_OK;
+                               }
+                       }
+                       else
+                       {
+                               if (!com_samsung_slp_nfc_agent_launch(proxy, &status, &error))
+                               {
+                                       DEBUG_ERR_MSG("[%s(): %d] faile to launch nfc-manager\n", __FUNCTION__, __LINE__);
+                                       DEBUG_ERR_MSG("[%s(): %d] error : %s\n", __FUNCTION__, __LINE__, error->message);
+                                       g_error_free(error);
+                               }
+                               else
+                               {
+                                       DEBUG_CLIENT_MSG("[%s(): %d] launch is completed\n", __FUNCTION__, __LINE__);
+
+                                       if (vconf_set_bool(VCONFKEY_NFC_STATE, TRUE) != 0)
+                                       {
+                                               DEBUG_ERR_MSG("vconf_set_bool failed");
+                                       }
+
+                                       if (vconf_set_int(NET_NFC_VCONF_KEY_PROGRESS, 0) != 0)
+                                       {
+                                               DEBUG_ERR_MSG("vconf_set_bool failed");
+                                       }
+
+                                       ret = NET_NFC_OK;
+                               }
+                       }
+
+                       g_object_unref(proxy);
+               }
+               else
+               {
+                       DEBUG_ERR_MSG("dbus_g_proxy_new_for_name returns NULL");
+               }
+       }
+       else
+       {
+               DEBUG_ERR_MSG("dbus_g_bus_get returns NULL [%s]", error->message);
+               g_error_free(error);
+       }
+       /* todo it will be move to the point of  init response */
+       if (g_net_nfc_set_activation_completed_cb)
+       {
+               DEBUG_ERR_MSG("g_net_nfc_set_activation_completed_cb ret[%d]",ret);
+
+               g_net_nfc_set_activation_completed_cb(ret,NULL);
+
+               g_net_nfc_set_activation_completed_cb = NULL;
+       }
+       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(int client_type)
+{
+       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;
+       request.client_type = client_type;
+
+       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;
+}
+
+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;
+}
+
+client_context_t* net_nfc_get_client_context()
+{
+       return &g_client_context;
+}
+
+bool net_nfc_tag_is_connected()
+{
+       pthread_mutex_lock(&g_client_context.g_client_lock);
+
+       if(g_client_context.target_info != NULL && g_client_context.target_info->handle != NULL){
+
+               pthread_mutex_unlock(&g_client_context.g_client_lock);
+
+               return true;
+       }
+       else{
+
+               pthread_mutex_unlock(&g_client_context.g_client_lock);
+
+               return false;
+       }
+}
+
diff --git a/src/clientlib/net_nfc_client_tag.c b/src/clientlib/net_nfc_client_tag.c
new file mode 100644 (file)
index 0000000..06882c2
--- /dev/null
@@ -0,0 +1,328 @@
+/*\r
+  * Copyright 2012  Samsung Electronics Co., Ltd\r
+  *\r
+  * Licensed under the Flora License, Version 1.0 (the "License");\r
+  * you may not use this file except in compliance with the License.\r
+  * You may obtain a copy of the License at\r
+\r
+  *     http://www.tizenopensource.org/license\r
+  *\r
+  * Unless required by applicable law or agreed to in writing, software\r
+  * distributed under the License is distributed on an "AS IS" BASIS,\r
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+  * See the License for the specific language governing permissions and\r
+  * limitations under the License.\r
+  */\r
+\r
+#include "net_nfc_tag.h"\r
+#include "net_nfc_typedef_private.h"\r
+#include "net_nfc_client_ipc_private.h"\r
+#include "net_nfc_debug_private.h"\r
+#include "net_nfc_util_private.h"\r
+#include "net_nfc_util_ndef_message.h"\r
+#include "net_nfc_client_nfc_private.h"\r
+#include "net_nfc_client_util_private.h"\r
+\r
+#include <string.h>\r
+#include <pthread.h>\r
+\r
+#ifndef NET_NFC_EXPORT_API\r
+#define NET_NFC_EXPORT_API __attribute__((visibility("default")))\r
+#endif\r
+\r
+NET_NFC_EXPORT_API net_nfc_error_e net_nfc_format_ndef(net_nfc_target_handle_h handle, data_h key, void* trans_param)\r
+{\r
+       net_nfc_error_e ret;\r
+       net_nfc_request_format_ndef_t *request = NULL;\r
+       uint32_t length = 0;\r
+       data_s *struct_key = (data_s *)key;\r
+\r
+       if (handle == NULL)\r
+       {\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+\r
+       length = sizeof(net_nfc_request_format_ndef_t);\r
+       if (struct_key != NULL)\r
+       {\r
+               length += struct_key->length;\r
+       }\r
+\r
+       _net_nfc_client_util_alloc_mem(request, length);\r
+       if (request == NULL)\r
+       {\r
+               return NET_NFC_ALLOC_FAIL;\r
+       }\r
+\r
+       request->length = length;\r
+       request->request_type = NET_NFC_MESSAGE_FORMAT_NDEF;\r
+       request->handle = (net_nfc_target_handle_s *)handle;\r
+       request->trans_param = trans_param;\r
+\r
+       if (struct_key != NULL && struct_key->length > 0)\r
+       {\r
+               request->key.length = struct_key->length;\r
+               memcpy(&request->key.buffer, struct_key->buffer, request->key.length);\r
+       }\r
+\r
+       ret = _net_nfc_client_send_reqeust((net_nfc_request_msg_t *)request, NULL);\r
+\r
+       _net_nfc_client_util_free_mem(request);\r
+\r
+       return ret;\r
+}\r
+\r
+NET_NFC_EXPORT_API net_nfc_error_e net_nfc_set_tag_filter(net_nfc_event_filter_e config)\r
+{\r
+\r
+       client_context_t* client_context = net_nfc_get_client_context();\r
+\r
+       pthread_mutex_lock(&(client_context->g_client_lock));\r
+       client_context->filter = config;\r
+       pthread_mutex_unlock(&(client_context->g_client_lock));\r
+\r
+       return NET_NFC_OK;\r
+}\r
+\r
+NET_NFC_EXPORT_API net_nfc_event_filter_e net_nfc_get_tag_filter()\r
+{\r
+\r
+       client_context_t* client_context = net_nfc_get_client_context();\r
+\r
+       pthread_mutex_lock(&(client_context->g_client_lock));\r
+       net_nfc_event_filter_e filter = client_context->filter;\r
+       pthread_mutex_unlock(&(client_context->g_client_lock));\r
+\r
+       return filter;\r
+}\r
+\r
+NET_NFC_EXPORT_API net_nfc_error_e net_nfc_transceive(net_nfc_target_handle_h handle, data_h rawdata, void* trans_param)\r
+{\r
+       net_nfc_error_e ret;\r
+       net_nfc_request_transceive_t *request = NULL;\r
+       client_context_t *client_context_tmp = NULL;\r
+       net_nfc_target_info_s *target_info = NULL;\r
+       uint32_t length = 0;\r
+       data_s *data = (data_s *)rawdata;\r
+\r
+       DEBUG_CLIENT_MSG("send reqeust :: transceive = [%d]", handle);\r
+\r
+       if (handle == NULL || rawdata == NULL)\r
+       {\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+\r
+       if (!net_nfc_tag_is_connected())\r
+       {\r
+               return NET_NFC_OPERATION_FAIL;\r
+       }\r
+\r
+       client_context_tmp = net_nfc_get_client_context();\r
+       if (client_context_tmp == NULL || client_context_tmp->target_info == NULL)\r
+       {\r
+               return NET_NFC_NO_DATA_FOUND;\r
+       }\r
+       /* fill trans information struct */\r
+       target_info = client_context_tmp->target_info;\r
+\r
+       length = sizeof(net_nfc_request_transceive_t) + data->length;\r
+\r
+       _net_nfc_client_util_alloc_mem(request, length);\r
+       if (request == NULL)\r
+       {\r
+               return NET_NFC_ALLOC_FAIL;\r
+       }\r
+\r
+       /* fill request message */\r
+       request->length = length;\r
+       request->request_type = NET_NFC_MESSAGE_TRANSCEIVE;\r
+       request->handle = (net_nfc_target_handle_s *)handle;\r
+       request->trans_param = trans_param;\r
+       request->info.dev_type = (uint32_t)target_info->devType;\r
+\r
+       request->info.trans_data.length = data->length;\r
+       memcpy(&request->info.trans_data.buffer, data->buffer, request->info.trans_data.length);\r
+\r
+       ret = _net_nfc_client_send_reqeust((net_nfc_request_msg_t *)request, NULL);\r
+\r
+       _net_nfc_client_util_free_mem(request);\r
+\r
+       return ret;\r
+}\r
+\r
+NET_NFC_EXPORT_API net_nfc_error_e net_nfc_read_tag(net_nfc_target_handle_h handle, void* trans_param)\r
+{\r
+       net_nfc_error_e ret;\r
+       net_nfc_request_read_ndef_t request = { 0, };\r
+\r
+       DEBUG_CLIENT_MSG("send reqeust :: read ndef = [%X]", handle);\r
+\r
+       if (handle == NULL)\r
+       {\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+\r
+       if (!net_nfc_tag_is_connected())\r
+       {\r
+               return NET_NFC_OPERATION_FAIL;\r
+       }\r
+\r
+       request.length = sizeof(net_nfc_request_read_ndef_t);\r
+       request.request_type = NET_NFC_MESSAGE_READ_NDEF;\r
+       request.handle = (net_nfc_target_handle_s*)handle;\r
+       request.trans_param = trans_param;\r
+\r
+       ret = _net_nfc_client_send_reqeust((net_nfc_request_msg_t *)&request, NULL);\r
+\r
+       return ret;\r
+}\r
+\r
+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)\r
+{\r
+       net_nfc_request_write_ndef_t *request = NULL;\r
+       net_nfc_error_e result;\r
+       data_s data;\r
+       uint32_t length = 0, ndef_length = 0;\r
+\r
+       DEBUG_CLIENT_MSG("send reqeust :: write ndef = [%d]", handle);\r
+\r
+       if (handle == NULL || msg == NULL)\r
+       {\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+\r
+       if (!net_nfc_tag_is_connected())\r
+       {\r
+               return NET_NFC_OPERATION_FAIL;\r
+       }\r
+\r
+       ndef_length = net_nfc_util_get_ndef_message_length((ndef_message_s *)msg);\r
+       if (ndef_length == 0)\r
+       {\r
+               return NET_NFC_INVALID_PARAM;\r
+       }\r
+\r
+       length = sizeof(net_nfc_request_write_ndef_t) + ndef_length;\r
+\r
+       _net_nfc_client_util_alloc_mem(request, length);\r
+       if (request == NULL)\r
+       {\r
+               return NET_NFC_ALLOC_FAIL;\r
+       }\r
+\r
+       /* fill request message */\r
+       request->length = length;\r
+       request->request_type = NET_NFC_MESSAGE_WRITE_NDEF;\r
+       request->handle = (net_nfc_target_handle_s*)handle;\r
+       request->trans_param = trans_param;\r
+       request->data.length = ndef_length;\r
+\r
+       data.length = ndef_length;\r
+       data.buffer = request->data.buffer;\r
+\r
+       result = net_nfc_util_convert_ndef_message_to_rawdata((ndef_message_s *)msg, &data);\r
+       if (result != NET_NFC_OK)\r
+       {\r
+               DEBUG_CLIENT_MSG("NDEF to rawdata is failed (reason:%d)", result);\r
+               _net_nfc_client_util_free_mem(request);\r
+               return result;\r
+       }\r
+\r
+       result = _net_nfc_client_send_reqeust((net_nfc_request_msg_t *)request, NULL);\r
+\r
+       _net_nfc_client_util_free_mem(request);\r
+\r
+       return result;\r
+}\r
+\r
+NET_NFC_EXPORT_API net_nfc_error_e net_nfc_is_tag_connected(void* trans_param)\r
+{\r
+       net_nfc_request_is_tag_connected_t request = { 0, };\r
+       net_nfc_error_e result;\r
+\r
+       request.length =  sizeof(net_nfc_request_is_tag_connected_t);\r
+       request.request_type = NET_NFC_MESSAGE_IS_TAG_CONNECTED;\r
+       request.trans_param = trans_param;\r
+\r
+       result = _net_nfc_client_send_reqeust((net_nfc_request_msg_t *)&request, NULL);\r
+\r
+       return result;\r
+}\r
+\r
+NET_NFC_EXPORT_API net_nfc_error_e net_nfc_make_read_only_ndef_tag(net_nfc_target_handle_h handle, void* trans_param)\r
+{\r
+       net_nfc_error_e result;\r
+       net_nfc_request_make_read_only_ndef_t request = { 0, };\r
+       client_context_t *tmp_client_context = NULL;\r
+       net_nfc_target_info_s *target_info = NULL;\r
+\r
+       DEBUG_CLIENT_MSG("send reqeust :: make read only ndef tag = [%d]", handle);\r
+\r
+       if (handle == NULL)\r
+       {\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+\r
+       if (!net_nfc_tag_is_connected())\r
+       {\r
+               return NET_NFC_OPERATION_FAIL;\r
+       }\r
+\r
+       tmp_client_context = net_nfc_get_client_context();\r
+       if (tmp_client_context != NULL)\r
+       {\r
+\r
+               target_info = tmp_client_context->target_info;\r
+\r
+               if (target_info != NULL)\r
+               {\r
+                       bool is_supported_tag = false;\r
+\r
+                       switch (target_info->devType)\r
+                       {\r
+                       case NET_NFC_ISO14443_A_PICC :\r
+                       case NET_NFC_MIFARE_MINI_PICC :\r
+                       case NET_NFC_MIFARE_1K_PICC :\r
+                       case NET_NFC_MIFARE_4K_PICC :\r
+                       case NET_NFC_MIFARE_ULTRA_PICC :\r
+                       case NET_NFC_JEWEL_PICC :\r
+                               is_supported_tag = true;\r
+                               break;\r
+                       default :\r
+                               is_supported_tag = false;\r
+                               break;\r
+                       }\r
+\r
+                       if (!is_supported_tag)\r
+                       {\r
+                               DEBUG_MSG("not supported tag for read only ndef tag");\r
+                               return NET_NFC_NOT_SUPPORTED;\r
+                       }\r
+               }\r
+       }\r
+\r
+       request.length = sizeof(net_nfc_request_make_read_only_ndef_t);\r
+       request.request_type = NET_NFC_MESSAGE_MAKE_READ_ONLY_NDEF;\r
+       request.handle = (net_nfc_target_handle_s*)handle;\r
+       request.trans_param = trans_param;\r
+\r
+       result = _net_nfc_client_send_reqeust((net_nfc_request_msg_t *)&request, NULL);\r
+\r
+       return result;\r
+}\r
+\r
+NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_current_tag_info(void* trans_param)\r
+{\r
+       net_nfc_error_e result = NET_NFC_OK;\r
+       net_nfc_request_get_current_tag_info_t request = { 0, };\r
+\r
+       request.length = sizeof(net_nfc_request_get_current_tag_info_t);\r
+       request.request_type = NET_NFC_MESSAGE_GET_CURRENT_TAG_INFO;\r
+       request.trans_param = trans_param;\r
+\r
+       result = _net_nfc_client_send_reqeust((net_nfc_request_msg_t *)&request, NULL);\r
+\r
+       return result;\r
+}\r
+\r
+\r
diff --git a/src/clientlib/net_nfc_client_tag_felica.c b/src/clientlib/net_nfc_client_tag_felica.c
new file mode 100644 (file)
index 0000000..1bda0b4
--- /dev/null
@@ -0,0 +1,461 @@
+/*\r
+  * Copyright 2012  Samsung Electronics Co., Ltd\r
+  *\r
+  * Licensed under the Flora License, Version 1.0 (the "License");\r
+  * you may not use this file except in compliance with the License.\r
+  * You may obtain a copy of the License at\r
+\r
+  *     http://www.tizenopensource.org/license\r
+  *\r
+  * Unless required by applicable law or agreed to in writing, software\r
+  * distributed under the License is distributed on an "AS IS" BASIS,\r
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+  * See the License for the specific language governing permissions and\r
+  * limitations under the License.\r
+  */\r
+\r
+#include "net_nfc_tag.h"\r
+#include "net_nfc_typedef_private.h"\r
+#include "net_nfc_client_ipc_private.h"\r
+#include "net_nfc_debug_private.h"\r
+#include "net_nfc_util_private.h"\r
+#include "net_nfc_client_nfc_private.h"\r
+#include "net_nfc_tag_felica.h"\r
+#include "net_nfc_target_info.h"\r
+\r
+#include <string.h>\r
+\r
+#ifndef NET_NFC_EXPORT_API\r
+#define NET_NFC_EXPORT_API __attribute__((visibility("default")))\r
+#endif\r
+\r
+#define FELICA_CMD_POLL 0x00\r
+#define FELICA_CMD_REQ_SERVICE 0x02\r
+#define FELICA_CMD_REQ_RESPONSE 0x04\r
+#define FELICA_CMD_READ_WITHOUT_ENC 0x06\r
+#define FELICA_CMD_WRITE_WITHOUT_ENC 0x08\r
+#define FELICA_CMD_REQ_SYSTEM_CODE 0x0C\r
+#define FELICA_TAG_KEY "IDm"\r
+\r
+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)\r
+{\r
+       if(handle == NULL)\r
+               return NET_NFC_NULL_PARAMETER;\r
+\r
+       if(!net_nfc_tag_is_connected()){\r
+               return NET_NFC_OPERATION_FAIL;\r
+       }\r
+\r
+       client_context_t* client_context_tmp = net_nfc_get_client_context();\r
+       net_nfc_target_info_s* target_info = NULL;\r
+\r
+       if((target_info = client_context_tmp->target_info) == NULL){\r
+               return NET_NFC_NO_DATA_FOUND;\r
+       }\r
+\r
+       if(target_info->devType != NET_NFC_FELICA_PICC){\r
+               DEBUG_CLIENT_MSG("only felica tag is available");\r
+               return NET_NFC_NOT_ALLOWED_OPERATION;\r
+       }\r
+\r
+       uint8_t send_buffer[6] = {0x00, };\r
+\r
+       /* total size of requet command */\r
+       send_buffer[0] = 0x06;\r
+       send_buffer[1] = FELICA_CMD_POLL;\r
+\r
+       /* use wild card for system code */\r
+       send_buffer[2] = 0xff;\r
+       send_buffer[3] = 0xff;\r
+\r
+       send_buffer[4] = req_code;\r
+       send_buffer[5] = time_slote;\r
+\r
+       DEBUG_MSG_PRINT_BUFFER(send_buffer, 6);\r
+\r
+       data_s rawdata;\r
+\r
+       rawdata.buffer = send_buffer;\r
+       rawdata.length = 6;\r
+\r
+       return net_nfc_transceive(handle, (data_h)&rawdata, trans_param);\r
+\r
+\r
+}\r
+\r
+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)\r
+{\r
+       if(handle == NULL || area_service_list == NULL)\r
+               return NET_NFC_NULL_PARAMETER;\r
+\r
+       if(!net_nfc_tag_is_connected()){\r
+               return NET_NFC_OPERATION_FAIL;\r
+       }\r
+\r
+       client_context_t* client_context_tmp = net_nfc_get_client_context();\r
+       net_nfc_target_info_s* target_info = NULL;\r
+\r
+       if((target_info = client_context_tmp->target_info) == NULL){\r
+               return NET_NFC_NO_DATA_FOUND;\r
+       }\r
+\r
+       if(target_info->devType != NET_NFC_FELICA_PICC){\r
+               DEBUG_CLIENT_MSG("only Jewel tag is available");\r
+               return NET_NFC_NOT_ALLOWED_OPERATION;\r
+       }\r
+\r
+       data_h IDm = NULL;\r
+\r
+       if(net_nfc_get_tag_info_value((net_nfc_target_info_h)target_info, FELICA_TAG_KEY, &IDm) != NET_NFC_OK){\r
+               return NET_NFC_NO_DATA_FOUND;\r
+       }\r
+\r
+\r
+       if(((data_s*)IDm)->length != 8){\r
+\r
+               return NET_NFC_OUT_OF_BOUND;\r
+       }\r
+\r
+       if(number_of_area_service > 32){\r
+               return NET_NFC_OUT_OF_BOUND;\r
+       }\r
+\r
+\r
+       uint32_t send_buffer_length = 1 + 1 + 8 + 1 + (2 * number_of_services); /* size + cmd + UID + number of service service count + service list */\r
+       uint8_t* send_buffer = NULL;\r
+       uint8_t* temp = NULL;\r
+\r
+       if((send_buffer = calloc(send_buffer_length, sizeof(uint8_t))) == NULL){\r
+               return NET_NFC_ALLOC_FAIL;\r
+       }\r
+\r
+       temp = send_buffer;\r
+\r
+       /* set cmd length */\r
+       *send_buffer = send_buffer_length;\r
+       send_buffer++;\r
+\r
+       /* set cmd */\r
+       *send_buffer = FELICA_CMD_REQ_SERVICE;\r
+       send_buffer++;\r
+\r
+       /* set IDm */\r
+       memcpy(send_buffer, ((data_s*)IDm)->buffer, ((data_s*)IDm)->length);\r
+       send_buffer = send_buffer + ((data_s*)IDm)->length;\r
+\r
+\r
+       /* set the number of service codes */\r
+       *send_buffer = number_of_area_service;\r
+       send_buffer++;\r
+\r
+       int i = 0;\r
+\r
+       for(; i < number_of_services; i++){\r
+               memcpy(send_buffer, &area_service_list[i], sizeof(uint16_t));\r
+               send_buffer = send_buffer + 2;\r
+       }\r
+\r
+       DEBUG_MSG_PRINT_BUFFER(temp, send_buffer_length);\r
+\r
+       data_s rawdata;\r
+\r
+       rawdata.buffer = send_buffer;\r
+       rawdata.length = send_buffer_length;\r
+\r
+       net_nfc_error_e result = NET_NFC_OK;\r
+       result = net_nfc_transceive(handle, (data_h)&rawdata, trans_param);\r
+\r
+       if(temp != NULL)\r
+               free(temp);\r
+\r
+       return result;\r
+}\r
+\r
+NET_NFC_EXPORT_API net_nfc_error_e net_nfc_felica_request_response (net_nfc_target_handle_h handle, void* trans_param)\r
+{\r
+       if(handle == NULL)\r
+               return NET_NFC_NULL_PARAMETER;\r
+\r
+       if(!net_nfc_tag_is_connected()){\r
+               return NET_NFC_OPERATION_FAIL;\r
+       }\r
+\r
+       client_context_t* client_context_tmp = net_nfc_get_client_context();\r
+       net_nfc_target_info_s* target_info = NULL;\r
+\r
+       if((target_info = client_context_tmp->target_info) == NULL){\r
+               return NET_NFC_NO_DATA_FOUND;\r
+       }\r
+\r
+       if(target_info->devType != NET_NFC_FELICA_PICC){\r
+               DEBUG_CLIENT_MSG("only Jewel tag is available");\r
+               return NET_NFC_NOT_ALLOWED_OPERATION;\r
+       }\r
+\r
+       data_h IDm = NULL;\r
+\r
+       if(net_nfc_get_tag_info_value((net_nfc_target_info_h)target_info, FELICA_TAG_KEY, &IDm) != NET_NFC_OK){\r
+               return NET_NFC_NO_DATA_FOUND;\r
+       }\r
+\r
+       if(((data_s*)IDm)->length != 8){\r
+\r
+               return NET_NFC_OUT_OF_BOUND;\r
+       }\r
+\r
+       uint8_t send_buffer[10] = {0x00, };\r
+\r
+       send_buffer[0] = 0xA;\r
+       send_buffer[1] = FELICA_CMD_REQ_RESPONSE;\r
+\r
+       memcpy(send_buffer + 2, ((data_s*)IDm)->buffer, ((data_s*)IDm)->length);\r
+\r
+       DEBUG_MSG_PRINT_BUFFER(send_buffer, 10);\r
+\r
+       data_s rawdata;\r
+\r
+       rawdata.buffer = send_buffer;\r
+       rawdata.length = 10;\r
+\r
+       return net_nfc_transceive(handle, (data_h)&rawdata, trans_param);\r
+\r
+}\r
+\r
+\r
+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)\r
+{\r
+       if(handle == NULL || service_list == NULL || block_list == NULL)\r
+               return NET_NFC_NULL_PARAMETER;\r
+\r
+       if(!net_nfc_tag_is_connected()){\r
+               return NET_NFC_OPERATION_FAIL;\r
+       }\r
+\r
+       client_context_t* client_context_tmp = net_nfc_get_client_context();\r
+       net_nfc_target_info_s* target_info = NULL;\r
+\r
+       if((target_info = client_context_tmp->target_info) == NULL){\r
+               return NET_NFC_NO_DATA_FOUND;\r
+       }\r
+\r
+       if(target_info->devType != NET_NFC_FELICA_PICC){\r
+               DEBUG_CLIENT_MSG("only Jewel tag is available");\r
+               return NET_NFC_NOT_ALLOWED_OPERATION;\r
+       }\r
+\r
+       data_h IDm = NULL;\r
+\r
+       if(net_nfc_get_tag_info_value((net_nfc_target_info_h)target_info, FELICA_TAG_KEY, &IDm) != NET_NFC_OK){\r
+               return NET_NFC_NO_DATA_FOUND;\r
+       }\r
+\r
+       if(((data_s*)IDm)->length != 8){\r
+\r
+               return NET_NFC_OUT_OF_BOUND;\r
+       }\r
+\r
+       if(number_of_services > 16 ){\r
+               return NET_NFC_OUT_OF_BOUND;\r
+       }\r
+\r
+       uint32_t send_buffer_length = 1 + 1 + 8 + 1 + (2 * number_of_services) + 1 + number_of_blocks;\r
+       uint8_t* send_buffer = NULL;\r
+       uint8_t* temp = NULL;\r
+\r
+       if((send_buffer = calloc(send_buffer_length, sizeof(uint8_t))) == NULL){\r
+               return NET_NFC_ALLOC_FAIL;\r
+       }\r
+\r
+       temp = send_buffer;\r
+\r
+       *send_buffer = send_buffer_length;\r
+       send_buffer++;\r
+\r
+       *send_buffer = FELICA_CMD_READ_WITHOUT_ENC;\r
+       send_buffer++;\r
+\r
+       memcpy(send_buffer, ((data_s*)IDm)->buffer, ((data_s*)IDm)->length);\r
+       send_buffer = send_buffer + ((data_s*)IDm)->length;\r
+\r
+       *send_buffer = number_of_services;\r
+       send_buffer++;\r
+\r
+       int i = 0;\r
+       for(; i < number_of_services; i++){\r
+               memcpy(send_buffer, &service_list[i], sizeof(uint16_t));\r
+               send_buffer = send_buffer + 2;\r
+       }\r
+\r
+       *send_buffer = number_of_blocks;\r
+       send_buffer++;\r
+\r
+       for(i=0; i < number_of_blocks; i++){\r
+               memcpy(send_buffer, &block_list[i], sizeof(uint8_t));\r
+               send_buffer++;\r
+       }\r
+\r
+       DEBUG_MSG_PRINT_BUFFER(temp, send_buffer_length);\r
+\r
+       data_s rawdata;\r
+\r
+       rawdata.buffer = temp;\r
+       rawdata.length = send_buffer_length;\r
+\r
+       net_nfc_error_e result = NET_NFC_OK;\r
+       result = net_nfc_transceive(handle, (data_h)&rawdata, trans_param);\r
+\r
+       if(temp != NULL)\r
+               free(temp);\r
+\r
+       return result;\r
+\r
+}\r
+\r
+\r
+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)\r
+{\r
+       if(handle == NULL || service_list == NULL || block_list == NULL || data == NULL)\r
+               return NET_NFC_NULL_PARAMETER;\r
+\r
+       if(!net_nfc_tag_is_connected()){\r
+               return NET_NFC_OPERATION_FAIL;\r
+       }\r
+\r
+       client_context_t* client_context_tmp = net_nfc_get_client_context();\r
+       net_nfc_target_info_s* target_info = NULL;\r
+\r
+       if((target_info = client_context_tmp->target_info) == NULL){\r
+               return NET_NFC_NO_DATA_FOUND;\r
+       }\r
+\r
+       if(target_info->devType != NET_NFC_FELICA_PICC){\r
+               DEBUG_CLIENT_MSG("only Jewel tag is available");\r
+               return NET_NFC_NOT_ALLOWED_OPERATION;\r
+       }\r
+\r
+       data_h IDm = NULL;\r
+\r
+       if(net_nfc_get_tag_info_value((net_nfc_target_info_h)target_info, FELICA_TAG_KEY, &IDm) != NET_NFC_OK){\r
+               return NET_NFC_NO_DATA_FOUND;\r
+       }\r
+\r
+       if(((data_s*)IDm)->length != 8){\r
+\r
+               return NET_NFC_OUT_OF_BOUND;\r
+       }\r
+\r
+       if(number_of_services > 16 ){\r
+               return NET_NFC_OUT_OF_BOUND;\r
+       }\r
+\r
+       if(((data_s*)data)->length > 16 * number_of_blocks){\r
+               return NET_NFC_OUT_OF_BOUND;\r
+       }\r
+\r
+       uint32_t send_buffer_length = 1 + 1 + 8 + 1 + (2 * number_of_services) + 1 + number_of_blocks + ((data_s*)data)->length;\r
+       uint8_t* send_buffer = NULL;\r
+       uint8_t* temp = NULL;\r
+\r
+       if((send_buffer = calloc(send_buffer_length, sizeof(uint8_t))) == NULL){\r
+               return NET_NFC_ALLOC_FAIL;\r
+       }\r
+\r
+       temp = send_buffer;\r
+\r
+       *send_buffer = send_buffer_length;\r
+       send_buffer++;\r
+\r
+       *send_buffer = FELICA_CMD_WRITE_WITHOUT_ENC;\r
+       send_buffer++;\r
+\r
+       memcpy(send_buffer, ((data_s*)IDm)->buffer, ((data_s*)IDm)->length);\r
+       send_buffer = send_buffer + ((data_s*)IDm)->length;\r
+\r
+       *send_buffer = number_of_services;\r
+       send_buffer++;\r
+\r
+       int i = 0;\r
+       for(; i < number_of_services; i++){\r
+               memcpy(send_buffer, &service_list[i], sizeof(uint16_t));\r
+               send_buffer = send_buffer + 2;\r
+       }\r
+\r
+       *send_buffer = number_of_blocks;\r
+       send_buffer++;\r
+\r
+       for(i=0; i < number_of_blocks; i++){\r
+               memcpy(send_buffer, &block_list[i], sizeof(uint8_t));\r
+               send_buffer++;\r
+       }\r
+\r
+       memcpy(send_buffer, ((data_s*)data)->buffer, ((data_s*)data)->length);\r
+\r
+       DEBUG_MSG_PRINT_BUFFER(temp, send_buffer_length);\r
+\r
+       data_s rawdata;\r
+\r
+       rawdata.buffer = temp;\r
+       rawdata.length = send_buffer_length;\r
+\r
+       net_nfc_error_e result = NET_NFC_OK;\r
+\r
+       result = net_nfc_transceive(handle, (data_h)&rawdata, trans_param);\r
+\r
+       if(temp != NULL)\r
+               free(temp);\r
+\r
+       return result;\r
+\r
+}\r
+\r
+\r
+NET_NFC_EXPORT_API net_nfc_error_e net_nfc_felica_request_system_code (net_nfc_target_handle_h handle, void* trans_param)\r
+{\r
+       if(handle == NULL)\r
+               return NET_NFC_NULL_PARAMETER;\r
+\r
+       if(!net_nfc_tag_is_connected()){\r
+               return NET_NFC_OPERATION_FAIL;\r
+       }\r
+\r
+       client_context_t* client_context_tmp = net_nfc_get_client_context();\r
+       net_nfc_target_info_s* target_info = NULL;\r
+\r
+       if((target_info = client_context_tmp->target_info) == NULL){\r
+               return NET_NFC_NO_DATA_FOUND;\r
+       }\r
+\r
+       if(target_info->devType != NET_NFC_FELICA_PICC){\r
+               DEBUG_CLIENT_MSG("only Jewel tag is available");\r
+               return NET_NFC_NOT_ALLOWED_OPERATION;\r
+       }\r
+\r
+       data_h IDm = NULL;\r
+\r
+       if(net_nfc_get_tag_info_value((net_nfc_target_info_h)target_info, FELICA_TAG_KEY, &IDm) != NET_NFC_OK){\r
+               return NET_NFC_NO_DATA_FOUND;\r
+       }\r
+\r
+       if(((data_s*)IDm)->length != 8){\r
+\r
+               return NET_NFC_OUT_OF_BOUND;\r
+       }\r
+\r
+       uint8_t send_buffer[10] = {0x00, };\r
+\r
+       send_buffer[0] = 0xA;\r
+       send_buffer[1] = FELICA_CMD_REQ_SYSTEM_CODE;\r
+\r
+       memcpy(send_buffer + 2, ((data_s *)IDm)->buffer, ((data_s *)IDm)->length);\r
+\r
+       DEBUG_MSG_PRINT_BUFFER(send_buffer, 10);\r
+\r
+       data_s rawdata;\r
+\r
+       rawdata.buffer = send_buffer;\r
+       rawdata.length = 10;\r
+\r
+       return net_nfc_transceive(handle, (data_h)&rawdata, trans_param);\r
+\r
+}\r
+\r
diff --git a/src/clientlib/net_nfc_client_tag_jewel.c b/src/clientlib/net_nfc_client_tag_jewel.c
new file mode 100644 (file)
index 0000000..4f4c340
--- /dev/null
@@ -0,0 +1,333 @@
+/*\r
+  * Copyright 2012  Samsung Electronics Co., Ltd\r
+  *\r
+  * Licensed under the Flora License, Version 1.0 (the "License");\r
+  * you may not use this file except in compliance with the License.\r
+  * You may obtain a copy of the License at\r
+\r
+  *     http://www.tizenopensource.org/license\r
+  *\r
+  * Unless required by applicable law or agreed to in writing, software\r
+  * distributed under the License is distributed on an "AS IS" BASIS,\r
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+  * See the License for the specific language governing permissions and\r
+  * limitations under the License.\r
+  */\r
+\r
+#include "net_nfc_tag.h"\r
+#include "net_nfc_typedef_private.h"\r
+#include "net_nfc_client_ipc_private.h"\r
+#include "net_nfc_debug_private.h"\r
+#include "net_nfc_util_private.h"\r
+#include "net_nfc_client_nfc_private.h"\r
+#include "net_nfc_tag_jewel.h"\r
+#include "net_nfc_target_info.h"\r
+\r
+#include <string.h>\r
+\r
+#ifndef NET_NFC_EXPORT_API\r
+#define NET_NFC_EXPORT_API __attribute__((visibility("default")))\r
+#endif\r
+\r
+\r
+\r
+#define JEWEL_CMD_REQA 0x26\r
+#define JEWEL_CMD_WUPA 0x52\r
+#define JEWEL_CMD_RID 0x78\r
+#define JEWEL_CMD_RALL 0x00\r
+#define JEWEL_CMD_READ 0x01\r
+#define JEWEL_CMD_WRITE_E 0x53\r
+#define JEWEL_CMD_WRITE_NE 0x1A\r
+#define JEWEL_TAG_KEY  "UID"\r
+\r
+NET_NFC_EXPORT_API net_nfc_error_e net_nfc_jewel_read_id (net_nfc_target_handle_h handle, void* trans_param)\r
+{\r
+       if(handle == NULL)\r
+               return NET_NFC_NULL_PARAMETER;\r
+\r
+       if(!net_nfc_tag_is_connected()){\r
+               return NET_NFC_OPERATION_FAIL;\r
+       }\r
+\r
+       client_context_t* client_context_tmp = net_nfc_get_client_context();\r
+       net_nfc_target_info_s* target_info = NULL;\r
+\r
+       if((target_info = client_context_tmp->target_info) == NULL){\r
+               return NET_NFC_NO_DATA_FOUND;\r
+       }\r
+\r
+       if(target_info->devType != NET_NFC_JEWEL_PICC){\r
+               DEBUG_CLIENT_MSG("only Jewel tag is available");\r
+               return NET_NFC_NOT_ALLOWED_OPERATION;\r
+       }\r
+\r
+       uint8_t send_buffer[9] = {0x00, };\r
+       send_buffer[0] = JEWEL_CMD_RID;\r
+\r
+       net_nfc_util_compute_CRC(CRC_B, send_buffer, 9);\r
+\r
+       DEBUG_MSG_PRINT_BUFFER(send_buffer, 9);\r
+\r
+       data_s rawdata;\r
+\r
+       rawdata.buffer = send_buffer;\r
+       rawdata.length = 9;\r
+\r
+       return net_nfc_transceive(handle, (data_h)&rawdata, trans_param);\r
+\r
+\r
+}\r
+\r
+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)\r
+{\r
+       if(handle == NULL)\r
+               return NET_NFC_NULL_PARAMETER;\r
+\r
+       if(block > 0xE || byte > 0x7 ){\r
+\r
+               return NET_NFC_OUT_OF_BOUND;\r
+       }\r
+\r
+       if(!net_nfc_tag_is_connected()){\r
+               return NET_NFC_OPERATION_FAIL;\r
+       }\r
+\r
+       client_context_t* client_context_tmp = net_nfc_get_client_context();\r
+       net_nfc_target_info_s* target_info = NULL;\r
+\r
+       if((target_info = client_context_tmp->target_info) == NULL){\r
+               return NET_NFC_NO_DATA_FOUND;\r
+       }\r
+\r
+       if(target_info->devType != NET_NFC_JEWEL_PICC){\r
+               DEBUG_CLIENT_MSG("only Jewel tag is available");\r
+               return NET_NFC_NOT_ALLOWED_OPERATION;\r
+       }\r
+\r
+       data_h UID = NULL;\r
+\r
+       if(net_nfc_get_tag_info_value((net_nfc_target_info_h)target_info, JEWEL_TAG_KEY, &UID) != NET_NFC_OK){\r
+               return NET_NFC_NO_DATA_FOUND;\r
+       }\r
+\r
+\r
+       if(((data_s*)UID)->length != 4){\r
+\r
+               return NET_NFC_OUT_OF_BOUND;\r
+       }\r
+\r
+       uint8_t send_buffer[9] = {0x00, };\r
+\r
+       /* command */\r
+       send_buffer[0] = JEWEL_CMD_READ;\r
+\r
+       /* addr */\r
+       send_buffer[1] = (((block << 3) & 0x78) | (byte & 0x7));\r
+\r
+       /* data */\r
+       send_buffer[2] = 0x00;\r
+\r
+       /* UID0 ~ 3 */\r
+       memcpy(&(send_buffer[3]), ((data_s*)UID)->buffer, ((data_s*)UID)->length);\r
+\r
+       net_nfc_util_compute_CRC(CRC_B, send_buffer, 9);\r
+\r
+       DEBUG_MSG_PRINT_BUFFER(send_buffer, 9);\r
+\r
+       data_s rawdata;\r
+\r
+       rawdata.buffer = send_buffer;\r
+       rawdata.length = 9;\r
+\r
+       return net_nfc_transceive(handle, (data_h)&rawdata, trans_param);\r
+}\r
+\r
+NET_NFC_EXPORT_API net_nfc_error_e net_nfc_jewel_read_all (net_nfc_target_handle_h handle, void* trans_param)\r
+{\r
+       if(handle == NULL )\r
+               return NET_NFC_NULL_PARAMETER;\r
+\r
+       if(!net_nfc_tag_is_connected()){\r
+               return NET_NFC_OPERATION_FAIL;\r
+       }\r
+\r
+       client_context_t* client_context_tmp = net_nfc_get_client_context();\r
+       net_nfc_target_info_s* target_info = NULL;\r
+\r
+       if((target_info = client_context_tmp->target_info) == NULL){\r
+               return NET_NFC_NO_DATA_FOUND;\r
+       }\r
+\r
+       if(target_info->devType != NET_NFC_JEWEL_PICC){\r
+               DEBUG_CLIENT_MSG("only Jewel tag is available");\r
+               return NET_NFC_NOT_ALLOWED_OPERATION;\r
+       }\r
+\r
+       data_h UID = NULL;\r
+\r
+       if(net_nfc_get_tag_info_value((net_nfc_target_info_h)target_info, JEWEL_TAG_KEY, &UID) != NET_NFC_OK){\r
+               return NET_NFC_NO_DATA_FOUND;\r
+       }\r
+\r
+       if(((data_s*)UID)->length != 4){\r
+\r
+               return NET_NFC_OUT_OF_BOUND;\r
+       }\r
+\r
+       uint8_t send_buffer[9] = {0x00, };\r
+\r
+       /* command */\r
+       send_buffer[0] = JEWEL_CMD_RALL;\r
+\r
+       /* addr */\r
+       send_buffer[1] = 0x00;\r
+\r
+       /* data */\r
+       send_buffer[2] = 0x00;\r
+\r
+       /* UID0 ~ 3 */\r
+       memcpy(&(send_buffer[3]), ((data_s*)UID)->buffer, ((data_s*)UID)->length);\r
+\r
+       net_nfc_util_compute_CRC(CRC_B, send_buffer, 9);\r
+\r
+       DEBUG_MSG_PRINT_BUFFER(send_buffer, 9);\r
+\r
+\r
+       data_s rawdata;\r
+\r
+       rawdata.buffer = send_buffer;\r
+       rawdata.length = 9;\r
+\r
+       return net_nfc_transceive(handle, (data_h)&rawdata, trans_param);\r
+\r
+\r
+}\r
+\r
+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)\r
+{\r
+       if(handle == NULL)\r
+               return NET_NFC_NULL_PARAMETER;\r
+\r
+\r
+       if(block > 0xE || byte > 0x7 ){\r
+\r
+               return NET_NFC_OUT_OF_BOUND;\r
+       }\r
+\r
+       if(!net_nfc_tag_is_connected()){\r
+               return NET_NFC_OPERATION_FAIL;\r
+       }\r
+\r
+       client_context_t* client_context_tmp = net_nfc_get_client_context();\r
+       net_nfc_target_info_s* target_info = NULL;\r
+\r
+       if((target_info = client_context_tmp->target_info) == NULL){\r
+               return NET_NFC_NO_DATA_FOUND;\r
+       }\r
+\r
+       if((target_info = client_context_tmp->target_info) == NULL){\r
+               return NET_NFC_NO_DATA_FOUND;\r
+       }\r
+\r
+       data_h UID = NULL;\r
+\r
+       if(net_nfc_get_tag_info_value((net_nfc_target_info_h)target_info, JEWEL_TAG_KEY, &UID) != NET_NFC_OK){\r
+               return NET_NFC_NO_DATA_FOUND;\r
+       }\r
+\r
+       if(((data_s*)UID)->length != 4){\r
+\r
+               return NET_NFC_OUT_OF_BOUND;\r
+       }\r
+\r
+\r
+       uint8_t send_buffer[9] = {0x00, };\r
+\r
+       /* command */\r
+       send_buffer[0] = JEWEL_CMD_WRITE_E;\r
+\r
+       /* addr */\r
+       send_buffer[1] = (((block << 3) & 0x78) | (byte & 0x7));\r
+\r
+       /* data */\r
+       send_buffer[2] = data;\r
+\r
+       /* UID0 ~ 3 */\r
+       memcpy(&(send_buffer[3]), ((data_s*)UID)->buffer, ((data_s*)UID)->length);\r
+\r
+       net_nfc_util_compute_CRC(CRC_B, send_buffer, 9);\r
+\r
+       DEBUG_MSG_PRINT_BUFFER(send_buffer, 9);\r
+\r
+       data_s rawdata;\r
+\r
+       rawdata.buffer = send_buffer;\r
+       rawdata.length = 9;\r
+\r
+       return net_nfc_transceive(handle, (data_h)&rawdata, trans_param);\r
+\r
+}\r
+\r
+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)\r
+{\r
+       if(handle == NULL)\r
+               return NET_NFC_NULL_PARAMETER;\r
+\r
+       if(block > 0xE || byte > 0x7 ){\r
+\r
+               return NET_NFC_OUT_OF_BOUND;\r
+       }\r
+\r
+       if(!net_nfc_tag_is_connected()){\r
+               return NET_NFC_OPERATION_FAIL;\r
+       }\r
+\r
+       client_context_t* client_context_tmp = net_nfc_get_client_context();\r
+       net_nfc_target_info_s* target_info = NULL;\r
+\r
+       if((target_info = client_context_tmp->target_info) == NULL){\r
+               return NET_NFC_NO_DATA_FOUND;\r
+       }\r
+\r
+       if(target_info->devType != NET_NFC_JEWEL_PICC){\r
+               DEBUG_CLIENT_MSG("only Jewel tag is available");\r
+               return NET_NFC_NOT_ALLOWED_OPERATION;\r
+       }\r
+\r
+       data_h UID = NULL;\r
+\r
+       if(net_nfc_get_tag_info_value((net_nfc_target_info_h)target_info, JEWEL_TAG_KEY, &UID) != NET_NFC_OK){\r
+               return NET_NFC_NO_DATA_FOUND;\r
+       }\r
+\r
+       if(((data_s*)UID)->length != 4){\r
+\r
+               return NET_NFC_OUT_OF_BOUND;\r
+       }\r
+\r
+       uint8_t send_buffer[9] = {0x00, };\r
+\r
+       /* command */\r
+       send_buffer[0] = JEWEL_CMD_WRITE_NE;\r
+\r
+       /* addr */\r
+       send_buffer[1] = (((block << 3) & 0x78) | (byte & 0x7));\r
+\r
+       /* data */\r
+       send_buffer[2] = data;\r
+\r
+       /* UID0 ~ 3 */\r
+       memcpy(&(send_buffer[3]), ((data_s*)UID)->buffer, ((data_s*)UID)->length);\r
+\r
+       net_nfc_util_compute_CRC(CRC_B, send_buffer, 9);\r
+\r
+       DEBUG_MSG_PRINT_BUFFER(send_buffer, 9);\r
+\r
+       data_s rawdata;\r
+\r
+       rawdata.buffer = send_buffer;\r
+       rawdata.length = 9;\r
+\r
+       return net_nfc_transceive(handle, (data_h)&rawdata, trans_param);\r
+}\r
+\r
diff --git a/src/clientlib/net_nfc_client_tag_mifare.c b/src/clientlib/net_nfc_client_tag_mifare.c
new file mode 100644 (file)
index 0000000..b2bc2eb
--- /dev/null
@@ -0,0 +1,852 @@
+/*\r
+  * Copyright 2012  Samsung Electronics Co., Ltd\r
+  *\r
+  * Licensed under the Flora License, Version 1.0 (the "License");\r
+  * you may not use this file except in compliance with the License.\r
+  * You may obtain a copy of the License at\r
+\r
+  *     http://www.tizenopensource.org/license\r
+  *\r
+  * Unless required by applicable law or agreed to in writing, software\r
+  * distributed under the License is distributed on an "AS IS" BASIS,\r
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+  * See the License for the specific language governing permissions and\r
+  * limitations under the License.\r
+  */\r
+\r
+#include "net_nfc_tag.h"\r
+#include "net_nfc_data.h"\r
+#include "net_nfc_typedef_private.h"\r
+#include "net_nfc_client_ipc_private.h"\r
+#include "net_nfc_debug_private.h"\r
+#include "net_nfc_client_nfc_private.h"\r
+#include "net_nfc_tag_mifare.h"\r
+#include "net_nfc_target_info.h"\r
+#include "net_nfc_util_private.h"\r
+\r
+#include <string.h>\r
+\r
+#ifndef NET_NFC_EXPORT_API\r
+#define NET_NFC_EXPORT_API __attribute__((visibility("default")))\r
+#endif\r
+\r
+\r
+#define MIFARE_CMD_RAW                 0x00U\r
+#define MIFARE_CMD_AUTH_A              0x60U /**< authenticate with key A */\r
+#define MIFARE_CMD_AUTH_B                      0x61U /**< authenticate with key B */\r
+#define MIFARE_CMD_READ                        0x30U /**< read 16 bytes */\r
+#define MIFARE_CMD_WRITE_BLOCK         0xA0U /**< write 16 bytes */\r
+#define MIFARE_CMD_WRITE_PAGE  0xA2U /**< write 4 bytes */\r
+#define MIFARE_CMD_INCREMENT           0xC1U /**< Increment. */\r
+#define MIFARE_CMD_DECREMENT           0xC0U /**< Decrement. */\r
+#define MIFARE_CMD_TRANSFER            0xB0U /**< Tranfer.   */\r
+#define MIFARE_CMD_RESTORE             0xC2U /**< Restore.   */\r
+#define MIFARE_TAG_KEY "UID"\r
+\r
+#define MIFARE_CMD_READ_SECTOR 0x38U /* read sector */\r
+#define MIFARE_CMD_WRITE_SECTOR        0xA8U /* write sector */\r
+\r
+static uint8_t default_key[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};\r
+static uint8_t mad_key[6] = {0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5};\r
+static uint8_t net_nfc_forum_key[6] = {0xD3, 0xF7, 0xD3, 0xF7, 0xD3, 0xF7};\r
+\r
+#define MIFARE_BLOCK_4 4\r
+#define MIFARE_BLOCK_16 16\r
+\r
+#define MIFARE_MINI_SECTORS 5\r
+#define MIFARE_1K_SECTORS 16\r
+#define MIFARE_4K_SECTORS 40\r
+\r
+#define MIFARE_BLOCK_SIZE 16   /* 1 block is 16 byte */\r
+#define MIFARE_PAGE_SIZE 4     /* 1 page is 4 byte */\r
+\r
+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)\r
+{\r
+       if(handle == NULL || auth_key == NULL)\r
+               return NET_NFC_NULL_PARAMETER;\r
+\r
+       if(!net_nfc_tag_is_connected()){\r
+               return NET_NFC_OPERATION_FAIL;\r
+       }\r
+\r
+       data_s* key = (data_s*)auth_key;\r
+\r
+       if(key->length != 6){\r
+               return NET_NFC_OUT_OF_BOUND;\r
+       }\r
+\r
+       client_context_t* tmp_client_context = net_nfc_get_client_context();\r
+\r
+       net_nfc_target_info_s* target_info = NULL;\r
+\r
+       if(tmp_client_context != NULL){\r
+\r
+               target_info = tmp_client_context->target_info;\r
+\r
+               if(target_info != NULL){\r
+\r
+                       if(target_info->devType < NET_NFC_MIFARE_MINI_PICC || target_info->devType > NET_NFC_MIFARE_4K_PICC){\r
+                               DEBUG_CLIENT_MSG("This is not MIFARE Classic TAG \n");\r
+                               return NET_NFC_NOT_SUPPORTED;\r
+                       }\r
+               }\r
+       }\r
+\r
+       data_h UID = NULL;\r
+\r
+       if(net_nfc_get_tag_info_value((net_nfc_target_info_h)target_info, MIFARE_TAG_KEY, &UID) != NET_NFC_OK){\r
+               return NET_NFC_NO_DATA_FOUND;\r
+       }\r
+\r
+       uint8_t* send_buffer = NULL;\r
+       int send_buffer_length = 0;\r
+\r
+       uint8_t sector_to_block = 0;\r
+\r
+       switch(target_info->devType){\r
+               case NET_NFC_MIFARE_MINI_PICC:\r
+               {\r
+                       /* 0 ~ 4 : 5 sector and 4 block with 16 bytes */\r
+                       if(sector > MIFARE_MINI_SECTORS - 1){\r
+\r
+                               return NET_NFC_OUT_OF_BOUND;\r
+                       }\r
+                       else{\r
+\r
+                               sector_to_block = sector * MIFARE_BLOCK_4 + 3;\r
+                       }\r
+               }\r
+               break;\r
+               case NET_NFC_MIFARE_1K_PICC:\r
+               {\r
+                       /* 0 ~ 15 : 16 sector and 4 block with 16 bytes */\r
+                       if(sector > MIFARE_1K_SECTORS){\r
+\r
+                               return NET_NFC_OUT_OF_BOUND;\r
+                       }\r
+                       else{\r
+\r
+                               sector_to_block = sector * MIFARE_BLOCK_4 + 3;\r
+                       }\r
+               }\r
+               break;\r
+               case NET_NFC_MIFARE_4K_PICC:\r
+               {\r
+                       /* 0 ~ 31 : 32 sector and 4 block with 16 bytes\r
+                         * 32 ~ 39 : 8 sector and 16 block with 16 bytes\r
+                         */\r
+                       if(sector > MIFARE_4K_SECTORS){\r
+\r
+                               return NET_NFC_OUT_OF_BOUND;\r
+                       }\r
+                       else{\r
+\r
+                               if(sector < 32){\r
+\r
+                                       sector_to_block = sector * MIFARE_BLOCK_4 + 3;\r
+                               }else{\r
+\r
+                                       sector_to_block = (31 * MIFARE_BLOCK_4 + 3) + (sector - 32) * MIFARE_BLOCK_16 + 15;\r
+                               }\r
+                       }\r
+               }\r
+                       break;\r
+               default:\r
+                       break;\r
+       }\r
+\r
+       uint8_t* temp = NULL;\r
+       send_buffer_length = 1 + 1 + ((data_s*)UID)->length + key->length + 2; /* cmd + addr + UID + AUTH_KEY + CRC_A */\r
+\r
+       if((send_buffer = calloc(send_buffer_length , sizeof(uint8_t))) == NULL){\r
+\r
+               net_nfc_free_data(UID);\r
+               return NET_NFC_ALLOC_FAIL;\r
+       }\r
+\r
+       temp = send_buffer;\r
+\r
+       *temp = MIFARE_CMD_AUTH_A;\r
+       temp++;\r
+\r
+       *temp = sector_to_block;\r
+       temp++;\r
+\r
+       memcpy(temp, ((data_s*)UID)->buffer, ((data_s*)UID)->length);\r
+       temp = temp + ((data_s*)UID)->length;\r
+\r
+       memcpy(temp, key->buffer, key->length);\r
+\r
+       net_nfc_util_compute_CRC(CRC_A, send_buffer, send_buffer_length);\r
+\r
+       data_s rawdata ;\r
+\r
+       rawdata.buffer = send_buffer;\r
+       rawdata.length = send_buffer_length;\r
+\r
+       net_nfc_error_e result = net_nfc_transceive(handle, (data_h)&rawdata, trans_param);\r
+\r
+       if(send_buffer != NULL){\r
+\r
+               free(send_buffer);\r
+       }\r
+\r
+       return result;\r
+\r
+}\r
+\r
+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)\r
+{\r
+       if(handle == NULL || auth_key == NULL)\r
+               return NET_NFC_NULL_PARAMETER;\r
+\r
+       if(!net_nfc_tag_is_connected()){\r
+               return NET_NFC_OPERATION_FAIL;\r
+       }\r
+\r
+       data_s* key = (data_s*)auth_key;\r
+\r
+       if(key->length != 6){\r
+               return NET_NFC_OUT_OF_BOUND;\r
+       }\r
+\r
+       client_context_t* tmp_client_context = net_nfc_get_client_context();\r
+\r
+       net_nfc_target_info_s* target_info = NULL;\r
+\r
+       if(tmp_client_context != NULL){\r
+\r
+               target_info = tmp_client_context->target_info;\r
+\r
+               if(target_info != NULL){\r
+\r
+                       if(target_info->devType < NET_NFC_MIFARE_MINI_PICC || target_info->devType > NET_NFC_MIFARE_4K_PICC){\r
+                               DEBUG_CLIENT_MSG("This is not MIFARE Classic TAG \n");\r
+                               return NET_NFC_NOT_SUPPORTED;\r
+                       }\r
+               }\r
+       }\r
+\r
+       data_h UID = NULL;\r
+\r
+       if(net_nfc_get_tag_info_value((net_nfc_target_info_h)target_info, MIFARE_TAG_KEY, &UID) != NET_NFC_OK){\r
+               return NET_NFC_NO_DATA_FOUND;\r
+       }\r
+\r
+\r
+       uint8_t* send_buffer = NULL;\r
+       int send_buffer_length = 0;\r
+\r
+       uint8_t sector_to_block = 0;\r
+\r
+       switch(target_info->devType){\r
+               case NET_NFC_MIFARE_MINI_PICC:\r
+               {\r
+                       /* 0 ~ 4 : 5 sector and 4 block with 16 bytes */\r
+                       if(sector > MIFARE_MINI_SECTORS){\r
+                               return NET_NFC_OUT_OF_BOUND;\r
+                       }\r
+                       else{\r
+                               sector_to_block = sector * MIFARE_BLOCK_4 + 3;\r
+                       }\r
+               }\r
+               break;\r
+               case NET_NFC_MIFARE_1K_PICC:\r
+               {\r
+                       /* 0 ~ 15 : 16 sector and 4 block with 16 bytes */\r
+                       if(sector > MIFARE_1K_SECTORS){\r
+                               return NET_NFC_OUT_OF_BOUND;\r
+                       }\r
+                       else{\r
+                               sector_to_block = sector * MIFARE_BLOCK_4 + 3;\r
+                       }\r
+               }\r
+               break;\r
+               case NET_NFC_MIFARE_4K_PICC:\r
+               {\r
+                       /* 0 ~ 31 : 32 sector and 4 block with 16 bytes\r
+                         * 32 ~ 39 : 8 sector and 16 block with 16 bytes\r
+                         */\r
+                       if(sector > MIFARE_4K_SECTORS){\r
+                               return NET_NFC_OUT_OF_BOUND;\r
+                       }\r
+                       else{\r
+                               if(sector < 32){\r
+                                       sector_to_block = sector * MIFARE_BLOCK_4 + 3;\r
+                               }else{\r
+                                       sector_to_block = (31 * MIFARE_BLOCK_4 + 3) + (sector - 32) * MIFARE_BLOCK_16+ 15;\r
+                               }\r
+                       }\r
+               }\r
+                       break;\r
+               default:\r
+                       break;\r
+       }\r
+\r
+\r
+       uint8_t* temp = NULL;\r
+       send_buffer_length = 1 + 1 + ((data_s*)UID)->length + key->length + 2; /* cmd + addr + UID + AUTH_KEY + CRC_A */\r
+\r
+       if((send_buffer = calloc(send_buffer_length , sizeof(uint8_t))) == NULL){\r
+\r
+               net_nfc_free_data(UID);\r
+               return NET_NFC_ALLOC_FAIL;\r
+       }\r
+\r
+       temp = send_buffer;\r
+\r
+       *temp = MIFARE_CMD_AUTH_B;\r
+       temp++;\r
+\r
+       *temp = sector_to_block;\r
+       temp++;\r
+\r
+       memcpy(temp, ((data_s*)UID)->buffer, ((data_s*)UID)->length);\r
+       temp = temp + ((data_s*)UID)->length;\r
+\r
+       memcpy(temp, key->buffer, key->length);\r
+\r
+       net_nfc_util_compute_CRC(CRC_A, send_buffer, send_buffer_length);\r
+\r
+       data_s rawdata;\r
+\r
+       rawdata.buffer = send_buffer;\r
+       rawdata.length = send_buffer_length;\r
+\r
+       net_nfc_error_e result = net_nfc_transceive(handle, (data_h)&rawdata, trans_param);\r
+\r
+       if(send_buffer != NULL){\r
+               free(send_buffer);\r
+       }\r
+\r
+       return result;\r
+\r
+}\r
+\r
+NET_NFC_EXPORT_API net_nfc_error_e net_nfc_mifare_read(net_nfc_target_handle_h handle, uint8_t addr, void* trans_param)\r
+{\r
+       if(handle == NULL)\r
+               return NET_NFC_NULL_PARAMETER;\r
+\r
+       if(!net_nfc_tag_is_connected()){\r
+               return NET_NFC_OPERATION_FAIL;\r
+       }\r
+\r
+       client_context_t* tmp_client_context = net_nfc_get_client_context();\r
+\r
+       net_nfc_target_info_s* target_info = NULL;\r
+\r
+       if(tmp_client_context != NULL){\r
+\r
+               target_info = tmp_client_context->target_info;\r
+\r
+               if(target_info != NULL){\r
+\r
+                       if(target_info->devType < NET_NFC_MIFARE_MINI_PICC || target_info->devType > NET_NFC_MIFARE_ULTRA_PICC){\r
+                               DEBUG_CLIENT_MSG("This is not MIFARE TAG = [%d] \n", target_info->devType);\r
+                               return NET_NFC_NOT_SUPPORTED;\r
+                       }\r
+\r
+                       if(target_info->devType == NET_NFC_MIFARE_ULTRA_PICC ){\r
+\r
+                               if(addr > 7){\r
+                                       return NET_NFC_OUT_OF_BOUND;\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+\r
+       uint8_t send_buffer[4] = {0};\r
+\r
+       send_buffer[0] = MIFARE_CMD_READ;\r
+       send_buffer[1] = addr;\r
+\r
+       net_nfc_util_compute_CRC(CRC_A, send_buffer, 4);\r
+\r
+       data_s rawdata;\r
+\r
+       rawdata.buffer = send_buffer;\r
+       rawdata.length = 4;\r
+\r
+       return net_nfc_transceive(handle, (data_h)&rawdata, trans_param);\r
+}\r
+\r
+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)\r
+{\r
+       if(handle == NULL)\r
+               return NET_NFC_NULL_PARAMETER;\r
+\r
+       if(!net_nfc_tag_is_connected()){\r
+               return NET_NFC_OPERATION_FAIL;\r
+       }\r
+\r
+       client_context_t* tmp_client_context = net_nfc_get_client_context();\r
+\r
+       net_nfc_target_info_s* target_info = NULL;\r
+\r
+       if(tmp_client_context != NULL){\r
+\r
+               target_info = tmp_client_context->target_info;\r
+\r
+               if(target_info != NULL){\r
+\r
+                       if(target_info->devType < NET_NFC_MIFARE_MINI_PICC || target_info->devType > NET_NFC_MIFARE_ULTRA_PICC){\r
+                               DEBUG_CLIENT_MSG("This is not MIFARE TAG = [%d] \n", target_info->devType);\r
+                               return NET_NFC_NOT_SUPPORTED;\r
+                       }\r
+\r
+                       if(target_info->devType == NET_NFC_MIFARE_ULTRA_PICC ){\r
+\r
+                               if(addr > 7){\r
+                                       return NET_NFC_OUT_OF_BOUND;\r
+                               }\r
+                       }\r
+               }\r
+               else {\r
+                       return NET_NFC_NOT_INITIALIZED;\r
+               }\r
+       }\r
+\r
+       uint8_t* send_buffer = NULL;\r
+       uint32_t send_buffer_length = 0;\r
+\r
+       if(target_info->devType == NET_NFC_MIFARE_ULTRA_PICC){\r
+\r
+               if(((data_s*)data)->length > MIFARE_PAGE_SIZE){\r
+\r
+                       send_buffer_length = 1 + 1 + MIFARE_PAGE_SIZE + 2; /* cmd + addr + page + CRC */\r
+\r
+                       uint8_t* temp = NULL;\r
+                       if((send_buffer = calloc(send_buffer_length, sizeof(uint8_t))) == NULL)\r
+                               return NET_NFC_ALLOC_FAIL;\r
+\r
+                       temp = send_buffer;\r
+\r
+                       *temp = MIFARE_CMD_WRITE_PAGE;\r
+                       temp++;\r
+\r
+                       *temp = addr;\r
+                       temp++;\r
+\r
+                       memcpy(temp, ((data_s*)data)->buffer, MIFARE_PAGE_SIZE);\r
+\r
+               }\r
+               else{\r
+\r
+                       send_buffer_length = 1 + 1 + ((data_s*)data)->length + 2; /* cmd + addr + page + CRC */\r
+\r
+                       uint8_t* temp = NULL;\r
+                       if((send_buffer = calloc(send_buffer_length, sizeof(uint8_t))) == NULL)\r
+                               return NET_NFC_ALLOC_FAIL;\r
+\r
+                       temp = send_buffer;\r
+\r
+                       *temp = MIFARE_CMD_WRITE_PAGE;\r
+                       temp++;\r
+\r
+                       *temp = addr;\r
+                       temp++;\r
+\r
+                       memcpy(temp, ((data_s*)data)->buffer, ((data_s*)data)->length);\r
+               }\r
+\r
+       }\r
+       else{\r
+\r
+               if(((data_s*)data)->length > MIFARE_BLOCK_SIZE){\r
+\r
+                       send_buffer_length = 1 + 1 + MIFARE_BLOCK_SIZE + 2; /* cmd + addr + page + CRC */\r
+\r
+                       uint8_t* temp = NULL;\r
+                       if((send_buffer = calloc(send_buffer_length, sizeof(uint8_t))) == NULL)\r
+                               return NET_NFC_ALLOC_FAIL;\r
+\r
+                       temp = send_buffer;\r
+\r
+                       *temp = MIFARE_CMD_WRITE_BLOCK;\r
+                       temp++;\r
+\r
+                       *temp = addr;\r
+                       temp++;\r
+\r
+                       memcpy(temp, ((data_s*)data)->buffer, MIFARE_BLOCK_SIZE);\r
+               }\r
+               else{\r
+                       send_buffer_length = 1 + 1 + ((data_s*)data)->length + 2; /* cmd + addr + page + CRC */\r
+\r
+                       uint8_t* temp = NULL;\r
+                       if((send_buffer = calloc(send_buffer_length, sizeof(uint8_t))) == NULL)\r
+                               return NET_NFC_ALLOC_FAIL;\r
+\r
+                       temp = send_buffer;\r
+\r
+                       *temp = MIFARE_CMD_WRITE_BLOCK;\r
+                       temp++;\r
+\r
+                       *temp = addr;\r
+                       temp++;\r
+\r
+                       memcpy(temp, ((data_s*)data)->buffer, ((data_s*)data)->length);\r
+               }\r
+       }\r
+\r
+       net_nfc_util_compute_CRC(CRC_A, send_buffer, send_buffer_length);\r
+\r
+       data_s rawdata;\r
+\r
+       rawdata.buffer = send_buffer;\r
+       rawdata.length = send_buffer_length;\r
+\r
+       net_nfc_error_e result = net_nfc_transceive(handle, (data_h)&rawdata, trans_param);\r
+\r
+       if(send_buffer != NULL)\r
+               free(send_buffer);\r
+\r
+       return result;\r
+}\r
+\r
+\r
+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)\r
+{\r
+       if(handle == NULL)\r
+               return NET_NFC_NULL_PARAMETER;\r
+\r
+       if(!net_nfc_tag_is_connected()){\r
+               return NET_NFC_OPERATION_FAIL;\r
+       }\r
+\r
+       client_context_t* tmp_client_context = net_nfc_get_client_context();\r
+\r
+       net_nfc_target_info_s* target_info = NULL;\r
+\r
+       if(tmp_client_context != NULL){\r
+\r
+               target_info = tmp_client_context->target_info;\r
+\r
+               if(target_info != NULL){\r
+\r
+                       if(target_info->devType < NET_NFC_MIFARE_MINI_PICC || target_info->devType > NET_NFC_MIFARE_ULTRA_PICC){\r
+                               DEBUG_CLIENT_MSG("This is not MIFARE TAG = [%d] \n", target_info->devType);\r
+                               return NET_NFC_NOT_SUPPORTED;\r
+                       }\r
+\r
+                       if(target_info->devType == NET_NFC_MIFARE_ULTRA_PICC ){\r
+\r
+                               if(addr > 7){\r
+                                       return NET_NFC_OUT_OF_BOUND;\r
+                               }\r
+                       }\r
+               }\r
+               else {\r
+                       return NET_NFC_NOT_INITIALIZED;\r
+               }\r
+       }\r
+\r
+       uint8_t* send_buffer = NULL;\r
+       uint32_t send_buffer_length = 0;\r
+\r
+       if(target_info->devType == NET_NFC_MIFARE_ULTRA_PICC){\r
+\r
+               if(((data_s*)data)->length > MIFARE_PAGE_SIZE){\r
+\r
+                       send_buffer_length = 1 + 1 + MIFARE_PAGE_SIZE + 2; /* cmd + addr + page + CRC */\r
+\r
+                       uint8_t* temp = NULL;\r
+                       if((send_buffer = calloc(send_buffer_length, sizeof(uint8_t))) == NULL)\r
+                               return NET_NFC_ALLOC_FAIL;\r
+\r
+                       temp = send_buffer;\r
+\r
+                       *temp = MIFARE_CMD_WRITE_PAGE;\r
+                       temp++;\r
+\r
+                       *temp = addr;\r
+                       temp++;\r
+\r
+                       memcpy(temp, ((data_s*)data)->buffer, MIFARE_PAGE_SIZE);\r
+\r
+               }\r
+               else{\r
+\r
+                       send_buffer_length = 1 + 1 + ((data_s*)data)->length + 2; /* cmd + addr + page + CRC */\r
+\r
+                       uint8_t* temp = NULL;\r
+                       if((send_buffer = calloc(send_buffer_length, sizeof(uint8_t))) == NULL)\r
+                               return NET_NFC_ALLOC_FAIL;\r
+\r
+                       temp = send_buffer;\r
+\r
+                       *temp = MIFARE_CMD_WRITE_PAGE;\r
+                       temp++;\r
+\r
+                       *temp = addr;\r
+                       temp++;\r
+\r
+                       memcpy(temp, ((data_s*)data)->buffer, ((data_s*)data)->length);\r
+               }\r
+\r
+       }\r
+       else{\r
+\r
+               if(((data_s*)data)->length > MIFARE_PAGE_SIZE){\r
+\r
+                       send_buffer_length = 1 + 1 + MIFARE_PAGE_SIZE + 2; /* cmd + addr + page + CRC */\r
+\r
+                       uint8_t* temp = NULL;\r
+                       if((send_buffer = calloc(send_buffer_length, sizeof(uint8_t))) == NULL)\r
+                               return NET_NFC_ALLOC_FAIL;\r
+\r
+                       temp = send_buffer;\r
+\r
+                       *temp = MIFARE_CMD_WRITE_BLOCK;\r
+                       temp++;\r
+\r
+                       *temp = addr;\r
+                       temp++;\r
+\r
+                       memcpy(temp, ((data_s*)data)->buffer, MIFARE_PAGE_SIZE);\r
+\r
+               }\r
+               else{\r
+\r
+                       send_buffer_length = 1 + 1 + ((data_s*)data)->length + 2; /* cmd + addr + page + CRC */\r
+\r
+                       uint8_t* temp = NULL;\r
+                       if((send_buffer = calloc(send_buffer_length, sizeof(uint8_t))) == NULL)\r
+                               return NET_NFC_ALLOC_FAIL;\r
+\r
+                       temp = send_buffer;\r
+\r
+                       *temp = MIFARE_CMD_WRITE_BLOCK;\r
+                       temp++;\r
+\r
+                       *temp = addr;\r
+                       temp++;\r
+\r
+                       memcpy(temp, ((data_s*)data)->buffer, ((data_s*)data)->length);\r
+               }\r
+\r
+       }\r
+\r
+       net_nfc_util_compute_CRC(CRC_A, send_buffer, send_buffer_length);\r
+\r
+       data_s rawdata;\r
+\r
+       rawdata.buffer = send_buffer;\r
+       rawdata.length = send_buffer_length;\r
+\r
+       net_nfc_error_e result = net_nfc_transceive(handle, (data_h)&rawdata, trans_param);\r
+\r
+       if(send_buffer != NULL)\r
+               free(send_buffer);\r
+\r
+       return result;\r
+}\r
+\r
+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)\r
+{\r
+       if(handle == NULL)\r
+               return NET_NFC_NULL_PARAMETER;\r
+\r
+       if(!net_nfc_tag_is_connected()){\r
+               return NET_NFC_OPERATION_FAIL;\r
+       }\r
+\r
+       client_context_t* tmp_client_context = net_nfc_get_client_context();\r
+\r
+       net_nfc_target_info_s* target_info = NULL;\r
+\r
+       if(tmp_client_context != NULL){\r
+\r
+               target_info = tmp_client_context->target_info;\r
+\r
+               if(target_info != NULL){\r
+\r
+                       if(target_info->devType < NET_NFC_MIFARE_MINI_PICC || target_info->devType > NET_NFC_MIFARE_4K_PICC){\r
+                               DEBUG_CLIENT_MSG("This is not MIFARE Classic TAG = [%d] \n", target_info->devType);\r
+                               return NET_NFC_NOT_SUPPORTED;\r
+                       }\r
+               }\r
+       }\r
+\r
+       uint8_t send_buffer[8] = {0};\r
+\r
+       send_buffer[0] = MIFARE_CMD_INCREMENT;\r
+       send_buffer[1] = addr;\r
+\r
+       /* little endian. little value of byte array will be saved first in memory */\r
+       send_buffer[5] = (value & 0xFF000000) >> 24;\r
+       send_buffer[4] = (value & 0x00FF0000) >> 16;\r
+       send_buffer[3] = (value & 0x0000FF00) >> 8;\r
+       send_buffer[2] = (value & 0x000000FF);\r
+\r
+       net_nfc_util_compute_CRC(CRC_A, send_buffer, 8);\r
+\r
+       data_s rawdata;\r
+\r
+       rawdata.buffer = send_buffer;\r
+       rawdata.length = 8;\r
+\r
+       return net_nfc_transceive(handle, (data_h)&rawdata, trans_param);\r
+}\r
+\r
+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)\r
+{\r
+       if(handle == NULL)\r
+               return NET_NFC_NULL_PARAMETER;\r
+\r
+       if(!net_nfc_tag_is_connected()){\r
+               return NET_NFC_OPERATION_FAIL;\r
+       }\r
+\r
+       client_context_t* tmp_client_context = net_nfc_get_client_context();\r
+\r
+       net_nfc_target_info_s* target_info = NULL;\r
+\r
+       if(tmp_client_context != NULL){\r
+\r
+               target_info = tmp_client_context->target_info;\r
+\r
+               if(target_info != NULL){\r
+\r
+                       if(target_info->devType < NET_NFC_MIFARE_MINI_PICC || target_info->devType > NET_NFC_MIFARE_4K_PICC){\r
+                               DEBUG_CLIENT_MSG("This is not MIFARE Classic TAG = [%d] \n", target_info->devType);\r
+                               return NET_NFC_NOT_SUPPORTED;\r
+                       }\r
+               }\r
+       }\r
+\r
+       uint8_t send_buffer[8] = {0};\r
+\r
+       send_buffer[0] = MIFARE_CMD_DECREMENT;\r
+       send_buffer[1] = addr;\r
+\r
+\r
+       // little endian. little value of byte array will be saved first in memory\r
+       send_buffer[5] = (value & 0xFF000000) >> 24;\r
+       send_buffer[4] = (value & 0x00FF0000) >> 16;\r
+       send_buffer[3] = (value & 0x0000FF00) >> 8;\r
+       send_buffer[2] = (value & 0x000000FF);\r
+\r
+       net_nfc_util_compute_CRC(CRC_A, send_buffer, 8);\r
+\r
+       DEBUG_MSG_PRINT_BUFFER(send_buffer, 8);\r
+\r
+       data_s rawdata;\r
+\r
+       rawdata.buffer = send_buffer;\r
+       rawdata.length = 8;\r
+\r
+       return net_nfc_transceive(handle, (data_h)&rawdata, trans_param);\r
+\r
+}\r
+\r
+NET_NFC_EXPORT_API net_nfc_error_e net_nfc_mifare_transfer(net_nfc_target_handle_h handle, uint8_t addr, void* trans_param)\r
+{\r
+       if(handle == NULL)\r
+               return NET_NFC_NULL_PARAMETER;\r
+\r
+       if(!net_nfc_tag_is_connected()){\r
+               return NET_NFC_OPERATION_FAIL;\r
+       }\r
+\r
+       client_context_t* tmp_client_context = net_nfc_get_client_context();\r
+\r
+       net_nfc_target_info_s* target_info = NULL;\r
+\r
+       if(tmp_client_context != NULL){\r
+\r
+               target_info = tmp_client_context->target_info;\r
+\r
+               if(target_info != NULL){\r
+\r
+                       if(target_info->devType < NET_NFC_MIFARE_MINI_PICC || target_info->devType > NET_NFC_MIFARE_4K_PICC){\r
+                               DEBUG_CLIENT_MSG("This is not MIFARE Classic TAG = [%d] \n", target_info->devType);\r
+                               return NET_NFC_NOT_SUPPORTED;\r
+                       }\r
+               }\r
+       }\r
+\r
+       uint8_t send_buffer[4] = {0};\r
+\r
+       send_buffer[0] = MIFARE_CMD_TRANSFER;\r
+       send_buffer[1] = addr;\r
+\r
+       net_nfc_util_compute_CRC(CRC_A, send_buffer, 4);\r
+\r
+       data_s rawdata;\r
+\r
+       rawdata.buffer = send_buffer;\r
+       rawdata.length = 4;\r
+\r
+       return net_nfc_transceive(handle, (data_h)&rawdata, trans_param);\r
+\r
+}\r
+\r
+NET_NFC_EXPORT_API net_nfc_error_e net_nfc_mifare_restore(net_nfc_target_handle_h handle, uint8_t addr, void* trans_param)\r
+{\r
+       if(handle == NULL)\r
+               return NET_NFC_NULL_PARAMETER;\r
+\r
+       if(!net_nfc_tag_is_connected()){\r
+               return NET_NFC_OPERATION_FAIL;\r
+       }\r
+\r
+       client_context_t* tmp_client_context = net_nfc_get_client_context();\r
+\r
+       net_nfc_target_info_s* target_info = NULL;\r
+\r
+       if(tmp_client_context != NULL){\r
+\r
+               target_info = tmp_client_context->target_info;\r
+\r
+               if(target_info != NULL){\r
+\r
+                       if(target_info->devType < NET_NFC_MIFARE_MINI_PICC || target_info->devType > NET_NFC_MIFARE_4K_PICC){\r
+                               DEBUG_CLIENT_MSG("This is not MIFARE Classic TAG = [%d] \n", target_info->devType);\r
+                               return NET_NFC_NOT_SUPPORTED;\r
+                       }\r
+               }\r
+       }\r
+\r
+       uint8_t send_buffer[4] = {0};\r
+\r
+       send_buffer[0] = MIFARE_CMD_RESTORE;\r
+       send_buffer[1] = addr;\r
+\r
+       net_nfc_util_compute_CRC(CRC_A, send_buffer, 4);\r
+\r
+       data_s rawdata ;\r
+\r
+       rawdata.buffer = send_buffer;\r
+       rawdata.length = 4;\r
+\r
+       return net_nfc_transceive(handle, (data_h)&rawdata, trans_param);\r
+}\r
+\r
+\r
+NET_NFC_EXPORT_API net_nfc_error_e net_nfc_mifare_create_default_key(data_h* key)\r
+{\r
+       if(key == NULL)\r
+               return NET_NFC_NULL_PARAMETER;\r
+\r
+       return net_nfc_create_data(key, default_key, 6);\r
+}\r
+\r
+NET_NFC_EXPORT_API net_nfc_error_e net_nfc_mifare_create_application_directory_key(data_h* key)\r
+{\r
+       if(key == NULL)\r
+               return NET_NFC_NULL_PARAMETER;\r
+\r
+\r
+       return net_nfc_create_data(key, mad_key, 6);\r
+}\r
+\r
+NET_NFC_EXPORT_API net_nfc_error_e net_nfc_mifare_create_net_nfc_forum_key(data_h* key)\r
+{\r
+       if(key == NULL)\r
+               return NET_NFC_NULL_PARAMETER;\r
+\r
+       return net_nfc_create_data(key, net_nfc_forum_key, 6);\r
+}\r
+\r
diff --git a/src/clientlib/net_nfc_client_target_info.c b/src/clientlib/net_nfc_client_target_info.c
new file mode 100644 (file)
index 0000000..4be7fa0
--- /dev/null
@@ -0,0 +1,169 @@
+/*\r
+  * Copyright 2012  Samsung Electronics Co., Ltd\r
+  *\r
+  * Licensed under the Flora License, Version 1.0 (the "License");\r
+  * you may not use this file except in compliance with the License.\r
+  * You may obtain a copy of the License at\r
+\r
+  *     http://www.tizenopensource.org/license\r
+  *\r
+  * Unless required by applicable law or agreed to in writing, software\r
+  * distributed under the License is distributed on an "AS IS" BASIS,\r
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+  * See the License for the specific language governing permissions and\r
+  * limitations under the License.\r
+  */\r
+\r
+#include "net_nfc_typedef_private.h"\r
+#include "net_nfc_target_info.h"\r
+#include "net_nfc_data.h"\r
+#include "net_nfc_debug_private.h"\r
+#include <stdbool.h>\r
+\r
+#ifndef NET_NFC_EXPORT_API\r
+#define NET_NFC_EXPORT_API __attribute__((visibility("default")))\r
+#endif\r
+\r
+\r
+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)\r
+{\r
+       if (target_info == NULL || type == NULL){\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+       net_nfc_target_info_s * target_info_private = (net_nfc_target_info_s*) target_info;\r
+\r
+       *type = target_info_private->devType;\r
+       return NET_NFC_OK;\r
+}\r
+\r
+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)\r
+{\r
+       if (target_info == NULL || handle == NULL){\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+       net_nfc_target_info_s * target_info_private = (net_nfc_target_info_s*) target_info;\r
+\r
+       *handle = (net_nfc_target_handle_h) target_info_private->handle;\r
+       return NET_NFC_OK;\r
+}\r
+\r
+NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_tag_ndef_support (net_nfc_target_info_h target_info, bool * is_support)\r
+{\r
+       if (target_info == NULL || is_support == NULL){\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+       net_nfc_target_info_s * target_info_private = (net_nfc_target_info_s*) target_info;\r
+\r
+       *is_support = (bool) target_info_private->is_ndef_supported;\r
+       return NET_NFC_OK;\r
+}\r
+\r
+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)\r
+{\r
+       if (target_info == NULL || max_size == NULL){\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+       net_nfc_target_info_s * target_info_private = (net_nfc_target_info_s*) target_info;\r
+\r
+       *max_size = target_info_private->maxDataSize;\r
+       return NET_NFC_OK;\r
+}\r
+\r
+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)\r
+{\r
+       if (target_info == NULL || actual_data == NULL){\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+       net_nfc_target_info_s * target_info_private = (net_nfc_target_info_s*) target_info;\r
+\r
+       *actual_data = target_info_private->actualDataSize;\r
+       return NET_NFC_OK;\r
+}\r
+\r
+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)\r
+{\r
+       if(keys == NULL || number_of_keys == NULL || target_info == NULL)\r
+       {\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+\r
+       net_nfc_target_info_s* handle = (net_nfc_target_info_s*)target_info;\r
+\r
+       if(handle->tag_info_list == NULL)\r
+       {\r
+               return NET_NFC_NO_DATA_FOUND;\r
+       }\r
+\r
+       if(handle->number_of_keys <= 0)\r
+       {\r
+               return NET_NFC_NO_DATA_FOUND;\r
+       }\r
+\r
+       int i = 0;\r
+\r
+       if (handle->keylist != NULL){\r
+               *keys = handle->keylist;\r
+               return NET_NFC_OK;\r
+       }\r
+\r
+       *keys = (char **)calloc(handle->number_of_keys, sizeof(char *));\r
+\r
+       if(*keys == NULL)\r
+               return NET_NFC_ALLOC_FAIL;\r
+\r
+       net_nfc_tag_info_s* tag_info = handle->tag_info_list;\r
+\r
+       for(; i < handle->number_of_keys; i++, tag_info++)\r
+       {\r
+               (*keys)[i] = tag_info->key;\r
+       }\r
+\r
+       *number_of_keys = handle->number_of_keys;\r
+\r
+       DEBUG_CLIENT_MSG("number of keys = [%d]", handle->number_of_keys);\r
+\r
+       handle->keylist = *keys;\r
+\r
+       return NET_NFC_OK;\r
+}\r
+\r
+\r
+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)\r
+{\r
+       if(target_info == NULL || key == NULL || value == NULL)\r
+       {\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+\r
+       net_nfc_target_info_s* handle = (net_nfc_target_info_s*)target_info;\r
+\r
+       if(handle->tag_info_list == NULL)\r
+       {\r
+               return NET_NFC_NO_DATA_FOUND;\r
+       }\r
+\r
+       int i = 0;\r
+\r
+       net_nfc_tag_info_s* tag_info = handle->tag_info_list;\r
+\r
+       for(; i < handle->number_of_keys; i++, tag_info++)\r
+       {\r
+               if(strcmp(key, tag_info->key) == 0)\r
+               {\r
+                       if(tag_info->value == NULL)\r
+                       {\r
+                               return NET_NFC_NO_DATA_FOUND;\r
+                       }\r
+                       else\r
+                       {\r
+                               *value = tag_info->value;\r
+                               break;\r
+                       }\r
+               }\r
+       }\r
+\r
+       if(i == handle->number_of_keys)\r
+               return NET_NFC_NOT_SUPPORTED;\r
+\r
+       return NET_NFC_OK;\r
+}\r
diff --git a/src/clientlib/net_nfc_client_test.c b/src/clientlib/net_nfc_client_test.c
new file mode 100644 (file)
index 0000000..7dc99d4
--- /dev/null
@@ -0,0 +1,80 @@
+/*
+  * Copyright 2012  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://www.tizenopensource.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"
+
+
+#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)
+{
+       int user_context;
+
+       DEBUG_CLIENT_MSG("user_param = [%d] trans_param = [%d] , 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)
+{
+       int user_context;
+
+       DEBUG_CLIENT_MSG("user_param = [%d] trans_param = [%d] data = [%d]", 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;
+       }
+}
diff --git a/src/clientlib/net_nfc_client_util.c b/src/clientlib/net_nfc_client_util.c
new file mode 100644 (file)
index 0000000..c47324c
--- /dev/null
@@ -0,0 +1,48 @@
+/*\r
+  * Copyright 2012  Samsung Electronics Co., Ltd\r
+  *\r
+  * Licensed under the Flora License, Version 1.0 (the "License");\r
+  * you may not use this file except in compliance with the License.\r
+  * You may obtain a copy of the License at\r
+\r
+  *     http://www.tizenopensource.org/license\r
+  *\r
+  * Unless required by applicable law or agreed to in writing, software\r
+  * distributed under the License is distributed on an "AS IS" BASIS,\r
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+  * See the License for the specific language governing permissions and\r
+  * limitations under the License.\r
+  */\r
+\r
+#include <stdlib.h>\r
+#include <string.h>\r
+\r
+#include "net_nfc_client_util_private.h"\r
+\r
+void __net_nfc_client_util_free_mem(void** mem, char * filename, unsigned int line)\r
+{\r
+       if (mem == NULL || *mem == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       free(*mem);\r
+\r
+       *mem = NULL;\r
+}\r
+\r
+void __net_nfc_client_util_alloc_mem(void** mem, int size, char * filename, unsigned int line)\r
+{\r
+       if (mem == NULL || size <= 0)\r
+       {\r
+               return;\r
+       }\r
+\r
+       *mem = malloc(size);\r
+\r
+       if (*mem != NULL)\r
+       {\r
+               memset(*mem, 0x0, size);\r
+       }\r
+}\r
+\r
diff --git a/src/clientlib/nfc.pc.in b/src/clientlib/nfc.pc.in
new file mode 100755 (executable)
index 0000000..8731985
--- /dev/null
@@ -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 (file)
index 0000000..10624fb
--- /dev/null
@@ -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 svi)
+
+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 -mno-thumb-interwork -msoft-float -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("-fpie")
+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
+)
+
+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 100644 (file)
index 0000000..79df6ff
--- /dev/null
@@ -0,0 +1,101 @@
+/*
+  * Copyright 2012  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://www.tizenopensource.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 <stdio.h>
+#include <errno.h>
+#include <time.h>
+#include <sys/time.h>
+#include <libgen.h>
+
+// below define should define before dlog.h
+#define LOG_TAG "NET_NFC_MANAGER"
+
+#include <dlog.h>
+
+#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 DEBUG_MSG_PRINT_BUFFER(buffer,length) \
+do {\
+       LOGD(LOG_COLOR_GREEN"[file = %s : method = %s : line = %d]"LOG_COLOR_END, basename(__FILE__), __func__, __LINE__); \
+       int i = 0;\
+       LOGD(LOG_COLOR_BLUE"BUFFER => \n"LOG_COLOR_END);\
+       for(; i < length; i++)\
+       {\
+               LOGD(LOG_COLOR_BLUE" [0x%x] "LOG_COLOR_END,buffer[i]);\
+       }\
+       LOGD(LOG_COLOR_BLUE"\n\n"LOG_COLOR_END);\
+}while(0);
+
+#define DEBUG_MSG_PRINT_BUFFER_CHAR(buffer,length) \
+do {\
+       LOGD(LOG_COLOR_GREEN"[file = %s : method = %s : line = %d]"LOG_COLOR_END, basename(__FILE__), __func__, __LINE__); \
+       int i = 0;\
+       LOGD(LOG_COLOR_BLUE"BUFFER => \n"LOG_COLOR_END);\
+       for(; i < length; i++)\
+       {\
+               LOGD(LOG_COLOR_BLUE" [%c] "LOG_COLOR_END,buffer[i]);\
+       }\
+       LOGD(LOG_COLOR_BLUE"\n\n"LOG_COLOR_END);\
+}while(0);
+
+#define DEBUG_MSG(format,args...) \
+do {\
+       LOGD(LOG_COLOR_BROWN"[file = %s : method = %s : line = %d]"LOG_COLOR_END, basename(__FILE__), __func__, __LINE__); \
+       LOGD(LOG_COLOR_BROWN""format""LOG_COLOR_END, ##args);\
+}while(0);
+
+#define DEBUG_SERVER_MSG(format,args...) \
+do {\
+       LOGD(LOG_COLOR_PURPLE"[file = %s : method = %s : line = %d]"LOG_COLOR_END, basename(__FILE__), __func__, __LINE__); \
+       LOGD(LOG_COLOR_PURPLE""format""LOG_COLOR_END, ##args);\
+}while(0);
+
+#define DEBUG_CLIENT_MSG(format,args...) \
+do {\
+       LOGD(LOG_COLOR_GREEN"[file = %s : method = %s : line = %d]"LOG_COLOR_END, basename(__FILE__), __func__, __LINE__); \
+       LOGD(LOG_COLOR_GREEN""format""LOG_COLOR_END, ##args);\
+}while(0);
+
+#define DEBUG_ERR_MSG(format,args...) \
+do {\
+       LOGD(LOG_COLOR_RED"[ERR :: file = %s : method = %s : line = %d]"LOG_COLOR_END, basename(__FILE__), __func__, __LINE__); \
+       LOGD(LOG_COLOR_RED""format""LOG_COLOR_END, ##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);\
+       LOGD(str); \
+       LOGD("\t time = [%s] \n", 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 (file)
index 0000000..fdd02e7
--- /dev/null
@@ -0,0 +1,117 @@
+/*\r
+  * Copyright 2012  Samsung Electronics Co., Ltd\r
+  *\r
+  * Licensed under the Flora License, Version 1.0 (the "License");\r
+  * you may not use this file except in compliance with the License.\r
+  * You may obtain a copy of the License at\r
+\r
+  *     http://www.tizenopensource.org/license\r
+  *\r
+  * Unless required by applicable law or agreed to in writing, software\r
+  * distributed under the License is distributed on an "AS IS" BASIS,\r
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+  * See the License for the specific language governing permissions and\r
+  * limitations under the License.\r
+  */\r
+\r
+#ifndef NET_NFC_OEM_CONTROLLER_H\r
+#define NET_NFC_OEM_CONTROLLER_H\r
+\r
+#include "net_nfc_typedef_private.h"\r
+\r
+typedef bool (*net_nfc_oem_controller_init)(net_nfc_error_e *result);\r
+typedef bool (*net_nfc_oem_controller_deinit)(void);\r
+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);\r
+typedef bool (*net_nfc_oem_controller_unregister_listener)(void);\r
+typedef bool (*net_nfc_oem_controller_check_firmware_version)(net_nfc_error_e *result);\r
+typedef bool (*net_nfc_oem_controller_update_firmware)(net_nfc_error_e *result);\r
+typedef bool (*net_nfc_oem_controller_get_stack_information)(net_nfc_stack_information_s *stack_info, net_nfc_error_e *result);\r
+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);\r
+typedef bool (*net_nfc_oem_controller_get_secure_element_list)(net_nfc_secure_element_info_s *list, int* count, net_nfc_error_e *result);\r
+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);\r
+typedef bool (*net_nfc_oem_controller_check_target_presence)(net_nfc_target_handle_s *handle, net_nfc_error_e *result);\r
+typedef bool (*net_nfc_oem_controller_connect)(net_nfc_target_handle_s *handle, net_nfc_error_e *result);\r
+typedef bool (*net_nfc_oem_controller_disconnect)(net_nfc_target_handle_s *handle, net_nfc_error_e *result);\r
+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);\r
+typedef bool (*net_nfc_oem_controller_read_ndef)(net_nfc_target_handle_s *handle, data_s **data, net_nfc_error_e *result);\r
+typedef bool (*net_nfc_oem_controller_write_ndef)(net_nfc_target_handle_s *handle, data_s *data, net_nfc_error_e *result);\r
+typedef bool (*net_nfc_oem_controller_make_read_only_ndef)(net_nfc_target_handle_s *handle, net_nfc_error_e *result);\r
+typedef bool (*net_nfc_oem_controller_format_ndef)(net_nfc_target_handle_s *handle, data_s *secure_key, net_nfc_error_e *result);\r
+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);\r
+typedef bool (*net_nfc_oem_controller_exception_handler)(void);\r
+typedef bool (*net_nfc_oem_controller_is_ready)(net_nfc_error_e *result);\r
+\r
+// LLCP API DEFINE\r
+\r
+typedef bool (*net_nfc_oem_controller_llcp_config)(net_nfc_llcp_config_info_s *config, net_nfc_error_e *result);\r
+typedef bool (*net_nfc_oem_controller_llcp_check_llcp)(net_nfc_target_handle_s *handle, net_nfc_error_e *result);\r
+typedef bool (*net_nfc_oem_controller_llcp_activate_llcp)(net_nfc_target_handle_s *handle, net_nfc_error_e *result);\r
+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);\r
+typedef bool (*net_nfc_oem_controller_llcp_bind)(net_nfc_llcp_socket_t socket, uint8_t service_access_point, net_nfc_error_e *result);\r
+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);\r
+typedef bool (*net_nfc_oem_controller_llcp_accept)(net_nfc_llcp_socket_t socket, net_nfc_error_e *result);\r
+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);\r
+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);\r
+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);\r
+typedef bool (*net_nfc_oem_controller_llcp_socket_close)(net_nfc_llcp_socket_t socket, net_nfc_error_e *result);\r
+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);\r
+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);\r
+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);\r
+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);\r
+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);\r
+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);\r
+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);\r
+\r
+typedef bool (*net_nfc_oem_controller_sim_test)(net_nfc_error_e *result);\r
+typedef bool (*net_nfc_oem_controller_test_mode_on)(net_nfc_error_e *result);\r
+typedef bool (*net_nfc_oem_controller_test_mode_off)(net_nfc_error_e *result);\r
+\r
+typedef struct _net_nfc_oem_interface_s\r
+{\r
+       net_nfc_oem_controller_init init;\r
+       net_nfc_oem_controller_deinit deinit;\r
+       net_nfc_oem_controller_register_listener register_listener;\r
+       net_nfc_oem_controller_unregister_listener unregister_listener;\r
+       net_nfc_oem_controller_check_firmware_version check_firmware_version;\r
+       net_nfc_oem_controller_update_firmware update_firmeware;\r
+       net_nfc_oem_controller_get_stack_information get_stack_information;\r
+       net_nfc_oem_controller_configure_discovery configure_discovery;\r
+       net_nfc_oem_controller_get_secure_element_list get_secure_element_list;\r
+       net_nfc_oem_controller_set_secure_element_mode set_secure_element_mode;\r
+       net_nfc_oem_controller_connect connect;\r
+       net_nfc_oem_controller_connect disconnect;\r
+       net_nfc_oem_controller_check_ndef check_ndef;\r
+       net_nfc_oem_controller_check_target_presence check_presence;\r
+       net_nfc_oem_controller_read_ndef read_ndef;\r
+       net_nfc_oem_controller_write_ndef write_ndef;\r
+       net_nfc_oem_controller_make_read_only_ndef make_read_only_ndef;\r
+       net_nfc_oem_controller_transceive transceive;\r
+       net_nfc_oem_controller_format_ndef format_ndef;\r
+       net_nfc_oem_controller_exception_handler exception_handler;\r
+       net_nfc_oem_controller_is_ready is_ready;\r
+\r
+       net_nfc_oem_controller_llcp_config config_llcp;\r
+       net_nfc_oem_controller_llcp_check_llcp check_llcp_status;\r
+       net_nfc_oem_controller_llcp_activate_llcp activate_llcp;\r
+       net_nfc_oem_controller_llcp_create_socket create_llcp_socket;\r
+       net_nfc_oem_controller_llcp_bind bind_llcp_socket;\r
+       net_nfc_oem_controller_llcp_listen listen_llcp_socket;\r
+       net_nfc_oem_controller_llcp_accept accept_llcp_socket;\r
+       net_nfc_oem_controller_llcp_connect_by_url connect_llcp_by_url;\r
+       net_nfc_oem_controller_llcp_connect connect_llcp;\r
+       net_nfc_oem_controller_llcp_disconnect disconnect_llcp;\r
+       net_nfc_oem_controller_llcp_socket_close close_llcp_socket;\r
+       net_nfc_oem_controller_llcp_recv recv_llcp;\r
+       net_nfc_oem_controller_llcp_send send_llcp;\r
+       net_nfc_oem_controller_llcp_recv_from recv_from_llcp;\r
+       net_nfc_oem_controller_llcp_send_to send_to_llcp;\r
+       net_nfc_oem_controller_llcp_reject reject_llcp;\r
+       net_nfc_oem_controller_llcp_get_remote_config get_remote_config;\r
+       net_nfc_oem_controller_llcp_get_remote_socket_info get_remote_socket_info;\r
+\r
+       net_nfc_oem_controller_sim_test sim_test;\r
+       net_nfc_oem_controller_test_mode_on test_mode_on;\r
+       net_nfc_oem_controller_test_mode_off test_mode_off;\r
+} net_nfc_oem_interface_s;\r
+\r
+#endif\r
diff --git a/src/commonlib/include/net_nfc_typedef.h b/src/commonlib/include/net_nfc_typedef.h
new file mode 100644 (file)
index 0000000..cb9cf1c
--- /dev/null
@@ -0,0 +1,499 @@
+/*
+  * Copyright 2012  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://www.tizenopensource.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
+ @{
+ <P> "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.  </P>
+
+ NFC Manager APIs are defined in <net_nfc.h>, <net_nfc_typedef.h>
+
+ <P>
+ Memory management rules <br>
+ 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())
+ </p>
+
+ @}
+ */
+
+/**
+ @addtogroup NET_NFC_TYPEDEF
+ @{
+ This documents provide the NFC defines
+
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdint.h>
+#include <stdbool.h>
+
+#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, <br> This events is received after calling the "net_nfc_tranceive"
+                                                                        <br> 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, <br> This events is received after calling the "net_nfc_read_tag"
+                                                                <br> 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, <br> This events is received after calling the "net_nfc_write_ndef"
+                                                                <br> data pointer always returns NULL */
+       NET_NFC_MESSAGE_MAKE_READ_ONLY_NDEF, /**< Type: Response Event, <br> This events is received after calling the "net_nfc_make_read_only_ndef"
+                                                                                <br> data pointer always returns NULL */
+       NET_NFC_MESSAGE_IS_TAG_CONNECTED, /**< Type: Response Event, <br> This events is received after calling the "net_nfc_is_tag_conneced"
+                                                                                <br> data pointer always returns NULL */
+       NET_NFC_MESSAGE_GET_CURRENT_TAG_INFO, /**< Type: Response Event, <br> This events is received after calling the "net_nfc_get_current_tag_infof"
+                                                                <br> 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, <br> This events is received after calling the "net_nfc_get_current_target_handle"
+                                                                <br> 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, <br> When a tag or SE is detected, you got this event.
+                                                                        <br> The data contains the target info , need to cast to net_nfc_target_info_h*/
+       NET_NFC_MESSAGE_NOTIFY, /**< This Notify Event <br> when the unexpected error has occurred, this event is delivered. data pointer always returns NULL  */
+       NET_NFC_MESSAGE_TAG_DETACHED, /**< Type: Notify Event, <br> When a tag or SE is disappeared, you got this event.
+                                                                        <br> The data contains the target info , need to cast to net_nfc_target_info_h but it does not have detail target info
+                                                                        <br> please, do not use "net_nfc_get_tag_info_keys" when you got this event*/
+       NET_NFC_MESSAGE_FORMAT_NDEF, /**< Type: Response Event <br> After complete "net_nfc_format_ndef", this event is delivered */
+       NET_NFC_MESSAGE_LLCP_DISCOVERED,/**< Type: Notify Event <br> When LLCP is discovered and remote device is support llcp, you receive this event
+                                                                        <br> data pointer contains the remote llcp configuration info. Cast to net_nfc_llcp_config_info_h*/
+       NET_NFC_MESSAGE_P2P_DETACHED, /**< Type: Notify Event <br> When LLCP is de-activated by removing the device, you receive this event*/
+       NET_NFC_MESSAGE_LLCP_CONFIG, /**< Type: Response Event. <br> The operation of "net_nfc_set_llcp_local_configure" is completed */
+
+       NET_NFC_MESSAGE_P2P_DISCOVERED, /**< Type: Notify Event <br> The remove device is detected and ready for transferring data to remote side */
+       NET_NFC_MESSAGE_P2P_SEND, /**< Type: Response Event, <br> This events is received after calling the "net_nfc_send_exchanger_data" */
+       NET_NFC_MESSAGE_P2P_RECEIVE, /**< Type: Notify Event, <br> 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_CONNECTION_HANDOVER, /**< Type: Response Event. <br> 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_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 <br> this event indicates "net_nfc_listen_llcp" requested is completed*/
+       NET_NFC_MESSAGE_LLCP_ACCEPTED, /**< Type: Notify Event. <br>  Remote socket is accepted to listening socket
+                                                                        <br> data pointer contains the remote socket info (Cast to net_nfc_llcp_socket_option_h)*/
+       NET_NFC_MESSAGE_LLCP_CONNECT, /**< Type: Response Event. <br> "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.<br>  "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,<br>  "net_nfc_send_llcp" operation is completed (connection mode)*/
+       NET_NFC_MESSAGE_LLCP_SEND_TO, /**< Type: Response Event,<br>  "net_nfc_send_llcp_to"operation is completed (connectionless mode)*/
+       NET_NFC_MESSAGE_LLCP_RECEIVE, /**< Type: Response Event,<br>  "net_nfc_receive_llcp" operation is completed (connection mode)
+                                                                        <br> data pointer contains received data (Cast to data_h)*/
+       NET_NFC_MESSAGE_LLCP_RECEIVE_FROM, /**< Type: Response Event,<br>  "net_nfc_receive_llcp_from" operation is completed (connectionless mode)*/
+       NET_NFC_MESSAGE_LLCP_DISCONNECT, /**< Type: Response Event,<br>  "net_nfc_disconnect_llcp" request is completed */
+       NET_NFC_MESSAGE_LLCP_ERROR, /**< Type: Notify Event,<br>  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;
+
+#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 100644 (file)
index 0000000..734648e
--- /dev/null
@@ -0,0 +1,1325 @@
+/*
+ * Copyright (C) 2010 NXP Semiconductors
+ * Copyright (C) 2012 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 <em> Reader B structure </em> 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 <em> Jewel Reader structure </em> 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 <em> Felica Reader structure </em> 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 <em> Reader A structure </em> 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 <em> \ref Halnet_nfc_eDataRate enum </em> 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 <em> NFCIP1 structure </em> 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;
+
+typedef enum _server_state_e
+{
+       NET_NFC_SERVER_IDLE,
+       NET_NFC_SERVER_DISCOVERY,
+       NET_NFC_TAG_CONNECTED,
+       NET_NFC_SE_CONNECTED,
+       NET_NFC_LLCP_CONNECTED,
+       NET_NFC_SNEP_CLIENT_CONNECTED,
+       NET_NFC_NPP_CLIENT_CONNECTED,
+       NET_NFC_SNEP_SERVER_CONNECTED,
+} server_state_e;
+
+#define        NET_NFC_CLIENT_TYPE_INVALID  0x00
+#define        NET_NFC_CLIENT_TYPE_MASTER 0x01
+#define        NET_NFC_CLIENT_TYPE_LISTENER 0x02
+
+// these are messages for request
+
+typedef struct _net_nfc_request_msg_t
+{
+       /* DON'T MODIFY THIS CODE - BEGIN */
+       uint32_t length;
+       uint32_t request_type; // NET_NFC_MESSAGE
+       uint32_t user_param;
+       /* DON'T MODIFY THIS CODE - END */
+} net_nfc_request_msg_t;
+
+typedef struct _net_nfc_request_change_client_state_t
+{
+       /* DON'T MODIFY THIS CODE - BEGIN */
+       uint32_t length;
+       uint32_t request_type;
+       uint32_t user_param;
+       /* DON'T MODIFY THIS CODE - END */
+       client_state_e client_state;
+       int client_type;
+} net_nfc_request_change_client_state_t;
+
+typedef struct _net_nfc_request_transceive_t
+{
+       /* DON'T MODIFY THIS CODE - BEGIN */
+       uint32_t length;
+       uint32_t request_type;
+       uint32_t user_param;
+       /* DON'T MODIFY THIS CODE - END */
+       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
+{
+       /* DON'T MODIFY THIS CODE - BEGIN */
+       uint32_t length;
+       uint32_t request_type;
+       uint32_t user_param;
+       /* DON'T MODIFY THIS CODE - END */
+       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
+{
+       /* DON'T MODIFY THIS CODE - BEGIN */
+       uint32_t length;
+       uint32_t request_type;
+       uint32_t user_param;
+       /* DON'T MODIFY THIS CODE - END */
+       net_nfc_target_handle_s *handle;
+       void *trans_param;
+} net_nfc_request_read_ndef_t;
+
+typedef struct _net_nfc_request_test_t
+{
+       /* DON'T MODIFY THIS CODE - BEGIN */
+       uint32_t length;
+       uint32_t request_type;
+       uint32_t user_param;
+       /* DON'T MODIFY THIS CODE - END */
+       net_nfc_target_handle_s *handle;
+       void *trans_param;
+} net_nfc_request_test_t;
+
+typedef struct _net_nfc_request_make_read_only_ndef_t
+{
+       /* DON'T MODIFY THIS CODE - BEGIN */
+       uint32_t length;
+       uint32_t request_type;
+       uint32_t user_param;
+       /* DON'T MODIFY THIS CODE - END */
+       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
+{
+       /* DON'T MODIFY THIS CODE - BEGIN */
+       uint32_t length;
+       uint32_t request_type;
+       uint32_t user_param;
+       /* DON'T MODIFY THIS CODE - END */
+       void *trans_param;
+} net_nfc_request_is_tag_connected_t;
+
+typedef struct _net_nfc_request_write_ndef_t
+{
+       /* DON'T MODIFY THIS CODE - BEGIN */
+       uint32_t length;
+       uint32_t request_type;
+       uint32_t user_param;
+       /* DON'T MODIFY THIS CODE - END */
+       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
+{
+       /* DON'T MODIFY THIS CODE - BEGIN */
+       uint32_t length;
+       uint32_t request_type;
+       uint32_t user_param;
+       /* DON'T MODIFY THIS CODE - END */
+       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
+{
+       /* DON'T MODIFY THIS CODE - BEGIN */
+       uint32_t length;
+       uint32_t request_type;
+       uint32_t user_param;
+       /* DON'T MODIFY THIS CODE - END */
+       net_nfc_target_handle_s *handle;
+       void *object;
+} net_nfc_request_terminate_t;
+
+
+typedef struct _net_nfc_request_reset_mode_t
+{
+       /* DON'T MODIFY THIS CODE - BEGIN */
+       uint32_t length;
+       uint32_t request_type;
+       uint32_t user_param;
+       /* DON'T MODIFY THIS CODE - END */
+       int mode;
+} net_nfc_request_reset_mode_t;
+
+typedef struct _net_nfc_request_target_detected_t
+{
+       /* DON'T MODIFY THIS CODE - BEGIN */
+       uint32_t length;
+       uint32_t request_type;
+       uint32_t user_param;
+       /* DON'T MODIFY THIS CODE - END */
+       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
+{
+       /* DON'T MODIFY THIS CODE - BEGIN */
+       uint32_t length;
+       uint32_t request_type;
+       uint32_t user_param;
+       /* DON'T MODIFY THIS CODE - END */
+       net_nfc_data_s aid;
+       net_nfc_data_s param;
+}net_nfc_request_se_event_t;
+
+typedef struct _net_nfc_request_get_current_tag_info_t
+{
+       /* DON'T MODIFY THIS CODE - BEGIN */
+       uint32_t length;
+       uint32_t request_type;
+       uint32_t user_param;
+       /* DON'T MODIFY THIS CODE - END */
+       void *trans_param;
+} net_nfc_request_get_current_tag_info_t;
+
+typedef struct _net_nfc_request_get_current_target_handle_t
+{
+       /* DON'T MODIFY THIS CODE - BEGIN */
+       uint32_t length;
+       uint32_t request_type;
+       uint32_t user_param;
+       /* DON'T MODIFY THIS CODE - END */
+       void *trans_param;
+} net_nfc_request_get_current_target_handle_t;
+
+typedef struct _net_nfc_request_llcp_msg_t
+{
+       /* DON'T MODIFY THIS CODE - BEGIN */
+       uint32_t length;
+       uint32_t request_type;
+       uint32_t user_param;
+       /* DON'T MODIFY THIS CODE - END */
+       uint32_t result;
+} net_nfc_request_llcp_msg_t;
+
+typedef struct _net_nfc_request_p2p_send_t
+{
+       /* DON'T MODIFY THIS CODE - BEGIN */
+       uint32_t length;
+       uint32_t request_type;
+       uint32_t user_param;
+       /* DON'T MODIFY THIS CODE - END */
+       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
+{
+       /* DON'T MODIFY THIS CODE - BEGIN */
+       uint32_t length;
+       uint32_t request_type;
+       uint32_t user_param;
+       /* DON'T MODIFY THIS CODE - END */
+       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
+{
+       /* DON'T MODIFY THIS CODE - BEGIN */
+       uint32_t length;
+       uint32_t request_type;
+       uint32_t user_param;
+       /* DON'T MODIFY THIS CODE - END */
+       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
+{
+       /* DON'T MODIFY THIS CODE - BEGIN */
+       uint32_t length;
+       uint32_t request_type;
+       uint32_t user_param;
+       /* DON'T MODIFY THIS CODE - END */
+       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
+{
+       /* DON'T MODIFY THIS CODE - BEGIN */
+       uint32_t length;
+       uint32_t request_type;
+       uint32_t user_param;
+       /* DON'T MODIFY THIS CODE - END */
+       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
+{
+       /* DON'T MODIFY THIS CODE - BEGIN */
+       uint32_t length;
+       uint32_t request_type;
+       uint32_t user_param;
+       /* DON'T MODIFY THIS CODE - END */
+       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
+{
+       /* DON'T MODIFY THIS CODE - BEGIN */
+       uint32_t length;
+       uint32_t request_type;
+       uint32_t user_param;
+       /* DON'T MODIFY THIS CODE - END */
+       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
+{
+       /* DON'T MODIFY THIS CODE - BEGIN */
+       uint32_t length;
+       uint32_t request_type;
+       uint32_t user_param;
+       /* DON'T MODIFY THIS CODE - END */
+       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
+{
+       /* DON'T MODIFY THIS CODE - BEGIN */
+       uint32_t length;
+       uint32_t request_type;
+       uint32_t user_param;
+       /* DON'T MODIFY THIS CODE - END */
+       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
+{
+       /* DON'T MODIFY THIS CODE - BEGIN */
+       uint32_t length;
+       uint32_t request_type;
+       uint32_t user_param;
+       /* DON'T MODIFY THIS CODE - END */
+       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
+{
+       /* DON'T MODIFY THIS CODE - BEGIN */
+       uint32_t length;
+       uint32_t request_type;
+       uint32_t user_param;
+       /* DON'T MODIFY THIS CODE - END */
+       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
+{
+       /* DON'T MODIFY THIS CODE - BEGIN */
+       uint32_t length;
+       uint32_t request_type;
+       uint32_t user_param;
+       /* DON'T MODIFY THIS CODE - END */
+       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
+{
+       /* DON'T MODIFY THIS CODE - BEGIN */
+       uint32_t length;
+       uint32_t request_type;
+       uint32_t user_param;
+       /* DON'T MODIFY THIS CODE - END */
+       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
+{
+       /* DON'T MODIFY THIS CODE - BEGIN */
+       uint32_t length;
+       uint32_t request_type;
+       uint32_t user_param;
+       /* DON'T MODIFY THIS CODE - END */
+       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
+{
+       /* DON'T MODIFY THIS CODE - BEGIN */
+       uint32_t length;
+       uint32_t request_type;
+       uint32_t user_param;
+       /* DON'T MODIFY THIS CODE - END */
+       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
+{
+       /* DON'T MODIFY THIS CODE - BEGIN */
+       uint32_t length;
+       uint32_t request_type;
+       uint32_t user_param;
+       /* DON'T MODIFY THIS CODE - END */
+       net_nfc_target_handle_s *handle;
+       uint32_t devType;
+} net_nfc_request_watch_dog_t;
+
+typedef struct _net_nfc_request_set_se_t
+{
+       /* DON'T MODIFY THIS CODE - BEGIN */
+       uint32_t length;
+       uint32_t request_type;
+       uint32_t user_param;
+       /* DON'T MODIFY THIS CODE - END */
+       uint8_t se_type;
+       void *trans_param;
+} net_nfc_request_set_se_t;
+
+typedef struct _net_nfc_request_get_se_t
+{
+       /* DON'T MODIFY THIS CODE - BEGIN */
+       uint32_t length;
+       uint32_t request_type;
+       uint32_t user_param;
+       /* DON'T MODIFY THIS CODE - END */
+       void *trans_param;
+} net_nfc_request_get_se_t;
+
+typedef struct _net_nfc_request_open_internal_se_t
+{
+       /* DON'T MODIFY THIS CODE - BEGIN */
+       uint32_t length;
+       uint32_t request_type;
+       uint32_t user_param;
+       /* DON'T MODIFY THIS CODE - END */
+       uint8_t se_type;
+       void *trans_param;
+} net_nfc_request_open_internal_se_t;
+
+typedef struct _net_nfc_request_close_internal_se_t
+{
+       /* DON'T MODIFY THIS CODE - BEGIN */
+       uint32_t length;
+       uint32_t request_type;
+       uint32_t user_param;
+       /* DON'T MODIFY THIS CODE - END */
+       net_nfc_target_handle_s *handle;
+       void *trans_param;
+} net_nfc_request_close_internal_se_t;
+
+typedef struct _net_nfc_request_send_apdu_t
+{
+       /* DON'T MODIFY THIS CODE - BEGIN */
+       uint32_t length;
+       uint32_t request_type;
+       uint32_t user_param;
+       /* DON'T MODIFY THIS CODE - END */
+       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
+{
+       /* DON'T MODIFY THIS CODE - BEGIN */
+       uint32_t length;
+       uint32_t request_type;
+       uint32_t user_param;
+       /* DON'T MODIFY THIS CODE - END */
+       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
+//
+typedef struct _net_nfc_response_msg_t
+{
+       int response_type; /* NET_NFC_MESSAGE :  this type should be int do not 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_error_e result;
+       void *trans_param;
+} net_nfc_response_test_t;
+
+typedef struct _net_nfc_response_notify_t
+{
+       net_nfc_error_e result;
+} net_nfc_response_notify_t;
+
+typedef struct _net_nfc_response_init_t
+{
+       net_nfc_error_e result;
+} net_nfc_response_init_t;
+
+typedef struct _net_nfc_response_tag_discovered_t
+{
+       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_error_e result;
+} net_nfc_response_tag_discovered_t;
+
+typedef struct _net_nfc_response_se_event_t
+{
+       data_s aid;
+       data_s param;
+       net_nfc_error_e result;
+} net_nfc_response_se_event_t;
+
+typedef struct _net_nfc_response_get_current_tag_info_t
+{
+       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_error_e result;
+       void *trans_param;
+} net_nfc_response_get_current_tag_info_t;
+
+typedef struct _net_nfc_response_get_current_target_handle_t
+{
+       net_nfc_target_handle_s *handle;
+       uint32_t devType;
+       net_nfc_error_e result;
+       void *trans_param;
+} net_nfc_response_get_current_target_handle_t;
+
+typedef struct _net_nfc_response_target_detached_t
+{
+       net_nfc_target_handle_s *handle;
+       uint32_t devType;
+} net_nfc_response_target_detached_t;
+
+typedef struct _net_nfc_response_transceive_t
+{
+       net_nfc_error_e result;
+       void *trans_param;
+       data_s data;
+} net_nfc_response_transceive_t;
+
+typedef struct _net_nfc_response_read_ndef_t
+{
+       net_nfc_error_e result;
+       void *trans_param;
+       data_s data;
+} net_nfc_response_read_ndef_t;
+
+typedef struct _net_nfc_response_write_ndef_t
+{
+       net_nfc_error_e result;
+       void *trans_param;
+} net_nfc_response_write_ndef_t;
+
+typedef struct _net_nfc_response_make_read_only_ndef_t
+{
+       net_nfc_error_e result;
+       void *trans_param;
+} net_nfc_response_make_read_only_ndef_t;
+
+typedef struct _net_nfc_response_is_tag_connected_t
+{
+       net_nfc_error_e result;
+       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_error_e result;
+       void *trans_param;
+} net_nfc_response_format_ndef_t;
+
+typedef struct _net_nfc_response_p2p_discovered_t
+{
+       net_nfc_error_e result;
+       net_nfc_target_handle_s *handle;
+} net_nfc_response_p2p_discovered_t;
+
+typedef struct _net_nfc_response_p2p_send_t
+{
+       net_nfc_target_handle_s *handle;
+       net_nfc_error_e result;
+} net_nfc_response_p2p_send_t;
+
+typedef struct _net_nfc_response_llcp_discovered_t
+{
+       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_error_e result;
+} net_nfc_response_llcp_detached_t;
+
+typedef struct _net_nfc_response_incomming_llcp_t
+{
+       net_nfc_error_e result;
+       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_error_e result;
+       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_error_e result;
+       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_error_e result;
+       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_error_e result;
+       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_error_e result;
+       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_error_e result;
+       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_error_e result;
+       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_error_e result;
+       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_error_e result;
+       void *trans_param;
+} net_nfc_response_config_llcp_t;
+
+typedef struct _net_nfc_response_close_llcp_t
+{
+       net_nfc_error_e result;
+       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_error_e result;
+       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_error_e result;
+       uint8_t se_type;
+       void *trans_param;
+} net_nfc_response_set_se_t;
+
+typedef struct _net_nfc_response_get_se_t
+{
+       net_nfc_error_e result;
+       uint8_t se_type;
+       void *trans_param;
+} net_nfc_response_get_se_t;
+
+typedef struct _net_nfc_response_open_internal_se_t
+{
+       net_nfc_error_e result;
+       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_error_e result;
+       void *trans_param;
+} net_nfc_response_close_internal_se_t;
+
+typedef struct _net_nfc_response_send_apdu_t
+{
+       net_nfc_error_e result;
+       data_s data;
+       void *trans_param;
+} net_nfc_response_send_apdu_t;
+
+typedef struct _net_nfc_response_get_server_state_t
+{
+       net_nfc_error_e result;
+       server_state_e state;
+} net_nfc_response_get_server_state_t;
+
+typedef struct _net_nfc_response_connection_handover
+{
+       net_nfc_error_e result;
+       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 _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_INVALD = 0x00, /**< Indicates SE type is Invalid */
+       SECURE_ELEMENT_TYPE_ESE = 0x01, /**< Indicates SE type is SmartMX */
+       SECURE_ELEMENT_TYPE_UICC = 0x02, /**<Indicates SE type is   UICC */
+       SECURE_ELEMENT_TYPE_Unknown = 0x03 /**< Indicates SE type is Unknown */
+} net_nfc_secure_element_type_e;
+
+typedef enum _net_nfc_secure_element_state_e
+{
+       SECURE_ELEMENT_ACTIVE_STATE = 0x00, /**< state of the SE is active  */
+       SECURE_ELEMENT_INACTIVE_STATE = 0x01 /**< state of the SE is In active*/
+
+} net_nfc_secure_element_state_e;
+
+typedef struct _secure_element_info_s
+{
+       net_nfc_target_handle_s *handle;
+       net_nfc_secure_element_type_e secure_element_type;
+       net_nfc_secure_element_state_e secure_element_state;
+
+} net_nfc_secure_element_info_s;
+
+typedef enum _net_nfc_secure_element_mode_e
+{
+       SECURE_ELEMENT_WIRED_MODE = 0x00, /**< Enables Wired Mode communication.This mode shall be applied to */
+       SECURE_ELEMENT_VIRTUAL_MODE, /**< Enables Virtual Mode communication.This can be applied to UICC as well as SmartMX*/
+       SECURE_ELEMENT_OFF_MODE /**< Inactivate SE.This means,put SE in in-active state */
+} net_nfc_secure_element_mode_e;
+
+typedef enum _net_nfc_message_service_e
+{
+       NET_NFC_MESSAGE_SERVICE_RESET = 2000,
+       NET_NFC_MESSAGE_SERVICE_INIT,
+       NET_NFC_MESSAGE_SERVICE_DEINIT,
+       NET_NFC_MESSAGE_SERVICE_STANDALONE_TARGET_DETECTED,
+       NET_NFC_MESSAGE_SERVICE_SE,
+       NET_NFC_MESSAGE_SERVICE_TERMINATION,
+       NET_NFC_MESSAGE_SERVICE_SLAVE_TARGET_DETECTED,
+       NET_NFC_MESSAGE_SERVICE_SLAVE_ESE_DETECTED,
+       NET_NFC_MESSAGE_SERVICE_RESTART_POLLING_LOOP,
+       NET_NFC_MESSAGE_SERVICE_LLCP_ACCEPT,
+       NET_NFC_MESSAGE_SERVICE_LLCP_SEND,
+       NET_NFC_MESSAGE_SERVICE_LLCP_SEND_TO,
+       NET_NFC_MESSAGE_SERVICE_LLCP_RECEIVE,
+       NET_NFC_MESSAGE_SERVICE_LLCP_RECEIVE_FROM,
+       NET_NFC_MESSAGE_SERVICE_LLCP_CONNECT,
+       NET_NFC_MESSAGE_SERVICE_LLCP_CONNECT_SAP,
+       NET_NFC_MESSAGE_SERVICE_LLCP_DISCONNECT,
+       NET_NFC_MESSAGE_SERVICE_LLCP_DEACTIVATED,
+       NET_NFC_MESSAGE_SERVICE_LLCP_SOCKET_ERROR,
+       NET_NFC_MESSAGE_SERVICE_LLCP_SOCKET_ACCEPTED_ERROR,
+       NET_NFC_MESSAGE_SERVICE_LLCP_CLOSE, /**< Type: Response Event,<br>  "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_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;
+
+#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 100644 (file)
index 0000000..a834f1c
--- /dev/null
@@ -0,0 +1,38 @@
+/*\r
+  * Copyright 2012  Samsung Electronics Co., Ltd\r
+  *\r
+  * Licensed under the Flora License, Version 1.0 (the "License");\r
+  * you may not use this file except in compliance with the License.\r
+  * You may obtain a copy of the License at\r
+\r
+  *     http://www.tizenopensource.org/license\r
+  *\r
+  * Unless required by applicable law or agreed to in writing, software\r
+  * distributed under the License is distributed on an "AS IS" BASIS,\r
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+  * See the License for the specific language governing permissions and\r
+  * limitations under the License.\r
+  */\r
+\r
+#ifndef __NET_NFC_UTIL_DEFINES__\r
+#define __NET_NFC_UTIL_DEFINES__\r
+\r
+#define NET_NFC_UTIL_MSG_TYPE_REQUEST 0\r
+#define NET_NFC_UTIL_MSG_TYPE_RESPONSE 1\r
+\r
+#define CONN_HANOVER_MAJOR_VER 1\r
+#define CONN_HANOVER_MINOR_VER 2\r
+\r
+#define CONN_HANDOVER_BT_CARRIER_MIME_NAME "application/vnd.bluetooth.ep.oob"\r
+#define CONN_HANDOVER_WIFI_BSS_CARRIER_MIME_NAME "application/vnd.wfa.wsc"\r
+#define CONN_HANDOVER_WIFI_IBSS_CARRIER_MIME_NAME "application/vnd.wfa.wsc;mode=ibss"\r
+\r
+#define BLUETOOTH_ADDRESS_LENGTH 6\r
+#define HIDDEN_BT_ADDR_FILE "/opt/etc/.bd_addr"\r
+\r
+#define NET_NFC_VCONF_KEY_PROGRESS "db/nfc/progress"\r
+\r
+/* define vconf key */\r
+#define NET_NFC_DISABLE_LAUNCH_POPUP_KEY "memory/nfc/popup_disabled"\r
+\r
+#endif\r
diff --git a/src/commonlib/include/net_nfc_util_handover.h b/src/commonlib/include/net_nfc_util_handover.h
new file mode 100644 (file)
index 0000000..15d6036
--- /dev/null
@@ -0,0 +1,97 @@
+/*\r
+  * Copyright 2012  Samsung Electronics Co., Ltd\r
+  *\r
+  * Licensed under the Flora License, Version 1.0 (the "License");\r
+  * you may not use this file except in compliance with the License.\r
+  * You may obtain a copy of the License at\r
+\r
+  *     http://www.tizenopensource.org/license\r
+  *\r
+  * Unless required by applicable law or agreed to in writing, software\r
+  * distributed under the License is distributed on an "AS IS" BASIS,\r
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+  * See the License for the specific language governing permissions and\r
+  * limitations under the License.\r
+  */\r
+\r
+#ifndef __NET_NFC_UTIL_HANDOVER__\r
+#define __NET_NFC_UTIL_HANDOVER__\r
+\r
+#include "net_nfc_typedef_private.h"\r
+\r
+#ifdef __cplusplus\r
+extern "C"\r
+{\r
+#endif\r
+\r
+net_nfc_error_e net_nfc_util_create_carrier_config(net_nfc_carrier_config_s **config, net_nfc_conn_handover_carrier_type_e type);\r
+\r
+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);\r
+\r
+net_nfc_error_e net_nfc_util_remove_carrier_config_property(net_nfc_carrier_config_s *config, uint16_t attribute);\r
+\r
+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);\r
+\r
+net_nfc_error_e net_nfc_util_append_carrier_config_group(net_nfc_carrier_config_s *config, net_nfc_carrier_property_s *group);\r
+\r
+net_nfc_error_e net_nfc_util_remove_carrier_config_group(net_nfc_carrier_config_s *config, net_nfc_carrier_property_s *group);\r
+\r
+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);\r
+\r
+net_nfc_error_e net_nfc_util_free_carrier_config(net_nfc_carrier_config_s *config);\r
+\r
+net_nfc_error_e net_nfc_util_create_carrier_config_group(net_nfc_carrier_property_s **group, uint16_t attribute);\r
+\r
+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);\r
+\r
+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);\r
+\r
+net_nfc_error_e net_nfc_util_remove_carrier_config_group_property(net_nfc_carrier_property_s *group, uint16_t attribute);\r
+\r
+net_nfc_error_e net_nfc_util_free_carrier_group(net_nfc_carrier_property_s *group);\r
+\r
+net_nfc_error_e net_nfc_util_create_ndef_record_with_carrier_config(ndef_record_s **record, net_nfc_carrier_config_s *config);\r
+\r
+net_nfc_error_e net_nfc_util_create_carrier_config_from_config_record(net_nfc_carrier_config_s **config, ndef_record_s *record);\r
+\r
+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);\r
+\r
+net_nfc_error_e net_nfc_util_remove_carrier_config_record(ndef_message_s *message, ndef_record_s *record);\r
+\r
+net_nfc_error_e net_nfc_util_get_carrier_config_record(ndef_message_s *message, int index, ndef_record_s **record);\r
+\r
+net_nfc_error_e net_nfc_util_get_handover_random_number(ndef_message_s *message, unsigned short *random_number);\r
+\r
+net_nfc_error_e net_nfc_util_get_alternative_carrier_record_count(ndef_message_s *message, unsigned int *count);\r
+\r
+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);\r
+\r
+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);\r
+\r
+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);\r
+\r
+/**\r
+ this function will get carrier type.\r
+\r
+ @param[in]    carrier_info                    connection handover carrier info handler\r
+ @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.\r
+\r
+ @return               return the result of the calling the function\r
+\r
+ @exception NET_NFC_NULL_PARAMETER             parameter(s) has(have) illegal NULL pointer(s)\r
+ */\r
+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);\r
+\r
+net_nfc_error_e net_nfc_util_create_handover_request_message(ndef_message_s **message);\r
+\r
+net_nfc_error_e net_nfc_util_create_handover_select_message(ndef_message_s **message);\r
+\r
+net_nfc_error_e net_nfc_util_create_handover_error_record(ndef_record_s **record, uint8_t reason, uint32_t data);\r
+\r
+net_nfc_error_e net_nfc_util_get_selector_power_status(ndef_message_s *message, net_nfc_conn_handover_carrier_state_e *power_state);\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+\r
+#endif\r
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 100644 (file)
index 0000000..7cd3844
--- /dev/null
@@ -0,0 +1,65 @@
+/*\r
+  * Copyright 2012  Samsung Electronics Co., Ltd\r
+  *\r
+  * Licensed under the Flora License, Version 1.0 (the "License");\r
+  * you may not use this file except in compliance with the License.\r
+  * You may obtain a copy of the License at\r
+\r
+  *     http://www.tizenopensource.org/license\r
+  *\r
+  * Unless required by applicable law or agreed to in writing, software\r
+  * distributed under the License is distributed on an "AS IS" BASIS,\r
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+  * See the License for the specific language governing permissions and\r
+  * limitations under the License.\r
+  */\r
+\r
+#ifndef __NET_NFC_UTIL_NDEF_MESSAGE__\r
+#define __NET_NFC_UTIL_NDEF_MESSAGE__\r
+\r
+#include "net_nfc_typedef_private.h"\r
+\r
+/*\r
+ convert rawdata into ndef message structure\r
+ */\r
+net_nfc_error_e net_nfc_util_convert_rawdata_to_ndef_message(data_s *rawdata, ndef_message_s *ndef);\r
+\r
+/*\r
+ this util function converts into rawdata from ndef message structure\r
+ */\r
+net_nfc_error_e net_nfc_util_convert_ndef_message_to_rawdata(ndef_message_s *ndef, data_s *rawdata);\r
+\r
+/*\r
+ get total bytes of ndef message in serial form\r
+ */\r
+uint32_t net_nfc_util_get_ndef_message_length(ndef_message_s *message);\r
+\r
+/*\r
+ free ndef message. this function also free any defined buffer insdie structures\r
+ */\r
+net_nfc_error_e net_nfc_util_free_ndef_message(ndef_message_s *msg);\r
+\r
+/*\r
+ append record into ndef message\r
+ */\r
+net_nfc_error_e net_nfc_util_append_record(ndef_message_s *msg, ndef_record_s *record);\r
+\r
+/*\r
+ print out ndef structure value with printf function. this is for just debug purpose\r
+ */\r
+void net_nfc_util_print_ndef_message(ndef_message_s *msg);\r
+\r
+net_nfc_error_e net_nfc_util_create_ndef_message(ndef_message_s **ndef_message);\r
+\r
+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);\r
+\r
+net_nfc_error_e net_nfc_util_append_record_by_index(ndef_message_s *ndef_message, int index, ndef_record_s *record);\r
+\r
+net_nfc_error_e net_nfc_util_get_record_by_index(ndef_message_s *ndef_message, int index, ndef_record_s **record);\r
+\r
+net_nfc_error_e net_nfc_util_remove_record_by_index(ndef_message_s *ndef_message, int index);\r
+\r
+net_nfc_error_e net_nfc_util_search_record_by_id(ndef_message_s *ndef_message, data_s *id, ndef_record_s **record);\r
+\r
+#endif\r
+\r
diff --git a/src/commonlib/include/net_nfc_util_ndef_parser.h b/src/commonlib/include/net_nfc_util_ndef_parser.h
new file mode 100644 (file)
index 0000000..394c7f8
--- /dev/null
@@ -0,0 +1,85 @@
+/*
+ * Copyright (C) 2010 NXP Semiconductors
+ * Copyright (C) 2012 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_UTIL_NDEF_PARSER__
+#define __NET_NFC_UTIL_NDEF_PARSER__
+
+#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 SLP_FRINET_NFC_NDEFRECORD_FLAGS_MB       ((uint8_t)0x80)  /**< This marks the begin of a NDEF Message. */
+#define SLP_FRINET_NFC_NDEFRECORD_FLAGS_ME       ((uint8_t)0x40)  /**< Set if the record is at the Message End. */
+#define SLP_FRINET_NFC_NDEFRECORD_FLAGS_CF       ((uint8_t)0x20)  /**< Chunk Flag: The record is a record chunk only. */
+#define SLP_FRINET_NFC_NDEFRECORD_FLAGS_SR       ((uint8_t)0x10)  /**< Short Record: Payload Length is encoded in ONE byte only. */
+#define SLP_FRINET_NFC_NDEFRECORD_FLAGS_IL       ((uint8_t)0x08)  /**< The ID Length Field is present. */
+/*@}*/
+
+/* Internal:
+ * NDEF Record #defines for constant value
+ */
+#define SLPFRINFCNDEFRECORD_CHUNKBIT_SET         1               /** \internal Chunk Bit is set. */
+#define SLPFRINFCNDEFRECORD_CHUNKBIT_SET_ZERO    0                             /** \internal Chunk Bit is not set. */
+#define SLPNFCSTSHL8                           8
+#define SLPNFCSTSHL16                            16              /** \internal Shift 16 bits(left or right). */
+#define SLPNFCSTSHL24                            24              /** \internal Shift 24 bits(left or right). */
+#define SLPFRINFCNDEFRECORD_NORMAL_RECORD_BYTE   4               /** \internal Normal record. */
+#define SLP_FRINET_NFC_NDEFRECORD_TNFBYTE_MASK       ((uint8_t)0x07) /** \internal For masking */
+#define SLP_FRINET_NFC_NDEFRECORD_BUF_INC1           1               /** \internal Increment Buffer Address by 1 */
+#define SLP_FRINET_NFC_NDEFRECORD_BUF_INC2           2               /** \internal Increment Buffer Address by 2 */
+#define SLP_FRINET_NFC_NDEFRECORD_BUF_INC3           3               /** \internal Increment Buffer Address by 3 */
+#define SLP_FRINET_NFC_NDEFRECORD_BUF_INC4           4               /** \internal Increment Buffer Address by 4 */
+#define SLP_FRINET_NFC_NDEFRECORD_BUF_INC5           5               /** \internal Increment Buffer Address by 5 */
+#define SLP_FRINET_NFC_NDEFRECORD_BUF_TNF_VALUE      ((uint8_t)0x00) /** \internal If TNF = Empty, Unknown and Unchanged, the id, type and payload length is ZERO  */
+#define SLP_FRINET_NFC_NDEFRECORD_FLAG_MASK          ((uint8_t)0xF8) /** \internal To Mask the Flag Byte */
+
+
+#define NET_NFC_NDEF_TNF_EMPTY        ((uint8_t)0x00)  /**< Empty Record, no type, ID or payload present. */
+#define NET_NFC_NDEF_TNF_NFCWELLKNOWN ((uint8_t)0x01)  /**< NFC well-known type (RTD). */
+#define NET_NFC_NDEF_TNF_MEDIATYPE    ((uint8_t)0x02)  /**< Media Type. */
+#define NET_NFC_NDEF_TNF_ABSURI       ((uint8_t)0x03)  /**< Absolute URI. */
+#define NET_NFC_NDEF_TNF_NFCEXT       ((uint8_t)0x04)  /**< Nfc External Type (following the RTD format). */
+#define NET_NFC_NDEF_TNF_UNKNOWN      ((uint8_t)0x05)  /**< Unknown type; Contains no Type information. */
+#define NET_NFC_NDEF_TNF_UNCHANGED    ((uint8_t)0x06)  /**< Unchanged: Used for Chunked Records. */
+#define NET_NFC_NDEF_TNF_RESERVED     ((uint8_t)0x07)  /**< RFU, must not be used. */
+
+void __phFriNfc_NdefRecord_RecordFlag(uint8_t* rawData, ndef_record_s* record);
+uint8_t __phFriNfc_NdefRecord_TypeNameFormat(uint8_t *rawData, ndef_record_s* record);
+net_nfc_error_e __phFriNfc_NdefRecord_RecordIDCheck(uint8_t *rawData,
+       uint8_t *TypeLength,
+       uint8_t *TypeLengthByte,
+       uint8_t *PayloadLengthByte,
+       uint32_t *PayloadLength,
+       uint8_t *IDLengthByte,
+       uint8_t *IDLength,
+       ndef_record_s *record);
+net_nfc_error_e __phFriNfc_NdefRecord_Parse(ndef_record_s*Record, uint8_t *RawRecord, int *readData);
+uint8_t __phFriNfc_NdefRecord_GenFlag(ndef_record_s* record);
+net_nfc_error_e __phFriNfc_NdefRecord_Generate(ndef_record_s*Record,
+       uint8_t *Buffer,
+       uint32_t MaxBufferSize,
+       uint32_t *BytesWritten);
+
+#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 100644 (file)
index 0000000..8bbc1c6
--- /dev/null
@@ -0,0 +1,52 @@
+/*\r
+  * Copyright 2012  Samsung Electronics Co., Ltd\r
+  *\r
+  * Licensed under the Flora License, Version 1.0 (the "License");\r
+  * you may not use this file except in compliance with the License.\r
+  * You may obtain a copy of the License at\r
+\r
+  *     http://www.tizenopensource.org/license\r
+  *\r
+  * Unless required by applicable law or agreed to in writing, software\r
+  * distributed under the License is distributed on an "AS IS" BASIS,\r
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+  * See the License for the specific language governing permissions and\r
+  * limitations under the License.\r
+  */\r
+\r
+#ifndef __NET_NFC_UTIL_NDEF_RECORD__\r
+#define __NET_NFC_UTIL_NDEF_RECORD__\r
+\r
+#include "net_nfc_typedef_private.h"\r
+\r
+/*\r
+ create record structure with basic info\r
+ */\r
+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);\r
+\r
+/*\r
+ create text type record\r
+ */\r
+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);\r
+\r
+/*\r
+ this utility function help to create uri type record\r
+ */\r
+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);\r
+\r
+/*\r
+ free ndef record. it free all the buffered data\r
+ */\r
+net_nfc_error_e net_nfc_util_free_record(ndef_record_s *record);\r
+\r
+/*\r
+ convert schema enum value to character string.\r
+ */\r
+net_nfc_error_e net_nfc_util_set_record_id(ndef_record_s *record, uint8_t *data, int length);\r
+\r
+/*\r
+ get total bytes of ndef record in serial form\r
+ */\r
+uint32_t net_nfc_util_get_record_length(ndef_record_s *record);\r
+\r
+#endif\r
diff --git a/src/commonlib/include/net_nfc_util_private.h b/src/commonlib/include/net_nfc_util_private.h
new file mode 100644 (file)
index 0000000..0383099
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+  * Copyright 2012  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://www.tizenopensource.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 <stdio.h>
+#include <libgen.h>
+
+#include "net_nfc_typedef_private.h"
+
+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__)
+
+/* 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);
+
+void net_nfc_util_play_target_detect_sound(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/net_nfc_util.c b/src/commonlib/net_nfc_util.c
new file mode 100644 (file)
index 0000000..1206ef9
--- /dev/null
@@ -0,0 +1,453 @@
+/*
+  * Copyright 2012  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://www.tizenopensource.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 <stdlib.h>
+#include <string.h>
+#include <pthread.h>
+
+// 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"
+
+// platform header
+#include <bluetooth-api.h>
+#include <vconf.h>
+#include <svi.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://anonymouse:anonymouse@",
+               "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;
+
+NET_NFC_EXPORT_API void __net_nfc_util_free_mem(void **mem, char *filename, unsigned int line)
+{
+       if (mem == NULL || *mem == NULL)
+       {
+               DEBUG_MSG("FILE: %s, LINE:%d, Invalid parameter in mem free util (pointer 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", filename, line);
+               return;
+       }
+
+       if (*mem != NULL)
+       {
+               DEBUG_MSG("FILE: %s, LINE:%d, WARNING: Pointer is already allocated or it was not initialized with NULL", filename, line);
+       }
+
+       *mem = calloc(1, size);
+
+       if (*mem == NULL)
+       {
+               DEBUG_MSG("FILE: %s, LINE:%d, Allocation is failed\n", 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->buffer == 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, };
+
+                               char 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();
+}
+
+void net_nfc_util_play_target_detect_sound(void)
+{
+       int bSoundOn = 0;
+       int bVibrationOn = 0;
+
+       int svi_handle = -1;
+       int err;
+       if (vconf_get_bool(VCONFKEY_SETAPPL_SOUND_STATUS_BOOL, &bSoundOn) < 0)
+               return;
+
+       if (vconf_get_bool(VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL, &bVibrationOn) < 0)
+               return;
+
+       err = svi_init(&svi_handle);
+       if (err != SVI_SUCCESS)
+       {
+               svi_fini(svi_handle);
+               return;
+       }
+
+
+       if (bVibrationOn)
+       {
+               err = svi_play_vib(svi_handle, SVI_VIB_TOUCH_SIP);
+       }
+
+       if (bSoundOn)
+       {
+               err = svi_play_sound(svi_handle, SVI_SND_TOUCH_SIP);
+       }
+
+       svi_fini(svi_handle);
+}
+
+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 (file)
index 0000000..fc41507
--- /dev/null
@@ -0,0 +1,1544 @@
+/*\r
+  * Copyright 2012  Samsung Electronics Co., Ltd\r
+  *\r
+  * Licensed under the Flora License, Version 1.0 (the "License");\r
+  * you may not use this file except in compliance with the License.\r
+  * You may obtain a copy of the License at\r
+\r
+  *     http://www.tizenopensource.org/license\r
+  *\r
+  * Unless required by applicable law or agreed to in writing, software\r
+  * distributed under the License is distributed on an "AS IS" BASIS,\r
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+  * See the License for the specific language governing permissions and\r
+  * limitations under the License.\r
+  */\r
+\r
+#include <glib.h>\r
+\r
+#include "net_nfc_typedef_private.h"\r
+#include "net_nfc_debug_private.h"\r
+#include "net_nfc_util_defines.h"\r
+#include "net_nfc_util_private.h"\r
+#include "net_nfc_util_ndef_record.h"\r
+#include "net_nfc_util_ndef_message.h"\r
+#include "net_nfc_util_handover.h"\r
+\r
+typedef struct _search_index\r
+{\r
+       int target;\r
+       int current;\r
+       void *found;\r
+} search_index;\r
+\r
+static int __property_equal_to(gconstpointer key1, gconstpointer key2)\r
+{\r
+       net_nfc_carrier_property_s *arg1 = (net_nfc_carrier_property_s *)key1;\r
+       net_nfc_carrier_property_s *arg2 = (net_nfc_carrier_property_s *)key2;\r
+\r
+       if (arg1->attribute < arg2->attribute)\r
+       {\r
+               return -1;\r
+       }\r
+       else if (arg1->attribute > arg2->attribute)\r
+       {\r
+               return 1;\r
+       }\r
+       else\r
+       {\r
+               return 0;\r
+       }\r
+}\r
+\r
+static net_nfc_carrier_property_s *__find_property_by_attrubute(GList *list, uint16_t attribute)\r
+{\r
+       GList *found = NULL;\r
+       net_nfc_carrier_property_s temp;\r
+\r
+       temp.attribute = attribute;\r
+       found = g_list_find_custom(list, &temp, __property_equal_to);\r
+\r
+       if (found == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       return (net_nfc_carrier_property_s *)found->data;\r
+}\r
+\r
+static void __find_nth_group(gpointer data, gpointer user_data)\r
+{\r
+       net_nfc_carrier_property_s *info = (net_nfc_carrier_property_s *)data;\r
+       search_index *nth = (search_index *)user_data;\r
+\r
+       if (info == NULL || user_data == NULL)\r
+               return;\r
+\r
+       if (info->is_group)\r
+       {\r
+               if (nth->current == nth->target)\r
+               {\r
+                       nth->found = data;\r
+               }\r
+               nth->current++;\r
+       }\r
+}\r
+\r
+static void __free_all_data(gpointer data, gpointer user_data)\r
+{\r
+       net_nfc_carrier_property_s *info = (net_nfc_carrier_property_s *)data;\r
+\r
+       if (info == NULL)\r
+               return;\r
+\r
+       if (info->is_group)\r
+       {\r
+               DEBUG_MSG("FREE: group is found");\r
+               net_nfc_util_free_carrier_group((net_nfc_carrier_property_s *)info);\r
+       }\r
+       else\r
+       {\r
+               DEBUG_MSG("FREE: element is found ATTRIB:0x%X length:%d", info->attribute, info->length);\r
+               _net_nfc_util_free_mem(info->data);\r
+               _net_nfc_util_free_mem(info);\r
+       }\r
+}\r
+\r
+static net_nfc_error_e __net_nfc_util_create_connection_handover_collsion_resolution_record(ndef_record_s **record)\r
+{\r
+       uint32_t state = 0;\r
+       data_s typeName = { 0 };\r
+       data_s payload = { 0 };\r
+       uint8_t rand_buffer[2] = { 0, 0 };\r
+       uint16_t random_num;\r
+\r
+       if (record == NULL)\r
+               return NET_NFC_NULL_PARAMETER;\r
+\r
+       state = (uint32_t)time(NULL);\r
+       random_num = (unsigned short)rand_r(&state);\r
+\r
+       typeName.buffer = (uint8_t *)COLLISION_DETECT_RECORD_TYPE;\r
+       typeName.length = strlen(COLLISION_DETECT_RECORD_TYPE);\r
+\r
+       rand_buffer[0] = (random_num & 0xff00) >> 8;    // MSB\r
+       rand_buffer[1] = (random_num & 0x00ff); // LSB\r
+\r
+       payload.buffer = rand_buffer;\r
+       payload.length = 2;\r
+\r
+       DEBUG_MSG("rand number = [0x%x] [0x%x] => [0x%x]", payload.buffer[0], payload.buffer[1], random_num);\r
+\r
+       return net_nfc_util_create_record(NET_NFC_RECORD_WELL_KNOWN_TYPE, &typeName, NULL, &payload, record);\r
+}\r
+\r
+static int __net_nfc_get_size_of_attribute(int attribute)\r
+{\r
+       switch (attribute)\r
+       {\r
+       case NET_NFC_BT_ATTRIBUTE_UUID16_PART :\r
+       case NET_NFC_BT_ATTRIBUTE_UUID16 :\r
+       case NET_NFC_BT_ATTRIBUTE_UUID32_PART :\r
+       case NET_NFC_BT_ATTRIBUTE_UUID32 :\r
+       case NET_NFC_BT_ATTRIBUTE_UUID128_PART :\r
+       case NET_NFC_BT_ATTRIBUTE_UUID128 :\r
+       case NET_NFC_BT_ATTRIBUTE_NAME_PART :\r
+       case NET_NFC_BT_ATTRIBUTE_NAME :\r
+       case NET_NFC_BT_ATTRIBUTE_TXPOWER :\r
+       case NET_NFC_BT_ATTRIBUTE_OOB_COD :\r
+       case NET_NFC_BT_ATTRIBUTE_OOB_HASH_C :\r
+       case NET_NFC_BT_ATTRIBUTE_OOB_HASH_R :\r
+       case NET_NFC_BT_ATTRIBUTE_ID :\r
+       case NET_NFC_BT_ATTRIBUTE_MANUFACTURER :\r
+       case NET_NFC_BT_ATTRIBUTE_ADDRESS :\r
+               //              case NET_NFC_WIFI_ATTRIBUTE_VERSION2:\r
+               return 1;\r
+\r
+       default :\r
+               return 2;\r
+       }\r
+}\r
+\r
+net_nfc_error_e net_nfc_util_create_carrier_config(net_nfc_carrier_config_s **config, net_nfc_conn_handover_carrier_type_e type)\r
+{\r
+       if (config == NULL)\r
+       {\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+\r
+       if (type < 0 || type >= NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN)\r
+       {\r
+               return NET_NFC_OUT_OF_BOUND;\r
+       }\r
+\r
+       _net_nfc_util_alloc_mem(*config, sizeof(net_nfc_carrier_config_s));\r
+       if (*config == NULL)\r
+       {\r
+               return NET_NFC_ALLOC_FAIL;\r
+       }\r
+\r
+       (*config)->type = type;\r
+       (*config)->length = 0;\r
+\r
+       return NET_NFC_OK;\r
+}\r
+\r
+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)\r
+{\r
+       net_nfc_carrier_property_s *elem = NULL;\r
+\r
+       DEBUG_MSG("ADD property: [ATTRIB:0x%X, SIZE:%d]", attribute, size);\r
+\r
+       if (config == NULL || data == NULL)\r
+       {\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+\r
+       if (__find_property_by_attrubute(config->data, attribute) != NULL)\r
+       {\r
+               return NET_NFC_ALREADY_REGISTERED;\r
+       }\r
+\r
+       _net_nfc_util_alloc_mem(elem, sizeof (net_nfc_carrier_property_s));\r
+       if (elem == NULL)\r
+       {\r
+               return NET_NFC_ALLOC_FAIL;\r
+       }\r
+       elem->attribute = attribute;\r
+       elem->length = size;\r
+       elem->is_group = false;\r
+       _net_nfc_util_alloc_mem(elem->data, size);\r
+\r
+       if (elem->data == NULL)\r
+       {\r
+               _net_nfc_util_free_mem(elem);\r
+               return NET_NFC_ALLOC_FAIL;\r
+       }\r
+       memcpy(elem->data, data, size);\r
+\r
+       config->data = g_list_append(config->data, elem);\r
+       config->length += size + 2 * __net_nfc_get_size_of_attribute(attribute);\r
+\r
+       DEBUG_MSG("ADD completed total length %d", config->length);\r
+\r
+       return NET_NFC_OK;\r
+}\r
+\r
+net_nfc_error_e net_nfc_util_remove_carrier_config_property(net_nfc_carrier_config_s *config, uint16_t attribute)\r
+{\r
+       net_nfc_carrier_property_s *elem = NULL;\r
+\r
+       if (config == NULL)\r
+       {\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+\r
+       elem = __find_property_by_attrubute(config->data, attribute);\r
+       if (elem == NULL)\r
+       {\r
+               return NET_NFC_NO_DATA_FOUND;\r
+       }\r
+\r
+       config->data = g_list_remove(config->data, elem);\r
+       config->length -= (elem->length + 2 * __net_nfc_get_size_of_attribute(attribute));\r
+\r
+       if (elem->is_group)\r
+       {\r
+               net_nfc_util_free_carrier_group((net_nfc_carrier_property_s *)elem);\r
+       }\r
+       else\r
+       {\r
+               _net_nfc_util_free_mem(elem->data);\r
+               _net_nfc_util_free_mem(elem);\r
+       }\r
+\r
+       return NET_NFC_OK;\r
+}\r
+\r
+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)\r
+{\r
+       net_nfc_carrier_property_s *elem = NULL;\r
+\r
+       if (config == NULL || size == NULL || data == NULL)\r
+       {\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+\r
+       elem = __find_property_by_attrubute(config->data, attribute);\r
+       if (elem == NULL)\r
+       {\r
+               *size = 0;\r
+               *data = NULL;\r
+               return NET_NFC_NO_DATA_FOUND;\r
+       }\r
+\r
+       *size = elem->length;\r
+       if (elem->is_group)\r
+       {\r
+               *data = NULL;\r
+       }\r
+       else\r
+       {\r
+               *data = elem->data;\r
+       }\r
+\r
+       return NET_NFC_OK;\r
+}\r
+\r
+net_nfc_error_e net_nfc_util_append_carrier_config_group(net_nfc_carrier_config_s *config, net_nfc_carrier_property_s *group)\r
+{\r
+       if (config == NULL || group == NULL)\r
+       {\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+       if (g_list_find(config->data, group) != NULL)\r
+       {\r
+               return NET_NFC_ALREADY_REGISTERED;\r
+       }\r
+\r
+       config->data = g_list_append(config->data, group);\r
+       config->length += group->length;\r
+\r
+       return NET_NFC_OK;\r
+}\r
+\r
+net_nfc_error_e net_nfc_util_remove_carrier_config_group(net_nfc_carrier_config_s *config, net_nfc_carrier_property_s *group)\r
+{\r
+       if (config == NULL || group == NULL)\r
+       {\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+\r
+       if (g_list_find(config->data, group) != NULL)\r
+       {\r
+               return NET_NFC_NO_DATA_FOUND;\r
+       }\r
+\r
+       config->length -= group->length;\r
+       config->data = g_list_remove(config->data, group);\r
+\r
+       net_nfc_util_free_carrier_group((net_nfc_carrier_property_s *)group);\r
+\r
+       return NET_NFC_OK;\r
+}\r
+\r
+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)\r
+{\r
+       search_index result;\r
+\r
+       if (config == NULL || group == NULL)\r
+       {\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+\r
+       if (index < 0)\r
+       {\r
+               return NET_NFC_OUT_OF_BOUND;\r
+       }\r
+\r
+       result.current = 0;\r
+       result.target = index;\r
+       result.found = NULL;\r
+\r
+       g_list_foreach(config->data, __find_nth_group, &result);\r
+\r
+       if (result.found == NULL)\r
+       {\r
+               return NET_NFC_NO_DATA_FOUND;\r
+       }\r
+       *group = (net_nfc_carrier_property_s *)result.found;\r
+\r
+       return NET_NFC_OK;\r
+}\r
+\r
+net_nfc_error_e net_nfc_util_free_carrier_config(net_nfc_carrier_config_s *config)\r
+{\r
+       if (config == NULL)\r
+       {\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+\r
+       g_list_foreach(config->data, __free_all_data, NULL);\r
+       g_list_free(config->data);\r
+\r
+       _net_nfc_util_free_mem(config);\r
+\r
+       return NET_NFC_OK;\r
+}\r
+\r
+net_nfc_error_e net_nfc_util_create_carrier_config_group(net_nfc_carrier_property_s **group, uint16_t attribute)\r
+{\r
+       if (group == NULL)\r
+       {\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+\r
+       _net_nfc_util_alloc_mem(*group, sizeof(net_nfc_carrier_property_s));\r
+       if (*group == NULL)\r
+       {\r
+               return NET_NFC_ALLOC_FAIL;\r
+       }\r
+\r
+       (*group)->attribute = attribute;\r
+       (*group)->is_group = true;\r
+\r
+       return NET_NFC_OK;\r
+}\r
+\r
+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)\r
+{\r
+       net_nfc_carrier_property_s *elem = NULL;\r
+\r
+       DEBUG_MSG("ADD group property: [ATTRIB:0x%X, SIZE:%d]", attribute, size);\r
+\r
+       if (group == NULL || data == NULL)\r
+       {\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+\r
+       if (__find_property_by_attrubute((GList *)group->data, attribute) != NULL)\r
+       {\r
+               return NET_NFC_ALREADY_REGISTERED;\r
+       }\r
+\r
+       _net_nfc_util_alloc_mem(elem, sizeof (net_nfc_carrier_property_s));\r
+       if (elem == NULL)\r
+       {\r
+               return NET_NFC_ALLOC_FAIL;\r
+       }\r
+       elem->attribute = attribute;\r
+       elem->length = size;\r
+       elem->is_group = false;\r
+\r
+       _net_nfc_util_alloc_mem(elem->data, size);\r
+       if (elem->data == NULL)\r
+       {\r
+               _net_nfc_util_free_mem(elem);\r
+               return NET_NFC_ALLOC_FAIL;\r
+       }\r
+       memcpy(elem->data, data, size);\r
+       group->length += size + 2 * __net_nfc_get_size_of_attribute(attribute);\r
+       group->data = g_list_append((GList *)(group->data), elem);\r
+\r
+       DEBUG_MSG("ADD group completed total length %d", group->length);\r
+\r
+       return NET_NFC_OK;\r
+}\r
+\r
+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)\r
+{\r
+       net_nfc_carrier_property_s *elem = NULL;\r
+\r
+       if (group == NULL || size == NULL || data == NULL)\r
+       {\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+\r
+       elem = __find_property_by_attrubute((GList*)(group->data), attribute);\r
+       if (elem == NULL)\r
+       {\r
+               *size = 0;\r
+               *data = NULL;\r
+               return NET_NFC_NO_DATA_FOUND;\r
+       }\r
+\r
+       *size = elem->length;\r
+       *data = elem->data;\r
+\r
+       return NET_NFC_OK;\r
+}\r
+\r
+net_nfc_error_e net_nfc_util_remove_carrier_config_group_property(net_nfc_carrier_property_s *group, uint16_t attribute)\r
+{\r
+       net_nfc_carrier_property_s *elem = NULL;\r
+\r
+       if (group == NULL)\r
+       {\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+\r
+       elem = __find_property_by_attrubute((GList*)(group->data), attribute);\r
+       if (elem == NULL)\r
+       {\r
+               return NET_NFC_NO_DATA_FOUND;\r
+       }\r
+       group->length -= elem->length;\r
+       group->data = g_list_remove((GList*)(group->data), elem);\r
+\r
+       _net_nfc_util_free_mem(elem->data);\r
+       _net_nfc_util_free_mem(elem);\r
+\r
+       return NET_NFC_OK;\r
+\r
+}\r
+\r
+net_nfc_error_e net_nfc_util_free_carrier_group(net_nfc_carrier_property_s *group)\r
+{\r
+       if (group == NULL)\r
+       {\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+       g_list_foreach((GList*)(group->data), __free_all_data, NULL);\r
+       g_list_free((GList*)(group->data));\r
+\r
+       _net_nfc_util_free_mem(group);\r
+\r
+       return NET_NFC_OK;\r
+}\r
+\r
+static void __make_serial_wifi(gpointer data, gpointer user_data)\r
+{\r
+       net_nfc_carrier_property_s *info = (net_nfc_carrier_property_s *)data;\r
+       data_s *payload = (data_s *)user_data;\r
+       uint8_t *current;\r
+       int inc = 0;\r
+\r
+       if (info == NULL || user_data == NULL)\r
+               return;\r
+\r
+       current = payload->buffer + payload->length;\r
+       inc = __net_nfc_get_size_of_attribute(info->attribute);\r
+\r
+       if (info->is_group)\r
+       {\r
+               DEBUG_MSG("[WIFI]Found Group make recursive");\r
+               *(uint16_t *)current = info->attribute;\r
+               *(uint16_t *)(current + inc) = info->length;\r
+               payload->length += (inc + inc);\r
+               g_list_foreach((GList *)info->data, __make_serial_wifi, payload);\r
+       }\r
+       else\r
+       {\r
+               DEBUG_MSG("[WIFI]Element is found attrib:0x%X length:%d current:%d", info->attribute, info->length, payload->length);\r
+               *(uint16_t *)current = info->attribute;\r
+               *(uint16_t *)(current + inc) = info->length;\r
+               memcpy(current + inc + inc, info->data, info->length);\r
+               payload->length += (inc + inc + info->length);\r
+       }\r
+}\r
+\r
+static void __make_serial_bt(gpointer data, gpointer user_data)\r
+{\r
+       net_nfc_carrier_property_s *info = (net_nfc_carrier_property_s *)data;\r
+       data_s *payload = (data_s *)user_data;\r
+       uint8_t *current;\r
+       int inc = 0;\r
+\r
+       if (info == NULL || user_data == NULL)\r
+               return;\r
+\r
+       current = payload->buffer + payload->length; /* payload->length is zero */\r
+\r
+       if (info->is_group)\r
+       {\r
+               DEBUG_MSG("[BT]Found Group. call recursive");\r
+               g_list_foreach((GList *)info->data, __make_serial_bt, payload);\r
+       }\r
+       else\r
+       {\r
+               if (info->attribute != NET_NFC_BT_ATTRIBUTE_ADDRESS)\r
+               {\r
+                       DEBUG_MSG("[BT]Element is found attrib:0x%X length:%d current:%d", info->attribute, info->length, payload->length);\r
+                       inc = __net_nfc_get_size_of_attribute(info->attribute);\r
+                       *current = info->length + 1;\r
+                       *(current + inc) = info->attribute;\r
+                       memcpy(current + inc + inc, info->data, info->length);\r
+                       payload->length += (inc + inc + info->length);\r
+               }\r
+               else\r
+               {\r
+                       DEBUG_MSG("[BT]BT address is found length:%d", info->length);\r
+                       memcpy(current, info->data, info->length);\r
+                       payload->length += (info->length);\r
+               }\r
+       }\r
+}\r
+\r
+net_nfc_error_e net_nfc_util_create_ndef_record_with_carrier_config(ndef_record_s **record, net_nfc_carrier_config_s *config)\r
+{\r
+       data_s payload = { NULL, 0 };\r
+       data_s record_type = { NULL, 0 };\r
+\r
+       if (record == NULL || config == NULL)\r
+       {\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+\r
+       _net_nfc_util_alloc_mem(payload.buffer, config->length);\r
+       if (payload.buffer == NULL)\r
+       {\r
+               return NET_NFC_ALLOC_FAIL;\r
+       }\r
+       payload.length = 0; /* this should be zero because this will be used as current position of data written */\r
+\r
+       if (config->type == NET_NFC_CONN_HANDOVER_CARRIER_WIFI_BSS)\r
+       {\r
+               record_type.buffer = (uint8_t *)CONN_HANDOVER_WIFI_BSS_CARRIER_MIME_NAME;\r
+               record_type.length = strlen(CONN_HANDOVER_WIFI_BSS_CARRIER_MIME_NAME);\r
+               g_list_foreach(config->data, __make_serial_wifi, &payload);\r
+       }\r
+       else if (config->type == NET_NFC_CONN_HANDOVER_CARRIER_WIFI_IBSS)\r
+       {\r
+               record_type.buffer = (uint8_t *)CONN_HANDOVER_WIFI_IBSS_CARRIER_MIME_NAME;\r
+               record_type.length = strlen(CONN_HANDOVER_WIFI_IBSS_CARRIER_MIME_NAME);\r
+               g_list_foreach(config->data, __make_serial_wifi, &payload);\r
+       }\r
+       else if (config->type == NET_NFC_CONN_HANDOVER_CARRIER_BT)\r
+       {\r
+               record_type.buffer = (uint8_t *)CONN_HANDOVER_BT_CARRIER_MIME_NAME;\r
+               record_type.length = strlen(CONN_HANDOVER_BT_CARRIER_MIME_NAME);\r
+               payload.buffer += 2; /* OOB total length */\r
+               g_list_foreach(config->data, __make_serial_bt, &payload);\r
+               payload.buffer -= 2; /* return to original */\r
+               payload.length += 2;\r
+               payload.buffer[0] = payload.length & 0xFF;\r
+               payload.buffer[1] = (payload.length >> 8) & 0xFF;\r
+       }\r
+       else\r
+       {\r
+               return NET_NFC_NOT_SUPPORTED;\r
+       }\r
+\r
+       DEBUG_MSG("payload length = %d", payload.length);\r
+\r
+       return net_nfc_util_create_record(NET_NFC_RECORD_MIME_TYPE, &record_type, NULL, &payload, record);\r
+}\r
+\r
+static net_nfc_error_e __net_nfc_get_list_from_serial_for_wifi(GList **list, uint8_t *data, uint32_t length)\r
+{\r
+       net_nfc_carrier_property_s *elem = NULL;\r
+       uint8_t *current = data;\r
+       uint8_t *last = current + length;\r
+\r
+       while (current < last)\r
+       {\r
+               _net_nfc_util_alloc_mem(elem, sizeof(net_nfc_carrier_property_s));\r
+               if (elem == NULL)\r
+               {\r
+                       return NET_NFC_ALLOC_FAIL;\r
+               }\r
+               elem->attribute = *((uint16_t *)current);\r
+               elem->length = *((uint16_t *)(current + 2));\r
+\r
+               if (elem->attribute == NET_NFC_WIFI_ATTRIBUTE_CREDENTIAL)\r
+               {\r
+                       __net_nfc_get_list_from_serial_for_wifi((GList **)&(elem->data), (current + 4), elem->length);\r
+                       elem->is_group = true;\r
+               }\r
+               else\r
+               {\r
+                       _net_nfc_util_alloc_mem(elem->data, elem->length);\r
+                       if (elem->data == NULL)\r
+                       {\r
+                               _net_nfc_util_free_mem(elem);\r
+                               return NET_NFC_ALLOC_FAIL;\r
+                       }\r
+                       memcpy(elem->data, (current + 4), elem->length);\r
+                       elem->is_group = false;\r
+               }\r
+               *list = g_list_append(*list, elem);\r
+               current += (4 + elem->length);\r
+       }\r
+\r
+       return NET_NFC_OK;\r
+}\r
+\r
+net_nfc_error_e __net_nfc_get_list_from_serial_for_bt(GList **list, uint8_t *data, uint32_t length)\r
+{\r
+       net_nfc_carrier_property_s *elem = NULL;\r
+       uint8_t *current = data;\r
+       uint8_t *last = NULL;\r
+\r
+       current += 2; /* remove oob data length  two bytes length*/\r
+       length -= 2;\r
+\r
+       _net_nfc_util_alloc_mem(elem, sizeof(net_nfc_carrier_property_s));\r
+       if (elem == NULL)\r
+       {\r
+               return NET_NFC_ALLOC_FAIL;\r
+       }\r
+       elem->attribute = (uint16_t)NET_NFC_BT_ATTRIBUTE_ADDRESS;\r
+       elem->length = 6; /* BT address length is always 6 */\r
+\r
+       _net_nfc_util_alloc_mem(elem->data, elem->length);\r
+       if (elem->data == NULL)\r
+       {\r
+               _net_nfc_util_free_mem(elem);\r
+               return NET_NFC_ALLOC_FAIL;\r
+       }\r
+       memcpy(elem->data, current, elem->length);\r
+       elem->is_group = false;\r
+\r
+       current += 6; /* BT address length is always 6 */\r
+       length -= 6; /* substracted by 6 (Address length)*/\r
+       *list = g_list_append(*list, elem);\r
+\r
+       last = current + length;\r
+\r
+       while (current < last)\r
+       {\r
+               _net_nfc_util_alloc_mem(elem, sizeof(net_nfc_carrier_property_s));\r
+               if (elem == NULL)\r
+               {\r
+                       return NET_NFC_ALLOC_FAIL;\r
+               }\r
+               elem->length = *((uint8_t *)current) - 1;\r
+               elem->attribute = *((uint8_t *)(++current));\r
+\r
+               _net_nfc_util_alloc_mem(elem->data, elem->length);\r
+               if (elem->data == NULL)\r
+               {\r
+                       _net_nfc_util_free_mem(elem);\r
+                       return NET_NFC_ALLOC_FAIL;\r
+               }\r
+               memcpy(elem->data, (++current), elem->length);\r
+               elem->is_group = false;\r
+\r
+               current += elem->length;\r
+               *list = g_list_append(*list, elem);\r
+       }\r
+\r
+       return NET_NFC_OK;\r
+}\r
+\r
+net_nfc_error_e net_nfc_util_create_carrier_config_from_config_record(net_nfc_carrier_config_s **config, ndef_record_s *record)\r
+{\r
+       net_nfc_error_e result = NET_NFC_OK;\r
+       net_nfc_conn_handover_carrier_type_e type;\r
+\r
+       if (record == NULL || config == NULL)\r
+       {\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+\r
+       if (strncmp((char *)record->type_s.buffer, CONN_HANDOVER_WIFI_BSS_CARRIER_MIME_NAME, record->type_s.length) == 0)\r
+       {\r
+               type = NET_NFC_CONN_HANDOVER_CARRIER_WIFI_BSS;\r
+       }\r
+       else if (strncmp((char *)record->type_s.buffer, CONN_HANDOVER_WIFI_IBSS_CARRIER_MIME_NAME, record->type_s.length) == 0)\r
+       {\r
+               type = NET_NFC_CONN_HANDOVER_CARRIER_WIFI_IBSS;\r
+       }\r
+       else if (strncmp((char *)record->type_s.buffer, CONN_HANDOVER_BT_CARRIER_MIME_NAME, record->type_s.length) == 0)\r
+       {\r
+               type = NET_NFC_CONN_HANDOVER_CARRIER_BT;\r
+       }\r
+       else\r
+       {\r
+               DEBUG_MSG("Record type is not config type");\r
+               return NET_NFC_INVALID_FORMAT;\r
+       }\r
+\r
+       result = net_nfc_util_create_carrier_config(config, type);\r
+       if (*config == NULL)\r
+       {\r
+               return NET_NFC_ALLOC_FAIL;\r
+       }\r
+\r
+       switch ((*config)->type)\r
+       {\r
+       case NET_NFC_CONN_HANDOVER_CARRIER_WIFI_BSS :\r
+               case NET_NFC_CONN_HANDOVER_CARRIER_WIFI_IBSS :\r
+               result = __net_nfc_get_list_from_serial_for_wifi((GList **)&((*config)->data), record->payload_s.buffer, record->payload_s.length);\r
+               break;\r
+       case NET_NFC_CONN_HANDOVER_CARRIER_BT :\r
+               result = __net_nfc_get_list_from_serial_for_bt((GList **)&((*config)->data), record->payload_s.buffer, record->payload_s.length);\r
+               break;\r
+       case NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN :\r
+               result = NET_NFC_NOT_SUPPORTED;\r
+               break;\r
+       }\r
+\r
+       if (result != NET_NFC_OK)\r
+       {\r
+               net_nfc_util_free_carrier_config((net_nfc_carrier_config_s *)*config);\r
+       }\r
+\r
+       return result;\r
+}\r
+\r
+net_nfc_error_e net_nfc_util_create_handover_request_message(ndef_message_s **message)\r
+{\r
+       ndef_message_s *inner_message = NULL;\r
+       net_nfc_error_e error;\r
+       ndef_record_s *record = NULL;\r
+       data_s type = { NULL, 0 };\r
+       data_s payload = { NULL, 0 };\r
+       int size = 0;\r
+\r
+       if (message == NULL)\r
+       {\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+\r
+       error = net_nfc_util_create_ndef_message(message);\r
+       if (error != NET_NFC_OK)\r
+       {\r
+               return error;\r
+       }\r
+\r
+       error = net_nfc_util_create_ndef_message(&inner_message);\r
+       if (error != NET_NFC_OK)\r
+       {\r
+               net_nfc_util_free_ndef_message(*message);\r
+               *message = NULL;\r
+\r
+               return error;\r
+       }\r
+\r
+       __net_nfc_util_create_connection_handover_collsion_resolution_record(&record);\r
+       net_nfc_util_append_record(inner_message, record);\r
+\r
+       size = net_nfc_util_get_ndef_message_length(inner_message) + 1;\r
+       _net_nfc_util_alloc_mem(payload.buffer, size);\r
+       if (payload.buffer == NULL)\r
+       {\r
+               net_nfc_util_free_ndef_message(inner_message);\r
+               net_nfc_util_free_ndef_message(*message);\r
+               *message = NULL;\r
+\r
+               return NET_NFC_ALLOC_FAIL;\r
+       }\r
+       payload.length = size;\r
+\r
+       uint8_t version = ((CONN_HANOVER_MAJOR_VER << 4) & 0xf0) | (CONN_HANOVER_MINOR_VER & 0x0f);\r
+\r
+       (payload.buffer)[0] = version;\r
+       (payload.buffer)++;\r
+       (payload.length)--;\r
+\r
+       error = net_nfc_util_convert_ndef_message_to_rawdata(inner_message, &payload);\r
+       if (error != NET_NFC_OK)\r
+       {\r
+               _net_nfc_util_free_mem(payload.buffer);\r
+               net_nfc_util_free_ndef_message(inner_message);\r
+               net_nfc_util_free_ndef_message(*message);\r
+               *message = NULL;\r
+\r
+               return error;\r
+       }\r
+\r
+       net_nfc_util_free_ndef_message(inner_message);\r
+       (payload.buffer)--;\r
+       (payload.length)++;\r
+\r
+       type.buffer = (uint8_t *)CONN_HANDOVER_REQ_RECORD_TYPE;\r
+       type.length = strlen(CONN_HANDOVER_REQ_RECORD_TYPE);\r
+\r
+       net_nfc_util_create_record(NET_NFC_RECORD_WELL_KNOWN_TYPE, &type, NULL, &payload, &record);\r
+       net_nfc_util_append_record(*message, record);\r
+\r
+       _net_nfc_util_free_mem(payload.buffer);\r
+\r
+       return NET_NFC_OK;\r
+}\r
+\r
+net_nfc_error_e net_nfc_util_create_handover_select_message(ndef_message_s **message)\r
+{\r
+       net_nfc_error_e error = NET_NFC_OK;\r
+       ndef_record_s *record = NULL;\r
+       data_s type = { NULL, 0 };\r
+       data_s payload = { NULL, 0 };\r
+\r
+       if (message == NULL)\r
+       {\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+\r
+       error = net_nfc_util_create_ndef_message(message);\r
+       if (error != NET_NFC_OK)\r
+       {\r
+               return error;\r
+       }\r
+\r
+       _net_nfc_util_alloc_mem(payload.buffer, 1);\r
+       if (payload.buffer == NULL)\r
+       {\r
+               net_nfc_util_free_ndef_message(*message);\r
+               return NET_NFC_ALLOC_FAIL;\r
+       }\r
+       payload.length = (uint32_t)1;\r
+\r
+       (payload.buffer)[0] = ((CONN_HANOVER_MAJOR_VER << 4) & 0xf0) | (CONN_HANOVER_MINOR_VER & 0x0f);\r
+\r
+       type.buffer = (uint8_t*)CONN_HANDOVER_SEL_RECORD_TYPE;\r
+       type.length = strlen(CONN_HANDOVER_SEL_RECORD_TYPE);\r
+\r
+       net_nfc_util_create_record(NET_NFC_RECORD_WELL_KNOWN_TYPE, &type, NULL, &payload, &record);\r
+       net_nfc_util_append_record(*message, record);\r
+\r
+       _net_nfc_util_free_mem(payload.buffer);\r
+\r
+       return NET_NFC_OK;\r
+}\r
+\r
+net_nfc_error_e net_nfc_util_create_handover_error_record(ndef_record_s **record, uint8_t reason, uint32_t data)\r
+{\r
+       data_s type;\r
+       data_s payload;\r
+       int size = 1;\r
+\r
+       switch (reason)\r
+       {\r
+       case 0x01 :\r
+               size += 1;\r
+               break;\r
+       case 0x02 :\r
+               size += 4;\r
+               break;\r
+       case 0x03 :\r
+               size += 1;\r
+               break;\r
+       }\r
+\r
+       _net_nfc_util_alloc_mem(payload.buffer, size);\r
+       if (payload.buffer == NULL)\r
+       {\r
+               return NET_NFC_ALLOC_FAIL;\r
+       }\r
+       payload.length = size;\r
+\r
+       type.buffer = (uint8_t *)ERROR_RECORD_TYPE;\r
+       type.length = strlen(ERROR_RECORD_TYPE);\r
+\r
+       net_nfc_util_create_record(NET_NFC_RECORD_WELL_KNOWN_TYPE, &type, NULL, &payload, (ndef_record_s **)record);\r
+\r
+       _net_nfc_util_free_mem(payload.buffer);\r
+\r
+       return NET_NFC_OK;\r
+}\r
+\r
+/*\r
+ inner_msg should be freed after using\r
+ */\r
+\r
+static net_nfc_error_e __net_nfc_get_inner_message(ndef_message_s *message, ndef_message_s *inner_msg)\r
+{\r
+       net_nfc_error_e error;\r
+       ndef_record_s *inner_record = NULL;\r
+\r
+       if (message == NULL || inner_msg == NULL)\r
+       {\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+\r
+       inner_record = message->records;\r
+       if (inner_record == NULL)\r
+       {\r
+               // This message is not connection handover message\r
+               return NET_NFC_INVALID_FORMAT;\r
+       }\r
+\r
+       if (strncmp((char*)(inner_record->type_s.buffer), CONN_HANDOVER_REQ_RECORD_TYPE, (size_t)(inner_record->type_s.length)) != 0\r
+               && strncmp((char*)(inner_record->type_s.buffer), CONN_HANDOVER_SEL_RECORD_TYPE, (size_t)(inner_record->type_s.length)) != 0)\r
+       {\r
+               // This message is not connection handover message\r
+               return NET_NFC_INVALID_FORMAT;\r
+       }\r
+\r
+       if (inner_record->payload_s.length > 1)\r
+       {\r
+               /* There is Alternative Carrier Record or Collision Res. Rec. */\r
+               (inner_record->payload_s.buffer)++; /* version */\r
+               (inner_record->payload_s.length)--;\r
+               error = net_nfc_util_convert_rawdata_to_ndef_message(&(inner_record->payload_s), inner_msg);\r
+               (inner_record->payload_s.buffer)--;\r
+               (inner_record->payload_s.length)++;\r
+       }\r
+       else\r
+       {\r
+               error = NET_NFC_NO_DATA_FOUND;\r
+       }\r
+\r
+       return error;\r
+}\r
+\r
+static net_nfc_error_e __net_nfc_replace_inner_message(ndef_message_s *message, ndef_message_s *inner_msg)\r
+{\r
+       net_nfc_error_e error;\r
+       ndef_record_s *inner_record = NULL;\r
+\r
+       if (message == NULL || inner_msg == NULL)\r
+       {\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+\r
+       inner_record = message->records;\r
+       if (inner_record == NULL)\r
+       {\r
+               // This message is not connection handover message\r
+               DEBUG_ERR_MSG("inner_record == NULL");\r
+               return NET_NFC_INVALID_FORMAT;\r
+       }\r
+\r
+       if (strncmp((char *)(inner_record->type_s.buffer), CONN_HANDOVER_REQ_RECORD_TYPE, (size_t)(inner_record->type_s.length)) != 0\r
+               && strncmp((char *)(inner_record->type_s.buffer), CONN_HANDOVER_SEL_RECORD_TYPE, (size_t)(inner_record->type_s.length)) != 0)\r
+       {\r
+               // This message is not connection handover message\r
+               DEBUG_ERR_MSG("unknown type [%s]", inner_record->type_s.buffer);\r
+               return NET_NFC_INVALID_FORMAT;\r
+       }\r
+\r
+       if (inner_record->payload_s.length >= 1)\r
+       {\r
+               /* There is Alternative Carrier Record or Collision Res. Rec. */\r
+               data_s tdata = { NULL, 0 };\r
+               int inner_length;\r
+\r
+               inner_length = net_nfc_util_get_ndef_message_length(inner_msg);\r
+\r
+               _net_nfc_util_alloc_mem(tdata.buffer, inner_length + 1);\r
+               if (tdata.buffer == NULL)\r
+               {\r
+                       return NET_NFC_ALLOC_FAIL;\r
+               }\r
+\r
+               (tdata.buffer)++;\r
+               tdata.length = inner_length;\r
+               error = net_nfc_util_convert_ndef_message_to_rawdata(inner_msg, &tdata);\r
+               if (error == NET_NFC_OK)\r
+               {\r
+                       (tdata.buffer)--;\r
+                       (tdata.length)++;\r
+                       (tdata.buffer)[0] = (inner_record->payload_s.buffer)[0];\r
+                       _net_nfc_util_free_mem(inner_record->payload_s.buffer);\r
+                       inner_record->payload_s.buffer = tdata.buffer;\r
+                       inner_record->payload_s.length = tdata.length;\r
+               }\r
+               else\r
+               {\r
+                       DEBUG_ERR_MSG("net_nfc_util_convert_ndef_message_to_rawdata failed [%d]", error);\r
+                       _net_nfc_util_free_mem(tdata.buffer);\r
+               }\r
+       }\r
+       else\r
+       {\r
+               DEBUG_ERR_MSG("inner_record->payload_s.length(%d) < 1 ", inner_record->payload_s.length);\r
+               error = NET_NFC_INVALID_FORMAT;\r
+       }\r
+\r
+       return error;\r
+}\r
+\r
+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)\r
+{\r
+       ndef_message_s *inner_msg = NULL;\r
+       ndef_record_s *carrier_rec = NULL;\r
+       data_s payload = { NULL, 0 };\r
+       data_s type = { NULL, 0 };\r
+       int config_ref_count = 0;\r
+       net_nfc_error_e error;\r
+       char buffer[256] = { 0, };\r
+\r
+       if (message == NULL || record == NULL)\r
+       {\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+\r
+       if ((error = net_nfc_util_create_ndef_message(&inner_msg)) != NET_NFC_OK)\r
+       {\r
+               DEBUG_MSG("net_nfc_util_create_ndef_message failed [%d]", error);\r
+\r
+               return error;\r
+       }\r
+\r
+       if ((error = __net_nfc_get_inner_message(message, inner_msg)) == NET_NFC_OK)\r
+       {\r
+               int idx = 1;\r
+               ndef_record_s *last_rec = inner_msg->records;\r
+\r
+               for (; idx < inner_msg->recordCount; idx++)\r
+               {\r
+                       last_rec = last_rec->next;\r
+               }\r
+\r
+               if (strncmp((char *)last_rec->type_s.buffer, COLLISION_DETECT_RECORD_TYPE, (size_t)last_rec->type_s.length) == 0)\r
+               {\r
+                       config_ref_count = 0;\r
+               }\r
+               else if (strncmp((char *)last_rec->type_s.buffer, ALTERNATIVE_RECORD_TYPE, (size_t)last_rec->type_s.length) == 0)\r
+               {\r
+                       strncpy(buffer, (char *)((last_rec->payload_s.buffer) + 2), (size_t)(last_rec->payload_s.buffer[1]));\r
+                       config_ref_count = atoi(buffer);\r
+               }\r
+       }\r
+       else\r
+       {\r
+               /* selector record type can include empty inner message. so that case, we will continue */\r
+               if (memcmp((char *)message->records->type_s.buffer, CONN_HANDOVER_SEL_RECORD_TYPE, (size_t)message->records->type_s.length) != 0)\r
+               {\r
+                       DEBUG_ERR_MSG("ERROR [%d]", error);\r
+\r
+                       net_nfc_util_free_ndef_message(inner_msg);\r
+\r
+                       return error;\r
+               }\r
+       }\r
+\r
+       type.buffer = (uint8_t *)ALTERNATIVE_RECORD_TYPE;\r
+       type.length = strlen(ALTERNATIVE_RECORD_TYPE);\r
+\r
+       config_ref_count++;\r
+       snprintf(buffer, sizeof(buffer), "  %d ", config_ref_count);    /* total size of payload is generally greater than 4. this is a trick :)*/\r
+\r
+       payload.length = strlen(buffer);\r
+       payload.buffer = (uint8_t *)buffer;\r
+       payload.buffer[0] = (uint8_t)(power_status & 0x3);      /* first byte, power status */\r
+       payload.buffer[1] = (uint8_t)payload.length - 2;        /* payload length except 2 bytes (power status and itself) */\r
+\r
+       error = net_nfc_util_create_record(NET_NFC_RECORD_WELL_KNOWN_TYPE, &type, NULL, &payload, &carrier_rec);\r
+       if (error != NET_NFC_OK)\r
+       {\r
+               DEBUG_ERR_MSG("net_nfc_util_create_record failed [%d]", error);\r
+\r
+               net_nfc_util_free_ndef_message(inner_msg);\r
+\r
+               return error;\r
+       }\r
+\r
+       error = net_nfc_util_append_record(inner_msg, carrier_rec);\r
+       if (error != NET_NFC_OK)\r
+       {\r
+               DEBUG_ERR_MSG("net_nfc_util_create_record failed [%d]", error);\r
+\r
+               net_nfc_util_free_record(carrier_rec);\r
+               net_nfc_util_free_ndef_message(inner_msg);\r
+\r
+               return error;\r
+       }\r
+\r
+       error = __net_nfc_replace_inner_message(message, inner_msg);\r
+       net_nfc_util_free_ndef_message(inner_msg);\r
+       if (error != NET_NFC_OK)\r
+       {\r
+               DEBUG_ERR_MSG("__net_nfc_replace_inner_message failed [%d]", error);\r
+\r
+               return error;\r
+       }\r
+\r
+       /* set record id to record that will be appended to ndef message */\r
+       error = net_nfc_util_set_record_id((ndef_record_s *)record, (uint8_t *)(buffer + 2), payload.length - 2);\r
+       if (error != NET_NFC_OK)\r
+       {\r
+               DEBUG_ERR_MSG("net_nfc_util_set_record_id failed [%d]", error);\r
+\r
+               return error;\r
+       }\r
+\r
+       error = net_nfc_util_append_record(message, (ndef_record_s *)record);\r
+       if (error != NET_NFC_OK)\r
+       {\r
+               DEBUG_ERR_MSG("net_nfc_util_append_record failed [%d]", error);\r
+\r
+               return error;\r
+       }\r
+\r
+       return NET_NFC_OK;\r
+}\r
+\r
+net_nfc_error_e net_nfc_util_remove_carrier_config_record(ndef_message_s *message, ndef_record_s *record)\r
+{\r
+       ndef_message_s *inner_msg = NULL;\r
+       int idx = 0;\r
+       int saved_idx = 0;\r
+       net_nfc_error_e error;\r
+       ndef_record_s *current = NULL;\r
+       ndef_record_s *record_priv = (ndef_record_s *)record;\r
+\r
+       if (message == NULL || record == NULL)\r
+       {\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+\r
+       current = message->records;\r
+\r
+       for (idx = 0; idx < message->recordCount; idx++)\r
+       {\r
+               if (current == record)\r
+               {\r
+                       break;\r
+               }\r
+               current = current->next;\r
+       }\r
+\r
+       if (current == NULL || idx == message->recordCount)\r
+       {\r
+               DEBUG_MSG("The reference is not found in config records");\r
+\r
+               return NET_NFC_NO_DATA_FOUND;\r
+       }\r
+       saved_idx = idx;\r
+\r
+       if ((error = net_nfc_util_create_ndef_message(&inner_msg)) != NET_NFC_OK)\r
+       {\r
+               DEBUG_MSG("net_nfc_util_create_ndef_message failed [%d]", error);\r
+\r
+               return error;\r
+       }\r
+\r
+       if ((error = __net_nfc_get_inner_message(message, inner_msg)) == NET_NFC_OK)\r
+       {\r
+               current = inner_msg->records;\r
+\r
+               for (idx = 0; idx < inner_msg->recordCount; idx++)\r
+               {\r
+                       if (strncmp((char *)current->type_s.buffer, ALTERNATIVE_RECORD_TYPE, (size_t)current->type_s.length) == 0)\r
+                       {\r
+                               if ((uint32_t)(current->payload_s.buffer[1]) == record_priv->id_s.length &&\r
+                                       strncmp((char *)(current->payload_s.buffer + 2), (char*)(record_priv->id_s.buffer), (size_t)current->payload_s.buffer[1]) == 0)\r
+                               {\r
+                                       // comparing the instance\r
+                                       break;\r
+                               }\r
+                       }\r
+                       current = current->next;\r
+               }\r
+\r
+               if (current == NULL || idx == message->recordCount)\r
+               {\r
+                       DEBUG_MSG("The reference is not found in inner message");\r
+\r
+                       error = NET_NFC_NO_DATA_FOUND;\r
+               }\r
+               else\r
+               {\r
+                       net_nfc_util_remove_record_by_index(inner_msg, idx);\r
+                       __net_nfc_replace_inner_message(message, inner_msg);\r
+\r
+                       // remove the record only if the inner record is found.\r
+                       net_nfc_util_remove_record_by_index(message, saved_idx);\r
+               }\r
+\r
+               net_nfc_util_free_ndef_message(inner_msg);\r
+       }\r
+\r
+       return error;\r
+}\r
+\r
+net_nfc_error_e net_nfc_util_get_carrier_config_record(ndef_message_s *message, int index, ndef_record_s** record)\r
+{\r
+       ndef_message_s *inner_msg = NULL;\r
+       data_s id;\r
+       net_nfc_error_e error;\r
+       ndef_record_s *current = NULL;\r
+       int idx = 0;\r
+       int current_idx = 0;\r
+\r
+       if (message == NULL || record == NULL)\r
+       {\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+\r
+       if ((error = net_nfc_util_create_ndef_message(&inner_msg)) != NET_NFC_OK)\r
+       {\r
+               DEBUG_MSG("net_nfc_util_create_ndef_message failed [%d]", error);\r
+\r
+               return error;\r
+       }\r
+\r
+       if ((error = __net_nfc_get_inner_message(message, inner_msg)) == NET_NFC_OK)\r
+       {\r
+               current = inner_msg->records;\r
+               for (idx = 0; idx < inner_msg->recordCount; idx++)\r
+               {\r
+                       if (strncmp((char*)current->type_s.buffer, ALTERNATIVE_RECORD_TYPE, (size_t)current->type_s.length) == 0)\r
+                       {\r
+                               if (current_idx == index)\r
+                                       break;\r
+                               current_idx++;\r
+                       }\r
+                       current = current->next;\r
+               }\r
+\r
+               if (current == NULL || idx == message->recordCount)\r
+               {\r
+                       DEBUG_MSG("The reference is not found in inner message");\r
+\r
+                       error = NET_NFC_NO_DATA_FOUND;\r
+               }\r
+               else\r
+               {\r
+                       id.buffer = (current->payload_s.buffer) + 2;\r
+                       id.length = current->payload_s.buffer[1];\r
+\r
+                       error = net_nfc_util_search_record_by_id(message, &id, record);\r
+               }\r
+\r
+               net_nfc_util_free_ndef_message(inner_msg);\r
+       }\r
+\r
+       return error;\r
+}\r
+\r
+net_nfc_error_e net_nfc_util_get_handover_random_number(ndef_message_s *message, unsigned short *random_number)\r
+{\r
+       net_nfc_error_e error;\r
+       ndef_message_s *inner_msg = NULL;\r
+       ndef_record_s *cr_record = NULL;\r
+\r
+       if (message == NULL)\r
+       {\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+\r
+       if ((error = net_nfc_util_create_ndef_message(&inner_msg)) != NET_NFC_OK)\r
+       {\r
+               DEBUG_MSG("net_nfc_util_create_ndef_message failed [%d]", error);\r
+\r
+               return error;\r
+       }\r
+\r
+       if ((error = __net_nfc_get_inner_message(message, inner_msg)) == NET_NFC_OK)\r
+       {\r
+               cr_record = inner_msg->records;\r
+               if (strncmp((char*)cr_record->type_s.buffer, COLLISION_DETECT_RECORD_TYPE, (size_t)cr_record->type_s.length) != 0\r
+                       || cr_record->payload_s.length < 2)\r
+               {\r
+                       DEBUG_MSG("There is no Collision resolution record");\r
+\r
+                       error = NET_NFC_INVALID_FORMAT;\r
+               }\r
+               else\r
+               {\r
+                       *random_number = (cr_record->payload_s.buffer[0] << 8) & (cr_record->payload_s.buffer[1]);\r
+               }\r
+\r
+               net_nfc_util_free_ndef_message(inner_msg);\r
+       }\r
+\r
+       return error;\r
+}\r
+\r
+net_nfc_error_e net_nfc_util_get_alternative_carrier_record_count(ndef_message_s *message, unsigned int *count)\r
+{\r
+       net_nfc_error_e error;\r
+       ndef_message_s *inner_msg = NULL;\r
+       ndef_record_s *current = NULL;\r
+       int idx;\r
+\r
+       if (message == NULL || count == 0)\r
+       {\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+\r
+       if ((error = net_nfc_util_create_ndef_message(&inner_msg)) != NET_NFC_OK)\r
+       {\r
+               DEBUG_MSG("net_nfc_util_create_ndef_message failed [%d]", error);\r
+\r
+               return error;\r
+       }\r
+\r
+       *count = 0;\r
+\r
+       if ((error = __net_nfc_get_inner_message(message, inner_msg)) == NET_NFC_OK)\r
+       {\r
+               current = inner_msg->records;\r
+               for (idx = 0; idx < inner_msg->recordCount; idx++)\r
+               {\r
+                       if (strncmp((char *)current->type_s.buffer, ALTERNATIVE_RECORD_TYPE, (size_t)current->type_s.length) == 0)\r
+                       {\r
+                               (*count)++;\r
+                       }\r
+                       current = current->next;\r
+               }\r
+               net_nfc_util_free_ndef_message(inner_msg);\r
+       }\r
+\r
+       return error;\r
+}\r
+\r
+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)\r
+{\r
+       net_nfc_error_e error;\r
+       ndef_message_s *inner_msg = NULL;\r
+       ndef_record_s *current = NULL;\r
+       int idx;\r
+       int idx_count = 0;\r
+\r
+       if (message == NULL)\r
+       {\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+\r
+       if (index < 0)\r
+       {\r
+               return NET_NFC_OUT_OF_BOUND;\r
+       }\r
+\r
+       if ((error = net_nfc_util_create_ndef_message(&inner_msg)) != NET_NFC_OK)\r
+       {\r
+               DEBUG_MSG("net_nfc_util_create_ndef_message failed [%d]", error);\r
+\r
+               return error;\r
+       }\r
+\r
+       if ((error = __net_nfc_get_inner_message(message, inner_msg)) == NET_NFC_OK)\r
+       {\r
+               current = inner_msg->records;\r
+               for (idx = 0; idx < inner_msg->recordCount; idx++)\r
+               {\r
+                       if (strncmp((char *)current->type_s.buffer, ALTERNATIVE_RECORD_TYPE, (size_t)current->type_s.length) == 0)\r
+                       {\r
+                               if (idx_count == index)\r
+                               {\r
+                                       *power_state = current->payload_s.buffer[0] & 0x3;\r
+                                       net_nfc_util_free_ndef_message(inner_msg);\r
+                                       return NET_NFC_OK;\r
+                               }\r
+                               idx_count++;\r
+                       }\r
+                       current = current->next;\r
+               }\r
+\r
+               net_nfc_util_free_ndef_message(inner_msg);\r
+               error = NET_NFC_OUT_OF_BOUND;\r
+       }\r
+\r
+       return error;\r
+}\r
+\r
+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)\r
+{\r
+       net_nfc_error_e error;\r
+       ndef_message_s *inner_msg = NULL;\r
+       ndef_record_s *current = NULL;\r
+       int idx;\r
+       int idx_count = 0;\r
+\r
+       if (message == NULL)\r
+       {\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+       if (index < 0)\r
+       {\r
+               return NET_NFC_OUT_OF_BOUND;\r
+       }\r
+\r
+       if ((error = net_nfc_util_create_ndef_message(&inner_msg)) != NET_NFC_OK)\r
+       {\r
+               DEBUG_MSG("net_nfc_util_create_ndef_message failed [%d]", error);\r
+\r
+               return error;\r
+       }\r
+\r
+       if ((error = __net_nfc_get_inner_message(message, inner_msg)) == NET_NFC_OK)\r
+       {\r
+               current = inner_msg->records;\r
+               for (idx = 0; idx < inner_msg->recordCount; idx++)\r
+               {\r
+                       if (strncmp((char *)current->type_s.buffer, ALTERNATIVE_RECORD_TYPE, (size_t)current->type_s.length) == 0)\r
+                       {\r
+                               if (idx_count == index)\r
+                               {\r
+                                       current->payload_s.buffer[0] = (power_status & 0x3) | (current->payload_s.buffer[0] & 0xFC);\r
+\r
+                                       __net_nfc_replace_inner_message(message, inner_msg);\r
+                                       net_nfc_util_free_ndef_message(inner_msg);\r
+\r
+                                       return NET_NFC_OK;\r
+                               }\r
+                               idx_count++;\r
+                       }\r
+                       current = current->next;\r
+               }\r
+\r
+               net_nfc_util_free_ndef_message(inner_msg);\r
+               error = NET_NFC_OUT_OF_BOUND;\r
+       }\r
+\r
+       return error;\r
+}\r
+\r
+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)\r
+{\r
+       if (strncmp((char *)record->type_s.buffer, CONN_HANDOVER_BT_CARRIER_MIME_NAME, (size_t)record->type_s.length) == 0)\r
+       {\r
+               *type = NET_NFC_CONN_HANDOVER_CARRIER_BT;\r
+       }\r
+       else if (strncmp((char *)record->type_s.buffer, CONN_HANDOVER_WIFI_BSS_CARRIER_MIME_NAME, (size_t)record->type_s.length) == 0)\r
+       {\r
+               *type = NET_NFC_CONN_HANDOVER_CARRIER_WIFI_BSS;\r
+       }\r
+       else if (strncmp((char *)record->type_s.buffer, CONN_HANDOVER_WIFI_IBSS_CARRIER_MIME_NAME, (size_t)record->type_s.length) == 0)\r
+       {\r
+               *type = NET_NFC_CONN_HANDOVER_CARRIER_WIFI_IBSS;\r
+       }\r
+       else\r
+       {\r
+               *type = NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN;\r
+       }\r
+\r
+       return NET_NFC_OK;\r
+}\r
+\r
+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)\r
+{\r
+       ndef_record_s *record = NULL;\r
+       net_nfc_error_e error;\r
+\r
+       error = net_nfc_util_get_carrier_config_record(message, index, (ndef_record_s **)&record);\r
+       if (error != NET_NFC_OK)\r
+       {\r
+               return error;\r
+       }\r
+\r
+       return net_nfc_util_get_alternative_carrier_type_from_record(record, type);\r
+}\r
+\r
+net_nfc_error_e net_nfc_util_get_selector_power_status(ndef_message_s *message, net_nfc_conn_handover_carrier_state_e *power_state)\r
+{\r
+       net_nfc_error_e error;\r
+       ndef_message_s *inner_msg = NULL;\r
+       ndef_record_s *current = NULL;\r
+       int idx;\r
+       net_nfc_conn_handover_carrier_state_e selector_state = NET_NFC_CONN_HANDOVER_CARRIER_INACTIVATE;\r
+\r
+       if (message == NULL)\r
+       {\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+\r
+       if ((error = net_nfc_util_create_ndef_message(&inner_msg)) == NET_NFC_OK)\r
+       {\r
+               if ((error = __net_nfc_get_inner_message(message, inner_msg)) == NET_NFC_OK)\r
+               {\r
+                       if (inner_msg->recordCount > 1)\r
+                       {\r
+                               current = inner_msg->records;\r
+                               for (idx = 0; idx < inner_msg->recordCount; idx++)\r
+                               {\r
+                                       if (strncmp((char *)current->type_s.buffer, ALTERNATIVE_RECORD_TYPE, (size_t)current->type_s.length) == 0)\r
+                                       {\r
+                                               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))\r
+                                               {\r
+                                                       selector_state = NET_NFC_CONN_HANDOVER_CARRIER_ACTIVATE;\r
+                                                       break;\r
+                                               }\r
+                                       }\r
+                                       current = current->next;\r
+                               }\r
+                       }\r
+                       else\r
+                       {\r
+                               /* always activate when ac is only one */\r
+                               selector_state = NET_NFC_CONN_HANDOVER_CARRIER_ACTIVATE;\r
+                       }\r
+\r
+                       *power_state = selector_state;\r
+               }\r
+               else\r
+               {\r
+                       DEBUG_ERR_MSG("_net_nfc_util_create_ndef_message failed [%d]", error);\r
+               }\r
+\r
+               net_nfc_util_free_ndef_message(inner_msg);\r
+       }\r
+       else\r
+       {\r
+               DEBUG_ERR_MSG("_net_nfc_util_create_ndef_message failed [%d]", error);\r
+               error = NET_NFC_ALLOC_FAIL;\r
+       }\r
+\r
+       return error;\r
+}\r
+\r
diff --git a/src/commonlib/net_nfc_util_ndef_message.c b/src/commonlib/net_nfc_util_ndef_message.c
new file mode 100644 (file)
index 0000000..5ba5bdf
--- /dev/null
@@ -0,0 +1,548 @@
+/*\r
+  * Copyright 2012  Samsung Electronics Co., Ltd\r
+  *\r
+  * Licensed under the Flora License, Version 1.0 (the "License");\r
+  * you may not use this file except in compliance with the License.\r
+  * You may obtain a copy of the License at\r
+\r
+  *     http://www.tizenopensource.org/license\r
+  *\r
+  * Unless required by applicable law or agreed to in writing, software\r
+  * distributed under the License is distributed on an "AS IS" BASIS,\r
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+  * See the License for the specific language governing permissions and\r
+  * limitations under the License.\r
+  */\r
+\r
+#include "net_nfc_debug_private.h"\r
+#include "net_nfc_util_defines.h"\r
+#include "net_nfc_util_private.h"\r
+#include "net_nfc_util_ndef_message.h"\r
+#include "net_nfc_util_ndef_record.h"\r
+#include "net_nfc_util_ndef_parser.h"\r
+\r
+static net_nfc_error_e __net_nfc_repair_record_flags(ndef_message_s *ndef_message);\r
+\r
+net_nfc_error_e net_nfc_util_convert_rawdata_to_ndef_message(data_s *rawdata, ndef_message_s *ndef)\r
+{\r
+       ndef_record_s *newRec = NULL;\r
+       ndef_record_s *prevRec = NULL;\r
+       int dataRead = 0;\r
+       uint8_t *current = NULL;\r
+       int totalLength = 0;\r
+       net_nfc_error_e rst = NET_NFC_OK;\r
+\r
+       if (rawdata == NULL || ndef == NULL)\r
+               return NET_NFC_NULL_PARAMETER;\r
+\r
+       current = rawdata->buffer;\r
+       ndef->recordCount = 0;\r
+\r
+       do\r
+       {\r
+               if (rawdata->length < totalLength)\r
+                       return NET_NFC_NDEF_BUF_END_WITHOUT_ME;\r
+\r
+               _net_nfc_util_alloc_mem(newRec, sizeof(ndef_record_s));\r
+               if (newRec == NULL)\r
+                       return NET_NFC_ALLOC_FAIL;\r
+\r
+               rst = __phFriNfc_NdefRecord_Parse(newRec, current, &dataRead);\r
+               if (rst != NET_NFC_OK)\r
+               {\r
+                       _net_nfc_util_free_mem(newRec);\r
+                       return rst;\r
+               }\r
+\r
+               if (ndef->recordCount == 0)\r
+                       ndef->records = newRec;\r
+               else\r
+                       prevRec->next = newRec;\r
+\r
+               prevRec = newRec;\r
+               totalLength += dataRead;\r
+               current += dataRead;\r
+               (ndef->recordCount)++;\r
+       }\r
+       while (!prevRec->ME);\r
+\r
+       return rst;\r
+}\r
+\r
+net_nfc_error_e net_nfc_util_convert_ndef_message_to_rawdata(ndef_message_s *ndef, data_s *rawdata)\r
+{\r
+       ndef_record_s *current = NULL;\r
+       ndef_record_s *completed = NULL;\r
+       uint8_t *current_buf = NULL;\r
+       int remain = 0;\r
+       uint32_t written = 0;\r
+       net_nfc_error_e rst = NET_NFC_OK;\r
+\r
+       if (rawdata == NULL || ndef == NULL)\r
+               return NET_NFC_NULL_PARAMETER;\r
+\r
+       current = ndef->records;\r
+       completed = ndef->records;\r
+       current_buf = rawdata->buffer;\r
+       remain = rawdata->length;\r
+\r
+       do\r
+       {\r
+               if (remain < 0)\r
+                       return NET_NFC_NDEF_BUF_END_WITHOUT_ME;\r
+\r
+               rst = __phFriNfc_NdefRecord_Generate(current, current_buf, remain, &written);\r
+               if (rst != NET_NFC_OK)\r
+                       return rst;\r
+\r
+               completed = current;\r
+               current = current->next;\r
+               remain -= written;\r
+               current_buf += written;\r
+       }\r
+       while (!completed->ME);\r
+\r
+       return rst;\r
+}\r
+\r
+net_nfc_error_e net_nfc_util_append_record(ndef_message_s *msg, ndef_record_s *record)\r
+{\r
+       if (msg == NULL || record == NULL)\r
+       {\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+\r
+       if (msg->recordCount == 0)\r
+       {\r
+               // set short message and append\r
+               record->MB = 1;\r
+               record->ME = 1;\r
+               record->next = NULL;\r
+\r
+               msg->records = record;\r
+\r
+               msg->recordCount++;\r
+\r
+               DEBUG_MSG("record is added to NDEF message :: count [%d]", msg->recordCount);\r
+       }\r
+       else\r
+       {\r
+               ndef_record_s *current = NULL;\r
+               ndef_record_s *prev = NULL;\r
+\r
+               // set flag :: this record is FIRST\r
+               current = msg->records;\r
+\r
+               if (current != NULL)\r
+               {\r
+                       // first node\r
+                       current->MB = 1;\r
+                       current->ME = 0;\r
+\r
+                       prev = current;\r
+\r
+                       // second node\r
+                       current = current->next;\r
+\r
+                       while (current != NULL)\r
+                       {\r
+                               current->MB = 0;\r
+                               current->ME = 0;\r
+                               prev = current;\r
+                               current = current->next;\r
+                       }\r
+\r
+                       // set flag :: this record is END\r
+                       record->MB = 0;\r
+                       record->ME = 1;\r
+\r
+                       prev->next = record;\r
+                       msg->recordCount++;\r
+               }\r
+\r
+       }\r
+\r
+       return NET_NFC_OK;\r
+}\r
+\r
+uint32_t net_nfc_util_get_ndef_message_length(ndef_message_s *message)\r
+{\r
+       ndef_record_s *current;\r
+       int total = 0;\r
+\r
+       if (message == NULL)\r
+       {\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+\r
+       current = message->records;\r
+\r
+       while (current != NULL)\r
+       {\r
+               total += net_nfc_util_get_record_length(current);\r
+               current = current->next;\r
+       }\r
+\r
+       DEBUG_MSG("total byte length = [%d]", total);\r
+\r
+       return total;\r
+}\r
+\r
+void net_nfc_util_print_ndef_message(ndef_message_s *msg)\r
+{\r
+       int idx = 0, idx2 = 0;\r
+       ndef_record_s *current = NULL;\r
+       char buffer[1024];\r
+\r
+       if (msg == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       //                123456789012345678901234567890123456789012345678901234567890\r
+       printf("========== NDEF Message ====================================\n");\r
+       printf("Total NDEF Records count: %d\n", msg->recordCount);\r
+       current = msg->records;\r
+       for (idx = 0; idx < msg->recordCount; idx++)\r
+       {\r
+               if (current == NULL)\r
+               {\r
+                       DEBUG_ERR_MSG("Message Record is NULL!! unexpected error");\r
+                       printf("============================================================\n");\r
+                       return;\r
+               }\r
+               printf("---------- Record -----------------------------------------\n");\r
+               printf("MB:%d ME:%d CF:%d SR:%d IL:%d TNF:0x%02X\n",\r
+                       current->MB, current->ME, current->CF, current->SR, current->IL, current->TNF);\r
+               printf("TypeLength:%d  PayloadLength:%d  IDLength:%d\n",\r
+                       current->type_s.length, current->payload_s.length, current->id_s.length);\r
+               if (current->type_s.buffer != NULL)\r
+               {\r
+                       memcpy(buffer, current->type_s.buffer, current->type_s.length);\r
+                       buffer[current->type_s.length] = '\0';\r
+                       printf("Type: %s\n", buffer);\r
+               }\r
+               if (current->id_s.buffer != NULL)\r
+               {\r
+                       memcpy(buffer, current->id_s.buffer, current->id_s.length);\r
+                       buffer[current->id_s.length] = '\0';\r
+                       printf("ID: %s\n", buffer);\r
+               }\r
+               if (current->payload_s.buffer != NULL)\r
+               {\r
+                       printf("Payload: ");\r
+                       for (idx2 = 0; idx2 < current->payload_s.length; idx2++)\r
+                       {\r
+                               if (idx2 % 16 == 0)\r
+                                       printf("\n\t");\r
+                               printf("%02X ", current->payload_s.buffer[idx2]);\r
+                       }\r
+                       printf("\n");\r
+               }\r
+               current = current->next;\r
+       }\r
+       //                123456789012345678901234567890123456789012345678901234567890\r
+       printf("============================================================\n");\r
+\r
+}\r
+\r
+net_nfc_error_e net_nfc_util_free_ndef_message(ndef_message_s *msg)\r
+{\r
+       int idx = 0;\r
+       ndef_record_s *prev, *current;\r
+\r
+       if (msg == NULL)\r
+               return NET_NFC_NULL_PARAMETER;\r
+\r
+       current = msg->records;\r
+\r
+       for (idx = 0; idx < msg->recordCount; idx++)\r
+       {\r
+               if (current == NULL)\r
+                       break;\r
+\r
+               prev = current;\r
+               current = current->next;\r
+\r
+               net_nfc_util_free_record(prev);\r
+       }\r
+\r
+       _net_nfc_util_free_mem(msg);\r
+\r
+       return NET_NFC_OK;\r
+}\r
+\r
+net_nfc_error_e net_nfc_util_create_ndef_message(ndef_message_s **ndef_message)\r
+{\r
+       if (ndef_message == NULL)\r
+       {\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+\r
+       _net_nfc_util_alloc_mem(*ndef_message, sizeof(ndef_message_s));\r
+\r
+       return NET_NFC_OK;\r
+}\r
+\r
+net_nfc_error_e net_nfc_util_remove_record_by_index(ndef_message_s *ndef_message, int index)\r
+{\r
+       int current_idx = 0;\r
+       ndef_record_s *prev;\r
+       ndef_record_s *next;\r
+       ndef_record_s *current;\r
+\r
+       if (ndef_message == NULL)\r
+       {\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+\r
+       if (index < 0 || index >= ndef_message->recordCount)\r
+       {\r
+               return NET_NFC_OUT_OF_BOUND;\r
+       }\r
+\r
+       if (index == 0)\r
+       {\r
+               current = ndef_message->records;\r
+               next = ndef_message->records->next;\r
+               ndef_message->records = next;\r
+       }\r
+       else\r
+       {\r
+               prev = ndef_message->records;\r
+               for (; current_idx < index - 1; current_idx++)\r
+               {\r
+                       prev = prev->next;\r
+                       if (prev == NULL)\r
+                       {\r
+                               return NET_NFC_INVALID_FORMAT;\r
+                       }\r
+               }\r
+               current = prev->next;\r
+               if (current == NULL)\r
+               {\r
+                       return NET_NFC_INVALID_FORMAT;\r
+               }\r
+               next = current->next;\r
+               prev->next = next;\r
+       }\r
+\r
+       net_nfc_util_free_record(current);\r
+       (ndef_message->recordCount)--;\r
+\r
+       return __net_nfc_repair_record_flags(ndef_message);\r
+}\r
+\r
+net_nfc_error_e net_nfc_util_get_record_by_index(ndef_message_s *ndef_message, int index, ndef_record_s **record)\r
+{\r
+       ndef_record_s *current;\r
+       int idx = 0;\r
+\r
+       if (ndef_message == NULL || record == NULL)\r
+       {\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+\r
+       if (index < 0 || index >= ndef_message->recordCount)\r
+       {\r
+               return NET_NFC_OUT_OF_BOUND;\r
+       }\r
+\r
+       current = ndef_message->records;\r
+\r
+       for (; current != NULL && idx < index; idx++)\r
+       {\r
+               current = current->next;\r
+       }\r
+\r
+       *record = current;\r
+\r
+       return NET_NFC_OK;\r
+}\r
+\r
+net_nfc_error_e net_nfc_util_append_record_by_index(ndef_message_s *ndef_message, int index, ndef_record_s *record)\r
+{\r
+       int idx = 0;\r
+       ndef_record_s *prev;\r
+       ndef_record_s *next;\r
+\r
+       if (ndef_message == NULL || record == NULL)\r
+       {\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+\r
+       if (index < 0 || index > ndef_message->recordCount)\r
+       {\r
+               return NET_NFC_OUT_OF_BOUND;\r
+       }\r
+\r
+       prev = ndef_message->records;\r
+\r
+       if (index == 0)\r
+       {\r
+               ndef_message->records = record;\r
+               record->next = prev;\r
+       }\r
+       else\r
+       {\r
+               for (; idx < index - 1; idx++)\r
+               {\r
+                       prev = prev->next;\r
+                       if (prev == NULL)\r
+                       {\r
+                               return NET_NFC_INVALID_FORMAT;\r
+                       }\r
+               }\r
+               next = prev->next;\r
+               prev->next = record;\r
+               record->next = next;\r
+       }\r
+       (ndef_message->recordCount)++;\r
+\r
+       return __net_nfc_repair_record_flags(ndef_message);\r
+}\r
+\r
+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)\r
+{\r
+       int idx = 0;\r
+       ndef_record_s *record_private;\r
+       uint32_t type_length;\r
+       uint8_t *buf;\r
+\r
+       if (ndef_message == NULL || type == NULL || record == NULL)\r
+       {\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+\r
+       type_length = type->length;\r
+       buf = type->buffer;\r
+\r
+       /* remove prefix of nfc specific urn */\r
+       if (type_length > 12)\r
+       {\r
+               if (memcmp(buf, "urn:nfc:ext:", 12) == 0 ||\r
+                       memcmp(buf, "urn:nfc:wkt:", 12) == 0)\r
+               {\r
+                       buf += 12;\r
+                       type_length -= 12;\r
+               }\r
+       }\r
+\r
+       record_private = ndef_message->records;\r
+\r
+       for (; idx < ndef_message->recordCount; idx++)\r
+       {\r
+               if (record_private == NULL)\r
+               {\r
+                       *record = NULL;\r
+\r
+                       return NET_NFC_INVALID_FORMAT;\r
+               }\r
+\r
+               if (record_private->TNF == tnf &&\r
+                       type_length == record_private->type_s.length &&\r
+                       memcmp(buf, record_private->type_s.buffer, type_length) == 0)\r
+               {\r
+                       *record = record_private;\r
+\r
+                       return NET_NFC_OK;\r
+               }\r
+\r
+               record_private = record_private->next;\r
+       }\r
+\r
+       return NET_NFC_NO_DATA_FOUND;\r
+}\r
+\r
+net_nfc_error_e net_nfc_util_search_record_by_id(ndef_message_s *ndef_message, data_s *id, ndef_record_s **record)\r
+{\r
+       int idx = 0;\r
+       ndef_record_s *record_in_msg;\r
+       uint32_t id_length;\r
+       uint8_t *buf;\r
+\r
+       if (ndef_message == NULL || id == NULL || record == NULL)\r
+       {\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+\r
+       id_length = id->length;\r
+       buf = id->buffer;\r
+\r
+       record_in_msg = ndef_message->records;\r
+\r
+       for (; idx < ndef_message->recordCount; idx++)\r
+       {\r
+               if (record_in_msg == NULL)\r
+               {\r
+                       *record = NULL;\r
+\r
+                       return NET_NFC_INVALID_FORMAT;\r
+               }\r
+               if (id_length == record_in_msg->id_s.length &&\r
+                       memcmp(buf, record_in_msg->id_s.buffer, id_length) == 0)\r
+               {\r
+                       *record = record_in_msg;\r
+\r
+                       return NET_NFC_OK;\r
+               }\r
+\r
+               record_in_msg = record_in_msg->next;\r
+       }\r
+\r
+       return NET_NFC_NO_DATA_FOUND;\r
+}\r
+\r
+static net_nfc_error_e __net_nfc_repair_record_flags(ndef_message_s *ndef_message)\r
+{\r
+       int idx = 0;\r
+       ndef_record_s *record;\r
+\r
+       if (ndef_message == NULL)\r
+       {\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+\r
+       record = ndef_message->records;\r
+\r
+       if (ndef_message->recordCount == 1)\r
+       {\r
+               if (record == NULL)\r
+               {\r
+                       return NET_NFC_INVALID_FORMAT;\r
+               }\r
+\r
+               record->MB = 1;\r
+               record->ME = 1;\r
+\r
+               return NET_NFC_OK;\r
+       }\r
+\r
+       for (idx = 0; idx < ndef_message->recordCount; idx++)\r
+       {\r
+               if (record == NULL)\r
+               {\r
+                       return NET_NFC_INVALID_FORMAT;\r
+               }\r
+\r
+               if (idx == 0)\r
+               {\r
+                       record->MB = 1;\r
+                       record->ME = 0;\r
+               }\r
+               else if (idx == ndef_message->recordCount - 1)\r
+               {\r
+                       record->MB = 0;\r
+                       record->ME = 1;\r
+               }\r
+               else\r
+               {\r
+                       record->MB = 0;\r
+                       record->ME = 0;\r
+               }\r
+               record = record->next;\r
+       }\r
+\r
+       return NET_NFC_OK;\r
+}\r
+\r
diff --git a/src/commonlib/net_nfc_util_ndef_parser.c b/src/commonlib/net_nfc_util_ndef_parser.c
new file mode 100644 (file)
index 0000000..bc3be5a
--- /dev/null
@@ -0,0 +1,482 @@
+/*
+ * Copyright (C) 2010 NXP Semiconductors
+ * Copyright (C) 2012 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.
+ */
+
+
+#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_ndef_parser.h"
+
+/* Calculate the Flags of the record */
+void __phFriNfc_NdefRecord_RecordFlag(uint8_t *rawData, ndef_record_s* record)
+{
+       if (*rawData & SLP_FRINET_NFC_NDEFRECORD_FLAGS_MB)
+       {
+               record->MB = 1;
+       }
+       if (*rawData & SLP_FRINET_NFC_NDEFRECORD_FLAGS_ME)
+       {
+               record->ME = 1;
+       }
+       if (*rawData & SLP_FRINET_NFC_NDEFRECORD_FLAGS_CF)
+       {
+               record->CF = 1;
+       }
+       if (*rawData & SLP_FRINET_NFC_NDEFRECORD_FLAGS_SR)
+       {
+               record->SR = 1;
+       }
+       if (*rawData & SLP_FRINET_NFC_NDEFRECORD_FLAGS_IL)
+       {
+               record->IL = 1;
+       }
+}
+
+/* Calculate the Type Name Format for the record */
+uint8_t __phFriNfc_NdefRecord_TypeNameFormat(uint8_t *rawData, ndef_record_s* record)
+{
+       uint8_t tnf = *rawData & SLP_FRINET_NFC_NDEFRECORD_TNFBYTE_MASK;
+
+       switch (tnf)
+       {
+       case NET_NFC_NDEF_TNF_EMPTY :
+               case NET_NFC_NDEF_TNF_NFCWELLKNOWN :
+               case NET_NFC_NDEF_TNF_MEDIATYPE :
+               case NET_NFC_NDEF_TNF_ABSURI :
+               case NET_NFC_NDEF_TNF_NFCEXT :
+               case NET_NFC_NDEF_TNF_UNKNOWN :
+               case NET_NFC_NDEF_TNF_UNCHANGED :
+               case NET_NFC_NDEF_TNF_RESERVED :
+               record->TNF = tnf;
+               break;
+       default :
+               tnf = 0xFF;
+               break;
+       }
+       return tnf;
+
+}
+
+net_nfc_error_e __phFriNfc_NdefRecord_RecordIDCheck(uint8_t *rawData,
+       uint8_t *TypeLength,
+       uint8_t *TypeLengthByte,
+       uint8_t *PayloadLengthByte,
+       uint32_t *PayloadLength,
+       uint8_t *IDLengthByte,
+       uint8_t *IDLength,
+       ndef_record_s *record)
+{
+       net_nfc_error_e Status = NET_NFC_OK;
+
+       /* Check for Type Name Format  depending on the TNF,  Type Length value is set*/
+       if (record->TNF == NET_NFC_NDEF_TNF_EMPTY)
+       {
+               *TypeLength = *(rawData + SLP_FRINET_NFC_NDEFRECORD_BUF_INC1);
+
+               if (*(rawData + SLP_FRINET_NFC_NDEFRECORD_BUF_INC1) != 0)
+               {
+                       /* Type Length  Error */
+                       Status = NET_NFC_NDEF_TYPE_LENGTH_IS_NOT_OK;
+                       return Status;
+               }
+
+               *TypeLengthByte = 1;
+
+               /* Check for Short Record */
+               if (record->SR)
+               {
+                       /* For Short Record, Payload Length Byte is 1 */
+                       *PayloadLengthByte = 1;
+                       /*  1 for Header byte */
+                       *PayloadLength = *(rawData + *TypeLengthByte + 1);
+                       if (*PayloadLength != 0)
+                       {
+                               /* PayloadLength  Error */
+                               Status = NET_NFC_NDEF_PAYLOAD_LENGTH_IS_NOT_OK;
+                               return Status;
+                       }
+               }
+               else
+               {
+                       /* For Normal Record, Payload Length Byte is 4 */
+                       *PayloadLengthByte = SLPFRINFCNDEFRECORD_NORMAL_RECORD_BYTE;
+                       *PayloadLength = ((((uint32_t)(*(rawData + SLP_FRINET_NFC_NDEFRECORD_BUF_INC2))) << SLPNFCSTSHL24) +
+                               (((uint32_t)(*(rawData + SLP_FRINET_NFC_NDEFRECORD_BUF_INC3))) << SLPNFCSTSHL16) +
+                               (((uint32_t)(*(rawData + SLP_FRINET_NFC_NDEFRECORD_BUF_INC4))) << SLPNFCSTSHL8) +
+                               *(rawData + SLP_FRINET_NFC_NDEFRECORD_BUF_INC5));
+                       if (*PayloadLength != 0)
+                       {
+                               /* PayloadLength  Error */
+                               Status = NET_NFC_NDEF_PAYLOAD_LENGTH_IS_NOT_OK;
+                               return Status;
+                       }
+               }
+
+               /* Check for ID Length existence */
+               if (record->IL)
+               {
+                       /* Length Byte exists and it is 1 byte */
+                       *IDLengthByte = 1;
+                       /*  1 for Header byte */
+                       *IDLength = (uint8_t)*(rawData + *PayloadLengthByte + *TypeLengthByte + SLP_FRINET_NFC_NDEFRECORD_BUF_INC1);
+                       if (*IDLength != 0)
+                       {
+                               /* IDLength  Error */
+                               Status = NET_NFC_NDEF_ID_LENGTH_IS_NOT_OK;
+                               return Status;
+                       }
+               }
+               else
+               {
+                       *IDLengthByte = 0;
+                       *IDLength = 0;
+               }
+       }
+       else
+       {
+               if (record->TNF == NET_NFC_NDEF_TNF_UNKNOWN
+                       || record->TNF == NET_NFC_NDEF_TNF_UNCHANGED)
+               {
+                       if (*(rawData + SLP_FRINET_NFC_NDEFRECORD_BUF_INC1) != 0)
+                       {
+                               /* Type Length  Error */
+                               Status = NET_NFC_NDEF_TYPE_LENGTH_IS_NOT_OK;
+                               return Status;
+                       }
+                       *TypeLength = 0;
+                       *TypeLengthByte = 1;
+               }
+               else if(record->TNF == NET_NFC_NDEF_TNF_ABSURI) /* temp_patch_for_absoluteURI */
+               {
+                       *TypeLength = 0;
+                       *TypeLengthByte = 0;
+               }
+               else
+               {
+                       /*  1 for Header byte */
+                       *TypeLength = *(rawData + SLP_FRINET_NFC_NDEFRECORD_BUF_INC1);
+                       *TypeLengthByte = 1;
+               }
+
+               /* Check for Short Record */
+               if (record->SR)
+               {
+                       /* For Short Record, Payload Length Byte is 1 */
+                       *PayloadLengthByte = 1;
+                       /*  1 for Header byte */
+                       *PayloadLength = *(rawData + *TypeLengthByte + SLP_FRINET_NFC_NDEFRECORD_BUF_INC1);
+               }
+               else
+               {
+                       /* For Normal Record, Payload Length Byte is 4 */
+                       *PayloadLengthByte = SLPFRINFCNDEFRECORD_NORMAL_RECORD_BYTE;
+                       *PayloadLength = ((((uint32_t)(*(rawData + SLP_FRINET_NFC_NDEFRECORD_BUF_INC2))) << SLPNFCSTSHL24) +
+                               (((uint32_t)(*(rawData + SLP_FRINET_NFC_NDEFRECORD_BUF_INC3))) << SLPNFCSTSHL16) +
+                               (((uint32_t)(*(rawData + SLP_FRINET_NFC_NDEFRECORD_BUF_INC4))) << SLPNFCSTSHL8) +
+                               *(rawData + SLP_FRINET_NFC_NDEFRECORD_BUF_INC5));
+               }
+
+               /* Check for ID Length existence */
+               if (record->IL)
+               {
+                       *IDLengthByte = 1;
+                       /*  1 for Header byte */
+                       *IDLength = (uint8_t)*(rawData + *PayloadLengthByte + *TypeLengthByte + SLP_FRINET_NFC_NDEFRECORD_BUF_INC1);
+               }
+               else
+               {
+                       *IDLengthByte = 0;
+                       *IDLength = 0;
+               }
+       }
+       return Status;
+}
+
+/*!
+ *
+ *  Extract a specific NDEF record from the data, provided by the caller. The data is a buffer holding
+ *  at least the entire NDEF record (received via the NFC link, for example).
+ *
+ * \param[out] Record               The NDEF record structure. The storage for the structure has to be provided by the
+ *                                  caller matching the requirements for \b Extraction, as described in the compound
+ *                                  documentation.
+ * \param[in]  RawRecord            The Pointer to the buffer, selected out of the array returned by
+ *                                  the \ref phFriNfc_NdefRecord_GetRecords function.
+ *
+ * \retval NFCSTATUS_SUCCESS                Operation successful.
+ * \retval NFCSTATUS_INVALID_PARAMETER      At least one parameter of the function is invalid.
+ *
+ * \note There are some caveats:
+ *       - The "RawRecord" Data buffer must exist at least as long as the function execution time plus the time
+ *         needed by the caller to evaluate the extracted information. No copying of the contained data is done.
+ *       - Using the "RawRecord" and "RawRecordMaxSize" parameters the function internally checks whether the
+ *         data to extract are within the bounds of the buffer.
+ *
+ *
+ */
+net_nfc_error_e __phFriNfc_NdefRecord_Parse(ndef_record_s*Record, uint8_t *RawRecord, int *readData)
+{
+       net_nfc_error_e Status = NET_NFC_OK;
+       uint8_t PayloadLengthByte = 0,
+               TypeLengthByte = 0,
+               TypeLength = 0,
+               IDLengthByte = 0,
+               IDLength = 0,
+               Tnf = 0;
+       uint32_t PayloadLength = 0;
+       *readData = 0;
+       uint8_t *original = RawRecord;
+
+       if (Record == NULL || RawRecord == NULL)
+       {
+               Status = NET_NFC_NULL_PARAMETER;
+       }
+       else
+       {
+               /* Calculate the Flag Value */
+               __phFriNfc_NdefRecord_RecordFlag(RawRecord, Record);
+
+               /* Calculate the Type Namr format of the record */
+               Tnf = __phFriNfc_NdefRecord_TypeNameFormat(RawRecord, Record);
+               if (Tnf != 0xFF)
+               {
+                       /* To Calculate the IDLength and PayloadLength for short or normal record */
+                       Status = __phFriNfc_NdefRecord_RecordIDCheck(RawRecord,
+                               &TypeLength,
+                               &TypeLengthByte,
+                               &PayloadLengthByte,
+                               &PayloadLength,
+                               &IDLengthByte,
+                               &IDLength
+                               , Record);
+                       Record->type_s.length = TypeLength;
+                       Record->payload_s.length = PayloadLength;
+                       Record->id_s.length = IDLength;
+                       RawRecord = (RawRecord + PayloadLengthByte + IDLengthByte + TypeLengthByte + SLP_FRINET_NFC_NDEFRECORD_BUF_INC1);
+
+                       if (Record->type_s.length != 0)
+                       {
+                               _net_nfc_util_alloc_mem((Record->type_s.buffer), Record->type_s.length);
+
+                               if (Record->type_s.buffer != NULL)
+                                       memcpy(Record->type_s.buffer, RawRecord, Record->type_s.length);
+                       }
+
+                       RawRecord = (RawRecord + Record->type_s.length);
+
+                       if (Record->id_s.length != 0)
+                       {
+                               _net_nfc_util_alloc_mem(Record->id_s.buffer, Record->id_s.length);
+                               if (Record->id_s.buffer != NULL)
+                                       memcpy(Record->id_s.buffer, RawRecord, Record->id_s.length);
+                       }
+
+                       RawRecord = RawRecord + Record->id_s.length;
+                       _net_nfc_util_alloc_mem(Record->payload_s.buffer, Record->payload_s.length);
+                       if (Record->payload_s.buffer != NULL)
+                               memcpy(Record->payload_s.buffer, RawRecord, Record->payload_s.length);
+
+                       *readData = RawRecord + Record->payload_s.length - original;
+               }
+               else
+               {
+                       Status = NET_NFC_ALLOC_FAIL;
+               }
+       }
+       return Status;
+}
+
+/* Calculate the Flags of the record */
+uint8_t __phFriNfc_NdefRecord_GenFlag(ndef_record_s* record)
+{
+       uint8_t flag = 0x00;
+       if (record->MB)
+       {
+               flag = flag | SLP_FRINET_NFC_NDEFRECORD_FLAGS_MB;
+       }
+       if (record->ME)
+       {
+               flag = flag | SLP_FRINET_NFC_NDEFRECORD_FLAGS_ME;
+       }
+       if (record->CF)
+       {
+               flag = flag | SLP_FRINET_NFC_NDEFRECORD_FLAGS_CF;
+       }
+       if (record->SR)
+       {
+               flag = flag | SLP_FRINET_NFC_NDEFRECORD_FLAGS_SR;
+       }
+       if (record->IL)
+       {
+               flag = flag | SLP_FRINET_NFC_NDEFRECORD_FLAGS_IL;
+       }
+       return flag;
+}
+
+/*!
+ *  The function writes one NDEF record to a specified memory location. Called within a loop, it is possible to
+ *  write more records into a contiguous buffer, in each cycle advancing by the number of bytes written for
+ *  each record.
+ *
+ * \param[in]     Record             The Array of NDEF record structures to append. The structures
+ *                                   have to be filled by the caller matching the requirements for
+ *                                   \b Composition, as described in the documentation of
+ *                                   the \ref phFriNfc_NdefRecord_t "NDEF Record" structure.
+ * \param[in]     Buffer             The pointer to the buffer.
+ * \param[in]     MaxBufferSize      The data buffer's maximum size, provided by the caller.
+ * \param[out]    BytesWritten       The actual number of bytes written to the buffer. This can be used by
+ *                                   the caller to serialise more than one record into the same buffer before
+ *                                   handing it over to another instance.
+ *
+ * \retval NFCSTATUS_SUCCESS                  Operation successful.
+ * \retval NFCSTATUS_INVALID_PARAMETER        At least one parameter of the function is invalid.
+ * \retval NFCSTATUS_BUFFER_TOO_SMALL         The data buffer, provided by the caller is to small to
+ *                                            hold the composed NDEF record. The existing content is not changed.
+ *
+ */
+net_nfc_error_e __phFriNfc_NdefRecord_Generate(ndef_record_s *Record,
+       uint8_t *Buffer,
+       uint32_t MaxBufferSize,
+       uint32_t *BytesWritten)
+{
+       uint8_t FlagCheck,
+               TypeCheck = 0,
+               *temp,
+               i;
+       uint32_t i_data = 0;
+
+       if (Record == NULL || Buffer == NULL || BytesWritten == NULL || MaxBufferSize == 0)
+       {
+               DEBUG_MSG("Record = [%p]||Buffer = [%p]||BytesWritten = [%p]||MaxBufferSize = [%d]", Record, Buffer, BytesWritten, MaxBufferSize);
+               return NET_NFC_NULL_PARAMETER;
+       }
+
+       /* calculate the length of the record and check with the buffersize if it exceeds return */
+       i_data = net_nfc_util_get_record_length(Record);
+       if (i_data > MaxBufferSize)
+       {
+               return NET_NFC_INVALID_FORMAT;
+       }
+       *BytesWritten = i_data;
+
+       /*fill the first byte of the message(all the flags) */
+       /*increment the buffer*/
+       *Buffer = (__phFriNfc_NdefRecord_GenFlag(Record) | Record->TNF);
+       Buffer++;
+
+       /* check the TypeNameFlag for SLP_FRINET_NFC_NDEFRECORD_TNF_EMPTY */
+       FlagCheck = Record->TNF;
+       if (FlagCheck == NET_NFC_NDEF_TNF_EMPTY)
+       {
+               /* fill the typelength idlength and payloadlength with zero(empty message)*/
+               for (i = 0; i < 3; i++)
+               {
+                       *Buffer = SLP_FRINET_NFC_NDEFRECORD_BUF_TNF_VALUE;
+                       Buffer++;
+               }
+               return NET_NFC_OK;
+       }
+
+       /* check for TNF Unknown or Unchanged */
+       FlagCheck = Record->TNF;
+       if (FlagCheck == NET_NFC_NDEF_TNF_UNKNOWN ||
+               FlagCheck == NET_NFC_NDEF_TNF_UNCHANGED)
+       {
+               *Buffer = SLP_FRINET_NFC_NDEFRECORD_BUF_TNF_VALUE;
+               Buffer++;
+       }
+       else if (FlagCheck == NET_NFC_NDEF_TNF_ABSURI )  /* temp_patch_for_absoluteURI */
+       {
+               // nothing for type
+       }
+       else
+       {
+               *Buffer = Record->type_s.length;
+               Buffer++;
+               TypeCheck = 1;
+       }
+
+       /* check for the short record bit if it is then payloadlength is only one byte */
+       FlagCheck = Record->SR;
+       if (FlagCheck != 0)
+       {
+               *Buffer = (uint8_t)(Record->payload_s.length & 0x000000ff);
+               Buffer++;
+       }
+       else
+       {
+               /* if it is normal record payloadlength is 4 byte(32 bit)*/
+               *Buffer = (uint8_t)((Record->payload_s.length & 0xff000000) >> SLPNFCSTSHL24);
+               Buffer++;
+               *Buffer = (uint8_t)((Record->payload_s.length & 0x00ff0000) >> SLPNFCSTSHL16);
+               Buffer++;
+               *Buffer = (uint8_t)((Record->payload_s.length & 0x0000ff00) >> SLPNFCSTSHL8);
+               Buffer++;
+               *Buffer = (uint8_t)((Record->payload_s.length & 0x000000ff));
+               Buffer++;
+       }
+
+       /*check for IL bit set(Flag), if so then IDlength is present*/
+       FlagCheck = Record->IL;
+
+       if (FlagCheck != 0)
+       {
+               *Buffer = Record->id_s.length;
+               Buffer++;
+       }
+
+       /*check for TNF and fill the Type*/
+       temp = Record->type_s.buffer;
+       if (TypeCheck != 0)
+       {
+               for (i = 0; i < (Record->type_s.length); i++)
+               {
+                       *Buffer = *temp;
+                       Buffer++;
+                       temp++;
+               }
+       }
+
+       /*check for IL bit set(Flag), if so then IDlength is present and fill the ID*/
+       //FlagCheck=Record->IL;
+       temp = Record->id_s.buffer;
+
+       if (FlagCheck != 0)
+       {
+               for (i = 0; i < (Record->id_s.length); i++)
+               {
+                       *Buffer = *temp;
+                       Buffer++;
+                       temp++;
+               }
+       }
+
+       temp = Record->payload_s.buffer;
+       /*check for SR bit and then correspondingly use the payload length*/
+
+       for (i_data = 0; i_data < (Record->payload_s.length); i_data++)
+       {
+               *Buffer = *temp;
+               Buffer++;
+               temp++;
+       }
+
+       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 100644 (file)
index 0000000..c97d304
--- /dev/null
@@ -0,0 +1,316 @@
+/*\r
+  * Copyright 2012  Samsung Electronics Co., Ltd\r
+  *\r
+  * Licensed under the Flora License, Version 1.0 (the "License");\r
+  * you may not use this file except in compliance with the License.\r
+  * You may obtain a copy of the License at\r
+\r
+  *     http://www.tizenopensource.org/license\r
+  *\r
+  * Unless required by applicable law or agreed to in writing, software\r
+  * distributed under the License is distributed on an "AS IS" BASIS,\r
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+  * See the License for the specific language governing permissions and\r
+  * limitations under the License.\r
+  */\r
+\r
+#include "net_nfc_debug_private.h"\r
+#include "net_nfc_util_defines.h"\r
+#include "net_nfc_util_private.h"\r
+#include "net_nfc_util_ndef_parser.h"\r
+#include "net_nfc_util_ndef_record.h"\r
+\r
+net_nfc_error_e net_nfc_util_free_record(ndef_record_s *record)\r
+{\r
+       if (record == NULL)\r
+               return NET_NFC_NULL_PARAMETER;\r
+\r
+       if (record->type_s.buffer != NULL)\r
+               _net_nfc_util_free_mem(record->type_s.buffer);\r
+       if (record->id_s.buffer != NULL)\r
+               _net_nfc_util_free_mem(record->id_s.buffer);\r
+       if (record->payload_s.buffer != NULL)\r
+               _net_nfc_util_free_mem(record->payload_s.buffer);\r
+\r
+       _net_nfc_util_free_mem(record);\r
+\r
+       return NET_NFC_OK;\r
+}\r
+\r
+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)\r
+{\r
+       ndef_record_s *record_temp = NULL;\r
+\r
+       if (typeName == NULL || payload == NULL || record == NULL)\r
+       {\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+\r
+       if (recordType < NET_NFC_RECORD_EMPTY || recordType > NET_NFC_RECORD_EXTERNAL_RTD)\r
+       {\r
+               return NET_NFC_OUT_OF_BOUND;\r
+       }\r
+\r
+       /* empty_tag */\r
+       if (recordType == NET_NFC_RECORD_EMPTY)\r
+       {\r
+               if ((typeName->buffer != NULL) || (payload->buffer != NULL) || (id->buffer != NULL) || (typeName->length != 0) || (payload->length != 0) || (id->length != 0))\r
+                       return NET_NFC_NULL_PARAMETER;\r
+       }\r
+\r
+       _net_nfc_util_alloc_mem(record_temp, sizeof(ndef_record_s));\r
+       if (record_temp == NULL)\r
+       {\r
+               return NET_NFC_ALLOC_FAIL;\r
+       }\r
+\r
+       // set type name and length and  TNF field\r
+       record_temp->TNF = recordType;\r
+       record_temp->type_s.length = typeName->length;\r
+\r
+       if(record_temp->type_s.length > 0)\r
+       {\r
+               _net_nfc_util_alloc_mem(record_temp->type_s.buffer, record_temp->type_s.length);\r
+               if (record_temp->type_s.buffer == NULL)\r
+               {\r
+                       _net_nfc_util_free_mem(record_temp);\r
+\r
+                       return NET_NFC_ALLOC_FAIL;\r
+               }\r
+\r
+               memcpy(record_temp->type_s.buffer, typeName->buffer, record_temp->type_s.length);\r
+       }\r
+       else\r
+       {\r
+               record_temp->type_s.buffer = NULL;\r
+               record_temp->type_s.length = 0;\r
+       }\r
+\r
+       // set payload\r
+       record_temp->payload_s.length = payload->length;\r
+       if(payload->length >0)\r
+       {\r
+               _net_nfc_util_alloc_mem(record_temp->payload_s.buffer, record_temp->payload_s.length);\r
+               if (record_temp->payload_s.buffer == NULL)\r
+               {\r
+                       _net_nfc_util_free_mem(record_temp->type_s.buffer);\r
+                       _net_nfc_util_free_mem(record_temp);\r
+\r
+                       return NET_NFC_ALLOC_FAIL;\r
+               }\r
+\r
+               memcpy(record_temp->payload_s.buffer, payload->buffer, record_temp->payload_s.length);\r
+       }\r
+       else\r
+       {\r
+               record_temp->payload_s.buffer = NULL;\r
+               record_temp->payload_s.length = 0;\r
+       }\r
+\r
+       if (payload->length < 256)\r
+       {\r
+               record_temp->SR = 1;\r
+       }\r
+       else\r
+       {\r
+               record_temp->SR = 0;\r
+       }\r
+\r
+       // set id and id length and IL field\r
+       if (id != NULL && id->buffer != NULL && id->length > 0)\r
+       {\r
+               record_temp->id_s.length = id->length;\r
+               _net_nfc_util_alloc_mem(record_temp->id_s.buffer, record_temp->id_s.length);\r
+               if (record_temp->id_s.buffer == NULL)\r
+               {\r
+                       _net_nfc_util_free_mem(record_temp->payload_s.buffer);\r
+                       _net_nfc_util_free_mem(record_temp->type_s.buffer);\r
+                       _net_nfc_util_free_mem(record_temp);\r
+\r
+                       return NET_NFC_ALLOC_FAIL;\r
+               }\r
+\r
+               memcpy(record_temp->id_s.buffer, id->buffer, record_temp->id_s.length);\r
+               record_temp->IL = 1;\r
+       }\r
+       else\r
+       {\r
+               record_temp->IL = 0;\r
+               record_temp->id_s.buffer = NULL;\r
+               record_temp->id_s.length = 0;\r
+       }\r
+\r
+       // this is default value\r
+       record_temp->MB = 1;\r
+       record_temp->ME = 1;\r
+\r
+       record_temp->next = NULL;\r
+\r
+       *record = record_temp;\r
+\r
+       return NET_NFC_OK;\r
+}\r
+\r
+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)\r
+{\r
+       net_nfc_error_e error;\r
+       data_s type_data;\r
+       data_s payload_data = { NULL, 0 };\r
+\r
+       if (uri == NULL)\r
+       {\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+\r
+       payload_data.length = strlen((char *)uri) + 1;\r
+       if (payload_data.length == 1)\r
+       {\r
+               return NET_NFC_INVALID_PARAM;\r
+       }\r
+\r
+       _net_nfc_util_alloc_mem(payload_data.buffer, payload_data.length);\r
+       if (payload_data.buffer == NULL)\r
+       {\r
+               return NET_NFC_ALLOC_FAIL;\r
+       }\r
+\r
+       payload_data.buffer[0] = protocol_schema;       /* first byte of payload is protocol scheme */\r
+       memcpy(payload_data.buffer + 1, uri, payload_data.length - 1);\r
+\r
+       type_data.length = 1;\r
+       type_data.buffer = (uint8_t *)URI_RECORD_TYPE;\r
+\r
+       error = net_nfc_util_create_record(NET_NFC_RECORD_WELL_KNOWN_TYPE, &type_data, NULL, &payload_data, record);\r
+\r
+       _net_nfc_util_free_mem(payload_data.buffer);\r
+\r
+       return error;\r
+}\r
+\r
+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)\r
+{\r
+       data_s type_data;\r
+       data_s payload_data;\r
+       int controll_byte;\r
+       int offset = 0;\r
+\r
+       if (text == NULL || lang_code_str == NULL)\r
+       {\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+\r
+       if ((encode < NET_NFC_ENCODE_UTF_8 || encode > NET_NFC_ENCODE_UTF_16))\r
+       {\r
+               return NET_NFC_OUT_OF_BOUND;\r
+       }\r
+\r
+       payload_data.length = strlen((char *)text) + strlen(lang_code_str) + 1;\r
+\r
+       _net_nfc_util_alloc_mem(payload_data.buffer, payload_data.length);\r
+       if (payload_data.buffer == NULL)\r
+       {\r
+               return NET_NFC_ALLOC_FAIL;\r
+       }\r
+\r
+       controll_byte = strlen(lang_code_str) & 0x3F;\r
+       if (encode == NET_NFC_ENCODE_UTF_16)\r
+       {\r
+               controll_byte = controll_byte | 0x80;\r
+       }\r
+\r
+       payload_data.buffer[0] = controll_byte;\r
+\r
+       offset = 1;\r
+       memcpy(payload_data.buffer + offset, lang_code_str, strlen(lang_code_str));\r
+\r
+       offset = offset + strlen(lang_code_str);\r
+       memcpy(payload_data.buffer + offset, (char *)text, strlen((char *)text));\r
+\r
+       type_data.length = 1;\r
+       type_data.buffer = (uint8_t *)TEXT_RECORD_TYPE;\r
+\r
+       net_nfc_util_create_record(NET_NFC_RECORD_WELL_KNOWN_TYPE, &type_data, NULL, &payload_data, record);\r
+\r
+       _net_nfc_util_free_mem(payload_data.buffer);\r
+\r
+       return NET_NFC_OK;\r
+}\r
+\r
+net_nfc_error_e net_nfc_util_set_record_id(ndef_record_s *record, uint8_t *data, int length)\r
+{\r
+       if (record == NULL || data == NULL)\r
+       {\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+\r
+       if (length < 1)\r
+       {\r
+               return NET_NFC_OUT_OF_BOUND;\r
+       }\r
+\r
+       if (record->id_s.buffer != NULL && record->id_s.length > 0)\r
+       {\r
+               _net_nfc_util_free_mem(record->id_s.buffer);\r
+       }\r
+\r
+       _net_nfc_util_alloc_mem(record->id_s.buffer, length);\r
+       if (record->id_s.buffer == NULL)\r
+       {\r
+               return NET_NFC_ALLOC_FAIL;\r
+       }\r
+       memcpy(record->id_s.buffer, data, length);\r
+       record->id_s.length = length;\r
+       record->IL = 1;\r
+\r
+       return NET_NFC_OK;\r
+}\r
+\r
+uint32_t net_nfc_util_get_record_length(ndef_record_s *Record)\r
+{\r
+       uint32_t RecordLength = 1;\r
+\r
+       /* Type length is present only for following TNF\r
+        NET_NFC_TNF_NFCWELLKNOWN\r
+        NET_NFC_TNF_MEDIATYPE\r
+        SLP_FRINET_NFC_NDEFRECORD_TNF_ABSURI\r
+        SLP_FRINET_NFC_NDEFRECORD_TNF_NFCEXT\r
+        */\r
+\r
+       /* ++ is for the Type Length Byte */\r
+       RecordLength++;\r
+       if (Record->TNF != NET_NFC_NDEF_TNF_EMPTY &&\r
+               Record->TNF != NET_NFC_NDEF_TNF_UNKNOWN &&\r
+               Record->TNF != NET_NFC_NDEF_TNF_ABSURI &&  /* temp_patch_for_absoluteURI */\r
+               Record->TNF != NET_NFC_NDEF_TNF_UNCHANGED)\r
+       {\r
+               RecordLength += Record->type_s.length;\r
+       }\r
+\r
+       /* to check if payloadlength is 8bit or 32bit*/\r
+       if (Record->SR != 0)\r
+       {\r
+               /* ++ is for the Payload Length Byte */\r
+               RecordLength++;/* for short record*/\r
+       }\r
+       else\r
+       {\r
+               /* + NET_NFC_NDEF_NORMAL_RECORD_BYTE is for the Payload Length Byte */\r
+               RecordLength += SLPFRINFCNDEFRECORD_NORMAL_RECORD_BYTE;/* for normal record*/\r
+       }\r
+\r
+       /* for non empty record */\r
+       if (Record->TNF != NET_NFC_NDEF_TNF_EMPTY)\r
+       {\r
+               RecordLength += Record->payload_s.length;\r
+       }\r
+\r
+       /* ID and IDlength are present only if IL flag is set*/\r
+       if (Record->IL != 0)\r
+       {\r
+               RecordLength += Record->id_s.length;\r
+               /* ++ is for the ID Length Byte */\r
+               RecordLength++;\r
+       }\r
+\r
+       return RecordLength;\r
+}\r
diff --git a/src/commonlib/nfc-common-lib.pc.in b/src/commonlib/nfc-common-lib.pc.in
new file mode 100755 (executable)
index 0000000..1df1eee
--- /dev/null
@@ -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 (file)
index 0000000..5ba198c
--- /dev/null
@@ -0,0 +1,88 @@
+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)
+
+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 -mno-thumb-interwork -msoft-float -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("-DBROADCAST_MESSAGE")
+ADD_DEFINITIONS("-DSAVE_TARGET_INFO_IN_CC")
+ADD_DEFINITIONS("-fpie")
+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")
+#FIND_PROGRAM(DBUS_BINDING_TOOL NAMES dbus-binding-tool)
+#EXEC_PROGRAM("${DBUS_BINDING_TOOL}" ARGS "--prefix=dbus_service ${CMAKE_CURRENT_SOURCE_DIR}/server/dbus-service.xml --mode=glib-server --output=${CMAKE_CURRENT_SOURCE_DIR}/server/include/dbus-service-glue.h")
+#EXEC_PROGRAM("${DBUS_BINDING_TOOL}" ARGS "--prefix=dbus_service ${CMAKE_CURRENT_SOURCE_DIR}/server/dbus-service.xml --mode=glib-client --output=${CMAKE_CURRENT_SOURCE_DIR}/server/include/dbus-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")
+#TARGET_LINK_LIBRARIES(${NFC_MANAGER_DAEMON} ${manager_pkges_LDFLAGS} "-L${CMAKE_CURRENT_SOURCE_DIR}/../../cmake_tmp/src/stack/" "-lnfc-stack")
+
+ADD_CUSTOM_TARGET(dbus_service_glue_private.h
+                COMMAND dbus-binding-tool --prefix=dbus_service ${CMAKE_CURRENT_SOURCE_DIR}/resource/dbus_service.xml
+               --mode=glib-server --output=${CMAKE_CURRENT_SOURCE_DIR}/include/dbus_service_glue_private.h
+                DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/resource/dbus_service.xml
+)
+ADD_DEPENDENCIES(${NFC_MANAGER_DAEMON} dbus_service_glue_private.h)
+
+ADD_CUSTOM_TARGET(dbus_service_binding_private.h
+               COMMAND dbus-binding-tool --prefix=dbus_service ${CMAKE_CURRENT_SOURCE_DIR}/resource/dbus_service.xml
+               --mode=glib-client --output=${CMAKE_CURRENT_SOURCE_DIR}/include/dbus_service_binding_private.h
+                DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/resource/dbus_service.xml
+)
+ADD_DEPENDENCIES(${NFC_MANAGER_DAEMON} dbus_service_binding_private.h)
+
+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 (file)
index 0000000..98e247d
--- /dev/null
@@ -0,0 +1,35 @@
+/*\r
+  * Copyright 2012  Samsung Electronics Co., Ltd\r
+  *\r
+  * Licensed under the Flora License, Version 1.0 (the "License");\r
+  * you may not use this file except in compliance with the License.\r
+  * You may obtain a copy of the License at\r
+\r
+  *     http://www.tizenopensource.org/license\r
+  *\r
+  * Unless required by applicable law or agreed to in writing, software\r
+  * distributed under the License is distributed on an "AS IS" BASIS,\r
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+  * See the License for the specific language governing permissions and\r
+  * limitations under the License.\r
+  */\r
+\r
+#ifndef NET_NFC_APP_UTIL_H\r
+#define NET_NFC_APP_UTIL_H\r
+\r
+#include "net_nfc_typedef.h"\r
+#include "net_nfc_typedef_private.h"\r
+#include <aul.h>\r
+\r
+#ifndef MESSAGE_STORAGE\r
+#define MESSAGE_STORAGE "/opt/share/service/nfc-manager"\r
+#endif\r
+\r
+net_nfc_error_e net_nfc_app_util_store_ndef_message(data_s *data);\r
+net_nfc_error_e net_nfc_app_util_process_ndef(data_s *data);\r
+void net_nfc_app_util_aul_launch_app(char* package_name, bundle* kb);\r
+void net_nfc_app_util_clean_storage(char* src_path);\r
+bool net_nfc_app_util_is_dir(const char* path_name);\r
+int net_nfc_app_util_appsvc_launch(const char *operation, const char *uri, const char *mime, const char *data);\r
+\r
+#endif\r
diff --git a/src/manager/include/net_nfc_controller_private.h b/src/manager/include/net_nfc_controller_private.h
new file mode 100644 (file)
index 0000000..9f5af99
--- /dev/null
@@ -0,0 +1,77 @@
+/*\r
+  * Copyright 2012  Samsung Electronics Co., Ltd\r
+  *\r
+  * Licensed under the Flora License, Version 1.0 (the "License");\r
+  * you may not use this file except in compliance with the License.\r
+  * You may obtain a copy of the License at\r
+\r
+  *     http://www.tizenopensource.org/license\r
+  *\r
+  * Unless required by applicable law or agreed to in writing, software\r
+  * distributed under the License is distributed on an "AS IS" BASIS,\r
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+  * See the License for the specific language governing permissions and\r
+  * limitations under the License.\r
+  */\r
+\r
+#ifndef NET_NFC_CONTROLLER_H\r
+#define NET_NFC_CONTROLLER_H\r
+\r
+#include "net_nfc_typedef.h"\r
+#include "net_nfc_typedef_private.h"\r
+\r
+void* net_nfc_controller_onload(void);\r
+bool net_nfc_controller_unload(void* handle);\r
+bool net_nfc_controller_init (net_nfc_error_e* result);\r
+bool net_nfc_controller_deinit (void);\r
+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);\r
+bool net_nfc_controller_unregister_listener(void);\r
+bool net_nfc_controller_check_firmware_version(net_nfc_error_e* result);\r
+bool net_nfc_controller_update_firmware(net_nfc_error_e* result);\r
+bool net_nfc_controller_get_stack_information(net_nfc_stack_information_s* stack_info, net_nfc_error_e* result);\r
+bool net_nfc_controller_confiure_discovery (net_nfc_discovery_mode_e mode, net_nfc_event_filter_e config, net_nfc_error_e* result);\r
+bool net_nfc_controller_get_secure_element_list(net_nfc_secure_element_info_s* list, int* count, net_nfc_error_e* result);\r
+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);\r
+bool net_nfc_controller_check_target_presence(net_nfc_target_handle_s* handle, net_nfc_error_e* result);\r
+bool net_nfc_controller_connect(net_nfc_target_handle_s* handle, net_nfc_error_e* result);\r
+bool net_nfc_controller_disconnect(net_nfc_target_handle_s* handle, net_nfc_error_e* result);\r
+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);\r
+bool net_nfc_controller_read_ndef(net_nfc_target_handle_s* handle, data_s** data, net_nfc_error_e* result);\r
+bool net_nfc_controller_write_ndef(net_nfc_target_handle_s* handle, data_s* data, net_nfc_error_e* result);\r
+bool net_nfc_controller_make_read_only_ndef(net_nfc_target_handle_s* handle,  net_nfc_error_e* result);\r
+bool net_nfc_controller_format_ndef(net_nfc_target_handle_s* handle, data_s* secure_key, net_nfc_error_e* result);\r
+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);\r
+bool net_nfc_controller_exception_handler(void);\r
+bool net_nfc_controller_is_ready(net_nfc_error_e* result);\r
+\r
+// LLCP API DEFINE\r
+\r
+bool net_nfc_controller_llcp_config(net_nfc_llcp_config_info_s * config, net_nfc_error_e * result);\r
+bool net_nfc_controller_llcp_check_llcp(net_nfc_target_handle_s* handle, net_nfc_error_e* result);\r
+bool net_nfc_controller_llcp_activate_llcp(net_nfc_target_handle_s * handle, net_nfc_error_e* result);\r
+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);\r
+bool net_nfc_controller_llcp_bind(net_nfc_llcp_socket_t socket, uint8_t service_access_point, net_nfc_error_e* result);\r
+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);\r
+bool net_nfc_controller_llcp_accept(net_nfc_llcp_socket_t socket, net_nfc_error_e* result);\r
+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);\r
+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);\r
+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);\r
+bool net_nfc_controller_llcp_socket_close(net_nfc_llcp_socket_t socket, net_nfc_error_e* result);\r
+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);\r
+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);\r
+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);\r
+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);\r
+bool net_nfc_controller_llcp_reject(net_nfc_target_handle_s* handle, net_nfc_llcp_socket_t     socket, net_nfc_error_e* result);\r
+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);\r
+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);\r
+\r
+\r
+\r
+// LLCP API DEFINE\r
+\r
+bool net_nfc_controller_sim_test(net_nfc_error_e* result);\r
+bool net_nfc_controller_test_mode_on(net_nfc_error_e* result);\r
+bool net_nfc_controller_test_mode_off(net_nfc_error_e* result);\r
+bool net_nfc_test_sim(void);\r
+#endif\r
+\r
diff --git a/src/manager/include/net_nfc_dbus_service_obj_private.h b/src/manager/include/net_nfc_dbus_service_obj_private.h
new file mode 100644 (file)
index 0000000..6a18fa3
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+  * Copyright 2012  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://www.tizenopensource.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 <glib-object.h>
+
+typedef struct _Dbus_Service Dbus_Service;
+typedef struct _Dbus_ServiceClass Dbus_ServiceClass;
+
+#define DBUS_SERVICE_NAME "com.samsung.slp.nfc.manager"
+#define DBUS_SERVICE_PATH "/com/samsung/slp/nfc/manager"
+
+
+GType dbus_service_get_type (void);
+
+struct _Dbus_Service
+{
+  GObject parent;
+  int status;
+};
+
+struct _Dbus_ServiceClass
+{
+  GObjectClass parent;
+};
+
+#define DBUS_SERVICE_TYPE                              (dbus_service_get_type ())
+#define DBUS_SERVICE(object)                   (G_TYPE_CHECK_INSTANCE_CAST ((object), DBUS_SERVICE_TYPE, Dbus_Service))
+#define DBUS_SERVICE_CLASS(klass)              (G_TYPE_CHECK_CLASS_CAST ((klass), DBUS_SERVICE_TYPE, Dbus_Service_Class))
+#define IS_DBUS_SERVICE(object)                        (G_TYPE_CHECK_INSTANCE_TYPE ((object), DBUS_SERVICE_TYPE))
+#define IS_DBUS_SERVICE_CLASS(klass)   (G_TYPE_CHECK_CLASS_TYPE ((klass), DBUS_SERVICE_TYPE))
+#define DBUS_SERVICE_GET_CLASS(obj)            (G_TYPE_INSTANCE_GET_CLASS ((obj), DBUS_SERVICE_TYPE, Dbus_Service_Class))
+
+typedef enum
+{
+  DBUS_SERVICE_ERROR_INVALID_PRAM
+} Dbus_Service_Error;
+
+GQuark dbus_service_error_quark (void);
+#define DBUS_SERVICE_ERROR dbus_service_error_quark ()
+
+/**
+ *     launch the nfc-manager
+ */
+gboolean dbus_service_launch (Dbus_Service *dbus_service, guint *result_val, GError **error);
+
+gboolean dbus_service_se_only (Dbus_Service *dbus_service, guint *result_val, GError **error);
+
+gboolean dbus_service_terminate (Dbus_Service *dbus_service, guint *result_val, GError **error);
+
+
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 (file)
index 0000000..819d217
--- /dev/null
@@ -0,0 +1,49 @@
+/*\r
+  * Copyright 2012  Samsung Electronics Co., Ltd\r
+  *\r
+  * Licensed under the Flora License, Version 1.0 (the "License");\r
+  * you may not use this file except in compliance with the License.\r
+  * You may obtain a copy of the License at\r
+\r
+  *     http://www.tizenopensource.org/license\r
+  *\r
+  * Unless required by applicable law or agreed to in writing, software\r
+  * distributed under the License is distributed on an "AS IS" BASIS,\r
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+  * See the License for the specific language governing permissions and\r
+  * limitations under the License.\r
+  */\r
+\r
+#ifndef __NET_NFC_MANAGER_UTIL_PRIVATE__\r
+#define __NET_NFC_MANAGER_UTIL_PRIVATE__\r
+\r
+\r
+#define NET_NFC_SERVER_ADDRESS "127.0.0.1"\r
+#define NET_NFC_SERVER_PORT 3000\r
+\r
+#define NET_NFC_SERVER_DOMAIN "/tmp/nfc-manager-server-domain"\r
+\r
+#define NET_NFC_MANAGER_DATA_PATH                              "/opt/data/nfc-manager-daemon"\r
+#define NET_NFC_MANAGER_DATA_PATH_MESSAGE              "message"\r
+#define NET_NFC_MANAGER_DATA_PATH_CONFIG               "config"\r
+#define NET_NFC_MANAGER_NDEF_FILE_NAME                 "ndef-message.txt"\r
+#define NET_NFC_MANAGER_LLCP_CONFIG_FILE_NAME  "nfc-manager-config.txt"\r
+\r
+#define BUFFER_LENGTH_MAX 1024\r
+\r
+#define READ_BUFFER_LENGTH_MAX BUFFER_LENGTH_MAX\r
+#define WRITE_BUFFER_LENGTH_MAX BUFFER_LENGTH_MAX\r
+#define NET_NFC_MAX_LLCP_SOCKET_BUFFER BUFFER_LENGTH_MAX\r
+\r
+/* Memory utils */\r
+/* free memory, after free given memory it set NULL. Before proceed free, this function also check NULL */\r
+void __net_nfc_manager_util_free_mem(void** mem, char * filename, unsigned int line);\r
+/* allocation memory */\r
+void __net_nfc_manager_util_alloc_mem(void** mem, int size, char * filename, unsigned int line);\r
+#define         _net_nfc_manager_util_alloc_mem(mem,size) __net_nfc_manager_util_alloc_mem((void **)&mem,size,__FILE__, __LINE__)\r
+#define         _net_nfc_manager_util_free_mem(mem) __net_nfc_manager_util_free_mem((void **)&mem,__FILE__, __LINE__)\r
+\r
+\r
+\r
+#endif\r
+\r
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 100644 (file)
index 0000000..76df0e0
--- /dev/null
@@ -0,0 +1,30 @@
+/*\r
+  * Copyright 2012  Samsung Electronics Co., Ltd\r
+  *\r
+  * Licensed under the Flora License, Version 1.0 (the "License");\r
+  * you may not use this file except in compliance with the License.\r
+  * You may obtain a copy of the License at\r
+\r
+  *     http://www.tizenopensource.org/license\r
+  *\r
+  * Unless required by applicable law or agreed to in writing, software\r
+  * distributed under the License is distributed on an "AS IS" BASIS,\r
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+  * See the License for the specific language governing permissions and\r
+  * limitations under the License.\r
+  */\r
+\r
+#ifndef __NET_NFC_SERVER_DISPATCHER__\r
+#define __NET_NFC_SERVER_DISPATCHER__\r
+\r
+#include "net_nfc_typedef_private.h"\r
+\r
+void net_nfc_dispatcher_queue_push(net_nfc_request_msg_t* req_msg);\r
+bool net_nfc_dispatcher_start_thread();\r
+void net_nfc_dispatcher_cleanup_queue(void);\r
+void net_nfc_dispatcher_put_cleaner(void);\r
+\r
+\r
+#endif\r
+\r
+\r
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 100644 (file)
index 0000000..99539b1
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+  * Copyright 2012  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://www.tizenopensource.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 <glib-object.h>
+
+#include "net_nfc_typedef_private.h"
+
+#define MAX_CLIENTS 10
+
+typedef struct net_nfc_server_info_t
+{
+       uint32_t server_src_id ;
+       uint32_t client_src_id ; /* current client src id */
+
+       GIOChannel* server_channel ;
+       GIOChannel* client_channel ; /* current client channel */
+
+       int server_sock_fd ;
+       int client_sock_fd ; /* current client sock fd*/
+
+       server_state_e state;
+#ifdef BROADCAST_MESSAGE
+       net_nfc_server_received_message_s* received_message;
+#endif
+
+       int connected_client_count;
+
+       net_nfc_current_target_info_s*  target_info;
+}net_nfc_server_info_t;
+
+bool net_nfc_server_ipc_initialize();
+bool net_nfc_server_ipc_finalize();
+bool net_nfc_server_recv_message_from_client(int client_sock_fd, void* message, int length);
+bool net_nfc_server_get_current_client_context(void* client_context);
+bool net_nfc_server_check_client_is_running(void* client_context);
+
+net_nfc_target_handle_s* net_nfc_server_get_current_client_target_handle(int socket_fd);
+bool net_nfc_server_set_current_client_target_handle(int socket_fd, net_nfc_target_handle_s* handle);
+
+bool net_nfc_server_get_client_type(int socket, int* client_type);
+bool net_nfc_server_set_client_type(int socket, int type);
+bool net_nfc_server_set_server_state(server_state_e state);
+server_state_e net_nfc_server_get_server_state();
+
+bool _net_nfc_send_response_msg (int msg_type, ...);
+bool _net_nfc_check_client_handle ();
+server_state_e net_nfc_get_server_state();
+void net_nfc_server_set_tag_info(void * info);
+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 100644 (file)
index 0000000..19b2f1c
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+  * Copyright 2012  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://www.tizenopensource.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 100644 (file)
index 0000000..d179326
--- /dev/null
@@ -0,0 +1,200 @@
+/*\r
+  * Copyright 2012  Samsung Electronics Co., Ltd\r
+  *\r
+  * Licensed under the Flora License, Version 1.0 (the "License");\r
+  * you may not use this file except in compliance with the License.\r
+  * You may obtain a copy of the License at\r
+\r
+  *     http://www.tizenopensource.org/license\r
+  *\r
+  * Unless required by applicable law or agreed to in writing, software\r
+  * distributed under the License is distributed on an "AS IS" BASIS,\r
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+  * See the License for the specific language governing permissions and\r
+  * limitations under the License.\r
+  */\r
+\r
+#ifndef NET_NFC_SERVICE_LLCP_PRIVATE_H\r
+#define NET_NFC_SERVICE_LLCP_PRIVATE_H\r
+\r
+#include "net_nfc_typedef_private.h"\r
+\r
+/* define */\r
+/* Service Name should be followed naming rule. */\r
+// service access name\r
+\r
+#define SDP_SAN                                        "urn:nfc:sn:sdp"\r
+#define IP_SAN                                 "urn:nfc:sn:ip"\r
+#define SNEP_SAN                               "urn:nfc:sn:snep"\r
+#define OBEX_SAN                               "urn:nfc:sn:obex"\r
+\r
+#define CONN_HANDOVER_SAN      "urn:nfc:sn:handover"\r
+\r
+#define NPP_SAN                              "com.android.npp"\r
+#define NPP_SAP 0x10\r
+\r
+#define SDP_SAP        1    /* service discovery protocol service access point */\r
+#define IP_SAP 2       /* Internet protocol service access point */\r
+#define OBEX_SAP 3  /* ojbect exchange service access point */\r
+#define SNEP_SAP 4  /* simple ndef exchange protocol service access point */\r
+\r
+#define CONN_HANDOVER_SAP 5 /* connection handover service access point */\r
+\r
+#define SNEP_MAJOR_VER 1\r
+#define SNEP_MINOR_VER 0\r
+\r
+\r
+#define NPP_MAJOR_VER 0\r
+#define NPP_MINOR_VER 1\r
+\r
+#define NPP_NDEF_ENTRY 0x00000001\r
+\r
+#define NPP_ACTION_CODE 0x01\r
+\r
+#define SNEP_MAX_BUFFER 128 /* simple NDEF exchange protocol */\r
+#define CH_MAX_BUFFER 128     /* connection handover */\r
+\r
+typedef enum{\r
+       NPP_REQ_CONTINUE = 0x00,\r
+       NPP_REQ_REJECT,\r
+       NPP_RESP_CONT,\r
+       NPP_RESP_SUCCESS,\r
+       NPP_RESP_NOT_FOUND,\r
+       NPP_RESP_EXCESS_DATA,\r
+       NPP_RESP_BAD_REQ,\r
+       NPP_RESP_NOT_IMPLEMEN,\r
+       NPP_RESP_UNSUPPORTED_VER,\r
+       NPP_RESP_REJECT,\r
+}npp_command_field_e;\r
+\r
+typedef enum{\r
+       SNEP_REQ_CONTINUE = 0x00,\r
+       SNEP_REQ_GET = 0x01,\r
+       SNEP_REQ_PUT = 0x02,\r
+       SNEP_REQ_REJECT = 0x7F,\r
+       SNEP_RESP_CONT = 0x80,\r
+       SNEP_RESP_SUCCESS = 0x81,\r
+       SNEP_RESP_NOT_FOUND = 0xC0,\r
+       SNEP_RESP_EXCESS_DATA = 0xC1,\r
+       SNEP_RESP_BAD_REQ = 0xC2,\r
+       SNEP_RESP_NOT_IMPLEMENT = 0xE0,\r
+       SNEP_RESP_UNSUPPORTED_VER = 0xE1,\r
+       SNEP_RESP_REJECT = 0xFF,\r
+}snep_command_field_e;\r
+\r
+/* static variable */\r
+\r
+typedef enum {\r
+       NET_NFC_STATE_EXCHANGER_SERVER = 0x00,\r
+       NET_NFC_STATE_EXCHANGER_SERVER_NPP,\r
+\r
+       NET_NFC_STATE_EXCHANGER_CLIENT,\r
+       NET_NFC_STATE_CONN_HANDOVER_REQUEST,\r
+       NET_NFC_STATE_CONN_HANDOVER_SELECT,\r
+} llcp_state_e;\r
+\r
+typedef enum {\r
+       NET_NFC_LLCP_STEP_01 = 0xFFFF,\r
+       NET_NFC_LLCP_STEP_02,\r
+       NET_NFC_LLCP_STEP_03,\r
+       NET_NFC_LLCP_STEP_04,\r
+       NET_NFC_LLCP_STEP_05,\r
+       NET_NFC_LLCP_STEP_06,\r
+       NET_NFC_LLCP_STEP_07,\r
+       NET_NFC_LLCP_STEP_08,\r
+       NET_NFC_LLCP_STEP_09,\r
+       NET_NFC_LLCP_STEP_10,\r
+       NET_NFC_LLCP_STEP_11,\r
+       NET_NFC_LLCP_STEP_12,\r
+       NET_NFC_LLCP_STEP_13,\r
+       NET_NFC_LLCP_STEP_14,\r
+       NET_NFC_LLCP_STEP_15,\r
+       NET_NFC_LLCP_STEP_16,\r
+       NET_NFC_LLCP_STEP_17,\r
+       NET_NFC_LLCP_STEP_18,\r
+       NET_NFC_LLCP_STEP_19,\r
+       NET_NFC_LLCP_STEP_20,\r
+       NET_NFC_LLCP_STEP_RETURN,\r
+       NET_NFC_STATE_SOCKET_ERROR,\r
+       NET_NFC_STATE_ERROR,\r
+} net_nfc_state_e;\r
+\r
+typedef struct _net_nfc_llcp_state_t{\r
+       unsigned int step;\r
+       unsigned int fragment_offset;\r
+       llcp_state_e state;\r
+       net_nfc_llcp_socket_t socket;\r
+       uint16_t max_capability;\r
+       net_nfc_target_handle_s * handle;\r
+       net_nfc_error_e prev_result;\r
+       net_nfc_llcp_socket_t incomming_socket;\r
+       ndef_message_s *requester;\r
+       ndef_message_s *selector;\r
+       bool low_power;\r
+       void * user_data;\r
+\r
+       llcp_app_protocol_e type_app_protocol;\r
+       net_nfc_conn_handover_carrier_type_e type;\r
+\r
+} net_nfc_llcp_state_t;\r
+\r
+\r
+typedef struct _net_nfc_llcp_npp_t{\r
+       uint8_t npp_version;\r
+       uint32_t npp_ndef_entry;\r
+       uint8_t npp_action_code;\r
+       uint32_t npp_ndef_length;\r
+} __attribute__((packed))net_nfc_llcp_npp_t;\r
+\r
+#define NET_NFC_COMMON_HANDOVER_CONTEXT unsigned int step;\\r
+                                                                               net_nfc_llcp_state_t *llcp_state;\\r
+                                                                               void *user_data;\\r
+                                                                               net_nfc_error_e result;\\r
+                                                                               net_nfc_conn_handover_carrier_type_e request_type;\\r
+                                                                               void *data;\\r
+                                                                               bool is_requester;\r
+\r
+typedef struct _net_nfc_handover_context_t\r
+{\r
+       NET_NFC_COMMON_HANDOVER_CONTEXT;\r
+}\r
+net_nfc_handover_context_t;\r
+\r
+typedef struct _net_nfc_handover_create_config_context_t\r
+{\r
+       NET_NFC_COMMON_HANDOVER_CONTEXT;\r
+\r
+       net_nfc_conn_handover_carrier_type_e current_type;\r
+       ndef_message_s *ndef_message;\r
+       ndef_message_s *requester; /* for low power selector */\r
+       bool is_low_power;\r
+}\r
+net_nfc_handover_create_config_context_t;\r
+\r
+typedef struct _net_nfc_handover_process_config_context_t\r
+{\r
+       NET_NFC_COMMON_HANDOVER_CONTEXT;\r
+\r
+       net_nfc_carrier_config_s *config;\r
+}\r
+net_nfc_handover_process_config_context_t;\r
+\r
+bool net_nfc_service_llcp_process_accept(net_nfc_request_msg_t* msg);\r
+bool net_nfc_service_llcp_terminate_connection(net_nfc_request_msg_t* msg);\r
+bool net_nfc_service_llcp_disconnect_target(net_nfc_request_msg_t* msg);\r
+bool net_nfc_service_llcp_process_socket_error(net_nfc_request_msg_t* msg);\r
+bool net_nfc_service_llcp_process_accepted_socket_error(net_nfc_request_msg_t* msg);\r
+bool net_nfc_service_llcp_process_send_to_socket(net_nfc_request_msg_t* msg);\r
+bool net_nfc_service_llcp_process_send_socket(net_nfc_request_msg_t* msg);\r
+bool net_nfc_service_llcp_process_receive_socket(net_nfc_request_msg_t* msg);\r
+bool net_nfc_service_llcp_process_receive_from_socket(net_nfc_request_msg_t* msg);\r
+bool net_nfc_service_llcp_process_connect_socket(net_nfc_request_msg_t* msg);\r
+bool net_nfc_service_llcp_process_connect_sap_socket(net_nfc_request_msg_t* msg);\r
+bool net_nfc_service_llcp_process_disconnect_socket(net_nfc_request_msg_t* msg);\r
+net_nfc_error_e net_nfc_service_send_exchanger_msg(net_nfc_request_p2p_send_t* msg);\r
+bool net_nfc_service_llcp_process(net_nfc_target_handle_s* handle, int devType, net_nfc_error_e* result);\r
+\r
+void net_nfc_service_llcp_remove_state (net_nfc_llcp_state_t * state);\r
+void net_nfc_service_llcp_add_state (net_nfc_llcp_state_t * state);\r
+\r
+#endif\r
diff --git a/src/manager/include/net_nfc_service_private.h b/src/manager/include/net_nfc_service_private.h
new file mode 100644 (file)
index 0000000..f05d28c
--- /dev/null
@@ -0,0 +1,32 @@
+/*\r
+  * Copyright 2012  Samsung Electronics Co., Ltd\r
+  *\r
+  * Licensed under the Flora License, Version 1.0 (the "License");\r
+  * you may not use this file except in compliance with the License.\r
+  * You may obtain a copy of the License at\r
+\r
+  *     http://www.tizenopensource.org/license\r
+  *\r
+  * Unless required by applicable law or agreed to in writing, software\r
+  * distributed under the License is distributed on an "AS IS" BASIS,\r
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+  * See the License for the specific language governing permissions and\r
+  * limitations under the License.\r
+  */\r
+\r
+#ifndef NET_NFC_SERVICE_PRIVATE_H\r
+#define NET_NFC_SERVICE_PRIVATE_H\r
+\r
+#include "net_nfc_typedef_private.h"\r
+\r
+bool net_nfc_service_slave_mode_target_detected(net_nfc_request_msg_t* msg);\r
+bool net_nfc_service_standalone_mode_target_detected(net_nfc_request_msg_t* msg);\r
+bool net_nfc_service_termination (net_nfc_request_msg_t* msg);\r
+\r
+void net_nfc_service_target_detected_cb(void* info, void* user_context);\r
+void net_nfc_service_se_transaction_cb(void* info, void* user_context);\r
+void net_nfc_service_llcp_event_cb(void* info, void* user_context);\r
+\r
+void net_nfc_service_msg_processing(data_s* data);\r
+\r
+#endif\r
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 100644 (file)
index 0000000..fbdfeaa
--- /dev/null
@@ -0,0 +1,36 @@
+/*\r
+  * Copyright 2012  Samsung Electronics Co., Ltd\r
+  *\r
+  * Licensed under the Flora License, Version 1.0 (the "License");\r
+  * you may not use this file except in compliance with the License.\r
+  * You may obtain a copy of the License at\r
+\r
+  *     http://www.tizenopensource.org/license\r
+  *\r
+  * Unless required by applicable law or agreed to in writing, software\r
+  * distributed under the License is distributed on an "AS IS" BASIS,\r
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+  * See the License for the specific language governing permissions and\r
+  * limitations under the License.\r
+  */\r
+\r
+#ifndef NET_NFC_SERVICE_SE_PRIVATE_H\r
+#define NET_NFC_SERVICE_SE_PRIVATE_H\r
+\r
+#include "net_nfc_typedef_private.h"\r
+\r
+typedef struct _se_setting_t{\r
+       net_nfc_target_handle_s* current_ese_handle;\r
+       void* open_request_trans_param;\r
+}se_setting_t;\r
+\r
+void net_nfc_service_se_detected(net_nfc_request_msg_t* req_msg);\r
+\r
+/* TAPI SIM API */\r
+\r
+bool net_nfc_service_tapi_init(void);\r
+void net_nfc_service_tapi_deinit(void);\r
+bool net_nfc_service_transfer_apdu(data_s* apdu, void* trans_param);\r
+bool net_nfc_service_request_atr(void* trans_param);\r
+\r
+#endif\r
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 100644 (file)
index 0000000..03c2679
--- /dev/null
@@ -0,0 +1,26 @@
+/*\r
+  * Copyright 2012  Samsung Electronics Co., Ltd\r
+  *\r
+  * Licensed under the Flora License, Version 1.0 (the "License");\r
+  * you may not use this file except in compliance with the License.\r
+  * You may obtain a copy of the License at\r
+\r
+  *     http://www.tizenopensource.org/license\r
+  *\r
+  * Unless required by applicable law or agreed to in writing, software\r
+  * distributed under the License is distributed on an "AS IS" BASIS,\r
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+  * See the License for the specific language governing permissions and\r
+  * limitations under the License.\r
+  */\r
+\r
+#ifndef NET_NFC_SERVICE_TAG_PRIVATE_H\r
+#define NET_NFC_SERVICE_TAG_PRIVATE_H\r
+\r
+#include "net_nfc_typedef_private.h"\r
+\r
+data_s* net_nfc_service_tag_process(net_nfc_target_handle_s* handle, int devType, net_nfc_error_e* result);\r
+void net_nfc_service_clean_tag_context(net_nfc_request_target_detected_t* stand_alone, net_nfc_error_e result);\r
+void net_nfc_service_watch_dog(net_nfc_request_msg_t* req_msg);\r
+\r
+#endif\r
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 100644 (file)
index 0000000..4ab35d5
--- /dev/null
@@ -0,0 +1,26 @@
+/*\r
+  * Copyright 2012  Samsung Electronics Co., Ltd\r
+  *\r
+  * Licensed under the Flora License, Version 1.0 (the "License");\r
+  * you may not use this file except in compliance with the License.\r
+  * You may obtain a copy of the License at\r
+\r
+  *     http://www.tizenopensource.org/license\r
+  *\r
+  * Unless required by applicable law or agreed to in writing, software\r
+  * distributed under the License is distributed on an "AS IS" BASIS,\r
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+  * See the License for the specific language governing permissions and\r
+  * limitations under the License.\r
+  */\r
+\r
+#ifndef NET_NFC_SERVICE_VCONF_H\r
+#define NET_NFC_SERVICE_VCONF_H\r
+\r
+void net_nfc_service_vconf_register_notify_listener();\r
+void net_nfc_service_vconf_unregister_notify_listener();\r
+bool _net_nfc_check_pprom_is_completed ();\r
+void _net_nfc_set_pprom_is_completed ();\r
+\r
+\r
+#endif\r
diff --git a/src/manager/net_nfc_app_util.c b/src/manager/net_nfc_app_util.c
new file mode 100644 (file)
index 0000000..bb1dd47
--- /dev/null
@@ -0,0 +1,749 @@
+/*\r
+  * Copyright 2012  Samsung Electronics Co., Ltd\r
+  *\r
+  * Licensed under the Flora License, Version 1.0 (the "License");\r
+  * you may not use this file except in compliance with the License.\r
+  * You may obtain a copy of the License at\r
+\r
+  *     http://www.tizenopensource.org/license\r
+  *\r
+  * Unless required by applicable law or agreed to in writing, software\r
+  * distributed under the License is distributed on an "AS IS" BASIS,\r
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+  * See the License for the specific language governing permissions and\r
+  * limitations under the License.\r
+  */\r
+\r
+#include <dirent.h>\r
+#include <pwd.h>\r
+#include <grp.h>\r
+#include <sys/stat.h>\r
+#include <time.h>\r
+#include <sys/time.h>\r
+#include <pthread.h>\r
+#include <unistd.h>\r
+#include <stdlib.h>\r
+#include <curl/curl.h>\r
+#include <glib.h>\r
+\r
+#include "net_nfc_typedef.h"\r
+#include "net_nfc_typedef_private.h"\r
+#include "net_nfc_debug_private.h"\r
+#include "net_nfc_util_defines.h"\r
+#include "net_nfc_util_private.h"\r
+#include "net_nfc_util_ndef_message.h"\r
+#include "net_nfc_manager_util_private.h"\r
+#include "net_nfc_app_util_private.h"\r
+//#include "syspopup_caller.h"\r
+\r
+#include "appsvc.h"\r
+#include "aul.h"\r
+#include "vconf.h"\r
+\r
+#define NET_NFC_DEFAULT_APP "com.samsung.nfc-app"\r
+#define NET_NFC_SYSPOPUP "nfc-syspopup"\r
+\r
+#define BT_CARRIER_MIME_NAME "application/vnd.bluetooth.ep.oob"\r
+#define WIFI_CARRIER_MIME_NAME "application/vnd.wfa.wsc"\r
+\r
+static bool _net_nfc_app_util_get_operation_from_record(ndef_record_s *record, char *operation, size_t length);\r
+static bool _net_nfc_app_util_get_mime_from_record(ndef_record_s *record, char *mime, size_t length);\r
+static bool _net_nfc_app_util_get_data_from_record(ndef_record_s *record, char *data, size_t length);\r
+\r
+static char *uri_scheme[] =\r
+{\r
+       "http:",\r
+       "https:",\r
+       "ftp:",\r
+       "sftp:",\r
+       "smb:",\r
+       "nfs:",\r
+       "telnet:",\r
+       "file:",\r
+       "ssh:",\r
+       "market:",\r
+       "tel:",\r
+       "mailto",\r
+       "news:",\r
+       "sip:",\r
+       "sips:",\r
+       "tftp:",\r
+       "imap:",\r
+       "pop:",\r
+       "",\r
+};\r
+\r
+net_nfc_error_e net_nfc_app_util_process_ndef(data_s *data)\r
+{\r
+       net_nfc_error_e result = NET_NFC_UNKNOWN_ERROR;\r
+       ndef_message_s *msg = NULL;\r
+       char operation[2048] = {0, };\r
+       char mime[2048] = {0, };\r
+       char text[2048] = {0, };\r
+       int ret = 0;\r
+       int disable = 0;\r
+\r
+       if (data == NULL || data->buffer == NULL || data->length == 0)\r
+       {\r
+               DEBUG_ERR_MSG("net_nfc_app_util_process_ndef NET_NFC_NULL_PARAMETER");\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+\r
+       /* create file */\r
+       if ((result = net_nfc_app_util_store_ndef_message(data)) != NET_NFC_OK)\r
+       {\r
+               DEBUG_ERR_MSG("net_nfc_app_util_store_ndef_message failed [%d]", result);\r
+               return result;\r
+       }\r
+\r
+       /* check state of launch popup */\r
+       if (vconf_get_bool(NET_NFC_DISABLE_LAUNCH_POPUP_KEY, &disable) == 0 && disable == TRUE)\r
+       {\r
+               DEBUG_MSG("skip launch popup");\r
+               result = NET_NFC_OK;\r
+               return result;\r
+       }\r
+\r
+       if(net_nfc_util_create_ndef_message (&msg) != NET_NFC_OK)\r
+       {\r
+               DEBUG_ERR_MSG ("memory alloc fail..");\r
+               return NET_NFC_ALLOC_FAIL;\r
+       }\r
+\r
+       /* parse ndef message and fill appsvc data */\r
+       if ((result = net_nfc_util_convert_rawdata_to_ndef_message(data, msg)) != NET_NFC_OK)\r
+       {\r
+               DEBUG_ERR_MSG("net_nfc_app_util_store_ndef_message failed [%d]", result);\r
+               goto ERROR;\r
+       }\r
+\r
+       if (_net_nfc_app_util_get_operation_from_record(msg->records, operation, sizeof(operation)) == FALSE)\r
+       {\r
+               DEBUG_ERR_MSG("_net_nfc_app_util_get_operation_from_record failed [%d]", result);\r
+               result = NET_NFC_UNKNOWN_ERROR;\r
+               goto ERROR;\r
+       }\r
+\r
+       DEBUG_MSG("operation : %s", operation);\r
+\r
+       if (_net_nfc_app_util_get_mime_from_record(msg->records, mime, sizeof(mime)) == FALSE)\r
+       {\r
+               DEBUG_ERR_MSG("_net_nfc_app_util_get_mime_from_record failed [%d]", result);\r
+               result = NET_NFC_UNKNOWN_ERROR;\r
+               goto ERROR;\r
+       }\r
+\r
+       DEBUG_MSG("mime : %s", mime);\r
+\r
+       /* launch appsvc */\r
+       if (_net_nfc_app_util_get_data_from_record(msg->records, text, sizeof(text)) == TRUE)\r
+       {\r
+               ret = net_nfc_app_util_appsvc_launch(operation, NULL, mime, text);\r
+       }\r
+       else\r
+       {\r
+               ret = net_nfc_app_util_appsvc_launch(operation, NULL, mime, NULL);\r
+       }\r
+\r
+       DEBUG_MSG("net_nfc_app_util_appsvc_launch return %d", ret);\r
+\r
+       result = NET_NFC_OK;\r
+\r
+ERROR :\r
+       net_nfc_util_free_ndef_message(msg);\r
+\r
+       return result;\r
+}\r
+\r
+bool _net_nfc_app_util_change_file_owner_permission(FILE *file)\r
+{\r
+       char *buffer = NULL;\r
+       size_t buffer_len = 0;\r
+       struct passwd pwd = { 0, };\r
+       struct passwd *pw_inhouse = NULL;\r
+       struct group grp = { 0, };\r
+       struct group *gr_inhouse = NULL;\r
+\r
+       if (file == NULL)\r
+               return false;\r
+\r
+       /* change permission */\r
+       fchmod(fileno(file), 0777);\r
+\r
+       /* change owner */\r
+       /* get passwd id */\r
+       buffer_len = sysconf(_SC_GETPW_R_SIZE_MAX);\r
+       if (buffer_len == -1)\r
+       {\r
+               buffer_len = 16384;\r
+       }\r
+\r
+       _net_nfc_util_alloc_mem(buffer, buffer_len);\r
+       if (buffer == NULL)\r
+               return false;\r
+\r
+       getpwnam_r("inhouse", &pwd, buffer, buffer_len, &pw_inhouse);\r
+       _net_nfc_util_free_mem(buffer);\r
+\r
+       /* get group id */\r
+       buffer_len = sysconf(_SC_GETGR_R_SIZE_MAX);\r
+       if (buffer_len == -1)\r
+       {\r
+               buffer_len = 16384;\r
+       }\r
+\r
+       _net_nfc_util_alloc_mem(buffer, buffer_len);\r
+       if (buffer == NULL)\r
+               return false;\r
+\r
+       getgrnam_r("inhouse", &grp, buffer, buffer_len, &gr_inhouse);\r
+       _net_nfc_util_free_mem(buffer);\r
+\r
+       if ((pw_inhouse != NULL) && (gr_inhouse != NULL))\r
+       {\r
+               if (fchown(fileno(file), pw_inhouse->pw_uid, gr_inhouse->gr_gid) < 0)\r
+               {\r
+                       DEBUG_ERR_MSG("failed to change owner");\r
+               }\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+net_nfc_error_e net_nfc_app_util_store_ndef_message(data_s *data)\r
+{\r
+       net_nfc_error_e result = NET_NFC_UNKNOWN_ERROR;\r
+       char file_name[1024] = { 0, };\r
+       struct stat st;\r
+       FILE *fp = NULL;\r
+\r
+       if (data == NULL)\r
+       {\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+\r
+       /* check and make directory */\r
+       snprintf(file_name, sizeof(file_name), "%s/%s", NET_NFC_MANAGER_DATA_PATH, NET_NFC_MANAGER_DATA_PATH_MESSAGE);\r
+       DEBUG_MSG("path : %s", file_name);\r
+\r
+       if (stat(file_name, &st) == -1)\r
+       {\r
+               char command[1024];\r
+\r
+               DEBUG_MSG("path doesn't exist : %s", file_name);\r
+\r
+               snprintf(command, sizeof(command), "mkdir -p -m 755 %s", file_name);\r
+               DEBUG_MSG("command : %s", command);\r
+\r
+               system(command);\r
+\r
+               if (stat(file_name, &st) == -1)\r
+               {\r
+                       DEBUG_ERR_MSG("mkdir failed");\r
+                       return NET_NFC_UNKNOWN_ERROR;\r
+               }\r
+       }\r
+\r
+       /* create file */\r
+       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);\r
+       DEBUG_MSG("file path : %s", file_name);\r
+\r
+       unlink(file_name);\r
+\r
+       DEBUG_MSG("file name is = [%s]", file_name);\r
+\r
+       if ((fp = fopen(file_name, "w")) != NULL)\r
+       {\r
+               int length = 0;\r
+\r
+               if ((length = fwrite(data->buffer, 1, data->length, fp)) > 0)\r
+               {\r
+                       DEBUG_MSG("[%d] bytes is written \n", length);\r
+               }\r
+               else\r
+               {\r
+                       DEBUG_MSG("write is failed = [%d] \n", data->length);\r
+               }\r
+\r
+               _net_nfc_app_util_change_file_owner_permission(fp);\r
+\r
+               fflush(fp);\r
+               fsync(fileno(fp));\r
+               fclose(fp);\r
+\r
+               result = NET_NFC_OK;\r
+       }\r
+\r
+       return result;\r
+}\r
+\r
+bool net_nfc_app_util_is_dir(const char* path_name)\r
+{\r
+       struct stat statbuf = {0};\r
+\r
+       if (stat(path_name, &statbuf) == -1)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if(S_ISDIR(statbuf.st_mode) != 0)\r
+       {\r
+               return true;\r
+       }\r
+       else\r
+       {\r
+               return false;\r
+       }\r
+}\r
+\r
+void net_nfc_app_util_clean_storage(char* src_path)\r
+{\r
+       struct dirent* ent = NULL;\r
+       DIR* dir = NULL;\r
+\r
+       char path[1024] = {0};\r
+\r
+       if ((dir = opendir(src_path)) == NULL )\r
+       {\r
+               return;\r
+       }\r
+\r
+       while((ent = readdir(dir)) != NULL)\r
+       {\r
+               if( strncmp(ent->d_name, "." , 1 ) == 0 || strncmp(ent->d_name, ".." , 2) == 0)\r
+               {\r
+                       continue;\r
+               }\r
+               else\r
+               {\r
+                       snprintf(path,1024, "%s/%s", src_path, ent->d_name);\r
+\r
+                       if(net_nfc_app_util_is_dir(path) != false)\r
+                       {\r
+                               net_nfc_app_util_clean_storage(path);\r
+                               rmdir(path);\r
+                       }\r
+                       else\r
+                       {\r
+                               unlink(path);\r
+                       }\r
+\r
+               }\r
+       }\r
+\r
+       closedir(dir);\r
+\r
+       rmdir(src_path);\r
+}\r
+\r
+static bool _net_nfc_app_util_get_operation_from_record(ndef_record_s *record, char *operation, size_t length)\r
+{\r
+       bool result = FALSE;\r
+       char *op_text = NULL;\r
+\r
+       if (record == NULL || operation == NULL || length == 0)\r
+       {\r
+               return result;\r
+       }\r
+\r
+       switch (record->TNF)\r
+       {\r
+       case NET_NFC_RECORD_WELL_KNOWN_TYPE :\r
+               op_text = "http://tizen.org/appsvc/operation/nfc_well_known_type";\r
+               break;\r
+       case NET_NFC_RECORD_MIME_TYPE :\r
+               op_text = "http://tizen.org/appsvc/operation/nfc_mime_type";\r
+               break;\r
+       case NET_NFC_RECORD_URI : /* Absolute URI */\r
+               op_text = "http://tizen.org/appsvc/operation/nfc_uri_type";\r
+               break;\r
+       case NET_NFC_RECORD_EXTERNAL_RTD : /* external type */\r
+               op_text = "http://tizen.org/appsvc/operation/nfc_external_type";\r
+               break;\r
+       case NET_NFC_RECORD_EMPTY : /* empty_tag */\r
+               op_text = "http://tizen.org/appsvc/operation/nfc_empty_type";\r
+               break;\r
+       case NET_NFC_RECORD_UNKNOWN : /* unknown msg. discard it */\r
+       case NET_NFC_RECORD_UNCHAGNED : /* RFU msg. discard it */\r
+       default :\r
+               break;\r
+       }\r
+\r
+       if (op_text != NULL)\r
+       {\r
+               size_t op_length = 0;\r
+\r
+               op_length = MIN(strlen(op_text) + 1, length);\r
+\r
+               strncpy(operation, op_text, op_length - 1);\r
+               operation[op_length - 1] = '\0';\r
+               result = TRUE;\r
+       }\r
+\r
+       return result;\r
+}\r
+\r
+static bool _net_nfc_app_util_get_mime_from_record(ndef_record_s *record, char *mime, size_t length)\r
+{\r
+       bool result = FALSE;\r
+\r
+       if (record == NULL || mime == NULL || length == 0)\r
+       {\r
+               return result;\r
+       }\r
+\r
+       switch (record->TNF)\r
+       {\r
+       case NET_NFC_RECORD_WELL_KNOWN_TYPE :\r
+               {\r
+                       if (record->type_s.buffer == NULL || record->type_s.length == 0 || record->payload_s.buffer == NULL || record->payload_s.length == 0)\r
+                       {\r
+                               DEBUG_ERR_MSG("Broken NDEF Message [NET_NFC_RECORD_WELL_KNOWN_TYPE]");\r
+                               break;\r
+                       }\r
+\r
+                       if (record->type_s.length == 1 && record->type_s.buffer[0] == 'U')\r
+                       {\r
+                               snprintf(mime, length, "U/0x%02x", record->payload_s.buffer[0]);\r
+                       }\r
+                       else\r
+                       {\r
+                               memcpy(mime, record->type_s.buffer, record->type_s.length);\r
+                               mime[record->type_s.length] = '\0';\r
+\r
+                               strncat(mime, "/*", 2);\r
+                               mime[record->type_s.length + 2] = '\0';\r
+                       }\r
+\r
+                       DEBUG_MSG("mime [%s]", mime);\r
+\r
+                       result = TRUE;\r
+               }\r
+               break;\r
+\r
+       case NET_NFC_RECORD_MIME_TYPE :\r
+               {\r
+                       char *token = NULL;\r
+                       char *buffer = NULL;\r
+                       int len = 0;\r
+\r
+                       if (record->type_s.buffer == NULL || record->type_s.length == 0)\r
+                       {\r
+                               DEBUG_ERR_MSG("Broken NDEF Message [NET_NFC_RECORD_MIME_TYPE]");\r
+                               break;\r
+                       }\r
+\r
+                       /* get mime type */\r
+                       _net_nfc_manager_util_alloc_mem(buffer, record->type_s.length + 1);\r
+                       if (buffer == NULL)\r
+                       {\r
+                               DEBUG_ERR_MSG("_net_nfc_manager_util_alloc_mem return NULL");\r
+                               break;\r
+                       }\r
+                       memcpy(buffer, record->type_s.buffer, record->type_s.length);\r
+\r
+                       DEBUG_MSG("NET_NFC_RECORD_MIME_TYPE type [%s]", buffer);\r
+\r
+                       token = strchr(buffer, ';');\r
+                       if (token != NULL)\r
+                       {\r
+                               DEBUG_MSG("token = strchr(buffer, ';') != NULL, len [%d]", token - buffer);\r
+                               len = MIN(token - buffer, length - 1);\r
+                       }\r
+                       else\r
+                       {\r
+                               len = MIN(strlen(buffer), length - 1);\r
+                       }\r
+\r
+                       DEBUG_MSG("len [%d]", len);\r
+\r
+                       strncpy(mime, buffer, len);\r
+                       mime[len] = '\0';\r
+\r
+                       DEBUG_MSG("mime [%s]", mime);\r
+\r
+                       _net_nfc_manager_util_free_mem(buffer);\r
+\r
+                       result = TRUE;\r
+               }\r
+               break;\r
+\r
+       case NET_NFC_RECORD_URI : /* Absolute URI */\r
+               {\r
+                       CURL *curl_handle = NULL;\r
+                       char *buffer = NULL;\r
+                       uint32_t scheme_len = 0;\r
+                       int index = 0;\r
+                       char scheme[100] = {0, };\r
+\r
+                       if (record->payload_s.buffer == NULL || record->payload_s.length == 0)\r
+                       {\r
+                               DEBUG_ERR_MSG("Broken NDEF Message [NET_NFC_RECORD_URI]");\r
+                               break;\r
+                       }\r
+\r
+                       _net_nfc_manager_util_alloc_mem(buffer, record->payload_s.length + 1);\r
+                       if (buffer == NULL)\r
+                       {\r
+                               DEBUG_ERR_MSG("_net_nfc_manager_util_alloc_mem return NULL");\r
+                               break;\r
+                       }\r
+                       memcpy(buffer, record->payload_s.buffer, record->payload_s.length);\r
+\r
+                       while (strlen(uri_scheme[index]) > 0)\r
+                       {\r
+                               if (strncasecmp(buffer, uri_scheme[index], strlen(uri_scheme[index])) == 0)\r
+                               {\r
+                                       scheme_len = MIN(sizeof(scheme) - 1, strlen(uri_scheme[index]) - 1);\r
+\r
+                                       memcpy(scheme, uri_scheme[index], scheme_len);\r
+                                       scheme[scheme_len] = '\0';\r
+                                       break;\r
+                               }\r
+                               index++;\r
+                       }\r
+\r
+                       if (scheme_len == 0)\r
+                       {\r
+                               scheme_len = MIN(sizeof(scheme) - 1, strlen("unknown"));\r
+\r
+                               memcpy(scheme, "unknown", scheme_len);\r
+                               scheme[scheme_len] = '\0';\r
+                       }\r
+\r
+                       DEBUG_MSG("mime not end [%s]", mime);\r
+                       _net_nfc_manager_util_free_mem(buffer);\r
+\r
+                       /* percent encode uri */\r
+                       curl_handle = curl_easy_init();\r
+                       if (curl_handle == NULL)\r
+                       {\r
+                               DEBUG_ERR_MSG("curl_easy_init return NULL");\r
+                               break;\r
+                       }\r
+\r
+                       buffer = curl_easy_escape(curl_handle, (char *)record->payload_s.buffer, record->payload_s.length);\r
+                       if (buffer == NULL)\r
+                       {\r
+                               DEBUG_ERR_MSG("curl_easy_escape return NULL");\r
+                               curl_easy_cleanup(curl_handle);\r
+                               break;\r
+                       }\r
+                       DEBUG_MSG("curl_easy_escape result [%s]", buffer);\r
+\r
+                       snprintf(mime, length, "%s/%s", scheme, buffer);\r
+                       DEBUG_MSG("mime [%s]", mime);\r
+\r
+                       /* release curl */\r
+                       curl_free(buffer);\r
+                       curl_easy_cleanup(curl_handle);\r
+\r
+                       result = TRUE;\r
+               }\r
+               break;\r
+\r
+       case NET_NFC_RECORD_EXTERNAL_RTD : /* external type */\r
+               {\r
+                       CURL *curl_handle = NULL;\r
+                       char *token = NULL;\r
+                       char *buffer = NULL;\r
+                       int token_len = 0;\r
+                       int len = 0;\r
+\r
+                       if (record->type_s.buffer == NULL || record->type_s.length == 0)\r
+                       {\r
+                               DEBUG_ERR_MSG("Broken NDEF Message [NET_NFC_RECORD_EXTERNAL_RTD]");\r
+                               break;\r
+                       }\r
+\r
+                       /* get mime type */\r
+                       _net_nfc_manager_util_alloc_mem(buffer, record->type_s.length + 1);\r
+                       if (buffer == NULL)\r
+                       {\r
+                               DEBUG_ERR_MSG("_net_nfc_manager_util_alloc_mem return NULL");\r
+                               break;\r
+                       }\r
+                       memcpy(buffer, record->type_s.buffer, record->type_s.length);\r
+\r
+                       DEBUG_MSG("NET_NFC_RECORD_EXTERNAL_RTD type [%s]", buffer);\r
+\r
+                       token = strchr(buffer, ':');\r
+                       if (token != NULL)\r
+                       {\r
+                               DEBUG_MSG("token = strchr(buffer, ':') != NULL");\r
+                               *token = '/';\r
+                               token_len = token - buffer;\r
+\r
+                               memcpy(mime, buffer, token_len);\r
+                               mime[token_len] = '/';\r
+                               mime[token_len + 1] = '\0';\r
+                       }\r
+                       else\r
+                       {\r
+                               strncpy(mime, "unknown/", 8);\r
+                               mime[8] = '\0';\r
+                       }\r
+\r
+                       DEBUG_MSG("mime not end [%s]", mime);\r
+                       _net_nfc_manager_util_free_mem(buffer);\r
+\r
+                       /* percent encode uri */\r
+                       curl_handle = curl_easy_init();\r
+                       if (curl_handle == NULL)\r
+                       {\r
+                               DEBUG_ERR_MSG("curl_easy_init return NULL");\r
+                               break;\r
+                       }\r
+\r
+                       buffer = curl_easy_escape(curl_handle, (char *)record->payload_s.buffer, record->payload_s.length);\r
+                       if (buffer == NULL)\r
+                       {\r
+                               DEBUG_ERR_MSG("curl_easy_escape return NULL");\r
+                               curl_easy_cleanup(curl_handle);\r
+                               break;\r
+                       }\r
+                       DEBUG_MSG("curl_easy_escape result [%s]", buffer);\r
+\r
+                       token_len = strlen(mime);\r
+                       len = MIN(length - token_len - 1, strlen(buffer));\r
+\r
+                       memcpy(mime + token_len, buffer, len);\r
+                       mime[len + token_len] = '\0';\r
+\r
+                       DEBUG_MSG("mime [%s]", mime);\r
+\r
+                       /* release curl */\r
+                       curl_free(buffer);\r
+                       curl_easy_cleanup(curl_handle);\r
+\r
+                       result = TRUE;\r
+               }\r
+               break;\r
+\r
+       case NET_NFC_RECORD_EMPTY :  /* empty_tag */\r
+               result = TRUE;\r
+               mime = NULL;\r
+               break;\r
+\r
+\r
+       case NET_NFC_RECORD_UNKNOWN : /* unknown msg. discard it */\r
+       case NET_NFC_RECORD_UNCHAGNED : /* RFU msg. discard it */\r
+       default :\r
+               break;\r
+       }\r
+\r
+       return result;\r
+}\r
+\r
+static bool _net_nfc_app_util_get_data_from_record(ndef_record_s *record, char *data, size_t length)\r
+{\r
+       bool result = FALSE;\r
+\r
+       if (record == NULL || data == NULL || length == 0)\r
+       {\r
+               return result;\r
+       }\r
+\r
+       switch (record->TNF)\r
+       {\r
+       case NET_NFC_RECORD_WELL_KNOWN_TYPE :\r
+               {\r
+                       if (record->type_s.buffer == NULL || record->type_s.length == 0 || record->payload_s.buffer == NULL || record->payload_s.length == 0)\r
+                       {\r
+                               DEBUG_ERR_MSG("Broken NDEF Message [NET_NFC_RECORD_WELL_KNOWN_TYPE]");\r
+                               break;\r
+                       }\r
+\r
+                       if (record->type_s.length == 1 && record->type_s.buffer[0] == 'T')\r
+                       {\r
+                               uint8_t *buffer_temp = record->payload_s.buffer;\r
+                               uint32_t buffer_length = record->payload_s.length;\r
+\r
+                               int index = (buffer_temp[0] & 0x3F) + 1;\r
+                               int text_length = buffer_length - index;\r
+\r
+                               memcpy(data, &(buffer_temp[index]), MIN(text_length, length));\r
+                       }\r
+\r
+                       DEBUG_MSG("data [%s]", data);\r
+\r
+                       result = TRUE;\r
+               }\r
+               break;\r
+\r
+       case NET_NFC_RECORD_MIME_TYPE :\r
+       case NET_NFC_RECORD_URI : /* Absolute URI */\r
+       case NET_NFC_RECORD_EXTERNAL_RTD : /* external type */\r
+       case NET_NFC_RECORD_EMPTY : /* empy msg. discard it */\r
+       case NET_NFC_RECORD_UNKNOWN : /* unknown msg. discard it */\r
+       case NET_NFC_RECORD_UNCHAGNED : /* RFU msg. discard it */\r
+       default :\r
+               break;\r
+       }\r
+\r
+       return result;\r
+}\r
+\r
+void net_nfc_app_util_aul_launch_app(char* package_name, bundle* kb)\r
+{\r
+       int result = 0;\r
+       if((result = aul_launch_app(package_name, kb)) < 0)\r
+       {\r
+               switch(result)\r
+               {\r
+                       case AUL_R_EINVAL:\r
+                               DEBUG_MSG("aul launch error : AUL_R_EINVAL");\r
+                               break;\r
+                       case AUL_R_ECOMM:\r
+                               DEBUG_MSG("aul launch error : AUL_R_ECOM");\r
+                               break;\r
+                       case AUL_R_ERROR:\r
+                               DEBUG_MSG("aul launch error : AUL_R_ERROR");\r
+                               break;\r
+                       default:\r
+                               DEBUG_MSG("aul launch error : unknown ERROR");\r
+                               break;\r
+               }\r
+       }\r
+       else\r
+       {\r
+               DEBUG_MSG("success to launch [%s]", package_name);\r
+       }\r
+}\r
+\r
+int net_nfc_app_util_appsvc_launch(const char *operation, const char *uri, const char *mime, const char *data)\r
+{\r
+       int result = -1;\r
+\r
+       bundle *bd = NULL;\r
+\r
+       bd = bundle_create();\r
+       if (bd == NULL)\r
+               return result;\r
+\r
+       if (operation != NULL)\r
+       {\r
+               appsvc_set_operation(bd, operation);\r
+       }\r
+\r
+       if (uri != NULL)\r
+       {\r
+               appsvc_set_uri(bd, uri);\r
+       }\r
+\r
+       if (mime != NULL)\r
+       {\r
+               appsvc_set_mime(bd, mime);\r
+       }\r
+\r
+       if (data != NULL)\r
+       {\r
+               appsvc_add_data(bd, "data", data);\r
+       }\r
+\r
+       result = appsvc_run_service(bd, 0, NULL, NULL);\r
+\r
+       bundle_free(bd);\r
+\r
+       return result;\r
+}\r
diff --git a/src/manager/net_nfc_controller.c b/src/manager/net_nfc_controller.c
new file mode 100644 (file)
index 0000000..b7ebd64
--- /dev/null
@@ -0,0 +1,706 @@
+/*\r
+  * Copyright 2012  Samsung Electronics Co., Ltd\r
+  *\r
+  * Licensed under the Flora License, Version 1.0 (the "License");\r
+  * you may not use this file except in compliance with the License.\r
+  * You may obtain a copy of the License at\r
+\r
+  *     http://www.tizenopensource.org/license\r
+  *\r
+  * Unless required by applicable law or agreed to in writing, software\r
+  * distributed under the License is distributed on an "AS IS" BASIS,\r
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+  * See the License for the specific language governing permissions and\r
+  * limitations under the License.\r
+  */\r
+\r
+#include <stdio.h>\r
+#include <dlfcn.h>\r
+#include <unistd.h>\r
+\r
+#include "net_nfc_oem_controller.h"\r
+#include "net_nfc_controller_private.h"\r
+#include "net_nfc_util_private.h"\r
+#include "net_nfc_debug_private.h"\r
+#include "net_nfc_server_ipc_private.h"\r
+#include "net_nfc_server_dispatcher_private.h"\r
+\r
+#define NET_NFC_OEM_LIBRARY_PATH "/usr/lib/libnfc-plugin.so"\r
+\r
+static net_nfc_oem_interface_s g_interface;\r
+\r
+void* net_nfc_controller_onload()\r
+{\r
+       void* handle = NULL;\r
+       bool (*onload) (net_nfc_oem_interface_s* interfaces);\r
+\r
+       FILE *fp;\r
+       char cpuinfo_buffer[1024];\r
+       size_t bytes_read;\r
+       char *match_revision;\r
+       int revision;\r
+               char *token;\r
+       char *token_cpuinfo[10];\r
+       int i = 0;\r
+       const char *library_path;\r
+\r
+\r
+       fp = fopen( "/proc/cpuinfo" , "r" );\r
+       bytes_read = fread(cpuinfo_buffer , 1 , sizeof(cpuinfo_buffer) , fp);/* Read the cpuinfo to bytes_read */\r
+       fclose(fp);\r
+\r
+       match_revision = strstr(cpuinfo_buffer , "Hardware");\r
+       if(match_revision != NULL)\r
+       {\r
+               token = strtok(match_revision , " :\n");\r
+\r
+               while(token != NULL &&  i  < 5)\r
+               {\r
+                       i++;\r
+                       DEBUG_SERVER_MSG("token = %s\n" , token);\r
+\r
+                       token=  strtok(NULL , " :\n");\r
+\r
+                       token_cpuinfo[i] = token;\r
+                       DEBUG_SERVER_MSG("temp[%d]'s value = %s\n" ,i ,  token_cpuinfo[i]);\r
+               }\r
+\r
+               revision = atoi(token_cpuinfo[3]);\r
+               DEBUG_SERVER_MSG("revision = %d\n" , revision );\r
+\r
+               if(!(strncmp(token_cpuinfo[1] , "SLP_PQ" , 6)) && (revision >= 7))\r
+               {\r
+                       DEBUG_SERVER_MSG("It's SLP_PQ && Revision 7!!\n");\r
+                       library_path = "/usr/lib/libnfc-plugin-65nxp.so";\r
+\r
+               }\r
+               else\r
+               {\r
+                       DEBUG_SERVER_MSG("It's NOT!!!! SLP_PQ && Revision 7!!\n");\r
+                       library_path = "/usr/lib/libnfc-plugin.so";\r
+               }\r
+       }\r
+       else\r
+       {\r
+               DEBUG_SERVER_MSG("It doesn't have Hardware info!! \n");\r
+               library_path = "/usr/lib/libnfc-plugin.so";\r
+       }\r
+\r
+\r
+       if((handle = dlopen(library_path/*NET_NFC_OEM_LIBRARY_PATH*/, RTLD_LAZY)) != NULL)\r
+       {\r
+               if((onload = dlsym(handle, "onload")) != NULL)\r
+               {\r
+                       if(onload(&g_interface) == true)\r
+                       {\r
+                               DEBUG_SERVER_MSG("success to load library");\r
+                               return handle;\r
+                       }\r
+                       else\r
+                       {\r
+                               DEBUG_SERVER_MSG("failed to load library");\r
+                       }\r
+               }\r
+               else\r
+               {\r
+                       DEBUG_SERVER_MSG("can not find symbol onload");\r
+               }\r
+       }\r
+       else\r
+       {\r
+               DEBUG_SERVER_MSG("dlopen is failed \n");\r
+       }\r
+\r
+       if(handle != NULL)\r
+       {\r
+               dlclose(handle);\r
+               handle = NULL;\r
+       }\r
+\r
+       return false;\r
+}\r
+\r
+bool net_nfc_controller_unload(void* handle)\r
+{\r
+       memset(&g_interface, 0x00, sizeof(net_nfc_oem_interface_s));\r
+\r
+       if(handle != NULL)\r
+       {\r
+               dlclose(handle);\r
+               handle = NULL;\r
+       }\r
+       return true;\r
+}\r
+\r
+bool net_nfc_controller_init (net_nfc_error_e* result)\r
+{\r
+       if(g_interface.init != NULL)\r
+       {\r
+               return g_interface.init(result);\r
+       }\r
+       else\r
+       {\r
+               *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;\r
+               DEBUG_SERVER_MSG("interface is null");\r
+               return false;\r
+       }\r
+}\r
+\r
+bool net_nfc_controller_deinit (void)\r
+{\r
+       if(g_interface.deinit != NULL)\r
+       {\r
+               return g_interface.deinit();\r
+       }\r
+       else\r
+       {\r
+               DEBUG_SERVER_MSG("interface is null");\r
+               return false;\r
+       }\r
+}\r
+\r
+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)\r
+{\r
+       if(g_interface.register_listener != NULL)\r
+       {\r
+               return g_interface.register_listener(target_detection_listener, se_transaction_listener, llcp_event_listener, result);\r
+       }\r
+       else\r
+       {\r
+               *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;\r
+               DEBUG_SERVER_MSG("interface is null");\r
+               return false;\r
+       }\r
+}\r
+\r
+bool net_nfc_controller_unregister_listener()\r
+{\r
+       if(g_interface.unregister_listener != NULL)\r
+       {\r
+               return g_interface.unregister_listener();\r
+       }\r
+       else\r
+       {\r
+               DEBUG_SERVER_MSG("interface is null");\r
+               return false;\r
+       }\r
+}\r
+\r
+bool net_nfc_controller_check_firmware_version(net_nfc_error_e* result)\r
+{\r
+       if(g_interface.check_firmware_version != NULL)\r
+       {\r
+               return g_interface.check_firmware_version(result);\r
+       }\r
+       else\r
+       {\r
+               *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;\r
+               DEBUG_SERVER_MSG("interface is null");\r
+               return false;\r
+       }\r
+}\r
+\r
+bool net_nfc_controller_update_firmware(net_nfc_error_e* result)\r
+{\r
+       if(g_interface.update_firmeware != NULL)\r
+       {\r
+               return g_interface.update_firmeware(result);\r
+       }\r
+       else\r
+       {\r
+               *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;\r
+               DEBUG_SERVER_MSG("interface is null");\r
+               return false;\r
+       }\r
+}\r
+\r
+bool net_nfc_controller_get_stack_information(net_nfc_stack_information_s* stack_info, net_nfc_error_e* result)\r
+{\r
+       if(g_interface.get_stack_information != NULL)\r
+       {\r
+               return g_interface.get_stack_information(stack_info, result);\r
+       }\r
+       else\r
+       {\r
+               *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;\r
+               DEBUG_SERVER_MSG("interface is null");\r
+               return false;\r
+       }\r
+}\r
+\r
+bool net_nfc_controller_confiure_discovery (net_nfc_discovery_mode_e mode, net_nfc_event_filter_e config, net_nfc_error_e* result)\r
+{\r
+       if(g_interface.configure_discovery != NULL)\r
+       {\r
+               return g_interface.configure_discovery(mode, config, result);\r
+       }\r
+       else\r
+       {\r
+               *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;\r
+               DEBUG_SERVER_MSG("interface is null");\r
+               return false;\r
+       }\r
+}\r
+\r
+bool net_nfc_controller_get_secure_element_list(net_nfc_secure_element_info_s* list, int* count, net_nfc_error_e* result)\r
+{\r
+       if(g_interface.get_secure_element_list != NULL)\r
+       {\r
+               return g_interface.get_secure_element_list(list, count, result);\r
+       }\r
+       else\r
+       {\r
+               *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;\r
+               DEBUG_SERVER_MSG("interface is null");\r
+               return false;\r
+       }\r
+}\r
+\r
+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)\r
+{\r
+       if(g_interface.set_secure_element_mode != NULL)\r
+       {\r
+               return g_interface.set_secure_element_mode(element_type, mode, result);\r
+       }\r
+       else\r
+       {\r
+               *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;\r
+               DEBUG_SERVER_MSG("interface is null");\r
+               return false;\r
+       }\r
+}\r
+\r
+bool net_nfc_controller_check_target_presence(net_nfc_target_handle_s* handle, net_nfc_error_e* result)\r
+{\r
+       if(g_interface.check_presence != NULL)\r
+       {\r
+               return g_interface.check_presence(handle, result);\r
+       }\r
+       else\r
+       {\r
+               *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;\r
+               DEBUG_SERVER_MSG("interface is null");\r
+               return false;\r
+       }\r
+}\r
+\r
+bool net_nfc_controller_connect(net_nfc_target_handle_s* handle, net_nfc_error_e* result)\r
+{\r
+       if(g_interface.connect != NULL)\r
+       {\r
+               return g_interface.connect(handle, result);\r
+       }\r
+       else\r
+       {\r
+               *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;\r
+               DEBUG_SERVER_MSG("interface is null");\r
+               return false;\r
+       }\r
+}\r
+\r
+bool net_nfc_controller_disconnect(net_nfc_target_handle_s* handle, net_nfc_error_e* result)\r
+{\r
+       if(g_interface.disconnect != NULL)\r
+       {\r
+               net_nfc_server_free_current_tag_info();\r
+\r
+               return g_interface.disconnect(handle, result);\r
+       }\r
+       else\r
+       {\r
+               *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;\r
+               DEBUG_SERVER_MSG("interface is null");\r
+               return false;\r
+       }\r
+}\r
+\r
+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)\r
+{\r
+       if(g_interface.check_ndef != NULL)\r
+       {\r
+               return g_interface.check_ndef(handle, ndef_card_state, max_data_size, real_data_size, result);\r
+       }\r
+       else\r
+       {\r
+               *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;\r
+               DEBUG_SERVER_MSG("interface is null");\r
+               return false;\r
+       }\r
+}\r
+\r
+bool net_nfc_controller_read_ndef(net_nfc_target_handle_s* handle, data_s** data, net_nfc_error_e* result)\r
+{\r
+       if(g_interface.read_ndef != NULL)\r
+       {\r
+               return g_interface.read_ndef(handle, data, result);\r
+       }\r
+       else\r
+       {\r
+               *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;\r
+               DEBUG_SERVER_MSG("interface is null");\r
+               return false;\r
+       }\r
+}\r
+\r
+bool net_nfc_controller_write_ndef(net_nfc_target_handle_s* handle, data_s* data, net_nfc_error_e* result)\r
+{\r
+       if(g_interface.write_ndef != NULL)\r
+       {\r
+               return g_interface.write_ndef(handle, data, result);\r
+       }\r
+       else\r
+       {\r
+               *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;\r
+               DEBUG_SERVER_MSG("interface is null");\r
+               return false;\r
+       }\r
+}\r
+\r
+bool net_nfc_controller_make_read_only_ndef(net_nfc_target_handle_s* handle,  net_nfc_error_e* result)\r
+{\r
+       if(g_interface.make_read_only_ndef != NULL)\r
+       {\r
+               return g_interface.make_read_only_ndef(handle, result);\r
+       }\r
+       else\r
+       {\r
+               *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;\r
+               DEBUG_SERVER_MSG("interface is null");\r
+               return false;\r
+       }\r
+}\r
+\r
+bool net_nfc_controller_format_ndef(net_nfc_target_handle_s* handle, data_s* secure_key, net_nfc_error_e* result)\r
+{\r
+       if(g_interface.format_ndef != NULL)\r
+       {\r
+               return g_interface.format_ndef(handle, secure_key, result);\r
+       }\r
+       else\r
+       {\r
+               *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;\r
+               DEBUG_SERVER_MSG("interface is null");\r
+               return false;\r
+       }\r
+}\r
+\r
+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)\r
+{\r
+       if(g_interface.transceive != NULL)\r
+       {\r
+               return g_interface.transceive(handle, info, data, result);\r
+       }\r
+       else\r
+       {\r
+               *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;\r
+               DEBUG_SERVER_MSG("interface is null");\r
+               return false;\r
+       }\r
+}\r
+\r
+bool net_nfc_controller_exception_handler()\r
+{\r
+       if(g_interface.exception_handler != NULL)\r
+       {\r
+               return g_interface.exception_handler();\r
+       }\r
+       else\r
+       {\r
+               DEBUG_SERVER_MSG("interface is null");\r
+               return false;\r
+       }\r
+}\r
+\r
+bool net_nfc_controller_is_ready(net_nfc_error_e* result)\r
+{\r
+       if(g_interface.is_ready != NULL)\r
+       {\r
+               return g_interface.is_ready(result);\r
+       }\r
+       else\r
+       {\r
+               *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;\r
+               DEBUG_SERVER_MSG("interface is null");\r
+               return false;\r
+       }\r
+}\r
+\r
+bool net_nfc_controller_llcp_config(net_nfc_llcp_config_info_s * config, net_nfc_error_e* result)\r
+{\r
+       if(g_interface.config_llcp != NULL)\r
+       {\r
+               return g_interface.config_llcp(config, result);\r
+       }\r
+       else\r
+       {\r
+               *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;\r
+               DEBUG_SERVER_MSG("interface is null");\r
+               return false;\r
+       }\r
+}\r
+bool net_nfc_controller_llcp_check_llcp(net_nfc_target_handle_s* handle, net_nfc_error_e* result)\r
+{\r
+       if(g_interface.check_llcp_status != NULL)\r
+       {\r
+               return g_interface.check_llcp_status(handle, result);\r
+       }\r
+       else\r
+       {\r
+               *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;\r
+               DEBUG_SERVER_MSG("interface is null");\r
+               return false;\r
+       }\r
+}\r
+bool net_nfc_controller_llcp_activate_llcp(net_nfc_target_handle_s* handle, net_nfc_error_e* result)\r
+{\r
+       if(g_interface.activate_llcp != NULL)\r
+       {\r
+               return g_interface.activate_llcp(handle, result);\r
+       }\r
+       else\r
+       {\r
+               *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;\r
+               DEBUG_SERVER_MSG("interface is null");\r
+               return false;\r
+       }\r
+}\r
+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)\r
+{\r
+       if(g_interface.create_llcp_socket != NULL)\r
+       {\r
+               return g_interface.create_llcp_socket(socket,socketType, miu, rw,  result, user_param);\r
+       }\r
+       else\r
+       {\r
+               *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;\r
+               DEBUG_SERVER_MSG("interface is null");\r
+               return false;\r
+       }\r
+}\r
+bool net_nfc_controller_llcp_bind(net_nfc_llcp_socket_t socket, uint8_t service_access_point, net_nfc_error_e* result)\r
+{\r
+       if(g_interface.bind_llcp_socket != NULL)\r
+       {\r
+               return g_interface.bind_llcp_socket(socket, service_access_point, result);\r
+       }\r
+       else\r
+       {\r
+               *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;\r
+               DEBUG_SERVER_MSG("interface is null");\r
+               return false;\r
+       }\r
+}\r
+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)\r
+{\r
+       if(g_interface.listen_llcp_socket != NULL)\r
+       {\r
+               return g_interface.listen_llcp_socket(handle, service_access_name, socket, result, user_param);\r
+       }\r
+       else\r
+       {\r
+               *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;\r
+               DEBUG_SERVER_MSG("interface is null");\r
+               return false;\r
+       }\r
+}\r
+bool net_nfc_controller_llcp_accept(net_nfc_llcp_socket_t socket, net_nfc_error_e* result)\r
+{\r
+       if(g_interface.accept_llcp_socket != NULL)\r
+       {\r
+               return g_interface.accept_llcp_socket(socket, result);\r
+       }\r
+       else\r
+       {\r
+               *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;\r
+               DEBUG_SERVER_MSG("interface is null");\r
+               return false;\r
+       }\r
+}\r
+\r
+bool net_nfc_controller_llcp_reject(net_nfc_target_handle_s* handle, net_nfc_llcp_socket_t socket, net_nfc_error_e* result)\r
+{\r
+       if (g_interface.reject_llcp != NULL){\r
+               return g_interface.reject_llcp (handle, socket, result);\r
+       }\r
+       else {\r
+               *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;\r
+               DEBUG_SERVER_MSG("interface is null");\r
+               return false;\r
+       }\r
+}\r
+\r
+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)\r
+{\r
+       if(g_interface.connect_llcp_by_url != NULL)\r
+       {\r
+               return g_interface.connect_llcp_by_url(handle, socket, service_access_name, result, user_param);\r
+       }\r
+       else\r
+       {\r
+               *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;\r
+               DEBUG_SERVER_MSG("interface is null");\r
+               return false;\r
+       }\r
+}\r
+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)\r
+{\r
+       if(g_interface.connect_llcp != NULL)\r
+       {\r
+               return g_interface.connect_llcp(handle, socket, service_access_point, result, user_param);\r
+       }\r
+       else\r
+       {\r
+               *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;\r
+               DEBUG_SERVER_MSG("interface is null");\r
+               return false;\r
+       }\r
+}\r
+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)\r
+{\r
+       if(g_interface.disconnect_llcp != NULL)\r
+       {\r
+               return g_interface.disconnect_llcp(handle, socket, result ,user_param);\r
+       }\r
+       else\r
+       {\r
+               *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;\r
+               DEBUG_SERVER_MSG("interface is null");\r
+               return false;\r
+       }\r
+}\r
+bool net_nfc_controller_llcp_socket_close(net_nfc_llcp_socket_t socket, net_nfc_error_e* result)\r
+{\r
+       if(g_interface.close_llcp_socket != NULL)\r
+       {\r
+               return g_interface.close_llcp_socket(socket, result);\r
+       }\r
+       else\r
+       {\r
+               *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;\r
+               DEBUG_SERVER_MSG("interface is null");\r
+               return false;\r
+       }\r
+}\r
+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)\r
+{\r
+       if(g_interface.recv_llcp != NULL)\r
+       {\r
+               return g_interface.recv_llcp(handle, socket, data, result, user_param);\r
+       }\r
+       else\r
+       {\r
+               *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;\r
+               DEBUG_SERVER_MSG("interface is null");\r
+               return false;\r
+       }\r
+}\r
+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)\r
+{\r
+       if(g_interface.send_llcp != NULL)\r
+       {\r
+               return g_interface.send_llcp(handle, socket, data, result, user_param);\r
+       }\r
+       else\r
+       {\r
+               *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;\r
+               DEBUG_SERVER_MSG("interface is null");\r
+               return false;\r
+       }\r
+}\r
+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)\r
+{\r
+       if(g_interface.recv_from_llcp != NULL)\r
+       {\r
+               return g_interface.recv_from_llcp(handle, socket, data, result, user_param);\r
+       }\r
+       else\r
+       {\r
+               *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;\r
+               DEBUG_SERVER_MSG("interface is null");\r
+               return false;\r
+       }\r
+}\r
+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)\r
+{\r
+       if(g_interface.send_to_llcp != NULL)\r
+       {\r
+               return g_interface.send_to_llcp(handle, socket, data, service_access_point, result, user_param);\r
+       }\r
+       else\r
+       {\r
+               *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;\r
+               DEBUG_SERVER_MSG("interface is null");\r
+               return false;\r
+       }\r
+}\r
+\r
+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)\r
+{\r
+       if(g_interface.get_remote_config != NULL)\r
+       {\r
+               return g_interface.get_remote_config (handle, config, result);\r
+       }\r
+       else\r
+       {\r
+               *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;\r
+               DEBUG_SERVER_MSG("interface is null");\r
+               return false;\r
+       }\r
+}\r
+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)\r
+{\r
+       if(g_interface.get_remote_socket_info!= NULL)\r
+       {\r
+               return g_interface.get_remote_socket_info (handle, socket,option, result);\r
+       }\r
+       else\r
+       {\r
+               *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;\r
+               DEBUG_SERVER_MSG("interface is null");\r
+               return false;\r
+       }\r
+\r
+}\r
+\r
+bool net_nfc_controller_sim_test(net_nfc_error_e* result)\r
+{\r
+       if(g_interface.sim_test!= NULL)\r
+       {\r
+               return g_interface.sim_test(result);\r
+       }\r
+       else\r
+       {\r
+               *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;\r
+               DEBUG_SERVER_MSG("interface is null");\r
+               return false;\r
+       }\r
+}\r
+\r
+bool net_nfc_controller_test_mode_on(net_nfc_error_e* result)\r
+{\r
+       if(g_interface.test_mode_on!= NULL)\r
+       {\r
+               return g_interface.test_mode_on(result);\r
+       }\r
+       else\r
+       {\r
+               *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;\r
+               DEBUG_SERVER_MSG("interface is null");\r
+               return false;\r
+       }\r
+}\r
+\r
+bool net_nfc_controller_test_mode_off(net_nfc_error_e* result)\r
+{\r
+       if(g_interface.test_mode_off != NULL)\r
+       {\r
+               return g_interface.test_mode_off(result);\r
+       }\r
+       else\r
+       {\r
+               *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;\r
+               DEBUG_SERVER_MSG("interface is null");\r
+               return false;\r
+       }\r
+}\r
+\r
diff --git a/src/manager/net_nfc_dbus_service_obj.c b/src/manager/net_nfc_dbus_service_obj.c
new file mode 100644 (file)
index 0000000..450a271
--- /dev/null
@@ -0,0 +1,95 @@
+/*
+  * Copyright 2012  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://www.tizenopensource.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 <stdlib.h>
+#include <glib-object.h>
+#include <dbus/dbus-glib-bindings.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <pthread.h>
+
+#include "net_nfc_typedef_private.h"
+#include "net_nfc_debug_private.h"
+#include "net_nfc_controller_private.h"
+#include "net_nfc_server_dispatcher_private.h"
+#include "net_nfc_manager_util_private.h"
+#include "net_nfc_dbus_service_obj_private.h"
+#include "dbus_service_glue_private.h"
+
+G_DEFINE_TYPE(Dbus_Service, dbus_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 dbus_service_error_quark(void)
+{
+       return g_quark_from_static_string("dbus_service_error");
+}
+
+static void dbus_service_init(Dbus_Service *dbus_service)
+{
+}
+
+static void dbus_service_class_init(Dbus_ServiceClass *dbus_service_class)
+{
+       dbus_g_object_type_install_info(DBUS_SERVICE_TYPE, &dbus_glib_dbus_service_object_info);
+}
+
+gboolean dbus_service_launch(Dbus_Service *dbus_service, guint *result_val, GError **error)
+{
+       return TRUE;
+}
+
+gboolean dbus_service_se_only(Dbus_Service *dbus_service, guint *result_val, GError **error)
+{
+       net_nfc_request_terminate_t *term = NULL;
+
+       DEBUG_SERVER_MSG("dbus_service_se_only is called ..\n");
+
+       *result_val = NET_NFC_OK;
+
+       _net_nfc_manager_util_alloc_mem(term, sizeof(net_nfc_request_terminate_t));
+       if (term != NULL)
+       {
+               term->length = sizeof(net_nfc_request_terminate_t);
+               term->request_type = NET_NFC_MESSAGE_SERVICE_TERMINATION;
+               term->handle = NULL;
+               term->object = dbus_service;
+
+               net_nfc_dispatcher_queue_push((net_nfc_request_msg_t *)term);
+       }
+
+       return TRUE;
+}
+
+gboolean dbus_service_terminate(Dbus_Service *dbus_service, guint *result_val, GError **error)
+{
+       net_nfc_controller_deinit();
+
+       DEBUG_SERVER_MSG("service terminated");
+
+       exit(0);
+
+       return TRUE;
+}
diff --git a/src/manager/net_nfc_manager.c b/src/manager/net_nfc_manager.c
new file mode 100644 (file)
index 0000000..5d12c6d
--- /dev/null
@@ -0,0 +1,178 @@
+/*
+  * Copyright 2012  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://www.tizenopensource.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 <glib.h>
+#include <dbus/dbus-glib.h>
+#include <dbus/dbus-glib-bindings.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_dbus_service_obj_private.h"
+#include "net_nfc_controller_private.h"
+#include "net_nfc_util_private.h"
+
+#include "net_nfc_util_defines.h"
+#include "heynoti.h"
+#include "vconf.h"
+
+GMainLoop* loop = NULL;
+
+bool __net_nfc_intialize_dbus_connection ();
+void __net_nfc_discovery_polling_cb(int signo);
+
+int main()
+{
+
+       DEBUG_SERVER_MSG("start nfc manager");
+
+       net_nfc_app_util_clean_storage(MESSAGE_STORAGE);
+
+       if(!g_thread_supported())
+       {
+               g_thread_init(NULL);
+       }
+
+       dbus_g_thread_init();
+
+       g_type_init();
+
+       void* handle = NULL;
+
+       handle = net_nfc_controller_onload();
+
+       if(handle == NULL)
+       {
+               DEBUG_SERVER_MSG("load plugin library is failed");
+               return 0;
+       }
+
+       if(net_nfc_server_ipc_initialize() != true)
+       {
+               DEBUG_ERR_MSG("nfc server ipc initialization is failed \n");
+               return 0;
+       }
+
+
+       DEBUG_SERVER_MSG("nfc server ipc init is ok \n");
+
+
+       if (__net_nfc_intialize_dbus_connection ())
+       {
+               DEBUG_SERVER_MSG("Registering DBUS is OK! \n");
+       }
+       else
+       {
+               DEBUG_SERVER_MSG("Registering DBUS is FAILED !!!\n");
+       }
+
+       int result = 0;
+       int fd = 0;
+
+       fd = heynoti_init();
+       DEBUG_MSG("Noti init: %d\n", 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\n", result);
+
+       if (result == -1)
+               return 0;
+
+       result = heynoti_attach_handler(fd);
+       DEBUG_MSG("attach handler : %d\n", result);
+
+       if (result == -1)
+               return 0;
+
+       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;
+}
+
+void __net_nfc_discovery_polling_cb(int signo)
+{
+       int status;
+       net_nfc_error_e result;
+
+       DEBUG_MSG("__net_nfc_discovery_polling_cb[Enter]");
+
+       if(net_nfc_controller_confiure_discovery(NET_NFC_DISCOVERY_MODE_CONFIG, NET_NFC_ALL_ENABLE, &result) == true)
+       {
+               DEBUG_SERVER_MSG("someone wake-up the nfc-manager daemon. and it succeeds to restart the polling. ");
+       }
+       else
+       {
+               if (vconf_set_int(NET_NFC_VCONF_KEY_PROGRESS, result) != 0)
+               {
+                       DEBUG_ERR_MSG("vconf_set_int(NET_NFC_VCONF_KEY_PROGRESS, ERROR) != 0");
+               }
+               exit(result);
+       }
+
+       DEBUG_MSG("__net_nfc_discovery_polling_cb[Out]");
+}
+
+bool __net_nfc_intialize_dbus_connection ()
+{
+
+       GError *error = NULL;
+       DBusGProxy *proxy;
+       GObject *object = NULL;
+       guint32 name;
+       DBusGConnection *connection;
+
+       connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
+       if (connection == NULL) {
+               DEBUG_ERR_MSG ("DBUS: getting dbus connection is failed \n");
+               DEBUG_SERVER_MSG("DBUS: %s", error->message);
+               g_error_free (error);
+               return false;
+       }
+
+       object = g_object_new (DBUS_SERVICE_TYPE, NULL);
+
+       dbus_g_connection_register_g_object (connection, DBUS_SERVICE_PATH, object);
+
+       proxy = dbus_g_proxy_new_for_name (connection, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS);
+
+       /* Make sure getting name is correct version or not */
+       if (!org_freedesktop_DBus_request_name (proxy, DBUS_SERVICE_NAME, 0, &name, &error))
+       {
+               DEBUG_ERR_MSG ("DBUS: getting dbus proxy is failed \n");
+               DEBUG_SERVER_MSG("DBUS: %s", error->message);
+               g_error_free (error);
+               return false;
+       }
+
+       if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != name)
+       {
+               DEBUG_SERVER_MSG ("Requested name is: %d", name);
+       }
+       return true;
+}
+
diff --git a/src/manager/net_nfc_manager_util.c b/src/manager/net_nfc_manager_util.c
new file mode 100644 (file)
index 0000000..10e80aa
--- /dev/null
@@ -0,0 +1,61 @@
+/*\r
+  * Copyright 2012  Samsung Electronics Co., Ltd\r
+  *\r
+  * Licensed under the Flora License, Version 1.0 (the "License");\r
+  * you may not use this file except in compliance with the License.\r
+  * You may obtain a copy of the License at\r
+\r
+  *     http://www.tizenopensource.org/license\r
+  *\r
+  * Unless required by applicable law or agreed to in writing, software\r
+  * distributed under the License is distributed on an "AS IS" BASIS,\r
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+  * See the License for the specific language governing permissions and\r
+  * limitations under the License.\r
+  */\r
+\r
+#include <stdlib.h>\r
+#include <string.h>\r
+\r
+#include "net_nfc_manager_util_private.h"\r
+#include "net_nfc_debug_private.h"\r
+\r
+\r
+void __net_nfc_manager_util_free_mem (void** mem, char * filename, unsigned int line)\r
+{\r
+       if (mem == NULL || *mem == NULL)\r
+       {\r
+               //DEBUG_MSG ("FILE: %s, LINE:%d, Invalid parameter in mem free util (pinter is NULL)\n", filename, line);\r
+               return;\r
+       }\r
+       free(*mem);\r
+       *mem = NULL;\r
+}\r
+\r
+void __net_nfc_manager_util_alloc_mem(void** mem, int size, char * filename, unsigned int line)\r
+{\r
+       if (mem == NULL || size <= 0)\r
+       {\r
+               //DEBUG_MSG ("FILE: %s, LINE:%d, Invalid parameter in mem alloc util\n", filename, line);\r
+               return;\r
+       }\r
+\r
+//     DEBUG_MSG("size to malloc() = [%d]", size);\r
+\r
+       if (*mem != NULL)\r
+       {\r
+//             DEBUG_MSG("FILE: %s, LINE:%d, WARNING: Pointer is already allocated or it was not initialized with NULL\n", filename, line);\r
+       }\r
+\r
+       *mem = malloc (size);\r
+\r
+       if (*mem != NULL)\r
+       {\r
+               memset (*mem, 0x0, size);\r
+       }\r
+       else\r
+       {\r
+//             DEBUG_MSG("FILE: %s, LINE:%d, Allocation is failed\n", filename, line);\r
+       }\r
+}\r
+\r
diff --git a/src/manager/net_nfc_server_dispatcher.c b/src/manager/net_nfc_server_dispatcher.c
new file mode 100644 (file)
index 0000000..9b520f2
--- /dev/null
@@ -0,0 +1,1388 @@
+/*\r
+  * Copyright 2012  Samsung Electronics Co., Ltd\r
+  *\r
+  * Licensed under the Flora License, Version 1.0 (the "License");\r
+  * you may not use this file except in compliance with the License.\r
+  * You may obtain a copy of the License at\r
+\r
+  *     http://www.tizenopensource.org/license\r
+  *\r
+  * Unless required by applicable law or agreed to in writing, software\r
+  * distributed under the License is distributed on an "AS IS" BASIS,\r
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+  * See the License for the specific language governing permissions and\r
+  * limitations under the License.\r
+  */\r
+\r
+#include <stdlib.h>\r
+#include <string.h>\r
+#include <pthread.h>\r
+#include <stdarg.h>\r
+#include <glib.h>\r
+#include "vconf.h"\r
+\r
+#include "net_nfc_server_dispatcher_private.h"\r
+#include "net_nfc_typedef_private.h"\r
+#include "net_nfc_controller_private.h"\r
+#include "net_nfc_server_ipc_private.h"\r
+#include "net_nfc_debug_private.h"\r
+#include "net_nfc_util_private.h"\r
+#include "net_nfc_util_defines.h"\r
+#include "net_nfc_controller_private.h"\r
+#include "net_nfc_service_private.h"\r
+#include "net_nfc_service_llcp_private.h"\r
+#include "net_nfc_service_llcp_handover_private.h"\r
+#include "net_nfc_service_tag_private.h"\r
+#include "net_nfc_dbus_service_obj_private.h"\r
+#include "net_nfc_manager_util_private.h"\r
+#include "net_nfc_service_se_private.h"\r
+\r
+static GQueue *g_dispatcher_queue;\r
+static pthread_cond_t g_dispatcher_queue_cond = PTHREAD_COND_INITIALIZER;\r
+static pthread_mutex_t g_dispatcher_queue_lock = PTHREAD_MUTEX_INITIALIZER;\r
+static pthread_t g_dispatcher_thread;\r
+\r
+extern se_setting_t g_se_setting;\r
+\r
+uint8_t g_se_cur_type = SECURE_ELEMENT_TYPE_INVALD;\r
+uint8_t g_se_cur_mode = SECURE_ELEMENT_OFF_MODE;\r
+static uint8_t g_se_prev_type = SECURE_ELEMENT_TYPE_INVALD;\r
+static uint8_t g_se_prev_mode = SECURE_ELEMENT_OFF_MODE;\r
+\r
+static void *_net_nfc_dispatcher_thread_func(void *data);\r
+static net_nfc_request_msg_t *_net_nfc_dispatcher_queue_pop();\r
+\r
+\r
+static net_nfc_request_msg_t *_net_nfc_dispatcher_queue_pop()\r
+{\r
+       net_nfc_request_msg_t *msg = NULL;\r
+       msg = g_queue_pop_head (g_dispatcher_queue);\r
+       return msg;\r
+}\r
+\r
+void net_nfc_dispatcher_queue_push(net_nfc_request_msg_t *req_msg)\r
+{\r
+       pthread_mutex_lock(&g_dispatcher_queue_lock);\r
+        g_queue_push_tail (g_dispatcher_queue, req_msg);\r
+       pthread_cond_signal(&g_dispatcher_queue_cond);\r
+       pthread_mutex_unlock(&g_dispatcher_queue_lock);\r
+}\r
+\r
+bool net_nfc_dispatcher_start_thread()\r
+{\r
+       net_nfc_request_msg_t *req_msg = NULL;\r
+       pthread_attr_t attr;\r
+\r
+       DEBUG_SERVER_MSG("init queue");\r
+\r
+       g_dispatcher_queue = g_queue_new();\r
+\r
+       pthread_attr_init(&attr);\r
+       pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);\r
+\r
+       _net_nfc_util_alloc_mem(req_msg, sizeof(net_nfc_request_msg_t));\r
+       if (req_msg == NULL)\r
+               return false;\r
+\r
+       req_msg->length = sizeof(net_nfc_request_msg_t);\r
+       req_msg->request_type = NET_NFC_MESSAGE_SERVICE_INIT;\r
+\r
+       net_nfc_dispatcher_queue_push(req_msg);\r
+\r
+       if(pthread_create(&g_dispatcher_thread, &attr, _net_nfc_dispatcher_thread_func, NULL) != 0)\r
+       {\r
+               return false;\r
+       }\r
+       else\r
+       {\r
+               DEBUG_SERVER_MSG("put controller init request");\r
+               return true;\r
+       }\r
+}\r
+\r
+\r
+static void *_net_nfc_dispatcher_thread_func(void *data)\r
+{\r
+       net_nfc_request_msg_t *req_msg = NULL;\r
+\r
+       DEBUG_SERVER_MSG("net_nfc_controller_thread is created ");\r
+\r
+       while(1)\r
+       {\r
+               pthread_mutex_lock(&g_dispatcher_queue_lock);\r
+               if((req_msg = _net_nfc_dispatcher_queue_pop()) == NULL)\r
+               {\r
+                       pthread_cond_wait(&g_dispatcher_queue_cond, &g_dispatcher_queue_lock);\r
+                       pthread_mutex_unlock(&g_dispatcher_queue_lock);\r
+                       continue;\r
+               }\r
+               pthread_mutex_unlock(&g_dispatcher_queue_lock);\r
+\r
+               //DEBUG_SERVER_MSG("net_nfc_controller get command = [%d]", req_msg->request_type);\r
+\r
+               switch(req_msg->request_type)\r
+               {\r
+               case NET_NFC_MESSAGE_SERVICE_CLEANER:\r
+                       {\r
+                               DEBUG_SERVER_MSG("client is terminated abnormally");\r
+\r
+                               if(g_se_prev_type == SECURE_ELEMENT_TYPE_ESE)\r
+                               {\r
+                                       net_nfc_error_e result = NET_NFC_OK;\r
+                                       net_nfc_target_handle_s *ese_handle = g_se_setting.current_ese_handle;\r
+\r
+                                       if(ese_handle != NULL)\r
+                                       {\r
+\r
+                                               DEBUG_SERVER_MSG("ese_handle was not freed and disconnected");\r
+\r
+                                               if(net_nfc_controller_disconnect(ese_handle, &result) == false)\r
+                                               {\r
+                                                       net_nfc_controller_exception_handler();\r
+                                               }\r
+#ifdef BROADCAST_MESSAGE\r
+                                               net_nfc_server_set_server_state(        NET_NFC_SERVER_IDLE);\r
+#endif\r
+                                               g_se_setting.current_ese_handle = NULL;\r
+                                       }\r
+\r
+                                       if((g_se_prev_type != g_se_cur_type) || (g_se_prev_mode != g_se_cur_mode))\r
+                                       {\r
+                                               net_nfc_controller_set_secure_element_mode(g_se_prev_type , g_se_prev_mode, &result);\r
+\r
+                                               g_se_cur_type = g_se_prev_type;\r
+                                               g_se_cur_mode = g_se_prev_mode;\r
+                                       }\r
+                               }\r
+                               else if(g_se_prev_type == SECURE_ELEMENT_TYPE_UICC)\r
+                               {\r
+                                       net_nfc_service_tapi_deinit();\r
+                               }\r
+                               else\r
+                               {\r
+                                       DEBUG_SERVER_MSG("SE type is not valid");\r
+                               }\r
+                       }\r
+                       break;\r
+\r
+               case NET_NFC_MESSAGE_SEND_APDU_SE:\r
+                       {\r
+                               net_nfc_request_send_apdu_t *detail = (net_nfc_request_send_apdu_t *)req_msg;\r
+\r
+                               if (detail->handle == (net_nfc_target_handle_s *)UICC_TARGET_HANDLE)\r
+                               {\r
+                                       data_s apdu_data = {NULL, 0};\r
+\r
+                                       if (net_nfc_util_duplicate_data(&apdu_data, &detail->data) == false)\r
+                                               break;\r
+\r
+                                       net_nfc_service_transfer_apdu(&apdu_data, detail->trans_param);\r
+\r
+                                       net_nfc_util_free_data(&apdu_data);\r
+                               }\r
+                               else if (detail->handle == g_se_setting.current_ese_handle)\r
+                               {\r
+                                       data_s *data = NULL;\r
+                                       net_nfc_error_e result = NET_NFC_OK;\r
+                                       net_nfc_transceive_info_s info;\r
+                                       bool success = true;\r
+\r
+                                       info.dev_type = NET_NFC_ISO14443_A_PICC;\r
+                                       if (net_nfc_util_duplicate_data(&info.trans_data, &detail->data) == false)\r
+                                               break;\r
+\r
+                                       if ((success = net_nfc_controller_transceive(detail->handle, &info, &data, &result)) == true)\r
+                                       {\r
+                                               if (data != NULL)\r
+                                               {\r
+                                                       DEBUG_SERVER_MSG("trasceive data recieved [%d], Success = %d", data->length, success);\r
+                                               }\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               DEBUG_SERVER_MSG("trasceive is failed = [%d]", result);\r
+                                       }\r
+                                       net_nfc_util_free_data(&info.trans_data);\r
+\r
+                                       net_nfc_response_send_apdu_t resp = { 0 };\r
+\r
+                                       resp.result = result;\r
+                                       resp.trans_param = detail->trans_param;\r
+\r
+                                       if (success && data != NULL)\r
+                                       {\r
+                                               resp.data.length = data->length;\r
+\r
+                                               DEBUG_MSG("send response send apdu msg");\r
+                                               _net_nfc_send_response_msg(req_msg->request_type, (void *)&resp, sizeof(net_nfc_response_send_apdu_t),\r
+                                                       data->buffer, data->length, NULL);\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               DEBUG_MSG("send response send apdu msg");\r
+                                               _net_nfc_send_response_msg(req_msg->request_type, (void *)&resp, sizeof(net_nfc_response_send_apdu_t), NULL);\r
+                                       }\r
+                               }\r
+                               else\r
+                               {\r
+                                       DEBUG_SERVER_MSG("invalid se handle");\r
+\r
+                                       net_nfc_response_send_apdu_t resp = { 0 };\r
+                                       resp.result = NET_NFC_INVALID_PARAM;\r
+                                       resp.trans_param = detail->trans_param;\r
+\r
+                                       _net_nfc_send_response_msg(req_msg->request_type, (void *)&resp, sizeof(net_nfc_response_send_apdu_t), NULL);\r
+                               }\r
+\r
+                       }\r
+                       break;\r
+\r
+               case NET_NFC_MESSAGE_CLOSE_INTERNAL_SE:\r
+                       {\r
+                               net_nfc_request_close_internal_se_t *detail = (net_nfc_request_close_internal_se_t *)req_msg;\r
+                               net_nfc_response_close_internal_se_t resp = { 0 };\r
+\r
+                               resp.trans_param = detail->trans_param;\r
+                               resp.result = NET_NFC_OK;\r
+\r
+                               if (detail->handle == (net_nfc_target_handle_s *)UICC_TARGET_HANDLE)\r
+                               {\r
+                                       /*deinit TAPI*/\r
+                                       DEBUG_SERVER_MSG("UICC is current secure element");\r
+                                       net_nfc_service_tapi_deinit();\r
+\r
+                               }\r
+                               else if (detail->handle == g_se_setting.current_ese_handle)\r
+                               {\r
+\r
+                                       if (net_nfc_controller_disconnect(detail->handle, &(resp.result)) == false)\r
+                                       {\r
+                                               net_nfc_controller_exception_handler();\r
+                                       }\r
+\r
+#ifdef BROADCAST_MESSAGE\r
+                                       net_nfc_server_set_server_state(NET_NFC_SERVER_IDLE);\r
+#endif\r
+                                       g_se_setting.current_ese_handle = NULL;\r
+                               }\r
+                               else\r
+                               {\r
+                                       DEBUG_SERVER_MSG("invalid se handle received handle = [0x%x] and current handle = [0x%x]", detail->handle, g_se_setting.current_ese_handle);\r
+                               }\r
+\r
+                               if ((g_se_prev_type != g_se_cur_type) || (g_se_prev_mode != g_se_cur_mode))\r
+                               {\r
+                                       /*return back se mode*/\r
+                                       net_nfc_controller_set_secure_element_mode(g_se_prev_type, g_se_prev_mode, &(resp.result));\r
+\r
+                                       g_se_cur_type = g_se_prev_type;\r
+                                       g_se_cur_mode = g_se_prev_mode;\r
+                               }\r
+\r
+                               _net_nfc_send_response_msg(req_msg->request_type, (void *)&resp, sizeof(net_nfc_response_close_internal_se_t), NULL);\r
+                       }\r
+                       break;\r
+\r
+               case NET_NFC_MESSAGE_OPEN_INTERNAL_SE:\r
+                       {\r
+                               net_nfc_error_e result = NET_NFC_OK;\r
+                               net_nfc_request_open_internal_se_t *detail = (net_nfc_request_open_internal_se_t *)req_msg;\r
+\r
+                               g_se_prev_type = g_se_cur_type;\r
+                               g_se_prev_mode = g_se_cur_mode;\r
+\r
+                               if (detail->se_type == SECURE_ELEMENT_TYPE_UICC)\r
+                               {\r
+                                       /*off ESE*/\r
+                                       net_nfc_controller_set_secure_element_mode(SECURE_ELEMENT_TYPE_ESE, SECURE_ELEMENT_OFF_MODE, &result);\r
+\r
+                                       /*Off UICC. UICC SHOULD not be detected by external reader when being communicated in internal process*/\r
+                                       net_nfc_controller_set_secure_element_mode(SECURE_ELEMENT_TYPE_UICC, SECURE_ELEMENT_OFF_MODE, &result);\r
+\r
+                                       g_se_cur_type = SECURE_ELEMENT_TYPE_UICC;\r
+                                       g_se_cur_mode = SECURE_ELEMENT_OFF_MODE;\r
+\r
+                                       net_nfc_response_open_internal_se_t resp = { 0 };\r
+\r
+                                       /*Init tapi api and return back response*/\r
+                                       if (net_nfc_service_tapi_init() != true)\r
+                                       {\r
+                                               net_nfc_service_tapi_deinit();\r
+                                               resp.result = NET_NFC_INVALID_STATE;\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               resp.result = NET_NFC_OK;\r
+                                       }\r
+\r
+                                       resp.handle = (net_nfc_target_handle_s *)UICC_TARGET_HANDLE;\r
+                                       resp.trans_param = detail->trans_param;\r
+                                       resp.se_type = SECURE_ELEMENT_TYPE_UICC;\r
+\r
+                                       _net_nfc_send_response_msg(req_msg->request_type, (void *)&resp, sizeof(net_nfc_response_set_se_t), NULL);\r
+                               }\r
+                               else\r
+                               {\r
+                                       /*Connect NFC-WI to ESE*/\r
+                                       net_nfc_controller_set_secure_element_mode(SECURE_ELEMENT_TYPE_ESE, SECURE_ELEMENT_WIRED_MODE, &result);\r
+\r
+                                       /*off UICC*/\r
+                                       net_nfc_controller_set_secure_element_mode(SECURE_ELEMENT_TYPE_UICC, SECURE_ELEMENT_OFF_MODE, &result);\r
+\r
+                                       g_se_cur_type = SECURE_ELEMENT_TYPE_ESE;\r
+                                       g_se_cur_mode = SECURE_ELEMENT_WIRED_MODE;\r
+                                       g_se_setting.open_request_trans_param = detail->trans_param;\r
+\r
+                                       if (result != NET_NFC_OK)\r
+                                       {\r
+                                               net_nfc_response_open_internal_se_t resp = { 0 };\r
+                                               resp.result = result;\r
+                                               _net_nfc_send_response_msg(req_msg->request_type, (void *)&resp, sizeof(net_nfc_response_set_se_t), NULL);\r
+                                       }\r
+                               }\r
+                       }\r
+                       break;\r
+\r
+               case NET_NFC_MESSAGE_SET_SE:\r
+                       {\r
+                               net_nfc_request_set_se_t *detail = (net_nfc_request_set_se_t *)req_msg;\r
+                               net_nfc_response_set_se_t resp = { 0 };\r
+\r
+                               resp.trans_param = detail->trans_param;\r
+                               resp.se_type = detail->se_type;\r
+\r
+                               if (detail->se_type == SECURE_ELEMENT_TYPE_UICC)\r
+                               {\r
+                                       g_se_cur_type = SECURE_ELEMENT_TYPE_UICC;\r
+                                       g_se_cur_mode = SECURE_ELEMENT_VIRTUAL_MODE;\r
+\r
+                                       /*turn on UICC*/\r
+                                       net_nfc_controller_set_secure_element_mode(SECURE_ELEMENT_TYPE_UICC, SECURE_ELEMENT_VIRTUAL_MODE, &(resp.result));\r
+\r
+                                       /*turn off ESE*/\r
+                                       net_nfc_controller_set_secure_element_mode(SECURE_ELEMENT_TYPE_ESE, SECURE_ELEMENT_OFF_MODE, &(resp.result));\r
+\r
+                               }\r
+                               else if (detail->se_type == SECURE_ELEMENT_TYPE_ESE)\r
+                               {\r
+                                       g_se_cur_type = SECURE_ELEMENT_TYPE_ESE;\r
+                                       g_se_cur_mode = SECURE_ELEMENT_VIRTUAL_MODE;\r
+\r
+                                       /*Turn on UICC*/\r
+                                       net_nfc_controller_set_secure_element_mode(SECURE_ELEMENT_TYPE_UICC, SECURE_ELEMENT_OFF_MODE, &(resp.result));\r
+\r
+                                       /*turn off ESE*/\r
+                                       net_nfc_controller_set_secure_element_mode(SECURE_ELEMENT_TYPE_ESE, SECURE_ELEMENT_VIRTUAL_MODE, &(resp.result));\r
+\r
+                               }\r
+                               else\r
+                               {\r
+                                       g_se_cur_type = SECURE_ELEMENT_TYPE_INVALD;\r
+                                       g_se_cur_mode = SECURE_ELEMENT_OFF_MODE;\r
+\r
+                                       /*turn on UICC*/\r
+                                       net_nfc_controller_set_secure_element_mode(SECURE_ELEMENT_TYPE_UICC, SECURE_ELEMENT_OFF_MODE, &(resp.result));\r
+\r
+                                       /*turn off ESE*/\r
+                                       net_nfc_controller_set_secure_element_mode(SECURE_ELEMENT_TYPE_ESE, SECURE_ELEMENT_OFF_MODE, &(resp.result));\r
+\r
+                               }\r
+\r
+                               _net_nfc_send_response_msg(req_msg->request_type, (void *)&resp, sizeof(net_nfc_response_set_se_t), NULL);\r
+                       }\r
+                       break;\r
+\r
+               case NET_NFC_MESSAGE_GET_SE:\r
+                       {\r
+                               net_nfc_request_get_se_t *detail = (net_nfc_request_get_se_t *)req_msg;\r
+                               net_nfc_response_get_se_t resp = { 0 };\r
+\r
+                               resp.result = NET_NFC_OK;\r
+                               resp.trans_param = detail->trans_param;\r
+                               resp.se_type = g_se_cur_type;\r
+\r
+                               _net_nfc_send_response_msg(req_msg->request_type, (void *)&resp, sizeof(net_nfc_response_get_se_t), NULL);\r
+                       }\r
+                       break;\r
+\r
+               case NET_NFC_MESSAGE_P2P_SEND :\r
+                       {\r
+                               net_nfc_request_p2p_send_t *exchanger = (net_nfc_request_p2p_send_t *)req_msg;\r
+\r
+                               if (exchanger != NULL)\r
+                               {\r
+                                       if (net_nfc_service_send_exchanger_msg(exchanger) != NET_NFC_OK)\r
+                                       {\r
+                                               DEBUG_SERVER_MSG("net_nfc_service_send_exchanger_msg is failed");\r
+\r
+                                               /*send result to client*/\r
+                                               int client_context = 0;\r
+                                               if (net_nfc_server_get_current_client_context(&client_context) == true)\r
+                                               {\r
+                                                       if (net_nfc_server_check_client_is_running(&client_context) == true)\r
+                                                       {\r
+                                                               int client_type = 0;\r
+                                                               if (net_nfc_server_get_client_type(client_context, &client_type) == true)\r
+                                                               {\r
+                                                                       net_nfc_response_p2p_send_t resp_msg = { 0, };\r
+                                                                       resp_msg.result = NET_NFC_P2P_SEND_FAIL;\r
+\r
+                                                                       if (_net_nfc_send_response_msg(NET_NFC_MESSAGE_P2P_SEND, &resp_msg, sizeof(net_nfc_response_p2p_send_t), NULL) == true)\r
+                                                                       {\r
+                                                                               DEBUG_SERVER_MSG("send exchange failed message to client");\r
+                                                                       }\r
+                                                               }\r
+                                                       }\r
+                                               }\r
+                                       }\r
+                               }\r
+                       }\r
+                       break;\r
+\r
+               case NET_NFC_MESSAGE_TRANSCEIVE :\r
+                       {\r
+                               net_nfc_transceive_info_s info;\r
+                               net_nfc_request_transceive_t *trans = (net_nfc_request_transceive_t *)req_msg;\r
+                               data_s *data = NULL;\r
+                               bool success;\r
+\r
+                               if (net_nfc_util_duplicate_data(&info.trans_data, &trans->info.trans_data) == true)\r
+                               {\r
+                                       net_nfc_response_transceive_t resp = { 0, };\r
+\r
+                                       info.dev_type = trans->info.dev_type;\r
+\r
+                                       resp.result = NET_NFC_OK;\r
+                                       resp.trans_param = trans->trans_param;\r
+\r
+                                       DEBUG_MSG("call transceive");\r
+                                       if ((success = net_nfc_controller_transceive(trans->handle, &info, &data, &(resp.result))) == true)\r
+                                       {\r
+                                               if (data != NULL)\r
+                                                       DEBUG_SERVER_MSG("trasceive data recieved [%d], Success = %d", data->length, success);\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               DEBUG_SERVER_MSG("trasceive is failed = [%d]", resp.result);\r
+                                       }\r
+\r
+                                       if (_net_nfc_check_client_handle())\r
+                                       {\r
+                                               if (success && data != NULL)\r
+                                               {\r
+                                                       resp.data.length = data->length;\r
+\r
+                                                       DEBUG_MSG("send response trans msg");\r
+                                                       _net_nfc_send_response_msg(req_msg->request_type, (void *)&resp, sizeof(net_nfc_response_transceive_t),\r
+                                                               data->buffer, data->length, NULL);\r
+                                               }\r
+                                               else\r
+                                               {\r
+                                                       DEBUG_MSG("send response trans msg");\r
+                                                       _net_nfc_send_response_msg(req_msg->request_type, (void *)&resp, sizeof(net_nfc_response_transceive_t), NULL);\r
+                                               }\r
+                                       }\r
+\r
+                                       net_nfc_util_free_data(&info.trans_data);\r
+                               }\r
+                       }\r
+                       break;\r
+\r
+               case NET_NFC_MESSAGE_MAKE_READ_ONLY_NDEF:\r
+                       {\r
+                               net_nfc_response_make_read_only_ndef_t resp = { 0, };\r
+                               net_nfc_request_make_read_only_ndef_t *make_readOnly = (net_nfc_request_make_read_only_ndef_t *)req_msg;\r
+\r
+                               resp.result = NET_NFC_OK;\r
+                               resp.trans_param = make_readOnly->trans_param;\r
+\r
+                               net_nfc_controller_make_read_only_ndef(make_readOnly->handle, &(resp.result));\r
+\r
+                               if (_net_nfc_check_client_handle())\r
+                               {\r
+                                       _net_nfc_send_response_msg(req_msg->request_type, (void *)&resp, sizeof(net_nfc_response_write_ndef_t), NULL);\r
+                               }\r
+                       }\r
+                       break;\r
+\r
+               case NET_NFC_MESSAGE_IS_TAG_CONNECTED:\r
+                       {\r
+                               net_nfc_response_is_tag_connected_t resp = { 0, };\r
+                               net_nfc_request_is_tag_connected_t *detail = (net_nfc_request_is_tag_connected_t *)req_msg;\r
+                               net_nfc_current_target_info_s* target_info = NULL;\r
+\r
+                               target_info = net_nfc_server_get_tag_info();\r
+\r
+                               if(target_info != NULL)\r
+                               {\r
+                                       resp.result = NET_NFC_OK;\r
+                                       resp.devType = target_info->devType;\r
+                               }\r
+                               else\r
+                               {\r
+                                       resp.result = NET_NFC_NOT_CONNECTED;\r
+                                       resp.devType = NET_NFC_UNKNOWN_TARGET;\r
+                               }\r
+\r
+                               resp.trans_param = detail->trans_param;\r
+\r
+                               _net_nfc_send_response_msg(req_msg->request_type, (void *)&resp, sizeof(net_nfc_response_is_tag_connected_t), NULL);\r
+                       }\r
+                       break;
+\r
+               case NET_NFC_MESSAGE_GET_CURRENT_TAG_INFO:\r
+                       {\r
+                               net_nfc_response_get_current_tag_info_t resp = { 0, };\r
+                               net_nfc_request_get_current_tag_info_t *detail = (net_nfc_request_get_current_tag_info_t *)req_msg;\r
+                               net_nfc_current_target_info_s *target_info = NULL;\r
+                               net_nfc_error_e result = NET_NFC_OK;\r
+\r
+                               resp.trans_param = detail->trans_param;\r
+\r
+                               target_info = net_nfc_server_get_tag_info();\r
+\r
+                               if(target_info != NULL)\r
+                               {\r
+                                       bool success = true;\r
+                                       data_s* recv_data = NULL;\r
+\r
+                                       memset(&resp, 0x00, sizeof(net_nfc_response_get_current_tag_info_t));\r
+\r
+                                       if(target_info->devType != NET_NFC_NFCIP1_TARGET  && target_info->devType != NET_NFC_NFCIP1_INITIATOR)\r
+                                       {\r
+#ifdef BROADCAST_MESSAGE\r
+                                               net_nfc_server_set_server_state(        NET_NFC_TAG_CONNECTED);\r
+#endif\r
+                                               DEBUG_SERVER_MSG("tag is connected");\r
+\r
+                                               uint8_t ndef_card_state = 0;\r
+                                               int max_data_size = 0;\r
+                                               int real_data_size = 0;\r
+\r
+                                               if(net_nfc_controller_check_ndef(target_info->handle, &ndef_card_state, &max_data_size, &real_data_size, &result) == true)\r
+                                               {\r
+                                                       resp.ndefCardState = ndef_card_state;\r
+                                                       resp.maxDataSize = max_data_size;\r
+                                                       resp.actualDataSize = real_data_size;\r
+                                                       resp.is_ndef_supported = 1;\r
+                                               }\r
+                                               else\r
+                                               {\r
+                                                       resp.is_ndef_supported = 0;\r
+                                                       resp.ndefCardState = 0;\r
+                                                       resp.maxDataSize = 0;\r
+                                                       resp.actualDataSize = 0;\r
+                                               }\r
+\r
+                                               resp.devType = target_info->devType;\r
+                                               resp.handle = target_info->handle;\r
+                                               resp.number_of_keys = target_info->number_of_keys;\r
+\r
+                                               net_nfc_util_duplicate_data(&resp.target_info_values, &target_info->target_info_values);\r
+\r
+                                               if(resp.is_ndef_supported)\r
+                                               {\r
+                                                       if(net_nfc_controller_read_ndef (target_info->handle, &recv_data, &(resp.result)) == true) {\r
+                                                               DEBUG_SERVER_MSG("net_nfc_controller_read_ndef is success");\r
+\r
+                                                               resp.raw_data.length = recv_data->length;\r
+\r
+                                                               success = _net_nfc_send_response_msg (req_msg->request_type, (void *)&resp,  sizeof (net_nfc_response_get_current_tag_info_t),\r
+                                                                       (void *)(resp.target_info_values.buffer), resp.target_info_values.length,\r
+                                                                       (void *)(recv_data->buffer), recv_data->length, NULL);\r
+                                                       }\r
+                                                       else {\r
+                                                               DEBUG_SERVER_MSG("net_nfc_controller_read_ndef is fail");\r
+\r
+                                                               resp.raw_data.length = 0;\r
+\r
+                                                               success = _net_nfc_send_response_msg (req_msg->request_type, (void *)&resp,  sizeof (net_nfc_response_get_current_tag_info_t),\r
+                                                                       (void *)(resp.target_info_values.buffer), resp.target_info_values.length, NULL);\r
+                                                       }\r
+                                               }\r
+                                               else\r
+                                               {\r
+                                                       resp.raw_data.length = 0;\r
+\r
+                                                       success = _net_nfc_send_response_msg (req_msg->request_type, (void *)&resp,  sizeof (net_nfc_response_get_current_tag_info_t),\r
+                                                               (void *)(resp.target_info_values.buffer), resp.target_info_values.length, NULL);\r
+                                               }\r
+\r
+                                               net_nfc_util_free_data(&resp.target_info_values);\r
+\r
+                                       }\r
+                               }\r
+                               else\r
+                               {\r
+                                       resp.result = NET_NFC_NOT_CONNECTED;\r
+                                       _net_nfc_send_response_msg(req_msg->request_type, (void *)&resp, sizeof(net_nfc_response_get_current_tag_info_t), NULL);\r
+\r
+\r
+                               }\r
+                       }\r
+                       break;\r
+\r
+               case NET_NFC_MESSAGE_GET_CURRENT_TARGET_HANDLE:\r
+                       {\r
+                               net_nfc_response_get_current_target_handle_t resp = { 0, };\r
+                               net_nfc_request_get_current_target_handle_t *detail = (net_nfc_request_get_current_target_handle_t *)req_msg;\r
+                               net_nfc_current_target_info_s *target_info = NULL;\r
+                               net_nfc_error_e result = NET_NFC_OK;\r
+\r
+                               resp.trans_param = detail->trans_param;\r
+\r
+                               target_info = net_nfc_server_get_tag_info();\r
+\r
+                               if(target_info != NULL)\r
+                               {\r
+                                       resp.handle = target_info->handle;\r
+                                       resp.devType = target_info->devType;\r
+                                       resp.result = NET_NFC_OK;\r
+\r
+                               }\r
+                               else\r
+                               {\r
+                                       resp.result = NET_NFC_NOT_CONNECTED;\r
+                               }\r
+\r
+                               _net_nfc_send_response_msg(req_msg->request_type, (void *)&resp, sizeof(net_nfc_response_get_current_target_handle_t), NULL);\r
+\r
+                       }\r
+                       break;\r
+\r
+               case NET_NFC_GET_SERVER_STATE:\r
+                       {\r
+                               net_nfc_response_get_server_state_t resp = { 0, };\r
+\r
+                               resp.state = net_nfc_get_server_state();\r
+                               resp.result = NET_NFC_OK;\r
+\r
+                               _net_nfc_send_response_msg(req_msg->request_type, (void *)&resp, sizeof(net_nfc_response_get_server_state_t), NULL);\r
+                       }\r
+                       break;\r
+\r
+               case NET_NFC_MESSAGE_READ_NDEF:\r
+                       {\r
+                               net_nfc_response_read_ndef_t resp = { 0, };\r
+                               net_nfc_request_read_ndef_t *read = (net_nfc_request_read_ndef_t*)req_msg;\r
+                               data_s *data = NULL;\r
+                               bool success;\r
+\r
+                               resp.trans_param = read->trans_param;\r
+                               resp.result = NET_NFC_OK;\r
+\r
+                               success = net_nfc_controller_read_ndef(read->handle, &data, &(resp.result));\r
+\r
+                               if (_net_nfc_check_client_handle())\r
+                               {\r
+                                       if (success)\r
+                                       {\r
+                                               resp.data.length = data->length;\r
+                                               _net_nfc_send_response_msg(req_msg->request_type, (void *)&resp, sizeof(net_nfc_response_read_ndef_t),\r
+                                                       data->buffer, data->length, NULL);\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               resp.data.length = 0;\r
+                                               resp.data.buffer = NULL;\r
+                                               _net_nfc_send_response_msg(req_msg->request_type, (void *)&resp, sizeof(net_nfc_response_read_ndef_t), NULL);\r
+                                       }\r
+                               }\r
+                       }\r
+                       break;\r
+\r
+               case NET_NFC_MESSAGE_WRITE_NDEF:\r
+                       {\r
+                               net_nfc_request_write_ndef_t *write_ndef = (net_nfc_request_write_ndef_t *)req_msg;\r
+                               data_s data = { NULL, 0 };\r
+\r
+                               if (net_nfc_util_duplicate_data(&data, &write_ndef->data) == true)\r
+                               {\r
+                                       net_nfc_response_write_ndef_t resp = { 0, };\r
+\r
+                                       resp.result = NET_NFC_OK;\r
+                                       resp.trans_param = write_ndef->trans_param;\r
+\r
+                                       net_nfc_controller_write_ndef(write_ndef->handle, &data, &(resp.result));\r
+                                       if (_net_nfc_check_client_handle())\r
+                                       {\r
+                                               _net_nfc_send_response_msg(req_msg->request_type, (void *)&resp, sizeof(net_nfc_response_write_ndef_t), NULL);\r
+                                       }\r
+\r
+                                       net_nfc_util_free_data(&data);\r
+                               }\r
+                       }\r
+                       break;\r
+\r
+               case NET_NFC_MESSAGE_SIM_TEST:\r
+                       {\r
+                               net_nfc_response_test_t resp = { 0, };\r
+                               net_nfc_request_test_t *sim_test = (net_nfc_request_test_t *)req_msg;\r
+                               net_nfc_error_e result = NET_NFC_OK;\r
+\r
+                               resp.result = NET_NFC_OK;\r
+                               resp.trans_param = sim_test->trans_param;\r
+\r
+                               if (net_nfc_controller_test_mode_off(&result) == true)\r
+                               {\r
+                                       if (net_nfc_controller_test_mode_on(&result) == true)\r
+                                       {\r
+                                               if (net_nfc_controller_sim_test(&result) == true)\r
+                                               {\r
+                                                       DEBUG_SERVER_MSG("net_nfc_controller_sim_test Result [SUCCESS]");\r
+                                               }\r
+                                               else\r
+                                               {\r
+                                                       resp.result = NET_NFC_UNKNOWN_ERROR;\r
+                                                       DEBUG_SERVER_MSG("net_nfc_controller_sim_test Result [ERROR1]");\r
+                                               }\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               resp.result = NET_NFC_UNKNOWN_ERROR;\r
+                                               DEBUG_SERVER_MSG("net_nfc_controller_sim_test Result [ERROR2]");\r
+                                       }\r
+                               }\r
+                               else\r
+                               {\r
+                                       resp.result = NET_NFC_UNKNOWN_ERROR;\r
+                                       DEBUG_SERVER_MSG("net_nfc_controller_sim_test Result [ERROR3]");\r
+                               }\r
+\r
+                               DEBUG_SERVER_MSG("SEND RESPONSE!!");\r
+                               _net_nfc_send_response_msg(req_msg->request_type, (void *)&resp, sizeof(net_nfc_response_test_t), NULL);\r
+                       }\r
+                       break;\r
+\r
+               case NET_NFC_MESSAGE_SERVICE_DEINIT:\r
+                       {\r
+                               net_nfc_controller_deinit();\r
+                       }\r
+                       break;\r
+\r
+               case NET_NFC_MESSAGE_SERVICE_INIT:\r
+                       {\r
+                               net_nfc_error_e result;\r
+\r
+                               if(net_nfc_controller_init(&result) == true)\r
+                               {\r
+                                       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)\r
+                                       {\r
+                                               if(net_nfc_controller_confiure_discovery(NET_NFC_DISCOVERY_MODE_CONFIG, NET_NFC_ALL_ENABLE, &result) == true)\r
+                                               {\r
+                                                       DEBUG_SERVER_MSG("now, nfc is ready");\r
+                                               }\r
+                                               else\r
+                                               {\r
+                                                       DEBUG_ERR_MSG("net_nfc_controller_confiure_discovery failed [%d]", result);\r
+\r
+                                                       if (vconf_set_int(NET_NFC_VCONF_KEY_PROGRESS, result) != 0)\r
+                                                       {\r
+                                                               DEBUG_ERR_MSG("vconf_set_int(NET_NFC_VCONF_KEY_PROGRESS, ERROR) != 0");\r
+                                                       }\r
+                                                       exit(result);\r
+                                               }\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               DEBUG_ERR_MSG("net_nfc_controller_register_listener failed [%d]", result);\r
+\r
+                                               if (vconf_set_int(NET_NFC_VCONF_KEY_PROGRESS, result) != 0)\r
+                                               {\r
+                                                       DEBUG_ERR_MSG("vconf_set_int(NET_NFC_VCONF_KEY_PROGRESS, ERROR) != 0");\r
+                                               }\r
+                                               exit(result);\r
+                                       }\r
+\r
+                                       net_nfc_llcp_config_info_s config = {128, 1, 100, 0};\r
+                                       if(net_nfc_controller_llcp_config(&config, &result) == true)\r
+                                       {\r
+                                               /*We need to check the stack that supports the llcp or not.*/\r
+                                               DEBUG_SERVER_MSG("llcp is enabled");\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               DEBUG_SERVER_MSG("llcp is disabled")\r
+                                       }\r
+\r
+                                       DEBUG_SERVER_MSG("set ESE");\r
+\r
+                                       if(net_nfc_controller_set_secure_element_mode(SECURE_ELEMENT_TYPE_ESE, SECURE_ELEMENT_OFF_MODE, &result) == true)\r
+                                       {\r
+                                               DEBUG_SERVER_MSG("set ESE is ok");\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               DEBUG_SERVER_MSG("failed to set ESE as enable = [%d]", result);\r
+                                       }\r
+\r
+                                       DEBUG_SERVER_MSG("set UICC");\r
+\r
+                                       if(net_nfc_controller_set_secure_element_mode(SECURE_ELEMENT_TYPE_UICC, SECURE_ELEMENT_OFF_MODE, &result) == true)\r
+                                       {\r
+                                               DEBUG_SERVER_MSG("set UICC is ok");\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               DEBUG_SERVER_MSG("failed to set UICC as enable = [%d]", result);\r
+                                       }\r
+\r
+                                       g_se_cur_type = SECURE_ELEMENT_TYPE_UICC;\r
+                                       g_se_cur_mode = SECURE_ELEMENT_VIRTUAL_MODE;\r
+                                       g_se_prev_type = SECURE_ELEMENT_TYPE_UICC;\r
+                                       g_se_prev_mode = SECURE_ELEMENT_VIRTUAL_MODE;\r
+\r
+                                       if (vconf_set_int(NET_NFC_VCONF_KEY_PROGRESS, 0) != 0)\r
+                                       {\r
+                                               DEBUG_ERR_MSG("vconf_set_int(NET_NFC_VCONF_KEY_PROGRESS, SUCCESS) != 0");\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               DEBUG_SERVER_MSG("update vconf key NET_NFC_VCONF_KEY_PROGRESS [SUCCESS]");\r
+                                       }\r
+                               }\r
+                               else\r
+                               {\r
+                                       DEBUG_ERR_MSG("net_nfc_controller_init failed [%d]", result);\r
+\r
+                                       if (vconf_set_int(NET_NFC_VCONF_KEY_PROGRESS, result) != 0)\r
+                                       {\r
+                                               DEBUG_ERR_MSG("vconf_set_int(NET_NFC_VCONF_KEY_PROGRESS, ERROR) != 0");\r
+                                       }\r
+                                       /*We have to considerate when initialization is failed.*/\r
+                                       exit(result);\r
+                               }\r
+                       }\r
+                       break;\r
+\r
+               case NET_NFC_MESSAGE_SERVICE_STANDALONE_TARGET_DETECTED:\r
+                       {\r
+                               net_nfc_service_standalone_mode_target_detected(req_msg);\r
+                       }\r
+                       break;\r
+\r
+               case NET_NFC_MESSAGE_SERVICE_RESTART_POLLING_LOOP:\r
+                       {\r
+                               net_nfc_error_e result = NET_NFC_OK;\r
+\r
+                               if (net_nfc_controller_confiure_discovery(NET_NFC_DISCOVERY_MODE_RESUME, NET_NFC_ALL_ENABLE, &result) == true)\r
+                               {\r
+                                       DEBUG_SERVER_MSG("now, nfc polling loop is running again");\r
+                               }\r
+                       }\r
+                       break;\r
+\r
+               case NET_NFC_MESSAGE_SERVICE_LLCP_ACCEPT:\r
+                       {\r
+                               net_nfc_service_llcp_process_accept(req_msg);\r
+                       }\r
+                       break;\r
+\r
+               case NET_NFC_MESSAGE_SERVICE_LLCP_DEACTIVATED:\r
+                       {\r
+                               net_nfc_service_llcp_disconnect_target(req_msg);\r
+                       }\r
+                       break;\r
+\r
+               case NET_NFC_MESSAGE_SERVICE_LLCP_SOCKET_ERROR:\r
+                       {\r
+                               net_nfc_service_llcp_process_socket_error(req_msg);\r
+                       }\r
+                       break;\r
+\r
+               case NET_NFC_MESSAGE_SERVICE_LLCP_SOCKET_ACCEPTED_ERROR:\r
+                       {\r
+                               net_nfc_service_llcp_process_accepted_socket_error(req_msg);\r
+                       }\r
+                       break;\r
+\r
+               case NET_NFC_MESSAGE_SERVICE_LLCP_SEND :\r
+                       {\r
+                               net_nfc_service_llcp_process_send_socket(req_msg);\r
+                       }\r
+                       break;\r
+\r
+               case NET_NFC_MESSAGE_SERVICE_LLCP_SEND_TO :\r
+                       {\r
+                               net_nfc_service_llcp_process_send_to_socket(req_msg);\r
+                       }\r
+                       break;\r
+\r
+               case NET_NFC_MESSAGE_SERVICE_LLCP_RECEIVE :\r
+                       {\r
+                               net_nfc_service_llcp_process_receive_socket(req_msg);\r
+                       }\r
+                       break;\r
+\r
+               case NET_NFC_MESSAGE_SERVICE_LLCP_RECEIVE_FROM :\r
+                       {\r
+                               net_nfc_service_llcp_process_receive_from_socket(req_msg);\r
+                       }\r
+                       break;\r
+\r
+               case NET_NFC_MESSAGE_SERVICE_LLCP_CONNECT :\r
+                       {\r
+                               net_nfc_service_llcp_process_connect_socket(req_msg);\r
+                       }\r
+                       break;\r
+\r
+               case NET_NFC_MESSAGE_SERVICE_LLCP_CONNECT_SAP :\r
+                       {\r
+                               net_nfc_service_llcp_process_connect_sap_socket(req_msg);\r
+                       }\r
+                       break;\r
+\r
+               case NET_NFC_MESSAGE_SERVICE_LLCP_DISCONNECT :\r
+                       {\r
+                               net_nfc_service_llcp_process_disconnect_socket(req_msg);\r
+                       }\r
+                       break;\r
+\r
+               case NET_NFC_MESSAGE_SERVICE_SE :\r
+                       {\r
+                               net_nfc_request_set_se_t *detail = (net_nfc_request_set_se_t *)req_msg;\r
+                               net_nfc_error_e result = NET_NFC_OK;\r
+                               int mode;\r
+\r
+                               if (detail == NULL)\r
+                                       break;\r
+\r
+                               mode = (int)detail->se_type;\r
+\r
+                               if(mode == NET_NFC_SE_CMD_UICC_ON )\r
+                               {\r
+                                       /*turn on UICC*/\r
+                                       net_nfc_controller_set_secure_element_mode(SECURE_ELEMENT_TYPE_UICC, SECURE_ELEMENT_VIRTUAL_MODE, &result);\r
+\r
+                                       /*turn off ESE*/\r
+                                       net_nfc_controller_set_secure_element_mode(SECURE_ELEMENT_TYPE_ESE , SECURE_ELEMENT_OFF_MODE, &result);\r
+                               }\r
+                               else if(mode == NET_NFC_SE_CMD_ESE_ON)\r
+                               {\r
+                                       /*turn off UICC*/\r
+                                       net_nfc_controller_set_secure_element_mode(SECURE_ELEMENT_TYPE_UICC, SECURE_ELEMENT_OFF_MODE, &result);\r
+\r
+                                       /*turn on ESE*/\r
+                                       net_nfc_controller_set_secure_element_mode(SECURE_ELEMENT_TYPE_ESE , SECURE_ELEMENT_VIRTUAL_MODE, &result);\r
+                               }\r
+                               else if(mode == NET_NFC_SE_CMD_ALL_OFF)\r
+                               {\r
+                                       /*turn off both*/\r
+                                       net_nfc_controller_set_secure_element_mode(SECURE_ELEMENT_TYPE_UICC, SECURE_ELEMENT_OFF_MODE, &result);\r
+\r
+                                       /*turn on ESE*/\r
+                                       net_nfc_controller_set_secure_element_mode(SECURE_ELEMENT_TYPE_ESE , SECURE_ELEMENT_OFF_MODE, &result);\r
+                               }\r
+                               else\r
+                               {\r
+                                       /*turn off both*/\r
+                                       net_nfc_controller_set_secure_element_mode(SECURE_ELEMENT_TYPE_UICC, SECURE_ELEMENT_VIRTUAL_MODE, &result);\r
+\r
+                                       /*turn on ESE*/\r
+                                       net_nfc_controller_set_secure_element_mode(SECURE_ELEMENT_TYPE_ESE , SECURE_ELEMENT_VIRTUAL_MODE, &result);\r
+                               }\r
+                       }\r
+                       break;\r
+\r
+               case NET_NFC_MESSAGE_SERVICE_TERMINATION :\r
+                       {\r
+                               net_nfc_service_termination(req_msg);\r
+                       }\r
+                       break;\r
+\r
+               case NET_NFC_MESSAGE_SERVICE_SLAVE_TARGET_DETECTED :\r
+                       {\r
+                               net_nfc_service_slave_mode_target_detected(req_msg);\r
+                       }\r
+                       break;\r
+\r
+               case NET_NFC_MESSAGE_SERVICE_SLAVE_ESE_DETECTED :\r
+                       {\r
+                               net_nfc_service_se_detected(req_msg);\r
+                       }\r
+                       break;\r
+\r
+               case NET_NFC_MESSAGE_FORMAT_NDEF :\r
+                       {\r
+                               net_nfc_request_format_ndef_t *detail = (net_nfc_request_format_ndef_t *)req_msg;\r
+                               data_s data = { NULL, 0 };\r
+\r
+                               if (net_nfc_util_duplicate_data(&data, &detail->key) == true)\r
+                               {\r
+                                       net_nfc_response_format_ndef_t resp = { 0 };\r
+\r
+                                       resp.result = NET_NFC_OK;\r
+                                       resp.trans_param = detail->trans_param;\r
+\r
+                                       net_nfc_controller_format_ndef(detail->handle, &data, &(resp.result));\r
+                                       if (_net_nfc_check_client_handle())\r
+                                       {\r
+                                               _net_nfc_send_response_msg(req_msg->request_type, (void *)&resp, sizeof(net_nfc_response_format_ndef_t), NULL);\r
+                                       }\r
+\r
+                                       net_nfc_util_free_data(&data);\r
+                               }\r
+                       }\r
+                       break;\r
+\r
+               case NET_NFC_MESSAGE_LLCP_LISTEN :\r
+                       {\r
+                               net_nfc_response_listen_socket_t resp = { 0 };\r
+                               net_nfc_request_listen_socket_t *detail = (net_nfc_request_listen_socket_t *)req_msg;\r
+                               net_nfc_response_llcp_socket_error_t *error = NULL;\r
+                               bool success = false;\r
+\r
+                               _net_nfc_manager_util_alloc_mem(error, sizeof (net_nfc_response_llcp_socket_error_t));\r
+\r
+                               if (detail == NULL || error == NULL)\r
+                               {\r
+                                       DEBUG_SERVER_MSG("ERROR: invalid detail info or allocation is failed");\r
+                                       break;\r
+                               }\r
+\r
+                               resp.result = NET_NFC_IPC_FAIL;\r
+                               error->client_socket = detail->client_socket;\r
+                               error->handle = detail->handle;\r
+\r
+                               success = net_nfc_controller_llcp_create_socket(&(detail->oal_socket), detail->type, detail->miu, detail->rw, &(resp.result), error);\r
+\r
+                               if (success == true)\r
+                               {\r
+                                       error->oal_socket = resp.oal_socket = detail->oal_socket;\r
+                                       success = net_nfc_controller_llcp_bind(detail->oal_socket, detail->sap, &(resp.result));\r
+                               }\r
+\r
+                               if (success == true)\r
+                               {\r
+                                       DEBUG_SERVER_MSG("OAL socket in Listen :%d", detail->oal_socket);\r
+                                       success = net_nfc_controller_llcp_listen(detail->handle, detail->service_name.buffer, detail->oal_socket, &(resp.result), error);\r
+                               }\r
+\r
+                               resp.oal_socket = detail->oal_socket;\r
+                               resp.client_socket = detail->client_socket;\r
+                               resp.trans_param = detail->trans_param;\r
+\r
+                               if (_net_nfc_check_client_handle())\r
+                               {\r
+                                       _net_nfc_send_response_msg(req_msg->request_type, (void *)&resp, sizeof(net_nfc_response_listen_socket_t), NULL);\r
+                               }\r
+                       }\r
+                       break;\r
+\r
+               case NET_NFC_MESSAGE_LLCP_CONNECT :\r
+                       {\r
+                               net_nfc_response_connect_socket_t *resp = NULL;\r
+                               net_nfc_request_connect_socket_t *detail = (net_nfc_request_connect_socket_t *)req_msg;\r
+                               net_nfc_response_llcp_socket_error_t *error = NULL;\r
+                               bool success = false;\r
+\r
+                               _net_nfc_manager_util_alloc_mem(error, sizeof (net_nfc_response_llcp_socket_error_t));\r
+                               _net_nfc_manager_util_alloc_mem(resp, sizeof (net_nfc_response_connect_socket_t));\r
+\r
+                               if (detail == NULL || resp == NULL || error == NULL)\r
+                               {\r
+                                       DEBUG_SERVER_MSG("ERROR: invalid detail info or allocation is failed");\r
+                                       break;\r
+                               }\r
+\r
+                               error->client_socket = detail->client_socket;\r
+                               error->handle = detail->handle;\r
+                               resp->result = NET_NFC_IPC_FAIL;\r
+\r
+                               success = net_nfc_controller_llcp_create_socket(&(detail->oal_socket), detail->type, detail->miu, detail->rw, &(resp->result), error);\r
+\r
+                               if (success == true)\r
+                               {\r
+\r
+                                       error->oal_socket = resp->oal_socket = detail->oal_socket;\r
+                                       DEBUG_SERVER_MSG("connect client socket [%d]", detail->client_socket);\r
+                                       resp->client_socket = detail->client_socket;\r
+                                       resp->trans_param = detail->trans_param;\r
+\r
+                                       success = net_nfc_controller_llcp_connect_by_url(detail->handle, detail->oal_socket, detail->service_name.buffer, &(resp->result), resp);\r
+                               }\r
+\r
+                               if (success == false)\r
+                               {\r
+                                       DEBUG_SERVER_MSG("connect client socket is failed");\r
+\r
+                                       if (_net_nfc_check_client_handle())\r
+                                       {\r
+                                               _net_nfc_send_response_msg(req_msg->request_type, (void *)resp, sizeof(net_nfc_response_connect_socket_t), NULL);\r
+                                       }\r
+                                       _net_nfc_manager_util_free_mem(resp);\r
+                               }\r
+                       }\r
+                       break;\r
+\r
+               case NET_NFC_MESSAGE_LLCP_CONNECT_SAP :\r
+                       {\r
+                               net_nfc_response_connect_sap_socket_t *resp = NULL;\r
+                               net_nfc_request_connect_sap_socket_t *detail = (net_nfc_request_connect_sap_socket_t *)req_msg;\r
+                               bool success = false;\r
+\r
+                               _net_nfc_manager_util_alloc_mem(resp, sizeof (net_nfc_response_connect_sap_socket_t));\r
+\r
+                               if (detail == NULL || resp == NULL)\r
+                               {\r
+                                       DEBUG_SERVER_MSG("ERROR: invalid detail info or allocation is failed");\r
+                                       break;\r
+                               }\r
+\r
+                               resp->result = NET_NFC_IPC_FAIL;\r
+                               success = net_nfc_controller_llcp_create_socket(&(detail->oal_socket), detail->type, detail->miu, detail->rw, &(resp->result), NULL);\r
+\r
+                               if (success == true)\r
+                               {\r
+                                       resp->oal_socket = detail->oal_socket;\r
+                                       resp->client_socket = detail->client_socket;\r
+                                       resp->trans_param = detail->trans_param;\r
+\r
+                                       success = net_nfc_controller_llcp_connect(detail->handle, detail->oal_socket, detail->sap, &(resp->result), resp);\r
+                               }\r
+\r
+                               if (success == false)\r
+                               {\r
+                                       if (_net_nfc_check_client_handle())\r
+                                       {\r
+                                               _net_nfc_send_response_msg(req_msg->request_type, (void *)resp, sizeof(net_nfc_response_connect_sap_socket_t), NULL);\r
+                                       }\r
+                                       _net_nfc_manager_util_free_mem(resp);\r
+                               }\r
+                       }\r
+                       break;\r
+\r
+               case NET_NFC_MESSAGE_LLCP_SEND :\r
+                       {\r
+                               net_nfc_request_send_socket_t *detail = (net_nfc_request_send_socket_t *)req_msg;\r
+                               data_s data = { NULL, 0 };\r
+\r
+                               if (detail == NULL)\r
+                               {\r
+                                       DEBUG_SERVER_MSG("ERROR: invalid detail info");\r
+                                       break;\r
+                               }\r
+\r
+                               if (net_nfc_util_duplicate_data(&data, &detail->data) == true)\r
+                               {\r
+                                       net_nfc_response_send_socket_t *resp = NULL;\r
+\r
+                                       _net_nfc_manager_util_alloc_mem(resp, sizeof (net_nfc_response_send_socket_t));\r
+                                       if (resp == NULL)\r
+                                       {\r
+                                               DEBUG_SERVER_MSG("ERROR: allocation is failed");\r
+                                               net_nfc_util_free_data(&data);\r
+                                               break;\r
+                                       }\r
+\r
+                                       resp->result = NET_NFC_IPC_FAIL;\r
+                                       resp->client_socket = detail->client_socket;\r
+                                       resp->trans_param = detail->trans_param;\r
+\r
+                                       if (net_nfc_controller_llcp_send(detail->handle, detail->oal_socket, &data, &(resp->result), resp) == false)\r
+                                       {\r
+                                               if (_net_nfc_check_client_handle())\r
+                                               {\r
+                                                       _net_nfc_send_response_msg(req_msg->request_type, (void *)resp, sizeof(net_nfc_response_send_socket_t), NULL);\r
+                                               }\r
+                                               _net_nfc_manager_util_free_mem(resp);\r
+                                       }\r
+\r
+                                       net_nfc_util_free_data(&data);\r
+                               }\r
+                       }\r
+                       break;\r
+\r
+               case NET_NFC_MESSAGE_LLCP_RECEIVE :\r
+                       {\r
+                               net_nfc_response_receive_socket_t *resp = NULL;\r
+                               net_nfc_request_receive_socket_t *detail = (net_nfc_request_receive_socket_t *)req_msg;\r
+                               bool success = false;\r
+\r
+                               _net_nfc_manager_util_alloc_mem(resp, sizeof (net_nfc_response_receive_socket_t));\r
+\r
+                               if (detail == NULL || resp == NULL)\r
+                               {\r
+                                       DEBUG_SERVER_MSG("ERROR: invalid detail info or allocation is failed");\r
+                                       break;\r
+                               }\r
+\r
+                               resp->result = NET_NFC_IPC_FAIL;\r
+                               resp->client_socket = detail->client_socket;\r
+                               resp->trans_param = detail->trans_param;\r
+                               _net_nfc_manager_util_alloc_mem(resp->data.buffer, detail->req_length);\r
+                               resp->data.length = detail->req_length;\r
+\r
+                               if (resp->data.buffer != NULL)\r
+                               {\r
+                                       success = net_nfc_controller_llcp_recv(detail->handle, detail->oal_socket, &(resp->data), &(resp->result), resp);\r
+                               }\r
+                               else\r
+                               {\r
+                                       resp->result = NET_NFC_ALLOC_FAIL;\r
+                               }\r
+\r
+                               if (success == false)\r
+                               {\r
+                                       if (_net_nfc_check_client_handle())\r
+                                       {\r
+                                               _net_nfc_send_response_msg(req_msg->request_type, (void *)resp, sizeof(net_nfc_response_receive_socket_t), NULL);\r
+                                       }\r
+                                       _net_nfc_manager_util_free_mem(resp->data.buffer);\r
+                                       _net_nfc_manager_util_free_mem(resp);\r
+                               }\r
+                       }\r
+                       break;\r
+\r
+               case NET_NFC_MESSAGE_SERVICE_LLCP_CLOSE :\r
+                       {\r
+                               net_nfc_response_close_socket_t resp = { 0, };\r
+                               net_nfc_request_close_socket_t *detail = (net_nfc_request_close_socket_t *)req_msg;\r
+\r
+                               resp.result = NET_NFC_IPC_FAIL;\r
+                               if (detail != NULL)\r
+                               {\r
+                                       net_nfc_controller_llcp_socket_close(detail->oal_socket, &(resp.result));\r
+\r
+                                       resp.client_socket = detail->client_socket;\r
+                                       resp.trans_param = detail->trans_param;\r
+\r
+                                       if (_net_nfc_check_client_handle())\r
+                                       {\r
+                                               _net_nfc_send_response_msg(req_msg->request_type, (void *)&resp, sizeof(net_nfc_response_close_socket_t), NULL);\r
+                                       }\r
+                               }\r
+                       }\r
+                       break;\r
+\r
+               case NET_NFC_MESSAGE_LLCP_DISCONNECT :  /* change resp to local variable. if there is some problem, check this first. */\r
+                       {\r
+                               net_nfc_response_disconnect_socket_t resp = { 0, };\r
+                               net_nfc_request_disconnect_socket_t *detail = (net_nfc_request_disconnect_socket_t *)req_msg;\r
+\r
+                               resp.result = NET_NFC_IPC_FAIL;\r
+                               if (detail != NULL)\r
+                               {\r
+                                       resp.client_socket = detail->client_socket;\r
+                                       resp.trans_param = detail->trans_param;\r
+\r
+                                       if (false == net_nfc_controller_llcp_disconnect(detail->handle, detail->oal_socket, &(resp.result), &resp))\r
+                                       {\r
+                                               if (_net_nfc_check_client_handle())\r
+                                               {\r
+                                                       _net_nfc_send_response_msg(req_msg->request_type, (void *)&resp, sizeof(net_nfc_response_disconnect_socket_t), NULL);\r
+                                               }\r
+                                       }\r
+                               }\r
+                       }\r
+                       break;\r
+\r
+               case NET_NFC_MESSAGE_LLCP_ACCEPTED :\r
+                       {\r
+                               net_nfc_request_accept_socket_t *detail = (net_nfc_request_accept_socket_t *)req_msg;\r
+                               net_nfc_response_accept_socket_t resp = { 0, };\r
+\r
+                               resp.result = NET_NFC_IPC_FAIL;\r
+                               if (detail != NULL)\r
+                               {\r
+                                       net_nfc_controller_llcp_accept(detail->incomming_socket, &(resp.result));\r
+\r
+                                       resp.client_socket = detail->client_socket;\r
+                                       resp.trans_param = detail->trans_param;\r
+\r
+                                       if (_net_nfc_check_client_handle())\r
+                                       {\r
+                                               _net_nfc_send_response_msg(req_msg->request_type, (void *)&resp, sizeof(net_nfc_response_accept_socket_t), NULL);\r
+                                       }\r
+                               }\r
+                       }\r
+                       break;\r
+\r
+               case NET_NFC_MESSAGE_LLCP_CONFIG :\r
+                       {\r
+                               net_nfc_request_config_llcp_t *detail = (net_nfc_request_config_llcp_t *)req_msg;\r
+                               net_nfc_response_config_llcp_t resp = { 0, };\r
+\r
+                               resp.result = NET_NFC_IPC_FAIL;\r
+                               if (detail != NULL)\r
+                               {\r
+                                       net_nfc_controller_llcp_config(&(detail->config), &(resp.result));\r
+                                       resp.trans_param = detail->trans_param;\r
+\r
+                                       if (_net_nfc_check_client_handle())\r
+                                       {\r
+                                               _net_nfc_send_response_msg(req_msg->request_type, (void *)&resp, sizeof(net_nfc_response_config_llcp_t), NULL);\r
+                                       }\r
+                               }\r
+                       }\r
+                       break;\r
+\r
+               case NET_NFC_MESSAGE_CONNECTION_HANDOVER :\r
+                       {\r
+                               net_nfc_request_connection_handover_t *detail = (net_nfc_request_connection_handover_t *)req_msg;\r
+                               net_nfc_response_connection_handover_t response = { 0, };\r
+\r
+                               if (detail != NULL)\r
+                               {\r
+                                       if ((response.result = net_nfc_service_llcp_handover_send_request_msg(detail)) != NET_NFC_OK)\r
+                                       {\r
+                                               response.event = NET_NFC_OPERATION_FAIL;\r
+                                               response.type = NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN;\r
+\r
+                                               _net_nfc_send_response_msg(req_msg->request_type, (void *)&response, sizeof(net_nfc_response_connection_handover_t), NULL);\r
+                                       }\r
+                               }\r
+                       }\r
+                       break;\r
+\r
+               case NET_NFC_MESSAGE_SERVICE_WATCH_DOG :\r
+                       {\r
+                               net_nfc_service_watch_dog(req_msg);\r
+                               continue;\r
+                       }\r
+                       break;\r
+\r
+                       default:\r
+                       break;\r
+               }\r
+\r
+               /*need to free req_msg*/\r
+               _net_nfc_manager_util_free_mem(req_msg);\r
+       }\r
+       return (void *)NULL;\r
+}\r
+\r
+\r
+void net_nfc_dispatcher_cleanup_queue(void)\r
+{\r
+       pthread_mutex_lock(&g_dispatcher_queue_lock);\r
+\r
+       DEBUG_SERVER_MSG("cleanup dispatcher Q start");\r
+\r
+       net_nfc_request_msg_t *req_msg = NULL;\r
+\r
+       while((req_msg = _net_nfc_dispatcher_queue_pop()) != NULL)\r
+       {\r
+               DEBUG_SERVER_MSG("abandon request");\r
+               _net_nfc_manager_util_free_mem(req_msg);\r
+       }\r
+\r
+       DEBUG_SERVER_MSG("cleanup dispatcher Q end");\r
+\r
+       pthread_mutex_unlock(&g_dispatcher_queue_lock);\r
+}\r
+\r
+void net_nfc_dispatcher_put_cleaner(void)\r
+{\r
+       net_nfc_request_msg_t *req_msg = NULL;\r
+\r
+       _net_nfc_util_alloc_mem(req_msg, sizeof(net_nfc_request_msg_t));\r
+       if(req_msg != NULL)\r
+       {\r
+               DEBUG_SERVER_MSG("put cleaner request");\r
+\r
+               req_msg->length = sizeof(net_nfc_request_msg_t);\r
+               req_msg->request_type = NET_NFC_MESSAGE_SERVICE_CLEANER;\r
+               net_nfc_dispatcher_queue_push(req_msg);\r
+       }\r
+}\r
diff --git a/src/manager/net_nfc_server_ipc.c b/src/manager/net_nfc_server_ipc.c
new file mode 100644 (file)
index 0000000..5c1f224
--- /dev/null
@@ -0,0 +1,1202 @@
+/*
+  * Copyright 2012  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://www.tizenopensource.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 <stdio.h>
+#include <stdlib.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <arpa/inet.h>
+#include <netinet/in.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <glib-object.h>
+#include <unistd.h>
+#include <pthread.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_server_ipc_private.h"
+#include "net_nfc_server_dispatcher_private.h"
+#include "net_nfc_controller_private.h"
+#include "net_nfc_manager_util_private.h"
+
+#ifdef SECURITY_SERVER
+#include <security-server.h>
+#endif
+
+
+/* define */
+
+typedef struct _net_nfc_client_info_t{
+       int socket;
+       GIOChannel* channel;
+       uint32_t src_id;
+       client_state_e state;
+       int client_type;
+       //client_type_e client_type;
+       net_nfc_target_handle_s* target_handle;
+}net_nfc_client_info_t;
+
+#define NET_NFC_MANAGER_OBJECT "nfc-manager"
+#define NET_NFC_CLIENT_MAX 5
+
+
+
+/////////////////////////////
+
+/* static variable */
+
+static net_nfc_server_info_t g_server_info = {0,};
+static net_nfc_client_info_t g_client_info[NET_NFC_CLIENT_MAX] = {{0, NULL, 0, NET_NFC_CLIENT_INACTIVE_STATE, 0, NULL},};
+
+#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;
+
+/////////////////
+
+
+/*define static function*/
+
+static gboolean net_nfc_server_ipc_callback_func(GIOChannel* channel, GIOCondition condition, gpointer data);
+static bool net_nfc_server_cleanup_client_context(GIOChannel* channel);
+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();
+static bool net_nfc_server_add_client_context(int socket, GIOChannel* channel, uint32_t src_id, client_state_e state);
+static bool net_nfc_server_change_client_state(int socket, client_state_e state);
+static bool net_nfc_server_set_current_client_context(int socket_fd);
+static int net_nfc_server_get_client_sock_fd(GIOChannel* channel);
+static client_state_e net_nfc_server_get_client_state(int socket_fd);
+static void net_nfc_server_set_non_block_socket(int socket);
+
+/////////////////////////
+
+
+static void net_nfc_server_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");
+
+       }
+}
+
+bool net_nfc_server_ipc_initialize()
+{
+
+       /* initialize server context */
+
+       g_server_info.server_src_id = 0;
+       g_server_info.client_src_id = 0;
+
+       g_server_info.server_channel = (GIOChannel *)NULL;
+       g_server_info.client_channel = (GIOChannel *)NULL;
+
+       g_server_info.server_sock_fd = -1;
+       g_server_info.client_sock_fd = -1;
+
+       g_server_info.state = NET_NFC_SERVER_IDLE;
+
+#ifdef BROADCAST_MESSAGE
+       g_server_info.received_message = NULL;
+#endif
+       ///////////////////////////////
+       g_server_info.target_info = NULL;
+
+#ifdef USE_UNIX_DOMAIN
+
+       remove(NET_NFC_SERVER_DOMAIN);
+
+       struct sockaddr_un saddrun_rv;
+
+       memset(&saddrun_rv, 0, sizeof(struct sockaddr_un));
+
+       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 \n");
+               return false;
+       }
+
+       net_nfc_server_set_non_block_socket(g_server_info.server_sock_fd);
+
+       saddrun_rv.sun_family = AF_UNIX;
+       strncpy ( saddrun_rv.sun_path, NET_NFC_SERVER_DOMAIN, sizeof(saddrun_rv.sun_path) - 1 );
+
+       if(bind(g_server_info.server_sock_fd, (struct sockaddr *)&saddrun_rv, sizeof(saddrun_rv)) < 0)
+       {
+               DEBUG_ERR_MSG("bind is failed \n");
+               goto ERROR;
+       }
+
+       if(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;
+       memset(&serv_addr, 0x00, sizeof(struct sockaddr_in));
+
+       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 \n");
+               return false;
+       }
+
+       net_nfc_server_set_non_block_socket(g_server_info.server_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);
+
+       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 \n");
+               goto ERROR;
+       }
+
+
+#endif
+
+       if(listen(g_server_info.server_sock_fd, MAX_CLIENTS) < 0)
+       {
+               DEBUG_ERR_MSG("listen is failed \n");
+               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 \n");
+                       goto ERROR;
+               }
+       }
+       else
+       {
+               DEBUG_ERR_MSG(" g_io_channel_unix_new is failed \n");
+               goto ERROR;
+       }
+
+#ifdef SECURITY_SERVER
+
+       gid = security_server_get_gid(NET_NFC_MANAGER_OBJECT);
+       if(gid == 0)
+       {
+               DEBUG_SERVER_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)
+       {
+               if((cookies = (char *)calloc(1, cookies_size)) == NULL)
+               {
+                       goto ERROR;
+               }
+       }
+
+#endif
+
+       net_nfc_dispatcher_start_thread();
+
+       DEBUG_SERVER_MSG("server ipc is initialized");
+
+       return true;
+ERROR:
+       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;
+}
+
+bool net_nfc_server_ipc_finalize()
+{
+       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.client_channel != NULL)
+       {
+               g_io_channel_unref(g_server_info.client_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;
+       }
+
+
+       if(g_server_info.client_sock_fd != -1)
+       {
+               shutdown(g_server_info.client_sock_fd, SHUT_RDWR);
+               close(g_server_info.client_sock_fd);
+               g_server_info.client_sock_fd = -1;
+       }
+
+       return true;
+}
+
+gboolean net_nfc_server_ipc_callback_func(GIOChannel* channel, GIOCondition condition, gpointer data)
+{
+       if((G_IO_ERR & condition) || (G_IO_HUP & condition))
+       {
+               DEBUG_SERVER_MSG("IO ERROR \n");
+               if(channel == g_server_info.server_channel)
+               {
+                       DEBUG_SERVER_MSG("server socket is closed");
+                       net_nfc_server_ipc_finalize();
+               }
+               else
+               {
+                       DEBUG_SERVER_MSG("client socket is closed");
+                       if(net_nfc_server_cleanup_client_context(channel) == false)
+                       {
+                               DEBUG_ERR_MSG("failed to cleanup");
+                       }
+
+                       pthread_mutex_lock(&g_server_socket_lock);
+
+                       g_server_info.client_channel = NULL;
+                       g_server_info.client_sock_fd = -1;
+                       g_server_info.client_src_id = 0;
+
+                       pthread_mutex_unlock(&g_server_socket_lock);
+
+               }
+
+               net_nfc_dispatcher_cleanup_queue();
+
+               net_nfc_dispatcher_put_cleaner();
+
+               return FALSE;
+       }
+       else if(G_IO_NVAL & condition)
+       {
+               DEBUG_SERVER_MSG("INVALID socket \n");
+
+               return FALSE;
+       }
+       else if(G_IO_IN & condition)
+       {
+               int client_sock_fd = 0;
+
+               if(channel == g_server_info.server_channel)
+               {
+                       net_nfc_server_process_client_connect_request();
+               }
+               else if((client_sock_fd = net_nfc_server_get_client_sock_fd(channel)) > 0)
+               {
+                       net_nfc_error_e result = NET_NFC_OK;
+
+                       if(net_nfc_server_read_client_request(client_sock_fd, &result) == false)
+                       {
+                               DEBUG_SERVER_MSG("read client request is failed = [0x%x]", result);
+
+                               DEBUG_SERVER_MSG("client socket is closed");
+
+                               if(net_nfc_server_cleanup_client_context(channel) == false)
+                               {
+                                       DEBUG_ERR_MSG("failed to cleanup");
+                               }
+
+                               pthread_mutex_lock(&g_server_socket_lock);
+
+                               g_server_info.client_channel = NULL;
+                               g_server_info.client_sock_fd = -1;
+                               g_server_info.client_src_id = 0;
+
+                               pthread_mutex_unlock(&g_server_socket_lock);
+
+                               return FALSE;
+                       }
+               }
+               else
+               {
+                       DEBUG_SERVER_MSG("unknown channel \n");
+                       return FALSE;
+               }
+       }
+
+       return TRUE;
+}
+
+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(g_server_info.connected_client_count == NET_NFC_CLIENT_MAX)
+       {
+               DEBUG_SERVER_MSG("client is fully servered. no more capa is remained.");
+
+               int tmp_client_sock_fd = -1;
+
+               if((tmp_client_sock_fd = accept(g_server_info.server_sock_fd, NULL, &addrlen)) < 0)
+               {
+                       DEBUG_ERR_MSG("can not accept client");
+                       return false;
+               }
+               else
+               {
+                       shutdown(tmp_client_sock_fd, SHUT_RDWR);
+                       close(tmp_client_sock_fd);
+                       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");
+
+       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 bound with g_io_channel");
+
+       if(net_nfc_server_add_client_context(client_sock_fd, client_channel, client_src_id, NET_NFC_CLIENT_INACTIVE_STATE) == false)
+       {
+               DEBUG_ERR_MSG("failed to add client");
+       }
+       return true;
+
+ERROR:
+
+       if(client_channel != NULL)
+       {
+               g_io_channel_unref(client_channel);
+       }
+
+       if(client_sock_fd != -1)
+       {
+               shutdown(client_sock_fd, SHUT_RDWR);
+               close(client_sock_fd);
+       }
+
+       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_manager_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) == false)
+                       {
+                               return false;
+                       }
+                       readbyes -= read_size;
+               }
+               return false;
+       }
+
+       if(net_nfc_server_recv_message_from_client (client_sock_fd, *detail, size) == false)
+       {
+               _net_nfc_manager_util_free_mem (*detail);
+               return false;
+       }
+       return true;
+}
+
+bool net_nfc_server_read_client_request(int client_sock_fd, net_nfc_error_e *result)
+{
+       uint32_t length = 0;
+       net_nfc_request_msg_t *req_msg = NULL;
+
+#ifdef SECURITY_SERVER
+       if(net_nfc_server_recv_message_from_client(client_sock_fd, (void *)cookies, cookies_size) == false)
+       {
+               *result = NET_NFC_IPC_FAIL;
+               return false;
+       }
+       else
+       {
+               char printf_buff[BUFFER_LENGTH_MAX] ={0,};
+               int buff_count = BUFFER_LENGTH_MAX;
+               int i = 0;
+
+               for(; i < cookies_size; i++)
+               {
+                       buff_count -= snprintf (printf_buff + BUFFER_LENGTH_MAX - buff_count, buff_count, " %02X", cookies[i]);
+               }
+               DEBUG_SERVER_MSG ("server got cookies >>>> %s", printf_buff);
+       }
+#endif
+
+       if (net_nfc_server_recv_message_from_client(client_sock_fd, (void *)&length, sizeof(uint32_t)) == true && length != 0)
+       {
+               _net_nfc_util_alloc_mem(req_msg, length);
+               if (req_msg != NULL)
+               {
+                       if (net_nfc_server_recv_message_from_client(client_sock_fd, (void *)req_msg + sizeof(uint32_t), length - sizeof(uint32_t)) == true)
+                       {
+                               req_msg->length = length;
+                       }
+                       else
+                       {
+                               _net_nfc_util_free_mem(req_msg);
+                               *result = NET_NFC_IPC_FAIL;
+                               return false;
+                       }
+               }
+               else
+               {
+                       *result = NET_NFC_ALLOC_FAIL;
+                       return false;
+               }
+       }
+       else
+       {
+               *result = NET_NFC_IPC_FAIL;
+               return false;
+       }
+
+       DEBUG_SERVER_MSG("message from client. request type = [%d]", req_msg->request_type);
+
+#ifdef BROADCAST_MESSAGE
+       if(req_msg->request_type != NET_NFC_MESSAGE_SERVICE_CHANGE_CLIENT_STATE)
+       {
+               net_nfc_server_received_message_s* p = (net_nfc_server_received_message_s*)malloc(sizeof(net_nfc_server_received_message_s));
+
+               p->client_fd = client_sock_fd;
+               p->mes_type = req_msg->request_type;
+               p->next = g_server_info.received_message;
+               g_server_info.received_message = p;
+       }
+#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;
+
+                       if (net_nfc_server_change_client_state(client_sock_fd, detail->client_state) == true)
+                       {
+                               if (detail->client_state == NET_NFC_CLIENT_ACTIVE_STATE)
+                               {
+                                       /* 1. check the client_sock_fd is current socket */
+                                       net_nfc_server_set_client_type(client_sock_fd, detail->client_type);
+
+                                       if (client_sock_fd == g_server_info.client_sock_fd)
+                                       {
+                                       }
+                                       else
+                                       {
+                                               /* 1. deactivate before client socket */
+                                               /* 2. set client_sock_fd as current client socket */
+                                               if (g_server_info.client_sock_fd != -1)
+                                               {
+                                                       /* if server context.client_sock_fd is 0, then there was no client before*/
+                                                       net_nfc_server_change_client_state(g_server_info.client_sock_fd, NET_NFC_CLIENT_INACTIVE_STATE);
+                                               }
+
+                                               net_nfc_server_set_current_client_context(client_sock_fd);
+                                       }
+                               }
+                               else
+                               {
+                                       /* 1. check the client_sock_fd is current socket */
+                                       if (client_sock_fd == g_server_info.client_sock_fd)
+                                       {
+                                               /* 1. unset current client sock */
+                                               pthread_mutex_lock(&g_server_socket_lock);
+                                               g_server_info.client_channel = NULL;
+                                               g_server_info.client_sock_fd = -1;
+                                               g_server_info.client_src_id = 0;
+                                               pthread_mutex_unlock(&g_server_socket_lock);
+
+                                               /* 2. change client state */
+                                               net_nfc_server_change_client_state(g_server_info.client_sock_fd, NET_NFC_CLIENT_INACTIVE_STATE);
+                                       }
+                                       else
+                                       {
+                                               /* 1. change client state */
+                                               net_nfc_server_change_client_state(g_server_info.client_sock_fd, NET_NFC_CLIENT_INACTIVE_STATE);
+                                       }
+                               }
+                       }
+
+                       DEBUG_SERVER_MSG("net_nfc_server_read_client_request is finished");
+
+                       _net_nfc_manager_util_free_mem(req_msg);
+
+                       return true;
+               }
+               break;
+
+       default :
+               break;
+       }
+
+#ifdef SECURITY_SERVER
+       int error = 0;
+       if((error = security_server_check_privilege(cookies, gid)) < 0)
+       {
+               DEBUG_SERVER_MSG("failed to authentificate client [%d]", error);
+               *result = NET_NFC_SECURITY_FAIL;
+
+               _net_nfc_manager_util_free_mem(req_msg);
+
+               return false;
+       }
+#endif
+
+#ifdef BROADCAST_MESSAGE
+       net_nfc_dispatcher_queue_push(req_msg);
+       return true;
+
+#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");
+               return true;
+       }
+       else
+       {
+               DEBUG_SERVER_MSG("client is deactivated");
+
+               /* free req_msg */
+               _net_nfc_manager_util_free_mem(req_msg);
+
+               DEBUG_SERVER_MSG("net_nfc_server_read_client_request is finished");
+               return false;
+       }
+#endif
+}
+
+static bool net_nfc_server_cleanup_client_context(GIOChannel* channel)
+{
+       DEBUG_SERVER_MSG("client up client context");
+       int i = 0;
+
+       bool ret = false;
+
+       pthread_mutex_lock(&g_server_socket_lock);
+
+       for(; i < NET_NFC_CLIENT_MAX; i++)
+       {
+               if(g_client_info[i].channel == channel)
+               {
+
+                       if(g_client_info[i].channel != NULL)
+                       {
+                               g_io_channel_unref(g_client_info[i].channel);
+                       }
+
+                       /* need to check . is it neccesary to remove g_source_id */
+                       if(g_client_info[i].src_id > 0)
+                       {
+                               g_source_remove(g_client_info[i].src_id);
+                       }
+
+                       if(g_client_info[i].socket > 0)
+                       {
+                               shutdown(g_client_info[i].socket, SHUT_RDWR);
+                               close(g_client_info[i].socket);
+                       }
+
+                       g_client_info[i].socket = 0;
+                       g_client_info[i].channel = NULL;
+                       g_client_info[i].src_id = 0;
+                       g_client_info[i].state = NET_NFC_CLIENT_INACTIVE_STATE;
+                       g_client_info[i].target_handle = NULL;
+
+                       ret = true;
+
+                       g_server_info.connected_client_count--;
+
+                       break;
+               }
+       }
+
+       pthread_mutex_unlock(&g_server_socket_lock);
+
+       DEBUG_SERVER_MSG("current client count = [%d]", g_server_info.connected_client_count);
+
+       return ret;
+}
+
+#ifdef BROADCAST_MESSAGE
+bool net_nfc_server_send_message_to_client(int mes_type, void* message, int length)
+#else
+bool net_nfc_server_send_message_to_client(void* message, int length)
+#endif
+{
+#ifdef BROADCAST_MESSAGE
+       net_nfc_server_received_message_s* p1;
+       net_nfc_server_received_message_s* p2;
+
+       int leng, i;
+
+       p1 = g_server_info.received_message;
+       p2 = NULL;
+
+       while(p1 != NULL)
+       {
+               if(p1->mes_type == mes_type)
+               {
+                       pthread_mutex_lock(&g_server_socket_lock);
+                       leng = send(p1->client_fd, (void *)message, length, 0);
+                       pthread_mutex_unlock(&g_server_socket_lock);
+
+                       if(p2 != NULL)
+                       {
+                               p2->next = p1->next;
+                       }
+                       else
+                       {
+                               g_server_info.received_message = p1->next;
+                       }
+                       free(p1);
+
+                       if(leng > 0)
+                       {
+                               return true;
+                       }
+                       else
+                       {
+                               DEBUG_ERR_MSG("failed to send message, socket = [%d], msg_length = [%d]", p1->client_fd, length);
+                               return false;
+                       }
+               }
+               p2 = p1;
+               p1 = p1->next;
+       }
+
+       for(i=0; i<NET_NFC_CLIENT_MAX; i++)
+       {
+               if(g_client_info[i].socket)
+               {
+                       pthread_mutex_lock(&g_server_socket_lock);
+                       leng = send(g_client_info[i].socket, (void *)message, length, 0);
+                       pthread_mutex_unlock(&g_server_socket_lock);
+               }
+
+               if(leng <= 0)
+               {
+                       DEBUG_ERR_MSG("failed to send message, socket = [%d], msg_length = [%d]", g_server_info.client_sock_fd, length);
+               }
+       }
+
+       return true;
+#else
+       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
+}
+
+bool net_nfc_server_recv_message_from_client(int client_sock_fd, void* message, int length)
+{
+       int leng = recv(client_sock_fd, message, length, 0);
+
+       if(leng > 0)
+       {
+               return true;
+       }
+       else
+       {
+               DEBUG_ERR_MSG("failed to recv message, socket = [%d], msg_length = [%d]", g_server_info.client_sock_fd, length);
+               return false;
+       }
+}
+
+static int net_nfc_server_get_client_sock_fd(GIOChannel* channel)
+{
+       int i = 0;
+
+       int client_sock_fd = 0;
+
+       pthread_mutex_lock(&g_server_socket_lock);
+
+       for(; i < NET_NFC_CLIENT_MAX; i++)
+       {
+               if(g_client_info[i].channel == channel)
+               {
+                       client_sock_fd = g_client_info[i].socket ;
+                       break;
+               }
+       }
+
+       pthread_mutex_unlock(&g_server_socket_lock);
+
+       return client_sock_fd;
+}
+
+static bool net_nfc_server_set_current_client_context(int socket_fd)
+{
+       int i = 0;
+
+       bool ret = false;
+
+       pthread_mutex_lock(&g_server_socket_lock);
+
+       for(; i < NET_NFC_CLIENT_MAX; i++)
+       {
+               if(g_client_info[i].socket == socket_fd)
+               {
+                       g_server_info.client_sock_fd = g_client_info[i].socket ;
+                       g_server_info.client_channel = g_client_info[i].channel ;
+                       g_server_info.client_src_id = g_client_info[i].src_id ;
+
+                       ret = true;
+
+                       break;
+               }
+       }
+
+       pthread_mutex_unlock(&g_server_socket_lock);
+
+       return ret;
+}
+
+bool net_nfc_server_get_current_client_context(void* client_context)
+{
+#ifdef BROADCAST_MESSAGE
+       return true;
+#else
+       *((int *)client_context) = g_server_info.client_sock_fd;
+
+       return true;
+#endif
+}
+
+static client_state_e net_nfc_server_get_client_state(int socket_fd)
+{
+       int i = 0;
+
+       client_state_e client_state = NET_NFC_CLIENT_INACTIVE_STATE;
+
+       for(; i < NET_NFC_CLIENT_MAX; i++)
+       {
+               if(g_client_info[i].socket == socket_fd)
+               {
+                       client_state = g_client_info[i].state ;
+                       break;
+               }
+       }
+
+       return client_state;
+}
+
+
+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;
+}
+
+bool net_nfc_server_check_client_is_running(void* client_context)
+{
+#ifdef BROADCAST_MESSAGE
+       int i = 0;
+
+       pthread_mutex_lock(&g_server_socket_lock);
+
+       for(; i < NET_NFC_CLIENT_MAX; i++)
+       {
+               if(g_client_info[i].socket > 0)
+               {
+                       pthread_mutex_unlock(&g_server_socket_lock);
+                       return true;
+               }
+       }
+
+       pthread_mutex_unlock(&g_server_socket_lock);
+       return false;
+#else
+       int client_fd = *((int *)client_context);
+
+       if(client_fd > 0)
+               return true;
+       else
+               return false;
+#endif
+}
+
+static bool net_nfc_server_add_client_context(int socket, GIOChannel* channel, uint32_t src_id, client_state_e state)
+{
+       DEBUG_SERVER_MSG("add client context");
+       int i = 0;
+
+       bool ret = false;
+
+       pthread_mutex_lock(&g_server_socket_lock);
+
+       for(; i < NET_NFC_CLIENT_MAX; i++)
+       {
+               if(g_client_info[i].socket == 0 && g_client_info[i].channel == NULL)
+               {
+                       g_client_info[i].socket = socket;
+                       g_client_info[i].channel = channel;
+                       g_client_info[i].src_id = src_id;
+                       g_client_info[i].state = state;
+
+                       ret = true;
+
+                       g_server_info.connected_client_count++;
+
+                       break;
+               }
+       }
+
+       pthread_mutex_unlock(&g_server_socket_lock);
+
+       DEBUG_SERVER_MSG("current client count = [%d]", g_server_info.connected_client_count);
+
+       return ret;
+}
+
+static bool net_nfc_server_change_client_state(int socket, client_state_e state)
+{
+       int i = 0;
+
+       bool ret = false;
+
+       pthread_mutex_lock(&g_server_socket_lock);
+
+       for(; i < NET_NFC_CLIENT_MAX; i++)
+       {
+               if(g_client_info[i].socket == socket)
+               {
+                       g_client_info[i].state = state;
+
+                       ret = true;
+
+                       break;
+               }
+       }
+
+       pthread_mutex_unlock(&g_server_socket_lock);
+
+       return ret;
+}
+
+
+bool net_nfc_server_set_client_type(int socket, int type)
+{
+       int i = 0;
+
+       bool ret = false;
+
+       pthread_mutex_lock(&g_server_socket_lock);
+
+       for(; i < NET_NFC_CLIENT_MAX; i++)
+       {
+               if(g_client_info[i].socket == socket)
+               {
+                       g_client_info[i].client_type = type;
+
+                       ret = true;
+
+                       break;
+               }
+       }
+
+       pthread_mutex_unlock(&g_server_socket_lock);
+
+       return ret;
+}
+
+bool net_nfc_server_set_server_state(server_state_e state)
+{
+       pthread_mutex_lock(&g_server_socket_lock);
+
+       g_server_info.state = state;
+
+       pthread_mutex_unlock(&g_server_socket_lock);
+
+       return true;
+}
+
+server_state_e net_nfc_server_get_server_state()
+{
+       return g_server_info.state;
+}
+
+bool net_nfc_server_get_client_type(int socket, int* client_type)
+{
+       int i = 0;
+
+       bool ret = false;
+
+       if(socket < 0 || client_type == NULL)
+       {
+               return ret;
+       }
+
+       pthread_mutex_lock(&g_server_socket_lock);
+
+       for(; i < NET_NFC_CLIENT_MAX; i++)
+       {
+               if(g_client_info[i].socket == socket)
+               {
+                       *client_type = g_client_info[i].client_type;
+
+                       ret = true;
+
+                       break;
+               }
+       }
+
+       pthread_mutex_unlock(&g_server_socket_lock);
+
+       return ret;
+}
+
+
+bool _net_nfc_send_response_msg(int msg_type, ...)
+{
+       va_list args;
+       int total_size = 0;
+       int size = 0;
+       int written_size = 0;
+       void * data;
+       uint8_t* send_buffer = NULL;
+
+       va_start (args, msg_type);
+       if (va_arg (args, void*) != NULL)
+       {
+               while ((size = va_arg(args, int)) != 0)
+               {
+
+                       total_size+=size;
+
+                       if (va_arg (args, void*) == NULL)
+                       {
+                               break;
+                       }
+               }
+       }
+       va_end (args);
+
+       total_size += sizeof (int);
+       _net_nfc_manager_util_alloc_mem (send_buffer, total_size);
+       memcpy(send_buffer, &(msg_type), sizeof(int));
+       written_size += sizeof (int);
+
+       va_start (args, msg_type);
+       while ((data = va_arg(args, void *)) != 0)
+       {
+               size = va_arg (args, int);
+               if (size == 0) return false;
+               memcpy (send_buffer + written_size, data, size);
+               written_size += size;
+       }
+       va_end (args);
+#ifdef BROADCAST_MESSAGE
+       if(net_nfc_server_send_message_to_client(msg_type, (void *)send_buffer, total_size) == true)
+#else
+       if(net_nfc_server_send_message_to_client((void *)send_buffer, total_size) == true)
+#endif
+       {
+               DEBUG_SERVER_MSG("SERVER : [MSG:%d] sending response is ok ", msg_type);
+       }
+       _net_nfc_manager_util_free_mem(send_buffer);
+       return true;
+}
+
+
+bool _net_nfc_check_client_handle ()
+{
+#ifdef BROADCAST_MESSAGE
+       return true;
+#else
+       int client_context = 0;
+       if(net_nfc_server_get_current_client_context(&client_context) == true &&
+               net_nfc_server_check_client_is_running(&client_context) == true &&
+               net_nfc_server_get_current_client_target_handle(client_context) != NULL)
+       {
+               return true;
+       }
+       return false;
+#endif
+}
+
+
+server_state_e net_nfc_get_server_state()
+{
+       return g_server_info.state;
+}
+
+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;
+
+       _net_nfc_util_alloc_mem(target_info, sizeof(net_nfc_current_target_info_s) + detail->target_info_values.length);
+
+       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);
+       }
+
+       pthread_mutex_lock(&g_server_socket_lock);
+
+       g_server_info.target_info = target_info;
+
+       pthread_mutex_unlock(&g_server_socket_lock);
+
+}
+
+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 (file)
index 0000000..2e429e4
--- /dev/null
@@ -0,0 +1,512 @@
+/*\r
+  * Copyright 2012  Samsung Electronics Co., Ltd\r
+  *\r
+  * Licensed under the Flora License, Version 1.0 (the "License");\r
+  * you may not use this file except in compliance with the License.\r
+  * You may obtain a copy of the License at\r
+\r
+  *     http://www.tizenopensource.org/license\r
+  *\r
+  * Unless required by applicable law or agreed to in writing, software\r
+  * distributed under the License is distributed on an "AS IS" BASIS,\r
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+  * See the License for the specific language governing permissions and\r
+  * limitations under the License.\r
+  */\r
+\r
+#include "net_nfc_controller_private.h"\r
+#include "net_nfc_util_private.h"\r
+#include "net_nfc_typedef.h"\r
+#include "net_nfc_debug_private.h"\r
+#include "net_nfc_service_private.h"\r
+#include "net_nfc_service_se_private.h"\r
+#include "net_nfc_app_util_private.h"\r
+#include "net_nfc_dbus_service_obj_private.h"\r
+#include "net_nfc_server_ipc_private.h"\r
+#include "net_nfc_server_dispatcher_private.h"\r
+#include "net_nfc_manager_util_private.h"\r
+\r
+#include "net_nfc_service_tag_private.h"\r
+#include "net_nfc_service_llcp_private.h"\r
+\r
+#include "net_nfc_util_ndef_message.h"\r
+#include "net_nfc_util_ndef_record.h"\r
+\r
+#include <pthread.h>\r
+#include <malloc.h>\r
+\r
+\r
+/* static variable */\r
+\r
+/* static callback function */\r
+\r
+/* static function */\r
+\r
+extern uint8_t g_se_cur_type;\r
+extern uint8_t g_se_cur_mode;\r
+\r
+static void _net_nfc_service_show_exception_msg(char* msg);\r
+\r
+static bool _net_nfc_service_check_internal_ese_detected()\r
+{\r
+\r
+       if(g_se_cur_type == SECURE_ELEMENT_TYPE_ESE && g_se_cur_mode == SECURE_ELEMENT_WIRED_MODE)\r
+       {\r
+               return true;\r
+       }\r
+\r
+       return false;\r
+}\r
+\r
+\r
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r
+\r
+void net_nfc_service_target_detected_cb(void *info, void *user_context)\r
+{\r
+       int client_context = 0;\r
+       net_nfc_request_msg_t *req_msg = (net_nfc_request_msg_t *)info;\r
+\r
+       if (info == NULL)\r
+               return;\r
+\r
+       net_nfc_server_set_tag_info(info);\r
+\r
+       if (req_msg->request_type == NET_NFC_MESSAGE_SERVICE_RESTART_POLLING_LOOP)\r
+       {\r
+               net_nfc_dispatcher_queue_push(req_msg);\r
+       }\r
+#ifdef BROADCAST_MESSAGE\r
+       net_nfc_request_target_detected_t *detail = (net_nfc_request_target_detected_t *)req_msg;\r
+       req_msg->request_type = NET_NFC_MESSAGE_SERVICE_SLAVE_TARGET_DETECTED;\r
+       net_nfc_dispatcher_queue_push(req_msg);\r
+#else\r
+       else if (net_nfc_server_get_current_client_context(&client_context) == true &&\r
+               net_nfc_server_check_client_is_running(&client_context) == true)\r
+       {\r
+               net_nfc_request_target_detected_t *detail = (net_nfc_request_target_detected_t *)req_msg;\r
+\r
+               if (!_net_nfc_service_check_internal_ese_detected())\r
+               {\r
+                       req_msg->request_type = NET_NFC_MESSAGE_SERVICE_SLAVE_TARGET_DETECTED;\r
+               }\r
+               else\r
+               {\r
+                       req_msg->request_type = NET_NFC_MESSAGE_SERVICE_SLAVE_ESE_DETECTED;\r
+\r
+                       (detail->handle)->connection_type = NET_NFC_SE_CONNECTION;\r
+               }\r
+\r
+               net_nfc_server_set_current_client_target_handle(client_context, detail->handle);\r
+\r
+               net_nfc_dispatcher_queue_push(req_msg);\r
+\r
+               DEBUG_SERVER_MSG("current client is listener. stand alone mode will be activated");\r
+       }\r
+       else\r
+       {\r
+               req_msg->request_type = NET_NFC_MESSAGE_SERVICE_STANDALONE_TARGET_DETECTED;\r
+               net_nfc_dispatcher_queue_push(req_msg);\r
+       }\r
+#endif\r
+}\r
+\r
+void net_nfc_service_se_transaction_cb(void* info, void* user_context)\r
+{\r
+       int client_context = 0;\r
+       bool success;\r
+\r
+       net_nfc_request_se_event_t* se_event = (net_nfc_request_se_event_t *)info;\r
+\r
+       DEBUG_SERVER_MSG("se event [%d]", se_event->request_type);\r
+\r
+       if(net_nfc_server_get_current_client_context(&client_context) == true)\r
+       {\r
+               if(net_nfc_server_check_client_is_running(&client_context) == true)\r
+               {\r
+                       net_nfc_response_se_event_t resp_msg  = {0,};\r
+\r
+                       resp_msg.aid.length = se_event->aid.length;\r
+                       resp_msg.param.length = se_event->param.length;\r
+\r
+                       if(resp_msg.aid.length > 0)\r
+                       {\r
+\r
+                               if(resp_msg.param.length > 0)\r
+                               {\r
+                                       success = _net_nfc_send_response_msg (se_event->request_type, (void *)&resp_msg,  sizeof (net_nfc_response_se_event_t),\r
+                                                       (void *)(se_event->aid.buffer), resp_msg.aid.length,\r
+                                                       (void *)(se_event->param.buffer), resp_msg.param.length, NULL);\r
+                               }\r
+                               else\r
+                               {\r
+                                       success = _net_nfc_send_response_msg (se_event->request_type, (void *)&resp_msg,  sizeof (net_nfc_response_se_event_t),\r
+                                                               (void *)(se_event->aid.buffer), resp_msg.aid.length, NULL);\r
+                               }\r
+                       }\r
+                       else\r
+                       {\r
+                               success = _net_nfc_send_response_msg (se_event->request_type, (void *)&resp_msg,  sizeof (net_nfc_response_se_event_t), NULL);\r
+                       }\r
+\r
+                       if(success == true)\r
+                       {\r
+                               DEBUG_SERVER_MSG("sending response is ok");\r
+                       }\r
+               }\r
+       }\r
+}\r
+\r
+void net_nfc_service_llcp_event_cb(void* info, void* user_context)\r
+{\r
+       net_nfc_request_llcp_msg_t *req_msg = (net_nfc_request_llcp_msg_t *)info;\r
+\r
+       if(req_msg == NULL)\r
+       {\r
+               DEBUG_SERVER_MSG("req msg is null");\r
+               return;\r
+       }\r
+\r
+       if (req_msg->request_type == NET_NFC_MESSAGE_SERVICE_LLCP_ACCEPT)\r
+       {\r
+               net_nfc_request_accept_socket_t *detail = (net_nfc_request_accept_socket_t *)req_msg;\r
+               detail->trans_param = user_context;\r
+       }\r
+\r
+       req_msg->user_param = (uint32_t)user_context;\r
+\r
+       net_nfc_dispatcher_queue_push((net_nfc_request_msg_t *)req_msg);\r
+}\r
+\r
+bool net_nfc_service_standalone_mode_target_detected(net_nfc_request_msg_t* msg)\r
+{\r
+       net_nfc_request_target_detected_t* stand_alone = (net_nfc_request_target_detected_t *)msg;\r
+       net_nfc_error_e error_status = NET_NFC_OK;\r
+\r
+       data_s *recv_data = NULL;\r
+\r
+       DEBUG_SERVER_MSG("*** Detected! type [0x%X(%d)] ***", stand_alone->devType);\r
+\r
+       switch(stand_alone->devType)\r
+       {\r
+               case NET_NFC_NFCIP1_TARGET :\r
+               case NET_NFC_NFCIP1_INITIATOR :\r
+               {\r
+                       DEBUG_SERVER_MSG(" LLCP is detected");\r
+\r
+                       net_nfc_service_llcp_process(stand_alone->handle, stand_alone->devType, &error_status);\r
+\r
+                       malloc_trim(0);\r
+                       return true;\r
+               }\r
+               break;\r
+\r
+               default:\r
+               {\r
+                       DEBUG_SERVER_MSG(" PICC or PCD is detectd.");\r
+                       recv_data = net_nfc_service_tag_process(stand_alone->handle, stand_alone->devType, &error_status);\r
+               }\r
+               break;\r
+       }\r
+\r
+       if(recv_data != NULL)\r
+       {\r
+               net_nfc_util_play_target_detect_sound();\r
+               net_nfc_service_msg_processing(recv_data);\r
+       }\r
+       else\r
+       {\r
+               if(((stand_alone->devType == NET_NFC_NFCIP1_INITIATOR) || (stand_alone->devType == NET_NFC_NFCIP1_TARGET)))\r
+               {\r
+                       DEBUG_SERVER_MSG("p2p operation. recv data is NULL");\r
+               }\r
+               else\r
+               {\r
+                       net_nfc_util_play_target_detect_sound();\r
+\r
+                       if(error_status == NET_NFC_NO_NDEF_SUPPORT)\r
+                       {\r
+                               DEBUG_SERVER_MSG("device type = [%d], it has null data", stand_alone->devType);\r
+\r
+                               /* 1. make empty type record */\r
+                               ndef_message_s *msg = NULL;\r
+                               ndef_record_s *record = NULL;\r
+                               data_s typeName;\r
+                               data_s id;\r
+                               data_s payload;\r
+                               data_s rawdata;\r
+                               int ndef_length = 0;\r
+\r
+                               if (net_nfc_util_create_ndef_message(&msg) != NET_NFC_OK)\r
+                                       return true;\r
+\r
+                               DEBUG_SERVER_MSG("NET_NFC_NO_NDEF_SUPPORT #1");\r
+\r
+                               memset(&typeName, 0x00, sizeof(data_s));\r
+                               memset(&id, 0x00, sizeof(data_s));\r
+                               memset(&payload, 0x00, sizeof(data_s));\r
+\r
+                               if (net_nfc_util_create_record(NET_NFC_RECORD_EMPTY, &typeName, &id, &payload, &record) != NET_NFC_OK)\r
+                                       return true;\r
+\r
+                               DEBUG_SERVER_MSG("NET_NFC_NO_NDEF_SUPPORT #2");\r
+\r
+                               if (net_nfc_util_append_record(msg, record) != NET_NFC_OK)\r
+                                       return true;\r
+\r
+                               DEBUG_SERVER_MSG("NET_NFC_NO_NDEF_SUPPORT #3");\r
+\r
+                               memset(&rawdata, 0x00, sizeof(data_s));\r
+                               ndef_length = net_nfc_util_get_ndef_message_length(msg);\r
+                               _net_nfc_util_alloc_mem(rawdata.buffer, ndef_length);\r
+                               rawdata.length = ndef_length;\r
+\r
+                               if (net_nfc_util_convert_ndef_message_to_rawdata(msg, &rawdata) != NET_NFC_OK)\r
+                                       return true;\r
+\r
+                               DEBUG_SERVER_MSG("NET_NFC_NO_NDEF_SUPPORT #4");\r
+\r
+                               /* 2. With this, process service routine */\r
+                               net_nfc_service_msg_processing(&rawdata);\r
+                       }\r
+                       else\r
+                       {\r
+                               _net_nfc_service_show_exception_msg("Try again");\r
+                       }\r
+               }\r
+       }\r
+\r
+       if(stand_alone->devType != NET_NFC_NFCIP1_INITIATOR && stand_alone->devType != NET_NFC_NFCIP1_TARGET)\r
+       {\r
+               net_nfc_request_watch_dog_t* watch_dog_msg = NULL;\r
+\r
+               _net_nfc_util_alloc_mem(watch_dog_msg, sizeof(net_nfc_request_watch_dog_t));\r
+\r
+               if(watch_dog_msg != NULL)\r
+               {\r
+                       watch_dog_msg->length = sizeof(net_nfc_request_watch_dog_t);\r
+                       watch_dog_msg->request_type = NET_NFC_MESSAGE_SERVICE_WATCH_DOG;\r
+                       watch_dog_msg->devType = stand_alone->devType;\r
+                       watch_dog_msg->handle = stand_alone->handle;\r
+\r
+                       net_nfc_dispatcher_queue_push((net_nfc_request_msg_t *)watch_dog_msg);\r
+               }\r
+\r
+       }\r
+\r
+       DEBUG_SERVER_MSG("stand alone mode is end");\r
+       malloc_trim(0);\r
+\r
+       return true;\r
+}\r
+\r
+bool net_nfc_service_slave_mode_target_detected(net_nfc_request_msg_t* msg)\r
+{\r
+       DEBUG_SERVER_MSG("target detected callback for client");\r
+\r
+       net_nfc_error_e result = NET_NFC_OK;\r
+       int request_type = NET_NFC_MESSAGE_TAG_DISCOVERED;\r
+       net_nfc_response_tag_discovered_t resp_msg  = {0,};\r
+       bool success = true;\r
+       data_s* recv_data = NULL;\r
+\r
+       memset(&resp_msg, 0x00, sizeof(net_nfc_response_tag_discovered_t));\r
+\r
+       net_nfc_request_target_detected_t *detail_msg = (net_nfc_request_target_detected_t *)msg;\r
+\r
+       if(detail_msg == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if(detail_msg->devType != NET_NFC_NFCIP1_TARGET  && detail_msg->devType != NET_NFC_NFCIP1_INITIATOR)\r
+       {\r
+               if (!net_nfc_controller_connect (detail_msg->handle, &result))\r
+               {\r
+                       DEBUG_SERVER_MSG("connect failed");\r
+                       return false;\r
+               }\r
+\r
+#ifdef BROADCAST_MESSAGE\r
+               net_nfc_server_set_server_state(        NET_NFC_TAG_CONNECTED);\r
+#endif\r
+               DEBUG_SERVER_MSG("tag is connected");\r
+\r
+               uint8_t ndef_card_state = 0;\r
+               int max_data_size = 0;\r
+               int real_data_size = 0;\r
+\r
+               if(net_nfc_controller_check_ndef(detail_msg->handle, &ndef_card_state, &max_data_size, &real_data_size, &result) == true)\r
+               {\r
+                       resp_msg.ndefCardState = ndef_card_state;\r
+                       resp_msg.maxDataSize = max_data_size;\r
+                       resp_msg.actualDataSize = real_data_size;\r
+                       resp_msg.is_ndef_supported = 1;\r
+               }\r
+               else\r
+               {\r
+                       resp_msg.ndefCardState = 0;\r
+                       resp_msg.is_ndef_supported = 0;\r
+                       resp_msg.maxDataSize = 0;\r
+                       resp_msg.actualDataSize = 0;\r
+               }\r
+\r
+               resp_msg.devType = detail_msg->devType;\r
+               resp_msg.handle = detail_msg->handle;\r
+               resp_msg.number_of_keys = detail_msg->number_of_keys;\r
+\r
+               net_nfc_util_duplicate_data(&resp_msg.target_info_values, &detail_msg->target_info_values);\r
+\r
+               if(resp_msg.is_ndef_supported)\r
+               {\r
+                       if(net_nfc_controller_read_ndef (detail_msg->handle, &recv_data, &(resp_msg.result)) == true) {\r
+                               DEBUG_SERVER_MSG("net_nfc_controller_read_ndef is success");\r
+\r
+                               resp_msg.raw_data.length = recv_data->length;\r
+\r
+                               success = _net_nfc_send_response_msg (request_type, (void *)&resp_msg,  sizeof (net_nfc_response_tag_discovered_t),\r
+                                       (void *)(resp_msg.target_info_values.buffer), resp_msg.target_info_values.length,\r
+                                       (void *)(recv_data->buffer), recv_data->length, NULL);\r
+\r
+#ifdef BROADCAST_MESSAGE\r
+                               net_nfc_util_play_target_detect_sound();\r
+                               net_nfc_service_msg_processing(recv_data);\r
+#endif\r
+                       }\r
+                       else {\r
+                               DEBUG_SERVER_MSG("net_nfc_controller_read_ndef is fail");\r
+\r
+                               resp_msg.raw_data.length = 0;\r
+\r
+                               success = _net_nfc_send_response_msg (request_type, (void *)&resp_msg,  sizeof (net_nfc_response_tag_discovered_t),\r
+                                       (void *)(resp_msg.target_info_values.buffer), resp_msg.target_info_values.length, NULL);\r
+                       }\r
+               }\r
+               else\r
+               {\r
+#ifdef BROADCAST_MESSAGE\r
+                       DEBUG_SERVER_MSG("device type = [%d], it has null data", detail_msg->devType);\r
+\r
+                       /* 1. make empty type record */\r
+                       ndef_message_s *msg = NULL;\r
+                       ndef_record_s *record = NULL;\r
+                       data_s typeName;\r
+                       data_s id;\r
+                       data_s payload;\r
+                       data_s rawdata;\r
+                       int ndef_length = 0;\r
+\r
+                       if (net_nfc_util_create_ndef_message(&msg) != NET_NFC_OK)\r
+                               return true;\r
+\r
+                       DEBUG_SERVER_MSG("NET_NFC_NO_NDEF_SUPPORT #1");\r
+\r
+                       memset(&typeName, 0x00, sizeof(data_s));\r
+                       memset(&id, 0x00, sizeof(data_s));\r
+                       memset(&payload, 0x00, sizeof(data_s));\r
+\r
+                       if (net_nfc_util_create_record(NET_NFC_RECORD_EMPTY, &typeName, &id, &payload, &record) != NET_NFC_OK)\r
+                               return true;\r
+\r
+                       DEBUG_SERVER_MSG("NET_NFC_NO_NDEF_SUPPORT #2");\r
+\r
+                       if (net_nfc_util_append_record(msg, record) != NET_NFC_OK)\r
+                               return true;\r
+\r
+                       DEBUG_SERVER_MSG("NET_NFC_NO_NDEF_SUPPORT #3");\r
+\r
+                       memset(&rawdata, 0x00, sizeof(data_s));\r
+                       ndef_length = net_nfc_util_get_ndef_message_length(msg);\r
+                       _net_nfc_util_alloc_mem(rawdata.buffer, ndef_length);\r
+                       rawdata.length = ndef_length;\r
+\r
+                       if (net_nfc_util_convert_ndef_message_to_rawdata(msg, &rawdata) != NET_NFC_OK)\r
+                               return true;\r
+\r
+                       DEBUG_SERVER_MSG("NET_NFC_NO_NDEF_SUPPORT #4");\r
+\r
+                       /* 2. With this, process service routine */\r
+                       net_nfc_service_msg_processing(&rawdata);\r
+#endif\r
+                       resp_msg.raw_data.length = 0;\r
+                       success = _net_nfc_send_response_msg (request_type, (void *)&resp_msg,  sizeof (net_nfc_response_tag_discovered_t),\r
+                               (void *)(resp_msg.target_info_values.buffer), resp_msg.target_info_values.length, NULL);\r
+               }\r
+\r
+               net_nfc_util_free_data(&resp_msg.target_info_values);\r
+\r
+               DEBUG_SERVER_MSG("turn on watch dog");\r
+\r
+               net_nfc_request_watch_dog_t* watch_dog_msg = NULL;\r
+\r
+               _net_nfc_util_alloc_mem(watch_dog_msg, sizeof(net_nfc_request_watch_dog_t));\r
+               if(watch_dog_msg != NULL)\r
+               {\r
+                       watch_dog_msg->length = sizeof(net_nfc_request_watch_dog_t);\r
+                       watch_dog_msg->request_type = NET_NFC_MESSAGE_SERVICE_WATCH_DOG;\r
+                       watch_dog_msg->devType = detail_msg->devType;\r
+                       watch_dog_msg->handle = detail_msg->handle;\r
+\r
+                       net_nfc_dispatcher_queue_push((net_nfc_request_msg_t *)watch_dog_msg);\r
+               }\r
+       }\r
+       else /* LLCP */\r
+       {\r
+               net_nfc_error_e error_status = NET_NFC_OK;\r
+\r
+               net_nfc_service_llcp_process(detail_msg->handle, detail_msg->devType, &error_status);\r
+       }\r
+\r
+       return success;\r
+}\r
+\r
+bool net_nfc_service_termination (net_nfc_request_msg_t* msg)\r
+{\r
+       net_nfc_error_e result;\r
+\r
+       if (net_nfc_controller_is_ready (&result) == true)\r
+       {\r
+       }\r
+       else\r
+       {\r
+               DEBUG_SERVER_MSG("Not initialized");\r
+               net_nfc_controller_init (&result);\r
+       }\r
+\r
+\r
+       if (net_nfc_controller_confiure_discovery(NET_NFC_DISCOVERY_MODE_CONFIG, NET_NFC_ALL_DISABLE, &result) != true)\r
+       {\r
+               DEBUG_SERVER_MSG("failed to discover off %d", result);\r
+       }\r
+\r
+       if (net_nfc_controller_set_secure_element_mode (NET_NFC_SE_CMD_UICC_ON, SECURE_ELEMENT_VIRTUAL_MODE, &result) != true)\r
+       {\r
+               DEBUG_SERVER_MSG("failed to set se mode to default mode: %d", result);\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+void net_nfc_service_msg_processing(data_s* data)\r
+{\r
+       if(data != NULL)\r
+       {\r
+               net_nfc_app_util_process_ndef(data);\r
+       }\r
+       else\r
+       {\r
+               _net_nfc_service_show_exception_msg("unknown type tag");\r
+       }\r
+}\r
+\r
+\r
+static void _net_nfc_service_show_exception_msg(char* msg)\r
+{\r
+       bundle* kb = NULL;\r
+       kb = bundle_create();\r
+       bundle_add(kb, "type", "default");\r
+       bundle_add(kb, "text", msg);\r
+\r
+       net_nfc_app_util_aul_launch_app("com.samsung.nfc-app", kb); /* empty_tag */\r
+\r
+       bundle_free(kb);\r
+}\r
diff --git a/src/manager/net_nfc_service_llcp.c b/src/manager/net_nfc_service_llcp.c
new file mode 100644 (file)
index 0000000..b91679b
--- /dev/null
@@ -0,0 +1,2582 @@
+/*\r
+  * Copyright 2012  Samsung Electronics Co., Ltd\r
+  *\r
+  * Licensed under the Flora License, Version 1.0 (the "License");\r
+  * you may not use this file except in compliance with the License.\r
+  * You may obtain a copy of the License at\r
+\r
+  *     http://www.tizenopensource.org/license\r
+  *\r
+  * Unless required by applicable law or agreed to in writing, software\r
+  * distributed under the License is distributed on an "AS IS" BASIS,\r
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+  * See the License for the specific language governing permissions and\r
+  * limitations under the License.\r
+  */\r
+\r
+#include "net_nfc_controller_private.h"\r
+#include "net_nfc_util_private.h"\r
+#include "net_nfc_typedef.h"\r
+#include "net_nfc_debug_private.h"\r
+#include "net_nfc_service_private.h"\r
+#include "net_nfc_app_util_private.h"\r
+#include "net_nfc_dbus_service_obj_private.h"\r
+#include "net_nfc_server_ipc_private.h"\r
+#include "net_nfc_server_dispatcher_private.h"\r
+#include "net_nfc_manager_util_private.h"\r
+#include "net_nfc_service_llcp_private.h"\r
+#include "net_nfc_service_llcp_handover_private.h"\r
+\r
+#include <pthread.h>\r
+#include <malloc.h>\r
+\r
+#include <netinet/in.h>\r
+\r
+\r
+static uint8_t snep_server_buffer[SNEP_MAX_BUFFER] = {0,};\r
+static uint8_t snep_client_buffer[SNEP_MAX_BUFFER] = {0,};\r
+\r
+static data_s snep_server_data ={snep_server_buffer, SNEP_MAX_BUFFER};\r
+static data_s snep_client_data ={snep_client_buffer, SNEP_MAX_BUFFER};\r
+\r
+static net_nfc_llcp_state_t current_llcp_client_state;\r
+static net_nfc_llcp_state_t current_llcp_server_state;\r
+\r
+\r
+/* static callback function */\r
+\r
+net_nfc_error_e _net_nfc_service_llcp_get_server_configuration_value(char* service_name, char* attr_name, char* attr_value);\r
+static bool _net_nfc_service_llcp_state_process(net_nfc_request_msg_t *msg);\r
+\r
+static bool _net_nfc_service_llcp_snep_server(net_nfc_llcp_state_t * state, net_nfc_error_e* result);\r
+static bool _net_nfc_service_llcp_client(net_nfc_llcp_state_t * state, net_nfc_error_e* result);\r
+static data_s* _net_nfc_service_llcp_snep_create_msg(snep_command_field_e resp_field, data_s* information);\r
+static net_nfc_error_e _net_nfc_service_llcp_snep_check_req_msg(data_s* snep_msg, uint8_t* resp_code);\r
+static net_nfc_error_e _net_nfc_service_llcp_snep_get_code(data_s* snep_msg, uint8_t* code);\r
+static net_nfc_error_e _net_nfc_service_llcp_snep_get_information_length(data_s* snep_msg, uint32_t* length);\r
+static net_nfc_error_e _net_nfc_service_llcp_snep_check_resp_msg(data_s* snep_msg);\r
+\r
+static bool _net_nfc_service_llcp_npp_server(net_nfc_llcp_state_t * state, net_nfc_error_e* result);\r
+static data_s* _net_nfc_service_llcp_npp_create_msg(data_s* information);\r
+static net_nfc_error_e _net_nfc_service_llcp_npp_check_req_msg(data_s* npp_msg, uint8_t* resp_code);\r
+static net_nfc_error_e _net_nfc_service_llcp_npp_get_information_length(data_s* npp_msg, uint32_t* length);\r
+\r
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r
+\r
+GList * state_list = NULL;\r
+static bool net_nfc_service_llcp_is_valid_state (net_nfc_llcp_state_t * state)\r
+{\r
+       if (g_list_find (state_list, state) != NULL){\r
+               return true;\r
+       }\r
+       return false;\r
+}\r
+void net_nfc_service_llcp_remove_state (net_nfc_llcp_state_t * state)\r
+{\r
+       if (state != NULL){\r
+               state_list = g_list_remove (state_list, state);\r
+       }\r
+}\r
+void net_nfc_service_llcp_add_state (net_nfc_llcp_state_t * state)\r
+{\r
+       if (state != NULL){\r
+               state_list = g_list_append (state_list, state);\r
+       }\r
+}\r
+\r
+\r
+bool net_nfc_service_llcp_process(net_nfc_target_handle_s* handle, int devType, net_nfc_error_e* result)\r
+{\r
+       *result = NET_NFC_OK;\r
+\r
+       DEBUG_SERVER_MSG("connection type = [%d]", handle->connection_type);\r
+\r
+       if(devType == NET_NFC_NFCIP1_TARGET)\r
+       {\r
+               DEBUG_SERVER_MSG("trying to connect to tag = [0x%x]", handle);\r
+\r
+               if (net_nfc_controller_connect (handle, result) != true)\r
+               {\r
+                       DEBUG_SERVER_MSG("connect failed");\r
+\r
+                       if (net_nfc_controller_confiure_discovery (NET_NFC_DISCOVERY_MODE_RESUME ,NET_NFC_ALL_ENABLE ,result) == false)\r
+                       {\r
+                               net_nfc_controller_exception_handler();\r
+\r
+                       }\r
+\r
+                       return false;\r
+               }\r
+       }\r
+\r
+#ifdef BROADCAST_MESSAGE\r
+       net_nfc_server_set_server_state(        NET_NFC_LLCP_CONNECTED);\r
+#endif\r
+\r
+       DEBUG_SERVER_MSG("check LLCP");\r
+\r
+       if(net_nfc_controller_llcp_check_llcp(handle, result) == true)\r
+       {\r
+               DEBUG_SERVER_MSG("activate LLCP");\r
+               if(net_nfc_controller_llcp_activate_llcp(handle, result) == true)\r
+               {\r
+\r
+#ifdef SUPPORT_CONFIG_FILE\r
+                       char value[64] = {0,};\r
+                       if(net_nfc_service_get_configuration_value("service", "exchange_service", value) == NET_NFC_OK)\r
+                       {\r
+                               if(strcmp(value, "true") == 0)\r
+                               {\r
+                                       net_nfc_llcp_state_t * exchange_state_server = NULL;\r
+                                       _net_nfc_manager_util_alloc_mem (exchange_state_server,sizeof (net_nfc_llcp_state_t));\r
+\r
+                                       exchange_state_server->handle = handle;\r
+                                       exchange_state_server->state = NET_NFC_STATE_EXCHANGER_SERVER;\r
+                                       exchange_state_server->step = NET_NFC_LLCP_STEP_01;\r
+                                       exchange_state_server->user_data = NULL;\r
+\r
+                                       net_nfc_service_llcp_add_state (exchange_state_server);\r
+\r
+                                       if (_net_nfc_service_llcp_snep_server (exchange_state_server, result) == false){\r
+                                               return false;\r
+                                       }\r
+\r
+                                       handle->app_type = exchange_state_server->type_app_protocol;\r
+                                       DEBUG_SERVER_MSG("handle->app_type = [%d]" , handle->app_type);\r
+\r
+                               }\r
+                               else\r
+                               {\r
+                                       DEBUG_SERVER_MSG("llcp exchange service is trunned off");\r
+                               }\r
+\r
+                       }\r
+                       else\r
+                       {\r
+                               net_nfc_llcp_state_t * exchange_state_server = NULL;\r
+                               _net_nfc_manager_util_alloc_mem (exchange_state_server,sizeof (net_nfc_llcp_state_t));\r
+\r
+                               exchange_state_server->handle = handle;\r
+                               exchange_state_server->state = NET_NFC_STATE_EXCHANGER_SERVER;\r
+                               exchange_state_server->step = NET_NFC_LLCP_STEP_01;\r
+                               exchange_state_server->user_data = NULL;\r
+\r
+                               net_nfc_service_llcp_add_state (exchange_state_server);\r
+\r
+                               if (_net_nfc_service_llcp_npp_server (exchange_state_server, result) == false)\r
+                               {\r
+                                       DEBUG_SERVER_MSG("ERROR!!!!!!!!!!!!!!!");\r
+                                       return false;\r
+                               }\r
+                               else\r
+                               {\r
+                                       handle->app_type = exchange_state_server->type_app_protocol;\r
+                                       DEBUG_SERVER_MSG("handle->app_type = [%d]" , handle->app_type);\r
+                               }\r
+                       }\r
+\r
+                       memset(value, 0x00, 64);\r
+\r
+                       if(net_nfc_service_get_configuration_value("service", "connection_handover", value) == NET_NFC_OK){\r
+                               if(strcmp(value, "true") == 0){\r
+\r
+                                       net_nfc_llcp_state_t * conn_handover_selector = NULL;\r
+                                       _net_nfc_manager_util_alloc_mem (conn_handover_selector,sizeof (net_nfc_llcp_state_t));\r
+\r
+                                       conn_handover_selector->handle = handle;\r
+                                       conn_handover_selector->state = NET_NFC_STATE_CONN_HANDOVER_SELECT;\r
+                                       conn_handover_selector->step = NET_NFC_LLCP_STEP_01;\r
+                                       conn_handover_selector->user_data = NULL;\r
+\r
+                                       net_nfc_service_llcp_add_state (conn_handover_selector);\r
+\r
+                                       if (_net_nfc_service_llcp_stand_alone_conn_handover_selector (conn_handover_selector, result) == false){\r
+                                               return false;\r
+                                       }\r
+                               }\r
+                               else\r
+                               {\r
+                                       DEBUG_SERVER_MSG("llcp connection handover is trunned off");\r
+                               }\r
+                       }\r
+\r
+#else/* Use the NPP & the SNEP FOR LLCP , Handover*/\r
+\r
+                       /* NPP */\r
+                       net_nfc_llcp_state_t * exchange_state_server_NPP = NULL;\r
+                       _net_nfc_manager_util_alloc_mem (exchange_state_server_NPP,sizeof (net_nfc_llcp_state_t));\r
+                       exchange_state_server_NPP->handle = handle;\r
+                       exchange_state_server_NPP->state = NET_NFC_STATE_EXCHANGER_SERVER_NPP;\r
+                       exchange_state_server_NPP->step = NET_NFC_LLCP_STEP_01;\r
+                       exchange_state_server_NPP->user_data = NULL;\r
+\r
+                       net_nfc_service_llcp_add_state (exchange_state_server_NPP);\r
+\r
+                       if (_net_nfc_service_llcp_npp_server (exchange_state_server_NPP, result) == false)\r
+                       {\r
+                               return false;\r
+                       }\r
+\r
+                       /* SNEP */\r
+                       net_nfc_llcp_state_t * exchange_state_server_SNEP = NULL;\r
+                       _net_nfc_manager_util_alloc_mem (exchange_state_server_SNEP,sizeof (net_nfc_llcp_state_t));\r
+                       exchange_state_server_SNEP->handle = handle;\r
+                       exchange_state_server_SNEP->state = NET_NFC_STATE_EXCHANGER_SERVER;\r
+                       exchange_state_server_SNEP->step = NET_NFC_LLCP_STEP_01;\r
+                       exchange_state_server_SNEP->user_data = NULL;\r
+\r
+                       net_nfc_service_llcp_add_state (exchange_state_server_SNEP);\r
+\r
+                       if (_net_nfc_service_llcp_snep_server (exchange_state_server_SNEP, result) == false)\r
+                       {\r
+                               return false;\r
+                       }\r
+\r
+                       net_nfc_llcp_state_t * conn_handover_selector = NULL;\r
+                       _net_nfc_manager_util_alloc_mem (conn_handover_selector,sizeof (net_nfc_llcp_state_t));\r
+                       conn_handover_selector->handle = handle;\r
+                       conn_handover_selector->state = NET_NFC_STATE_CONN_HANDOVER_SELECT;\r
+                       conn_handover_selector->step = NET_NFC_LLCP_STEP_01;\r
+                       conn_handover_selector->user_data = NULL;\r
+\r
+                       net_nfc_service_llcp_add_state (conn_handover_selector);\r
+\r
+                       if (net_nfc_service_llcp_connection_handover_selector (conn_handover_selector, result) == false)\r
+                       {\r
+                               return false;\r
+                       }\r
+\r
+#endif\r
+               }\r
+       }\r
+\r
+       DEBUG_SERVER_MSG("handle->app_type = [%d]" , handle->app_type);\r
+\r
+       if (_net_nfc_check_client_handle ())\r
+       {\r
+               net_nfc_response_p2p_discovered_t req_msg = {0,};\r
+               req_msg.handle = handle;\r
+               req_msg.result = NET_NFC_OK;\r
+\r
+               _net_nfc_send_response_msg (NET_NFC_MESSAGE_P2P_DISCOVERED, &req_msg, sizeof (net_nfc_response_p2p_discovered_t), NULL);\r
+       }\r
+\r
+       DEBUG_SERVER_MSG("stand alone llcp service is finished");\r
+       return false;\r
+}\r
+\r
+\r
+static bool _net_nfc_service_llcp_state_process(net_nfc_request_msg_t *msg)\r
+{\r
+       net_nfc_request_llcp_msg_t *llcp_msg = (net_nfc_request_llcp_msg_t *)msg;\r
+       net_nfc_llcp_state_t *state = NULL;\r
+       bool result;\r
+       net_nfc_error_e error;\r
+\r
+       DEBUG_SERVER_MSG("llcp service by nfc-manager");\r
+\r
+       if (msg == NULL)\r
+       {\r
+               DEBUG_SERVER_MSG("msg is NULL");\r
+               return false;\r
+       }\r
+\r
+       state = (net_nfc_llcp_state_t *)(llcp_msg->user_param);\r
+\r
+       if (state == NULL || !net_nfc_service_llcp_is_valid_state(state))\r
+       {\r
+               DEBUG_SERVER_MSG("state is NULL");\r
+               return false;\r
+       }\r
+\r
+       switch (msg->request_type)\r
+       {\r
+       case NET_NFC_MESSAGE_SERVICE_LLCP_SOCKET_ACCEPTED_ERROR:\r
+       case NET_NFC_MESSAGE_SERVICE_LLCP_SOCKET_ERROR:\r
+               state->step = NET_NFC_STATE_SOCKET_ERROR;\r
+               break;\r
+\r
+       default:\r
+               break;\r
+       }\r
+\r
+       state->prev_result = llcp_msg->result;\r
+\r
+       DEBUG_SERVER_MSG("service type = [%d]", state->state);\r
+\r
+       switch (state->state)\r
+       {\r
+       case NET_NFC_STATE_EXCHANGER_SERVER :\r
+               DEBUG_SERVER_MSG("exchanger server service");\r
+               result = _net_nfc_service_llcp_snep_server(state, &error);\r
+               break;\r
+\r
+       case NET_NFC_STATE_EXCHANGER_CLIENT :\r
+               DEBUG_SERVER_MSG("exchanger client service");\r
+               memcpy(&current_llcp_client_state, state, sizeof(net_nfc_llcp_state_t));\r
+               result = _net_nfc_service_llcp_client(state, &error);\r
+               break;\r
+\r
+       case NET_NFC_STATE_EXCHANGER_SERVER_NPP :\r
+               DEBUG_SERVER_MSG("exchanger sesrver npp");\r
+               result = _net_nfc_service_llcp_npp_server(state, &error);\r
+               break;\r
+\r
+       case NET_NFC_STATE_CONN_HANDOVER_REQUEST :\r
+               DEBUG_SERVER_MSG("NET_NFC_STATE_CONN_HANDOVER_REQUEST");\r
+               result = net_nfc_service_llcp_connection_handover_requester(state, &error);\r
+               break;\r
+\r
+       case NET_NFC_STATE_CONN_HANDOVER_SELECT :\r
+               DEBUG_SERVER_MSG("NET_NFC_STATE_CONN_HANDOVER_SELECT");\r
+               result = net_nfc_service_llcp_connection_handover_selector(state, &error);\r
+               break;\r
+\r
+       default :\r
+               DEBUG_SERVER_MSG("Unkown state state name: %d", state->state);\r
+               return false;\r
+       }\r
+\r
+       return result;\r
+}\r
+\r
+bool net_nfc_service_llcp_process_accept(net_nfc_request_msg_t *msg)\r
+{\r
+       bool res = false;\r
+       net_nfc_request_accept_socket_t *accept = (net_nfc_request_accept_socket_t *)msg;\r
+       net_nfc_llcp_state_t *state = NULL;\r
+\r
+       if (accept == NULL || (void *)accept->user_param == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       net_nfc_server_set_server_state(NET_NFC_SNEP_SERVER_CONNECTED);\r
+\r
+       if (msg->request_type == NET_NFC_MESSAGE_SERVICE_LLCP_ACCEPT)\r
+       {\r
+               state = (net_nfc_llcp_state_t *)accept->user_param;\r
+\r
+               state->incomming_socket = accept->incomming_socket;\r
+\r
+               DEBUG_SERVER_MSG("Incomming socket : %X", state->incomming_socket);\r
+\r
+               res = _net_nfc_service_llcp_state_process(msg);\r
+       }\r
+\r
+       return res;\r
+}\r
+\r
+bool net_nfc_service_llcp_disconnect_target(net_nfc_request_msg_t *msg)\r
+{\r
+       net_nfc_request_llcp_msg_t *llcp_msg = (net_nfc_request_llcp_msg_t *)msg;\r
+       net_nfc_target_handle_s *handle = NULL;\r
+\r
+       DEBUG_SERVER_MSG("llcp disconnect target");\r
+\r
+       if (llcp_msg == NULL)\r
+               return false;\r
+\r
+       handle = (net_nfc_target_handle_s *)llcp_msg->user_param;\r
+       if (handle != NULL)\r
+       {\r
+               net_nfc_error_e result = NET_NFC_OK;\r
+\r
+               if (net_nfc_controller_disconnect(handle, &result) == false)\r
+               {\r
+                       if (result != NET_NFC_NOT_CONNECTED)\r
+                       {\r
+                               net_nfc_controller_exception_handler();\r
+                       }\r
+                       else\r
+                       {\r
+                               DEBUG_SERVER_MSG("target was not connected.");\r
+                       }\r
+               }\r
+               net_nfc_server_set_server_state(NET_NFC_SERVER_IDLE);\r
+       }\r
+       else\r
+       {\r
+               DEBUG_SERVER_MSG("the target ID = [0x%x] was not connected before. current device may be a TARGET");\r
+       }\r
+\r
+       if (_net_nfc_check_client_handle())\r
+       {\r
+               net_nfc_response_llcp_detached_t message = { 0, };\r
+               message.result = NET_NFC_OK;\r
+               _net_nfc_send_response_msg(NET_NFC_MESSAGE_P2P_DETACHED, &message, sizeof(net_nfc_response_llcp_detached_t), NULL);\r
+       }\r
+\r
+       llcp_msg->user_param = 0; /*detail message should be NULL, because the handle is already freed in disconnect function */\r
+\r
+       return true;\r
+}\r
+\r
+bool net_nfc_service_llcp_process_socket_error(net_nfc_request_msg_t *msg)\r
+{\r
+       net_nfc_request_llcp_msg_t *llcp_msg = (net_nfc_request_llcp_msg_t *)msg;\r
+       bool res = false;\r
+\r
+       if (msg == NULL)\r
+               return false;\r
+\r
+       if (_net_nfc_check_client_handle())\r
+       {\r
+               /* in case of slave mode */\r
+               net_nfc_response_llcp_socket_error_t *error = (net_nfc_response_llcp_socket_error_t *)llcp_msg->user_param;\r
+\r
+               error->error = llcp_msg->result;\r
+               DEBUG_SERVER_MSG("Socket error returned [%d]", error->error);\r
+               return _net_nfc_send_response_msg(NET_NFC_MESSAGE_LLCP_ERROR, error, sizeof(net_nfc_response_llcp_socket_error_t), NULL);\r
+       }\r
+\r
+       res = _net_nfc_service_llcp_state_process(msg);\r
+\r
+       llcp_msg->user_param = 0;\r
+\r
+       return res;\r
+}\r
+\r
+bool net_nfc_service_llcp_process_accepted_socket_error(net_nfc_request_msg_t *msg)\r
+{\r
+       net_nfc_request_llcp_msg_t *llcp_msg = (net_nfc_request_llcp_msg_t *)msg;\r
+       bool res = false;\r
+\r
+       if (msg == NULL)\r
+               return false;\r
+\r
+       if (_net_nfc_check_client_handle())\r
+       {\r
+               /* in case of slave mode the error message will be deliver to client stub*/\r
+               net_nfc_response_llcp_socket_error_t *error = (net_nfc_response_llcp_socket_error_t *)llcp_msg->user_param;\r
+               error->error = llcp_msg->result;\r
+               return _net_nfc_send_response_msg(NET_NFC_MESSAGE_LLCP_ERROR, error, sizeof(net_nfc_response_llcp_socket_error_t), NULL);\r
+       }\r
+\r
+       res = _net_nfc_service_llcp_state_process(msg);\r
+\r
+       llcp_msg->user_param = 0;\r
+\r
+       return res;\r
+}\r
+\r
+bool net_nfc_service_llcp_process_connect_socket(net_nfc_request_msg_t *msg)\r
+{\r
+       net_nfc_request_msg_t *llcp_msg = (net_nfc_request_msg_t *)msg;\r
+       bool res = false;\r
+\r
+       if (msg == NULL)\r
+               return false;\r
+\r
+       res = _net_nfc_service_llcp_state_process(msg);\r
+\r
+       llcp_msg->user_param = 0;\r
+\r
+       return res;\r
+}\r
+\r
+bool net_nfc_service_llcp_process_connect_sap_socket(net_nfc_request_msg_t *msg)\r
+{\r
+       net_nfc_request_llcp_msg_t *llcp_msg = (net_nfc_request_llcp_msg_t *)msg;\r
+       bool res = false;\r
+\r
+       if (msg == NULL)\r
+               return false;\r
+\r
+       if (_net_nfc_check_client_handle())\r
+       {\r
+               net_nfc_response_connect_sap_socket_t *detail = (net_nfc_response_connect_sap_socket_t *)llcp_msg->user_param;\r
+               detail->result = llcp_msg->result;\r
+               return _net_nfc_send_response_msg(NET_NFC_MESSAGE_LLCP_CONNECT_SAP, detail, sizeof(net_nfc_response_connect_sap_socket_t), NULL);\r
+       }\r
+       res = _net_nfc_service_llcp_state_process(msg);\r
+\r
+       llcp_msg->user_param = 0;\r
+\r
+       return res;\r
+}\r
+\r
+bool net_nfc_service_llcp_process_send_socket(net_nfc_request_msg_t *msg)\r
+{\r
+       net_nfc_request_msg_t *llcp_msg = (net_nfc_request_msg_t *)msg;\r
+       bool res = false;\r
+\r
+       if (msg == NULL)\r
+               return false;\r
+\r
+       res = _net_nfc_service_llcp_state_process(msg);\r
+\r
+       llcp_msg->user_param = 0;\r
+\r
+       return res;\r
+}\r
+\r
+bool net_nfc_service_llcp_process_send_to_socket(net_nfc_request_msg_t* msg)\r
+{\r
+       net_nfc_request_llcp_msg_t *llcp_msg = (net_nfc_request_llcp_msg_t *)msg;\r
+       bool res = false;\r
+\r
+       if (msg == NULL)\r
+               return false;\r
+\r
+       if (_net_nfc_check_client_handle())\r
+       {\r
+               /* in case of slave mode the error message will be deliver to client stub*/\r
+               net_nfc_response_send_socket_t *detail = (net_nfc_response_send_socket_t *)llcp_msg->user_param;\r
+               detail->result = llcp_msg->result;\r
+               return _net_nfc_send_response_msg(NET_NFC_MESSAGE_LLCP_SEND_TO, detail, sizeof(net_nfc_response_send_socket_t), NULL);\r
+       }\r
+       res = _net_nfc_service_llcp_state_process(msg);\r
+\r
+       llcp_msg->user_param = 0;\r
+\r
+       return res;\r
+}\r
+\r
+bool net_nfc_service_llcp_process_receive_socket(net_nfc_request_msg_t *msg)\r
+{\r
+       net_nfc_request_msg_t *llcp_msg = (net_nfc_request_msg_t *)msg;\r
+       bool res = false;\r
+\r
+       if (msg == NULL)\r
+               return false;\r
+\r
+       res = _net_nfc_service_llcp_state_process(msg);\r
+\r
+       llcp_msg->user_param = 0;\r
+\r
+       return res;\r
+}\r
+\r
+bool net_nfc_service_llcp_process_receive_from_socket(net_nfc_request_msg_t *msg)\r
+{\r
+       net_nfc_request_llcp_msg_t *llcp_msg = (net_nfc_request_llcp_msg_t *)msg;\r
+       bool res = false;\r
+\r
+       if (msg == NULL)\r
+               return false;\r
+\r
+       if (_net_nfc_check_client_handle())\r
+       {\r
+               net_nfc_response_receive_socket_t *detail = (net_nfc_response_receive_socket_t *)llcp_msg->user_param;\r
+               detail->result = llcp_msg->result;\r
+               return _net_nfc_send_response_msg(NET_NFC_MESSAGE_LLCP_RECEIVE_FROM, detail, sizeof(net_nfc_response_receive_socket_t),\r
+                       detail->data.buffer, detail->data.length, NULL);\r
+       }\r
+       res = _net_nfc_service_llcp_state_process(msg);\r
+\r
+       llcp_msg->user_param = 0;\r
+\r
+       return res;\r
+}\r
+\r
+bool net_nfc_service_llcp_process_disconnect_socket(net_nfc_request_msg_t *msg)\r
+{\r
+       net_nfc_request_llcp_msg_t *llcp_msg = (net_nfc_request_llcp_msg_t *)msg;\r
+       bool res = false;\r
+\r
+       if (msg == NULL)\r
+               return false;\r
+\r
+       if (_net_nfc_check_client_handle())\r
+       {\r
+               net_nfc_response_disconnect_socket_t *detail = (net_nfc_response_disconnect_socket_t *)llcp_msg->user_param;\r
+               detail->result = llcp_msg->result;\r
+               return _net_nfc_send_response_msg(NET_NFC_MESSAGE_LLCP_DISCONNECT, detail, sizeof(net_nfc_response_disconnect_socket_t), NULL);\r
+       }\r
+\r
+       res = _net_nfc_service_llcp_state_process(msg);\r
+\r
+       llcp_msg->user_param = 0;\r
+\r
+       return res;\r
+}\r
+\r
+net_nfc_error_e net_nfc_service_send_exchanger_msg(net_nfc_request_p2p_send_t *msg)\r
+{\r
+       net_nfc_error_e error = NET_NFC_OK;\r
+       data_s *ex_data = NULL;\r
+       net_nfc_llcp_state_t * exchange_state_client = NULL;\r
+\r
+       DEBUG_SERVER_MSG("send exchanger msg to remote client");\r
+\r
+       if(msg == NULL)\r
+       {\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+\r
+       if(msg->handle == NULL)\r
+       {\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+\r
+       _net_nfc_manager_util_alloc_mem(ex_data, sizeof(data_s));\r
+       if (ex_data == NULL)\r
+       {\r
+               DEBUG_SERVER_MSG(" alocation is failed");\r
+               return NET_NFC_ALLOC_FAIL;\r
+       }\r
+       ex_data->length = msg->data.length;\r
+\r
+       _net_nfc_manager_util_alloc_mem(ex_data->buffer, ex_data->length);\r
+       if (ex_data->buffer == NULL)\r
+       {\r
+               DEBUG_SERVER_MSG(" alocation is failed");\r
+               _net_nfc_manager_util_free_mem(ex_data);\r
+               return NET_NFC_ALLOC_FAIL;\r
+       }\r
+       memcpy(ex_data->buffer, &msg->data.buffer, msg->data.length);\r
+\r
+       _net_nfc_manager_util_alloc_mem(exchange_state_client, sizeof(net_nfc_llcp_state_t));\r
+       if (exchange_state_client == NULL)\r
+       {\r
+               DEBUG_SERVER_MSG(" alocation is failed");\r
+               _net_nfc_manager_util_free_mem(ex_data);\r
+               _net_nfc_manager_util_free_mem(ex_data->buffer);\r
+               return NET_NFC_ALLOC_FAIL;\r
+       }\r
+\r
+       exchange_state_client->handle = msg->handle;\r
+       exchange_state_client->state = NET_NFC_STATE_EXCHANGER_CLIENT;\r
+       exchange_state_client->step = NET_NFC_LLCP_STEP_01;\r
+       exchange_state_client->user_data = ex_data;\r
+       net_nfc_service_llcp_add_state(exchange_state_client);\r
+\r
+       if (_net_nfc_service_llcp_client(exchange_state_client, &error) == true)\r
+       {\r
+               return NET_NFC_OK;\r
+       }\r
+       else\r
+       {\r
+               DEBUG_SERVER_MSG("exchange client operation is failed");\r
+               return NET_NFC_OPERATION_FAIL;\r
+       }\r
+}\r
+\r
+net_nfc_error_e _net_nfc_service_llcp_get_server_configuration_value(char* service_name, char* attr_name, char* attr_value)\r
+{\r
+       if (service_name == NULL || attr_name == NULL || attr_value == NULL)\r
+       {\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+\r
+       FILE* fp = NULL;\r
+       char file_path[512] = { 0, };\r
+\r
+       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);\r
+\r
+       if ((fp = fopen(file_path, "r")) == NULL)\r
+       {\r
+               return NET_NFC_UNKNOWN_ERROR;\r
+       }\r
+\r
+       char temp[128] = { 0, };\r
+       while (fgets(temp, sizeof(temp), fp) != NULL)\r
+       {\r
+               net_nfc_util_strip_string(temp, 128);\r
+               char service_name_temp[128] = { 0, };\r
+\r
+               if (temp[0] == '#')\r
+                       continue;\r
+\r
+               if (temp[0] == '[')\r
+               {\r
+                       int i = 0;\r
+                       char ch = 0;\r
+\r
+                       while ((ch = temp[i++]) != '\n')\r
+                       {\r
+                               if (ch == ']')\r
+                               {\r
+                                       memcpy(service_name_temp, &temp[1], i - 2);\r
+                                       break;\r
+                               }\r
+                       }\r
+\r
+                       if (strlen(service_name_temp) != 0)\r
+                       {\r
+                               DEBUG_SERVER_MSG("[%s] is found", service_name_temp);\r
+                               if (strcmp(service_name_temp, service_name) == 0)\r
+                               {\r
+                                       DEBUG_SERVER_MSG("[%s] and [%s] are matched", service_name_temp, service_name);\r
+\r
+                                       while (fgets(temp, sizeof(temp), fp) != NULL)\r
+                                       {\r
+                                               if (strcmp(temp, "\n") == 0)\r
+                                                       break;\r
+\r
+                                               net_nfc_util_strip_string(temp, 128);\r
+\r
+                                               char* pos = NULL;\r
+\r
+                                               if ((pos = strstr(temp, "=")) != NULL)\r
+                                               {\r
+                                                       char attr_name_temp[64] = { 0, };\r
+\r
+                                                       memcpy(attr_name_temp, temp, pos - temp);\r
+\r
+                                                       DEBUG_SERVER_MSG("attr_name = [%s]", attr_name);\r
+\r
+                                                       if (strcmp(attr_name, attr_name_temp) == 0)\r
+                                                       {\r
+                                                               memcpy(attr_value, pos + 1, strlen(pos + 1) - 1);\r
+                                                               DEBUG_SERVER_MSG("attr_value = [%s]", attr_value);\r
+\r
+                                                               if (fp != NULL)\r
+                                                                       fclose(fp);\r
+\r
+                                                               return NET_NFC_OK;\r
+                                                       }\r
+\r
+                                               }\r
+                                               else\r
+                                                       break;\r
+\r
+                                       }\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+\r
+       if (fp != NULL)\r
+               fclose(fp);\r
+\r
+       return NET_NFC_NO_DATA_FOUND;\r
+\r
+}\r
+\r
+static bool _net_nfc_service_llcp_snep_server(net_nfc_llcp_state_t * state, net_nfc_error_e* result)\r
+{\r
+       bool need_clean_up = false;\r
+\r
+       if (result == NULL){\r
+               DEBUG_SERVER_MSG("result is NULL");\r
+               return false;\r
+       }\r
+\r
+       *result = NET_NFC_OK;\r
+\r
+       switch (state->step)\r
+       {\r
+               case NET_NFC_LLCP_STEP_01:\r
+               {\r
+                       DEBUG_SERVER_MSG("step 1");\r
+\r
+                       if(net_nfc_controller_llcp_create_socket(&(state->socket), NET_NFC_LLCP_SOCKET_TYPE_CONNECTIONORIENTED, SNEP_MAX_BUFFER, 1, result, state) == false)    {\r
+                               state->step = NET_NFC_STATE_ERROR;\r
+                               break;\r
+                       }\r
+\r
+                       DEBUG_SERVER_MSG("bind server socket with service acess point = [0x%x]",  SNEP_SAP);\r
+                       if(net_nfc_controller_llcp_bind(state->socket, SNEP_SAP, result) == false){\r
+                               state->step = NET_NFC_STATE_ERROR;\r
+                               break;\r
+                       }\r
+\r
+                       DEBUG_SERVER_MSG("listen server socket with service access name = [%s]", SNEP_SAN);\r
+                       state->step = NET_NFC_LLCP_STEP_02;\r
+                       if(net_nfc_controller_llcp_listen(state->handle, (uint8_t *)SNEP_SAN, state->socket, result, state) == false)\r
+                       {\r
+                               state->step = NET_NFC_STATE_ERROR;\r
+                               break;\r
+                       }\r
+\r
+                       state->type_app_protocol = NET_NFC_SNEP;\r
+\r
+               }\r
+               break;\r
+\r
+               case NET_NFC_LLCP_STEP_02:\r
+               {\r
+\r
+                       DEBUG_SERVER_MSG("step 2");\r
+\r
+                       if (state->prev_result != NET_NFC_OK) {\r
+                               DEBUG_SERVER_MSG("snep: listen is failed...");\r
+                               state->step = NET_NFC_STATE_ERROR;\r
+                               break;\r
+                       }\r
+\r
+                       net_nfc_llcp_state_t * new_client = NULL;\r
+                       _net_nfc_manager_util_alloc_mem (new_client,sizeof (net_nfc_llcp_state_t));\r
+\r
+                       new_client->handle = state->handle;\r
+                       new_client->state = state->state;\r
+                       new_client->socket = state->incomming_socket;\r
+                       new_client->step = NET_NFC_LLCP_STEP_03;\r
+                       new_client->user_data = NULL;\r
+\r
+                       memset(snep_server_data.buffer,  0x00, SNEP_MAX_BUFFER);\r
+                       snep_server_data.length = SNEP_MAX_BUFFER;\r
+\r
+                       current_llcp_server_state.handle = state->handle;\r
+                       current_llcp_server_state.socket = state->incomming_socket;\r
+\r
+                       net_nfc_service_llcp_add_state (new_client);\r
+\r
+                       if(net_nfc_controller_llcp_recv(new_client->handle, new_client->socket , &snep_server_data, result, new_client) == false){\r
+                               state->step = NET_NFC_STATE_ERROR;\r
+                               break;\r
+                       }\r
+               }\r
+               break;\r
+\r
+               case NET_NFC_LLCP_STEP_03:\r
+               {\r
+                       DEBUG_SERVER_MSG("step 3");\r
+                       DEBUG_SERVER_MSG("receive request msg from snep client");\r
+\r
+                       state->step = NET_NFC_LLCP_STEP_04;\r
+\r
+                       if (state->prev_result != NET_NFC_OK) {\r
+                               DEBUG_SERVER_MSG("snep : recevie is failed...");\r
+                               state->step = NET_NFC_STATE_ERROR;\r
+                               break;\r
+                       }\r
+\r
+                       uint8_t resp_code = 0;\r
+                       data_s* resp_msg = NULL;\r
+\r
+                       if(_net_nfc_service_llcp_snep_check_req_msg(&snep_server_data, &resp_code) != NET_NFC_OK)\r
+                       {\r
+\r
+                               DEBUG_SERVER_MSG("Not valid request msg = [0x%X]", resp_code);\r
+                               resp_msg = _net_nfc_service_llcp_snep_create_msg(resp_code, NULL);\r
+\r
+                               if(net_nfc_controller_llcp_send(state->handle, state->socket, resp_msg, result, state) == false)\r
+                               {\r
+\r
+                                       _net_nfc_manager_util_free_mem(resp_msg->buffer);\r
+                                       _net_nfc_manager_util_free_mem(resp_msg);\r
+                               }\r
+\r
+                       }\r
+                       else{\r
+\r
+                               uint32_t information_length = 0;\r
+                               if(_net_nfc_service_llcp_snep_get_information_length(&snep_server_data, &information_length) == NET_NFC_OK)\r
+                               {\r
+\r
+                                       DEBUG_SERVER_MSG("MAX capa of server is = [%d] and received byte is = [%d]", SNEP_MAX_BUFFER, snep_server_data.length);\r
+\r
+                                       /* msg = header(fixed 6 byte) + information(changable) */\r
+                                       if(information_length + 6 > SNEP_MAX_BUFFER){\r
+\r
+                                               DEBUG_SERVER_MSG("request msg length is too long to receive at a time");\r
+\r
+                                               DEBUG_SERVER_MSG("total msg length is = [%d]", information_length + 6);\r
+\r
+                                               data_s* fragment = (data_s *)calloc(1, sizeof(data_s));\r
+\r
+                                               if(fragment == NULL){\r
+                                                       state->step = NET_NFC_STATE_ERROR;\r
+                                                       break;\r
+                                               }\r
+\r
+                                               fragment->buffer = (uint8_t*)calloc(information_length + 6, sizeof(uint8_t));\r
+\r
+                                               if(fragment->buffer == NULL){\r
+                                                       state->step = NET_NFC_STATE_ERROR;\r
+                                                       _net_nfc_manager_util_free_mem (fragment);\r
+                                                       break;\r
+                                               }\r
+\r
+                                               state->step = NET_NFC_LLCP_STEP_05;\r
+\r
+                                               fragment->length = information_length + 6;\r
+                                               state->user_data = fragment;\r
+\r
+                                               memcpy(fragment->buffer, snep_server_data.buffer, snep_server_data.length);\r
+\r
+                                               /* set zero. this is first time */\r
+                                               state->fragment_offset = 0;\r
+                                               state->fragment_offset += snep_server_data.length;\r
+\r
+                                               resp_msg = _net_nfc_service_llcp_snep_create_msg(SNEP_RESP_CONT, NULL);\r
+\r
+                                               DEBUG_SERVER_MSG("send continue response msg");\r
+\r
+                                               if(net_nfc_controller_llcp_send(state->handle, state->socket, resp_msg, result, state) == false)\r
+                                               {\r
+                                                       _net_nfc_manager_util_free_mem(resp_msg->buffer);\r
+                                                       _net_nfc_manager_util_free_mem(resp_msg);\r
+                                               }\r
+\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               resp_msg = _net_nfc_service_llcp_snep_create_msg(SNEP_RESP_SUCCESS, NULL);\r
+\r
+                                               DEBUG_SERVER_MSG("send success response msg");\r
+\r
+                                               if(net_nfc_controller_llcp_send(state->handle, state->socket, resp_msg, result, state) == false)\r
+                                               {\r
+                                                       _net_nfc_manager_util_free_mem(resp_msg->buffer);\r
+                                                       _net_nfc_manager_util_free_mem(resp_msg);\r
+                                               }\r
+\r
+                                               net_nfc_util_play_target_detect_sound();\r
+\r
+                                               data_s temp = {NULL, 0};\r
+\r
+                                               /* version, command, information_length are head. */\r
+                                               temp.buffer = snep_server_data.buffer + sizeof(uint8_t) + sizeof(uint8_t) + sizeof(uint32_t);\r
+                                                if((_net_nfc_service_llcp_snep_get_information_length(&snep_server_data, &(temp.length))) == NET_NFC_OK)\r
+                                                {\r
+                                                       int client_context;\r
+\r
+                                                       DEBUG_SERVER_MSG("process received msg");\r
+\r
+                                                       if(net_nfc_server_get_current_client_context(&client_context) == true)\r
+                                                       {\r
+                                                               if(net_nfc_server_check_client_is_running(&client_context) == true)\r
+                                                               {\r
+                                                                       net_nfc_response_p2p_receive_t resp = {0};\r
+                                                                       data_s data;\r
+\r
+                                                                       _net_nfc_manager_util_alloc_mem (data.buffer, temp.length);\r
+\r
+                                                                       memcpy(data.buffer, temp.buffer, temp.length);\r
+\r
+                                                                       resp.data.length = temp.length;\r
+                                                                       resp.result = NET_NFC_OK;\r
+\r
+                                                                       _net_nfc_send_response_msg (NET_NFC_MESSAGE_P2P_RECEIVE, (void*)&resp, sizeof (net_nfc_response_p2p_receive_t),\r
+                                                                                       data.buffer, resp.data.length , NULL);\r
+                                                               }\r
+                                                       }\r
+                                                       net_nfc_service_msg_processing(&temp);\r
+                                                }\r
+                                       }\r
+                               }\r
+                       }\r
+               }\r
+               break;\r
+\r
+               case NET_NFC_LLCP_STEP_04:\r
+               {\r
+                       DEBUG_SERVER_MSG("step 4");\r
+\r
+                       if (state->prev_result != NET_NFC_OK)\r
+                       {\r
+                               DEBUG_SERVER_MSG("snep : sending is failed...");\r
+                               state->step = NET_NFC_STATE_ERROR;\r
+                               break;\r
+                       }\r
+                       else\r
+                       {\r
+                               net_nfc_error_e error;\r
+\r
+                               DEBUG_SERVER_MSG("snep : sending response is success...");\r
+                               state->step = NET_NFC_LLCP_STEP_02;\r
+                               state->handle = current_llcp_server_state.handle;\r
+                               state->incomming_socket = current_llcp_server_state.socket;\r
+\r
+                               _net_nfc_service_llcp_snep_server(state, &error);\r
+                       }\r
+\r
+               }\r
+               break;\r
+\r
+               case NET_NFC_LLCP_STEP_05:\r
+               {\r
+                       DEBUG_SERVER_MSG("step 5");\r
+\r
+                       if (state->prev_result != NET_NFC_OK)\r
+                       {\r
+                               DEBUG_SERVER_MSG("snep: sending CONT response is failed...");\r
+                               state->step = NET_NFC_STATE_ERROR;\r
+                               break;\r
+                       }\r
+\r
+                       state->step = NET_NFC_LLCP_STEP_06;\r
+\r
+                       memset(snep_server_data.buffer,  0x00, SNEP_MAX_BUFFER);\r
+                       snep_server_data.length = SNEP_MAX_BUFFER;\r
+\r
+                       if(net_nfc_controller_llcp_recv(state->handle, state->socket , &snep_server_data, result, state) == false)\r
+                       {\r
+                               state->step = NET_NFC_STATE_ERROR;\r
+                               break;\r
+                       }\r
+               }\r
+               break;\r
+\r
+               case NET_NFC_LLCP_STEP_06:\r
+               {\r
+                       DEBUG_SERVER_MSG("step 6");\r
+\r
+                       if (state->prev_result != NET_NFC_OK) {\r
+                               DEBUG_SERVER_MSG("snep: recv is failed...");\r
+                               state->step = NET_NFC_STATE_ERROR;\r
+                               break;\r
+                       }\r
+\r
+                       if(((data_s*)state->user_data)->length > (snep_server_data.length + state->fragment_offset))\r
+                       {\r
+\r
+                               /* receive more */\r
+                               /* copy fragment to buffer. */\r
+                               data_s* fragment = state->user_data;\r
+                               if(fragment != NULL)\r
+                               {\r
+                                       memcpy(fragment->buffer + state->fragment_offset, snep_server_data.buffer, snep_server_data.length);\r
+                                       state->fragment_offset += snep_server_data.length;\r
+                               }\r
+\r
+                               state->step = NET_NFC_LLCP_STEP_06;\r
+\r
+                               memset(snep_server_data.buffer,  0x00, SNEP_MAX_BUFFER);\r
+                               snep_server_data.length = SNEP_MAX_BUFFER;\r
+\r
+                               if(net_nfc_controller_llcp_recv(state->handle, state->socket , &snep_server_data, result, state) == false)\r
+                               {\r
+                                       state->step = NET_NFC_STATE_ERROR;\r
+                                       break;\r
+                               }\r
+\r
+                       }\r
+                       else if(((data_s*)state->user_data)->length == (snep_server_data.length + state->fragment_offset)){\r
+\r
+                               /* receving is completed */\r
+                               DEBUG_SERVER_MSG("recv is completed");\r
+\r
+                               data_s* fragment = state->user_data;\r
+\r
+                               if(fragment != NULL)\r
+                               {\r
+                                       memcpy(fragment->buffer + state->fragment_offset, snep_server_data.buffer, snep_server_data.length);\r
+                                       state->fragment_offset += snep_server_data.length;\r
+                               }\r
+\r
+                               data_s* resp_msg = _net_nfc_service_llcp_snep_create_msg(SNEP_RESP_SUCCESS, NULL);\r
+\r
+                               if(resp_msg != NULL)\r
+                               {\r
+                                       if(net_nfc_controller_llcp_send(state->handle, state->socket, resp_msg, result, state) == false)\r
+                                       {\r
+\r
+                                               _net_nfc_manager_util_free_mem(resp_msg->buffer);\r
+                                               _net_nfc_manager_util_free_mem(resp_msg);\r
+                                       }\r
+                               }\r
+\r
+                               net_nfc_util_play_target_detect_sound();\r
+\r
+                               data_s temp = {NULL, 0};\r
+\r
+                               /* version, command, information_length are head. */\r
+                               temp.buffer = ((data_s*)(state->user_data))->buffer + sizeof(uint8_t) + sizeof(uint8_t) + sizeof(uint32_t);\r
+                                if((_net_nfc_service_llcp_snep_get_information_length(((data_s*)(state->user_data)), &(temp.length))) == NET_NFC_OK)\r
+                                {\r
+\r
+                                       int client_context;\r
+\r
+\r
+                                       if(net_nfc_server_get_current_client_context(&client_context) == true)\r
+                                       {\r
+                                               if(net_nfc_server_check_client_is_running(&client_context) == true)\r
+                                               {\r
+                                                       net_nfc_response_p2p_receive_t resp = {0};\r
+                                                       data_s data;\r
+\r
+                                                       _net_nfc_manager_util_alloc_mem (data.buffer, temp.length);\r
+\r
+                                                       memcpy(data.buffer, temp.buffer, temp.length);\r
+\r
+                                                       resp.data.length = temp.length;\r
+                                                       resp.result = NET_NFC_OK;\r
+\r
+                                                       _net_nfc_send_response_msg (NET_NFC_MESSAGE_P2P_RECEIVE, (void*)&resp, sizeof (net_nfc_response_p2p_receive_t),\r
+                                                                       data.buffer, resp.data.length , NULL);\r
+                                               }\r
+                                       }\r
+\r
+                                       net_nfc_service_msg_processing(&temp);\r
+\r
+                                }\r
+\r
+                                _net_nfc_manager_util_free_mem(((data_s*)(state->user_data))->buffer);\r
+                                _net_nfc_manager_util_free_mem(state->user_data);\r
+                               state->user_data = NULL;\r
+                               state->step = 0;\r
+\r
+                       }\r
+                       else\r
+                       {\r
+                               DEBUG_SERVER_MSG("msg length is not matched. we have got more message");\r
+\r
+                               data_s* resp_msg = _net_nfc_service_llcp_snep_create_msg(SNEP_RESP_BAD_REQ, NULL);\r
+\r
+                               if(resp_msg != NULL)\r
+                               {\r
+                                       if(net_nfc_controller_llcp_send(state->handle, state->socket, resp_msg, result, state) == false)\r
+                                       {\r
+\r
+                                               _net_nfc_manager_util_free_mem(resp_msg->buffer);\r
+                                               _net_nfc_manager_util_free_mem(resp_msg);\r
+                                       }\r
+                               }\r
+                                _net_nfc_manager_util_free_mem(((data_s*)(state->user_data))->buffer);\r
+                                _net_nfc_manager_util_free_mem(state->user_data);\r
+                               state->user_data = NULL;\r
+                               state->step = 0;\r
+                       }\r
+               }\r
+               break;\r
+\r
+               case NET_NFC_STATE_SOCKET_ERROR:\r
+               {\r
+                       DEBUG_SERVER_MSG("snep : socket error is received %d", state->prev_result);\r
+                       need_clean_up = true;\r
+               }\r
+               break;\r
+\r
+               default:\r
+               {\r
+                       DEBUG_SERVER_MSG("unknown step = [%d]", state->step);\r
+                       need_clean_up = true;\r
+               }\r
+               break;\r
+\r
+       }\r
+\r
+       if(state->step == NET_NFC_STATE_ERROR)\r
+       {\r
+               net_nfc_util_play_target_detect_sound();\r
+               DEBUG_SERVER_MSG("nfc state error");\r
+               state->step = 0;\r
+       }\r
+\r
+       if (need_clean_up == true)\r
+       {\r
+               net_nfc_controller_llcp_socket_close (state->socket, result);\r
+               net_nfc_service_llcp_remove_state (state);\r
+               _net_nfc_manager_util_free_mem (state);\r
+       }\r
+\r
+       if (*result != NET_NFC_OK)\r
+       {\r
+               return false;\r
+       }\r
+       return true;\r
+}\r
+\r
+static bool _net_nfc_service_llcp_npp_server(net_nfc_llcp_state_t * state, net_nfc_error_e* result)\r
+{\r
+       bool need_clean_up = false;\r
+\r
+       DEBUG_SERVER_MSG("_net_nfc_service_llcp_npp_server");\r
+\r
+       if (result == NULL)\r
+       {\r
+               DEBUG_SERVER_MSG("result is NULL");\r
+               return false;\r
+       }\r
+       *result = NET_NFC_OK;\r
+\r
+       switch (state->step)\r
+       {\r
+               case NET_NFC_LLCP_STEP_01:\r
+               {\r
+                       DEBUG_SERVER_MSG("NPP step 1");\r
+\r
+                       if(net_nfc_controller_llcp_create_socket(&(state->socket), NET_NFC_LLCP_SOCKET_TYPE_CONNECTIONORIENTED, SNEP_MAX_BUFFER, 1, result, state) == false)\r
+                       {\r
+                               DEBUG_SERVER_MSG("creaete socket for npp FAIL");\r
+                               state->step = NET_NFC_STATE_ERROR;\r
+                               break;\r
+                       }\r
+\r
+                       if(net_nfc_controller_llcp_bind(state->socket, NPP_SAP, result) == false)\r
+                       {\r
+                               DEBUG_SERVER_MSG("bind socket for npp FAIL");\r
+                               state->step = NET_NFC_STATE_ERROR;\r
+                               break;\r
+                       }\r
+\r
+                       state->step = NET_NFC_LLCP_STEP_02;\r
+                       if(net_nfc_controller_llcp_listen(state->handle, (uint8_t *)NPP_SAN, state->socket, result, state) == false)\r
+                       {\r
+                               DEBUG_SERVER_MSG("listen socket for npp FAIL");\r
+                               state->step = NET_NFC_STATE_ERROR;\r
+                               break;\r
+                       }\r
+                       state->type_app_protocol = NET_NFC_NPP;\r
+               }\r
+               break;\r
+\r
+               case NET_NFC_LLCP_STEP_02:\r
+               {\r
+\r
+                       DEBUG_SERVER_MSG("step 2");\r
+\r
+                       if (state->prev_result != NET_NFC_OK)\r
+                       {\r
+                               DEBUG_SERVER_MSG("NPP: listen is failed...");\r
+                               state->step = NET_NFC_STATE_ERROR;\r
+                               break;\r
+                       }\r
+\r
+                       net_nfc_llcp_state_t * new_client = NULL;\r
+                       _net_nfc_manager_util_alloc_mem (new_client,sizeof (net_nfc_llcp_state_t));\r
+\r
+                       new_client->handle = state->handle;\r
+                       new_client->state = state->state;\r
+                       new_client->socket = state->incomming_socket;\r
+                       new_client->step = NET_NFC_LLCP_STEP_03;\r
+                       new_client->user_data = NULL;\r
+\r
+                       memset(snep_server_data.buffer,  0x00, SNEP_MAX_BUFFER);\r
+                       snep_server_data.length = SNEP_MAX_BUFFER;\r
+\r
+                       current_llcp_server_state.handle = state->handle;\r
+                       current_llcp_server_state.socket = state->incomming_socket;\r
+                       net_nfc_service_llcp_add_state (new_client);\r
+\r
+                       if(net_nfc_controller_llcp_recv(new_client->handle, new_client->socket , &snep_server_data, result, new_client) == false)\r
+                       {\r
+                               state->step = NET_NFC_STATE_ERROR;\r
+                               break;\r
+                       }\r
+               }\r
+               break;\r
+\r
+               case NET_NFC_LLCP_STEP_03:\r
+               {\r
+                       /* send back success response */\r
+                       DEBUG_SERVER_MSG("step 3");\r
+                       DEBUG_SERVER_MSG("receive request msg from snep client");\r
+\r
+                       state->step = NET_NFC_LLCP_STEP_04;\r
+\r
+                       if (state->prev_result != NET_NFC_OK)\r
+                       {\r
+                               DEBUG_SERVER_MSG("snep : recevie is failed...");\r
+                               state->step = NET_NFC_STATE_ERROR;\r
+                               break;\r
+                       }\r
+\r
+                       uint8_t resp_code = 0;\r
+                       data_s* resp_msg = NULL;\r
+\r
+                       if(_net_nfc_service_llcp_npp_check_req_msg(&snep_server_data, &resp_code) != NET_NFC_OK)\r
+                       {\r
+\r
+                               DEBUG_SERVER_MSG("Not valid request msg = [0x%X]", resp_code);\r
+                               state->step = NET_NFC_STATE_ERROR;\r
+                               break;\r
+                       }\r
+                       else\r
+                       {\r
+\r
+                               uint32_t information_length = 0;\r
+                               if(_net_nfc_service_llcp_npp_get_information_length(&snep_server_data, &information_length) == NET_NFC_OK){\r
+\r
+                                       DEBUG_SERVER_MSG("MAX capa of server is = [%d] and received byte is = [%d]", SNEP_MAX_BUFFER, snep_server_data.length);\r
+\r
+                                       /* msg = header(fixed 10 byte) + information(changable) */\r
+                                       if(information_length + 10 > SNEP_MAX_BUFFER)\r
+                                       {\r
+                                               DEBUG_SERVER_MSG("request msg length is too long to receive at a time");\r
+\r
+                                               DEBUG_SERVER_MSG("total msg length is = [%d]", information_length + 10);\r
+\r
+                                               data_s* fragment = (data_s *)calloc(1, sizeof(data_s));\r
+\r
+                                               if(fragment == NULL){\r
+                                                       state->step = NET_NFC_STATE_ERROR;\r
+                                                       break;\r
+                                               }\r
+\r
+                                               fragment->buffer = (uint8_t*)calloc(information_length + 10, sizeof(uint8_t));\r
+\r
+                                               if(fragment->buffer == NULL)\r
+                                               {\r
+                                                       state->step = NET_NFC_STATE_ERROR;\r
+                                                       _net_nfc_manager_util_free_mem (fragment);\r
+                                                       break;\r
+                                               }\r
+\r
+                                               state->step = NET_NFC_LLCP_STEP_05;\r
+\r
+                                               fragment->length = information_length + 10;\r
+                                               state->user_data = fragment;\r
+\r
+                                               memcpy(fragment->buffer, snep_server_data.buffer, snep_server_data.length);\r
+\r
+                                               /* set zero. this is first time */\r
+                                               state->fragment_offset = 0;\r
+                                               state->fragment_offset += snep_server_data.length;\r
+\r
+                                               resp_msg = _net_nfc_service_llcp_snep_create_msg(SNEP_RESP_CONT, NULL);\r
+\r
+                                               DEBUG_SERVER_MSG("send continue response msg");\r
+\r
+                                               if(net_nfc_controller_llcp_send(state->handle, state->socket, resp_msg, result, state) == false)\r
+                                               {\r
+\r
+                                                       _net_nfc_manager_util_free_mem(resp_msg->buffer);\r
+                                                       _net_nfc_manager_util_free_mem(resp_msg);\r
+                                               }\r
+\r
+                                       }\r
+                                       else /*the size of the ndef is smaller than the max size*/\r
+                                       {\r
+                                               DEBUG_SERVER_MSG("Success to receive the msg");\r
+\r
+                                               net_nfc_util_play_target_detect_sound();\r
+\r
+                                               data_s temp = {NULL, 0};\r
+\r
+                                               /* version, command, information_length are head. */\r
+                                               temp.buffer = snep_server_data.buffer + sizeof(uint8_t) + sizeof(uint8_t) + sizeof(uint32_t) + sizeof(uint32_t);\r
+                                               DEBUG_SERVER_MSG("check the string = [%s]" , temp.buffer );\r
+                                                if((_net_nfc_service_llcp_npp_get_information_length(&snep_server_data, &(temp.length))) == NET_NFC_OK)\r
+                                                {\r
+\r
+                                                       int client_context;\r
+\r
+                                                       DEBUG_SERVER_MSG("process received msg");\r
+\r
+                                                       if(net_nfc_server_get_current_client_context(&client_context) == true)\r
+                                                       {\r
+                                                               if(net_nfc_server_check_client_is_running(&client_context) == true)\r
+                                                               {\r
+\r
+                                                                       net_nfc_response_p2p_receive_t resp = {0};\r
+                                                                       data_s data;\r
+\r
+                                                                       _net_nfc_manager_util_alloc_mem (data.buffer, temp.length);\r
+\r
+                                                                       memcpy(data.buffer, temp.buffer, temp.length);\r
+\r
+                                                                       resp.data.length = temp.length;\r
+                                                                       resp.result = NET_NFC_OK;\r
+\r
+                                                                       _net_nfc_send_response_msg (NET_NFC_MESSAGE_P2P_RECEIVE, (void*)&resp, sizeof (net_nfc_response_p2p_receive_t),\r
+                                                                                       data.buffer, resp.data.length , NULL);\r
+\r
+                                                               }\r
+                                                       }\r
+                                                       net_nfc_service_msg_processing(&temp);\r
+                                                }\r
+                                       }\r
+                               }\r
+                       }\r
+\r
+               }\r
+               break;\r
+\r
+               case NET_NFC_LLCP_STEP_04:\r
+               {\r
+                       DEBUG_SERVER_MSG("step 4");\r
+\r
+                       if (state->prev_result != NET_NFC_OK)\r
+                       {\r
+                               DEBUG_SERVER_MSG("NPP : sending is failed...");\r
+                               state->step = NET_NFC_STATE_ERROR;\r
+                               break;\r
+                       }\r
+                       else\r
+                       {\r
+                               net_nfc_error_e error;\r
+\r
+                               DEBUG_SERVER_MSG("NPP : Receiving the message is success...");\r
+                               state->step = NET_NFC_LLCP_STEP_02;\r
+                               state->handle = current_llcp_server_state.handle;\r
+                               state->incomming_socket = current_llcp_server_state.socket;\r
+                               _net_nfc_service_llcp_npp_server(state, &error);\r
+\r
+                       }\r
+\r
+               }\r
+               break;\r
+\r
+               case NET_NFC_LLCP_STEP_05:\r
+               {\r
+                       DEBUG_SERVER_MSG("step 5");\r
+\r
+                       if (state->prev_result != NET_NFC_OK)\r
+                       {\r
+                               DEBUG_SERVER_MSG("NPP: sending CONT response is failed...");\r
+                               state->step = NET_NFC_STATE_ERROR;\r
+                               break;\r
+                       }\r
+\r
+                       state->step = NET_NFC_LLCP_STEP_06;\r
+\r
+                       memset(snep_server_data.buffer,  0x00, SNEP_MAX_BUFFER);\r
+                       snep_server_data.length = SNEP_MAX_BUFFER;\r
+\r
+                       if(net_nfc_controller_llcp_recv(state->handle, state->socket , &snep_server_data, result, state) == false)\r
+                       {\r
+                               state->step = NET_NFC_STATE_ERROR;\r
+                               break;\r
+                       }\r
+               }\r
+               break;\r
+\r
+               case NET_NFC_LLCP_STEP_06:\r
+               {\r
+                       DEBUG_SERVER_MSG("step 6");\r
+\r
+                       if (state->prev_result != NET_NFC_OK)\r
+                       {\r
+                               DEBUG_SERVER_MSG("snep: recv is failed...");\r
+                               state->step = NET_NFC_STATE_ERROR;\r
+                               break;\r
+                       }\r
+\r
+                       if(((data_s*)state->user_data)->length > (snep_server_data.length + state->fragment_offset)){\r
+\r
+                               /* receive more */\r
+                               /* copy fragment to buffer. */\r
+                               data_s* fragment = state->user_data;\r
+                               if(fragment != NULL)\r
+                               {\r
+                                       memcpy(fragment->buffer + state->fragment_offset, snep_server_data.buffer, snep_server_data.length);\r
+                                       state->fragment_offset += snep_server_data.length;\r
+                               }\r
+\r
+                               state->step = NET_NFC_LLCP_STEP_06;\r
+\r
+                               memset(snep_server_data.buffer,  0x00, SNEP_MAX_BUFFER);\r
+                               snep_server_data.length = SNEP_MAX_BUFFER;\r
+\r
+                               if(net_nfc_controller_llcp_recv(state->handle, state->socket , &snep_server_data, result, state) == false)\r
+                               {\r
+                                       state->step = NET_NFC_STATE_ERROR;\r
+                                       break;\r
+                               }\r
+\r
+                       }\r
+                       else if(((data_s*)state->user_data)->length == (snep_server_data.length + state->fragment_offset))\r
+                       {\r
+\r
+                               /* receving is completed  */\r
+                               DEBUG_SERVER_MSG("recv is completed");\r
+                               data_s* fragment = state->user_data;\r
+                               if(fragment != NULL)\r
+                               {\r
+                                       memcpy(fragment->buffer + state->fragment_offset, snep_server_data.buffer, snep_server_data.length);\r
+                                       state->fragment_offset += snep_server_data.length;\r
+                               }\r
+\r
+                               data_s* resp_msg = _net_nfc_service_llcp_snep_create_msg(SNEP_RESP_SUCCESS, NULL);\r
+\r
+                               if(resp_msg != NULL)\r
+                               {\r
+                                       if(net_nfc_controller_llcp_send(state->handle, state->socket, resp_msg, result, state) == false)\r
+                                       {\r
+                                               _net_nfc_manager_util_free_mem(resp_msg->buffer);\r
+                                               _net_nfc_manager_util_free_mem(resp_msg);\r
+                                       }\r
+                               }\r
+\r
+                               net_nfc_util_play_target_detect_sound();\r
+\r
+                               data_s temp = {NULL, 0};\r
+\r
+                               /* version, command, information_length are head. */\r
+                               temp.buffer = ((data_s*)(state->user_data))->buffer + sizeof(uint8_t) + sizeof(uint8_t) + sizeof(uint32_t);\r
+                                if((_net_nfc_service_llcp_snep_get_information_length(((data_s*)(state->user_data)), &(temp.length))) == NET_NFC_OK)\r
+                                {\r
+\r
+                                       int client_context;\r
+                                       if(net_nfc_server_get_current_client_context(&client_context) == true)\r
+                                       {\r
+                                               if(net_nfc_server_check_client_is_running(&client_context) == true)\r
+                                               {\r
+                                                       net_nfc_response_p2p_receive_t resp = {0};\r
+                                                       data_s data;\r
+\r
+                                                       _net_nfc_manager_util_alloc_mem (data.buffer, temp.length);\r
+\r
+                                                       memcpy(data.buffer, temp.buffer, temp.length);\r
+\r
+                                                       resp.data.length = temp.length;\r
+                                                       resp.result = NET_NFC_OK;\r
+\r
+                                                       _net_nfc_send_response_msg (NET_NFC_MESSAGE_P2P_RECEIVE, (void*)&resp, sizeof (net_nfc_response_p2p_receive_t),\r
+                                                                       data.buffer, resp.data.length , NULL);\r
+\r
+                                               }\r
+                                       }\r
+\r
+                                       net_nfc_service_msg_processing(&temp);\r
+\r
+                                }\r
+\r
+                                _net_nfc_manager_util_free_mem(((data_s*)(state->user_data))->buffer);\r
+                                _net_nfc_manager_util_free_mem(state->user_data);\r
+                               state->user_data = NULL;\r
+                               state->step = 0;\r
+                       }\r
+                       else\r
+                       {\r
+                               DEBUG_SERVER_MSG("msg length is not matched. we have got more message");\r
+\r
+                               data_s* resp_msg = _net_nfc_service_llcp_snep_create_msg(SNEP_RESP_BAD_REQ, NULL);\r
+\r
+                               if(resp_msg != NULL)\r
+                               {\r
+                                       if(net_nfc_controller_llcp_send(state->handle, state->socket, resp_msg, result, state) == false)\r
+                                       {\r
+\r
+                                               _net_nfc_manager_util_free_mem(resp_msg->buffer);\r
+                                               _net_nfc_manager_util_free_mem(resp_msg);\r
+                                       }\r
+                               }\r
+\r
+                               _net_nfc_manager_util_free_mem(((data_s*)(state->user_data))->buffer);\r
+                               _net_nfc_manager_util_free_mem(state->user_data);\r
+                               state->user_data = NULL;\r
+                               state->step = 0;\r
+                       }\r
+\r
+                       net_nfc_error_e error;\r
+\r
+                       state->step = NET_NFC_LLCP_STEP_02;\r
+                       state->handle = current_llcp_server_state.handle;\r
+                       state->incomming_socket = current_llcp_server_state.socket;\r
+                       _net_nfc_service_llcp_npp_server(state, &error);\r
+\r
+\r
+               }\r
+               break;\r
+\r
+               case NET_NFC_STATE_SOCKET_ERROR:\r
+               {\r
+                       DEBUG_SERVER_MSG("snep : socket error is received %d", state->prev_result);\r
+                       need_clean_up = true;\r
+               }\r
+               break;\r
+\r
+               default:\r
+               {\r
+                       DEBUG_SERVER_MSG("unknown step = [%d]", state->step);\r
+                       need_clean_up = true;\r
+               }\r
+               break;\r
+\r
+       }\r
+\r
+       if(state->step == NET_NFC_STATE_ERROR)\r
+       {\r
+               /* server should not notify exchanger result to client application. it MUST be handled in nfc-manager side */\r
+               net_nfc_util_play_target_detect_sound();\r
+               DEBUG_SERVER_MSG("nfc state error");\r
+               state->step = 0;\r
+       }\r
+\r
+\r
+       if (need_clean_up == true)\r
+       {\r
+               net_nfc_controller_llcp_socket_close (state->socket, result);\r
+               net_nfc_service_llcp_remove_state (state);\r
+               _net_nfc_manager_util_free_mem (state);\r
+       }\r
+\r
+       if (*result != NET_NFC_OK){\r
+               return false;\r
+       }\r
+       return true;\r
+}\r
+\r
+static bool _net_nfc_service_llcp_client(net_nfc_llcp_state_t * state, net_nfc_error_e* result)\r
+{\r
+\r
+       bool need_clean_up = false;\r
+\r
+       DEBUG_SERVER_MSG("_net_nfc_service_llcp_client [%d]" , state->step);\r
+\r
+       if (result == NULL)\r
+       {\r
+               DEBUG_SERVER_MSG("result is NULL");\r
+               return false;\r
+       }\r
+\r
+       *result = NET_NFC_OK;\r
+\r
+       if(((net_nfc_server_get_server_state() == NET_NFC_SNEP_CLIENT_CONNECTED) ||  (net_nfc_server_get_server_state() == NET_NFC_NPP_CLIENT_CONNECTED))\r
+               && state->step == NET_NFC_LLCP_STEP_01)\r
+       {\r
+               state->socket = current_llcp_client_state.socket;\r
+               state->type_app_protocol = current_llcp_client_state.type_app_protocol;\r
+               state->step = NET_NFC_LLCP_STEP_02;\r
+       }\r
+\r
+       switch (state->step)\r
+       {\r
+               case NET_NFC_LLCP_STEP_01:\r
+               {\r
+                       DEBUG_SERVER_MSG("step 1");\r
+\r
+                       if(net_nfc_controller_llcp_create_socket(&(state->socket), NET_NFC_LLCP_SOCKET_TYPE_CONNECTIONORIENTED, SNEP_MAX_BUFFER, 1, result, state) == false)\r
+                       {\r
+                               state->step = NET_NFC_STATE_ERROR;\r
+                               DEBUG_SERVER_MSG(" Fail to Create socket for SNEP in client.");\r
+                               break;\r
+                       }\r
+\r
+                       DEBUG_SERVER_MSG("connect to remote server with socket = [0x%x]", state->socket);\r
+\r
+                       state->step = NET_NFC_LLCP_STEP_02;\r
+\r
+                       if(net_nfc_controller_llcp_connect_by_url(state->handle, state->socket, (uint8_t *) SNEP_SAN, result, state) == true)\r
+                       {\r
+                               DEBUG_SERVER_MSG("Success to connect by url  for SNEP in client.");\r
+                               net_nfc_server_set_server_state(        NET_NFC_SNEP_CLIENT_CONNECTED);\r
+                               state->type_app_protocol = NET_NFC_SNEP;\r
+                               break;\r
+                       }\r
+                       else\r
+                       {\r
+                               state->step = NET_NFC_STATE_ERROR;\r
+                               DEBUG_SERVER_MSG("Fail to connect to  socket for snep & npp in client.");\r
+                               break;\r
+                       }\r
+               }\r
+               break;\r
+\r
+               case NET_NFC_LLCP_STEP_02:\r
+               {\r
+\r
+                       DEBUG_SERVER_MSG("step 2");\r
+\r
+                       if (state->prev_result != NET_NFC_OK) {\r
+                               DEBUG_SERVER_MSG("snep client: connect is failed [%d]", state->prev_result);\r
+\r
+                               if(NET_NFC_OPERATION_FAIL == state->prev_result)\r
+                               {\r
+                                       if(net_nfc_controller_llcp_connect_by_url(state->handle, state->socket, (uint8_t *) "com.android.npp", result, state) == true)\r
+                                       {\r
+                                               DEBUG_SERVER_MSG("Success to connect by url  for NPP in client.");\r
+                                               state->type_app_protocol = NET_NFC_NPP;\r
+                                               state->step = NET_NFC_LLCP_STEP_02;\r
+                                               net_nfc_server_set_server_state(NET_NFC_NPP_CLIENT_CONNECTED);\r
+\r
+                                               break;\r
+                                       }\r
+                               }\r
+                               else\r
+                               {\r
+                                       state->step = NET_NFC_STATE_ERROR;\r
+                               }\r
+                               break;\r
+                       }\r
+\r
+                       if(state->user_data == NULL)\r
+                       {\r
+                               DEBUG_SERVER_MSG("no data to send to server. just terminate client thread");\r
+                               state->step = NET_NFC_STATE_ERROR;\r
+                               break;\r
+                       }\r
+\r
+                       net_nfc_llcp_socket_option_s retmoe_socket_info = {0,0,0};\r
+                       if(net_nfc_controller_llcp_get_remote_socket_info (state->handle, state->socket, &retmoe_socket_info, result) == true)\r
+                       {\r
+                               state->max_capability = retmoe_socket_info.miu;\r
+                               DEBUG_SERVER_MSG("SERVER MIU = [%d]", state->max_capability);\r
+                       }\r
+                       else\r
+                       {\r
+                               state->max_capability = SNEP_MAX_BUFFER;\r
+                               DEBUG_SERVER_MSG("SERVER MIU = [%d]", state->max_capability);\r
+                       }\r
+\r
+                       data_s* req_msg = NULL;\r
+\r
+                       if(state->type_app_protocol == NET_NFC_SNEP)\r
+                       {\r
+                               req_msg = _net_nfc_service_llcp_snep_create_msg(SNEP_REQ_PUT, (data_s *)state->user_data);\r
+                       }\r
+                       else\r
+                       {\r
+                               req_msg = _net_nfc_service_llcp_npp_create_msg((data_s *)state->user_data);\r
+                       }\r
+\r
+                       _net_nfc_manager_util_free_mem (((data_s *)state->user_data)->buffer);\r
+                       _net_nfc_manager_util_free_mem (state->user_data);\r
+\r
+                       state->user_data = NULL;\r
+\r
+                       if(req_msg == NULL)\r
+                       {\r
+                               DEBUG_SERVER_MSG("failed to create req msg");\r
+                               state->step = NET_NFC_STATE_ERROR;\r
+                               break;\r
+                       }\r
+\r
+                       state->step = NET_NFC_LLCP_STEP_03;\r
+\r
+                       if(req_msg->length <= state->max_capability)\r
+                       {\r
+\r
+                               DEBUG_SERVER_MSG("send req data");\r
+\r
+                               if(net_nfc_controller_llcp_send(state->handle, state->socket, req_msg, result, state) == false)\r
+                               {\r
+                                       DEBUG_SERVER_MSG("failed to send req msg");\r
+                                       _net_nfc_manager_util_free_mem (req_msg->buffer);\r
+                                       _net_nfc_manager_util_free_mem (req_msg);\r
+                                       state->step = NET_NFC_STATE_ERROR;\r
+                                       break;\r
+                               }\r
+                               else\r
+                               {\r
+                                       _net_nfc_manager_util_free_mem (req_msg->buffer);\r
+                                       _net_nfc_manager_util_free_mem (req_msg);\r
+                               }\r
+                       }\r
+                       else{\r
+\r
+                               /* send first fragment */\r
+\r
+                               DEBUG_SERVER_MSG("send first fragment");\r
+\r
+                               data_s fragment = {NULL, 0};\r
+\r
+                               if((fragment.buffer = (uint8_t *)calloc(state->max_capability, sizeof(uint8_t))) == NULL)\r
+                               {\r
+                                       _net_nfc_manager_util_free_mem (req_msg->buffer);\r
+                                       _net_nfc_manager_util_free_mem (req_msg);\r
+                                       state->user_data = NULL;\r
+                                       state->step = NET_NFC_STATE_ERROR;\r
+                                       break;\r
+                               }\r
+\r
+                               memcpy(fragment.buffer, req_msg->buffer, state->max_capability);\r
+                               fragment.length = state->max_capability;\r
+\r
+                               data_s* extra_msg = NULL;\r
+\r
+                               if((extra_msg = (data_s*)calloc(1, sizeof(data_s))) == NULL)\r
+                               {\r
+                                       _net_nfc_manager_util_free_mem (req_msg->buffer);\r
+                                       _net_nfc_manager_util_free_mem (req_msg);\r
+                                       _net_nfc_manager_util_free_mem(fragment.buffer);\r
+                                       state->user_data = NULL;\r
+                                       state->step = NET_NFC_STATE_ERROR;\r
+                                       break;\r
+                               }\r
+\r
+                               if((extra_msg->buffer = calloc(req_msg->length - state->max_capability, sizeof(uint8_t))) == NULL)\r
+                               {\r
+                                       _net_nfc_manager_util_free_mem (req_msg->buffer);\r
+                                       _net_nfc_manager_util_free_mem (req_msg);\r
+                                       _net_nfc_manager_util_free_mem(extra_msg);\r
+                                       _net_nfc_manager_util_free_mem(fragment.buffer);\r
+                                       state->user_data = NULL;\r
+                                       state->step = NET_NFC_STATE_ERROR;\r
+                                       break;\r
+                               }\r
+\r
+                               extra_msg->length = req_msg->length - state->max_capability;\r
+                               memcpy(extra_msg->buffer, req_msg->buffer + state->max_capability, extra_msg->length);\r
+\r
+                               state->user_data = extra_msg;\r
+\r
+                               net_nfc_controller_llcp_send(state->handle, state->socket, &fragment, result, state);\r
+\r
+                               _net_nfc_manager_util_free_mem (req_msg->buffer);\r
+                               _net_nfc_manager_util_free_mem (req_msg);\r
+                               _net_nfc_manager_util_free_mem(fragment.buffer);\r
+                       }\r
+               }\r
+               break;\r
+\r
+               case NET_NFC_LLCP_STEP_03:\r
+               {\r
+                       DEBUG_SERVER_MSG("step 3");\r
+\r
+                       if (state->prev_result != NET_NFC_OK)\r
+                       {\r
+                               DEBUG_SERVER_MSG("snep client: llcp send is failed [%d]", state->prev_result);\r
+                               state->step = NET_NFC_STATE_ERROR;\r
+                               break;\r
+                       }\r
+\r
+                       state->step = NET_NFC_LLCP_STEP_04;\r
+\r
+                       if(state->type_app_protocol == NET_NFC_SNEP)\r
+                       {\r
+\r
+                               memset(snep_client_data.buffer,  0x00, SNEP_MAX_BUFFER);\r
+                               snep_client_data.length = SNEP_MAX_BUFFER;\r
+\r
+                               DEBUG_SERVER_MSG("try to recv server response");\r
+\r
+                               if(net_nfc_controller_llcp_recv(state->handle, state->socket , &snep_client_data, result, state) == false)\r
+                               {\r
+\r
+                                       DEBUG_SERVER_MSG("recv operation is failed");\r
+                                       state->step = NET_NFC_STATE_ERROR;\r
+                                       break;\r
+                               }\r
+                       }\r
+                       else\r
+                       {\r
+                               DEBUG_SERVER_MSG("NET_NFC_NPP. Don't use the response message. So we skip it!");\r
+                       }\r
+\r
+\r
+               }\r
+               break;\r
+\r
+               case NET_NFC_LLCP_STEP_04:\r
+               {\r
+                       DEBUG_SERVER_MSG("step 4");\r
+\r
+                       if (state->prev_result != NET_NFC_OK)\r
+                       {\r
+                               DEBUG_SERVER_MSG("snep client: llcp recv is failed [%d]", state->prev_result);\r
+                               state->step = NET_NFC_STATE_ERROR;\r
+                               break;\r
+                       }\r
+\r
+                       if(state->type_app_protocol == NET_NFC_NPP)\r
+                       {\r
+                               net_nfc_response_p2p_send_t req_msg = {0,};\r
+\r
+                               DEBUG_SERVER_MSG("It's NET_NFC_NPP. Send completed event to client!");\r
+                               net_nfc_util_play_target_detect_sound();\r
+\r
+\r
+                               req_msg.handle = state->handle;\r
+                               req_msg.result = NET_NFC_OK;\r
+\r
+                               _net_nfc_send_response_msg (NET_NFC_MESSAGE_P2P_SEND, &req_msg, sizeof (net_nfc_response_p2p_send_t), NULL);\r
+                               break;\r
+                       }\r
+\r
+                       uint8_t code = 0;\r
+\r
+                       if(_net_nfc_service_llcp_snep_check_resp_msg(&snep_client_data) == NET_NFC_OK)\r
+                       {\r
+\r
+                               if(_net_nfc_service_llcp_snep_get_code(&snep_client_data, &code) == NET_NFC_OK)\r
+                               {\r
+\r
+                                       if(code == SNEP_RESP_SUCCESS)\r
+                                       {\r
+\r
+                                               DEBUG_SERVER_MSG("success response");\r
+                                               net_nfc_util_play_target_detect_sound();\r
+\r
+                                               net_nfc_response_p2p_send_t req_msg = {0,};\r
+\r
+                                               req_msg.handle = state->handle;\r
+                                               req_msg.result = NET_NFC_OK;\r
+\r
+                                               _net_nfc_send_response_msg (NET_NFC_MESSAGE_P2P_SEND, &req_msg, sizeof (net_nfc_response_p2p_send_t), NULL);\r
+                                       }\r
+                                       else if(code == SNEP_RESP_CONT)\r
+                                       {\r
+\r
+                                               DEBUG_SERVER_MSG("continue response");\r
+\r
+                                               data_s* msg = state->user_data;\r
+\r
+                                               if(msg == NULL)\r
+                                               {\r
+                                                       state->step = NET_NFC_STATE_ERROR;\r
+                                                       break;\r
+                                               }\r
+\r
+                                               if(msg->length > state->max_capability)\r
+                                               {\r
+                                                       state->step = NET_NFC_LLCP_STEP_05;\r
+\r
+                                                       data_s fragment = {NULL, 0};\r
+                                                       data_s* extra_msg = NULL;\r
+\r
+                                                       if((fragment.buffer = (uint8_t *)calloc(state->max_capability, sizeof(uint8_t))) == NULL)\r
+                                                       {\r
+                                                               _net_nfc_manager_util_free_mem(msg->buffer);\r
+                                                               _net_nfc_manager_util_free_mem(msg);\r
+                                                               state->user_data = NULL;\r
+                                                               state->step = NET_NFC_STATE_ERROR;\r
+                                                               break;\r
+                                                       }\r
+\r
+                                                       fragment.length = state->max_capability;\r
+                                                       memcpy(fragment.buffer, msg->buffer, state->max_capability);\r
+\r
+                                                       if((extra_msg = calloc(1, sizeof(data_s))) == NULL)\r
+                                                       {\r
+                                                               _net_nfc_manager_util_free_mem(fragment.buffer);\r
+                                                               _net_nfc_manager_util_free_mem(msg->buffer);\r
+                                                               _net_nfc_manager_util_free_mem(msg);\r
+                                                               state->step = NET_NFC_STATE_ERROR;\r
+                                                               state->user_data = NULL;\r
+                                                               break;\r
+                                                       }\r
+\r
+                                                       if((extra_msg->buffer = calloc(msg->length - state->max_capability, sizeof(uint8_t))) == NULL)\r
+                                                       {\r
+                                                               _net_nfc_manager_util_free_mem(extra_msg);\r
+                                                               _net_nfc_manager_util_free_mem(fragment.buffer);\r
+                                                               _net_nfc_manager_util_free_mem(msg->buffer);\r
+                                                               _net_nfc_manager_util_free_mem(msg);\r
+                                                               state->step = NET_NFC_STATE_ERROR;\r
+                                                               state->user_data = NULL;\r
+                                                               break;\r
+                                                       }\r
+\r
+                                                       extra_msg->length = msg->length - state->max_capability;\r
+                                                       memcpy(extra_msg->buffer, msg->buffer + state->max_capability, msg->length - state->max_capability);\r
+\r
+                                                       state->user_data = extra_msg;\r
+\r
+                                                       DEBUG_SERVER_MSG("send next fragment msg");\r
+                                                       net_nfc_controller_llcp_send(state->handle, state->socket, &fragment, result, state);\r
+\r
+                                                       _net_nfc_manager_util_free_mem(fragment.buffer);\r
+                                                       _net_nfc_manager_util_free_mem(msg->buffer);\r
+                                                       _net_nfc_manager_util_free_mem(msg);\r
+\r
+                                               }\r
+                                               else\r
+                                               {\r
+                                                       DEBUG_SERVER_MSG("send last fragment msg");\r
+                                                       net_nfc_util_play_target_detect_sound();\r
+                                                       state->step = NET_NFC_LLCP_STEP_06;\r
+\r
+                                                       net_nfc_controller_llcp_send(state->handle, state->socket, msg, result, state);\r
+\r
+                                                       _net_nfc_manager_util_free_mem(msg->buffer);\r
+                                                       _net_nfc_manager_util_free_mem(msg);\r
+\r
+                                                       state->user_data = NULL;\r
+                                               }\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               DEBUG_SERVER_MSG("error response = [%d] from server", code);\r
+                                       }\r
+                               }\r
+                       }\r
+                       else\r
+                       {\r
+                               DEBUG_SERVER_MSG("we have got error response");\r
+                       }\r
+               }\r
+               break;\r
+\r
+               case NET_NFC_LLCP_STEP_05:\r
+               {\r
+                       if (state->prev_result != NET_NFC_OK)\r
+                       {\r
+                               DEBUG_SERVER_MSG("snep client: llcp send is failed [%d]", state->prev_result);\r
+                               state->step = NET_NFC_STATE_ERROR;\r
+                               break;\r
+                       }\r
+\r
+                       /* check extra data */\r
+                       if(state->user_data == NULL)\r
+                       {\r
+                               state->step = NET_NFC_STATE_ERROR;\r
+                               break;\r
+                       }\r
+\r
+                       data_s* msg = state->user_data;\r
+\r
+                       if(msg->length > state->max_capability)\r
+                       {\r
+\r
+                               state->step = NET_NFC_LLCP_STEP_05;\r
+\r
+                               data_s fragment = {NULL, 0};\r
+                               data_s* extra_msg = NULL;\r
+\r
+                               fragment.buffer = (uint8_t *)calloc(state->max_capability, sizeof(uint8_t));\r
+                               fragment.length = state->max_capability;\r
+                               memcpy(fragment.buffer, msg->buffer, state->max_capability);\r
+\r
+                               extra_msg = calloc(1, sizeof(data_s));\r
+\r
+                               extra_msg->buffer = calloc(msg->length - state->max_capability, sizeof(uint8_t));\r
+                               extra_msg->length = msg->length - state->max_capability;\r
+                               memcpy(extra_msg->buffer, msg->buffer + state->max_capability, msg->length - state->max_capability);\r
+\r
+                               state->user_data = extra_msg;\r
+\r
+                               DEBUG_SERVER_MSG("send next fragment msg");\r
+                               net_nfc_controller_llcp_send(state->handle, state->socket, &fragment, result, state);\r
+\r
+                               _net_nfc_manager_util_free_mem(fragment.buffer);\r
+                               _net_nfc_manager_util_free_mem(msg->buffer);\r
+                               _net_nfc_manager_util_free_mem(msg);\r
+                       }\r
+                       else\r
+                       {\r
+\r
+                               state->step = NET_NFC_LLCP_STEP_06;\r
+\r
+                               DEBUG_SERVER_MSG("send last fragment msg");\r
+                               net_nfc_util_play_target_detect_sound();\r
+\r
+                               net_nfc_controller_llcp_send(state->handle, state->socket, msg, result, state);\r
+\r
+                               _net_nfc_manager_util_free_mem(msg->buffer);\r
+                               _net_nfc_manager_util_free_mem(msg);\r
+\r
+                               state->user_data = NULL;\r
+\r
+                       }\r
+\r
+               }\r
+               break;\r
+\r
+               case NET_NFC_LLCP_STEP_06:\r
+               {\r
+                       net_nfc_response_p2p_send_t req_msg = {0,};\r
+\r
+                       req_msg.handle = state->handle;\r
+\r
+                       if (state->prev_result != NET_NFC_OK)\r
+                       {\r
+                               DEBUG_SERVER_MSG("snep client: llcp send is failed [%d]", state->prev_result);\r
+\r
+                               req_msg.result = NET_NFC_P2P_SEND_FAIL;\r
+\r
+                               _net_nfc_send_response_msg (NET_NFC_MESSAGE_P2P_SEND, &req_msg, sizeof (net_nfc_response_p2p_send_t), NULL);\r
+                               state->step = NET_NFC_STATE_ERROR;\r
+                               break;\r
+                       }\r
+                       else\r
+                       {\r
+                               req_msg.result = NET_NFC_OK;\r
+\r
+                               _net_nfc_send_response_msg (NET_NFC_MESSAGE_P2P_SEND, &req_msg, sizeof (net_nfc_response_p2p_send_t), NULL);\r
+                       }\r
+\r
+                       DEBUG_SERVER_MSG("sending last fragment msg is ok");\r
+               }\r
+               break;\r
+\r
+               case NET_NFC_STATE_SOCKET_ERROR:\r
+               {\r
+                       DEBUG_SERVER_MSG("snep client: socket error is received [%d]", state->prev_result);\r
+                       need_clean_up = true;\r
+               }\r
+               break;\r
+\r
+               default:\r
+                       need_clean_up = true;\r
+               break;\r
+\r
+       }\r
+\r
+       if(state->step == NET_NFC_STATE_ERROR){\r
+               net_nfc_response_p2p_send_t req_msg = {0,};\r
+\r
+               req_msg.handle = state->handle;\r
+               req_msg.result = NET_NFC_P2P_SEND_FAIL;\r
+\r
+               net_nfc_util_play_target_detect_sound();\r
+               _net_nfc_send_response_msg (NET_NFC_MESSAGE_P2P_SEND, &req_msg, sizeof (net_nfc_response_p2p_send_t), NULL);\r
+               state->step = 0;\r
+       }\r
+\r
+       if (need_clean_up == true )\r
+       {\r
+               net_nfc_controller_llcp_socket_close (state->socket, result);\r
+               net_nfc_service_llcp_remove_state (state);\r
+               _net_nfc_manager_util_free_mem (state);\r
+       }\r
+\r
+       if (*result != NET_NFC_OK && *result != NET_NFC_BUSY)\r
+       {\r
+               DEBUG_SERVER_MSG("error = [%d]", *result);\r
+               return false;\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+static data_s* _net_nfc_service_llcp_snep_create_msg(snep_command_field_e resp_field, data_s* information)\r
+{\r
+       uint8_t response = (uint8_t)resp_field;\r
+       uint8_t version = 0;\r
+       uint32_t length_field = 0;\r
+\r
+       version = SNEP_MAJOR_VER;\r
+       version = (((version << 4) & 0xf0) | (SNEP_MINOR_VER & 0x0f));\r
+\r
+       data_s* snep_msg = NULL;\r
+\r
+       if(information == NULL){\r
+\r
+               length_field = 0;\r
+\r
+               if((snep_msg = (data_s*)calloc(1, sizeof(data_s))) == NULL){\r
+                       return NULL;\r
+               }\r
+\r
+               snep_msg->length = sizeof(uint8_t) + sizeof(uint8_t) + sizeof(uint32_t);\r
+               if((snep_msg->buffer = calloc(snep_msg->length, sizeof(uint8_t))) == NULL){\r
+\r
+                       _net_nfc_manager_util_free_mem(snep_msg);\r
+                       return NULL;\r
+               }\r
+\r
+               uint8_t* temp = snep_msg->buffer;\r
+\r
+               /* copy version */\r
+               *temp = version;\r
+               temp++;\r
+\r
+               /* copy response */\r
+               *temp = response;\r
+               temp++;\r
+       }\r
+       else\r
+       {\r
+\r
+               if((snep_msg = (data_s*)calloc(1, sizeof(data_s))) == NULL)\r
+               {\r
+                       return NULL;\r
+               }\r
+                                                       /* version        response              length                       payload*/\r
+               snep_msg->length = sizeof(uint8_t) + sizeof(uint8_t) + sizeof(uint32_t) + information->length;\r
+\r
+               if((snep_msg->buffer = (uint8_t *)calloc(snep_msg->length, sizeof(uint8_t))) == NULL)\r
+               {\r
+                       _net_nfc_manager_util_free_mem(snep_msg);\r
+                       return NULL;\r
+               }\r
+\r
+               memset(snep_msg->buffer,  0x00, snep_msg->length);\r
+\r
+               uint8_t* temp = snep_msg->buffer;\r
+\r
+               /* copy version */\r
+               *temp = version;\r
+               temp++;\r
+\r
+               /* copy response */\r
+               *temp = response;\r
+               temp++;\r
+\r
+               DEBUG_SERVER_MSG("information->length[%d]", information->length);\r
+               /* change the length data as network order for compatibility with android */\r
+               length_field = htonl(information->length);\r
+\r
+               /* length will be se 0. so we don't need to copy value */\r
+               memcpy(temp, &length_field, sizeof(uint32_t));\r
+               temp += sizeof(uint32_t);\r
+\r
+               /* copy ndef information to response msg */\r
+               memcpy(temp, information->buffer, information->length);\r
+       }\r
+       return snep_msg;\r
+}\r
+\r
+static data_s* _net_nfc_service_llcp_npp_create_msg( data_s* information)\r
+{\r
+       uint8_t version;\r
+       uint32_t length_field = 0;\r
+       uint32_t npp_ndef_entry = NPP_NDEF_ENTRY;\r
+       uint32_t big_endian_npp_ndef_entry = 0;\r
+\r
+       version = NPP_MAJOR_VER;\r
+       version = (((version << 4) & 0xf0) | (NPP_MINOR_VER & 0x0f));\r
+\r
+       data_s* npp_msg = NULL;\r
+\r
+       if(information == NULL)\r
+       {\r
+               length_field = 0;\r
+\r
+               if((npp_msg = (data_s*)calloc(1, sizeof(data_s))) == NULL)\r
+               {\r
+                       return NULL;\r
+               }\r
+                                              /* version               ndef entry       action code      message length*/\r
+               npp_msg->length = sizeof(uint8_t) + sizeof(uint32_t) + sizeof(uint8_t) + sizeof(uint32_t);\r
+               if((npp_msg->buffer = calloc(npp_msg->length, sizeof(uint8_t))) == NULL){\r
+\r
+                       _net_nfc_manager_util_free_mem(npp_msg);\r
+                       return NULL;\r
+               }\r
+\r
+               uint8_t* temp = npp_msg->buffer;\r
+\r
+               /* copy version */\r
+               *temp = version;\r
+               temp++;\r
+\r
+               /* copy npp ndef entry */\r
+               big_endian_npp_ndef_entry = htonl(npp_ndef_entry);\r
+               memcpy((void *)temp , (void *)&big_endian_npp_ndef_entry , sizeof(uint32_t));\r
+               temp += sizeof(uint32_t);\r
+       }\r
+       else\r
+       {\r
+\r
+               /*Make the npp header*/\r
+               net_nfc_llcp_npp_t npp_header_buffer;\r
+\r
+               npp_header_buffer.npp_version = version;\r
+               npp_header_buffer.npp_ndef_entry = htonl(NPP_NDEF_ENTRY);\r
+               npp_header_buffer.npp_action_code = NPP_ACTION_CODE;\r
+               npp_header_buffer.npp_ndef_length = htonl(information->length);\r
+\r
+               /*Make the npp message*/\r
+               if((npp_msg = (data_s*)calloc(1, sizeof(data_s))) == NULL)\r
+               {\r
+                       return NULL;\r
+               }\r
+\r
+               npp_msg->length = sizeof(net_nfc_llcp_npp_t) + information->length;\r
+\r
+               if((npp_msg->buffer = (uint8_t *)calloc(npp_msg->length, sizeof(uint8_t))) == NULL)\r
+               {\r
+                       _net_nfc_manager_util_free_mem(npp_msg);\r
+                       return NULL;\r
+               }\r
+\r
+               memset(npp_msg->buffer,  0x00 , npp_msg->length);\r
+\r
+               memcpy(npp_msg->buffer , &npp_header_buffer , sizeof(net_nfc_llcp_npp_t));\r
+\r
+               memcpy((npp_msg->buffer) + sizeof(net_nfc_llcp_npp_t), information->buffer, information->length);\r
+\r
+       }\r
+\r
+       return npp_msg;\r
+}\r
+\r
+static net_nfc_error_e _net_nfc_service_llcp_snep_check_req_msg(data_s* snep_msg, uint8_t* resp_code)\r
+{\r
+       /* version check */\r
+       /* command check */\r
+\r
+       if(snep_msg == NULL || snep_msg->buffer == NULL || resp_code == NULL)\r
+       {\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+\r
+       *resp_code = 0;\r
+\r
+       uint8_t* temp = NULL;\r
+       uint8_t version = 0;\r
+       bool is_supported_req = false;\r
+       uint8_t req = 0;\r
+\r
+       temp = snep_msg->buffer;\r
+\r
+       /* get vesrion. and compare it with ours */\r
+       version = *temp;\r
+\r
+       if(version == 0)\r
+       {\r
+               DEBUG_SERVER_MSG("no version is set");\r
+               *resp_code = SNEP_RESP_UNSUPPORTED_VER;\r
+               return NET_NFC_UNKNOWN_ERROR;\r
+       }\r
+       else\r
+       {\r
+               uint8_t major = (version & 0xf0) >> 4;\r
+               uint8_t minor = (version & 0x0f);\r
+\r
+               DEBUG_SERVER_MSG("major = [%d], minor = [%d]", major, minor);\r
+\r
+               if(major != SNEP_MAJOR_VER || minor > SNEP_MINOR_VER)\r
+               {\r
+                       DEBUG_SERVER_MSG("version is not matched");\r
+                       *resp_code = SNEP_RESP_UNSUPPORTED_VER;\r
+                       return NET_NFC_UNKNOWN_ERROR;\r
+               }\r
+       }\r
+\r
+       temp++;\r
+\r
+       /* get command */\r
+       req = *temp;\r
+       temp++;\r
+\r
+       switch(req)\r
+       {\r
+               case SNEP_REQ_CONTINUE :\r
+               case SNEP_REQ_PUT :\r
+               case SNEP_REQ_REJECT :\r
+                       is_supported_req = true;\r
+                       break;\r
+\r
+               case SNEP_REQ_GET :\r
+               default:\r
+                       is_supported_req = false;\r
+                       break;\r
+\r
+       }\r
+\r
+       if(is_supported_req == false)\r
+       {\r
+\r
+               DEBUG_SERVER_MSG("not supported req command");\r
+               *resp_code = SNEP_RESP_NOT_IMPLEMENT;\r
+               return NET_NFC_UNKNOWN_ERROR;\r
+       }\r
+\r
+       uint32_t information_length = 0;\r
+\r
+       memcpy(&information_length, temp, sizeof(uint32_t));\r
+\r
+       if(req == SNEP_REQ_PUT && information_length == 0)\r
+       {\r
+\r
+               DEBUG_SERVER_MSG("no information data is exist");\r
+               *resp_code = SNEP_RESP_BAD_REQ;\r
+               return NET_NFC_UNKNOWN_ERROR;\r
+       }\r
+\r
+       return NET_NFC_OK;\r
+}\r
+\r
+static net_nfc_error_e _net_nfc_service_llcp_npp_check_req_msg(data_s* npp_msg, uint8_t* resp_code)\r
+{\r
+       /* version check */\r
+       /* action code  check */\r
+\r
+       if(npp_msg == NULL || npp_msg->buffer == NULL || resp_code == NULL)\r
+       {\r
+\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+\r
+       *resp_code = 0;\r
+\r
+       uint8_t* temp = NULL;\r
+       uint8_t version = 0;\r
+       bool is_supported_req = false;\r
+       uint32_t ndef_entry_number = 0;\r
+       uint8_t action_codes = 0;\r
+\r
+       temp = npp_msg->buffer;\r
+\r
+       /* get vesrion. and compare it with ours */\r
+       version = *temp;\r
+\r
+       if(version == 0)\r
+       {\r
+               DEBUG_SERVER_MSG("no version is set");\r
+               *resp_code = NPP_RESP_UNSUPPORTED_VER;\r
+               return NET_NFC_UNKNOWN_ERROR;\r
+       }\r
+       else\r
+       {\r
+               uint8_t major = (version & 0xf0) >> 4;\r
+               uint8_t minor = (version & 0x0f);\r
+\r
+               DEBUG_SERVER_MSG("major = [%d], minor = [%d]", major, minor);\r
+\r
+               if(major != 0x00 || minor > 0x01)\r
+               {\r
+                       DEBUG_SERVER_MSG("version is not matched");\r
+                       *resp_code = NPP_RESP_UNSUPPORTED_VER;\r
+                       return NET_NFC_UNKNOWN_ERROR;\r
+               }\r
+\r
+       }\r
+\r
+       /*Increase the address. Because we already get the version of the npp. so we have to get the "number of ndef entry" */\r
+       temp++;\r
+\r
+       /* get command */\r
+       ndef_entry_number = ntohl (*((uint32_t *)(temp)));\r
+\r
+       DEBUG_SERVER_MSG("check the number of ndef entry = [%d]" , ndef_entry_number);\r
+       temp+= 4;\r
+\r
+       /* action code*/\r
+       memcpy(&action_codes, temp, sizeof(uint8_t));\r
+\r
+       DEBUG_SERVER_MSG("check the action_codes = [%d]" , action_codes);\r
+\r
+       switch(action_codes)\r
+       {\r
+               case 0x01 :\r
+                       is_supported_req = true;\r
+                       break;\r
+               default:\r
+                       is_supported_req = false;\r
+                       break;\r
+\r
+       }\r
+\r
+       if(is_supported_req == false){\r
+\r
+               DEBUG_SERVER_MSG("not supported action codes");\r
+               *resp_code = NPP_RESP_NOT_IMPLEMEN;\r
+               return NET_NFC_UNKNOWN_ERROR;\r
+       }\r
+\r
+       temp++;\r
+\r
+       uint32_t information_length = 0;\r
+\r
+       memcpy(&information_length, temp, sizeof(uint32_t));\r
+\r
+       if(action_codes != 0x01 || information_length == 0)\r
+       {\r
+\r
+               DEBUG_SERVER_MSG("no information data is exist");\r
+               *resp_code = NPP_RESP_UNSUPPORTED_VER;\r
+               return NET_NFC_UNKNOWN_ERROR;\r
+       }\r
+       return NET_NFC_OK;\r
+}\r
+\r
+static net_nfc_error_e _net_nfc_service_llcp_snep_get_code(data_s* snep_msg, uint8_t* code)\r
+{\r
+       if(snep_msg == NULL || snep_msg->buffer == NULL || code == NULL)\r
+       {\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+\r
+       uint8_t* temp = NULL;\r
+\r
+       temp = snep_msg->buffer;\r
+\r
+       temp++;\r
+\r
+       *code = *temp;\r
+\r
+       return NET_NFC_OK;\r
+}\r
+\r
+static net_nfc_error_e _net_nfc_service_llcp_snep_get_information_length(data_s* snep_msg, uint32_t* length)\r
+{\r
+       if(snep_msg == NULL || snep_msg->buffer == NULL)\r
+       {\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+\r
+       uint8_t* temp = NULL;\r
+       uint32_t temp_length = 0;\r
+\r
+       temp = snep_msg->buffer;\r
+       temp += 2;\r
+\r
+       /* change the length data as host order for compatibility with android */\r
+       temp_length = ntohl (*((uint32_t *)(temp)));\r
+       memcpy(length, &temp_length, sizeof(uint32_t));\r
+\r
+       DEBUG_SERVER_MSG("check the snep ndef length [%d]" , *length);\r
+\r
+       return NET_NFC_OK;\r
+}\r
+\r
+static net_nfc_error_e _net_nfc_service_llcp_npp_get_information_length(data_s* npp_msg, uint32_t* length)\r
+{\r
+       if(npp_msg == NULL || npp_msg->buffer == NULL){\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+\r
+       uint8_t* temp = NULL;\r
+       uint32_t temp_length = 0;\r
+\r
+       temp = npp_msg->buffer;\r
+       temp += 6;\r
+\r
+       DEBUG_SERVER_MSG("check the npp ndef length address= [%x]" , temp);\r
+\r
+       temp_length = ntohl (*((uint32_t *)(temp)));\r
+       memcpy(length, &temp_length, sizeof(uint32_t));\r
+\r
+       DEBUG_SERVER_MSG("check the npp ndef temp_length= [%d]" , temp_length);\r
+\r
+       DEBUG_SERVER_MSG("check the npp ndef length= [%d]" , *length);\r
+\r
+       return NET_NFC_OK;\r
+}\r
+\r
+static net_nfc_error_e _net_nfc_service_llcp_snep_check_resp_msg(data_s* snep_msg)\r
+{\r
+       /* version check */\r
+       /* command check */\r
+\r
+       if(snep_msg == NULL || snep_msg->buffer == NULL)\r
+       {\r
+\r
+               return NET_NFC_NULL_PARAMETER;\r
+       }\r
+\r
+       uint8_t* temp = NULL;\r
+       uint8_t version = 0;\r
+       bool is_supported_resp = false;\r
+       uint8_t resp = 0;\r
+\r
+       temp = snep_msg->buffer;\r
+\r
+       /* get vesrion. and compare it with ours */\r
+       version = *temp;\r
+\r
+       if(version == 0)\r
+       {\r
+               DEBUG_SERVER_MSG("version is wrong");\r
+               return NET_NFC_UNKNOWN_ERROR;\r
+       }\r
+       else\r
+       {\r
+               uint8_t major = (version & 0xf0) >> 4;\r
+               uint8_t minor = (version & 0x0f);\r
+\r
+               DEBUG_SERVER_MSG("major[%d], minor[%d]", major, minor);\r
+\r
+               if(major != SNEP_MAJOR_VER || minor > SNEP_MINOR_VER)\r
+               {\r
+                       DEBUG_SERVER_MSG("version is not matched");\r
+                       return NET_NFC_UNKNOWN_ERROR;\r
+               }\r
+\r
+       }\r
+\r
+       temp++;\r
+\r
+       /* get command */\r
+       resp = *temp;\r
+       temp++;\r
+\r
+       DEBUG_SERVER_MSG("result = [%d]", resp);\r
+\r
+       switch(resp)\r
+       {\r
+               case SNEP_RESP_CONT :\r
+               case SNEP_RESP_SUCCESS :\r
+               case SNEP_RESP_NOT_FOUND :\r
+               case SNEP_RESP_EXCESS_DATA :\r
+               case SNEP_RESP_BAD_REQ :\r
+               case SNEP_RESP_NOT_IMPLEMENT :\r
+               case SNEP_RESP_UNSUPPORTED_VER :\r
+               case SNEP_RESP_REJECT :\r
+                       is_supported_resp = true;\r
+                       break;\r
+               default:\r
+                       is_supported_resp = false;\r
+                       break;\r
+\r
+       }\r
+\r
+       if(is_supported_resp == false)\r
+       {\r
+               DEBUG_SERVER_MSG("not supported resp command = [%d]", resp);\r
+               return NET_NFC_UNKNOWN_ERROR;\r
+       }\r
+\r
+       uint32_t information_length = 0;\r
+\r
+       memcpy(&information_length, temp, sizeof(uint32_t));\r
+\r
+       if(resp != SNEP_RESP_SUCCESS && information_length != 0)\r
+       {\r
+               DEBUG_SERVER_MSG("error response should not have any information data");\r
+               return NET_NFC_UNKNOWN_ERROR;\r
+       }\r
+\r
+       return NET_NFC_OK;\r
+}\r
diff --git a/src/manager/net_nfc_service_llcp_handover.c b/src/manager/net_nfc_service_llcp_handover.c
new file mode 100644 (file)
index 0000000..9abfc1d
--- /dev/null
@@ -0,0 +1,1922 @@
+/*
+  * Copyright 2012  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://www.tizenopensource.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 "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_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_manager_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->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(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_manager_util_alloc_mem(context, sizeof(net_nfc_llcp_state_t));
+       if (context != NULL)
+       {
+               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(net_nfc_exchanger_event_e event, net_nfc_conn_handover_carrier_type_e type, data_s *data)
+{
+       int client_context = 0;
+
+       LOGD("[%s] START", __func__);
+
+       if (net_nfc_server_get_current_client_context(&client_context) == true)
+       {
+               if (net_nfc_server_check_client_is_running(&client_context) == true)
+               {
+                       int client_type = 0;
+                       if (net_nfc_server_get_client_type(client_context, &client_type) == 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(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(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_manager_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_manager_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->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_util_play_target_detect_sound();
+
+                       /* 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_util_play_target_detect_sound();
+               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_manager_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", result);
+               }
+       }
+       else
+       {
+               DEBUG_ERR_MSG("_net_nfc_util_create_ndef_message failed", 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_util_play_target_detect_sound();
+
+                       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", *result);
+                                       state->step = NET_NFC_STATE_ERROR;
+                               }
+                       }
+                       else
+                       {
+                               DEBUG_ERR_MSG("_net_nfc_service_handover_create_selector_message_from_rawdata failed", *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_util_play_target_detect_sound();
+               _net_nfc_service_llcp_handover_send_response(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_manager_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_manager_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_manager_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 > 0)
+                                       {
+                                               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 > 0)
+                                       {
+                                               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);
+                                               }
+                                       }
+
+                                       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_manager_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]");
+                       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]");
+                       break;
+
+               case NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN :
+                       DEBUG_MSG("[NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN]");
+                       break;
+
+               default :
+                       DEBUG_MSG("[unknown]");
+                       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 > 0)
+                       {
+                               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");
+
+                               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);
+
+                       /* send handover success message to client */
+                       _net_nfc_service_llcp_handover_send_response(NET_NFC_OK, NET_NFC_CONN_HANDOVER_CARRIER_BT, &data);
+
+                       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);
+               }
+               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 > 0)
+                       {
+                               oob->hash_len = MIN(sizeof(oob->hash), hash.length);
+                               memcpy(oob->hash, hash.buffer, oob->hash_len);
+                       }
+
+                       if (hash.length > 0)
+                       {
+                               oob->randomizer_len = MIN(sizeof(oob->randomizer), randomizer.length);
+                               memcpy(oob->randomizer, randomizer.buffer, oob->randomizer_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 100644 (file)
index 0000000..e918e1f
--- /dev/null
@@ -0,0 +1,383 @@
+/*\r
+  * Copyright 2012  Samsung Electronics Co., Ltd\r
+  *\r
+  * Licensed under the Flora License, Version 1.0 (the "License");\r
+  * you may not use this file except in compliance with the License.\r
+  * You may obtain a copy of the License at\r
+\r
+  *     http://www.tizenopensource.org/license\r
+  *\r
+  * Unless required by applicable law or agreed to in writing, software\r
+  * distributed under the License is distributed on an "AS IS" BASIS,\r
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+  * See the License for the specific language governing permissions and\r
+  * limitations under the License.\r
+  */\r
+\r
+#include "net_nfc_controller_private.h"\r
+#include "net_nfc_util_private.h"\r
+#include "net_nfc_typedef.h"\r
+#include "net_nfc_debug_private.h"\r
+#include "net_nfc_service_private.h"\r
+#include "net_nfc_app_util_private.h"\r
+#include "net_nfc_dbus_service_obj_private.h"\r
+#include "net_nfc_server_ipc_private.h"\r
+#include "net_nfc_server_dispatcher_private.h"\r
+#include "net_nfc_manager_util_private.h"\r
+#include "net_nfc_service_se_private.h"\r
+\r
+#include <pthread.h>\r
+#include <glib.h>\r
+#include <malloc.h>\r
+\r
+#include <TapiCommon.h>\r
+#include <TelSim.h>\r
+#include <ITapiSim.h>\r
+\r
+/* define */\r
+/* For ESE*/\r
+se_setting_t g_se_setting;\r
+\r
+\r
+/* For UICC */\r
+\r
+static unsigned int tapi_event_list[] =\r
+{\r
+        TAPI_EVENT_SIM_APDU_CNF,\r
+        TAPI_EVENT_SIM_ATR_CNF\r
+};\r
+\r
+typedef struct _uicc_context_t{\r
+       int req_id;\r
+       void* trans_param;\r
+}uicc_context_t;\r
+\r
+static unsigned int *p_event_subscription_ids = NULL;\r
+\r
+static bool net_nfc_service_check_sim_state(void);\r
+static int  sim_callback  (TelTapiEvent_t *sim_event);\r
+\r
+#define TAPI_EVENT_COUNT (sizeof(tapi_event_list) / sizeof(unsigned int))\r
+\r
+static GList * list = NULL;\r
+\r
+\r
+static int _compare_func (gconstpointer key1, gconstpointer key2)\r
+{\r
+       uicc_context_t * arg1 = (uicc_context_t*) key1;\r
+       uicc_context_t * arg2 = (uicc_context_t *) key2;\r
+\r
+       if (arg1->req_id < arg2->req_id){\r
+               return -1;\r
+       }\r
+       else if (arg1->req_id > arg2->req_id){\r
+               return 1;\r
+       }\r
+       else {\r
+               return 0;\r
+       }\r
+}\r
+\r
+static void _append_data(uicc_context_t* data)\r
+{\r
+       if (data != NULL)\r
+       {\r
+               list = g_list_append (list, data);\r
+       }\r
+}\r
+\r
+static uicc_context_t* _get_data(int req_id)\r
+{\r
+       if(list != NULL)\r
+       {\r
+\r
+               GList* found = NULL;\r
+\r
+               uicc_context_t value = {0, NULL};\r
+               value.req_id = req_id;\r
+\r
+               found = g_list_find_custom (list, &value, _compare_func );\r
+\r
+               if(found != NULL){\r
+                       return (uicc_context_t*)found->data;\r
+               }\r
+       }\r
+\r
+       return NULL;\r
+}\r
+\r
+static void _remove_data(uicc_context_t* data)\r
+{\r
+       if(list != NULL)\r
+       {\r
+\r
+               list = g_list_remove (list, data);\r
+       }\r
+}\r
+\r
+void net_nfc_service_se_detected(net_nfc_request_msg_t *msg)\r
+{\r
+       net_nfc_request_target_detected_t *detail_msg = NULL;\r
+       net_nfc_target_handle_s *handle = detail_msg->handle;\r
+       net_nfc_error_e state = NET_NFC_OK;\r
+       net_nfc_response_open_internal_se_t resp = { 0 };\r
+\r
+       if (msg == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       detail_msg = (net_nfc_request_target_detected_t *)(msg);\r
+       g_se_setting.current_ese_handle = handle;\r
+\r
+       DEBUG_SERVER_MSG("trying to connect to ESE = [0x%x]", handle);\r
+\r
+       if (!net_nfc_controller_connect(handle, &state))\r
+       {\r
+               DEBUG_SERVER_MSG("connect failed = [%d]", state);\r
+               resp.result = state;\r
+       }\r
+\r
+#ifdef BROADCAST_MESSAGE\r
+       net_nfc_server_set_server_state( NET_NFC_SE_CONNECTED);\r
+#endif\r
+\r
+       resp.handle = handle;\r
+       resp.trans_param = g_se_setting.open_request_trans_param;\r
+       resp.se_type = SECURE_ELEMENT_TYPE_ESE;\r
+\r
+       DEBUG_SERVER_MSG("trans param = [%d]", resp.trans_param);\r
+\r
+       _net_nfc_send_response_msg(NET_NFC_MESSAGE_OPEN_INTERNAL_SE, &resp, sizeof(net_nfc_response_open_internal_se_t), NULL);\r
+\r
+       g_se_setting.open_request_trans_param = NULL;\r
+}\r
+\r
+\r
+bool net_nfc_service_tapi_init(void)\r
+{\r
+       DEBUG_SERVER_MSG("tapi init");\r
+\r
+       unsigned int event_counts = TAPI_EVENT_COUNT;\r
+\r
+       if ( tel_init() == TAPI_API_SUCCESS)\r
+       {\r
+               if((p_event_subscription_ids = (unsigned int *)calloc(1, sizeof(tapi_event_list))) == NULL)\r
+               {\r
+                       return false;\r
+               }\r
+\r
+\r
+               int i = 0;\r
+\r
+               for(; i < event_counts; i++)\r
+               {\r
+                       tel_register_event(tapi_event_list[i], &(p_event_subscription_ids[i]), (TelAppCallback)sim_callback, NULL);\r
+               }\r
+\r
+       }\r
+       else\r
+       {\r
+               DEBUG_SERVER_MSG(" tel_init() failed");\r
+               return false;\r
+       }\r
+\r
+       tel_register_app_name("com.samsung.nfc");\r
+\r
+       DEBUG_SERVER_MSG(" tel_init() is success");\r
+\r
+       return net_nfc_service_check_sim_state();\r
+\r
+}\r
+\r
+void net_nfc_service_tapi_deinit(void)\r
+{\r
+       DEBUG_SERVER_MSG("deinit tapi");\r
+\r
+       unsigned int event_counts = TAPI_EVENT_COUNT;\r
+       int i = 0;\r
+\r
+       if(p_event_subscription_ids != NULL)\r
+       {\r
+               for(; i < event_counts; i++){\r
+                       tel_deregister_event(p_event_subscription_ids[i]);\r
+               }\r
+       }\r
+\r
+       tel_deinit();\r
+\r
+       if(p_event_subscription_ids != NULL)\r
+       {\r
+               free(p_event_subscription_ids);\r
+               p_event_subscription_ids = NULL;\r
+       }\r
+}\r
+\r
+bool net_nfc_service_transfer_apdu(data_s* apdu, void* trans_param)\r
+{\r
+       if(apdu == NULL)\r
+               return false;\r
+\r
+       TelSimApdu_t  apdu_data = {0};\r
+\r
+       apdu_data.apdu = apdu->buffer;\r
+       apdu_data.apdu_len = apdu->length;\r
+\r
+       DEBUG_SERVER_MSG("tranfer apdu \n");\r
+\r
+       int req_id = 0;\r
+       TapiResult_t error = tel_req_sim_apdu(&apdu_data, (int *)&req_id);\r
+\r
+       if(error != TAPI_API_SUCCESS)\r
+       {\r
+               DEBUG_SERVER_MSG("request sim apdu is failed with error = [%d] \n", error);\r
+               return false;\r
+       }\r
+       else\r
+       {\r
+               uicc_context_t* context = calloc(1, sizeof(uicc_context_t));\r
+\r
+               if(context != NULL)\r
+               {\r
+                       context->req_id = req_id;\r
+                       _append_data(context);\r
+               }\r
+\r
+               DEBUG_SERVER_MSG("sim apdu request is success \n");\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+bool net_nfc_service_request_atr(void* trans_param)\r
+{\r
+       int req_id = 0;\r
+       TapiResult_t error = tel_req_sim_atr((int *)&req_id);\r
+\r
+       if(error != TAPI_API_SUCCESS)\r
+       {\r
+               DEBUG_SERVER_MSG("failed to request ATR  = [%d]\n", error);\r
+               return false;\r
+       }\r
+       else\r
+       {\r
+               uicc_context_t* context = calloc(1, sizeof(uicc_context_t));\r
+\r
+               if(context != NULL)\r
+               {\r
+                       context->req_id = req_id;\r
+                       _append_data(context);\r
+               }\r
+\r
+               DEBUG_SERVER_MSG("request is success \n");\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+static bool net_nfc_service_check_sim_state(void)\r
+{\r
+       DEBUG_SERVER_MSG("check sim state");\r
+\r
+       TelSimCardStatus_t state = TAPI_API_SUCCESS;\r
+       int b_card_changed = 0;\r
+\r
+       TapiResult_t error  = tel_get_sim_init_info(&state, &b_card_changed);\r
+\r
+       DEBUG_SERVER_MSG("current sim init state = [%d] \n", state);\r
+\r
+       if(error != TAPI_API_SUCCESS)\r
+       {\r
+               DEBUG_SERVER_MSG("error = [%d] \n", error);\r
+               return false;\r
+       }\r
+       else if(state ==TAPI_SIM_STATUS_SIM_INIT_COMPLETED || state == TAPI_SIM_STATUS_SIM_INITIALIZING)\r
+       {\r
+               DEBUG_SERVER_MSG("sim is initialized \n");\r
+       }\r
+       else\r
+       {\r
+               DEBUG_SERVER_MSG("sim is not initialized \n");\r
+               return false;\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+static int  sim_callback  (TelTapiEvent_t *sim_event)\r
+{\r
+       DEBUG_SERVER_MSG("[SIM]Reques Id[%d]", sim_event->RequestId);\r
+       DEBUG_SERVER_MSG("[SIM]event state [%d]", sim_event->Status);\r
+\r
+       switch(sim_event->EventType)\r
+       {\r
+               case TAPI_EVENT_SIM_APDU_CNF:\r
+               {\r
+                       DEBUG_SERVER_MSG("TAPI_EVENT_SIM_APDU_CNF");\r
+\r
+                       net_nfc_response_send_apdu_t resp = {0};\r
+\r
+                       uicc_context_t* temp = _get_data(sim_event->RequestId);\r
+\r
+                       if(temp != NULL)\r
+                       {\r
+                               resp.trans_param = temp->trans_param;\r
+                               _remove_data(temp);\r
+                               free(temp);\r
+                       }\r
+                       else\r
+                       {\r
+                               resp.trans_param = NULL;\r
+                       }\r
+\r
+                       if(sim_event->Status == TAPI_API_SUCCESS)\r
+                       {\r
+                               resp.result = NET_NFC_OK;\r
+                       }\r
+                       else\r
+                       {\r
+                               resp.result = NET_NFC_OPERATION_FAIL;\r
+                       }\r
+\r
+                       if(sim_event->pData != NULL)\r
+                       {\r
+\r
+                               TelSimApduResp_t* apdu = (TelSimApduResp_t*)sim_event->pData;\r
+\r
+                               if(apdu->apdu_resp_len > 0)\r
+                               {\r
+                                       resp.data.length = apdu->apdu_resp_len;\r
+                                       DEBUG_MSG("send response send apdu msg");\r
+                                       _net_nfc_send_response_msg (NET_NFC_MESSAGE_SEND_APDU_SE, (void*)&resp, sizeof(net_nfc_response_send_apdu_t), apdu->apdu_resp, apdu->apdu_resp_len, NULL);\r
+                               }\r
+                               else\r
+                               {\r
+                                       DEBUG_MSG("send response send apdu msg");\r
+                                       _net_nfc_send_response_msg (NET_NFC_MESSAGE_SEND_APDU_SE, (void*)&resp, sizeof(net_nfc_response_send_apdu_t), NULL);\r
+                               }\r
+                       }\r
+                       else\r
+                       {\r
+                               DEBUG_MSG("send response send apdu msg");\r
+                               _net_nfc_send_response_msg (NET_NFC_MESSAGE_SEND_APDU_SE, (void*)&resp, sizeof(net_nfc_response_send_apdu_t), NULL);\r
+                       }\r
+               }\r
+               break;\r
+\r
+               case TAPI_EVENT_SIM_ATR_CNF:\r
+               {\r
+                       DEBUG_SERVER_MSG("TAPI_EVENT_SIM_ATR_CNF");\r
+               }\r
+               break;\r
+\r
+               default:\r
+               {\r
+                       DEBUG_SERVER_MSG("[SIM]Undhandled event type [%d]", sim_event->EventType);\r
+                       DEBUG_SERVER_MSG("[SIM]Undhandled event state [%d]", sim_event->Status);\r
+               }\r
+               break;\r
+       }\r
+\r
+       return 0;\r
+}\r
+\r
diff --git a/src/manager/net_nfc_service_tag.c b/src/manager/net_nfc_service_tag.c
new file mode 100644 (file)
index 0000000..c13e852
--- /dev/null
@@ -0,0 +1,183 @@
+/*\r
+  * Copyright 2012  Samsung Electronics Co., Ltd\r
+  *\r
+  * Licensed under the Flora License, Version 1.0 (the "License");\r
+  * you may not use this file except in compliance with the License.\r
+  * You may obtain a copy of the License at\r
+\r
+  *     http://www.tizenopensource.org/license\r
+  *\r
+  * Unless required by applicable law or agreed to in writing, software\r
+  * distributed under the License is distributed on an "AS IS" BASIS,\r
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+  * See the License for the specific language governing permissions and\r
+  * limitations under the License.\r
+  */\r
+\r
+#include "net_nfc_controller_private.h"\r
+#include "net_nfc_util_private.h"\r
+#include "net_nfc_typedef.h"\r
+#include "net_nfc_debug_private.h"\r
+#include "net_nfc_service_private.h"\r
+#include "net_nfc_app_util_private.h"\r
+#include "net_nfc_dbus_service_obj_private.h"\r
+#include "net_nfc_server_ipc_private.h"\r
+#include "net_nfc_server_dispatcher_private.h"\r
+#include "net_nfc_manager_util_private.h"\r
+\r
+#include <pthread.h>\r
+#include <malloc.h>\r
+\r
+/* define */\r
+\r
+\r
+/* static variable */\r
+\r
+\r
+/* static callback function */\r
+\r
+\r
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r
+\r
+\r
+void net_nfc_service_watch_dog(net_nfc_request_msg_t* req_msg)\r
+{\r
+       net_nfc_request_watch_dog_t *detail_msg = NULL;\r
+       net_nfc_error_e result = NET_NFC_OK;\r
+       bool isPresentTarget = true;\r
+\r
+       if (req_msg == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       detail_msg = (net_nfc_request_watch_dog_t *)req_msg;\r
+\r
+       //DEBUG_SERVER_MSG("connection type = [%d]", detail_msg->handle->connection_type);\r
+\r
+       if ((detail_msg->handle->connection_type == NET_NFC_P2P_CONNECTION_TARGET) || (detail_msg->handle->connection_type == NET_NFC_TAG_CONNECTION))\r
+       {\r
+               isPresentTarget = net_nfc_controller_check_target_presence(detail_msg->handle, &result);\r
+       }\r
+       else\r
+       {\r
+               isPresentTarget = false;\r
+       }\r
+\r
+       if (isPresentTarget == true)\r
+       {\r
+               /* put message again */\r
+               net_nfc_dispatcher_queue_push(req_msg);\r
+       }\r
+       else\r
+       {\r
+               //DEBUG_SERVER_MSG("try to disconnect target = [%d]", detail_msg->handle);\r
+\r
+               if (net_nfc_controller_disconnect(detail_msg->handle, &result) == false)\r
+               {\r
+                       net_nfc_controller_exception_handler();\r
+               }\r
+\r
+#ifdef BROADCAST_MESSAGE\r
+               net_nfc_server_set_server_state( NET_NFC_SERVER_IDLE);\r
+#endif\r
+\r
+               if (_net_nfc_check_client_handle())\r
+               {\r
+                       int request_type = NET_NFC_MESSAGE_TAG_DETACHED;\r
+\r
+                       net_nfc_response_target_detached_t target_detached = { 0, };\r
+                       memset(&target_detached, 0x00, sizeof(net_nfc_response_target_detached_t));\r
+\r
+                       target_detached.devType = detail_msg->devType;\r
+                       target_detached.handle = detail_msg->handle;\r
+\r
+                       _net_nfc_send_response_msg(request_type, (void*)&target_detached, sizeof(net_nfc_response_target_detached_t), NULL);\r
+               }\r
+\r
+               _net_nfc_manager_util_free_mem(req_msg);\r
+\r
+               net_nfc_dispatcher_cleanup_queue();\r
+       }\r
+}\r
+\r
+void net_nfc_service_clean_tag_context(net_nfc_request_target_detected_t* stand_alone, net_nfc_error_e result)\r
+{\r
+       if(result == NET_NFC_OK)\r
+       {\r
+               bool isPresentTarget = true;\r
+               net_nfc_error_e result = NET_NFC_OK;\r
+\r
+               while(isPresentTarget)\r
+               {\r
+                       isPresentTarget = net_nfc_controller_check_target_presence (stand_alone->handle, &result);\r
+               }\r
+\r
+               if (net_nfc_controller_disconnect (stand_alone->handle, &result) == false)\r
+               {\r
+                       net_nfc_controller_exception_handler();\r
+               }\r
+       }\r
+       else\r
+       {\r
+\r
+               net_nfc_error_e result = NET_NFC_OK;\r
+\r
+               if(result != NET_NFC_TARGET_IS_MOVED_AWAY && result != NET_NFC_OPERATION_FAIL)\r
+               {\r
+                       bool isPresentTarget = true;\r
+\r
+                       while(isPresentTarget)\r
+                       {\r
+                               isPresentTarget = net_nfc_controller_check_target_presence (stand_alone->handle, &result );\r
+                       }\r
+               }\r
+\r
+               DEBUG_SERVER_MSG("try to disconnect target = [%d]", stand_alone->handle->connection_id);\r
+\r
+               if (net_nfc_controller_disconnect (stand_alone->handle, &result) == false)\r
+               {\r
+                       net_nfc_controller_exception_handler();\r
+               }\r
+       }\r
+\r
+#ifdef BROADCAST_MESSAGE\r
+       net_nfc_server_set_server_state(        NET_NFC_SERVER_IDLE);\r
+#endif\r
+\r
+}\r
+\r
+\r
+data_s* net_nfc_service_tag_process(net_nfc_target_handle_s* handle, int devType, net_nfc_error_e* result)\r
+{\r
+       net_nfc_error_e status = NET_NFC_OK;\r
+       data_s* recv_data = NULL;\r
+       *result = NET_NFC_OK;\r
+\r
+       DEBUG_SERVER_MSG("trying to connect to tag = [0x%x]", handle);\r
+\r
+       if (!net_nfc_controller_connect (handle, &status))\r
+       {\r
+               DEBUG_SERVER_MSG("connect failed");\r
+               *result = status;\r
+               return NULL;\r
+       }\r
+\r
+#ifdef BROADCAST_MESSAGE\r
+       net_nfc_server_set_server_state(NET_NFC_TAG_CONNECTED);\r
+#endif\r
+\r
+       DEBUG_SERVER_MSG("read ndef from tag");\r
+\r
+       if(net_nfc_controller_read_ndef (handle, &recv_data, &status) == true)\r
+       {\r
+               return recv_data;\r
+       }\r
+       else\r
+       {\r
+               DEBUG_SERVER_MSG("can not read card");\r
+               *result = status;\r
+               return NULL;\r
+       }\r
+\r
+}\r
diff --git a/src/manager/net_nfc_service_vconf.c b/src/manager/net_nfc_service_vconf.c
new file mode 100644 (file)
index 0000000..badd71e
--- /dev/null
@@ -0,0 +1,263 @@
+/*\r
+  * Copyright 2012  Samsung Electronics Co., Ltd\r
+  *\r
+  * Licensed under the Flora License, Version 1.0 (the "License");\r
+  * you may not use this file except in compliance with the License.\r
+  * You may obtain a copy of the License at\r
+\r
+  *     http://www.tizenopensource.org/license\r
+  *\r
+  * Unless required by applicable law or agreed to in writing, software\r
+  * distributed under the License is distributed on an "AS IS" BASIS,\r
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+  * See the License for the specific language governing permissions and\r
+  * limitations under the License.\r
+  */\r
+\r
+#include <vconf.h>\r
+#include <glib.h>\r
+#include <string.h>\r
+#include "net_nfc_typedef_private.h"\r
+#include "net_nfc_debug_private.h"\r
+#include "net_nfc_controller_private.h"\r
+#include "net_nfc_util_private.h"\r
+#include "net_nfc_server_dispatcher_private.h"\r
+#include "net_nfc_app_util_private.h"\r
+#include "aul.h"\r
+\r
+\r
+#define GALLERY_PKG_NAME_KEY NET_NFC_KEY_PREFIX"deb.com.samsung.gallery"\r
+#define CONTACT_PKG_NAME_KEY NET_NFC_KEY_PREFIX"deb.com.samsung.contacts"\r
+#define BROWSER_PKG_NAME_KEY NET_NFC_KEY_PREFIX"deb.com.samsung.browser"\r
+#define VIDEO_PKG_NAME_KEY NET_NFC_KEY_PREFIX"deb.com.samsung.video-player"\r
+\r
+#define NET_NFC_MODE_SE_KEY NET_NFC_KEY_PREFIX"se"\r
+#define NET_NFC_EEPROM_WRITEN NET_NFC_KEY_PREFIX"eeprom"\r
+\r
+\r
+#define NET_NFC_MODE_SE_ON 1\r
+#define NET_NFC_MODE_SE_OFF 0\r
+\r
+#define TIMEOUT 60 /* secs */\r
+\r
+#define NET_NFC_KEY_PREFIX "memory/nfc/client/"\r
+\r
+static guint g_source_id_gallery = 0;\r
+static guint g_source_id_contact = 0;\r
+static guint g_source_id_browser = 0;\r
+static guint g_source_id_video = 0;\r
+\r
+static bool is_EEPROM_writen = false;\r
+\r
+// static function\r
+\r
+static gboolean timedout_func(gpointer data);\r
+static void net_nfc_service_vconf_changed_cb(keynode_t* key, void* data);\r
+\r
+/////////////////////////////////////////////////////////////////////////\r
+\r
+\r
+\r
+static gboolean timedout_func(gpointer data)\r
+{\r
+       DEBUG_SERVER_MSG("timed out. clean up the value of key = [%s] \n", (char *)data);\r
+\r
+       vconf_set_str((char *)data, "");\r
+\r
+       if(strcmp((char *)data, GALLERY_PKG_NAME_KEY) == 0){g_source_id_gallery = 0;}\r
+       else if(strcmp((char *)data, CONTACT_PKG_NAME_KEY) == 0){g_source_id_contact = 0;}\r
+       else if(strcmp((char *)data, BROWSER_PKG_NAME_KEY) == 0){g_source_id_browser = 0;}\r
+       else if(strcmp((char *)data, VIDEO_PKG_NAME_KEY) == 0){g_source_id_video = 0;}\r
+\r
+       return FALSE;\r
+}\r
+\r
+static void net_nfc_service_se_setting_cb(keynode_t* key, void* data)\r
+{\r
+       DEBUG_SERVER_MSG("se vconf value is changed");\r
+\r
+       if(vconf_keynode_get_type(key) == VCONF_TYPE_INT)\r
+       {\r
+               net_nfc_request_set_se_t *msg = NULL;\r
+               int value = vconf_keynode_get_int(key);\r
+\r
+               if(value < NET_NFC_SE_CMD_UICC_ON  || value > NET_NFC_SE_CMD_ALL_ON)\r
+               {\r
+                       DEBUG_ERR_MSG("invalid value for setting SE mode");\r
+                       return;\r
+               }\r
+\r
+               _net_nfc_util_alloc_mem(msg, sizeof(net_nfc_request_set_se_t));\r
+               if(msg == NULL)\r
+               {\r
+                       DEBUG_ERR_MSG("failed to malloc");\r
+                       return;\r
+               }\r
+\r
+               msg->length =  sizeof(net_nfc_request_set_se_t);\r
+               msg->request_type = NET_NFC_MESSAGE_SERVICE_SE;\r
+               msg->se_type = value;\r
+\r
+               net_nfc_dispatcher_queue_push((net_nfc_request_msg_t *)msg);\r
+       }\r
+       else\r
+       {\r
+               DEBUG_ERR_MSG("unknown type for setting SE mode. only int type will be accepted");\r
+       }\r
+}\r
+\r
+static void net_nfc_service_vconf_changed_cb(keynode_t* key, void* data)\r
+{\r
+       DEBUG_SERVER_MSG("vconf value is changed");\r
+\r
+       if(vconf_keynode_get_type(key) == VCONF_TYPE_STRING)\r
+       {\r
+               char* str = vconf_keynode_get_str(key);\r
+               char* vconf_key = vconf_keynode_get_name(key);\r
+\r
+               if(str != NULL && (strlen(str) > 0))\r
+               {\r
+                       if( strcmp(vconf_key, GALLERY_PKG_NAME_KEY) == 0)\r
+                       {\r
+                               /* make g timer for key A */\r
+                               if(g_source_id_gallery != 0)\r
+                               {\r
+                                       g_source_remove(g_source_id_gallery);\r
+                                       g_source_id_gallery = 0;\r
+                               }\r
+\r
+                               g_source_id_gallery = g_timeout_add_seconds(TIMEOUT, timedout_func, GALLERY_PKG_NAME_KEY);\r
+                       }\r
+                       else if( strcmp(vconf_key, CONTACT_PKG_NAME_KEY) == 0)\r
+                       {\r
+                               /* make g timer for key B */\r
+                               if(g_source_id_contact != 0)\r
+                               {\r
+                                       g_source_remove(g_source_id_contact);\r
+                                       g_source_id_contact = 0;\r
+                               }\r
+                               g_source_id_contact = g_timeout_add_seconds(TIMEOUT, timedout_func, CONTACT_PKG_NAME_KEY);\r
+\r
+                       }\r
+                       else if( strcmp(vconf_key, BROWSER_PKG_NAME_KEY) == 0)\r
+                       {\r
+                               /* make g timer for key A */\r
+                               if(g_source_id_browser != 0)\r
+                               {\r
+                                       g_source_remove(g_source_id_browser);\r
+                                       g_source_id_browser = 0;\r
+                               }\r
+                               g_source_id_browser = g_timeout_add_seconds(TIMEOUT, timedout_func, BROWSER_PKG_NAME_KEY);\r
+\r
+                       }\r
+                       else if( strcmp(vconf_key, VIDEO_PKG_NAME_KEY) == 0)\r
+                       {\r
+                               /* make g timer for key A */\r
+                               if(g_source_id_video != 0)\r
+                               {\r
+                                       g_source_remove(g_source_id_video);\r
+                                       g_source_id_video = 0;\r
+                               }\r
+\r
+                               g_source_id_video = g_timeout_add_seconds(TIMEOUT, timedout_func, VIDEO_PKG_NAME_KEY);\r
+                       }\r
+                       else\r
+                       {\r
+                               DEBUG_SERVER_MSG("unknown key value is changed \n");\r
+                       }\r
+\r
+               }\r
+               else\r
+               {\r
+\r
+                       if( strcmp(vconf_key, GALLERY_PKG_NAME_KEY) == 0)\r
+                       {\r
+                               /* make g timer for key A */\r
+                               if(g_source_id_gallery != 0)\r
+                               {\r
+                                       g_source_remove(g_source_id_gallery);\r
+                                       g_source_id_gallery = 0;\r
+                               }\r
+                       }\r
+                       else if( strcmp(vconf_key, CONTACT_PKG_NAME_KEY) == 0)\r
+                       {\r
+                               /* make g timer for key B */\r
+                               if(g_source_id_contact != 0)\r
+                               {\r
+                                       g_source_remove(g_source_id_contact);\r
+                                       g_source_id_contact = 0;\r
+                               }\r
+\r
+                       }\r
+                       else if( strcmp(vconf_key, BROWSER_PKG_NAME_KEY) == 0)\r
+                       {\r
+                               /* make g timer for key A */\r
+                               if(g_source_id_browser != 0)\r
+                               {\r
+                                       g_source_remove(g_source_id_browser);\r
+                                       g_source_id_browser = 0;\r
+                               }\r
+\r
+                       }\r
+                       else if( strcmp(vconf_key, VIDEO_PKG_NAME_KEY) == 0)\r
+                       {\r
+                               /* make g timer for key A */\r
+                               if(g_source_id_video != 0)\r
+                               {\r
+                                       g_source_remove(g_source_id_video);\r
+                                       g_source_id_video = 0;\r
+                               }\r
+                       }\r
+                       else\r
+                       {\r
+                               DEBUG_ERR_MSG("unknown key \n");\r
+                       }\r
+\r
+                       DEBUG_SERVER_MSG("value is cleard. so turn off the timer \n");\r
+               }\r
+       }\r
+       else\r
+       {\r
+               DEBUG_ERR_MSG("unknown value type \n");\r
+       }\r
+}\r
+\r
+\r
+bool _net_nfc_check_pprom_is_completed ()\r
+{\r
+\r
+       int vconf_val= false;\r
+\r
+       if (is_EEPROM_writen) return true;\r
+       if (vconf_get_bool (NET_NFC_EEPROM_WRITEN, &vconf_val) != 0)\r
+       {\r
+               vconf_val = false;\r
+       }\r
+       if (vconf_val == true) return true;\r
+       return false;\r
+}\r
+\r
+void _net_nfc_set_pprom_is_completed ()\r
+{\r
+       vconf_set_bool (NET_NFC_EEPROM_WRITEN, true);\r
+       is_EEPROM_writen = true;\r
+}\r
+\r
+\r
+void net_nfc_service_vconf_register_notify_listener()\r
+{\r
+       vconf_notify_key_changed(GALLERY_PKG_NAME_KEY, net_nfc_service_vconf_changed_cb, NULL);\r
+       vconf_notify_key_changed(CONTACT_PKG_NAME_KEY, net_nfc_service_vconf_changed_cb, NULL);\r
+       vconf_notify_key_changed(BROWSER_PKG_NAME_KEY, net_nfc_service_vconf_changed_cb, NULL);\r
+       vconf_notify_key_changed(VIDEO_PKG_NAME_KEY, net_nfc_service_vconf_changed_cb, NULL);\r
+       vconf_notify_key_changed(NET_NFC_MODE_SE_KEY, net_nfc_service_se_setting_cb, NULL);\r
+}\r
+\r
+void net_nfc_service_vconf_unregister_notify_listener()\r
+{\r
+       vconf_ignore_key_changed(GALLERY_PKG_NAME_KEY, net_nfc_service_vconf_changed_cb);\r
+       vconf_ignore_key_changed(CONTACT_PKG_NAME_KEY, net_nfc_service_vconf_changed_cb);\r
+       vconf_ignore_key_changed(BROWSER_PKG_NAME_KEY, net_nfc_service_vconf_changed_cb);\r
+       vconf_ignore_key_changed(VIDEO_PKG_NAME_KEY, net_nfc_service_vconf_changed_cb);\r
+       vconf_ignore_key_changed(NET_NFC_MODE_SE_KEY, net_nfc_service_se_setting_cb);\r
+}\r
diff --git a/src/manager/resource/dbus_service.xml b/src/manager/resource/dbus_service.xml
new file mode 100644 (file)
index 0000000..e220029
--- /dev/null
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<node name="/com/samsung/slp/nfc/manager">
+
+  <interface name="com.samsung.slp.nfc.manager">
+
+    <method name="Launch">
+      <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="dbus_service_launch"/>
+      <arg type="u" name="result_val" direction="out"/>
+    </method>
+
+    <method name="Se_only">
+      <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="dbus_service_se_only"/>
+      <arg type="u" name="result_val" direction="out"/>
+    </method>
+
+    <method name="Terminate">
+      <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="dbus_service_terminate"/>
+      <arg type="u" name="result_val" direction="out"/>
+    </method>
+
+  </interface>
+</node>
diff --git a/src/manager/resource/nfc-manager-config.txt.in b/src/manager/resource/nfc-manager-config.txt.in
new file mode 100644 (file)
index 0000000..93f928d
--- /dev/null
@@ -0,0 +1,9 @@
+# NFC MANAGER SERVER LLCP CONFIG AND OPTION
+
+[service]
+data_exchange_service=true
+data_exchange_client=true
+connection_handover_service=true
+
+[option]
+ADD=on
diff --git a/test_clinet_app/bt_paring/Makefile b/test_clinet_app/bt_paring/Makefile
new file mode 100755 (executable)
index 0000000..b29816b
--- /dev/null
@@ -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 100644 (file)
index 0000000..703f9fd
--- /dev/null
@@ -0,0 +1,214 @@
+/*
+  * Copyright 2012  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://www.tizenopensource.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 <stdio.h>
+#include <stdlib.h>
+
+#include <bluetooth-api.h>
+#include <glib.h>
+
+#include <net_nfc.h>
+
+#include <pthread.h>
+
+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/nfc_client/Makefile b/test_clinet_app/nfc_client/Makefile
new file mode 100755 (executable)
index 0000000..82a1825
--- /dev/null
@@ -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 100644 (file)
index 0000000..eb0bd01
--- /dev/null
@@ -0,0 +1,3520 @@
+/*
+  * Copyright 2012  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://www.tizenopensource.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 <stdio.h>
+#include <stdlib.h>
+#include <net_nfc_typedef.h>
+#include <net_nfc.h>
+#include <net_nfc_exchanger.h>
+
+#include <pthread.h>
+#include "nfc_api_test.h"
+
+#include <glib.h>
+
+/* 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<count; i++)
+       {
+               PRINT_INFO("%d. %s START\n", i, nfcTestMatrix[i].testName);
+
+               if(nfcTestMatrix[i].testFn !=NULL){
+                       nfcTestMatrix[i].testResult = nfcTestMatrix[i].testFn(i, NULL);
+                       //print_test_result (nfcTestMatrix[i].testName, nfcTestMatrix[i].testResult);
+               }
+       }
+
+       return false;
+}
+
+int main()
+{
+
+       GMainLoop* loop = NULL;
+       loop = g_main_new(TRUE);
+
+       g_timeout_add_seconds(1, test_process_func, NULL); // 1secs
+       g_main_loop_run(loop);
+
+       return 0;
+}
+
+void print_test_result (char * str, net_nfc_test_result_e result)
+{
+       if (result == NET_NFC_TEST_OK){
+               PRINT_RESULT_SUCCESS("TEST [%s] is PASSED",str);
+       }
+       else if (result == NET_NFC_TEST_FAIL){
+               PRINT_RESULT_FAIL("TEST [%s] is FAILED",str);
+       }
+       else {
+               PRINT_INFO("TEST is being tested\n");
+       }
+}
+
+
+/*=================================================================================*/
+
+static net_nfc_test_result_e test_case_result;
+
+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 );
+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);
+
+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 )
+{
+       // do nothing
+}
+
+int nfcTestClientInit(uint8_t testNumber,void* arg_ptr2)
+{
+       net_nfc_error_e result;
+       result = net_nfc_initialize();
+       CHECK_RESULT(result);
+
+
+       result = net_nfc_set_response_callback (net_nfc_test_client_cb, NULL);
+       CHECK_RESULT(result);
+
+       result = net_nfc_unset_response_callback ();
+       CHECK_RESULT(result);
+
+       result = net_nfc_deinitialize ();
+       CHECK_RESULT(result);
+
+       return NET_NFC_TEST_OK;
+}
+
+
+net_nfc_exchanger_data_h net_nfc_exchanger_callback(net_nfc_exchanger_event_e event, void * user_param)
+{
+       PRINT_INFO(" event = [%d] \n", event);
+       test_case_result = NET_NFC_TEST_OK;
+
+       switch(event)
+       {
+               case NET_NFC_EXCHANGER_DATA_REQUESTED:
+               {
+                       PRINT_INFO("exchange is requested");
+                       net_nfc_exchanger_data_h ex_data = NULL;
+                       net_nfc_error_e error = NET_NFC_OK;
+                       data_h payload = NULL;
+
+/*
+                       uint8_t buffer[1024] = {0};
+
+                       int i = 0;
+                       for(; i< 1024; i++){
+                               buffer[i] = 'a';
+                       }
+
+                       net_nfc_create_data(&payload, buffer, 1024);
+*/
+
+                       if((error = net_nfc_create_exchanger_data(&ex_data, (uint8_t *)"http://www.samsung.com")) == NET_NFC_OK)
+                       //if((error = net_nfc_create_exchanger_url_type_data(&ex_data, NET_NFC_SCHEMA_FULL_URI, (uint8_t *)"file://test.txt")) == NET_NFC_OK)
+                       //if((error = net_nfc_create_exchanger_raw_type_data(&ex_data, "text/plain", payload)) == NET_NFC_OK)
+                       {
+                               return ex_data;
+                       }
+                       else
+                       {
+                               PRINT_INFO("create exchanger data is failed = [%d]", error);
+                               //pthread_cond_signal (&pcond);
+                               return NULL;
+                       }
+               }
+               case NET_NFC_EXCHANGER_TRANSFER_FAILED:
+               case NET_NFC_EXCHANGER_TRANSFER_COMPLETED:
+               default:
+               {
+                       //pthread_cond_signal (&pcond);
+
+                       if(event == NET_NFC_EXCHANGER_TRANSFER_COMPLETED)
+                       {
+                               PRINT_INFO("transfer exchanger msg is completed");
+                       }
+                       else
+                       {
+                               PRINT_INFO("transfer exchanger msg is failed");
+                       }
+
+                       return NULL;
+               }
+       }
+
+}
+
+/*=================================================================================*/
+static void net_nfc_test_reader_cb(net_nfc_message_e message, net_nfc_error_e result, void* data, void* user_param, void * trans_data)
+{
+       int user_context;
+
+       PRINT_INFO("user_param = [%d] trans_param = [%d]", user_param, trans_data);
+
+       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 id: %X\n", id);
+                       PRINT_INFO("Is NDEF supoort: %d\n", is_ndef);
+
+                       if (is_ndef){
+                               int actual_size;
+                               int max_size;
+                               net_nfc_get_tag_actual_data_size (target_info ,&actual_size);
+                               net_nfc_get_tag_max_data_size (target_info ,&max_size);
+                               PRINT_INFO("\tmax data [%d]\tactual data [%d]\n", max_size,actual_size );
+                               net_nfc_read_tag (id, (void *)2);
+                       }
+                       else{
+                               PRINT_INSTRUCT("Please use NDEF formated tag!!");
+                               test_case_result = NET_NFC_TEST_FAIL;
+                       }
+                       break;
+               }
+               case NET_NFC_MESSAGE_READ_NDEF:{
+                       if(data != NULL){
+                               ndef_message_h ndef = (ndef_message_h)(data);
+                               data_h rawdata;
+                               net_nfc_create_rawdata_from_ndef_message (ndef ,&rawdata);
+                               PRINT_INFO("read ndef message is ok, length is [%d]", net_nfc_get_data_length(rawdata));
+                               //_//net_nfc_ndef_print_message (ndef);
+                               /*
+
+                               if (memcmp(net_nfc_get_data_buffer (rawdata),nfcTestSpHex, net_nfc_get_data_length (rawdata)) == 0){
+                                       test_case_result = NET_NFC_TEST_OK;
+                               }
+                               */
+                       }
+                       pthread_mutex_lock (&plock);
+                       pthread_cond_signal (&pcond);
+                       pthread_mutex_unlock (&plock);
+                       break;
+               }
+               default:
+                       break;
+       }
+}
+
+
+static void net_nfc_test_format_cb(net_nfc_message_e message, net_nfc_error_e result, void* data, void* user_param, void * trans_data)
+{
+       int user_context;
+
+       PRINT_INFO("user_param = [%d] trans_param = [%d]", user_param, trans_data);
+
+       switch(message)
+       {
+               case NET_NFC_MESSAGE_TAG_DISCOVERED:{
+
+                       PRINT_INFO("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 id: %X\n", id);
+                       PRINT_INFO("Is NDEF supoort: %d\n", is_ndef);
+
+                       data_h ndef_key = NULL;
+                       net_nfc_mifare_create_net_nfc_forum_key(&ndef_key);
+                       net_nfc_format_ndef(id, ndef_key, NULL);
+
+               }
+               break;
+
+               case NET_NFC_MESSAGE_FORMAT_NDEF:{
+                       PRINT_INFO("NET_NFC_MESSAGE_FORMAT_NDEF");
+                       PRINT_INFO("result = [%d]", result);
+               }
+               break;
+               case NET_NFC_MESSAGE_TAG_DETACHED:
+               {
+                       PRINT_INFO("NET_NFC_MESSAGE_TAG_DETACHED");
+               }
+               break;
+               default:
+                       break;
+       }
+}
+
+static void net_nfc_test_se_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_GET_SE :
+               {
+                       PRINT_INFO("NET_NFC_MESSAGE_GET_SE result = [%d] se type = [%d]", result, *((uint8_t *)data));
+                       //net_nfc_set_secure_element_type(NET_NFC_SE_TYPE_ESE, NULL);
+                       net_nfc_set_secure_element_type(NET_NFC_SE_TYPE_UICC, NULL);
+               }
+               break;
+               case NET_NFC_MESSAGE_SET_SE :
+               {
+                       PRINT_INFO("NET_NFC_MESSAGE_SET_SE result = [%d] se type = [%d]", result, *((uint8_t *)data));
+                       net_nfc_open_internal_secure_element(NET_NFC_SE_TYPE_ESE, NULL);
+                       //net_nfc_open_internal_secure_element(NET_NFC_SE_TYPE_UICC, NULL);
+               }
+               break;
+               case NET_NFC_MESSAGE_OPEN_INTERNAL_SE :
+               {
+                       PRINT_INFO("NET_NFC_MESSAGE_OPEN_INTERNAL_SE result = [%d] and handle = [0x%x]", result, data);
+                       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
+                       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;
+}
+
+int nfcTestExchanger(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;
+
+       if((result = net_nfc_set_exchanger_cb(net_nfc_exchanger_callback, NULL)) != NET_NFC_OK){
+               test_case_result = NET_NFC_TEST_FAIL;
+               PRINT_INFO("failed to set exchanger_cb = [%d]", result);
+               return test_case_result;
+       }
+       else{
+               PRINT_INFO("setting exchange callback is ok = [%d]", result);
+       }
+
+/*
+       if((result = net_nfc_initialize()) != NET_NFC_NOT_ALLOWED_OPERATION){
+               test_case_result = NET_NFC_TEST_FAIL;
+               PRINT_INFO("NET_NFC_NOT_ALLOWED_OPERATION 1 is not returned = [%d]", result);
+               return test_case_result;
+       }else{
+               PRINT_INFO("net_nfc_init is failed = [%d]", result);
+       }
+
+       if((result = net_nfc_unset_exchanger_cb()) != NET_NFC_OK){
+               test_case_result = NET_NFC_TEST_FAIL;
+               PRINT_INFO("unset exchanger cb is failed = [%d]", result);
+               return test_case_result;
+       }else{
+               PRINT_INFO("unset ex cb is ok = [%d]", result);
+       }
+
+       if((result = net_nfc_initialize()) != NET_NFC_OK){
+               test_case_result = NET_NFC_TEST_FAIL;
+               PRINT_INFO("net_nfc_init is failed = [%d]", result);
+               return test_case_result;
+       }else{
+               PRINT_INFO("net_nfc_init is ok = [%d]", result);
+       }
+
+       if((result = net_nfc_set_exchanger_cb(net_nfc_exchanger_callback, NULL)) != NET_NFC_NOT_ALLOWED_OPERATION){
+               test_case_result = NET_NFC_TEST_FAIL;
+               PRINT_INFO("NET_NFC_NOT_ALLOWED_OPERATION 2 is not returned = [%d]", result);
+               return test_case_result;
+       }else{
+               PRINT_INFO("set ex cb is failed = [%d]", result);
+       }
+
+       if((result = net_nfc_deinitialize()) != NET_NFC_OK){
+               test_case_result = NET_NFC_TEST_FAIL;
+               PRINT_INFO("nfc deinit is failed = [%d]", result);
+               return test_case_result;
+       }else{
+               PRINT_INFO("net_nfc_deinit is ok = [%d]", result);
+       }
+
+       if((result = net_nfc_set_exchanger_cb(net_nfc_exchanger_callback, NULL)) != NET_NFC_OK){
+               PRINT_INFO("set exchanger cb is failed = [%d]", result);
+               test_case_result = NET_NFC_TEST_FAIL;
+               return test_case_result;
+       }else{
+               PRINT_INFO("settting ex cb is ok = [%d]", result);
+       }
+*/
+
+       //pthread_cond_wait (&pcond,&plock );
+
+       //PRINT_INFO("operation is end");
+       //result = net_nfc_unset_exchanger_cb();
+       //CHECK_RESULT(result);
+
+       test_case_result = NET_NFC_TEST_OK;
+
+       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 , &lto);
+                       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 , &lto);
+                       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 100644 (file)
index 0000000..a6196c1
--- /dev/null
@@ -0,0 +1,88 @@
+/*\r
+  * Copyright 2012  Samsung Electronics Co., Ltd\r
+  *\r
+  * Licensed under the Flora License, Version 1.0 (the "License");\r
+  * you may not use this file except in compliance with the License.\r
+  * You may obtain a copy of the License at\r
+\r
+  *     http://www.tizenopensource.org/license\r
+  *\r
+  * Unless required by applicable law or agreed to in writing, software\r
+  * distributed under the License is distributed on an "AS IS" BASIS,\r
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+  * See the License for the specific language governing permissions and\r
+  * limitations under the License.\r
+  */\r
+\r
+#ifndef __NET_NFC_TEST_H__\r
+#define __NET_NFC_TEST_H__\r
+\r
+typedef enum {\r
+       NET_NFC_TEST_NOT_YET,\r
+       NET_NFC_TEST_OK,\r
+       NET_NFC_TEST_FAIL,\r
+}net_nfc_test_result_e;\r
+\r
+\r
+#define LOG_COLOR_RED          "\033[0;31m"\r
+#define LOG_COLOR_GREEN        "\033[0;32m"\r
+#define LOG_COLOR_BROWN        "\033[0;33m"\r
+#define LOG_COLOR_BLUE                 "\033[0;34m"\r
+#define LOG_COLOR_PURPLE       "\033[0;35m"\r
+#define LOG_COLOR_CYAN                 "\033[0;36m"\r
+#define LOG_COLOR_LIGHTBLUE "\033[0;37m"\r
+#define LOG_COLOR_END          "\033[0;m"\r
+\r
+#define PRINT_INSTRUCT(format,args...) \\r
+do {\\r
+       printf(LOG_COLOR_BLUE""format""LOG_COLOR_END"\n", ##args);\\r
+}while(0);\r
+\r
+#define PRINT_RESULT_FAIL(format,args...) \\r
+do {\\r
+       printf(LOG_COLOR_RED""format""LOG_COLOR_END"\n", ##args);\\r
+}while(0);\r
+\r
+#define PRINT_RESULT_SUCCESS(format,args...) \\r
+do {\\r
+       printf(LOG_COLOR_GREEN""format""LOG_COLOR_END"\n", ##args);\\r
+}while(0);\r
+\r
+#define PRINT_INFO(format,args...) \\r
+do {\\r
+       printf(format"\n", ##args);\\r
+}while(0);\r
+\r
+\r
+#define CHECK_RESULT(X)\\r
+       do{\\r
+               if(X!=NET_NFC_OK){\\r
+                       PRINT_RESULT_FAIL("FILE:%s, LINE:%d, RESULT:%d",__FILE__,__LINE__,X);\\r
+                       return NET_NFC_TEST_FAIL;\\r
+               }\\r
+       }while(0)\r
+\r
+\r
+#define CHECK_ASSULT(X)\\r
+       do{\\r
+               if(!(X)){\\r
+                       PRINT_RESULT_FAIL("FILE:%s, LINE:%d, RESULT:%d",__FILE__,__LINE__,X);\\r
+                       return NET_NFC_TEST_FAIL;\\r
+               }\\r
+       }while(0)\r
+\r
+/* struct defines */\r
+typedef int nfcTestStartFn_t(uint8_t testNumber,void* arg_ptr2);\r
+\r
+typedef struct\r
+{\r
+  char*                                testName;\r
+  nfcTestStartFn_t*    testFn;\r
+  uint8_t                      testResult;\r
+} nfcTestType;\r
+\r
+\r
+\r
+\r
+#endif\r
+\r