From: Jihoon Jung Date: Mon, 15 Jun 2015 02:46:40 +0000 (+0900) Subject: Apply Tizen 2.4 nfc api X-Git-Tag: accepted/tizen/mobile/20150617.082148^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F88%2F41388%2F1;p=platform%2Fcore%2Fapi%2Fnfc.git Apply Tizen 2.4 nfc api Signed-off-by: Ji-hoon Jung Change-Id: If624822f8dc4a4b424afe1a299d833b603c49414 --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 6b4d14f..5f623ad 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,27 +11,36 @@ SET(Services "social" "telephony" "system" -) + ) # project SET(project_prefix "capi") +SET(prefix "/usr") +SET(version "0.0.3") +SET(maintainer "Seungkeun Lee , Kangho Hur") +SET(description "A NFC library in Tizen Native API") SET(service "network") SET(submodule "nfc") +# for package file +SET(dependents "dlog glib-2.0 gio-2.0 nfc capi-base-common vconf capi-system-info") +SET(pc_dependents "capi-base-common") + SET(fw_name "${project_prefix}-${service}-${submodule}") -PROJECT(${fw_name} C) -INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include) +PROJECT(${fw_name}) + +SET(CMAKE_INSTALL_PREFIX ${prefix}) +SET(PREFIX ${CMAKE_INSTALL_PREFIX}) +SET(LIBDIR ${CMAKE_LIB_DIR}) +SET(VERSION ${version}) + +SET(INC_DIR include) +INCLUDE_DIRECTORIES(${INC_DIR}) INCLUDE(FindPkgConfig) -IF(X11_SUPPORT) -pkg_check_modules(pkgs REQUIRED dlog glib-2.0 gio-2.0 nfc-common nfc capi-base-common - vconf ecore-x) -ELSE() -pkg_check_modules(pkgs REQUIRED dlog glib-2.0 gio-2.0 nfc-common nfc capi-base-common - vconf) -ENDIF(X11_SUPPORT) -FOREACH(flag ${pkgs_CFLAGS}) +pkg_check_modules(${fw_name} REQUIRED ${dependents}) +FOREACH(flag ${${fw_name}_CFLAGS}) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") ENDFOREACH(flag) @@ -42,35 +51,48 @@ IF("${ARCH}" STREQUAL "arm") ADD_DEFINITIONS("-DTARGET") ENDIF("${ARCH}" STREQUAL "arm") -IF(X11_SUPPORT) - ADD_DEFINITIONS("-DHAVE_X11") -ENDIF(X11_SUPPORT) ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"") +ADD_DEFINITIONS("-DTIZEN_DEBUG") -SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -Wl,--rpath=${LIB_INSTALL_DIR}") +SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -Wl,--rpath=${LIBDIR}") -SET(SOURCES src/nfc.c) +SET(SOURCES src/nfc_p2p.c + src/nfc_p2p_handover.c + src/nfc_tag.c + src/nfc_card_emulation.c + src/nfc_manager.c + src/nfc_common.c + src/nfc_ndef.c) ADD_LIBRARY(${fw_name} SHARED ${SOURCES}) -TARGET_LINK_LIBRARIES(${fw_name} ${pkgs_LDFLAGS}) -SET_TARGET_PROPERTIES(${fw_name} PROPERTIES VERSION ${FULLVER} SOVERSION ${MAJORVER}) -INSTALL(TARGETS ${fw_name} DESTINATION ${LIB_INSTALL_DIR}) +TARGET_LINK_LIBRARIES(${fw_name} ${${fw_name}_LDFLAGS}) + +SET_TARGET_PROPERTIES(${fw_name} + PROPERTIES + VERSION ${FULLVER} + SOVERSION ${MAJORVER} + CLEAN_DIRECT_OUTPUT 1 +) + +INSTALL(TARGETS ${fw_name} DESTINATION ${LIBDIR}) INSTALL( - DIRECTORY include/ DESTINATION include/${service} + DIRECTORY ${INC_DIR}/ DESTINATION include/${service} FILES_MATCHING - PATTERN "*_internal.h" EXCLUDE - PATTERN "include/*.h" + PATTERN "*_common.h" EXCLUDE + PATTERN "${INC_DIR}/*.h" ) SET(PC_NAME ${fw_name}) -SET(PC_REQUIRED "capi-base-common") +SET(PC_REQUIRED ${pc_dependents}) SET(PC_LDFLAGS -l${fw_name}) -SET(PREFIX ${CMAKE_INSTALL_PREFIX}) -SET(VERSION ${FULLVER}) -CONFIGURE_FILE(${fw_name}.pc.in ${fw_name}.pc @ONLY) -INSTALL(FILES ${fw_name}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) +CONFIGURE_FILE( + ${fw_name}.pc.in + ${CMAKE_CURRENT_SOURCE_DIR}/${fw_name}.pc + @ONLY +) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${fw_name}.pc DESTINATION ${LIBDIR}/pkgconfig) #ADD_SUBDIRECTORY(test) diff --git a/LICENSE.APLv2 b/LICENSE.APLv2 index ec68963..2e43946 100644 --- a/LICENSE.APLv2 +++ b/LICENSE.APLv2 @@ -1,206 +1,206 @@ -Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved. - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - 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. - - 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, - 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 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 in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) 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 - - (d) 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 Apache License to your work. - - To apply the Apache 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 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. - - - +Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + 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. + + 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, + 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 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 in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) 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 + + (d) 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 Apache License to your work. + + To apply the Apache 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 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. + + + diff --git a/TC/_export_env.sh b/TC/_export_env.sh deleted file mode 100755 index 7a317f8..0000000 --- a/TC/_export_env.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/sh - -source ./config - -export TET_INSTALL_PATH=$TET_INSTALL_HOST_PATH # tetware root path -#export TET_TARGET_PATH=$TET_INSTALL_PATH/tetware-simulator # tetware target 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 deleted file mode 100755 index 3fd8e3f..0000000 --- a/TC/_export_target_env.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/sh -. ./config - -export TET_INSTALL_PATH=$TET_INSTALL_TARGET_PATH # path to path -#export TET_TARGET_PATH=$TET_INSTALL_PATH/tetware-simulator -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 deleted file mode 100755 index 72aad6c..0000000 --- a/TC/build.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/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 deleted file mode 100755 index 29743e0..0000000 --- a/TC/clean.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/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 b/TC/config deleted file mode 100644 index ecb0344..0000000 --- a/TC/config +++ /dev/null @@ -1,3 +0,0 @@ -PKG_NAME=capi-network-nfc -TET_INSTALL_HOST_PATH=/var/tmp/TETware -TET_INSTALL_TARGET_PATH=/TETware diff --git a/TC/push.sh b/TC/push.sh deleted file mode 100755 index 5eb9510..0000000 --- a/TC/push.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/sh - -. ./config - -TC_PATH=/opt/home/$PKG_NAME - -echo $TC_PATH - -sdb shell "mkdir -p $TC_PATH" - -sdb push . $TC_PATH - - diff --git a/TC/run.sh b/TC/run.sh deleted file mode 100755 index cec5778..0000000 --- a/TC/run.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/sh - -source ./_export_target_env.sh - -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 7 -f chtml -o $HTML_RESULT $JOURNAL_RESULT diff --git a/TC/testcase/Makefile b/TC/testcase/Makefile deleted file mode 100644 index a7c9b44..0000000 --- a/TC/testcase/Makefile +++ /dev/null @@ -1,24 +0,0 @@ -CC ?= gcc - -C_FILES = $(shell ls *.c) - -PKGS = glib-2.0 capi-network-nfc - -LDFLAGS = `pkg-config --libs $(PKGS)` -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 $(PKGS)` -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 deleted file mode 100644 index c32b2cd..0000000 --- a/TC/testcase/tslist +++ /dev/null @@ -1,5 +0,0 @@ -/testcase/utc_network_nfc -/testcase/utc_network_nfc_ndef_record -/testcase/utc_network_nfc_ndef_message -/testcase/utc_network_nfc_se -/testcase/utc_network_nfc_snep diff --git a/TC/testcase/utc_network_nfc.c b/TC/testcase/utc_network_nfc.c deleted file mode 100644 index 0d8a737..0000000 --- a/TC/testcase/utc_network_nfc.c +++ /dev/null @@ -1,516 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include - -enum -{ - POSITIVE_TC_IDX = 0x01, - NEGATIVE_TC_IDX, -}; - -static void startup(void); -static void cleanup(void); - -void (*tet_startup)(void) = startup; -void (*tet_cleanup)(void) = cleanup; - -static void nfc_manager_is_supported_p(void); -static void nfc_manager_is_supported_n(void); -static void nfc_manager_initialize_p(void); -static void nfc_manager_initialize_n(void); -static void nfc_manager_deinitialize_p(void); -static void nfc_manager_deinitialize_n(void); -static void nfc_manager_set_activation_changed_cb_p(void); -static void nfc_manager_set_activation_changed_cb_n(void); -static void nfc_manager_is_activated_p(void); -static void nfc_manager_is_activated_n(void); -static void nfc_manager_set_activation_p(void); -static void nfc_manager_set_activation_n(void); -static void nfc_manager_set_tag_discovered_cb_p(void); -static void nfc_manager_set_tag_discovered_cb_n(void); -static void nfc_manager_set_ndef_discovered_cb_p(void); -static void nfc_manager_set_ndef_discovered_cb_n(void); -static void nfc_manager_set_p2p_target_discovered_cb_p(void); -static void nfc_manager_set_p2p_target_discovered_cb_n(void); -static void nfc_manager_set_se_event_cb_p(void); -static void nfc_manager_set_se_event_cb_n(void); -static void nfc_manager_set_se_transaction_event_cb_p(void); -static void nfc_manager_set_se_transaction_event_cb_n(void); -static void nfc_manager_set_system_handler_enable_p(void); -static void nfc_manager_set_system_handler_enable_n(void); -static void nfc_manager_set_system_handler_enable_force_p(void); -static void nfc_manager_set_system_handler_enable_force_n(void); -static void nfc_manager_set_card_emulation_se_type_p(void); -static void nfc_manager_set_card_emulation_se_type_n(void); -static void nfc_manager_get_card_emulation_se_type_p(void); -static void nfc_manager_get_card_emulation_se_type_n(void); - -static void _activation_changed_cb(bool activated, void *user_data); -static void _activation_completed_cb(int error, void *user_data); -static void utc_test_cb(void * user_data); - -struct tet_testlist tet_testlist[] = -{ - { nfc_manager_is_supported_p, POSITIVE_TC_IDX }, - { nfc_manager_is_supported_n, NEGATIVE_TC_IDX }, - { nfc_manager_initialize_p, POSITIVE_TC_IDX }, - { nfc_manager_initialize_n, NEGATIVE_TC_IDX }, - { nfc_manager_deinitialize_p, POSITIVE_TC_IDX }, - { nfc_manager_deinitialize_n, NEGATIVE_TC_IDX }, - { nfc_manager_set_activation_changed_cb_p, POSITIVE_TC_IDX }, - { nfc_manager_set_activation_changed_cb_n, NEGATIVE_TC_IDX }, - { nfc_manager_is_activated_p, POSITIVE_TC_IDX }, - { nfc_manager_is_activated_n, NEGATIVE_TC_IDX }, - { nfc_manager_set_activation_p, POSITIVE_TC_IDX }, - { nfc_manager_set_activation_n, NEGATIVE_TC_IDX }, - { nfc_manager_set_tag_discovered_cb_p, POSITIVE_TC_IDX }, - { nfc_manager_set_tag_discovered_cb_n, NEGATIVE_TC_IDX }, - { nfc_manager_set_ndef_discovered_cb_p, POSITIVE_TC_IDX }, - { nfc_manager_set_ndef_discovered_cb_n, NEGATIVE_TC_IDX }, - { nfc_manager_set_p2p_target_discovered_cb_p, POSITIVE_TC_IDX }, - { nfc_manager_set_p2p_target_discovered_cb_n, NEGATIVE_TC_IDX }, - { nfc_manager_set_se_event_cb_p, POSITIVE_TC_IDX }, - { nfc_manager_set_se_event_cb_n, NEGATIVE_TC_IDX }, - { nfc_manager_set_p2p_target_discovered_cb_p, POSITIVE_TC_IDX }, - { nfc_manager_set_p2p_target_discovered_cb_n, NEGATIVE_TC_IDX }, - { nfc_manager_set_se_transaction_event_cb_p, POSITIVE_TC_IDX }, - { nfc_manager_set_se_transaction_event_cb_n, NEGATIVE_TC_IDX }, - { nfc_manager_set_system_handler_enable_p, POSITIVE_TC_IDX }, - { nfc_manager_set_system_handler_enable_n, NEGATIVE_TC_IDX }, - { nfc_manager_set_system_handler_enable_force_p, POSITIVE_TC_IDX }, - { nfc_manager_set_system_handler_enable_force_n, NEGATIVE_TC_IDX }, - { nfc_manager_set_card_emulation_se_type_p, POSITIVE_TC_IDX }, - { nfc_manager_set_card_emulation_se_type_n, NEGATIVE_TC_IDX }, - { nfc_manager_get_card_emulation_se_type_p, POSITIVE_TC_IDX }, - { nfc_manager_get_card_emulation_se_type_n, NEGATIVE_TC_IDX }, - - { 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 _activation_changed_cb(bool activated, void *user_data) -{ - if (activated == true) - { - } - else if (activated == false) - { - } -} - -static void _activation_completed_cb(int error, void *user_data) -{ -} - -static void utc_test_cb(void *user_data) -{ -} - -static void nfc_manager_is_supported_p(void) -{ - bool result; - - result = nfc_manager_is_supported(); - - dts_check_eq(__func__, result, true, "nfc_manager_is_supported is failed"); -} - -static void nfc_manager_is_supported_n(void) -{ - dts_pass(__func__, "PASS"); -} - -static void nfc_manager_initialize_p() -{ - int ret; - - ret = nfc_manager_initialize(NULL, NULL); - - nfc_manager_deinitialize(); - - dts_check_eq(__func__, ret, NFC_ERROR_NONE, "nfc_manager_initialize_p is failed"); -} - -static void nfc_manager_initialize_n() -{ - int ret; - - ret = nfc_manager_initialize(NULL, NULL); - - dts_pass(__func__, "PASS"); -} - -static void nfc_manager_deinitialize_p() -{ - int ret; - - nfc_manager_initialize(NULL, NULL); - - ret = nfc_manager_deinitialize(); - - dts_check_eq(__func__, ret, NFC_ERROR_NONE, "nfc_manager_initialize_p is failed"); -} - -static void nfc_manager_deinitialize_n() -{ - int ret; - - ret = nfc_manager_deinitialize(); - - dts_pass(__func__, "PASS"); -} - -static void nfc_manager_set_activation_changed_cb_p(void) -{ - int ret; - - ret = nfc_manager_initialize(NULL, NULL); - if (ret == NFC_ERROR_NONE) { - ret = nfc_manager_set_activation_changed_cb(_activation_changed_cb, NULL); - - nfc_manager_deinitialize(); - } - - dts_check_eq(__func__, ret, NFC_ERROR_NONE, "nfc_manager_set_activation_changed_cb_p is failed"); -} - -static void nfc_manager_set_activation_changed_cb_n(void) -{ - int ret; - - ret = nfc_manager_initialize(NULL, NULL); - if (ret == NFC_ERROR_NONE) { - ret = nfc_manager_set_activation_changed_cb(NULL, NULL); - - nfc_manager_deinitialize(); - } - - dts_check_ne(__func__, ret, NFC_ERROR_NONE, "nfc_manager_set_activation_changed_cb_n not allow null"); -} - -static void nfc_manager_is_activated_p(void) -{ - int ret; - bool result; - - ret = nfc_manager_initialize(NULL, NULL); - if (ret == NFC_ERROR_NONE) { - result = nfc_manager_is_activated(); - - nfc_manager_deinitialize(); - } - - dts_check_eq(__func__, result, true, "nfc_manager_is_activated is failed"); -} - -static void nfc_manager_is_activated_n(void) -{ - dts_pass(__func__, "PASS"); -} - -static void nfc_manager_set_activation_p() -{ - int ret; - - ret = nfc_manager_initialize(NULL, NULL); - if (ret == NFC_ERROR_NONE) { - ret = nfc_manager_set_activation(1, _activation_completed_cb, NULL); - - nfc_manager_deinitialize(); - } - - dts_pass(__func__, "PASS"); -} - -static void nfc_manager_set_activation_n() -{ - int ret; - - ret = nfc_manager_initialize(NULL, NULL); - if (ret == NFC_ERROR_NONE) { - ret = nfc_manager_set_activation(1, NULL, NULL); - - nfc_manager_deinitialize(); - } - - dts_pass(__func__, "PASS"); -} - -static void nfc_manager_set_tag_discovered_cb_p() -{ - int ret; - - ret = nfc_manager_initialize(NULL, NULL); - if (ret == NFC_ERROR_NONE) { - ret = nfc_manager_set_tag_discovered_cb(utc_test_cb, NULL); - - nfc_manager_deinitialize(); - } - - dts_check_eq(__func__, ret, NFC_ERROR_NONE, "nfc_manager_set_tag_discovered_cb_p is failed"); -} - -static void nfc_manager_set_tag_discovered_cb_n() -{ - int ret; - - ret = nfc_manager_initialize(NULL, NULL); - if (ret == NFC_ERROR_NONE) { - ret = nfc_manager_set_tag_discovered_cb(NULL, NULL); - - nfc_manager_deinitialize(); - } - - dts_check_ne(__func__, ret, NFC_ERROR_NONE, "nfc_manager_set_tag_discovered_cb_n not allow null"); -} - -static void nfc_manager_set_ndef_discovered_cb_p() -{ - int ret; - - ret = nfc_manager_initialize(NULL, NULL); - if (ret == NFC_ERROR_NONE) { - ret = nfc_manager_set_ndef_discovered_cb(utc_test_cb, NULL); - - nfc_manager_deinitialize(); - } - - dts_check_eq(__func__, ret, NFC_ERROR_NONE, "nfc_manager_set_ndef_discovered_cb_p is failed"); -} - -static void nfc_manager_set_ndef_discovered_cb_n() -{ - int ret; - - ret = nfc_manager_initialize(NULL, NULL); - if (ret == NFC_ERROR_NONE) { - ret = nfc_manager_set_ndef_discovered_cb(NULL, NULL); - - nfc_manager_deinitialize(); - } - - dts_check_ne(__func__, ret, NFC_ERROR_NONE, "nfc_manager_set_ndef_discovered_cb_n not allow null"); -} - -static void nfc_manager_set_p2p_target_discovered_cb_p() -{ - int ret; - - ret = nfc_manager_initialize(NULL, NULL); - if (ret == NFC_ERROR_NONE) { - ret = nfc_manager_set_p2p_target_discovered_cb(utc_test_cb, NULL); - - nfc_manager_deinitialize(); - } - - dts_check_eq(__func__, ret, NFC_ERROR_NONE, "nfc_manager_set_p2p_target_discovered_cb_p is failed"); -} - -static void nfc_manager_set_p2p_target_discovered_cb_n() -{ - int ret; - - ret = nfc_manager_initialize(NULL, NULL); - if (ret == NFC_ERROR_NONE) { - ret = nfc_manager_set_p2p_target_discovered_cb(NULL, NULL); - - nfc_manager_deinitialize(); - } - - dts_check_ne(__func__, ret, NFC_ERROR_NONE, "nfc_manager_set_p2p_target_discovered_cb_n not allow null"); -} - -static void nfc_manager_set_se_event_cb_p() -{ - int ret; - - ret = nfc_manager_initialize(NULL, NULL); - if (ret == NFC_ERROR_NONE) { - ret = nfc_manager_set_se_event_cb(utc_test_cb, NULL); - - nfc_manager_deinitialize(); - } - - dts_check_eq(__func__, ret, NFC_ERROR_NONE, "nfc_manager_set_se_event_cb_p is failed"); -} - -static void nfc_manager_set_se_event_cb_n() -{ - int ret; - - ret = nfc_manager_initialize(NULL, NULL); - if (ret == NFC_ERROR_NONE) { - ret = nfc_manager_set_se_event_cb(NULL, NULL); - - nfc_manager_deinitialize(); - } - - dts_check_ne(__func__, ret, NFC_ERROR_NONE, "nfc_manager_set_se_event_cb_n not allow null"); -} - -static void nfc_manager_set_se_transaction_event_cb_p() -{ - int ret; - - ret = nfc_manager_initialize(NULL, NULL); - if (ret == NFC_ERROR_NONE) { - ret = nfc_manager_set_se_transaction_event_cb(utc_test_cb, NULL); - - nfc_manager_deinitialize(); - } - - dts_check_eq(__func__, ret, NFC_ERROR_NONE, "nfc_manager_set_se_transaction_event_cb_p is failed"); -} - -static void nfc_manager_set_se_transaction_event_cb_n() -{ - int ret; - - ret = nfc_manager_initialize(NULL, NULL); - if (ret == NFC_ERROR_NONE) { - ret = nfc_manager_set_se_transaction_event_cb(NULL, NULL); - - nfc_manager_deinitialize(); - } - - dts_check_ne(__func__, ret, NFC_ERROR_NONE, "nfc_manager_set_se_transaction_event_cb_n not allow null"); -} - -static void nfc_manager_set_system_handler_enable_p() -{ - int ret; - - ret = nfc_manager_initialize(NULL, NULL); - if (ret == NFC_ERROR_NONE) { - ret = nfc_manager_set_system_handler_enable(true); - - nfc_manager_deinitialize(); - } - - dts_check_eq(__func__, ret, NFC_ERROR_NONE, "nfc_manager_set_system_handler_enable is failed"); -} - -static void nfc_manager_set_system_handler_enable_n() -{ - int ret; - - ret = nfc_manager_initialize(NULL, NULL); - if (ret == NFC_ERROR_NONE) { - ret = nfc_manager_set_system_handler_enable(false); - - nfc_manager_deinitialize(); - } - - dts_pass(__func__, "PASS"); -} - -static void nfc_manager_set_system_handler_enable_force_p(void) -{ - int ret; - - ret = nfc_manager_initialize(NULL, NULL); - if (ret == NFC_ERROR_NONE) { - ret = nfc_manager_set_system_handler_enable_force(true); - - nfc_manager_deinitialize(); - } - - dts_check_eq(__func__, ret, NFC_ERROR_NONE, "nfc_manager_set_system_handler_enable_force is failed"); -} - -static void nfc_manager_set_system_handler_enable_force_n(void) -{ - int ret; - - ret = nfc_manager_initialize(NULL, NULL); - if (ret == NFC_ERROR_NONE) { - ret = nfc_manager_set_system_handler_enable_force(false); - - nfc_manager_deinitialize(); - } - - dts_pass(__func__, "PASS"); -} - -static void nfc_manager_set_card_emulation_se_type_p(void) -{ - int ret; - - ret = nfc_manager_initialize(NULL, NULL); - if (ret == NFC_ERROR_NONE) { - ret = nfc_manager_set_card_emulation_se_type(NFC_SE_TYPE_ESE, NULL, NULL); - - nfc_manager_deinitialize(); - } - - dts_check_eq(__func__, ret, NFC_ERROR_NONE, "nfc_manager_set_card_emulation_se_type is failed"); -} - -static void nfc_manager_set_card_emulation_se_type_n(void) -{ - int ret; - - ret = nfc_manager_initialize(NULL, NULL); - if (ret == NFC_ERROR_NONE) { - ret = nfc_manager_set_card_emulation_se_type((nfc_se_type_e)0xff, NULL, NULL); - - nfc_manager_deinitialize(); - } - - dts_check_ne(__func__, ret, NFC_ERROR_NONE, "nfc_manager_set_card_emulation_se_type not allow null"); -} - -static void nfc_manager_get_card_emulation_se_type_p(void) -{ - int ret; - nfc_se_type_e type; - - ret = nfc_manager_initialize(NULL, NULL); - if (ret == NFC_ERROR_NONE) { - ret = nfc_manager_get_card_emulation_se_type(&type); - - nfc_manager_deinitialize(); - } - - dts_check_eq(__func__, ret, NFC_ERROR_NONE, "nfc_manager_get_card_emulation_se_type is failed"); -} - -static void nfc_manager_get_card_emulation_se_type_n(void) -{ - int ret; - nfc_se_type_e type; - - ret = nfc_manager_initialize(NULL, NULL); - if (ret == NFC_ERROR_NONE) { - ret = nfc_manager_get_card_emulation_se_type(NULL); - - nfc_manager_deinitialize(); - } - - dts_check_ne(__func__, ret, NFC_ERROR_NONE, "nfc_manager_get_card_emulation_se_type not allow null"); -} diff --git a/TC/testcase/utc_network_nfc_ndef_message.c b/TC/testcase/utc_network_nfc_ndef_message.c deleted file mode 100644 index 0c5b101..0000000 --- a/TC/testcase/utc_network_nfc_ndef_message.c +++ /dev/null @@ -1,301 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include - -enum -{ - POSITIVE_TC_IDX = 0x01, - NEGATIVE_TC_IDX, -}; - -static void startup(void); -static void cleanup(void); - -void (*tet_startup)(void) = startup; -void (*tet_cleanup)(void) = cleanup; - -static void utc_nfc_ndef_message_create_p(void); -static void utc_nfc_ndef_message_create_n(void); -static void utc_nfc_ndef_message_create_from_rawdata_p(void); -static void utc_nfc_ndef_message_create_from_rawdata_n(void); -static void utc_nfc_ndef_message_destroy_p(void); -static void utc_nfc_ndef_message_destroy_n(void); -static void utc_nfc_ndef_message_get_record_count_p(void); -static void utc_nfc_ndef_message_get_record_count_n(void); -static void utc_nfc_ndef_message_get_rawdata_p(void); -static void utc_nfc_ndef_message_get_rawdata_n(void); -static void utc_nfc_ndef_message_append_record_p(void); -static void utc_nfc_ndef_message_append_record_n(void); -static void utc_nfc_ndef_message_insert_record_p(void); -static void utc_nfc_ndef_message_insert_record_n(void); -static void utc_nfc_ndef_message_remove_record_p(void); -static void utc_nfc_ndef_message_remove_record_n(void); -static void utc_nfc_ndef_message_get_record_p(void); -static void utc_nfc_ndef_message_get_record_n(void); - -struct tet_testlist tet_testlist[] = -{ - { utc_nfc_ndef_message_create_p, POSITIVE_TC_IDX }, - { utc_nfc_ndef_message_create_n, NEGATIVE_TC_IDX }, - { utc_nfc_ndef_message_create_from_rawdata_p, POSITIVE_TC_IDX }, - { utc_nfc_ndef_message_create_from_rawdata_n, NEGATIVE_TC_IDX }, - { utc_nfc_ndef_message_destroy_p, POSITIVE_TC_IDX }, - { utc_nfc_ndef_message_destroy_n, NEGATIVE_TC_IDX }, - { utc_nfc_ndef_message_get_record_count_p, POSITIVE_TC_IDX }, - { utc_nfc_ndef_message_get_record_count_n, NEGATIVE_TC_IDX }, - { utc_nfc_ndef_message_get_rawdata_p, POSITIVE_TC_IDX }, - { utc_nfc_ndef_message_get_rawdata_n, NEGATIVE_TC_IDX }, - { utc_nfc_ndef_message_append_record_p, POSITIVE_TC_IDX }, - { utc_nfc_ndef_message_append_record_n, NEGATIVE_TC_IDX }, - { utc_nfc_ndef_message_insert_record_p, POSITIVE_TC_IDX }, - { utc_nfc_ndef_message_insert_record_n, NEGATIVE_TC_IDX }, - { utc_nfc_ndef_message_remove_record_p, POSITIVE_TC_IDX }, - { utc_nfc_ndef_message_remove_record_n, NEGATIVE_TC_IDX }, - { utc_nfc_ndef_message_get_record_p, POSITIVE_TC_IDX }, - { utc_nfc_ndef_message_get_record_n, NEGATIVE_TC_IDX }, - - { 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_nfc_ndef_message_create_p(void) -{ - int ret; - nfc_ndef_message_h message; - - ret = nfc_ndef_message_create(&message); - nfc_ndef_message_destroy(message); - - dts_check_eq(__func__, ret, NFC_ERROR_NONE, "nfc_ndef_message_create is failed"); -} - -static void utc_nfc_ndef_message_create_n(void) -{ - int ret; - - ret = nfc_ndef_message_create(NULL); - - dts_check_ne(__func__, ret, NFC_ERROR_NONE, "nfc_ndef_message_create not allow null"); -} - -static void utc_nfc_ndef_message_create_from_rawdata_p(void) -{ - int ret; - unsigned char *buffer; - uint32_t size; - nfc_ndef_message_h message; - nfc_ndef_message_h message2; - nfc_ndef_record_h record1; - - ret = nfc_ndef_message_create(&message); - nfc_ndef_record_create_text(&record1, "test", "en-US", NFC_ENCODE_UTF_8); - nfc_ndef_message_append_record(message, record1); - nfc_ndef_message_get_rawdata(message, &buffer, &size); - ret = nfc_ndef_message_create_from_rawdata(&message2, buffer, size); - - nfc_ndef_message_destroy(message2); - nfc_ndef_message_destroy(message); - free(buffer); - - dts_check_eq(__func__, ret, NFC_ERROR_NONE, "nfc_ndef_message_create_from_rawdata is failed"); -} - -static void utc_nfc_ndef_message_create_from_rawdata_n(void) -{ - int ret; - - ret = nfc_ndef_message_create_from_rawdata(NULL, NULL, 0); - - dts_check_ne(__func__, ret, NFC_ERROR_NONE, "nfc_ndef_message_create_from_rawdata not allow null"); -} - -static void utc_nfc_ndef_message_destroy_p(void) -{ - int ret; - nfc_ndef_message_h message; - - ret = nfc_ndef_message_create(&message); - ret = nfc_ndef_message_destroy(message); - - dts_check_eq(__func__, ret, NFC_ERROR_NONE, "nfc_ndef_message_destroy is failed"); -} - -static void utc_nfc_ndef_message_destroy_n(void) -{ - int ret; - - ret = nfc_ndef_message_destroy(NULL); - - dts_check_ne(__func__, ret, NFC_ERROR_NONE, "nfc_ndef_message_destroy not allow null"); -} - -static void utc_nfc_ndef_message_get_record_count_p(void) -{ - int ret; - int count; - nfc_ndef_message_h message; - nfc_ndef_record_h record1; - - ret = nfc_ndef_message_create(&message); - nfc_ndef_record_create_text(&record1, "test", "en-US", NFC_ENCODE_UTF_8); - nfc_ndef_message_append_record(message, record1); - ret = nfc_ndef_message_get_record_count(message, &count); - nfc_ndef_message_destroy(message); - - dts_check_eq(__func__, ret, NFC_ERROR_NONE, "nfc_ndef_message_get_record_count is failed"); -} - -static void utc_nfc_ndef_message_get_record_count_n(void) -{ - int ret; - - ret = nfc_ndef_message_get_record_count(NULL, NULL); - - dts_check_ne(__func__, ret, NFC_ERROR_NONE, "nfc_ndef_message_get_record_count not allow null"); -} - -static void utc_nfc_ndef_message_get_rawdata_p(void) -{ - int ret; - unsigned char *buffer; - uint32_t size; - nfc_ndef_message_h message; - nfc_ndef_record_h record1; - - ret = nfc_ndef_message_create(&message); - nfc_ndef_record_create_text(&record1, "test", "en-US", NFC_ENCODE_UTF_8); - nfc_ndef_message_append_record(message, record1); - ret = nfc_ndef_message_get_rawdata(message, &buffer, &size); - nfc_ndef_message_destroy(message); - free(buffer); - - dts_check_eq(__func__, ret, NFC_ERROR_NONE, "nfc_ndef_message_get_rawdata is failed"); -} - -static void utc_nfc_ndef_message_get_rawdata_n(void) -{ - int ret; - - ret = nfc_ndef_message_get_rawdata(NULL, NULL, NULL); - - dts_check_ne(__func__, ret, NFC_ERROR_NONE, "nfc_ndef_message_get_rawdata not allow null"); -} - -static void utc_nfc_ndef_message_append_record_p(void) -{ - int ret; - nfc_ndef_message_h message; - nfc_ndef_record_h record1; - - ret = nfc_ndef_message_create(&message); - nfc_ndef_record_create_text(&record1, "test", "en-US", NFC_ENCODE_UTF_8); - ret = nfc_ndef_message_append_record(message, record1); - nfc_ndef_message_destroy(message); - - dts_check_eq(__func__, ret, NFC_ERROR_NONE, "nfc_ndef_message_append_record is failed"); -} - -static void utc_nfc_ndef_message_append_record_n(void) -{ - int ret; - - ret = nfc_ndef_message_append_record(NULL, NULL); - - dts_check_ne(__func__, ret, NFC_ERROR_NONE, "nfc_ndef_message_append_record not allow null"); -} - -static void utc_nfc_ndef_message_insert_record_p(void) -{ - int ret; - nfc_ndef_message_h message; - nfc_ndef_record_h record1; - - ret = nfc_ndef_message_create(&message); - nfc_ndef_record_create_text(&record1, "test", "en-US", NFC_ENCODE_UTF_8); - ret = nfc_ndef_message_insert_record(message, 0, record1); - nfc_ndef_message_destroy(message); - - dts_check_eq(__func__, ret, NFC_ERROR_NONE, "nfc_ndef_message_insert_record is failed"); -} - -static void utc_nfc_ndef_message_insert_record_n(void) -{ - int ret; - - ret = nfc_ndef_message_insert_record(NULL, 0, NULL); - - dts_check_ne(__func__, ret, NFC_ERROR_NONE, "nfc_ndef_message_insert_record not allow null"); -} - -static void utc_nfc_ndef_message_remove_record_p(void) -{ - int ret; - nfc_ndef_message_h message; - nfc_ndef_record_h record1; - - ret = nfc_ndef_message_create(&message); - nfc_ndef_record_create_text(&record1, "test", "en-US", NFC_ENCODE_UTF_8); - ret = nfc_ndef_message_insert_record(message, 0, record1); - ret = nfc_ndef_message_remove_record(message, 0); - nfc_ndef_message_destroy(message); - - dts_check_eq(__func__, ret, NFC_ERROR_NONE, "nfc_ndef_message_remove_record is failed"); -} - -static void utc_nfc_ndef_message_remove_record_n(void) -{ - int ret; - - ret = nfc_ndef_message_remove_record(NULL, 0); - - dts_check_ne(__func__, ret, NFC_ERROR_NONE, "nfc_ndef_message_remove_record not allow null"); -} - -static void utc_nfc_ndef_message_get_record_p(void) -{ - int ret; - nfc_ndef_message_h message; - nfc_ndef_record_h record1, record2; - - ret = nfc_ndef_message_create(&message); - nfc_ndef_record_create_text(&record1, "test", "en-US", NFC_ENCODE_UTF_8); - ret = nfc_ndef_message_insert_record(message, 0, record1); - ret = nfc_ndef_message_get_record(message, 0, &record2); - nfc_ndef_message_destroy(message); - - dts_check_eq(__func__, ret, NFC_ERROR_NONE, "nfc_ndef_message_get_record is failed"); -} - -static void utc_nfc_ndef_message_get_record_n(void) -{ - int ret; - - ret = nfc_ndef_message_get_record(NULL, 0, NULL); - - dts_check_ne(__func__, ret, NFC_ERROR_NONE, "nfc_ndef_message_get_record not allow null"); -} diff --git a/TC/testcase/utc_network_nfc_ndef_record.c b/TC/testcase/utc_network_nfc_ndef_record.c deleted file mode 100644 index 0c386db..0000000 --- a/TC/testcase/utc_network_nfc_ndef_record.c +++ /dev/null @@ -1,545 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include - -enum -{ - POSITIVE_TC_IDX = 0x01, - NEGATIVE_TC_IDX, -}; - -static void startup(void); -static void cleanup(void); - -void (*tet_startup)(void) = startup; -void (*tet_cleanup)(void) = cleanup; - -static void utc_nfc_ndef_record_create_p(void); -static void utc_nfc_ndef_record_create_n(void); -static void utc_nfc_ndef_record_create_text_p(void); -static void utc_nfc_ndef_record_create_text_n(void); -static void utc_nfc_ndef_record_create_uri_p(void); -static void utc_nfc_ndef_record_create_uri_n(void); -static void utc_nfc_ndef_record_create_mime_p(void); -static void utc_nfc_ndef_record_create_mime_n_1(void); -static void utc_nfc_ndef_record_create_mime_n_2(void); -static void utc_nfc_ndef_record_create_mime_n_3(void); -static void utc_nfc_ndef_record_destroy_p(void); -static void utc_nfc_ndef_record_destroy_n(void); -static void utc_nfc_ndef_record_set_id_p(void); -static void utc_nfc_ndef_record_set_id_n(void); -static void utc_nfc_ndef_record_get_id_p(void); -static void utc_nfc_ndef_record_get_id_n(void); -static void utc_nfc_ndef_record_get_payload_p(void); -static void utc_nfc_ndef_record_get_payload_n(void); -static void utc_nfc_ndef_record_get_type_p(void); -static void utc_nfc_ndef_record_get_type_n(void); -static void utc_nfc_ndef_record_get_tnf_p(void); -static void utc_nfc_ndef_record_get_tnf_n(void); -static void utc_nfc_ndef_record_get_text_p(void); -static void utc_nfc_ndef_record_get_text_n(void); -static void utc_nfc_ndef_record_get_langcode_p(void); -static void utc_nfc_ndef_record_get_langcode_n(void); -static void utc_nfc_ndef_record_get_encode_type_p(void); -static void utc_nfc_ndef_record_get_encode_type_n(void); -static void utc_nfc_ndef_record_get_uri_p(void); -static void utc_nfc_ndef_record_get_uri_n(void); -static void utc_nfc_ndef_record_get_mime_type_p(void); -static void utc_nfc_ndef_record_get_mime_type_n(void); - -struct tet_testlist tet_testlist[] = { - { utc_nfc_ndef_record_create_p, POSITIVE_TC_IDX }, - { utc_nfc_ndef_record_create_n, NEGATIVE_TC_IDX }, - { utc_nfc_ndef_record_create_text_p, POSITIVE_TC_IDX }, - { utc_nfc_ndef_record_create_text_n, NEGATIVE_TC_IDX }, - { utc_nfc_ndef_record_create_uri_p, POSITIVE_TC_IDX }, - { utc_nfc_ndef_record_create_uri_n, NEGATIVE_TC_IDX }, - { utc_nfc_ndef_record_create_mime_p, POSITIVE_TC_IDX }, - { utc_nfc_ndef_record_create_mime_n_1, NEGATIVE_TC_IDX }, - { utc_nfc_ndef_record_create_mime_n_2, NEGATIVE_TC_IDX }, - { utc_nfc_ndef_record_create_mime_n_3, NEGATIVE_TC_IDX }, - { utc_nfc_ndef_record_destroy_p, POSITIVE_TC_IDX }, - { utc_nfc_ndef_record_destroy_n, NEGATIVE_TC_IDX }, - { utc_nfc_ndef_record_set_id_p, POSITIVE_TC_IDX }, - { utc_nfc_ndef_record_set_id_n, NEGATIVE_TC_IDX }, - { utc_nfc_ndef_record_get_id_p, POSITIVE_TC_IDX }, - { utc_nfc_ndef_record_get_id_n, NEGATIVE_TC_IDX }, - { utc_nfc_ndef_record_get_payload_p, POSITIVE_TC_IDX }, - { utc_nfc_ndef_record_get_payload_n, NEGATIVE_TC_IDX }, - { utc_nfc_ndef_record_get_type_p, POSITIVE_TC_IDX }, - { utc_nfc_ndef_record_get_type_n, NEGATIVE_TC_IDX }, - { utc_nfc_ndef_record_get_tnf_p, POSITIVE_TC_IDX }, - { utc_nfc_ndef_record_get_tnf_n, NEGATIVE_TC_IDX }, - { utc_nfc_ndef_record_get_text_p, POSITIVE_TC_IDX }, - { utc_nfc_ndef_record_get_text_n, NEGATIVE_TC_IDX }, - { utc_nfc_ndef_record_get_langcode_p, POSITIVE_TC_IDX }, - { utc_nfc_ndef_record_get_langcode_n, NEGATIVE_TC_IDX }, - { utc_nfc_ndef_record_get_encode_type_p, POSITIVE_TC_IDX }, - { utc_nfc_ndef_record_get_encode_type_n, NEGATIVE_TC_IDX }, - { utc_nfc_ndef_record_get_uri_p, POSITIVE_TC_IDX }, - { utc_nfc_ndef_record_get_uri_n, NEGATIVE_TC_IDX }, - { utc_nfc_ndef_record_get_mime_type_p, POSITIVE_TC_IDX }, - { utc_nfc_ndef_record_get_mime_type_n, NEGATIVE_TC_IDX }, - { 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_nfc_ndef_record_create_p(void) -{ - int ret; - nfc_ndef_record_h record; - unsigned char testbuffer[] = "TEST"; - - ret = nfc_ndef_record_create(&record, NFC_RECORD_TNF_WELL_KNOWN, testbuffer, 1, testbuffer, 4, testbuffer, 4); - if (ret == 0) - nfc_ndef_record_destroy(record); - - dts_check_eq(__func__, ret, NFC_ERROR_NONE, "nfc_ndef_record_create is failed"); -} - -static void utc_nfc_ndef_record_create_n(void) -{ - int ret; - unsigned char testbuffer[] = "TEST"; - - ret = nfc_ndef_record_create(NULL, NFC_RECORD_TNF_WELL_KNOWN, testbuffer, 1, testbuffer, 4, testbuffer, 4); - - dts_check_ne(__func__, ret, NFC_ERROR_NONE, "nfc_ndef_record_h not allow null"); -} - -static void utc_nfc_ndef_record_create_text_p(void) -{ - int ret; - nfc_ndef_record_h record; - - ret = nfc_ndef_record_create_text(&record, "test", "en-US", NFC_ENCODE_UTF_8); - if (ret == 0) - nfc_ndef_record_destroy(record); - - dts_check_eq(__func__, ret, NFC_ERROR_NONE, "nfc_ndef_record_create_text is failed"); -} - -static void utc_nfc_ndef_record_create_text_n(void) -{ - int ret; - - ret = nfc_ndef_record_create_text(NULL, "test", "en-US", NFC_ENCODE_UTF_8); - - dts_check_ne(__func__, ret, NFC_ERROR_NONE, "nfc_ndef_record_h not allow null"); -} - -static void utc_nfc_ndef_record_create_uri_p(void) -{ - int ret; - nfc_ndef_record_h record; - - ret = nfc_ndef_record_create_uri(&record, "http://test.com"); - if (ret == 0) - nfc_ndef_record_destroy(record); - - dts_check_eq(__func__, ret, NFC_ERROR_NONE, "nfc_ndef_record_create_uri is failed"); -} - -static void utc_nfc_ndef_record_create_uri_n(void) -{ - int ret; - - ret = nfc_ndef_record_create_uri(NULL, "http://test.com"); - - dts_check_ne(__func__, ret, NFC_ERROR_NONE, "nfc_ndef_record_h not allow null"); -} - -static void utc_nfc_ndef_record_create_mime_p(void) -{ - int ret; - nfc_ndef_record_h record; - - ret = nfc_ndef_record_create_mime(&record, "text/plain", (unsigned char *)"the text record", sizeof("the text record")); - if (ret == NFC_ERROR_NONE) - nfc_ndef_record_destroy(record); - - dts_check_eq(__func__, ret, NFC_ERROR_NONE, "nfc_ndef_record_create_mime is failed"); -} - -static void utc_nfc_ndef_record_create_mime_n_1(void) -{ - int ret = NFC_ERROR_NONE; - - ret = nfc_ndef_record_create_mime(NULL, "text/plain", (unsigned char *)"the text record", sizeof("the text record")); - - dts_check_eq(__func__, ret, NFC_ERROR_INVALID_PARAMETER, "nfc_ndef_record_h null not allowed"); -} - -static void utc_nfc_ndef_record_create_mime_n_2(void) -{ - int ret; - nfc_ndef_record_h record; - - ret = nfc_ndef_record_create_mime(&record, NULL, (unsigned char *)"the text record", sizeof("the text record")); - if (ret == NFC_ERROR_NONE) - nfc_ndef_record_destroy(record); - - dts_check_eq(__func__, ret, NFC_ERROR_INVALID_PARAMETER, "mime_type null not allowed"); -} - -static void utc_nfc_ndef_record_create_mime_n_3(void) -{ - int ret; - nfc_ndef_record_h record; - - ret = nfc_ndef_record_create_mime(&record, "text/plain", NULL, sizeof("the text record")); - if (ret == NFC_ERROR_NONE) - nfc_ndef_record_destroy(record); - - dts_check_eq(__func__, ret, NFC_ERROR_INVALID_PARAMETER, "data null not allowed"); -} - -static void utc_nfc_ndef_record_destroy_p(void) -{ - int ret; - nfc_ndef_record_h record; - - ret = nfc_ndef_record_create_text(&record, "test", "en-US", NFC_ENCODE_UTF_8); - if (ret != 0) { - dts_fail(__func__, "can't create record\n"); - return; - } - - ret = nfc_ndef_record_destroy(record); - - dts_check_eq(__func__, ret, NFC_ERROR_NONE, "nfc_ndef_record_destroy is failed"); -} - -static void utc_nfc_ndef_record_destroy_n(void) -{ - int ret; - - ret = nfc_ndef_record_destroy(NULL); - - dts_check_ne(__func__, ret, NFC_ERROR_NONE, "nfc_ndef_record_h not allow null"); -} - -static void utc_nfc_ndef_record_set_id_p(void) -{ - int ret; - nfc_ndef_record_h record; - - ret = nfc_ndef_record_create_text(&record, "test", "en-US", NFC_ENCODE_UTF_8); - if (ret != NFC_ERROR_NONE) { - dts_fail(__func__, "can't create record\n"); - return; - } - - ret = nfc_ndef_record_set_id(record, (unsigned char *)"test", 4); - - nfc_ndef_record_destroy(record); - - dts_check_eq(__func__, ret, NFC_ERROR_NONE, "nfc_ndef_record_set_id is failed"); -} - -static void utc_nfc_ndef_record_set_id_n(void) -{ - int ret; - - ret = nfc_ndef_record_set_id(NULL, (unsigned char *)"test", 4); - - dts_check_ne(__func__, ret, NFC_ERROR_NONE, "nfc_ndef_record_h not allow null"); -} - -static void utc_nfc_ndef_record_get_id_p(void) -{ - int ret; - int size; - nfc_ndef_record_h record; - unsigned char *id; - - ret = nfc_ndef_record_create_text(&record, "test", "en-US", NFC_ENCODE_UTF_8); - if (ret != NFC_ERROR_NONE) { - dts_fail(__func__, "can't create record\n"); - return; - } - - ret = nfc_ndef_record_set_id(record, (unsigned char *)"test", 4); - if (ret != NFC_ERROR_NONE) { - dts_fail(__func__, "can't set id\n"); - return; - } - - ret = nfc_ndef_record_get_id(record, &id, &size); - - nfc_ndef_record_destroy(record); - - dts_check_eq(__func__, ret, NFC_ERROR_NONE, "nfc_ndef_record_get_id is failed"); -} - -static void utc_nfc_ndef_record_get_id_n(void) -{ - int ret; - - ret = nfc_ndef_record_get_id(NULL, NULL, NULL); - - dts_check_ne(__func__, ret, NFC_ERROR_NONE, "nfc_ndef_record_h not allow null"); -} - -static void utc_nfc_ndef_record_get_payload_p(void) -{ - int ret = 0; - uint32_t size; - nfc_ndef_record_h record; - unsigned char *payload; - - ret = nfc_ndef_record_create_text(&record, "test", "en-US", NFC_ENCODE_UTF_8); - if (ret != NFC_ERROR_NONE) { - dts_fail(__func__, "can't create record\n"); - return; - } - - ret = nfc_ndef_record_get_payload(record, &payload, &size); - - nfc_ndef_record_destroy(record); - - dts_check_eq(__func__, ret, NFC_ERROR_NONE, "nfc_ndef_record_get_payload is failed"); -} - -static void utc_nfc_ndef_record_get_payload_n(void) -{ - int ret; - - ret = nfc_ndef_record_set_id(NULL, (unsigned char *)"test", 4); - - dts_check_ne(__func__, ret, NFC_ERROR_NONE, "nfc_ndef_record_h not allow null"); -} - -static void utc_nfc_ndef_record_get_type_p(void) -{ - int ret; - int size; - nfc_ndef_record_h record; - unsigned char *data; - - ret = nfc_ndef_record_create_text(&record, "test", "en-US", NFC_ENCODE_UTF_8); - if (ret != NFC_ERROR_NONE) { - dts_fail(__func__, "can't create record\n"); - return; - } - - ret = nfc_ndef_record_get_type(record, &data, &size); - - nfc_ndef_record_destroy(record); - - dts_check_eq(__func__, ret, NFC_ERROR_NONE, "nfc_ndef_record_get_type is failed"); -} - -static void utc_nfc_ndef_record_get_type_n(void) -{ - int ret; - - ret = nfc_ndef_record_get_type(NULL, NULL, NULL); - - dts_check_ne(__func__, ret, NFC_ERROR_NONE, "nfc_ndef_record_h not allow null"); -} - -static void utc_nfc_ndef_record_get_tnf_p(void) -{ - int ret; - nfc_ndef_record_h record; - nfc_record_tnf_e tnf; - - ret = nfc_ndef_record_create_text(&record, "test", "en-US", NFC_ENCODE_UTF_8); - if (ret != NFC_ERROR_NONE) { - dts_fail(__func__, "can't create record\n"); - return; - } - - ret = nfc_ndef_record_get_tnf(record, &tnf); - - nfc_ndef_record_destroy(record); - - dts_check_eq(__func__, ret, NFC_ERROR_NONE, "nfc_ndef_record_get_tnf is failed"); -} - -static void utc_nfc_ndef_record_get_tnf_n(void) -{ - int ret; - - ret = nfc_ndef_record_get_tnf(NULL, NULL); - - dts_check_ne(__func__, ret, NFC_ERROR_NONE, "nfc_ndef_record_h not allow null"); -} - -static void utc_nfc_ndef_record_get_text_p(void) -{ - int ret; - char *text; - nfc_ndef_record_h record; - - ret = nfc_ndef_record_create_text(&record, "test", "en-US", NFC_ENCODE_UTF_8); - if (ret != NFC_ERROR_NONE) { - dts_fail(__func__, "can't create record\n"); - return; - } - - ret = nfc_ndef_record_get_text(record, &text); - if (ret == 0) { - free(text); - } - - nfc_ndef_record_destroy(record); - - dts_check_eq(__func__, ret, NFC_ERROR_NONE, "nfc_ndef_record_get_tnf is failed"); -} - -static void utc_nfc_ndef_record_get_text_n(void) -{ - int ret; - - ret = nfc_ndef_record_get_text(NULL, NULL); - - dts_check_ne(__func__, ret, NFC_ERROR_NONE, "nfc_ndef_record_h not allow null"); -} - -static void utc_nfc_ndef_record_get_langcode_p(void) -{ - int ret; - char *text; - nfc_ndef_record_h record; - - ret = nfc_ndef_record_create_text(&record, "test", "en-US", NFC_ENCODE_UTF_8); - if (ret != NFC_ERROR_NONE) { - dts_fail(__func__, "can't create record\n"); - return; - } - - ret = nfc_ndef_record_get_langcode(record, &text); - if (ret == 0) { - free(text); - } - - nfc_ndef_record_destroy(record); - - dts_check_eq(__func__, ret, NFC_ERROR_NONE, "nfc_ndef_record_get_tnf is failed"); - -} -static void utc_nfc_ndef_record_get_langcode_n(void) -{ - int ret; - - ret = nfc_ndef_record_get_langcode(NULL, NULL); - - dts_check_ne(__func__, ret, NFC_ERROR_NONE, "nfc_ndef_record_h not allow null"); -} - -static void utc_nfc_ndef_record_get_encode_type_p(void) -{ - int ret; - nfc_encode_type_e type; - nfc_ndef_record_h record; - - ret = nfc_ndef_record_create_text(&record, "test", "en-US", NFC_ENCODE_UTF_8); - if (ret != NFC_ERROR_NONE) { - dts_fail(__func__, "can't create record\n"); - return; - } - - ret = nfc_ndef_record_get_encode_type(record, &type); - - nfc_ndef_record_destroy(record); - - dts_check_eq(__func__, ret, NFC_ERROR_NONE, "nfc_ndef_record_get_encode_type is failed"); -} - -static void utc_nfc_ndef_record_get_encode_type_n(void) -{ - int ret; - - ret = nfc_ndef_record_get_encode_type(NULL, NULL); - - dts_check_ne(__func__, ret, NFC_ERROR_NONE, "nfc_ndef_record_h not allow null"); -} - -static void utc_nfc_ndef_record_get_uri_p(void) -{ - int ret; - char *uri; - nfc_ndef_record_h record; - - ret = nfc_ndef_record_create_uri(&record, "http://test.com"); - if (ret != NFC_ERROR_NONE) { - dts_fail(__func__, "can't create record\n"); - return; - } - - ret = nfc_ndef_record_get_uri(record, &uri); - if (ret == 0) { - free(uri); - } - - nfc_ndef_record_destroy(record); - - dts_check_eq(__func__, ret, NFC_ERROR_NONE, "nfc_ndef_record_get_uri is failed"); -} - -static void utc_nfc_ndef_record_get_uri_n(void) -{ - int ret; - - ret = nfc_ndef_record_get_uri(NULL, NULL); - - dts_check_ne(__func__, ret, NFC_ERROR_NONE, "nfc_ndef_record_h not allow null"); -} - -static void utc_nfc_ndef_record_get_mime_type_p(void) -{ - int ret; - char *mime_type; - nfc_ndef_record_h record; - - ret = nfc_ndef_record_create_mime(&record, "text/plain", (unsigned char *)"the text record", sizeof("the text record")); - if (ret != NFC_ERROR_NONE) { - dts_fail(__func__, "can't create record\n"); - return; - } - - ret = nfc_ndef_record_get_mime_type(record, &mime_type); - if (ret == NFC_ERROR_NONE) { - free(mime_type); - } - - nfc_ndef_record_destroy(record); - - dts_check_eq(__func__, ret, NFC_ERROR_NONE, "nfc_ndef_record_get_mime_type is failed"); -} - -static void utc_nfc_ndef_record_get_mime_type_n(void) -{ - int ret; - - ret = nfc_ndef_record_get_mime_type(NULL, NULL); - - dts_check_eq(__func__, ret, NFC_ERROR_INVALID_PARAMETER, "nfc_ndef_record_h not allow null"); -} diff --git a/TC/testcase/utc_network_nfc_se.c b/TC/testcase/utc_network_nfc_se.c deleted file mode 100644 index 7181f2e..0000000 --- a/TC/testcase/utc_network_nfc_se.c +++ /dev/null @@ -1,151 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include - -enum -{ - POSITIVE_TC_IDX = 0x01, - NEGATIVE_TC_IDX, -}; - -static void startup(void); -static void cleanup(void); - -void (*tet_startup)(void) = startup; -void (*tet_cleanup)(void) = cleanup; - -static void nfc_se_open_secure_element_p(void); -static void nfc_se_open_secure_element_n(void); -static void nfc_se_get_atr_p(void); -static void nfc_se_get_atr_n(void); -static void nfc_se_send_apdu_p(void); -static void nfc_se_send_apdu_n(void); -static void nfc_se_close_secure_element_p(void); -static void nfc_se_close_secure_element_n(void); - -struct tet_testlist tet_testlist[] = -{ - { nfc_se_open_secure_element_p, POSITIVE_TC_IDX }, - { nfc_se_open_secure_element_n, NEGATIVE_TC_IDX }, - { nfc_se_get_atr_p, POSITIVE_TC_IDX }, - { nfc_se_get_atr_n, NEGATIVE_TC_IDX }, - { nfc_se_send_apdu_p, POSITIVE_TC_IDX }, - { nfc_se_send_apdu_n, NEGATIVE_TC_IDX }, - { nfc_se_close_secure_element_p, POSITIVE_TC_IDX }, - { nfc_se_close_secure_element_n, NEGATIVE_TC_IDX }, - - { NULL, 0 }, -}; - -//this method is called only once in start -static void startup(void) -{ - /* start of TC */ - nfc_manager_initialize(NULL, NULL); -} - -static void cleanup(void) -{ - /* end of TC */ - nfc_manager_deinitialize(); -} - -static nfc_se_h se_handle; - -static void nfc_se_open_secure_element_p(void) -{ - int ret; - - ret = nfc_se_open_secure_element(NFC_SE_TYPE_ESE, &se_handle); - - dts_check_eq(__func__, ret, NFC_ERROR_NONE, "nfc_se_open_secure_element is failed"); -} - -static void nfc_se_open_secure_element_n(void) -{ - int ret; - - ret = nfc_se_open_secure_element((nfc_se_type_e)0xff, NULL); - - dts_check_ne(__func__, ret, NFC_ERROR_NONE, "nfc_se_open_secure_element not allow null"); -} - -static void nfc_se_get_atr_p(void) -{ - int ret; - unsigned char *atr; - unsigned int atr_len; - - ret = nfc_se_get_atr(se_handle, &atr, &atr_len); - if (ret == NFC_ERROR_NONE) { - free(atr); - } - - dts_check_eq(__func__, ret, NFC_ERROR_NONE, "nfc_se_get_atr is failed"); -} - -static void nfc_se_get_atr_n(void) -{ - int ret; - - ret = nfc_se_get_atr(NULL, NULL, NULL); - - dts_check_ne(__func__, ret, NFC_ERROR_NONE, "nfc_se_get_atr not allow null"); -} - -static void nfc_se_send_apdu_p(void) -{ - int ret; - unsigned char cmd[] = { 0x00, 0x70, 0x00, 0x00, 0x00 }; - unsigned char *resp; - unsigned int resp_len; - - ret = nfc_se_send_apdu(se_handle, cmd, sizeof(cmd), &resp, &resp_len); - if (ret == NFC_ERROR_NONE) { - free(resp); - } - - dts_check_eq(__func__, ret, NFC_ERROR_NONE, "nfc_se_send_apdu is failed"); -} - -static void nfc_se_send_apdu_n(void) -{ - int ret; - - ret = nfc_se_send_apdu(NULL, NULL, 0, NULL, NULL); - - dts_check_ne(__func__, ret, NFC_ERROR_NONE, "nfc_se_send_apdu not allow null"); -} - -static void nfc_se_close_secure_element_p(void) -{ - int ret; - - ret = nfc_se_close_secure_element(se_handle); - - dts_check_eq(__func__, ret, NFC_ERROR_NONE, "nfc_se_close_secure_element is failed"); -} - -static void nfc_se_close_secure_element_n(void) -{ - int ret; - - ret = nfc_se_close_secure_element(NULL); - - dts_check_ne(__func__, ret, NFC_ERROR_NONE, "nfc_se_close_secure_element not allow null"); -} diff --git a/TC/testcase/utc_network_nfc_snep.c b/TC/testcase/utc_network_nfc_snep.c deleted file mode 100644 index 602825e..0000000 --- a/TC/testcase/utc_network_nfc_snep.c +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include - -enum -{ - POSITIVE_TC_IDX = 0x01, - NEGATIVE_TC_IDX, -}; - -static void startup(void); -static void cleanup(void); - -void (*tet_startup)(void) = startup; -void (*tet_cleanup)(void) = cleanup; - -static void nfc_snep_register_server_p(void); -static void nfc_snep_register_server_n(void); -static void nfc_snep_unregister_server_p(void); -static void nfc_snep_unregister_server_n(void); - -struct tet_testlist tet_testlist[] = -{ - { nfc_snep_register_server_p, POSITIVE_TC_IDX }, - { nfc_snep_register_server_n, NEGATIVE_TC_IDX }, - { nfc_snep_unregister_server_p, POSITIVE_TC_IDX }, - { nfc_snep_unregister_server_n, NEGATIVE_TC_IDX }, - - { NULL, 0 }, -}; - -static void _activation_completed_cb(nfc_error_e error, void *user_data) -{ - g_main_loop_quit((GMainLoop *)user_data); -} - -//this method is called only once in start -static void startup(void) -{ - /* start of TC */ - nfc_manager_initialize(NULL, NULL); - - if (nfc_manager_is_activated() == false) { - GMainLoop *loop; - - loop = g_main_loop_new(NULL, false); - - nfc_manager_set_activation(true, _activation_completed_cb, loop); - - g_main_loop_run(loop); - } -} - -static void cleanup(void) -{ - /* end of TC */ - nfc_manager_deinitialize(); -} - -static const char *san = "abcd:efgh"; -static int sap = 0x22; - -static void _snep_event_cb(nfc_p2p_snep_h handle, - nfc_snep_event_e event, nfc_error_e result, - nfc_ndef_message_h msg, void *user_data) -{ - -} - -static void nfc_snep_register_server_p(void) -{ - int ret; - - ret = nfc_snep_register_server(san, sap, _snep_event_cb, NULL); - if (ret == NFC_ERROR_NONE) { - nfc_snep_unregister_server(san, sap); - } - - dts_check_eq(__func__, ret, NFC_ERROR_NONE, "nfc_snep_register_server is failed"); -} - -static void nfc_snep_register_server_n(void) -{ - int ret; - - ret = nfc_snep_register_server(NULL, 0, NULL, NULL); - - dts_check_ne(__func__, ret, NFC_ERROR_NONE, "nfc_snep_register_server not allowed"); -} - -static void nfc_snep_unregister_server_p(void) -{ - int ret; - - ret = nfc_snep_register_server(san, sap, _snep_event_cb, NULL); - if (ret == NFC_ERROR_NONE) { - ret = nfc_snep_unregister_server(san, sap); - } - - dts_check_eq(__func__, ret, NFC_ERROR_NONE, "nfc_snep_register_server is failed"); -} - -static void nfc_snep_unregister_server_n(void) -{ - int ret; - - ret = nfc_snep_unregister_server(san, sap); - - dts_check_eq(__func__, ret, NFC_ERROR_NONE, "nfc_snep_register_server is failed"); -} diff --git a/TC/tet_scen b/TC/tet_scen deleted file mode 100644 index 03f029a..0000000 --- a/TC/tet_scen +++ /dev/null @@ -1,7 +0,0 @@ -all - ^TEST -##### Scenarios for TEST ##### - -# Test scenario -TEST - :include:/testcase/tslist diff --git a/TC/tetbuild.cfg b/TC/tetbuild.cfg deleted file mode 100644 index f7eda55..0000000 --- a/TC/tetbuild.cfg +++ /dev/null @@ -1,5 +0,0 @@ -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 deleted file mode 100644 index 02d7030..0000000 --- a/TC/tetclean.cfg +++ /dev/null @@ -1,5 +0,0 @@ -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 deleted file mode 100644 index ef3e452..0000000 --- a/TC/tetexec.cfg +++ /dev/null @@ -1,5 +0,0 @@ -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/capi-network-nfc.manifest b/capi-network-nfc.manifest new file mode 100644 index 0000000..ca37499 --- /dev/null +++ b/capi-network-nfc.manifest @@ -0,0 +1,6 @@ + + + + + + diff --git a/capi-network-nfc.pc.in b/capi-network-nfc.pc.in index 653e6e2..8792e0a 100644 --- a/capi-network-nfc.pc.in +++ b/capi-network-nfc.pc.in @@ -1,14 +1,15 @@ + # Package Information for pkg-config prefix=@PREFIX@ exec_prefix=/usr -libdir=@LIB_INSTALL_DIR@ -includedir=@INCLUDE_INSTALL_DIR@/@service@ +libdir=/usr/lib +includedir=/usr/include/network Name: @PC_NAME@ -Description: A NFC library in Tizen core API +Description: @PACKAGE_DESCRIPTION@ Version: @VERSION@ -Requires: @PC_REQUIRED@ +Requires: @PC_REQUIRED@ Libs: -L${libdir} @PC_LDFLAGS@ Cflags: -I${includedir} diff --git a/debian/README b/debian/README deleted file mode 100644 index e69de29..0000000 diff --git a/debian/capi-network-nfc-dev.install b/debian/capi-network-nfc-dev.install deleted file mode 100644 index 761a28b..0000000 --- a/debian/capi-network-nfc-dev.install +++ /dev/null @@ -1,4 +0,0 @@ -/usr/include/* -/usr/include/*/* -/usr/lib/pkgconfig/*.pc - diff --git a/debian/capi-network-nfc-dev.postinst b/debian/capi-network-nfc-dev.postinst deleted file mode 100644 index 1a24852..0000000 --- a/debian/capi-network-nfc-dev.postinst +++ /dev/null @@ -1 +0,0 @@ -#!/bin/sh diff --git a/debian/capi-network-nfc.install b/debian/capi-network-nfc.install deleted file mode 100644 index 4a755a4..0000000 --- a/debian/capi-network-nfc.install +++ /dev/null @@ -1 +0,0 @@ -/usr/lib/lib*.so* diff --git a/debian/capi-network-nfc.postinst b/debian/capi-network-nfc.postinst deleted file mode 100644 index 1a24852..0000000 --- a/debian/capi-network-nfc.postinst +++ /dev/null @@ -1 +0,0 @@ -#!/bin/sh diff --git a/debian/changelog b/debian/changelog deleted file mode 100644 index 9220c26..0000000 --- a/debian/changelog +++ /dev/null @@ -1,159 +0,0 @@ -capi-network-nfc (0.0.1-20) unstable; urgency=low - - * Modify the nfc set state function - * Git: slp/api/nfc - * Tag: capi-network-nfc_0.0.1-20 - - -- Sungjae Lim Wed, 11 July 2012 12:20:08 +0900 - -capi-network-nfc (0.0.1-19) unstable; urgency=low - - * ADD NFC Err case for empty tag and not ndef format - * Git: slp/api/nfc - * Tag: capi-network-nfc_0.0.1-19 - - -- Sechang Sohn Fri, 18 May 2012 14:20:08 +0900 - -capi-network-nfc (0.0.1-18) unstable; urgency=low - - * Patch for NFC Err case pssing issue - * Git: slp/api/nfc - * Tag: capi-network-nfc_0.0.1-18 - - -- Sechang Sohn Fri, 11 May 2012 14:45:44 +0900 - -capi-network-nfc (0.0.1-17) unstable; urgency=low - - * prevent NFC set state CB reset - * Git: slp/api/nfc - * Tag: capi-network-nfc_0.0.1-17 - - -- Sechang Sohn Wed, 18 Apr 2012 17:21:56 +0900 - -capi-network-nfc (0.0.1-16) unstable; urgency=low - - * make transfer NFC set state user data - * Git: slp/api/nfc - * Tag: capi-network-nfc_0.0.1-16 - - -- Sechang Sohn Tue, 10 Apr 2012 15:05:24 +0900 - -capi-network-nfc (0.0.1-15) unstable; urgency=low - - * Adjust the calling sequence of callback - * Git: slp/api/nfc - * Tag: capi-network-nfc_0.0.1-15 - - -- Wonkyu Kwon Mon, 09 Apr 2012 15:50:00 +0900 - -capi-network-nfc (0.0.1-14) unstable; urgency=low - - * add NFC nfc_manager_is_supported added - * Git: slp/api/nfc - * Tag: capi-network-nfc_0.0.1-14 - - -- Sechang Sohn Mon, 09 Apr 2012 12:18:51 +0900 - -capi-network-nfc (0.0.1-13) unstable; urgency=low - - * add NFC init/deinit CB - * Git: slp/api/nfc - * Tag: capi-network-nfc_0.0.1-13 - - -- Sechang Sohn Thu, 05 Apr 2012 14:15:52 +0900 - -capi-network-nfc (0.0.1-12) unstable; urgency=low - - * add NFC tag write exception - * Git: slp/api/nfc - * Tag: capi-network-nfc_0.0.1-12 - - -- Sechang Sohn Thu, 29 Mar 2012 14:28:33 +0900 - -capi-network-nfc (0.0.1-11) unstable; urgency=low - - * add SE event API - * Git: slp/api/nfc - * Tag: capi-network-nfc_0.0.1-11 - - -- Seungkeun Lee Tue, 20 Mar 2012 13:23:01 +0900 - -capi-network-nfc (0.0.1-10) unstable; urgency=low - - * add NFC API added - * Git: slp/api/nfc - * Tag: capi-network-nfc_0.0.1-10 - - -- Sechang Sohn Mon, 12 Mar 2012 18:44:59 +0900 - -capi-network-nfc (0.0.1-9) unstable; urgency=low - - * Type casting bug fix - * Git: slp/api/nfc - * Tag: capi-network-nfc_0.0.1-9 - - -- Sangsoo Lee Mon, 12 Mar 2012 15:50:05 +0900 - -capi-network-nfc (0.0.1-8) unstable; urgency=low - - * add NFC Handover API - * Git: slp/api/nfc - * Tag: capi-network-nfc_0.0.1-8 - - -- Sechang Sohn Mon, 27 Feb 2012 18:28:58 +0900 - -capi-network-nfc (0.0.1-7) unstable; urgency=low - - * add so version - * Git: slp/api/nfc - * Tag: capi-network-nfc_0.0.1-7 - - -- Seungkeun Lee , Kangho Hur Tue, 14 Feb 2012 16:49:32 +0900 - -capi-network-nfc (0.0.1-6) unstable; urgency=low - - * add extern - * Git: slp/api/nfc - * Tag: capi-network-nfc_0.0.1-6 - - -- Seungkeun Lee , Kangho Hur Mon, 06 Feb 2012 15:56:17 +0900 - -capi-network-nfc (0.0.1-5) unstable; urgency=low - - * Update bug fix - * Git: 165.213.149.219:29418/slp/api/nfc - * Tag: capi-network-nfc_0.0.1-5 - - -- Seungkeun Lee , Kangho Hur Wed, 14 Dec 2011 13:43:26 +0900 - -capi-network-nfc (0.0.1-4) unstable; urgency=low - - * update error none value - * Git: slp-source.sec.samsung.net:slp/api/nfc - * Tag: capi-network-nfc_0.0.1-4 - - -- Seungkeun Lee , Kangho Hur Mon, 05 Dec 2011 11:12:56 +0900 - -capi-network-nfc (0.0.1-3) unstable; urgency=low - - * Update New NFC API - * Git: slp-source.sec.samsung.net:slp/api/nfc - * Tag: capi-network-nfc_0.0.1-3 - - -- Seungkeun Lee , Kangho Hur Wed, 30 Nov 2011 17:59:15 +0900 - -capi-network-nfc (0.0.1-2) unstable; urgency=low - - * Update package dependancy - * Git: slp-source.sec.samsung.net:slp/api/nfc - * Tag: capi-network-nfc_0.0.1-2 - - -- Seungkeun Lee , Kangho Hur Mon, 29 Aug 2011 10:38:48 +0900 - -capi-network-nfc (0.0.1-1) unstable; urgency=low - - * Initial upload - * Git: slp-source.sec.samsung.net:slp/api/nfc - * Tag: capi-network-nfc_0.0.1-1 - - -- Seungkeun Lee , Kangho Hur Thu, 04 Aug 2011 17:46:48 +0900 diff --git a/debian/compat b/debian/compat deleted file mode 100644 index 7ed6ff8..0000000 --- a/debian/compat +++ /dev/null @@ -1 +0,0 @@ -5 diff --git a/debian/control b/debian/control deleted file mode 100644 index 884fca6..0000000 --- a/debian/control +++ /dev/null @@ -1,22 +0,0 @@ - -Source: capi-network-nfc -Section: libs -Priority: extra -Maintainer: Sechang Sohn , Sungjae Lim , Seungkeun Lee , Kangho Hur -Build-Depends: debhelper (>= 5), libnfc-common-lib-dev, libnfc-manager-dev, dlog-dev, capi-base-common-dev, libglib2.0-dev - -Package: capi-network-nfc -Architecture: any -Depends: ${shlibs:Depends}, ${misc:Depends} -Description: A NFC library in Tizen Native API - -Package: capi-network-nfc-dev -Architecture: any -Depends: ${shlibs:Depends}, ${misc:Depends}, capi-network-nfc (= ${Source-Version}), capi-base-common-dev -Description: A NFC library in Tizen Native API (DEV) - -Package: capi-network-nfc-dbg -Architecture: any -Depends: ${shlibs:Depends}, ${misc:Depends}, capi-network-nfc (= ${Source-Version}) -Description: A NFC library in Tizen Native API (DBG) - diff --git a/debian/rules b/debian/rules deleted file mode 100755 index d075260..0000000 --- a/debian/rules +++ /dev/null @@ -1,68 +0,0 @@ -#!/usr/bin/make -f - -CFLAGS = -Wall -g - -FULLVER ?= $(shell dpkg-parsechangelog | grep Version: | cut -d ' ' -f 2 | cut -d '-' -f 1) -MAJORVER ?= $(shell echo $(FULLVER) | cut -d '.' -f 1) - -ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS))) - CFLAGS += -O0 -else - CFLAGS += -O2 -endif -CMAKE_ROOT_DIR ?= $(CURDIR) -CMAKE_BUILD_DIR ?= $(CURDIR)/cmake_build_tmp - -configure: configure-stamp -configure-stamp: - dh_testdir - mkdir -p $(CMAKE_BUILD_DIR) && cd $(CMAKE_BUILD_DIR) && cmake .. -DFULLVER=${FULLVER} -DMAJORVER=${MAJORVER} - touch configure-stamp - - -build: build-stamp -build-stamp: configure-stamp - dh_testdir - cd $(CMAKE_BUILD_DIR) && $(MAKE) - touch $@ - -clean: - cd $(CMAKE_ROOT_DIR) - dh_testdir - dh_testroot - rm -f build-stamp configure-stamp - rm -f - rm -rf $(CMAKE_BUILD_DIR) - dh_clean - -install: build - dh_testdir - dh_testroot - dh_clean -k - dh_installdirs - - cd $(CMAKE_BUILD_DIR) && $(MAKE) DESTDIR=$(CURDIR)/debian/tmp install - -binary-indep: build install - -binary-arch: build install - dh_testdir - dh_testroot - dh_installchangelogs - dh_installdocs - dh_installexamples - dh_install --sourcedir=debian/tmp - dh_installman - dh_link - dh_strip --dbg-package=capi-network-nfc-dbg - dh_fixperms - 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/doc/nfc_doc.h b/doc/nfc_doc.h new file mode 100755 index 0000000..2cb660d --- /dev/null +++ b/doc/nfc_doc.h @@ -0,0 +1,297 @@ +/* + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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. + */ + + + /** + * @file nfc_doc.h + * @brief This file contains high level documentation the NFC API. + */ + +/** + * @defgroup CAPI_NETWORK_NFC_MODULE NFC + * @brief The NFC API provides very short-range radio communication technology. + * @ingroup CAPI_NETWORK_FRAMEWORK + * + * @par + * @section CAPI_NETWORK_NFC_MODULE_HEADER Required Header + * \#include + * @section CAPI_NETWORK_NFC_MODULE_OVERVIEW Overview + * NFC Service enables applications to\n + * - set up nfc manager\n + * - read / write ndef message or raw data and get attribute of tag\n + * - create NDEF(NFC Data Exchange Format) message or NDEF record\n + * - receive/send ndef message to the peer target\n + * - read / write data to the Secure Element for Card Emulation mode\n + * + * @subsection CAPI_NETWORK_NFC_MANAGER_MODULE_DESCRIPTION nfc-manager + * The nfc manager api provides functions to connect nfc-server and register event listener\n + * - control connection with nfc-server. \n + * - register / deregister event listeners for detecting tag, ndef, llcp, secure element \n + * - set / unset tag filter to be listened only in case of specific tag. \n + * + * @subsection CAPI_NETWORK_NFC_NDEF_MODULE_DESCRIPTION NDEF(NFC Data Exchange Format) + * The NDEF(NFC Data Exchange Format) api provides functions to make NDEF record and NDEF message.\n + * - create NDEF record and retrieve specific field of NDEF record\n + * - create NDEF message with NDEF records\n + * + * @subsection CAPI_NETWORK_NFC_TAG_MODULE_DESCRIPTION TAG + * The TAG api provide functions to read or write NDEF(NFC Data Exchange Format) and also low level transaction API with Non NDEF tag. \n + * - read NDEF from NDEF compatible TAG\n + * - write NDEF to NDEF compatible TAG\n + * - check whether tag has NDEF or not\n + * - format NFC forum tag to be compatible with NDEF\n + * - read specific attributes from tag by ISO14443\n + * - low level api of MIFARE classic and MIFARE ultra light\n + * + * @subsection CAPI_NETWORK_NFC_P2P_MODULE_DESCRIPTION Peer to Peer + * The Peer to Peer api provide functions to exchange NDEF data with peer target. + * - send ndef message\n + * - receive ndef message\n + * + * @subsection CAPI_NETWORK_NFC_SE_MODULE_DESCRIPTION Card Emulation + * The Card Emulation api provide functions to exchange data with Secure Element. + * - send apdu to secure element\n + * - get atr from secure element\n + */ + +/** + * @defgroup CAPI_NETWORK_NFC_MANAGER_MODULE Manager + * @brief NFC Manager API provides access to NFC Events. + * @ingroup CAPI_NETWORK_NFC_MODULE + * + * @section CAPI_NETWORK_NFC_MANAGER_MODULE_HEADER Required Header + * \#include + * @section CAPI_NETWORK_NFC_MANAGER_MODULE_OVERVIEW Overview + * The nfc manager api provides functions to connect nfc-server and register event listener\n + * - control connection with nfc-server. \n + * - register / deregister event listeners for detecting tag, ndef, llcp, secure element \n + * - set / unset tag filter to be listened only in case of specific tag. \n + * @section CAPI_NETWORK_NFC_MANAGER_MODULE_FEATURE Related Features + * This API is related with the following features:\n + * - http://tizen.org/feature/network.nfc\n + * - http://tizen.org/feature/network.nfc.tag\n + * - http://tizen.org/feature/network.nfc.p2p\n + * - http://tizen.org/feature/network.nfc.card_emulation\n + * - http://tizen.org/feature/network.secure_element.uicc\n + * - http://tizen.org/feature/network.secure_element.ese\n + * + * It is recommended to design feature related codes in your application for reliability.\n + * + * You can check if a devrice supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE, thereby controlling the procedure of your application.\n + * + * To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.\n + * + * More details on featuring your application can be found from Feature Element. + * + */ + + +/** + * @defgroup CAPI_NETWORK_NFC_NDEF_MODULE NDEF + * @brief The NDEF api provides functions to make NDEF record and NDEF message. + * @ingroup CAPI_NETWORK_NFC_MODULE + * @section CAPI_NETWORK_NFC_NDEF_MODULE_HEADER Required Header + * \#include + * @section CAPI_NETWORK_NFC_NDEF_MODULE_OVERVIEW Overview + * The NDEF api provides functions to make NDEF record and NDEF message.\n + * - create NDEF record and retrieve specific field of NDEF record\n + * - create NDEF message with NDEF records\n + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
APIs Description
@ref CAPI_NETWORK_NFC_NDEF_RECORD_MODULE Record API provides NDEF record and retrieve specific field of NDEF record
@ref CAPI_NETWORK_NFC_NDEF_MESSAGE_MODULE Message API provides functions to create NDEF message and insert/remove records in NDEF message
+ * + */ + +/** + * @defgroup CAPI_NETWORK_NFC_NDEF_RECORD_MODULE Record + * @ingroup CAPI_NETWORK_NFC_NDEF_MODULE + * @brief Record API provides an NDEF record. + * @section CAPI_NETWORK_NFC_NDEF_RECORD_MODULE_HEADER Required Header + * \#include + * + * @section CAPI_NETWORK_NFC_NDEF_RECORD_MODULE_OVERVIEW Overview + * The NDEF record api provides functions to make NDEF record\n + * - create / destroy NDEF record\n + * - set / get elements from NDEF record\n + * + * @section CAPI_NETWORK_NFC_NDEF_RECORD_MODULE_FEATURE Related Features + * This API is related with the following features:\n + * - http://tizen.org/feature/network.nfc\n + * + * It is recommended to design feature related codes in your application for reliability.\n + * + * You can check if a devrice supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE, thereby controlling the procedure of your application.\n + * + * To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.\n + * + * More details on featuring your application can be found from Feature Element. + * + */ + +/** + * @defgroup CAPI_NETWORK_NFC_NDEF_MESSAGE_MODULE Message + * @ingroup CAPI_NETWORK_NFC_NDEF_MODULE + * @brief Message API provides functions to create NDEF message and insert/remove records in NDEF message + * @section CAPI_NETWORK_NFC_NDEF_MESSAGE_MODULE_HEADER Required Header + * \#include + * + * @section CAPI_NETWORK_NFC_NDEF_MESSAGE_MODULE_OVERVIEW Overview + * The NDEF message api provides functions to make NDEF message\n + * - create / destroy NDEF message\n + * - insert / remove NDEF record\n + * - get NDEF record from NDEF message\n + * + * @section CAPI_NETWORK_NFC_NDEF_MESSAGE_MODULE_FEATURE Related Features + * This API is related with the following features:\n + * - http://tizen.org/feature/network.nfc\n + * + * It is recommended to design feature related codes in your application for reliability.\n + * + * You can check if a devrice supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE, thereby controlling the procedure of your application.\n + * + * To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.\n + * + * More details on featuring your application can be found from Feature Element. + * + */ + +/** + * @defgroup CAPI_NETWORK_NFC_TAG_MODULE TAG + * @ingroup CAPI_NETWORK_NFC_MODULE + * @brief TAG API provide functions for read/write operation on NDEF and also provide low level API of Mifare + * @section CAPI_NETWORK_NFC_TAG_MODULE_HEADER Required Header + * \#include + * @section CAPI_NETWORK_NFC_TAG_MODULE_OVERVIEW Overview + * The TAG api provides functions to read or write NDEF and low level transaction APIs with Non NDEF tag. \n + * - read NDEF from NDEF compatible TAG\n + * - write NDEF to NDEF compatible TAG\n + * - check whether tag has NDEF or not\n + * - format NFC forum tag to be compatible with NDEF\n + * - read specific attributes from tag by ISO14443\n + * - low level api of MIFARE classic and MIFARE ultra light\n + * @section CAPI_NETWORK_NFC_TAG_MODULE_FEATURE Related Features + * This API is related with the following features:\n + * - http://tizen.org/feature/network.nfc\n + * - http://tizen.org/feature/network.nfc.tag\n + * + * It is recommended to design feature related codes in your application for reliability.\n + * + * You can check if a devrice supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE, thereby controlling the procedure of your application.\n + * + * To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.\n + * + * More details on featuring your application can be found from Feature Element. + * + */ + +/** + * @defgroup CAPI_NETWORK_NFC_TAG_MIFARE_MODULE Mifare + * @ingroup CAPI_NETWORK_NFC_TAG_MODULE + * @brief API provides access to MIFARE specific I/O operations on a Tag. + * @section CAPI_NETWORK_NFC_TAG_MIFARE_MODULE_HEADER Required Header + * \#include + * @section CAPI_NETWORK_NFC_TAG_MIFARE_MODULE_OVERVIEW Overview + + MIFARE Classic is also known as MIFARE Standard.\n + MIFARE Classic tags are divided into sectors, and each sector is sub-divided into blocks. Block size is always 16 bytes.\n + + MIFARE Classic Mini are 320 bytes (SIZE_MINI), with 5 sectors each of 4 blocks.\n + MIFARE Classic 1k are 1024 bytes (SIZE_1K), with 16 sectors each of 4 blocks.\n + MIFARE Classic 2k are 2048 bytes (SIZE_2K), with 32 sectors each of 4 blocks.\n + MIFARE Classic 4k are 4096 bytes (SIZE_4K). The first 32 sectors contain 4 blocks and the last 8 sectors contain 16 blocks.\n + + MIFARE Classic tags require authentication on a per-sector basis before any other I/O operations on that sector can be performed. \n + There are two keys per sector, and ACL bits determine what I/O operations are allowed on that sector after authenticating with a key\n + * @section CAPI_NETWORK_NFC_TAG_MIFARE_MODULE_FEATURE Related Features + * This API is related with the following features:\n + * - http://tizen.org/feature/network.nfc\n + * - http://tizen.org/feature/network.nfc.tag\n + * + * It is recommended to design feature related codes in your application for reliability.\n + * + * You can check if a devrice supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE, thereby controlling the procedure of your application.\n + * + * To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.\n + * + * More details on featuring your application can be found from Feature Element. + * + */ + + + /** + * @defgroup CAPI_NETWORK_NFC_P2P_MODULE Peer to Peer + * @ingroup CAPI_NETWORK_NFC_MODULE + * @brief The peer to peer api provide functions to exchange NDEF data with peer target. + * @section CAPI_NETWORK_NFC_P2P_MODULE_HEADER Required Header + * \#include + * @section CAPI_NETWORK_NFC_P2P_MODULE_OVERVIEW Overview + * The peer to peer api provides functions to exchange NDEF data with the peer target. \n + * - send ndef message + * - receive ndef message + * @section CAPI_NETWORK_NFC_P2P_MODULE_FEATURE Related Features + * This API is related with the following features:\n + * - http://tizen.org/feature/network.nfc\n + * - http://tizen.org/feature/network.nfc.p2p\n + * + * It is recommended to design feature related codes in your application for reliability.\n + * + * You can check if a devrice supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE, thereby controlling the procedure of your application.\n + * + * To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.\n + * + * More details on featuring your application can be found from Feature Element. + * + */ + + /** + * @defgroup CAPI_NETWORK_NFC_SE_MODULE Card Emulation + * @ingroup CAPI_NETWORK_NFC_MODULE + * @brief The Card Emulation api provide functions to exchange data with Secure Element. + * @section CAPI_NETWORK_NFC_SE_MODULE_HEADER Required Header + * \#include + * @section CAPI_NETWORK_NFC_SE_MODULE_OVERVIEW Overview + * The Card Emulation api provide functions to exchange data with Secure Element. \n + * - send apdu to secure element + * - get atr from secure element + * @section CAPI_NETWORK_NFC_SE_MODULE_FEATURE Related Features + * This API is related with the following features:\n + * - http://tizen.org/feature/network.nfc\n + * - http://tizen.org/feature/network.nfc.card_emulation\n + * - http://tizen.org/feature/network.nfc.card_emulation.hce\n + * - http://tizen.org/feature/network.secure_element.uicc\n + * - http://tizen.org/feature/network.secure_element.ese\n + * + * It is recommended to design feature related codes in your application for reliability.\n + * + * You can check if a devrice supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE, thereby controlling the procedure of your application.\n + * + * To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.\n + * + * More details on featuring your application can be found from Feature Element. + * + */ diff --git a/include/nfc.h b/include/nfc.h old mode 100644 new mode 100755 index 0b2c5ac..4176e41 --- a/include/nfc.h +++ b/include/nfc.h @@ -29,11 +29,11 @@ extern "C" { * @brief This file contains the NFC API. */ -#define NFC_ERROR_CLASS TIZEN_ERROR_NETWORK_CLASS | 0x200 - +#define NFC_ERROR_CLASS TIZEN_ERROR_NFC /** * @brief Error codes reported by the NFC API. + * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif * @ingroup CAPI_NETWORK_NFC_MANAGER_MODULE */ typedef enum { @@ -47,18 +47,24 @@ typedef enum { NFC_ERROR_DEVICE_BUSY = TIZEN_ERROR_RESOURCE_BUSY, /**< Previous operation is not finished still busy */ NFC_ERROR_NO_DEVICE = NFC_ERROR_CLASS | 0x04, /**< no device */ NFC_ERROR_NOT_ACTIVATED = NFC_ERROR_CLASS | 0x05, /**< NFC is not activated */ - NFC_ERROR_NOT_SUPPORTED = NFC_ERROR_CLASS | 0x06, /**< Not supported */ - NFC_ERROR_ALREADY_ACTIVATED = NFC_ERROR_CLASS | 0x07, /**< Already activated */ - NFC_ERROR_ALREADY_DEACTIVATED = NFC_ERROR_CLASS | 0x08, /**< Already deactivated */ - NFC_ERROR_READ_ONLY_NDEF = NFC_ERROR_CLASS | 0x09, /**< Read only tag */ - NFC_ERROR_NO_SPACE_ON_NDEF = NFC_ERROR_CLASS | 0x0a, /**< No enough space on tag */ - NFC_ERROR_NO_NDEF_MESSAGE = NFC_ERROR_CLASS | 0x0b, /**< No NDEF Message on Tag */ - NFC_ERROR_NOT_NDEF_FORMAT = NFC_ERROR_CLASS | 0x0c, /**< Not NDEF format Tag */ - NFC_ERROR_SECURITY_RESTRICTED = NFC_ERROR_CLASS | 0x0d /**< Restricted by security system policy */ + NFC_ERROR_NOT_SUPPORTED = TIZEN_ERROR_NOT_SUPPORTED, /**< Not supported */ + NFC_ERROR_ALREADY_ACTIVATED = NFC_ERROR_CLASS | 0x06, /**< Already activated */ + NFC_ERROR_ALREADY_DEACTIVATED = NFC_ERROR_CLASS | 0x07, /**< Already deactivated */ + NFC_ERROR_READ_ONLY_NDEF = NFC_ERROR_CLASS | 0x08, /**< Read only tag */ + NFC_ERROR_NO_SPACE_ON_NDEF = NFC_ERROR_CLASS | 0x09, /**< No enough space on tag */ + NFC_ERROR_NO_NDEF_MESSAGE = NFC_ERROR_CLASS | 0x0a, /**< No NDEF Message on Tag */ + NFC_ERROR_NOT_NDEF_FORMAT = NFC_ERROR_CLASS | 0x0b, /**< Not NDEF format Tag */ + NFC_ERROR_SECURITY_RESTRICTED = NFC_ERROR_CLASS | 0x0c, /**< Restricted by access control */ + NFC_ERROR_PERMISSION_DENIED = TIZEN_ERROR_PERMISSION_DENIED, /**< Restricted by Smack */ + NFC_ERROR_ILLEGAL_STATE = NFC_ERROR_CLASS | 0x0d, /**< The state is wrong */ + NFC_ERROR_NOT_INITIALIZED = NFC_ERROR_CLASS | 0x0e, /**< NFC is not initialized */ + NFC_ERROR_TAG_NOT_SUPPORTED = NFC_ERROR_CLASS | 0x0f, /**< Tag is not supported */ + NFC_ERROR_AID_ALREADY_REGISTERED = NFC_ERROR_CLASS | 0x10 /**< AID already registered (@b Since: 2.3.1) */ } nfc_error_e; /** * @brief Enumerations for record TNF (Type Name Format) + * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif * @details It is indicate format of type field * @ingroup CAPI_NETWORK_NFC_NDEF_RECORD_MODULE */ @@ -75,6 +81,7 @@ typedef enum { /** * @brief Enumerations for NFC encode types + * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif * @ingroup CAPI_NETWORK_NFC_NDEF_RECORD_MODULE */ typedef enum { @@ -84,6 +91,7 @@ typedef enum { /** * @brief Enumerations for NFC tag types + * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif * @ingroup CAPI_NETWORK_NFC_TAG_MODULE */ typedef enum { @@ -92,9 +100,9 @@ typedef enum { NFC_ISO14443_A_PICC, /**< ISO14443_A PICC */ NFC_ISO14443_4A_PICC, /**< ISO14443_4A PICC */ NFC_ISO14443_3A_PICC, /**< ISO14443_3A PICC */ - NFC_MIFARE_MINI_PICC, /**< MIFARE_MINI_PICC */ - NFC_MIFARE_1K_PICC, /**< MIFARE_1K_PICC */ - NFC_MIFARE_4K_PICC, /**< MIFARE_4K_PICC */ + NFC_MIFARE_MINI_PICC, /**< MIFARE_MINI_PICC */ + NFC_MIFARE_1K_PICC, /**< MIFARE_1K_PICC */ + NFC_MIFARE_4K_PICC, /**< MIFARE_4K_PICC */ NFC_MIFARE_ULTRA_PICC, /**< MIFARE_ULTRA_PICC */ NFC_MIFARE_DESFIRE_PICC, /**< MIFARE_DESFIRE_PICC */ NFC_ISO14443_B_PICC, /**< ISO14443_B PICC */ @@ -103,14 +111,16 @@ typedef enum { NFC_FELICA_PICC, /**< FELICA PICC */ NFC_JEWEL_PICC, /**< JEWEL PICC */ NFC_ISO15693_PICC, /**< ISO15693 PICC */ + NFC_BARCODE_128_PICC, /**< BARCODE_128 PICC */ + NFC_BARCODE_256_PICC, /**< BARCODE_256 PICC */ + NFC_NFCIP1_TARGET, /**< NFCIP1_TARGET */ NFC_NFCIP1_INITIATOR, /**< NFCIP1_INITIATOR */ } nfc_tag_type_e; - - /** * @brief Enumerations for NFC Tag filter + * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif * @ingroup CAPI_NETWORK_NFC_MANAGER_MODULE */ typedef enum { @@ -125,18 +135,8 @@ typedef enum { } nfc_tag_filter_e; /** - * @brief Enumerations of polling request code for FeliCa tag - * @ingroup CAPI_NETWORK_NFC_TAG_FELICA - */ -typedef enum { - NFC_TAG_FELICA_POLL_NO_REQUEST = 0x00, /**< NO REQUEST */ - NFC_TAG_FELICA_POLL_SYSTEM_CODE_REQUEST= 0x01, /**< SYSTEM CODE REQUEST */ - NFC_TAG_FELICA_POLL_COMM_SPEED_REQUEST= 0x02, /**< COMM SPEED REQUEST */ -} nfc_tag_felica_poll_request_code_e; - - -/** * @brief Enumerations for NFC discovered type + * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif * @ingroup CAPI_NETWORK_NFC_MANAGER_MODULE */ typedef enum { @@ -146,14 +146,15 @@ typedef enum { /** * @brief Enumerations for NFC Secure Element (SIM/UICC(Universal Integrated Circuit Card)) event + * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif * @ingroup CAPI_NETWORK_NFC_MANAGER_MODULE */ typedef enum{ NFC_SE_EVENT_START_TRANSACTION, /**< This event notifies the terminal host that it shall launch an application associated to an NFC application in a UICC(Universal Integrated Circuit Card) host. */ - NFC_SE_EVENT_END_TRANSACTION, /**< This event notifies the terminal host that current transaction in process was ended. */ - NFC_SE_EVENT_CONNECTIVITY, /**< It's ready signal to communicate UICC(Universal Integrated Circuit Card) with terminal host. \nUICC(Universal Integrated Circuit Card) create pipe and open the pipe chanel.\nThen it sends the signal to terminal host or host controller. */ - NFC_SE_EVENT_FIELD_ON, /**< When the CLF(Contactless Front-end) detects a RF field, the card RF gate sends the event #NFC_SE_EVENT_FIELD_ON to the card application gate.\nWhen there are multiple open card RF gates the CLF shall send the #NFC_SE_EVENT_FIELD_ON on all open pipes to these gates.Next the CLF starts the initialization and anti-collision process as defined in ISO/IEC 14443-3 [6]*/ - NFC_SE_EVENT_FIELD_OFF, /**< When the CLF(Contactless Front-end) detects that the RF field is off, the card RF gate shall send #NFC_SE_EVENT_FIELD_OFF to the card application gate.\nWhen there are multiple open card RF gates the CLF shall send the #NFC_SE_EVENT_FIELD_OFF to one gate only.*/ + NFC_SE_EVENT_END_TRANSACTION, /**< This event notifies the terminal host that current transaction in process was ended. */ + NFC_SE_EVENT_CONNECTIVITY, /**< It's ready signal to communicate UICC(Universal Integrated Circuit Card) with terminal host. UICC(Universal Integrated Circuit Card) create pipe and open the pipe chanel. Then it sends the signal to terminal host or host controller. */ + NFC_SE_EVENT_FIELD_ON, /**< When the CLF(Contactless Front-end) detects a RF field, the card RF gate sends the event #NFC_SE_EVENT_FIELD_ON to the card application gate. When there are multiple open card RF gates the CLF shall send the #NFC_SE_EVENT_FIELD_ON on all open pipes to these gates.Next the CLF starts the initialization and anti-collision process as defined in ISO/IEC 14443-3 [6]*/ + NFC_SE_EVENT_FIELD_OFF, /**< When the CLF(Contactless Front-end) detects that the RF field is off, the card RF gate shall send #NFC_SE_EVENT_FIELD_OFF to the card application gate. When there are multiple open card RF gates the CLF shall send the #NFC_SE_EVENT_FIELD_OFF to one gate only.*/ NFC_SE_EVENT_TRANSACTION, /**< This event notifies , external reader trys to access secure element */ NFC_SE_EVENT_SE_TYPE_CHANGED, /**< This event notifies, changing the emulated secure element type */ NFC_SE_EVENT_CARD_EMULATION_CHANGED, /**< This event notifies, changing the card emulation mode */ @@ -161,16 +162,20 @@ typedef enum{ /** * @brief Enumerations for NFC Secure Element (SIM/UICC(Universal Integrated Circuit Card)) type + * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif * @ingroup CAPI_NETWORK_NFC_MANAGER_MODULE */ typedef enum{ NFC_SE_TYPE_DISABLE = 0x00, /**< Disable card emulation */ NFC_SE_TYPE_ESE = 0x01, /**< SmartMX type card emulation */ - NFC_SE_TYPE_UICC = 0x02 /**< UICC type card emulation */ + NFC_SE_TYPE_UICC = 0x02, /**< UICC type card emulation */ + NFC_SE_TYPE_SDCARD = 0x03, /**< SDCARD card emulation (Not yet supported on Tizen) (@b Since: 2.3.1) */ + NFC_SE_TYPE_HCE = 0x04 /**< Host based card emulation (@b Since: 2.3.1) */ } nfc_se_type_e; /** * @brief Enumerations for NFC Card Emulation Mode type + * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif * @ingroup CAPI_NETWORK_NFC_MANAGER_MODULE */ typedef enum{ @@ -179,18 +184,8 @@ typedef enum{ } nfc_se_card_emulation_mode_type_e; /** - * @brief Enumerations for NFC AC(Alternative Carrier) - * @ingroup CAPI_NETWORK_NFC_P2P_MODULE - */ -typedef enum { - NFC_AC_TYPE_BT = 0x00, /**< Bluetooth AC*/ - NFC_AC_TYPE_WIFI, /** +#include +#include + +#include +#include +#include + +#include "net_nfc.h" +#include "nfc.h" +#include "nfc_internal.h" + +#define COLOR_RED "\033[0;31m" +#define COLOR_GREEN "\033[0;32m" +#define COLOR_BROWN "\033[0;33m" +#define COLOR_BLUE "\033[0;34m" +#define COLOR_PURPLE "\033[0;35m" +#define COLOR_CYAN "\033[0;36m" +#define COLOR_LIGHTBLUE "\033[0;37m" +#define COLOR_END "\033[0;m" + +#define NFC_FEATURE "http://tizen.org/feature/network.nfc" +#define NFC_TAG_FEATURE "http://tizen.org/feature/network.nfc" +#define NFC_P2P_FEATURE "http://tizen.org/feature/network.nfc" +#define NFC_CE_FEATURE "http://tizen.org/feature/network.nfc.card_emulation" +#define NFC_CE_HCE_FEATURE "http://tizen.org/feature/network.nfc.card_emulation.hce" + +#define CHECK_INIT() \ + do{\ + if(nfc_common_is_initialized() == false) \ + { \ + LOG_ERR("[ERROR][%s] NFC not initialized", __func__); \ + return NFC_ERROR_NOT_INITIALIZED; \ + } \ + }while(0) + +#define CHECK_SUPPORTED(str) \ + do{\ + if(nfc_common_is_supported(str) == false) \ + { \ + LOG_ERR("[ERROR][%s] NFC not supported", __func__); \ + return NFC_ERROR_NOT_SUPPORTED; \ + } \ + }while(0) + +#define CHECK_ACTIVATED() \ + do{\ + if (!nfc_manager_is_activated()) \ + { \ + LOG_ERR("[ERROR][%s] NFC not activated", __func__); \ + return NFC_ERROR_NOT_ACTIVATED; \ + } \ + } while(0) + +#define CHECK_INVALID(expr) \ + do{\ + if (expr) \ + { \ + LOG_ERR("[ERROR][%s] INVALID PARAMETER (%s)", __func__, #expr); \ + return NFC_ERROR_INVALID_PARAMETER; \ + } \ + } while(0) + +#define CHECK_APP_PERMISSION() \ + do{\ + if (nfc_common_check_app_permission() == false) \ + { \ + LOG_ERR("[ERROR][%s] Permission check fail", __func__); \ + return NFC_ERROR_SECURITY_RESTRICTED; \ + } \ + } while(0) + +#ifdef LOG_TAG +#undef LOG_TAG +#endif + +#define LOG_TAG "NFC_CAPI" + +#define LOG_DEBUG(fmt, ...) \ + do { \ + LOGD(COLOR_BROWN" " fmt COLOR_END, ##__VA_ARGS__); \ + } while (0) +#define LOG_ERR(fmt, ...) \ + do { \ + LOGE(COLOR_RED" " fmt COLOR_END, ##__VA_ARGS__); \ + } while (0) +#define LOG_BEGIN() \ + do { \ + LOGD(COLOR_BLUE"BEGIN >>>>"COLOR_END); \ + } while (0) +#define LOG_END() \ + do { \ + LOGD(COLOR_BLUE"END <<<<"COLOR_END); \ + } while (0) + +typedef struct +{ + bool initialized; + bool on_activation_doing; + + net_nfc_target_info_h current_tag; + + //net_nfc_target_handle_s current_target; + net_nfc_target_handle_h current_target; + + nfc_tag_discovered_cb on_tag_discovered_cb; + void *on_tag_discovered_user_data; + + nfc_ndef_discovered_cb on_ndef_discovered_cb; + void *on_ndef_discovered_user_data; + + nfc_p2p_target_discovered_cb on_p2p_target_discovered_cb; + void *on_p2p_target_discovered_user_data; + + nfc_p2p_data_received_cb on_p2p_recv_cb; + void *on_p2p_recv_user_data; + + nfc_se_event_cb on_se_event_cb; + void *on_se_event_user_data; + + nfc_se_transaction_event_cb on_se_transaction_event_cb; + void *on_se_transaction_event_user_data; + + nfc_connection_handover_event_cb on_handover_event_cb; + void *on_handover_event_user_data; + + nfc_hce_event_cb on_hce_event_cb; + void *on_hce_event_user_data; + + nfc_se_registered_aid_cb on_se_registered_aid_cb; + void *on_se_registered_aid_cb_user_data; +} +_nfc_context_s; + +_nfc_context_s gdbus_nfc_context; + +pid_t nfc_common_get_focus_app_pid(); +char * nfc_common_get_bt_address_string(data_h data); +bool nfc_common_check_app_permission(); +int nfc_common_convert_error_code(const char *func, int native_error_code); +bool nfc_common_is_initialized(); +bool nfc_common_is_supported(char *str); +int nfc_common_get_rawdata_size(nfc_ndef_message_h ndef_message, unsigned int *byte_size); + +#endif // __NFC_LOG_H__ diff --git a/include/nfc_internal.h b/include/nfc_internal.h old mode 100644 new mode 100755 index 9ab6e87..22f7ce0 --- a/include/nfc_internal.h +++ b/include/nfc_internal.h @@ -1,52 +1,562 @@ /* -* Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + #ifndef __NFC_INTERNAL_H__ #define __NFC_INTERNAL_H__ -#include - #include "nfc.h" -typedef struct -{ - bool initialized; - bool on_activation_doing; +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Enumerations for Handover event + * @ingroup CAPI_NETWORK_NFC_HANDOVER_MODULE + */ +typedef enum { + NFC_HANDOVER_EVENT_START = 0x00, /**< handover started */ + NFC_HANDOVER_EVENT_FINISH = 0x01, /**< handover finished */ +} nfc_handover_event_e; + +/** + * @brief Enumerations for NFC AC(Alternative Carrier) + * @ingroup CAPI_NETWORK_NFC_HANDOVER_MODULE + */ +typedef enum { + NFC_AC_TYPE_BT = 0x00, /**< Bluetooth AC*/ + NFC_AC_TYPE_WIFI, /** -#include - -#include "nfc.h" - - -typedef enum { - _NFC_CALLBACK_TYPE_RESULT=0, - _NFC_CALLBACK_TYPE_DATA=1, -} _nfc_callback_type; - - -typedef struct { - bool initialized; - - nfc_tag_discovered_cb on_tag_discovered_cb; - void * on_tag_discovered_user_data; - nfc_ndef_discovered_cb on_ndef_discovered_cb; - void * on_ndef_discovered_user_data; - net_nfc_target_info_s *current_tag; - - //net_nfc_target_handle_s current_target; - net_nfc_target_handle_h current_target; - - nfc_p2p_target_discovered_cb on_p2p_discovered_cb; - void * on_p2p_discovered_user_data; - - nfc_se_event_cb on_se_event_cb; - void * on_se_event_user_data; - - nfc_p2p_send_completed_cb on_p2p_send_completed_cb; - void * on_p2p_send_completed_user_data; - - nfc_p2p_data_recived_cb on_p2p_recv_cb; - void * on_p2p_recv_user_data; - - nfc_p2p_connection_handover_completed_cb on_p2p_connection_handover_completed_cb; - void * on_p2p_connection_handover_completed_user_data; - - nfc_initialize_completed_cb on_initialize_completed_cb; - - //nfc_se_transaction_event_cb on_se_transaction_event_cb; - //void * on_se_transaction_event_user_data; - - nfc_se_transaction_event_cb on_eSE_transaction_event_cb; - void * on_eSE_transaction_event_user_data; - - nfc_se_transaction_event_cb on_UICC_transaction_event_cb; - void * on_UICC_transaction_event_user_data; - - net_nfc_se_type_e on_se_type; - - nfc_activation_changed_cb on_activation_changed_cb; - void * on_activation_changed_user_data; - - nfc_activation_completed_cb on_activation_completed_cb; - void * on_activation_completed_user_data; - bool on_activation_doing; - -} _nfc_context_s; - -typedef struct { - void * callback; - void * user_data; - int callback_type; -} _async_callback_data; - -#endif // __NFC_PRIVATE_H__ diff --git a/packaging/capi-network-nfc b/packaging/capi-network-nfc new file mode 100644 index 0000000..ec68963 --- /dev/null +++ b/packaging/capi-network-nfc @@ -0,0 +1,206 @@ +Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + 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. + + 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, + 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 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 in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) 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 + + (d) 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 Apache License to your work. + + To apply the Apache 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 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. + + + diff --git a/packaging/capi-network-nfc.manifest b/packaging/capi-network-nfc.manifest deleted file mode 100644 index 017d22d..0000000 --- a/packaging/capi-network-nfc.manifest +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/packaging/capi-network-nfc.spec b/packaging/capi-network-nfc.spec index 56fd156..de0215e 100644 --- a/packaging/capi-network-nfc.spec +++ b/packaging/capi-network-nfc.spec @@ -1,38 +1,27 @@ -%bcond_with x -%bcond_with neard_nfc - Name: capi-network-nfc -Summary: NFC Core API -Version: 0.1.5 +Summary: A NFC library in Native API +Version: 0.2.0 Release: 0 Group: Network & Connectivity/NFC License: Apache-2.0 Source0: %{name}-%{version}.tar.gz -Source1001: %{name}.manifest BuildRequires: cmake BuildRequires: pkgconfig(dlog) BuildRequires: pkgconfig(glib-2.0) BuildRequires: pkgconfig(gobject-2.0) -%if %{with neard_nfc} -BuildRequires: nfc-client-lib-neard-devel -BuildRequires: nfc-common-neard-devel -%else BuildRequires: nfc-client-lib-devel -BuildRequires: nfc-common-devel -%endif BuildRequires: pkgconfig(capi-base-common) BuildRequires: pkgconfig(vconf) -%if %{with x} -BuildRequires: pkgconfig(ecore-x) -%endif +BuildRequires: pkgconfig(capi-system-info) + Requires(post): /sbin/ldconfig Requires(postun): /sbin/ldconfig %description -A library for Tizen NFC Core API. +A library for Tizen NFC Native API. %package devel -Summary: NFC Core API (devel) +Summary: A NFC library in Native API (Development) Group: Network & Connectivity/Development Requires: %{name} = %{version}-%{release} @@ -42,21 +31,23 @@ This package contains the development files for %{name}. %prep %setup -q -cp %{SOURCE1001} . %build +export CFLAGS="$CFLAGS -DTIZEN_ENGINEER_MODE" +export CXXFLAGS="$CXXFLAGS -DTIZEN_ENGINEER_MODE" +export FFLAGS="$FFLAGS -DTIZEN_ENGINEER_MODE" + MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'` -%cmake . -DFULLVER=%{version} -DMAJORVER=${MAJORVER} \ -%if %{with x} - -DX11_SUPPORT=On -%else - -DX11_SUPPORT=Off -%endif +cmake . -DCMAKE_INSTALL_PREFIX=/usr -DFULLVER=%{version} -DMAJORVER=${MAJORVER} -DCMAKE_LIB_DIR=%{_libdir} make %{?jobs:-j%jobs} %install +rm -rf %{buildroot} +mkdir -p %{buildroot}/usr/share/license +cp -af %{_builddir}/%{name}-%{version}/packaging/capi-network-nfc %{buildroot}/usr/share/license/ + %make_install %post -p /sbin/ldconfig @@ -65,12 +56,11 @@ make %{?jobs:-j%jobs} %files -%manifest %{name}.manifest -%{_libdir}/libcapi-network-nfc.so.* -%license LICENSE.APLv2 +%manifest capi-network-nfc.manifest +%{_libdir}/libcapi-network-nfc.so* +/usr/share/license/capi-network-nfc %files devel -%manifest %{name}.manifest %{_includedir}/network/*.h %{_libdir}/pkgconfig/*.pc %{_libdir}/libcapi-network-nfc.so diff --git a/src/nfc.c b/src/nfc.c deleted file mode 100755 index 4d2d3e0..0000000 --- a/src/nfc.c +++ /dev/null @@ -1,3133 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include - -#include -#ifdef HAVE_X11 -#include -#endif -#include - -#include "nfc_internal.h" - -#define LOG_TAG "CAPI_NETWORK_NFC" -#include - -/** - * @brief The default factory key. - * @details The key is 0xff, 0xff, 0xff, 0xff, 0xff, 0xff - * @ingroup CAPI_NETWORK_NFC_TAG_MIFARE_MODULE - */ -const unsigned char NFC_TAG_MIFARE_KEY_DEFAULT[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; - -/** - * @brief The well-known key for tags formatted according to the MIFARE Application Directory (MAD) specification. - * @details The key is 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5 - * @ingroup CAPI_NETWORK_NFC_TAG_MIFARE_MODULE - */ -const unsigned char NFC_TAG_MIFARE_KEY_APPLICATION_DIRECTORY[6] = {0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5}; - -/** - * @brief The well-known key for tags formatted according to the NDEF on Mifare Classic specification. - * @details The key is 0xD3, 0xF7, 0xD3, 0xF7, 0xD3, 0xF7 - * @ingroup CAPI_NETWORK_NFC_TAG_MIFARE_MODULE - */ -const unsigned char NFC_TAG_MIFARE_KEY_NFC_FORUM[6] = {0xD3, 0xF7, 0xD3, 0xF7, 0xD3, 0xF7}; - - -/** - * @brief RTD(Record type definition) Type - Smart Poster type. - * @ingroup CAPI_NETWORK_NFC_NDEF_RECORD_MODULE - */ -const unsigned char NFC_RECORD_SMART_POSTER_TYPE[2] = { 'S', 'p' }; - -/** - * @brief RTD(Record type definition) Type - Text type. - * @ingroup CAPI_NETWORK_NFC_NDEF_RECORD_MODULE - */ -const unsigned char NFC_RECORD_TEXT_TYPE[1] = { 'T' }; -/** - * @brief RTD(Record type definition) Type - URI type. - * @ingroup CAPI_NETWORK_NFC_NDEF_RECORD_MODULE - */ -const unsigned char NFC_RECORD_URI_TYPE[1] = { 'U' }; -/** - * @brief RTD(Record type definition) Type - Alternative Carrier type. - * @ingroup CAPI_NETWORK_NFC_NDEF_RECORD_MODULE - */ -const unsigned char NFC_RECORD_ALTERNATIVE_CARRIER_TYPE[2] = { 'a','c' }; -/** - * @brief RTD(Record type definition) Type - Handover Carrier type. - * @ingroup CAPI_NETWORK_NFC_NDEF_RECORD_MODULE - */ -const unsigned char NFC_RECORD_HANDOVER_CARRIER_TYPE[2] = { 'H','c' }; -/** - * @brief RTD(Record type definition) Type - Handover Request type. - * @ingroup CAPI_NETWORK_NFC_NDEF_RECORD_MODULE - */ -const unsigned char NFC_RECORD_HANDOVER_REQUEST_TYPE[2] = { 'H','r' }; -/** - * @brief RTD(Record type definition) Type - Handover Select type. - * @ingroup CAPI_NETWORK_NFC_NDEF_RECORD_MODULE - */ -const unsigned char NFC_RECORD_HANDOVER_SELECT_TYPE[2] = { 'H','s' }; - - -static _nfc_context_s gdbus_nfc_context; - -/********************************Utility functions***********************/ - -static pid_t _get_focus_app_pid() -{ -#ifdef HAVE_X11 - Ecore_X_Window focus; - pid_t pid; - - ecore_x_init(NULL); - - focus = ecore_x_window_focus_get(); - if (ecore_x_netwm_pid_get(focus, &pid)) - return pid; - -#endif - return -1; -} - -static bool _check_app_permission() -{ - pid_t focus_app_pid, current_app_pid; - - focus_app_pid = _get_focus_app_pid(); - current_app_pid = getpgid(getpid()); - - LOGD("[check app permission] focus_app_pid [%d], current_app_pid [%d]", - focus_app_pid, current_app_pid); - -#ifdef HAVE_X11 - if (-1 == current_app_pid) - return false; - else - return (focus_app_pid == current_app_pid) ? true : false; -#endif - - return true; -} - -static int _return_invalid_param(const char *func) -{ - LOGE("INVALID_PARAMETER : %s", func); - - return NFC_ERROR_INVALID_PARAMETER; -} - -static int _convert_error_code(const char *func, int native_error_code) -{ - int error_code = NFC_ERROR_NONE; - char *errorstr = NULL; - - switch (native_error_code) - { - case NET_NFC_OK: - error_code = NFC_ERROR_NONE; - errorstr = "ERROR_NONE"; - break; - - case NET_NFC_ALLOC_FAIL: - error_code = NFC_ERROR_OUT_OF_MEMORY; - errorstr = "OUT_OF_MEMORY"; - break; - - case NET_NFC_NOT_CONNECTED: - error_code = NFC_ERROR_NO_DEVICE; - errorstr = "NO_DEVICE"; - break; - - case NET_NFC_UNKNOWN_ERROR: - case NET_NFC_THREAD_CREATE_FAIL: - case NET_NFC_INVALID_STATE: - case NET_NFC_IPC_FAIL: - case NET_NFC_BUFFER_TOO_SMALL: - case NET_NFC_COMMUNICATE_WITH_CONTROLLER_FAILED: - case NET_NFC_RF_ERROR: - case NET_NFC_NOT_SUPPORTED: - case NET_NFC_TAG_READ_FAILED: - case NET_NFC_TAG_WRITE_FAILED: - case NET_NFC_OPERATION_FAIL: - case NET_NFC_SECURITY_FAIL: - case NET_NFC_INSUFFICIENT_STORAGE: - case NET_NFC_NOT_INITIALIZED: - case NET_NFC_NOT_REGISTERED: - error_code = NFC_ERROR_OPERATION_FAILED; - errorstr = "OPERATION_FAILED"; - break; - - case NET_NFC_OUT_OF_BOUND: - case NET_NFC_NULL_PARAMETER: - case NET_NFC_NOT_ALLOWED_OPERATION: - case NET_NFC_LLCP_INVALID_SOCKET: - case NET_NFC_NO_DATA_FOUND: - error_code = NFC_ERROR_INVALID_PARAMETER; - errorstr = "INVALID_PARAMETER"; - break; - case NET_NFC_NDEF_RECORD_IS_NOT_EXPECTED_TYPE: - error_code = NFC_ERROR_INVALID_RECORD_TYPE; - errorstr = "INVALID_RECORD_TYPE"; - break; - - case NET_NFC_ALREADY_INITIALIZED: - case NET_NFC_ALREADY_REGISTERED: - error_code = NFC_ERROR_NONE; - errorstr = "ERROR_NONE"; - break; - - case NET_NFC_RF_TIMEOUT: - error_code = NFC_ERROR_TIMED_OUT; - errorstr = "TIMED_OUT"; - break; - case NET_NFC_INVALID_FORMAT: - case NET_NFC_NDEF_TYPE_LENGTH_IS_NOT_OK: - case NET_NFC_NDEF_ID_LENGTH_IS_NOT_OK: - case NET_NFC_NDEF_BUF_END_WITHOUT_ME: - error_code = NFC_ERROR_INVALID_NDEF_MESSAGE; - errorstr = "INVALID_NDEF_MESSAGE"; - break; - case NET_NFC_NO_NDEF_MESSAGE: - error_code = NFC_ERROR_NO_NDEF_MESSAGE; - errorstr = "NO_NDEF_MESSAGE"; - break; - case NET_NFC_BUSY : - error_code = NFC_ERROR_DEVICE_BUSY; - errorstr = "DEVICE_BUSY"; - break; - case NET_NFC_NO_NDEF_SUPPORT: - error_code = NFC_ERROR_NOT_NDEF_FORMAT; - errorstr = "NOT_SUPPORTED"; - break; - default : - error_code = NFC_ERROR_OPERATION_FAILED; - errorstr = "OPERATION_FAILED"; - } - - LOGE("NFC %s(0x%08x)", errorstr, error_code); - - return error_code; -} - -static bool _is_initialized() -{ - return gdbus_nfc_context.initialized; -} - -/**********************Activate/DeActivate*****************/ - -bool nfc_manager_is_supported(void) -{ - int nfc_supported = 0; - - net_nfc_client_is_nfc_supported(&nfc_supported); - - return (!!nfc_supported); -} - -static void _activation_changed(net_nfc_error_e result, void *user_data) -{ - nfc_activation_completed_cb callback; - void *user_param; - - if (user_data == NULL) { - return; - } - - g_variant_get((GVariant*)user_data, "(uu)", (guint*)&callback, (guint*)&user_param); - - if (callback != NULL) { - callback(_convert_error_code(__func__, result), user_param); - } - - g_variant_unref((GVariant *)user_data); -} - -int nfc_manager_set_activation(bool activation, - nfc_activation_completed_cb callback, - void *user_data) -{ - int ret; - int nfc_supported = 0; -#if 0 - unsigned int state; -#endif - ret = net_nfc_client_is_nfc_supported(&nfc_supported); - if (ret != NET_NFC_OK || nfc_supported == false) - { - LOGE("NFC not supported"); - - return NFC_ERROR_NOT_SUPPORTED; - } -#if 0 - ret = net_nfc_client_manager_get_server_state_sync(&state); - if (ret == NFC_ERROR_NONE && state != 0) - { - LOGE("nfc_manager_check_activation BUSY!!!!!"); - - return NFC_ERROR_DEVICE_BUSY; - } -#endif - if (nfc_manager_is_activated() == activation) - { - if (activation) - { - ret = NFC_ERROR_ALREADY_ACTIVATED; - } - else - { - ret = NFC_ERROR_ALREADY_DEACTIVATED; - } - } - else - { - GVariant *parameter; - - parameter = g_variant_new("(uu)", callback, user_data); - if (parameter != NULL) - { - ret = net_nfc_client_manager_set_active(activation, - _activation_changed, - parameter); - if (ret != NET_NFC_OK) - { - LOGE("net_nfc_client_manager_set_active fail"); - - g_variant_unref(parameter); - } - } - else - { - ret = NET_NFC_ALLOC_FAIL; - } - - ret = _convert_error_code(__func__, ret); - } - - return ret; -} - -bool nfc_manager_is_activated(void) -{ - int activated = 0; - - net_nfc_client_get_nfc_state(&activated); - - return (!!activated); -} - -int nfc_manager_set_activation_changed_cb(nfc_activation_changed_cb callback, - void *user_data) -{ - if (callback == NULL) - return _return_invalid_param(__func__); - - net_nfc_client_manager_set_activated(callback, user_data); - - return NFC_ERROR_NONE; -} - -void nfc_manager_unset_activation_changed_cb(void) -{ - net_nfc_client_manager_unset_activated(); -} - -#if 0 -void _net_nfc_manager_get_current_target_handle_( - net_nfc_error_e result, - net_nfc_target_handle_s *handle, - void *user_data) -{ - gdbus_nfc_context.current_target =(net_nfc_target_handle_s*) handle; - - nfc_initialize_completed_cb cb = - gdbus_nfc_context.on_initialize_completed_cb; - gdbus_nfc_context.on_initialize_completed_cb = NULL; - if( cb ) - { - cb( result, user_data ); - } - -} - -void _net_nfc_manager_get_current_tag_info_( - net_nfc_error_e result, - net_nfc_target_info_s *info, - void *user_data) -{ - if (info != NULL) - { - if (gdbus_nfc_context.current_tag != NULL) - { - net_nfc_release_tag_info(gdbus_nfc_context.current_tag); - gdbus_nfc_context.current_tag = NULL; - } - - net_nfc_duplicate_target_info(info, &gdbus_nfc_context.current_tag); - } - - nfc_initialize_completed_cb cb = - gdbus_nfc_context.on_initialize_completed_cb; - gdbus_nfc_context.on_initialize_completed_cb = NULL; - if (cb) - { - cb(result, user_data); - } -} - - -void _net_nfc_manager_tag_connected_cb( - net_nfc_error_e result, - net_nfc_target_type_e dev_type, - void *user_data) -{ - net_nfc_target_type_e devType = dev_type; - int capi_result; - - if( (devType == NET_NFC_NFCIP1_TARGET )|| - (devType == NET_NFC_NFCIP1_INITIATOR )) - { - net_nfc_client_tag_get_current_target_handle( - _net_nfc_manager_get_current_target_handle_, - user_data); - } - else if( (devType > NET_NFC_UNKNOWN_TARGET )&& - (devType < NET_NFC_NFCIP1_TARGET )) - { - net_nfc_client_tag_get_current_tag_info( - _net_nfc_manager_get_current_tag_info_, - user_data); - } - else - { - if (result == NET_NFC_NOT_CONNECTED) - { - capi_result = NFC_ERROR_NONE; - } - - if( gdbus_nfc_context.on_initialize_completed_cb ) - { - nfc_initialize_completed_cb cb = - gdbus_nfc_context.on_initialize_completed_cb; - gdbus_nfc_context.on_initialize_completed_cb = NULL; - cb( capi_result,user_data ); - } - } -} -#endif - -static void _nfc_manager_tag_discovered_cb(net_nfc_target_info_s *info, - void *user_data) -{ - gdbus_nfc_context.current_tag = info; - - if (gdbus_nfc_context.on_tag_discovered_cb != NULL) { - gdbus_nfc_context.on_tag_discovered_cb( - NFC_DISCOVERED_TYPE_ATTACHED, - gdbus_nfc_context.current_tag, - gdbus_nfc_context.on_tag_discovered_user_data); - } - - /* ndef discovered cb */ - if (gdbus_nfc_context.on_ndef_discovered_cb && - info->raw_data.buffer != NULL) - { - ndef_message_s *ndef_message; - - net_nfc_create_ndef_message_from_rawdata(&ndef_message, &(info->raw_data)); - - gdbus_nfc_context.on_ndef_discovered_cb(ndef_message, - gdbus_nfc_context.on_ndef_discovered_user_data); - - net_nfc_free_ndef_message(ndef_message); - } -} - -static void _nfc_manager_tag_detached_cb(void *user_data) -{ - if (gdbus_nfc_context.on_tag_discovered_cb != NULL) { - gdbus_nfc_context.on_tag_discovered_cb( - NFC_DISCOVERED_TYPE_DETACHED, - gdbus_nfc_context.current_tag, - gdbus_nfc_context.on_tag_discovered_user_data); - } - - gdbus_nfc_context.current_tag = NULL; -} -static void _p2p_target_discovered_cb( - net_nfc_target_handle_s *handle_info, - void *user_data) -{ - gdbus_nfc_context.current_target = handle_info; - - if (gdbus_nfc_context.on_p2p_target_discovered_cb != NULL) { - gdbus_nfc_context.on_p2p_target_discovered_cb( - NFC_DISCOVERED_TYPE_ATTACHED, - (nfc_p2p_target_h)gdbus_nfc_context.current_target, - gdbus_nfc_context.on_p2p_target_discovered_user_data); - } -} - -static void _p2p_device_detached(void *user_data) -{ - nfc_p2p_target_h handle = (nfc_p2p_target_h)gdbus_nfc_context.current_target; - - if (gdbus_nfc_context.on_p2p_target_discovered_cb != NULL) { - gdbus_nfc_context.on_p2p_target_discovered_cb( - NFC_DISCOVERED_TYPE_DETACHED, - handle, - gdbus_nfc_context.on_p2p_target_discovered_user_data); - } - - /* unset data_received callback */ - nfc_p2p_unset_data_received_cb(handle); - - gdbus_nfc_context.current_target = NULL; -} - -static void _se_event_cb(net_nfc_message_e message, void *user_data) -{ - if (gdbus_nfc_context.on_se_event_cb != NULL) { - if(message == NET_NFC_MESSAGE_SE_CARD_EMULATION_CHANGED) - gdbus_nfc_context.on_se_event_cb( - NFC_SE_EVENT_CARD_EMULATION_CHANGED, - gdbus_nfc_context.on_se_event_user_data); - - else if(message == NET_NFC_MESSAGE_SE_TYPE_CHANGED) - gdbus_nfc_context.on_se_event_cb( - NFC_SE_EVENT_SE_TYPE_CHANGED, - gdbus_nfc_context.on_se_event_user_data); - } -} - -/* deprecated */ -static gboolean _initialize_cb(gpointer user_data) -{ - nfc_initialize_completed_cb callback; - void *user_param; - - if (user_data == NULL) - return false; - - g_variant_get((GVariant*)user_data, "(uu)", (guint*)&callback, (guint*)&user_param); - - if (callback != NULL) { - callback(NFC_ERROR_NONE, user_param); - } - - g_variant_unref((GVariant *)user_data); - - return false; -} - -int nfc_manager_initialize(nfc_initialize_completed_cb callback, void *user_data) -{ - int ret; - int nfc_supported = 0; - - net_nfc_client_is_nfc_supported(&nfc_supported); - if (!nfc_supported) - { - LOGE("NFC_ERROR_NOT_SUPPORTED"); - - return NFC_ERROR_NOT_SUPPORTED; - } - - if (!_is_initialized()) - { - ret = net_nfc_client_initialize(); - if (ret != NET_NFC_OK) - return _convert_error_code(__func__, ret); - - memset(&gdbus_nfc_context, 0, sizeof(gdbus_nfc_context)); - - gdbus_nfc_context.initialized = true; - - net_nfc_client_tag_set_tag_detached(_nfc_manager_tag_detached_cb, NULL); - net_nfc_client_tag_set_tag_discovered(_nfc_manager_tag_discovered_cb, NULL); - - net_nfc_client_p2p_set_device_discovered(_p2p_target_discovered_cb, NULL); - - net_nfc_client_p2p_set_device_detached(_p2p_device_detached, NULL); - net_nfc_client_se_set_event_cb(_se_event_cb, NULL); - - /* invoke callback if it needs */ - if (callback != NULL) { - g_main_context_invoke(NULL, - _initialize_cb, - g_variant_new("(uu)", callback, user_data)); - } -#if 0 - gdbus_nfc_context.on_initialize_completed_cb = callback; - - ret = net_nfc_client_tag_is_tag_connected( - _net_nfc_manager_tag_connected_cb, - user_data); - - if( ret != NET_NFC_OK ) - return _convert_error_code(__func__, ret); -#endif - } - - return NFC_ERROR_NONE; -} - -int nfc_manager_initialize_sync() -{ - int ret; - int nfc_supported = 0; - - net_nfc_client_is_nfc_supported(&nfc_supported); - if (!nfc_supported) - { - LOGE("NFC_ERROR_NOT_SUPPORTED"); - - return NFC_ERROR_NOT_SUPPORTED; - } - - if (!_is_initialized()) - { -#if 0 - net_nfc_target_type_e devType; -#endif - memset(&gdbus_nfc_context, 0, sizeof(gdbus_nfc_context)); - - ret = net_nfc_client_initialize(); - if (ret != NET_NFC_OK) - return _convert_error_code(__func__, ret); - - gdbus_nfc_context.initialized = true; - - net_nfc_client_tag_set_tag_detached(_nfc_manager_tag_detached_cb, NULL); - net_nfc_client_tag_set_tag_discovered(_nfc_manager_tag_discovered_cb, NULL); - - net_nfc_client_p2p_set_device_discovered(_p2p_target_discovered_cb, NULL); - - net_nfc_client_p2p_set_device_detached(_p2p_device_detached, NULL); - net_nfc_client_se_set_event_cb(_se_event_cb, NULL); -#if 0 - ret = net_nfc_client_tag_is_tag_connected_sync(&devType); - if (ret == NET_NFC_OK) - { - if ((devType == NET_NFC_NFCIP1_TARGET) || - (devType == NET_NFC_NFCIP1_INITIATOR)) - { - net_nfc_client_tag_get_current_target_handle_sync( - &gdbus_nfc_context.current_target); - } - else if ((devType > NET_NFC_UNKNOWN_TARGET) && - (devType < NET_NFC_NFCIP1_TARGET)) - { - if (gdbus_nfc_context.current_tag != NULL) - { - net_nfc_release_tag_info(gdbus_nfc_context.current_tag); - gdbus_nfc_context.current_tag = NULL; - } - - net_nfc_client_tag_get_current_tag_info_sync( - &gdbus_nfc_context.current_tag); - } - } - else - { - if (ret == NET_NFC_NOT_CONNECTED) - { - ret = NFC_ERROR_NONE; - } - } - - if (ret != NET_NFC_OK) - return _convert_error_code(__func__, ret); -#endif - } - - return NFC_ERROR_NONE; -} - -int nfc_manager_deinitialize (void) -{ - int ret = NET_NFC_OK; - - if (_is_initialized()) - { - net_nfc_client_p2p_unset_device_discovered(); - net_nfc_client_p2p_unset_device_detached(); - - net_nfc_client_tag_unset_tag_discovered(); - net_nfc_client_tag_unset_tag_detached(); - - ret = net_nfc_client_deinitialize(); - - gdbus_nfc_context.initialized = false; - } - - return _convert_error_code(__func__, ret); -} - -/*********************** NDEF Functions*********************/ - -int nfc_manager_set_ndef_discovered_cb(nfc_ndef_discovered_cb callback, - void *user_data) -{ - if (callback == NULL) - return _return_invalid_param(__func__); - - gdbus_nfc_context.on_ndef_discovered_cb = callback; - gdbus_nfc_context.on_ndef_discovered_user_data = user_data; - - return NFC_ERROR_NONE; -} - -void nfc_manager_unset_ndef_discovered_cb(void) -{ - gdbus_nfc_context.on_ndef_discovered_cb = NULL; - gdbus_nfc_context.on_ndef_discovered_user_data = NULL; -} - -void nfc_manager_set_tag_filter(int filter) -{ - net_nfc_client_tag_set_filter(filter); -} - -int nfc_manager_get_tag_filter(void) -{ - return net_nfc_client_tag_get_filter(); -} - -static void _net_nfc_manager_tag_format_ndef_cb(net_nfc_error_e result, - void *user_data) -{ - nfc_tag_format_completed_cb callback; - void *user_param; - - if (user_data == NULL) { - return; - } - - g_variant_get((GVariant*)user_data, "(uu)", (guint*)&callback, (guint*)&user_param); - - if (callback != NULL) { - callback(_convert_error_code(__func__, result), - user_param); - } - - g_variant_unref((GVariant *)user_data); -} - -int nfc_tag_format_ndef(nfc_tag_h tag, unsigned char *key, int key_size, - nfc_tag_format_completed_cb callback, void *user_data) -{ - int ret; - data_s key_data = { key, key_size }; - GVariant *parameter; - - if (tag == NULL) - return _return_invalid_param(__func__); - - if (!nfc_manager_is_activated()) - { - return NFC_ERROR_NOT_ACTIVATED; - } - - if (_check_app_permission() == false) - { - LOGE("permission check fail"); - - return NFC_ERROR_SECURITY_RESTRICTED; - } - - parameter = g_variant_new("(uu)", - GPOINTER_TO_UINT(callback), GPOINTER_TO_UINT(user_data)); - if (parameter != NULL) { - ret = net_nfc_client_ndef_format( - tag->handle, - &key_data, - _net_nfc_manager_tag_format_ndef_cb, - parameter); - if (ret != NET_NFC_OK) { - g_variant_unref(parameter); - } - } else { - ret = NET_NFC_ALLOC_FAIL; - } - - return _convert_error_code(__func__, ret); -} - -static void _net_nfc_manager_tag_read_ndef_cb(net_nfc_error_e result, - ndef_message_s *message, void *user_data) -{ - nfc_tag_read_completed_cb callback; - void *user_param; - - if (user_data == NULL) { - return; - } - - g_variant_get((GVariant*)user_data, "(uu)", (guint*)&callback, (guint*)&user_param); - - if (callback != NULL) { - callback(_convert_error_code(__func__, result), message, user_param); - } - - g_variant_unref((GVariant *)user_data); -} - -int nfc_tag_read_ndef(nfc_tag_h tag, nfc_tag_read_completed_cb callback, - void *user_data) -{ - int ret; - GVariant *parameter; - - if (tag == NULL) - return _return_invalid_param(__func__); - - if (!nfc_manager_is_activated()) - { - return NFC_ERROR_NOT_ACTIVATED; - } - - parameter = g_variant_new("(uu)", - GPOINTER_TO_UINT(callback), GPOINTER_TO_UINT(user_data)); - if (parameter != NULL) { - ret = net_nfc_client_ndef_read( - tag->handle, - _net_nfc_manager_tag_read_ndef_cb, - parameter); - if (ret != NET_NFC_OK) { - g_variant_unref(parameter); - } - } else { - ret = NET_NFC_ALLOC_FAIL; - } - - return _convert_error_code(__func__, ret); -} - -int nfc_ndef_message_get_rawdata_size(nfc_ndef_message_h ndef_message, - unsigned int *byte_size) -{ - int ret; - - if (ndef_message == NULL || byte_size == NULL) - return _return_invalid_param(__func__); - - ret = net_nfc_get_ndef_message_byte_length(ndef_message, - (unsigned int *)byte_size); - - return _convert_error_code(__func__, ret); -} - -static void _net_nfc_manager_tag_write_ndef_cb(net_nfc_error_e result, - void *user_data) -{ - nfc_tag_write_completed_cb callback; - void *user_param; - - if (user_data == NULL) { - return; - } - - g_variant_get((GVariant*)user_data, "(uu)", (guint*)&callback, (guint*)&user_param); - - if (callback != NULL) { - callback(_convert_error_code(__func__, result), user_param); - } - - g_variant_unref((GVariant *)user_data); -} - -int nfc_tag_write_ndef(nfc_tag_h tag, nfc_ndef_message_h msg, - nfc_tag_write_completed_cb callback, void *user_data) -{ - int ret; - unsigned int byte_size = 0; - GVariant *parameter; - - if (tag == NULL) - return _return_invalid_param(__func__); - - if (!nfc_manager_is_activated()) - { - return NFC_ERROR_NOT_ACTIVATED; - } - - if (_check_app_permission() == false) - { - LOGE("permission check fail"); - return NFC_ERROR_SECURITY_RESTRICTED; - } - - if (tag->ndefCardState == NET_NFC_NDEF_CARD_READ_ONLY) { - return NFC_ERROR_READ_ONLY_NDEF; - } - - nfc_ndef_message_get_rawdata_size(msg, &byte_size); - if (tag->maxDataSize < byte_size) { - return NFC_ERROR_NO_SPACE_ON_NDEF; - } - - parameter = g_variant_new("(uu)", - GPOINTER_TO_UINT(callback), GPOINTER_TO_UINT(user_data)); - if (parameter != NULL) { - ret = net_nfc_client_ndef_write( - tag->handle, - msg, - _net_nfc_manager_tag_write_ndef_cb, - parameter); - if (ret != NET_NFC_OK) { - g_variant_unref(parameter); - } - } else { - ret = NET_NFC_ALLOC_FAIL; - } - - return _convert_error_code(__func__, ret); -} - -int nfc_manager_get_cached_message(nfc_ndef_message_h *ndef_message) -{ - int ret; - - if (ndef_message == NULL) - return _return_invalid_param(__func__); - - ret = net_nfc_retrieve_current_ndef_message(ndef_message); - - return _convert_error_code(__func__, ret); -} - -int nfc_ndef_record_create(nfc_ndef_record_h *record, - nfc_record_tnf_e tnf, - const unsigned char *type, - int type_size, - const unsigned char *id, - int id_size, - const unsigned char *payload, - int payload_size) -{ - int ret; - data_s type_data = { (unsigned char *)type, type_size }; - data_s id_data = { (unsigned char *)id, id_size }; - data_s payload_data = { (unsigned char *)payload, payload_size }; - - if (record == NULL || type == NULL || type_size <= 0) - return _return_invalid_param(__func__); - - ret = net_nfc_create_record(record, tnf, &type_data, &id_data, &payload_data); - - return _convert_error_code(__func__, ret); -} - -int nfc_ndef_record_create_text(nfc_ndef_record_h *record, const char *text, - const char *lang_code, nfc_encode_type_e encode) -{ - int ret; - - if (record == NULL || text == NULL || lang_code == NULL) - return _return_invalid_param(__func__); - - ret = net_nfc_create_text_type_record(record, text, lang_code, encode); - - return _convert_error_code(__func__, ret); -} - -int nfc_ndef_record_create_uri(nfc_ndef_record_h *record, - const char *uri) -{ - int ret; - - if (record == NULL || uri == NULL) - return _return_invalid_param(__func__); - - ret = net_nfc_create_uri_type_record(record, uri, NET_NFC_SCHEMA_FULL_URI); - - return _convert_error_code(__func__, ret); -} - -int nfc_ndef_record_create_mime(nfc_ndef_record_h *record, const char *mime_type, - const unsigned char *data, int data_size) -{ - int ret; - - if (record == NULL || mime_type == NULL || - data == NULL || data_size <= 0) - return _return_invalid_param(__func__); - - ret = nfc_ndef_record_create(record, - NFC_RECORD_TNF_MIME_MEDIA, - (unsigned char *)mime_type, - strlen(mime_type), - NULL, - 0, - data, - data_size); - - return _convert_error_code(__func__, ret); -} - -int nfc_ndef_record_get_mime_type(nfc_ndef_record_h record, char **mime_type) -{ - int ret; - nfc_record_tnf_e tnf; - unsigned char *typename; - int length; - - if (record == NULL || mime_type == NULL) - return _return_invalid_param(__func__); - - if (nfc_ndef_record_get_tnf(record, &tnf) != NET_NFC_OK || - tnf != NFC_RECORD_TNF_MIME_MEDIA) - { - return NFC_ERROR_INVALID_RECORD_TYPE; - } - - ret = nfc_ndef_record_get_type(record, &typename, &length); - if (ret == NET_NFC_OK) { - *mime_type = calloc(1, length + 1); - if (*mime_type != NULL) { - memcpy(*mime_type, typename, length); - } else { - ret = NET_NFC_ALLOC_FAIL; - } - } - - return _convert_error_code(__func__, ret); -} - -int nfc_ndef_record_destroy(nfc_ndef_record_h record) -{ - int ret; - - if (record == NULL) - return _return_invalid_param(__func__); - - ret = net_nfc_free_record(record); - - return _convert_error_code(__func__, ret); -} - -int nfc_ndef_record_set_id(nfc_ndef_record_h record, unsigned char *id, int id_size) -{ - int ret; - data_s id_data = { id, id_size }; - - if (record == NULL || id == NULL) - return _return_invalid_param(__func__); - - ret = net_nfc_set_record_id(record, &id_data); - - return _convert_error_code(__func__, ret); -} - -int nfc_ndef_record_get_payload(nfc_ndef_record_h record, - unsigned char **payload, - unsigned int *size) -{ - int ret; - data_s *payload_data; - - if (record == NULL || payload == NULL || size == NULL) - return _return_invalid_param(__func__); - - *payload = NULL; - *size = 0; - - ret = net_nfc_get_record_payload(record, &payload_data); - if (ret == NET_NFC_OK) { - *payload = payload_data->buffer; - *size = payload_data->length; - } else { - *payload = NULL; - *size = 0; - } - - return _convert_error_code(__func__, ret); -} - -int nfc_ndef_record_get_type(nfc_ndef_record_h record, unsigned char **type, - int *size) -{ - int ret; - data_s *type_data; - - if (record == NULL || type == NULL || size == NULL) - return _return_invalid_param(__func__); - - ret = net_nfc_get_record_type(record, &type_data); - if (ret == NET_NFC_OK) { - *type = type_data->buffer; - *size = type_data->length; - } else { - *type = NULL; - *size = 0; - } - - return _convert_error_code(__func__, ret); -} - -int nfc_ndef_record_get_id(nfc_ndef_record_h record, unsigned char **id, int *size) -{ - int ret; - data_s *id_data; - - if (record == NULL || id == NULL || size == NULL) - return _return_invalid_param(__func__); - - *id = NULL; - *size = 0; - - ret = net_nfc_get_record_id(record, &id_data); - if (ret == NET_NFC_OK) { - *id = id_data->buffer; - *size = id_data->length; - } else { - *id = NULL; - *size = 0; - } - - return _convert_error_code(__func__, ret); -} - -int nfc_ndef_record_get_tnf(nfc_ndef_record_h record, nfc_record_tnf_e *tnf) -{ - int ret; - - if (record == NULL || tnf == NULL) - return _return_invalid_param(__func__); - - ret = net_nfc_get_record_tnf(record, (net_nfc_record_tnf_e *)tnf); - - return _convert_error_code(__func__, ret); -} - -int nfc_ndef_record_get_text(nfc_ndef_record_h record, char **buffer) -{ - int ret; - - if (record == NULL || buffer == NULL) - return _return_invalid_param(__func__); - - ret = net_nfc_create_text_string_from_text_record(record, buffer); - - return _convert_error_code(__func__, ret); -} - -int nfc_ndef_record_get_langcode(nfc_ndef_record_h record, char **lang_code) -{ - int ret; - - if (record == NULL || lang_code == NULL) - return _return_invalid_param(__func__); - - ret = net_nfc_get_languange_code_string_from_text_record(record, - lang_code); - - return _convert_error_code(__func__, ret); -} - -int nfc_ndef_record_get_encode_type(nfc_ndef_record_h record, - nfc_encode_type_e *encode) -{ - int ret; - - if (record == NULL || encode == NULL) - return _return_invalid_param(__func__); - - ret = net_nfc_get_encoding_type_from_text_record( - record, - (net_nfc_encode_type_e *)encode); - - /* if( ret == NFC_NDEF_RECORD_IS_NOT_EXPECTED_TYPE) - LOGE("%s reord type is not text type");*/ - - return _convert_error_code(__func__, ret); -} - -int nfc_ndef_record_get_uri(nfc_ndef_record_h record, char **uri) -{ - int ret; - - if (record == NULL || uri == NULL) - return _return_invalid_param(__func__); - - ret = net_nfc_create_uri_string_from_uri_record(record, uri); - - return _convert_error_code(__func__, ret); -} - -int nfc_ndef_message_create(nfc_ndef_message_h *ndef_message) -{ - int ret; - - if (ndef_message == NULL) - return _return_invalid_param(__func__); - - ret = net_nfc_create_ndef_message(ndef_message); - - return _convert_error_code(__func__, ret); -} - -int nfc_ndef_message_create_from_rawdata( - nfc_ndef_message_h *ndef_message, - const unsigned char *rawdata, - unsigned int rawdata_size) -{ - int ret; - data_s rawdata_data = { (unsigned char *)rawdata, rawdata_size }; - - if (ndef_message == NULL || rawdata == NULL || rawdata_size <= 0) - return _return_invalid_param(__func__); - - ret = net_nfc_create_ndef_message_from_rawdata(ndef_message, &rawdata_data); - - return _convert_error_code(__func__, ret); -} - -int nfc_ndef_message_destroy(nfc_ndef_message_h ndef_message) -{ - int ret; - - if (ndef_message == NULL) - return _return_invalid_param(__func__); - - ret = net_nfc_free_ndef_message(ndef_message); - - return _convert_error_code(__func__, ret); -} - -int nfc_ndef_message_get_record_count(nfc_ndef_message_h ndef_message, - int *count) -{ - int ret; - - if (ndef_message == NULL || count == NULL) - return _return_invalid_param(__func__); - - ret = net_nfc_get_ndef_message_record_count(ndef_message, count); - - return _convert_error_code(__func__, ret); -} - -int nfc_ndef_message_get_rawdata(nfc_ndef_message_h ndef_message, - unsigned char **rawdata, - unsigned int *rawdata_size) -{ - int ret; - data_s *rawdata_data; - - if (ndef_message == NULL || rawdata == NULL || rawdata_size == NULL) - return _return_invalid_param(__func__); - - *rawdata = NULL; - *rawdata_size = 0; - - ret = net_nfc_create_rawdata_from_ndef_message(ndef_message, &rawdata_data); - if (ret == NET_NFC_OK) { - *rawdata = calloc(1, rawdata_data->length); - memcpy(*rawdata, rawdata_data->buffer, rawdata_data->length); - *rawdata_size = rawdata_data->length; - - net_nfc_free_data(rawdata_data); - } - - return _convert_error_code(__func__, ret); -} - -int nfc_ndef_message_append_record(nfc_ndef_message_h ndef_message, - nfc_ndef_record_h record) -{ - int ret; - - if (ndef_message == NULL || record == NULL) - return _return_invalid_param(__func__); - - ret = net_nfc_append_record_to_ndef_message(ndef_message, record); - - return _convert_error_code(__func__, ret); -} - -int nfc_ndef_message_insert_record(nfc_ndef_message_h ndef_message, - int index, nfc_ndef_record_h record) -{ - int ret; - - if (ndef_message == NULL || record == NULL) - return _return_invalid_param(__func__); - - ret = net_nfc_append_record_by_index(ndef_message, index, record); - - return _convert_error_code(__func__, ret); -} - -int nfc_ndef_message_remove_record(nfc_ndef_message_h ndef_message, - int index) -{ - int ret; - - if (ndef_message == NULL) - return _return_invalid_param(__func__); - - ret = net_nfc_remove_record_by_index(ndef_message, index); - - return _convert_error_code(__func__, ret); -} - -int nfc_ndef_message_get_record(nfc_ndef_message_h ndef_message, - int index, nfc_ndef_record_h *record) -{ - int ret; - - if (ndef_message == NULL || record == NULL) - return _return_invalid_param(__func__); - - ret = net_nfc_get_record_by_index(ndef_message, index, record); - - return _convert_error_code(__func__, ret); -} - -int nfc_tag_get_type(nfc_tag_h tag, nfc_tag_type_e *type) -{ - int ret; - - if (tag == NULL || type == NULL) - return _return_invalid_param(__func__); - - ret = net_nfc_get_tag_type(tag, (net_nfc_target_type_e *)type); - - return _convert_error_code(__func__, ret); -} - -int nfc_tag_is_support_ndef(nfc_tag_h tag, bool *is_support) -{ - int ret; - - if (tag == NULL || is_support == NULL) - return _return_invalid_param(__func__); - - ret = net_nfc_get_tag_ndef_support(tag, is_support); - - return _convert_error_code(__func__, ret); -} - -int nfc_tag_get_maximum_ndef_size(nfc_tag_h tag, unsigned int *max_size) -{ - int ret; - - if (tag == NULL || max_size == NULL) - return _return_invalid_param(__func__); - - ret = net_nfc_get_tag_max_data_size(tag, max_size); - - return _convert_error_code(__func__, ret); -} - -int nfc_tag_get_ndef_size(nfc_tag_h tag, unsigned int *actual_data_size) -{ - int ret; - - if (tag == NULL || actual_data_size == NULL) - return _return_invalid_param(__func__); - - ret = net_nfc_get_tag_actual_data_size(tag, actual_data_size); - - return _convert_error_code(__func__, ret); -} - -int nfc_tag_foreach_information(nfc_tag_h tag, nfc_tag_information_cb callback, - void *user_data) -{ - net_nfc_tag_info_s *taglist = NULL; - int i; - bool cont; - - if (tag == NULL || callback == NULL) - return _return_invalid_param(__func__); - - taglist = tag->tag_info_list; - - if (taglist == NULL) { - return NFC_ERROR_NOT_SUPPORTED; - } - - for (i = 0; i < tag->number_of_keys; i++) { - cont = callback(taglist[i].key, - net_nfc_get_data_buffer(taglist[i].value), - net_nfc_get_data_length(taglist[i].value), - user_data); - - if (!cont) - break; - } - - return NFC_ERROR_NONE; -} - -/********************************Tag Functions***********************************/ - -int nfc_manager_get_connected_tag(nfc_tag_h *tag) -{ - int ret; - net_nfc_target_info_s *result = NULL; - - if (tag == NULL) - return _return_invalid_param(__func__); - - *tag = NULL; - - if (gdbus_nfc_context.current_tag == NULL) { - ret = net_nfc_client_tag_get_current_tag_info_sync(&result); - if (ret == NET_NFC_OK) { - *tag = result; - } - } else { - /* FIXME ??? */ - *tag = gdbus_nfc_context.current_tag; - - ret = NET_NFC_OK; - } - - return _convert_error_code(__func__, ret); -} - -int nfc_manager_get_connected_target(nfc_p2p_target_h *target) -{ - int ret; - net_nfc_target_handle_s *result = NULL; - - if (target == NULL) - return _return_invalid_param(__func__); - - *target = NULL; - - if (gdbus_nfc_context.current_target == NULL) { - ret = net_nfc_client_tag_get_current_target_handle_sync(&result); - if (ret == NET_NFC_OK) { - gdbus_nfc_context.current_target = result; - - *target = gdbus_nfc_context.current_target; - } - } else { - /* FIXME ??? */ - *target = gdbus_nfc_context.current_target; - - ret = NET_NFC_OK; - } - - return _convert_error_code(__func__, ret); -} - -int nfc_manager_set_tag_discovered_cb(nfc_tag_discovered_cb callback, - void *user_data) -{ - if (callback == NULL) - return _return_invalid_param(__func__); - - gdbus_nfc_context.on_tag_discovered_cb = callback; - gdbus_nfc_context.on_tag_discovered_user_data = user_data; - - return NFC_ERROR_NONE; -} - -void nfc_manager_unset_tag_discovered_cb(void) -{ - gdbus_nfc_context.on_tag_discovered_cb = NULL; - gdbus_nfc_context.on_tag_discovered_user_data = NULL; -} -#if 0 -void _nfc_manager_tag_detached_cb(void *user_data) -{ - if (gdbus_nfc_context.on_tag_discovered_cb) - { - gdbus_nfc_context.on_tag_discovered_cb( - NFC_DISCOVERED_TYPE_DETACHED, - (nfc_tag_h)gdbus_nfc_context.current_tag, - gdbus_nfc_context.on_tag_discovered_user_data); - } - - if (gdbus_nfc_context.current_tag != NULL ) - { - net_nfc_release_tag_info(gdbus_nfc_context.current_tag); - gdbus_nfc_context.current_tag = NULL; - } -} - -int nfc_manager_set_tag_detached_cb(nfc_tag_discovered_cb callback, - void *user_data) -{ - if (callback == NULL) - return _return_invalid_param(__func__); - - gdbus_nfc_context.on_tag_discovered_cb = callback; - gdbus_nfc_context.on_tag_discovered_user_data = user_data; - - net_nfc_client_tag_set_tag_detached( - _nfc_manager_tag_detached_cb, - user_data); - - return NFC_ERROR_NONE; -} - -void nfc_manager_unset_tag_detached_cb(void) -{ - net_nfc_client_tag_unset_tag_detached(); -} -#endif -/******************************Popup Notification*******************************/ - -int nfc_manager_set_system_handler_enable(bool enable) -{ - int ret; - int state; - - if (enable == true) { - state = NET_NFC_LAUNCH_APP_SELECT; - } else { - state = NET_NFC_NO_LAUNCH_APP_SELECT; - } - - ret = net_nfc_client_sys_handler_set_launch_popup_state(state); - - return _convert_error_code(__func__, ret); -} - -int nfc_manager_set_system_handler_enable_force(bool enable) -{ - int ret; - int state; - - if (enable == true) { - state = NET_NFC_LAUNCH_APP_SELECT; - } else { - state = NET_NFC_NO_LAUNCH_APP_SELECT; - } - - ret = net_nfc_client_sys_handler_set_launch_popup_state_force(state); - - return _convert_error_code(__func__, ret); -} - -bool nfc_manager_is_system_handler_enabled(void) -{ - int state = 0; - - net_nfc_client_sys_handler_get_launch_popup_state(&state); - - if (NET_NFC_LAUNCH_APP_SELECT == state) - return true; - else - return false; -} - -/******************************Handover*******************************/ - -static void _net_nfc_manager_p2p_handover_cb(net_nfc_error_e result, - net_nfc_conn_handover_carrier_type_e carrier, data_s *ac_data, void *user_data) -{ - nfc_p2p_connection_handover_completed_cb callback; - void *user_param; - - if (user_data == NULL) { - return; - } - - g_variant_get((GVariant*)user_data, "(uu)", (guint*)&callback, (guint*)&user_param); - - if (callback != NULL) { - nfc_ac_type_e carrior_type = NFC_AC_TYPE_UNKNOWN; - char buffer[50] = { 0, }; - - if (carrier == NET_NFC_CONN_HANDOVER_CARRIER_BT) { - carrior_type = NFC_AC_TYPE_BT; - if (ac_data != NULL && ac_data->buffer != NULL) - { - snprintf(buffer, sizeof(buffer), - "%02x:%02x:%02x:%02x:%02x:%02x", - ac_data->buffer[0], ac_data->buffer[1], - ac_data->buffer[2], ac_data->buffer[3], - ac_data->buffer[4], ac_data->buffer[5]); - } - } - - callback(_convert_error_code(__func__, result), - carrior_type, (void *)buffer, - strlen(buffer), user_param); - } - - g_variant_unref((GVariant *)user_data); -} - -int nfc_p2p_connection_handover(nfc_p2p_target_h target, nfc_ac_type_e type, - nfc_p2p_connection_handover_completed_cb callback, void *user_data) -{ - int ret; - net_nfc_conn_handover_carrier_type_e net_ac_type = - NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN; - GVariant *parameter; - - if (target == NULL) - return _return_invalid_param(__func__); - - if (type > NFC_AC_TYPE_UNKNOWN) - return _return_invalid_param(__func__); - - if (!nfc_manager_is_activated()) { - return NFC_ERROR_NOT_ACTIVATED; - } - - switch (type) - { - case NFC_AC_TYPE_BT : - net_ac_type = NET_NFC_CONN_HANDOVER_CARRIER_BT; - break; - - case NFC_AC_TYPE_WIFI : - net_ac_type = NET_NFC_CONN_HANDOVER_CARRIER_WIFI_BSS; - break; - - case NFC_AC_TYPE_WIFI_DIRECT : - net_ac_type = NET_NFC_CONN_HANDOVER_CARRIER_WIFI_IBSS; - break; - - case NFC_AC_TYPE_UNKNOWN : - net_ac_type = NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN; - break; - - default: - break; - } - - parameter = g_variant_new("(uu)", - GPOINTER_TO_UINT(callback), GPOINTER_TO_UINT(user_data)); - if (parameter != NULL) { - ret = net_nfc_client_p2p_connection_handover( - (net_nfc_target_handle_s*)target, - net_ac_type, - _net_nfc_manager_p2p_handover_cb, - parameter); - if (ret != NET_NFC_OK) { - g_variant_unref(parameter); - } - } else { - ret = NET_NFC_ALLOC_FAIL; - } - - return _convert_error_code(__func__, ret); -} - -bool nfc_p2p_is_supported_ac_type(nfc_ac_type_e carrier) -{ - bool result = false; - - if (carrier == NFC_AC_TYPE_BT) - result = true; - - return result; -} - -/**********************P2P functions************************************/ - -static void _p2p_send_cb(net_nfc_error_e result, void *user_data) -{ - nfc_p2p_send_completed_cb callback; - void *user_param; - - if (user_data == NULL) { - return; - } - - g_variant_get((GVariant*)user_data, "(uu)", (guint*)&callback, (guint*)&user_param); - - if (callback != NULL) { - callback(_convert_error_code(__func__, result), user_param); - } - - g_variant_unref((GVariant *)user_data); -} - -int nfc_p2p_send(nfc_p2p_target_h target, nfc_ndef_message_h message, - nfc_p2p_send_completed_cb callback, void *user_data) -{ - int ret; - data_s *rawdata; - GVariant *parameter; - - if (target == NULL || message == NULL) - return _return_invalid_param(__func__); - - if (!nfc_manager_is_activated()) - return NFC_ERROR_NOT_ACTIVATED; - - if (_check_app_permission() == false) - { - LOGE("permission check fail"); - - return NFC_ERROR_SECURITY_RESTRICTED; - } - - parameter = g_variant_new("(uu)", - GPOINTER_TO_UINT(callback), GPOINTER_TO_UINT(user_data)); - if (parameter != NULL) { - net_nfc_create_rawdata_from_ndef_message(message, &rawdata); - ret = net_nfc_client_p2p_send((net_nfc_target_handle_s*)target, - rawdata, - _p2p_send_cb, - parameter); - if (ret != NET_NFC_OK) { - g_variant_unref(parameter); - } - - net_nfc_free_data(rawdata); - } else { - ret = NET_NFC_ALLOC_FAIL; - } - - return _convert_error_code(__func__, ret); -} - -int nfc_p2p_send_no_permission(nfc_p2p_target_h target, - nfc_ndef_message_h message, nfc_p2p_send_completed_cb callback, void *user_data) -{ - int ret; - data_s *rawdata; - GVariant *parameter; - - if (target == NULL || message == NULL) - return _return_invalid_param(__func__); - - if (!nfc_manager_is_activated()) - return NFC_ERROR_NOT_ACTIVATED; - - /* skip check app permission */ - - parameter = g_variant_new("(uu)", - GPOINTER_TO_UINT(callback), GPOINTER_TO_UINT(user_data)); - if (parameter != NULL) { - net_nfc_create_rawdata_from_ndef_message(message, &rawdata); - ret = net_nfc_client_p2p_send((net_nfc_target_handle_s*)target, - rawdata, - _p2p_send_cb, - parameter); - if (ret != NET_NFC_OK) { - g_variant_unref(parameter); - } - - net_nfc_free_data(rawdata); - } else { - ret = NET_NFC_ALLOC_FAIL; - } - - return _convert_error_code(__func__, ret); -} - -static void _net_nfc_manager_p2p_set_data_received_cb(data_s *data, - void *user_data) -{ - if (gdbus_nfc_context.on_p2p_recv_cb != NULL) - { - ndef_message_s *ndef_message; - - net_nfc_create_ndef_message_from_rawdata(&ndef_message, data); - - gdbus_nfc_context.on_p2p_recv_cb( - (nfc_p2p_target_h)(gdbus_nfc_context.current_target), - ndef_message, - gdbus_nfc_context.on_p2p_recv_user_data); - - net_nfc_free_ndef_message(ndef_message); - } -} - -int nfc_p2p_set_data_received_cb(nfc_p2p_target_h target, - nfc_p2p_data_recived_cb callback, void *user_data) -{ - if (target == NULL || callback == NULL) - return _return_invalid_param(__func__); - - if (gdbus_nfc_context.current_target != target) - return _return_invalid_param(__func__); - - gdbus_nfc_context.on_p2p_recv_cb = callback; - gdbus_nfc_context.on_p2p_recv_user_data = user_data; - - net_nfc_client_p2p_set_data_received( - _net_nfc_manager_p2p_set_data_received_cb, - NULL); - - return NFC_ERROR_NONE; -} - -int nfc_p2p_unset_data_received_cb(nfc_p2p_target_h target) -{ - if (target == NULL) - return _return_invalid_param(__func__); - - if (gdbus_nfc_context.current_target != target) - return _return_invalid_param(__func__); - - net_nfc_client_p2p_unset_data_received(); - - gdbus_nfc_context.on_p2p_recv_cb = NULL; - gdbus_nfc_context.on_p2p_recv_user_data = NULL; - - return NFC_ERROR_NONE; -} - -int nfc_manager_set_p2p_target_discovered_cb( - nfc_p2p_target_discovered_cb callback, void *user_data) -{ - if (callback == NULL) - return _return_invalid_param(__func__); - - gdbus_nfc_context.on_p2p_target_discovered_cb = callback; - gdbus_nfc_context.on_p2p_target_discovered_user_data = user_data; - - return NFC_ERROR_NONE; -} - -void nfc_manager_unset_p2p_target_discovered_cb(void) -{ - gdbus_nfc_context.on_p2p_target_discovered_cb = NULL; - gdbus_nfc_context.on_p2p_target_discovered_user_data = NULL; -} - -/******************************SNEP***********************************/ - -static void _net_nfc_manager_snep_start_server( - net_nfc_snep_handle_h arg_handle, - net_nfc_snep_type_t event, - net_nfc_error_e result, - nfc_ndef_message_h msg, - void *user_data) -{ - nfc_snep_event_cb callback; - void *user_param; - - if (user_data == NULL) { - return; - } - - g_variant_get((GVariant*)user_data, "(uu)", (guint*)&callback, (guint*)&user_param); - - if (callback != NULL) { - nfc_snep_event_e snep_event; - - switch ((int)event) { - case NET_NFC_SNEP_GET : - snep_event = NFC_SNEP_EVENT_GET; - break; - - case NET_NFC_SNEP_PUT : - snep_event = NFC_SNEP_EVENT_PUT; - break; - - case NET_NFC_LLCP_REGISTERED : - snep_event = NFC_SNEP_EVENT_REGISTER; - break; - - case NET_NFC_LLCP_UNREGISTERED : - snep_event = NFC_SNEP_EVENT_UNREGISTER; - break; - - case NET_NFC_LLCP_START : - snep_event = NFC_SNEP_EVENT_START; - break; - - case NET_NFC_LLCP_STOP : - default : - snep_event = NFC_SNEP_EVENT_STOP; - break; - } - - callback(arg_handle, snep_event, - _convert_error_code(__func__, result) - , msg, user_param); - - if (snep_event == NFC_SNEP_EVENT_STOP) { - g_variant_unref(user_data); - } - } -} - -int nfc_snep_start_server(nfc_p2p_target_h target, const char *san, int sap, - nfc_snep_event_cb callback, void *user_data) -{ - net_nfc_error_e result; - GVariant *parameter; - - if (target == NULL) { - return NFC_ERROR_INVALID_PARAMETER; - } - - parameter = g_variant_new("(uu)", - GPOINTER_TO_UINT(callback), GPOINTER_TO_UINT(user_data)); - if (parameter != NULL) { - result = net_nfc_client_snep_start_server( - (net_nfc_target_handle_s*)target, - san, - (sap_t)sap, - _net_nfc_manager_snep_start_server, - parameter); - if (result != NET_NFC_OK) { - g_variant_unref(parameter); - } - } else { - result = NET_NFC_ALLOC_FAIL; - } - - return _convert_error_code(__func__, result); -} - -static void _net_nfc_manager_snep_start_client( - net_nfc_snep_handle_h arg_handle, - net_nfc_snep_type_t event, - net_nfc_error_e result, - nfc_ndef_message_h msg, - void *user_data) -{ - nfc_snep_event_cb callback; - void *user_param; - - if (user_data == NULL) { - return; - } - - g_variant_get((GVariant*)user_data, "(uu)", (guint*)&callback, (guint*)&user_param); - - if (callback != NULL) { - nfc_snep_event_e snep_event; - - switch ((int)event) { - case NET_NFC_SNEP_GET : - snep_event = NFC_SNEP_EVENT_GET; - break; - - case NET_NFC_SNEP_PUT : - snep_event = NFC_SNEP_EVENT_PUT; - break; - - case NET_NFC_LLCP_REGISTERED : - snep_event = NFC_SNEP_EVENT_REGISTER; - break; - - case NET_NFC_LLCP_UNREGISTERED : - snep_event = NFC_SNEP_EVENT_UNREGISTER; - break; - - case NET_NFC_LLCP_START : - snep_event = NFC_SNEP_EVENT_START; - break; - - case NET_NFC_LLCP_STOP : - default : - snep_event = NFC_SNEP_EVENT_STOP; - break; - } - - callback(arg_handle, snep_event, _convert_error_code(__func__, result), - msg, user_param); - - if (snep_event == NFC_SNEP_EVENT_STOP) { - g_variant_unref(user_data); - } - } -} - -int nfc_snep_start_client(nfc_p2p_target_h target, const char *san, int sap, - nfc_snep_event_cb callback, void *user_data) -{ - net_nfc_error_e result; - GVariant *parameter; - - if (target == NULL) { - return NFC_ERROR_INVALID_PARAMETER; - } - - parameter = g_variant_new("(uu)", - GPOINTER_TO_UINT(callback), GPOINTER_TO_UINT(user_data)); - if (parameter != NULL) { - result = net_nfc_client_snep_start_client( - (net_nfc_target_handle_s*)target, - san, - (sap_t)sap, - _net_nfc_manager_snep_start_client, - parameter); - if (result != NET_NFC_OK) { - g_variant_unref(parameter); - } - } else { - result = NET_NFC_ALLOC_FAIL; - } - - return _convert_error_code(__func__, result); -} - -static void _net_nfc_manager_snep_send_request( - net_nfc_snep_handle_h target, - net_nfc_snep_type_t event, - net_nfc_error_e result, - ndef_message_s *msg, - void *user_data) -{ - nfc_snep_event_cb callback; - void *user_param; - - if (user_data == NULL) { - return; - } - - g_variant_get((GVariant*)user_data, "(uu)", (guint*)&callback, (guint*)&user_param); - - if (callback != NULL) { - callback((nfc_p2p_snep_h)target, - event, - _convert_error_code(__func__, result), - (nfc_ndef_message_h)msg, - user_param); - } - - g_variant_unref((GVariant *)user_data); -} - -int nfc_snep_send_client_request(nfc_p2p_snep_h handle, nfc_snep_type_e type, - nfc_ndef_message_h msg, nfc_snep_event_cb callback, void *user_data) -{ - net_nfc_error_e result; - GVariant *parameter; - - if (handle == NULL || msg == NULL) { - return NFC_ERROR_INVALID_PARAMETER; - } - - parameter = g_variant_new("(uu)", - GPOINTER_TO_UINT(callback), GPOINTER_TO_UINT(user_data)); - if (parameter != NULL) { - result = net_nfc_client_snep_send_client_request( - (net_nfc_target_handle_s*)handle, - type, - msg, - _net_nfc_manager_snep_send_request, - parameter); - if (result != NET_NFC_OK) { - g_variant_unref(parameter); - } - } else { - result = NET_NFC_ALLOC_FAIL; - } - - return _convert_error_code(__func__, result); -} - -static void _snep_event_cb(net_nfc_snep_handle_h target, net_nfc_snep_type_t event, - net_nfc_error_e result, ndef_message_s *msg, void *user_data) -{ - nfc_snep_event_cb callback; - void *user_param; - - if (user_data == NULL) { - return; - } - - g_variant_get((GVariant*)user_data, "(uu)", (guint*)&callback, (guint*)&user_param); - - if (callback != NULL) { - switch ((int)event) { - case NET_NFC_SNEP_GET : - event = NFC_SNEP_EVENT_GET; - break; - - case NET_NFC_SNEP_PUT : - event = NFC_SNEP_EVENT_PUT; - break; - - case NET_NFC_LLCP_REGISTERED : - event = NFC_SNEP_EVENT_REGISTER; - break; - - case NET_NFC_LLCP_UNREGISTERED : - event = NFC_SNEP_EVENT_UNREGISTER; - break; - - case NET_NFC_LLCP_START : - event = NFC_SNEP_EVENT_START; - break; - - case NET_NFC_LLCP_STOP : - event = NFC_SNEP_EVENT_STOP; - break; - } - - callback(target, event, _convert_error_code(__func__, result), msg, user_param); - } - - if ((int)event == NFC_SNEP_EVENT_UNREGISTER) { - g_variant_unref((GVariant *)user_data); - } -} - -int nfc_snep_register_server(const char *san, int sap, - nfc_snep_event_cb callback, void *user_data) -{ - net_nfc_error_e result; - GVariant *parameter; - - if (san == NULL) { - return _return_invalid_param(__func__); - } - - parameter = g_variant_new("(uu)", - GPOINTER_TO_UINT(callback), GPOINTER_TO_UINT(user_data)); - if (parameter != NULL) { - result = net_nfc_client_snep_register_server(san, (sap_t)sap, - _snep_event_cb, parameter); - if (result != NET_NFC_OK) { - g_variant_unref(parameter); - } - } else { - result = NET_NFC_ALLOC_FAIL; - } - - return _convert_error_code(__func__, result); -} - -int nfc_snep_unregister_server(const char *san, int sap) -{ - net_nfc_error_e result; - - result = net_nfc_client_snep_unregister_server(san, (sap_t)sap); - - return _convert_error_code(__func__, result); -} - -int nfc_snep_stop_service(nfc_p2p_target_h target, nfc_p2p_snep_h clients) -{ - int ret; - - ret = net_nfc_client_snep_stop_service_sync(target, clients); - - return _convert_error_code(__func__, ret); -} - -/******************************Secure Element***********************************/ - -static void _net_nfc_manager_set_card_emulation_se_type_cb( - net_nfc_error_e result, void *user_data) -{ - nfc_set_card_emulation_completed_cb callback; - void *user_param; - - if (user_data == NULL) { - return; - } - - g_variant_get((GVariant*)user_data, "(uu)", (guint*)&callback, (guint*)&user_param); - - if (callback != NULL) { - callback(_convert_error_code(__func__, result), - user_param); - } - - g_variant_unref((GVariant *)user_data); -} - -int nfc_manager_set_card_emulation_se_type(nfc_se_type_e type, - nfc_set_card_emulation_completed_cb callback, void *user_data) -{ - int ret; - net_nfc_se_type_e se_type; - GVariant *parameter; - - if ((type < NFC_SE_TYPE_DISABLE) || (type > NFC_SE_TYPE_UICC)) - { - return _return_invalid_param(__func__); - } - - if (!nfc_manager_is_activated()) - { - return NFC_ERROR_NOT_ACTIVATED; - } - - switch (type) - { - case NFC_SE_TYPE_DISABLE : - se_type = NET_NFC_SE_TYPE_NONE; - break; - case NFC_SE_TYPE_ESE : - se_type = NET_NFC_SE_TYPE_ESE; - break; - case NFC_SE_TYPE_UICC : - se_type = NET_NFC_SE_TYPE_UICC; - break; - default: - break; - } - - parameter = g_variant_new("(uu)", - GPOINTER_TO_UINT(callback), GPOINTER_TO_UINT(user_data)); - if (parameter != NULL) { - ret = net_nfc_client_se_set_secure_element_type( - se_type, - _net_nfc_manager_set_card_emulation_se_type_cb, - parameter); - if (ret != NET_NFC_OK) { - g_variant_unref(parameter); - } - } else { - ret = NET_NFC_ALLOC_FAIL; - } - - return _convert_error_code(__func__, ret); -} - -int nfc_manager_set_se_type(nfc_se_type_e type) -{ - int ret; - net_nfc_se_type_e se_type = NET_NFC_SE_TYPE_NONE; - - if ((type < NFC_SE_TYPE_DISABLE) || (type > NFC_SE_TYPE_UICC)) - { - return _return_invalid_param(__func__); - } - - if (!nfc_manager_is_activated()) - { - return NFC_ERROR_NOT_ACTIVATED; - } - - switch (type) - { - case NFC_SE_TYPE_DISABLE : - se_type = NET_NFC_SE_TYPE_NONE; - break; - case NFC_SE_TYPE_ESE : - se_type = NET_NFC_SE_TYPE_ESE; - break; - case NFC_SE_TYPE_UICC : - se_type = NET_NFC_SE_TYPE_UICC; - break; - } - - ret = net_nfc_client_se_set_secure_element_type_sync(se_type); - - return _convert_error_code(__func__, ret); -} - -int nfc_manager_get_card_emulation_se_type(nfc_se_type_e *type) -{ - int ret; - int se_type; - - ret = vconf_get_int(VCONFKEY_NFC_SE_TYPE, &se_type); - if (ret == 0) - { - if ((se_type >= NFC_SE_TYPE_DISABLE) - && (se_type <= NFC_SE_TYPE_UICC)) - { - *type = se_type; - - ret = NFC_ERROR_NONE; - } - else - { - ret = NFC_ERROR_OPERATION_FAILED; - } - } - else - { - ret = NFC_ERROR_OPERATION_FAILED; - } - - return ret; -} - -int nfc_se_open_secure_element(nfc_se_type_e se_type, nfc_se_h *handle) -{ - net_nfc_error_e result; - net_nfc_se_type_e type; - net_nfc_target_handle_s *temp = NULL; - - switch (se_type) - { - case NFC_SE_TYPE_ESE : - type = NET_NFC_SE_TYPE_ESE; - break; - - case NFC_SE_TYPE_UICC : - type = NET_NFC_SE_TYPE_UICC; - break; - - default: - return NFC_ERROR_INVALID_PARAMETER; - break; - } - - result = net_nfc_client_se_open_internal_secure_element_sync(type, &temp); - if (result == NET_NFC_OK) { - *handle = (nfc_se_h)temp; - } - - return _convert_error_code(__func__, result); -} - -int nfc_se_send_apdu(nfc_se_h handle, unsigned char *cmd, unsigned int cmd_len, - unsigned char **resp, unsigned int *resp_len) -{ - net_nfc_error_e result; - data_s command, *response = NULL; - - if (handle == NULL || cmd == NULL || cmd_len == 0 || - resp == NULL || resp_len == NULL ) { - return _return_invalid_param(__func__); - } - - *resp = NULL; - *resp_len = 0; - - command.buffer = cmd; - command.length = cmd_len; - - result = net_nfc_client_se_send_apdu_sync( - (net_nfc_target_handle_s*)handle, - &command, - &response); - - if (result == NET_NFC_OK && response != NULL - && response->buffer != NULL) { - if (response->length >= 2) { - *resp = calloc(1, response->length); - if (*resp != NULL) { - memcpy(*resp, response->buffer, response->length); - *resp_len = response->length; - } else { - result = NET_NFC_ALLOC_FAIL; - } - } else { - result = NET_NFC_OPERATION_FAIL; - } - } - - if (response != NULL) { - net_nfc_free_data(response); - } - - return _convert_error_code(__func__, result); -} - -int nfc_se_get_atr(nfc_se_h handle, unsigned char **atr, unsigned int *atr_len) -{ - net_nfc_error_e result; - data_s *response = NULL; - - if (handle == NULL || atr == NULL || atr_len == NULL) { - return _return_invalid_param(__func__); - } - - *atr = NULL; - *atr_len = 0; - - result = net_nfc_client_se_get_atr_sync( - (net_nfc_target_handle_s*)handle, - &response); - - if (result == NET_NFC_OK && response != NULL - && response->buffer != NULL && response->length > 0) { - *atr = calloc(1, response->length); - if (*atr != NULL) { - memcpy(*atr, response->buffer, response->length); - *atr_len = response->length; - } else { - result = NET_NFC_ALLOC_FAIL; - } - } - - if (response != NULL) { - net_nfc_free_data(response); - } - - return _convert_error_code(__func__, result); -} - -int nfc_se_close_secure_element(nfc_se_h handle) -{ - net_nfc_error_e result; - - result = net_nfc_client_se_close_internal_secure_element_sync( - (net_nfc_target_handle_s*)handle); - - return _convert_error_code(__func__, result); -} - -int nfc_se_enable_card_emulation() -{ - net_nfc_error_e result; - - result = net_nfc_set_card_emulation_mode_sync(NET_NFC_CARD_EMELATION_ENABLE); - - return _convert_error_code(__func__, result); -} - -int nfc_se_disable_card_emulation() -{ - net_nfc_error_e result; - - result = net_nfc_set_card_emulation_mode_sync(NET_NFC_CARD_EMULATION_DISABLE); - - return _convert_error_code(__func__, result); -} - -int nfc_se_get_card_emulation_mode(nfc_se_card_emulation_mode_type_e *type) -{ - net_nfc_error_e result; - net_nfc_se_type_e se_type; - - result = net_nfc_get_card_emulation_mode(&se_type); - - if(result == NET_NFC_OK) - { - if(se_type == NET_NFC_SE_TYPE_NONE) - { - *type = NFC_SE_CARD_EMULATION_MODE_OFF; - } - else if(se_type == NET_NFC_SE_TYPE_ESE || se_type == NET_NFC_SE_TYPE_UICC) - { - *type = NFC_SE_CARD_EMULATION_MODE_ON; - } - } - else - { - result = NET_NFC_OPERATION_FAIL; - } - - return _convert_error_code(__func__, result);; -} - -int nfc_manager_set_se_event_cb(nfc_se_event_cb callback, void *user_data) -{ - if (callback == NULL) - return _return_invalid_param(__func__); - - net_nfc_client_se_set_event_cb( - (net_nfc_client_se_event)callback, - user_data); - - return NFC_ERROR_NONE; -} - -void nfc_manager_unset_se_event_cb(void) -{ - net_nfc_client_se_unset_event_cb(); - - gdbus_nfc_context.on_se_transaction_event_cb = NULL; - gdbus_nfc_context.on_se_transaction_event_user_data = NULL; -} - -static void _se_transaction_event_cb( - net_nfc_se_type_e se_type, - data_s* aid, - data_s* param, - void *user_data) -{ - if (gdbus_nfc_context.on_se_transaction_event_cb != NULL) { - gdbus_nfc_context.on_se_transaction_event_cb( - se_type, - net_nfc_get_data_buffer(aid), - net_nfc_get_data_length(aid), - net_nfc_get_data_buffer(param), - net_nfc_get_data_length(param), - gdbus_nfc_context.on_se_transaction_event_user_data); - } -} - -int nfc_manager_set_se_transaction_event_cb( - nfc_se_type_e se_type, - nfc_se_transaction_event_cb callback, - void *user_data) -{ - net_nfc_se_type_e type = NET_NFC_SE_TYPE_NONE; - - if (callback == NULL) - return _return_invalid_param(__func__); - - gdbus_nfc_context.on_se_transaction_event_cb = callback; - gdbus_nfc_context.on_se_transaction_event_user_data = user_data; - - switch(se_type) - { - case NFC_SE_TYPE_ESE: - type = NET_NFC_SE_TYPE_ESE; - break; - - case NFC_SE_TYPE_UICC: - type = NET_NFC_SE_TYPE_UICC; - break; - default: - return _return_invalid_param(__func__); - break; - - } - - net_nfc_client_se_set_transaction_event_cb(type, _se_transaction_event_cb, user_data); - - return NFC_ERROR_NONE; -} - -void nfc_manager_unset_se_transaction_event_cb(nfc_se_type_e se_type) -{ - net_nfc_se_type_e type = NET_NFC_SE_TYPE_NONE; - - switch(se_type) - { - case NFC_SE_TYPE_ESE: - type = NET_NFC_SE_TYPE_ESE; - break; - - case NFC_SE_TYPE_UICC: - type = NET_NFC_SE_TYPE_UICC; - break; - default: - type = NET_NFC_SE_TYPE_NONE; - break; - } - net_nfc_client_se_unset_transaction_event_cb(type); -} - -/************************************Raw Data- Transceive*********************/ - -static void _net_nfc_manager_tag_transceive_data(net_nfc_error_e result, - data_s *arg_data, void *user_data) -{ - nfc_tag_transceive_completed_cb callback; - void *user_param; - - if (user_data == NULL) { - return; - } - - g_variant_get((GVariant*)user_data, "(uu)", (guint*)&callback, (guint*)&user_param); - - if (callback != NULL) { - unsigned char *buffer = NULL; - int buffer_size = 0; - - if (result == NET_NFC_OK && arg_data != NULL) { - buffer = arg_data->buffer; - buffer_size = arg_data->length; - } - - callback(_convert_error_code(__func__, result), - buffer, - buffer_size, - user_param); - } - - g_variant_unref((GVariant *)user_data); -} - -int nfc_tag_transceive(nfc_tag_h tag, unsigned char *buffer, int buffer_size, - nfc_tag_transceive_completed_cb callback, void *user_data) -{ - int ret; - data_s rawdata = { buffer, buffer_size }; - GVariant *parameter; - - if (tag == NULL || buffer == NULL || buffer_size <= 0) - return _return_invalid_param(__func__); - - if (!nfc_manager_is_activated()) - { - return NFC_ERROR_NOT_ACTIVATED; - } - - if (_check_app_permission() == false) - { - LOGE("permission check fail"); - - return NFC_ERROR_SECURITY_RESTRICTED; - } - - parameter = g_variant_new("(uu)", - GPOINTER_TO_UINT(callback), GPOINTER_TO_UINT(user_data)); - if (parameter != NULL) { - ret = net_nfc_client_transceive_data( - tag->handle, - &rawdata, - _net_nfc_manager_tag_transceive_data, - parameter); - if (ret != NET_NFC_OK) { - g_variant_unref(parameter); - } - } else { - ret = NET_NFC_ALLOC_FAIL; - } - - return _convert_error_code(__func__, ret); -} - -/*********************************Mifare*********************************/ -/* FIXME */ -static void _net_nfc_manager_mifare_authenticate_with_keyA( - net_nfc_error_e result, void *user_data) -{ - nfc_mifare_authenticate_with_keyA_completed_cb callback; - void *user_param; - - if (user_data == NULL) { - return; - } - - g_variant_get((GVariant*)user_data, "(uu)",(guint*)&callback, (guint*)&user_param); - - if (callback != NULL) { - callback(_convert_error_code(__func__, result), user_param); - } - - g_variant_unref((GVariant *)user_data); -} - -int nfc_mifare_authenticate_with_keyA(nfc_tag_h tag, - int sector_index, - unsigned char *auth_key, - nfc_mifare_authenticate_with_keyA_completed_cb callback, - void *user_data) -{ - int ret; - data_s auth_key_data = { auth_key, 6 }; - GVariant *parameter; - - if (tag == NULL || auth_key == NULL) - return _return_invalid_param(__func__); - - if (!nfc_manager_is_activated()) - { - return NFC_ERROR_NOT_ACTIVATED; - } - - parameter = g_variant_new("(uu)", - GPOINTER_TO_UINT(callback), GPOINTER_TO_UINT(user_data)); - if (parameter != NULL) { - ret = net_nfc_client_mifare_authenticate_with_keyA( - tag->handle, - sector_index, - &auth_key_data, - _net_nfc_manager_mifare_authenticate_with_keyA, - parameter); - if (ret != NET_NFC_OK) { - g_variant_unref(parameter); - } - } else { - ret = NET_NFC_ALLOC_FAIL; - } - - return _convert_error_code(__func__, ret); -} - -static void _net_nfc_manager_mifare_authenticate_with_keyB( - net_nfc_error_e result, void *user_data) -{ - nfc_mifare_authenticate_with_keyB_completed_cb callback; - void *user_param; - - if (user_data == NULL) { - return; - } - - g_variant_get((GVariant*)user_data, "(uu)", (guint*)&callback, (guint*)&user_param); - - if (callback != NULL) { - callback(_convert_error_code(__func__, result), user_param); - } - - g_variant_unref((GVariant *)user_data); -} - -int nfc_mifare_authenticate_with_keyB(nfc_tag_h tag, - int sector_index, - unsigned char *auth_key, - nfc_mifare_authenticate_with_keyB_completed_cb callback, - void *user_data) -{ - int ret; - data_s auth_key_data = { auth_key, 6 }; - GVariant *parameter; - - if (tag == NULL || auth_key == NULL) - return _return_invalid_param(__func__); - - if (!nfc_manager_is_activated()) - { - return NFC_ERROR_NOT_ACTIVATED; - } - - parameter = g_variant_new("(uu)", - GPOINTER_TO_UINT(callback), GPOINTER_TO_UINT(user_data)); - if (parameter != NULL) { - ret = net_nfc_client_mifare_authenticate_with_keyB( - tag->handle, - sector_index, - &auth_key_data, - _net_nfc_manager_mifare_authenticate_with_keyB, - parameter); - if (ret != NET_NFC_OK) { - g_variant_unref(parameter); - } - } else { - ret = NET_NFC_ALLOC_FAIL; - } - - return _convert_error_code(__func__, ret); -} - -/* FIXME */ -static void _net_nfc_manager_mifare_read_block(net_nfc_error_e result, - data_s *data, void *user_data) -{ - nfc_mifare_read_block_completed_cb callback; - void *user_param; - - if (user_data == NULL) { - return; - } - - g_variant_get((GVariant*)user_data, "(uu)", (guint*)&callback, (guint*)&user_param); - - if (callback != NULL) { - uint8_t *buffer = NULL; - int length = 0; - - if (result == NET_NFC_OK && data != NULL) { - buffer = data->buffer; - length = data->length; - } - - callback(_convert_error_code(__func__, result), - buffer, - length, - user_param); - } - - g_variant_unref((GVariant *)user_data); -} - -int nfc_mifare_read_block(nfc_tag_h tag, int block_index, - nfc_mifare_read_block_completed_cb callback, void *user_data) -{ - int ret; - GVariant *parameter; - - if (tag == NULL) - return _return_invalid_param(__func__); - - if (!nfc_manager_is_activated()) - { - return NFC_ERROR_NOT_ACTIVATED; - } - - parameter = g_variant_new("(uu)", - GPOINTER_TO_UINT(callback), GPOINTER_TO_UINT(user_data)); - if (parameter != NULL) { - ret = net_nfc_client_mifare_read( - tag->handle, - block_index, - _net_nfc_manager_mifare_read_block, - parameter); - if (ret != NET_NFC_OK) { - g_variant_unref(parameter); - } - } else { - ret = NET_NFC_ALLOC_FAIL; - } - - return _convert_error_code(__func__, ret); -} -#if 0 -/* FIXME : ... */ -static void _mifare_read_page(net_nfc_error_e result, - data_s *data, - void *user_data) -{ - nfc_mifare_read_page_completed_cb callback; - void *user_param; - - if (user_data == NULL) { - return; - } - - g_variant_get((GVariant*)user_data, "(uu)", (guint*)&callback, (guint*)&user_param); - - if (callback != NULL) { - uint8_t *buffer = NULL; - int length = 0; - - if (result == NET_NFC_OK && data != NULL) { - buffer = data->buffer; - length = data->length; - } - - callback(_convert_error_code(__func__, result), - buffer, - length, - user_param); - } - - g_variant_unref((GVariant *)user_data); -} -#endif -int nfc_mifare_read_page(nfc_tag_h tag, int page_index, - nfc_mifare_read_page_completed_cb callback, void *user_data) -{ - int ret; - GVariant *parameter; - - if (!nfc_manager_is_activated()) - { - return NFC_ERROR_NOT_ACTIVATED; - } - - parameter = g_variant_new("(uu)", - GPOINTER_TO_UINT(callback), GPOINTER_TO_UINT(user_data)); - if (parameter != NULL) { - /* FIXME : not implemented */ - // ret = net_nfc_client_mifare_read_block(tag, - // page_index, - // _mifare_read_page, - // parameter); - // if (ret != NET_NFC_OK) { - g_variant_unref(parameter); - // } - } else { - ret = NET_NFC_ALLOC_FAIL; - } - - return _convert_error_code(__func__, ret); -} - -static void _net_nfc_manager_mifare_write_block(net_nfc_error_e result, - void *user_data) -{ - nfc_mifare_write_block_completed_cb callback; - void *user_param; - - if (user_data == NULL) { - return; - } - - g_variant_get((GVariant*)user_data, "(uu)", (guint*)&callback, (guint*)&user_param); - - if (callback != NULL) { - callback(_convert_error_code(__func__, result), user_param); - } - - g_variant_unref((GVariant *)user_data); -} - -int nfc_mifare_write_block(nfc_tag_h tag, int block_index, unsigned char *buffer, - int buffer_size, nfc_mifare_write_block_completed_cb callback, void *user_data) -{ - int ret; - data_s block_data = { buffer, buffer_size }; - GVariant *parameter; - - if (tag == NULL || buffer == NULL || buffer_size <= 0) - return _return_invalid_param(__func__); - - if (!nfc_manager_is_activated()) - { - return NFC_ERROR_NOT_ACTIVATED; - } - - parameter = g_variant_new("(uu)", - GPOINTER_TO_UINT(callback), GPOINTER_TO_UINT(user_data)); - if (parameter != NULL) { - ret = net_nfc_client_mifare_write_block( - tag->handle, - block_index, - &block_data, - _net_nfc_manager_mifare_write_block, - parameter); - if (ret != NET_NFC_OK) { - g_variant_unref(parameter); - } - } else { - ret = NET_NFC_ALLOC_FAIL; - } - - return _convert_error_code(__func__, ret); -} - -static void _mifare_write_page(net_nfc_error_e result, void *user_data) -{ - nfc_mifare_write_page_completed_cb callback; - void *user_param; - - if (user_data == NULL) { - return; - } - - g_variant_get((GVariant*)user_data,"(uu)", (guint *)&callback, (guint*)&user_param); - - if (callback != NULL) { - callback(_convert_error_code(__func__, result), user_param); - } - - g_variant_unref((GVariant *)user_data); -} - -int nfc_mifare_write_page(nfc_tag_h tag, int page_index, unsigned char *buffer, - int buffer_size, nfc_mifare_write_page_completed_cb callback, void *user_data) -{ - int ret; - data_s block_data = { buffer, buffer_size }; - GVariant *parameter; - - if (tag == NULL || buffer == NULL || buffer_size <= 0) - return _return_invalid_param(__func__); - - if (!nfc_manager_is_activated()) - { - return NFC_ERROR_NOT_ACTIVATED; - } - - parameter = g_variant_new("(uu)", - GPOINTER_TO_UINT(callback), GPOINTER_TO_UINT(user_data)); - if (parameter != NULL) { - ret = net_nfc_client_mifare_write_page( - tag->handle, - page_index, - &block_data, - _mifare_write_page, - parameter); - if (ret != NET_NFC_OK) { - g_variant_unref(parameter); - } - } else { - ret = NET_NFC_ALLOC_FAIL; - } - - return _convert_error_code(__func__, ret); -} - -static void _net_nfc_manager_mifare_increment(net_nfc_error_e result, - void *user_data) -{ - nfc_mifare_increment_completed_cb callback; - void *user_param; - - if (user_data == NULL) { - return; - } - - g_variant_get((GVariant*)user_data, "(uu)", (guint*)&callback, (guint*)&user_param); - - if (callback != NULL) { - callback(_convert_error_code(__func__, result), user_param); - } - - g_variant_unref((GVariant *)user_data); -} - -int nfc_mifare_increment(nfc_tag_h tag, int block_index, int value, - nfc_mifare_increment_completed_cb callback, void *user_data) -{ - int ret; - GVariant *parameter; - - if (tag == NULL ) - return _return_invalid_param(__func__); - - if (!nfc_manager_is_activated()) - { - return NFC_ERROR_NOT_ACTIVATED; - } - - parameter = g_variant_new("(uu)", - GPOINTER_TO_UINT(callback), GPOINTER_TO_UINT(user_data)); - if (parameter != NULL) { - ret = net_nfc_client_mifare_increment( - tag->handle, - block_index, - value, - _net_nfc_manager_mifare_increment, - parameter); - if (ret != NET_NFC_OK) { - g_variant_unref(parameter); - } - } else { - ret = NET_NFC_ALLOC_FAIL; - } - - return _convert_error_code(__func__, ret); -} - -static void _net_nfc_manager_mifare_decrement(net_nfc_error_e result, - void *user_data) -{ - nfc_mifare_decrement_completed_cb callback; - void *user_param; - - if (user_data == NULL) { - return; - } - - g_variant_get((GVariant*)user_data, "(uu)", (guint*)&callback, (guint*)&user_param); - - if (callback != NULL) { - callback(_convert_error_code(__func__, result), user_param); - } - - g_variant_unref((GVariant *)user_data); -} - -int nfc_mifare_decrement(nfc_tag_h tag, int block_index, int value, - nfc_mifare_decrement_completed_cb callback, void *user_data) -{ - int ret; - GVariant *parameter; - - if (tag == NULL) - return _return_invalid_param(__func__); - - if (!nfc_manager_is_activated()) - { - return NFC_ERROR_NOT_ACTIVATED; - } - - parameter = g_variant_new("(uu)", - GPOINTER_TO_UINT(callback), GPOINTER_TO_UINT(user_data)); - if (parameter != NULL) { - ret = net_nfc_client_mifare_decrement( - tag->handle, - block_index, - value, - _net_nfc_manager_mifare_decrement, - parameter); - if (ret != NET_NFC_OK) { - g_variant_unref(parameter); - } - } else { - ret = NET_NFC_ALLOC_FAIL; - } - - return _convert_error_code(__func__, ret); -} - -static void _net_nfc_manager_mifare_transfer(net_nfc_error_e result, - void *user_data) -{ - nfc_mifare_transfer_completed_cb callback; - void *user_param; - - if (user_data == NULL) { - return; - } - - g_variant_get((GVariant*)user_data, "(uu)", (guint*)&callback, (guint*)&user_param); - - if (callback != NULL) { - callback(_convert_error_code(__func__, result), user_param); - } - - g_variant_unref((GVariant *)user_data); -} - -int nfc_mifare_transfer(nfc_tag_h tag, int block_index, - nfc_mifare_transfer_completed_cb callback, void *user_data) -{ - int ret; - GVariant *parameter; - - if (tag == NULL) - return _return_invalid_param(__func__); - - if (!nfc_manager_is_activated()) - { - return NFC_ERROR_NOT_ACTIVATED; - } - - parameter = g_variant_new("(uu)", - GPOINTER_TO_UINT(callback), GPOINTER_TO_UINT(user_data)); - if (parameter != NULL) { - ret = net_nfc_client_mifare_transfer( - tag->handle, - block_index, - _net_nfc_manager_mifare_transfer, - parameter); - if (ret != NET_NFC_OK) { - g_variant_unref(parameter); - } - } else { - ret = NET_NFC_ALLOC_FAIL; - } - - return _convert_error_code(__func__, ret); -} - -static void _net_nfc_manager_mifare_restore(net_nfc_error_e result, - void *user_data) -{ - nfc_mifare_restore_completed_cb callback; - void *user_param; - - if (user_data == NULL) { - return; - } - - g_variant_get((GVariant*)user_data,"(uu)", (guint*)&callback, (guint*)&user_param); - - if (callback != NULL) { - callback(_convert_error_code(__func__, result), user_param); - } - - g_variant_unref((GVariant *)user_data); -} - -int nfc_mifare_restore(nfc_tag_h tag, int block_index, - nfc_mifare_restore_completed_cb callback, void *user_data) -{ - int ret; - GVariant *parameter; - - if (tag == NULL) - return _return_invalid_param(__func__); - - if (!nfc_manager_is_activated()) - { - return NFC_ERROR_NOT_ACTIVATED; - } - - parameter = g_variant_new("(uu)", - GPOINTER_TO_UINT(callback), GPOINTER_TO_UINT(user_data)); - if (parameter != NULL) { - ret = net_nfc_client_mifare_restore( - tag->handle, - block_index, - _net_nfc_manager_mifare_restore, - parameter); - if (ret != NET_NFC_OK) { - g_variant_unref(parameter); - } - } else { - ret = NET_NFC_ALLOC_FAIL; - } - - return _convert_error_code(__func__, ret); -} diff --git a/src/nfc_card_emulation.c b/src/nfc_card_emulation.c new file mode 100644 index 0000000..fdb7891 --- /dev/null +++ b/src/nfc_card_emulation.c @@ -0,0 +1,418 @@ +/* +* Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "nfc_common.h" + +int nfc_se_open_secure_element_internal( + nfc_se_type_e se_type, + nfc_se_h *handle) +{ + net_nfc_error_e result; + net_nfc_se_type_e type; + net_nfc_target_handle_h temp = NULL; + + LOG_BEGIN(); + + CHECK_SUPPORTED(NFC_CE_FEATURE); + CHECK_INIT(); + CHECK_INVALID(handle == NULL); + + switch (se_type) + { + case NFC_SE_TYPE_ESE : + type = NET_NFC_SE_TYPE_ESE; + break; + + case NFC_SE_TYPE_UICC : + type = NET_NFC_SE_TYPE_UICC; + break; + + default: + return NFC_ERROR_INVALID_PARAMETER; + break; + } + + result = net_nfc_client_se_open_internal_secure_element_sync( + type, + &temp); + if (result == NET_NFC_OK) { + *handle = (nfc_se_h)temp; + } + + return nfc_common_convert_error_code(__func__, result); +} + + +int nfc_se_send_apdu_internal(nfc_se_h handle, + unsigned char *cmd, + unsigned int cmd_len, + unsigned char **resp, + unsigned int *resp_len) +{ + net_nfc_error_e result; + data_h command = NULL; + + LOG_BEGIN(); + + CHECK_SUPPORTED(NFC_CE_FEATURE); + CHECK_INIT(); + CHECK_INVALID(handle == NULL); + CHECK_INVALID(cmd == NULL); + CHECK_INVALID(cmd_len == 0); + CHECK_INVALID(resp == NULL); + CHECK_INVALID(resp_len == NULL); + + if (cmd_len == 3 && cmd[0] == 'A' && cmd[1] == 'T' && cmd[2] == 'R') { + LOG_DEBUG("cheat... invoke get atr"); + return nfc_se_get_atr_internal(handle, resp, resp_len); + } + + *resp = NULL; + *resp_len = 0; + + result = net_nfc_create_data(&command, cmd, cmd_len); + if (result == NET_NFC_OK) { + data_h response = NULL; + + result = net_nfc_client_se_send_apdu_sync( + (net_nfc_target_handle_h)handle, + command, + &response); + if (result == NET_NFC_OK && response != NULL) { + uint8_t *buffer; + uint32_t length; + + buffer = net_nfc_get_data_buffer(response); + length = net_nfc_get_data_length(response); + + if (buffer != NULL && length > 0) { + *resp = calloc(1, length); + if (*resp != NULL) { + memcpy(*resp, buffer, length); + *resp_len = length; + } else { + result = NET_NFC_ALLOC_FAIL; + } + } else { + result = NET_NFC_NO_DATA_FOUND; + } + + net_nfc_free_data(response); + } + + net_nfc_free_data(command); + } else { + LOG_ERR("net_nfc_create_data failed, [%d]", result); + } + + return nfc_common_convert_error_code(__func__, result); +} + + +int nfc_se_get_atr_internal(nfc_se_h handle, unsigned char **atr, unsigned int *atr_len) +{ + net_nfc_error_e result; + data_h response = NULL; + + LOG_BEGIN(); + + CHECK_SUPPORTED(NFC_CE_FEATURE); + CHECK_INIT(); + CHECK_INVALID(handle == NULL); + CHECK_INVALID(atr == NULL); + CHECK_INVALID(atr_len == NULL); + + *atr = NULL; + *atr_len = 0; + + result = net_nfc_client_se_get_atr_sync( + (net_nfc_target_handle_h)handle, + &response); + if (result == NET_NFC_OK && response != NULL) { + uint8_t *buffer; + uint32_t length; + + buffer = net_nfc_get_data_buffer(response); + length = net_nfc_get_data_length(response); + + if (buffer != NULL && length > 0) { + *atr = calloc(1, length); + if (*atr != NULL) { + memcpy(*atr, buffer, length); + *atr_len = length; + } else { + result = NET_NFC_ALLOC_FAIL; + } + } else { + result = NET_NFC_NO_DATA_FOUND; + } + + net_nfc_free_data(response); + } + + return nfc_common_convert_error_code(__func__, result); +} + +int nfc_se_close_secure_element_internal(nfc_se_h handle) +{ + net_nfc_error_e result; + + LOG_BEGIN(); + + CHECK_SUPPORTED(NFC_CE_FEATURE); + CHECK_INIT(); + + result = net_nfc_client_se_close_internal_secure_element_sync( + (net_nfc_target_handle_h)handle); + + return nfc_common_convert_error_code(__func__, result); +} + +int nfc_se_enable_card_emulation() +{ + net_nfc_error_e result; + + LOG_BEGIN(); + + CHECK_SUPPORTED(NFC_CE_FEATURE); + CHECK_INIT(); + + result = net_nfc_set_card_emulation_mode_sync(NET_NFC_CARD_EMELATION_ENABLE); + + return nfc_common_convert_error_code(__func__, result); +} + +int nfc_se_disable_card_emulation() +{ + net_nfc_error_e result; + + LOG_BEGIN(); + + CHECK_SUPPORTED(NFC_CE_FEATURE); + CHECK_INIT(); + + result = net_nfc_set_card_emulation_mode_sync(NET_NFC_CARD_EMULATION_DISABLE); + + return nfc_common_convert_error_code(__func__, result); +} + +int nfc_se_get_card_emulation_mode(nfc_se_card_emulation_mode_type_e *mode) +{ + net_nfc_error_e result; + net_nfc_card_emulation_mode_t se_mode; + + LOG_BEGIN(); + + CHECK_SUPPORTED(NFC_CE_FEATURE); + CHECK_INIT(); + CHECK_INVALID(mode == NULL); + + result = net_nfc_get_card_emulation_mode_sync(&se_mode); + + switch(se_mode) + { + case NET_NFC_CARD_EMELATION_ENABLE : + *mode = NFC_SE_CARD_EMULATION_MODE_ON; + break; + + case NET_NFC_CARD_EMULATION_DISABLE : + *mode = NFC_SE_CARD_EMULATION_MODE_OFF; + break; + } + + return nfc_common_convert_error_code(__func__, result);; +} + +int nfc_hce_send_apdu_response(nfc_se_h handle, unsigned char *resp, unsigned int resp_len) +{ + net_nfc_error_e result; + data_h data; + + LOG_BEGIN(); + + CHECK_SUPPORTED(NFC_CE_HCE_FEATURE); + CHECK_INIT(); + CHECK_INVALID(resp == NULL); + CHECK_INVALID(resp_len == 0); + + result = net_nfc_create_data(&data, resp, resp_len); + if (result == NET_NFC_OK) { + result = net_nfc_client_hce_response_apdu_sync(handle, data); + net_nfc_free_data(data); + } + else { + LOG_ERR("net_nfc_create_data failed, [%d]", result); + } + + return nfc_common_convert_error_code(__func__, result); +} + +int nfc_se_set_default_route(nfc_se_type_e powered_on_status, nfc_se_type_e powered_off_status, nfc_se_type_e low_battery_status) +{ + net_nfc_error_e result; + + LOG_BEGIN(); + + CHECK_SUPPORTED(NFC_CE_HCE_FEATURE); + CHECK_INIT(); + + result = net_nfc_client_se_set_default_route_sync(powered_on_status, powered_off_status, low_battery_status); + + return nfc_common_convert_error_code(__func__, result); +} + +int nfc_se_is_activated_handler_for_aid(nfc_se_type_e se_type, const char *aid, bool *is_activated_handler) +{ + net_nfc_error_e result; + + LOG_BEGIN(); + + CHECK_SUPPORTED(NFC_CE_HCE_FEATURE); + CHECK_INIT(); + CHECK_INVALID(aid == NULL); + CHECK_INVALID(is_activated_handler == NULL); + + result = net_nfc_client_se_is_activated_aid_handler_sync((net_nfc_se_type_e)se_type, aid, is_activated_handler); + + return nfc_common_convert_error_code(__func__, result); +} + +int nfc_se_is_activated_handler_for_category(nfc_se_type_e se_type, nfc_card_emulation_category_type_e category, bool *is_activated_handler) +{ + net_nfc_error_e result; + + LOG_BEGIN(); + + CHECK_SUPPORTED(NFC_CE_HCE_FEATURE); + CHECK_INIT(); + CHECK_INVALID(is_activated_handler == NULL); + + result = net_nfc_client_se_is_activated_category_handler_sync((net_nfc_se_type_e)se_type, category, is_activated_handler); + + return nfc_common_convert_error_code(__func__, result); +} + +int nfc_se_register_aid(nfc_se_type_e se_type, nfc_card_emulation_category_type_e category, const char *aid) +{ + net_nfc_error_e result; + + LOG_BEGIN(); + + CHECK_SUPPORTED(NFC_CE_HCE_FEATURE); + CHECK_INIT(); + CHECK_INVALID(aid == NULL); + + result = net_nfc_client_se_register_aids_sync((net_nfc_se_type_e)se_type, category, aid); + + return nfc_common_convert_error_code(__func__, result); +} + +int nfc_se_unregister_aid(nfc_se_type_e se_type, nfc_card_emulation_category_type_e category, const char *aid) +{ + net_nfc_error_e result; + + LOG_BEGIN(); + + CHECK_SUPPORTED(NFC_CE_HCE_FEATURE); + CHECK_INIT(); + CHECK_INVALID(aid == NULL); + + result = net_nfc_client_se_unregister_aid_sync((net_nfc_se_type_e)se_type, category, aid); + + return nfc_common_convert_error_code(__func__, result); +} + +int nfc_se_get_registered_aids_count(nfc_se_type_e se_type, nfc_card_emulation_category_type_e category, int *count) +{ + net_nfc_error_e result; + + LOG_BEGIN(); + + CHECK_SUPPORTED(NFC_CE_HCE_FEATURE); + CHECK_INIT(); + CHECK_INVALID(count == NULL); + + result = net_nfc_client_se_get_registered_aids_count_sync( + (net_nfc_se_type_e)NFC_SE_TYPE_HCE, + (net_nfc_card_emulation_category_t)category, + (size_t *)count); + + return nfc_common_convert_error_code(__func__, result); +} + +static void _se_registered_aid_event_cb(net_nfc_se_type_e se_type, + const char *aid, bool readonly, void *user_data) +{ + LOG_BEGIN(); + + if (gdbus_nfc_context.on_se_registered_aid_cb != NULL) { + gdbus_nfc_context.on_se_registered_aid_cb( + (nfc_se_type_e)se_type, + aid, + readonly, + gdbus_nfc_context.on_se_registered_aid_cb_user_data); + } +} + +int nfc_se_foreach_registered_aids(nfc_se_type_e se_type, nfc_card_emulation_category_type_e category, nfc_se_registered_aid_cb callback, void *user_data) +{ + net_nfc_error_e result; + + LOG_BEGIN(); + + CHECK_SUPPORTED(NFC_CE_HCE_FEATURE); + CHECK_INIT(); + CHECK_INVALID(callback == NULL); + + gdbus_nfc_context.on_se_registered_aid_cb = callback; + gdbus_nfc_context.on_se_registered_aid_cb_user_data = user_data; + + result = net_nfc_client_se_foreach_registered_aids_sync((net_nfc_se_type_e)se_type, + (net_nfc_card_emulation_category_t)category, + (net_nfc_client_se_registered_aid_cb)_se_registered_aid_event_cb, + user_data); + + return nfc_common_convert_error_code(__func__, result); +} + +int nfc_se_add_route_for_aid_internal(const char *aid, nfc_se_type_e se_type, const char* pkg_name, bool unlock_required, + nfc_se_power_type_e power, nfc_card_emulation_category_type_e category) +{ + net_nfc_error_e result; + + LOG_BEGIN(); + + CHECK_SUPPORTED(NFC_CE_HCE_FEATURE); + CHECK_INIT(); + + result = net_nfc_client_se_add_route_aid_sync(pkg_name, se_type, category, aid, unlock_required, power); + + return nfc_common_convert_error_code(__func__, result); +} + +int nfc_se_remove_route_for_aid_internal(const char* pkg_name, const char *aid) +{ + net_nfc_error_e result; + + LOG_BEGIN(); + + CHECK_SUPPORTED(NFC_CE_HCE_FEATURE); + CHECK_INIT(); + + result = net_nfc_client_se_remove_route_aid_sync(pkg_name, aid); + + return nfc_common_convert_error_code(__func__, result); +} diff --git a/src/nfc_common.c b/src/nfc_common.c new file mode 100644 index 0000000..0dfe109 --- /dev/null +++ b/src/nfc_common.c @@ -0,0 +1,217 @@ +/* +* Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "nfc_common.h" + +pid_t nfc_common_get_focus_app_pid() +{ +/* + Ecore_X_Window focus; + pid_t pid; + + ecore_x_init(NULL); + + focus = ecore_x_window_focus_get(); + if (ecore_x_netwm_pid_get(focus, &pid)) + return pid; +*/ + return -1; +} + +char * nfc_common_get_bt_address_string(data_h data) +{ + uint8_t *buffer; + uint32_t length; + + if (data == NULL) { + return NULL; + } + + buffer = net_nfc_get_data_buffer(data); + length = net_nfc_get_data_length(data); + + if (buffer == NULL || length < 6) { + return NULL; + } + + return g_strdup_printf("%02X:%02X:%02X:%02X:%02X:%02X", + buffer[0], + buffer[1], + buffer[2], + buffer[3], + buffer[4], + buffer[5]); +} + +bool nfc_common_check_app_permission() +{ + pid_t focus_app_pid, current_app_pid; + + focus_app_pid = nfc_common_get_focus_app_pid(); + current_app_pid = getpgid(getpid()); + + LOGD("[check app permission] focus_app_pid [%d], current_app_pid [%d]", focus_app_pid, + current_app_pid); + + return (focus_app_pid == current_app_pid) ? true : false; +} + +int nfc_common_convert_error_code(const char *func, int native_error_code) +{ + int error_code = NFC_ERROR_NONE; + char *errorstr = NULL; + + switch (native_error_code) + { + case NET_NFC_OK: + error_code = NFC_ERROR_NONE; + errorstr = "ERROR_NONE"; + break; + + case NET_NFC_ALLOC_FAIL: + error_code = NFC_ERROR_OUT_OF_MEMORY; + errorstr = "OUT_OF_MEMORY"; + break; + + case NET_NFC_NOT_CONNECTED: + error_code = NFC_ERROR_NO_DEVICE; + errorstr = "NO_DEVICE"; + break; + + case NET_NFC_UNKNOWN_ERROR: + case NET_NFC_THREAD_CREATE_FAIL: + case NET_NFC_IPC_FAIL: + case NET_NFC_BUFFER_TOO_SMALL: + case NET_NFC_COMMUNICATE_WITH_CONTROLLER_FAILED: + case NET_NFC_RF_ERROR: + case NET_NFC_NOT_SUPPORTED: + case NET_NFC_TAG_READ_FAILED: + case NET_NFC_TAG_WRITE_FAILED: + case NET_NFC_OPERATION_FAIL: + case NET_NFC_INSUFFICIENT_STORAGE: + case NET_NFC_NOT_INITIALIZED: + case NET_NFC_NOT_REGISTERED: + error_code = NFC_ERROR_OPERATION_FAILED; + errorstr = "OPERATION_FAILED"; + break; + + case NET_NFC_SECURITY_FAIL: + error_code = NFC_ERROR_SECURITY_RESTRICTED; + errorstr = "SECURITY_RESTRICTED"; + break; + + case NET_NFC_INVALID_STATE: + error_code = NFC_ERROR_ILLEGAL_STATE; + errorstr = "ILLEGAL_STATE"; + break; + + case NET_NFC_OUT_OF_BOUND: + case NET_NFC_NULL_PARAMETER: + case NET_NFC_NOT_ALLOWED_OPERATION: + case NET_NFC_LLCP_INVALID_SOCKET: + case NET_NFC_NO_DATA_FOUND: + error_code = NFC_ERROR_INVALID_PARAMETER; + errorstr = "INVALID_PARAMETER"; + break; + case NET_NFC_NDEF_RECORD_IS_NOT_EXPECTED_TYPE: + error_code = NFC_ERROR_INVALID_RECORD_TYPE; + errorstr = "INVALID_RECORD_TYPE"; + break; + + case NET_NFC_ALREADY_INITIALIZED: + case NET_NFC_ALREADY_REGISTERED: + error_code = NFC_ERROR_NONE; + errorstr = "ERROR_NONE"; + break; + + case NET_NFC_RF_TIMEOUT: + error_code = NFC_ERROR_TIMED_OUT; + errorstr = "TIMED_OUT"; + break; + case NET_NFC_INVALID_FORMAT: + case NET_NFC_NDEF_TYPE_LENGTH_IS_NOT_OK: + case NET_NFC_NDEF_ID_LENGTH_IS_NOT_OK: + case NET_NFC_NDEF_BUF_END_WITHOUT_ME: + error_code = NFC_ERROR_INVALID_NDEF_MESSAGE; + errorstr = "INVALID_NDEF_MESSAGE"; + break; + case NET_NFC_NO_NDEF_MESSAGE: + error_code = NFC_ERROR_NO_NDEF_MESSAGE; + errorstr = "NO_NDEF_MESSAGE"; + break; + case NET_NFC_BUSY : + error_code = NFC_ERROR_DEVICE_BUSY; + errorstr = "DEVICE_BUSY"; + break; + case NET_NFC_NO_NDEF_SUPPORT: + error_code = NFC_ERROR_NOT_NDEF_FORMAT; + errorstr = "NOT_SUPPORTED"; + break; + case NET_NFC_PERMISSION_DENIED: + error_code = NFC_ERROR_PERMISSION_DENIED; + errorstr = "PERMISSION_DENIED"; + break; + case NET_NFC_NOT_ACTIVATED: + error_code = NFC_ERROR_NOT_ACTIVATED; + errorstr = "NOT_ACTIVATED"; + break; + default : + error_code = NFC_ERROR_OPERATION_FAILED; + errorstr = "OPERATION_FAILED"; + } + + if ( error_code != NFC_ERROR_NONE ) + LOGE("NFC func : %s, %s(0x%08x)", func, errorstr, error_code); + + return error_code; +} + +bool nfc_common_is_initialized() +{ + return gdbus_nfc_context.initialized; +} + +bool nfc_common_is_supported(char *str) +{ + int ret; + bool is_supported; + + ret = system_info_get_platform_bool(str, &is_supported); + + if(ret != 0) + return false; + + return is_supported; +} + +int nfc_common_get_rawdata_size(nfc_ndef_message_h ndef_message, + unsigned int *byte_size) +{ + int ret; + + LOG_BEGIN(); + + CHECK_SUPPORTED(NFC_FEATURE); + CHECK_INIT(); + CHECK_INVALID(ndef_message == NULL); + CHECK_INVALID(byte_size == NULL); + + ret = net_nfc_get_ndef_message_byte_length(ndef_message, + (unsigned int *)byte_size); + + return nfc_common_convert_error_code(__func__, ret); +} + diff --git a/src/nfc_manager.c b/src/nfc_manager.c new file mode 100644 index 0000000..760a31c --- /dev/null +++ b/src/nfc_manager.c @@ -0,0 +1,925 @@ +/* +* Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "nfc_common.h" + +bool nfc_manager_is_supported(void) +{ + bool nfc_supported = false; + + LOG_BEGIN(); + + nfc_supported = nfc_common_is_supported(NFC_FEATURE); + + if(nfc_supported == true) + set_last_result(NFC_ERROR_NONE); + else + set_last_result(NFC_ERROR_NOT_SUPPORTED); + + return nfc_supported; +} + +static void _activation_changed_cb(net_nfc_error_e result, void *user_data) +{ + nfc_activation_completed_cb callback; + void *user_param; + + LOG_BEGIN(); + + if(user_data == NULL) { + LOG_ERR("user_data is NULL"); + return; + } + + g_variant_get((GVariant *)user_data, + "(uu)", + (guint *)&callback, + (guint *)&user_param); + + if (callback != NULL) { + callback(nfc_common_convert_error_code(__func__, result), user_param); + } + + g_variant_unref((GVariant *)user_data); +} + +int nfc_manager_set_activation(bool activation, + nfc_activation_completed_cb callback, + void *user_data) +{ + int ret; + + LOG_BEGIN(); + + CHECK_SUPPORTED(NFC_FEATURE); + CHECK_INIT(); + + if(nfc_manager_is_activated() == activation) + { + if (activation) + { + ret = NFC_ERROR_ALREADY_ACTIVATED; + } + else + { + ret = NFC_ERROR_ALREADY_DEACTIVATED; + } + } + else + { + GVariant *parameter; + + parameter = g_variant_new("(uu)", + callback, + user_data); + if (parameter != NULL) + { + ret = net_nfc_client_manager_set_active(activation, + _activation_changed_cb, + parameter); + if (ret != NET_NFC_OK) + { + LOG_ERR("net_nfc_client_manager_set_active fail"); + + g_variant_unref(parameter); + } + } + else + { + ret = NET_NFC_ALLOC_FAIL; + } + + ret = nfc_common_convert_error_code(__func__, ret); + } + + return ret; +} + +bool nfc_manager_is_activated(void) +{ + int ret; + int activated = 0; + + LOG_BEGIN(); + + if(nfc_common_is_supported(NFC_FEATURE) == false) + { + set_last_result(NFC_ERROR_NOT_SUPPORTED); + return false; + } + + ret = net_nfc_client_get_nfc_state(&activated); + + set_last_result(nfc_common_convert_error_code(__func__,ret)); + + return (!!activated); +} + +int nfc_manager_set_activation_changed_cb(nfc_activation_changed_cb callback, + void *user_data) +{ + LOG_BEGIN(); + + CHECK_SUPPORTED(NFC_FEATURE); + CHECK_INIT(); + CHECK_INVALID(callback == NULL); + + net_nfc_client_manager_set_activated(callback, user_data); + + return NFC_ERROR_NONE; +} + +void nfc_manager_unset_activation_changed_cb(void) +{ + LOG_BEGIN(); + + if(nfc_common_is_supported(NFC_FEATURE) == false) + { + LOG_ERR("NFC not supported"); + set_last_result(NFC_ERROR_NOT_SUPPORTED); + return; + } + + if(nfc_common_is_initialized() == false) + { + LOG_ERR("NFC not initialized"); + set_last_result(NFC_ERROR_NOT_INITIALIZED); + return; + } + + net_nfc_client_manager_unset_activated(); + + set_last_result(NFC_ERROR_NONE); +} + +int nfc_manager_initialize(void) +{ + int ret = NET_NFC_OK; + + LOG_BEGIN(); + + CHECK_SUPPORTED(NFC_FEATURE); + + if(!nfc_common_is_initialized()) + { + ret = net_nfc_client_initialize(); + if (ret != NET_NFC_OK) + return nfc_common_convert_error_code(__func__, ret); + + memset(&gdbus_nfc_context, 0, sizeof(gdbus_nfc_context)); + + gdbus_nfc_context.initialized = true; + } + + return nfc_common_convert_error_code(__func__, ret); +} + +int nfc_manager_deinitialize (void) +{ + int ret = NET_NFC_OK; + + LOG_BEGIN(); + + CHECK_SUPPORTED(NFC_FEATURE); + + if(nfc_common_is_initialized()) + { + net_nfc_client_se_unset_event_cb(); + + net_nfc_client_p2p_unset_device_discovered(); + net_nfc_client_p2p_unset_device_detached(); + + net_nfc_client_tag_unset_tag_discovered(); + net_nfc_client_tag_unset_tag_detached(); + + ret = net_nfc_client_deinitialize(); + + gdbus_nfc_context.initialized = false; + } + + return nfc_common_convert_error_code(__func__, ret); +} + +static void _tag_discovered_cb(net_nfc_target_info_h info, void *user_data) +{ + LOG_BEGIN(); + + gdbus_nfc_context.current_tag = info; + + if(gdbus_nfc_context.on_tag_discovered_cb != NULL) { + gdbus_nfc_context.on_tag_discovered_cb( + NFC_DISCOVERED_TYPE_ATTACHED, + (nfc_tag_h)gdbus_nfc_context.current_tag, + gdbus_nfc_context.on_tag_discovered_user_data); + } + + /* ndef discovered cb */ + if(gdbus_nfc_context.on_ndef_discovered_cb) + { + ndef_message_h ndef_message = NULL; + + if (net_nfc_get_tag_ndef_message((net_nfc_target_info_h)info, + &ndef_message) == NET_NFC_OK) { + gdbus_nfc_context.on_ndef_discovered_cb(ndef_message, + gdbus_nfc_context.on_ndef_discovered_user_data); + + net_nfc_free_ndef_message(ndef_message); + } + } +} + +static void _tag_detached_cb(void *user_data) +{ + LOG_BEGIN(); + + if(gdbus_nfc_context.on_tag_discovered_cb != NULL) { + gdbus_nfc_context.on_tag_discovered_cb( + NFC_DISCOVERED_TYPE_DETACHED, + (nfc_tag_h)gdbus_nfc_context.current_tag, + gdbus_nfc_context.on_tag_discovered_user_data); + } + + gdbus_nfc_context.current_tag = NULL; +} + +int nfc_manager_set_ndef_discovered_cb( + nfc_ndef_discovered_cb callback, + void *user_data) +{ + LOG_BEGIN(); + + CHECK_SUPPORTED(NFC_FEATURE); + CHECK_INIT(); + CHECK_INVALID(callback == NULL); + + net_nfc_client_tag_set_tag_discovered(_tag_discovered_cb, NULL); + net_nfc_client_tag_set_tag_detached(_tag_detached_cb, NULL); + + gdbus_nfc_context.on_ndef_discovered_cb = callback; + gdbus_nfc_context.on_ndef_discovered_user_data = user_data; + + return NFC_ERROR_NONE; +} + +void nfc_manager_unset_ndef_discovered_cb( void ) +{ + LOG_BEGIN(); + + if(nfc_common_is_supported(NFC_FEATURE) == false) + { + LOG_ERR("NFC not supported"); + set_last_result(NFC_ERROR_NOT_SUPPORTED); + return; + } + + if(nfc_common_is_initialized() == false) + { + LOG_ERR("NFC not initialized"); + set_last_result(NFC_ERROR_NOT_INITIALIZED); + return; + } + + gdbus_nfc_context.on_ndef_discovered_cb = NULL; + gdbus_nfc_context.on_ndef_discovered_user_data = NULL; + + set_last_result(NFC_ERROR_NONE); +} + +void nfc_manager_set_tag_filter(int filter) +{ + LOG_BEGIN(); + + if(nfc_common_is_supported(NFC_TAG_FEATURE) == false) + { + LOG_ERR("NFC not supported"); + set_last_result(NFC_ERROR_NOT_SUPPORTED); + return; + } + + if(nfc_common_is_initialized() == false) + { + LOG_ERR("NFC not initialized"); + set_last_result(NFC_ERROR_NOT_INITIALIZED); + return; + } + + if(filter < NET_NFC_ALL_DISABLE) + { + LOG_ERR("Invalid parameter"); + set_last_result(NFC_ERROR_INVALID_PARAMETER); + return; + } + + net_nfc_client_tag_set_filter(filter); + + set_last_result(NFC_ERROR_NONE); +} + +int nfc_manager_get_tag_filter(void) +{ + LOG_BEGIN(); + + if(nfc_common_is_supported(NFC_TAG_FEATURE) == false) + { + LOG_ERR("NFC not supported"); + set_last_result(NFC_ERROR_NOT_SUPPORTED); + return 0; + } + + if(nfc_common_is_initialized() == false) + { + LOG_ERR("NFC not initialized"); + set_last_result(NFC_ERROR_NOT_INITIALIZED); + return 0; + } + + set_last_result(NFC_ERROR_NONE); + + return net_nfc_client_tag_get_filter(); +} + +int nfc_manager_get_connected_tag(nfc_tag_h *tag) +{ + int ret; + net_nfc_target_info_h result = NULL; + + LOG_BEGIN(); + + CHECK_SUPPORTED(NFC_TAG_FEATURE); + CHECK_INIT(); + CHECK_INVALID(tag == NULL); + + *tag = NULL; + + net_nfc_client_tag_set_tag_discovered(_tag_discovered_cb, NULL); + net_nfc_client_tag_set_tag_detached(_tag_detached_cb, NULL); + + + if(gdbus_nfc_context.current_tag == NULL) { + ret = net_nfc_client_tag_get_current_tag_info_sync(&result); + if (ret == NET_NFC_OK) { + *tag = (nfc_tag_h)result; + } + } else { + /* FIXME ??? */ + *tag = gdbus_nfc_context.current_tag; + + ret = NET_NFC_OK; + } + + return nfc_common_convert_error_code(__func__, ret); +} + +int nfc_manager_get_connected_target(nfc_p2p_target_h *target) +{ + int ret; + net_nfc_target_handle_h result = NULL; + + LOG_BEGIN(); + + CHECK_SUPPORTED(NFC_P2P_FEATURE); + CHECK_INIT(); + CHECK_INVALID(target == NULL); + + *target = NULL; + + net_nfc_client_tag_set_tag_discovered(_tag_discovered_cb, NULL); + net_nfc_client_tag_set_tag_detached(_tag_detached_cb, NULL); + + if(gdbus_nfc_context.current_target == NULL) { + ret = net_nfc_client_tag_get_current_target_handle_sync(&result); + if (ret == NET_NFC_OK) { + gdbus_nfc_context.current_target = result; + + *target = gdbus_nfc_context.current_target; + } + } else { + /* FIXME ??? */ + *target = gdbus_nfc_context.current_target; + + ret = NET_NFC_OK; + } + + return nfc_common_convert_error_code(__func__, ret); +} + +int nfc_manager_set_tag_discovered_cb(nfc_tag_discovered_cb callback, + void *user_data) +{ + LOG_BEGIN(); + + CHECK_SUPPORTED(NFC_TAG_FEATURE); + CHECK_INIT(); + CHECK_INVALID(callback == NULL); + + net_nfc_client_tag_set_tag_discovered(_tag_discovered_cb, NULL); + net_nfc_client_tag_set_tag_detached(_tag_detached_cb, NULL); + + gdbus_nfc_context.on_tag_discovered_cb = callback; + gdbus_nfc_context.on_tag_discovered_user_data = user_data; + + return NFC_ERROR_NONE; +} + +void nfc_manager_unset_tag_discovered_cb(void) +{ + LOG_BEGIN(); + + if(nfc_common_is_supported(NFC_TAG_FEATURE) == false) + { + LOG_ERR("NFC not supported"); + set_last_result(NFC_ERROR_NOT_SUPPORTED); + return; + } + + if(nfc_common_is_initialized() == false) + { + LOG_ERR("NFC not initialized"); + set_last_result(NFC_ERROR_NOT_INITIALIZED); + return; + } + + gdbus_nfc_context.on_tag_discovered_cb = NULL; + gdbus_nfc_context.on_tag_discovered_user_data = NULL; + + set_last_result(NFC_ERROR_NONE); +} + +static void _p2p_discovered_cb( + net_nfc_target_handle_h handle_info, + void *user_data) +{ + LOG_BEGIN(); + + gdbus_nfc_context.current_target = handle_info; + + if(gdbus_nfc_context.on_p2p_target_discovered_cb != NULL) { + gdbus_nfc_context.on_p2p_target_discovered_cb( + NFC_DISCOVERED_TYPE_ATTACHED, + (nfc_p2p_target_h)gdbus_nfc_context.current_target, + gdbus_nfc_context.on_p2p_target_discovered_user_data); + } +} + +static void _p2p_detached_cb(void *user_data) +{ + nfc_p2p_target_h handle = + (nfc_p2p_target_h)gdbus_nfc_context.current_target; + + LOG_BEGIN(); + + if(gdbus_nfc_context.on_p2p_target_discovered_cb != NULL) { + gdbus_nfc_context.on_p2p_target_discovered_cb( + NFC_DISCOVERED_TYPE_DETACHED, + handle, + gdbus_nfc_context.on_p2p_target_discovered_user_data); + } + + /* unset data_received callback */ + nfc_p2p_unset_data_received_cb(handle); + + gdbus_nfc_context.current_target = NULL; +} + +int nfc_manager_set_p2p_target_discovered_cb( + nfc_p2p_target_discovered_cb callback, + void *user_data) +{ + LOG_BEGIN(); + + CHECK_SUPPORTED(NFC_P2P_FEATURE); + CHECK_INIT(); + CHECK_INVALID(callback == NULL); + + net_nfc_client_p2p_set_device_discovered(_p2p_discovered_cb, NULL); + net_nfc_client_p2p_set_device_detached(_p2p_detached_cb, NULL); + + gdbus_nfc_context.on_p2p_target_discovered_cb = callback; + gdbus_nfc_context.on_p2p_target_discovered_user_data = user_data; + + return NFC_ERROR_NONE; +} + +void nfc_manager_unset_p2p_target_discovered_cb(void) +{ + LOG_BEGIN(); + + if(nfc_common_is_supported(NFC_P2P_FEATURE) == false) + { + LOG_ERR("NFC not supported"); + set_last_result(NFC_ERROR_NOT_SUPPORTED); + return; + } + + if(nfc_common_is_initialized() == false) + { + LOG_ERR("NFC not initialized"); + set_last_result(NFC_ERROR_NOT_INITIALIZED); + return; + } + + gdbus_nfc_context.on_p2p_target_discovered_cb = NULL; + gdbus_nfc_context.on_p2p_target_discovered_user_data = NULL; + + set_last_result(NFC_ERROR_NONE); +} + +int nfc_manager_set_system_handler_enable(bool enable) +{ + int ret; + int state; + + LOG_BEGIN(); + + CHECK_SUPPORTED(NFC_FEATURE); + CHECK_INIT(); + + if (enable == true) { + state = 0; + } else { + state = 1; + } + + ret = net_nfc_client_sys_handler_set_launch_popup_state(state); + + return nfc_common_convert_error_code(__func__, ret); +} + +int nfc_manager_set_system_handler_enable_force(bool enable) +{ + int ret; + int state; + + LOG_BEGIN(); + + CHECK_SUPPORTED(NFC_FEATURE); + CHECK_INIT(); + + if (enable == true) { + state = 0; + } else { + state = 1; + } + + ret = net_nfc_client_sys_handler_set_launch_popup_state_force(state); + + return nfc_common_convert_error_code(__func__, ret); +} + +bool nfc_manager_is_system_handler_enabled(void) +{ + int ret; + int state = 0; + + LOG_BEGIN(); + + if(nfc_common_is_supported(NFC_FEATURE) == false) + { + LOG_ERR("NFC not supported"); + set_last_result(NFC_ERROR_NOT_SUPPORTED); + return false; + } + + if(nfc_common_is_initialized() == false) + { + LOG_ERR("NFC not initialized"); + set_last_result(NFC_ERROR_NOT_INITIALIZED); + return false; + } + + ret = net_nfc_client_sys_handler_get_launch_popup_state(&state); + + set_last_result(nfc_common_convert_error_code(__func__,ret)); + + return (state == 0); +} + +int nfc_manager_get_cached_message(nfc_ndef_message_h *ndef_message) +{ + int ret; + + LOG_BEGIN(); + + CHECK_SUPPORTED(NFC_FEATURE); + CHECK_INIT(); + CHECK_INVALID(ndef_message == NULL); + + ret = net_nfc_retrieve_current_ndef_message(ndef_message); + + return nfc_common_convert_error_code(__func__, ret); +} + +static void _se_event_cb(net_nfc_message_e message, void *user_data) +{ + LOG_BEGIN(); + + if (gdbus_nfc_context.on_se_event_cb != NULL) { + if(message == NET_NFC_MESSAGE_SE_CARD_EMULATION_CHANGED) + gdbus_nfc_context.on_se_event_cb( + NFC_SE_EVENT_CARD_EMULATION_CHANGED, + gdbus_nfc_context.on_se_event_user_data); + + else if(message == NET_NFC_MESSAGE_SE_TYPE_CHANGED) + gdbus_nfc_context.on_se_event_cb( + NFC_SE_EVENT_SE_TYPE_CHANGED, + gdbus_nfc_context.on_se_event_user_data); + else if(message == NET_NFC_MESSAGE_SE_FIELD_ON) + gdbus_nfc_context.on_se_event_cb( + NFC_SE_EVENT_FIELD_ON, + gdbus_nfc_context.on_se_event_user_data); + } +} + +int nfc_manager_set_se_event_cb(nfc_se_event_cb callback, void *user_data) +{ + LOG_BEGIN(); + + CHECK_SUPPORTED(NFC_CE_FEATURE); + CHECK_INIT(); + CHECK_INVALID(callback == NULL); + + net_nfc_client_se_set_event_cb(_se_event_cb, NULL); + + gdbus_nfc_context.on_se_event_cb = callback; + gdbus_nfc_context.on_se_event_user_data = user_data; + + return NFC_ERROR_NONE; +} + +void nfc_manager_unset_se_event_cb(void) +{ + LOG_BEGIN(); + + if(nfc_common_is_supported(NFC_CE_FEATURE) == false) + { + LOG_ERR("NFC not supported"); + set_last_result(NFC_ERROR_NOT_SUPPORTED); + return; + } + + if(nfc_common_is_initialized() == false) + { + LOG_ERR("NFC not initialized"); + set_last_result(NFC_ERROR_NOT_INITIALIZED); + return; + } + + gdbus_nfc_context.on_se_event_cb = NULL; + gdbus_nfc_context.on_se_event_user_data = NULL; + + set_last_result(NFC_ERROR_NONE); +} + +static void _se_transaction_event_cb(net_nfc_se_type_e se_type, data_h aid, + data_h param, void *user_data) +{ + LOG_BEGIN(); + + if (gdbus_nfc_context.on_se_transaction_event_cb != NULL) { + gdbus_nfc_context.on_se_transaction_event_cb( + se_type, + net_nfc_get_data_buffer(aid), + net_nfc_get_data_length(aid), + net_nfc_get_data_buffer(param), + net_nfc_get_data_length(param), + gdbus_nfc_context.on_se_transaction_event_user_data); + } +} + +int nfc_manager_set_se_transaction_event_cb( + nfc_se_type_e se_type, + nfc_se_transaction_event_cb callback, + void *user_data) +{ + net_nfc_se_type_e type = NET_NFC_SE_TYPE_NONE; + + LOG_BEGIN(); + + CHECK_SUPPORTED(NFC_CE_FEATURE); + CHECK_INIT(); + CHECK_INVALID(callback == NULL); + + gdbus_nfc_context.on_se_transaction_event_cb = callback; + gdbus_nfc_context.on_se_transaction_event_user_data = user_data; + + switch(se_type) + { + case NFC_SE_TYPE_ESE: + type = NET_NFC_SE_TYPE_ESE; + break; + + case NFC_SE_TYPE_UICC: + type = NET_NFC_SE_TYPE_UICC; + break; + case NET_NFC_SE_TYPE_HCE: + type = NET_NFC_SE_TYPE_HCE; + break; + default: + return NFC_ERROR_INVALID_PARAMETER; + break; + + } + + net_nfc_client_se_set_transaction_event_cb(type, _se_transaction_event_cb, user_data); + + return NFC_ERROR_NONE; +} + +void nfc_manager_unset_se_transaction_event_cb(nfc_se_type_e se_type) +{ + net_nfc_se_type_e type = NET_NFC_SE_TYPE_NONE; + + LOG_BEGIN(); + + if(nfc_common_is_supported(NFC_CE_FEATURE) == false) + { + LOG_ERR("NFC not supported"); + set_last_result(NFC_ERROR_NOT_SUPPORTED); + return; + } + + if(nfc_common_is_initialized() == false) + { + LOG_ERR("NFC not initialized"); + set_last_result(NFC_ERROR_NOT_INITIALIZED); + return; + } + + switch(se_type) + { + case NFC_SE_TYPE_ESE: + type = NET_NFC_SE_TYPE_ESE; + break; + + case NFC_SE_TYPE_UICC: + type = NET_NFC_SE_TYPE_UICC; + break; + default: + type = NET_NFC_SE_TYPE_NONE; + break; + } + + net_nfc_client_se_unset_transaction_event_cb(type); + + set_last_result(NFC_ERROR_NONE); +} + +int nfc_manager_enable_transaction_fg_dispatch() +{ + net_nfc_error_e result; + + LOG_BEGIN(); + + CHECK_SUPPORTED(NFC_CE_FEATURE); + CHECK_INIT(); + + result = net_nfc_client_se_set_transaction_fg_dispatch(true); + + return nfc_common_convert_error_code(__func__, result); +} + +int nfc_manager_disable_transaction_fg_dispatch() +{ + net_nfc_error_e result; + + CHECK_SUPPORTED(NFC_CE_FEATURE); + CHECK_INIT(); + + result = net_nfc_client_se_set_transaction_fg_dispatch(false); + + return nfc_common_convert_error_code(__func__, result); +} + +int nfc_manager_set_se_type(nfc_se_type_e type) +{ + int ret; + net_nfc_se_type_e se_type = NET_NFC_SE_TYPE_NONE; + + LOG_BEGIN(); + + CHECK_SUPPORTED(NFC_CE_FEATURE); + CHECK_INIT(); + CHECK_INVALID(type < NFC_SE_TYPE_DISABLE); + CHECK_INVALID(type > NFC_SE_TYPE_HCE); + + switch (type) + { + case NFC_SE_TYPE_ESE : + se_type = NET_NFC_SE_TYPE_ESE; + break; + case NFC_SE_TYPE_UICC : + se_type = NET_NFC_SE_TYPE_UICC; + break; + case NFC_SE_TYPE_HCE : + se_type = NET_NFC_SE_TYPE_HCE; + break; + default : + se_type = NET_NFC_SE_TYPE_NONE; + break; + } + + ret = net_nfc_client_se_set_secure_element_type_sync(se_type); + + return nfc_common_convert_error_code(__func__, ret); +} + +int nfc_manager_get_se_type(nfc_se_type_e *type) +{ + int ret; + net_nfc_se_type_e se_type = NET_NFC_SE_TYPE_NONE; + + LOG_BEGIN(); + + CHECK_SUPPORTED(NFC_CE_FEATURE); + CHECK_INIT(); + CHECK_INVALID(type == NULL); + + ret = net_nfc_client_se_get_secure_element_type_sync(&se_type); + + switch (se_type) + { + case NET_NFC_SE_TYPE_ESE : + *type = NFC_SE_TYPE_ESE; + break; + case NET_NFC_SE_TYPE_UICC : + *type = NFC_SE_TYPE_UICC; + break; + case NET_NFC_SE_TYPE_HCE : + *type = NFC_SE_TYPE_HCE; + break; + default: + *type = NFC_SE_TYPE_DISABLE; + break; + } + + return nfc_common_convert_error_code(__func__, ret); +} + +static void _hce_event_cb(net_nfc_target_handle_h handle, + net_nfc_hce_event_t event, data_h apdu, void *user_data) +{ + LOG_BEGIN(); + + if (gdbus_nfc_context.on_hce_event_cb != NULL) { + gdbus_nfc_context.on_hce_event_cb( + (nfc_se_h)handle, + (nfc_hce_event_type_e)event, + net_nfc_get_data_buffer(apdu), + net_nfc_get_data_length(apdu), + gdbus_nfc_context.on_hce_event_user_data); + } +} + +int nfc_manager_set_hce_event_cb(nfc_hce_event_cb callback, void *user_data) +{ + net_nfc_error_e result; + LOG_BEGIN(); + + CHECK_SUPPORTED(NFC_CE_HCE_FEATURE); + CHECK_INIT(); + CHECK_INVALID(callback == NULL); + + gdbus_nfc_context.on_hce_event_cb = callback; + gdbus_nfc_context.on_hce_event_user_data = user_data; + + result = net_nfc_client_hce_set_event_received_cb(_hce_event_cb, user_data); + + return nfc_common_convert_error_code(__func__, result); +} + +void nfc_manager_unset_hce_event_cb(void) +{ + LOG_BEGIN(); + + if(nfc_common_is_supported(NFC_CE_HCE_FEATURE) == false) + { + LOG_ERR("NFC not supported"); + set_last_result(NFC_ERROR_NOT_SUPPORTED); + return; + } + + if(nfc_common_is_initialized() == false) + { + LOG_ERR("NFC not initialized"); + set_last_result(NFC_ERROR_NOT_INITIALIZED); + return; + } + + net_nfc_client_hce_unset_event_received_cb(); + + set_last_result(NFC_ERROR_NONE); +} + diff --git a/src/nfc_ndef.c b/src/nfc_ndef.c new file mode 100644 index 0000000..446f386 --- /dev/null +++ b/src/nfc_ndef.c @@ -0,0 +1,596 @@ +/* +* Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "nfc_common.h" + +int nfc_ndef_record_create(nfc_ndef_record_h *record, + nfc_record_tnf_e tnf, + const unsigned char *type, + int type_size, + const unsigned char *id, + int id_size, + const unsigned char *payload, + unsigned int payload_size) +{ + int ret; + data_h type_data = NULL; + data_h id_data = NULL; + data_h payload_data = NULL; + + LOG_BEGIN(); + + CHECK_SUPPORTED(NFC_FEATURE); + CHECK_INIT(); + CHECK_INVALID(record == NULL); + + net_nfc_create_data(&type_data, type, type_size); + + if (id != NULL && id_size > 0) { + net_nfc_create_data(&id_data, id, id_size); + } + + if (payload != NULL && payload_size > 0) { + net_nfc_create_data(&payload_data, payload, payload_size); + } + + ret = net_nfc_create_record( + (ndef_record_h *)record, + tnf, + type_data, + id_data, + payload_data); + + if (payload_data != NULL) { + net_nfc_free_data(payload_data); + } + + if (id_data != NULL) { + net_nfc_free_data(id_data); + } + + net_nfc_free_data(type_data); + + return nfc_common_convert_error_code(__func__, ret); +} + + +int nfc_ndef_record_create_text(nfc_ndef_record_h *record, + const char *text, + const char *lang_code, + nfc_encode_type_e encode) +{ + int ret; + + LOG_BEGIN(); + + CHECK_SUPPORTED(NFC_FEATURE); + CHECK_INIT(); + CHECK_INVALID(record == NULL); + CHECK_INVALID(text == NULL); + CHECK_INVALID(lang_code == NULL); + + ret = net_nfc_create_text_type_record( + (ndef_record_h *)record, + text, + lang_code, + encode); + + return nfc_common_convert_error_code(__func__, ret); +} + +int nfc_ndef_record_create_uri(nfc_ndef_record_h *record, + const char *uri) +{ + int ret; + + LOG_BEGIN(); + + CHECK_SUPPORTED(NFC_FEATURE); + CHECK_INIT(); + CHECK_INVALID(record == NULL); + CHECK_INVALID(uri == NULL); + + ret = net_nfc_create_uri_type_record( + (ndef_record_h *)record, + uri, + NET_NFC_SCHEMA_FULL_URI); + + return nfc_common_convert_error_code(__func__, ret); +} + +int nfc_ndef_record_create_mime(nfc_ndef_record_h *record, + const char *mime_type, + const unsigned char *data, + unsigned int data_size) +{ + int ret; + + LOG_BEGIN(); + + CHECK_SUPPORTED(NFC_FEATURE); + CHECK_INIT(); + CHECK_INVALID(record == NULL); + CHECK_INVALID(mime_type == NULL); + CHECK_INVALID(data == NULL); + CHECK_INVALID(data_size <= 0); + + ret = nfc_ndef_record_create(record, + NFC_RECORD_TNF_MIME_MEDIA, + (unsigned char *)mime_type, + strlen(mime_type), + NULL, + 0, + data, + data_size); + + return nfc_common_convert_error_code(__func__, ret); +} + +int nfc_ndef_record_get_mime_type(nfc_ndef_record_h record, + char **mime_type) +{ + int ret; + nfc_record_tnf_e tnf; + unsigned char *typename; + int length; + + LOG_BEGIN(); + + CHECK_SUPPORTED(NFC_FEATURE); + CHECK_INIT(); + CHECK_INVALID(record == NULL); + CHECK_INVALID(mime_type == NULL); + + if (nfc_ndef_record_get_tnf(record, &tnf) != NET_NFC_OK || + tnf != NFC_RECORD_TNF_MIME_MEDIA) + { + return NFC_ERROR_INVALID_RECORD_TYPE; + } + + ret = nfc_ndef_record_get_type(record, &typename, &length); + if (ret == NET_NFC_OK) { + *mime_type = calloc(1, length + 1); + if (*mime_type != NULL) { + memcpy(*mime_type, typename, length); + } else { + ret = NET_NFC_ALLOC_FAIL; + } + } + + return nfc_common_convert_error_code(__func__, ret); +} + +int nfc_ndef_record_destroy(nfc_ndef_record_h record) +{ + int ret; + + LOG_BEGIN(); + + CHECK_SUPPORTED(NFC_FEATURE); + CHECK_INIT(); + CHECK_INVALID(record == NULL); + + ret = net_nfc_free_record(record); + + return nfc_common_convert_error_code(__func__, ret); +} + +int nfc_ndef_record_set_id(nfc_ndef_record_h record, + unsigned char *id, + int id_size) +{ + int ret; + data_h id_data = NULL; + + LOG_BEGIN(); + + CHECK_SUPPORTED(NFC_FEATURE); + CHECK_INIT(); + CHECK_INVALID(record == NULL); + CHECK_INVALID(id == NULL); + + ret = net_nfc_create_data(&id_data, id, id_size); + if (ret == NET_NFC_OK) { + ret = net_nfc_set_record_id(record, id_data); + + net_nfc_free_data(id_data); + } else { + LOG_ERR("net_nfc_create_data failed, [%d]", ret); + } + + return nfc_common_convert_error_code(__func__, ret); +} + +int nfc_ndef_record_get_payload(nfc_ndef_record_h record, + unsigned char **payload, + unsigned int *size) +{ + int ret; + data_h payload_data; + + LOG_BEGIN(); + + CHECK_SUPPORTED(NFC_FEATURE); + CHECK_INIT(); + CHECK_INVALID(record == NULL); + CHECK_INVALID(payload == NULL); + CHECK_INVALID(size == NULL); + + *payload = NULL; + *size = 0; + + ret = net_nfc_get_record_payload(record, &payload_data); + if (ret == NET_NFC_OK) { + *payload = net_nfc_get_data_buffer(payload_data); + *size = net_nfc_get_data_length(payload_data); + } else { + *payload = NULL; + *size = 0; + } + + return nfc_common_convert_error_code(__func__, ret); +} + +int nfc_ndef_record_get_type(nfc_ndef_record_h record, + unsigned char **type, + int *size) +{ + int ret; + data_h type_data; + + LOG_BEGIN(); + + CHECK_SUPPORTED(NFC_FEATURE); + CHECK_INIT(); + CHECK_INVALID(record == NULL); + CHECK_INVALID(type == NULL); + CHECK_INVALID(size == NULL); + + *type = NULL; + *size = 0; + + ret = net_nfc_get_record_type(record, &type_data); + if (ret == NET_NFC_OK) { + *type = net_nfc_get_data_buffer(type_data); + *size = net_nfc_get_data_length(type_data); + } else { + *type = NULL; + *size = 0; + } + + return nfc_common_convert_error_code(__func__, ret); +} + +int nfc_ndef_record_get_id(nfc_ndef_record_h record, + unsigned char **id, + int *size) +{ + int ret; + data_h id_data; + + LOG_BEGIN(); + + CHECK_SUPPORTED(NFC_FEATURE); + CHECK_INIT(); + CHECK_INVALID(record == NULL); + CHECK_INVALID(id == NULL); + CHECK_INVALID(size == NULL); + + *id = NULL; + *size = 0; + + ret = net_nfc_get_record_id(record, &id_data); + if (ret == NET_NFC_OK) { + *id = net_nfc_get_data_buffer(id_data); + *size = net_nfc_get_data_length(id_data); + } else { + *id = NULL; + *size = 0; + } + + return nfc_common_convert_error_code(__func__, ret); +} + +int nfc_ndef_record_get_tnf(nfc_ndef_record_h record, nfc_record_tnf_e *tnf) +{ + int ret; + + LOG_BEGIN(); + + CHECK_SUPPORTED(NFC_FEATURE); + CHECK_INIT(); + CHECK_INVALID(record == NULL); + CHECK_INVALID(tnf == NULL); + + ret = net_nfc_get_record_tnf(record, (net_nfc_record_tnf_e *)tnf); + + return nfc_common_convert_error_code(__func__, ret); +} + +int nfc_ndef_record_get_text(nfc_ndef_record_h record, char **buffer) +{ + int ret; + unsigned char* record_type = NULL; + int type_size = 0; + + LOG_BEGIN(); + + CHECK_SUPPORTED(NFC_FEATURE); + CHECK_INIT(); + CHECK_INVALID(record == NULL); + CHECK_INVALID(buffer == NULL); + + ret = nfc_ndef_record_get_type(record, &record_type, &type_size); + + if (ret == NFC_ERROR_NONE && record_type != NULL && type_size != 0 && + !strcmp((char*)record_type, "T")) + { + LOG_ERR("record type is T"); + ret = net_nfc_create_text_string_from_text_record(record, buffer); + } + else + { + LOG_ERR("record type is not T"); + return NFC_ERROR_INVALID_RECORD_TYPE; + } + + return nfc_common_convert_error_code(__func__, ret); +} + +int nfc_ndef_record_get_langcode(nfc_ndef_record_h record, char **lang_code) +{ + int ret; + + LOG_BEGIN(); + + CHECK_SUPPORTED(NFC_FEATURE); + CHECK_INIT(); + CHECK_INVALID(record == NULL); + CHECK_INVALID(lang_code == NULL); + + ret = net_nfc_get_languange_code_string_from_text_record(record, lang_code); + + return nfc_common_convert_error_code(__func__, ret); +} + +int nfc_ndef_record_get_encode_type( + nfc_ndef_record_h record, + nfc_encode_type_e *encode) +{ + int ret; + + LOG_BEGIN(); + + CHECK_SUPPORTED(NFC_FEATURE); + CHECK_INIT(); + CHECK_INVALID(record == NULL); + CHECK_INVALID(encode == NULL); + + ret = net_nfc_get_encoding_type_from_text_record( + record, + (net_nfc_encode_type_e *)encode); + + /* if( ret == NFC_NDEF_RECORD_IS_NOT_EXPECTED_TYPE) + LOGE("%s reord type is not text type");*/ + + return nfc_common_convert_error_code(__func__, ret); +} + +int nfc_ndef_record_get_uri(nfc_ndef_record_h record, char **uri) +{ + int ret; + + LOG_BEGIN(); + + CHECK_SUPPORTED(NFC_FEATURE); + CHECK_INIT(); + CHECK_INVALID(record == NULL); + CHECK_INVALID(uri == NULL); + + ret = net_nfc_create_uri_string_from_uri_record(record, uri); + + return nfc_common_convert_error_code(__func__, ret); +} + +int nfc_ndef_message_create(nfc_ndef_message_h *ndef_message) +{ + int ret; + + LOG_BEGIN(); + + CHECK_SUPPORTED(NFC_FEATURE); + CHECK_INIT(); + CHECK_INVALID(ndef_message == NULL); + + ret = net_nfc_create_ndef_message(ndef_message); + + return nfc_common_convert_error_code(__func__, ret); +} + +int nfc_ndef_message_create_from_rawdata( + nfc_ndef_message_h *ndef_message, + const unsigned char *rawdata, + unsigned int rawdata_size) +{ + int ret; + data_h rawdata_data = NULL; + + LOG_BEGIN(); + + CHECK_SUPPORTED(NFC_FEATURE); + CHECK_INIT(); + CHECK_INVALID(ndef_message == NULL); + CHECK_INVALID(rawdata == NULL); + CHECK_INVALID(rawdata_size <= 0); + + ret = net_nfc_create_data(&rawdata_data, rawdata, rawdata_size); + if (ret == NET_NFC_OK) { + ret = net_nfc_create_ndef_message_from_rawdata( + (ndef_message_h *)ndef_message, + rawdata_data); + + net_nfc_free_data(rawdata_data); + } else { + LOG_ERR("net_nfc_create_data failed, [%d]", ret); + } + + return nfc_common_convert_error_code(__func__, ret); +} + +int nfc_ndef_message_destroy(nfc_ndef_message_h ndef_message) +{ + int ret; + + LOG_BEGIN(); + + CHECK_SUPPORTED(NFC_FEATURE); + CHECK_INIT(); + CHECK_INVALID(ndef_message == NULL); + + ret = net_nfc_free_ndef_message(ndef_message); + + return nfc_common_convert_error_code(__func__, ret); +} + +int nfc_ndef_message_get_record_count(nfc_ndef_message_h ndef_message, + int *count) +{ + int ret; + + LOG_BEGIN(); + + CHECK_SUPPORTED(NFC_FEATURE); + CHECK_INIT(); + CHECK_INVALID(ndef_message == NULL); + CHECK_INVALID(count == NULL); + + ret = net_nfc_get_ndef_message_record_count(ndef_message, count); + + return nfc_common_convert_error_code(__func__, ret); +} + +int nfc_ndef_message_get_rawdata(nfc_ndef_message_h ndef_message, + unsigned char **rawdata, + unsigned int *rawdata_size) +{ + int ret; + data_h rawdata_data; + + LOG_BEGIN(); + + CHECK_SUPPORTED(NFC_FEATURE); + CHECK_INIT(); + CHECK_INVALID(ndef_message == NULL); + CHECK_INVALID(rawdata == NULL); + CHECK_INVALID(rawdata_size == NULL); + + *rawdata = NULL; + *rawdata_size = 0; + + ret = net_nfc_create_rawdata_from_ndef_message(ndef_message, + &rawdata_data); + if (ret == NET_NFC_OK) { + uint8_t *buffer; + uint32_t length; + + buffer = net_nfc_get_data_buffer(rawdata_data); + length = net_nfc_get_data_length(rawdata_data); + + *rawdata = calloc(1, length); + if (*rawdata != NULL) { + memcpy(*rawdata, buffer, length); + *rawdata_size = length; + } else { + ret = NET_NFC_ALLOC_FAIL; + } + + net_nfc_free_data(rawdata_data); + } + + return nfc_common_convert_error_code(__func__, ret); +} + +int nfc_ndef_message_append_record(nfc_ndef_message_h ndef_message, + nfc_ndef_record_h record) +{ + int ret; + + LOG_BEGIN(); + + CHECK_SUPPORTED(NFC_FEATURE); + CHECK_INIT(); + CHECK_INVALID(ndef_message == NULL); + CHECK_INVALID(record == NULL); + + ret = net_nfc_append_record_to_ndef_message(ndef_message, record); + + return nfc_common_convert_error_code(__func__, ret); +} + +int nfc_ndef_message_insert_record(nfc_ndef_message_h ndef_message, + int index, + nfc_ndef_record_h record) +{ + int ret; + + LOG_BEGIN(); + + CHECK_SUPPORTED(NFC_FEATURE); + CHECK_INIT(); + CHECK_INVALID(ndef_message == NULL); + CHECK_INVALID(record == NULL); + + ret = net_nfc_append_record_by_index(ndef_message, index, record); + + return nfc_common_convert_error_code(__func__, ret); +} + +int nfc_ndef_message_remove_record(nfc_ndef_message_h ndef_message, + int index) +{ + int ret; + + LOG_BEGIN(); + + CHECK_SUPPORTED(NFC_FEATURE); + CHECK_INIT(); + CHECK_INVALID(ndef_message == NULL); + + ret = net_nfc_remove_record_by_index(ndef_message, index); + + return nfc_common_convert_error_code(__func__, ret); +} + +int nfc_ndef_message_get_record(nfc_ndef_message_h ndef_message, + int index, + nfc_ndef_record_h *record) +{ + int ret; + + LOG_BEGIN(); + + CHECK_SUPPORTED(NFC_FEATURE); + CHECK_INIT(); + CHECK_INVALID(ndef_message == NULL); + CHECK_INVALID(record == NULL); + + ret = net_nfc_get_record_by_index(ndef_message, + index, + (ndef_record_h*)record); + + return nfc_common_convert_error_code(__func__, ret); +} + diff --git a/src/nfc_p2p.c b/src/nfc_p2p.c new file mode 100644 index 0000000..656b957 --- /dev/null +++ b/src/nfc_p2p.c @@ -0,0 +1,543 @@ +/* +* Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "nfc_common.h" + +static void _p2p_send_cb(net_nfc_error_e result, void *user_data) +{ + nfc_p2p_send_completed_cb callback; + void *user_param; + + LOG_BEGIN(); + + if (user_data == NULL) { + return; + } + + g_variant_get((GVariant *)user_data, + "(uu)", + (guint *)&callback, + (guint *)&user_param); + + if (callback != NULL) { + callback(nfc_common_convert_error_code(__func__, result), user_param); + } + + g_variant_unref((GVariant *)user_data); +} + +int nfc_p2p_send(nfc_p2p_target_h target, + nfc_ndef_message_h message, + nfc_p2p_send_completed_cb callback, + void *user_data) +{ + int ret; + data_h rawdata; + GVariant *parameter; + + LOG_BEGIN(); + + CHECK_SUPPORTED(NFC_P2P_FEATURE); + CHECK_INIT(); + CHECK_INVALID(message == NULL); + CHECK_INVALID(target == NULL); + CHECK_ACTIVATED(); + CHECK_APP_PERMISSION(); + + parameter = g_variant_new("(uu)", + GPOINTER_TO_UINT(callback), + GPOINTER_TO_UINT(user_data)); + if (parameter != NULL) { + net_nfc_create_rawdata_from_ndef_message(message, &rawdata); + ret = net_nfc_client_p2p_send((net_nfc_target_handle_h)target, + rawdata, + _p2p_send_cb, + parameter); + if (ret != NET_NFC_OK) { + g_variant_unref(parameter); + } + + net_nfc_free_data(rawdata); + } else { + ret = NET_NFC_ALLOC_FAIL; + } + + return nfc_common_convert_error_code(__func__, ret); +} + +int nfc_p2p_send_no_permission( + nfc_p2p_target_h target, + nfc_ndef_message_h message, + nfc_p2p_send_completed_cb callback, + void *user_data) +{ + int ret; + data_h rawdata; + GVariant *parameter; + + LOG_BEGIN(); + + CHECK_SUPPORTED(NFC_P2P_FEATURE); + CHECK_INIT(); + CHECK_INVALID(target == NULL); + CHECK_INVALID(message == NULL); + CHECK_ACTIVATED(); + + /* skip check app permission */ + + parameter = g_variant_new("(uu)", + GPOINTER_TO_UINT(callback), + GPOINTER_TO_UINT(user_data)); + if (parameter != NULL) { + net_nfc_create_rawdata_from_ndef_message(message, &rawdata); + ret = net_nfc_client_p2p_send((net_nfc_target_handle_h)target, + rawdata, + _p2p_send_cb, + parameter); + if (ret != NET_NFC_OK) { + g_variant_unref(parameter); + } + + net_nfc_free_data(rawdata); + } else { + ret = NET_NFC_ALLOC_FAIL; + } + + return nfc_common_convert_error_code(__func__, ret); +} + +static void _p2p_set_data_received_cb(data_h data, void *user_data) +{ + LOG_BEGIN(); + + if (gdbus_nfc_context.on_p2p_recv_cb != NULL) + { + ndef_message_h ndef_message; + + net_nfc_create_ndef_message_from_rawdata(&ndef_message, data); + + gdbus_nfc_context.on_p2p_recv_cb( + (nfc_p2p_target_h)(gdbus_nfc_context.current_target), + ndef_message, + gdbus_nfc_context.on_p2p_recv_user_data); + + net_nfc_free_ndef_message(ndef_message); + } +} + +int nfc_p2p_set_data_received_cb(nfc_p2p_target_h target, + nfc_p2p_data_received_cb callback, + void *user_data) +{ + LOG_BEGIN(); + + CHECK_SUPPORTED(NFC_P2P_FEATURE); + CHECK_INIT(); + CHECK_INVALID(target == NULL); + CHECK_INVALID(callback == NULL); + CHECK_INVALID(gdbus_nfc_context.current_target != target); + + gdbus_nfc_context.on_p2p_recv_cb = callback; + gdbus_nfc_context.on_p2p_recv_user_data = user_data; + + net_nfc_client_p2p_set_data_received(_p2p_set_data_received_cb, NULL); + + return NFC_ERROR_NONE; +} + +int nfc_p2p_unset_data_received_cb(nfc_p2p_target_h target) +{ + LOG_BEGIN(); + + CHECK_SUPPORTED(NFC_P2P_FEATURE); + CHECK_INIT(); + CHECK_INVALID(target == NULL); + CHECK_INVALID(gdbus_nfc_context.current_target != target); + + net_nfc_client_p2p_unset_data_received(); + + gdbus_nfc_context.on_p2p_recv_cb = NULL; + gdbus_nfc_context.on_p2p_recv_user_data = NULL; + + return NFC_ERROR_NONE; +} + +static void _snep_start_server_cb( + net_nfc_snep_handle_h arg_handle, + net_nfc_snep_type_t event, + net_nfc_error_e result, + nfc_ndef_message_h msg, + void *user_data) +{ + nfc_snep_event_cb callback; + void *user_param; + + LOG_BEGIN(); + + if (user_data == NULL) { + LOG_ERR("user_data is NULL"); + return; + } + + g_variant_get((GVariant *)user_data, + "(uu)", + (guint *)&callback, + (guint *)&user_param); + + if (callback != NULL) { + nfc_snep_event_e snep_event; + + switch ((int)event) { + case NET_NFC_SNEP_GET : + snep_event = NFC_SNEP_EVENT_GET; + break; + + case NET_NFC_SNEP_PUT : + snep_event = NFC_SNEP_EVENT_PUT; + break; + + case NET_NFC_LLCP_REGISTERED : + snep_event = NFC_SNEP_EVENT_REGISTER; + break; + + case NET_NFC_LLCP_UNREGISTERED : + snep_event = NFC_SNEP_EVENT_UNREGISTER; + break; + + case NET_NFC_LLCP_START : + snep_event = NFC_SNEP_EVENT_START; + break; + + case NET_NFC_LLCP_STOP : + default : + snep_event = NFC_SNEP_EVENT_STOP; + break; + } + + callback(arg_handle, snep_event, + nfc_common_convert_error_code(__func__, result), + msg, user_param); + + if (snep_event == NFC_SNEP_EVENT_STOP) { + g_variant_unref(user_data); + } + } +} + +int nfc_snep_start_server(nfc_p2p_target_h target, + const char *san, + int sap, + nfc_snep_event_cb callback, + void *user_data) +{ + net_nfc_error_e result; + GVariant *parameter; + + LOG_BEGIN(); + + CHECK_SUPPORTED(NFC_P2P_FEATURE); + CHECK_INIT(); + CHECK_INVALID(target == NULL); + + parameter = g_variant_new("(uu)", + GPOINTER_TO_UINT(callback), + GPOINTER_TO_UINT(user_data)); + if (parameter != NULL) { + result = net_nfc_client_snep_start_server( + (net_nfc_target_handle_h)target, + san, + (sap_t)sap, + _snep_start_server_cb, + parameter); + if (result != NET_NFC_OK) { + g_variant_unref(parameter); + } + } else { + result = NET_NFC_ALLOC_FAIL; + } + + return nfc_common_convert_error_code(__func__, result); +} + +static void _snep_start_client_cb(net_nfc_snep_handle_h arg_handle, + net_nfc_snep_type_t event, + net_nfc_error_e result, + nfc_ndef_message_h msg, + void *user_data) +{ + nfc_snep_event_cb callback; + void *user_param; + + LOG_BEGIN(); + + if (user_data == NULL) { + LOG_ERR("user_data is NULL"); + return; + } + + g_variant_get((GVariant *)user_data, + "(uu)", + (guint *)&callback, + (guint *)&user_param); + + if (callback != NULL) { + nfc_snep_event_e snep_event; + + switch ((int)event) { + case NET_NFC_SNEP_GET : + snep_event = NFC_SNEP_EVENT_GET; + break; + + case NET_NFC_SNEP_PUT : + snep_event = NFC_SNEP_EVENT_PUT; + break; + + case NET_NFC_LLCP_REGISTERED : + snep_event = NFC_SNEP_EVENT_REGISTER; + break; + + case NET_NFC_LLCP_UNREGISTERED : + snep_event = NFC_SNEP_EVENT_UNREGISTER; + break; + + case NET_NFC_LLCP_START : + snep_event = NFC_SNEP_EVENT_START; + break; + + case NET_NFC_LLCP_STOP : + default : + snep_event = NFC_SNEP_EVENT_STOP; + break; + } + + callback(arg_handle, snep_event, + nfc_common_convert_error_code(__func__, result), + msg, user_param); + + if (snep_event == NFC_SNEP_EVENT_STOP) { + g_variant_unref(user_data); + } + } +} + +int nfc_snep_start_client(nfc_p2p_target_h target, + const char *san, + int sap, + nfc_snep_event_cb callback, + void *user_data) +{ + net_nfc_error_e result; + GVariant *parameter; + + LOG_BEGIN(); + + CHECK_SUPPORTED(NFC_P2P_FEATURE); + CHECK_INIT(); + CHECK_INVALID(target == NULL); + + parameter = g_variant_new("(uu)", + GPOINTER_TO_UINT(callback), + GPOINTER_TO_UINT(user_data)); + if (parameter != NULL) { + result = net_nfc_client_snep_start_client( + (net_nfc_target_handle_h)target, + san, + (sap_t)sap, + _snep_start_client_cb, + parameter); + if (result != NET_NFC_OK) { + g_variant_unref(parameter); + } + } else { + result = NET_NFC_ALLOC_FAIL; + } + + return nfc_common_convert_error_code(__func__, result); +} + +static void _snep_send_request_cb(net_nfc_snep_handle_h target, + net_nfc_snep_type_t event, net_nfc_error_e result, ndef_message_h msg, void *user_data) +{ + nfc_snep_event_cb callback; + void *user_param; + + LOG_BEGIN(); + + if (user_data == NULL) { + LOG_ERR("user_data is NULL"); + return; + } + + g_variant_get((GVariant *)user_data, + "(uu)", + (guint *)&callback, + (guint *)&user_param); + + if (callback != NULL) { + callback((nfc_p2p_snep_h)target, + event, + nfc_common_convert_error_code(__func__, result), + (nfc_ndef_message_h)msg, + user_param); + } + + g_variant_unref((GVariant *)user_data); +} + +int nfc_snep_send_client_request(nfc_p2p_snep_h handle, + nfc_snep_type_e type, + nfc_ndef_message_h msg, + nfc_snep_event_cb callback, + void *user_data) +{ + net_nfc_error_e result; + GVariant *parameter; + + LOG_BEGIN(); + + CHECK_SUPPORTED(NFC_P2P_FEATURE); + CHECK_INIT(); + CHECK_INVALID(handle == NULL); + CHECK_INVALID(msg == NULL); + + parameter = g_variant_new("(uu)", + GPOINTER_TO_UINT(callback), + GPOINTER_TO_UINT(user_data)); + if (parameter != NULL) { + result = net_nfc_client_snep_send_client_request( + (net_nfc_target_handle_h)handle, + type, + msg, + _snep_send_request_cb, + parameter); + if (result != NET_NFC_OK) { + g_variant_unref(parameter); + } + } else { + result = NET_NFC_ALLOC_FAIL; + } + + return nfc_common_convert_error_code(__func__, result); +} + +static void _snep_event_cb(net_nfc_snep_handle_h target, net_nfc_snep_type_t event, + net_nfc_error_e result, ndef_message_h msg, void *user_data) +{ + nfc_snep_event_cb callback; + void *user_param; + + LOG_BEGIN(); + + if (user_data == NULL) { + LOG_ERR("user_data is NULL"); + return; + } + + g_variant_get((GVariant *)user_data, + "(uu)", + (guint *)&callback, + (guint *)&user_param); + + if (callback != NULL) { + switch ((int)event) { + case NET_NFC_SNEP_GET : + event = NFC_SNEP_EVENT_GET; + break; + + case NET_NFC_SNEP_PUT : + event = NFC_SNEP_EVENT_PUT; + break; + + case NET_NFC_LLCP_REGISTERED : + event = NFC_SNEP_EVENT_REGISTER; + break; + + case NET_NFC_LLCP_UNREGISTERED : + event = NFC_SNEP_EVENT_UNREGISTER; + break; + + case NET_NFC_LLCP_START : + event = NFC_SNEP_EVENT_START; + break; + + case NET_NFC_LLCP_STOP : + event = NFC_SNEP_EVENT_STOP; + break; + } + + callback(target, event, + nfc_common_convert_error_code(__func__, result), + (ndef_message_h)msg, user_param); + } +} + +int nfc_snep_register_server(const char *san, int sap, + nfc_snep_event_cb callback, void *user_data) +{ + net_nfc_error_e result; + GVariant *parameter; + + LOG_BEGIN(); + + CHECK_SUPPORTED(NFC_P2P_FEATURE); + CHECK_INIT(); + CHECK_INVALID(san == NULL); + CHECK_INVALID(sap == 0); + + parameter = g_variant_new("(uu)", + GPOINTER_TO_UINT(callback), + GPOINTER_TO_UINT(user_data)); + if (parameter != NULL) { + result = net_nfc_client_snep_register_server(san, (sap_t)sap, + _snep_event_cb, parameter); + if (result != NET_NFC_OK) { + g_variant_unref(parameter); + } + } else { + result = NET_NFC_ALLOC_FAIL; + } + + return nfc_common_convert_error_code(__func__, result); +} + +int nfc_snep_unregister_server(const char *san, int sap) +{ + net_nfc_error_e result; + + LOG_BEGIN(); + + CHECK_SUPPORTED(NFC_P2P_FEATURE); + CHECK_INIT(); + + result = net_nfc_client_snep_unregister_server(san, (sap_t)sap); + + return nfc_common_convert_error_code(__func__, result); +} + +int nfc_snep_stop_service(nfc_p2p_target_h target, nfc_p2p_snep_h clients) +{ + net_nfc_error_e result; + + LOG_BEGIN(); + + CHECK_SUPPORTED(NFC_P2P_FEATURE); + CHECK_INIT(); + + result = net_nfc_client_snep_stop_service_sync(target, clients); + + return nfc_common_convert_error_code(__func__, result); +} + diff --git a/src/nfc_p2p_handover.c b/src/nfc_p2p_handover.c new file mode 100644 index 0000000..68e2b5a --- /dev/null +++ b/src/nfc_p2p_handover.c @@ -0,0 +1,563 @@ +/* +* Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "nfc_common.h" + +static void _p2p_handover_cb(net_nfc_error_e result, + net_nfc_conn_handover_carrier_type_e carrier, data_h ac_data, void *user_data) +{ + nfc_p2p_connection_handover_completed_cb callback; + void *user_param; + + LOG_BEGIN(); + + if (user_data == NULL) { + return; + } + + g_variant_get((GVariant *)user_data, + "(uu)", + (guint *)&callback, + (guint *)&user_param); + + if (callback != NULL) { + nfc_ac_type_e carrior_type; + char *buffer; + int len = 0; + + switch (carrier) { + case NET_NFC_CONN_HANDOVER_CARRIER_BT : + carrior_type = NFC_AC_TYPE_BT; + buffer = nfc_common_get_bt_address_string(ac_data); + if(buffer != NULL) + len = strlen(buffer); + break; + + case NET_NFC_CONN_HANDOVER_CARRIER_WIFI_WPS : + carrior_type = NFC_AC_TYPE_WIFI; + buffer = nfc_common_get_bt_address_string(ac_data); + if(buffer != NULL) + len = strlen(buffer); + break; + + case NET_NFC_CONN_HANDOVER_CARRIER_WIFI_P2P : + carrior_type = NFC_AC_TYPE_WIFI_DIRECT; + buffer = nfc_common_get_bt_address_string(ac_data); + if(buffer != NULL) + len = strlen(buffer); + break; + + default : + carrior_type = NFC_AC_TYPE_UNKNOWN; + buffer = NULL; + len = 0; + break; + } + + callback(nfc_common_convert_error_code(__func__, result), + carrior_type, (void *)buffer, + len, user_param); + + if (buffer != NULL) { + g_free(buffer); + } + } + + g_variant_unref((GVariant *)user_data); +} + +int nfc_p2p_connection_handover(nfc_p2p_target_h target, + nfc_ac_type_e type, + nfc_p2p_connection_handover_completed_cb callback, + void *user_data) +{ + int ret; + net_nfc_conn_handover_carrier_type_e net_ac_type = + NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN; + GVariant *parameter; + + LOG_BEGIN(); + + CHECK_SUPPORTED(NFC_P2P_FEATURE); + CHECK_INIT(); + CHECK_INVALID(target == NULL); + CHECK_INVALID(type > NFC_AC_TYPE_UNKNOWN); + CHECK_ACTIVATED(); + + switch (type) + { + case NFC_AC_TYPE_BT : + net_ac_type = NET_NFC_CONN_HANDOVER_CARRIER_BT; + break; + + case NFC_AC_TYPE_WIFI : + net_ac_type = NET_NFC_CONN_HANDOVER_CARRIER_WIFI_WPS; + break; + + case NFC_AC_TYPE_WIFI_DIRECT : + net_ac_type = NET_NFC_CONN_HANDOVER_CARRIER_WIFI_P2P; + break; + + case NFC_AC_TYPE_UNKNOWN : + net_ac_type = NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN; + break; + + default: + break; + } + + parameter = g_variant_new("(uu)", + GPOINTER_TO_UINT(callback), + GPOINTER_TO_UINT(user_data)); + if (parameter != NULL) { + ret = net_nfc_client_p2p_connection_handover( + (net_nfc_target_handle_h)target, + net_ac_type, + _p2p_handover_cb, + parameter); + if (ret != NET_NFC_OK) { + g_variant_unref(parameter); + } + } else { + ret = NET_NFC_ALLOC_FAIL; + } + + return nfc_common_convert_error_code(__func__, ret); +} + +static void _connection_handover_event_cb( + net_nfc_handover_event_e event, + net_nfc_error_e result, + net_nfc_conn_handover_carrier_type_e carrier, + data_h ac_data, + data_h ndef_message, + void *user_data) +{ + LOG_BEGIN(); + + if (gdbus_nfc_context.on_handover_event_cb != NULL) { + nfc_ndef_message_h message; + nfc_ac_type_e type; + char *address; + + net_nfc_create_ndef_message_from_rawdata(&message, ndef_message); + + if (event == NET_NFC_HANDOVER_START) { + type = NFC_AC_TYPE_UNKNOWN; + address = NULL; + } else { + switch (carrier) { + case NET_NFC_CONN_HANDOVER_CARRIER_BT : + type = NFC_AC_TYPE_BT; + address = nfc_common_get_bt_address_string(ac_data); + break; + + case NET_NFC_CONN_HANDOVER_CARRIER_WIFI_WPS : + type = NFC_AC_TYPE_WIFI; + address = nfc_common_get_bt_address_string(ac_data); + break; + + case NET_NFC_CONN_HANDOVER_CARRIER_WIFI_P2P : + type = NFC_AC_TYPE_WIFI_DIRECT; + address = nfc_common_get_bt_address_string(ac_data); + break; + + default : + type = NFC_AC_TYPE_UNKNOWN; + address = NULL; + break; + } + } + + gdbus_nfc_context.on_handover_event_cb( + nfc_common_convert_error_code(__func__, result), + event, + type, + address, + message, + gdbus_nfc_context.on_handover_event_user_data); + + if (address != NULL) { + g_free(address); + } + net_nfc_free_ndef_message(message); + } + + LOG_END(); +} + +int nfc_connection_handover_set_event_cb(nfc_connection_handover_event_cb callback, void *user_data) +{ + LOG_BEGIN(); + + CHECK_SUPPORTED(NFC_P2P_FEATURE); + CHECK_INIT(); + CHECK_INVALID(callback == NULL); + + gdbus_nfc_context.on_handover_event_cb = callback; + gdbus_nfc_context.on_handover_event_user_data = user_data; + + net_nfc_client_handover_set_handover_event_cb(_connection_handover_event_cb, NULL); + + return NFC_ERROR_NONE; +} + +int nfc_connection_handover_unset_event_cb(void) +{ + LOG_BEGIN(); + + CHECK_SUPPORTED(NFC_P2P_FEATURE); + CHECK_INIT(); + + net_nfc_client_handover_unset_handover_event_cb(); + + gdbus_nfc_context.on_handover_event_cb = NULL; + gdbus_nfc_context.on_handover_event_user_data = NULL; + + return NFC_ERROR_NONE; +} + +bool nfc_p2p_is_supported_ac_type(nfc_ac_type_e carrier) +{ + bool result = false; + + LOG_BEGIN(); + + if (carrier == NFC_AC_TYPE_BT) + result = true; + + return result; +} + +int nfc_handover_message_import_from_ndef_message(nfc_handover_message_h *result, nfc_ndef_message_h msg) +{ + net_nfc_error_e ret; + + LOG_BEGIN(); + + CHECK_SUPPORTED(NFC_P2P_FEATURE); + CHECK_INIT(); + CHECK_INVALID(msg == NULL); + CHECK_INVALID(result == NULL); + + ret = net_nfc_import_handover_from_ndef_message( + (ndef_message_h)msg, (net_nfc_ch_message_h *)result); + + return nfc_common_convert_error_code(__func__, ret); +} + +int nfc_handover_message_get_random_number(nfc_handover_message_h message, unsigned short *random_number) +{ + net_nfc_error_e result; + + LOG_BEGIN(); + + CHECK_SUPPORTED(NFC_P2P_FEATURE); + CHECK_INIT(); + CHECK_INVALID(message == NULL); + CHECK_INVALID(random_number == NULL); + + result = net_nfc_get_handover_random_number( + (net_nfc_ch_message_h)message, + random_number); + + return nfc_common_convert_error_code(__func__, result); +} + +int nfc_handover_message_get_carrier_count(nfc_handover_message_h message, unsigned int *count) +{ + net_nfc_error_e result; + + LOG_BEGIN(); + + CHECK_SUPPORTED(NFC_P2P_FEATURE); + CHECK_INIT(); + CHECK_INVALID(message == NULL); + CHECK_INVALID(count == NULL); + + result = net_nfc_get_handover_carrier_count( + (net_nfc_ch_message_h)message, + count); + + return nfc_common_convert_error_code(__func__, result); +} + +int nfc_handover_message_get_carrier(nfc_handover_message_h message, int index, nfc_handover_carrier_h *carrier) +{ + net_nfc_error_e result; + + LOG_BEGIN(); + + CHECK_SUPPORTED(NFC_P2P_FEATURE); + CHECK_INIT(); + CHECK_INVALID(message == NULL); + CHECK_INVALID(carrier == NULL); + + result = net_nfc_get_handover_carrier( + (net_nfc_ch_message_h)message, + index, + (net_nfc_ch_carrier_h *)carrier); + + return nfc_common_convert_error_code(__func__, result); +} + +int nfc_handover_message_get_carrier_by_type(nfc_handover_message_h message, nfc_ac_type_e type, nfc_handover_carrier_h *carrier) +{ + net_nfc_error_e result; + net_nfc_conn_handover_carrier_type_e temp; + + LOG_BEGIN(); + + CHECK_SUPPORTED(NFC_P2P_FEATURE); + CHECK_INIT(); + CHECK_INVALID(message == NULL); + CHECK_INVALID(carrier == NULL); + + switch (type) { + case NFC_AC_TYPE_BT : + temp = NET_NFC_CONN_HANDOVER_CARRIER_BT; + break; + + case NFC_AC_TYPE_WIFI : + temp = NET_NFC_CONN_HANDOVER_CARRIER_WIFI_WPS; + break; + + case NFC_AC_TYPE_WIFI_DIRECT : + temp = NET_NFC_CONN_HANDOVER_CARRIER_WIFI_P2P; + break; + + default: + temp = NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN; + break; + } + result = net_nfc_get_handover_carrier_by_type( + (net_nfc_ch_message_h)message, + temp, + (net_nfc_ch_carrier_h *)carrier); + + return nfc_common_convert_error_code(__func__, result); +} + +int nfc_handover_message_destroy(nfc_handover_message_h message) +{ + net_nfc_error_e result; + + LOG_BEGIN(); + + CHECK_SUPPORTED(NFC_P2P_FEATURE); + CHECK_INIT(); + CHECK_INVALID(message == NULL); + + result = net_nfc_free_handover_message((net_nfc_ch_message_h)message); + + return nfc_common_convert_error_code(__func__, result); +} + + +int nfc_handover_carrier_get_cps(nfc_handover_carrier_h carrier, nfc_ac_state_e *cps) +{ + net_nfc_error_e result; + net_nfc_conn_handover_carrier_state_e temp; + + LOG_BEGIN(); + + CHECK_SUPPORTED(NFC_P2P_FEATURE); + CHECK_INIT(); + CHECK_INVALID(carrier == NULL); + CHECK_INVALID(cps == NULL); + + result = net_nfc_get_handover_carrier_cps( + (net_nfc_ch_carrier_h)carrier, &temp); + if (result == NET_NFC_OK) { + switch (temp) { + case NET_NFC_CONN_HANDOVER_CARRIER_INACTIVATE : + *cps = NFC_AC_STATE_INACTIVATE; + break; + + case NET_NFC_CONN_HANDOVER_CARRIER_ACTIVATE : + *cps = NFC_AC_STATE_ACTIVATE; + break; + + case NET_NFC_CONN_HANDOVER_CARRIER_ACTIVATING : + *cps = NFC_AC_STATE_ACTIVATING; + break; + + default : + *cps = NFC_AC_STATE_UNKNOWN; + break; + } + } + + return nfc_common_convert_error_code(__func__, result); +} + +int nfc_handover_carrier_get_type(nfc_handover_carrier_h carrier, nfc_ac_type_e *type) +{ + net_nfc_error_e result; + net_nfc_conn_handover_carrier_type_e temp; + + LOG_BEGIN(); + + CHECK_SUPPORTED(NFC_P2P_FEATURE); + CHECK_INIT(); + CHECK_INVALID(carrier == NULL); + CHECK_INVALID(type == NULL); + + result = net_nfc_get_handover_carrier_type( + (net_nfc_ch_carrier_h)carrier, &temp); + if (result == NET_NFC_OK) { + switch (temp) { + case NET_NFC_CONN_HANDOVER_CARRIER_BT : + *type = NFC_AC_TYPE_BT; + break; + + case NET_NFC_CONN_HANDOVER_CARRIER_WIFI_WPS : + *type = NFC_AC_TYPE_WIFI; + break; + + case NET_NFC_CONN_HANDOVER_CARRIER_WIFI_P2P : + *type = NFC_AC_TYPE_WIFI_DIRECT; + break; + + default : + *type = NFC_AC_TYPE_UNKNOWN; + break; + } + } + + return nfc_common_convert_error_code(__func__, result); +} + +int nfc_handover_carrier_get_carrier_record(nfc_handover_carrier_h carrier, nfc_ndef_record_h *record) +{ + net_nfc_error_e result; + + LOG_BEGIN(); + + CHECK_SUPPORTED(NFC_P2P_FEATURE); + CHECK_INIT(); + CHECK_INVALID(carrier == NULL); + CHECK_INVALID(record == NULL); + + result = net_nfc_get_handover_carrier_record( + (net_nfc_ch_carrier_h)carrier, (ndef_record_h *)record); + + return nfc_common_convert_error_code(__func__, result); +} + +int nfc_handover_carrier_get_auxiliary_record_count(nfc_handover_carrier_h carrier, unsigned int *count) +{ + net_nfc_error_e result; + + LOG_BEGIN(); + + CHECK_SUPPORTED(NFC_P2P_FEATURE); + CHECK_INIT(); + CHECK_INVALID(carrier == NULL); + CHECK_INVALID(count == NULL); + + result = net_nfc_get_handover_auxiliary_record_count( + (net_nfc_ch_carrier_h)carrier, count); + + return nfc_common_convert_error_code(__func__, result); +} + +int nfc_handover_carrier_get_auxiliary_record(nfc_handover_carrier_h carrier, int index, nfc_ndef_record_h *record) +{ + net_nfc_error_e result; + + LOG_BEGIN(); + + CHECK_SUPPORTED(NFC_P2P_FEATURE); + CHECK_INIT(); + CHECK_INVALID(carrier == NULL); + CHECK_INVALID(record == NULL); + + result = net_nfc_get_handover_auxiliary_record( + (net_nfc_ch_carrier_h)carrier, + index, (ndef_record_h *)record); + + return nfc_common_convert_error_code(__func__, result); +} + +int nfc_handover_carrier_get_handover_config(nfc_handover_carrier_h carrier, nfc_handover_config_h *config) +{ + net_nfc_error_e result; + + LOG_BEGIN(); + + CHECK_SUPPORTED(NFC_P2P_FEATURE); + CHECK_INIT(); + CHECK_INVALID(carrier == NULL); + CHECK_INVALID(config == NULL); + + result = net_nfc_create_carrier_config_from_carrier( + (net_nfc_carrier_config_h *)config, + (net_nfc_ch_carrier_h)carrier); + + return nfc_common_convert_error_code(__func__, result); +} + +int nfc_handover_carrier_destroy(nfc_handover_carrier_h carrier) +{ + net_nfc_error_e result; + + LOG_BEGIN(); + + CHECK_SUPPORTED(NFC_P2P_FEATURE); + CHECK_INIT(); + CHECK_INVALID(carrier == NULL); + + result = net_nfc_free_handover_carrier((net_nfc_ch_carrier_h)carrier); + + return nfc_common_convert_error_code(__func__, result); +} + + +int nfc_handover_config_get_property(nfc_handover_config_h config, unsigned short attribute, unsigned short *size, unsigned char **data) +{ + net_nfc_error_e result; + + LOG_BEGIN(); + + CHECK_SUPPORTED(NFC_P2P_FEATURE); + CHECK_INIT(); + CHECK_INVALID(config == NULL); + CHECK_INVALID(size == NULL); + CHECK_INVALID(data == NULL); + + result = net_nfc_get_carrier_config_property( + (net_nfc_carrier_config_h)config, + attribute, size, data); + + return nfc_common_convert_error_code(__func__, result); +} + +int nfc_handover_config_destroy(nfc_handover_config_h config) +{ + net_nfc_error_e result; + + LOG_BEGIN(); + + CHECK_SUPPORTED(NFC_P2P_FEATURE); + CHECK_INIT(); + CHECK_INVALID(config == NULL); + + result = net_nfc_free_carrier_config((net_nfc_carrier_config_h)config); + + return nfc_common_convert_error_code(__func__, result); +} + diff --git a/src/nfc_tag.c b/src/nfc_tag.c new file mode 100644 index 0000000..ae3d7b0 --- /dev/null +++ b/src/nfc_tag.c @@ -0,0 +1,1147 @@ +/* +* Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "nfc_common.h" + +static void _tag_format_ndef_cb(net_nfc_error_e result, + void *user_data) +{ + nfc_tag_format_completed_cb callback; + void *user_param; + + LOG_BEGIN(); + + if (user_data == NULL) { + LOG_ERR("user_data is NULL"); + return; + } + + g_variant_get((GVariant *)user_data, + "(uu)", + (guint *)&callback, + (guint *)&user_param); + + if (callback != NULL) { + callback(nfc_common_convert_error_code(__func__, result), + user_param); + } + + g_variant_unref((GVariant *)user_data); +} + +int nfc_tag_format_ndef(nfc_tag_h tag, + unsigned char *key, + int key_size, + nfc_tag_format_completed_cb callback, + void *user_data) +{ + int ret; + data_h key_data = NULL; + + LOG_BEGIN(); + + CHECK_SUPPORTED(NFC_TAG_FEATURE); + CHECK_INIT(); + CHECK_INVALID(tag == NULL); + CHECK_ACTIVATED(); + CHECK_APP_PERMISSION(); + + ret = net_nfc_create_data(&key_data, key, key_size); + if (ret == NET_NFC_OK) { + net_nfc_target_handle_h handle = NULL; + + ret = net_nfc_get_tag_handle((net_nfc_target_info_h)tag, + &handle); + if (ret == NET_NFC_OK) { + GVariant *parameter; + + parameter = g_variant_new("(uu)", + GPOINTER_TO_UINT(callback), + GPOINTER_TO_UINT(user_data)); + if (parameter != NULL) { + ret = net_nfc_client_ndef_format( + handle, + key_data, + _tag_format_ndef_cb, + parameter); + if (ret != NET_NFC_OK) { + g_variant_unref(parameter); + } + } else { + ret = NET_NFC_ALLOC_FAIL; + } + } else { + LOG_ERR("net_nfc_get_tag_handle failed, [%d]", ret); + } + + net_nfc_free_data(key_data); + } else { + LOG_ERR("net_nfc_create_data failed, [%d]", ret); + } + + return nfc_common_convert_error_code(__func__, ret); +} + +static void _tag_read_ndef_cb(net_nfc_error_e result, ndef_message_h message, + void *user_data) +{ + nfc_tag_read_completed_cb callback; + void *user_param; + + LOG_BEGIN(); + + if (user_data == NULL) { + LOG_ERR("user_data is NULL"); + return; + } + + g_variant_get((GVariant *)user_data, + "(uu)", + (guint *)&callback, + (guint *)&user_param); + + if (callback != NULL) { + callback(nfc_common_convert_error_code(__func__, result), + (nfc_ndef_message_h)message, + user_param); + } + + g_variant_unref((GVariant *)user_data); +} + +int nfc_tag_read_ndef(nfc_tag_h tag, + nfc_tag_read_completed_cb callback, + void * user_data) +{ + int ret; + net_nfc_target_handle_h handle = NULL; + + CHECK_SUPPORTED(NFC_TAG_FEATURE); + CHECK_INIT(); + CHECK_INVALID(tag == NULL); + CHECK_ACTIVATED(); + + ret = net_nfc_get_tag_handle((net_nfc_target_info_h)tag, &handle); + if (ret == NET_NFC_OK) { + GVariant *parameter; + + parameter = g_variant_new("(uu)", + GPOINTER_TO_UINT(callback), + GPOINTER_TO_UINT(user_data)); + if (parameter != NULL) { + ret = net_nfc_client_ndef_read( + handle, + _tag_read_ndef_cb, + parameter); + if (ret != NET_NFC_OK) { + g_variant_unref(parameter); + } + } else { + ret = NET_NFC_ALLOC_FAIL; + } + } else { + LOG_ERR("net_nfc_get_tag_handle failed, [%d]", ret); + } + + return nfc_common_convert_error_code(__func__, ret); +} + +static void _tag_write_ndef_cb(net_nfc_error_e result, + void *user_data) +{ + nfc_tag_write_completed_cb callback; + void *user_param; + + LOG_BEGIN(); + + if (user_data == NULL) { + LOG_ERR("user_data is NULL"); + return; + } + + g_variant_get((GVariant *)user_data, + "(uu)", + (guint *)&callback, + (guint *)&user_param); + + if (callback != NULL) { + callback(nfc_common_convert_error_code(__func__, result), user_param); + } + + g_variant_unref((GVariant *)user_data); +} + +int nfc_tag_write_ndef(nfc_tag_h tag, + nfc_ndef_message_h msg, + nfc_tag_write_completed_cb callback, + void *user_data) +{ + int ret; + net_nfc_target_handle_h handle = NULL; + unsigned int byte_size = 0; + uint32_t max_len = 0; + net_nfc_ndef_card_state_e state = NET_NFC_NDEF_CARD_INVALID; + + CHECK_SUPPORTED(NFC_TAG_FEATURE); + CHECK_INIT(); + CHECK_INVALID(tag == NULL); + CHECK_ACTIVATED(); + CHECK_APP_PERMISSION(); + + ret = net_nfc_get_tag_ndef_state((net_nfc_target_info_h)tag, &state); + if (ret != NET_NFC_OK) { + LOG_ERR("net_nfc_get_tag_ndef_state failed, [%d]", ret); + return nfc_common_convert_error_code(__func__, ret);; + } + + if (state == NET_NFC_NDEF_CARD_READ_ONLY) { + return NFC_ERROR_READ_ONLY_NDEF; + } + + ret = net_nfc_get_tag_max_data_size((net_nfc_target_info_h)tag, &max_len); + if (ret != NET_NFC_OK) { + LOG_ERR("net_nfc_get_tag_max_data_size failed, [%d]", ret); + return nfc_common_convert_error_code(__func__, ret);; + } + + ret = nfc_common_get_rawdata_size(msg, &byte_size); + if (ret != NFC_ERROR_NONE) { + LOG_ERR("nfc_ndef_message_get_rawdata_size failed, [%d]", ret); + return nfc_common_convert_error_code(__func__, ret);; + } + + if (max_len < byte_size) { + return NFC_ERROR_NO_SPACE_ON_NDEF; + } + + ret = net_nfc_get_tag_handle((net_nfc_target_info_h)tag, &handle); + if (ret == NET_NFC_OK) { + GVariant *parameter; + + parameter = g_variant_new("(uu)", + GPOINTER_TO_UINT(callback), + GPOINTER_TO_UINT(user_data)); + if (parameter != NULL) { + ret = net_nfc_client_ndef_write( + handle, + msg, + _tag_write_ndef_cb, + parameter); + if (ret != NET_NFC_OK) { + g_variant_unref(parameter); + } + } else { + ret = NET_NFC_ALLOC_FAIL; + } + } else { + LOG_ERR("net_nfc_get_tag_handle failed, [%d]", ret); + } + + return nfc_common_convert_error_code(__func__, ret); +} + +static void _tag_transceive_data_cb(net_nfc_error_e result, data_h arg_data, + void *user_data) +{ + nfc_tag_transceive_completed_cb callback; + void *user_param; + + LOG_BEGIN(); + + if (user_data == NULL) { + return; + } + + g_variant_get((GVariant *)user_data, + "(uu)", + (guint *)&callback, + (guint *)&user_param); + + if (callback != NULL) { + uint8_t *buffer = NULL; + uint32_t length = 0; + + if (result == NET_NFC_OK && arg_data != NULL) { + buffer = net_nfc_get_data_buffer(arg_data); + length = net_nfc_get_data_length(arg_data); + } + + callback(nfc_common_convert_error_code(__func__, result), + buffer, + length, + user_param); + } + + g_variant_unref((GVariant *)user_data); +} + +int nfc_tag_transceive(nfc_tag_h tag, + unsigned char *buffer, + int buffer_size, + nfc_tag_transceive_completed_cb callback, + void *user_data) +{ + int ret; + data_h rawdata = NULL; + + CHECK_SUPPORTED(NFC_TAG_FEATURE); + CHECK_INIT(); + CHECK_INVALID(tag == NULL); + CHECK_INVALID(buffer == NULL); + CHECK_INVALID(buffer_size <= 0); + CHECK_ACTIVATED(); + CHECK_APP_PERMISSION(); + + ret = net_nfc_create_data(&rawdata, buffer, buffer_size); + if (ret == NET_NFC_OK) { + net_nfc_target_handle_h handle = NULL; + + ret = net_nfc_get_tag_handle((net_nfc_target_info_h)tag, &handle); + if (ret == NET_NFC_OK) { + GVariant *parameter; + + parameter = g_variant_new("(uu)", + GPOINTER_TO_UINT(callback), + GPOINTER_TO_UINT(user_data)); + if (parameter != NULL) { + ret = net_nfc_client_transceive_data( + handle, + rawdata, + _tag_transceive_data_cb, + parameter); + if (ret != NET_NFC_OK) { + g_variant_unref(parameter); + } + } else { + ret = NET_NFC_ALLOC_FAIL; + } + } else { + LOG_ERR("net_nfc_get_tag_handle failed, [%d]", ret); + } + + net_nfc_free_data(rawdata); + } else { + LOG_ERR("net_nfc_create_data failed, [%d]", ret); + } + + return nfc_common_convert_error_code(__func__, ret); +} + +int nfc_tag_get_type(nfc_tag_h tag, nfc_tag_type_e *type) +{ + int ret; + + LOG_BEGIN(); + + CHECK_SUPPORTED(NFC_TAG_FEATURE); + CHECK_INIT(); + CHECK_INVALID(tag == NULL); + CHECK_INVALID(type == NULL); + + ret = net_nfc_get_tag_type(tag, (net_nfc_target_type_e *)type); + + return nfc_common_convert_error_code(__func__, ret); +} + +int nfc_tag_is_support_ndef(nfc_tag_h tag, bool *is_support) +{ + int ret; + + LOG_BEGIN(); + + CHECK_SUPPORTED(NFC_TAG_FEATURE); + CHECK_INIT(); + CHECK_INVALID(tag == NULL); + CHECK_INVALID(is_support == NULL); + + ret = net_nfc_get_tag_ndef_support(tag, is_support); + + return nfc_common_convert_error_code(__func__, ret); +} + +int nfc_tag_get_maximum_ndef_size(nfc_tag_h tag, unsigned int *max_size) +{ + int ret; + + LOG_BEGIN(); + CHECK_SUPPORTED(NFC_TAG_FEATURE); + CHECK_INIT(); + CHECK_INVALID(tag == NULL); + CHECK_INVALID(max_size == NULL); + + ret = net_nfc_get_tag_max_data_size(tag, max_size); + + return nfc_common_convert_error_code(__func__, ret); +} + +int nfc_tag_get_ndef_size(nfc_tag_h tag, unsigned int *actual_data_size) +{ + int ret; + + LOG_BEGIN(); + + CHECK_SUPPORTED(NFC_TAG_FEATURE); + CHECK_INIT(); + CHECK_INVALID(tag == NULL); + CHECK_INVALID(actual_data_size == NULL); + + ret = net_nfc_get_tag_actual_data_size(tag, actual_data_size); + + return nfc_common_convert_error_code(__func__, ret); +} + +int nfc_tag_foreach_information(nfc_tag_h tag, + nfc_tag_information_cb callback, + void *user_data) +{ + int ret; + int i, count = 0; + char **keys = NULL; + data_h value = NULL; + + bool cont; + + LOG_BEGIN(); + CHECK_SUPPORTED(NFC_TAG_FEATURE); + CHECK_INIT(); + CHECK_INVALID(tag == NULL); + CHECK_INVALID(callback == NULL); + + ret = net_nfc_get_tag_info_keys((net_nfc_target_info_h)tag, + &keys, &count); + + if(ret != NET_NFC_OK) + return nfc_common_convert_error_code(__func__, ret); + + for (i = 0; i < count; i++) { + net_nfc_get_tag_info_value((net_nfc_target_info_h)tag, keys[i], + &value); + + cont = callback(keys[i], + net_nfc_get_data_buffer(value), + net_nfc_get_data_length(value), + user_data); + + if (!cont) + break; + } + + return NFC_ERROR_NONE; +} + +/* FIXME */ +static void _mifare_authenticate_with_keyA_cb(net_nfc_error_e result, + void *user_data) +{ + nfc_mifare_authenticate_with_keyA_completed_cb callback; + void *user_param; + + LOG_BEGIN(); + + if (user_data == NULL) { + LOG_ERR("user_data is NULL"); + return; + } + + g_variant_get((GVariant *)user_data, + "(uu)", + (guint *)&callback, + (guint *)&user_param); + + if (callback != NULL) { + callback(nfc_common_convert_error_code(__func__, result), user_param); + } + + g_variant_unref((GVariant *)user_data); +} + +int nfc_mifare_authenticate_with_keyA(nfc_tag_h tag, + int sector_index, + unsigned char *auth_key, + nfc_mifare_authenticate_with_keyA_completed_cb callback, + void *user_data) +{ + int ret; + data_h auth_key_data = NULL; + + CHECK_SUPPORTED(NFC_TAG_FEATURE); + CHECK_INIT(); + CHECK_INVALID(tag == NULL); + CHECK_INVALID(auth_key == NULL); + CHECK_ACTIVATED(); + + ret = net_nfc_create_data(&auth_key_data, auth_key, 6); + if (ret == NET_NFC_OK) { + net_nfc_target_handle_h handle = NULL; + + ret = net_nfc_get_tag_handle((net_nfc_target_info_h)tag, &handle); + if (ret == NET_NFC_OK) { + GVariant *parameter; + + parameter = g_variant_new("(uu)", + GPOINTER_TO_UINT(callback), + GPOINTER_TO_UINT(user_data)); + if (parameter != NULL) { + ret = net_nfc_client_mifare_authenticate_with_keyA( + handle, + sector_index, + auth_key_data, + _mifare_authenticate_with_keyA_cb, + parameter); + if (ret != NET_NFC_OK) { + g_variant_unref(parameter); + } + } else { + ret = NET_NFC_ALLOC_FAIL; + } + } else { + LOG_ERR("net_nfc_get_tag_handle failed, [%d]", ret); + } + + net_nfc_free_data(auth_key_data); + } else { + LOG_ERR("net_nfc_create_data failed, [%d]", ret); + } + + return nfc_common_convert_error_code(__func__, ret); +} + + +static void _mifare_authenticate_with_keyB_cb(net_nfc_error_e result, + void *user_data) +{ + nfc_mifare_authenticate_with_keyB_completed_cb callback; + void *user_param; + + if (user_data == NULL) { + LOG_ERR("user_data is NULL"); + return; + } + + g_variant_get((GVariant *)user_data, + "(uu)", + (guint *)&callback, + (guint *)&user_param); + + if (callback != NULL) { + callback(nfc_common_convert_error_code(__func__, result), user_param); + } + + g_variant_unref((GVariant *)user_data); +} + +int nfc_mifare_authenticate_with_keyB(nfc_tag_h tag, + int sector_index, + unsigned char *auth_key, + nfc_mifare_authenticate_with_keyB_completed_cb callback, + void *user_data) +{ + int ret; + data_h auth_key_data = NULL; + + LOG_BEGIN(); + + CHECK_SUPPORTED(NFC_TAG_FEATURE); + CHECK_INIT(); + CHECK_INVALID(tag == NULL); + CHECK_INVALID(auth_key == NULL); + CHECK_ACTIVATED(); + + ret = net_nfc_create_data(&auth_key_data, auth_key, 6); + if (ret == NET_NFC_OK) { + net_nfc_target_handle_h handle = NULL; + + ret = net_nfc_get_tag_handle((net_nfc_target_info_h)tag, &handle); + if (ret == NET_NFC_OK) { + GVariant *parameter; + + parameter = g_variant_new("(uu)", + GPOINTER_TO_UINT(callback), + GPOINTER_TO_UINT(user_data)); + if (parameter != NULL) { + ret = net_nfc_client_mifare_authenticate_with_keyB( + handle, + sector_index, + auth_key_data, + _mifare_authenticate_with_keyB_cb, + parameter); + if (ret != NET_NFC_OK) { + g_variant_unref(parameter); + } + } else { + ret = NET_NFC_ALLOC_FAIL; + } + } else { + LOG_ERR("net_nfc_get_tag_handle failed, [%d]", ret); + } + + net_nfc_free_data(auth_key_data); + } else { + LOG_ERR("net_nfc_create_data failed, [%d]", ret); + } + + return nfc_common_convert_error_code(__func__, ret); +} + +/* FIXME */ +static void _mifare_read_block_cb(net_nfc_error_e result, data_h data, + void *user_data) +{ + nfc_mifare_read_block_completed_cb callback; + void *user_param; + + if (user_data == NULL) { + LOG_ERR("user_data is NULL"); + return; + } + + g_variant_get((GVariant *)user_data, + "(uu)", + (guint *)&callback, + (guint *)&user_param); + + if (callback != NULL) { + uint8_t *buffer = NULL; + int length = 0; + + if (result == NET_NFC_OK && data != NULL) { + buffer = net_nfc_get_data_buffer(data); + length = net_nfc_get_data_length(data); + } + + callback(nfc_common_convert_error_code(__func__, result), + buffer, + length, + user_param); + } + + g_variant_unref((GVariant *)user_data); +} + +int nfc_mifare_read_block(nfc_tag_h tag, + int block_index, + nfc_mifare_read_block_completed_cb callback, + void *user_data) +{ + int ret; + net_nfc_target_handle_h handle = NULL; + + LOG_BEGIN(); + + CHECK_SUPPORTED(NFC_TAG_FEATURE); + CHECK_INIT(); + CHECK_INVALID(tag == NULL); + + ret = net_nfc_get_tag_handle((net_nfc_target_info_h)tag, &handle); + if (ret == NET_NFC_OK) { + GVariant *parameter; + + parameter = g_variant_new("(uu)", + GPOINTER_TO_UINT(callback), + GPOINTER_TO_UINT(user_data)); + if (parameter != NULL) { + ret = net_nfc_client_mifare_read( + handle, + block_index, + _mifare_read_block_cb, + parameter); + if (ret != NET_NFC_OK) { + g_variant_unref(parameter); + } + } else { + ret = NET_NFC_ALLOC_FAIL; + } + } else { + LOG_ERR("net_nfc_get_tag_handle failed, [%d]", ret); + } + + return nfc_common_convert_error_code(__func__, ret); +} + +int nfc_mifare_read_page(nfc_tag_h tag, + int page_index, + nfc_mifare_read_page_completed_cb callback, + void *user_data) +{ + int ret; + GVariant *parameter; + + LOG_BEGIN(); + + CHECK_SUPPORTED(NFC_TAG_FEATURE); + CHECK_INIT(); + CHECK_INVALID(tag == NULL); + + parameter = g_variant_new("(uu)", + GPOINTER_TO_UINT(callback), + GPOINTER_TO_UINT(user_data)); + if (parameter != NULL) { + /* FIXME : not implemented */ +// ret = net_nfc_client_mifare_read_block(tag, +// page_index, +// _mifare_read_page_cb, +// parameter); +// if (ret != NET_NFC_OK) { + g_variant_unref(parameter); + ret = NET_NFC_OK; +// } + } else { + ret = NET_NFC_ALLOC_FAIL; + } + + return nfc_common_convert_error_code(__func__, ret); +} + +static void _mifare_write_block_cb(net_nfc_error_e result, void *user_data) +{ + nfc_mifare_write_block_completed_cb callback; + void *user_param; + + LOG_BEGIN(); + + if (user_data == NULL) { + LOG_ERR("user_data is NULL"); + return; + } + + g_variant_get((GVariant *)user_data, + "(uu)", + (guint *)&callback, + (guint *)&user_param); + + if (callback != NULL) { + callback(nfc_common_convert_error_code(__func__, result), user_param); + } + + g_variant_unref((GVariant *)user_data); +} + +int nfc_mifare_write_block(nfc_tag_h tag, + int block_index, + unsigned char *buffer, + int buffer_size, + nfc_mifare_write_block_completed_cb callback, + void *user_data) +{ + int ret; + data_h block_data = NULL; + + LOG_BEGIN(); + + CHECK_SUPPORTED(NFC_TAG_FEATURE); + CHECK_INIT(); + CHECK_INVALID(tag == NULL); + CHECK_INVALID(buffer == NULL); + CHECK_INVALID(buffer_size <= 0); + CHECK_ACTIVATED(); + + ret = net_nfc_create_data(&block_data, buffer, buffer_size); + if (ret == NET_NFC_OK) { + net_nfc_target_handle_h handle = NULL; + + ret = net_nfc_get_tag_handle((net_nfc_target_info_h)tag, + &handle); + if (ret == NET_NFC_OK) { + GVariant *parameter; + + parameter = g_variant_new("(uu)", + GPOINTER_TO_UINT(callback), + GPOINTER_TO_UINT(user_data)); + if (parameter != NULL) { + ret = net_nfc_client_mifare_write_block( + handle, + block_index, + block_data, + _mifare_write_block_cb, + parameter); + if (ret != NET_NFC_OK) { + g_variant_unref(parameter); + } + } else { + ret = NET_NFC_ALLOC_FAIL; + } + } else { + LOG_ERR("net_nfc_get_tag_handle failed, [%d]", ret); + } + + net_nfc_free_data(block_data); + } else { + LOG_ERR("net_nfc_create_data failed, [%d]", ret); + } + + return nfc_common_convert_error_code(__func__, ret); +} + +static void _mifare_write_page_cb(net_nfc_error_e result, void *user_data) +{ + nfc_mifare_write_page_completed_cb callback; + void *user_param; + + LOG_BEGIN(); + + if (user_data == NULL) { + LOG_ERR("user_data is NULL"); + return; + } + + g_variant_get((GVariant *)user_data, + "(uu)", + (guint *)&callback, + (guint *)&user_param); + + if (callback != NULL) { + callback(nfc_common_convert_error_code(__func__, result), user_param); + } + + g_variant_unref((GVariant *)user_data); +} + +int nfc_mifare_write_page(nfc_tag_h tag, + int page_index, + unsigned char *buffer, + int buffer_size, + nfc_mifare_write_page_completed_cb callback, + void *user_data) +{ + int ret; + data_h block_data = NULL; + + LOG_BEGIN(); + CHECK_SUPPORTED(NFC_TAG_FEATURE); + CHECK_INIT(); + CHECK_INVALID(tag == NULL); + CHECK_INVALID(buffer == NULL); + CHECK_INVALID(buffer_size <= 0); + CHECK_ACTIVATED(); + + ret = net_nfc_create_data(&block_data, buffer, buffer_size); + if (ret == NET_NFC_OK) { + net_nfc_target_handle_h handle = NULL; + + ret = net_nfc_get_tag_handle((net_nfc_target_info_h)tag, + &handle); + if (ret == NET_NFC_OK) { + GVariant *parameter; + + parameter = g_variant_new("(uu)", + GPOINTER_TO_UINT(callback), + GPOINTER_TO_UINT(user_data)); + if (parameter != NULL) { + ret = net_nfc_client_mifare_write_page( + handle, + page_index, + block_data, + _mifare_write_page_cb, + parameter); + if (ret != NET_NFC_OK) { + g_variant_unref(parameter); + } + } else { + ret = NET_NFC_ALLOC_FAIL; + } + } else { + LOG_ERR("net_nfc_get_tag_handle failed, [%d]", ret); + } + + net_nfc_free_data(block_data); + } else { + LOG_ERR("net_nfc_create_data failed, [%d]", ret); + } + + return nfc_common_convert_error_code(__func__, ret); +} + +static void _mifare_increment_cb(net_nfc_error_e result, void *user_data) +{ + nfc_mifare_increment_completed_cb callback; + void *user_param; + + LOG_BEGIN(); + + if (user_data == NULL) { + LOG_ERR("user_data is NULL"); + return; + } + + g_variant_get((GVariant *)user_data, + "(uu)", + (guint *)&callback, + (guint *)&user_param); + + if (callback != NULL) { + callback(nfc_common_convert_error_code(__func__, result), user_param); + } + + g_variant_unref((GVariant *)user_data); +} + +int nfc_mifare_increment(nfc_tag_h tag, + int block_index, + int value, + nfc_mifare_increment_completed_cb callback, + void *user_data) +{ + int ret; + net_nfc_target_handle_h handle = NULL; + + LOG_BEGIN(); + + CHECK_SUPPORTED(NFC_TAG_FEATURE); + CHECK_INIT(); + CHECK_INVALID(tag == NULL); + CHECK_ACTIVATED(); + + ret = net_nfc_get_tag_handle((net_nfc_target_info_h)tag, &handle); + if (ret == NET_NFC_OK) { + GVariant *parameter; + + parameter = g_variant_new("(uu)", + GPOINTER_TO_UINT(callback), + GPOINTER_TO_UINT(user_data)); + if (parameter != NULL) { + ret = net_nfc_client_mifare_increment( + handle, + block_index, + value, + _mifare_increment_cb, + parameter); + if (ret != NET_NFC_OK) { + g_variant_unref(parameter); + } + } else { + ret = NET_NFC_ALLOC_FAIL; + } + } else { + LOG_ERR("net_nfc_get_tag_handle failed, [%d]", ret); + } + + return nfc_common_convert_error_code(__func__, ret); +} + +static void _mifare_decrement_cb(net_nfc_error_e result, void *user_data) +{ + nfc_mifare_decrement_completed_cb callback; + void *user_param; + + LOG_BEGIN(); + + if (user_data == NULL) { + LOG_ERR("user_data is NULL"); + return; + } + + g_variant_get((GVariant *)user_data, + "(uu)", + (guint *)&callback, + (guint *)&user_param); + + if (callback != NULL) { + callback(nfc_common_convert_error_code(__func__, result), user_param); + } + + g_variant_unref((GVariant *)user_data); +} + +int nfc_mifare_decrement(nfc_tag_h tag, + int block_index, + int value, + nfc_mifare_decrement_completed_cb callback, + void *user_data) +{ + int ret; + net_nfc_target_handle_h handle = NULL; + + LOG_BEGIN(); + + CHECK_SUPPORTED(NFC_TAG_FEATURE); + CHECK_INIT(); + CHECK_INVALID(tag == NULL); + CHECK_ACTIVATED(); + + ret = net_nfc_get_tag_handle((net_nfc_target_info_h)tag, &handle); + if (ret == NET_NFC_OK) { + GVariant *parameter; + + parameter = g_variant_new("(uu)", + GPOINTER_TO_UINT(callback), + GPOINTER_TO_UINT(user_data)); + if (parameter != NULL) { + ret = net_nfc_client_mifare_decrement( + handle, + block_index, + value, + _mifare_decrement_cb, + parameter); + if (ret != NET_NFC_OK) { + g_variant_unref(parameter); + } + } else { + ret = NET_NFC_ALLOC_FAIL; + } + } else { + LOG_ERR("net_nfc_get_tag_handle failed, [%d]", ret); + } + + return nfc_common_convert_error_code(__func__, ret); +} + +static void _mifare_transfer_cb(net_nfc_error_e result, void *user_data) +{ + nfc_mifare_transfer_completed_cb callback; + void *user_param; + + LOG_BEGIN(); + + if (user_data == NULL) { + LOG_ERR("user_data is NULL"); + return; + } + + g_variant_get((GVariant *)user_data, + "(uu)", + (guint *)&callback, + (guint *)&user_param); + + if (callback != NULL) { + callback(nfc_common_convert_error_code(__func__, result), user_param); + } + + g_variant_unref((GVariant *)user_data); +} + +int nfc_mifare_transfer(nfc_tag_h tag, + int block_index, + nfc_mifare_transfer_completed_cb callback, + void *user_data) +{ + int ret; + net_nfc_target_handle_h handle = NULL; + + LOG_BEGIN(); + + CHECK_SUPPORTED(NFC_TAG_FEATURE); + CHECK_INIT(); + CHECK_INVALID(tag == NULL); + CHECK_ACTIVATED(); + + ret = net_nfc_get_tag_handle((net_nfc_target_info_h)tag, &handle); + if (ret == NET_NFC_OK) { + GVariant *parameter; + + parameter = g_variant_new("(uu)", + GPOINTER_TO_UINT(callback), + GPOINTER_TO_UINT(user_data)); + if (parameter != NULL) { + ret = net_nfc_client_mifare_transfer( + handle, + block_index, + _mifare_transfer_cb, + parameter); + if (ret != NET_NFC_OK) { + g_variant_unref(parameter); + } + } else { + ret = NET_NFC_ALLOC_FAIL; + } + } else { + LOG_ERR("net_nfc_get_tag_handle failed, [%d]", ret); + } + + return nfc_common_convert_error_code(__func__, ret); +} + +static void _mifare_restore_cb(net_nfc_error_e result, void *user_data) +{ + nfc_mifare_restore_completed_cb callback; + void *user_param; + + LOG_BEGIN(); + + if (user_data == NULL) { + LOG_ERR("user_data is NULL"); + return; + } + + g_variant_get((GVariant *)user_data, + "(uu)", + (guint *)&callback, + (guint *)&user_param); + + if (callback != NULL) { + callback(nfc_common_convert_error_code(__func__, result), user_param); + } + + g_variant_unref((GVariant *)user_data); +} + +int nfc_mifare_restore(nfc_tag_h tag, + int block_index, + nfc_mifare_restore_completed_cb callback, + void *user_data) +{ + int ret; + net_nfc_target_handle_h handle = NULL; + + LOG_BEGIN(); + + CHECK_SUPPORTED(NFC_TAG_FEATURE); + CHECK_INIT(); + CHECK_INVALID(tag == NULL); + CHECK_ACTIVATED(); + + ret = net_nfc_get_tag_handle((net_nfc_target_info_h)tag, &handle); + if (ret == NET_NFC_OK) { + GVariant *parameter; + + parameter = g_variant_new("(uu)", + GPOINTER_TO_UINT(callback), + GPOINTER_TO_UINT(user_data)); + if (parameter != NULL) { + ret = net_nfc_client_mifare_restore( + handle, + block_index, + _mifare_restore_cb, + parameter); + if (ret != NET_NFC_OK) { + g_variant_unref(parameter); + } + } else { + ret = NET_NFC_ALLOC_FAIL; + } + } else { + LOG_ERR("net_nfc_get_tag_handle failed, [%d]", ret); + } + + return nfc_common_convert_error_code(__func__, ret); +} + +int nfc_barcode_get_barcode(unsigned char **barcode, int *barcode_len) +{ + int ret; + + LOG_BEGIN(); + + CHECK_SUPPORTED(NFC_TAG_FEATURE); + CHECK_INIT(); + CHECK_INVALID(barcode == NULL); + CHECK_INVALID(barcode_len == NULL); + + *barcode_len = 0; + + ret = net_nfc_client_barcode_get_barcode_sync(barcode, barcode_len); + + return nfc_common_convert_error_code(__func__, ret); +} diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 20a03af..474d37d 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,7 +1,7 @@ SET(fw_test "${fw_name}-test") INCLUDE(FindPkgConfig) -pkg_check_modules(${fw_test} REQUIRED nfc-common-lib nfc dlog elementary evas ecore) +pkg_check_modules(${fw_test} REQUIRED dlog glib-2.0) FOREACH(flag ${${fw_test}_CFLAGS}) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") MESSAGE(${flag}) @@ -9,9 +9,6 @@ ENDFOREACH() SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -Wall") -#ADD_EXECUTABLE("system-sensor" system-sensor.c) -#TARGET_LINK_LIBRARIES("system-sensor" ${fw_name} ${${fw_test}_LDFLAGS}) - aux_source_directory(. sources) FOREACH(src ${sources}) GET_FILENAME_COMPONENT(src_name ${src} NAME_WE) diff --git a/test/network_nfc_test.c b/test/network_nfc_test.c deleted file mode 100644 index f5da0ac..0000000 --- a/test/network_nfc_test.c +++ /dev/null @@ -1,656 +0,0 @@ -/* -* Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; -pthread_mutex_t mutex2 = PTHREAD_MUTEX_INITIALIZER; - -int is_terminate = 0; -int timeout_counter; -int success; - - -Eina_Bool timeout_handler(void *data){ - if( timeout_counter == 0 ){ - is_terminate = 1; - printf("Fail, timeout!\n"); - return 0; - } - timeout_counter--; - - if( success ) - return 0; - - return 1; -} - -int print_result(const char * func, int error ) -{ - printf("%s ret = %x\n", func , error); - if( error != 0 ) - return -1; - return 0; -} - -char *byteToString(unsigned char* buffer, int size){ - static char localbuffer[255]; - memset(localbuffer, 0, 255); - memcpy(localbuffer, buffer, size); - return localbuffer; -} - -void print_ndef_message(nfc_ndef_message_h message){ - char *tnf_tbl[] = { - "NFC_RECORD_TNF_EMPTY", - "NFC_RECORD_TNF_WELL_KNOWN", - "NFC_RECORD_TNF_MIME_MEDIA", - "NFC_RECORD_TNF_URI", - "NFC_RECORD_TNF_EXTERNAL_RTD", - "NFC_RECORD_TNF_UNKNOWN", - "NFC_RECORD_TNF_UNCHAGNED" - }; - nfc_record_tnf_e tnf; - unsigned char *type; - int type_size; - unsigned char *payload; - uint32_t payload_size; - nfc_ndef_record_h record; - int ret; - - ret = nfc_ndef_message_get_record(message, 0 , &record); - if( ret != 0 ){ - printf("can't found NDEF Record\n"); - return; - } - - - nfc_ndef_record_get_tnf(record, &tnf); - nfc_ndef_record_get_type(record, &type, &type_size); - nfc_ndef_record_get_payload(record, &payload, &payload_size); - - printf("tnf \t: %s\n", tnf_tbl[tnf]); - printf("type \t: %s\n", byteToString(type, type_size)); - printf("payload : %s\n", byteToString(payload, payload_size) ); - - if( tnf == NFC_RECORD_TNF_WELL_KNOWN && type[0] == 'U' ){ - char *uri; - nfc_ndef_record_get_uri(record, &uri); - printf("uri \t: %s\n", uri); - free(uri); - } - - if( tnf == NFC_RECORD_TNF_WELL_KNOWN && type[0] == 'T' ){ - char *text; - nfc_ndef_record_get_text(record, &text); - printf("text \t: %s\n", text); - free(text); - nfc_ndef_record_get_langcode(record , &text); - printf("langcode : %s\n", text); - free(text); - } - -} - - -void ndef_record_create_test(nfc_error_e error, void *user_data){ - int ret=0; - char *tnf_tbl[] = { - "NFC_RECORD_TNF_EMPTY", - "NFC_RECORD_TNF_WELL_KNOWN", - "NFC_RECORD_TNF_MIME_MEDIA", - "NFC_RECORD_TNF_URI", - "NFC_RECORD_TNF_EXTERNAL_RTD", - "NFC_RECORD_TNF_UNKNOWN", - "NFC_RECORD_TNF_UNCHAGNED" - }; - nfc_ndef_record_h record1; - nfc_record_tnf_e tnf; - unsigned char *type; - int type_size; - unsigned char *id; - int id_size; - unsigned char *payload; - unsigned int payload_size; - - char *strp = NULL; - char *strp2 = NULL; - - - printf("---------------------------------------------------\n"); - printf(" NEF Record Create Test\n"); - - ret = nfc_ndef_record_create(&record1, NFC_RECORD_TNF_WELL_KNOWN, NFC_RECORD_SMART_POSTER_TYPE, sizeof(NFC_RECORD_SMART_POSTER_TYPE), (unsigned char*)"id", strlen("id"), (unsigned char*)"testpayload", strlen("testpayload")); - print_result("nfc_ndef_record_create" , ret); - - nfc_ndef_record_get_tnf(record1, &tnf); - nfc_ndef_record_get_type(record1, &type, &type_size); - nfc_ndef_record_get_id(record1, &id, &id_size); - nfc_ndef_record_get_payload(record1, &payload, &payload_size); - - printf("tnf \t: %s\n", tnf_tbl[tnf]); - printf("type \t: %s\n", byteToString(type, type_size)); - printf("id \t: %s\n" , byteToString(id, id_size) ); - printf("payload : %s\n", byteToString(payload, payload_size) ); - - nfc_ndef_record_destroy(record1); - - printf("\n"); - - strp = NULL; - ret = nfc_ndef_record_create_mime(&record1, "text/plain", (unsigned char*)"the text record", sizeof("the text record")); - print_result("nfc_ndef_record_create_mime" , ret); - - nfc_ndef_record_get_tnf(record1, &tnf); - nfc_ndef_record_get_mime_type(record1 , &strp); - nfc_ndef_record_get_type(record1, &type, &type_size); - nfc_ndef_record_get_payload(record1, &payload, &payload_size); - - printf("tnf \t: %s\n", tnf_tbl[tnf]); - printf("mimetype: %s\n", strp); - printf("type \t: %s\n", byteToString(type, type_size)); - printf("payload : %s\n", byteToString(payload, payload_size) ); - - - nfc_ndef_record_destroy(record1); - free(strp); - - printf("\n"); - - ret = nfc_ndef_record_create_text(&record1, "the text record", "us-en", NFC_ENCODE_UTF_8); - print_result("nfc_ndef_record_create_text" , ret); - - nfc_ndef_record_get_tnf(record1, &tnf); - nfc_ndef_record_get_type(record1, &type, &type_size); - nfc_ndef_record_get_payload(record1, &payload, &payload_size); - nfc_ndef_record_get_text(record1, &strp); - nfc_ndef_record_get_langcode(record1, &strp2); - - printf("tnf \t: %s\n", tnf_tbl[tnf]); - printf("type \t: %s\n", byteToString(type, type_size)); - printf("payload : %s\n", byteToString(payload, payload_size) ); - printf("text \t: %s\n", strp); - printf("langcode: %s\n", strp2); - nfc_ndef_record_destroy(record1); - free(strp); - free(strp2); - - printf("\n"); - - ret = nfc_ndef_record_create_uri(&record1,"http://samsung.com"); - print_result("nfc_ndef_record_create_uri" , ret); - - - nfc_ndef_record_get_tnf(record1, &tnf); - nfc_ndef_record_get_type(record1, &type, &type_size); - nfc_ndef_record_get_payload(record1, &payload, &payload_size); - nfc_ndef_record_get_uri(record1, &strp); - - printf("tnf \t: %s\n", tnf_tbl[tnf]); - printf("type \t: %s\n", byteToString(type, type_size)); - printf("payload : %s\n", byteToString(payload, payload_size) ); - printf("uri \t: %s\n", strp); - - nfc_ndef_record_destroy(record1); - free(strp); - - printf("\n"); - - - ret = nfc_ndef_record_create_uri(&record1,"http://samsung.com"); - print_result("nfc_ndef_record_create_uri" , ret); - - ret = nfc_ndef_record_get_mime_type(record1, &strp); - print_result("nfc_ndef_record_get_mime_type" , ret); - ret = nfc_ndef_record_get_text(record1,&strp); - print_result("nfc_ndef_record_get_text" , ret); - ret = nfc_ndef_record_get_langcode(record1,&strp); - print_result("nfc_ndef_record_get_langcode" , ret); - ret = nfc_ndef_record_get_uri(record1,&strp); - print_result("nfc_ndef_record_get_uri" , ret); - free(strp); - - nfc_ndef_record_destroy(record1); - - printf("---------------------------------------------------\n"); - printf("\n"); - is_terminate = 1; - return ; - -} - - - -void _ndef_discovered_cb(nfc_ndef_message_h message, void * user_data){ - printf("Discovered NDEF Message!\n"); - print_ndef_message(message); - success = 1; - is_terminate = 1; -} - -void read_ndef_from_tag_using_ndef_discovered(nfc_error_e error, void *user_data){ - int ret; - - success = 0; - timeout_counter = 30; - - ret = nfc_manager_set_ndef_discovered_cb(_ndef_discovered_cb , NULL); - print_result("nfc_manager_set_ndef_discovered_cb", ret); - printf("Now, Bring the tag closer.\n"); - ecore_timer_add(1, timeout_handler, NULL); - -} - -void _write_completed_cb(nfc_error_e result , void * user_data){ - - printf("write completed!result %s\n" , result == 0 ? "Success": "Fail"); - success = 1; - is_terminate = 1; -} - - -void _tag_discovered_cb(nfc_discovered_type_e type, nfc_tag_h tag, void * user_data){ - if( type == NFC_DISCOVERED_TYPE_ATTACHED ){ - - printf("Discovered Tag!\n"); - //write NDEF Message - nfc_ndef_record_h record; - nfc_ndef_message_h message; - nfc_ndef_record_create_uri(&record, "http://samsung.com"); - nfc_ndef_message_create(&message); - nfc_ndef_message_append_record(message, record); - printf("Write request!\n"); - timeout_counter = 30; - nfc_tag_write_ndef(tag, message , _write_completed_cb , NULL); - nfc_ndef_message_destroy(message); - } -} - - -void write_ndef_to_tag(nfc_error_e error, void *user_data){ - - nfc_tag_h tag; - int ret ; - - printf("write_ndef_to_tag\n"); - ret = nfc_manager_get_connected_tag(&tag); - printf("nfc_manager_get_connected_tag ret(0x%08x) !\n",ret); - - - if ( ret == NFC_ERROR_NONE) - { - printf("tag alread attached !\n"); - //write NDEF Message - nfc_ndef_record_h record; - nfc_ndef_message_h message; - nfc_ndef_record_create_uri(&record, "http://samsung.com"); - nfc_ndef_message_create(&message); - nfc_ndef_message_append_record(message, record); - printf("Write request!\n"); - timeout_counter = 30; - nfc_tag_write_ndef(tag, message , _write_completed_cb , NULL); - nfc_ndef_message_destroy(message); - } - else - { - - int ret; - - success = 0; - timeout_counter = 30; - - ret = nfc_manager_set_tag_discovered_cb( _tag_discovered_cb , NULL); - print_result("nfc_manager_set_tag_discovered_cb", ret); - - printf("Now, Bring the tag closer. Will be writen a new NDEF Message\n"); - ecore_timer_add(1, timeout_handler, NULL); - - } -} - - -void _send_completed_cb(nfc_error_e result , void *user_data){ - printf("send completed!result %s\n" , result == 0 ? "Success": "Fail"); - success = 1; - is_terminate = 1; -} - - - -void _handover_completed_cb(nfc_error_e result, nfc_ac_type_e carrior, void * ac_data, int ac_data_size , void *user_data){ - - char * address =(char *) (strdup(ac_data)); - - printf("handover completed!result %d AC type is [%d] \n" , result,carrior); - printf("address [%s] address size[%d]\n" , address, ac_data_size); - - free(address); - success = 1; - is_terminate = 1; -} - -Eina_Bool send_test(void *data){ - - nfc_p2p_target_h target = (nfc_p2p_target_h)data; - nfc_ndef_message_h message; - nfc_ndef_record_h record; - - nfc_ndef_record_create_uri(&record, "http://samsung.com"); - nfc_ndef_message_create(&message); - nfc_ndef_message_append_record(message, record); - printf("Send Request!\n"); - timeout_counter =30; - nfc_p2p_send(target, message , _send_completed_cb, NULL); - nfc_ndef_message_destroy(message); - return 0; -} - - -Eina_Bool handover_test(void *data){ - - nfc_p2p_target_h target = (nfc_p2p_target_h)data; - nfc_ac_type_e type = NFC_AC_TYPE_BT; - - if(nfc_p2p_is_supported_ac_type(type)) - printf("NFC_AC_TYPE_BT supported\n"); - - nfc_p2p_connection_handover(target, type , _handover_completed_cb, NULL); - - return 0; -} - -void _target_discovered_cb(nfc_discovered_type_e type, nfc_p2p_target_h target, void * user_data){ - if( type == NFC_DISCOVERED_TYPE_ATTACHED){ - printf("Discovered new target!\n"); - ecore_idler_add(send_test, target); - } -} - -void _target_discovered_for_connect_handover_cb(nfc_discovered_type_e type, nfc_p2p_target_h target, void * user_data){ - if( type == NFC_DISCOVERED_TYPE_ATTACHED){ - printf("Discovered new target!\n"); - ecore_idler_add(handover_test, target); - } -} -void _card_emulation_changed_cb(nfc_se_event_e event , void *user_data){ - if(NFC_SE_EVENT_SE_CARD_EMULATION_CHANGED == event) - { - printf("CARD_EMULATION_CHANGED arrived!!!!\n"); - } -} - -void send_ndef_to_peer(nfc_error_e error, void *user_data){ - - nfc_p2p_target_h target; - int ret ; - - printf("send_ndef_to_peer\n"); - - ret = nfc_manager_get_connected_target(&target); - if ( ret == NFC_ERROR_NONE) - { - printf("target already attached!\n"); - ecore_idler_add(send_test, target); - } - else - { - - int ret ; - success = 0; - timeout_counter =30; - ret = nfc_manager_set_p2p_target_discovered_cb(_target_discovered_cb , NULL); - printf("Now, Bring the target closer. Will be sent a new NDEF Message\n"); - ecore_timer_add(1, timeout_handler, NULL); - } -} - -void connect_handover_to_peer(nfc_error_e error, void *user_data){ - int ret ; - success = 0; - timeout_counter =30; - ret = nfc_manager_set_p2p_target_discovered_cb(_target_discovered_for_connect_handover_cb , NULL); - printf("Now, Bring the target closer. Will be tried to connect handover\n"); - ecore_timer_add(1, timeout_handler, NULL); -} - -void _p2p_recv_cb(nfc_p2p_target_h target , nfc_ndef_message_h message, void *user_data){ - - printf("recevie a new message!\n"); - print_ndef_message(message); - - success = 1; - is_terminate = 1; -} - - -void _target_discovered_cb2(nfc_discovered_type_e type, nfc_p2p_target_h target, void * user_data){ - if( type == NFC_DISCOVERED_TYPE_ATTACHED){ - printf("Discovered new target!\n"); - printf("I wait a new Message.......\n"); - timeout_counter = 30; - nfc_p2p_set_data_received_cb(target, _p2p_recv_cb,NULL); - }else{ - printf("Peer target is detached!!!!\n"); - } -} - - - -void recv_ndef_from_peer(nfc_error_e error, void *user_data){ - int ret ; - success = 0; - timeout_counter = 30; - ret = nfc_manager_set_p2p_target_discovered_cb(_target_discovered_cb2 , NULL); - printf("Now, Bring the target closer. and send a new NDEF Message to the this target\n"); - ecore_timer_add(1, timeout_handler, NULL); - -} - - -void _activation_changed_cb(bool activated , void *user_data){ - if( activated == true){ - printf("NET_NFC_MESSAGE_INIT received\n"); - }else if( activated == false){ - printf("NET_NFC_MESSAGE_DEINIT received\n"); - } -} - - -void on_activation_changed_cb_test(nfc_error_e error, void *user_data){ - int ret ; - success = 0; - timeout_counter = 30; - ret = nfc_manager_set_activation_changed_cb(_activation_changed_cb , NULL); - printf("Now, wait NET_NFC_MESSAGE_INIT or NET_NFC_MESSAGE_DEINIT\n"); - ecore_timer_add(1, timeout_handler, NULL); - -} - - - -Eina_Bool check_terminate(void *data){ - if( is_terminate ){ - nfc_manager_deinitialize(); - elm_exit(); - return 0; - } - return 1; -} - - -char *menu = - "------------------\n" - " 0. NFC OFF\n" - " 1. NFC ON\n" - " 2. ON/OFF on_activation_changed_cb check\n" - "------------------\n" - - " a. ndef record test\n" - " b. ndef discoverd cb test\n" - " c. write ndef to tag \n" - " d. send ndef to peer \n" - " e. recv ndef from peer\n" - " f. connect handover to peer\n" - "------------------\n" - - " g. ON nfc_manager_enable_system_handler\n" - " h. OFF nfc_manager_enable_system_handler\n" - - - - "------------------\n" - ">"; - - void set_activation_completed_cb(nfc_error_e error, void *user_data) -{ - printf("set_activation_completed_cb ret(%d) \n", error); - -} - -int main(int argc, char ** argv) -{ - elm_init(argc, argv); - is_terminate = 0; - char select[255]; - int ret; - - - printf( menu ); - gets(select); - - switch(select[0]){ - - case '0': - ret = nfc_manager_set_activation(0, set_activation_completed_cb, NULL); - printf("nfc_manager_set_activation set off ret(0x%08x) \n", ret); - - if (ret == NFC_ERROR_NOT_SUPPORTED) - { - printf("NFC_ERROR_NOT_SUPPORTED \n"); - } - else if (ret == NFC_ERROR_ALREADY_ACTIVATED) - { - printf("NFC_ERROR_ALREADY_ACTIVATED \n"); - - } - else if (ret == NFC_ERROR_ALREADY_DEACTIVATED) - { - printf("NFC_ERROR_ALREADY_DEACTIVATED \n"); - - } - else if (ret == NFC_ERROR_OPERATION_FAILED) - { - printf("NFC_ERROR_OPERATION_FAILED \n"); - - } - elm_shutdown(); - return 0; - - case '1': - ret = nfc_manager_set_activation(1, set_activation_completed_cb, NULL); - printf("nfc_manager_set_activation set off ret(0x%08x) \n", ret); - - if (ret == NFC_ERROR_NOT_SUPPORTED) - { - printf("NFC_ERROR_NOT_SUPPORTED \n"); - } - else if (ret == NFC_ERROR_ALREADY_ACTIVATED) - { - printf("NFC_ERROR_ALREADY_ACTIVATED \n"); - - } - else if (ret == NFC_ERROR_ALREADY_DEACTIVATED) - { - printf("NFC_ERROR_ALREADY_DEACTIVATED \n"); - - } - else if (ret == NFC_ERROR_OPERATION_FAILED) - { - printf("NFC_ERROR_OPERATION_FAILED \n"); - - } - elm_shutdown(); - return 0; - - case '2': - ret = nfc_manager_initialize(on_activation_changed_cb_test,NULL); - print_result("on_activation_changed_cb", ret); - break; - - case 'a': - ret = nfc_manager_initialize(ndef_record_create_test,NULL); - print_result("nfc_manager_initialize", ret); - break; - case 'b': - ret = nfc_manager_initialize(read_ndef_from_tag_using_ndef_discovered,NULL); - print_result("nfc_manager_initialize", ret); - break; - case 'c': - ret = nfc_manager_initialize(write_ndef_to_tag,NULL); - print_result("nfc_manager_initialize", ret); - break; - case 'd': - ret = nfc_manager_initialize(send_ndef_to_peer,NULL); - print_result("nfc_manager_initialize", ret); - break; - case 'e': - ret = nfc_manager_initialize(recv_ndef_from_peer,NULL); - print_result("nfc_manager_initialize", ret); - break; - case 'f': - ret = nfc_manager_initialize(connect_handover_to_peer,NULL); - print_result("nfc_manager_initialize", ret); - break; - - - case 'g': - ret = nfc_manager_set_system_handler_enable(true); - - printf("nfc_manager_set_system_handler_enable(true) ret [%d] current [%d]\n", ret,nfc_manager_is_system_handler_enabled()); - elm_shutdown(); - return 0; - case 'h': - ret = nfc_manager_set_system_handler_enable(false); - printf("nfc_manager_set_system_handler_enable(false) ret [%d] current [%d]\n", ret,nfc_manager_is_system_handler_enabled()); - elm_shutdown(); - return 0; - - - - default: - printf("wrong selection!\n"); - is_terminate = 1; - } - - - - ecore_timer_add(1, check_terminate, NULL); - - elm_run(); - elm_shutdown(); - - - return 0; -} diff --git a/test/nfc_unit_test.c b/test/nfc_unit_test.c new file mode 100644 index 0000000..8f66922 --- /dev/null +++ b/test/nfc_unit_test.c @@ -0,0 +1,183 @@ +#include +#include +#include +#include + +#include + +#define BUFFER_LEN 10 +#define PRT(format, args...) printf("%s:%d() "format, __FUNCTION__, __LINE__, ##args) +#define TC_PRT(format, args...) PRT(format"\n", ##args) + + +GMainLoop *main_loop = NULL; + +typedef struct { + const char *tc_name; + int tc_code; +} tc_table_t; + +tc_table_t tc_table[] = { + /* manage api*/ + {"nfc_manager_initialize" ,1}, //OK + {"nfc_snep_register_server", 2}, + + /* -----------*/ + {"Finish" , 0x00ff}, + {NULL , 0x0000}, +}; + +void tc_usage_print(void) +{ + int i = 0; + + while (tc_table[i].tc_name) + { + if (tc_table[i].tc_code != 0x00ff) + { + TC_PRT("Key %d : usage %s", tc_table[i].tc_code, tc_table[i].tc_name); + } + else + { + TC_PRT("Key %d : usage %s\n\n", 0x00ff, tc_table[i].tc_name); + } + + i++; + } +} + + +void _nfc_snep_event_cb(nfc_p2p_snep_h handle, nfc_snep_event_e event, nfc_error_e result, nfc_ndef_message_h msg, void *user_data) +{ + TC_PRT("Inside _nfc_snep_event_cb"); + switch(event) + { + case NFC_SNEP_EVENT_STOP: + TC_PRT("NFC_SNEP_EVENT_STOP"); + break; + case NFC_SNEP_EVENT_START: + TC_PRT("NFC_SNEP_EVENT_START"); + break; + case NFC_SNEP_EVENT_GET: + TC_PRT("NFC_SNEP_EVENT_GET"); + break; + case NFC_SNEP_EVENT_PUT: + TC_PRT("NFC_SNEP_EVENT_PUT"); + break; + case NFC_SNEP_EVENT_REGISTER: + TC_PRT("NFC_SNEP_EVENT_REGISTER"); + break; + case NFC_SNEP_EVENT_UNREGISTER: + TC_PRT("NFC_SNEP_EVENT_UNREGISTER"); + break; + } +} + +void _nfc_p2p_target_discovered_cb(nfc_discovered_type_e type, nfc_p2p_target_h target, void *user_data) +{ + int result; + + TC_PRT("Inside server"); + result = nfc_snep_register_server("default", 4, _nfc_snep_event_cb, NULL); + TC_PRT("nfc_snep_register_server %d", result); + + result = nfc_snep_start_server(target, "default", 4, _nfc_snep_event_cb, NULL); + TC_PRT("nfc_snep_start_server %d", result); +} + +int test_input_callback(void *data) +{ + long test_id = (long)data; + + switch (test_id) { + case 0x00ff: + TC_PRT("Finished"); + g_main_loop_quit(main_loop); + break; + case 1: //nfc_manager_initialize + { + int ret; + ret = nfc_manager_initialize(); + + if(ret == NFC_ERROR_NONE) + TC_PRT("nfc initialize success"); + else + TC_PRT("nfc initialize failed"); + } + break; + case 2: //TBT - snep behavior + { + int ret; + ret = nfc_manager_initialize(); + + if(ret == NFC_ERROR_NONE) + { + TC_PRT("register cb"); + nfc_manager_set_p2p_target_discovered_cb(_nfc_p2p_target_discovered_cb, NULL); + } + } + case 3: //nfc_snep_register_server + { + int ret; + ret = nfc_snep_register_server("default", 4, NULL, NULL); + + if(ret == NFC_ERROR_NONE) + TC_PRT("success"); + else + TC_PRT("failed"); + } + default: + break; + } + + return 0; +} + +static gboolean key_event_cb(GIOChannel *chan, + GIOCondition cond, + gpointer data) +{ + char buf[BUFFER_LEN] = { 0 }; + + gsize len = 0; + long test_id; + + memset(buf, 0, sizeof(buf)); + + if (g_io_channel_read_chars(chan, buf, sizeof(buf), &len, NULL) == G_IO_STATUS_ERROR) + return FALSE; + + tc_usage_print(); + test_id = atoi(buf); + + if (test_id) + g_idle_add(test_input_callback, (void *)test_id); + + return TRUE; +} + + +int main(int argc, char ** argv) +{ + GIOChannel *key_io; + +//#if !GLIB_CHECK_VERSION(2,35,0) +// g_type_init(); +//#endif + + key_io = g_io_channel_unix_new(fileno(stdin)); + + g_io_channel_set_encoding(key_io, NULL, NULL); + g_io_channel_set_flags(key_io, G_IO_FLAG_NONBLOCK, NULL); + + g_io_add_watch(key_io, G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL, + key_event_cb, NULL); + + g_io_channel_unref(key_io); + + main_loop = g_main_loop_new(NULL, FALSE); + + g_main_loop_run(main_loop); + + return 0; +}