revise file name.
revise indent.
revise makefiles.
cleanup code.
Change-Id: Ic7c714c0916c6d35ff07839aedef81a281bcb8af
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+PROJECT(nfc-manager C)
-MESSAGE("build nfc-common-lib and nfc-manager")
+INCLUDE(FindPkgConfig)
+
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Wall -Werror-implicit-function-declaration")
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fPIC -fvisibility=hidden")
+#SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fno-strict-aliasing")
+
+#SET(ARM_CFLAGS "-mabi=aapcs-linux -fno-common")
+
+FIND_PROGRAM(UNAME NAMES uname)
+EXEC_PROGRAM("${UNAME}" ARGS "-m" OUTPUT_VARIABLE "ARCH")
+IF("${ARCH}" MATCHES "^arm.*")
+ ADD_DEFINITIONS("-DTARGET")
+ MESSAGE("add -DTARGET")
+ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${ARM_CFLAGS}")
+ENDIF()
+
+SET(CMAKE_SHARED_LINKER_FLAGS " -Wl,--as-needed -Wl,--rpath=${LIB_INSTALL_DIR}")
+SET(CMAKE_EXE_LINKER_FLAGS " -Wl,--as-needed -Wl,--rpath=${LIB_INSTALL_DIR}")
SET(PREFIX ${CMAKE_INSTALL_PREFIX})
-SET(LIBDIR "${PREFIX}/lib")
-SET(MODULEDIR "${LIBDIR}/nfc")
-ADD_DEFINITIONS("-D_GNU_SOURCE")
+ADD_DEFINITIONS("-DNFC_MANAGER_MODULEDIR=\"${LIB_INSTALL_DIR}/nfc\"")
+
#ADD_DEFINITIONS("-DSECURITY_SERVER")
+ADD_DEFINITIONS("-DUSE_FULL_URI")
+#ADD_DEFINITIONS("-DESE_ALWAYS_ON")
-ADD_SUBDIRECTORY(src/commonlib)
-ADD_SUBDIRECTORY(src/clientlib)
-ADD_SUBDIRECTORY(src/manager)
-#ADD_SUBDIRECTORY(test_clinet_app/ndef-tool)
-#ADD_SUBDIRECTORY(test_clinet_app/nfc_client)
+ADD_SUBDIRECTORY(common)
+ADD_SUBDIRECTORY(client)
+ADD_SUBDIRECTORY(daemon)
ADD_SUBDIRECTORY(tests)
+#ADD_SUBDIRECTORY(tools/ndef-tool)
+#ADD_SUBDIRECTORY(tools/nfc-client)
+++ /dev/null
-#!/bin/sh
-
-. ./config
-export TET_INSTALL_PATH=$TET_INSTALL_HOST_PATH
-export TET_TARGET_PATH=$TET_INSTALL_PATH/tetware-target # tetware target path
-export PATH=$TET_TARGET_PATH/bin:$PATH
-export LD_LIBRARY_PATH=$TET_TARGET_PATH/lib/tet3:$LD_LIBRARY_PATH
-export TET_ROOT=$TET_TARGET_PATH
+++ /dev/null
-#!/bin/sh
-. ./config
-export TET_INSTALL_PATH=$TET_INSTALL_TARGET_PATH # path to path
-export TET_TARGET_PATH=$TET_INSTALL_PATH/tetware-target
-export PATH=$TET_TARGET_PATH/bin:$PATH
-export LD_LIBRARY_PATH=$TET_TARGET_PATH/lib/tet3:$LD_LIBRARY_PATH
-export TET_ROOT=$TET_TARGET_PATH
+++ /dev/null
-#!/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
+++ /dev/null
-#!/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
+++ /dev/null
-CAPI_PROJECT_ROOT=/home/abyss/capi
-TET_INSTALL_HOST_PATH=/home/abyss/TETware
-TET_INSTALL_TARGET_PATH=/mnt/nfs/TETware
+++ /dev/null
-#!/bin/sh
-
-. ./_export_target_env.sh # setting environment variables
-
-export TET_SUITE_ROOT=`pwd`
-FILE_NAME_EXTENSION=`date +%s`
-
-RESULT_DIR=results
-HTML_RESULT=$RESULT_DIR/exec-tar-result-$FILE_NAME_EXTENSION.html
-JOURNAL_RESULT=$RESULT_DIR/exec-tar-result-$FILE_NAME_EXTENSION.journal
-
-mkdir -p $RESULT_DIR
-
-tcc -e -j $JOURNAL_RESULT -p ./
-grw -c 3 -f chtml -o $HTML_RESULT $JOURNAL_RESULT
+++ /dev/null
-CC ?= gcc
-
-C_FILES = $(shell ls *.c)
-
-ifeq ($(ARCH),target)
- PKG_CONFIG_PATH=/usr/lib/pkgconfig
- export PKG_CONFIG_PATH
- CC=arm-linux-gcc -Wall
- CXX=arm-linux-g++ -Wall
-else
- PKG_CONFIG_PATH=/usr/lib/pkgconfig
- export PKG_CONFIG_PATH
- CC=gcc -Wall
- CXX=gcc -Wall
-endif
-
-
-LDFLAGS = `pkg-config --libs nfc nfc-common-lib glib-2.0`
-LDFLAGS += $(TET_ROOT)/lib/tet3/tcm_s.o
-LDFLAGS += -L$(TET_ROOT)/lib/tet3 -ltcm_s
-LDFLAGS += -L$(TET_ROOT)/lib/tet3 -lapi_s
-
-CFLAGS = -I. `pkg-config --cflags nfc nfc-common-lib glib-2.0`
-CFLAGS += -I$(TET_ROOT)/inc/tet3
-CFLAGS += -Wall
-
-TCS := $(shell ls -1 *.c | cut -d. -f1)
-
-all: $(TCS)
-
-%: %.c
- $(CC) -o $@ $< $(CFLAGS) $(LDFLAGS)
-
-clean:
- rm -f $(TCS)
+++ /dev/null
-/testcase/utc_net_nfc_client_data
-/testcase/utc_net_nfc_client_exchanger
-/testcase/utc_net_nfc_client_internal_se
-/testcase/utc_net_nfc_client_ndef_message
-/testcase/utc_net_nfc_client_ndef_record
-/testcase/utc_net_nfc_client_nfc
-/testcase/utc_net_nfc_client_tag
-/testcase/utc_net_nfc_client_tag_felica
-/testcase/utc_net_nfc_client_tag_jewel
-/testcase/utc_net_nfc_client_tag_mifare
-/testcase/utc_net_nfc_client_target_info
-
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
-
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-#include <tet_api.h>
-#include <stdint.h>
-
-#include <net_nfc_data.h>
-#include <net_nfc_typedef.h>
-#include <net_nfc_typedef_internal.h>
-#include <net_nfc_util_internal.h>
-
-
-enum {
- POSITIVE_TC_IDX = 0x01,
- NEGATIVE_TC_IDX,
-};
-static void startup(void);
-static void cleanup(void);
-
-void (*tet_startup)(void) = startup;
-void (*tet_cleanup)(void) = cleanup;
-
-static void utc_net_nfc_create_data_only_p(void);
-static void utc_net_nfc_create_data_only_n(void);
-static void utc_net_nfc_create_data_p(void);
-static void utc_net_nfc_create_data_n(void);
-static void utc_net_nfc_get_data_p(void);
-static void utc_net_nfc_get_data_n(void);
-static void utc_net_nfc_set_data_p(void);
-static void utc_net_nfc_set_data_n(void);
-static void utc_net_nfc_get_data_length_p(void);
-static void utc_net_nfc_get_data_length_n(void);
-static void utc_net_nfc_get_data_buffer_p(void);
-static void utc_net_nfc_get_data_buffer_n(void);
-static void utc_net_nfc_free_data_p(void);
-static void utc_net_nfc_free_data_n(void);
-
-
-
-
-struct tet_testlist tet_testlist[] = {
- { utc_net_nfc_create_data_only_p , POSITIVE_TC_IDX },
- { utc_net_nfc_create_data_only_n , NEGATIVE_TC_IDX },
- { utc_net_nfc_create_data_p, POSITIVE_TC_IDX },
- { utc_net_nfc_create_data_n , NEGATIVE_TC_IDX},
- { utc_net_nfc_get_data_p, 1},
- { utc_net_nfc_get_data_n, 2 },
- { utc_net_nfc_set_data_p, 1},
- { utc_net_nfc_set_data_n, 2},
- { utc_net_nfc_get_data_length_p, 1},
- { utc_net_nfc_get_data_length_n, 2},
- { utc_net_nfc_get_data_buffer_p, 1},
- { utc_net_nfc_get_data_buffer_n, 2},
- { utc_net_nfc_free_data_p, 1},
- { utc_net_nfc_free_data_n, 2},
- { NULL, 0 },
-};
-
-//this method is called only once in start
-static void startup(void)
-{
- /* start of TC */
-}
-
-static void cleanup(void)
-{
- /* end of TC */
-}
-static void utc_net_nfc_create_data_only_p(void)
-{
- int ret=0;
- data_h* config = NULL;
-
- config = calloc(1 , sizeof(data_h));
-
- ret = net_nfc_create_data_only(config);
-
- dts_check_eq(__func__, ret, NET_NFC_OK, "net_nfc_create_data_only is failed");
-}
-
-static void utc_net_nfc_create_data_only_n(void)
-{
- int ret=0;
-
- ret = net_nfc_create_data_only(NULL);
-
- dts_check_ne(__func__, ret, NET_NFC_OK, "net_nfc_create_data not allow null");
-}
-
-static void utc_net_nfc_create_data_p(void)
-{
- int ret=0;
- data_h* config = NULL;
- uint8_t* sec_param = NULL;
-
- config = calloc(1, sizeof(data_h));
- sec_param = calloc(1, sizeof(uint8_t));
- memcpy(sec_param , "U" , sizeof(uint8_t));
-
- ret = net_nfc_create_data(config , sec_param/*"U"*/ , 1);
-
- free(config);
-
- dts_check_eq(__func__, ret, NET_NFC_OK, "net_nfc_create_data is failed");
-}
-
-static void utc_net_nfc_create_data_n(void)
-{
- int ret=0;
-
- ret = net_nfc_create_data(NULL , NULL , 0);
-
- dts_check_ne(__func__, ret, NET_NFC_OK, "net_nfc_create_data_only not allow null");
-}
-
-static void utc_net_nfc_get_data_p(void)
-{
- int ret=0;
- data_h data = NULL;
- uint8_t* byte = NULL;
- uint32_t length;
-
- byte = calloc(10, sizeof(uint8_t));
-
- data = calloc(1, sizeof(data_s));
-
- ret = net_nfc_get_data(data , &byte , &length);
-
- free(data);
- free(byte);
-
- dts_check_eq(__func__, ret, NET_NFC_OK, "net_nfc_get_data is failed");
-}
-
-static void utc_net_nfc_get_data_n(void)
-{
- int ret=0;
-
- ret = net_nfc_get_data(NULL , NULL , NULL);
-
- dts_check_ne(__func__, ret, NET_NFC_OK, "net_nfc_get_data not allow null");
-}
-
-static void utc_net_nfc_set_data_p(void)
-{
- int ret=0;
- data_h data = NULL;
- uint8_t main_record_name[] = "samsung.com:allshare";
-
- data = calloc(1, sizeof(data_h));
-
- ret = net_nfc_set_data (data, main_record_name, 20);
-
- dts_check_eq(__func__, ret, NET_NFC_OK, "net_nfc_set_data is failed");
-}
-
-static void utc_net_nfc_set_data_n(void)
-{
- int ret=0;
-
- ret = net_nfc_set_data(NULL , NULL , 0);
-
- dts_check_ne(__func__, ret, NET_NFC_OK, "net_nfc_set_data not allow null");
-}
-
-static void utc_net_nfc_get_data_length_p(void)
-{
- int ret=0;
- int length = 0;
- data_s* data = NULL;
- //uint8_t temp_data[] = "www.samsung.com";
- uint32_t temp_size = 16;
-
- data = calloc(1, sizeof(data_s));
-
- //data->buffer = temp_data;
- data->length = temp_size;
-
- length = net_nfc_get_data_length ((data_h)data);
-
- if(length > 0)
- {
- ret = NET_NFC_OK;
- }
- else
- {
- ret = NET_NFC_UNKNOWN_ERROR;
- }
-
- free(data);
-
- dts_check_eq(__func__, ret, NET_NFC_OK, "net_nfc_get_data_length is failed");
-}
-
-static void utc_net_nfc_get_data_length_n(void)
-{
- int ret=0;
- int length = 0;
-
- length = net_nfc_get_data_length(NULL);
-
- if(length > 0)
- {
- ret = NET_NFC_OK;
- }
- else
- {
- ret = NET_NFC_UNKNOWN_ERROR;
- }
-
- dts_check_ne(__func__, ret, NET_NFC_OK, "net_nfc_get_data_length not allow null");
-}
-
-static void utc_net_nfc_get_data_buffer_p(void)
-{
- int ret=0;
- uint8_t* buffer = NULL;
- data_s* data = NULL;
- uint8_t temp_data[] = "www.samsung.com";
- int temp_size = 16;
-
- data = calloc(1, sizeof(data_s));
-
- data->buffer = temp_data;
- data->length = temp_size;
-
- buffer = net_nfc_get_data_buffer ((data_h)data);
-
- if(buffer != NULL)
- {
- ret = NET_NFC_OK;
- }
- else
- {
- ret = NET_NFC_UNKNOWN_ERROR;
- }
-
- free(data);
-
- dts_check_eq(__func__, ret, NET_NFC_OK, "net_nfc_get_data_buffer is failed");
-}
-
-static void utc_net_nfc_get_data_buffer_n(void)
-{
- int ret=0;
- uint8_t* buffer = NULL;
-
- buffer = net_nfc_get_data_buffer(NULL);
-
- if(buffer != NULL)
- {
- ret = NET_NFC_OK;
- }
- else
- {
- ret = NET_NFC_UNKNOWN_ERROR;
- }
-
- dts_check_ne(__func__, ret, NET_NFC_OK, "net_nfc_get_data_buffer not allow null");
-}
-
-static void utc_net_nfc_free_data_p(void)
-{
- int ret=0;
- data_h data = NULL;
- //uint8_t temp_data[] = "www.samsung.com";
- //uint32_t temp_size = 16;
-
- data = calloc(1, sizeof(data_h));
-
- ret = net_nfc_free_data (data);
-
- dts_check_eq(__func__, ret, NET_NFC_OK, "net_nfc_free_data is failed");
-}
-
-static void utc_net_nfc_free_data_n(void)
-{
- int ret=0;
-
- ret = net_nfc_free_data(NULL);
-
- dts_check_ne(__func__, ret, NET_NFC_OK, "net_nfc_free_data not allow null");
-}
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
-
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-#include <tet_api.h>
-#include <net_nfc_data.h>
-#include <stdint.h>
-
-#include <net_nfc_exchanger.h>
-#include <net_nfc_typedef.h>
-#include <net_nfc_typedef_internal.h>
-#include <net_nfc_util_internal.h>
-
-
-enum {
- POSITIVE_TC_IDX = 0x01,
- NEGATIVE_TC_IDX,
-};
-static void startup(void);
-static void cleanup(void);
-
-void (*tet_startup)(void) = startup;
-void (*tet_cleanup)(void) = cleanup;
-
-static void utc_net_nfc_create_exchanger_data_p(void);
-static void utc_net_nfc_create_exchanger_data_n(void);
-static void utc_net_nfc_free_exchanger_data_p(void);
-static void utc_net_nfc_free_exchanger_data_n(void);
-static void utc_net_nfc_set_exchanger_cb_p(void);
-static void utc_net_nfc_set_exchanger_cb_n(void);
-static void utc_net_nfc_unset_exchanger_cb_p(void);
-static void utc_net_nfc_unset_exchanger_cb_n(void);
-
-
-
-
-
-struct tet_testlist tet_testlist[] = {
- { utc_net_nfc_create_exchanger_data_p , POSITIVE_TC_IDX},
- { utc_net_nfc_create_exchanger_data_n , NEGATIVE_TC_IDX},
- { utc_net_nfc_free_exchanger_data_p, 1},
- { utc_net_nfc_free_exchanger_data_n, 2 },
- { utc_net_nfc_set_exchanger_cb_p, 1},
- { utc_net_nfc_set_exchanger_cb_n, 2},
- { utc_net_nfc_unset_exchanger_cb_p, 1},
- { utc_net_nfc_unset_exchanger_cb_n, 2},
- { NULL, 0 },
-};
-
-//this method is called only once in start
-static void startup(void)
-{
- /* start of TC */
-}
-
-static void cleanup(void)
-{
- /* end of TC */
-}
-static void utc_net_nfc_create_exchanger_data_p(void)
-{
- int ret=0;
- net_nfc_exchanger_data_h* ex_data = NULL;
- char temp[] = "http://www.samsung.com";
- data_s payload;
-
- payload.length= 23;
-
- payload.buffer = calloc(1 , 23*sizeof(char));
-
- memcpy(payload.buffer , temp , sizeof(temp));
-
- ex_data = calloc(1 , sizeof(ex_data));
-
- ret = net_nfc_create_exchanger_data(ex_data , (data_h)&payload);
-
- dts_check_eq(__func__, ret, NET_NFC_OK, "net_nfc_create_exchanger_url_type_data is failed");
-}
-
-static void utc_net_nfc_create_exchanger_data_n(void)
-{
- int ret=0;
-
- ret = net_nfc_create_exchanger_data(NULL , NULL);
-
- dts_check_ne(__func__, ret, NET_NFC_OK, "net_nfc_create_exchanger_url_type_data not allow null");
-}
-
-static void utc_net_nfc_free_exchanger_data_p(void)
-{
- int ret=0;
- net_nfc_exchanger_data_h ex_data = NULL;
- char temp[] = "http://www.samsung.com";
- data_s payload;
-
- payload.length= 23;
-
- payload.buffer = calloc(1 , 23*sizeof(char));
-
- memcpy(payload.buffer , temp , sizeof(temp));
-
- net_nfc_create_exchanger_data(&ex_data , (data_h)&payload );
-
- ret = net_nfc_free_exchanger_data(ex_data);
-
- dts_check_eq(__func__, ret, NET_NFC_OK, "utc_net_nfc_free_exchanger_data_p is failed");
-}
-
-static void utc_net_nfc_free_exchanger_data_n(void)
-{
- int ret=0;
-
- ret = net_nfc_free_exchanger_data(NULL);
-
- dts_check_ne(__func__, ret, NET_NFC_OK, "utc_net_nfc_free_exchanger_data_p not allow null");
-}
-
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
-
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-#include <tet_api.h>
-
-#include "net_nfc_tag.h"
-#include "net_nfc_typedef_internal.h"
-#include "net_nfc_internal_se.h"
-#include "net_nfc_util_internal.h"
-#include "net_nfc_data.h"
-
-
-enum {
- POSITIVE_TC_IDX = 0x01,
- NEGATIVE_TC_IDX,
-};
-static void startup(void);
-static void cleanup(void);
-
-void (*tet_startup)(void) = startup;
-void (*tet_cleanup)(void) = cleanup;
-
-static void utc_net_nfc_set_secure_element_type_p(void);
-static void utc_net_nfc_set_secure_element_type_n(void);
-static void utc_net_nfc_get_secure_element_type_p(void);
-static void utc_net_nfc_get_secure_element_type_n(void);
-static void utc_net_nfc_open_internal_secure_element_p(void);
-static void utc_net_nfc_open_internal_secure_element_n(void);
-static void utc_net_nfc_close_internal_secure_element_p(void);
-static void utc_net_nfc_close_internal_secure_element_n(void);
-static void utc_net_nfc_send_apdu_p(void);
-static void utc_net_nfc_send_apdu_n(void);
-
-
-
-struct tet_testlist tet_testlist[] = {
- { utc_net_nfc_set_secure_element_type_p , POSITIVE_TC_IDX },
- { utc_net_nfc_set_secure_element_type_n , NEGATIVE_TC_IDX },
- { utc_net_nfc_get_secure_element_type_p, POSITIVE_TC_IDX },
- { utc_net_nfc_get_secure_element_type_n , NEGATIVE_TC_IDX},
- { utc_net_nfc_open_internal_secure_element_p, 1},
- { utc_net_nfc_open_internal_secure_element_n, 2 },
- { utc_net_nfc_close_internal_secure_element_p, 1},
- { utc_net_nfc_close_internal_secure_element_n, 2},
- { utc_net_nfc_send_apdu_p, 1},
- { utc_net_nfc_send_apdu_n, 2},
- { NULL, 0 },
-};
-
-//this method is called only once in start
-static void startup(void)
-{
- /* start of TC */
-}
-
-static void cleanup(void)
-{
- /* end of TC */
-}
-static void utc_net_nfc_set_secure_element_type_p(void)
-{
- int ret=0;
-
- ret = net_nfc_set_secure_element_type(NET_NFC_SE_TYPE_UICC, NULL);
-
- dts_pass(__func__, "PASS");
-}
-
-static void utc_net_nfc_set_secure_element_type_n(void)
-{
- int ret=0;
-
- ret = net_nfc_set_secure_element_type( -1 , NULL);
-
- dts_pass(__func__, "PASS");
-}
-
-static void utc_net_nfc_get_secure_element_type_p(void)
-{
- int ret=0;
-
- ret = net_nfc_get_secure_element_type(NULL);
-
- dts_pass(__func__, "PASS");
-}
-
-static void utc_net_nfc_get_secure_element_type_n(void)
-{
- int ret=0;
-
- ret = net_nfc_get_secure_element_type(NULL);
-
- dts_pass(__func__, "PASS");
-}
-
-static void utc_net_nfc_open_internal_secure_element_p(void)
-{
- net_nfc_open_internal_secure_element(NET_NFC_SE_TYPE_ESE, NULL);
-
- dts_pass(__func__, "PASS");
-}
-
-static void utc_net_nfc_open_internal_secure_element_n(void)
-{
- int ret=0;
-
- ret = net_nfc_open_internal_secure_element(NET_NFC_SE_TYPE_ESE, NULL);
-
- dts_pass(__func__, "PASS");
-}
-
-static void utc_net_nfc_close_internal_secure_element_p(void)
-{
- int ret=0;
- void * trans_data = NULL;
-
- ret = net_nfc_close_internal_secure_element ((net_nfc_target_handle_h)trans_data, NULL);
-
- dts_pass(__func__, "PASS");
-}
-
-static void utc_net_nfc_close_internal_secure_element_n(void)
-{
- int ret=0;
-
- ret = net_nfc_close_internal_secure_element(NULL , NULL);
-
- dts_pass(__func__, "PASS");
-}
-
-static void utc_net_nfc_send_apdu_p(void)
-{
- int ret ;
- net_nfc_target_handle_h data = NULL;
- data_h apdu = NULL;
- uint8_t apdu_cmd[4] = {0x00, 0xA4, 0x00, 0x0C} ; // CLA 0-> use default channel and no secure message. 0xA4 -> select instruction
-
- //data->connection_id = 1;
- //data->connection_type = NET_NFC_SE_CONNECTION;
-
- net_nfc_create_data(&apdu, apdu_cmd, 4);
-
- ret = net_nfc_send_apdu((net_nfc_target_handle_h)(data), apdu, data);
-
- dts_pass(__func__, "PASS");
-}
-
-static void utc_net_nfc_send_apdu_n(void)
-{
- int ret ;
-
- ret = net_nfc_send_apdu(NULL , NULL , NULL );
-
- dts_pass(__func__, "PASS");
-}
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
-
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-#include <tet_api.h>
-#include <stdint.h>
-
-#include "net_nfc_ndef_message.h"
-#include "net_nfc_util_internal.h"
-#include "net_nfc.h" // to use net_nfc_data
-
-
-enum {
- POSITIVE_TC_IDX = 0x01,
- NEGATIVE_TC_IDX,
-};
-static void startup(void);
-static void cleanup(void);
-
-void (*tet_startup)(void) = startup;
-void (*tet_cleanup)(void) = cleanup;
-
-static void utc_net_nfc_create_ndef_message_p(void);
-static void utc_net_nfc_create_ndef_message_n(void);
-static void utc_net_nfc_create_rawdata_from_ndef_message_p(void);
-static void utc_net_nfc_create_rawdata_from_ndef_message_n(void);
-static void utc_net_nfc_create_ndef_message_from_rawdata_p(void);
-static void utc_net_nfc_create_ndef_message_from_rawdata_n(void);
-static void utc_net_nfc_get_ndef_message_byte_length_p(void);
-static void utc_net_nfc_get_ndef_message_byte_length_n(void);
-static void utc_net_nfc_append_record_to_ndef_message_p(void);
-static void utc_net_nfc_append_record_to_ndef_message_n(void);
-static void utc_net_nfc_free_ndef_message_p(void);
-static void utc_net_nfc_free_ndef_message_n(void);
-static void utc_net_nfc_get_ndef_message_record_count_p(void);
-static void utc_net_nfc_get_ndef_message_record_count_n(void);
-
-
-
-
-struct tet_testlist tet_testlist[] = {
- { utc_net_nfc_create_ndef_message_p , POSITIVE_TC_IDX },
- { utc_net_nfc_create_ndef_message_n , NEGATIVE_TC_IDX },
- { utc_net_nfc_create_rawdata_from_ndef_message_p, POSITIVE_TC_IDX },
- { utc_net_nfc_create_rawdata_from_ndef_message_n , NEGATIVE_TC_IDX},
- { utc_net_nfc_create_ndef_message_from_rawdata_p, 1},
- { utc_net_nfc_create_ndef_message_from_rawdata_n, 2 },
- { utc_net_nfc_get_ndef_message_byte_length_p, 1},
- { utc_net_nfc_get_ndef_message_byte_length_n, 2},
- { utc_net_nfc_append_record_to_ndef_message_p, 1},
- { utc_net_nfc_append_record_to_ndef_message_n, 2},
- { utc_net_nfc_free_ndef_message_p, 1},
- { utc_net_nfc_free_ndef_message_n, 2},
- { utc_net_nfc_get_ndef_message_record_count_p, 1},
- { utc_net_nfc_get_ndef_message_record_count_n, 2},
- { NULL, 0 },
-};
-
-//this method is called only once in start
-static void startup(void)
-{
- /* start of TC */
-}
-
-static void cleanup(void)
-{
- /* end of TC */
-}
-static void utc_net_nfc_create_ndef_message_p(void)
-{
- int ret ;
- ndef_message_h message;
-
- ret = net_nfc_create_ndef_message(&message);
- net_nfc_free_ndef_message(message);
-
- dts_check_eq(__func__, ret, NET_NFC_OK, "net_nfc_create_ndef_message is failed");
-}
-
-static void utc_net_nfc_create_ndef_message_n(void)
-{
- int ret=0;
-
- ret = net_nfc_create_ndef_message( NULL);
-
- dts_check_ne(__func__, ret, NET_NFC_OK, "net_nfc_create_ndef_message not allow null");
-}
-
-static void utc_net_nfc_create_rawdata_from_ndef_message_p(void)
-{
- int ret ;
- char url[] = "samsung.com";
- ndef_record_h record = NULL;
- ndef_message_h msg = NULL;
- data_h rawdata = NULL;
-
- net_nfc_create_uri_type_record(&record, url, NET_NFC_SCHEMA_HTTPS_WWW);
-
- net_nfc_create_ndef_message(&msg);
-
- net_nfc_append_record_to_ndef_message(msg, record);
-
- ret = net_nfc_create_rawdata_from_ndef_message (msg, &rawdata);
-
- dts_check_eq(__func__, ret, NET_NFC_OK, "net_nfc_create_rawdata_from_ndef_message is failed");
-}
-
-static void utc_net_nfc_create_rawdata_from_ndef_message_n(void)
-{
- int ret ;
-
- ret = net_nfc_create_rawdata_from_ndef_message (NULL, NULL);
-
- dts_check_ne(__func__, ret, NET_NFC_OK, "net_nfc_create_rawdata_from_ndef_message not allow null");
-}
-
-static void utc_net_nfc_create_ndef_message_from_rawdata_p(void)
-{
- int ret ;
- uint8_t url[] = "samsung.com";
- ndef_message_s* msg = NULL;
- data_s* rawdata = NULL;
-
- rawdata = calloc(1, sizeof(data_s));
- msg = calloc(1, sizeof(ndef_message_s));
-
- rawdata->buffer = url;
- rawdata->length = 11;
-
- ret = net_nfc_create_ndef_message_from_rawdata ((ndef_message_h*)msg, (data_h)rawdata);
-
- net_nfc_free_ndef_message((ndef_message_h)msg);
-
- dts_check_eq(__func__, ret, NET_NFC_OK, "net_nfc_create_ndef_message_from_rawdata is failed");
-}
-
-static void utc_net_nfc_create_ndef_message_from_rawdata_n(void)
-{
- int ret ;
-
- ret = net_nfc_create_ndef_message_from_rawdata (NULL, NULL);
-
- dts_check_ne(__func__, ret, NET_NFC_OK,"net_nfc_create_ndef_message_from_rawdata not allow null");
-}
-
-static void utc_net_nfc_get_ndef_message_byte_length_p(void)
-{
- int ret ;
- char url[] = "samsung.com";
- ndef_record_h record = NULL;
- ndef_message_h msg = NULL;
- uint32_t length = 0;
-
- net_nfc_create_uri_type_record(&record, url, NET_NFC_SCHEMA_HTTPS_WWW);
-
- net_nfc_create_ndef_message(&msg);
-
- net_nfc_append_record_to_ndef_message(msg, record);
-
- ret = net_nfc_get_ndef_message_byte_length(msg , &length);
-
- dts_check_eq(__func__, ret, NET_NFC_OK, "net_nfc_get_ndef_message_byte_length is failed");
-}
-
-static void utc_net_nfc_get_ndef_message_byte_length_n(void)
-{
- int ret ;
-
- ret = net_nfc_get_ndef_message_byte_length (NULL, NULL);
-
- dts_check_ne(__func__, ret, NET_NFC_OK,"net_nfc_get_ndef_message_byte_length not allow null");
-}
-
-static void utc_net_nfc_append_record_to_ndef_message_p(void)
-{
- int ret ;
- char url[] = "samsung.com";
- ndef_record_h record = NULL;
- ndef_message_h msg = NULL;
-
- net_nfc_create_uri_type_record(&record, url, NET_NFC_SCHEMA_HTTPS_WWW);
-
- net_nfc_create_ndef_message(&msg);
-
- ret = net_nfc_append_record_to_ndef_message(msg, record);
-
- dts_check_eq(__func__, ret, NET_NFC_OK, "net_nfc_append_record_to_ndef_message is failed");
-}
-
-static void utc_net_nfc_append_record_to_ndef_message_n(void)
-{
- int ret ;
-
- ret = net_nfc_append_record_to_ndef_message (NULL, NULL);
-
- dts_check_ne(__func__, ret, NET_NFC_OK,"net_nfc_append_record_to_ndef_message not allow null");
-}
-
-static void utc_net_nfc_free_ndef_message_p(void)
-{
- int ret ;
- ndef_message_h message;
-
- net_nfc_create_ndef_message(&message);
- ret = net_nfc_free_ndef_message(message);
-
- dts_check_eq(__func__, ret, NET_NFC_OK, "utc_net_nfc_free_ndef_message_n is failed");
-}
-
-static void utc_net_nfc_free_ndef_message_n(void)
-{
- int ret=0;
-
- ret = net_nfc_free_ndef_message( NULL);
-
- dts_check_ne(__func__, ret, NET_NFC_OK, "utc_net_nfc_free_ndef_message_n not allow null");
-}
-
-static void utc_net_nfc_get_ndef_message_record_count_p(void)
-{
- int ret ;
- char url[] = "samsung.com";
- ndef_record_h record = NULL;
- ndef_message_h msg = NULL;
- int count = 0;
-
- net_nfc_create_uri_type_record(&record, url, NET_NFC_SCHEMA_HTTPS_WWW);
-
- net_nfc_create_ndef_message(&msg);
-
- net_nfc_append_record_to_ndef_message(msg, record);
-
- ret = net_nfc_get_ndef_message_record_count( msg , &count );
-
- dts_check_eq(__func__, ret, NET_NFC_OK, "net_nfc_get_ndef_message_record_count is failed");
-}
-
-static void utc_net_nfc_get_ndef_message_record_count_n(void)
-{
- int ret=0;
-
- ret = net_nfc_get_ndef_message_record_count( NULL , NULL);
-
- dts_check_ne(__func__, ret, NET_NFC_OK, "net_nfc_get_ndef_message_record_count not allow null");
-}
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
-
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <tet_api.h>
-#include <stdint.h>
-
-#include "net_nfc_ndef_record.h"
-#include "net_nfc_ndef_message.h"
-#include "net_nfc_util_internal.h"
-#include "net_nfc_data.h"
-//#include "net_nfc_debug_internal.h"
-#include "net_nfc_util_internal.h"
-
-
-enum {
- POSITIVE_TC_IDX = 0x01,
- NEGATIVE_TC_IDX,
-};
-static void startup(void);
-static void cleanup(void);
-
-void (*tet_startup)(void) = startup;
-void (*tet_cleanup)(void) = cleanup;
-
-static void utc_net_nfc_create_record_p(void);
-static void utc_net_nfc_create_record_n(void);
-static void utc_net_nfc_create_text_type_record_p(void);
-static void utc_net_nfc_create_text_type_record_n(void);
-static void utc_net_nfc_create_uri_type_record_p(void);
-static void utc_net_nfc_create_uri_type_record_n(void);
-static void utc_net_nfc_free_record_p(void);
-static void utc_net_nfc_free_record_n(void);
-static void utc_net_nfc_get_record_payload_p(void);
-static void utc_net_nfc_get_record_payload_n(void);
-static void utc_net_nfc_get_record_type_p(void);
-static void utc_net_nfc_get_record_type_n(void);
-static void utc_net_nfc_set_record_id_p(void);
-static void utc_net_nfc_set_record_id_n(void);
-static void utc_net_nfc_get_record_id_p(void);
-static void utc_net_nfc_get_record_id_n(void);
-static void utc_net_nfc_get_record_tnf_p(void);
-static void utc_net_nfc_get_record_tnf_n(void);
-static void utc_net_nfc_get_record_flags_p(void);
-static void utc_net_nfc_get_record_flags_n(void);
-static void utc_net_nfc_get_record_mb_p(void);
-static void utc_net_nfc_get_record_mb_n(void);
-static void utc_net_nfc_get_record_me_p(void);
-static void utc_net_nfc_get_record_me_n(void);
-static void utc_net_nfc_get_record_cf_p(void);
-static void utc_net_nfc_get_record_cf_n(void);
-static void utc_net_nfc_get_record_il_p(void);
-static void utc_net_nfc_get_record_il_n(void);
-static void utc_net_nfc_get_record_sr_p(void);
-static void utc_net_nfc_get_record_sr_n(void);
-static void utc_net_nfc_create_text_string_from_text_record_p(void);
-static void utc_net_nfc_create_text_string_from_text_record_n(void);
-static void utc_net_nfc_get_languange_code_string_from_text_record_p(void);
-static void utc_net_nfc_get_languange_code_string_from_text_record_n(void);
-static void utc_net_nfc_get_encoding_type_from_text_record_p(void);
-static void utc_net_nfc_get_encoding_type_from_text_record_n(void);
-static void utc_net_nfc_create_uri_string_from_uri_record_p(void);
-static void utc_net_nfc_create_uri_string_from_uri_record_n(void);
-
-
-
-
-
-
-
-struct tet_testlist tet_testlist[] = {
- { utc_net_nfc_create_record_p , POSITIVE_TC_IDX },
- { utc_net_nfc_create_record_n , NEGATIVE_TC_IDX },
- { utc_net_nfc_create_text_type_record_p, POSITIVE_TC_IDX },
- { utc_net_nfc_create_text_type_record_n , NEGATIVE_TC_IDX},
- { utc_net_nfc_create_uri_type_record_p, 1},
- { utc_net_nfc_create_uri_type_record_n, 2 },
- { utc_net_nfc_free_record_p, 1},
- { utc_net_nfc_free_record_n, 2},
- { utc_net_nfc_get_record_payload_p, 1},
- { utc_net_nfc_get_record_payload_n, 2},
- { utc_net_nfc_get_record_type_p, 1},
- { utc_net_nfc_get_record_type_n, 2},
- { utc_net_nfc_set_record_id_p, 1},
- { utc_net_nfc_set_record_id_n, 2},
- { utc_net_nfc_get_record_id_p, 1},
- { utc_net_nfc_get_record_id_n, 2},
- { utc_net_nfc_get_record_tnf_p, 1},
- { utc_net_nfc_get_record_tnf_n, 2},
- { utc_net_nfc_get_record_flags_p, 1},
- { utc_net_nfc_get_record_flags_n, 2},
- { utc_net_nfc_get_record_mb_p, 1},
- { utc_net_nfc_get_record_mb_n, 2},
- { utc_net_nfc_get_record_me_p, 1},
- { utc_net_nfc_get_record_me_n, 2},
- { utc_net_nfc_get_record_cf_p, 1},
- { utc_net_nfc_get_record_cf_n, 2},
- { utc_net_nfc_get_record_il_p, 1},
- { utc_net_nfc_get_record_il_n, 2},
- { utc_net_nfc_get_record_sr_p, 1},
- { utc_net_nfc_get_record_sr_n, 2},
- { utc_net_nfc_create_text_string_from_text_record_p, 1},
- { utc_net_nfc_create_text_string_from_text_record_n, 2},
- { utc_net_nfc_get_languange_code_string_from_text_record_p, 1},
- { utc_net_nfc_get_languange_code_string_from_text_record_n, 2},
- { utc_net_nfc_get_encoding_type_from_text_record_p, 1},
- { utc_net_nfc_get_encoding_type_from_text_record_n, 2},
- { utc_net_nfc_create_uri_string_from_uri_record_p, 1},
- { utc_net_nfc_create_uri_string_from_uri_record_n, 2},
- { NULL, 0 },
-};
-
-//this method is called only once in start
-static void startup(void)
-{
- /* start of TC */
-}
-
-static void cleanup(void)
-{
- /* end of TC */
-}
-static void utc_net_nfc_create_record_p(void)
-{
- int ret ;
- ndef_record_h record = NULL;
- data_s* payload = NULL;
- data_s* typeName = NULL;
- uint8_t url[] = "samsung.com";
- uint8_t temp[] = "U";
-
- typeName = calloc(1, sizeof(data_s));
- payload = calloc(1, sizeof(data_s));
-
- typeName->buffer = temp;
- typeName->length = 1;
-
- payload->buffer = url;
- payload->length = 11;
-
- ret = net_nfc_create_record(&record, NET_NFC_RECORD_WELL_KNOWN_TYPE, (data_h)typeName, NULL, (data_h)payload);
-
- net_nfc_free_record(record);
-
- free(payload);
- free(typeName);
- dts_check_eq(__func__, ret, NET_NFC_OK, "net_nfc_create_record is failed");
-}
-
-static void utc_net_nfc_create_record_n(void)
-{
- int ret=0;
-
- ret = net_nfc_create_record( NULL , 0 , NULL , NULL , NULL);
-
- dts_check_ne(__func__, ret, NET_NFC_OK, "net_nfc_create_record not allow null");
-}
-
-static void utc_net_nfc_create_text_type_record_p(void)
-{
- int ret ;
- ndef_record_h record = NULL;
-
- ret = net_nfc_create_text_type_record(&record, "This is real NFC", "en-US", NET_NFC_ENCODE_UTF_8);
-
- net_nfc_free_record(record);
-
- dts_check_eq(__func__, ret, NET_NFC_OK, "net_nfc_create_text_type_record is failed");
-}
-
-static void utc_net_nfc_create_text_type_record_n(void)
-{
- int ret=0;
-
- ret = net_nfc_create_text_type_record( NULL , NULL , NULL , 0 );
-
- dts_check_ne(__func__, ret, NET_NFC_OK, "net_nfc_create_text_type_record not allow null");
-}
-
-static void utc_net_nfc_create_uri_type_record_p(void)
-{
- int ret ;
- ndef_record_h record = NULL;
-
- ret = net_nfc_create_uri_type_record(&record ,"http://www.naver.com", NET_NFC_SCHEMA_FULL_URI);
-
- net_nfc_free_record(record);
-
- dts_check_eq(__func__, ret, NET_NFC_OK, "net_nfc_create_uri_type_record is failed");
-}
-
-static void utc_net_nfc_create_uri_type_record_n(void)
-{
- int ret=0;
-
- ret = net_nfc_create_uri_type_record( NULL , NULL , 0 );
-
- dts_check_ne(__func__, ret, NET_NFC_OK, "net_nfc_create_uri_type_record not allow null");
-}
-
-static void utc_net_nfc_free_record_p(void)
-{
- int ret ;
- ndef_record_h record = NULL;
-
- net_nfc_create_uri_type_record(&record ,"http://www.naver.com", NET_NFC_SCHEMA_FULL_URI);
-
- ret = net_nfc_free_record(record);
-
- dts_check_eq(__func__, ret, NET_NFC_OK, "net_nfc_free_record is failed");
-}
-
-static void utc_net_nfc_free_record_n(void)
-{
- int ret=0;
-
- ret = net_nfc_free_record(NULL);
-
- dts_check_ne(__func__, ret, NET_NFC_OK, "net_nfc_free_record not allow null");
-}
-
-static void utc_net_nfc_get_record_payload_p(void)
-{
- int ret ;
- ndef_record_h record = NULL;
- data_h payload = NULL;
-
- net_nfc_create_uri_type_record(&record ,"http://www.naver.com", NET_NFC_SCHEMA_FULL_URI);
-
- ret = net_nfc_get_record_payload(record, &payload);
-
- net_nfc_free_record(record);
-
- dts_check_eq(__func__, ret, NET_NFC_OK, "net_nfc_get_record_payload is failed");
-}
-
-static void utc_net_nfc_get_record_payload_n(void)
-{
- int ret=0;
-
- ret = net_nfc_get_record_payload(NULL, NULL);
-
- dts_check_ne(__func__, ret, NET_NFC_OK, "net_nfc_get_record_payload not allow null");
-}
-
-static void utc_net_nfc_get_record_type_p(void)
-{
- int ret ;
- ndef_record_h record = NULL;
- data_h record_type = NULL;
-
- net_nfc_create_uri_type_record(&record ,"http://www.naver.com", NET_NFC_SCHEMA_FULL_URI);
-
- ret = net_nfc_get_record_type(record, &record_type);
-
- net_nfc_free_record(record);
-
- dts_check_eq(__func__, ret, NET_NFC_OK, "net_nfc_get_record_type is failed");
-}
-
-static void utc_net_nfc_get_record_type_n(void)
-{
- int ret=0;
-
- ret = net_nfc_get_record_type(NULL, NULL);
-
- dts_check_ne(__func__, ret, NET_NFC_OK, "net_nfc_get_record_type not allow null");
-}
-
-static void utc_net_nfc_set_record_id_p(void)
-{
- int ret ;
- ndef_record_h record = NULL;
- data_s* id = NULL;
- uint8_t temp[] = "test";
-
- net_nfc_create_uri_type_record(&record ,"http://www.naver.com", NET_NFC_SCHEMA_FULL_URI);
-
- id = calloc(1, sizeof(data_s));
- id->buffer = temp;
- id->length = 4;
-
- ret = net_nfc_set_record_id(record, (data_h)id);
-
- net_nfc_free_record(record);
-
- dts_check_eq(__func__, ret, NET_NFC_OK, "net_nfc_set_record_id is failed");
-}
-
-static void utc_net_nfc_set_record_id_n(void)
-{
- int ret=0;
-
- ret = net_nfc_set_record_id(NULL, NULL);
-
- dts_check_ne(__func__, ret, NET_NFC_OK, "net_nfc_set_record_id not allow null");
-}
-
-static void utc_net_nfc_get_record_id_p(void)
-{
- int ret ;
- ndef_record_h record = NULL;
- data_s* id = NULL;
- data_h id_data = NULL;
- uint8_t temp[] = "test";
-
- net_nfc_create_uri_type_record(&record ,"http://www.naver.com", NET_NFC_SCHEMA_FULL_URI);
-
- id = calloc(1, sizeof(data_s));
- id->buffer = temp;
- id->length = 4;
-
- net_nfc_set_record_id(record, (data_h)id);
-
- ret = net_nfc_get_record_id(record, &id_data);
-
- net_nfc_free_record(record);
-
- dts_check_eq(__func__, ret, NET_NFC_OK, "net_nfc_get_record_id is failed");
-}
-
-static void utc_net_nfc_get_record_id_n(void)
-{
- int ret=0;
-
- ret = net_nfc_get_record_id(NULL, NULL);
-
- dts_check_ne(__func__, ret, NET_NFC_OK, "net_nfc_get_record_id not allow null");
-}
-
-static void utc_net_nfc_get_record_tnf_p(void)
-{
- int ret ;
- ndef_record_h record = NULL;
- net_nfc_record_tnf_e* tnf = NULL;
-
- record = calloc( 1 , sizeof(ndef_record_h));
-
- net_nfc_create_uri_type_record(&record ,"http://www.naver.com", NET_NFC_SCHEMA_FULL_URI);
-
- tnf = calloc( 1 , sizeof(net_nfc_record_tnf_e));
-
- ret = net_nfc_get_record_tnf(record, tnf);
-
- net_nfc_free_record(record);
-
- dts_check_eq(__func__, ret, NET_NFC_OK, "net_nfc_get_record_tnf is failed");
-}
-
-static void utc_net_nfc_get_record_tnf_n(void)
-{
- int ret=0;
-
- ret = net_nfc_get_record_tnf(NULL, NULL);
-
- dts_check_ne(__func__, ret, NET_NFC_OK, "net_nfc_get_record_tnf not allow null");
-}
-
-static void utc_net_nfc_get_record_flags_p(void)
-{
- net_nfc_error_e ret=0;
- ndef_record_s* record = NULL;
- uint8_t temp = 0x80;
-
- record = calloc(1, sizeof(ndef_record_s));
-
- net_nfc_create_uri_type_record((ndef_record_h*)&record ,"http://www.naver.com", NET_NFC_SCHEMA_FULL_URI);
-
- ret = net_nfc_get_record_flags((ndef_record_h)record, &temp);
-
- dts_check_eq(__func__, ret, NET_NFC_OK, "net_nfc_get_record_flags is failed");
-}
-
-static void utc_net_nfc_get_record_flags_n(void)
-{
- net_nfc_error_e ret=0;
-
- ret = net_nfc_get_record_flags(NULL, NULL);
-
- dts_check_ne(__func__, ret, NET_NFC_OK, "net_nfc_get_record_flags is failed");
-}
-
-static void utc_net_nfc_get_record_mb_p(void)
-{
- unsigned char ret=0;
- unsigned char flag = 0x80;
-
- ret = net_nfc_get_record_mb (flag);
-
- dts_pass(__func__, "PASS");
-}
-
-static void utc_net_nfc_get_record_mb_n(void)
-{
- unsigned char ret=0;
-
- ret = net_nfc_get_record_mb(0x00);
-
- dts_pass(__func__, "PASS");
-}
-
-static void utc_net_nfc_get_record_me_p(void)
-{
- unsigned char ret=0;
-
- ret = net_nfc_get_record_me(0xff);
-
- dts_pass(__func__, "PASS");
-}
-
-static void utc_net_nfc_get_record_me_n(void)
-{
- unsigned char ret=0;
-
- ret = net_nfc_get_record_me(0xff);
-
- dts_pass(__func__, "PASS");
-}
-
-static void utc_net_nfc_get_record_cf_p(void)
-{
- unsigned char ret=0;
-
- ret = net_nfc_get_record_cf(0xff);
-
- dts_pass(__func__, "PASS");
-}
-
-static void utc_net_nfc_get_record_cf_n(void)
-{
- unsigned char ret=0;
-
- ret = net_nfc_get_record_cf(0xff);
-
- dts_pass(__func__, "PASS");
-}
-
-static void utc_net_nfc_get_record_il_p(void)
-{
- unsigned char ret=0;
-
- ret = net_nfc_get_record_il(0xff);
-
- dts_pass(__func__, "PASS");
-}
-
-static void utc_net_nfc_get_record_il_n(void)
-{
- unsigned char ret=0;
-
- ret = net_nfc_get_record_il(0xff);
-
- dts_pass(__func__, "PASS");
-}
-
-static void utc_net_nfc_get_record_sr_p(void)
-{
- unsigned char ret=0;
-
- ret = net_nfc_get_record_sr (0xff);
-
- dts_pass(__func__, "PASS");
-}
-
-static void utc_net_nfc_get_record_sr_n(void)
-{
- unsigned char ret=0;
-
- ret = net_nfc_get_record_sr(0xff);
-
- dts_pass(__func__, "PASS");
-}
-static void utc_net_nfc_create_text_string_from_text_record_p(void)
-{
- int ret ;
- ndef_record_h record = NULL;
- char *disp_text = NULL;
-
- net_nfc_create_text_type_record(&record, "This is real NFC", "en-US", NET_NFC_ENCODE_UTF_8);
-
- ret = net_nfc_create_text_string_from_text_record (record, &disp_text);
-
- dts_check_eq(__func__, ret, NET_NFC_OK, "net_nfc_create_text_string_from_text_record is failed");
-}
-
-static void utc_net_nfc_create_text_string_from_text_record_n(void)
-{
- int ret ;
-
- ret = net_nfc_create_text_string_from_text_record (NULL, NULL);
-
- dts_check_ne(__func__, ret, NET_NFC_OK, "net_nfc_create_text_string_from_text_record not allow null");
-}
-
-static void utc_net_nfc_get_languange_code_string_from_text_record_p(void)
-{
- int ret ;
- ndef_record_h record = NULL;
- char* language_code_str = NULL;
-
- net_nfc_create_text_type_record(&record, "This is real NFC", "en-US", NET_NFC_ENCODE_UTF_8);
-
- ret = net_nfc_get_languange_code_string_from_text_record (record, &language_code_str);
-
- dts_check_eq(__func__, ret, NET_NFC_OK, "net_nfc_get_languange_code_string_from_text_record is failed");
-}
-
-static void utc_net_nfc_get_languange_code_string_from_text_record_n(void)
-{
- int ret ;
-
- ret = net_nfc_get_languange_code_string_from_text_record (NULL, NULL);
-
- dts_check_ne(__func__, ret, NET_NFC_OK, "net_nfc_get_languange_code_string_from_text_record not allow null");
-}
-
-static void utc_net_nfc_get_encoding_type_from_text_record_p(void)
-{
- int ret ;
- ndef_record_h record = NULL;
- net_nfc_encode_type_e utf;
-
- net_nfc_create_text_type_record(&record, "This is real NFC", "en-US", NET_NFC_ENCODE_UTF_8);
-
- ret = net_nfc_get_encoding_type_from_text_record (record, &utf);
-
- dts_check_eq(__func__, ret, NET_NFC_OK, "net_nfc_get_encoding_type_from_text_record is failed");
-}
-
-static void utc_net_nfc_get_encoding_type_from_text_record_n(void)
-{
- int ret ;
-
- ret = net_nfc_get_encoding_type_from_text_record (NULL, NULL);
-
- dts_check_ne(__func__, ret, NET_NFC_OK, "net_nfc_get_encoding_type_from_text_record not allow null");
-}
-
-static void utc_net_nfc_create_uri_string_from_uri_record_p(void)
-{
- int ret=0;
- ndef_record_h record = NULL;
- char *disp_text = NULL;
-
- net_nfc_create_uri_type_record(&record ,"http://www.naver.com", NET_NFC_SCHEMA_FULL_URI);
-
- net_nfc_create_uri_string_from_uri_record(record, &disp_text);
-
- dts_check_eq(__func__, ret, NET_NFC_OK, "net_nfc_create_uri_string_from_uri_record is failed");
-}
-
-static void utc_net_nfc_create_uri_string_from_uri_record_n(void)
-{
- int ret=0;
-
- ret = net_nfc_create_uri_string_from_uri_record(NULL, NULL);
-
- dts_check_ne(__func__, ret, NET_NFC_OK, "net_nfc_create_uri_string_from_uri_record is failed");
-}
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
-
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-#include <tet_api.h>
-
-#include "net_nfc.h"
-#include "net_nfc_typedef.h"
-#include "net_nfc_util_internal.h"
-
-#ifdef SECURITY_SERVER
-#include <security-server.h>
-#endif
-
-
-enum {
- POSITIVE_TC_IDX = 0x01,
- NEGATIVE_TC_IDX,
-};
-static void startup(void);
-static void cleanup(void);
-
-void (*tet_startup)(void) = startup;
-void (*tet_cleanup)(void) = cleanup;
-
-static void utc_net_nfc_initialize_p(void);
-static void utc_net_nfc_initialize_n(void);
-static void utc_net_nfc_deinitialize_p(void);
-static void utc_net_nfc_deinitialize_n(void);
-static void utc_net_nfc_set_response_callback_p(void);
-static void utc_net_nfc_set_response_callback_n(void);
-static void utc_net_nfc_unset_response_callback_p(void);
-static void utc_net_nfc_unset_response_callback_n(void);
-
-static void net_nfc_test_client_cb(net_nfc_message_e message, net_nfc_error_e result, void* data, void* user_param, void * trans_data )
-{
-};
-
-
-
-struct tet_testlist tet_testlist[] = {
- { utc_net_nfc_initialize_p , POSITIVE_TC_IDX },
- { utc_net_nfc_initialize_n , NEGATIVE_TC_IDX },
- { utc_net_nfc_deinitialize_p, POSITIVE_TC_IDX },
- { utc_net_nfc_deinitialize_n , NEGATIVE_TC_IDX},
- { utc_net_nfc_set_response_callback_p, 1},
- { utc_net_nfc_set_response_callback_n, 2 },
- { utc_net_nfc_unset_response_callback_p, 1},
- { utc_net_nfc_unset_response_callback_n, 2},
- { NULL, 0 },
-};
-
-//this method is called only once in start
-static void startup(void)
-{
- /* start of TC */
-}
-
-static void cleanup(void)
-{
- /* end of TC */
-}
-static void utc_net_nfc_initialize_p(void)
-{
- int ret ;
-
- ret = net_nfc_initialize();
- net_nfc_deinitialize();
-
- dts_pass(__func__, "PASS");
-}
-
-static void utc_net_nfc_initialize_n(void)
-{
- int ret=0;
-
- ret = net_nfc_initialize();
- net_nfc_deinitialize();
-
- dts_pass(__func__, "PASS");
-}
-
-static void utc_net_nfc_deinitialize_p(void)
-{
- int ret ;
-
- net_nfc_initialize();
- ret = net_nfc_deinitialize();
-
- dts_check_eq(__func__, ret, NET_NFC_OK, "net_nfc_deinitialize is failed");
-}
-
-static void utc_net_nfc_deinitialize_n(void)
-{
- int ret=0;
-
- ret = net_nfc_deinitialize();
-
- dts_check_eq(__func__, ret, NET_NFC_OK, "net_nfc_deinitialize not allow null");
-}
-
-static void utc_net_nfc_set_response_callback_p(void)
-{
- int ret ;
- //net_nfc_response_cb cb;
-
- net_nfc_initialize();
-
- ret = net_nfc_set_response_callback(net_nfc_test_client_cb, NULL);
-
- net_nfc_unset_response_callback();
-
- dts_check_eq(__func__, ret, NET_NFC_OK, "net_nfc_set_response_callback is failed");
-}
-
-static void utc_net_nfc_set_response_callback_n(void)
-{
- int ret=0;
-
- ret = net_nfc_set_response_callback(NULL, NULL);
-
- dts_check_ne(__func__, ret, NET_NFC_OK, "net_nfc_set_response_callback not allow null");
-}
-
-static void utc_net_nfc_unset_response_callback_p(void)
-{
- int ret ;
- //net_nfc_response_cb cb;
-
- net_nfc_initialize();
-
- net_nfc_set_response_callback(net_nfc_test_client_cb, NULL);
-
- ret = net_nfc_unset_response_callback();
-
- net_nfc_deinitialize();
-
- dts_check_eq(__func__, ret, NET_NFC_OK, "net_nfc_unset_response_callback is failed");
-}
-
-static void utc_net_nfc_unset_response_callback_n(void)
-{
- int ret=0;
-
- ret = net_nfc_unset_response_callback();
-
- dts_check_ne(__func__, ret, NET_NFC_OK, "net_nfc_unset_response_callback not allow null");
-}
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
-
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-#include <tet_api.h>
-#include <stdint.h>
-
-#include "net_nfc_typedef_internal.h"
-#include "net_nfc_util_internal.h"
-#include "net_nfc.h"
-
-
-enum {
- POSITIVE_TC_IDX = 0x01,
- NEGATIVE_TC_IDX,
-};
-static void startup(void);
-static void cleanup(void);
-
-void (*tet_startup)(void) = startup;
-void (*tet_cleanup)(void) = cleanup;
-
-static void utc_net_nfc_format_ndef_p(void);
-static void utc_net_nfc_format_ndef_n(void);
-static void utc_net_nfc_set_tag_filter_p(void);
-static void utc_net_nfc_set_tag_filter_n(void);
-static void utc_net_nfc_get_tag_filter_p(void);
-static void utc_net_nfc_get_tag_filter_n(void);
-static void utc_net_nfc_transceive_p(void);
-static void utc_net_nfc_transceive_n(void);
-static void utc_net_nfc_read_ndef_p(void);
-static void utc_net_nfc_read_ndef_n(void);
-static void utc_net_nfc_write_ndef_p(void);
-static void utc_net_nfc_write_ndef_n(void);
-static void utc_net_nfc_make_read_only_ndef_tag_p(void);
-static void utc_net_nfc_make_read_only_ndef_tag_n(void);
-
-
-struct tet_testlist tet_testlist[] = {
- { utc_net_nfc_format_ndef_p , POSITIVE_TC_IDX },
- { utc_net_nfc_format_ndef_n , NEGATIVE_TC_IDX },
- { utc_net_nfc_set_tag_filter_p, POSITIVE_TC_IDX },
- { utc_net_nfc_set_tag_filter_n , NEGATIVE_TC_IDX},
- { utc_net_nfc_get_tag_filter_p, 1},
- { utc_net_nfc_get_tag_filter_n, 2 },
- { utc_net_nfc_transceive_p, 1},
- { utc_net_nfc_transceive_n, 2},
- { utc_net_nfc_read_ndef_p, 1},
- { utc_net_nfc_read_ndef_n, 2},
- { utc_net_nfc_write_ndef_p, 1},
- { utc_net_nfc_write_ndef_n, 2},
- { utc_net_nfc_make_read_only_ndef_tag_p, 1},
- { utc_net_nfc_make_read_only_ndef_tag_n, 2},
- { NULL, 0 },
-};
-
-//this method is called only once in start
-static void startup(void)
-{
- /* start of TC */
-}
-
-static void cleanup(void)
-{
- /* end of TC */
-}
-
-static void utc_net_nfc_format_ndef_p(void)
-{
- int ret=0;
- data_h key;
- uint8_t data [] = {0xff,0xff,0xff,0xff,0xff,0xff};
-
- net_nfc_initialize();
-
- net_nfc_create_data (&key, data, 6);
-
- ret = net_nfc_format_ndef((net_nfc_target_handle_h) 0x302023, key, NULL);
-
- net_nfc_deinitialize();
-
- dts_pass(__func__, "PASS");
-}
-
-static void utc_net_nfc_format_ndef_n(void)
-{
- int ret=0;
-
- ret = net_nfc_format_ndef(NULL, NULL, NULL);
-
- dts_pass(__func__, "PASS");
-}
-
-static void utc_net_nfc_set_tag_filter_p(void)
-{
- int ret=0;
-
- net_nfc_initialize();
-
- ret = net_nfc_set_tag_filter(NET_NFC_ISO14443A_ENABLE);
-
- net_nfc_deinitialize();
-
- dts_pass(__func__, "PASS");
-}
-
-static void utc_net_nfc_set_tag_filter_n(void)
-{
- int ret=0;
- net_nfc_event_filter_e config = NET_NFC_ALL_ENABLE;
-
- ret = net_nfc_set_tag_filter(config);
-
- dts_pass(__func__, "PASS");
-}
-
-static void utc_net_nfc_get_tag_filter_p(void)
-{
- net_nfc_event_filter_e ret=0;
-
- net_nfc_initialize();
-
- net_nfc_set_tag_filter(NET_NFC_ISO14443A_ENABLE);
-
- ret = net_nfc_get_tag_filter();
-
- net_nfc_deinitialize();
-
- dts_pass(__func__, "PASS");
-}
-
-static void utc_net_nfc_get_tag_filter_n(void)
-{
- net_nfc_event_filter_e ret=0;
-
- ret = net_nfc_get_tag_filter();
-
- dts_pass(__func__, "PASS");
-}
-
-static void utc_net_nfc_transceive_p(void)
-{
- int ret ;
- net_nfc_target_handle_h handle = NULL;
- void* trans_param = NULL;
- unsigned char send_buffer[6] = {0x00, };
-
- send_buffer[0] = 0x06;
- send_buffer[1] = 0x00;
-
- // use wild card for system code
- send_buffer[2] = 0xff;
- send_buffer[3] = 0xff;
-
- send_buffer[4] = 0xff;
- send_buffer[5] = 0xff;
-
- data_s rawdata;
-
- rawdata.buffer = send_buffer;
- rawdata.length = 6;
-
- ret = net_nfc_transceive(handle, (data_h)&rawdata, trans_param);
-
- dts_pass(__func__, "PASS");
-}
-
-static void utc_net_nfc_transceive_n(void)
-{
- int ret ;
-
- ret = net_nfc_transceive(NULL, NULL, NULL);
-
- dts_pass(__func__, "PASS");
-}
-
-static void utc_net_nfc_read_ndef_p(void)
-{
- int ret ;
-
- ret = net_nfc_read_tag((net_nfc_target_handle_h) 0x302023, NULL);
-
- dts_pass(__func__, "PASS");
-}
-
-static void utc_net_nfc_read_ndef_n(void)
-{
- int ret ;
-
- ret = net_nfc_read_tag(NULL, NULL);
-
- dts_pass(__func__, "PASS");
-}
-
-static void utc_net_nfc_write_ndef_p(void)
-{
- int ret ;
- ndef_message_h message = NULL;
- ndef_record_h record = NULL;
-
- net_nfc_initialize();
-
- net_nfc_create_ndef_message (&message);
- net_nfc_create_text_type_record (&record, "abc" ,"en-US" ,NET_NFC_ENCODE_UTF_8);
- net_nfc_append_record_to_ndef_message (message ,record);
-
- ret = net_nfc_write_ndef ((net_nfc_target_handle_h)0x302023 ,message ,NULL);
-
- net_nfc_deinitialize();
-
- dts_pass(__func__, "PASS");
-}
-
-static void utc_net_nfc_write_ndef_n(void)
-{
- int ret ;
-
- ret = net_nfc_write_ndef(NULL, NULL , NULL);
-
- dts_pass(__func__, "PASS");
-}
-
-static void utc_net_nfc_make_read_only_ndef_tag_p(void)
-{
- int ret ;
-
- net_nfc_initialize();
-
- ret = net_nfc_make_read_only_ndef_tag ((net_nfc_target_handle_h)0x302023 , NULL);
-
- net_nfc_deinitialize();
-
- dts_pass(__func__, "PASS");
-}
-
-static void utc_net_nfc_make_read_only_ndef_tag_n(void)
-{
- int ret;
-
- ret = net_nfc_make_read_only_ndef_tag(NULL , NULL);
-
- dts_pass(__func__, "PASS");
-}
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
-
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-#include <tet_api.h>
-
-#include "net_nfc_ndef_record.h"
-#include "net_nfc_ndef_message.h"
-#include "net_nfc_util_internal.h"
-#include "net_nfc_data.h"
-#include "net_nfc.h"
-#include "net_nfc_tag_felica.h"
-
-
-enum {
- POSITIVE_TC_IDX = 0x01,
- NEGATIVE_TC_IDX,
-};
-static void startup(void);
-static void cleanup(void);
-
-void (*tet_startup)(void) = startup;
-void (*tet_cleanup)(void) = cleanup;
-
-static void utc_net_nfc_felica_poll_p(void);
-static void utc_net_nfc_felica_poll_n(void);
-static void utc_net_nfc_felica_request_service_p(void);
-static void utc_net_nfc_felica_request_service_n(void);
-static void utc_net_nfc_felica_request_response_p(void);
-static void utc_net_nfc_felica_request_response_n(void);
-static void utc_net_nfc_felica_read_without_encryption_p(void);
-static void utc_net_nfc_felica_read_without_encryption_n(void);
-static void utc_net_nfc_felica_write_without_encryption_p(void);
-static void utc_net_nfc_felica_write_without_encryption_n(void);
-static void utc_net_nfc_felica_request_system_code_p(void);
-static void utc_net_nfc_felica_request_system_code_n(void);
-
-
-struct tet_testlist tet_testlist[] = {
- { utc_net_nfc_felica_poll_p , POSITIVE_TC_IDX },
- { utc_net_nfc_felica_poll_n , NEGATIVE_TC_IDX },
- { utc_net_nfc_felica_request_service_p, POSITIVE_TC_IDX },
- { utc_net_nfc_felica_request_service_n , NEGATIVE_TC_IDX},
- { utc_net_nfc_felica_request_response_p, 1},
- { utc_net_nfc_felica_request_response_n, 2 },
- { utc_net_nfc_felica_read_without_encryption_p, 1},
- { utc_net_nfc_felica_read_without_encryption_n, 2},
- { utc_net_nfc_felica_write_without_encryption_p, 1},
- { utc_net_nfc_felica_write_without_encryption_n, 2},
- { utc_net_nfc_felica_request_system_code_p, 1},
- { utc_net_nfc_felica_request_system_code_n, 2},
- { NULL, 0 },
-};
-
-//this method is called only once in start
-static void startup(void)
-{
- /* start of TC */
-}
-
-static void cleanup(void)
-{
- /* end of TC */
-}
-
-static void utc_net_nfc_felica_poll_p(void)
-{
- int ret=0;
-
- net_nfc_initialize();
-
- ret = net_nfc_felica_poll((net_nfc_target_handle_h) 0x302023, NET_NFC_FELICA_POLL_COMM_SPEED_REQUEST , 0x0 , NULL);
-
- net_nfc_deinitialize();
-
- dts_pass(__func__, "PASS");
-}
-
-static void utc_net_nfc_felica_poll_n(void)
-{
- int ret=0;
- uint8_t temp[]= "a";
-
- ret = net_nfc_felica_poll(NULL , NET_NFC_FELICA_POLL_NO_REQUEST , temp[0] , NULL);
-
- dts_pass(__func__, "PASS");
-}
-
-static void utc_net_nfc_felica_request_service_p(void)
-{
- int ret=0;
- unsigned short service_code = 0xffff;
-
- net_nfc_initialize();
-
- net_nfc_felica_poll((net_nfc_target_handle_h) 0x302023, NET_NFC_FELICA_POLL_COMM_SPEED_REQUEST , 0x0 , NULL);
-
- ret = net_nfc_felica_request_service((net_nfc_target_handle_h) 0x302023 , 1 , &service_code , 1 , NULL);
-
- net_nfc_deinitialize();
-
- dts_pass(__func__, "PASS");
-}
-
-static void utc_net_nfc_felica_request_service_n(void)
-{
- int ret=0;
-
- ret = net_nfc_felica_request_service(NULL , 1 , NULL , 1, NULL);
-
- dts_pass(__func__, "PASS");
-}
-
-static void utc_net_nfc_felica_request_response_p(void)
-{
- int ret=0;
-
- net_nfc_initialize();
-
- net_nfc_felica_poll((net_nfc_target_handle_h) 0x302023, NET_NFC_FELICA_POLL_COMM_SPEED_REQUEST , 0x0 , NULL);
-
- ret = net_nfc_felica_request_response((net_nfc_target_handle_h) 0x302023 , NULL);
-
- net_nfc_deinitialize();
-
- dts_pass(__func__, "PASS");
-}
-
-static void utc_net_nfc_felica_request_response_n(void)
-{
- int ret=0;
-
- ret = net_nfc_felica_request_response( NULL , NULL );
-
- dts_pass(__func__, "PASS");
-}
-
-static void utc_net_nfc_felica_read_without_encryption_p(void)
-{
- int ret=0;
- unsigned short service_code = 0xffff;
- unsigned char blocks = 0x2;
-
- net_nfc_initialize();
-
- net_nfc_felica_poll((net_nfc_target_handle_h) 0x302023, NET_NFC_FELICA_POLL_COMM_SPEED_REQUEST , 0x0 , NULL);
-
- ret = net_nfc_felica_read_without_encryption((net_nfc_target_handle_h) 0x302023, 1, &service_code, 1, &blocks, NULL);
-
- net_nfc_deinitialize();
-
- dts_pass(__func__, "PASS");
-}
-
-static void utc_net_nfc_felica_read_without_encryption_n(void)
-{
- int ret=0;
-
- ret = net_nfc_felica_read_without_encryption(NULL, 1, NULL, 1, NULL, NULL);
-
- dts_pass(__func__, "PASS");
-}
-
-static void utc_net_nfc_felica_write_without_encryption_p(void)
-{
- int ret=0;
- unsigned short service_code = 0xffff;
- unsigned char blocks = 0x2;
- unsigned char send_buffer[6] = {0x00, };
-
- send_buffer[0] = 0x06;
- send_buffer[1] = 0x00;
-
- // use wild card for system code
- send_buffer[2] = 0xff;
- send_buffer[3] = 0xff;
-
- send_buffer[4] = 0xff;
- send_buffer[5] = 0xff;
-
- data_h rawdata = NULL;
-
- rawdata = calloc(1,sizeof(data_h));
-
- net_nfc_initialize();
-
- net_nfc_felica_poll((net_nfc_target_handle_h) 0x302023, NET_NFC_FELICA_POLL_COMM_SPEED_REQUEST , 0x0 , NULL);
-
- ret = net_nfc_felica_write_without_encryption((net_nfc_target_handle_h) 0x302023, 1, &service_code, 1, &blocks, rawdata , NULL);
-
- net_nfc_deinitialize();
-
- dts_pass(__func__, "PASS");
-}
-
-static void utc_net_nfc_felica_write_without_encryption_n(void)
-{
- int ret=0;
-
- ret = net_nfc_felica_write_without_encryption(NULL, 1, NULL, 1, NULL, NULL , NULL);
-
- dts_pass(__func__, "PASS");
-}
-
-static void utc_net_nfc_felica_request_system_code_p(void)
-{
- int ret=0;
- //unsigned short service_code = 0xffff;
- //unsigned char blocks = 0x2;
-
- net_nfc_initialize();
-
- net_nfc_felica_poll((net_nfc_target_handle_h) 0x302023, NET_NFC_FELICA_POLL_COMM_SPEED_REQUEST , 0x0 , NULL);
-
- ret = net_nfc_felica_request_system_code((net_nfc_target_handle_h) 0x302023 , NULL);
-
- net_nfc_deinitialize();
-
- dts_pass(__func__, "PASS");
-}
-
-static void utc_net_nfc_felica_request_system_code_n(void)
-{
- int ret=0;
-
- ret = net_nfc_felica_request_system_code(NULL, NULL);
-
- dts_pass(__func__, "PASS");
-}
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
-
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-#include <tet_api.h>
-
-#include "net_nfc_tag.h"
-#include "net_nfc_typedef_internal.h"
-#include "net_nfc_util_internal.h"
-#include "net_nfc_tag_jewel.h"
-#include "net_nfc_target_info.h"
-#include "net_nfc.h"
-
-#include <string.h>
-
-
-enum {
- POSITIVE_TC_IDX = 0x01,
- NEGATIVE_TC_IDX,
-};
-static void startup(void);
-static void cleanup(void);
-
-void (*tet_startup)(void) = startup;
-void (*tet_cleanup)(void) = cleanup;
-
-static void utc_net_nfc_jewel_read_id_p(void);
-static void utc_net_nfc_jewel_read_id_n(void);
-static void utc_net_nfc_jewel_read_byte_p(void);
-static void utc_net_nfc_jewel_read_byte_n(void);
-static void utc_net_nfc_jewel_read_all_p(void);
-static void utc_net_nfc_jewel_read_all_n(void);
-static void utc_net_nfc_jewel_write_with_erase_p(void);
-static void utc_net_nfc_jewel_write_with_erase_n(void);
-static void utc_net_nfc_jewel_write_with_no_erase_p(void);
-static void utc_net_nfc_jewel_write_with_no_erase_n(void);
-
-
-struct tet_testlist tet_testlist[] = {
- { utc_net_nfc_jewel_read_id_p , POSITIVE_TC_IDX },
- { utc_net_nfc_jewel_read_id_n , NEGATIVE_TC_IDX },
- { utc_net_nfc_jewel_read_byte_p, POSITIVE_TC_IDX },
- { utc_net_nfc_jewel_read_byte_n , NEGATIVE_TC_IDX},
- { utc_net_nfc_jewel_read_all_p, 1},
- { utc_net_nfc_jewel_read_all_n, 2 },
- { utc_net_nfc_jewel_write_with_erase_p, 1},
- { utc_net_nfc_jewel_write_with_erase_n, 2},
- { utc_net_nfc_jewel_write_with_no_erase_p, 1},
- { utc_net_nfc_jewel_write_with_no_erase_n, 2},
- { NULL, 0 },
-};
-
-//this method is called only once in start
-static void startup(void)
-{
- /* start of TC */
-}
-
-static void cleanup(void)
-{
- /* end of TC */
-}
-
-static void utc_net_nfc_jewel_read_id_p(void)
-{
- int ret=0;
-
- net_nfc_initialize();
-
- ret = net_nfc_jewel_read_id((net_nfc_target_handle_h) 0x302023, NULL);
-
- net_nfc_deinitialize();
-
- dts_pass(__func__, "PASS");
-}
-
-static void utc_net_nfc_jewel_read_id_n(void)
-{
- int ret=0;
-
- ret = net_nfc_jewel_read_id(NULL , NULL );
-
- dts_pass(__func__, "PASS");
-}
-
-static void utc_net_nfc_jewel_read_byte_p(void)
-{
- int ret=0;
-
- net_nfc_initialize();
-
- ret = net_nfc_jewel_read_byte((net_nfc_target_handle_h) 0x302023 , 1 , 0 , NULL);
-
- net_nfc_deinitialize();
-
- dts_pass(__func__, "PASS");
-}
-
-static void utc_net_nfc_jewel_read_byte_n(void)
-{
- int ret=0;
-
- ret = net_nfc_jewel_read_byte(NULL , 0 , 0 , NULL);
-
- dts_pass(__func__, "PASS");
-}
-
-static void utc_net_nfc_jewel_read_all_p(void)
-{
- int ret=0;
-
- net_nfc_initialize();
-
- ret = net_nfc_jewel_read_all((net_nfc_target_handle_h) 0x302023 , NULL);
-
- net_nfc_deinitialize();
-
- dts_pass(__func__, "PASS");
-}
-
-static void utc_net_nfc_jewel_read_all_n(void)
-{
- int ret=0;
-
- ret = net_nfc_jewel_read_all( NULL , NULL );
-
- dts_pass(__func__, "PASS");
-}
-
-static void utc_net_nfc_jewel_write_with_erase_p(void)
-{
- int ret=0;
-
- net_nfc_initialize();
-
- ret = net_nfc_jewel_write_with_erase((net_nfc_target_handle_h) 0x302023 , 1 , 0 , 0xff , NULL);
-
- net_nfc_deinitialize();
-
- dts_pass(__func__, "PASS");
-}
-
-static void utc_net_nfc_jewel_write_with_erase_n(void)
-{
- int ret=0;
-
- ret = net_nfc_jewel_write_with_erase(NULL, 0, 0, 0xff, NULL);
-
- dts_pass(__func__, "PASS");
-}
-
-static void utc_net_nfc_jewel_write_with_no_erase_p(void)
-{
- int ret=0;
-
- net_nfc_initialize();
-
- ret = net_nfc_jewel_write_with_no_erase((net_nfc_target_handle_h) 0x302023 , 1 , 0 , 0xff , NULL);
-
- net_nfc_deinitialize();
-
- dts_pass(__func__, "PASS");
-}
-
-static void utc_net_nfc_jewel_write_with_no_erase_n(void)
-{
- int ret=0;
-
- ret = net_nfc_jewel_write_with_no_erase(NULL, 0, 0, 0xff, NULL);
-
- dts_pass(__func__, "PASS");
-}
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
-
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-#include <tet_api.h>
-
-#include "net_nfc_tag.h"
-#include "net_nfc_typedef_internal.h"
-#include "net_nfc_util_internal.h"
-#include "net_nfc_tag_jewel.h"
-#include "net_nfc_target_info.h"
-#include "net_nfc.h"
-
-#include <string.h>
-
-
-enum {
- POSITIVE_TC_IDX = 0x01,
- NEGATIVE_TC_IDX,
-};
-static void startup(void);
-static void cleanup(void);
-
-void (*tet_startup)(void) = startup;
-void (*tet_cleanup)(void) = cleanup;
-
-static void utc_net_nfc_mifare_create_default_key_p(void);
-static void utc_net_nfc_mifare_create_default_key_n(void);
-static void utc_net_nfc_mifare_create_application_directory_key_p(void);
-static void utc_net_nfc_mifare_create_application_directory_key_n(void);
-static void utc_net_nfc_mifare_create_net_nfc_forum_key_p(void);
-static void utc_net_nfc_mifare_create_net_nfc_forum_key_n(void);
-static void utc_net_nfc_mifare_authenticate_with_keyA_p(void);
-static void utc_net_nfc_mifare_authenticate_with_keyA_n(void);
-static void utc_net_nfc_mifare_authenticate_with_keyB_p(void);
-static void utc_net_nfc_mifare_authenticate_with_keyB_n(void);
-static void utc_net_nfc_mifare_read_p(void);
-static void utc_net_nfc_mifare_read_n(void);
-static void utc_net_nfc_mifare_write_block_p(void);
-static void utc_net_nfc_mifare_write_block_n(void);
-static void utc_net_nfc_mifare_write_page_p(void);
-static void utc_net_nfc_mifare_write_page_n(void);
-static void utc_net_nfc_mifare_increment_p(void);
-static void utc_net_nfc_mifare_increment_n(void);
-static void utc_net_nfc_mifare_decrement_p(void);
-static void utc_net_nfc_mifare_decrement_n(void);
-static void utc_net_nfc_mifare_transfer_p(void);
-static void utc_net_nfc_mifare_transfer_n(void);
-static void utc_net_nfc_mifare_restore_p(void);
-static void utc_net_nfc_mifare_restore_n(void);
-
-
-
-struct tet_testlist tet_testlist[] = {
- { utc_net_nfc_mifare_create_default_key_p , POSITIVE_TC_IDX },
- { utc_net_nfc_mifare_create_default_key_n , NEGATIVE_TC_IDX },
- { utc_net_nfc_mifare_create_application_directory_key_p, POSITIVE_TC_IDX },
- { utc_net_nfc_mifare_create_application_directory_key_n , NEGATIVE_TC_IDX},
- { utc_net_nfc_mifare_create_net_nfc_forum_key_p, 1},
- { utc_net_nfc_mifare_create_net_nfc_forum_key_n, 2 },
- { utc_net_nfc_mifare_authenticate_with_keyA_p, 1},
- { utc_net_nfc_mifare_authenticate_with_keyA_n, 2},
- { utc_net_nfc_mifare_authenticate_with_keyB_p, 1},
- { utc_net_nfc_mifare_authenticate_with_keyB_n, 2},
- { utc_net_nfc_mifare_read_p, 1},
- { utc_net_nfc_mifare_read_n, 2},
- { utc_net_nfc_mifare_write_block_p, 1},
- { utc_net_nfc_mifare_write_block_n, 2},
- { utc_net_nfc_mifare_write_page_p, 1},
- { utc_net_nfc_mifare_write_page_n, 2},
- { utc_net_nfc_mifare_increment_p, 1},
- { utc_net_nfc_mifare_increment_n, 2},
- { utc_net_nfc_mifare_decrement_p, 1},
- { utc_net_nfc_mifare_decrement_n, 2},
- { utc_net_nfc_mifare_transfer_p, 1},
- { utc_net_nfc_mifare_transfer_n, 2},
- { utc_net_nfc_mifare_restore_p, 1},
- { utc_net_nfc_mifare_restore_n, 2},
- { NULL, 0 },
-};
-
-//this method is called only once in start
-static void startup(void)
-{
- /* start of TC */
-}
-
-static void cleanup(void)
-{
- /* end of TC */
-}
-
-static void utc_net_nfc_mifare_create_default_key_p(void)
-{
- int ret=0;
- data_h default_key = NULL;
-
- net_nfc_initialize();
-
- ret = net_nfc_mifare_create_default_key(&default_key);
-
- net_nfc_deinitialize();
-
- dts_pass(__func__, "PASS");
-}
-
-static void utc_net_nfc_mifare_create_default_key_n(void)
-{
- int ret=0;
-
- ret = net_nfc_mifare_create_default_key(NULL);
-
- dts_pass(__func__, "PASS");
-}
-
-static void utc_net_nfc_mifare_create_application_directory_key_p(void)
-{
- int ret=0;
- data_h mad_key = NULL;
-
- net_nfc_initialize();
-
- ret = net_nfc_mifare_create_application_directory_key(&mad_key);
-
- net_nfc_deinitialize();
-
- dts_pass(__func__, "PASS");
-}
-
-static void utc_net_nfc_mifare_create_application_directory_key_n(void)
-{
- int ret=0;
-
- ret = net_nfc_mifare_create_application_directory_key(NULL);
-
- dts_pass(__func__, "PASS");
-}
-
-static void utc_net_nfc_mifare_create_net_nfc_forum_key_p(void)
-{
- int ret=0;
- data_h net_nfc_forum_key = NULL;
-
- net_nfc_initialize();
-
- ret = net_nfc_mifare_create_net_nfc_forum_key(&net_nfc_forum_key);
-
- net_nfc_deinitialize();
-
- dts_pass(__func__, "PASS");
-}
-
-static void utc_net_nfc_mifare_create_net_nfc_forum_key_n(void)
-{
- int ret=0;
-
- ret = net_nfc_mifare_create_net_nfc_forum_key( NULL );
-
- dts_pass(__func__, "PASS");
-}
-
-static void utc_net_nfc_mifare_authenticate_with_keyA_p(void)
-{
- data_h default_key = NULL;
- int sector = 1;
- data_h key = NULL;
-
- net_nfc_initialize();
-
- net_nfc_mifare_create_default_key(&default_key);
-
- key = default_key;
-
- net_nfc_mifare_authenticate_with_keyA((net_nfc_target_handle_h) 0x302023, sector, default_key, NULL);
-
- net_nfc_deinitialize();
-
- dts_pass(__func__, "PASS");
-}
-
-static void utc_net_nfc_mifare_authenticate_with_keyA_n(void)
-{
- int ret=0;
-
- ret = net_nfc_mifare_authenticate_with_keyA(NULL , 0 , NULL , NULL);
-
- dts_pass(__func__, "PASS");
-}
-
-static void utc_net_nfc_mifare_authenticate_with_keyB_p(void)
-{
- data_h default_key = NULL;
- int sector = 1;
- data_h key = NULL;
-
- net_nfc_initialize();
-
- net_nfc_mifare_create_default_key(&default_key);
-
- key = default_key;
-
- net_nfc_mifare_authenticate_with_keyB((net_nfc_target_handle_h) 0x302023, sector, key, NULL);
-
- net_nfc_deinitialize();
-
- dts_pass(__func__, "PASS");
-}
-
-static void utc_net_nfc_mifare_authenticate_with_keyB_n(void)
-{
- int ret=0;
-
- ret = net_nfc_mifare_authenticate_with_keyB(NULL , 0 , NULL , NULL);
-
- dts_pass(__func__, "PASS");
-}
-
-static void utc_net_nfc_mifare_read_p(void)
-{
- net_nfc_initialize();
-
- net_nfc_mifare_read((net_nfc_target_handle_h) 0x302023 , 5, NULL);
-
- net_nfc_deinitialize();
-
- dts_pass(__func__, "PASS");
-}
-
-static void utc_net_nfc_mifare_read_n(void)
-{
- int ret=0;
-
- ret = net_nfc_mifare_read(NULL , 0 , NULL);
-
- dts_pass(__func__, "PASS");
-}
-
-static void utc_net_nfc_mifare_write_block_p(void)
-{
- net_nfc_initialize();
-
- net_nfc_mifare_write_block((net_nfc_target_handle_h) 0x302023 , 5, NULL , NULL);
-
- net_nfc_deinitialize();
-
- dts_pass(__func__, "PASS");
-}
-
-static void utc_net_nfc_mifare_write_block_n(void)
-{
- int ret=0;
-
- ret = net_nfc_mifare_write_block(NULL , 0 , NULL , NULL);
-
- dts_pass(__func__, "PASS");
-}
-
-static void utc_net_nfc_mifare_write_page_p(void)
-{
- net_nfc_initialize();
-
- net_nfc_mifare_write_block((net_nfc_target_handle_h) 0x302023 , 5, NULL , NULL);
-
- net_nfc_deinitialize();
-
- dts_pass(__func__, "PASS");
-}
-
-static void utc_net_nfc_mifare_write_page_n(void)
-{
- int ret=0;
-
- ret = net_nfc_mifare_write_block(NULL , 0 , NULL , NULL);
-
- dts_pass(__func__, "PASS");
-}
-
-static void utc_net_nfc_mifare_increment_p(void)
-{
- net_nfc_initialize();
-
- net_nfc_mifare_increment((net_nfc_target_handle_h) 0x302023 , 5 , 0 , NULL);
-
- net_nfc_deinitialize();
-
- dts_pass(__func__, "PASS");
-}
-
-static void utc_net_nfc_mifare_increment_n(void)
-{
- int ret=0;
-
- ret = net_nfc_mifare_increment(NULL , 5 , 0 , NULL);
-
- dts_pass(__func__, "PASS");
-}
-
-static void utc_net_nfc_mifare_decrement_p(void)
-{
- net_nfc_initialize();
-
- net_nfc_mifare_decrement((net_nfc_target_handle_h) 0x302023 , 5 , 0 , NULL);
-
- net_nfc_deinitialize();
-
- dts_pass(__func__, "PASS");
-}
-
-static void utc_net_nfc_mifare_decrement_n(void)
-{
- int ret=0;
-
- ret = net_nfc_mifare_decrement(NULL , 5 , 0 , NULL);
-
- dts_pass(__func__, "PASS");
-}
-
-static void utc_net_nfc_mifare_transfer_p(void)
-{
- net_nfc_initialize();
-
- net_nfc_mifare_transfer((net_nfc_target_handle_h) 0x302023 , 5, NULL);
-
- net_nfc_deinitialize();
-
- dts_pass(__func__, "PASS");
-}
-
-static void utc_net_nfc_mifare_transfer_n(void)
-{
- int ret=0;
-
- ret = net_nfc_mifare_transfer(NULL , 5 , NULL);
-
- dts_pass(__func__, "PASS");
-}
-
-static void utc_net_nfc_mifare_restore_p(void)
-{
- net_nfc_initialize();
-
- net_nfc_mifare_restore((net_nfc_target_handle_h) 0x302023 , 5, NULL);
-
- net_nfc_deinitialize();
-
- dts_pass(__func__, "PASS");
-}
-
-static void utc_net_nfc_mifare_restore_n(void)
-{
- int ret=0;
-
- ret = net_nfc_mifare_restore(NULL , 5 , NULL);
-
- dts_pass(__func__, "PASS");
-}
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
-
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-#include <tet_api.h>
-
-#include "net_nfc_typedef.h"
-#include "net_nfc_typedef_internal.h"
-#include "net_nfc_target_info.h"
-#include "net_nfc_data.h"
-#include <stdbool.h>
-#include "net_nfc.h"
-
-enum {
- POSITIVE_TC_IDX = 0x01,
- NEGATIVE_TC_IDX,
-};
-static void startup(void);
-static void cleanup(void);
-
-void (*tet_startup)(void) = startup;
-void (*tet_cleanup)(void) = cleanup;
-
-static void utc_net_nfc_get_tag_type_p(void);
-static void utc_net_nfc_get_tag_type_n(void);
-static void utc_net_nfc_get_tag_handle_p(void);
-static void utc_net_nfc_get_tag_handle_n(void);
-static void utc_net_nfc_get_tag_ndef_support_p(void);
-static void utc_net_nfc_get_tag_ndef_support_n(void);
-static void utc_net_nfc_get_tag_max_data_size_p(void);
-static void utc_net_nfc_get_tag_max_data_size_n(void);
-static void utc_net_nfc_get_tag_actual_data_size_p(void);
-static void utc_net_nfc_get_tag_actual_data_size_n(void);
-static void utc_net_nfc_get_tag_info_keys_p(void);
-static void utc_net_nfc_get_tag_info_keys_n(void);
-static void utc_net_nfc_get_tag_info_value_p(void);
-static void utc_net_nfc_get_tag_info_value_n(void);
-
-
-struct tet_testlist tet_testlist[] = {
- { utc_net_nfc_get_tag_type_p , POSITIVE_TC_IDX },
- { utc_net_nfc_get_tag_type_n , NEGATIVE_TC_IDX },
- { utc_net_nfc_get_tag_handle_p, POSITIVE_TC_IDX },
- { utc_net_nfc_get_tag_handle_n , NEGATIVE_TC_IDX},
- { utc_net_nfc_get_tag_ndef_support_p, 1},
- { utc_net_nfc_get_tag_ndef_support_n, 2 },
- { utc_net_nfc_get_tag_max_data_size_p, 1},
- { utc_net_nfc_get_tag_max_data_size_n, 2},
- { utc_net_nfc_get_tag_actual_data_size_p, 1},
- { utc_net_nfc_get_tag_actual_data_size_n, 2},
- { utc_net_nfc_get_tag_info_keys_p, 1},
- { utc_net_nfc_get_tag_info_keys_n, 2},
- { utc_net_nfc_get_tag_info_value_p, 1},
- { utc_net_nfc_get_tag_info_value_n, 2},
- { NULL, 0 },
-};
-
-//this method is called only once in start
-static void startup(void)
-{
- /* start of TC */
-}
-
-static void cleanup(void)
-{
- /* end of TC */
-}
-
-static void utc_net_nfc_get_tag_type_p(void)
-{
- int ret=0;
- net_nfc_target_info_s* target_info;
- net_nfc_target_type_e type;
-
- target_info = calloc(1, sizeof(net_nfc_target_info_s));
-
- target_info->devType = NET_NFC_GENERIC_PICC;
-
- net_nfc_initialize();
-
- ret = net_nfc_get_tag_type((net_nfc_target_info_h)target_info , &type);
-
- net_nfc_deinitialize();
-
- free(target_info);
-
- dts_pass(__func__, "PASS");
-}
-
-static void utc_net_nfc_get_tag_type_n(void)
-{
- int ret=0;
-
- ret = net_nfc_get_tag_type(NULL , NULL);
-
- dts_pass(__func__, "PASS");
-}
-
-static void utc_net_nfc_get_tag_handle_p(void)
-{
- int ret=0;
- net_nfc_target_info_s* target_info;
- net_nfc_target_handle_h id;
-
- target_info = calloc(1, sizeof(net_nfc_target_info_s));
-
- target_info->handle = (net_nfc_target_handle_s*)0x302023;
-
- net_nfc_initialize();
-
- ret = net_nfc_get_tag_handle((net_nfc_target_info_h)target_info , &id);
-
- net_nfc_deinitialize();
-
- dts_pass(__func__, "PASS");
-}
-
-static void utc_net_nfc_get_tag_handle_n(void)
-{
- int ret=0;
-
- ret = net_nfc_get_tag_handle(NULL , NULL);
-
- dts_pass(__func__, "PASS");
-}
-
-static void utc_net_nfc_get_tag_ndef_support_p(void)
-{
- int ret=0;
- net_nfc_target_info_s* target_info;
- bool is_ndef;
-
- target_info = calloc(1, sizeof(net_nfc_target_info_s));
- target_info->is_ndef_supported = 1;
-
- net_nfc_initialize();
-
- ret = net_nfc_get_tag_ndef_support((net_nfc_target_info_h)target_info , &is_ndef);
-
- net_nfc_deinitialize();
-
- free(target_info);
-
- dts_pass(__func__, "PASS");
-}
-
-static void utc_net_nfc_get_tag_ndef_support_n(void)
-{
- int ret=0;
-
- ret = net_nfc_get_tag_ndef_support(NULL , NULL);
-
- dts_pass(__func__, "PASS");
-}
-
-static void utc_net_nfc_get_tag_max_data_size_p(void)
-{
- int ret=0;
- net_nfc_target_info_s* target_info;
- net_nfc_target_type_e max_size = 0;
-
- target_info = calloc(1, sizeof(net_nfc_target_info_s));
- target_info->maxDataSize = 128;
-
- net_nfc_initialize();
-
- ret = net_nfc_get_tag_max_data_size((net_nfc_target_info_h)target_info , &max_size);
-
- net_nfc_deinitialize();
-
- free(target_info);
-
- dts_pass(__func__, "PASS");
-}
-
-static void utc_net_nfc_get_tag_max_data_size_n(void)
-{
- int ret=0;
-
- ret = net_nfc_get_tag_max_data_size(NULL , NULL);
-
- dts_pass(__func__, "PASS");
-}
-
-static void utc_net_nfc_get_tag_actual_data_size_p(void)
-{
- int ret=0;
- net_nfc_target_info_s* target_info;
- net_nfc_target_type_e size = 0;
-
- target_info = calloc(1, sizeof(net_nfc_target_info_s));
- target_info->actualDataSize = 128;
-
- net_nfc_initialize();
-
- ret = net_nfc_get_tag_actual_data_size((net_nfc_target_info_h)target_info , &size);
-
- net_nfc_deinitialize();
-
- free(target_info);
-
- dts_pass(__func__, "PASS");
-}
-
-static void utc_net_nfc_get_tag_actual_data_size_n(void)
-{
- int ret=0;
-
- ret = net_nfc_get_tag_actual_data_size(NULL , NULL);
-
- dts_pass(__func__, "PASS");
-}
-
-static void utc_net_nfc_get_tag_info_keys_p(void)
-{
- int ret=0;
- net_nfc_target_info_s* target_info;
- char** keys = NULL;
- int nok = 0;
-
- target_info = calloc(1, sizeof(net_nfc_target_info_s));
-
- net_nfc_initialize();
-
- ret = net_nfc_get_tag_info_keys((net_nfc_target_info_h)target_info, &keys, &nok);
-
- net_nfc_deinitialize();
-
- free(target_info);
-
- dts_pass(__func__, "PASS");
-}
-
-static void utc_net_nfc_get_tag_info_keys_n(void)
-{
- int ret=0;
-
- ret = net_nfc_get_tag_info_keys(NULL , NULL , NULL);
-
- dts_pass(__func__, "PASS");
-}
-static void utc_net_nfc_get_tag_info_value_p(void)
-{
- net_nfc_target_info_s* target_info;
- data_h* value = NULL;
- char* keys = NULL;
-
- keys = calloc( 1 , sizeof(char));
-
- target_info = calloc(1, sizeof(net_nfc_target_info_s));
- target_info->actualDataSize = 128;
- target_info->tag_info_list = calloc(1 , sizeof(net_nfc_tag_info_s));
-
- target_info->tag_info_list->key = '1';
- target_info->tag_info_list->value = calloc(1 , sizeof(data_h));
-
- value = calloc(1, sizeof(data_h));
-
- net_nfc_initialize();
-
- //net_nfc_get_tag_info_keys((net_nfc_target_info_h)target_info, &keys, &nok);
-
- net_nfc_get_tag_info_value((net_nfc_target_info_h)target_info , keys , value);
-
- net_nfc_deinitialize();
-
- free(target_info->tag_info_list->value);
- free(target_info->tag_info_list);
- free(target_info);
- free(keys);
- free(value);
-
- dts_pass(__func__, "PASS");
-}
-
-static void utc_net_nfc_get_tag_info_value_n(void)
-{
- int ret=0;
-
- ret = net_nfc_get_tag_info_value(NULL , NULL , NULL);
-
- dts_pass(__func__, "PASS");
-}
+++ /dev/null
-all
- ^TEST
-##### Scenarios for TEST #####
-
-# Test scenario
-TEST
- :include:/testcase/tslist
+++ /dev/null
-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?
+++ /dev/null
-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
+++ /dev/null
-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 ?
--- /dev/null
+LINK_DIRECTORIES(${CMAKE_BINARY_DIR})
+INCLUDE_DIRECTORIES(include)
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/common)
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/common/include)
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/manager/include)
+
+SET(NFC_CLIENT "nfc")
+
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} CLIENT_SRCS)
+
+pkg_check_modules(client_pkgs REQUIRED security-server dlog ecore-x vconf)
+
+FOREACH(flag ${client_pkgs_CFLAGS})
+ SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+
+ADD_LIBRARY(${NFC_CLIENT} SHARED ${CLIENT_SRCS})
+TARGET_LINK_LIBRARIES(${NFC_CLIENT} ${client_pkgs_LDFLAGS} nfc-common)
+SET_TARGET_PROPERTIES(${NFC_CLIENT} PROPERTIES VERSION ${FULLVER} SOVERSION ${MAJORVER})
+
+FILE(GLOB CLIENT_HEADER include/*.h)
+SET(CLIENT_HEADER ${CLIENT_HEADER} ${CMAKE_SOURCE_DIR}/common/include/net_nfc_typedef.h)
+
+CONFIGURE_FILE(${NFC_CLIENT}.pc.in ${NFC_CLIENT}.pc @ONLY)
+INSTALL(FILES ${NFC_CLIENT}.pc DESTINATION lib/pkgconfig)
+
+INSTALL(TARGETS ${NFC_CLIENT} DESTINATION lib)
+
+FOREACH(hfile ${CLIENT_HEADER})
+ INSTALL(FILES ${hfile} DESTINATION include/${NFC_CLIENT})
+ENDFOREACH(hfile)
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __NET_NFC_H__
+#define __NET_NFC_H__
+
+#include "net_nfc_typedef.h"
+#include "net_nfc_data.h"
+#include "net_nfc_target_info.h"
+#include "net_nfc_ndef_message.h"
+#include "net_nfc_ndef_record.h"
+#include "net_nfc_sign_record.h"
+#include "net_nfc_ndef_message_handover.h"
+
+#include "net_nfc_client_context.h"
+#include "net_nfc_client_manager.h"
+#include "net_nfc_client_system_handler.h"
+#include "net_nfc_client_transceive.h"
+#include "net_nfc_client_tag.h"
+#include "net_nfc_client_ndef.h"
+#include "net_nfc_client_llcp.h"
+#include "net_nfc_client_p2p.h"
+#include "net_nfc_client_snep.h"
+#include "net_nfc_client_exchanger.h"
+#include "net_nfc_client_handover.h"
+#include "net_nfc_client_se.h"
+#include "net_nfc_client_tag_felica.h"
+#include "net_nfc_client_tag_jewel.h"
+#include "net_nfc_client_tag_mifare.h"
+#include "net_nfc_client_test.h"
+
+#endif //__NET_NFC_H__
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_CLIENT_CONTEXT_H__
+#define __NET_NFC_CLIENT_CONTEXT_H__
+
+#include "net_nfc_typedef.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define NET_NFC_SERVICE_EMPTY_TYPE \
+ "http://tizen.org/appcontrol/operation/nfc/empty"
+#define NET_NFC_SERVICE_WELL_KNOWN_TYPE \
+ "http://tizen.org/appcontrol/operation/nfc/wellknown"
+#define NET_NFC_SERVICE_EXTERNAL_TYPE \
+ "http://tizen.org/appcontrol/operation/nfc/external"
+#define NET_NFC_SERVICE_MIME_TYPE \
+ "http://tizen.org/appcontrol/operation/nfc/mime"
+#define NET_NFC_SERVICE_URI_TYPE \
+ "http://tizen.org/appcontrol/operation/nfc/uri"
+
+
+net_nfc_error_e net_nfc_client_initialize();
+
+net_nfc_error_e net_nfc_client_deinitialize();
+
+net_nfc_error_e net_nfc_client_is_nfc_supported(int *state);
+
+net_nfc_error_e net_nfc_client_get_nfc_state(int *state);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif //__NET_NFC_CLIENT_CONTEXT_H__
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_CLIENT_EXCHANGER_H__
+#define __NET_NFC_CLIENT_EXCHANGER_H__
+
+
+#include "net_nfc_typedef.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+@addtogroup NET_NFC_MANAGER_EXCHANGE
+@{
+
+*/
+
+
+/**
+ create net_nfc_exchagner raw type data handler with given values
+
+ @param[out] ex_data exchangner handler
+ @param[in] payload the data will be deliver (NDEF message)
+
+ @return result of this function call
+
+ @exception NET_NFC_ALLOC_FAIL memory allocation is failed
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illegal NULL pointer(s)
+*/
+net_nfc_error_e net_nfc_client_create_exchanger_data(
+ net_nfc_exchanger_data_h *ex_data,
+ data_h payload);
+
+
+/**
+ this makes free exchagner data handler
+
+ @param[in] ex_data exchagner handler
+
+ @return result of this function call
+
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+*/
+net_nfc_error_e net_nfc_client_free_exchanger_data (
+ net_nfc_exchanger_data_h ex_data);
+
+
+net_nfc_error_e net_nfc_client_unset_exchanger_cb();
+
+
+net_nfc_error_e net_nfc_client_send_exchanger_data (
+ net_nfc_exchanger_data_h ex_handle,
+ net_nfc_target_handle_h target_handle,
+ void* trans_param);
+
+/**
+ request connection handover with discovered P2P device
+
+ @param[in] target_handle target device handle
+ @param[in] type specific alternative carrier type (if type is NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN, it will be selected available type of this target)
+ @param[in] trans_param user data
+
+ @return result of this function call
+
+ @exception NET_NFC_ALLOC_FAIL memory allocation is failed
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+*/
+net_nfc_error_e net_nfc_client_exchanger_request_connection_handover(
+ net_nfc_target_handle_h target_handle,
+ net_nfc_conn_handover_carrier_type_e type);
+
+/**
+ get alternative carrier type from connection handover information handle.
+
+ @param[in] info_handle connection handover information handle
+ @param[out] type alternative carrier type
+
+ @return return the result of this operation
+
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+*/
+net_nfc_error_e net_nfc_client_exchanger_get_alternative_carrier_type(
+ net_nfc_connection_handover_info_h info_handle,
+ net_nfc_conn_handover_carrier_type_e *type);
+
+/**
+ get alternative carrier dependant data from connection handover information handle.
+ Bluetooth : target device address
+ Wifi : target device ip address
+
+ @param[in] info_handle connection handover information handle
+ @param[out] data alternative carrier data
+
+ @return return the result of this operation
+
+ @exception NET_NFC_ALLOC_FAIL memory allocation is failed
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+*/
+net_nfc_error_e net_nfc_client_exchanger_get_alternative_carrier_data(
+ net_nfc_connection_handover_info_h info_handle,
+ data_h *data);
+
+/**
+ this makes free alternative carrier data handler
+
+ @param[in] info_handle alternative carrier data handler
+
+ @return result of this function call
+
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+*/
+net_nfc_error_e net_nfc_client_exchanger_free_alternative_carrier_data(
+ net_nfc_connection_handover_info_h info_handle);
+
+
+/**
+@}
+*/
+
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif //__NET_NFC_CLIENT_EXCHANGER_H__
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_CLIENT_HANDOVER_H__
+#define __NET_NFC_CLIENT_HANDOVER_H__
+
+#include "net_nfc_typedef.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef void (*net_nfc_p2p_connection_handover_completed_cb)(
+ net_nfc_error_e result,
+ net_nfc_conn_handover_carrier_type_e carrier,
+ data_h ac_data,
+ void *user_data);
+
+
+net_nfc_error_e net_nfc_client_handover_free_alternative_carrier_data(
+ net_nfc_connection_handover_info_h info_handle);
+
+
+net_nfc_error_e net_nfc_client_handover_get_alternative_carrier_type(
+ net_nfc_connection_handover_info_h info_handle,
+ net_nfc_conn_handover_carrier_type_e *type);
+
+
+net_nfc_error_e net_nfc_client_handover_get_alternative_carrier_data(
+ net_nfc_connection_handover_info_h info_handle,
+ data_h *data);
+
+
+net_nfc_error_e net_nfc_client_p2p_connection_handover(
+ net_nfc_target_handle_h handle,
+ net_nfc_conn_handover_carrier_type_e arg_type,
+ net_nfc_p2p_connection_handover_completed_cb callback,
+ void *cb_data);
+
+
+net_nfc_error_e net_nfc_client_p2p_connection_handover_sync(
+ net_nfc_target_handle_h handle,
+ net_nfc_conn_handover_carrier_type_e arg_type,
+ net_nfc_conn_handover_carrier_type_e *out_carrier,
+ data_h *out_ac_data);
+
+/* TODO : move to internal header */
+net_nfc_error_e net_nfc_client_handover_init(void);
+
+void net_nfc_client_handover_deinit(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif //__NET_NFC_CLIENT_HANDOVER_H__
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_CLIENT_LLCP_H__
+#define __NET_NFC_CLIENT_LLCP_H__
+
+#include "net_nfc_typedef.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef void (*net_nfc_client_llcp_config_completed) (net_nfc_error_e result,
+ void *user_data);
+
+typedef void (*net_nfc_client_llcp_listen_completed) (net_nfc_error_e result,
+ net_nfc_llcp_socket_t client_socket,
+ void *user_data);
+
+typedef void (*net_nfc_client_llcp_connect_completed) (net_nfc_error_e result,
+ net_nfc_llcp_socket_t client_socket,
+ void *user_data);
+
+typedef void (*net_nfc_client_llcp_connect_sap_completed) (
+ net_nfc_error_e result,
+ net_nfc_llcp_socket_t client_socket,
+ void *user_data);
+
+typedef void (*net_nfc_client_llcp_send_completed) (net_nfc_error_e result,
+ net_nfc_llcp_socket_t client_socket,
+ void *user_data);
+
+typedef void (*net_nfc_client_llcp_send_to_completed) (net_nfc_error_e result,
+ net_nfc_llcp_socket_t client_socket,
+ void *user_data);
+
+typedef void (*net_nfc_client_llcp_receive_completed) (net_nfc_error_e result,
+ data_h data,
+ void *user_data);
+
+typedef void (*net_nfc_client_llcp_receive_from_completed) (
+ net_nfc_error_e result,
+ sap_t sap,
+ data_h data,
+ void *user_data);
+
+typedef void (*net_nfc_client_llcp_close_completed) (net_nfc_error_e result,
+ net_nfc_llcp_socket_t client_socket,
+ void *user_data);
+
+typedef void (*net_nfc_client_llcp_disconnect_completed) (
+ net_nfc_error_e result,
+ net_nfc_llcp_socket_t client_socket,
+ void *user_data);
+
+net_nfc_error_e net_nfc_client_llcp_config(net_nfc_llcp_config_info_h config,
+ net_nfc_client_llcp_config_completed callback,
+ void *user_data);
+
+net_nfc_error_e net_nfc_client_llcp_config_sync
+ (net_nfc_llcp_config_info_h config);
+
+net_nfc_error_e net_nfc_client_llcp_get_config
+ (net_nfc_llcp_config_info_h *config);
+
+net_nfc_error_e net_nfc_client_llcp_listen(net_nfc_llcp_socket_t socket,
+ const char *service_name,
+ sap_t sap,
+ net_nfc_client_llcp_listen_completed callback,
+ void *user_data);
+
+net_nfc_error_e net_nfc_client_llcp_listen_sync(net_nfc_llcp_socket_t socket,
+ const char *service_name,
+ sap_t sap,
+ net_nfc_llcp_socket_t *out_socket);
+
+net_nfc_error_e net_nfc_client_llcp_connect(net_nfc_llcp_socket_t socket,
+ const char *service_name,
+ net_nfc_client_llcp_connect_completed callback,
+ void *user_data);
+
+net_nfc_error_e net_nfc_client_llcp_connect_sync(net_nfc_llcp_socket_t socket,
+ const char *service_name,
+ net_nfc_llcp_socket_t *out_socket);
+
+net_nfc_error_e net_nfc_client_llcp_send(net_nfc_llcp_socket_t socket,
+ data_h data,
+ net_nfc_client_llcp_send_completed callback,
+ void *user_data);
+
+net_nfc_error_e net_nfc_client_llcp_send_sync(net_nfc_llcp_socket_t socket,
+ data_h data,
+ net_nfc_llcp_socket_t *out_socket);
+
+net_nfc_error_e net_nfc_client_llcp_send_to(net_nfc_llcp_socket_t socket,
+ sap_t sap,
+ data_h data,
+ net_nfc_client_llcp_send_to_completed callback,
+ void *user_data);
+
+net_nfc_error_e net_nfc_client_llcp_send_to_sync(net_nfc_llcp_socket_t socket,
+ sap_t sap,
+ data_h data,
+ net_nfc_llcp_socket_t *out_socket);
+
+net_nfc_error_e net_nfc_client_llcp_receive(net_nfc_llcp_socket_t socket,
+ size_t request_length,
+ net_nfc_client_llcp_receive_completed callback,
+ void *user_data);
+
+net_nfc_error_e net_nfc_client_llcp_receive_sync(net_nfc_llcp_socket_t socket,
+ size_t request_length,
+ data_h *out_data);
+
+net_nfc_error_e net_nfc_client_llcp_receive_from(net_nfc_llcp_socket_t socket,
+ size_t request_length,
+ net_nfc_client_llcp_receive_from_completed callback,
+ void *user_data);
+
+net_nfc_error_e net_nfc_client_llcp_receive_from_sync(net_nfc_llcp_socket_t socket,
+ size_t request_length,
+ sap_t *out_sap,
+ data_h *out_data);
+
+net_nfc_error_e net_nfc_client_llcp_close(net_nfc_llcp_socket_t socket,
+ net_nfc_client_llcp_close_completed callback,
+ void *user_data);
+
+net_nfc_error_e net_nfc_client_llcp_close_sync(net_nfc_llcp_socket_t socket,
+ net_nfc_llcp_socket_t *out_socket);
+
+net_nfc_error_e net_nfc_client_llcp_disconnect(net_nfc_llcp_socket_t socket,
+ net_nfc_client_llcp_disconnect_completed callback,
+ void *user_data);
+
+net_nfc_error_e net_nfc_client_llcp_disconnect_sync(
+ net_nfc_llcp_socket_t socket,
+ net_nfc_llcp_socket_t *out_socket);
+
+void net_nfc_client_llcp_create_socket(net_nfc_llcp_socket_t *socket,
+ net_nfc_llcp_socket_option_h option);
+
+net_nfc_error_e net_nfc_client_llcp_get_local_config(
+ net_nfc_llcp_config_info_h *config);
+
+net_nfc_error_e net_nfc_client_llcp_get_local_socket_option(
+ net_nfc_llcp_socket_t socket,
+ net_nfc_llcp_socket_option_h *option);
+
+net_nfc_error_e net_nfc_client_llcp_create_socket_option(
+ net_nfc_llcp_socket_option_h *option,
+ uint16_t miu,
+ uint8_t rw,
+ net_nfc_socket_type_e type);
+
+net_nfc_error_e net_nfc_client_llcp_socket_option_default(
+ net_nfc_llcp_socket_option_h *option);
+
+net_nfc_error_e net_nfc_client_llcp_get_socket_option_miu(
+ net_nfc_llcp_socket_option_h option,
+ uint16_t *miu);
+
+net_nfc_error_e net_nfc_client_llcp_set_socket_option_miu(
+ net_nfc_llcp_socket_option_h option,
+ uint16_t miu);
+
+net_nfc_error_e net_nfc_client_llcp_get_socket_option_rw(
+ net_nfc_llcp_socket_option_h option,
+ uint8_t *rt);
+
+net_nfc_error_e net_nfc_client_llcp_set_socket_option_rw(
+ net_nfc_llcp_socket_option_h option,
+ uint8_t rt);
+
+net_nfc_error_e net_nfc_client_llcp_get_socket_option_type(
+ net_nfc_llcp_socket_option_h option,
+ net_nfc_socket_type_e *type);
+
+net_nfc_error_e net_nfc_client_llcp_set_socket_option_type(
+ net_nfc_llcp_socket_option_h option,
+ net_nfc_socket_type_e type);
+
+net_nfc_error_e net_nfc_client_llcp_free_socket_option(
+ net_nfc_llcp_socket_option_h option);
+
+net_nfc_error_e net_nfc_client_llcp_create_config(
+ net_nfc_llcp_config_info_h *config,
+ uint16_t miu,
+ uint16_t wks,
+ uint8_t lto,
+ uint8_t option);
+
+net_nfc_error_e net_nfc_client_llcp_create_config_default(
+ net_nfc_llcp_config_info_h *config);
+
+net_nfc_error_e net_nfc_client_llcp_get_config_miu(
+ net_nfc_llcp_config_info_h config,
+ uint16_t *miu);
+
+net_nfc_error_e net_nfc_client_llcp_get_config_wks(
+ net_nfc_llcp_config_info_h config,
+ uint16_t *wks);
+
+net_nfc_error_e net_nfc_client_llcp_get_config_lto(
+ net_nfc_llcp_config_info_h config,
+ uint8_t *lto);
+
+net_nfc_error_e net_nfc_client_llcp_get_config_option(
+ net_nfc_llcp_config_info_h config,
+ uint8_t *option);
+
+net_nfc_error_e net_nfc_client_llcp_set_config_miu(
+ net_nfc_llcp_config_info_h config,
+ uint16_t miu);
+
+net_nfc_error_e net_nfc_client_llcp_set_config_wks(
+ net_nfc_llcp_config_info_h config,
+ uint16_t wks);
+
+net_nfc_error_e net_nfc_client_llcp_set_config_lto(
+ net_nfc_llcp_config_info_h config,
+ uint8_t lto);
+
+net_nfc_error_e net_nfc_client_llcp_set_config_option(
+ net_nfc_llcp_config_info_h config,
+ uint8_t option);
+
+net_nfc_error_e net_nfc_client_llcp_free_config(
+ net_nfc_llcp_config_info_h config);
+
+net_nfc_error_e net_nfc_client_llcp_create_socket_option_default(
+ net_nfc_llcp_socket_option_h *option);
+
+net_nfc_error_e net_nfc_client_llcp_connect_sap(net_nfc_llcp_socket_t socket,
+ sap_t sap,
+ net_nfc_client_llcp_connect_sap_completed callback,
+ void *user_data);
+
+net_nfc_error_e net_nfc_client_llcp_connect_sap_sync(
+ net_nfc_llcp_socket_t socket,
+ sap_t sap,
+ net_nfc_llcp_socket_t *out_socket);
+
+
+net_nfc_error_e net_nfc_client_llcp_init(void);
+
+void net_nfc_client_llcp_deinit(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif //__NET_NFC_CLIENT_LLCP_H__
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_CLIENT_MANAGER_H__
+#define __NET_NFC_CLIENT_MANAGER_H__
+
+#include "net_nfc_typedef.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef void (*net_nfc_client_manager_set_active_completed)(
+ net_nfc_error_e result,
+ void *user_data);
+
+typedef void (*net_nfc_client_manager_get_server_state_completed)(
+ net_nfc_error_e result,
+ unsigned int state,
+ void *user_data);
+
+typedef void (*net_nfc_client_manager_activated)(bool state,
+ void *user_data);
+
+void net_nfc_client_manager_set_activated(
+ net_nfc_client_manager_activated callback,
+ void *user_data);
+
+void net_nfc_client_manager_unset_activated(void);
+
+net_nfc_error_e net_nfc_client_manager_set_active(int state,
+ net_nfc_client_manager_set_active_completed callback,
+ void *user_data);
+
+net_nfc_error_e net_nfc_client_manager_set_active_sync(int state);
+
+net_nfc_error_e net_nfc_client_manager_get_server_state(
+ net_nfc_client_manager_get_server_state_completed callback,
+ void *user_data);
+
+net_nfc_error_e net_nfc_client_manager_get_server_state_sync(
+ unsigned int *state);
+
+/* TODO : move to internal header */
+net_nfc_error_e net_nfc_client_manager_init(void);
+
+void net_nfc_client_manager_deinit(void);
+
+bool net_nfc_client_manager_is_activated();
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif //__NET_NFC_CLIENT_MANAGER_H__
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_CLIENT_NDEF_H__
+#define __NET_NFC_CLIENT_NDEF_H__
+
+#include "net_nfc_typedef.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef void (*net_nfc_client_ndef_read_completed) (net_nfc_error_e result,
+ ndef_message_h message,
+ void *user_data);
+
+typedef void (*net_nfc_client_ndef_write_completed) (net_nfc_error_e result,
+ void *user_data);
+
+typedef void (*net_nfc_client_ndef_make_read_only_completed) (
+ net_nfc_error_e result,
+ void *user_data);
+
+typedef void (*net_nfc_client_ndef_format_completed) (net_nfc_error_e result,
+ void *user_data);
+
+net_nfc_error_e net_nfc_client_ndef_read(net_nfc_target_handle_h handle,
+ net_nfc_client_ndef_read_completed callback,
+ void *user_data);
+
+net_nfc_error_e net_nfc_client_ndef_read_sync(net_nfc_target_handle_h handle,
+ ndef_message_h *message);
+
+net_nfc_error_e net_nfc_client_ndef_write(net_nfc_target_handle_h handle,
+ ndef_message_h message,
+ net_nfc_client_ndef_write_completed callback,
+ void *user_data);
+
+net_nfc_error_e net_nfc_client_ndef_write_sync(net_nfc_target_handle_h handle,
+ ndef_message_h message);
+
+net_nfc_error_e net_nfc_client_ndef_make_read_only(
+ net_nfc_target_handle_h handle,
+ net_nfc_client_ndef_make_read_only_completed callback,
+ void *user_data);
+
+net_nfc_error_e net_nfc_client_ndef_make_read_only_sync(
+ net_nfc_target_handle_h handle);
+
+net_nfc_error_e net_nfc_client_ndef_format(net_nfc_target_handle_h handle,
+ data_h key,
+ net_nfc_client_ndef_format_completed callback,
+ void *user_data);
+
+net_nfc_error_e net_nfc_client_ndef_format_sync(
+ net_nfc_target_handle_h handle,
+ data_h key);
+
+/* TODO : move to internal header */
+net_nfc_error_e net_nfc_client_ndef_init(void);
+
+void net_nfc_client_ndef_deinit(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif //__NET_NFC_CLIENT_NDEF_H__
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_CLIENT_P2P_H__
+#define __NET_NFC_CLIENT_P2P_H__
+
+#include "net_nfc_typedef.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* p2p callbacks */
+
+typedef void (*net_nfc_client_p2p_send_completed)(net_nfc_error_e result,
+ void *user_data);
+
+typedef void (*net_nfc_client_p2p_device_discovered)(net_nfc_target_handle_h handle_info,
+ void *user_data);
+
+typedef void (*net_nfc_client_p2p_device_detached)(void *user_data);
+
+typedef void (*net_nfc_client_p2p_data_received)(
+ data_h p2p_data,
+ void *user_data);
+
+/* P2P client API's*/
+net_nfc_error_e net_nfc_client_p2p_send(net_nfc_exchanger_data_h exchg_data,
+ net_nfc_target_handle_h handle,
+ net_nfc_client_p2p_send_completed callback,
+ void *cb_data);
+
+net_nfc_error_e net_nfc_client_p2p_send_sync(
+ net_nfc_exchanger_data_h exchg_data,
+ net_nfc_target_handle_h handle);
+
+
+/* P2P client API's - used for registering callbacks*/
+void net_nfc_client_p2p_set_data_received(
+ net_nfc_client_p2p_data_received callback,
+ void *user_data);
+
+void net_nfc_client_p2p_set_device_detached(
+ net_nfc_client_p2p_device_detached callback,
+ void *user_data);
+
+void net_nfc_client_p2p_set_device_discovered(
+ net_nfc_client_p2p_device_discovered callback,
+ void *user_data);
+
+/* P2P client API's - used for unregistering callbacks*/
+void net_nfc_client_p2p_unset_data_received(void);
+
+void net_nfc_client_p2p_unset_device_detached(void);
+
+void net_nfc_client_p2p_unset_device_discovered(void);
+
+/* TODO : move to internal header */
+/* Init/Deint function calls*/
+net_nfc_error_e net_nfc_client_p2p_init(void);
+
+void net_nfc_client_p2p_deinit(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif //__NET_NFC_CLIENT_P2P_H__
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_CLIENT_SE_H__
+#define __NET_NFC_CLIENT_SE_H__
+
+#include <glib.h>
+#include "net_nfc_typedef.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*************Secure Element Callbacks*********/
+typedef void (*net_nfc_se_set_se_cb)(
+ net_nfc_error_e result,
+ void *user_data);
+
+typedef void (*net_nfc_se_open_se_cb)(
+ net_nfc_error_e result,
+ net_nfc_target_handle_h handle,
+ void *user_data);
+
+typedef void (*net_nfc_se_close_se_cb)(
+ net_nfc_error_e result,
+ void *user_data);
+
+typedef void (*net_nfc_se_get_atr_cb)(
+ net_nfc_error_e result,
+ data_h data,
+ void *user_data);
+
+typedef void (*net_nfc_se_send_apdu_cb)(
+ net_nfc_error_e result,
+ data_h data,
+ void *user_data);
+
+typedef void (*net_nfc_client_se_event)(
+ net_nfc_message_e event,
+ void *user_data);
+
+typedef void (*net_nfc_client_se_transaction_event)(data_h aid,
+ data_h param,
+ void *user_data);
+
+typedef void (*net_nfc_client_se_ese_detected_event)(
+ net_nfc_target_handle_h handle,
+ int dev_type,
+ data_h data,
+ void *user_data);
+
+/************* Secure Element API's*************/
+
+net_nfc_error_e net_nfc_client_se_set_secure_element_type(
+ net_nfc_se_type_e se_type,
+ net_nfc_se_set_se_cb callback,
+ void *user_data);
+
+
+net_nfc_error_e net_nfc_client_se_set_secure_element_type_sync(
+ net_nfc_se_type_e se_type);
+
+
+net_nfc_error_e net_nfc_client_se_get_secure_element_type(
+ void *user_data);
+
+
+net_nfc_error_e net_nfc_client_se_get_secure_element_type_sync(
+ gint *se_type);
+
+
+net_nfc_error_e net_nfc_client_se_open_internal_secure_element(
+ net_nfc_se_type_e se_type,
+ net_nfc_se_open_se_cb callback,
+ void *user_data);
+
+
+net_nfc_error_e net_nfc_client_se_open_internal_secure_element_sync(
+ net_nfc_se_type_e se_type,
+ net_nfc_target_handle_h *handle);
+
+
+net_nfc_error_e net_nfc_client_se_close_internal_secure_element(
+ net_nfc_target_handle_h handle,
+ net_nfc_se_close_se_cb callback,
+ void *user_data);
+
+
+net_nfc_error_e net_nfc_client_se_close_internal_secure_element_sync(
+ net_nfc_target_handle_h handle);
+
+
+net_nfc_error_e net_nfc_client_se_get_atr(
+ net_nfc_target_handle_h handle,
+ net_nfc_se_get_atr_cb callback,
+ void *user_data);
+
+
+net_nfc_error_e net_nfc_client_se_get_atr_sync(
+ net_nfc_target_handle_h handle,
+ data_h *atr);
+
+
+net_nfc_error_e net_nfc_client_se_send_apdu(
+ net_nfc_target_handle_h handle,
+ data_h apdu_data,
+ net_nfc_se_send_apdu_cb callback,
+ void *user_data);
+
+
+net_nfc_error_e net_nfc_client_se_send_apdu_sync(
+ net_nfc_target_handle_h handle,
+ data_h apdu_data,
+ data_h *response);
+
+
+/************* Secure Element CallBack Register/Deregister functions*************/
+
+void net_nfc_client_se_set_ese_detection_cb(
+ net_nfc_client_se_ese_detected_event callback,
+ void *user_data);
+
+void net_nfc_client_se_unset_ese_detection_cb(void);
+
+void net_nfc_client_se_set_transaction_event_cb(
+ net_nfc_client_se_transaction_event callback,
+ void *user_data);
+
+void net_nfc_client_se_unset_transaction_event_cb(void);
+
+void net_nfc_client_se_set_event_cb(net_nfc_client_se_event callback,
+ void *user_data);
+
+void net_nfc_client_se_unset_event_cb(void);
+
+
+/* TODO : move to internal header */
+/************* Secure Element Init/Deint*************/
+
+net_nfc_error_e net_nfc_client_se_init(void);
+
+
+void net_nfc_client_se_deinit(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif //__NET_NFC_CLIENT_SE_H__
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_CLIENT_SNEP_H__
+#define __NET_NFC_CLIENT_SNEP_H__
+
+#include "net_nfc_typedef.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef void (*net_nfc_client_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);
+
+net_nfc_error_e net_nfc_client_snep_start_server(
+ net_nfc_target_handle_h target,
+ const char *san,
+ sap_t sap,
+ net_nfc_client_snep_event_cb callback,
+ void *user_data);
+
+net_nfc_error_e net_nfc_client_snep_start_client(
+ net_nfc_target_handle_h target,
+ const char *san,
+ sap_t sap,
+ net_nfc_client_snep_event_cb callback,
+ void *user_data);
+
+net_nfc_error_e net_nfc_client_snep_send_client_request(
+ net_nfc_snep_handle_h handle,
+ net_nfc_snep_type_t snep_type,
+ ndef_message_h msg,
+ net_nfc_client_snep_event_cb callback,
+ void *user_data);
+
+net_nfc_error_e net_nfc_client_snep_send_client_request_sync(
+ net_nfc_target_handle_h target,
+ net_nfc_snep_type_t snep_type,
+ ndef_message_h msg,
+ net_nfc_snep_type_t *resp_type,
+ ndef_message_h *response);
+
+net_nfc_error_e net_nfc_client_snep_stop_service(
+ net_nfc_target_handle_h target,
+ net_nfc_snep_handle_h service,
+ net_nfc_client_snep_event_cb callback,
+ void *user_data);
+
+net_nfc_error_e net_nfc_client_snep_stop_service_sync(
+ net_nfc_target_handle_h target,
+ net_nfc_snep_handle_h service);
+
+net_nfc_error_e net_nfc_client_snep_register_server(const char *san,
+ sap_t sap,
+ net_nfc_client_snep_event_cb callback,
+ void *user_data);
+
+net_nfc_error_e net_nfc_client_snep_unregister_server(const char *san,
+ sap_t sap);
+
+/* TODO : move to internal header */
+net_nfc_error_e net_nfc_client_snep_init(void);
+
+void net_nfc_client_snep_deinit(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif //__NET_NFC_CLIENT_SNEP_H__
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_CLIENT_SYSTEM_HANDLER_H__
+#define __NET_NFC_CLIENT_SYSTEM_HANDLER_H__
+
+#include "net_nfc_typedef.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef void (*net_nfc_client_popup_set_state_callback)(
+ net_nfc_error_e result,
+ void *user_data);
+
+net_nfc_error_e net_nfc_client_sys_handler_set_state(int state,
+ net_nfc_client_popup_set_state_callback callback,
+ void *user_data);
+
+net_nfc_error_e net_nfc_client_sys_handler_set_state_force(int state,
+ net_nfc_client_popup_set_state_callback callback,
+ void *user_data);
+
+net_nfc_error_e net_nfc_client_sys_handler_set_state_sync(int state);
+
+net_nfc_error_e net_nfc_client_sys_handler_set_state_force_sync(int state);
+
+net_nfc_error_e net_nfc_client_sys_handler_set_launch_popup_state(int enable);
+
+net_nfc_error_e net_nfc_client_sys_handler_set_launch_popup_state_force(
+ int enable);
+
+net_nfc_error_e net_nfc_client_sys_handler_get_launch_popup_state(int *state);
+
+/* TODO : move to internal header */
+net_nfc_error_e net_nfc_client_sys_handler_init(void);
+
+void net_nfc_client_sys_handler_deinit(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif //__NET_NFC_CLIENT_SYSTEM_HANDLER_H__
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_CLIENT_TAG_H__
+#define __NET_NFC_CLIENT_TAG_H__
+
+#include "net_nfc_typedef.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef void (*net_nfc_client_tag_is_tag_connected_completed) (
+ net_nfc_error_e result,
+ net_nfc_target_type_e dev_type,
+ void *user_data);
+
+typedef void (*net_nfc_client_tag_get_current_tag_info_completed) (
+ net_nfc_error_e result,
+ net_nfc_target_info_h info,
+ void *user_data);
+
+typedef void (*net_nfc_client_tag_get_current_target_handle_completed) (
+ net_nfc_error_e result,
+ net_nfc_target_handle_h handle,
+ void *user_data);
+
+typedef void (*net_nfc_client_tag_tag_discovered) (net_nfc_target_info_h info,
+ void *user_data);
+
+typedef void (*net_nfc_client_tag_tag_detached) (void *user_data);
+
+
+net_nfc_error_e net_nfc_client_tag_is_tag_connected(
+ net_nfc_client_tag_is_tag_connected_completed callback,
+ void *user_data);
+
+net_nfc_error_e net_nfc_client_tag_is_tag_connected_sync(
+ net_nfc_target_type_e *dev_type);
+
+net_nfc_error_e net_nfc_client_tag_get_current_tag_info(
+ net_nfc_client_tag_get_current_tag_info_completed callback,
+ void *user_data);
+
+net_nfc_error_e net_nfc_client_tag_get_current_tag_info_sync(
+ net_nfc_target_info_h *info);
+
+net_nfc_error_e net_nfc_client_tag_get_current_target_handle(
+ net_nfc_client_tag_get_current_target_handle_completed callback,
+ void *user_data);
+
+net_nfc_error_e net_nfc_client_tag_get_current_target_handle_sync(
+ net_nfc_target_handle_h *handle);
+
+void net_nfc_client_tag_set_tag_discovered(
+ net_nfc_client_tag_tag_discovered callback,
+ void *user_data);
+
+void net_nfc_client_tag_unset_tag_discovered(void);
+
+void net_nfc_client_tag_set_tag_detached(
+ net_nfc_client_tag_tag_detached callback,
+ void *user_data);
+
+void net_nfc_client_tag_unset_tag_detached(void);
+
+void net_nfc_client_tag_set_filter(net_nfc_event_filter_e filter);
+
+net_nfc_event_filter_e net_nfc_client_tag_get_filter(void);
+
+/* TODO : move to internal header */
+net_nfc_error_e net_nfc_client_tag_init(void);
+
+void net_nfc_client_tag_deinit(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif //__NET_NFC_CLIENT_TAG_H__
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_CLIENT_TAG_FELICA_H__
+#define __NET_NFC_CLIENT_TAG_FELICA_H__
+
+#include "net_nfc_typedef.h"
+#include "net_nfc_client_transceive.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+
+ @addtogroup NET_NFC_MANAGER_TAG
+ @{
+
+ send poll request to felica tag.
+ Use this command to acquire and identify a card. Acqusition of IDm and PMm is possible with this command.
+ By specifying a request code , you can acquire system code or communication performance of the system.
+ By specifying a time slot, you can designate the maximum number of time slots possible to return response.
+
+ NET_NFC_FELICA_POLL_NO_REQUEST = 0x00
+ NET_NFC_FELICA_POLL_SYSTEM_CODE_REQUEST = 0x01
+ NET_NFC_FELICA_POLL_COMM_SPEED_REQUEST= 0x02
+
+ time slot
+
+ Time slot Max number of slots
+ 0x00, 1
+ 0x01, 2
+ 0x03, 4
+ 0x07, 8
+ 0x0f, 16
+
+ \par Sync (or) Async: Sync
+ This is a Asynchronous API
+
+ @param[in] handle target handle of detected tag
+ @param[in] req_code request code with this command
+ @param[in] time_slot time slot value
+
+ @return return the result of the calling the function
+
+ @exception NET_NFC_NULL_PARAMETER parameter has illigal NULL pointer
+ @exception NET_NFC_ALLOC_FAIL memory allocation is failed
+ @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization
+ @exception NET_NFC_BUSY Device is too busy to handle your request
+ @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error
+ @exception NET_NFC_RF_TIMEOUT Timeout is raised while communicate with tag
+ @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command
+ @exception NET_NFC_INVALID_HANDLE target handle is not valid
+ @exception NET_NFC_TAG_READ_FAILED received chunked data is not valied (damaged data is recieved) or error ack is recieved
+ @exception NET_NFC_NO_DATA_FOUND mendantory tag info (SYSTEM_CODE, etc) is not founded
+
+*/
+
+net_nfc_error_e net_nfc_client_felica_poll(net_nfc_target_handle_h handle,
+ net_nfc_felica_poll_request_code_e req_code,
+ uint8_t time_slote,
+ nfc_transceive_data_callback callback,
+ void *user_data);
+
+/**
+ Use this command to check for the existence of Area / Service specified by Area Code / Service Code
+ If the specified Area / Service exists, the card returns version information of the key known as "Key Version" (2 Bytes)
+ If the specified Area / Service does not exist, the card returns 0xffff as it s Key Version
+
+ \par Sync (or) Async: Sync
+ This is a Asynchronous API
+
+ @param[in] handle target handle of detected tag
+ @param[in] number_of_area_service the number of specified Area / Service list
+ @param[in] area_service_list specified Area / Service list
+
+ @return return the result of the calling the function
+
+ @exception NET_NFC_NULL_PARAMETER parameter has illigal NULL pointer
+ @exception NET_NFC_ALLOC_FAIL memory allocation is failed
+ @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization
+ @exception NET_NFC_BUSY Device is too busy to handle your request
+ @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error
+ @exception NET_NFC_RF_TIMEOUT Timeout is raised while communicate with tag
+ @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command
+ @exception NET_NFC_INVALID_HANDLE target handle is not valid
+ @exception NET_NFC_TAG_READ_FAILED received chunked data is not valied (damaged data is recieved) or error ack is recieved
+ @exception NET_NFC_NO_DATA_FOUND mendantory tag info (IDm, etc) is not founded
+ @exception NET_NFC_OUT_OF_BOUND the length of IDm is not correct. number of services exceed max value
+
+*/
+
+net_nfc_error_e net_nfc_client_felica_request_service(
+ net_nfc_target_handle_h handle,
+ uint8_t number_of_area_service,
+ uint16_t area_service_list[],
+ uint8_t number_of_services,
+ nfc_transceive_data_callback callback,
+ void *user_data);
+
+/**
+ Use this command to check whether a card exist
+ the Current mode of the card is returned.
+
+ Mode
+
+ 0x00 Mode0
+ 0x01 Mode1
+ 0x02 Mode2
+ 0x03 Mode3
+
+ \par Sync (or) Async: Sync
+ This is a Asynchronous API
+
+ @param[in] handle target handle of detected tag
+
+ @return return the result of the calling the function
+
+ @exception NET_NFC_NULL_PARAMETER parameter has illigal NULL pointer
+ @exception NET_NFC_ALLOC_FAIL memory allocation is failed
+ @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization
+ @exception NET_NFC_BUSY Device is too busy to handle your request
+ @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error
+ @exception NET_NFC_RF_TIMEOUT Timeout is raised while communicate with tag
+ @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command
+ @exception NET_NFC_INVALID_HANDLE target handle is not valid
+ @exception NET_NFC_TAG_READ_FAILED received chunked data is not valied (damaged data is recieved) or error ack is recieved
+ @exception NET_NFC_NO_DATA_FOUND mendantory tag info (IDm, etc) is not founded
+ @exception NET_NFC_OUT_OF_BOUND the length of IDm is not correct
+
+*/
+
+net_nfc_error_e net_nfc_client_felica_request_response(
+ net_nfc_target_handle_h handle,
+ nfc_transceive_data_callback callback,
+ void *user_data);
+
+/**
+ Use this command to read block data from a Service that requires no authentification
+
+ \par Sync (or) Async: Sync
+ This is a Asynchronous API
+
+ @param[in] handle target handle of detected tag
+ @param[in] number_of_service the number of service list to read
+ @param[in] service_list specified Service list to read
+ @param[in] number_of_blocks the number of blocks to read
+ @param[in] block_list the blocks to read
+
+ @return return the result of the calling the function
+
+ @exception NET_NFC_NULL_PARAMETER parameter has illigal NULL pointer
+ @exception NET_NFC_ALLOC_FAIL memory allocation is failed
+ @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization
+ @exception NET_NFC_BUSY Device is too busy to handle your request
+ @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error
+ @exception NET_NFC_RF_TIMEOUT Timeout is raised while communicate with tag
+ @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command
+ @exception NET_NFC_INVALID_HANDLE target handle is not valid
+ @exception NET_NFC_TAG_READ_FAILED received chunked data is not valied (damaged data is recieved) or error ack is recieved
+ @exception NET_NFC_NO_DATA_FOUND mendantory tag info (IDm, etc) is not founded
+ @exception NET_NFC_OUT_OF_BOUND the length of IDm is not correct
+
+*/
+
+net_nfc_error_e net_nfc_client_felica_read_without_encryption(
+ net_nfc_target_handle_h handle,
+ uint8_t number_of_services,
+ uint16_t service_list[],
+ uint8_t number_of_blocks,
+ uint8_t block_list[],
+ nfc_transceive_data_callback callback,
+ void *user_data);
+
+/**
+ Use this command to write block data to a Service that requires no authentification
+
+ \par Sync (or) Async: Sync
+ This is a Asynchronous API
+
+ @param[in] handle target handle of detected tag
+ @param[in] number_of_service the number of service list to write
+ @param[in] service_list specified Service list to write
+ @param[in] number_of_blocks the number of blocks to write
+ @param[in] block_list the blocks to write
+ @param[in] data the data to write
+
+ @return return the result of the calling the function
+
+ @exception NET_NFC_NULL_PARAMETER parameter has illigal NULL pointer
+ @exception NET_NFC_ALLOC_FAIL memory allocation is failed
+ @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization
+ @exception NET_NFC_BUSY Device is too busy to handle your request
+ @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error
+ @exception NET_NFC_RF_TIMEOUT Timeout is raised while communicate with tag
+ @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command
+ @exception NET_NFC_INVALID_HANDLE target handle is not valid
+ @exception NET_NFC_TAG_READ_FAILED received chunked data is not valied (damaged data is recieved) or error ack is recieved
+ @exception NET_NFC_NO_DATA_FOUND mendantory tag info (IDm, etc) is not founded
+ @exception NET_NFC_OUT_OF_BOUND the length of IDm is not correct. number of services exceed max value, the data length to write is exceed the limitation. It should be less than number_of_blocks * 16 bytes
+
+*/
+
+net_nfc_error_e net_nfc_client_felica_write_without_encryption(
+ net_nfc_target_handle_h handle,
+ uint8_t number_of_services,
+ uint16_t service_list[],
+ uint8_t number_of_blocks,
+ uint8_t block_list[],
+ data_h data,
+ nfc_transceive_data_callback callback,
+ void *user_data);
+
+/**
+ Use this command to acquire system code of the system located on a card
+ If a card is divided into mutiple system, this command acquires system code of all the system existing in the card
+
+ \par Sync (or) Async: Sync
+ This is a Asynchronous API
+
+ @param[in] handle target handle of detected tag
+
+ @return return the result of the calling the function
+
+ @exception NET_NFC_NULL_PARAMETER parameter has illigal NULL pointer
+ @exception NET_NFC_ALLOC_FAIL memory allocation is failed
+ @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization
+ @exception NET_NFC_BUSY Device is too busy to handle your request
+ @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error
+ @exception NET_NFC_RF_TIMEOUT Timeout is raised while communicate with tag
+ @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command
+ @exception NET_NFC_INVALID_HANDLE target handle is not valid
+ @exception NET_NFC_TAG_READ_FAILED received chunked data is not valied (damaged data is recieved) or error ack is recieved
+ @exception NET_NFC_NO_DATA_FOUND mendantory tag info (IDm, etc) is not founded
+ @exception NET_NFC_OUT_OF_BOUND the length of IDm is not correct.
+
+*/
+
+net_nfc_error_e net_nfc_client_felica_request_system_code(
+ net_nfc_target_handle_h handle,
+ nfc_transceive_data_callback callback,
+ void* trans_param);
+
+/**
+@}
+*/
+
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif //__NET_NFC_CLIENT_TAG_FELICA_H__
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_CLIENT_TAG_JEWEL_H__
+#define __NET_NFC_CLIENT_TAG_JEWEL_H__
+
+#include "net_nfc_typedef.h"
+#include "net_nfc_client_transceive.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+
+ @addtogroup NET_NFC_MANAGER_TAG
+ @{
+
+ read uid from jewel tag.
+
+ \par Sync (or) Async: Sync
+ This is a Asynchronous API
+
+ @param[in] handle target handle of detected tag
+
+ @return return the result of the calling the function
+
+ @exception NET_NFC_NULL_PARAMETER parameter has illigal NULL pointer
+ @exception NET_NFC_ALLOC_FAIL memory allocation is failed
+ @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization
+ @exception NET_NFC_BUSY Device is too busy to handle your request
+ @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error
+ @exception NET_NFC_RF_TIMEOUT Timeout is raised while communicate with tag
+ @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command
+ @exception NET_NFC_INVALID_HANDLE target handle is not valid
+ @exception NET_NFC_TAG_READ_FAILED received chunked data is not valied (damaged data is recieved) or error ack is recieved
+ @exception NET_NFC_NO_DATA_FOUND mendantory tag info (UID, etc) is not founded
+
+*/
+
+net_nfc_error_e net_nfc_client_jewel_read_id(net_nfc_target_handle_h handle,
+ nfc_transceive_data_callback callback,
+ void *user_data);
+
+/**
+ read one byte of specific address .
+
+ \par Sync (or) Async: Sync
+ This is a Asynchronous API
+
+ @param[in] handle target handle of detected tag
+ @param[in] block block number. (block 0 ~ block E)
+ @param[in] byte byte number. Each block has 8 bytes. (byte 0 ~ byte 7)
+
+ @return return the result of the calling the function
+
+ @exception NET_NFC_NULL_PARAMETER parameter has illigal NULL pointer
+ @exception NET_NFC_ALLOC_FAIL memory allocation is failed
+ @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization
+ @exception NET_NFC_BUSY Device is too busy to handle your request
+ @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error
+ @exception NET_NFC_RF_TIMEOUT Timeout is raised while communicate with tag
+ @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command
+ @exception NET_NFC_INVALID_HANDLE target handle is not valid
+ @exception NET_NFC_TAG_READ_FAILED received chunked data is not valied (damaged data is recieved) or error ack is recieved
+ @exception NET_NFC_NO_DATA_FOUND mendantory tag info (UID, etc) is not founded
+
+*/
+
+net_nfc_error_e net_nfc_client_jewel_read_byte(net_nfc_target_handle_h handle,
+ uint8_t block,
+ uint8_t byte,
+ nfc_transceive_data_callback callback,
+ void *user_data);
+
+/**
+ read all byte from tag .
+
+ \par Sync (or) Async: Sync
+ This is a Asynchronous API
+
+ @param[in] handle target handle of detected tag
+
+ @return return the result of the calling the function
+
+ @exception NET_NFC_NULL_PARAMETER parameter has illigal NULL pointer
+ @exception NET_NFC_ALLOC_FAIL memory allocation is failed
+ @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization
+ @exception NET_NFC_BUSY Device is too busy to handle your request
+ @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error
+ @exception NET_NFC_RF_TIMEOUT Timeout is raised while communicate with tag
+ @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command
+ @exception NET_NFC_INVALID_HANDLE target handle is not valid
+ @exception NET_NFC_TAG_READ_FAILED received chunked data is not valied (damaged data is recieved) or error ack is recieved
+ @exception NET_NFC_NO_DATA_FOUND mendantory tag info (UID, etc) is not founded
+
+*/
+
+
+net_nfc_error_e net_nfc_client_jewel_read_all(net_nfc_target_handle_h handle,
+ nfc_transceive_data_callback callback,
+ void *user_data);
+
+
+/**
+ operate erase and write cycle . If any of BLOCK-0 to BLOCK-D is locked then write with erase is barred form thoes blocks.
+ Additionally 0, D, E blocks are automatically in the lock condition. so write with erase is always barred from thoes blocks.
+
+ \par Sync (or) Async: Sync
+ This is a Asynchronous API
+
+ @param[in] handle target handle of detected tag
+ @param[in] block block number. (block 0 ~ block E)
+ @param[in] data the data to write
+ @param[in] byte byte number. Each block has 8 bytes. (byte 0 ~ byte 7)
+
+ @return return the result of the calling the function
+
+ @exception NET_NFC_NULL_PARAMETER parameter has illigal NULL pointer
+ @exception NET_NFC_ALLOC_FAIL memory allocation is failed
+ @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization
+ @exception NET_NFC_BUSY Device is too busy to handle your request
+ @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error
+ @exception NET_NFC_RF_TIMEOUT Timeout is raised while communicate with tag
+ @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command
+ @exception NET_NFC_INVALID_HANDLE target handle is not valid
+ @exception NET_NFC_TAG_WRITE_FAILED read only tag, or error ack is received from tag
+ @exception NET_NFC_NO_DATA_FOUND mendantory tag info (UID, etc) is not founded
+
+*/
+
+net_nfc_error_e net_nfc_client_jewel_write_with_erase(
+ net_nfc_target_handle_h handle,
+ uint8_t block,
+ uint8_t byte,
+ uint8_t data,
+ nfc_transceive_callback callback,
+ void *user_data);
+
+
+/**
+ operate no erase and write cycle .
+
+ The WRITE-NE command is available for three main purposes
+ - Lock . to set the ��lock bit�� for a block
+ - OTP . to set One-Time-Programmable bits (bytes 2 . 7 of Block-E), where between one and eight OTP bits can be set with a singleWRITE-NE command
+ - A fast-write in order to reduce overall time to write data to memory blocks for the first time given that the original condition of memory is zero
+
+ \par Sync (or) Async: Sync
+ This is a Asynchronous API
+
+ @param[in] handle target handle of detected tag
+ @param[in] block block number. (block 0 ~ block E)
+ @param[in] data the data to write
+ @param[in] byte byte number. Each block has 8 bytes. (byte 0 ~ byte 7)
+
+ @return return the result of the calling the function
+
+ @exception NET_NFC_NULL_PARAMETER parameter has illigal NULL pointer
+ @exception NET_NFC_ALLOC_FAIL memory allocation is failed
+ @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization
+ @exception NET_NFC_BUSY Device is too busy to handle your request
+ @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error
+ @exception NET_NFC_RF_TIMEOUT Timeout is raised while communicate with tag
+ @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command
+ @exception NET_NFC_INVALID_HANDLE target handle is not valid
+ @exception NET_NFC_TAG_WRITE_FAILED read only tag, or error ack is received from tag
+ @exception NET_NFC_NO_DATA_FOUND mendantory tag info (UID, etc) is not founded
+
+*/
+
+net_nfc_error_e net_nfc_client_jewel_write_with_no_erase(
+ net_nfc_target_handle_h handle,
+ uint8_t block,
+ uint8_t byte,
+ uint8_t data,
+ nfc_transceive_callback callback,
+ void *user_data);
+
+/**
+@}
+*/
+
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif //__NET_NFC_CLIENT_TAG_JEWEL_H__
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_TAG_MIFARE_H__
+#define __NET_NFC_TAG_MIFARE_H__
+
+#include "net_nfc_typedef.h"
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+
+ @addtogroup NET_NFC_MANAGER_TAG
+ @{
+ Authenticate a sector with key A. I/O operation. e.g. read / write /
+ increment / decrement will be available after successful authentication.
+ This API is only available for MIFARE classic
+
+ MIFARE CLASSIC MINI
+ => 0 ~ 4 : 5 sector and 4 block with 16 bytes
+
+ MIFARE CLASSIC 1K
+ => 0 ~ 15 : 16 sector and 4 block with 16 bytes
+
+ MIFARE CLASSIC 4K
+ => 0 ~ 31 : 32 sector and 4 block with 16 bytes
+ => 32 ~ 39 : 8 sector and 16 block with 16 bytes
+
+ \par Sync (or) Async: Sync
+ This is a Asynchronous API
+
+ @param[in] handle target handle of detected tag
+ @param[in] sector sector to authenticate with key A
+ @param[in] auth_key 6 byte key to authenticate the sector
+
+ @return return the result of the calling the function
+
+ @exception NET_NFC_NULL_PARAMETER parameter has illigal NULL pointer
+ @exception NET_NFC_ALLOC_FAIL memory allocation is failed
+ @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization
+ @exception NET_NFC_BUSY Device is too busy to handle your request
+ @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error
+ @exception NET_NFC_RF_TIMEOUT Timeout raised while communicate with tag
+ @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command
+ @exception NET_NFC_INVALID_HANDLE target handle is not valid
+ @exception NET_NFC_NO_DATA_FOUND mendantory tag info (UID, etc) is not founded
+
+*/
+
+net_nfc_error_e net_nfc_client_mifare_authenticate_with_keyA(
+ net_nfc_target_handle_h handle,
+ uint8_t sector,
+ data_h auth_key,
+ void *callback,
+ void *user_data);
+
+/**
+ Authenticate a sector with key B. I/O operation. e.g. read / write /
+ increment / decrement will be available after successful authentication.
+ This API is only available for MIFARE classic
+
+ MIFARE CLASSIC MINI
+ => 0 ~ 4 : 5 sector and 4 block with 16 bytes
+
+ MIFARE CLASSIC 1K
+ => 0 ~ 15 : 16 sector and 4 block with 16 bytes
+
+ MIFARE CLASSIC 4K
+ => 0 ~ 31 : 32 sector and 4 block with 16 bytes
+ => 32 ~ 39 : 8 sector and 16 block with 16 bytes
+
+ \par Sync (or) Async: Sync
+ This is a Asynchronous API
+
+ @param[in] handle target handle of detected tag
+ @param[in] sector sector to authenticate with key B
+ @param[in] auth_key 6 byte key to authenticate the sector
+
+ @return return the result of the calling the function
+
+ @exception NET_NFC_NULL_PARAMETER parameter has illigal NULL pointer
+ @exception NET_NFC_ALLOC_FAIL memory allocation is failed
+ @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization
+ @exception NET_NFC_BUSY Device is too busy to handle your request
+ @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error
+ @exception NET_NFC_RF_TIMEOUT Timeout raised while communicate with tag
+ @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command
+ @exception NET_NFC_INVALID_HANDLE target handle is not valid
+ @exception NET_NFC_NO_DATA_FOUND mendantory tag info (UID, etc) is not founded
+
+*/
+
+
+net_nfc_error_e net_nfc_client_mifare_authenticate_with_keyB(
+ net_nfc_target_handle_h handle,
+ uint8_t sector,
+ data_h auth_key,
+ void *callback,
+ void *user_data);
+
+/**
+ read block or read page. If detected card is MIFARE classic, then It will
+ read a block (16 byte). If detected card is Ultra light, then It will read
+ 4 page (16 block)
+
+ \par Sync (or) Async: Sync
+ This is a Asynchronous API
+
+ @param[in] handle target handle of detected tag
+ @param[in] addr block or starting page number
+
+ @return return the result of the calling the function
+
+ @exception NET_NFC_NULL_PARAMETER parameter has illigal NULL pointer
+ @exception NET_NFC_ALLOC_FAIL memory allocation is failed
+ @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization
+ @exception NET_NFC_BUSY Device is too busy to handle your request
+ @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error
+ @exception NET_NFC_RF_TIMEOUT Timeout raised while communicate with tag
+ @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command
+ @exception NET_NFC_INVALID_HANDLE target handle is not valid
+ @exception NET_NFC_TAG_READ_FAILED received chunked data is not valied (damaged data is recieved) or error ack is recieved
+*/
+
+net_nfc_error_e net_nfc_client_mifare_read(net_nfc_target_handle_h handle,
+ uint8_t addr,
+ void *callback,
+ void *user_data);
+
+/**
+ write block (16 byte) to addr. Only 4 bytes will be written when tag is
+ ultra light
+
+ \par Sync (or) Async: Sync
+ This is a Asynchronous API
+
+ @param[in] handle target handle of detected tag
+ @param[in] addr block or starting page number
+ @param[in] data data to write
+
+ @return return the result of the calling the function
+
+ @exception NET_NFC_NULL_PARAMETER parameter has illigal NULL pointer
+ @exception NET_NFC_ALLOC_FAIL memory allocation is failed
+ @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization
+ @exception NET_NFC_BUSY Device is too busy to handle your request
+ @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error
+ @exception NET_NFC_RF_TIMEOUT Timeout raised while communicate with tag
+ @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command
+ @exception NET_NFC_INVALID_HANDLE target handle is not valid
+ @exception NET_NFC_TAG_WRITE_FAILED read only tag, or error ack is received from tag
+
+*/
+
+
+net_nfc_error_e net_nfc_client_mifare_write_block(
+ net_nfc_target_handle_h handle,
+ uint8_t addr,
+ data_h data,
+ void *callback,
+ void *user_data);
+
+/**
+ write page (4 byte) to addr. Only 4 bytes will be written when tag is
+ MIFARE classic
+
+ \par Sync (or) Async: Sync
+ This is a Asynchronous API
+
+ @param[in] handle target handle of detected tag
+ @param[in] addr block or starting page number
+ @param[in] data data to write
+
+ @return return the result of the calling the function
+
+ @exception NET_NFC_NULL_PARAMETER parameter has illigal NULL pointer
+ @exception NET_NFC_ALLOC_FAIL memory allocation is failed
+ @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization
+ @exception NET_NFC_BUSY Device is too busy to handle your request
+ @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error
+ @exception NET_NFC_RF_TIMEOUT Timeout raised while communicate with tag
+ @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command
+ @exception NET_NFC_INVALID_HANDLE target handle is not valid
+ @exception NET_NFC_TAG_WRITE_FAILED read only tag, or error ack is received from tag
+
+*/
+
+net_nfc_error_e net_nfc_client_mifare_write_page(
+ net_nfc_target_handle_h handle,
+ uint8_t addr,
+ data_h data,
+ void *callback,
+ void *user_data);
+
+
+/**
+ Increase a value block, storing the result in the temporary block on the
+ tag
+ This API is only available for MIFARE classic
+
+ \par Sync (or) Async: Sync
+ This is a Asynchronous API
+
+ @param[in] handle target handle of detected tag
+ @param[in] addr block
+ @param[in] value index of block to increase, starting from 0
+
+ @return return the result of the calling the function
+
+ @exception NET_NFC_NULL_PARAMETER parameter has illigal NULL pointer
+ @exception NET_NFC_ALLOC_FAIL memory allocation is failed
+ @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization
+ @exception NET_NFC_BUSY Device is too busy to handle your request
+ @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error
+ @exception NET_NFC_RF_TIMEOUT Timeout raised while communicate with tag
+ @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command
+ @exception NET_NFC_INVALID_HANDLE target handle is not valid
+ @exception NET_NFC_TAG_WRITE_FAILED read only tag, or error ack is received from tag
+
+*/
+
+net_nfc_error_e net_nfc_client_mifare_increment(net_nfc_target_handle_h handle,
+ uint8_t addr,
+ int value,
+ void *callback,
+ void *user_data);
+
+/**
+ Decrease a value block, storing the result in the temporary block on the tag
+ This API is only available for MIFARE classic
+
+ \par Sync (or) Async: Sync
+ This is a Asynchronous API
+
+ @param[in] handle target handle of detected tag
+ @param[in] addr block
+ @param[in] value index of block to decrease, starting from 0
+
+ @return return the result of the calling the function
+
+ @exception NET_NFC_NULL_PARAMETER parameter has illigal NULL pointer
+ @exception NET_NFC_ALLOC_FAIL memory allocation is failed
+ @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization
+ @exception NET_NFC_BUSY Device is too busy to handle your request
+ @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error
+ @exception NET_NFC_RF_TIMEOUT Timeout raised while communicate with tag
+ @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command
+ @exception NET_NFC_INVALID_HANDLE target handle is not valid
+ @exception NET_NFC_TAG_WRITE_FAILED read only tag, or error ack is received from tag
+
+*/
+
+net_nfc_error_e net_nfc_client_mifare_decrement(net_nfc_target_handle_h handle,
+ uint8_t addr,
+ int value,
+ void *callback,
+ void *user_data);
+
+/**
+ Copy from the temporary block to a value block.
+ This API is only available for MIFARE classic
+
+ \par Sync (or) Async: Sync
+ This is a Asynchronous API
+
+ @param[in] handle target handle of detected tag
+ @param[in] addr block
+ @param[in] value index of block to decrease, starting from 0
+
+ @return return the result of the calling the function
+
+ @exception NET_NFC_NULL_PARAMETER parameter has illigal NULL pointer
+ @exception NET_NFC_ALLOC_FAIL memory allocation is failed
+ @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization
+ @exception NET_NFC_BUSY Device is too busy to handle your request
+ @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error
+ @exception NET_NFC_RF_TIMEOUT Timeout raised while communicate with tag
+ @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command
+ @exception NET_NFC_INVALID_HANDLE target handle is not valid
+ @exception NET_NFC_TAG_WRITE_FAILED read only tag, or error ack is received from tag
+
+*/
+
+net_nfc_error_e net_nfc_client_mifare_transfer(net_nfc_target_handle_h handle,
+ uint8_t addr,
+ void *callback,
+ void *user_data);
+
+/**
+ Copy from a value block to the temporary block.
+ This API is only available for MIFARE classic
+
+ \par Sync (or) Async: Sync
+ This is a Asynchronous API
+
+ @param[in] handle target handle of detected tag
+ @param[in] addr block
+ @param[in] value index of block to decrease, starting from 0
+
+ @return return the result of the calling the function
+
+ @exception NET_NFC_NULL_PARAMETER parameter has illigal NULL pointer
+ @exception NET_NFC_ALLOC_FAIL memory allocation is failed
+ @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization
+ @exception NET_NFC_BUSY Device is too busy to handle your request
+ @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error
+ @exception NET_NFC_RF_TIMEOUT Timeout raised while communicate with tag
+ @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command
+ @exception NET_NFC_INVALID_HANDLE target handle is not valid
+ @exception NET_NFC_TAG_WRITE_FAILED read only tag, or error ack is received from tag
+
+*/
+
+net_nfc_error_e net_nfc_client_mifare_restore(net_nfc_target_handle_h handle,
+ uint8_t addr,
+ void *callback,
+ void *user_data);
+
+/**
+ create default factory key. The key is 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
+
+ \par Sync (or) Async: Sync
+ This is a Asynchronous API
+
+ @param[in] key the handle to create key
+
+ @return return the result of the calling the function
+
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ @exception NET_NFC_ALLOC_FAIL memory allocation is failed
+
+*/
+
+net_nfc_error_e net_nfc_client_mifare_create_default_key(data_h* key);
+
+/**
+ create mifare application directory key. The key is 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5
+
+ \par Sync (or) Async: Sync
+ This is a Asynchronous API
+
+ @param[in] key the handle to create key
+
+ @return return the result of the calling the function
+
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ @exception NET_NFC_ALLOC_FAIL memory allocation is failed
+
+*/
+
+net_nfc_error_e net_nfc_client_mifare_create_application_directory_key(
+ data_h* key);
+
+/**
+ create nfc forum key. The key is 0xD3, 0xF7, 0xD3, 0xF7, 0xD3, 0xF7
+
+ \par Sync (or) Async: Sync
+ This is a Asynchronous API
+
+ @param[in] key the handle to create key
+
+ @return return the result of the calling the function
+
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ @exception NET_NFC_ALLOC_FAIL memory allocation is failed
+
+*/
+
+net_nfc_error_e net_nfc_client_mifare_create_net_nfc_forum_key(data_h* key);
+
+/**
+@}
+*/
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif //__NET_NFC_TAG_MIFARE_H__
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_CLIENT_TEST_H__
+#define __NET_NFC_CLIENT_TEST_H__
+
+#include "net_nfc_typedef.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef void (*net_nfc_client_test_sim_test_completed) (net_nfc_error_e result,
+ void *user_data);
+
+typedef void (*net_nfc_client_test_prbs_test_completed) (
+ net_nfc_error_e result,
+ void *user_data);
+
+typedef void (*net_nfc_client_test_get_firmware_version_completed) (
+ net_nfc_error_e result,
+ char *version,
+ void *user_data);
+typedef void (*net_nfc_client_test_set_ee_data_completed) (
+ net_nfc_error_e result,
+ void *user_data);
+
+
+net_nfc_error_e net_nfc_client_test_sim_test(
+ net_nfc_client_test_sim_test_completed callback,
+ void *user_data);
+
+net_nfc_error_e net_nfc_client_test_sim_test_sync(void);
+
+net_nfc_error_e net_nfc_client_test_prbs_test(uint32_t tech,
+ uint32_t rate,
+ net_nfc_client_test_prbs_test_completed callback,
+ void *user_data);
+
+net_nfc_error_e net_nfc_client_test_prbs_test_sync(uint32_t tech,
+ uint32_t rate);
+
+net_nfc_error_e net_nfc_client_test_get_firmware_version(
+ net_nfc_client_test_get_firmware_version_completed callback,
+ void *user_data);
+
+net_nfc_error_e net_nfc_client_test_get_firmware_version_sync(char **version);
+
+net_nfc_error_e net_nfc_client_test_set_ee_data(int mode,
+ int reg_id,
+ data_h data,
+ net_nfc_client_test_set_ee_data_completed callback,
+ void *user_data);
+
+net_nfc_error_e net_nfc_client_test_set_ee_data_sync(int mode,
+ int reg_id,
+ data_h data);
+
+
+/* TODO : move to internal header */
+net_nfc_error_e net_nfc_client_test_init(void);
+
+void net_nfc_client_test_deinit(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif //__NET_NFC_CLIENT_TEST_H__
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_CLIENT_TRANSCEIVE_H__
+#define __NET_NFC_CLIENT_TRANSCEIVE_H__
+
+#include "net_nfc_typedef.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef void (* nfc_transceive_callback)(net_nfc_error_e result,
+ void *user_data);
+
+typedef void (* nfc_transceive_data_callback)(net_nfc_error_e result,
+ data_h data,
+ void *user_data);
+
+net_nfc_error_e net_nfc_client_transceive(net_nfc_target_handle_h handle,
+ data_h rawdata,
+ nfc_transceive_callback callback,
+ void *user_data);
+
+net_nfc_error_e net_nfc_client_transceive_data(net_nfc_target_handle_h handle,
+ data_h rawdata,
+ nfc_transceive_data_callback callback,
+ void *user_data);
+
+net_nfc_error_e net_nfc_client_transceive_sync(net_nfc_target_handle_h handle,
+ data_h rawdata);
+
+net_nfc_error_e net_nfc_client_transceive_data_sync(
+ net_nfc_target_handle_h handle,
+ data_h rawdata,
+ data_h *response);
+
+/* TODO : move to internal header */
+net_nfc_error_e net_nfc_client_transceive_init(void);
+
+void net_nfc_client_transceive_deinit(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif //__NET_NFC_CLIENT_TRANSCEIVE_H__
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_DATA_H__
+#define __NET_NFC_DATA_H__
+
+#include "net_nfc_typedef.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/**
+
+ @addtogroup NET_NFC_MANAGER_INFO
+ @{
+ This document is for the APIs reference document
+
+ NFC Manager defines are defined in <nfc-manager-def.h>
+
+ @li @c #net_nfc_initialize Initialize the nfc device.
+
+*/
+
+/**
+ create data handler only.
+
+ @param[out] data data handler
+
+ @return return the result of this operation
+
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ @exception NET_NFC_ALLOC_FAIL memory allocation is failed
+ */
+
+net_nfc_error_e net_nfc_create_data_only (data_h* data);
+
+/**
+ create data handler with initial values, bytes will be copied into the data handler.
+
+ @param[out] data data handler
+ @param[in] bytes binary data
+ @param[in] length size of binary data;
+
+ @return return the result of this operation
+
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ @exception NET_NFC_ALLOC_FAIL memory allocation is failed
+ */
+net_nfc_error_e net_nfc_create_data (data_h* data, const uint8_t* bytes, const uint32_t length);
+
+/**
+ get the byes and length from data handler. data handler assume bytes may have '0x0' value.
+ that's why this function also provides the length.
+
+ @param[in] data data handler
+ @param[out] bytes binary pointer (it returns the direct pointer of handler's data) do not free this
+ @param[out] length length of the binary data;
+
+ @return return the result of this operation
+
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ */
+net_nfc_error_e net_nfc_get_data (const data_h data, uint8_t** bytes, uint32_t * length);
+
+/**
+ replace the data handler with given bytes. binary data (bytes) will be copied to data hander.
+ application should free or use local variable for given byte pointer.
+
+ @param[in] data data handler
+ @param[in] bytes binary data
+ @param[in] length size of binary data
+
+ @return return the result of this operation
+
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ */
+
+net_nfc_error_e net_nfc_set_data (const data_h data, const uint8_t* bytes, const uint32_t length);
+
+/**
+ get length of data handler's bytes.
+
+ @param[in] data data handler
+
+ @return length of bytes length
+
+ @exception 0 is returned if data is NULL
+ */
+
+uint32_t net_nfc_get_data_length (const data_h data);
+
+/**
+ get pointer of the handler's bytes (do not free this. it wll be freed when the application call "net_nfc_free_data" function
+
+ @param[in] data data handler
+
+ @return the pointer of bytes.
+
+ @exception NULL is returned if data is NULL
+ */
+
+uint8_t * net_nfc_get_data_buffer (const data_h data);
+
+/**
+ free data handler. (it also free the copied bytes)
+
+ @param[in] data data handler
+
+ @return return the result of this operation
+
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ */
+
+net_nfc_error_e net_nfc_free_data (data_h data);
+
+
+
+/**
+@}
+*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif //__NET_NFC_DATA_H__
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_NDEF_MESSAGE_H__
+#define __NET_NFC_NDEF_MESSAGE_H__
+
+#include "net_nfc_typedef.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/**
+
+ @addtogroup NET_NFC_MANAGER_NDEF
+ @{
+ This document is for the APIs reference document
+
+ NFC Manager defines are defined in <nfc-manager-def.h>
+
+ @li @c #net_nfc_initialize Initialize the nfc device.
+
+*/
+
+/**
+ create ndef message handler. this function allocate the ndef message handler and initialize.
+
+ \par Sync (or) Async: sync
+ This is a Synchronous API
+
+ @param[out] ndef_message instance of the ndef_message is retuened
+
+ @return return the result of the calling the function
+
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ @exception NET_NFC_ALLOC_FAIL memory allocation is failed
+
+ @code
+
+ net_nfc_error_e result = NET_NFC_OK;
+ ndef_message_h msg = NULL;
+ ndef_record_h record = NULL;
+
+ result = net_nfc_create_ndef_message (&msg);
+ if (result != NET_NFC_OK) return result;
+
+ result = net_nfc_create_uri_type_record (&record , "http://www.samsung.com" ,NET_NFC_SCHEMA_FULL_URI);
+ if (result != NET_NFC_OK) return result;
+
+ result = net_nfc_append_record_to_ndef_message (msg ,record);
+ if (result != NET_NFC_OK) return result;
+
+ net_nfc_write_ndef(id, msg, &user_context);
+
+ net_nfc_free_ndef_message (msg);
+
+ @endcode
+ */
+
+
+net_nfc_error_e net_nfc_create_ndef_message (ndef_message_h* ndef_message);
+
+/**
+ this APIs is the getter of record counts
+
+ \par Sync (or) Async: sync
+ This is a Synchronous API
+
+ @param[in] ndef_message output structure to get the record
+ @param[out] count number of record count
+
+
+ @return return the result of the calling the function
+
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+
+ @code
+
+ static void net_nfc_cb(net_nfc_message_e message, net_nfc_error_e result, void* data , void* userContext)
+ {
+ switch (message)
+ {
+ case NET_NFC_MESSAGE_READ_NDEF:
+ {
+ if(data != NULL)
+ {
+ int count = 0;
+ ndef_message_h ndef = (ndef_message_h)(data);
+ net_nfc_get_ndef_message_record_count (ndef, &count);
+ printf ("record count = %d\n", count);
+ }
+ }
+ break;
+ }
+ }
+ @endcode
+*/
+net_nfc_error_e net_nfc_get_ndef_message_record_count (ndef_message_h ndef_message, int * count);
+
+/**
+ This function converts the NDEF Message structure to serial bytes of ndef message.
+
+ it gets copy of the rawdata bytes from ndef_message. ndef_message has no effect after free rawdata
+ Application should free rawdata.
+
+ \par Sync (or) Async: sync
+ This is a Synchronous API
+
+ @param[in] ndef_message output structure to get the record
+ @param[out] rawdata this is the raw data that will be formed into the
+
+ @return return the result of the calling the function
+
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ @exception NET_NFC_ALLOC_FAIL memory allocation is failed
+ @exception NET_NFC_NDEF_BUF_END_WITHOUT_ME Wrong formatted NDEF message
+
+ @code
+
+ net_nfc_error_e result = NET_NFC_OK;
+ data_h rawdata;
+ ndef_message_h msg = NULL;
+ ndef_record_h record = NULL;
+ int idx;
+ uint8_t * buffer = NULL;
+
+ result = net_nfc_create_ndef_message (&msg);
+ if (result != NET_NFC_OK) return result;
+
+ result = net_nfc_create_uri_type_record (&record , "http://www.samsung.com" ,NET_NFC_SCHEMA_FULL_URI);
+ if (result != NET_NFC_OK) return result;
+
+ result = net_nfc_append_record_to_ndef_message (msg ,record);
+ if (result != NET_NFC_OK) return result;
+
+ net_nfc_create_rawdata_from_ndef_message (msg, &rawdata);
+
+ buffer = net_nfc_get_data_buffer (rawdata) ;
+
+ for (idx = 0; idx < net_nfc_get_data_length (rawdata) ; idx++)
+ {
+ printf (" %02X", buffer[idx]);
+ if (idx % 16 == 0) printf ("\n");
+ }
+
+ net_nfc_free_ndef_message (msg);
+
+ @endcode
+
+
+*/
+
+net_nfc_error_e net_nfc_create_rawdata_from_ndef_message (ndef_message_h ndef_message, data_h* rawdata);
+
+/**
+ This function return the structure of ndef_message from serial format of ndef message.
+ You may say create ndef handler from raw serial bytes
+ it cunsumes the bytes array until get the (ME==1). it retunrs error if the bytes array does not have ME flag.
+ if the array has two NDEF Message serially (not recursive case - like smart poster). the first NDEF message
+ will be converted to ndef_message handler, and other messages will be ignored.
+
+ \par Sync (or) Async: sync
+ This is a Synchronous API
+
+ @param[out] ndef_message ndef message handler that will be returned
+ @param[in] rawdata ndef message that formed in bytes array
+
+ @return return the result of the calling the function
+
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ @exception NET_NFC_ALLOC_FAIL memory allocation is failed
+ @exception NET_NFC_NDEF_BUF_END_WITHOUT_ME Wrong formatted NDEF message
+
+ @code
+
+ static void net_nfc_cb(net_nfc_message_e message, net_nfc_error_e result, void* data , void* userContext)
+ {
+ switch (message)
+ {
+ case NET_NFC_MESSAGE_READ_NDEF:
+ {
+ if(data != NULL)
+ {
+ record_h record;
+ ndef_message_h url;
+ data_h ndef_type;
+ data_h payload;
+
+ ndef_message_h ndef = (ndef_message_h)(data);
+ net_nfc_get_record_by_index (ndef, 0, &record);
+ net_nfc_get_record_type (record, &ndef_type);
+ if (strncmp (ndef_type.buffer, "Sp", ndef_type.length)){
+ net_nfc_get_record_payload (record, &payload);
+ net_nfc_create_ndef_message_from_rawdata (&url, payload);
+ printf_ndef_massage (url);
+ }
+ }
+ }
+ break;
+ }
+ }
+ @endcode
+
+*/
+
+
+net_nfc_error_e net_nfc_create_ndef_message_from_rawdata (ndef_message_h* ndef_message, data_h rawdata);
+
+/**
+ it returns the total size of ndef message bytes. parse the structure data and count the bytes
+ to know the length of bytes required to store the NDEF message.
+
+ it calculates the length every time application calls this function. it does not cache inside.
+ TODO: do we need to cache the value inside of ndef_message_h
+
+ \par Sync (or) Async: sync
+ This is a Synchronous API
+
+ @param[in] ndef_message this is the raw data that will be formed into the
+ @param[out] length number of bytes required to create ndef message serial format
+
+ @return return the result of the calling the function
+
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+*/
+
+net_nfc_error_e net_nfc_get_ndef_message_byte_length(ndef_message_h ndef_message, uint32_t *length);
+/**
+ Append a record to ndef message structure.
+ This API help to create NDEF message and it control Record flags to follow the NDEF forum specification
+
+ \par Sync (or) Async: sync
+ This is a Synchronous API
+
+ @param[in] ndef_message NDEF message structure
+ @param[in] record a record will be added into the ndef message
+
+ @return return the result of the calling the function
+
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+
+ @code
+
+ net_nfc_error_e result = NET_NFC_OK;
+ data_h rawdata;
+ ndef_message_h msg = NULL;
+ ndef_record_h record = NULL;
+ int idx;
+ uint8_t * buffer = NULL;
+
+ result = net_nfc_create_ndef_message (&msg);
+ if (result != NET_NFC_OK) return result;
+
+ result = net_nfc_create_uri_type_record (&record , "http://www.samsung.com" ,NET_NFC_SCHEMA_FULL_URI);
+ if (result != NET_NFC_OK) return result;
+
+ result = net_nfc_append_record_to_ndef_message (msg ,record);
+ if (result != NET_NFC_OK) return result;
+
+ net_nfc_create_rawdata_from_ndef_message (msg, &rawdata);
+
+ buffer = net_nfc_get_data_buffer (rawdata) ;
+
+ for (idx = 0; idx < net_nfc_get_data_length (rawdata) ; idx++)
+ {
+ printf (" %02X", buffer[idx]);
+ if (idx % 16 == 0) printf ("\n");
+ }
+
+ net_nfc_free_ndef_message (msg);
+
+ @endcode
+*/
+net_nfc_error_e net_nfc_append_record_to_ndef_message(ndef_message_h ndef_message, ndef_record_h record);
+
+/**
+ remove the record that indicated by index number.
+ and this deleted record will be freed.
+
+ \par Sync (or) Async: sync
+ This is a Synchronous API
+
+ @param[in] ndef_message the message wil be freed
+ @param[in] index index of record
+
+ @return return the result of the calling the function
+
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ @exception NET_NFC_OUT_OF_BOUND index is out of bound
+ @exception NET_NFC_INVALID_FORMAT Wrong formatted ndef message
+
+*/
+
+net_nfc_error_e net_nfc_remove_record_by_index (ndef_message_h ndef_message, int index);
+
+/**
+ get record by index. this function just return the pointer of record.
+ if you change the record value it directly affected to NDEF message
+
+ \par Sync (or) Async: sync
+ This is a Synchronous API
+
+ @param[in] ndef_message the message wil be freed
+ @param[in] index index of record
+ @param[in] record record pointer
+
+ @return return the result of the calling the function
+
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ @exception NET_NFC_OUT_OF_BOUND index is out of bound
+
+*/
+net_nfc_error_e net_nfc_get_record_by_index (ndef_message_h ndef_message, int index, ndef_record_h* record);
+
+/**
+ Add a record by index. This API help to add record by index. MB or ME bits will automatically assained.
+
+ \par Sync (or) Async: sync
+ This is a Synchronous API
+
+ @param[in] ndef_message the message wil be freed
+ @param[in] index index of record
+ @param[in] record record pointer
+
+ @return return the result of the calling the function
+
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ @exception NET_NFC_OUT_OF_BOUND index is out of bound
+ @exception NET_NFC_INVALID_FORMAT Wrong formatted ndef message
+ */
+
+net_nfc_error_e net_nfc_append_record_by_index (ndef_message_h ndef_message,int index, ndef_record_h record);
+
+
+/**
+ search the specific type in the NDEF message. this function return the first record that holds the type.
+ if the type has "urn:nfc:wkt:" or "urn:nfc:ext:", these prefix will be removed automatically.
+
+ @param[in] ndef_message NDEF message handler
+ @param[in] tnf TNF value
+ @param[in] type Record type , include type length
+ @param[out] record record handle
+
+ @return return the result of the calling the function
+
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ @exception NET_NFC_NO_DATA_FOUND search is failed
+ @exception NET_NFC_INVALID_FORMAT Wrong formatted ndef message
+
+ @code
+
+ static void net_nfc_cb(net_nfc_message_e message, net_nfc_error_e result, void* data , void* userContext)
+ {
+ switch (message)
+ {
+ case NET_NFC_MESSAGE_READ_NDEF:
+ {
+ if(data != NULL)
+ {
+ date_h type;
+ int count = 0;
+ ndef_message_h ndef = (ndef_message_h)(data);
+ ndef_record_h record;
+ net_nfc_create_data (&type, "Sp", 2);
+ net_nfc_search_record_by_type (ndef, NET_NFC_RECORD_WELL_KNOWN_TYPE, type, &record);
+ }
+ }
+ break;
+ }
+ }
+
+ @endcode
+
+*/
+net_nfc_error_e net_nfc_search_record_by_type (ndef_message_h ndef_message, net_nfc_record_tnf_e tnf, data_h type, ndef_record_h * record);
+
+
+/**
+ this function helps to free the ndef_message_s type structure.
+ it has multiple ndef_record_s with linked list form and each record has own pointer.
+ this function free these memory in one shot!
+ don't worry about the record handler. these handlers also freed.
+
+ \par Sync (or) Async: sync
+ This is a Synchronous API
+
+ @param[in] ndef_message the message wil be freed
+
+ @return return the result of the calling the function
+
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+
+*/
+
+net_nfc_error_e net_nfc_free_ndef_message(ndef_message_h ndef_message);
+
+
+/**
+ retreive ndef message which is read by nfc-manager .
+ after reading message, it will be removed from nfc-manager storage
+
+ \par Sync (or) Async: sync
+ This is a Synchronous API
+
+ @param[in] ndef_message the message wil be retrieved
+
+ @return return the result of the calling the function
+
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ @exception NET_NFC_NO_NDEF_MESSAGE No ndef message is found
+ @exception NET_NFC_INVALID_FORMAT Wrong formatted ndef message
+ @exception NET_NFC_ALLOC_FAIL memory allocation is failed
+
+*/
+
+net_nfc_error_e net_nfc_retrieve_current_ndef_message (ndef_message_h* ndef_message);
+
+
+/**
+@}
+*/
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif //__NET_NFC_NDEF_MESSAGE_H__
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_NDEF_MESSAGE_HANDOVER_H__
+#define __NET_NFC_NDEF_MESSAGE_HANDOVER_H__
+
+#include "net_nfc_typedef.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ This function create wifi configure handler instance.
+
+ @param[out] config instance handler
+ @param[in] type Carrier types it would be wifi add hoc or wifi AP
+
+ @return return the result of the calling the function
+
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ @exception NET_NFC_OUT_OF_BOUND type value is not enum value
+ @exception NET_NFC_ALLOC_FAIL allocation is failed
+ */
+
+net_nfc_error_e net_nfc_create_carrier_config (net_nfc_carrier_config_h * config, net_nfc_conn_handover_carrier_type_e type);
+
+/**
+ Add property key and value for configuration.
+ the data will be copied to config handle, you should free used data array.
+
+ @param[in] config instance handler
+ @param[in] attribute attribue key for value.
+ @param[in] size size of value
+ @param[in] data value array (binary type)
+
+ @return return the result of the calling the function
+
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ @exception NET_NFC_ALLOC_FAIL allocation is failed
+ */
+
+net_nfc_error_e net_nfc_add_carrier_config_property (net_nfc_carrier_config_h config, uint16_t attribute, uint16_t size, uint8_t * data);
+
+/**
+ Remove the key and value from configuration, you can also remove the group withe CREDENTIAL key.
+ The the attribute is exist then it will be removed and also freed automatically.
+
+ @param[in] config instance handler
+ @param[in] attribute attribue key for value.
+
+ @return return the result of the calling the function
+
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ @exception NET_NFC_NO_DATA_FOUND the given key is not found
+ @exception NET_NFC_ALREADY_REGISTERED the given attribute is already registered
+ */
+
+net_nfc_error_e net_nfc_remove_carrier_config_property (net_nfc_carrier_config_h config, uint16_t attribute);
+/**
+ Get the property value by attribute.
+
+ @param[in] config instance handler
+ @param[in] attribute attribue key for value.
+ @param[out] size size of value
+ @param[out] data value array (binary type)
+
+ @return return the result of the calling the function
+
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ @exception NET_NFC_NO_DATA_FOUND The given key is not found
+ */
+
+net_nfc_error_e net_nfc_get_carrier_config_property (net_nfc_carrier_config_h config, uint16_t attribute, uint16_t * size, uint8_t ** data);
+
+/**
+ The group will be joined into the configure
+
+ @param[in] config instance handler
+ @param[in] group group handle
+
+ @return return the result of the calling the function
+
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ @exception NET_NFC_ALREADY_REGISTERED The given group is already registered
+ */
+
+net_nfc_error_e net_nfc_append_carrier_config_group (net_nfc_carrier_config_h config, net_nfc_property_group_h group);
+
+/**
+ Remove the group from configure handle
+
+ @param[in] config instance handler
+ @param[in] group group handle
+
+ @return return the result of the calling the function
+
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ @exception NET_NFC_NO_DATA_FOUND given handle pointer is not exist in the configure handle
+ */
+
+net_nfc_error_e net_nfc_remove_carrier_config_group (net_nfc_carrier_config_h config, net_nfc_property_group_h group);
+
+/**
+ Get the group from configure handle by index
+
+ @param[in] config instance handler
+ @param[in] index index number
+ @param[out] group group handle
+
+ @return return the result of the calling the function
+
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ @exception NET_NFC_OUT_OF_BOUND the index number is not bound of the max count
+ @exception NET_NFC_NO_DATA_FOUND this is should be happened if the configure handle is dammaged
+ */
+
+net_nfc_error_e net_nfc_get_carrier_config_group (net_nfc_carrier_config_h config, int index, net_nfc_property_group_h * group);
+
+/**
+ free the configure handle
+
+ @param[in] config instance handler
+
+ @return return the result of the calling the function
+
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ */
+
+net_nfc_error_e net_nfc_free_carrier_config (net_nfc_carrier_config_h config);
+
+/**
+ create the group handle
+
+ @param[out] group instance group handler
+
+ @return return the result of the calling the function
+
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ @exception NET_NFC_ALLOC_FAIL allocation is failed
+ */
+
+net_nfc_error_e net_nfc_create_carrier_config_group (net_nfc_property_group_h * group, uint16_t attribute);
+
+/**
+ add property into the group
+
+ @param[in] group instance group handler
+ @param[in] attribute attribute of the property
+ @param[in] size size of data (value)
+ @param[in] data data of the property
+
+ @return return the result of the calling the function
+
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ @exception NET_NFC_ALLOC_FAIL allocation is failed
+ @exception NET_NFC_ALREADY_REGISTERED the given key is already registered
+ */
+
+net_nfc_error_e net_nfc_add_carrier_config_group_property (net_nfc_property_group_h group, uint16_t attribute, uint16_t size, uint8_t * data);
+
+/**
+ get property from group handle
+
+ @param[in] group instance group handler
+ @param[in] attribute attribute of the property
+ @param[out] size size of data (value)
+ @param[out] data data of the property
+
+ @return return the result of the calling the function
+
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ @exception NET_NFC_NO_DATA_FOUND the attribute does not exist in the group
+ */
+
+net_nfc_error_e net_nfc_get_carrier_config_group_property (net_nfc_property_group_h group, uint16_t attribute, uint16_t *size, uint8_t ** data);
+
+/**
+ remove the property from the group
+
+ @param[in] group instance group handler
+ @param[in] attribute attribute of the property
+
+ @return return the result of the calling the function
+
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ @exception NET_NFC_NO_DATA_FOUND the attribute does not exist in the group
+ */
+
+net_nfc_error_e net_nfc_remove_carrier_config_group_property (net_nfc_property_group_h group, uint16_t attribute);
+
+
+/**
+ free the group
+
+ @param[in] group instance group handler
+
+ @return return the result of the calling the function
+
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ */
+
+net_nfc_error_e net_nfc_free_carrier_group (net_nfc_property_group_h group);
+
+/**
+ Create record handler with config.
+
+ @param[out] record record handler
+ @param[in] config the wifi configure handle
+
+ @return return the result of the calling the function
+
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ @exception NET_NFC_ALLOC_FAIL allocation is failed
+ */
+
+net_nfc_error_e net_nfc_create_ndef_record_with_carrier_config (ndef_record_h * record, net_nfc_carrier_config_h config);
+
+
+/**
+ create configure from the ndef record. the. the record must contained the configuration.
+ config should be freed after using
+
+ @param[in] record record handler
+ @param[out] config the configure handle
+
+ @return return the result of the calling the function
+
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ @exception NET_NFC_ALLOC_FAIL allocation is failed
+ @exception NET_NFC_INVALID_FORMAT if the record does not contained the valid format.
+ */
+
+net_nfc_error_e net_nfc_create_carrier_config_from_config_record (net_nfc_carrier_config_h* config, ndef_record_h record);
+
+/**
+ append record into the connection handover request for reponse message;
+
+ @param[in] message ndef message handler
+ @param[in] record record handler
+ @param[in] power_status the power status of the current configuration
+
+ @return return the result of the calling the function
+
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ @exception NET_NFC_ALLOC_FAIL allocation is failed
+ @exception NET_NFC_INVALID_FORMAT if the record does not contained the valid format.
+ @exception NET_NFC_NO_DATA_FOUND the attribute does not exist in the group
+ */
+net_nfc_error_e net_nfc_append_carrier_config_record (ndef_message_h message, ndef_record_h record, net_nfc_conn_handover_carrier_state_e power_status);
+
+/**
+ append record into the connection handover request for reponse message;
+
+ @param[in] message ndef message handler
+ @param[in] record record handler
+
+ @return return the result of the calling the function
+
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ @exception NET_NFC_ALLOC_FAIL allocation is failed
+ @exception NET_NFC_INVALID_FORMAT if the record does not contained the valid format.
+ @exception NET_NFC_NO_DATA_FOUND Given record does not exist in the ndef message
+ */
+
+net_nfc_error_e net_nfc_remove_carrier_config_record (ndef_message_h message, ndef_record_h record);
+
+/**
+ get configure record from ndef message by index
+
+ @param[in] message ndef message handler
+ @param[in] index
+ @param[out] record record handler
+
+ @return return the result of the calling the function
+
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ @exception NET_NFC_ALLOC_FAIL allocation is failed
+ @exception NET_NFC_INVALID_FORMAT if the record does not contained the valid format.
+ */
+
+net_nfc_error_e net_nfc_get_carrier_config_record (ndef_message_h message, int index, ndef_record_h * record);
+
+/**
+ get randome number from the connection request message
+
+ @param[in] message ndef message handler
+ @param[out] randome_number randome number
+
+ @return return the result of the calling the function
+
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ @exception NET_NFC_INVALID_FORMAT if the record does not contained the valid format.
+ */
+
+net_nfc_error_e net_nfc_get_handover_random_number(ndef_message_h message, unsigned short* random_number);
+
+/**
+ get the count of the alternative (configuration) in the message
+
+ @param[in] message ndef message handler
+ @param[out] count number configuration in the message
+
+ @return return the result of the calling the function
+
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ @exception NET_NFC_INVALID_FORMAT if the record does not contained the valid format.
+ */
+net_nfc_error_e net_nfc_get_alternative_carrier_record_count (ndef_message_h message, unsigned int * count);
+
+
+/**
+ get power status of the given configruation
+
+ @param[in] message ndef message handler
+ @param[in] index index
+ @param[out] power_state power state of the alternative
+
+ @return return the result of the calling the function
+
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ @exception NET_NFC_INVALID_FORMAT if the record does not contained the valid format.
+ @exception NET_NFC_NO_DATA_FOUND there is no alternative record is found
+ @exception NET_NFC_OUT_OF_BOUND index number is out of message count
+ */
+
+net_nfc_error_e net_nfc_get_alternative_carrier_power_status (ndef_message_h message, int index, net_nfc_conn_handover_carrier_state_e * power_state);
+
+/**
+ set power status of the given configruation
+
+ @param[in] message ndef message handler
+ @param[in] index index
+ @param[in] power_state power state of the alternative
+
+ @return return the result of the calling the function
+
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ @exception NET_NFC_INVALID_FORMAT if the record does not contained the valid format.
+ @exception NET_NFC_NO_DATA_FOUND there is no alternative record is found
+ @exception NET_NFC_OUT_OF_BOUND index number is out of message count
+ */
+net_nfc_error_e net_nfc_set_alternative_carrier_power_status (ndef_message_h message, int index, net_nfc_conn_handover_carrier_state_e power_status);
+
+/**
+ this function will get carrier type.
+
+ @param[in] carrier_info connection handover carrier info handler
+ @param[in] carrier_type record type. it can be a NET_NFC_CONN_HANDOVER_CARRIER_BT or NET_NFC_CONN_HANDOVER_CARRIER_WIFI or NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN.
+
+ @return return the result of the calling the function
+
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ */
+
+net_nfc_error_e net_nfc_get_alternative_carrier_type (ndef_message_h message, int index, net_nfc_conn_handover_carrier_type_e * power_state);
+
+
+/**
+ craete the connection handover request message
+
+ @param[in] message connection handover carrier info handler
+
+ @return return the result of the calling the function
+
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ @exception NET_NFC_ALLOC_FAIL allocation is failed
+ */
+
+net_nfc_error_e net_nfc_create_handover_request_message (ndef_message_h * message);
+
+/**
+ craete the connection handover select message
+
+ @param[in] message connection handover carrier info handler
+
+ @return return the result of the calling the function
+
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ @exception NET_NFC_ALLOC_FAIL allocation is failed
+ */
+
+net_nfc_error_e net_nfc_create_handover_select_message (ndef_message_h * message);
+
+/**
+ craete the connection handover error record message
+
+ @param[out] record connection handover carrier info handler
+ @param[in] reason error codes (reason)
+ @param[in] data extra data for each error codes
+
+ @return return the result of the calling the function
+
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ @exception NET_NFC_ALLOC_FAIL allocation is failed
+ */
+net_nfc_error_e net_nfc_create_handover_error_record (ndef_record_h * record, uint8_t reason, uint32_t data);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif //__NET_NFC_NDEF_MESSAGE_HANDOVER_H__
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_NDEF_RECORD_H__
+#define __NET_NFC_NDEF_RECORD_H__
+
+#include "net_nfc_typedef.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/**
+
+ @addtogroup NET_NFC_MANAGER_RECORD
+ @{
+ This document is for the APIs reference document
+
+ NFC Manager defines are defined in <nfc-typedef.h>
+
+*/
+
+
+/**
+ This define gives you Message Begin from the flag byte
+
+ @param[in] flag flag that comes from "net_nfc_get_record_flags" function
+ @return the mb flag
+
+ @exception NONE
+ */
+uint8_t net_nfc_get_record_mb (uint8_t flag);
+/**
+ This define gives you Message end from the flag byte
+
+ @param[in] flag flag that comes from "net_nfc_get_record_flags" function
+ @return the me flag
+
+ @exception NONE
+ */
+uint8_t net_nfc_get_record_me (uint8_t flag);
+/**
+ This define gives you Chun Flag that indicate that either the first record chunk or a middle record chunk of a chunked payload
+
+ @param[in] flag flag that comes from "net_nfc_get_record_flags" function
+ @return the chunk flag
+
+ @exception NONE
+ */
+uint8_t net_nfc_get_record_cf (uint8_t flag);
+/**
+ This define gives you ID length present flag
+
+ @param[in] flag flag that comes from "net_nfc_get_record_flags" function
+ @return the il (id length flag) flag
+
+ @exception NONE
+
+*/
+uint8_t net_nfc_get_record_il (uint8_t flag);
+/**
+ This define gives you short record flag. This flag indicates that the payload length filed is a single octet
+
+ @param[in] flag flag that comes from "net_nfc_get_record_flags" function
+ @return the short record flag
+
+ @exception NONE
+ */
+uint8_t net_nfc_get_record_sr (uint8_t flag);
+
+
+
+/**
+ creat a record with given parameter value. this function automatically set the NDEF record flags
+
+ @param[out] record Record handler
+ @param[in] tnf record type (TNF value) empty, well known, mime type, URI, external, or unchanged
+ @param[in] typeName specify type name ex) Sp, U, or Hr ...
+ @param[in] id record id
+ @param[in] payload payload of this record
+
+ @return return the result of the calling the function
+
+ @exception NET_NFC_OUT_OF_BOUND tnf value is out of range
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ @exception NET_NFC_ALLOC_FAIL memory allocation is failed
+
+ @code
+ char uri[] = " yahoo.com";
+ ndef_record_s uriRecord;
+
+ data_h payload;
+
+ net_nfc_create_data (&payload, uri, strlen (uri));
+ uri[0] = 0x01;
+
+ if((result = net_nfc_create_record( &uriRecord, NET_NFC_RECORD_WELL_KNOWN_TYPE, "U" , NULL, payload, )) != NET_NFC_OK)
+ {
+ printf("U record is failed [%d]\n", result);
+ }
+ @endcode
+ */
+net_nfc_error_e net_nfc_create_record(ndef_record_h* record, net_nfc_record_tnf_e tnf, data_h typeName, data_h id, data_h payload );
+
+
+/**
+ this function helps to create text type payload
+ please, refer the NDEF forum specification "Text Record Type Definition"
+ it creates byte array payload can be used in text type record
+
+ this function does not encode the text. The paramter "text" will be asuumed as that it is already encoded with encode type.
+ this function just helps to create text records.
+
+ @param[out] record Record handler
+ @param[in] text encoded text (this should be text not binary)
+ @param[in] language_code_str language_code_str ex) en-US
+ @param[in] encode text concoding type such as "utf8"
+
+ @return return the result of the calling the function
+
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ @exception NET_NFC_ALLOC_FAIL memory allocation is failed
+
+
+ @code
+ net_nfc_error_e result = NET_NFC_OK;
+ ndef_message_h msg = NULL;
+ ndef_record_h record = NULL;
+
+ char* message = "Hello, NFC World";
+
+ net_nfc_create_ndef_message (&msg);
+ net_nfc_create_text_type_record (&record , message, "en-US", NET_NFC_ENCODE_UTF_8);
+ net_nfc_append_record_to_ndef_message (msg ,record);
+
+ @endcode
+
+*/
+net_nfc_error_e net_nfc_create_text_type_record(ndef_record_h* record, const char* text, const char* language_code_str, net_nfc_encode_type_e encode);
+
+/**
+ this function helps to create URI type payload
+ please refer the NFC forum specification "URI Record type Definition"
+ it creates byte array payload.
+
+ @param[out] record Record handler
+ @param[in] uri string uri that will be stored in the payload
+ @param[in] protocol_schema protocol schema that is specified in NFC Forum
+
+
+ @return return the result of the calling the function
+
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ @exception NET_NFC_ALLOC_FAIL memory allocation is failed
+
+ @code
+ net_nfc_error_e result = NET_NFC_OK;
+ ndef_message_h msg = NULL;
+ ndef_record_h record = NULL;
+
+ net_nfc_create_ndef_message (&msg);
+ net_nfc_create_uri_type_record (&record ,"http://www.samsung.com" ,NET_NFC_SCHEMA_FULL_URI);
+ net_nfc_append_record_to_ndef_message (msg ,record);
+ @endcode
+ */
+
+net_nfc_error_e net_nfc_create_uri_type_record(ndef_record_h* record, const char * uri, net_nfc_schema_type_e protocol_schema);
+
+/**
+ this function is getter of record payload.
+ this function gives you the pointer of pyaload that is contained by record.
+ Do not free the payload. it will be freed when the record is freed
+
+ @param[in] record Record handler
+ @param[out] payload data_h type payload pointer (it gives you the pointer of payload; not copied)
+
+ @return return the result of the calling the function
+
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+
+*/
+net_nfc_error_e net_nfc_get_record_payload (ndef_record_h record, data_h * payload);
+
+/**
+ this function is getter of record type.
+ this function gives you the pointer of record type that is contained by record.
+ Do not free the type. it will be freed when the record is freed
+
+ @param[in] record Record handler
+ @param[out] type dat_h type pointer (it gives you the pointer of type; not copied)
+
+ @return return the result of the calling the function
+
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+
+*/
+net_nfc_error_e net_nfc_get_record_type (ndef_record_h record, data_h * type);
+
+/**
+ this function is getter of record ID.
+ this function gives you the pointer of ID that is contained by record.
+ it may return NULL pointer if the ID is not exist
+ Do not free the type. it will be freed when the record is freed.
+
+ @param[in] record Record handler
+ @param[out] id dat_h type ID pointer (it gives you the pointer of payload not copied)
+
+ @return return the result of the calling the function
+
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ */
+net_nfc_error_e net_nfc_get_record_id (ndef_record_h record, data_h * id);
+
+/**
+ this function is getter of record TNF value.
+
+ @param[in] record Record handler
+ @param[out] tnf TNF value
+
+ @return return the result of the calling the function
+
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+
+
+*/
+net_nfc_error_e net_nfc_get_record_tnf(ndef_record_h record, net_nfc_record_tnf_e * tnf);
+
+/**
+ this function is getter of record flags.
+ you can get the each flag value by using defines "RECORD_GET_XX"
+
+ @param[in] record Record handler
+ @param[out] flag flag value (it gives you the pointer of payload not copied)
+
+ @return return the result of the calling the function
+
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+
+ @code
+
+ ndef_record_h record;
+ uint8_t flag;
+
+ net_nfc_get_record_by_index (msg, 0, &record);
+ if (record != NULL){
+ net_nfc_get_record_flags (record, &flag);
+ printf ("MB:%d, ME:%d, CF:%d, IL:%d, SR:%d\n",
+ net_nfc_get_record_mb(flag),
+ net_nfc_get_record_me(flag),
+ net_nfc_get_record_cf(flag),
+ net_nfc_get_record_il(flag),
+ net_nfc_get_record_sr(flag));
+ }
+
+ @endcode
+
+*/
+net_nfc_error_e net_nfc_get_record_flags (ndef_record_h record, uint8_t * flag);
+
+
+/**
+ you can set record ID with this function
+
+ @param[in] record Record handler
+ @param[in] id Record ID
+
+ @return return the result of the calling the function
+
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+
+*/
+net_nfc_error_e net_nfc_set_record_id (ndef_record_h record, data_h id);
+
+/**
+ this function free the record handler. do not use this function after appending the ndef message
+
+ @param[in] record Record handler
+
+ @return return the result of the calling the function
+
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+
+*/
+net_nfc_error_e net_nfc_free_record (ndef_record_h record);
+
+
+/**
+ this function get text from text record. it allocate buffer char and store the text string. you should free this string.
+
+ @param[in] record Record handler
+ @param[out] buffer text string
+
+ @return return the result of the calling the function
+
+ @exception NET_NFC_ALLOC_FAIL memory allocation is failed
+ @exception NET_NFC_NDEF_RECORD_IS_NOT_EXPECTED_TYPE record is not text record
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+
+*/
+
+net_nfc_error_e net_nfc_create_text_string_from_text_record(ndef_record_h record, char** buffer);
+
+/**
+ this function get language code from text record. (ex: US-en)
+
+ @param[in] record Record handler
+ @param[out] lang_code_str lang code string value followed by IANA
+
+ @return return the result of the calling the function
+
+ @exception NET_NFC_NDEF_RECORD_IS_NOT_EXPECTED_TYPE record is not text record
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+
+*/
+
+net_nfc_error_e net_nfc_get_languange_code_string_from_text_record (ndef_record_h record, char** lang_code_str);
+
+
+/**
+ this function get encoding type from text record (ex: UTF-8)
+
+ @param[in] record Record handler
+ @param[out] encoding encoding type
+
+ @return return the result of the calling the function
+
+ @exception NET_NFC_NDEF_RECORD_IS_NOT_EXPECTED_TYPE record is not text record
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+
+*/
+
+net_nfc_error_e net_nfc_get_encoding_type_from_text_record(ndef_record_h record, net_nfc_encode_type_e * encoding);
+
+
+/**
+ this function get URI from uri record. you should free the uri string.
+
+ @param[in] record Record handler
+ @param[out] uri uri text string
+
+ @return return the result of the calling the function
+
+ @exception NET_NFC_NDEF_RECORD_IS_NOT_EXPECTED_TYPE record is not uri record
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+
+*/
+
+net_nfc_error_e net_nfc_create_uri_string_from_uri_record(ndef_record_h record, char ** uri);
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif //__NET_NFC_NDEF_RECORD_H__
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_SIGN_RECORD_H__
+#define __NET_NFC_SIGN_RECORD_H__
+
+#include "net_nfc_typedef.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+
+/**
+
+ @addtogroup NET_NFC_MANAGER_RECORD
+ @{
+ This document is for the APIs reference document
+
+ NFC Manager defines are defined in <nfc-typedef.h>
+
+*/
+
+/**
+ this function make the signature of some continuous records
+ please refer the NFC forum specification "Signature Record type Definition"
+
+ @param[in/out] msg NDEF message handler. After executing this function, a signature record will be added.
+ @param[in] begin_index the index of beginning record that will be signed.
+ @param[in] end_index the last index of record that will be signed.
+ @param[in] cert_file PKCS #12 type certificate file (.p12). And the file should be encoded in DER type. (NOT PEM type)
+ @param[in] passowrd the password of cert_file
+
+ @return return the result of the calling the function
+
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illegal NULL pointer(s)
+ @exception NET_NFC_ALLOC_FAIL memory allocation is failed
+
+ @code
+ ndef_message_h msg = NULL;
+
+ // create a ndef message and add some records
+ // ...
+
+ net_nfc_sign_records(msg, 0, 1, "/tmp/cert.p12", "abcdef");
+ @endcode
+*/
+net_nfc_error_e net_nfc_sign_records(ndef_message_h msg, int begin_index, int end_index, char *cert_file, char *password);
+
+/**
+ this function make the signature of whole records in NDEF message
+
+ @param[in/out] msg NDEF message handler. After executing this function, a signature record will be added.
+ @param[in] cert_file PKCS #12 type certificate file (.p12). And the file should be encoded in DER type. (NOT PEM type)
+ @param[in] passowrd the password of cert_file
+
+ @return return the result of the calling the function
+
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illegal NULL pointer(s)
+ @exception NET_NFC_ALLOC_FAIL memory allocation is failed
+
+ @code
+ ndef_message_h msg = NULL;
+
+ // create a ndef message and add some records
+ // ...
+
+ net_nfc_sign_ndef_message(msg, "/tmp/cert.p12", "abcdef");
+ @endcode
+*/
+net_nfc_error_e net_nfc_sign_ndef_message(ndef_message_h msg, char *cert_file, char *password);
+
+/**
+ This function does verify signature of records
+ record MUST be continuous.
+
+ @param[in] begin_record the handle of beginning record that will be verified
+ @param[in] sign_record the handle of signature record
+
+ @return return the result of the calling the function
+
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illegal NULL pointer(s)
+ @exception NET_NFC_ALLOC_FAIL memory allocation is failed
+
+ @code
+ net_nfc_error_e error = NET_NFC_OK;
+ ndef_message_h msg = NULL;
+ ndef_record_h begin_record = NULL;
+ ndef_record_h sign_record = NULL;
+
+ // import NDEF message including the signature record.
+ // ...
+
+ net_nfc_get_record_by_index(msg, 0, &begin_record);
+ net_nfc_get_record_by_index(msg, 2, &sign_record);
+
+ error = net_nfc_verify_signature_records(begin_record, sign_record);
+
+ return (error == NET_NFC_OK);
+ @endcode
+*/
+net_nfc_error_e net_nfc_verify_signature_records(ndef_record_h begin_record, ndef_record_h sign_record);
+
+/**
+ This function does verify signature in NDEF message
+ If message has 2 or more signature record, it should do verify every signatures and return result.
+ (Despite of failing only one signature record, this function will return error.)
+
+ @param[in] msg NDEF message that will be verified.
+
+ @return return the result of the calling the function
+
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illegal NULL pointer(s)
+ @exception NET_NFC_ALLOC_FAIL memory allocation is failed
+
+ @code
+ net_nfc_error_e error = NET_NFC_OK;
+ ndef_message_h msg = NULL;
+
+ // import NDEF message including the signature record.
+ // ...
+
+ error = net_nfc_verify_signature_ndef_message(msg);
+
+ return (error == NET_NFC_OK);
+ @endcode
+*/
+net_nfc_error_e net_nfc_verify_signature_ndef_message(ndef_message_h msg);
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif //__NET_NFC_SIGN_RECORD_H__
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_TARGET_INFO_H__
+#define __NET_NFC_TARGET_INFO_H__
+
+#include "net_nfc_typedef.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+
+ @addtogroup NET_NFC_MANAGER_INFO
+ @{
+ This document is for the APIs reference document
+
+ NFC Manager defines are defined in <nfc-typedef.h>
+
+ These APIs help to get infomation of detected target. these target info handler holds
+ - type of target
+ - target ID
+ - ndef message supporting
+ - max data size (if this tag is ndef message tag)
+ - actual data size (if this tag is ndef message tag)
+ */
+
+/**
+ type getter from targte info handler
+
+ \par Sync (or) Async: Sync
+ This is a Synchronous API
+
+ @param[in] target_info target info handler
+ @param[out] type tag type these type is one of the enum "net_nfc_target_type_e" defined
+
+ @return return the result of calling this functions
+
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+
+*/
+
+net_nfc_error_e net_nfc_get_tag_type (net_nfc_target_info_h target_info, net_nfc_target_type_e * type);
+
+/**
+ type getter from targte info handler
+
+ \par Sync (or) Async: Sync
+ This is a Synchronous API
+
+ @param[in] target_info target info handler
+ @param[out] handle target handle that is generated by nfc-manager
+
+ @return return the result of calling this functions
+
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+
+*/
+
+net_nfc_error_e net_nfc_get_tag_handle(net_nfc_target_info_h target_info, net_nfc_target_handle_h * handle);
+
+/**
+ this API returns the NDEF support boolean value.
+ The TRUE value will be returned if the detected target is support NDEF, or return FALSE
+
+ \par Sync (or) Async: Sync
+ This is a Synchronous API
+
+ @param[in] target_info target info handler
+ @param[out] is_support boolean value of NDEF supporting
+
+ @return return the result of calling this functions
+
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+
+*/
+
+net_nfc_error_e net_nfc_get_tag_ndef_support (net_nfc_target_info_h target_info, bool * is_support);
+
+/**
+ The max size getter from targte info handler. This max size indicates the maximum size of NDEF message that can be stored in this detected tag.
+
+ \par Sync (or) Async: Sync
+ This is a Synchronous API
+
+ @param[in] target_info target info handler
+ @param[out] max_size max size of NDEF message that can be stored in this detected tag.
+
+ @return return the result of calling this functions
+
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+
+*/
+
+net_nfc_error_e net_nfc_get_tag_max_data_size (net_nfc_target_info_h target_info, uint32_t * max_size);
+
+/**
+ this function return the actual NDEF message size that stored in the tag
+
+ \par Sync (or) Async: Sync
+ This is a Synchronous API
+
+ @param[in] target_info target info handler
+ @param[out] actual_data the actual NDEF message size that stored in the tag
+
+ @return return the result of calling this functions
+
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+
+*/
+
+net_nfc_error_e net_nfc_get_tag_actual_data_size (net_nfc_target_info_h target_info, uint32_t * actual_data);
+
+
+/**
+ this function return keys which will be used to get a tag information
+
+ \par Sync (or) Async: Sync
+ This is a Synchronous API. keys will be freed by user.
+
+ @param[in] target_info target info handler
+ @param[out] keys pointer of double array. it will be array of string.
+ @param[out] number_of_keys length of array.
+
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ @exception NET_NFC_ALLOC_FAIL memory allocation is failed
+ @exception NET_NFC_NO_DATA_FOUND No data is returned
+
+ @code
+ void user_cb(net_nfc_message_e message, net_nfc_error_e result, void* data, void* trans_param)
+ {
+
+ switch(message)
+ {
+ case NET_NFC_MESSAGE_TAG_DISCOVERED:
+ if(info != NULL)
+ {
+ net_nfc_target_info_h target_info = (net_nfc_target_info_h)data;
+
+ char **keys;
+ int keys_length;
+
+ if(net_nfc_get_tag_info_keys(target_info, &keys, &keys_length) == true)
+ {
+ int index = 0;
+ for(; index < keys_length; index++)
+ {
+ char* key = keys[index];
+ }
+ }
+
+ free(keys);
+ }
+ }
+ }
+ @endcode
+
+ @return return the result of calling this functions
+
+*/
+
+net_nfc_error_e net_nfc_get_tag_info_keys(net_nfc_target_info_h target_info, char ***keys, int* number_of_keys);
+
+/**
+ this function return value which is matched key
+
+ \par Sync (or) Async: Sync
+ This is a Synchronous API
+
+ @param[in] target_info target info handler
+ @param[in] key key to retrieve
+ @param[out] value value which is matched with key
+
+ @code
+ void user_cb(net_nfc_message_e message, net_nfc_error_e result, void* data, void* trans_param)
+ {
+ switch(message)
+ {
+ case NET_NFC_MESSAGE_TAG_DISCOVERED:
+ if(info != NULL)
+ {
+ net_nfc_target_info_h target_info = (net_nfc_target_info_h)data;
+
+ char** keys;
+ int keys_length;
+
+ if(net_nfc_get_tag_info_keys(target_info, &keys, &keys_length) == NET_NFC_OK)
+ {
+ int index = 0;
+ for(; index < keys_length; index++)
+ {
+ char* key = keys[index];
+ data_h value;
+ net_nfc_get_tag_info_value(target_info, key, &value);
+ net_nfc_free_data(value);
+ }
+ }
+ }
+ }
+ }
+ @endcode
+
+ @return return the result of calling this functions
+
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illegal NULL pointer(s)
+ @exception NET_NFC_NO_DATA_FOUND No data is returned
+ */
+
+net_nfc_error_e net_nfc_get_tag_info_value(net_nfc_target_info_h target_info, const char* key, data_h* value);
+
+/**
+ Duplicate a handle of target information
+
+ ** IMPORTANT : After using duplicated handle, you should release a handle returned from this function.
+ ** You can release a handle by net_nfc_release_tag_info function.
+
+ \par Sync (or) Async: Sync
+ This is a Synchronous API
+
+ @param[in] origin The original handle you want to duplicate
+ @param[out] result The result of this function.
+
+ @code
+ void user_cb(net_nfc_message_e message, net_nfc_error_e result, void *data, void *trans_param)
+ {
+ switch(message)
+ {
+ case NET_NFC_MESSAGE_TAG_DISCOVERED:
+ net_nfc_target_info_h target_info = (net_nfc_target_info_h)data;
+ net_nfc_target_info_h handle = NULL;
+
+ net_nfc_duplicate_target_info(target_info, &handle);
+
+ // do something...
+
+ net_nfc_release_tag_info(handle);
+ break;
+ }
+ }
+ @endcode
+
+ @return return the result of calling this functions
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illegal NULL pointer(s)
+*/
+
+net_nfc_error_e net_nfc_duplicate_target_info(net_nfc_target_info_h origin, net_nfc_target_info_h *result);
+
+/**
+ After using net_nfc_target_info_h handle, you should release its resource by this function.
+
+ ** IMPORTANT : Never use this function in user callback you registered by net_nfc_set_response_callback function
+ ** This function is for the result of net_nfc_duplicate_target_info or net_nfc_get_current_tag_info_sync
+
+ \par Sync (or) Async: Sync
+ This is a Synchronous API
+
+ @param[in] target_info target info handle
+
+ @code
+ net_nfc_target_info_h handle;
+
+ net_nfc_get_current_tag_info_sync(&handle);
+
+ // do something...
+
+ net_nfc_release_tag_info(handle);
+ @endcode
+
+ @return return the result of calling this functions
+
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illegal NULL pointer(s)
+*/
+
+net_nfc_error_e net_nfc_release_tag_info(net_nfc_target_info_h target_info);
+
+
+/**
+@}
+*/
+
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif //__NET_NFC_TARGET_INFO_H__
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <glib.h>
+
+#ifdef SECURITY_SERVER
+#include "security-server.h"
+#endif
+
+#include "net_nfc_typedef.h"
+#include "net_nfc_util_gdbus_internal.h"
+#include "net_nfc_client_se.h"
+#include "net_nfc_client.h"
+#include "net_nfc_client_manager.h"
+#include "net_nfc_client_tag.h"
+#include "net_nfc_client_ndef.h"
+#include "net_nfc_client_transceive.h"
+#include "net_nfc_client_llcp.h"
+#include "net_nfc_client_snep.h"
+#include "net_nfc_client_p2p.h"
+#include "net_nfc_client_test.h"
+#include "net_nfc_client_system_handler.h"
+#include "net_nfc_client_handover.h"
+
+#ifdef SECURITY_SERVER
+static uint8_t *cookie;
+static size_t cookie_len;
+
+static void _init_smack()
+{
+ if (cookie == NULL) {
+ cookie_len = security_server_get_cookie_size();
+ if (cookie_len > 0) {
+ cookie = g_new0(uint8_t, cookie_len);
+ if (cookie != NULL) {
+ if (security_server_request_cookie(
+ (char *)cookie,
+ cookie_len) < 0) {
+ g_free(cookie);
+ cookie = NULL;
+ }
+ }
+ }
+ }
+}
+
+static void _deinit_smack()
+{
+ if (cookie != NULL) {
+ g_free(cookie);
+ cookie = NULL;
+ }
+}
+#endif
+
+GVariant *net_nfc_client_gdbus_get_privilege()
+{
+#ifdef SECURITY_SERVER
+ return net_nfc_util_gdbus_buffer_to_variant(cookie, cookie_len);
+#else
+ return net_nfc_util_gdbus_buffer_to_variant(NULL, 0);
+#endif
+}
+
+void net_nfc_client_gdbus_init(void)
+{
+#ifdef SECURITY_SERVER
+ _init_smack();
+#endif
+ if (net_nfc_client_manager_init() != NET_NFC_OK)
+ return;
+ if (net_nfc_client_tag_init() != NET_NFC_OK)
+ return;
+ if (net_nfc_client_ndef_init() != NET_NFC_OK)
+ return;
+ if (net_nfc_client_transceive_init() != NET_NFC_OK)
+ return;
+ if (net_nfc_client_llcp_init() != NET_NFC_OK)
+ return;
+ if (net_nfc_client_snep_init() != NET_NFC_OK)
+ return;
+ if (net_nfc_client_p2p_init() != NET_NFC_OK)
+ return;
+ if (net_nfc_client_sys_handler_init() != NET_NFC_OK)
+ return;
+ if (net_nfc_client_se_init() != NET_NFC_OK)
+ return;
+ if (net_nfc_client_test_init() != NET_NFC_OK)
+ return;
+ if(net_nfc_client_handover_init() != NET_NFC_OK)
+ return;
+}
+
+void net_nfc_client_gdbus_deinit(void)
+{
+ net_nfc_client_handover_deinit();
+ net_nfc_client_test_deinit();
+ net_nfc_client_se_deinit();
+ net_nfc_client_sys_handler_deinit();
+ net_nfc_client_p2p_deinit();
+ net_nfc_client_snep_deinit();
+ net_nfc_client_llcp_deinit();
+ net_nfc_client_transceive_deinit();
+ net_nfc_client_ndef_deinit();
+ net_nfc_client_tag_deinit();
+ net_nfc_client_manager_deinit();
+#ifdef SECURITY_SERVER
+ _deinit_smack();
+#endif
+}
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_CLIENT_H__
+#define __NET_NFC_CLIENT_H__
+
+#include <glib.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* TODO : change to internal header */
+void net_nfc_client_gdbus_init(void);
+
+void net_nfc_client_gdbus_deinit(void);
+
+GVariant *net_nfc_client_gdbus_get_privilege();
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif //__NET_NFC_CLIENT_H__
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include <vconf.h>
+
+#include "net_nfc_debug_internal.h"
+#include "net_nfc_typedef.h"
+#include "net_nfc_client.h"
+
+
+API net_nfc_error_e net_nfc_client_initialize()
+{
+ net_nfc_error_e result = NET_NFC_OK;
+
+ net_nfc_client_gdbus_init();
+
+ return result;
+}
+
+
+API net_nfc_error_e net_nfc_client_deinitialize()
+{
+ net_nfc_error_e result = NET_NFC_OK;
+
+ net_nfc_client_gdbus_deinit();
+
+ return result;
+}
+
+
+API net_nfc_error_e net_nfc_client_is_nfc_supported(int *state)
+{
+ net_nfc_error_e ret;
+
+ if (state != NULL)
+ {
+ if (vconf_get_bool(VCONFKEY_NFC_FEATURE, state) == 0)
+ {
+ ret = NET_NFC_OK;
+ }
+ else
+ {
+ ret = NET_NFC_INVALID_STATE;
+ }
+ }
+ else
+ {
+ ret = NET_NFC_NULL_PARAMETER;
+ }
+
+ return ret;
+}
+
+
+API net_nfc_error_e net_nfc_client_get_nfc_state(int *state)
+{
+ net_nfc_error_e ret;
+
+ if (state != NULL)
+ {
+ if (vconf_get_bool(VCONFKEY_NFC_STATE, state) == 0)
+ ret = NET_NFC_OK;
+ else
+ ret = NET_NFC_INVALID_STATE;
+ }
+ else
+ {
+ ret = NET_NFC_NULL_PARAMETER;
+ }
+
+ return ret;
+}
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <string.h>
+
+#include "net_nfc_data.h"
+#include "net_nfc_typedef_internal.h"
+#include "net_nfc_util_internal.h"
+#include "net_nfc_debug_internal.h"
+
+API net_nfc_error_e net_nfc_create_data_only(data_h* data)
+{
+ return net_nfc_create_data(data, NULL, 0);
+}
+
+API net_nfc_error_e net_nfc_create_data(data_h* data,
+ const uint8_t* bytes, const uint32_t length)
+{
+ data_s *tmp_data = NULL;
+
+ if (data == NULL)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ _net_nfc_util_alloc_mem(tmp_data, sizeof(data_s));
+ if (tmp_data == NULL)
+ return NET_NFC_ALLOC_FAIL;
+
+ if (length > 0)
+ {
+ _net_nfc_util_alloc_mem(tmp_data->buffer, length);
+ if (tmp_data->buffer == NULL)
+ {
+ _net_nfc_util_free_mem(tmp_data);
+ return NET_NFC_ALLOC_FAIL;
+ }
+
+ tmp_data->length = length;
+
+ if (bytes != NULL)
+ {
+ memcpy(tmp_data->buffer, bytes, length);
+ }
+ }
+
+ *data = (data_h)tmp_data;
+
+ return NET_NFC_OK;
+}
+
+API net_nfc_error_e net_nfc_get_data(const data_h data, uint8_t** bytes, uint32_t * length)
+{
+ if (data == NULL)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+ data_s * tmp_data = (data_s *)data;
+
+ *bytes = tmp_data->buffer;
+ *length = tmp_data->length;
+
+ return NET_NFC_OK;
+}
+
+API net_nfc_error_e net_nfc_set_data(const data_h data, const uint8_t* bytes, const uint32_t length)
+{
+ if (data == NULL)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+ data_s * tmp_data = (data_s *)data;
+
+ if (tmp_data->buffer == bytes && tmp_data->length == length)
+ {
+ return NET_NFC_OK;
+ }
+
+ if (tmp_data->buffer != NULL)
+ {
+ _net_nfc_util_free_mem(tmp_data->buffer);
+ }
+
+ if (length <= 0)
+ {
+ tmp_data->buffer = NULL;
+ tmp_data->length = 0;
+ return NET_NFC_OK;
+ }
+
+ if (length > 0)
+ {
+ _net_nfc_util_alloc_mem((tmp_data)->buffer, length);
+ }
+
+ if (bytes != NULL)
+ {
+ memcpy(tmp_data->buffer, bytes, length);
+ }
+
+ tmp_data->length = length;
+
+ return NET_NFC_OK;
+}
+
+API uint32_t net_nfc_get_data_length(const data_h data)
+{
+ if (data == NULL)
+ {
+ return 0;
+ }
+ data_s * tmp_data = (data_s *)data;
+
+ return tmp_data->length;
+}
+
+API uint8_t * net_nfc_get_data_buffer(const data_h data)
+{
+ if (data == NULL)
+ {
+ return NULL;
+ }
+ data_s * tmp_data = (data_s *)data;
+
+ return tmp_data->buffer;
+}
+
+API net_nfc_error_e net_nfc_free_data(data_h data)
+{
+ if (data == NULL)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+ data_s * tmp_data = (data_s *)data;
+
+ if (tmp_data->buffer != NULL)
+ {
+ _net_nfc_util_free_mem(tmp_data->buffer);
+ }
+ _net_nfc_util_free_mem(tmp_data);
+
+ return NET_NFC_OK;
+}
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <pthread.h>
+
+#include "net_nfc_typedef_internal.h"
+#include "net_nfc_debug_internal.h"
+#include "net_nfc_util_internal.h"
+#include "net_nfc_data.h"
+#include "net_nfc_client_context.h"
+#include "net_nfc_client_p2p.h"
+#include "net_nfc_client_handover.h"
+#include "net_nfc_client_exchanger.h"
+
+static net_nfc_exchanger_cb gdbus_exch_cb = NULL;
+
+API net_nfc_error_e net_nfc_client_create_exchanger_data(
+ net_nfc_exchanger_data_h *ex_data,
+ data_h payload)
+{
+ net_nfc_exchanger_data_s* tmp_ex_data = NULL;
+
+ if (ex_data == NULL || payload == NULL)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ _net_nfc_util_alloc_mem(
+ tmp_ex_data,
+ sizeof(net_nfc_exchanger_data_s));
+
+ if (tmp_ex_data == NULL)
+ {
+ return NET_NFC_ALLOC_FAIL;
+ }
+
+ tmp_ex_data->type = NET_NFC_EXCHANGER_RAW;
+
+ _net_nfc_util_alloc_mem(
+ tmp_ex_data->binary_data.buffer,
+ ((data_s *)payload)->length);
+
+ if (tmp_ex_data->binary_data.buffer == NULL)
+ {
+ _net_nfc_util_free_mem(tmp_ex_data);
+
+ return NET_NFC_ALLOC_FAIL;
+ }
+
+ memcpy(tmp_ex_data->binary_data.buffer,
+ ((data_s *)payload)->buffer,
+ ((data_s *)payload)->length);
+
+ tmp_ex_data->binary_data.length = ((data_s *)payload)->length;
+
+ *ex_data = (net_nfc_exchanger_data_h)tmp_ex_data;
+
+ return NET_NFC_OK;
+}
+
+
+API net_nfc_error_e net_nfc_client_free_exchanger_data(
+ net_nfc_exchanger_data_h ex_data)
+{
+ if (ex_data == NULL)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ if (((net_nfc_exchanger_data_s *)ex_data)->binary_data.buffer != NULL)
+ {
+ _net_nfc_util_free_mem(
+ ((net_nfc_exchanger_data_s *)ex_data)->binary_data.buffer);
+ }
+
+ _net_nfc_util_free_mem(ex_data);
+
+ return NET_NFC_OK;
+}
+
+API net_nfc_exchanger_cb net_nfc_client_get_exchanger_cb()
+{
+ return gdbus_exch_cb;
+}
+
+API net_nfc_error_e net_nfc_client_unset_exchanger_cb()
+{
+
+ if (gdbus_exch_cb == NULL)
+ {
+ return NET_NFC_NOT_REGISTERED;
+ }
+
+ gdbus_exch_cb = NULL;
+
+ net_nfc_client_deinitialize();
+
+ return NET_NFC_OK;
+}
+
+API net_nfc_error_e net_nfc_client_send_exchanger_data(
+ net_nfc_exchanger_data_h ex_handle,
+ net_nfc_target_handle_h target_handle,
+ void* trans_param)
+{
+ net_nfc_error_e ret;
+ net_nfc_exchanger_data_s *ex_data = (net_nfc_exchanger_data_s *)ex_handle;
+
+ DEBUG_CLIENT_MSG("send reqeust :: exchanger data = "
+ "[%p] target_handle = [%p]", ex_handle, target_handle);
+
+ /*Sync call is used because there is no callback provided*/
+ ret = net_nfc_client_p2p_send_sync(ex_data,target_handle);
+
+ return ret;
+}
+
+API net_nfc_error_e net_nfc_client_exchanger_request_connection_handover(
+ net_nfc_target_handle_h target_handle,
+ net_nfc_conn_handover_carrier_type_e type)
+{
+ net_nfc_error_e ret = NET_NFC_UNKNOWN_ERROR;
+ net_nfc_conn_handover_carrier_type_e carrier_type;
+ data_h data = NULL;
+
+ if (target_handle == NULL)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ ret = net_nfc_client_p2p_connection_handover_sync(target_handle,
+ type,
+ &carrier_type,
+ &data);
+
+ return ret;
+}
+
+API net_nfc_error_e net_nfc_client_exchanger_get_alternative_carrier_type(
+ net_nfc_connection_handover_info_h info_handle,
+ net_nfc_conn_handover_carrier_type_e *type)
+{
+ net_nfc_connection_handover_info_s *info = NULL;
+
+ if (info_handle == NULL || type == NULL)
+ return NET_NFC_NULL_PARAMETER;
+
+ info = (net_nfc_connection_handover_info_s *)info_handle;
+
+ *type = info->type;
+
+ return NET_NFC_OK;
+}
+
+API net_nfc_error_e net_nfc_client_exchanger_get_alternative_carrier_data(
+ net_nfc_connection_handover_info_h info_handle,
+ data_h *data)
+{
+ net_nfc_error_e result = NET_NFC_UNKNOWN_ERROR;
+ net_nfc_connection_handover_info_s *info = NULL;
+
+ if (info_handle == NULL || data == NULL)
+ return NET_NFC_NULL_PARAMETER;
+
+ info = (net_nfc_connection_handover_info_s *)info_handle;
+
+ result = net_nfc_create_data(data, info->data.buffer, info->data.length);
+
+ return result;
+}
+
+API net_nfc_error_e net_nfc_client_exchanger_free_alternative_carrier_data(
+ net_nfc_connection_handover_info_h info_handle)
+{
+ net_nfc_error_e result = NET_NFC_UNKNOWN_ERROR;
+ net_nfc_connection_handover_info_s *info = NULL;
+
+ if (info_handle == NULL)
+ return NET_NFC_NULL_PARAMETER;
+
+ info = (net_nfc_connection_handover_info_s *)info_handle;
+
+ if (info->data.buffer != NULL)
+ {
+ _net_nfc_util_free_mem(info->data.buffer);
+ }
+
+ _net_nfc_util_free_mem(info);
+
+ return result;
+}
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "net_nfc_typedef_internal.h"
+#include "net_nfc_debug_internal.h"
+#include "net_nfc_util_internal.h"
+#include "net_nfc_util_ndef_message.h"
+#include "net_nfc_util_gdbus_internal.h"
+#include "net_nfc_gdbus.h"
+#include "net_nfc_data.h"
+#include "net_nfc_client.h"
+#include "net_nfc_client_manager.h"
+#include "net_nfc_client_handover.h"
+
+typedef struct _HandoverFuncData HandoverFuncData;
+
+struct _HandoverFuncData
+{
+ gpointer handover_callback;
+ gpointer handover_data;
+};
+
+static NetNfcGDbusHandover *handover_proxy = NULL;
+
+static void p2p_connection_handover(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data);
+
+static void p2p_connection_handover(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ HandoverFuncData *func_data;
+ GVariant *data;
+ GError *error = NULL;
+ net_nfc_error_e result = NET_NFC_OK;
+ net_nfc_exchanger_event_e event;
+ net_nfc_conn_handover_carrier_type_e type;
+ data_s arg_data;
+
+ net_nfc_p2p_connection_handover_completed_cb callback;
+
+ if(net_nfc_gdbus_handover_call_request_finish (handover_proxy,
+ (gint32 *)&event,
+ (gint32 *)&type,
+ &data,
+ res,
+ &error) == FALSE)
+ {
+ result = NET_NFC_UNKNOWN_ERROR;
+
+ DEBUG_ERR_MSG("Can not finish"
+ " connection handover: %s", error->message);
+ g_error_free(error);
+ return;
+ }
+
+ func_data = user_data;
+ if(func_data == NULL)
+ {
+ DEBUG_ERR_MSG("can not get HandoverFuncData");
+ return;
+ }
+
+ if(func_data->handover_callback == NULL)
+ {
+ DEBUG_CLIENT_MSG("callback function is not avaiilable");
+ g_free(func_data);
+ return;
+ }
+
+ net_nfc_util_gdbus_variant_to_data_s(data, &arg_data);
+
+ callback = (net_nfc_p2p_connection_handover_completed_cb)
+ func_data->handover_callback;
+
+ callback(result,
+ type,
+ &arg_data,
+ func_data->handover_data);
+
+ net_nfc_util_free_data(&arg_data);
+
+ g_free(func_data);
+}
+
+
+API net_nfc_error_e net_nfc_client_handover_free_alternative_carrier_data(
+ net_nfc_connection_handover_info_h info_handle)
+{
+ net_nfc_error_e result = NET_NFC_UNKNOWN_ERROR;
+ net_nfc_connection_handover_info_s *info = NULL;
+
+ if (info_handle == NULL)
+ return NET_NFC_NULL_PARAMETER;
+
+ info = (net_nfc_connection_handover_info_s *)info_handle;
+
+ if (info->data.buffer != NULL)
+ {
+ _net_nfc_util_free_mem(info->data.buffer);
+ }
+
+ _net_nfc_util_free_mem(info);
+
+ return result;
+}
+
+
+API net_nfc_error_e net_nfc_client_handover_get_alternative_carrier_type(
+ net_nfc_connection_handover_info_h info_handle,
+ net_nfc_conn_handover_carrier_type_e *type)
+{
+ net_nfc_connection_handover_info_s *info = NULL;
+
+ if (info_handle == NULL || type == NULL)
+ return NET_NFC_NULL_PARAMETER;
+
+ info = (net_nfc_connection_handover_info_s *)info_handle;
+
+ *type = info->type;
+
+ return NET_NFC_OK;
+}
+
+API net_nfc_error_e net_nfc_client_handover_get_alternative_carrier_data(
+ net_nfc_connection_handover_info_h info_handle,
+ data_h *data)
+{
+ net_nfc_error_e result = NET_NFC_UNKNOWN_ERROR;
+ net_nfc_connection_handover_info_s *info = NULL;
+
+ if (info_handle == NULL || data == NULL)
+ return NET_NFC_NULL_PARAMETER;
+
+ info = (net_nfc_connection_handover_info_s *)info_handle;
+
+ result = net_nfc_create_data(data, info->data.buffer, info->data.length);
+
+ return result;
+}
+
+
+API net_nfc_error_e net_nfc_client_p2p_connection_handover(
+ net_nfc_target_handle_h handle,
+ net_nfc_conn_handover_carrier_type_e arg_type,
+ net_nfc_p2p_connection_handover_completed_cb callback,
+ void *cb_data)
+{
+
+ HandoverFuncData *funcdata = NULL;
+ net_nfc_target_handle_s *tag_handle = (net_nfc_target_handle_s *)handle;
+
+ if(handover_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not get handover Proxy");
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ funcdata = g_new0(HandoverFuncData, 1);
+ if (funcdata == NULL)
+ return NET_NFC_UNKNOWN_ERROR;
+
+ funcdata->handover_callback = (gpointer)callback;
+ funcdata->handover_data = cb_data;
+
+ net_nfc_gdbus_handover_call_request(handover_proxy,
+ GPOINTER_TO_UINT(tag_handle),
+ arg_type,
+ net_nfc_client_gdbus_get_privilege(),
+ NULL,
+ p2p_connection_handover,
+ funcdata);
+
+ return NET_NFC_OK;
+}
+
+
+API net_nfc_error_e net_nfc_client_p2p_connection_handover_sync(
+ net_nfc_target_handle_h handle,
+ net_nfc_conn_handover_carrier_type_e arg_type,
+ net_nfc_conn_handover_carrier_type_e *out_carrier,
+ data_h *out_ac_data)
+{
+
+ net_nfc_target_handle_s *tag_handle = (net_nfc_target_handle_s *)handle;
+ GError *error = NULL;
+ GVariant *out_data;
+ net_nfc_exchanger_event_e out_event;
+ net_nfc_conn_handover_carrier_type_e out_type;
+
+ if(handover_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not get handover Proxy");
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ if(net_nfc_gdbus_handover_call_request_sync(handover_proxy,
+ GPOINTER_TO_UINT(tag_handle),
+ arg_type,
+ net_nfc_client_gdbus_get_privilege(),
+ (gint32 *)&out_event,
+ (gint32 *)&out_type,
+ &out_data,
+ NULL,
+ &error) == FALSE)
+ {
+ DEBUG_ERR_MSG("handover (sync call) failed: %s",error->message);
+ g_error_free(error);
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ if (out_carrier)
+ {
+ *out_carrier = out_type;
+ }
+
+ if (out_ac_data)
+ {
+ *out_ac_data = net_nfc_util_gdbus_variant_to_data(out_data);
+ }
+
+ return NET_NFC_OK;
+}
+
+
+API net_nfc_error_e net_nfc_client_handover_init(void)
+{
+ GError *error = NULL;
+
+ if (handover_proxy)
+ {
+ DEBUG_CLIENT_MSG("Already initialized");
+ return NET_NFC_OK;
+ }
+
+ handover_proxy = net_nfc_gdbus_handover_proxy_new_for_bus_sync(
+ G_BUS_TYPE_SYSTEM,
+ G_DBUS_PROXY_FLAGS_NONE,
+ "org.tizen.NetNfcService",
+ "/org/tizen/NetNfcService/Handover",
+ NULL,
+ &error);
+
+ if(handover_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not create proxy : %s", error->message);
+ g_error_free(error);
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ return NET_NFC_OK;
+}
+
+API void net_nfc_client_handover_deinit(void)
+{
+ if(handover_proxy)
+ {
+ g_object_unref(handover_proxy);
+ handover_proxy = NULL;
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "net_nfc_typedef_internal.h"
+#include "net_nfc_debug_internal.h"
+#include "net_nfc_util_internal.h"
+#include "net_nfc_util_gdbus_internal.h"
+#include "net_nfc_gdbus.h"
+#include "net_nfc_client.h"
+#include "net_nfc_client_manager.h"
+#include "net_nfc_client_llcp.h"
+
+typedef struct _LlcpFuncData LlcpFuncData;
+
+struct _LlcpFuncData
+{
+ gpointer callback;
+ gpointer user_data;
+};
+
+static NetNfcGDbusLlcp *llcp_proxy = NULL;
+static net_nfc_llcp_config_info_s llcp_config = { 128, 0, 0, 1 };
+static net_nfc_target_handle_s *llcp_handle = NULL;
+static GList *socket_data_list = NULL;
+static guint socket_handle = 0;
+
+
+void llcp_socket_data_append(net_nfc_llcp_internal_socket_s *socket_data);
+
+void llcp_socket_data_remove(net_nfc_llcp_internal_socket_s *socket_data);
+
+net_nfc_llcp_internal_socket_s *llcp_socket_data_find(net_nfc_llcp_socket_t socket);
+
+/* aysnc callback */
+static void llcp_call_config(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data);
+
+static void llcp_call_listen(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data);
+
+static void llcp_call_connect(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data);
+
+static void llcp_call_connect_sap(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data);
+
+static void llcp_call_send(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data);
+
+static void llcp_call_send_to(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data);
+
+static void llcp_call_receive(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data);
+
+static void llcp_call_receive_from(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data);
+
+static void llcp_call_close(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data);
+
+static void llcp_call_disconnect(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data);
+
+/* signal callback */
+static void llcp_error(NetNfcGDbusLlcp *object,
+ guint arg_handle,
+ guint client_socket,
+ guint oal_socket,
+ gint error,
+ gpointer user_data);
+
+
+void llcp_socket_data_append(net_nfc_llcp_internal_socket_s *socket_data)
+{
+ if (socket_data_list == NULL)
+ return;
+
+ if (socket_data)
+ {
+ socket_data_list = g_list_append(socket_data_list,
+ socket_data);
+ }
+}
+
+void llcp_socket_data_remove(net_nfc_llcp_internal_socket_s *socket_data)
+{
+ if (socket_data_list == NULL)
+ return;
+
+ if (socket_data)
+ {
+ socket_data_list = g_list_remove(socket_data_list,
+ socket_data);
+
+ g_free(socket_data->service_name);
+ g_free(socket_data);
+ }
+}
+
+net_nfc_llcp_internal_socket_s *llcp_socket_data_find(net_nfc_llcp_socket_t socket)
+{
+ GList *pos;
+
+ if (socket_data_list == NULL)
+ return NULL;
+
+
+ for (pos = g_list_first(socket_data_list); pos ; pos = pos->data)
+ {
+ net_nfc_llcp_internal_socket_s *data;
+
+ data = pos->data;
+ if (data == NULL)
+ continue;
+
+ if (data->client_socket == socket)
+ break;
+ }
+
+ if (pos == NULL)
+ return NULL;
+
+ return pos->data;
+}
+
+static void llcp_call_config(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ LlcpFuncData *func_data;
+
+ net_nfc_error_e result = NET_NFC_OK;
+ GError *error = NULL;
+
+ net_nfc_client_llcp_config_completed callback;
+
+ if (net_nfc_gdbus_llcp_call_config_finish(
+ NET_NFC_GDBUS_LLCP(source_object),
+ res,
+ &error) == FALSE)
+ {
+ result = NET_NFC_UNKNOWN_ERROR;
+
+ DEBUG_ERR_MSG("Can not finish config: %s",
+ error->message);
+ g_error_free(error);
+ }
+
+ func_data = user_data;
+ if (func_data == NULL)
+ {
+ DEBUG_ERR_MSG("can not get LlcpFuncData");
+ return;
+ }
+
+ if (func_data->callback == NULL)
+ {
+ DEBUG_CLIENT_MSG("callback function is not available");
+ g_free(func_data);
+ return;
+ }
+
+ callback = (net_nfc_client_llcp_config_completed)func_data->callback;
+ callback(result, func_data->user_data);
+}
+
+static void llcp_call_listen(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ LlcpFuncData *func_data;
+
+ net_nfc_error_e result = NET_NFC_OK;
+ GError *error = NULL;
+
+ guint32 out_client_socket;
+ guint32 out_oal_socket;
+
+ net_nfc_llcp_internal_socket_s *socket_data = NULL;
+
+ net_nfc_client_llcp_listen_completed callback;
+
+ if (net_nfc_gdbus_llcp_call_listen_finish(
+ NET_NFC_GDBUS_LLCP(source_object),
+ &out_client_socket,
+ &out_oal_socket,
+ res,
+ &error) == FALSE)
+ {
+ result = NET_NFC_UNKNOWN_ERROR;
+
+ DEBUG_ERR_MSG("Can not finish listen: %s",
+ error->message);
+ g_error_free(error);
+ }
+
+ socket_data = llcp_socket_data_find(out_client_socket);
+ if (socket_data == NULL)
+ {
+ DEBUG_ERR_MSG("Wrong client socket is returned");
+ return;
+ }
+
+ socket_data->oal_socket = out_oal_socket;
+
+ func_data = user_data;
+ if (func_data == NULL)
+ {
+ DEBUG_ERR_MSG("can not get LlcpFuncData");
+ return;
+ }
+
+ if (func_data->callback == NULL)
+ {
+ DEBUG_CLIENT_MSG("callback function is not available");
+ g_free(func_data);
+ return;
+ }
+
+ callback = (net_nfc_client_llcp_listen_completed)func_data->callback;
+ callback(result, out_client_socket, func_data->user_data);
+}
+
+static void llcp_call_connect(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ LlcpFuncData *func_data;
+
+ net_nfc_error_e result = NET_NFC_OK;
+ GError *error = NULL;
+
+ guint32 out_client_socket;
+ guint32 out_oal_socket;
+
+ net_nfc_llcp_internal_socket_s *socket_data = NULL;
+
+ net_nfc_client_llcp_connect_completed callback;
+
+ if (net_nfc_gdbus_llcp_call_connect_finish(
+ NET_NFC_GDBUS_LLCP(source_object),
+ &out_client_socket,
+ &out_oal_socket,
+ res,
+ &error) == FALSE)
+ {
+ result = NET_NFC_UNKNOWN_ERROR;
+
+ DEBUG_ERR_MSG("Can not finish connect: %s",
+ error->message);
+ g_error_free(error);
+ }
+
+ socket_data = llcp_socket_data_find(out_client_socket);
+ if (socket_data == NULL)
+ {
+ DEBUG_ERR_MSG("Wrong client socket is returned");
+ return;
+ }
+
+ socket_data->oal_socket = out_oal_socket;
+
+ func_data = user_data;
+ if (func_data == NULL)
+ {
+ DEBUG_ERR_MSG("can not get LlcpFuncData");
+ return;
+ }
+
+ if (func_data->callback == NULL)
+ {
+ DEBUG_CLIENT_MSG("callback function is not available");
+ g_free(func_data);
+ return;
+ }
+
+ callback = (net_nfc_client_llcp_connect_completed)func_data->callback;
+ callback(result, out_client_socket, func_data->user_data);
+}
+
+static void llcp_call_connect_sap(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ LlcpFuncData *func_data;
+
+ net_nfc_error_e result = NET_NFC_OK;
+ GError *error = NULL;
+
+ guint32 out_client_socket;
+ guint32 out_oal_socket;
+
+ net_nfc_llcp_internal_socket_s *socket_data = NULL;
+
+ net_nfc_client_llcp_connect_sap_completed callback;
+
+ if (net_nfc_gdbus_llcp_call_connect_sap_finish(
+ NET_NFC_GDBUS_LLCP(source_object),
+ &out_client_socket,
+ &out_oal_socket,
+ res,
+ &error) == FALSE)
+ {
+ result = NET_NFC_UNKNOWN_ERROR;
+
+ DEBUG_ERR_MSG("Can not finish connect sap: %s",
+ error->message);
+ g_error_free(error);
+ }
+
+ socket_data = llcp_socket_data_find(out_client_socket);
+ if (socket_data == NULL)
+ {
+ DEBUG_ERR_MSG("Wrong client socket is returned");
+ return;
+ }
+
+ socket_data->oal_socket = out_oal_socket;
+
+ func_data = user_data;
+ if (func_data == NULL)
+ {
+ DEBUG_ERR_MSG("can not get LlcpFuncData");
+ return;
+ }
+
+ if (func_data->callback == NULL)
+ {
+ DEBUG_CLIENT_MSG("callback function is not available");
+ g_free(func_data);
+ return;
+ }
+
+ callback = (net_nfc_client_llcp_connect_sap_completed)
+ func_data->callback;
+ callback(result, out_client_socket, func_data->user_data);
+}
+
+
+static void llcp_call_send(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ LlcpFuncData *func_data;
+
+ guint32 out_client_socket;
+
+ net_nfc_error_e result = NET_NFC_OK;
+ GError *error = NULL;
+
+ net_nfc_client_llcp_send_completed callback;
+
+ if (net_nfc_gdbus_llcp_call_send_finish(
+ NET_NFC_GDBUS_LLCP(source_object),
+ &out_client_socket,
+ res,
+ &error) == FALSE)
+ {
+ result = NET_NFC_UNKNOWN_ERROR;
+
+ DEBUG_ERR_MSG("Can not finish send: %s",
+ error->message);
+
+ g_error_free(error);
+ }
+
+ func_data = user_data;
+ if (func_data == NULL)
+ {
+ DEBUG_ERR_MSG("can not get LlcpFuncData");
+ return;
+ }
+
+ if (func_data->callback == NULL)
+ {
+ DEBUG_CLIENT_MSG("callback function is not available");
+ g_free(func_data);
+ return;
+ }
+
+ callback = (net_nfc_client_llcp_send_completed)func_data->callback;
+ callback(result, out_client_socket, func_data->user_data);
+}
+
+static void llcp_call_send_to(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ LlcpFuncData *func_data;
+
+ guint32 out_client_socket;
+
+ net_nfc_error_e result = NET_NFC_OK;
+ GError *error = NULL;
+
+ net_nfc_client_llcp_send_to_completed callback;
+
+ if (net_nfc_gdbus_llcp_call_send_to_finish(
+ NET_NFC_GDBUS_LLCP(source_object),
+ &out_client_socket,
+ res,
+ &error) == FALSE)
+ {
+ result = NET_NFC_UNKNOWN_ERROR;
+
+ DEBUG_ERR_MSG("Can not finish send to: %s",
+ error->message);
+
+ g_error_free(error);
+ }
+ func_data = user_data;
+ if (func_data == NULL)
+ {
+ DEBUG_ERR_MSG("can not get LlcpFuncData");
+ return;
+ }
+
+ if (func_data->callback == NULL)
+ {
+ DEBUG_CLIENT_MSG("callback function is not available");
+ g_free(func_data);
+ return;
+ }
+
+ callback = (net_nfc_client_llcp_send_to_completed)func_data->callback;
+ callback(result, out_client_socket, func_data->user_data);
+}
+
+static void llcp_call_receive(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ LlcpFuncData *func_data;
+
+ GVariant *variant = NULL;
+ data_s data;
+
+ net_nfc_error_e result = NET_NFC_OK;
+ GError *error = NULL;
+
+ net_nfc_client_llcp_receive_completed callback;
+
+ if (net_nfc_gdbus_llcp_call_receive_finish(
+ NET_NFC_GDBUS_LLCP(source_object),
+ &variant,
+ res,
+ &error) == FALSE)
+ {
+ result = NET_NFC_UNKNOWN_ERROR;
+
+ DEBUG_ERR_MSG("Can not finish receive: %s",
+ error->message);
+
+ g_error_free(error);
+ }
+
+ func_data = user_data;
+ if (func_data == NULL)
+ {
+ DEBUG_ERR_MSG("can not get LlcpFuncData");
+ return;
+ }
+
+ if (func_data->callback == NULL)
+ {
+ DEBUG_CLIENT_MSG("callback function is not available");
+ g_free(func_data);
+ return;
+ }
+
+ net_nfc_util_gdbus_variant_to_data_s(variant, &data);
+
+ callback = (net_nfc_client_llcp_receive_completed)func_data->callback;
+ callback(result, &data, func_data->user_data);
+
+ net_nfc_util_free_data(&data);
+
+ g_free(func_data);
+}
+
+static void llcp_call_receive_from(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ LlcpFuncData *func_data;
+
+ GVariant *variant = NULL;
+
+ sap_t sap;
+ data_s data;
+
+ net_nfc_error_e result = NET_NFC_OK;
+ GError *error = NULL;
+
+ net_nfc_client_llcp_receive_from_completed callback;
+
+ if (net_nfc_gdbus_llcp_call_receive_from_finish(
+ NET_NFC_GDBUS_LLCP(source_object),
+ &sap,
+ &variant,
+ res,
+ &error) == FALSE)
+ {
+ result = NET_NFC_UNKNOWN_ERROR;
+
+ DEBUG_ERR_MSG("Can not finish receive from: %s",
+ error->message);
+
+ g_error_free(error);
+ }
+
+ func_data = user_data;
+ if (func_data == NULL)
+ {
+ DEBUG_ERR_MSG("can not get LlcpFuncData");
+ return;
+ }
+
+ if (func_data->callback == NULL)
+ {
+ DEBUG_CLIENT_MSG("callback function is not available");
+ g_free(func_data);
+ return;
+ }
+
+ net_nfc_util_gdbus_variant_to_data_s(variant, &data);
+
+ callback = (net_nfc_client_llcp_receive_from_completed)
+ func_data->callback;
+ callback(result, sap, &data, func_data->user_data);
+
+ net_nfc_util_free_data(&data);
+
+ g_free(func_data);
+}
+
+static void llcp_call_close(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ LlcpFuncData *func_data;
+
+ net_nfc_error_e result = NET_NFC_OK;
+ GError *error = NULL;
+
+ guint32 out_client_socket;
+
+ net_nfc_llcp_internal_socket_s *socket_data = NULL;
+
+ net_nfc_client_llcp_close_completed callback;
+
+ if (net_nfc_gdbus_llcp_call_close_finish(
+ NET_NFC_GDBUS_LLCP(source_object),
+ &out_client_socket,
+ res,
+ &error) == FALSE)
+ {
+ result = NET_NFC_UNKNOWN_ERROR;
+
+ DEBUG_ERR_MSG("Can not finish close: %s",
+ error->message);
+ g_error_free(error);
+ }
+
+ socket_data = llcp_socket_data_find(out_client_socket);
+ if (socket_data == NULL)
+ {
+ DEBUG_ERR_MSG("Wrong client socket is returned");
+ return;
+ }
+
+ func_data = user_data;
+ if (func_data == NULL)
+ {
+ DEBUG_ERR_MSG("can not get LlcpFuncData");
+ return;
+ }
+
+ if (func_data->callback == NULL)
+ {
+ DEBUG_CLIENT_MSG("callback function is not available");
+ g_free(func_data);
+ return;
+ }
+
+ callback = (net_nfc_client_llcp_close_completed)func_data->callback;
+ callback(result, out_client_socket, func_data->user_data);
+}
+
+static void llcp_call_disconnect(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ LlcpFuncData *func_data;
+
+ net_nfc_error_e result = NET_NFC_OK;
+ GError *error = NULL;
+
+ guint32 out_client_socket;
+
+ net_nfc_llcp_internal_socket_s *socket_data = NULL;
+
+ net_nfc_client_llcp_disconnect_completed callback;
+
+ if (net_nfc_gdbus_llcp_call_disconnect_finish(
+ NET_NFC_GDBUS_LLCP(source_object),
+ &out_client_socket,
+ res,
+ &error) == FALSE)
+ {
+ result = NET_NFC_UNKNOWN_ERROR;
+
+ DEBUG_ERR_MSG("Can not finish disconnect: %s",
+ error->message);
+ g_error_free(error);
+ }
+
+ socket_data = llcp_socket_data_find(out_client_socket);
+ if (socket_data == NULL)
+ {
+ DEBUG_ERR_MSG("Wrong client socket is returned");
+ return;
+ }
+
+ func_data = user_data;
+ if (func_data == NULL)
+ {
+ DEBUG_ERR_MSG("can not get LlcpFuncData");
+ return;
+ }
+
+ if (func_data->callback == NULL)
+ {
+ DEBUG_CLIENT_MSG("callback function is not available");
+ g_free(func_data);
+ return;
+ }
+
+ callback = (net_nfc_client_llcp_disconnect_completed)
+ func_data->callback;
+ callback(result, out_client_socket, func_data->user_data);
+}
+
+
+static void llcp_error(NetNfcGDbusLlcp *object,
+ guint arg_handle,
+ guint client_socket,
+ guint oal_socket,
+ gint error,
+ gpointer user_data)
+{
+ INFO_MSG(">>> SIGNAL arrived");
+}
+
+/* Public APIs */
+API net_nfc_error_e net_nfc_client_llcp_config(net_nfc_llcp_config_info_h config,
+ net_nfc_client_llcp_config_completed callback,
+ void *user_data)
+{
+ LlcpFuncData *func_data;
+ GVariant *variant = NULL;
+
+ if (llcp_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not get LlcpProxy");
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ if (config == NULL)
+ {
+ DEBUG_ERR_MSG("Config is empty");
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ func_data = g_new0(LlcpFuncData, 1);
+ func_data->callback = (gpointer)callback;
+ func_data->user_data = user_data;
+
+ memcpy(&llcp_config, config, sizeof(net_nfc_llcp_config_info_s));
+
+ variant = g_variant_new("(qqyy)",
+ config->miu,
+ config->wks,
+ config->lto,
+ config->option);
+
+ net_nfc_gdbus_llcp_call_config(llcp_proxy,
+ variant,
+ net_nfc_client_gdbus_get_privilege(),
+ NULL,
+ llcp_call_config,
+ func_data);
+
+ return NET_NFC_OK;
+}
+
+API net_nfc_error_e net_nfc_client_llcp_config_sync
+(net_nfc_llcp_config_info_h config)
+{
+ GVariant *variant = NULL;
+ GError *error = NULL;
+
+ if (llcp_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not get LlcpProxy");
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ memcpy(&llcp_config, config, sizeof(net_nfc_llcp_config_info_s));
+
+ variant = g_variant_new("(qqyy)",
+ config->miu,
+ config->wks,
+ config->lto,
+ config->option);
+
+ if (net_nfc_gdbus_llcp_call_config_sync(llcp_proxy,
+ variant,
+ net_nfc_client_gdbus_get_privilege(),
+ NULL,
+ &error) == FALSE)
+ {
+ DEBUG_ERR_MSG("can not config: %s",
+ error->message);
+ g_error_free(error);
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ return NET_NFC_OK;
+}
+
+API net_nfc_error_e net_nfc_client_llcp_get_config
+(net_nfc_llcp_config_info_h *config)
+{
+ if (config == NULL)
+ return NET_NFC_NULL_PARAMETER;
+
+ *config = (net_nfc_llcp_config_info_h)&llcp_config;
+
+ return NET_NFC_OK;
+}
+
+ API net_nfc_error_e net_nfc_client_llcp_listen(net_nfc_llcp_socket_t socket,
+ const char *service_name,
+ sap_t sap,
+ net_nfc_client_llcp_listen_completed callback,
+ void *user_data)
+{
+ LlcpFuncData *func_data;
+ net_nfc_llcp_internal_socket_s *socket_data = NULL;
+
+ if (llcp_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not get LlcpProxy");
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ if (service_name == NULL)
+ {
+ DEBUG_ERR_MSG("service_name is empty");
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ socket_data = llcp_socket_data_find(socket);
+ if (socket_data == NULL)
+ {
+ DEBUG_ERR_MSG("can not get socket_data");
+ return NET_NFC_LLCP_INVALID_SOCKET;
+ }
+
+ /* FIXME: temporary typecast to (uint8_t *) */
+ socket_data->service_name = (uint8_t *)g_strdup(service_name);
+ socket_data->sap = sap;
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ func_data = g_new0(LlcpFuncData, 1);
+ func_data->callback = (gpointer)callback;
+ func_data->user_data = user_data;
+
+ net_nfc_gdbus_llcp_call_listen(llcp_proxy,
+ GPOINTER_TO_UINT(llcp_handle),
+ socket_data->client_socket,
+ socket_data->oal_socket,
+ socket_data->miu,
+ socket_data->rw,
+ socket_data->type,
+ socket_data->sap,
+ service_name,
+ net_nfc_client_gdbus_get_privilege(),
+ NULL,
+ llcp_call_listen,
+ func_data);
+
+ return NET_NFC_OK;
+}
+
+ API net_nfc_error_e net_nfc_client_llcp_listen_sync(net_nfc_llcp_socket_t socket,
+ const char *service_name,
+ sap_t sap,
+ net_nfc_llcp_socket_t *out_socket)
+{
+ GError *error = NULL;
+ guint32 out_client_socket;
+ guint32 out_oal_socket;
+
+ net_nfc_llcp_internal_socket_s *socket_data = NULL;
+ net_nfc_llcp_internal_socket_s *out_socket_data = NULL;
+
+ if (llcp_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not get LlcpProxy");
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ if (service_name == NULL)
+ {
+ DEBUG_ERR_MSG("service_name is empty");
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ socket_data = llcp_socket_data_find(socket);
+ if (socket_data == NULL)
+ {
+ DEBUG_ERR_MSG("can not get socket_data");
+ return NET_NFC_LLCP_INVALID_SOCKET;
+ }
+
+ /* FIXME: temporary typecast to (uint8_t *) */
+ socket_data->service_name = (uint8_t *)g_strdup(service_name);
+ socket_data->sap = sap;
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ if (net_nfc_gdbus_llcp_call_listen_sync(llcp_proxy,
+ GPOINTER_TO_UINT(llcp_handle),
+ socket_data->client_socket,
+ socket_data->oal_socket,
+ socket_data->miu,
+ socket_data->rw,
+ socket_data->type,
+ socket_data->sap,
+ service_name,
+ net_nfc_client_gdbus_get_privilege(),
+ &out_client_socket,
+ &out_oal_socket,
+ NULL,
+ &error) == FALSE)
+ {
+ DEBUG_ERR_MSG("can not listen: %s",
+ error->message);
+ g_error_free(error);
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ out_socket_data = llcp_socket_data_find(out_client_socket);
+ if (out_socket_data == NULL || out_socket_data != socket_data)
+ {
+ DEBUG_ERR_MSG("Wrong client socket is returned");
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ out_socket_data->oal_socket = out_oal_socket;
+
+ if (out_socket)
+ *out_socket = out_client_socket;
+
+ return NET_NFC_OK;
+}
+
+ API net_nfc_error_e net_nfc_client_llcp_connect(net_nfc_llcp_socket_t socket,
+ const char *service_name,
+ net_nfc_client_llcp_connect_completed callback,
+ void *user_data)
+{
+ LlcpFuncData *func_data;
+ net_nfc_llcp_internal_socket_s *socket_data = NULL;
+
+ if (llcp_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not get LlcpProxy");
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ if (service_name == NULL)
+ {
+ DEBUG_ERR_MSG("service_name is empty");
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ socket_data = llcp_socket_data_find(socket);
+ if (socket_data == NULL)
+ {
+ DEBUG_ERR_MSG("can not get socket_data");
+ return NET_NFC_LLCP_INVALID_SOCKET;
+ }
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ func_data = g_new0(LlcpFuncData, 1);
+ func_data->callback = (gpointer)callback;
+ func_data->user_data = user_data;
+
+ net_nfc_gdbus_llcp_call_connect(llcp_proxy,
+ GPOINTER_TO_UINT(llcp_handle),
+ socket_data->client_socket,
+ socket_data->oal_socket,
+ socket_data->miu,
+ socket_data->rw,
+ socket_data->type,
+ service_name,
+ net_nfc_client_gdbus_get_privilege(),
+ NULL,
+ llcp_call_connect,
+ func_data);
+
+ return NET_NFC_OK;
+}
+
+ API net_nfc_error_e net_nfc_client_llcp_connect_sync(net_nfc_llcp_socket_t socket,
+ const char *service_name,
+ net_nfc_llcp_socket_t *out_socket)
+{
+ GError *error = NULL;
+ guint32 out_client_socket;
+ guint32 out_oal_socket;
+
+ net_nfc_llcp_internal_socket_s *socket_data = NULL;
+ net_nfc_llcp_internal_socket_s *out_socket_data = NULL;
+
+ if (llcp_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not get LlcpProxy");
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ if (service_name == NULL)
+ {
+ DEBUG_ERR_MSG("service_name is empty");
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ socket_data = llcp_socket_data_find(socket);
+ if (socket_data == NULL)
+ {
+ DEBUG_ERR_MSG("can not get socket_data");
+ return NET_NFC_LLCP_INVALID_SOCKET;
+ }
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ if (net_nfc_gdbus_llcp_call_connect_sync(llcp_proxy,
+ GPOINTER_TO_UINT(llcp_handle),
+ socket_data->client_socket,
+ socket_data->oal_socket,
+ socket_data->miu,
+ socket_data->rw,
+ socket_data->type,
+ service_name,
+ net_nfc_client_gdbus_get_privilege(),
+ &out_client_socket,
+ &out_oal_socket,
+ NULL,
+ &error) == FALSE)
+ {
+ DEBUG_ERR_MSG("can not connect: %s",
+ error->message);
+ g_error_free(error);
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ out_socket_data = llcp_socket_data_find(out_client_socket);
+ if (out_socket_data == NULL || out_socket_data != socket_data)
+ {
+ DEBUG_ERR_MSG("Wrong client socket is returned");
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ out_socket_data->oal_socket = out_oal_socket;
+
+ if (out_socket)
+ *out_socket = out_client_socket;
+
+ return NET_NFC_OK;
+}
+
+ API net_nfc_error_e net_nfc_client_llcp_connect_sap(net_nfc_llcp_socket_t socket,
+ sap_t sap,
+ net_nfc_client_llcp_connect_sap_completed callback,
+ void *user_data)
+{
+ LlcpFuncData *func_data;
+ net_nfc_llcp_internal_socket_s *socket_data = NULL;
+
+ if (llcp_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not get LlcpProxy");
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ socket_data = llcp_socket_data_find(socket);
+ if (socket_data == NULL)
+ {
+ DEBUG_ERR_MSG("can not get socket_data");
+ return NET_NFC_LLCP_INVALID_SOCKET;
+ }
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ func_data = g_new0(LlcpFuncData, 1);
+ func_data->callback = (gpointer)callback;
+ func_data->user_data = user_data;
+
+ net_nfc_gdbus_llcp_call_connect_sap(llcp_proxy,
+ GPOINTER_TO_UINT(llcp_handle),
+ socket_data->client_socket,
+ socket_data->oal_socket,
+ socket_data->miu,
+ socket_data->rw,
+ socket_data->type,
+ sap,
+ net_nfc_client_gdbus_get_privilege(),
+ NULL,
+ llcp_call_connect_sap,
+ func_data);
+
+ return NET_NFC_OK;
+}
+
+ API net_nfc_error_e net_nfc_client_llcp_connect_sap_sync(
+ net_nfc_llcp_socket_t socket,
+ sap_t sap,
+ net_nfc_llcp_socket_t *out_socket)
+{
+ GError *error = NULL;
+ guint32 out_client_socket;
+ guint32 out_oal_socket;
+
+ net_nfc_llcp_internal_socket_s *socket_data = NULL;
+ net_nfc_llcp_internal_socket_s *out_socket_data = NULL;
+
+ if (llcp_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not get LlcpProxy");
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ socket_data = llcp_socket_data_find(socket);
+ if (socket_data == NULL)
+ {
+ DEBUG_ERR_MSG("can not get socket_data");
+ return NET_NFC_LLCP_INVALID_SOCKET;
+ }
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ if (net_nfc_gdbus_llcp_call_connect_sap_sync(llcp_proxy,
+ GPOINTER_TO_UINT(llcp_handle),
+ socket_data->client_socket,
+ socket_data->oal_socket,
+ socket_data->miu,
+ socket_data->rw,
+ socket_data->type,
+ sap,
+ net_nfc_client_gdbus_get_privilege(),
+ &out_client_socket,
+ &out_oal_socket,
+ NULL,
+ &error) == FALSE)
+ {
+ DEBUG_ERR_MSG("can not connect: %s",
+ error->message);
+ g_error_free(error);
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ out_socket_data = llcp_socket_data_find(out_client_socket);
+ if (out_socket_data == NULL || out_socket_data != socket_data)
+ {
+ DEBUG_ERR_MSG("Wrong client socket is returned");
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ out_socket_data->oal_socket = out_oal_socket;
+
+ if (out_socket)
+ *out_socket = out_client_socket;
+
+ return NET_NFC_OK;
+}
+
+ API net_nfc_error_e net_nfc_client_llcp_send(net_nfc_llcp_socket_t socket,
+ data_h data,
+ net_nfc_client_llcp_send_completed callback,
+ void *user_data)
+{
+ LlcpFuncData *func_data;
+ GVariant *variant = NULL;
+ net_nfc_llcp_internal_socket_s *socket_data = NULL;
+
+ if (llcp_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not get LlcpProxy");
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ socket_data = llcp_socket_data_find(socket);
+ if (socket_data == NULL)
+ {
+ DEBUG_ERR_MSG("can not get socket_data");
+ return NET_NFC_LLCP_INVALID_SOCKET;
+ }
+
+ if (data == NULL)
+ {
+ DEBUG_ERR_MSG("data is empty");
+ return NET_NFC_INVALID_PARAM;
+ }
+
+ variant = net_nfc_util_gdbus_data_to_variant(data);
+ if (variant == NULL)
+ {
+ DEBUG_ERR_MSG("Can not convert to variant");
+ return NET_NFC_INVALID_PARAM;
+ }
+
+
+ func_data = g_new0(LlcpFuncData, 1);
+ func_data->callback = (gpointer)callback;
+ func_data->user_data = user_data;
+
+ net_nfc_gdbus_llcp_call_send(llcp_proxy,
+ GPOINTER_TO_UINT(llcp_handle),
+ socket_data->client_socket,
+ socket_data->oal_socket,
+ variant,
+ net_nfc_client_gdbus_get_privilege(),
+ NULL,
+ llcp_call_send,
+ func_data);
+
+ return NET_NFC_OK;
+}
+
+ API net_nfc_error_e net_nfc_client_llcp_send_sync(net_nfc_llcp_socket_t socket,
+ data_h data,
+ net_nfc_llcp_socket_t *out_socket)
+{
+ GVariant *variant;
+ GError *error = NULL;
+ guint32 out_client_socket;
+
+ net_nfc_llcp_internal_socket_s *socket_data;
+ net_nfc_llcp_internal_socket_s *out_socket_data;
+
+ if (llcp_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not get LlcpProxy");
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ socket_data = llcp_socket_data_find(socket);
+ if (socket_data == NULL)
+ {
+ DEBUG_ERR_MSG("can not get socket_data");
+ return NET_NFC_LLCP_INVALID_SOCKET;
+ }
+
+ if (data == NULL)
+ {
+ DEBUG_ERR_MSG("data is empty");
+ return NET_NFC_INVALID_PARAM;
+ }
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ variant = net_nfc_util_gdbus_data_to_variant(data);
+ if (variant == NULL)
+ {
+ DEBUG_ERR_MSG("Can not convert to variant");
+ return NET_NFC_INVALID_PARAM;
+ }
+
+ if (net_nfc_gdbus_llcp_call_send_sync(llcp_proxy,
+ GPOINTER_TO_UINT(llcp_handle),
+ socket_data->client_socket,
+ socket_data->oal_socket,
+ variant,
+ net_nfc_client_gdbus_get_privilege(),
+ &out_client_socket,
+ NULL,
+ &error) == FALSE)
+ {
+ DEBUG_ERR_MSG("can not call send: %s",
+ error->message);
+ g_error_free(error);
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ out_socket_data = llcp_socket_data_find(out_client_socket);
+ if (out_socket_data == NULL)
+ {
+ DEBUG_ERR_MSG("can not find socket_data");
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ if (out_socket)
+ *out_socket = out_client_socket;
+
+ return NET_NFC_OK;
+}
+
+
+ API net_nfc_error_e net_nfc_client_llcp_send_to(net_nfc_llcp_socket_t socket,
+ sap_t sap,
+ data_h data,
+ net_nfc_client_llcp_send_to_completed callback,
+ void *user_data)
+{
+ LlcpFuncData *func_data;
+ GVariant *variant = NULL;
+ net_nfc_llcp_internal_socket_s *socket_data = NULL;
+
+ if (llcp_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not get LlcpProxy");
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ socket_data = llcp_socket_data_find(socket);
+ if (socket_data == NULL)
+ {
+ DEBUG_ERR_MSG("can not get socket_data");
+ return NET_NFC_LLCP_INVALID_SOCKET;
+ }
+
+ if (data == NULL)
+ {
+ DEBUG_ERR_MSG("data is empty");
+ return NET_NFC_INVALID_PARAM;
+ }
+
+ variant = net_nfc_util_gdbus_data_to_variant(data);
+ if (variant == NULL)
+ {
+ DEBUG_ERR_MSG("Can not convert to variant");
+ return NET_NFC_INVALID_PARAM;
+ }
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ func_data = g_new0(LlcpFuncData, 1);
+ func_data->callback = (gpointer)callback;
+ func_data->user_data = user_data;
+
+ net_nfc_gdbus_llcp_call_send_to(llcp_proxy,
+ GPOINTER_TO_UINT(llcp_handle),
+ socket_data->client_socket,
+ socket_data->oal_socket,
+ sap,
+ variant,
+ net_nfc_client_gdbus_get_privilege(),
+ NULL,
+ llcp_call_send_to,
+ func_data);
+
+ return NET_NFC_OK;
+}
+
+ API net_nfc_error_e net_nfc_client_llcp_send_to_sync(net_nfc_llcp_socket_t socket,
+ sap_t sap,
+ data_h data,
+ net_nfc_llcp_socket_t *out_socket)
+{
+ GVariant *variant;
+ GError *error = NULL;
+ guint32 out_client_socket;
+
+ net_nfc_llcp_internal_socket_s *socket_data;
+ net_nfc_llcp_internal_socket_s *out_socket_data;
+
+ if (llcp_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not get LlcpProxy");
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ socket_data = llcp_socket_data_find(socket);
+ if (socket_data == NULL)
+ {
+ DEBUG_ERR_MSG("can not get socket_data");
+ return NET_NFC_LLCP_INVALID_SOCKET;
+ }
+
+ if (data == NULL)
+ {
+ DEBUG_ERR_MSG("data is empty");
+ return NET_NFC_INVALID_PARAM;
+ }
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ variant = net_nfc_util_gdbus_data_to_variant(data);
+ if (variant == NULL)
+ {
+ DEBUG_ERR_MSG("Can not convert to variant");
+ return NET_NFC_INVALID_PARAM;
+ }
+
+ if (net_nfc_gdbus_llcp_call_send_to_sync(llcp_proxy,
+ GPOINTER_TO_UINT(llcp_handle),
+ socket_data->client_socket,
+ socket_data->oal_socket,
+ sap,
+ variant,
+ net_nfc_client_gdbus_get_privilege(),
+ &out_client_socket,
+ NULL,
+ &error) == FALSE)
+ {
+ DEBUG_ERR_MSG("can not call send to: %s",
+ error->message);
+ g_error_free(error);
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ out_socket_data = llcp_socket_data_find(out_client_socket);
+ if (out_socket_data == NULL)
+ {
+ DEBUG_ERR_MSG("can not find socket_data");
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ if (out_socket)
+ *out_socket = out_client_socket;
+
+ return NET_NFC_OK;
+}
+
+ API net_nfc_error_e net_nfc_client_llcp_receive(net_nfc_llcp_socket_t socket,
+ size_t request_length,
+ net_nfc_client_llcp_receive_completed callback,
+ void *user_data)
+{
+ LlcpFuncData *func_data;
+ net_nfc_llcp_internal_socket_s *socket_data = NULL;
+
+ if (llcp_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not get LlcpProxy");
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ socket_data = llcp_socket_data_find(socket);
+ if (socket_data == NULL)
+ {
+ DEBUG_ERR_MSG("can not get socket_data");
+ return NET_NFC_LLCP_INVALID_SOCKET;
+ }
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ func_data = g_new0(LlcpFuncData, 1);
+ func_data->callback = (gpointer)callback;
+ func_data->user_data = user_data;
+
+ net_nfc_gdbus_llcp_call_receive(llcp_proxy,
+ GPOINTER_TO_UINT(llcp_handle),
+ socket_data->client_socket,
+ socket_data->oal_socket,
+ request_length,
+ net_nfc_client_gdbus_get_privilege(),
+ NULL,
+ llcp_call_receive,
+ func_data);
+
+ return NET_NFC_OK;
+}
+
+ API net_nfc_error_e net_nfc_client_llcp_receive_sync(net_nfc_llcp_socket_t socket,
+ size_t request_length,
+ data_h *out_data)
+{
+ GVariant *variant = NULL;
+ GError *error = NULL;
+ net_nfc_llcp_internal_socket_s *socket_data;
+
+ if (llcp_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not get LlcpProxy");
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ socket_data = llcp_socket_data_find(socket);
+ if (socket_data == NULL)
+ {
+ DEBUG_ERR_MSG("can not get socket_data");
+ return NET_NFC_LLCP_INVALID_SOCKET;
+ }
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ if (net_nfc_gdbus_llcp_call_receive_sync(llcp_proxy,
+ GPOINTER_TO_UINT(llcp_handle),
+ socket_data->client_socket,
+ socket_data->oal_socket,
+ request_length,
+ net_nfc_client_gdbus_get_privilege(),
+ &variant,
+ NULL,
+ &error) == FALSE)
+ {
+ DEBUG_ERR_MSG("can not call receive: %s",
+ error->message);
+ g_error_free(error);
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ if (out_data)
+ {
+ *out_data = net_nfc_util_gdbus_variant_to_data(variant);
+ }
+
+ return NET_NFC_OK;
+}
+
+ API net_nfc_error_e net_nfc_client_llcp_receive_from(net_nfc_llcp_socket_t socket,
+ size_t request_length,
+ net_nfc_client_llcp_receive_from_completed callback,
+ void *user_data)
+{
+ LlcpFuncData *func_data;
+ net_nfc_llcp_internal_socket_s *socket_data = NULL;
+
+ if (llcp_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not get LlcpProxy");
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ socket_data = llcp_socket_data_find(socket);
+ if (socket_data == NULL)
+ {
+ DEBUG_ERR_MSG("can not get socket_data");
+ return NET_NFC_LLCP_INVALID_SOCKET;
+ }
+
+ func_data = g_new0(LlcpFuncData, 1);
+ func_data->callback = (gpointer)callback;
+ func_data->user_data = user_data;
+
+ net_nfc_gdbus_llcp_call_receive_from(llcp_proxy,
+ GPOINTER_TO_UINT(llcp_handle),
+ socket_data->client_socket,
+ socket_data->oal_socket,
+ request_length,
+ net_nfc_client_gdbus_get_privilege(),
+ NULL,
+ llcp_call_receive_from,
+ func_data);
+
+ return NET_NFC_OK;
+}
+
+API net_nfc_error_e net_nfc_client_llcp_receive_from_sync
+(net_nfc_llcp_socket_t socket,
+ size_t request_length,
+ sap_t *out_sap,
+ data_h *out_data)
+{
+ GVariant *variant = NULL;
+ GError *error = NULL;
+ sap_t sap;
+
+ net_nfc_llcp_internal_socket_s *socket_data;
+
+ if (llcp_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not get LlcpProxy");
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ socket_data = llcp_socket_data_find(socket);
+ if (socket_data == NULL)
+ {
+ DEBUG_ERR_MSG("can not get socket_data");
+ return NET_NFC_LLCP_INVALID_SOCKET;
+ }
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ if (net_nfc_gdbus_llcp_call_receive_from_sync(llcp_proxy,
+ GPOINTER_TO_UINT(llcp_handle),
+ socket_data->client_socket,
+ socket_data->oal_socket,
+ request_length,
+ net_nfc_client_gdbus_get_privilege(),
+ &sap,
+ &variant,
+ NULL,
+ &error) == FALSE)
+ {
+ DEBUG_ERR_MSG("can not call receive from: %s",
+ error->message);
+ g_error_free(error);
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ if (*out_sap)
+ *out_sap = sap;
+
+ if (out_data)
+ {
+ *out_data = net_nfc_util_gdbus_variant_to_data(variant);
+ }
+
+ return NET_NFC_OK;
+}
+
+ API net_nfc_error_e net_nfc_client_llcp_close(net_nfc_llcp_socket_t socket,
+ net_nfc_client_llcp_close_completed callback,
+ void *user_data)
+{
+ LlcpFuncData *func_data;
+ net_nfc_llcp_internal_socket_s *socket_data = NULL;
+
+ if (llcp_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not get LlcpProxy");
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ socket_data = llcp_socket_data_find(socket);
+ if (socket_data == NULL)
+ {
+ DEBUG_ERR_MSG("can not get socket_data");
+ return NET_NFC_LLCP_INVALID_SOCKET;
+ }
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ func_data = g_new0(LlcpFuncData, 1);
+ func_data->callback = (gpointer)callback;
+ func_data->user_data = user_data;
+
+ net_nfc_gdbus_llcp_call_close(llcp_proxy,
+ GPOINTER_TO_UINT(llcp_handle),
+ socket_data->client_socket,
+ socket_data->oal_socket,
+ net_nfc_client_gdbus_get_privilege(),
+ NULL,
+ llcp_call_close,
+ func_data);
+
+ return NET_NFC_OK;
+}
+
+ API net_nfc_error_e net_nfc_client_llcp_close_sync(net_nfc_llcp_socket_t socket,
+ net_nfc_llcp_socket_t *out_socket)
+{
+ GError *error = NULL;
+ guint32 out_client_socket;
+
+ net_nfc_llcp_internal_socket_s *socket_data = NULL;
+ net_nfc_llcp_internal_socket_s *out_socket_data = NULL;
+
+ if (llcp_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not get LlcpProxy");
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ socket_data = llcp_socket_data_find(socket);
+ if (socket_data == NULL)
+ {
+ DEBUG_ERR_MSG("can not get socket_data");
+ return NET_NFC_LLCP_INVALID_SOCKET;
+ }
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ if (net_nfc_gdbus_llcp_call_close_sync(llcp_proxy,
+ GPOINTER_TO_UINT(llcp_handle),
+ socket_data->client_socket,
+ socket_data->oal_socket,
+ net_nfc_client_gdbus_get_privilege(),
+ &out_client_socket,
+ NULL,
+ &error) == FALSE)
+ {
+ DEBUG_ERR_MSG("can not close: %s",
+ error->message);
+ g_error_free(error);
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ out_socket_data = llcp_socket_data_find(out_client_socket);
+ if (out_socket_data == NULL || out_socket_data != socket_data)
+ {
+ DEBUG_ERR_MSG("Wrong client socket is returned");
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ if (out_socket)
+ *out_socket = out_client_socket;
+
+ return NET_NFC_OK;
+}
+
+ API net_nfc_error_e net_nfc_client_llcp_disconnect(net_nfc_llcp_socket_t socket,
+ net_nfc_client_llcp_disconnect_completed callback,
+ void *user_data)
+{
+ LlcpFuncData *func_data;
+ net_nfc_llcp_internal_socket_s *socket_data = NULL;
+
+ if (llcp_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not get LlcpProxy");
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ socket_data = llcp_socket_data_find(socket);
+ if (socket_data == NULL)
+ {
+ DEBUG_ERR_MSG("can not get socket_data");
+ return NET_NFC_LLCP_INVALID_SOCKET;
+ }
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ func_data = g_new0(LlcpFuncData, 1);
+ func_data->callback = (gpointer)callback;
+ func_data->user_data = user_data;
+
+ net_nfc_gdbus_llcp_call_disconnect(llcp_proxy,
+ GPOINTER_TO_UINT(llcp_handle),
+ socket_data->client_socket,
+ socket_data->oal_socket,
+ net_nfc_client_gdbus_get_privilege(),
+ NULL,
+ llcp_call_disconnect,
+ func_data);
+
+ return NET_NFC_OK;
+}
+
+ API net_nfc_error_e net_nfc_client_llcp_disconnect_sync(
+ net_nfc_llcp_socket_t socket,
+ net_nfc_llcp_socket_t *out_socket)
+{
+ GError *error = NULL;
+ guint32 out_client_socket;
+
+ net_nfc_llcp_internal_socket_s *socket_data = NULL;
+ net_nfc_llcp_internal_socket_s *out_socket_data = NULL;
+
+ if (llcp_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not get LlcpProxy");
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ socket_data = llcp_socket_data_find(socket);
+ if (socket_data == NULL)
+ {
+ DEBUG_ERR_MSG("can not get socket_data");
+ return NET_NFC_LLCP_INVALID_SOCKET;
+ }
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ if (net_nfc_gdbus_llcp_call_disconnect_sync(llcp_proxy,
+ GPOINTER_TO_UINT(llcp_handle),
+ socket_data->client_socket,
+ socket_data->oal_socket,
+ net_nfc_client_gdbus_get_privilege(),
+ &out_client_socket,
+ NULL,
+ &error) == FALSE)
+ {
+ DEBUG_ERR_MSG("can not disconnect: %s",
+ error->message);
+ g_error_free(error);
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ out_socket_data = llcp_socket_data_find(out_client_socket);
+ if (out_socket_data == NULL || out_socket_data != socket_data)
+ {
+ DEBUG_ERR_MSG("Wrong client socket is returned");
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ if (out_socket)
+ *out_socket = out_client_socket;
+
+ return NET_NFC_OK;
+}
+
+API void net_nfc_client_llcp_create_socket(net_nfc_llcp_socket_t *socket,
+ net_nfc_llcp_socket_option_h option)
+{
+ net_nfc_llcp_internal_socket_s *socket_data = NULL;
+
+ socket_data = g_new0(net_nfc_llcp_internal_socket_s, 1);
+
+ socket_data->client_socket = socket_handle++;
+
+ if (option)
+ {
+ socket_data->miu = option->miu;
+ socket_data->rw = option->rw;
+ socket_data->type = option->type;
+ }
+ else
+ {
+ socket_data->miu = 128;
+ socket_data->rw = 1;
+ socket_data->type =
+ NET_NFC_LLCP_SOCKET_TYPE_CONNECTIONORIENTED;
+ }
+
+ socket_data->device_id = llcp_handle;
+ socket_data->close_requested = false;
+
+
+ if (socket)
+ *socket = socket_data->client_socket;
+}
+
+
+ API net_nfc_error_e net_nfc_client_llcp_get_local_config(
+ net_nfc_llcp_config_info_h *config)
+{
+ if (config == NULL)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ *config = (net_nfc_llcp_config_info_h)&llcp_config;
+
+ return NET_NFC_OK;
+}
+
+ API net_nfc_error_e net_nfc_client_llcp_get_local_socket_option(
+ net_nfc_llcp_socket_t socket,
+ net_nfc_llcp_socket_option_h *info)
+{
+ net_nfc_llcp_internal_socket_s *socket_data = NULL;
+
+ DEBUG_CLIENT_MSG("function %s is called", __func__);
+
+ socket_data = llcp_socket_data_find(socket);
+ if (socket_data == NULL)
+ return NET_NFC_LLCP_INVALID_SOCKET;
+
+ *info = (net_nfc_llcp_socket_option_h)socket_data;
+
+ return NET_NFC_OK;
+}
+
+ API net_nfc_error_e net_nfc_client_llcp_create_socket_option(
+ net_nfc_llcp_socket_option_h *option,
+ uint16_t miu,
+ uint8_t rw,
+ net_nfc_socket_type_e type)
+{
+ net_nfc_llcp_socket_option_s *struct_option = NULL;
+
+ if (option == NULL)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ if (miu < 128 || miu > 1152 ||
+ rw < 1 || rw > 15 ||
+ type < NET_NFC_LLCP_SOCKET_TYPE_CONNECTIONORIENTED ||
+ type > NET_NFC_LLCP_SOCKET_TYPE_CONNECTIONLESS)
+ {
+ return NET_NFC_OUT_OF_BOUND;
+ }
+
+ _net_nfc_util_alloc_mem(struct_option, sizeof(net_nfc_llcp_socket_option_s));
+ if (struct_option != NULL)
+ {
+ struct_option->miu = miu;
+ struct_option->rw = rw;
+ struct_option->type = type;
+
+ *option = (net_nfc_llcp_socket_option_h)struct_option;
+
+ return NET_NFC_OK;
+ }
+ else
+ {
+ return NET_NFC_ALLOC_FAIL;
+ }
+}
+
+ API net_nfc_error_e net_nfc_client_llcp_create_socket_option_default(
+ net_nfc_llcp_socket_option_h *option)
+{
+ return net_nfc_client_llcp_create_socket_option(
+ option,
+ 128,
+ 1,
+ NET_NFC_LLCP_SOCKET_TYPE_CONNECTIONORIENTED);
+}
+
+ API net_nfc_error_e net_nfc_client_llcp_get_socket_option_miu(
+ net_nfc_llcp_socket_option_h option,
+ uint16_t *miu)
+{
+ if (option == NULL || miu == NULL)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+ net_nfc_llcp_socket_option_s *struct_option = (net_nfc_llcp_socket_option_s *)option;
+
+ *miu = struct_option->miu;
+ return NET_NFC_OK;
+}
+
+ API net_nfc_error_e net_nfc_client_llcp_set_socket_option_miu(
+ net_nfc_llcp_socket_option_h option,
+ uint16_t miu)
+{
+ if (option == NULL)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+ net_nfc_llcp_socket_option_s *struct_option = (net_nfc_llcp_socket_option_s *)option;
+
+ struct_option->miu = miu;
+ return NET_NFC_OK;
+}
+
+ API net_nfc_error_e net_nfc_client_llcp_get_socket_option_rw(
+ net_nfc_llcp_socket_option_h option,
+ uint8_t *rw)
+{
+ if (option == NULL || rw == NULL)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+ net_nfc_llcp_socket_option_s *struct_option = (net_nfc_llcp_socket_option_s *)option;
+
+ *rw = struct_option->rw;
+ return NET_NFC_OK;
+}
+
+ API net_nfc_error_e net_nfc_client_llcp_set_socket_option_rw(
+ net_nfc_llcp_socket_option_h option,
+ uint8_t rw)
+{
+ if (option == NULL)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+ net_nfc_llcp_socket_option_s *struct_option = (net_nfc_llcp_socket_option_s *)option;
+
+ struct_option->rw = rw;
+ return NET_NFC_OK;
+}
+
+ API net_nfc_error_e net_nfc_client_llcp_get_socket_option_type(
+ net_nfc_llcp_socket_option_h option,
+ net_nfc_socket_type_e * type)
+{
+ if (option == NULL || type == NULL)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+ net_nfc_llcp_socket_option_s *struct_option = (net_nfc_llcp_socket_option_s *)option;
+
+ *type = struct_option->type;
+ return NET_NFC_OK;
+}
+
+ API net_nfc_error_e net_nfc_client_llcp_set_socket_option_type(
+ net_nfc_llcp_socket_option_h option,
+ net_nfc_socket_type_e type)
+{
+ if (option == NULL)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+ net_nfc_llcp_socket_option_s *struct_option = (net_nfc_llcp_socket_option_s *)option;
+
+ struct_option->type = type;
+ return NET_NFC_OK;
+}
+
+ API net_nfc_error_e net_nfc_client_llcp_free_socket_option(
+ net_nfc_llcp_socket_option_h option)
+{
+ if (option == NULL)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ _net_nfc_util_free_mem(option);
+
+ return NET_NFC_OK;
+}
+
+ API net_nfc_error_e net_nfc_client_llcp_create_config(
+ net_nfc_llcp_config_info_h *config,
+ uint16_t miu,
+ uint16_t wks,
+ uint8_t lto,
+ uint8_t option)
+{
+ if (config == NULL)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ net_nfc_llcp_config_info_s **tmp_config =
+ (net_nfc_llcp_config_info_s **)config;
+
+ _net_nfc_util_alloc_mem(*tmp_config,
+ sizeof(net_nfc_llcp_config_info_s));
+
+ if (*tmp_config == NULL)
+ return NET_NFC_ALLOC_FAIL;
+
+ (*tmp_config)->miu = miu;
+ (*tmp_config)->wks = wks;
+ (*tmp_config)->lto = lto;
+ (*tmp_config)->option = option;
+
+ return NET_NFC_OK;
+}
+
+ API net_nfc_error_e net_nfc_client_llcp_create_config_default(net_nfc_llcp_config_info_h *config)
+{
+ return net_nfc_client_llcp_create_config(config, 128, 1, 10, 0);
+}
+
+ API net_nfc_error_e net_nfc_client_llcp_get_config_miu(
+ net_nfc_llcp_config_info_h config,
+ uint16_t *miu)
+{
+ if (config == NULL || miu == NULL)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ net_nfc_llcp_config_info_s *tmp_config =
+ (net_nfc_llcp_config_info_s *)config;
+
+ *miu = tmp_config->miu;
+
+ return NET_NFC_OK;
+}
+
+ API net_nfc_error_e net_nfc_client_llcp_get_config_wks(
+ net_nfc_llcp_config_info_h config,
+ uint16_t *wks)
+{
+ if (config == NULL || wks == NULL)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ net_nfc_llcp_config_info_s *tmp_config =
+ (net_nfc_llcp_config_info_s *)config;
+
+ *wks = tmp_config->wks;
+
+ return NET_NFC_OK;
+}
+
+ API net_nfc_error_e net_nfc_client_llcp_get_config_lto(
+ net_nfc_llcp_config_info_h config,
+ uint8_t *lto)
+{
+ if (config == NULL || lto == NULL)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ net_nfc_llcp_config_info_s *tmp_config =
+ (net_nfc_llcp_config_info_s *)config;
+
+ *lto = tmp_config->lto;
+
+ return NET_NFC_OK;
+}
+
+ API net_nfc_error_e net_nfc_client_llcp_get_config_option(
+ net_nfc_llcp_config_info_h config,
+ uint8_t *option)
+{
+ if (config == NULL || option == NULL)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ net_nfc_llcp_config_info_s *tmp_config =
+ (net_nfc_llcp_config_info_s *)config;
+
+ *option = tmp_config->option;
+
+ return NET_NFC_OK;
+}
+
+ API net_nfc_error_e net_nfc_client_llcp_set_config_miu(
+ net_nfc_llcp_config_info_h config,
+ uint16_t miu)
+{
+ if (config == NULL)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ if (miu < 128 || miu > 1152)
+ {
+ return NET_NFC_OUT_OF_BOUND;
+ }
+
+ net_nfc_llcp_config_info_s * tmp_config =
+ (net_nfc_llcp_config_info_s *)config;
+
+ tmp_config->miu = miu;
+
+ return NET_NFC_OK;
+}
+
+ API net_nfc_error_e net_nfc_client_llcp_set_config_wks(
+ net_nfc_llcp_config_info_h config,
+ uint16_t wks)
+{
+ if (config == NULL)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ net_nfc_llcp_config_info_s *tmp_config =
+ (net_nfc_llcp_config_info_s *)config;
+
+ tmp_config->wks = wks;
+
+ return NET_NFC_OK;
+}
+
+ API net_nfc_error_e net_nfc_client_llcp_set_config_lto(
+ net_nfc_llcp_config_info_h config,
+ uint8_t lto)
+{
+ if (config == NULL)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ net_nfc_llcp_config_info_s *tmp_config =
+ (net_nfc_llcp_config_info_s *)config;
+
+ tmp_config->lto = lto;
+
+ return NET_NFC_OK;
+}
+
+ API net_nfc_error_e net_nfc_client_llcp_set_config_option(
+ net_nfc_llcp_config_info_h config,
+ uint8_t option)
+{
+ if (config == NULL)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ net_nfc_llcp_config_info_s * tmp_config =
+ (net_nfc_llcp_config_info_s *)config;
+
+ tmp_config->option = option;
+
+ return NET_NFC_OK;
+}
+
+ API net_nfc_error_e net_nfc_client_llcp_free_config(net_nfc_llcp_config_info_h config)
+{
+ if (config == NULL)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ _net_nfc_util_free_mem(config);
+ return NET_NFC_OK;
+}
+
+net_nfc_error_e net_nfc_client_llcp_init(void)
+{
+ GError *error = NULL;
+
+ if (llcp_proxy)
+ {
+ DEBUG_CLIENT_MSG("Already initialized");
+ return NET_NFC_OK;
+ }
+
+ llcp_proxy = net_nfc_gdbus_llcp_proxy_new_for_bus_sync(
+ G_BUS_TYPE_SYSTEM,
+ G_DBUS_PROXY_FLAGS_NONE,
+ "org.tizen.NetNfcService",
+ "/org/tizen/NetNfcService/Llcp",
+ NULL,
+ &error);
+
+ if (llcp_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not create proxy : %s", error->message);
+ g_error_free(error);
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ g_signal_connect(llcp_proxy, "error",
+ G_CALLBACK(llcp_error), NULL);
+
+ return NET_NFC_OK;
+}
+
+void net_nfc_client_llcp_deinit(void)
+{
+ if (llcp_proxy)
+ {
+ g_object_unref(llcp_proxy);
+ llcp_proxy = NULL;
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "net_nfc_debug_internal.h"
+
+#include "net_nfc_gdbus.h"
+#include "net_nfc_client.h"
+#include "net_nfc_client_context.h"
+#include "net_nfc_client_manager.h"
+
+typedef struct _ManagerFuncData ManagerFuncData;
+
+struct _ManagerFuncData
+{
+ gpointer callback;
+ gpointer user_data;
+};
+
+static NetNfcGDbusManager *manager_proxy = NULL;
+static gboolean activation_is_running = FALSE;
+
+static ManagerFuncData *activated_func_data = NULL;
+
+static int is_activated = -1;
+
+static void manager_call_set_active_callback(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data);
+
+static void manager_call_get_server_state_callback(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data);
+
+
+static void manager_activated(NetNfcGDbusManager *manager,
+ gboolean activated,
+ gpointer user_data);
+
+
+static void manager_call_set_active_callback(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ ManagerFuncData *func_data;
+
+ net_nfc_error_e result = NET_NFC_OK;
+ GError *error = NULL;
+
+ net_nfc_client_manager_set_active_completed callback;
+ gpointer data;
+
+ activation_is_running = FALSE;
+
+ if (net_nfc_gdbus_manager_call_set_active_finish(
+ NET_NFC_GDBUS_MANAGER(source_object),
+ res,
+ &error) == FALSE)
+ {
+ result = NET_NFC_UNKNOWN_ERROR;
+
+ DEBUG_ERR_MSG("Can not finish call_set_active: %s",
+ error->message);
+ g_error_free(error);
+ }
+
+ func_data = user_data;
+ if (func_data == NULL)
+ return;
+
+ if (func_data->callback == NULL)
+ {
+ g_free(func_data);
+ return;
+ }
+
+
+ callback = (net_nfc_client_manager_set_active_completed)
+ func_data->callback;
+ data = func_data->user_data;
+
+ callback(result, data);
+
+ g_free(func_data);
+}
+
+static void manager_call_get_server_state_callback(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ ManagerFuncData *func_data;
+
+ net_nfc_error_e result = NET_NFC_OK;
+ guint out_state;
+ GError *error = NULL;
+
+ net_nfc_client_manager_get_server_state_completed callback;
+ gpointer data;
+
+ if (net_nfc_gdbus_manager_call_get_server_state_finish(
+ NET_NFC_GDBUS_MANAGER(source_object),
+ &out_state,
+ res,
+ &error) == FALSE)
+ {
+
+ result = NET_NFC_UNKNOWN_ERROR;
+
+ DEBUG_ERR_MSG("Can not finish get_server_state: %s",
+ error->message);
+ g_error_free(error);
+ }
+
+ func_data = user_data;
+ if (func_data == NULL)
+ return;
+
+ if (func_data->callback == NULL)
+ {
+ g_free(func_data);
+ return;
+ }
+
+ callback = (net_nfc_client_manager_get_server_state_completed)
+ func_data->callback;
+ data = func_data->user_data;
+
+ callback(result, out_state, data);
+
+ g_free(func_data);
+}
+
+
+static void manager_activated(NetNfcGDbusManager *manager,
+ gboolean activated,
+ gpointer user_data)
+{
+ bool state = false;
+
+ INFO_MSG(">>> SIGNAL arrived");
+ DEBUG_CLIENT_MSG("activated %d", activated);
+
+ /* update current state */
+ is_activated = (int)activated;
+
+ if (activated_func_data == NULL)
+ return;
+
+ if (activated == TRUE)
+ state = true;
+
+ if (activated_func_data->callback)
+ {
+ net_nfc_client_manager_activated callback;
+ gpointer user_data;
+
+ callback = (net_nfc_client_manager_activated)
+ (activated_func_data->callback);
+ user_data = activated_func_data->user_data;
+
+ callback(state, user_data);
+ }
+}
+
+API void net_nfc_client_manager_set_activated(
+ net_nfc_client_manager_activated callback,
+ void *user_data)
+{
+ if (activated_func_data == NULL)
+ activated_func_data = g_new0(ManagerFuncData, 1);
+
+ activated_func_data->callback = (gpointer)callback;
+ activated_func_data->user_data = user_data;
+}
+
+API void net_nfc_client_manager_unset_activated(void)
+{
+ if (activated_func_data == NULL)
+ {
+ DEBUG_ERR_MSG("manager_func_data is not initialized");
+ return;
+ }
+
+ g_free(activated_func_data);
+ activated_func_data = NULL;
+}
+
+API net_nfc_error_e net_nfc_client_manager_set_active(int state,
+ net_nfc_client_manager_set_active_completed callback,
+ void *user_data)
+{
+ gboolean active = FALSE;
+ ManagerFuncData *func_data;
+
+ if (manager_proxy == NULL)
+ return NET_NFC_UNKNOWN_ERROR;
+
+ /* allow this function even nfc is off */
+
+ if (activation_is_running == TRUE)
+ return NET_NFC_BUSY;
+
+ activation_is_running = TRUE;
+
+ func_data = g_new0(ManagerFuncData, 1);
+ if (func_data == NULL)
+ return NET_NFC_UNKNOWN_ERROR;
+
+ func_data->callback = (gpointer)callback;
+ func_data->user_data = user_data;
+
+ if (state == true)
+ active = TRUE;
+
+ net_nfc_gdbus_manager_call_set_active(manager_proxy,
+ active,
+ net_nfc_client_gdbus_get_privilege(),
+ NULL,
+ manager_call_set_active_callback,
+ func_data);
+
+ return NET_NFC_OK;
+}
+
+API net_nfc_error_e net_nfc_client_manager_set_active_sync(int state)
+{
+ GError *error = NULL;
+
+ if (manager_proxy == NULL)
+ return NET_NFC_UNKNOWN_ERROR;
+
+ /* allow this function even nfc is off */
+
+ if (net_nfc_gdbus_manager_call_set_active_sync(manager_proxy,
+ (gboolean)state,
+ net_nfc_client_gdbus_get_privilege(),
+ NULL,
+ &error) == FALSE)
+ {
+ DEBUG_CLIENT_MSG("can not call SetActive: %s",
+ error->message);
+ g_error_free(error);
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ return NET_NFC_OK;
+}
+
+API net_nfc_error_e net_nfc_client_manager_get_server_state(
+ net_nfc_client_manager_get_server_state_completed callback,
+ void *user_data)
+{
+ ManagerFuncData *func_data;
+
+ if (manager_proxy == NULL)
+ return NET_NFC_UNKNOWN_ERROR;
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ func_data = g_new0(ManagerFuncData, 1);
+ if (func_data == NULL)
+ return NET_NFC_UNKNOWN_ERROR;
+
+ func_data->callback = (gpointer) callback;
+ func_data->user_data = user_data;
+
+ net_nfc_gdbus_manager_call_get_server_state(manager_proxy,
+ net_nfc_client_gdbus_get_privilege(),
+ NULL,
+ manager_call_get_server_state_callback,
+ func_data);
+
+ return NET_NFC_OK;
+}
+
+API net_nfc_error_e net_nfc_client_manager_get_server_state_sync(
+ unsigned int *state)
+{
+ GError *error = NULL;
+ guint out_state;
+
+ if (manager_proxy == NULL)
+ return NET_NFC_UNKNOWN_ERROR;
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ if (net_nfc_gdbus_manager_call_get_server_state_sync(manager_proxy,
+ net_nfc_client_gdbus_get_privilege(),
+ &out_state,
+ NULL,
+ &error) == FALSE)
+ {
+ DEBUG_CLIENT_MSG("can not call GetServerState: %s",
+ error->message);
+ g_error_free(error);
+
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ *state = out_state;
+ return NET_NFC_OK;
+
+}
+
+net_nfc_error_e net_nfc_client_manager_init(void)
+{
+ GError *error = NULL;
+
+ if (manager_proxy)
+ {
+ DEBUG_CLIENT_MSG("Already initialized");
+ return NET_NFC_OK;
+ }
+
+ manager_proxy = net_nfc_gdbus_manager_proxy_new_for_bus_sync(
+ G_BUS_TYPE_SYSTEM,
+ G_DBUS_PROXY_FLAGS_NONE,
+ "org.tizen.NetNfcService",
+ "/org/tizen/NetNfcService/Manager",
+ NULL,
+ &error);
+
+ if (manager_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not create proxy : %s", error->message);
+ g_error_free(error);
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ g_signal_connect(manager_proxy, "activated",
+ G_CALLBACK(manager_activated), NULL);
+
+ return NET_NFC_OK;
+}
+
+void net_nfc_client_manager_deinit(void)
+{
+ if (manager_proxy)
+ {
+ g_object_unref(manager_proxy);
+ manager_proxy = NULL;
+ }
+
+ if (activated_func_data)
+ {
+ g_free(activated_func_data);
+ activated_func_data = NULL;
+ }
+}
+
+/* internal function */
+bool net_nfc_client_manager_is_activated()
+{
+ if (is_activated < 0) {
+ net_nfc_client_get_nfc_state(&is_activated);
+ }
+
+ return is_activated;
+}
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "net_nfc_typedef_internal.h"
+#include "net_nfc_debug_internal.h"
+#include "net_nfc_util_internal.h"
+#include "net_nfc_util_ndef_message.h"
+#include "net_nfc_util_gdbus_internal.h"
+#include "net_nfc_gdbus.h"
+#include "net_nfc_data.h"
+#include "net_nfc_ndef_message.h"
+#include "net_nfc_client.h"
+#include "net_nfc_client_manager.h"
+#include "net_nfc_client_ndef.h"
+#include "net_nfc_client_tag_internal.h"
+
+typedef struct _NdefFuncData NdefFuncData;
+
+struct _NdefFuncData
+{
+ gpointer callback;
+ gpointer user_data;
+};
+
+static NetNfcGDbusNdef *ndef_proxy = NULL;
+
+static ndef_message_h ndef_variant_to_message(GVariant *variant);
+
+static GVariant *ndef_message_to_variant(ndef_message_h message);
+
+static gboolean ndef_is_supported_tag(void);
+
+static void ndef_call_read(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data);
+
+static void ndef_call_write(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data);
+
+static void ndef_call_make_read_only(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data);
+
+static void ndef_call_format(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data);
+
+static ndef_message_h ndef_variant_to_message(GVariant *variant)
+{
+ data_s data;
+ ndef_message_h message = NULL;
+
+ net_nfc_util_gdbus_variant_to_data_s(variant, &data);
+
+ if (data.buffer && data.length > 0)
+ {
+ if (net_nfc_create_ndef_message_from_rawdata(&message, &data)
+ != NET_NFC_OK)
+ {
+ DEBUG_ERR_MSG("memory alloc fail...");
+ }
+
+ net_nfc_util_free_data(&data);
+ }
+
+ return message;
+}
+
+static GVariant *ndef_message_to_variant(ndef_message_h message)
+{
+ guint length;
+ data_s data;
+ GVariant *variant = NULL;
+
+ length = net_nfc_util_get_ndef_message_length(
+ (ndef_message_s *)message);
+
+ if (length == 0)
+ {
+ DEBUG_ERR_MSG("message length is 0");
+ return NULL;
+ }
+
+ data.length = length;
+ data.buffer = g_new0(guint8, length);
+
+ if(net_nfc_util_convert_ndef_message_to_rawdata(
+ (ndef_message_s *)message,
+ &data) != NET_NFC_OK)
+ {
+ DEBUG_ERR_MSG("can not convert ndef_message to rawdata");
+ return NULL;
+ }
+
+ variant = net_nfc_util_gdbus_data_to_variant(&data);
+
+ g_free(data.buffer);
+
+ return variant;
+}
+
+static gboolean ndef_is_supported_tag(void)
+{
+ net_nfc_target_info_s *target_info = NULL;
+
+ target_info = net_nfc_client_tag_get_client_target_info();
+
+ if (target_info == NULL)
+ {
+ DEBUG_ERR_MSG("target_info does not exist");
+ return TRUE;
+ }
+
+ switch (target_info->devType)
+ {
+ case NET_NFC_ISO14443_A_PICC :
+ case NET_NFC_MIFARE_MINI_PICC :
+ case NET_NFC_MIFARE_1K_PICC :
+ case NET_NFC_MIFARE_4K_PICC :
+ case NET_NFC_MIFARE_ULTRA_PICC :
+ case NET_NFC_JEWEL_PICC :
+ return TRUE;
+ break;
+ default:
+ DEBUG_CLIENT_MSG(
+ "not supported tag for read only tag");
+ return FALSE;
+ }
+}
+
+static void ndef_call_read(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ NdefFuncData *func_data;
+
+ net_nfc_error_e out_result = NET_NFC_OK;
+ GError *error = NULL;
+
+ net_nfc_client_ndef_read_completed callback;
+
+ GVariant *out_data = NULL;
+ ndef_message_h message = NULL;
+
+ if (net_nfc_gdbus_ndef_call_read_finish(
+ NET_NFC_GDBUS_NDEF(source_object),
+ (gint *)&out_result,
+ &out_data,
+ res,
+ &error) == FALSE)
+ {
+ out_result = NET_NFC_UNKNOWN_ERROR;
+
+ DEBUG_ERR_MSG("Can not finish read: %s", error->message);
+ g_error_free(error);
+ }
+
+ func_data = (NdefFuncData *)user_data;
+ if (func_data == NULL)
+ {
+ DEBUG_ERR_MSG("can not get NdefFuncData");
+ return;
+ }
+
+ if (func_data->callback == NULL)
+ {
+ DEBUG_CLIENT_MSG("callback function is not avaiilable");
+ g_free(func_data);
+ return;
+ }
+
+ if (out_result == NET_NFC_OK)
+ message = ndef_variant_to_message(out_data);
+
+ callback = (net_nfc_client_ndef_read_completed)func_data->callback;
+ callback(out_result, message, func_data->user_data);
+
+ if (message)
+ net_nfc_util_free_ndef_message(message);
+
+ g_free(func_data);
+}
+
+static void ndef_call_write(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ NdefFuncData *func_data;
+
+ net_nfc_error_e out_result = NET_NFC_OK;
+ GError *error = NULL;
+
+ net_nfc_client_ndef_write_completed callback;
+
+ if (net_nfc_gdbus_ndef_call_write_finish(
+ NET_NFC_GDBUS_NDEF(source_object),
+ (gint *)&out_result,
+ res,
+ &error) == FALSE)
+ {
+ out_result = NET_NFC_UNKNOWN_ERROR;
+
+ DEBUG_ERR_MSG("Can not finish write: %s", error->message);
+ g_error_free(error);
+ }
+
+ func_data = (NdefFuncData *)user_data;
+ if (func_data == NULL)
+ {
+ DEBUG_ERR_MSG("can not get NdefFuncData");
+ return;
+ }
+
+ if (func_data->callback == NULL)
+ {
+ DEBUG_CLIENT_MSG("callback function is not avaiilable");
+ g_free(func_data);
+ return;
+ }
+
+ callback = (net_nfc_client_ndef_write_completed)func_data->callback;
+ callback(out_result, func_data->user_data);
+
+ g_free(func_data);
+}
+
+static void ndef_call_make_read_only(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ NdefFuncData *func_data;
+
+ net_nfc_error_e out_result = NET_NFC_OK;
+ GError *error = NULL;
+
+ net_nfc_client_ndef_make_read_only_completed callback;
+
+ if (net_nfc_gdbus_ndef_call_make_read_only_finish(
+ NET_NFC_GDBUS_NDEF(source_object),
+ (gint *)&out_result,
+ res,
+ &error) == FALSE)
+ {
+ out_result = NET_NFC_UNKNOWN_ERROR;
+
+ DEBUG_ERR_MSG("Can not finish make read only: %s",
+ error->message);
+ g_error_free(error);
+ }
+
+ func_data = (NdefFuncData *)user_data;
+ if (func_data == NULL)
+ {
+ DEBUG_ERR_MSG("can not get NdefFuncData");
+ return;
+ }
+
+ if (func_data->callback == NULL)
+ {
+ DEBUG_CLIENT_MSG("callback function is not avaiilable");
+ g_free(func_data);
+ return;
+ }
+
+ callback = (net_nfc_client_ndef_make_read_only_completed)
+ func_data->callback;
+ callback(out_result, func_data->user_data);
+
+ g_free(func_data);
+}
+
+static void ndef_call_format(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ NdefFuncData *func_data;
+
+ net_nfc_error_e out_result = NET_NFC_OK;
+ GError *error = NULL;
+
+ net_nfc_client_ndef_format_completed callback;
+
+ if (net_nfc_gdbus_ndef_call_format_finish(
+ NET_NFC_GDBUS_NDEF(source_object),
+ (gint *)&out_result,
+ res,
+ &error) == FALSE)
+ {
+ out_result = NET_NFC_UNKNOWN_ERROR;
+
+ DEBUG_ERR_MSG("Can not finish format: %s", error->message);
+ g_error_free(error);
+ }
+
+ func_data = (NdefFuncData *)user_data;
+ if (func_data == NULL)
+ {
+ DEBUG_ERR_MSG("can not get NdefFuncData");
+ return;
+ }
+
+ if (func_data->callback == NULL)
+ {
+ DEBUG_CLIENT_MSG("callback function is not avaiilable");
+ g_free(func_data);
+ return;
+ }
+
+ callback = (net_nfc_client_ndef_format_completed) func_data->callback;
+ callback(out_result, func_data->user_data);
+
+ g_free(func_data);
+}
+
+API net_nfc_error_e net_nfc_client_ndef_read(net_nfc_target_handle_h handle,
+ net_nfc_client_ndef_read_completed callback,
+ void *user_data)
+{
+ NdefFuncData *func_data;
+
+ if (ndef_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not get NdefProxy");
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ DEBUG_CLIENT_MSG("send reqeust :: read ndef = [%p]", handle);
+
+ if (handle == NULL)
+ return NET_NFC_NULL_PARAMETER;
+
+ if (net_nfc_client_tag_is_connected() == FALSE)
+ return NET_NFC_OPERATION_FAIL;
+
+ func_data = g_new0(NdefFuncData, 1);
+
+ func_data->callback = (gpointer)callback;
+ func_data->user_data = user_data;
+
+ net_nfc_gdbus_ndef_call_read(ndef_proxy,
+ GPOINTER_TO_UINT(handle),
+ net_nfc_client_gdbus_get_privilege(),
+ NULL,
+ ndef_call_read,
+ func_data);
+
+ return NET_NFC_OK;
+}
+
+API net_nfc_error_e net_nfc_client_ndef_read_sync(net_nfc_target_handle_h handle,
+ ndef_message_h *message)
+{
+ GVariant *out_data = NULL;
+ GError *error = NULL;
+
+ net_nfc_error_e out_result = NET_NFC_OK;
+
+ if (ndef_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not get NdefProxy");
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ DEBUG_CLIENT_MSG("send reqeust :: read ndef = [%p]", handle);
+
+ if (handle == NULL)
+ return NET_NFC_NULL_PARAMETER;
+
+ if (net_nfc_client_tag_is_connected() == FALSE)
+ return NET_NFC_OPERATION_FAIL;
+
+ if (net_nfc_gdbus_ndef_call_read_sync(ndef_proxy,
+ GPOINTER_TO_UINT(handle),
+ net_nfc_client_gdbus_get_privilege(),
+ (gint *)&out_result,
+ &out_data,
+ NULL,
+ &error) == FALSE)
+ {
+ DEBUG_ERR_MSG("can not call read: %s",
+ error->message);
+ g_error_free(error);
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ *message = ndef_variant_to_message(out_data);
+
+ return out_result;
+}
+
+API net_nfc_error_e net_nfc_client_ndef_write(net_nfc_target_handle_h handle,
+ ndef_message_h message,
+ net_nfc_client_ndef_write_completed callback,
+ void *user_data)
+{
+ NdefFuncData *func_data;
+
+ GVariant *arg_data = NULL;
+
+ if (ndef_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not get NdefProxy");
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ if (handle == NULL)
+ return NET_NFC_NULL_PARAMETER;
+
+ if (message == NULL)
+ return NET_NFC_NULL_PARAMETER;
+
+ if (net_nfc_client_tag_is_connected() == FALSE)
+ return NET_NFC_OPERATION_FAIL;
+
+ func_data = g_new0(NdefFuncData, 1);
+
+ func_data->callback = (gpointer)callback;
+ func_data->user_data = user_data;
+
+ arg_data = ndef_message_to_variant(message);
+ if (arg_data == NULL)
+ return NET_NFC_INVALID_PARAM;
+
+ net_nfc_gdbus_ndef_call_write(ndef_proxy,
+ GPOINTER_TO_UINT(handle),
+ arg_data,
+ net_nfc_client_gdbus_get_privilege(),
+ NULL,
+ ndef_call_write,
+ func_data);
+
+ return NET_NFC_OK;
+}
+
+API net_nfc_error_e net_nfc_client_ndef_write_sync(net_nfc_target_handle_h handle,
+ ndef_message_h message)
+{
+ GVariant *arg_data = NULL;
+ GError *error = NULL;
+
+ net_nfc_error_e out_result = NET_NFC_OK;
+
+ if (ndef_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not get NdefProxy");
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ if (handle == NULL)
+ return NET_NFC_NULL_PARAMETER;
+
+ if (message == NULL)
+ return NET_NFC_NULL_PARAMETER;
+
+ if (net_nfc_client_tag_is_connected() == FALSE)
+ return NET_NFC_OPERATION_FAIL;
+
+ arg_data = ndef_message_to_variant(message);
+ if (arg_data == NULL)
+ return NET_NFC_INVALID_PARAM;
+
+ if (net_nfc_gdbus_ndef_call_write_sync(ndef_proxy ,
+ GPOINTER_TO_UINT(handle),
+ arg_data,
+ net_nfc_client_gdbus_get_privilege(),
+ (gint *)&out_result,
+ NULL,
+ &error) == FALSE)
+ {
+ DEBUG_ERR_MSG("can not call write: %s",
+ error->message);
+ g_error_free(error);
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ return out_result;
+}
+
+API net_nfc_error_e net_nfc_client_ndef_make_read_only(
+ net_nfc_target_handle_h handle,
+ net_nfc_client_ndef_make_read_only_completed callback,
+ void *user_data)
+{
+ NdefFuncData *func_data;
+
+ if (ndef_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not get NdefProxy");
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ if (handle == NULL)
+ return NET_NFC_NULL_PARAMETER;
+
+ if (net_nfc_client_tag_is_connected() == FALSE)
+ return NET_NFC_OPERATION_FAIL;
+
+ if (ndef_is_supported_tag() == FALSE)
+ return NET_NFC_NOT_SUPPORTED;
+
+ func_data = g_new0(NdefFuncData, 1);
+
+ func_data->callback = (gpointer)callback;
+ func_data->user_data = user_data;
+
+ net_nfc_gdbus_ndef_call_make_read_only(ndef_proxy,
+ GPOINTER_TO_UINT(handle),
+ net_nfc_client_gdbus_get_privilege(),
+ NULL,
+ ndef_call_make_read_only,
+ func_data);
+
+ return NET_NFC_OK;
+}
+
+API net_nfc_error_e net_nfc_client_ndef_make_read_only_sync(
+ net_nfc_target_handle_h handle)
+{
+ GError *error = NULL;
+
+ net_nfc_error_e out_result = NET_NFC_OK;
+
+ if (ndef_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not get NdefProxy");
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ if (handle == NULL)
+ return NET_NFC_NULL_PARAMETER;
+
+ if (net_nfc_client_tag_is_connected() == FALSE)
+ return NET_NFC_OPERATION_FAIL;
+
+ if (ndef_is_supported_tag() == FALSE)
+ return NET_NFC_NOT_SUPPORTED;
+
+ if (net_nfc_gdbus_ndef_call_make_read_only_sync(ndef_proxy,
+ GPOINTER_TO_UINT(handle),
+ net_nfc_client_gdbus_get_privilege(),
+ (gint *)&out_result,
+ NULL,
+ &error) == FALSE)
+ {
+ DEBUG_ERR_MSG("can not make read only: %s",
+ error->message);
+ g_error_free(error);
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ return out_result;
+}
+
+API net_nfc_error_e net_nfc_client_ndef_format(net_nfc_target_handle_h handle,
+ data_h key,
+ net_nfc_client_ndef_format_completed callback,
+ void *user_data)
+{
+ NdefFuncData *func_data;
+ GVariant *arg_data = NULL;
+
+
+ if (ndef_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not get NdefProxy");
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ if (handle == NULL)
+ return NET_NFC_NULL_PARAMETER;
+
+ if (key == NULL)
+ arg_data = net_nfc_util_gdbus_buffer_to_variant(NULL, 0);
+ else
+ {
+ data_s *key_s;
+
+ key_s = (data_s *)key;
+ arg_data = net_nfc_util_gdbus_data_to_variant(key_s);
+ }
+
+ if (arg_data == NULL)
+ return NET_NFC_INVALID_PARAM;
+
+ func_data = g_new0(NdefFuncData, 1);
+
+ func_data->callback = (gpointer)callback;
+ func_data->user_data = user_data;
+
+ net_nfc_gdbus_ndef_call_format(ndef_proxy ,
+ GPOINTER_TO_UINT(handle),
+ arg_data,
+ net_nfc_client_gdbus_get_privilege(),
+ NULL,
+ ndef_call_format,
+ func_data);
+
+ return NET_NFC_OK;
+}
+
+API net_nfc_error_e net_nfc_client_ndef_format_sync(
+ net_nfc_target_handle_h handle,
+ data_h key)
+{
+ GVariant *arg_data = NULL;
+ GError *error = NULL;
+
+ net_nfc_error_e out_result = NET_NFC_OK;
+
+ if (ndef_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not get NdefProxy");
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ if (handle == NULL)
+ return NET_NFC_NULL_PARAMETER;
+
+ if (key == NULL)
+ arg_data = net_nfc_util_gdbus_buffer_to_variant(NULL, 0);
+ else
+ {
+ data_s *key_s;
+
+ key_s = (data_s *)key;
+ arg_data = net_nfc_util_gdbus_data_to_variant(key_s);
+ }
+
+ if (arg_data == NULL)
+ return NET_NFC_INVALID_PARAM;
+
+ if (net_nfc_gdbus_ndef_call_format_sync(ndef_proxy ,
+ GPOINTER_TO_UINT(handle),
+ arg_data,
+ net_nfc_client_gdbus_get_privilege(),
+ (gint *)&out_result,
+ NULL,
+ &error) == FALSE)
+ {
+ DEBUG_ERR_MSG("can not call format: %s",
+ error->message);
+ g_error_free(error);
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ return out_result;
+}
+
+net_nfc_error_e net_nfc_client_ndef_init(void)
+{
+ GError *error = NULL;
+
+ if (ndef_proxy)
+ {
+ DEBUG_CLIENT_MSG("Already initialized");
+ return NET_NFC_OK;
+ }
+
+ ndef_proxy = net_nfc_gdbus_ndef_proxy_new_for_bus_sync(
+ G_BUS_TYPE_SYSTEM,
+ G_DBUS_PROXY_FLAGS_NONE,
+ "org.tizen.NetNfcService",
+ "/org/tizen/NetNfcService/Ndef",
+ NULL,
+ &error);
+
+ if (ndef_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not create proxy : %s", error->message);
+ g_error_free(error);
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ return NET_NFC_OK;
+}
+
+void net_nfc_client_ndef_deinit(void)
+{
+ if (ndef_proxy)
+ {
+ g_object_unref(ndef_proxy);
+ ndef_proxy = NULL;
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "net_nfc_debug_internal.h"
+#include "net_nfc_util_internal.h"
+#include "net_nfc_util_ndef_message.h"
+#include "net_nfc_ndef_message.h"
+#include "net_nfc_data.h"
+
+
+/* public functions */
+API net_nfc_error_e net_nfc_create_ndef_message(ndef_message_h *ndef_message)
+{
+ return net_nfc_util_create_ndef_message((ndef_message_s **)ndef_message);
+}
+
+API net_nfc_error_e net_nfc_create_rawdata_from_ndef_message(ndef_message_h ndef_message, data_h *rawdata)
+{
+ uint32_t count;
+ net_nfc_error_e result;
+ data_h data;
+
+ if (ndef_message == NULL || rawdata == NULL) {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ *rawdata = NULL;
+
+ result = net_nfc_get_ndef_message_byte_length(ndef_message, &count);
+ if (result != NET_NFC_OK) {
+ return result;
+ }
+
+ result = net_nfc_create_data(&data ,NULL, count);
+ if (result != NET_NFC_OK) {
+ return result;
+ }
+
+ result = net_nfc_util_convert_ndef_message_to_rawdata(
+ (ndef_message_s *)ndef_message, (data_s *)data);
+ if (result == NET_NFC_OK) {
+ *rawdata = data;
+ } else {
+ net_nfc_free_data(data);
+ }
+
+ return result;
+}
+
+API net_nfc_error_e net_nfc_create_ndef_message_from_rawdata(ndef_message_h *ndef_message, data_h rawdata)
+{
+ net_nfc_error_e result;
+ ndef_message_h msg;
+
+ if (ndef_message == NULL || rawdata == NULL) {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ *ndef_message = NULL;
+
+ result = net_nfc_create_ndef_message(&msg);
+ if (result != NET_NFC_OK) {
+ return result;
+ }
+
+ result = net_nfc_util_convert_rawdata_to_ndef_message(
+ (data_s *)rawdata, (ndef_message_s *)msg);
+ if (result == NET_NFC_OK) {
+ *ndef_message = msg;
+ } else {
+ net_nfc_free_ndef_message(msg);
+ }
+
+ return result;
+}
+
+API net_nfc_error_e net_nfc_get_ndef_message_byte_length(ndef_message_h ndef_message, uint32_t *length)
+{
+ net_nfc_error_e result;
+
+ if (ndef_message == NULL || length == NULL){
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ *length = net_nfc_util_get_ndef_message_length((ndef_message_s *)ndef_message);
+ if (*length > 0) {
+ result = NET_NFC_OK;
+ } else {
+ result = NET_NFC_INVALID_PARAM;
+ }
+
+ return result;
+}
+
+API net_nfc_error_e net_nfc_append_record_to_ndef_message(ndef_message_h ndef_message, ndef_record_h record)
+{
+ if (ndef_message == NULL || record == NULL){
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ return net_nfc_util_append_record((ndef_message_s*)ndef_message, (ndef_record_s *)record);
+}
+
+API net_nfc_error_e net_nfc_free_ndef_message(ndef_message_h ndef_message)
+{
+ if (ndef_message == NULL) {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ return net_nfc_util_free_ndef_message((ndef_message_s *)ndef_message);
+}
+
+API net_nfc_error_e net_nfc_get_ndef_message_record_count(ndef_message_h ndef_message, int *count)
+{
+ if (ndef_message == NULL || count == NULL) {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ ndef_message_s *msg = (ndef_message_s *)ndef_message;
+
+ *count = msg->recordCount;
+
+ return NET_NFC_OK;
+}
+
+API void net_nfc_ndef_print_message (ndef_message_h ndef_message )
+{
+ net_nfc_util_print_ndef_message ((ndef_message_s *)(ndef_message) );
+}
+
+
+API net_nfc_error_e net_nfc_search_record_by_type (ndef_message_h ndef_message, net_nfc_record_tnf_e tnf, data_h type, ndef_record_h* record)
+{
+ return net_nfc_util_search_record_by_type ((ndef_message_s*)ndef_message, tnf, (data_s *)type, (ndef_record_s**)record);
+}
+
+API net_nfc_error_e net_nfc_append_record_by_index (ndef_message_h ndef_message, int index, ndef_record_h record)
+{
+ return net_nfc_util_append_record_by_index ((ndef_message_s *) ndef_message, index, (ndef_record_s *) record);
+}
+
+API net_nfc_error_e net_nfc_get_record_by_index (ndef_message_h ndef_message, int index, ndef_record_h* record)
+{
+ return net_nfc_util_get_record_by_index ((ndef_message_s*) ndef_message, index, (ndef_record_s**) record);
+}
+
+API net_nfc_error_e net_nfc_remove_record_by_index (ndef_message_h ndef_message, int index)
+{
+ return net_nfc_util_remove_record_by_index ((ndef_message_s*)ndef_message, index);
+}
+
+API net_nfc_error_e net_nfc_retrieve_current_ndef_message(ndef_message_h* ndef_message)
+{
+ net_nfc_error_e result = NET_NFC_UNKNOWN_ERROR;
+ char file_path[1024] = { 0, };
+ FILE *fp = NULL;
+
+ if (ndef_message == NULL)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ snprintf(file_path, sizeof(file_path), "%s/%s/%s", NET_NFC_MANAGER_DATA_PATH, NET_NFC_MANAGER_DATA_PATH_MESSAGE, NET_NFC_MANAGER_NDEF_FILE_NAME);
+
+ if ((fp = fopen(file_path, "r")) != NULL)
+ {
+ long int size = 0;
+
+ /* rewind to start of file */
+ fseek(fp, 0, SEEK_END);
+ size = ftell(fp);
+ fseek(fp, 0, SEEK_SET);
+
+ DEBUG_CLIENT_MSG("message length = [%ld]", size);
+
+ if (size > 0)
+ {
+ uint8_t *buffer = NULL;
+
+ _net_nfc_util_alloc_mem(buffer, size);
+ if (buffer != NULL)
+ {
+ /* read fully */
+ if ((size = fread(buffer, 1, size, fp)) > 0)
+ {
+ data_h data = NULL;
+ if ((result = net_nfc_create_data(&data, buffer, size)) == NET_NFC_OK)
+ {
+ result = net_nfc_create_ndef_message_from_rawdata(ndef_message, data);
+
+ net_nfc_free_data(data);
+ }
+ }
+
+ _net_nfc_util_free_mem(buffer);
+ }
+ }
+ else
+ {
+ result = NET_NFC_ALLOC_FAIL;
+ }
+
+ fclose(fp);
+ }
+ else
+ {
+ result = NET_NFC_NO_NDEF_MESSAGE;
+ }
+
+ return result;
+}
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include <glib.h>
+
+#include "net_nfc_ndef_message_handover.h"
+#include "net_nfc_typedef_internal.h"
+#include "net_nfc_debug_internal.h"
+#include "net_nfc_util_internal.h"
+#include "net_nfc_util_handover.h"
+
+API net_nfc_error_e net_nfc_create_carrier_config (net_nfc_carrier_config_h * config, net_nfc_conn_handover_carrier_type_e type)
+{
+ return net_nfc_util_create_carrier_config ((net_nfc_carrier_config_s **) config, type);
+}
+
+API net_nfc_error_e net_nfc_add_carrier_config_property (net_nfc_carrier_config_h config, uint16_t attribute, uint16_t size, uint8_t * data)
+{
+ return net_nfc_util_add_carrier_config_property ((net_nfc_carrier_config_s *) config, attribute, size, data);
+}
+
+API net_nfc_error_e net_nfc_remove_carrier_config_property (net_nfc_carrier_config_h config, uint16_t attribute)
+{
+ return net_nfc_util_remove_carrier_config_property ((net_nfc_carrier_config_s *) config, attribute);
+}
+
+API net_nfc_error_e net_nfc_get_carrier_config_property (net_nfc_carrier_config_h config, uint16_t attribute, uint16_t * size, uint8_t ** data)
+{
+ return net_nfc_util_get_carrier_config_property ((net_nfc_carrier_config_s *) config, attribute, size, data);
+}
+
+API net_nfc_error_e net_nfc_append_carrier_config_group (net_nfc_carrier_config_h config, net_nfc_property_group_h group)
+{
+ return net_nfc_util_append_carrier_config_group ((net_nfc_carrier_config_s *) config, (net_nfc_carrier_property_s *) group);
+}
+
+API net_nfc_error_e net_nfc_remove_carrier_config_group (net_nfc_carrier_config_h config, net_nfc_property_group_h group)
+{
+ return net_nfc_util_remove_carrier_config_group ((net_nfc_carrier_config_s *) config, (net_nfc_carrier_property_s *) group);
+}
+
+API net_nfc_error_e net_nfc_get_carrier_config_group (net_nfc_carrier_config_h config, int index, net_nfc_property_group_h * group)
+{
+ return net_nfc_util_get_carrier_config_group ((net_nfc_carrier_config_s *) config, index, (net_nfc_carrier_property_s **) group);
+}
+
+API net_nfc_error_e net_nfc_free_carrier_config (net_nfc_carrier_config_h config)
+{
+ return net_nfc_util_free_carrier_config ((net_nfc_carrier_config_s *) config);
+}
+
+API net_nfc_error_e net_nfc_create_carrier_config_group (net_nfc_property_group_h * group, uint16_t attribute)
+{
+ return net_nfc_util_create_carrier_config_group ((net_nfc_carrier_property_s **) group, attribute);
+}
+
+API net_nfc_error_e net_nfc_add_carrier_config_group_property (net_nfc_property_group_h group, uint16_t attribute, uint16_t size, uint8_t * data)
+{
+ return net_nfc_util_add_carrier_config_group_property ((net_nfc_carrier_property_s*) group, attribute, size, data);
+}
+
+API net_nfc_error_e net_nfc_get_carrier_config_group_property (net_nfc_property_group_h group, uint16_t attribute, uint16_t *size, uint8_t ** data)
+{
+ return net_nfc_util_get_carrier_config_group_property ((net_nfc_carrier_property_s*) group, attribute, size, data);
+}
+
+API net_nfc_error_e net_nfc_remove_carrier_config_group_property (net_nfc_property_group_h group, uint16_t attribute)
+{
+ return net_nfc_util_remove_carrier_config_group_property ((net_nfc_carrier_property_s*) group, attribute);
+}
+
+API net_nfc_error_e net_nfc_free_carrier_group (net_nfc_property_group_h group)
+{
+ return net_nfc_util_free_carrier_group ((net_nfc_carrier_property_s*) group);
+}
+
+API net_nfc_error_e net_nfc_create_ndef_record_with_carrier_config (ndef_record_h * record, net_nfc_carrier_config_h config)
+{
+ return net_nfc_util_create_ndef_record_with_carrier_config ((ndef_record_s**) record, (net_nfc_carrier_config_s *) config);
+}
+
+API net_nfc_error_e net_nfc_create_carrier_config_from_config_record (net_nfc_carrier_config_h * config, ndef_record_h record)
+{
+ return net_nfc_util_create_carrier_config_from_config_record ((net_nfc_carrier_config_s **) config, (ndef_record_s *) record);
+
+}
+
+API net_nfc_error_e net_nfc_append_carrier_config_record (ndef_message_h message, ndef_record_h record, net_nfc_conn_handover_carrier_state_e power_status)
+{
+ return net_nfc_util_append_carrier_config_record ((ndef_message_s *) message, (ndef_record_s *) record, power_status);
+}
+
+API net_nfc_error_e net_nfc_remove_carrier_config_record (ndef_message_h message, ndef_record_h record)
+{
+ return net_nfc_util_remove_carrier_config_record ((ndef_message_s *) message, (ndef_record_s *) record);
+}
+
+API net_nfc_error_e net_nfc_get_carrier_config_record (ndef_message_h message, int index, ndef_record_h * record)
+{
+ return net_nfc_util_get_carrier_config_record ((ndef_message_s *) message, index, (ndef_record_s **) record);
+}
+
+API net_nfc_error_e net_nfc_get_handover_random_number(ndef_message_h message, unsigned short* random_number)
+{
+ return net_nfc_util_get_handover_random_number((ndef_message_s *) message, random_number);
+}
+
+API net_nfc_error_e net_nfc_get_alternative_carrier_record_count (ndef_message_h message, unsigned int * count)
+{
+ return net_nfc_util_get_alternative_carrier_record_count ((ndef_message_s *) message, count);
+}
+
+API net_nfc_error_e net_nfc_get_alternative_carrier_power_status (ndef_message_h message, int index, net_nfc_conn_handover_carrier_state_e * power_state)
+{
+ return net_nfc_util_get_alternative_carrier_power_status ((ndef_message_s *) message, index, power_state);
+}
+
+API net_nfc_error_e net_nfc_set_alternative_carrier_power_status (ndef_message_h message, int index, net_nfc_conn_handover_carrier_state_e power_status)
+{
+ return net_nfc_util_set_alternative_carrier_power_status ((ndef_message_s *) message, index, power_status);
+}
+
+API net_nfc_error_e net_nfc_get_alternative_carrier_type (ndef_message_h message, int index, net_nfc_conn_handover_carrier_type_e * type)
+{
+ return net_nfc_util_get_alternative_carrier_type ((ndef_message_s *) message, index, type);
+}
+
+API net_nfc_error_e net_nfc_create_handover_request_message (ndef_message_h * message)
+{
+ return net_nfc_util_create_handover_request_message ((ndef_message_s **) message);
+}
+
+API net_nfc_error_e net_nfc_create_handover_select_message (ndef_message_h * message)
+{
+ return net_nfc_util_create_handover_select_message((ndef_message_s **) message);
+}
+
+API net_nfc_error_e net_nfc_create_handover_error_record (ndef_record_h * record, uint8_t reason, uint32_t data)
+{
+ return net_nfc_util_create_handover_error_record ((ndef_record_s**) record, reason, data);
+}
+
+
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "net_nfc_ndef_record.h"
+#include "net_nfc_ndef_message.h"
+#include "net_nfc_data.h"
+#include "net_nfc_debug_internal.h"
+#include "net_nfc_util_internal.h"
+#include "net_nfc_util_ndef_record.h"
+
+API net_nfc_error_e net_nfc_create_record(ndef_record_h* record, net_nfc_record_tnf_e tnf, data_h typeName, data_h id, data_h payload)
+{
+ return net_nfc_util_create_record(tnf, (data_s*)typeName, (data_s*)id, (data_s*)payload, (ndef_record_s**)record);
+}
+
+API net_nfc_error_e net_nfc_create_text_type_record(ndef_record_h* record, const char* text, const char* language_code_str, net_nfc_encode_type_e encode)
+{
+ return net_nfc_util_create_text_type_record(text, language_code_str, encode, (ndef_record_s**)record);
+}
+
+API net_nfc_error_e net_nfc_create_uri_type_record(ndef_record_h* record, const char* uri, net_nfc_schema_type_e protocol_schema)
+{
+ return net_nfc_util_create_uri_type_record(uri, protocol_schema, (ndef_record_s**)record);
+}
+
+API net_nfc_error_e net_nfc_free_record(ndef_record_h record)
+{
+ return net_nfc_util_free_record((ndef_record_s*)record);
+}
+
+API net_nfc_error_e net_nfc_get_record_payload(ndef_record_h record, data_h * payload)
+{
+ if (record == NULL || payload == NULL)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+ ndef_record_s * struct_record = (ndef_record_s *)record;
+
+ *payload = (data_h)&(struct_record->payload_s);
+
+ return NET_NFC_OK;
+}
+
+API net_nfc_error_e net_nfc_get_record_type(ndef_record_h record, data_h * type)
+{
+ if (record == NULL || type == NULL)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+ ndef_record_s * struct_record = (ndef_record_s *)record;
+
+ *type = (data_h)&(struct_record->type_s);
+
+ return NET_NFC_OK;
+
+}
+
+API net_nfc_error_e net_nfc_get_record_id(ndef_record_h record, data_h * id)
+{
+ if (record == NULL || id == NULL)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+ ndef_record_s * struct_record = (ndef_record_s *)record;
+
+ *id = (data_h)&(struct_record->id_s);
+
+ return NET_NFC_OK;
+
+}
+
+API net_nfc_error_e net_nfc_get_record_tnf(ndef_record_h record, net_nfc_record_tnf_e * TNF)
+{
+ if (record == NULL || TNF == NULL)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+ ndef_record_s * struct_record = (ndef_record_s *)record;
+
+ *TNF = (net_nfc_record_tnf_e)struct_record->TNF;
+
+ return NET_NFC_OK;
+}
+
+API net_nfc_error_e net_nfc_set_record_id(ndef_record_h record, data_h id)
+{
+
+ ndef_record_s * tmp_record = (ndef_record_s *)record;
+ data_s * tmp_id = (data_s *)id;
+
+ if (tmp_id == NULL)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+ return net_nfc_util_set_record_id(tmp_record, tmp_id->buffer, tmp_id->length);
+}
+
+API net_nfc_error_e net_nfc_get_record_flags(ndef_record_h record, uint8_t * flag)
+{
+ if (record == NULL || flag == NULL)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ ndef_record_s * struct_record = (ndef_record_s *)record;
+
+ *flag = struct_record->MB;
+ *flag <<= 1;
+ *flag += struct_record->ME;
+ *flag <<= 1;
+ *flag += struct_record->CF;
+ *flag <<= 1;
+ *flag += struct_record->SR;
+ *flag <<= 1;
+ *flag += struct_record->IL;
+ *flag <<= 3;
+ *flag += struct_record->TNF;
+
+ return NET_NFC_OK;
+}
+
+API uint8_t net_nfc_get_record_mb(uint8_t flag)
+{
+ return ((flag >> 7) & 0x01);
+}
+
+API uint8_t net_nfc_get_record_me(uint8_t flag)
+{
+ return ((flag >> 6) & 0x01);
+}
+
+API uint8_t net_nfc_get_record_cf(uint8_t flag)
+{
+ return ((flag >> 5) & 0x01);
+}
+
+API uint8_t net_nfc_get_record_sr(uint8_t flag)
+{
+ return ((flag >> 4) & 0x01);
+}
+
+API uint8_t net_nfc_get_record_il(uint8_t flag)
+{
+ return ((flag >> 3) & 0x01);
+}
+
+API net_nfc_error_e net_nfc_create_text_string_from_text_record(ndef_record_h record, char** buffer)
+{
+ if (record == NULL || buffer == NULL)
+ {
+ return NET_NFC_ALLOC_FAIL;
+ }
+
+ data_h payload;
+ data_h rec_type;
+
+ if (net_nfc_get_record_type(record, &rec_type) == NET_NFC_OK)
+ {
+ if (strncmp((char *)net_nfc_get_data_buffer(rec_type), TEXT_RECORD_TYPE, 1) != 0)
+ {
+ DEBUG_CLIENT_MSG("record type is not matched");
+ return NET_NFC_NDEF_RECORD_IS_NOT_EXPECTED_TYPE;
+ }
+ }
+
+ if (net_nfc_get_record_payload(record, &payload) == NET_NFC_OK)
+ {
+ uint8_t* buffer_temp = net_nfc_get_data_buffer(payload);
+ uint32_t buffer_length = net_nfc_get_data_length(payload);
+
+ int controllbyte = buffer_temp[0];
+ int lang_code_length = controllbyte & 0x3F;
+ int index = lang_code_length + 1;
+ int text_length = buffer_length - (lang_code_length + 1);
+
+ if ((*buffer = (char *)calloc(1, text_length + 1)) != NULL)
+ {
+ memcpy(*buffer, &(buffer_temp[index]), text_length);
+ DEBUG_CLIENT_MSG("text = [%s]", *buffer);
+ }
+ else
+ {
+ return NET_NFC_ALLOC_FAIL;
+ }
+ }
+
+ return NET_NFC_OK;
+}
+
+API net_nfc_error_e net_nfc_get_languange_code_string_from_text_record(ndef_record_h record, char** lang_code_str)
+{
+ if (record == NULL || lang_code_str == NULL)
+ {
+ return NET_NFC_ALLOC_FAIL;
+ }
+
+ data_h payload;
+ data_h rec_type;
+
+ if (net_nfc_get_record_type(record, &rec_type) == NET_NFC_OK)
+ {
+ if (strncmp((char *)net_nfc_get_data_buffer(rec_type), TEXT_RECORD_TYPE, 1) != 0)
+ {
+ DEBUG_CLIENT_MSG("record type is not matched");
+ return NET_NFC_NDEF_RECORD_IS_NOT_EXPECTED_TYPE;
+ }
+ }
+
+ if (net_nfc_get_record_payload(record, &payload) == NET_NFC_OK)
+ {
+ uint8_t* buffer_temp = net_nfc_get_data_buffer(payload);
+ char * buffer = NULL;
+
+ int controllbyte = buffer_temp[0];
+ int lang_code_length = controllbyte & 0x3F;
+ int index = 1;
+
+ if ((buffer = (char *)calloc(1, lang_code_length + 1)) != NULL)
+ {
+ memcpy(buffer, &(buffer_temp[index]), lang_code_length);
+ DEBUG_CLIENT_MSG("language code = [%s]", buffer);
+
+ *lang_code_str = buffer;
+ }
+ else
+ {
+ return NET_NFC_ALLOC_FAIL;
+ }
+ }
+
+ return NET_NFC_OK;
+}
+
+API net_nfc_error_e net_nfc_get_encoding_type_from_text_record(ndef_record_h record, net_nfc_encode_type_e * encoding)
+{
+ if (record == NULL || encoding == NULL)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ data_h payload;
+ data_h rec_type;
+
+ if (net_nfc_get_record_type(record, &rec_type) == NET_NFC_OK)
+ {
+ if (strncmp((char *)net_nfc_get_data_buffer(rec_type), TEXT_RECORD_TYPE, 1) != 0)
+ {
+ DEBUG_CLIENT_MSG("record type is not matched");
+ return NET_NFC_NDEF_RECORD_IS_NOT_EXPECTED_TYPE;
+ }
+ }
+
+ if (net_nfc_get_record_payload(record, &payload) == NET_NFC_OK)
+ {
+ uint8_t* buffer_temp = net_nfc_get_data_buffer(payload);
+
+ int controllbyte = buffer_temp[0];
+
+ if ((controllbyte & 0x80) == 0x80)
+ {
+ *encoding = NET_NFC_ENCODE_UTF_16;
+ }
+ else
+ {
+ *encoding = NET_NFC_ENCODE_UTF_8;
+ }
+ }
+
+ return NET_NFC_OK;
+}
+
+API net_nfc_error_e net_nfc_create_uri_string_from_uri_record(ndef_record_h record, char **uri)
+{
+ return net_nfc_util_create_uri_string_from_uri_record((ndef_record_s *)record, uri);
+}
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "net_nfc_typedef_internal.h"
+#include "net_nfc_debug_internal.h"
+#include "net_nfc_util_internal.h"
+#include "net_nfc_util_ndef_message.h"
+#include "net_nfc_util_gdbus_internal.h"
+#include "net_nfc_gdbus.h"
+#include "net_nfc_client.h"
+#include "net_nfc_client_manager.h"
+#include "net_nfc_client_p2p.h"
+
+typedef struct _P2pFuncData P2pFuncData;
+
+struct _P2pFuncData
+{
+ gpointer p2p_send_callback;
+ gpointer p2p_send_data;
+};
+
+
+typedef struct _P2p_SignalHandler P2pSignalHandler;
+
+struct _P2p_SignalHandler
+{
+ net_nfc_client_p2p_device_discovered p2p_device_discovered_cb;
+ net_nfc_client_p2p_device_detached p2p_device_detached_cb;
+ net_nfc_client_p2p_data_received p2p_data_received_cb;
+
+ gpointer p2p_device_discovered_data;
+ gpointer p2p_device_detached_data;
+ gpointer p2p_data_received_data;
+};
+
+static NetNfcGDbusP2p *p2p_proxy = NULL;
+static P2pSignalHandler *p2p_signal_handler = NULL;
+
+static void p2p_device_detached(GObject *source_object,
+ gpointer user_data);
+
+static void p2p_device_discovered(GObject *source_object,
+ guint arg_handle,
+ gpointer user_data);
+
+static void p2p_device_data_received(GObject *source_object,
+ GVariant *arg_data,
+ gpointer user_data);
+
+static void p2p_call_send(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data);
+
+static void p2p_device_detached(GObject *source_object,
+ gpointer user_data)
+{
+ INFO_MSG(">>> SIGNAL arrived");
+
+ /*llcp client function to set/unset the current target id needs to be implemented*/
+ /*net_nfc_client_llcp_current_target_id(NULL);*/
+
+ if(p2p_signal_handler == NULL)
+ return;
+
+ if(p2p_signal_handler->p2p_device_detached_cb)
+ {
+ p2p_signal_handler->p2p_device_detached_cb(
+ p2p_signal_handler->p2p_device_detached_data);
+ }
+
+ /*llcp client function to close all socket needs to be implemented*/
+ /*net_nfc_client_llcp_close_all_socket();*/
+}
+
+static void p2p_device_discovered(GObject *source_object,
+ guint arg_handle,
+ gpointer user_data)
+{
+ net_nfc_target_handle_s *handle_info = NULL;
+
+ INFO_MSG(">>> SIGNAL arrived");
+
+ handle_info = GUINT_TO_POINTER(arg_handle);
+
+ if(p2p_signal_handler == NULL)
+ return;
+
+ if(p2p_signal_handler->p2p_device_discovered_cb)
+ {
+ p2p_signal_handler->p2p_device_discovered_cb(handle_info,
+ p2p_signal_handler->p2p_device_discovered_data);
+ }
+}
+
+static void p2p_device_data_received(GObject *source_object,
+ GVariant *arg_data,
+ gpointer user_data)
+{
+ INFO_MSG(">>> SIGNAL arrived");
+
+ if (p2p_signal_handler == NULL)
+ return;
+
+ if (p2p_signal_handler->p2p_data_received_cb)
+ {
+ data_s p2p_data;
+
+ net_nfc_util_gdbus_variant_to_data_s(arg_data, &p2p_data);
+
+ p2p_signal_handler->p2p_data_received_cb(&p2p_data,
+ p2p_signal_handler->p2p_data_received_data);
+
+ net_nfc_util_free_data(&p2p_data);
+ }
+}
+
+static void p2p_call_send(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ P2pFuncData *func_data;
+
+ net_nfc_error_e out_result = NET_NFC_OK;
+ GError *error = NULL;
+
+ net_nfc_client_p2p_send_completed callback;
+
+ if (net_nfc_gdbus_p2p_call_send_finish(
+ NET_NFC_GDBUS_P2P(source_object),
+ (gint *)&out_result,
+ res,
+ &error) == FALSE)
+ {
+ out_result = NET_NFC_UNKNOWN_ERROR;
+
+ DEBUG_ERR_MSG("Can not finish p2p send: %s", error->message);
+ g_error_free(error);
+ }
+
+ func_data = user_data;
+ if (func_data == NULL)
+ {
+ DEBUG_ERR_MSG("can not get P2pFuncData");
+ return;
+ }
+
+ if (func_data->p2p_send_callback == NULL)
+ {
+ DEBUG_CLIENT_MSG("callback function is not avaiilable");
+ g_free(func_data);
+ return;
+ }
+
+ callback = (net_nfc_client_p2p_send_completed)
+ func_data->p2p_send_callback;
+ callback(out_result, func_data->p2p_send_data);
+
+ g_free(func_data);
+}
+
+
+API net_nfc_error_e net_nfc_client_p2p_send(net_nfc_exchanger_data_h exchg_data,
+ net_nfc_target_handle_h handle,
+ net_nfc_client_p2p_send_completed callback,
+ void *cb_data)
+{
+
+ GVariant *arg_data = NULL;
+ P2pFuncData *func_data = NULL;
+ net_nfc_exchanger_data_s *exch_data;
+
+ if(p2p_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not get P2pProxy");
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ func_data = g_new0(P2pFuncData, 1);
+
+ func_data->p2p_send_callback = (gpointer)callback;
+ func_data->p2p_send_data = cb_data;
+
+ exch_data = (net_nfc_exchanger_data_s *)exchg_data;
+
+ arg_data = net_nfc_util_gdbus_data_to_variant(&exch_data->binary_data);
+
+ net_nfc_gdbus_p2p_call_send(p2p_proxy,
+ exch_data->type,
+ arg_data,
+ GPOINTER_TO_UINT(handle),
+ net_nfc_client_gdbus_get_privilege(),
+ NULL,
+ p2p_call_send,
+ func_data);
+
+ return NET_NFC_OK;
+}
+
+
+
+API net_nfc_error_e net_nfc_client_p2p_send_sync(
+ net_nfc_exchanger_data_h exchg_data,
+ net_nfc_target_handle_h handle)
+{
+ GVariant *arg_data = NULL;
+ GError *error = NULL;
+ net_nfc_exchanger_data_s *exch_data;
+
+ net_nfc_error_e out_result = NET_NFC_OK;
+
+ if (p2p_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not get P2pProxy");
+
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ exch_data = (net_nfc_exchanger_data_s *)exchg_data;
+
+ arg_data = net_nfc_util_gdbus_data_to_variant(&exch_data->binary_data);
+
+ if (net_nfc_gdbus_p2p_call_send_sync(p2p_proxy,
+ exch_data->type,
+ arg_data,
+ GPOINTER_TO_UINT(handle),
+ net_nfc_client_gdbus_get_privilege(),
+ (gint *)&out_result,
+ NULL,
+ &error) == FALSE)
+ {
+ DEBUG_ERR_MSG("p2p send (sync call) failed: %s",
+ error->message);
+
+ g_error_free(error);
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ return out_result;
+}
+
+
+API void net_nfc_client_p2p_set_device_discovered(
+ net_nfc_client_p2p_device_discovered callback,
+ void *user_data)
+{
+ if(p2p_signal_handler == NULL)
+ {
+ p2p_signal_handler = g_new0(P2pSignalHandler, 1);
+ }
+
+ p2p_signal_handler->p2p_device_discovered_cb = callback;
+ p2p_signal_handler->p2p_device_discovered_data = user_data;
+}
+
+
+API void net_nfc_client_p2p_set_device_detached(
+ net_nfc_client_p2p_device_detached callback,
+ void *user_data)
+{
+ if(p2p_signal_handler == NULL)
+ {
+ p2p_signal_handler = g_new0(P2pSignalHandler, 1);
+ }
+
+ p2p_signal_handler->p2p_device_detached_cb = callback;
+ p2p_signal_handler->p2p_device_detached_data = user_data;
+}
+
+
+API void net_nfc_client_p2p_set_data_received(
+ net_nfc_client_p2p_data_received callback,
+ void *user_data)
+{
+ if(p2p_signal_handler == NULL)
+ {
+ p2p_signal_handler = g_new0(P2pSignalHandler, 1);
+ }
+
+ p2p_signal_handler->p2p_data_received_cb = callback;
+ p2p_signal_handler->p2p_data_received_data = user_data;
+}
+
+
+API void net_nfc_client_p2p_unset_device_discovered(void)
+{
+ if(p2p_signal_handler == NULL)
+ {
+ DEBUG_ERR_MSG("p2p_signal_handler is not initialized");
+ return;
+ }
+
+ else
+ {
+ p2p_signal_handler->p2p_device_discovered_cb = NULL;
+ p2p_signal_handler->p2p_device_discovered_data = NULL;
+ g_free(p2p_signal_handler);
+ p2p_signal_handler = NULL;
+ }
+}
+
+
+API void net_nfc_client_p2p_unset_device_detached(void)
+{
+ if(p2p_signal_handler == NULL)
+ {
+ DEBUG_ERR_MSG("p2p_signal_handler is not initialized");
+ return;
+ }
+
+ else
+ {
+ p2p_signal_handler->p2p_device_detached_cb = NULL;
+ p2p_signal_handler->p2p_device_detached_data = NULL;
+ }
+}
+
+
+API void net_nfc_client_p2p_unset_data_received(void)
+{
+ if(p2p_signal_handler == NULL)
+ {
+ DEBUG_ERR_MSG("p2p_signal_handler is not initialized");
+ return;
+ }
+
+ else
+ {
+ p2p_signal_handler->p2p_data_received_cb = NULL;
+ p2p_signal_handler->p2p_data_received_data = NULL;
+ }
+}
+
+net_nfc_error_e net_nfc_client_p2p_init(void)
+{
+ GError *error = NULL;
+
+ if (p2p_proxy)
+ {
+ DEBUG_CLIENT_MSG("Already initialized");
+
+ return NET_NFC_OK;
+ }
+
+ p2p_proxy = net_nfc_gdbus_p2p_proxy_new_for_bus_sync(
+ G_BUS_TYPE_SYSTEM,
+ G_DBUS_PROXY_FLAGS_NONE,
+ "org.tizen.NetNfcService",
+ "/org/tizen/NetNfcService/P2p",
+ NULL,
+ &error);
+ if (p2p_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not create proxy : %s", error->message);
+ g_error_free(error);
+
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ g_signal_connect(p2p_proxy, "detached",
+ G_CALLBACK(p2p_device_detached), NULL);
+
+ g_signal_connect(p2p_proxy, "discovered",
+ G_CALLBACK(p2p_device_discovered), NULL);
+
+ g_signal_connect(p2p_proxy, "received",
+ G_CALLBACK(p2p_device_data_received), NULL);
+
+ return NET_NFC_OK;
+}
+
+void net_nfc_client_p2p_deinit(void)
+{
+ if(p2p_proxy)
+ {
+ g_object_unref(p2p_proxy);
+ p2p_proxy = NULL;
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "net_nfc_typedef_internal.h"
+#include "net_nfc_debug_internal.h"
+#include "net_nfc_util_internal.h"
+#include "net_nfc_util_ndef_message.h"
+#include "net_nfc_util_gdbus_internal.h"
+#include "net_nfc_gdbus.h"
+#include "net_nfc_client.h"
+#include "net_nfc_client_manager.h"
+#include "net_nfc_client_se.h"
+
+typedef struct _SeFuncData SeFuncData;
+
+struct _SeFuncData
+{
+ gpointer se_callback;
+ gpointer se_data;
+};
+
+typedef struct _SeEventHandler SeEventHandler;
+
+struct _SeEventHandler
+{
+ net_nfc_client_se_event se_event_cb;
+ gpointer se_event_data;
+};
+
+typedef struct _SeTransEventHandler SeTransEventHandler;
+
+struct _SeTransEventHandler
+{
+ net_nfc_client_se_transaction_event se_transaction_event_cb;
+ gpointer se_transaction_event_data;
+};
+
+typedef struct _SeESEDetectedHandler SeESEDetectedHandler;
+
+struct _SeESEDetectedHandler
+{
+ net_nfc_client_se_ese_detected_event se_ese_detected_cb;
+ gpointer se_ese_detected_data;
+};
+
+
+static NetNfcGDbusSecureElement *se_proxy = NULL;
+
+static SeEventHandler se_eventhandler;
+static SeTransEventHandler se_transeventhandler;
+static SeESEDetectedHandler se_esedetecthandler;
+
+static void se_ese_detected(GObject *source_object,
+ guint arg_handle,
+ gint arg_se_type,
+ GVariant *arg_data);
+
+static void se_type_changed(GObject *source_object,
+ gint arg_se_type);
+
+static void set_secure_element(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data);
+
+static void open_secure_element(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data);
+
+static void close_secure_element(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data);
+
+static void send_apdu_secure_element(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data);
+
+static void get_atr_secure_element(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data);
+
+
+static void se_ese_detected(GObject *source_object,
+ guint arg_handle,
+ gint arg_se_type,
+ GVariant *arg_data)
+{
+ INFO_MSG(">>> SIGNAL arrived");
+
+ if (se_esedetecthandler.se_ese_detected_cb != NULL) {
+ data_s buffer_data = { NULL, 0 };
+ net_nfc_client_se_ese_detected_event callback =
+ (net_nfc_client_se_ese_detected_event)se_esedetecthandler.se_ese_detected_cb;
+
+ net_nfc_util_gdbus_variant_to_data_s(arg_data, &buffer_data);
+
+ callback((net_nfc_target_handle_h)arg_handle,
+ arg_se_type, &buffer_data,
+ se_esedetecthandler.se_ese_detected_data);
+
+ net_nfc_util_free_data(&buffer_data);
+ }
+}
+
+
+static void se_type_changed(GObject *source_object,
+ gint arg_se_type)
+{
+ INFO_MSG(">>> SIGNAL arrived");
+
+ if (se_eventhandler.se_event_cb != NULL)
+ {
+ net_nfc_client_se_event callback =
+ (net_nfc_client_se_event)se_eventhandler.se_event_cb;
+
+ callback((net_nfc_message_e)arg_se_type,
+ se_eventhandler.se_event_data);
+ }
+}
+
+
+static void se_transaction_event(GObject *source_object,
+ gint arg_se_type,
+ GVariant *arg_aid,
+ GVariant *arg_param)
+{
+ INFO_MSG(">>> SIGNAL arrived");
+
+ if (se_transeventhandler.se_transaction_event_cb != NULL) {
+ net_nfc_client_se_transaction_event callback =
+ (net_nfc_client_se_transaction_event)se_transeventhandler.se_transaction_event_cb;
+ data_s aid = { NULL, 0 };
+ data_s param = { NULL, 0 };
+
+ net_nfc_util_gdbus_variant_to_data_s(arg_aid, &aid);
+ net_nfc_util_gdbus_variant_to_data_s(arg_param, ¶m);
+
+ callback(&aid, ¶m,
+ se_transeventhandler.se_transaction_event_data);
+
+ net_nfc_util_free_data(¶m);
+ net_nfc_util_free_data(&aid);
+ }
+}
+
+
+static void set_secure_element(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ SeFuncData *func_data = (SeFuncData *)user_data;
+ net_nfc_error_e result;
+ GError *error = NULL;
+
+ g_assert(user_data != NULL);
+
+ if (net_nfc_gdbus_secure_element_call_set_finish(se_proxy,
+ &result,
+ res,
+ &error) == FALSE)
+ {
+ result = NET_NFC_IPC_FAIL;
+
+ DEBUG_ERR_MSG("Could not set secure element: %s",
+ error->message);
+
+ g_error_free(error);
+ }
+
+ if (func_data->se_callback != NULL)
+ {
+ net_nfc_se_set_se_cb se_callback =
+ (net_nfc_se_set_se_cb)func_data->se_callback;
+
+ se_callback(result, func_data->se_data);
+ }
+
+ g_free(func_data);
+}
+
+
+static void open_secure_element(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ SeFuncData *func_data = (SeFuncData *)user_data;
+ net_nfc_error_e result;
+ GError *error = NULL;
+ guint out_handle;
+
+ g_assert(user_data != NULL);
+
+ if (net_nfc_gdbus_secure_element_call_open_secure_element_finish(
+ se_proxy,
+ &result,
+ &out_handle,
+ res,
+ &error) == FALSE)
+ {
+ result = NET_NFC_IPC_FAIL;
+
+ DEBUG_ERR_MSG("Could not open secure element: %s",
+ error->message);
+
+ g_error_free(error);
+ }
+
+ if (func_data->se_callback != NULL)
+ {
+ net_nfc_se_open_se_cb se_callback =
+ (net_nfc_se_open_se_cb)func_data->se_callback;
+
+ se_callback(result,
+ (net_nfc_target_handle_h)out_handle,
+ func_data->se_data);
+ }
+
+ g_free(func_data);
+}
+
+
+static void close_secure_element(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ SeFuncData *func_data = (SeFuncData *)user_data;
+ net_nfc_error_e result;
+ GError *error = NULL;
+
+ g_assert(user_data != NULL);
+
+ if (net_nfc_gdbus_secure_element_call_close_secure_element_finish(
+ se_proxy,
+ &result,
+ res,
+ &error) == FALSE)
+ {
+ result = NET_NFC_IPC_FAIL;
+
+ DEBUG_ERR_MSG("Could not close secure element: %s", error->message);
+
+ g_error_free(error);
+ }
+
+ if (func_data->se_callback != NULL)
+ {
+ net_nfc_se_close_se_cb se_callback =
+ (net_nfc_se_close_se_cb)func_data->se_callback;
+
+ se_callback(result, func_data->se_data);
+ }
+
+ g_free(func_data);
+}
+
+
+static void send_apdu_secure_element(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ SeFuncData *func_data = (SeFuncData *)user_data;
+ net_nfc_error_e result;
+ GVariant *out_response;
+ GError *error = NULL;
+
+ g_assert(user_data != NULL);
+
+ if (net_nfc_gdbus_secure_element_call_send_apdu_finish(
+ se_proxy,
+ &result,
+ &out_response,
+ res,
+ &error) == FALSE)
+ {
+ result = NET_NFC_IPC_FAIL;
+
+ DEBUG_ERR_MSG("Could not send apdu: %s", error->message);
+
+ g_error_free(error);
+ }
+
+ if (func_data->se_callback != NULL)
+ {
+ net_nfc_se_send_apdu_cb se_callback =
+ (net_nfc_se_send_apdu_cb)func_data->se_callback;
+ data_s data = { NULL, };
+
+ net_nfc_util_gdbus_variant_to_data_s(out_response, &data);
+
+ se_callback(result, &data, func_data->se_data);
+
+ net_nfc_util_free_data(&data);
+ }
+
+ g_free(func_data);
+}
+
+
+static void get_atr_secure_element(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ SeFuncData *func_data = (SeFuncData *)user_data;
+ net_nfc_error_e result;
+ GVariant *out_atr;
+ GError *error = NULL;
+
+ g_assert(user_data != NULL);
+
+ if (net_nfc_gdbus_secure_element_call_get_atr_finish(
+ se_proxy,
+ &result,
+ &out_atr,
+ res,
+ &error) == FALSE)
+ {
+ result = NET_NFC_IPC_FAIL;
+
+ DEBUG_ERR_MSG("Could not get atr: %s", error->message);
+
+ g_error_free(error);
+ }
+
+ if (func_data->se_callback != NULL)
+ {
+ net_nfc_se_get_atr_cb se_callback =
+ (net_nfc_se_get_atr_cb)func_data->se_callback;
+ data_s data = { NULL, };
+
+ net_nfc_util_gdbus_variant_to_data_s(out_atr, &data);
+
+ se_callback(result, &data, func_data->se_data);
+
+ net_nfc_util_free_data(&data);
+ }
+
+ g_free(func_data);
+}
+
+
+API net_nfc_error_e net_nfc_client_se_set_secure_element_type(
+ net_nfc_se_type_e se_type,
+ net_nfc_se_set_se_cb callback,
+ void *user_data)
+{
+ SeFuncData *func_data;
+
+ if (se_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not get se_proxy");
+
+ return NET_NFC_NOT_INITIALIZED;
+ }
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ func_data = g_new0(SeFuncData, 1);
+ if (func_data == NULL)
+ return NET_NFC_ALLOC_FAIL;
+
+ func_data->se_callback = (gpointer)callback;
+ func_data->se_data = user_data;
+
+ net_nfc_gdbus_secure_element_call_set(
+ se_proxy,
+ (gint)se_type,
+ net_nfc_client_gdbus_get_privilege(),
+ NULL,
+ set_secure_element,
+ func_data);
+
+ return NET_NFC_OK;
+}
+
+
+API net_nfc_error_e net_nfc_client_se_set_secure_element_type_sync(
+ net_nfc_se_type_e se_type)
+{
+ net_nfc_error_e result;
+ GError *error = NULL;
+
+ if (se_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not get se_proxy");
+
+ return NET_NFC_NOT_INITIALIZED;
+ }
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ if (net_nfc_gdbus_secure_element_call_set_sync(
+ se_proxy,
+ (gint)se_type,
+ net_nfc_client_gdbus_get_privilege(),
+ &result,
+ NULL,
+ &error) == FALSE)
+ {
+ DEBUG_ERR_MSG("Set secure element failed: %s", error->message);
+
+ g_error_free(error);
+
+ result = NET_NFC_IPC_FAIL;
+ }
+
+ return result;
+}
+
+
+API net_nfc_error_e net_nfc_client_se_open_internal_secure_element(
+ net_nfc_se_type_e se_type,
+ net_nfc_se_open_se_cb callback,
+ void *user_data)
+{
+ SeFuncData *func_data;
+
+ if (se_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not get se_proxy");
+
+ return NET_NFC_NOT_INITIALIZED;
+ }
+
+ /* allow this function even nfc is off */
+
+ func_data = g_new0(SeFuncData, 1);
+ if (func_data == NULL)
+ return NET_NFC_ALLOC_FAIL;
+
+ func_data->se_callback = (gpointer)callback;
+ func_data->se_data = user_data;
+
+ net_nfc_gdbus_secure_element_call_open_secure_element(
+ se_proxy,
+ (gint)se_type,
+ net_nfc_client_gdbus_get_privilege(),
+ NULL,
+ open_secure_element,
+ user_data);
+
+ return NET_NFC_OK;
+}
+
+
+API net_nfc_error_e net_nfc_client_se_open_internal_secure_element_sync(
+ net_nfc_se_type_e se_type,
+ net_nfc_target_handle_h *handle)
+{
+ net_nfc_error_e result;
+ guint out_handle;
+ GError *error = NULL;
+
+ if (handle == NULL) {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ if (se_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not get se_proxy");
+
+ return NET_NFC_NOT_INITIALIZED;
+ }
+
+ /* allow this function even nfc is off */
+
+ if (net_nfc_gdbus_secure_element_call_open_secure_element_sync(
+ se_proxy,
+ se_type,
+ net_nfc_client_gdbus_get_privilege(),
+ &result,
+ &out_handle,
+ NULL,
+ &error) == true) {
+ *handle = GUINT_TO_POINTER(out_handle);
+ } else {
+ DEBUG_ERR_MSG("Open internal secure element failed: %s",
+ error->message);
+ g_error_free(error);
+
+ result = NET_NFC_IPC_FAIL;
+ }
+
+ return result;
+}
+
+
+API net_nfc_error_e net_nfc_client_se_close_internal_secure_element(
+ net_nfc_target_handle_h handle,
+ net_nfc_se_close_se_cb callback,
+ void *user_data)
+{
+ SeFuncData *func_data;
+
+ if (se_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not get se_proxy");
+
+ return NET_NFC_NOT_INITIALIZED;
+ }
+
+ /* allow this function even nfc is off */
+
+ func_data = g_new0(SeFuncData, 1);
+ if (func_data == NULL)
+ return NET_NFC_ALLOC_FAIL;
+
+ func_data->se_callback = (gpointer)callback;
+ func_data->se_data = user_data;
+
+ net_nfc_gdbus_secure_element_call_close_secure_element(
+ se_proxy,
+ GPOINTER_TO_UINT(handle),
+ net_nfc_client_gdbus_get_privilege(),
+ NULL,
+ close_secure_element,
+ user_data);
+
+ return NET_NFC_OK;
+}
+
+
+API net_nfc_error_e net_nfc_client_se_close_internal_secure_element_sync(
+ net_nfc_target_handle_h handle)
+{
+ net_nfc_error_e result;
+ GError *error = NULL;
+
+ if (se_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not get se_proxy");
+
+ return NET_NFC_NOT_INITIALIZED;
+ }
+
+ /* allow this function even nfc is off */
+
+ if (net_nfc_gdbus_secure_element_call_close_secure_element_sync(
+ se_proxy,
+ GPOINTER_TO_UINT(handle),
+ net_nfc_client_gdbus_get_privilege(),
+ &result,
+ NULL,
+ &error) == FALSE)
+ {
+ DEBUG_ERR_MSG("close internal secure element failed: %s",
+ error->message);
+ g_error_free(error);
+
+ result = NET_NFC_IPC_FAIL;
+ }
+
+ return result;
+}
+
+
+API net_nfc_error_e net_nfc_client_se_get_atr(
+ net_nfc_target_handle_h handle,
+ net_nfc_se_get_atr_cb callback,
+ void *user_data)
+{
+ SeFuncData *func_data;
+
+ if (se_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not get se_proxy");
+
+ return NET_NFC_NOT_INITIALIZED;
+ }
+
+ /* allow this function even nfc is off */
+
+ func_data = g_new0(SeFuncData, 1);
+ if (func_data == NULL)
+ return NET_NFC_ALLOC_FAIL;
+
+ func_data->se_callback = (gpointer)callback;
+ func_data->se_data = user_data;
+
+ net_nfc_gdbus_secure_element_call_get_atr(
+ se_proxy,
+ GPOINTER_TO_UINT(handle),
+ net_nfc_client_gdbus_get_privilege(),
+ NULL,
+ get_atr_secure_element,
+ func_data);
+
+ return NET_NFC_OK;
+}
+
+
+API net_nfc_error_e net_nfc_client_se_get_atr_sync(
+ net_nfc_target_handle_h handle,
+ data_h *atr)
+{
+ net_nfc_error_e result;
+ GVariant *out_atr;
+ GError *error = NULL;
+
+ if (atr == NULL) {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ *atr = NULL;
+
+ if (se_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not get se_proxy");
+
+ return NET_NFC_NOT_INITIALIZED;
+ }
+
+ /* allow this function even nfc is off */
+
+ if (net_nfc_gdbus_secure_element_call_get_atr_sync(
+ se_proxy,
+ GPOINTER_TO_UINT(handle),
+ net_nfc_client_gdbus_get_privilege(),
+ &result,
+ &out_atr,
+ NULL,
+ &error) == true) {
+ *atr = net_nfc_util_gdbus_variant_to_data(out_atr);
+ } else {
+ DEBUG_ERR_MSG("Get attributes failed: %s", error->message);
+ g_error_free(error);
+
+ result = NET_NFC_IPC_FAIL;
+ }
+
+ return result;
+}
+
+
+API net_nfc_error_e net_nfc_client_se_send_apdu(
+ net_nfc_target_handle_h handle,
+ data_h apdu_data,
+ net_nfc_se_send_apdu_cb callback,
+ void *user_data)
+{
+ SeFuncData *func_data;
+ GVariant *arg_data;
+
+ if (se_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not get se_proxy");
+
+ return NET_NFC_NOT_INITIALIZED;
+ }
+
+ /* allow this function even nfc is off */
+
+ arg_data = net_nfc_util_gdbus_data_to_variant((data_s *)apdu_data);
+ if (arg_data == NULL)
+ return NET_NFC_INVALID_PARAM;
+
+ func_data = g_new0(SeFuncData, 1);
+ if (func_data == NULL) {
+ g_variant_unref(arg_data);
+
+ return NET_NFC_ALLOC_FAIL;
+ }
+
+ func_data->se_callback = (gpointer)callback;
+ func_data->se_data = user_data;
+
+ net_nfc_gdbus_secure_element_call_send_apdu(
+ se_proxy,
+ GPOINTER_TO_UINT(handle),
+ arg_data,
+ net_nfc_client_gdbus_get_privilege(),
+ NULL,
+ send_apdu_secure_element,
+ func_data);
+
+ return NET_NFC_OK;
+}
+
+
+API net_nfc_error_e net_nfc_client_se_send_apdu_sync(
+ net_nfc_target_handle_h handle,
+ data_h apdu_data,
+ data_h *response)
+{
+ net_nfc_error_e result;
+ GVariant *out_data;
+ GVariant *arg_data;
+ GError *error = NULL;
+
+ if (response == NULL) {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ *response = NULL;
+
+ if (se_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not get se_proxy");
+
+ return NET_NFC_NOT_INITIALIZED;
+ }
+
+ /* allow this function even nfc is off */
+
+ arg_data = net_nfc_util_gdbus_data_to_variant((data_s *)apdu_data);
+ if (arg_data == NULL)
+ return NET_NFC_INVALID_PARAM;
+
+ if (net_nfc_gdbus_secure_element_call_send_apdu_sync(
+ se_proxy,
+ GPOINTER_TO_UINT(handle),
+ arg_data,
+ net_nfc_client_gdbus_get_privilege(),
+ &result,
+ &out_data,
+ NULL,
+ &error) == true) {
+ *response = net_nfc_util_gdbus_variant_to_data(out_data);
+ } else {
+ DEBUG_ERR_MSG("Send APDU failed: %s",
+ error->message);
+ g_error_free(error);
+
+ result = NET_NFC_IPC_FAIL;
+ }
+
+ return result;
+}
+
+
+API void net_nfc_client_se_set_ese_detection_cb(
+ net_nfc_client_se_ese_detected_event callback,
+ void *user_data)
+{
+ se_esedetecthandler.se_ese_detected_cb = callback;
+ se_esedetecthandler.se_ese_detected_data = user_data;
+}
+
+
+API void net_nfc_client_se_unset_ese_detection_cb(void)
+{
+ net_nfc_client_se_set_ese_detection_cb(NULL, NULL);
+}
+
+
+API void net_nfc_client_se_set_transaction_event_cb(
+ net_nfc_client_se_transaction_event callback,
+ void *user_data)
+{
+ se_transeventhandler.se_transaction_event_cb = callback;
+ se_transeventhandler.se_transaction_event_data = user_data;
+}
+
+
+API void net_nfc_client_se_unset_transaction_event_cb(void)
+{
+ net_nfc_client_se_set_transaction_event_cb(NULL, NULL);
+}
+
+
+API void net_nfc_client_se_set_event_cb(net_nfc_client_se_event callback,
+ void *user_data)
+{
+ se_eventhandler.se_event_cb = callback;
+ se_eventhandler.se_event_data = user_data;
+}
+
+
+API void net_nfc_client_se_unset_event_cb(void)
+{
+ net_nfc_client_se_set_event_cb(NULL, NULL);
+}
+
+
+net_nfc_error_e net_nfc_client_se_init(void)
+{
+ GError *error = NULL;
+
+ if (se_proxy)
+ {
+ DEBUG_CLIENT_MSG("Already initialized");
+
+ return NET_NFC_OK;
+ }
+
+ se_proxy = net_nfc_gdbus_secure_element_proxy_new_for_bus_sync(
+ G_BUS_TYPE_SYSTEM,
+ G_DBUS_PROXY_FLAGS_NONE,
+ "org.tizen.NetNfcService",
+ "/org/tizen/NetNfcService/SecureElement",
+ NULL,
+ &error);
+ if (se_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not create proxy : %s", error->message);
+
+ g_error_free(error);
+
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ g_signal_connect(se_proxy, "se-type-changed",
+ G_CALLBACK(se_type_changed), NULL);
+
+ g_signal_connect(se_proxy, "ese-detected",
+ G_CALLBACK(se_ese_detected), NULL);
+
+ g_signal_connect(se_proxy, "transaction-event",
+ G_CALLBACK(se_transaction_event), NULL);
+
+ return NET_NFC_OK;
+}
+
+
+void net_nfc_client_se_deinit(void)
+{
+ if (se_proxy)
+ {
+ g_object_unref(se_proxy);
+ se_proxy = NULL;
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include "net_nfc_debug_internal.h"
+#include "net_nfc_util_sign_record.h"
+
+API net_nfc_error_e net_nfc_sign_records(ndef_message_h msg, int begin_index, int end_index, char *cert_file, char *password)
+{
+ return net_nfc_util_sign_records((ndef_message_s *)msg, begin_index, end_index, cert_file, password);
+}
+
+API net_nfc_error_e net_nfc_sign_ndef_message(ndef_message_h msg, char *cert_file, char *password)
+{
+ return net_nfc_util_sign_ndef_message((ndef_message_s *)msg, cert_file, password);
+}
+
+API net_nfc_error_e net_nfc_verify_signature_ndef_message(ndef_message_h msg)
+{
+ return net_nfc_util_verify_signature_ndef_message((ndef_message_s *)msg);
+}
+
+API net_nfc_error_e net_nfc_verify_signature_records(ndef_record_h begin_record, ndef_record_h sign_record)
+{
+ return net_nfc_util_verify_signature_records((ndef_record_s *)begin_record, (ndef_record_s *)sign_record);
+}
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "net_nfc_typedef_internal.h"
+#include "net_nfc_debug_internal.h"
+#include "net_nfc_util_internal.h"
+#include "net_nfc_util_ndef_message.h"
+#include "net_nfc_util_gdbus_internal.h"
+#include "net_nfc_gdbus.h"
+#include "net_nfc_data.h"
+#include "net_nfc_ndef_message.h"
+#include "net_nfc_client.h"
+#include "net_nfc_client_manager.h"
+#include "net_nfc_client_snep.h"
+
+static NetNfcGDbusSnep *snep_proxy = NULL;
+
+/*******************************************************************/
+
+static GVariant *snep_message_to_variant(ndef_message_h message);
+
+static ndef_message_h snep_variant_to_message(GVariant *variant);
+
+/*********************************************************************/
+
+static void snep_send_client_request(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data);
+
+/*********************************************************************/
+
+static GVariant *snep_message_to_variant(ndef_message_h message)
+{
+ data_h data = NULL;
+ GVariant *variant = NULL;
+
+ if (net_nfc_create_rawdata_from_ndef_message(message,
+ &data) != NET_NFC_OK)
+ {
+ DEBUG_ERR_MSG("can not convert ndef_message to rawdata");
+ return NULL;
+ }
+
+ variant = net_nfc_util_gdbus_data_to_variant((data_s *)data);
+
+ net_nfc_free_data(data);
+
+ return variant;
+}
+
+static ndef_message_h snep_variant_to_message(GVariant *variant)
+{
+ data_s data = { NULL, };
+ ndef_message_h message = NULL;
+
+ net_nfc_util_gdbus_variant_to_data_s(variant, &data);
+
+ if (data.buffer && data.length > 0)
+ {
+ if (net_nfc_create_ndef_message_from_rawdata(&message, &data)
+ != NET_NFC_OK)
+ {
+ DEBUG_ERR_MSG("memory alloc fail...");
+ }
+
+ net_nfc_util_free_data(&data);
+ }
+
+ return message;
+}
+
+static void snep_send_client_request(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ GVariant *parameter = (GVariant *)user_data;
+ GError *error = NULL;
+ net_nfc_error_e out_result;
+ net_nfc_snep_type_t out_type;
+ GVariant *out_data;
+
+ if (net_nfc_gdbus_snep_call_client_request_finish(
+ NET_NFC_GDBUS_SNEP(source_object),
+ (gint *)&out_result,
+ (guint *)&out_type,
+ &out_data,
+ res,
+ &error) == FALSE)
+ {
+ DEBUG_ERR_MSG("Can not finish send client request %s",
+ error->message);
+ g_error_free(error);
+
+ out_result = NET_NFC_UNKNOWN_ERROR;
+ }
+
+ if (parameter != NULL) {
+ net_nfc_client_snep_event_cb callback;
+ void *user_param;
+ net_nfc_snep_handle_h handle;
+ ndef_message_h message = NULL;
+
+ g_variant_get(parameter, "(uuu)",
+ (guint *)&callback,
+ (guint *)&user_param,
+ (guint *)&handle);
+
+ if (callback != NULL) {
+ message = snep_variant_to_message(out_data);
+
+ callback(handle, out_type, out_result,
+ message, user_param);
+ }
+
+ g_object_unref(parameter);
+ }
+}
+
+API net_nfc_error_e net_nfc_client_snep_start_server(
+ net_nfc_target_handle_h target,
+ const char *san,
+ sap_t sap,
+ net_nfc_client_snep_event_cb callback,
+ void *user_data)
+{
+ net_nfc_error_e result = NET_NFC_OK;
+ GError *error = NULL;
+ GVariant *parameter;
+
+ if (snep_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not get Snep Proxy");
+
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ parameter = g_variant_new("(uu)",
+ GPOINTER_TO_UINT(callback),
+ GPOINTER_TO_UINT(user_data));
+
+ g_object_ref(parameter);
+
+ if (net_nfc_gdbus_snep_call_server_start_sync(snep_proxy,
+ GPOINTER_TO_UINT(target),
+ sap,
+ san,
+ GPOINTER_TO_UINT(parameter),
+ net_nfc_client_gdbus_get_privilege(),
+ (gint *)&result,
+ NULL,
+ &error) == FALSE)
+ {
+ DEBUG_ERR_MSG("snep server(sync call) failed: %s",
+ error->message);
+ g_error_free(error);
+ g_object_unref(parameter);
+
+ result = NET_NFC_UNKNOWN_ERROR;
+ }
+
+ return result;
+}
+
+API net_nfc_error_e net_nfc_client_snep_start_client(
+ net_nfc_target_handle_h target,
+ const char *san,
+ sap_t sap,
+ net_nfc_client_snep_event_cb callback,
+ void *user_data)
+{
+ net_nfc_error_e result = NET_NFC_OK;
+ GError *error = NULL;
+ GVariant *parameter;
+
+ if (snep_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not get Snep Proxy");
+
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ parameter = g_variant_new("(uu)",
+ GPOINTER_TO_UINT(callback),
+ GPOINTER_TO_UINT(user_data));
+
+ g_object_ref(parameter);
+
+ if (net_nfc_gdbus_snep_call_client_start_sync(snep_proxy,
+ GPOINTER_TO_UINT(target),
+ sap,
+ san,
+ GPOINTER_TO_UINT(parameter),
+ net_nfc_client_gdbus_get_privilege(),
+ (gint *)&result,
+ NULL,
+ &error) == FALSE)
+ {
+ DEBUG_ERR_MSG("snep client(sync call) failed: %s",
+ error->message);
+ g_error_free(error);
+ g_object_unref(parameter);
+
+ result = NET_NFC_UNKNOWN_ERROR;
+ }
+
+ return result;
+}
+
+API net_nfc_error_e net_nfc_client_snep_send_client_request(
+ net_nfc_snep_handle_h target,
+ net_nfc_snep_type_t snep_type,
+ ndef_message_h msg,
+ net_nfc_client_snep_event_cb callback,
+ void *user_data)
+{
+ GVariant *ndef_msg = NULL;
+ GVariant *parameter;
+
+ if (target == NULL || msg == NULL)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ if (snep_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not get Snep Proxy");
+
+ return NET_NFC_NOT_INITIALIZED;
+ }
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ parameter = g_variant_new("(uuu)",
+ GPOINTER_TO_UINT(callback),
+ GPOINTER_TO_UINT(user_data),
+ GPOINTER_TO_UINT(target));
+
+ g_object_ref(parameter);
+
+ ndef_msg = snep_message_to_variant(msg);
+
+ net_nfc_gdbus_snep_call_client_request(snep_proxy,
+ GPOINTER_TO_UINT(target),
+ snep_type,
+ ndef_msg,
+ net_nfc_client_gdbus_get_privilege(),
+ NULL,
+ snep_send_client_request,
+ parameter);
+
+ return NET_NFC_OK;
+}
+#if 0
+API net_nfc_error_e net_nfc_client_snep_send_client_request_sync(
+ net_nfc_target_handle_h target,
+ net_nfc_snep_type_t snep_type,
+ ndef_message_h msg,
+ net_nfc_snep_type_t *resp_type,
+ ndef_message_h *response)
+{
+ GVariant *resp_msg = NULL;
+ GVariant *arg_msg = NULL;
+ GError *error = NULL;
+ net_nfc_error_e result;
+ guint type;
+
+ if (target == NULL || msg == NULL)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ if (snep_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not get Snep Proxy");
+
+ return NET_NFC_NOT_INITIALIZED;
+ }
+
+ arg_msg = snep_message_to_variant(msg);
+
+ if (net_nfc_gdbus_snep_call_client_request_sync(snep_proxy,
+ GPOINTER_TO_UINT(target),
+ snep_type,
+ arg_msg,
+ net_nfc_client_gdbus_get_privilege(),
+ &result,
+ resp_type,
+ &resp_msg,
+ NULL,
+ &error) == FALSE)
+ {
+ DEBUG_ERR_MSG(" send client request (sync call) failed: %s",
+ error->message);
+ g_error_free(error);
+
+ return NET_NFC_IPC_FAIL;
+ }
+
+ *response = NULL;
+
+ if (result == NET_NFC_OK)
+ {
+ data_s ndef_data = { NULL, };
+
+ net_nfc_util_gdbus_variant_to_data_s(resp_msg, &ndef_data);
+
+ if (ndef_data.buffer != NULL && ndef_data.length > 0)
+ {
+ result = net_nfc_create_ndef_message_from_rawdata(
+ response,
+ &ndef_data);
+
+ net_nfc_util_free_data(&ndef_data);
+ }
+ }
+
+ return result;
+}
+#endif
+API net_nfc_error_e net_nfc_client_snep_stop_service_sync(
+ net_nfc_target_handle_h target,
+ net_nfc_snep_handle_h service)
+{
+ net_nfc_error_e result = NET_NFC_OK;
+ GError *error = NULL;
+
+ if (target == NULL || service == NULL)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ if (snep_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not get Snep Proxy");
+
+ return NET_NFC_NOT_INITIALIZED;
+ }
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ if (net_nfc_gdbus_snep_call_stop_snep_sync(
+ snep_proxy,
+ GPOINTER_TO_UINT(target),
+ GPOINTER_TO_UINT(service),
+ net_nfc_client_gdbus_get_privilege(),
+ (gint *)&result,
+ NULL,
+ &error) == FALSE)
+ {
+ DEBUG_ERR_MSG("snep stop service(sync call) failed: %s",
+ error->message);
+ g_error_free(error);
+
+ return NET_NFC_IPC_FAIL;
+ }
+
+ return result;
+}
+
+static void _snep_event_cb(NetNfcGDbusSnep *object,
+ guint arg_handle,
+ guint arg_event,
+ gint arg_result,
+ GVariant *arg_ndef_msg,
+ guint arg_user_data)
+{
+ GVariant *parameter = (GVariant *)GUINT_TO_POINTER(arg_user_data);
+
+ INFO_MSG(">>> SIGNAL arrived");
+
+ DEBUG_CLIENT_MSG("handle [%p], event [%d], result [%d], user_data [%p]",
+ GUINT_TO_POINTER(arg_handle),
+ arg_event,
+ arg_result,
+ parameter);
+
+ if (parameter != NULL)
+ {
+ net_nfc_client_snep_event_cb callback;
+ void *user_data;
+
+ g_variant_get(parameter,
+ "(uu)",
+ &callback,
+ &user_data);
+
+ if (callback != NULL)
+ {
+ ndef_message_h message =
+ snep_variant_to_message(arg_ndef_msg);
+
+ callback(GUINT_TO_POINTER(arg_handle),
+ arg_event,
+ arg_result,
+ message,
+ user_data);
+ }
+
+ if (arg_event == NET_NFC_LLCP_UNREGISTERED) {
+ g_variant_unref(parameter);
+ }
+ }
+}
+
+API net_nfc_error_e net_nfc_client_snep_register_server(const char *san,
+ sap_t sap,
+ net_nfc_client_snep_event_cb callback,
+ void *user_data)
+{
+ net_nfc_error_e result = NET_NFC_OK;
+ GError *error = NULL;
+ GVariant *parameter;
+
+ if (snep_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not get Snep Proxy");
+
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ parameter = g_variant_new("(uu)",
+ GPOINTER_TO_UINT(callback),
+ GPOINTER_TO_UINT(user_data));
+
+ if (net_nfc_gdbus_snep_call_server_register_sync(snep_proxy,
+ sap,
+ san,
+ GPOINTER_TO_UINT(parameter),
+ net_nfc_client_gdbus_get_privilege(),
+ (gint *)&result,
+ NULL,
+ &error) == FALSE)
+ {
+ DEBUG_ERR_MSG("snep register server(sync call) failed: %s",
+ error->message);
+ g_error_free(error);
+ g_variant_unref(parameter);
+
+ result = NET_NFC_UNKNOWN_ERROR;
+ }
+
+ return result;
+}
+
+API net_nfc_error_e net_nfc_client_snep_unregister_server(const char *san,
+ sap_t sap)
+{
+ net_nfc_error_e result = NET_NFC_OK;
+ GError *error = NULL;
+
+ if (snep_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not get Snep Proxy");
+
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ if (net_nfc_gdbus_snep_call_server_unregister_sync(snep_proxy,
+ sap,
+ san,
+ net_nfc_client_gdbus_get_privilege(),
+ (gint *)&result,
+ NULL,
+ &error) == FALSE)
+ {
+ DEBUG_ERR_MSG("snep unregister server(sync call) failed: %s",
+ error->message);
+ g_error_free(error);
+
+ result = NET_NFC_UNKNOWN_ERROR;
+ }
+
+ return result;
+}
+
+net_nfc_error_e net_nfc_client_snep_init(void)
+{
+ GError *error = NULL;
+
+ if (snep_proxy)
+ {
+ DEBUG_CLIENT_MSG("Already initialized");
+
+ return NET_NFC_OK;
+ }
+
+ snep_proxy = net_nfc_gdbus_snep_proxy_new_for_bus_sync(
+ G_BUS_TYPE_SYSTEM,
+ G_DBUS_PROXY_FLAGS_NONE,
+ "org.tizen.NetNfcService",
+ "/org/tizen/NetNfcService/Snep",
+ NULL,
+ &error);
+ if (snep_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not create proxy : %s", error->message);
+ g_error_free(error);
+
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ g_signal_connect(snep_proxy, "snep-event",
+ G_CALLBACK(_snep_event_cb), NULL);
+
+ return NET_NFC_OK;
+}
+
+void net_nfc_client_snep_deinit(void)
+{
+ if (snep_proxy)
+ {
+ g_object_unref(snep_proxy);
+ snep_proxy = NULL;
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "Ecore_X.h"
+
+#include "net_nfc_typedef_internal.h"
+#include "net_nfc_debug_internal.h"
+#include "net_nfc_util_ndef_message.h"
+#include "net_nfc_gdbus.h"
+#include "net_nfc_client.h"
+#include "net_nfc_client_manager.h"
+#include "net_nfc_client_system_handler.h"
+
+typedef struct _PopupFuncData PopupFuncData;
+
+struct _PopupFuncData
+{
+ gpointer callback;
+ gpointer user_data;
+};
+
+static NetNfcGDbusPopup *popup_proxy = NULL;
+static int popup_state = 0;
+
+static void popup_set_active_callback(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data);
+
+static void popup_set_active_callback(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ PopupFuncData *func_data;
+
+ net_nfc_error_e result = NET_NFC_OK;
+ GError *error = NULL;
+
+ net_nfc_client_popup_set_state_callback callback;
+ gpointer data;
+
+ if (net_nfc_gdbus_popup_call_set_finish(
+ NET_NFC_GDBUS_POPUP(source_object),
+ res,
+ &error) == FALSE)
+ {
+
+ result = NET_NFC_UNKNOWN_ERROR;
+
+ DEBUG_ERR_MSG("Can not finish popup_set_active: %s",
+ error->message);
+ g_error_free(error);
+ }
+
+ func_data = user_data;
+ if (func_data == NULL)
+ return;
+
+ if (func_data->callback == NULL)
+ {
+ g_free(func_data);
+ return;
+ }
+
+ callback = (net_nfc_client_popup_set_state_callback)
+ func_data->callback;
+ data = func_data->user_data;
+
+ callback(result, data);
+
+ g_free(func_data);
+}
+
+API net_nfc_error_e net_nfc_client_sys_handler_set_state(int state,
+ net_nfc_client_popup_set_state_callback callback,
+ void *user_data)
+{
+ gboolean active = FALSE;
+ PopupFuncData *func_data;
+ net_nfc_launch_popup_check_e focus_state = CHECK_FOREGROUND;
+
+ if (popup_proxy == NULL )
+ return NET_NFC_NOT_INITIALIZED;
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ func_data = g_new0(PopupFuncData, 1);
+ if (func_data == NULL )
+ return NET_NFC_ALLOC_FAIL;
+
+ func_data->callback = (gpointer)callback;
+ func_data->user_data = user_data;
+
+ if (state == true)
+ active = TRUE;
+
+ net_nfc_gdbus_popup_call_set(popup_proxy,
+ active,
+ focus_state,
+ net_nfc_client_gdbus_get_privilege(),
+ NULL,
+ popup_set_active_callback,
+ func_data);
+
+ return NET_NFC_OK;
+}
+
+API net_nfc_error_e net_nfc_client_sys_handler_set_state_sync(int state)
+{
+ GError *error = NULL;
+ net_nfc_launch_popup_check_e focus_state = CHECK_FOREGROUND;
+
+ if (popup_proxy == NULL)
+ return NET_NFC_NOT_INITIALIZED;
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ if (net_nfc_gdbus_popup_call_set_sync(popup_proxy,
+ (gboolean)state,
+ focus_state,
+ net_nfc_client_gdbus_get_privilege(),
+ NULL,
+ &error) == FALSE)
+ {
+ DEBUG_CLIENT_MSG("can not call SetActive: %s",
+ error->message);
+ g_error_free(error);
+
+ return NET_NFC_IPC_FAIL;
+ }
+
+ return NET_NFC_OK;
+}
+
+API net_nfc_error_e net_nfc_client_sys_handler_set_state_force(int state,
+ net_nfc_client_popup_set_state_callback callback,
+ void *user_data)
+{
+ gboolean active = FALSE;
+ PopupFuncData *func_data;
+ net_nfc_launch_popup_check_e focus_state = NO_CHECK_FOREGROUND;
+
+ if (popup_proxy == NULL)
+ return NET_NFC_NOT_INITIALIZED;
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ func_data = g_new0(PopupFuncData, 1);
+ if (func_data == NULL)
+ return NET_NFC_ALLOC_FAIL;
+
+ func_data->callback = (gpointer)callback;
+ func_data->user_data = user_data;
+
+ if (state == true)
+ active = TRUE;
+
+ net_nfc_gdbus_popup_call_set(popup_proxy,
+ active,
+ focus_state,
+ net_nfc_client_gdbus_get_privilege(),
+ NULL,
+ popup_set_active_callback,
+ func_data);
+
+ return NET_NFC_OK;
+}
+
+API net_nfc_error_e net_nfc_client_sys_handler_set_state_force_sync(int state)
+{
+ GError *error = NULL;
+ net_nfc_launch_popup_check_e focus_state = NO_CHECK_FOREGROUND;
+
+ if (popup_proxy == NULL)
+ return NET_NFC_NOT_INITIALIZED;
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ if (net_nfc_gdbus_popup_call_set_sync(popup_proxy,
+ (gboolean)state,
+ focus_state,
+ net_nfc_client_gdbus_get_privilege(),
+ NULL,
+ &error) == FALSE)
+ {
+ DEBUG_CLIENT_MSG("can not call SetActive: %s",
+ error->message);
+ g_error_free(error);
+
+ return NET_NFC_IPC_FAIL;
+ }
+
+ return NET_NFC_OK;
+}
+
+API net_nfc_error_e net_nfc_client_sys_handler_set_launch_popup_state(
+ int enable)
+{
+ net_nfc_error_e ret;
+
+ popup_state = enable;
+
+ if (enable)
+ {
+ ret = net_nfc_client_sys_handler_set_state_sync(
+ NET_NFC_LAUNCH_APP_SELECT);
+ }
+ else
+ {
+ ret = net_nfc_client_sys_handler_set_state_sync(
+ NET_NFC_NO_LAUNCH_APP_SELECT);
+ }
+
+ return ret;
+}
+
+API net_nfc_error_e net_nfc_client_sys_handler_set_launch_popup_state_force(
+ int enable)
+{
+ net_nfc_error_e ret;
+
+ popup_state = enable;
+
+ if (enable)
+ {
+ ret = net_nfc_client_sys_handler_set_state_force_sync(
+ NET_NFC_LAUNCH_APP_SELECT);
+ }
+ else
+ {
+ ret = net_nfc_client_sys_handler_set_state_force_sync(
+ NET_NFC_NO_LAUNCH_APP_SELECT);
+ }
+
+ return ret;
+}
+
+API net_nfc_error_e net_nfc_client_sys_handler_get_launch_popup_state(
+ int *state)
+{
+ if (state == NULL)
+ return NET_NFC_NULL_PARAMETER;
+#if 1
+ *state = popup_state;
+#else
+ /* TODO : get state from server */
+ GError *error = NULL;
+
+ if (popup_proxy == NULL) {
+ DEBUG_ERR_MSG("popup_proxy is null");
+
+ return NET_NFC_NOT_INITIALIZED;
+ }
+
+ if (net_nfc_gdbus_popup_call_get_sync(popup_proxy,
+ net_nfc_client_gdbus_get_privilege(),
+ state,
+ NULL,
+ &error) == false) {
+ DEBUG_CLIENT_MSG("net_nfc_gdbus_popup_call_get_sync failed: %s",
+ error->message);
+ g_error_free(error);
+
+ return NET_NFC_IPC_FAIL;
+ }
+#endif
+ return NET_NFC_OK;
+}
+
+net_nfc_error_e net_nfc_client_sys_handler_init(void)
+{
+ GError *error = NULL;
+
+ if (popup_proxy)
+ {
+ DEBUG_CLIENT_MSG("Already initialized");
+
+ return NET_NFC_OK;
+ }
+
+ popup_proxy = net_nfc_gdbus_popup_proxy_new_for_bus_sync(
+ G_BUS_TYPE_SYSTEM,
+ G_DBUS_PROXY_FLAGS_NONE,
+ "org.tizen.NetNfcService",
+ "/org/tizen/NetNfcService/Popup",
+ NULL,
+ &error);
+ if (popup_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not create proxy : %s", error->message);
+ g_error_free(error);
+
+ return NET_NFC_OPERATION_FAIL;
+ }
+
+ return NET_NFC_OK;
+}
+
+void net_nfc_client_sys_handler_deinit(void)
+{
+ if (popup_proxy)
+ {
+ g_object_unref(popup_proxy);
+ popup_proxy = NULL;
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include "net_nfc_typedef_internal.h"
+#include "net_nfc_debug_internal.h"
+#include "net_nfc_util_gdbus_internal.h"
+#include "net_nfc_gdbus.h"
+#include "net_nfc_data.h"
+#include "net_nfc_target_info.h"
+#include "net_nfc_client.h"
+#include "net_nfc_client_manager.h"
+#include "net_nfc_client_tag.h"
+#include "net_nfc_client_tag_internal.h"
+
+typedef struct _TagFuncData TagFuncData;
+
+struct _TagFuncData
+{
+ gpointer callback;
+ gpointer user_data;
+};
+
+static NetNfcGDbusTag *tag_proxy = NULL;
+
+static TagFuncData *tag_discovered_func_data = NULL;
+static TagFuncData *tag_detached_func_data = NULL;
+
+static net_nfc_target_info_s *client_target_info = NULL;
+static net_nfc_event_filter_e client_filter = NET_NFC_ALL_ENABLE;
+
+static gboolean tag_check_filter(net_nfc_target_type_e type);
+
+static void tag_get_info_list(guint8 *buffer,
+ gint number_of_keys,
+ net_nfc_tag_info_s **list);
+
+static void tag_get_target_info(guint handle,
+ guint dev_type,
+ gboolean is_ndef_supported,
+ guchar ndef_card_state,
+ guint max_data_size,
+ guint actual_data_size,
+ guint number_of_keys,
+ GVariant *target_info_values,
+ GVariant *raw_data,
+ net_nfc_target_info_s **info);
+
+
+/* async callback */
+static void tag_is_tag_connected(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data);
+
+static void tag_get_current_tag_info(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data);
+
+static void tag_get_current_target_handle(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data);
+
+/* signal callback */
+static void tag_tag_discovered(NetNfcGDbusTag *object,
+ guint arg_handle,
+ gint arg_dev_type,
+ gboolean arg_is_ndef_supported,
+ guchar arg_ndef_card_state,
+ guint arg_max_data_size,
+ guint arg_actual_data_size,
+ guint arg_number_of_keys,
+ GVariant *arg_target_info_values,
+ GVariant *arg_raw_data,
+ gpointer user_data);
+
+static void tag_tag_detached(NetNfcGDbusTag *object,
+ guint arg_handle,
+ gint arg_dev_type,
+ gpointer user_data);
+
+static gboolean tag_check_filter(net_nfc_target_type_e type)
+{
+ net_nfc_event_filter_e converted = NET_NFC_ALL_ENABLE;
+
+ DEBUG_CLIENT_MSG("client filter = %d", client_filter);
+
+ if (type >= NET_NFC_ISO14443_A_PICC &&
+ type <= NET_NFC_MIFARE_DESFIRE_PICC)
+ {
+ converted = NET_NFC_ISO14443A_ENABLE;
+ }
+ else if (type >= NET_NFC_ISO14443_B_PICC &&
+ type <= NET_NFC_ISO14443_BPRIME_PICC)
+ {
+ converted = NET_NFC_ISO14443B_ENABLE;
+ }
+ else if (type == NET_NFC_FELICA_PICC)
+ {
+ converted = NET_NFC_FELICA_ENABLE;
+ }
+ else if (type == NET_NFC_JEWEL_PICC)
+ {
+ converted = NET_NFC_FELICA_ENABLE;
+ }
+ else if (type == NET_NFC_ISO15693_PICC)
+ {
+ converted = NET_NFC_ISO15693_ENABLE;
+ }
+
+ if ((converted & client_filter) == 0)
+ return FALSE;
+
+ return TRUE;
+}
+
+static void tag_get_info_list(guint8 *buffer,
+ gint number_of_keys,
+ net_nfc_tag_info_s **list)
+{
+ net_nfc_tag_info_s *tmp_list = NULL;
+ net_nfc_tag_info_s *current = NULL;
+
+ gint i = 0;
+ gint length;
+
+ guint8 *pos = buffer;
+
+ if (buffer == NULL)
+ return;
+
+ tmp_list = g_new0(net_nfc_tag_info_s, number_of_keys);
+ current = tmp_list;
+
+ while(i < number_of_keys)
+ {
+ gchar *str = NULL;
+ data_h value = NULL;
+
+ /* key */
+ length = *pos; /* first values is length of key */
+ pos++;
+
+ str = g_new0(gchar, length + 1);
+ memcpy(str, pos, length);
+
+ DEBUG_CLIENT_MSG("key = [%s]", str);
+
+ pos += length;
+
+ current->key = str;
+
+ /* value */
+ length = *pos; /* first value is length of value */
+ pos++;
+
+ value = NULL;
+ if (length > 0)
+ {
+ net_nfc_create_data(&value, pos, length);
+ pos += length;
+ }
+
+ current->value = value;
+
+ current++;
+ i++;
+ }
+
+ *list = tmp_list;
+}
+
+static void tag_get_target_info(guint handle,
+ guint dev_type,
+ gboolean is_ndef_supported,
+ guchar ndef_card_state,
+ guint max_data_size,
+ guint actual_data_size,
+ guint number_of_keys,
+ GVariant *target_info_values,
+ GVariant *raw_data,
+ net_nfc_target_info_s **info)
+{
+ guint8 *buffer = NULL;
+ net_nfc_target_info_s *info_data = NULL;
+ net_nfc_tag_info_s *list = NULL;
+
+ if (info == NULL)
+ return;
+
+ net_nfc_util_gdbus_variant_to_buffer(target_info_values,
+ &buffer, NULL);
+
+ tag_get_info_list(buffer, number_of_keys, &list);
+
+ info_data = g_new0(net_nfc_target_info_s, 1);
+
+ info_data->ndefCardState = ndef_card_state;
+ info_data->actualDataSize = actual_data_size;
+ info_data->maxDataSize = max_data_size;
+ info_data->devType = dev_type;
+ info_data->handle = GUINT_TO_POINTER(handle);
+ info_data->is_ndef_supported = (uint8_t)is_ndef_supported;
+ info_data->number_of_keys = number_of_keys;
+ info_data->tag_info_list = list;
+
+ net_nfc_util_gdbus_variant_to_data_s(raw_data,
+ &info_data->raw_data);
+
+ *info = info_data;
+}
+
+static void tag_is_tag_connected(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ TagFuncData *func_data;
+
+ net_nfc_error_e result = NET_NFC_OK;
+ GError *error = NULL;
+
+ gboolean out_is_connected = FALSE;
+ net_nfc_target_type_e out_dev_type;
+
+ net_nfc_client_tag_is_tag_connected_completed callback;
+
+ if (net_nfc_gdbus_tag_call_is_tag_connected_finish(
+ NET_NFC_GDBUS_TAG(source_object),
+ &out_is_connected,
+ (gint32 *)&out_dev_type,
+ res,
+ &error) == FALSE)
+ {
+ result = NET_NFC_UNKNOWN_ERROR;
+
+ DEBUG_ERR_MSG("Can not finish is_tag_connected: %s",
+ error->message);
+ g_error_free(error);
+
+ }
+
+ func_data = user_data;
+ if (func_data == NULL)
+ return;
+
+ if (func_data->callback == NULL)
+ {
+ g_free(func_data);
+ return;
+ }
+
+ if (out_is_connected == FALSE)
+ result = NET_NFC_NOT_CONNECTED;
+
+ callback = (net_nfc_client_tag_is_tag_connected_completed)
+ func_data->callback;
+ callback(result, out_dev_type, func_data->user_data);
+
+ g_free(func_data);
+}
+
+static void tag_get_current_tag_info(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ TagFuncData *func_data;
+
+ net_nfc_error_e result = NET_NFC_OK;
+
+ net_nfc_target_type_e out_dev_type;
+ gboolean out_is_connected = FALSE;
+ gboolean out_is_ndef_supported = FALSE;
+ guchar out_ndef_card_state;
+ guint out_handle;
+ guint out_max_data_size;
+ guint out_actual_data_size;
+ guint out_number_of_keys;
+ GVariant *out_target_info_values = NULL;
+ GVariant *out_raw_data = NULL;
+
+ GError *error = NULL;
+
+ net_nfc_client_tag_get_current_tag_info_completed callback;
+
+ /*FIXME: currently SAVE_TARGET_INFO_IN_CC support only */
+ net_nfc_target_info_s *info_s = NULL;
+
+ if (net_nfc_gdbus_tag_call_get_current_tag_info_finish (
+ NET_NFC_GDBUS_TAG(source_object),
+ &out_is_connected,
+ &out_handle,
+ (gint *)&out_dev_type,
+ &out_is_ndef_supported,
+ &out_ndef_card_state,
+ &out_max_data_size,
+ &out_actual_data_size,
+ &out_number_of_keys,
+ &out_target_info_values,
+ &out_raw_data,
+ res,
+ &error) == FALSE)
+ {
+ result = NET_NFC_UNKNOWN_ERROR;
+
+ DEBUG_ERR_MSG("Can not finish get_current_tag_info: %s",
+ error->message);
+ g_error_free(error);
+ }
+
+ func_data = user_data;
+ if(func_data == NULL)
+ return;
+
+ if (func_data->callback == NULL)
+ {
+ g_free(func_data);
+ return;
+ }
+
+ if (out_is_connected == FALSE)
+ result = NET_NFC_NOT_CONNECTED;
+
+ callback = (net_nfc_client_tag_get_current_tag_info_completed)
+ func_data->callback;
+
+ if (result != NET_NFC_OK)
+ {
+ callback(result, NULL, func_data->user_data);
+ g_free(func_data);
+ return;
+ }
+
+ if (tag_check_filter(out_dev_type) == FALSE)
+ DEBUG_CLIENT_MSG("The detected target is filtered out");
+
+ net_nfc_release_tag_info((net_nfc_target_info_h)client_target_info);
+ client_target_info = NULL;
+
+ tag_get_target_info(out_handle,
+ out_dev_type,
+ out_is_ndef_supported,
+ out_ndef_card_state,
+ out_max_data_size,
+ out_actual_data_size,
+ out_number_of_keys,
+ out_target_info_values,
+ out_raw_data,
+ &info_s);
+
+ client_target_info = info_s;
+
+ callback(result, info_s, func_data->user_data);
+
+ g_free(func_data);
+}
+
+static void tag_get_current_target_handle(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ TagFuncData *func_data;
+
+ net_nfc_target_handle_h handle = NULL;
+ net_nfc_target_type_e out_dev_type;
+
+ gboolean out_is_connected = FALSE;
+ guint out_handle = 0;
+
+ net_nfc_error_e result = NET_NFC_OK;
+ GError *error = NULL;
+
+ net_nfc_client_tag_get_current_target_handle_completed callback;
+
+ if (net_nfc_gdbus_tag_call_get_current_target_handle_finish(
+ NET_NFC_GDBUS_TAG(source_object),
+ &out_is_connected,
+ &out_handle,
+ (gint *)&out_dev_type,
+ res,
+ &error) == FALSE)
+ {
+ result = NET_NFC_UNKNOWN_ERROR;
+
+ DEBUG_ERR_MSG("Can not finish get_current_target_handle: %s",
+ error->message);
+ g_error_free(error);
+ }
+
+ func_data = user_data;
+ if (func_data == NULL)
+ return;
+
+ if (func_data->callback == NULL)
+ {
+ g_free(func_data);
+ return;
+ }
+
+ callback = (net_nfc_client_tag_get_current_target_handle_completed)
+ func_data->callback;
+
+ if (out_is_connected == FALSE)
+ result = NET_NFC_NOT_CONNECTED;
+
+ if (out_handle)
+ handle = GUINT_TO_POINTER(out_handle);
+
+ callback(result, handle, func_data->user_data);
+
+ g_free(func_data);
+}
+
+static void tag_tag_discovered(NetNfcGDbusTag *object,
+ guint arg_handle,
+ gint arg_dev_type,
+ gboolean arg_is_ndef_supported,
+ guchar arg_ndef_card_state,
+ guint arg_max_data_size,
+ guint arg_actual_data_size,
+ guint arg_number_of_keys,
+ GVariant *arg_target_info_values,
+ GVariant *arg_raw_data,
+ gpointer user_data)
+{
+ /*FIXME: currently SAVE_TARGET_INFO_IN_CC support only */
+ net_nfc_target_info_s *info_s = NULL;
+
+ net_nfc_client_tag_tag_discovered callback;
+
+ INFO_MSG(">>> SIGNAL arrived");
+
+ if (tag_discovered_func_data == NULL)
+ return;
+
+ if (tag_discovered_func_data->callback == NULL)
+ return;
+
+ if (tag_check_filter(arg_dev_type) == FALSE)
+ DEBUG_CLIENT_MSG("The detected target is filtered out");
+
+ net_nfc_release_tag_info((net_nfc_target_info_h)client_target_info);
+ client_target_info = NULL;
+
+ tag_get_target_info(arg_handle,
+ arg_dev_type,
+ arg_is_ndef_supported,
+ arg_ndef_card_state,
+ arg_max_data_size,
+ arg_actual_data_size,
+ arg_number_of_keys,
+ arg_target_info_values,
+ arg_raw_data,
+ &info_s);
+
+ client_target_info = info_s;
+
+ callback = (net_nfc_client_tag_tag_discovered)
+ tag_discovered_func_data->callback;
+
+ callback(info_s, tag_discovered_func_data->user_data);
+}
+
+static void tag_tag_detached(NetNfcGDbusTag *object,
+ guint arg_handle,
+ gint arg_dev_type,
+ gpointer user_data)
+{
+ net_nfc_client_tag_tag_detached callback;
+
+ INFO_MSG(">>> SIGNAL arrived");
+
+ if (tag_detached_func_data == NULL)
+ return;
+
+ if (tag_detached_func_data->callback == NULL)
+ return;
+
+ if (tag_check_filter(arg_dev_type) == FALSE)
+ DEBUG_CLIENT_MSG("The detected target is filtered out");
+
+ /*FIXME: currently SAVE_TARGET_INFO_IN_CC support only */
+ net_nfc_release_tag_info((net_nfc_target_info_h)client_target_info);
+ client_target_info = NULL;
+
+ callback = (net_nfc_client_tag_tag_detached)
+ tag_detached_func_data->callback;
+
+ callback(tag_detached_func_data->user_data);
+}
+
+/* internal funcion */
+gboolean net_nfc_client_tag_is_connected(void)
+{
+ if (client_target_info == NULL)
+ return FALSE;
+
+ if (client_target_info->handle == NULL)
+ return FALSE;
+
+ return TRUE;
+}
+
+net_nfc_target_info_s *net_nfc_client_tag_get_client_target_info(void)
+{
+ return client_target_info;
+}
+
+API net_nfc_error_e net_nfc_client_tag_is_tag_connected(
+ net_nfc_client_tag_is_tag_connected_completed callback,
+ void *user_data)
+{
+ TagFuncData *func_data;
+
+ if (tag_proxy == NULL)
+ return NET_NFC_UNKNOWN_ERROR;
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ func_data = g_new0(TagFuncData, 1);
+ if (func_data == NULL)
+ return NET_NFC_UNKNOWN_ERROR;
+
+ func_data->callback = (gpointer)callback;
+ func_data->user_data = user_data;
+
+ net_nfc_gdbus_tag_call_is_tag_connected(tag_proxy,
+ net_nfc_client_gdbus_get_privilege(),
+ NULL,
+ tag_is_tag_connected,
+ func_data);
+
+ return NET_NFC_OK;
+}
+
+API net_nfc_error_e net_nfc_client_tag_is_tag_connected_sync(
+ net_nfc_target_type_e *dev_type)
+{
+ net_nfc_target_type_e out_dev_type;
+
+ gboolean out_is_connected = FALSE;
+
+ GError *error = NULL;
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ if (net_nfc_gdbus_tag_call_is_tag_connected_sync(tag_proxy,
+ net_nfc_client_gdbus_get_privilege(),
+ &out_is_connected,
+ (gint *)&out_dev_type,
+ NULL,
+ &error) == FALSE)
+ {
+ DEBUG_ERR_MSG("Can not get is_tag_connected result: %s",
+ error->message);
+ g_error_free(error);
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ if (dev_type)
+ *dev_type = out_dev_type;
+
+ if (out_is_connected == FALSE)
+ return NET_NFC_NOT_CONNECTED;
+
+ return NET_NFC_OK;
+}
+
+API net_nfc_error_e net_nfc_client_tag_get_current_tag_info(
+ net_nfc_client_tag_get_current_tag_info_completed callback,
+ void *user_data)
+{
+ TagFuncData *func_data;
+
+ if (tag_proxy == NULL)
+ return NET_NFC_UNKNOWN_ERROR;
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ func_data = g_new0(TagFuncData, 1);
+ func_data->callback = (gpointer)callback;
+ func_data->user_data = user_data;
+
+
+ net_nfc_gdbus_tag_call_get_current_tag_info(tag_proxy,
+ net_nfc_client_gdbus_get_privilege(),
+ NULL,
+ tag_get_current_tag_info,
+ func_data);
+
+ return NET_NFC_OK;
+}
+
+API net_nfc_error_e net_nfc_client_tag_get_current_tag_info_sync(
+ net_nfc_target_info_h *info)
+{
+ net_nfc_target_type_e out_dev_type;
+ gboolean out_is_connected = FALSE;
+ gboolean out_is_ndef_supported;
+ guchar out_ndef_card_state;
+ guint out_handle;
+ guint out_max_data_size;
+ guint out_actual_data_size;
+ guint out_number_of_keys;
+ GVariant *out_target_info_values;
+ GVariant *out_raw_data;
+
+ net_nfc_target_info_s *info_s = NULL;
+
+ GError *error = NULL;
+
+ if (tag_proxy == NULL)
+ return NET_NFC_UNKNOWN_ERROR;
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ if (net_nfc_gdbus_tag_call_get_current_tag_info_sync(tag_proxy,
+ net_nfc_client_gdbus_get_privilege(),
+ &out_is_connected,
+ &out_handle,
+ (gint *)&out_dev_type,
+ &out_is_ndef_supported,
+ &out_ndef_card_state,
+ &out_max_data_size,
+ &out_actual_data_size,
+ &out_number_of_keys,
+ &out_target_info_values,
+ &out_raw_data,
+ NULL,
+ &error) == FALSE)
+ {
+ DEBUG_ERR_MSG("Can no get current_tag_info result: %s",
+ error->message);
+
+ g_error_free(error);
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ if (out_is_connected == FALSE)
+ return NET_NFC_NOT_CONNECTED;
+
+ /* TODO : do something */
+ if (info == NULL)
+ return NET_NFC_OK;
+
+ if(tag_check_filter(out_dev_type) == FALSE)
+ DEBUG_CLIENT_MSG("The detected target is filtered out");
+
+ tag_get_target_info(out_handle,
+ out_dev_type,
+ out_is_ndef_supported,
+ out_ndef_card_state,
+ out_max_data_size,
+ out_actual_data_size,
+ out_number_of_keys,
+ out_target_info_values,
+ out_raw_data,
+ &info_s);
+
+ *info = info_s;
+
+ return NET_NFC_OK;
+}
+
+API net_nfc_error_e net_nfc_client_tag_get_current_target_handle(
+ net_nfc_client_tag_get_current_target_handle_completed callback,
+ void *user_data)
+{
+ TagFuncData *func_data;
+
+ if (tag_proxy == NULL)
+ return NET_NFC_UNKNOWN_ERROR;
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ func_data = g_new0(TagFuncData, 1);
+ func_data->callback = (gpointer)callback;
+ func_data->user_data = user_data;
+
+ net_nfc_gdbus_tag_call_get_current_target_handle(tag_proxy,
+ net_nfc_client_gdbus_get_privilege(),
+ NULL,
+ tag_get_current_target_handle,
+ func_data);
+
+ return NET_NFC_OK;
+}
+
+API net_nfc_error_e net_nfc_client_tag_get_current_target_handle_sync(
+ net_nfc_target_handle_h *handle)
+{
+ net_nfc_target_type_e out_dev_type;
+ gboolean out_is_connected = FALSE;
+ guint out_handle;
+ GError *error = NULL;
+
+ if (tag_proxy == NULL)
+ return NET_NFC_UNKNOWN_ERROR;
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ if (net_nfc_gdbus_tag_call_get_current_target_handle_sync(tag_proxy,
+ net_nfc_client_gdbus_get_privilege(),
+ &out_is_connected,
+ &out_handle,
+ (gint *)&out_dev_type,
+ NULL,
+ &error) == FALSE)
+ {
+ DEBUG_ERR_MSG("Can no get current_target_handle result: %s",
+ error->message);
+
+ g_error_free(error);
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ if (out_is_connected == FALSE)
+ return NET_NFC_NOT_CONNECTED;
+
+ if (handle)
+ *handle = GUINT_TO_POINTER(out_handle);
+
+ return NET_NFC_OK;
+}
+
+API void net_nfc_client_tag_set_tag_discovered(
+ net_nfc_client_tag_tag_discovered callback,
+ void *user_data)
+{
+ if (tag_discovered_func_data == NULL)
+ tag_discovered_func_data = g_new0(TagFuncData, 1);
+
+ tag_discovered_func_data->callback = (gpointer) callback;
+ tag_discovered_func_data->user_data = user_data;
+}
+
+API void net_nfc_client_tag_unset_tag_discovered(void)
+{
+ if (tag_discovered_func_data)
+ {
+ g_free(tag_discovered_func_data);
+ tag_discovered_func_data = NULL;
+ }
+
+}
+
+API void net_nfc_client_tag_set_tag_detached(
+ net_nfc_client_tag_tag_detached callback,
+ void *user_data)
+{
+ if (tag_detached_func_data == NULL)
+ tag_detached_func_data = g_new0(TagFuncData, 1);
+
+ tag_detached_func_data->callback = (gpointer) callback;
+ tag_detached_func_data->user_data = user_data;
+}
+
+API void net_nfc_client_tag_unset_tag_detached(void)
+{
+ if (tag_detached_func_data)
+ {
+ g_free(tag_detached_func_data);
+ tag_detached_func_data = NULL;
+ }
+}
+
+API void net_nfc_client_tag_set_filter(net_nfc_event_filter_e filter)
+{
+ client_filter = filter;
+}
+
+API net_nfc_event_filter_e net_nfc_client_tag_get_filter(void)
+{
+ return client_filter;
+}
+
+net_nfc_error_e net_nfc_client_tag_init(void)
+{
+ GError *error = NULL;
+
+ if (tag_proxy)
+ {
+ DEBUG_CLIENT_MSG("Alrady initialized");
+ return NET_NFC_OK;
+ }
+
+ if (client_target_info)
+ {
+ net_nfc_release_tag_info(
+ (net_nfc_target_info_h)client_target_info);
+ client_target_info = NULL;
+ }
+
+ client_filter = NET_NFC_ALL_ENABLE;
+
+ tag_proxy = net_nfc_gdbus_tag_proxy_new_for_bus_sync(
+ G_BUS_TYPE_SYSTEM,
+ G_DBUS_PROXY_FLAGS_NONE,
+ "org.tizen.NetNfcService",
+ "/org/tizen/NetNfcService/Tag",
+ NULL,
+ &error);
+ if (tag_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not create proxy : %s", error->message);
+ g_error_free(error);
+
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ g_signal_connect(tag_proxy, "tag-discovered",
+ G_CALLBACK(tag_tag_discovered), NULL);
+
+ g_signal_connect(tag_proxy, "tag-detached",
+ G_CALLBACK(tag_tag_detached), NULL);
+
+ return NET_NFC_OK;
+}
+
+void net_nfc_client_tag_deinit(void)
+{
+ if (tag_proxy)
+ {
+ g_object_unref(tag_proxy);
+ tag_proxy = NULL;
+ }
+
+ if (tag_discovered_func_data)
+ {
+ g_free(tag_discovered_func_data);
+ tag_discovered_func_data = NULL;
+ }
+
+ if (tag_detached_func_data)
+ {
+ g_free(tag_detached_func_data);
+ tag_detached_func_data = NULL;
+ }
+
+ net_nfc_release_tag_info((net_nfc_target_info_h)client_target_info);
+ client_target_info = NULL;
+
+ client_filter = NET_NFC_ALL_ENABLE;
+}
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <glib.h>
+#include <string.h>
+
+#include "net_nfc_client_tag_felica.h"
+#include "net_nfc_client_tag_internal.h"
+
+#include "net_nfc_typedef_internal.h"
+#include "net_nfc_debug_internal.h"
+#include "net_nfc_util_internal.h"
+#include "net_nfc_target_info.h"
+
+#define FELICA_CMD_POLL 0x00
+#define FELICA_CMD_REQ_SERVICE 0x02
+#define FELICA_CMD_REQ_RESPONSE 0x04
+#define FELICA_CMD_READ_WITHOUT_ENC 0x06
+#define FELICA_CMD_WRITE_WITHOUT_ENC 0x08
+#define FELICA_CMD_REQ_SYSTEM_CODE 0x0C
+#define FELICA_TAG_KEY "IDm"
+
+API net_nfc_error_e net_nfc_client_felica_poll(net_nfc_target_handle_h handle,
+ net_nfc_felica_poll_request_code_e req_code,
+ uint8_t time_slote,
+ nfc_transceive_data_callback callback,
+ void *user_data)
+{
+ net_nfc_target_info_s* target_info = NULL;
+
+ data_s rawdata;
+
+ uint8_t send_buffer[6] = { 0x00, };
+
+ if (handle == NULL)
+ return NET_NFC_NULL_PARAMETER;
+
+ if(net_nfc_client_tag_is_connected() == FALSE)
+ return NET_NFC_OPERATION_FAIL;
+
+ target_info = net_nfc_client_tag_get_client_target_info();
+ if (target_info == NULL)
+ return NET_NFC_NO_DATA_FOUND;
+
+ if (target_info->devType != NET_NFC_FELICA_PICC)
+ {
+ DEBUG_CLIENT_MSG("only felica tag is available");
+ return NET_NFC_NOT_ALLOWED_OPERATION;
+ }
+
+ /* total size of requet command */
+ send_buffer[0] = 0x06;
+ send_buffer[1] = FELICA_CMD_POLL;
+
+ /* use wild card for system code */
+ send_buffer[2] = 0xff;
+ send_buffer[3] = 0xff;
+
+ send_buffer[4] = req_code;
+ send_buffer[5] = time_slote;
+
+ DEBUG_MSG_PRINT_BUFFER(send_buffer, 6);
+
+ rawdata.buffer = send_buffer;
+ rawdata.length = 6;
+
+ return net_nfc_client_transceive_data(handle,
+ (data_h)&rawdata,
+ callback,
+ user_data);
+}
+
+API net_nfc_error_e net_nfc_client_felica_request_service(
+ net_nfc_target_handle_h handle,
+ uint8_t number_of_area_service,
+ uint16_t area_service_list[],
+ uint8_t number_of_services,
+ nfc_transceive_data_callback callback,
+ void *user_data)
+{
+ net_nfc_target_info_s* target_info = NULL;
+
+ data_s rawdata;
+
+ data_h IDm = NULL;
+
+ uint32_t send_buffer_length;
+ uint8_t* send_buffer = NULL;
+ uint8_t* temp = NULL;
+
+ int i;
+
+ if (handle == NULL || area_service_list == NULL)
+ return NET_NFC_NULL_PARAMETER;
+
+ if(net_nfc_client_tag_is_connected() == FALSE)
+ return NET_NFC_OPERATION_FAIL;
+
+ target_info = net_nfc_client_tag_get_client_target_info();
+ if (target_info == NULL)
+ return NET_NFC_NO_DATA_FOUND;
+
+ if (target_info->devType != NET_NFC_FELICA_PICC)
+ {
+ DEBUG_CLIENT_MSG("only Jewel tag is available");
+ return NET_NFC_NOT_ALLOWED_OPERATION;
+ }
+
+ if (net_nfc_get_tag_info_value((net_nfc_target_info_h)target_info,
+ FELICA_TAG_KEY,
+ &IDm) != NET_NFC_OK)
+ {
+ return NET_NFC_NO_DATA_FOUND;
+ }
+
+ if (((data_s*)IDm)->length != 8)
+ return NET_NFC_OUT_OF_BOUND;
+
+ if (number_of_area_service > 32)
+ return NET_NFC_OUT_OF_BOUND;
+
+ /* size + cmd + UID + number of service service count + service list */
+ send_buffer_length = 1 + 1 + 8 + 1 + (2 * number_of_services);
+
+ _net_nfc_util_alloc_mem(send_buffer, send_buffer_length * sizeof(uint8_t));
+ if (send_buffer == NULL)
+ return NET_NFC_ALLOC_FAIL;
+
+ temp = send_buffer;
+
+ /* set cmd length */
+ *send_buffer = send_buffer_length;
+ send_buffer++;
+
+ /* set cmd */
+ *send_buffer = FELICA_CMD_REQ_SERVICE;
+ send_buffer++;
+
+ /* set IDm */
+ memcpy(send_buffer, ((data_s*)IDm)->buffer, ((data_s*)IDm)->length);
+ send_buffer = send_buffer + ((data_s*)IDm)->length;
+
+ /* set the number of service codes */
+ *send_buffer = number_of_area_service;
+ send_buffer++;
+
+ for (i = 0; i < number_of_services; i++)
+ {
+ memcpy(send_buffer, &area_service_list[i], sizeof(uint16_t));
+ send_buffer = send_buffer + 2;
+ }
+
+ DEBUG_MSG_PRINT_BUFFER(temp, send_buffer_length);
+
+ rawdata.buffer = send_buffer;
+ rawdata.length = send_buffer_length;
+
+ net_nfc_error_e result = NET_NFC_OK;
+ result = net_nfc_client_transceive_data(handle,
+ (data_h)&rawdata,
+ callback,
+ user_data);
+
+ if (temp != NULL)
+ _net_nfc_util_free_mem(temp);
+
+ return result;
+}
+
+API net_nfc_error_e net_nfc_client_felica_request_response(
+ net_nfc_target_handle_h handle,
+ nfc_transceive_data_callback callback,
+ void *user_data)
+{
+ net_nfc_target_info_s* target_info = NULL;
+
+ data_s rawdata;
+
+ data_h IDm = NULL;
+
+ uint8_t send_buffer[10] = { 0x00, };
+
+ if (handle == NULL)
+ return NET_NFC_NULL_PARAMETER;
+
+ if(net_nfc_client_tag_is_connected() == FALSE)
+ return NET_NFC_OPERATION_FAIL;
+
+ target_info = net_nfc_client_tag_get_client_target_info();
+ if (target_info == NULL)
+ return NET_NFC_NO_DATA_FOUND;
+
+ if (target_info->devType != NET_NFC_FELICA_PICC)
+ {
+ DEBUG_CLIENT_MSG("only Jewel tag is available");
+ return NET_NFC_NOT_ALLOWED_OPERATION;
+ }
+
+ if (net_nfc_get_tag_info_value((net_nfc_target_info_h)target_info,
+ FELICA_TAG_KEY,
+ &IDm) != NET_NFC_OK)
+ {
+ return NET_NFC_NO_DATA_FOUND;
+ }
+
+ if (((data_s*)IDm)->length != 8)
+ return NET_NFC_OUT_OF_BOUND;
+
+ send_buffer[0] = 0xA;
+ send_buffer[1] = FELICA_CMD_REQ_RESPONSE;
+
+ memcpy(send_buffer + 2,
+ ((data_s*)IDm)->buffer,
+ ((data_s*)IDm)->length);
+
+ DEBUG_MSG_PRINT_BUFFER(send_buffer, 10);
+
+ rawdata.buffer = send_buffer;
+ rawdata.length = 10;
+
+ return net_nfc_client_transceive_data(handle,
+ (data_h)&rawdata,
+ callback,
+ user_data);
+}
+
+API net_nfc_error_e net_nfc_client_felica_read_without_encryption(
+ net_nfc_target_handle_h handle,
+ uint8_t number_of_services,
+ uint16_t service_list[],
+ uint8_t number_of_blocks,
+ uint8_t block_list[],
+ nfc_transceive_data_callback callback,
+ void *user_data)
+{
+ net_nfc_target_info_s* target_info = NULL;
+
+ data_s rawdata;
+
+ data_h IDm = NULL;
+
+ uint32_t send_buffer_length;
+ uint8_t* send_buffer = NULL;
+ uint8_t* temp = NULL;
+
+ int i;
+
+ if (handle == NULL || service_list == NULL || block_list == NULL)
+ return NET_NFC_NULL_PARAMETER;
+
+ if(net_nfc_client_tag_is_connected() == FALSE)
+ return NET_NFC_OPERATION_FAIL;
+
+ target_info = net_nfc_client_tag_get_client_target_info();
+ if (target_info == NULL)
+ return NET_NFC_NO_DATA_FOUND;
+
+ if (target_info->devType != NET_NFC_FELICA_PICC)
+ {
+ DEBUG_CLIENT_MSG("only Jewel tag is available");
+ return NET_NFC_NOT_ALLOWED_OPERATION;
+ }
+
+ if (net_nfc_get_tag_info_value((net_nfc_target_info_h)target_info,
+ FELICA_TAG_KEY,
+ &IDm) != NET_NFC_OK)
+ {
+ return NET_NFC_NO_DATA_FOUND;
+ }
+
+ if (((data_s*)IDm)->length != 8)
+ return NET_NFC_OUT_OF_BOUND;
+
+ if (number_of_services > 16)
+ return NET_NFC_OUT_OF_BOUND;
+
+ send_buffer_length = 1 + 1 + 8 + 1 + (2 * number_of_services)
+ + 1 + number_of_blocks;
+
+ _net_nfc_util_alloc_mem(send_buffer,
+ send_buffer_length * sizeof(uint8_t));
+ if (send_buffer == NULL)
+ return NET_NFC_ALLOC_FAIL;
+
+ temp = send_buffer;
+
+ *send_buffer = send_buffer_length;
+ send_buffer++;
+
+ *send_buffer = FELICA_CMD_READ_WITHOUT_ENC;
+ send_buffer++;
+
+ memcpy(send_buffer, ((data_s*)IDm)->buffer, ((data_s*)IDm)->length);
+ send_buffer = send_buffer + ((data_s*)IDm)->length;
+
+ *send_buffer = number_of_services;
+ send_buffer++;
+
+ for (i = 0; i < number_of_services; i++)
+ {
+ memcpy(send_buffer, &service_list[i], sizeof(uint16_t));
+ send_buffer = send_buffer + 2;
+ }
+
+ *send_buffer = number_of_blocks;
+ send_buffer++;
+
+ for (i = 0; i < number_of_blocks; i++)
+ {
+ memcpy(send_buffer, &block_list[i], sizeof(uint8_t));
+ send_buffer++;
+ }
+
+ DEBUG_MSG_PRINT_BUFFER(temp, send_buffer_length);
+
+ rawdata.buffer = temp;
+ rawdata.length = send_buffer_length;
+
+ net_nfc_error_e result = NET_NFC_OK;
+ result = net_nfc_client_transceive_data(handle,
+ (data_h)&rawdata,
+ callback,
+ user_data);
+
+ if (temp != NULL)
+ _net_nfc_util_free_mem(temp);
+
+ return result;
+}
+
+API net_nfc_error_e net_nfc_client_felica_write_without_encryption(
+ net_nfc_target_handle_h handle,
+ uint8_t number_of_services,
+ uint16_t service_list[],
+ uint8_t number_of_blocks,
+ uint8_t block_list[],
+ data_h data,
+ nfc_transceive_data_callback callback,
+ void *user_data)
+{
+ net_nfc_target_info_s* target_info = NULL;
+
+ data_s rawdata;
+
+ data_h IDm = NULL;
+
+ uint32_t send_buffer_length;
+ uint8_t* send_buffer = NULL;
+ uint8_t* temp = NULL;
+
+ int i;
+
+ if (handle == NULL || service_list == NULL ||
+ block_list == NULL || data == NULL)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ if(net_nfc_client_tag_is_connected() == FALSE)
+ return NET_NFC_OPERATION_FAIL;
+ target_info = net_nfc_client_tag_get_client_target_info();
+ if (target_info == NULL)
+ return NET_NFC_NO_DATA_FOUND;
+
+ if (target_info->devType != NET_NFC_FELICA_PICC)
+ {
+ DEBUG_CLIENT_MSG("only Jewel tag is available");
+ return NET_NFC_NOT_ALLOWED_OPERATION;
+ }
+
+ if (net_nfc_get_tag_info_value((net_nfc_target_info_h)target_info,
+ FELICA_TAG_KEY,
+ &IDm) != NET_NFC_OK)
+ {
+ return NET_NFC_NO_DATA_FOUND;
+ }
+
+ if (((data_s*)IDm)->length != 8)
+ return NET_NFC_OUT_OF_BOUND;
+
+ if (number_of_services > 16)
+ return NET_NFC_OUT_OF_BOUND;
+
+ if (((data_s*)data)->length > 16 * number_of_blocks)
+ return NET_NFC_OUT_OF_BOUND;
+
+ send_buffer_length = 1 + 1 + 8 + 1 + (2 * number_of_services)
+ + 1 + number_of_blocks
+ +((data_s*)data)->length;
+
+ _net_nfc_util_alloc_mem(send_buffer,
+ send_buffer_length * sizeof(uint8_t));
+ if (send_buffer == NULL)
+ return NET_NFC_ALLOC_FAIL;
+
+ temp = send_buffer;
+
+ *send_buffer = send_buffer_length;
+ send_buffer++;
+
+ *send_buffer = FELICA_CMD_WRITE_WITHOUT_ENC;
+ send_buffer++;
+
+ memcpy(send_buffer, ((data_s*)IDm)->buffer, ((data_s*)IDm)->length);
+ send_buffer = send_buffer + ((data_s*)IDm)->length;
+
+ *send_buffer = number_of_services;
+ send_buffer++;
+
+ for (i = 0; i < number_of_services; i++)
+ {
+ memcpy(send_buffer, &service_list[i], sizeof(uint16_t));
+ send_buffer = send_buffer + 2;
+ }
+
+ *send_buffer = number_of_blocks;
+ send_buffer++;
+
+ for (i = 0; i < number_of_blocks; i++)
+ {
+ memcpy(send_buffer, &block_list[i], sizeof(uint8_t));
+ send_buffer++;
+ }
+
+ memcpy(send_buffer, ((data_s*)data)->buffer, ((data_s*)data)->length);
+
+ DEBUG_MSG_PRINT_BUFFER(temp, send_buffer_length);
+
+ rawdata.buffer = temp;
+ rawdata.length = send_buffer_length;
+
+ net_nfc_error_e result = NET_NFC_OK;
+
+ result = net_nfc_client_transceive_data(handle,
+ (data_h)&rawdata,
+ callback,
+ user_data);
+
+ if (temp != NULL)
+ _net_nfc_util_free_mem(temp);
+
+ return result;
+}
+
+API net_nfc_error_e net_nfc_client_felica_request_system_code(
+ net_nfc_target_handle_h handle,
+ nfc_transceive_data_callback callback,
+ void *user_data)
+{
+ net_nfc_target_info_s* target_info = NULL;
+
+ data_s rawdata;
+
+ data_h IDm = NULL;
+
+ uint8_t send_buffer[10] = { 0x00, };
+
+ if (handle == NULL)
+ return NET_NFC_NULL_PARAMETER;
+
+ if(net_nfc_client_tag_is_connected() == FALSE)
+ return NET_NFC_OPERATION_FAIL;
+
+ target_info = net_nfc_client_tag_get_client_target_info();
+ if (target_info == NULL)
+ return NET_NFC_NO_DATA_FOUND;
+
+ if (target_info->devType != NET_NFC_FELICA_PICC)
+ {
+ DEBUG_CLIENT_MSG("only Jewel tag is available");
+ return NET_NFC_NOT_ALLOWED_OPERATION;
+ }
+
+ if (net_nfc_get_tag_info_value((net_nfc_target_info_h)target_info,
+ FELICA_TAG_KEY,
+ &IDm) != NET_NFC_OK)
+ {
+ return NET_NFC_NO_DATA_FOUND;
+ }
+
+ if (((data_s*)IDm)->length != 8)
+ return NET_NFC_OUT_OF_BOUND;
+
+
+ send_buffer[0] = 0xA;
+ send_buffer[1] = FELICA_CMD_REQ_SYSTEM_CODE;
+
+ memcpy(send_buffer + 2,
+ ((data_s *)IDm)->buffer,
+ ((data_s *)IDm)->length);
+
+ DEBUG_MSG_PRINT_BUFFER(send_buffer, 10);
+
+ rawdata.buffer = send_buffer;
+ rawdata.length = 10;
+
+ return net_nfc_client_transceive_data(handle,
+ (data_h)&rawdata,
+ callback,
+ user_data);
+}
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_CLIENT_TAG_INTERNAL_H__
+#define __NET_NFC_CLIENT_TAG_INTERNAL_H__
+
+#include <glib.h>
+
+#include "net_nfc_typedef_internal.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+gboolean net_nfc_client_tag_is_connected(void);
+
+net_nfc_target_info_s *net_nfc_client_tag_get_client_target_info(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif //__NET_NFC_CLIENT_TAG_INTERNAL_H__
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <glib.h>
+#include <string.h>
+
+#include "net_nfc_client_tag_jewel.h"
+#include "net_nfc_client_tag_internal.h"
+
+#include "net_nfc_typedef_internal.h"
+#include "net_nfc_debug_internal.h"
+#include "net_nfc_util_internal.h"
+#include "net_nfc_target_info.h"
+
+
+#define JEWEL_CMD_REQA 0x26
+#define JEWEL_CMD_WUPA 0x52
+#define JEWEL_CMD_RID 0x78
+#define JEWEL_CMD_RALL 0x00
+#define JEWEL_CMD_READ 0x01
+#define JEWEL_CMD_WRITE_E 0x53
+#define JEWEL_CMD_WRITE_NE 0x1A
+#define JEWEL_TAG_KEY "UID"
+
+API net_nfc_error_e net_nfc_client_jewel_read_id(net_nfc_target_handle_h handle,
+ nfc_transceive_data_callback callback,
+ void *user_data)
+{
+ net_nfc_target_info_s* target_info = NULL;
+
+ data_s rawdata;
+
+ uint8_t send_buffer[9] = {0x00, };
+
+ if(handle == NULL)
+ return NET_NFC_NULL_PARAMETER;
+
+ if(net_nfc_client_tag_is_connected() == FALSE)
+ return NET_NFC_OPERATION_FAIL;
+
+ target_info = net_nfc_client_tag_get_client_target_info();
+ if (target_info == NULL)
+ return NET_NFC_NO_DATA_FOUND;
+
+ if(target_info->devType != NET_NFC_JEWEL_PICC)
+ {
+ DEBUG_CLIENT_MSG("only Jewel tag is available");
+ return NET_NFC_NOT_ALLOWED_OPERATION;
+ }
+
+ send_buffer[0] = JEWEL_CMD_RID;
+
+ net_nfc_util_compute_CRC(CRC_B, send_buffer, 9);
+
+ DEBUG_MSG_PRINT_BUFFER(send_buffer, 9);
+
+ rawdata.buffer = send_buffer;
+ rawdata.length = 9;
+
+ return net_nfc_client_transceive_data(handle,
+ (data_h)&rawdata,
+ callback,
+ user_data);
+}
+
+API net_nfc_error_e net_nfc_client_jewel_read_byte(net_nfc_target_handle_h handle,
+ uint8_t block,
+ uint8_t byte,
+ nfc_transceive_data_callback callback,
+ void *user_data)
+{
+ net_nfc_target_info_s* target_info = NULL;
+
+ data_s rawdata;
+
+ data_h UID = NULL;
+
+ uint8_t send_buffer[9] = {0x00, };
+
+ if(handle == NULL)
+ return NET_NFC_NULL_PARAMETER;
+
+ if(block > 0xE || byte > 0x7 )
+ return NET_NFC_OUT_OF_BOUND;
+
+ if(net_nfc_client_tag_is_connected() == FALSE)
+ return NET_NFC_OPERATION_FAIL;
+
+ target_info = net_nfc_client_tag_get_client_target_info();
+ if (target_info == NULL)
+ return NET_NFC_NO_DATA_FOUND;
+
+ if(target_info->devType != NET_NFC_JEWEL_PICC)
+ {
+ DEBUG_CLIENT_MSG("only Jewel tag is available");
+ return NET_NFC_NOT_ALLOWED_OPERATION;
+ }
+
+ if(net_nfc_get_tag_info_value((net_nfc_target_info_h)target_info,
+ JEWEL_TAG_KEY,
+ &UID) != NET_NFC_OK)
+ {
+ return NET_NFC_NO_DATA_FOUND;
+ }
+
+
+ if(((data_s*)UID)->length != 4)
+ return NET_NFC_OUT_OF_BOUND;
+
+ /* command */
+ send_buffer[0] = JEWEL_CMD_READ;
+
+ /* addr */
+ send_buffer[1] = (((block << 3) & 0x78) | (byte & 0x7));
+
+ /* data */
+ send_buffer[2] = 0x00;
+
+ /* UID0 ~ 3 */
+ memcpy(&(send_buffer[3]),
+ ((data_s*)UID)->buffer,
+ ((data_s*)UID)->length);
+
+ net_nfc_util_compute_CRC(CRC_B, send_buffer, 9);
+
+ DEBUG_MSG_PRINT_BUFFER(send_buffer, 9);
+
+ rawdata.buffer = send_buffer;
+ rawdata.length = 9;
+
+ return net_nfc_client_transceive_data(handle,
+ (data_h)&rawdata,
+ callback,
+ user_data);
+}
+
+API net_nfc_error_e net_nfc_client_jewel_read_all(net_nfc_target_handle_h handle,
+ nfc_transceive_data_callback callback,
+ void *user_data)
+{
+ net_nfc_target_info_s* target_info = NULL;
+
+ data_s rawdata;
+
+ data_h UID = NULL;
+
+ uint8_t send_buffer[9] = {0x00, };
+
+ if(handle == NULL )
+ return NET_NFC_NULL_PARAMETER;
+
+ if(net_nfc_client_tag_is_connected() == FALSE)
+ return NET_NFC_OPERATION_FAIL;
+
+ target_info = net_nfc_client_tag_get_client_target_info();
+ if (target_info == NULL)
+ return NET_NFC_NO_DATA_FOUND;
+
+ if(target_info->devType != NET_NFC_JEWEL_PICC)
+ {
+ DEBUG_CLIENT_MSG("only Jewel tag is available");
+ return NET_NFC_NOT_ALLOWED_OPERATION;
+ }
+
+ if(net_nfc_get_tag_info_value((net_nfc_target_info_h)target_info,
+ JEWEL_TAG_KEY,
+ &UID) != NET_NFC_OK)
+ {
+ return NET_NFC_NO_DATA_FOUND;
+ }
+
+ if(((data_s*)UID)->length != 4)
+ return NET_NFC_OUT_OF_BOUND;
+
+ /* command */
+ send_buffer[0] = JEWEL_CMD_RALL;
+
+ /* addr */
+ send_buffer[1] = 0x00;
+
+ /* data */
+ send_buffer[2] = 0x00;
+
+ /* UID0 ~ 3 */
+ memcpy(&(send_buffer[3]),
+ ((data_s*)UID)->buffer,
+ ((data_s*)UID)->length);
+
+ net_nfc_util_compute_CRC(CRC_B, send_buffer, 9);
+
+ DEBUG_MSG_PRINT_BUFFER(send_buffer, 9);
+
+ rawdata.buffer = send_buffer;
+ rawdata.length = 9;
+
+ return net_nfc_client_transceive_data(handle,
+ (data_h)&rawdata,
+ callback,
+ user_data);
+}
+
+API net_nfc_error_e net_nfc_client_jewel_write_with_erase(
+ net_nfc_target_handle_h handle,
+ uint8_t block,
+ uint8_t byte,
+ uint8_t data,
+ nfc_transceive_callback callback,
+ void *user_data)
+{
+ net_nfc_target_info_s* target_info = NULL;
+
+ data_s rawdata;
+
+ data_h UID = NULL;
+
+ uint8_t send_buffer[9] = {0x00, };
+
+ if(handle == NULL)
+ return NET_NFC_NULL_PARAMETER;
+
+ if(block > 0xE || byte > 0x7 )
+ return NET_NFC_OUT_OF_BOUND;
+
+ if(net_nfc_client_tag_is_connected() == FALSE)
+ return NET_NFC_OPERATION_FAIL;
+
+
+ target_info = net_nfc_client_tag_get_client_target_info();
+ if (target_info == NULL)
+ return NET_NFC_NO_DATA_FOUND;
+
+ if(net_nfc_get_tag_info_value((net_nfc_target_info_h)target_info,
+ JEWEL_TAG_KEY,
+ &UID) != NET_NFC_OK)
+ {
+ return NET_NFC_NO_DATA_FOUND;
+ }
+
+ if(((data_s*)UID)->length != 4)
+ return NET_NFC_OUT_OF_BOUND;
+
+ /* command */
+ send_buffer[0] = JEWEL_CMD_WRITE_E;
+
+ /* addr */
+ send_buffer[1] = (((block << 3) & 0x78) | (byte & 0x7));
+
+ /* data */
+ send_buffer[2] = data;
+
+ /* UID0 ~ 3 */
+ memcpy(&(send_buffer[3]),
+ ((data_s*)UID)->buffer,
+ ((data_s*)UID)->length);
+
+ net_nfc_util_compute_CRC(CRC_B, send_buffer, 9);
+
+ DEBUG_MSG_PRINT_BUFFER(send_buffer, 9);
+
+ rawdata.buffer = send_buffer;
+ rawdata.length = 9;
+
+ return net_nfc_client_transceive(handle,
+ (data_h)&rawdata,
+ callback,
+ user_data);
+
+}
+
+API net_nfc_error_e net_nfc_client_jewel_write_with_no_erase(
+ net_nfc_target_handle_h handle,
+ uint8_t block,
+ uint8_t byte,
+ uint8_t data,
+ nfc_transceive_callback callback,
+ void *user_data)
+{
+ net_nfc_target_info_s* target_info = NULL;
+
+ data_s rawdata;
+
+ data_h UID = NULL;
+
+ uint8_t send_buffer[9] = {0x00, };
+
+ if(handle == NULL)
+ return NET_NFC_NULL_PARAMETER;
+
+ if(block > 0xE || byte > 0x7 )
+ return NET_NFC_OUT_OF_BOUND;
+
+ if(net_nfc_client_tag_is_connected() == FALSE)
+ return NET_NFC_OPERATION_FAIL;
+
+ target_info = net_nfc_client_tag_get_client_target_info();
+ if (target_info == NULL)
+ return NET_NFC_NO_DATA_FOUND;
+
+ if(target_info->devType != NET_NFC_JEWEL_PICC)
+ {
+ DEBUG_CLIENT_MSG("only Jewel tag is available");
+ return NET_NFC_NOT_ALLOWED_OPERATION;
+ }
+
+ if(net_nfc_get_tag_info_value((net_nfc_target_info_h)target_info,
+ JEWEL_TAG_KEY,
+ &UID) != NET_NFC_OK)
+ {
+ return NET_NFC_NO_DATA_FOUND;
+ }
+
+ if(((data_s*)UID)->length != 4)
+ return NET_NFC_OUT_OF_BOUND;
+
+ /* command */
+ send_buffer[0] = JEWEL_CMD_WRITE_NE;
+
+ /* addr */
+ send_buffer[1] = (((block << 3) & 0x78) | (byte & 0x7));
+
+ /* data */
+ send_buffer[2] = data;
+
+ /* UID0 ~ 3 */
+ memcpy(&(send_buffer[3]),
+ ((data_s*)UID)->buffer,
+ ((data_s*)UID)->length);
+
+ net_nfc_util_compute_CRC(CRC_B, send_buffer, 9);
+
+ DEBUG_MSG_PRINT_BUFFER(send_buffer, 9);
+
+ rawdata.buffer = send_buffer;
+ rawdata.length = 9;
+
+ return net_nfc_client_transceive(handle,
+ (data_h)&rawdata,
+ callback,
+ user_data);
+}
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include <glib.h>
+#include <string.h>
+
+#include "net_nfc_client_transceive.h"
+#include "net_nfc_client_tag_internal.h"
+#include "net_nfc_client_tag_mifare.h"
+#include "net_nfc_data.h"
+#include "net_nfc_typedef_internal.h"
+#include "net_nfc_debug_internal.h"
+#include "net_nfc_target_info.h"
+#include "net_nfc_util_internal.h"
+
+#define MIFARE_CMD_RAW 0x00U
+#define MIFARE_CMD_AUTH_A 0x60U /**< authenticate with key A */
+#define MIFARE_CMD_AUTH_B 0x61U /**< authenticate with key B */
+#define MIFARE_CMD_READ 0x30U /**< read 16 bytes */
+#define MIFARE_CMD_WRITE_BLOCK 0xA0U /**< write 16 bytes */
+#define MIFARE_CMD_WRITE_PAGE 0xA2U /**< write 4 bytes */
+#define MIFARE_CMD_INCREMENT 0xC1U /**< Increment. */
+#define MIFARE_CMD_DECREMENT 0xC0U /**< Decrement. */
+#define MIFARE_CMD_TRANSFER 0xB0U /**< Tranfer. */
+#define MIFARE_CMD_RESTORE 0xC2U /**< Restore. */
+#define MIFARE_TAG_KEY "UID"
+
+#define MIFARE_CMD_READ_SECTOR 0x38U /* read sector */
+#define MIFARE_CMD_WRITE_SECTOR 0xA8U /* write sector */
+
+static uint8_t default_key[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
+static uint8_t mad_key[6] = { 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5 };
+static uint8_t net_nfc_forum_key[6] = { 0xD3, 0xF7, 0xD3, 0xF7, 0xD3, 0xF7 };
+
+#define MIFARE_BLOCK_4 4
+#define MIFARE_BLOCK_16 16
+
+#define MIFARE_MINI_SECTORS 5
+#define MIFARE_1K_SECTORS 16
+#define MIFARE_4K_SECTORS 40
+
+#define MIFARE_BLOCK_SIZE 16 /* 1 block is 16 byte */
+#define MIFARE_PAGE_SIZE 4 /* 1 page is 4 byte */
+
+
+API net_nfc_error_e net_nfc_client_mifare_authenticate_with_keyA(
+ net_nfc_target_handle_h handle,
+ uint8_t sector,
+ data_h auth_key,
+ void *callback,
+ void *user_data)
+{
+ net_nfc_target_info_s* target_info = NULL;
+
+ data_s *key;
+ data_s rawdata;
+
+ data_h UID = NULL;
+
+ uint8_t* send_buffer = NULL;
+ uint8_t* temp = NULL;
+
+ int send_buffer_length = 0;
+
+ uint8_t sector_to_block = 0;
+
+
+ if (handle == NULL || auth_key == NULL)
+ return NET_NFC_NULL_PARAMETER;
+
+ if (net_nfc_client_tag_is_connected() == FALSE)
+ return NET_NFC_OPERATION_FAIL;
+
+ key = (data_s *)auth_key;
+
+ if (key->length != 6)
+ return NET_NFC_OUT_OF_BOUND;
+
+ target_info = net_nfc_client_tag_get_client_target_info();
+
+ if (target_info)
+ {
+ if (target_info->devType < NET_NFC_MIFARE_MINI_PICC ||
+ target_info->devType > NET_NFC_MIFARE_4K_PICC)
+ {
+ DEBUG_CLIENT_MSG("not a MIFARE Classic TAG");
+ return NET_NFC_NOT_SUPPORTED;
+ }
+ }
+
+ if (net_nfc_get_tag_info_value((net_nfc_target_info_h)target_info,
+ MIFARE_TAG_KEY,
+ &UID) != NET_NFC_OK)
+ {
+ return NET_NFC_NO_DATA_FOUND;
+ }
+
+ switch (target_info->devType)
+ {
+ case NET_NFC_MIFARE_MINI_PICC :
+ /* 0 ~ 4 : 5 sector and 4 block with 16 bytes */
+ if (sector > MIFARE_MINI_SECTORS - 1)
+ return NET_NFC_OUT_OF_BOUND;
+
+ sector_to_block = sector * MIFARE_BLOCK_4 + 3;
+ break;
+ case NET_NFC_MIFARE_1K_PICC :
+ /* 0 ~ 15 : 16 sector and 4 block with 16 bytes */
+ if (sector > MIFARE_1K_SECTORS)
+ return NET_NFC_OUT_OF_BOUND;
+
+ sector_to_block = sector * MIFARE_BLOCK_4 + 3;
+ break;
+ case NET_NFC_MIFARE_4K_PICC :
+ /* 0 ~ 31 : 32 sector and 4 block with 16 bytes
+ * 32 ~ 39 : 8 sector and 16 block with 16 bytes
+ */
+ if (sector > MIFARE_4K_SECTORS)
+ return NET_NFC_OUT_OF_BOUND;
+
+ if (sector < 32)
+ sector_to_block = sector * MIFARE_BLOCK_4 + 3;
+ else
+ {
+ sector_to_block = (31 * MIFARE_BLOCK_4 + 3)
+ + (sector - 32)
+ * MIFARE_BLOCK_16 + 15;
+ }
+ break;
+ default :
+ break;
+ }
+
+
+ /* cmd + addr + UID + AUTH_KEY + CRC_A */
+ send_buffer_length = 1 + 1 + ((data_s*)UID)->length
+ + key->length + 2;
+
+ _net_nfc_util_alloc_mem(send_buffer,
+ send_buffer_length * sizeof(uint8_t));
+ if (send_buffer == NULL)
+ {
+ net_nfc_free_data(UID);
+ return NET_NFC_ALLOC_FAIL;
+ }
+
+ temp = send_buffer;
+
+ *temp = MIFARE_CMD_AUTH_A;
+ temp++;
+
+ *temp = sector_to_block;
+ temp++;
+
+ memcpy(temp, ((data_s*)UID)->buffer, ((data_s*)UID)->length);
+ temp = temp + ((data_s*)UID)->length;
+
+ memcpy(temp, key->buffer, key->length);
+
+ net_nfc_util_compute_CRC(CRC_A, send_buffer, send_buffer_length);
+
+
+ rawdata.buffer = send_buffer;
+ rawdata.length = send_buffer_length;
+
+ net_nfc_error_e result = net_nfc_client_transceive(handle,
+ (data_h)&rawdata,
+ callback,
+ user_data);
+
+ if (send_buffer != NULL)
+ _net_nfc_util_free_mem(send_buffer);
+
+ return result;
+}
+
+API net_nfc_error_e net_nfc_client_mifare_authenticate_with_keyB(
+ net_nfc_target_handle_h handle,
+ uint8_t sector,
+ data_h auth_key,
+ void *callback,
+ void *user_data)
+{
+ net_nfc_target_info_s* target_info = NULL;
+
+ data_s *key;
+ data_s rawdata;
+
+ data_h UID = NULL;
+
+ uint8_t* send_buffer = NULL;
+ uint8_t* temp = NULL;
+
+ int send_buffer_length = 0;
+
+ uint8_t sector_to_block = 0;
+
+
+ if (handle == NULL || auth_key == NULL)
+ return NET_NFC_NULL_PARAMETER;
+
+ if (net_nfc_client_tag_is_connected() == FALSE)
+ return NET_NFC_OPERATION_FAIL;
+
+ key = (data_s *)auth_key;
+
+ if (key->length != 6)
+ return NET_NFC_OUT_OF_BOUND;
+
+ target_info = net_nfc_client_tag_get_client_target_info();
+
+ if (target_info != NULL)
+ {
+ if (target_info->devType < NET_NFC_MIFARE_MINI_PICC ||
+ target_info->devType > NET_NFC_MIFARE_4K_PICC)
+ {
+ DEBUG_CLIENT_MSG("not a MIFARE Classic TAG");
+ return NET_NFC_NOT_SUPPORTED;
+ }
+ }
+
+ if (net_nfc_get_tag_info_value((net_nfc_target_info_h)target_info,
+ MIFARE_TAG_KEY,
+ &UID) != NET_NFC_OK)
+ {
+ return NET_NFC_NO_DATA_FOUND;
+ }
+
+ switch (target_info->devType)
+ {
+ case NET_NFC_MIFARE_MINI_PICC :
+ /* 0 ~ 4 : 5 sector and 4 block with 16 bytes */
+ if (sector > MIFARE_MINI_SECTORS)
+ return NET_NFC_OUT_OF_BOUND;
+
+ sector_to_block = sector * MIFARE_BLOCK_4 + 3;
+ break;
+ case NET_NFC_MIFARE_1K_PICC :
+ /* 0 ~ 15 : 16 sector and 4 block with 16 bytes */
+ if (sector > MIFARE_1K_SECTORS)
+ return NET_NFC_OUT_OF_BOUND;
+
+ sector_to_block = sector * MIFARE_BLOCK_4 + 3;
+ break;
+ case NET_NFC_MIFARE_4K_PICC :
+ /* 0 ~ 31 : 32 sector and 4 block with 16 bytes
+ * 32 ~ 39 : 8 sector and 16 block with 16 bytes
+ */
+ if (sector > MIFARE_4K_SECTORS)
+ return NET_NFC_OUT_OF_BOUND;
+
+ if (sector < 32)
+ sector_to_block = sector * MIFARE_BLOCK_4 + 3;
+ else
+ {
+ sector_to_block = (31 * MIFARE_BLOCK_4 + 3)
+ + (sector - 32)
+ * MIFARE_BLOCK_16 + 15;
+ }
+ break;
+ default :
+ break;
+ }
+
+ send_buffer_length = 1 + 1 + ((data_s*)UID)->length
+ + key->length + 2; /* cmd + addr + UID + AUTH_KEY + CRC_A */
+
+ _net_nfc_util_alloc_mem(send_buffer, send_buffer_length
+ * sizeof(uint8_t));
+ if (send_buffer == NULL)
+ {
+ net_nfc_free_data(UID);
+ return NET_NFC_ALLOC_FAIL;
+ }
+
+ temp = send_buffer;
+
+ *temp = MIFARE_CMD_AUTH_B;
+ temp++;
+
+ *temp = sector_to_block;
+ temp++;
+
+ memcpy(temp, ((data_s*)UID)->buffer, ((data_s*)UID)->length);
+ temp = temp + ((data_s*)UID)->length;
+
+ memcpy(temp, key->buffer, key->length);
+
+ net_nfc_util_compute_CRC(CRC_A, send_buffer, send_buffer_length);
+
+ rawdata.buffer = send_buffer;
+ rawdata.length = send_buffer_length;
+
+ net_nfc_error_e result = net_nfc_client_transceive(handle,
+ (data_h)&rawdata,
+ callback,
+ user_data);
+
+ if (send_buffer != NULL)
+ _net_nfc_util_free_mem(send_buffer);
+
+ return result;
+}
+
+API net_nfc_error_e net_nfc_client_mifare_read(net_nfc_target_handle_h handle,
+ uint8_t addr,
+ void *callback,
+ void *user_data)
+{
+ net_nfc_target_info_s* target_info = NULL;
+
+ data_s rawdata;
+
+ uint8_t send_buffer[4] = { 0 };
+
+
+ if (handle == NULL)
+ return NET_NFC_NULL_PARAMETER;
+
+ if (net_nfc_client_tag_is_connected() == FALSE)
+ return NET_NFC_OPERATION_FAIL;
+
+ target_info = net_nfc_client_tag_get_client_target_info();
+
+ if (target_info != NULL)
+ {
+ if (target_info->devType < NET_NFC_MIFARE_MINI_PICC ||
+ target_info->devType > NET_NFC_MIFARE_ULTRA_PICC)
+ {
+ DEBUG_CLIENT_MSG("not a MIFARE TAG = [%d]",
+ target_info->devType);
+ return NET_NFC_NOT_SUPPORTED;
+ }
+
+ if (target_info->devType == NET_NFC_MIFARE_ULTRA_PICC)
+ {
+ if (addr > 7)
+ return NET_NFC_OUT_OF_BOUND;
+ }
+ }
+
+
+ send_buffer[0] = MIFARE_CMD_READ;
+ send_buffer[1] = addr;
+
+ net_nfc_util_compute_CRC(CRC_A, send_buffer, 4);
+
+ rawdata.buffer = send_buffer;
+ rawdata.length = 4;
+
+ return net_nfc_client_transceive_data(handle,
+ (data_h)&rawdata,
+ callback,
+ user_data);
+}
+
+API net_nfc_error_e net_nfc_client_mifare_write_block(
+ net_nfc_target_handle_h handle,
+ uint8_t addr,
+ data_h data,
+ void *callback,
+ void *user_data)
+{
+ net_nfc_target_info_s* target_info = NULL;
+
+ data_s rawdata;
+
+ uint8_t* send_buffer = NULL;
+
+ uint32_t send_buffer_length = 0;
+
+
+ if (handle == NULL)
+ return NET_NFC_NULL_PARAMETER;
+
+ if (net_nfc_client_tag_is_connected() == FALSE)
+ return NET_NFC_OPERATION_FAIL;
+
+
+ target_info = net_nfc_client_tag_get_client_target_info();
+
+ if (target_info == NULL)
+ return NET_NFC_NOT_INITIALIZED;
+
+ if (target_info->devType < NET_NFC_MIFARE_MINI_PICC ||
+ target_info->devType > NET_NFC_MIFARE_ULTRA_PICC)
+ {
+ DEBUG_CLIENT_MSG("not a MIFARE TAG = [%d] \n",
+ target_info->devType);
+ return NET_NFC_NOT_SUPPORTED;
+ }
+
+ if (target_info->devType == NET_NFC_MIFARE_ULTRA_PICC)
+ {
+ if (addr > 7)
+ return NET_NFC_OUT_OF_BOUND;
+ }
+
+ if (target_info->devType == NET_NFC_MIFARE_ULTRA_PICC)
+ {
+ if (((data_s *)data)->length > MIFARE_PAGE_SIZE)
+ {
+ uint8_t* temp = NULL;
+
+ /* cmd + addr + page + CRC */
+ send_buffer_length = 1 + 1 + MIFARE_PAGE_SIZE + 2;
+
+ _net_nfc_util_alloc_mem(send_buffer,
+ send_buffer_length * sizeof(uint8_t));
+ if (send_buffer == NULL)
+ return NET_NFC_ALLOC_FAIL;
+
+ temp = send_buffer;
+
+ *temp = MIFARE_CMD_WRITE_PAGE;
+ temp++;
+
+ *temp = addr;
+ temp++;
+
+ memcpy(temp,
+ ((data_s*)data)->buffer,
+ MIFARE_PAGE_SIZE);
+
+ }
+ else
+ {
+ uint8_t* temp = NULL;
+
+ /* cmd + addr + page + CRC */
+ send_buffer_length = 1 + 1 +
+ ((data_s*)data)->length + 2;
+
+ _net_nfc_util_alloc_mem(send_buffer,
+ send_buffer_length * sizeof(uint8_t));
+ if (send_buffer == NULL)
+ return NET_NFC_ALLOC_FAIL;
+
+ temp = send_buffer;
+
+ *temp = MIFARE_CMD_WRITE_PAGE;
+ temp++;
+
+ *temp = addr;
+ temp++;
+
+ memcpy(temp,
+ ((data_s*)data)->buffer,
+ ((data_s*)data)->length);
+ }
+
+ }
+ else
+ {
+
+ if (((data_s*)data)->length > MIFARE_BLOCK_SIZE)
+ {
+ uint8_t* temp = NULL;
+
+ /* cmd + addr + page + CRC */
+ send_buffer_length = 1 + 1 + MIFARE_BLOCK_SIZE + 2;
+
+ _net_nfc_util_alloc_mem(send_buffer,
+ send_buffer_length * sizeof(uint8_t));
+ if (send_buffer == NULL)
+ return NET_NFC_ALLOC_FAIL;
+
+ temp = send_buffer;
+
+ *temp = MIFARE_CMD_WRITE_BLOCK;
+ temp++;
+
+ *temp = addr;
+ temp++;
+
+ memcpy(temp,
+ ((data_s*)data)->buffer,
+ MIFARE_BLOCK_SIZE);
+ }
+ else
+ {
+ uint8_t* temp = NULL;
+
+ /* cmd + addr + page + CRC */
+ send_buffer_length = 1 + 1 + ((data_s*)data)->length
+ + 2;
+
+ _net_nfc_util_alloc_mem(send_buffer,
+ send_buffer_length * sizeof(uint8_t));
+ if (send_buffer == NULL)
+ return NET_NFC_ALLOC_FAIL;
+
+ temp = send_buffer;
+
+ *temp = MIFARE_CMD_WRITE_BLOCK;
+ temp++;
+
+ *temp = addr;
+ temp++;
+
+ memcpy(temp,
+ ((data_s*)data)->buffer,
+ ((data_s*)data)->length);
+ }
+ }
+
+ net_nfc_util_compute_CRC(CRC_A, send_buffer, send_buffer_length);
+
+ rawdata.buffer = send_buffer;
+ rawdata.length = send_buffer_length;
+
+ net_nfc_error_e result = net_nfc_client_transceive(handle,
+ (data_h)&rawdata,
+ callback,
+ user_data);
+
+ if (send_buffer != NULL)
+ _net_nfc_util_free_mem(send_buffer);
+
+ return result;
+}
+
+API net_nfc_error_e net_nfc_client_mifare_write_page(
+ net_nfc_target_handle_h handle,
+ uint8_t addr,
+ data_h data,
+ void *callback,
+ void *user_data)
+{
+ net_nfc_target_info_s* target_info = NULL;
+
+ uint8_t* send_buffer = NULL;
+
+ uint32_t send_buffer_length = 0;
+
+ if (handle == NULL)
+ return NET_NFC_NULL_PARAMETER;
+
+ if (net_nfc_client_tag_is_connected() == FALSE)
+ return NET_NFC_OPERATION_FAIL;
+
+ target_info = net_nfc_client_tag_get_client_target_info();
+
+ if (target_info == NULL)
+ return NET_NFC_NOT_INITIALIZED;
+
+ if (target_info->devType < NET_NFC_MIFARE_MINI_PICC ||
+ target_info->devType > NET_NFC_MIFARE_ULTRA_PICC)
+ {
+ DEBUG_CLIENT_MSG("not a MIFARE TAG = [%d] \n",
+ target_info->devType);
+ return NET_NFC_NOT_SUPPORTED;
+ }
+
+ if (target_info->devType == NET_NFC_MIFARE_ULTRA_PICC)
+ {
+ if (addr > 7)
+ return NET_NFC_OUT_OF_BOUND;
+ }
+
+ if (target_info->devType == NET_NFC_MIFARE_ULTRA_PICC)
+ {
+ if (((data_s*)data)->length > MIFARE_PAGE_SIZE)
+ {
+ uint8_t* temp = NULL;
+
+ /* cmd + addr + page + CRC */
+ send_buffer_length = 1 + 1 + MIFARE_PAGE_SIZE + 2;
+
+ _net_nfc_util_alloc_mem(send_buffer,
+ send_buffer_length * sizeof(uint8_t));
+ if (send_buffer == NULL)
+ return NET_NFC_ALLOC_FAIL;
+
+ temp = send_buffer;
+
+ *temp = MIFARE_CMD_WRITE_PAGE;
+ temp++;
+
+ *temp = addr;
+ temp++;
+
+ memcpy(temp,
+ ((data_s*)data)->buffer,
+ MIFARE_PAGE_SIZE);
+ }
+ else
+ {
+ uint8_t* temp = NULL;
+
+ /* cmd + addr + page + CRC */
+ send_buffer_length = 1 + 1 + ((data_s*)data)->length
+ + 2;
+
+ _net_nfc_util_alloc_mem(send_buffer,
+ send_buffer_length * sizeof(uint8_t));
+ if (send_buffer == NULL)
+ return NET_NFC_ALLOC_FAIL;
+
+ temp = send_buffer;
+
+ *temp = MIFARE_CMD_WRITE_PAGE;
+ temp++;
+
+ *temp = addr;
+ temp++;
+
+ memcpy(temp,
+ ((data_s*)data)->buffer,
+ ((data_s*)data)->length);
+ }
+
+ }
+ else
+ {
+ if (((data_s*)data)->length > MIFARE_PAGE_SIZE)
+ {
+ uint8_t* temp = NULL;
+
+ /* cmd + addr + page + CRC */
+ send_buffer_length = 1 + 1 + MIFARE_PAGE_SIZE + 2;
+
+ _net_nfc_util_alloc_mem(send_buffer,
+ send_buffer_length * sizeof(uint8_t));
+ if (send_buffer == NULL)
+ return NET_NFC_ALLOC_FAIL;
+
+ temp = send_buffer;
+
+ *temp = MIFARE_CMD_WRITE_BLOCK;
+ temp++;
+
+ *temp = addr;
+ temp++;
+
+ memcpy(temp,
+ ((data_s*)data)->buffer,
+ MIFARE_PAGE_SIZE);
+
+ }
+ else
+ {
+ uint8_t* temp = NULL;
+
+ /* cmd + addr + page + CRC */
+ send_buffer_length = 1 + 1 + ((data_s*)data)->length
+ + 2;
+
+ _net_nfc_util_alloc_mem(send_buffer,
+ send_buffer_length * sizeof(uint8_t));
+ if (send_buffer == NULL)
+ return NET_NFC_ALLOC_FAIL;
+
+ temp = send_buffer;
+
+ *temp = MIFARE_CMD_WRITE_BLOCK;
+ temp++;
+
+ *temp = addr;
+ temp++;
+
+ memcpy(temp,
+ ((data_s*)data)->buffer,
+ ((data_s*)data)->length);
+ }
+
+ }
+
+ net_nfc_util_compute_CRC(CRC_A, send_buffer, send_buffer_length);
+
+ data_s rawdata;
+
+ rawdata.buffer = send_buffer;
+ rawdata.length = send_buffer_length;
+
+ net_nfc_error_e result = net_nfc_client_transceive(handle,
+ (data_h)&rawdata,
+ callback,
+ user_data);
+
+ if (send_buffer != NULL)
+ _net_nfc_util_free_mem(send_buffer);
+
+ return result;
+}
+
+API net_nfc_error_e net_nfc_client_mifare_increment(net_nfc_target_handle_h handle,
+ uint8_t addr,
+ int value,
+ void *callback,
+ void *user_data)
+{
+ net_nfc_target_info_s* target_info = NULL;
+
+ data_s rawdata;
+
+ uint8_t send_buffer[8] = { 0 };
+
+
+ if (handle == NULL)
+ return NET_NFC_NULL_PARAMETER;
+
+ if (net_nfc_client_tag_is_connected() == FALSE)
+ return NET_NFC_OPERATION_FAIL;
+
+ target_info = net_nfc_client_tag_get_client_target_info();
+
+ if (target_info)
+ {
+ if (target_info->devType < NET_NFC_MIFARE_MINI_PICC ||
+ target_info->devType > NET_NFC_MIFARE_4K_PICC)
+ {
+ DEBUG_CLIENT_MSG(
+ "not a MIFARE Classic TAG = [%d]",
+ target_info->devType);
+ return NET_NFC_NOT_SUPPORTED;
+ }
+ }
+
+
+ send_buffer[0] = MIFARE_CMD_INCREMENT;
+ send_buffer[1] = addr;
+
+ /* little endian.
+ little value of byte array will be saved first in memory */
+ send_buffer[5] = (value & 0xFF000000) >> 24;
+ send_buffer[4] = (value & 0x00FF0000) >> 16;
+ send_buffer[3] = (value & 0x0000FF00) >> 8;
+ send_buffer[2] = (value & 0x000000FF);
+
+ net_nfc_util_compute_CRC(CRC_A, send_buffer, 8);
+
+ rawdata.buffer = send_buffer;
+ rawdata.length = 8;
+
+ return net_nfc_client_transceive(handle, (data_h)&rawdata, callback,
+ user_data);
+}
+
+API net_nfc_error_e net_nfc_client_mifare_decrement(net_nfc_target_handle_h handle,
+ uint8_t addr,
+ int value,
+ void *callback,
+ void *user_data)
+{
+ net_nfc_target_info_s* target_info = NULL;
+
+ data_s rawdata;
+
+ uint8_t send_buffer[8] = { 0 };
+
+ if (handle == NULL)
+ return NET_NFC_NULL_PARAMETER;
+
+ if (net_nfc_client_tag_is_connected() == FALSE)
+ return NET_NFC_OPERATION_FAIL;
+
+ target_info = net_nfc_client_tag_get_client_target_info();
+
+ if (target_info)
+ {
+
+ if (target_info->devType < NET_NFC_MIFARE_MINI_PICC ||
+ target_info->devType > NET_NFC_MIFARE_4K_PICC)
+ {
+ DEBUG_CLIENT_MSG("not a MIFARE Classic TAG = [%d] \n",
+ target_info->devType);
+ return NET_NFC_NOT_SUPPORTED;
+ }
+ }
+
+ send_buffer[0] = MIFARE_CMD_DECREMENT;
+ send_buffer[1] = addr;
+
+ /* little endian.
+ little value of byte array will be saved first in memory */
+ send_buffer[5] = (value & 0xFF000000) >> 24;
+ send_buffer[4] = (value & 0x00FF0000) >> 16;
+ send_buffer[3] = (value & 0x0000FF00) >> 8;
+ send_buffer[2] = (value & 0x000000FF);
+
+ net_nfc_util_compute_CRC(CRC_A, send_buffer, 8);
+
+ DEBUG_MSG_PRINT_BUFFER(send_buffer, 8);
+
+ rawdata.buffer = send_buffer;
+ rawdata.length = 8;
+
+ return net_nfc_client_transceive(handle, (data_h)&rawdata, callback,
+ user_data);
+}
+
+API net_nfc_error_e net_nfc_client_mifare_transfer(net_nfc_target_handle_h handle,
+ uint8_t addr,
+ void *callback,
+ void *user_data)
+{
+ net_nfc_target_info_s* target_info = NULL;
+
+ data_s rawdata;
+
+ uint8_t send_buffer[4] = { 0 };
+
+ if (handle == NULL)
+ return NET_NFC_NULL_PARAMETER;
+
+ if (net_nfc_client_tag_is_connected() == FALSE)
+ return NET_NFC_OPERATION_FAIL;
+
+ target_info = net_nfc_client_tag_get_client_target_info();
+
+ if (target_info)
+ {
+ if (target_info->devType < NET_NFC_MIFARE_MINI_PICC ||
+ target_info->devType > NET_NFC_MIFARE_4K_PICC)
+ {
+ DEBUG_CLIENT_MSG("not a MIFARE Classic TAG = [%d]",
+ target_info->devType);
+ return NET_NFC_NOT_SUPPORTED;
+ }
+ }
+
+ send_buffer[0] = MIFARE_CMD_TRANSFER;
+ send_buffer[1] = addr;
+
+ net_nfc_util_compute_CRC(CRC_A, send_buffer, 4);
+
+ rawdata.buffer = send_buffer;
+ rawdata.length = 4;
+
+ return net_nfc_client_transceive(handle, (data_h)&rawdata, callback,
+ user_data);
+}
+
+API net_nfc_error_e net_nfc_client_mifare_restore(net_nfc_target_handle_h handle,
+ uint8_t addr,
+ void *callback,
+ void *user_data)
+{
+ net_nfc_target_info_s* target_info = NULL;
+
+ data_s rawdata;
+
+ uint8_t send_buffer[4] = { 0 };
+
+ if (handle == NULL)
+ return NET_NFC_NULL_PARAMETER;
+
+ if (net_nfc_client_tag_is_connected() == FALSE)
+ return NET_NFC_OPERATION_FAIL;
+
+ target_info = net_nfc_client_tag_get_client_target_info();
+
+ if (target_info)
+ {
+ if (target_info->devType < NET_NFC_MIFARE_MINI_PICC ||
+ target_info->devType > NET_NFC_MIFARE_4K_PICC)
+ {
+ DEBUG_CLIENT_MSG("not a MIFARE Classic TAG = [%d]",
+ target_info->devType);
+ return NET_NFC_NOT_SUPPORTED;
+ }
+ }
+
+ send_buffer[0] = MIFARE_CMD_RESTORE;
+ send_buffer[1] = addr;
+
+ net_nfc_util_compute_CRC(CRC_A, send_buffer, 4);
+
+ rawdata.buffer = send_buffer;
+ rawdata.length = 4;
+
+ return net_nfc_client_transceive(handle, (data_h)&rawdata, callback,
+ user_data);
+}
+
+API net_nfc_error_e net_nfc_client_mifare_create_default_key(data_h* key)
+{
+ if (key == NULL)
+ return NET_NFC_NULL_PARAMETER;
+
+ return net_nfc_create_data(key, default_key, 6);
+}
+
+API net_nfc_error_e net_nfc_client_mifare_create_application_directory_key(
+ data_h* key)
+{
+ if (key == NULL)
+ return NET_NFC_NULL_PARAMETER;
+
+ return net_nfc_create_data(key, mad_key, 6);
+}
+
+API net_nfc_error_e net_nfc_client_mifare_create_net_nfc_forum_key(data_h* key)
+{
+ if (key == NULL)
+ return NET_NFC_NULL_PARAMETER;
+
+ return net_nfc_create_data(key, net_nfc_forum_key, 6);
+}
+
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdbool.h>
+
+#include "net_nfc_typedef_internal.h"
+#include "net_nfc_debug_internal.h"
+#include "net_nfc_data.h"
+#include "net_nfc_target_info.h"
+#include "net_nfc_util_internal.h"
+
+API net_nfc_error_e net_nfc_get_tag_type(net_nfc_target_info_h target_info, net_nfc_target_type_e * type)
+{
+ if (target_info == NULL || type == NULL)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+ net_nfc_target_info_s * tmp_target_info = (net_nfc_target_info_s*)target_info;
+
+ *type = tmp_target_info->devType;
+ return NET_NFC_OK;
+}
+
+API net_nfc_error_e net_nfc_get_tag_handle(net_nfc_target_info_h target_info, net_nfc_target_handle_h * handle)
+{
+ if (target_info == NULL || handle == NULL)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+ net_nfc_target_info_s * tmp_target_info = (net_nfc_target_info_s*)target_info;
+
+ *handle = (net_nfc_target_handle_h)tmp_target_info->handle;
+ return NET_NFC_OK;
+}
+
+API net_nfc_error_e net_nfc_get_tag_ndef_support(net_nfc_target_info_h target_info, bool * is_support)
+{
+ if (target_info == NULL || is_support == NULL)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+ net_nfc_target_info_s * tmp_target_info = (net_nfc_target_info_s*)target_info;
+
+ *is_support = (bool)tmp_target_info->is_ndef_supported;
+ return NET_NFC_OK;
+}
+
+API net_nfc_error_e net_nfc_get_tag_max_data_size(net_nfc_target_info_h target_info, uint32_t * max_size)
+{
+ if (target_info == NULL || max_size == NULL)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+ net_nfc_target_info_s * tmp_target_info = (net_nfc_target_info_s*)target_info;
+
+ *max_size = tmp_target_info->maxDataSize;
+ return NET_NFC_OK;
+}
+
+API net_nfc_error_e net_nfc_get_tag_actual_data_size(net_nfc_target_info_h target_info, uint32_t * actual_data)
+{
+ if (target_info == NULL || actual_data == NULL)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+ net_nfc_target_info_s * tmp_target_info = (net_nfc_target_info_s*)target_info;
+
+ *actual_data = tmp_target_info->actualDataSize;
+ return NET_NFC_OK;
+}
+
+API net_nfc_error_e net_nfc_get_tag_info_keys(net_nfc_target_info_h target_info, char ***keys, int* number_of_keys)
+{
+ if (keys == NULL || number_of_keys == NULL || target_info == NULL)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ net_nfc_target_info_s* handle = (net_nfc_target_info_s*)target_info;
+
+ if (handle->tag_info_list == NULL)
+ {
+ return NET_NFC_NO_DATA_FOUND;
+ }
+
+ if (handle->number_of_keys <= 0)
+ {
+ return NET_NFC_NO_DATA_FOUND;
+ }
+
+ int i = 0;
+
+ if (handle->keylist != NULL)
+ {
+ *keys = handle->keylist;
+ return NET_NFC_OK;
+ }
+
+ _net_nfc_util_alloc_mem(*keys, handle->number_of_keys * sizeof(char *));
+ if (*keys == NULL)
+ return NET_NFC_ALLOC_FAIL;
+
+ net_nfc_tag_info_s* tag_info = handle->tag_info_list;
+
+ for (; i < handle->number_of_keys; i++, tag_info++)
+ {
+ (*keys)[i] = tag_info->key;
+ }
+
+ *number_of_keys = handle->number_of_keys;
+
+ DEBUG_CLIENT_MSG("number of keys = [%d]", handle->number_of_keys);
+
+ handle->keylist = *keys;
+
+ return NET_NFC_OK;
+}
+
+API net_nfc_error_e net_nfc_get_tag_info_value(net_nfc_target_info_h target_info, const char* key, data_h* value)
+{
+ if (target_info == NULL || key == NULL || value == NULL)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ net_nfc_target_info_s* handle = (net_nfc_target_info_s*)target_info;
+
+ if (handle->tag_info_list == NULL)
+ {
+ return NET_NFC_NO_DATA_FOUND;
+ }
+
+ int i = 0;
+
+ net_nfc_tag_info_s* tag_info = handle->tag_info_list;
+
+ for (; i < handle->number_of_keys; i++, tag_info++)
+ {
+ if (strcmp(key, tag_info->key) == 0)
+ {
+ if (tag_info->value == NULL)
+ {
+ return NET_NFC_NO_DATA_FOUND;
+ }
+ else
+ {
+ *value = tag_info->value;
+ break;
+ }
+ }
+ }
+
+ if (i == handle->number_of_keys)
+ return NET_NFC_NOT_SUPPORTED;
+
+ return NET_NFC_OK;
+}
+
+API net_nfc_error_e net_nfc_duplicate_target_info(net_nfc_target_info_h origin, net_nfc_target_info_h *result)
+{
+ net_nfc_target_info_s *handle = (net_nfc_target_info_s *)origin;
+ net_nfc_target_info_s *temp = NULL;
+
+ if (handle == NULL || result == NULL)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ _net_nfc_util_alloc_mem(temp, sizeof(net_nfc_target_info_s));
+ if (temp == NULL)
+ {
+ return NET_NFC_ALLOC_FAIL;
+ }
+
+ temp->ndefCardState = handle->ndefCardState;
+ temp->actualDataSize = handle->actualDataSize;
+ temp->maxDataSize = handle->maxDataSize;
+ temp->devType = handle->devType;
+ temp->handle = handle->handle;
+ temp->is_ndef_supported = handle->is_ndef_supported;
+ temp->number_of_keys = handle->number_of_keys;
+
+ if (temp->number_of_keys > 0)
+ {
+ int i;
+
+ _net_nfc_util_alloc_mem(temp->tag_info_list, temp->number_of_keys * sizeof(net_nfc_tag_info_s));
+ if (temp->tag_info_list == NULL)
+ {
+ _net_nfc_util_free_mem(temp);
+ return NET_NFC_ALLOC_FAIL;
+ }
+
+ for (i = 0; i < handle->number_of_keys; i++)
+ {
+ if (handle->tag_info_list[i].key != NULL)
+ _net_nfc_util_strdup(temp->tag_info_list[i].key, handle->tag_info_list[i].key);
+
+ if (handle->tag_info_list[i].value != NULL)
+ {
+ data_s *data = (data_s *)handle->tag_info_list[i].value;
+
+ net_nfc_create_data(&temp->tag_info_list[i].value, data->buffer, data->length);
+ }
+ }
+ }
+
+ if (handle->raw_data.length > 0)
+ {
+ net_nfc_util_alloc_data(&temp->raw_data, handle->raw_data.length);
+ memcpy(temp->raw_data.buffer, handle->raw_data.buffer, temp->raw_data.length);
+ }
+
+ *result = (net_nfc_target_info_h)temp;
+
+ return NET_NFC_OK;
+}
+
+static net_nfc_error_e net_nfc_util_release_tag_info(net_nfc_target_info_s *info)
+{
+ net_nfc_error_e result = NET_NFC_OK;
+ net_nfc_tag_info_s *list = NULL;
+
+ if (info == NULL)
+ return NET_NFC_NULL_PARAMETER;
+
+ list = info->tag_info_list;
+ if (list != NULL)
+ {
+ int i = 0;
+ for (i = 0; i < info->number_of_keys; i++, list++)
+ {
+ if (list->key != NULL)
+ _net_nfc_util_free_mem(list->key);
+
+ if (list->value != NULL)
+ net_nfc_free_data(list->value);
+ }
+
+ _net_nfc_util_free_mem(info->tag_info_list);
+ }
+
+ if (info->keylist != NULL)
+ {
+ _net_nfc_util_free_mem(info->keylist);
+ }
+
+ net_nfc_util_free_data(&info->raw_data);
+
+ return result;
+}
+
+API net_nfc_error_e net_nfc_release_tag_info(net_nfc_target_info_h target_info)
+{
+ net_nfc_error_e result = NET_NFC_OK;
+ net_nfc_target_info_s *info = (net_nfc_target_info_s *)target_info;
+
+ if (info == NULL)
+ return NET_NFC_NULL_PARAMETER;
+
+ net_nfc_util_release_tag_info(info);
+
+ _net_nfc_util_free_mem(info);
+
+ return result;
+}
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "net_nfc_debug_internal.h"
+#include "net_nfc_util_gdbus_internal.h"
+#include "net_nfc_gdbus.h"
+#include "net_nfc_client.h"
+#include "net_nfc_client_manager.h"
+#include "net_nfc_client_test.h"
+
+typedef struct _TestFuncData TestFuncData;
+
+struct _TestFuncData
+{
+ gpointer callback;
+ gpointer user_data;
+};
+
+static void test_call_sim_test_callback(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data);
+
+static void test_call_prbs_test_callback(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data);
+
+static void test_call_get_firmware_version_callback(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data);
+
+static void test_call_set_ee_data_callback(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data);
+
+static NetNfcGDbusTest *test_proxy = NULL;
+
+
+static void test_call_sim_test_callback(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ TestFuncData *func_data;
+
+ net_nfc_error_e out_result = NET_NFC_OK;
+ GError *error = NULL;
+
+ net_nfc_client_test_sim_test_completed callback;
+ gpointer data;
+
+ if (net_nfc_gdbus_test_call_sim_test_finish(
+ NET_NFC_GDBUS_TEST(source_object),
+ (gint *)&out_result,
+ res,
+ &error) == FALSE)
+ {
+
+ out_result = NET_NFC_UNKNOWN_ERROR;
+
+ DEBUG_ERR_MSG("Can not finish sim_test: %s",
+ error->message);
+ g_error_free(error);
+ }
+
+ func_data = user_data;
+ if (func_data == NULL)
+ return;
+
+ if (func_data->callback == NULL)
+ {
+ g_free(func_data);
+ return;
+ }
+
+ callback = (net_nfc_client_test_sim_test_completed)func_data->callback;
+ data = func_data->user_data;
+
+ callback(out_result, data);
+
+ g_free(func_data);
+}
+
+static void test_call_prbs_test_callback(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ TestFuncData *func_data;
+
+ net_nfc_error_e out_result = NET_NFC_OK;
+ GError *error = NULL;
+
+ net_nfc_client_test_prbs_test_completed callback;
+ gpointer data;
+
+ if (net_nfc_gdbus_test_call_prbs_test_finish(
+ NET_NFC_GDBUS_TEST(source_object),
+ (gint *)&out_result,
+ res,
+ &error) == FALSE)
+ {
+
+ out_result = NET_NFC_UNKNOWN_ERROR;
+
+ DEBUG_ERR_MSG("Can not finish prbs test: %s",
+ error->message);
+ g_error_free(error);
+ }
+
+ func_data = user_data;
+ if (func_data == NULL)
+ return;
+
+ if (func_data->callback == NULL)
+ {
+ g_free(func_data);
+ return;
+ }
+
+ callback = (net_nfc_client_test_prbs_test_completed)
+ func_data->callback;
+ data = func_data->user_data;
+
+ callback(out_result, data);
+
+ g_free(func_data);
+}
+
+static void test_call_get_firmware_version_callback(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ TestFuncData *func_data;
+
+ net_nfc_error_e out_result = NET_NFC_OK;
+ gchar *out_version = NULL;
+ GError *error = NULL;
+
+ net_nfc_client_test_get_firmware_version_completed callback;
+ gpointer data;
+
+ if (net_nfc_gdbus_test_call_get_firmware_version_finish(
+ NET_NFC_GDBUS_TEST(source_object),
+ (gint *)&out_result,
+ &out_version,
+ res,
+ &error) == FALSE)
+ {
+
+ out_result = NET_NFC_UNKNOWN_ERROR;
+
+ DEBUG_ERR_MSG("Can not finish get_firmware_version: %s",
+ error->message);
+ g_error_free(error);
+ }
+
+ func_data = user_data;
+ if (func_data == NULL)
+ return;
+
+ if (func_data->callback == NULL)
+ {
+ g_free(out_version);
+ g_free(func_data);
+ return;
+ }
+
+ callback = (net_nfc_client_test_get_firmware_version_completed)
+ func_data->callback;
+ data = func_data->user_data;
+
+ callback(out_result, out_version, data);
+
+ g_free(out_version);
+ g_free(func_data);
+}
+
+static void test_call_set_ee_data_callback(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ TestFuncData *func_data;
+
+ net_nfc_error_e out_result = NET_NFC_OK;
+
+ GError *error = NULL;
+
+ net_nfc_client_test_set_ee_data_completed callback;
+
+ if (net_nfc_gdbus_test_call_set_ee_data_finish(
+ NET_NFC_GDBUS_TEST(source_object),
+ (gint *)&out_result,
+ res,
+ &error) == FALSE)
+ {
+ out_result = NET_NFC_UNKNOWN_ERROR;
+
+ DEBUG_ERR_MSG("Can not finish set_ee_data: %s\n",
+ error->message);
+ g_error_free(error);
+ }
+
+ func_data = user_data;
+
+ if (func_data->callback == NULL)
+ {
+ g_free(func_data);
+ return;
+ }
+
+ callback = (net_nfc_client_test_set_ee_data_completed)
+ func_data->callback;
+
+ callback(out_result, func_data->user_data);
+
+ g_free(func_data);
+}
+
+
+API net_nfc_error_e net_nfc_client_test_sim_test(
+ net_nfc_client_test_sim_test_completed callback,
+ void *user_data)
+{
+ TestFuncData *func_data;
+
+ if (test_proxy == NULL)
+ return NET_NFC_UNKNOWN_ERROR;
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ func_data = g_new0(TestFuncData, 1);
+ if (func_data == NULL)
+ return NET_NFC_UNKNOWN_ERROR;
+
+ func_data->callback = (gpointer)callback;
+ func_data->user_data = user_data;
+
+ net_nfc_gdbus_test_call_sim_test(test_proxy,
+ net_nfc_client_gdbus_get_privilege(),
+ NULL,
+ test_call_sim_test_callback,
+ func_data);
+
+ return NET_NFC_OK;
+}
+
+API net_nfc_error_e net_nfc_client_test_sim_test_sync(void)
+{
+ GError *error = NULL;
+ net_nfc_error_e out_result = NET_NFC_OK;
+
+ if (test_proxy == NULL)
+ return NET_NFC_UNKNOWN_ERROR;
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ if (net_nfc_gdbus_test_call_sim_test_sync(test_proxy,
+ net_nfc_client_gdbus_get_privilege(),
+ (gint *)&out_result,
+ NULL,
+ &error) == FALSE)
+ {
+ DEBUG_CLIENT_MSG("can not call SimTest: %s",
+ error->message);
+ g_error_free(error);
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ return out_result;
+}
+
+API net_nfc_error_e net_nfc_client_test_prbs_test(uint32_t tech,
+ uint32_t rate,
+ net_nfc_client_test_prbs_test_completed callback,
+ void *user_data)
+{
+ TestFuncData *func_data;
+
+ if (test_proxy == NULL)
+ return NET_NFC_UNKNOWN_ERROR;
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ func_data = g_new0(TestFuncData, 1);
+ if (func_data == NULL)
+ return NET_NFC_UNKNOWN_ERROR;
+
+ func_data->callback = (gpointer)callback;
+ func_data->user_data = user_data;
+
+ net_nfc_gdbus_test_call_prbs_test(test_proxy,
+ tech,
+ rate,
+ net_nfc_client_gdbus_get_privilege(),
+ NULL,
+ test_call_prbs_test_callback,
+ func_data);
+
+ return NET_NFC_OK;
+}
+
+API net_nfc_error_e net_nfc_client_test_prbs_test_sync(uint32_t tech,
+ uint32_t rate)
+{
+ GError *error = NULL;
+ net_nfc_error_e out_result = NET_NFC_OK;
+
+ if (test_proxy == NULL)
+ return NET_NFC_UNKNOWN_ERROR;
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ if (net_nfc_gdbus_test_call_prbs_test_sync(test_proxy,
+ tech,
+ rate,
+ net_nfc_client_gdbus_get_privilege(),
+ (gint *)&out_result,
+ NULL,
+ &error) == FALSE)
+ {
+ DEBUG_CLIENT_MSG("can not call PrbsTest: %s",
+ error->message);
+ g_error_free(error);
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ return out_result;
+}
+
+API net_nfc_error_e net_nfc_client_test_get_firmware_version(
+ net_nfc_client_test_get_firmware_version_completed callback,
+ void *user_data)
+{
+ TestFuncData *func_data;
+
+ if (test_proxy == NULL)
+ return NET_NFC_UNKNOWN_ERROR;
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ func_data = g_new0(TestFuncData, 1);
+ if (func_data == NULL)
+ return NET_NFC_UNKNOWN_ERROR;
+
+ func_data->callback = (gpointer)callback;
+ func_data->user_data = user_data;
+
+ net_nfc_gdbus_test_call_get_firmware_version(test_proxy,
+ net_nfc_client_gdbus_get_privilege(),
+ NULL,
+ test_call_get_firmware_version_callback,
+ func_data);
+
+ return NET_NFC_OK;
+}
+
+API net_nfc_error_e net_nfc_client_test_get_firmware_version_sync(char **version)
+{
+ gchar *out_version = NULL;
+ GError *error = NULL;
+
+ net_nfc_error_e out_result = NET_NFC_OK;
+
+ if (test_proxy == NULL)
+ return NET_NFC_UNKNOWN_ERROR;
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ if (net_nfc_gdbus_test_call_get_firmware_version_sync(test_proxy,
+ net_nfc_client_gdbus_get_privilege(),
+ (gint *)out_result,
+ &out_version,
+ NULL,
+ &error) == FALSE)
+ {
+ DEBUG_CLIENT_MSG("can not call PrbsTest: %s",
+ error->message);
+ g_error_free(error);
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ if (version != NULL)
+ *version = out_version;
+
+ return out_result;
+}
+
+API net_nfc_error_e net_nfc_client_test_set_ee_data(int mode,
+ int reg_id,
+ data_h data,
+ net_nfc_client_test_set_ee_data_completed callback,
+ void *user_data)
+{
+ TestFuncData *func_data;
+ GVariant *variant = NULL;
+
+ if (test_proxy == NULL)
+ return NET_NFC_UNKNOWN_ERROR;
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ func_data = g_new0(TestFuncData, 1);
+ func_data->callback = (gpointer)callback;
+ func_data->user_data = user_data;
+
+ variant = net_nfc_util_gdbus_data_to_variant((data_s *)data);
+
+ net_nfc_gdbus_test_call_set_ee_data(test_proxy,
+ mode,
+ reg_id,
+ variant,
+ net_nfc_client_gdbus_get_privilege(),
+ NULL,
+ test_call_set_ee_data_callback,
+ func_data);
+
+ return NET_NFC_OK;
+}
+
+API net_nfc_error_e net_nfc_client_test_set_ee_data_sync(int mode,
+ int reg_id,
+ data_h data)
+{
+ GVariant *variant = NULL;
+ GError *error = NULL;
+
+ net_nfc_error_e out_result = NET_NFC_OK;
+
+ if (test_proxy == NULL)
+ return NET_NFC_UNKNOWN_ERROR;
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ variant = net_nfc_util_gdbus_data_to_variant((data_s *)data);
+
+ if (net_nfc_gdbus_test_call_set_ee_data_sync(test_proxy,
+ mode,
+ reg_id,
+ variant,
+ net_nfc_client_gdbus_get_privilege(),
+ (gint *)&out_result,
+ NULL,
+ &error) == FALSE)
+ {
+ DEBUG_CLIENT_MSG("can not call SetEeTest: %s",
+ error->message);
+ g_error_free(error);
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ return out_result;
+}
+
+net_nfc_error_e net_nfc_client_test_init(void)
+{
+ GError *error = NULL;
+
+ if (test_proxy)
+ {
+ DEBUG_CLIENT_MSG("Already initialized");
+
+ return NET_NFC_OK;
+ }
+
+ test_proxy = net_nfc_gdbus_test_proxy_new_for_bus_sync(
+ G_BUS_TYPE_SYSTEM,
+ G_DBUS_PROXY_FLAGS_NONE,
+ "org.tizen.NetNfcService",
+ "/org/tizen/NetNfcService/Test",
+ NULL,
+ &error);
+
+ if (test_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not create proxy : %s", error->message);
+ g_error_free(error);
+
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ return NET_NFC_OK;
+}
+
+void net_nfc_client_test_deinit(void)
+{
+ if (test_proxy)
+ {
+ g_object_unref(test_proxy);
+ test_proxy = NULL;
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <string.h>
+
+#include "net_nfc_typedef_internal.h"
+#include "net_nfc_debug_internal.h"
+#include "net_nfc_util_internal.h"
+#include "net_nfc_util_gdbus_internal.h"
+#include "net_nfc_gdbus.h"
+#include "net_nfc_client.h"
+#include "net_nfc_client_manager.h"
+#include "net_nfc_client_tag_internal.h"
+#include "net_nfc_client_transceive.h"
+
+static NetNfcGDbusTransceive *transceive_proxy = NULL;
+
+static GVariant *transceive_data_to_transceive_variant(
+ net_nfc_target_type_e dev_type,
+ data_s *data);
+
+static void transceive_call(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data);
+
+static void transceive_data_call(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data);
+
+typedef struct _TransceiveFuncData TransceiveFuncData;
+
+struct _TransceiveFuncData
+{
+ gpointer transceive_send_callback;
+ gpointer transceive_send_data;
+};
+
+static GVariant *transceive_data_to_transceive_variant(
+ net_nfc_target_type_e devType,
+ data_s *data)
+{
+ GVariant *variant = NULL;
+ data_s transceive_info = {NULL,};
+
+ if (data == NULL)
+ {
+ DEBUG_ERR_MSG("data is empty");
+ return NULL;
+ }
+
+ switch (devType)
+ {
+ case NET_NFC_MIFARE_MINI_PICC :
+ case NET_NFC_MIFARE_1K_PICC :
+ case NET_NFC_MIFARE_4K_PICC :
+ case NET_NFC_MIFARE_ULTRA_PICC :
+ if(net_nfc_util_alloc_data(&transceive_info,
+ data->length + 2) == true)
+ {
+ memcpy(transceive_info.buffer,
+ data->buffer,
+ data->length);
+
+ net_nfc_util_compute_CRC(CRC_A,
+ transceive_info.buffer,
+ transceive_info.length);
+ }
+ break;
+
+ case NET_NFC_JEWEL_PICC :
+ if (data->length > 9)
+ {
+ DEBUG_ERR_MSG("data length is larger than 9");
+ return NULL;
+ }
+
+ if(net_nfc_util_alloc_data(&transceive_info, 9) == true)
+ {
+ memcpy(transceive_info.buffer,
+ data->buffer,
+ data->length);
+ net_nfc_util_compute_CRC(CRC_B,
+ transceive_info.buffer,
+ transceive_info.length);
+ }
+
+ break;
+
+ default :
+ if(net_nfc_util_alloc_data(&transceive_info,
+ data->length) == true)
+ {
+ memcpy(transceive_info.buffer,
+ data->buffer,
+ data->length);
+ }
+ break;
+ }
+
+ variant = net_nfc_util_gdbus_data_to_variant(&transceive_info);
+
+ net_nfc_util_free_data(&transceive_info);
+
+ return variant;
+}
+
+static void transceive_data_call(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ TransceiveFuncData *func_data;
+
+ net_nfc_error_e out_result = NET_NFC_OK;
+ GError *error = NULL;
+
+ GVariant *out_data = NULL;
+
+ data_s resp = {NULL,};
+
+ if(net_nfc_gdbus_transceive_call_transceive_data_finish(
+ NET_NFC_GDBUS_TRANSCEIVE(source_object),
+ (gint *)&out_result,
+ &out_data,
+ res,
+ &error) == FALSE)
+ {
+ out_result = NET_NFC_UNKNOWN_ERROR;
+
+ DEBUG_ERR_MSG("Can not finish transceive: %s", error->message);
+ g_error_free(error);
+ }
+
+ func_data = (TransceiveFuncData*) user_data;
+ if(func_data == NULL)
+ {
+ DEBUG_ERR_MSG("can not get TransceiveFuncData");
+ return;
+ }
+
+ if(func_data->transceive_send_callback == NULL)
+ {
+ DEBUG_CLIENT_MSG("callback function is not avaiilable");
+ g_free(func_data);
+ return;
+ }
+
+ net_nfc_util_gdbus_variant_to_data_s(out_data, &resp);
+
+ ((nfc_transceive_data_callback)func_data->transceive_send_callback)(
+ out_result,
+ &resp,
+ func_data->transceive_send_data);
+
+ net_nfc_util_free_data(&resp);
+
+ g_free(func_data);
+}
+
+static void transceive_call(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ TransceiveFuncData *func_data;
+
+ net_nfc_error_e out_result = NET_NFC_OK;
+ GError *error = NULL;
+
+ if(net_nfc_gdbus_transceive_call_transceive_finish(
+ NET_NFC_GDBUS_TRANSCEIVE(source_object),
+ (gint *)&out_result,
+ res,
+ &error) == FALSE)
+ {
+ out_result = NET_NFC_UNKNOWN_ERROR;
+
+ DEBUG_ERR_MSG("Can not finish transceive: %s", error->message);
+ g_error_free(error);
+ }
+
+ func_data = (TransceiveFuncData*) user_data;
+ if(func_data == NULL)
+ {
+ DEBUG_ERR_MSG("can not get TransceiveFuncData");
+ return;
+ }
+
+ if(func_data->transceive_send_callback == NULL)
+ {
+ DEBUG_CLIENT_MSG("callback function is not avaiilable");
+ g_free(func_data);
+ return;
+ }
+
+ ((nfc_transceive_callback)func_data->transceive_send_callback)(
+ out_result,
+ func_data->transceive_send_data);
+
+ g_free(func_data);
+}
+
+API net_nfc_error_e net_nfc_client_transceive(net_nfc_target_handle_h handle,
+ data_h rawdata,
+ nfc_transceive_callback callback,
+ void *user_data)
+{
+ net_nfc_target_info_s *target_info = NULL;
+ data_s *data = (data_s *)rawdata;
+
+ GVariant *arg_data = NULL;
+ TransceiveFuncData *funcdata = NULL;
+
+ if (transceive_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not get TransceiveProxy");
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ DEBUG_CLIENT_MSG("send reqeust :: transceive = [%p]", handle);
+
+ if (handle == NULL || rawdata == NULL)
+ return NET_NFC_NULL_PARAMETER;
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ if (net_nfc_client_tag_is_connected() == FALSE)
+ return NET_NFC_OPERATION_FAIL;
+
+ /* fill trans information struct */
+ target_info = net_nfc_client_tag_get_client_target_info();
+
+ if (target_info == NULL)
+ return NET_NFC_OPERATION_FAIL;
+
+ arg_data = transceive_data_to_transceive_variant(target_info->devType,
+ data);
+ if (arg_data == NULL)
+ return NET_NFC_OPERATION_FAIL;
+
+ funcdata = g_new0(TransceiveFuncData, 1);
+
+ funcdata->transceive_send_callback = (gpointer)callback;
+ funcdata->transceive_send_data = user_data;
+
+ net_nfc_gdbus_transceive_call_transceive(transceive_proxy,
+ GPOINTER_TO_UINT(handle),
+ target_info->devType,
+ arg_data,
+ net_nfc_client_gdbus_get_privilege(),
+ NULL,
+ transceive_call,
+ funcdata);
+
+ return NET_NFC_OK;
+}
+
+API net_nfc_error_e net_nfc_client_transceive_data(net_nfc_target_handle_h handle,
+ data_h rawdata,
+ nfc_transceive_data_callback callback,
+ void *user_data)
+{
+ net_nfc_target_info_s *target_info = NULL;
+ data_s *data = (data_s *)rawdata;
+
+ GVariant *arg_data = NULL;
+ TransceiveFuncData *funcdata = NULL;
+
+ if (transceive_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not get TransceiveProxy");
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ DEBUG_CLIENT_MSG("send reqeust :: transceive = [%p]", handle);
+
+ if (handle == NULL || rawdata == NULL)
+ return NET_NFC_NULL_PARAMETER;
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ if (net_nfc_client_tag_is_connected() == FALSE)
+ return NET_NFC_OPERATION_FAIL;
+
+ /* fill trans information struct */
+ target_info = net_nfc_client_tag_get_client_target_info();
+
+ if (target_info == NULL)
+ return NET_NFC_OPERATION_FAIL;
+
+ arg_data = transceive_data_to_transceive_variant(target_info->devType,
+ data);
+ if (arg_data == NULL)
+ return NET_NFC_OPERATION_FAIL;
+
+ funcdata = g_new0(TransceiveFuncData, 1);
+
+ funcdata->transceive_send_callback = (gpointer)callback;
+ funcdata->transceive_send_data = user_data;
+
+ net_nfc_gdbus_transceive_call_transceive_data(transceive_proxy,
+ GPOINTER_TO_UINT(handle),
+ target_info->devType,
+ arg_data,
+ net_nfc_client_gdbus_get_privilege(),
+ NULL,
+ transceive_data_call,
+ funcdata);
+
+ return NET_NFC_OK;
+}
+
+API net_nfc_error_e net_nfc_client_transceive_sync(net_nfc_target_handle_h handle,
+ data_h rawdata)
+{
+ net_nfc_target_info_s *target_info = NULL;
+ data_s *data = (data_s *)rawdata;
+
+ GError *error = NULL;
+ GVariant *arg_data = NULL;
+
+ net_nfc_error_e out_result;
+
+ if (transceive_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not get TransceiveProxy");
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ DEBUG_CLIENT_MSG("send reqeust :: transceive = [%p]", handle);
+
+ if (handle == NULL || rawdata == NULL)
+ return NET_NFC_NULL_PARAMETER;
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ if (net_nfc_client_tag_is_connected() == FALSE)
+ return NET_NFC_OPERATION_FAIL;
+
+ /* fill trans information struct */
+ target_info = net_nfc_client_tag_get_client_target_info();
+
+ if (target_info == NULL)
+ return NET_NFC_OPERATION_FAIL;
+
+ arg_data = transceive_data_to_transceive_variant(target_info->devType,
+ data);
+ if (arg_data == NULL)
+ return NET_NFC_OPERATION_FAIL;
+
+ if(net_nfc_gdbus_transceive_call_transceive_sync(transceive_proxy,
+ GPOINTER_TO_UINT(handle),
+ target_info->devType,
+ arg_data,
+ net_nfc_client_gdbus_get_privilege(),
+ (gint *)&out_result,
+ NULL,
+ &error) == FALSE)
+ {
+ DEBUG_ERR_MSG("Transceive (sync call) failed: %s",
+ error->message);
+
+ g_error_free(error);
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ return out_result;
+}
+
+API net_nfc_error_e net_nfc_client_transceive_data_sync(
+ net_nfc_target_handle_h handle,
+ data_h rawdata,
+ data_h *response)
+{
+ net_nfc_target_info_s *target_info = NULL;
+ data_s *data = (data_s *)rawdata;
+
+ GError *error = NULL;
+ GVariant *arg_data = NULL;
+ GVariant *out_data = NULL;
+
+ net_nfc_error_e out_result = NET_NFC_OK;
+
+ if (transceive_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not get TransceiveProxy");
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ DEBUG_CLIENT_MSG("send reqeust :: transceive = [%p]", handle);
+
+ if (handle == NULL || rawdata == NULL)
+ return NET_NFC_NULL_PARAMETER;
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ if (net_nfc_client_tag_is_connected() == FALSE)
+ return NET_NFC_OPERATION_FAIL;
+
+ /* fill trans information struct */
+ target_info = net_nfc_client_tag_get_client_target_info();
+
+ if (target_info == NULL)
+ return NET_NFC_OPERATION_FAIL;
+
+ arg_data = transceive_data_to_transceive_variant(target_info->devType,
+ data);
+ if (arg_data == NULL)
+ return NET_NFC_OPERATION_FAIL;
+
+ if (net_nfc_gdbus_transceive_call_transceive_data_sync(
+ transceive_proxy,
+ GPOINTER_TO_UINT(handle),
+ target_info->devType,
+ arg_data,
+ net_nfc_client_gdbus_get_privilege(),
+ (gint *)&out_result,
+ &out_data,
+ NULL,
+ &error) == FALSE)
+ {
+ DEBUG_ERR_MSG("Transceive (sync call) failed: %s",
+ error->message);
+ g_error_free(error);
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ if (response && out_data != NULL)
+ {
+ *response = net_nfc_util_gdbus_variant_to_data(out_data);
+ }
+
+ return out_result;
+}
+
+
+net_nfc_error_e net_nfc_client_transceive_init(void)
+{
+ GError *error = NULL;
+
+ if (transceive_proxy)
+ {
+ DEBUG_CLIENT_MSG("Already initialized");
+
+ return NET_NFC_OK;
+ }
+
+ transceive_proxy = net_nfc_gdbus_transceive_proxy_new_for_bus_sync(
+ G_BUS_TYPE_SYSTEM,
+ G_DBUS_PROXY_FLAGS_NONE,
+ "org.tizen.NetNfcService",
+ "/org/tizen/NetNfcService/Transceive",
+ NULL,
+ &error);
+ if (transceive_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not create proxy : %s", error->message);
+ g_error_free(error);
+
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ return NET_NFC_OK;
+}
+
+void net_nfc_client_transceive_deinit(void)
+{
+ if(transceive_proxy)
+ {
+ g_object_unref(transceive_proxy);
+ transceive_proxy = NULL;
+ }
+}
--- /dev/null
+prefix=@PREFIX@
+exec_prefix=${prefix}/bin
+libdir=@LIB_INSTALL_DIR@
+includedir=@INCLUDE_INSTALL_DIR@/@NFC_CLIENT@
+
+Name: @NFC_CLIENT@
+Description: NFC
+Version: @FULLVER@
+Requires: glib-2.0
+Libs: -L${libdir} -l@NFC_CLIENT@
+Cflags: -I${includedir}
--- /dev/null
+INCLUDE_DIRECTORIES(include)
+
+SET(NFC_COMMON "nfc-common")
+
+FIND_PROGRAM(GDBUS_CODEGEN NAMES gdbus-codegen)
+EXEC_PROGRAM(${GDBUS_CODEGEN} ARGS
+ " --generate-c-code ${CMAKE_CURRENT_SOURCE_DIR}/net_nfc_gdbus"
+ " --c-namespace NetNfcGDbus"
+ " --interface-prefix org.tizen.NetNfcService."
+ " ${CMAKE_CURRENT_SOURCE_DIR}/net_nfc.xml"
+)
+
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} COMMON_SRCS)
+
+pkg_check_modules(common_pkgs REQUIRED glib-2.0 gio-2.0 gio-unix-2.0 dlog bluetooth-api
+ libssl)
+
+SET(EXTRA_CFLAGS "-fPIC -Wall -Werror-implicit-function-declaration")
+
+FOREACH(flag ${common_pkgs_CFLAGS})
+ SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+
+ADD_LIBRARY(${NFC_COMMON} SHARED ${COMMON_SRCS})
+SET_TARGET_PROPERTIES(${NFC_COMMON} PROPERTIES VERSION ${FULLVER} SOVERSION ${MAJORVER})
+TARGET_LINK_LIBRARIES(${NFC_COMMON} ${common_pkgs_LDFLAGS})
+
+FILE(GLOB COMMON_HEADER include/*.h)
+
+CONFIGURE_FILE(${NFC_COMMON}.pc.in ${NFC_COMMON}.pc @ONLY)
+INSTALL(FILES ${NFC_COMMON}.pc DESTINATION lib/pkgconfig)
+
+INSTALL(TARGETS ${NFC_COMMON} DESTINATION lib)
+
+FOREACH(hfile ${COMMON_HEADER})
+ INSTALL(FILES ${hfile} DESTINATION include/${NFC_COMMON})
+ENDFOREACH(hfile)
+
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_OEM_CONTROLLER_H__
+#define __NET_NFC_OEM_CONTROLLER_H__
+
+#include "net_nfc_typedef_internal.h"
+
+typedef bool (*net_nfc_oem_controller_init)(net_nfc_error_e *result);
+typedef bool (*net_nfc_oem_controller_deinit)(void);
+typedef bool (*net_nfc_oem_controller_register_listener)(target_detection_listener_cb target_detection_listener, se_transaction_listener_cb se_transaction_listener, llcp_event_listener_cb llcp_event_listener, net_nfc_error_e *result);
+typedef bool (*net_nfc_oem_controller_unregister_listener)(void);
+typedef bool (*net_nfc_oem_controller_support_nfc)(net_nfc_error_e *result);
+typedef bool (*net_nfc_oem_controller_get_firmware_version)(data_s **data, net_nfc_error_e *result);
+typedef bool (*net_nfc_oem_controller_check_firmware_version)(net_nfc_error_e *result);
+typedef bool (*net_nfc_oem_controller_update_firmware)(net_nfc_error_e *result);
+typedef bool (*net_nfc_oem_controller_get_stack_information)(net_nfc_stack_information_s *stack_info, net_nfc_error_e *result);
+typedef bool (*net_nfc_oem_controller_configure_discovery)(net_nfc_discovery_mode_e mode, net_nfc_event_filter_e config, net_nfc_error_e *result);
+typedef bool (*net_nfc_oem_controller_exception_handler)(void);
+
+/* tag api */
+typedef bool (*net_nfc_oem_controller_connect)(net_nfc_target_handle_s *handle, net_nfc_error_e *result);
+typedef bool (*net_nfc_oem_controller_disconnect)(net_nfc_target_handle_s *handle, net_nfc_error_e *result);
+typedef bool (*net_nfc_oem_controller_check_target_presence)(net_nfc_target_handle_s *handle, net_nfc_error_e *result);
+typedef bool (*net_nfc_oem_controller_check_ndef)(net_nfc_target_handle_s *handle, uint8_t *ndef_card_state, int *max_data_size, int *real_data_size, net_nfc_error_e *result);
+typedef bool (*net_nfc_oem_controller_read_ndef)(net_nfc_target_handle_s *handle, data_s **data, net_nfc_error_e *result);
+typedef bool (*net_nfc_oem_controller_write_ndef)(net_nfc_target_handle_s *handle, data_s *data, net_nfc_error_e *result);
+typedef bool (*net_nfc_oem_controller_make_read_only_ndef)(net_nfc_target_handle_s *handle, net_nfc_error_e *result);
+typedef bool (*net_nfc_oem_controller_format_ndef)(net_nfc_target_handle_s *handle, data_s *secure_key, net_nfc_error_e *result);
+typedef bool (*net_nfc_oem_controller_transceive)(net_nfc_target_handle_s *handle, net_nfc_transceive_info_s *info, data_s **data, net_nfc_error_e *result);
+typedef bool (*net_nfc_oem_controller_is_ready)(net_nfc_error_e *result);
+
+/* llcp api */
+typedef bool (*net_nfc_oem_controller_llcp_config)(net_nfc_llcp_config_info_s *config, net_nfc_error_e *result);
+typedef bool (*net_nfc_oem_controller_llcp_check_llcp)(net_nfc_target_handle_s *handle, net_nfc_error_e *result);
+typedef bool (*net_nfc_oem_controller_llcp_activate_llcp)(net_nfc_target_handle_s *handle, net_nfc_error_e *result);
+typedef bool (*net_nfc_oem_controller_llcp_create_socket)(net_nfc_llcp_socket_t *socket, net_nfc_socket_type_e socketType, uint16_t miu, uint8_t rw, net_nfc_error_e *result, void *user_param);
+typedef bool (*net_nfc_oem_controller_llcp_bind)(net_nfc_llcp_socket_t socket, uint8_t service_access_point, net_nfc_error_e *result);
+typedef bool (*net_nfc_oem_controller_llcp_listen)(net_nfc_target_handle_s *handle, uint8_t *service_access_name, net_nfc_llcp_socket_t socket, net_nfc_error_e *result, void *user_param);
+typedef bool (*net_nfc_oem_controller_llcp_accept)(net_nfc_llcp_socket_t socket, net_nfc_error_e *result, void *user_param);
+typedef bool (*net_nfc_oem_controller_llcp_connect_by_url)(net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, uint8_t *service_access_name, net_nfc_error_e *result, void *user_param);
+typedef bool (*net_nfc_oem_controller_llcp_connect)(net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, uint8_t service_access_point, net_nfc_error_e *result, void *user_param);
+typedef bool (*net_nfc_oem_controller_llcp_disconnect)(net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, net_nfc_error_e *result, void *user_param);
+typedef bool (*net_nfc_oem_controller_llcp_socket_close)(net_nfc_llcp_socket_t socket, net_nfc_error_e *result);
+typedef bool (*net_nfc_oem_controller_llcp_recv)(net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, data_s *data, net_nfc_error_e *result, void *user_param);
+typedef bool (*net_nfc_oem_controller_llcp_send)(net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, data_s *data, net_nfc_error_e *result, void *user_param);
+typedef bool (*net_nfc_oem_controller_llcp_recv_from)(net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, data_s *data, net_nfc_error_e *result, void *user_param);
+typedef bool (*net_nfc_oem_controller_llcp_send_to)(net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, data_s *data, uint8_t service_access_point, net_nfc_error_e *result, void *user_param);
+typedef bool (*net_nfc_oem_controller_llcp_reject)(net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, net_nfc_error_e *result);
+typedef bool (*net_nfc_oem_controller_llcp_get_remote_config)(net_nfc_target_handle_s *handle, net_nfc_llcp_config_info_s *config, net_nfc_error_e *result);
+typedef bool (*net_nfc_oem_controller_llcp_get_remote_socket_info)(net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, net_nfc_llcp_socket_option_s *option, net_nfc_error_e *result);
+
+/* secure element api */
+typedef bool (*net_nfc_oem_controller_get_secure_element_list)(net_nfc_secure_element_info_s *list, int* count, net_nfc_error_e *result);
+typedef bool (*net_nfc_oem_controller_set_secure_element_mode)(net_nfc_secure_element_type_e element_type, net_nfc_secure_element_mode_e mode, net_nfc_error_e *result);
+typedef bool (*net_nfc_oem_controller_secure_element_open)(net_nfc_secure_element_type_e element_type, net_nfc_target_handle_s **handle, net_nfc_error_e *result);
+typedef bool (*net_nfc_oem_controller_secure_element_get_atr)(net_nfc_target_handle_s *handle, data_s **atr, net_nfc_error_e *result);
+typedef bool (*net_nfc_oem_controller_secure_element_send_apdu)(net_nfc_target_handle_s *handle, data_s *command, data_s **response, net_nfc_error_e *result);
+typedef bool (*net_nfc_oem_controller_secure_element_close)(net_nfc_target_handle_s *handle, net_nfc_error_e *result);
+
+/* test api */
+typedef bool (*net_nfc_oem_controller_sim_test)(net_nfc_error_e *result);
+typedef bool (*net_nfc_oem_controller_prbs_test)(net_nfc_error_e *result , int tech , int rate);
+typedef bool (*net_nfc_oem_controller_test_mode_on)(net_nfc_error_e *result);
+typedef bool (*net_nfc_oem_controller_test_mode_off)(net_nfc_error_e *result);
+typedef bool (*net_nfc_oem_controller_eedata_register_set)(net_nfc_error_e *result , uint32_t mode , uint32_t reg_id , data_s *data);
+
+typedef struct _net_nfc_oem_interface_s
+{
+ net_nfc_oem_controller_init init;
+ net_nfc_oem_controller_deinit deinit;
+ net_nfc_oem_controller_register_listener register_listener;
+ net_nfc_oem_controller_unregister_listener unregister_listener;
+ net_nfc_oem_controller_get_firmware_version get_firmware_version;
+ net_nfc_oem_controller_check_firmware_version check_firmware_version;
+ net_nfc_oem_controller_update_firmware update_firmeware;
+ net_nfc_oem_controller_get_stack_information get_stack_information;
+ net_nfc_oem_controller_configure_discovery configure_discovery;
+ net_nfc_oem_controller_get_secure_element_list get_secure_element_list;
+ net_nfc_oem_controller_set_secure_element_mode set_secure_element_mode;
+ net_nfc_oem_controller_connect connect;
+ net_nfc_oem_controller_connect disconnect;
+ net_nfc_oem_controller_check_ndef check_ndef;
+ net_nfc_oem_controller_check_target_presence check_presence;
+ net_nfc_oem_controller_read_ndef read_ndef;
+ net_nfc_oem_controller_write_ndef write_ndef;
+ net_nfc_oem_controller_make_read_only_ndef make_read_only_ndef;
+ net_nfc_oem_controller_transceive transceive;
+ net_nfc_oem_controller_format_ndef format_ndef;
+ net_nfc_oem_controller_exception_handler exception_handler;
+ net_nfc_oem_controller_is_ready is_ready;
+
+ net_nfc_oem_controller_llcp_config config_llcp;
+ net_nfc_oem_controller_llcp_check_llcp check_llcp_status;
+ net_nfc_oem_controller_llcp_activate_llcp activate_llcp;
+ net_nfc_oem_controller_llcp_create_socket create_llcp_socket;
+ net_nfc_oem_controller_llcp_bind bind_llcp_socket;
+ net_nfc_oem_controller_llcp_listen listen_llcp_socket;
+ net_nfc_oem_controller_llcp_accept accept_llcp_socket;
+ net_nfc_oem_controller_llcp_connect_by_url connect_llcp_by_url;
+ net_nfc_oem_controller_llcp_connect connect_llcp;
+ net_nfc_oem_controller_llcp_disconnect disconnect_llcp;
+ net_nfc_oem_controller_llcp_socket_close close_llcp_socket;
+ net_nfc_oem_controller_llcp_recv recv_llcp;
+ net_nfc_oem_controller_llcp_send send_llcp;
+ net_nfc_oem_controller_llcp_recv_from recv_from_llcp;
+ net_nfc_oem_controller_llcp_send_to send_to_llcp;
+ net_nfc_oem_controller_llcp_reject reject_llcp;
+ net_nfc_oem_controller_llcp_get_remote_config get_remote_config;
+ net_nfc_oem_controller_llcp_get_remote_socket_info get_remote_socket_info;
+
+ net_nfc_oem_controller_sim_test sim_test;
+ net_nfc_oem_controller_prbs_test prbs_test;
+ net_nfc_oem_controller_test_mode_on test_mode_on;
+ net_nfc_oem_controller_test_mode_off test_mode_off;
+
+ net_nfc_oem_controller_support_nfc support_nfc;
+ net_nfc_oem_controller_eedata_register_set eedata_register_set;
+
+ net_nfc_oem_controller_secure_element_open secure_element_open;
+ net_nfc_oem_controller_secure_element_get_atr secure_element_get_atr;
+ net_nfc_oem_controller_secure_element_send_apdu secure_element_send_apdu;
+ net_nfc_oem_controller_secure_element_close secure_element_close;
+} net_nfc_oem_interface_s;
+
+#endif //__NET_NFC_OEM_CONTROLLER_H__
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_TYPEDEF_H__
+#define __NET_NFC_TYPEDEF_H__
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stddef.h>
+#include <stdint.h>
+#include <stdbool.h>
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+/**
+ NFC Manager
+ NFC Manager controls the nfc device with high level APIs such as SmartPoster and Connection handover.
+ It also support the JSR257 push handling.
+ This file describe the structure and defines of the NFC manager
+
+ @version 0.1
+
+ */
+
+/**
+ @defgroup NET_NFC_MANAGER The description of NFC Manager
+ @defgroup NET_NFC_TYPEDEF Defines and structures
+ @defgroup NET_NFC_MANAGER_API NFC Manager
+ @defgroup NET_NFC_MANAGER_INFO Tag Information and data APIs
+ @defgroup NET_NFC_MANAGER_TAG Tag Read/Write APIs
+ @defgroup NET_NFC_MANAGER_NDEF NDEF Message APIs
+ @defgroup NET_NFC_MANAGER_RECORD NDEF Record APIs
+ @defgroup NET_NFC_MANAGER_LLCP NFC LLCP APIs
+ @defgroup NET_NFC_MANAGER_APDU Internal APDU APIs
+ @defgroup NET_NFC_MANAGER_EXCHANGE App Exchanger APIs
+
+
+ @addtogroup NET_NFC_MANAGER
+ @{
+ <P> "NFC Manager" is the framework that provide NFC APIs,
+ and it also provide high level services such as Smart Poster, Connection Handover,
+ and JSR257 push registry. </P>
+
+ NFC Manager APIs are defined in <net_nfc.h>, <net_nfc_typedef.h>
+
+ <P>
+ Memory management rules <br>
+ depends on the the verb of each function it describe memory management roles
+
+ 1. set: copy the parameters and used inside of nfc-manager, you should free the parameter you have used
+ 2. append: it is similar to "set" but, it does not make copy, you SHOULD NOT free the parameter after use it belongs to nfc-manager and it will be freed later
+ (example "net_nfc_append_record_to_ndef_message") the appended record will be free the at the ndef message free time.
+ 3. get, search : it gives original pointer to you, DO NOT free the pointer get from nfc-manager API
+ 4. remove: automatically free inside of the this function do not free again.
+ 5. create: it allocate handle, therefore, you should consider free after using (for example "net_nfc_create_rawdata_from_ndef_message(ndef_message_h ndef_message, data_h *rawdata)"
+ this function allocate the data_h, you should free data with the function net_nfc_free_data())
+ </p>
+
+ @}
+ */
+
+/**
+ @addtogroup NET_NFC_TYPEDEF
+ @{
+ This documents provide the NFC defines
+
+ */
+
+/**
+ net_nfc_error_e is enum type that returned from each functions
+ it mostly contains the error codes and it may contains status codes.
+ */
+typedef enum
+{
+/*000*/NET_NFC_OK = 0, /**< Status is OK */
+/*999*/NET_NFC_UNKNOWN_ERROR = -999, /**< Unknown error */
+/*998*/NET_NFC_ALLOC_FAIL, /**< Memory allocation is failed */
+/*997*/NET_NFC_THREAD_CREATE_FAIL, /**< Thread creation is failed */
+/*996*/NET_NFC_INVALID_STATE, /**< State of NFC-Manager or nfc-stack is not normal */
+/*995*/NET_NFC_IPC_FAIL, /**< Communication with ipc is failed. (from client to server)*/
+/*994*/NET_NFC_OUT_OF_BOUND, /**< Index is out of bound */
+/*993*/NET_NFC_NULL_PARAMETER, /**< Unexpected NULL parameter is received */
+/*992*/NET_NFC_BUFFER_TOO_SMALL, /**< Requested buffer is too small to store data, this error should be received */
+/*991*/NET_NFC_ALREADY_INITIALIZED, /**< You tried to initialized again without de-init */
+/*990*/NET_NFC_COMMUNICATE_WITH_CONTROLLER_FAILED, /**< Communication with Controller Chipset is failed this is Fatal Error */
+/*989*/NET_NFC_RF_TIMEOUT, /**< Timeout is raised while communicate with a tag */
+/*988*/NET_NFC_RF_ERROR, /**< Unexpected package is received from target, you may receive this error comes by the low level RF communication fault*/
+/*987*/NET_NFC_NOT_INITIALIZED, /**< Application tries to request without initialization */
+/*986*/NET_NFC_NOT_SUPPORTED, /**< Request information or command is not supported in current connected target */
+/*985*/NET_NFC_ALREADY_REGISTERED, /**< Requested SAP number is already used by other socket or data is already appended or registered */
+/*984*/NET_NFC_NOT_ALLOWED_OPERATION, /**< Requested Operation is not allowed in the situation in critical time (such as write data on target)*/
+/*983*/NET_NFC_BUSY, /**< Previous operation is not finished. don't worry to get this message, most of request will be executed in the serial queue */
+/*982*/NET_NFC_INVALID_HANDLE, /**< Requested Device in not valid device */
+/*981*/NET_NFC_TAG_READ_FAILED, /**< Tag reading is failed because of unexpected chunk data is received or error ack is received */
+/*980*/NET_NFC_TAG_WRITE_FAILED, /**< When you try to write on read only tag or error ack is received */
+/*979*/NET_NFC_NO_NDEF_SUPPORT, /**< Tag is not supported NDEF format for tag is not formatted for NDEF */
+/*978*/NET_NFC_NO_NDEF_MESSAGE, /**< No data is received after NDEF reading */
+/*977*/NET_NFC_INVALID_FORMAT, /**< Received data is not readable or it has illegal values or format */
+/*976*/NET_NFC_INSUFFICIENT_STORAGE, /**< The connected tag does not have enough information */
+/*975*/NET_NFC_OPERATION_FAIL, /**< The remote target returned error while doing a operation*/
+/*974*/NET_NFC_NOT_CONNECTED, /**< remote is not connected correctly. This can be happened when the RF does not have enough strength */
+/*973*/NET_NFC_NO_DATA_FOUND, /**< Requested data is not found in the list or properties */
+/*972*/NET_NFC_SECURITY_FAIL, /**< Authentication is failed while communication with nfc-manager server */
+/*971*/NET_NFC_TARGET_IS_MOVED_AWAY, /**< Target is lost while doing a operation */
+/*970*/NET_NFC_TAG_IS_ALREADY_FORMATTED, /** Target is already formatted */
+/*969*/NET_NFC_NOT_REGISTERED, /**< removal is requested but requested data is not registered */
+/*968*/NET_NFC_INVALID_PARAM, /**< removal is requested but requested data is not registered */
+/*499*/NET_NFC_NDEF_TYPE_LENGTH_IS_NOT_OK = -499, /**< Illegal ndef record type length */
+/*498*/NET_NFC_NDEF_PAYLOAD_LENGTH_IS_NOT_OK, /**< Illegal ndef record payload length */
+/*497*/NET_NFC_NDEF_ID_LENGTH_IS_NOT_OK, /**< Illegal ndef record id length */
+/*496*/NET_NFC_NDEF_RECORD_IS_NOT_EXPECTED_TYPE, /**< Parameter record is not expected record. for example, try to URI from text record */
+/*495*/NET_NFC_NDEF_BUF_END_WITHOUT_ME, /**< NDEF messages is terminated without ME flag */
+/*494*/NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC, /**< Current device does not support NFC feature or this manager does not found plugin library */
+
+/*399*/NET_NFC_LLCP_INVALID_SOCKET = -399, /**< socket is not valid socket */
+/*398*/NET_NFC_LLCP_SOCKET_DISCONNECTED, /**< socket is disconnected */
+/*397*/NET_NFC_LLCP_SOCKET_FRAME_REJECTED, /**< send data is rejected from remote side */
+
+/*299*/NET_NFC_P2P_SEND_FAIL = -299, /**< P2P data send fail */
+} net_nfc_error_e;
+
+/**
+ Enum value of the record type ( TNF value )
+ */
+typedef enum
+{
+ NET_NFC_RECORD_EMPTY = 0x0,
+ NET_NFC_RECORD_WELL_KNOWN_TYPE,
+ NET_NFC_RECORD_MIME_TYPE, // Media type
+ NET_NFC_RECORD_URI,
+ NET_NFC_RECORD_EXTERNAL_RTD,
+ NET_NFC_RECORD_UNKNOWN,
+ NET_NFC_RECORD_UNCHAGNED,
+} net_nfc_record_tnf_e;
+
+/**
+ net_nfc_message_e is identify the events comes from nfc-manager.
+ most of the events response event that you requested operations.
+ and some of the events are generated by nfc-manager. (example, NET_NFC_MESSAGE_TAG_DISCOVERED, NET_NFC_MESSAGE_TAG_DETACHED,
+ NET_NFC_MESSAGE_LLCP_DISCOVERED and NET_NFC_MESSAGE_LLCP_DETACHED)
+
+ All of the events are delivered by the the callback function that registered with "net_nfc_set_response_callback"
+ */
+
+typedef enum
+{
+ NET_NFC_MESSAGE_TRANSCEIVE = 0, /**< Type: Response Event, <br> This events is received after calling the "net_nfc_tranceive"
+ <br> if the operation is success, the data parameter should cast into data_h or it return NULL*/
+ NET_NFC_MESSAGE_READ_NDEF, /**< Type: Response Event, <br> This events is received after calling the "net_nfc_read_tag"
+ <br> if the operation is success, the data parameter should cast into ndef_message_h or it return NULL */
+ NET_NFC_MESSAGE_WRITE_NDEF, /**< Type: Response Event, <br> This events is received after calling the "net_nfc_write_ndef"
+ <br> data pointer always returns NULL */
+ NET_NFC_MESSAGE_MAKE_READ_ONLY_NDEF, /**< Type: Response Event, <br> This events is received after calling the "net_nfc_make_read_only_ndef"
+ <br> data pointer always returns NULL */
+ NET_NFC_MESSAGE_IS_TAG_CONNECTED, /**< Type: Response Event, <br> This events is received after calling the "net_nfc_is_tag_conneced"
+ <br> data pointer always returns NULL */
+ NET_NFC_MESSAGE_GET_CURRENT_TAG_INFO, /**< Type: Response Event, <br> This events is received after calling the "net_nfc_get_current_tag_infof"
+ <br> if the operation is success, the data parameter should cast into net_nfc_target_info_h or it return NULL */
+ NET_NFC_MESSAGE_GET_CURRENT_TARGET_HANDLE, /**< Type: Response Event, <br> This events is received after calling the "net_nfc_get_current_target_handle"
+ <br> if the operation is success, the data parameter should cast into net_nfc_target_handle_h or it return NULL */
+ NET_NFC_MESSAGE_TAG_DISCOVERED, /**< Type: Notify Event, <br> When a tag or SE is detected, you got this event.
+ <br> The data contains the target info , need to cast to net_nfc_target_info_h*/
+ NET_NFC_MESSAGE_NOTIFY, /**< This Notify Event <br> when the unexpected error has occurred, this event is delivered. data pointer always returns NULL */
+ NET_NFC_MESSAGE_TAG_DETACHED, /**< Type: Notify Event, <br> When a tag or SE is disappeared, you got this event.
+ <br> The data contains the target info , need to cast to net_nfc_target_info_h but it does not have detail target info
+ <br> please, do not use "net_nfc_get_tag_info_keys" when you got this event*/
+/*10*/ NET_NFC_MESSAGE_FORMAT_NDEF, /**< Type: Response Event <br> After complete "net_nfc_format_ndef", this event is delivered */
+ NET_NFC_MESSAGE_LLCP_DISCOVERED,/**< Type: Notify Event <br> When LLCP is discovered and remote device is support llcp, you receive this event
+ <br> data pointer contains the remote llcp configuration info. Cast to net_nfc_llcp_config_info_h*/
+ NET_NFC_MESSAGE_P2P_DETACHED, /**< Type: Notify Event <br> When LLCP is de-activated by removing the device, you receive this event*/
+ NET_NFC_MESSAGE_LLCP_CONFIG, /**< Type: Response Event. <br> The operation of "net_nfc_set_llcp_local_configure" is completed */
+
+ NET_NFC_MESSAGE_P2P_DISCOVERED, /**< Type: Notify Event <br> The remove device is detected and ready for transferring data to remote side */
+ NET_NFC_MESSAGE_P2P_SEND, /**< Type: Response Event, <br> This events is received after calling the "net_nfc_send_exchanger_data" */
+ NET_NFC_MESSAGE_P2P_RECEIVE, /**< Type: Notify Event, <br> When llcp server socket receive some data, this event is delivered. */
+
+ NET_NFC_MESSAGE_SE_START_TRANSACTION, /**< Type: Notify Event, indicates external reader start transaction*/
+ NET_NFC_MESSAGE_SE_END_TRANSACTION, /**< Type: Notify Event, indicates external reader end transaction*/
+ NET_NFC_MESSAGE_SE_TYPE_TRANSACTION, /**< Type: Notify Event, Indicates external reader trying to access secure element */
+/*20*/ NET_NFC_MESSAGE_SE_CONNECTIVITY, /**< Type: Notify Event, This event notifies the terminal host that it shall send a connectivity event from UICC */
+ NET_NFC_MESSAGE_SE_FIELD_ON, /**< Type: Notify Event, indicates external reader field is on*/
+ NET_NFC_MESSAGE_SE_FIELD_OFF, /**< Type: Notify Event, indicates external reader field is off*/
+ NET_NFC_MESSAGE_SE_TYPE_CHANGED, /**< Type: Notify Event, indicates secure element type is changed*/
+
+ NET_NFC_MESSAGE_CONNECTION_HANDOVER, /**< Type: Response Event. <br> The result of connection handover. If it has been completed successfully, this event will include the information of alternative carrier. */
+
+ NET_NFC_MESSAGE_SET_SE,
+ NET_NFC_MESSAGE_GET_SE,
+ NET_NFC_MESSAGE_OPEN_INTERNAL_SE,
+ NET_NFC_MESSAGE_CLOSE_INTERNAL_SE,
+ NET_NFC_MESSAGE_SEND_APDU_SE,
+/*30*/ NET_NFC_MESSAGE_GET_ATR_SE,
+ NET_NFC_GET_SERVER_STATE,
+
+ NET_NFC_MESSAGE_SIM_TEST,
+
+ NET_NFC_MESSAGE_INIT,
+ NET_NFC_MESSAGE_DEINIT,
+
+ NET_NFC_MESSAGE_PRBS_TEST,
+
+ NET_NFC_MESSAGE_GET_FIRMWARE_VERSION,
+
+ NET_NFC_MESSAGE_SET_EEDATA,
+
+ NET_NFC_MESSAGE_SNEP_START_SERVER,
+ NET_NFC_MESSAGE_SNEP_START_CLIENT,
+/*40*/ NET_NFC_MESSAGE_SNEP_REQUEST,
+ NET_NFC_MESSAGE_SNEP_STOP_SERVICE,
+ NET_NFC_MESSAGE_SNEP_REGISTER_SERVER,
+ NET_NFC_MESSAGE_SNEP_UNREGISTER_SERVER,
+
+ NET_NFC_MESSAGE_CONNECT,
+ NET_NFC_MESSAGE_DISCONNECT,
+ NET_NFC_MESSAGE_SET_CARD_EMULATION,
+} net_nfc_message_e;
+
+typedef enum
+{
+ NET_NFC_UNKNOWN_TARGET = 0x00U,
+
+ /* Specific PICC Devices */
+
+ NET_NFC_GENERIC_PICC,
+ NET_NFC_ISO14443_A_PICC,
+ NET_NFC_ISO14443_4A_PICC,
+ NET_NFC_ISO14443_3A_PICC,
+ NET_NFC_MIFARE_MINI_PICC,
+ NET_NFC_MIFARE_1K_PICC,
+ NET_NFC_MIFARE_4K_PICC,
+ NET_NFC_MIFARE_ULTRA_PICC,
+ NET_NFC_MIFARE_DESFIRE_PICC,
+ NET_NFC_ISO14443_B_PICC,
+ NET_NFC_ISO14443_4B_PICC,
+ NET_NFC_ISO14443_BPRIME_PICC,
+ NET_NFC_FELICA_PICC,
+ NET_NFC_JEWEL_PICC,
+ NET_NFC_ISO15693_PICC,
+
+ /* NFC-IP1 Device Types */
+ NET_NFC_NFCIP1_TARGET,
+ NET_NFC_NFCIP1_INITIATOR,
+
+} net_nfc_target_type_e;
+
+/**
+ Card states for nfc tag
+ */
+typedef enum
+{
+ NET_NFC_NDEF_CARD_INVALID = 0x00, /**< The card is not NFC forum specified tag. The ndef format will be needed. */
+ NET_NFC_NDEF_CARD_INITIALISED, /**< The card is NFC forum specified tag, but It has no actual data. So, the ndef write will be needed. */
+ NET_NFC_NDEF_CARD_READ_WRITE, /**< The card is NFC forum specified tag. The ndef read and write will be allowed. */
+ NET_NFC_NDEF_CARD_READ_ONLY /**< The card is NFC forum specified tag, but only the ndef read will be allowed. */
+} net_nfc_ndef_card_state_e;
+
+/**
+ Encoding type for string message
+ */
+typedef enum
+{
+ NET_NFC_ENCODE_UTF_8 = 0x00,
+ NET_NFC_ENCODE_UTF_16,
+} net_nfc_encode_type_e;
+
+/**
+ URI scheme type defined in the NFC forum "URI Record Type Definition"
+ */
+typedef enum
+{
+ NET_NFC_SCHEMA_FULL_URI = 0x00, /**< protocol is specify by payload */
+ NET_NFC_SCHEMA_HTTP_WWW, /**< http://www. */
+ NET_NFC_SCHEMA_HTTPS_WWW, /**< https://www. */
+ NET_NFC_SCHEMA_HTTP, /**< http:// */
+ NET_NFC_SCHEMA_HTTPS, /**< https:// */
+ NET_NFC_SCHEMA_TEL, /**< tel: */
+ NET_NFC_SCHEMA_MAILTO, /**< mailto: */
+ NET_NFC_SCHEMA_FTP_ANONYMOUS, /**< ftp://anonymouse:anonymouse@ */
+ NET_NFC_SCHEMA_FTP_FTP, /**< ftp://ftp. */
+ NET_NFC_SCHEMA_FTPS, /**< ftps:// */
+ NET_NFC_SCHEMA_SFTP, /**< sftp:// */
+ NET_NFC_SCHEMA_SMB, /**< smb:// */
+ NET_NFC_SCHEMA_NFS, /**< nfs:// */
+ NET_NFC_SCHEMA_FTP, /**< ftp:// */
+ NET_NFC_SCHEMA_DAV, /**< dav:// */
+ NET_NFC_SCHEMA_NEWS, /**< news:// */
+ NET_NFC_SCHEMA_TELNET, /**< telnet:// */
+ NET_NFC_SCHEMA_IMAP, /**< imap: */
+ NET_NFC_SCHEMA_RTSP, /**< rtsp:// */
+ NET_NFC_SCHEMA_URN, /**< urn: */
+ NET_NFC_SCHEMA_POP, /**< pop: */
+ NET_NFC_SCHEMA_SIP, /**< sip: */
+ NET_NFC_SCHEMA_SIPS, /**< sips: */
+ NET_NFC_SCHEMA_TFTP, /**< tftp: */
+ NET_NFC_SCHEMA_BTSPP, /**< btspp:// */
+ NET_NFC_SCHEMA_BTL2CAP, /**< btl2cap:// */
+ NET_NFC_SCHEMA_BTGOEP, /**< btgoep:// */
+ NET_NFC_SCHEMA_TCPOBEX, /**< tcpobex:// */
+ NET_NFC_SCHEMA_IRDAOBEX, /**< irdaobex:// */
+ NET_NFC_SCHEMA_FILE, /**< file:// */
+ NET_NFC_SCHEMA_URN_EPC_ID, /**< urn:epc:id: */
+ NET_NFC_SCHEMA_URN_EPC_TAG, /**< urn:epc:tag: */
+ NET_NFC_SCHEMA_URN_EPC_PAT, /**< urn:epc:pat: */
+ NET_NFC_SCHEMA_URN_EPC_RAW, /**< urn:epc:raw: */
+ NET_NFC_SCHEMA_URN_EPC, /**< urn:epc: */
+ NET_NFC_SCHEMA_URN_NFC, /**< urn:epc:nfc: */
+ NET_NFC_SCHEMA_MAX /**< -- indicating max-- */
+} net_nfc_schema_type_e;
+
+// this is for target detect event filter
+
+typedef enum
+{
+ NET_NFC_ALL_DISABLE = 0x0000,
+ NET_NFC_ISO14443A_ENABLE = 0x0001,
+ NET_NFC_ISO14443B_ENABLE = 0x0002,
+ NET_NFC_ISO15693_ENABLE = 0x0004,
+ NET_NFC_FELICA_ENABLE = 0x0008,
+ NET_NFC_JEWEL_ENABLE = 0x0010,
+ NET_NFC_IP_ENABLE = 0x0020,
+ NET_NFC_ALL_ENABLE = ~0,
+
+} net_nfc_event_filter_e;
+
+/*
+ **************************************
+ LLCP defines
+ **************************************
+ */
+/**
+ These events are delivered to the each socket callback. These events are separated events that comes from "net_nfc_set_response_callback" callback
+ */
+typedef enum
+{
+ /* start number should be larger than "net_nfc_message_e"
+ because to make seperate with net_nfc_message_e event it may conflict in
+ the dispatcher and ipc part */
+ NET_NFC_MESSAGE_LLCP_LISTEN = 1000, /**< Type: Response Event <br> this event indicates "net_nfc_listen_llcp" requested is completed*/
+ NET_NFC_MESSAGE_LLCP_ACCEPTED, /**< Type: Notify Event. <br> Remote socket is accepted to listening socket
+ <br> data pointer contains the remote socket info (Cast to net_nfc_llcp_socket_option_h)*/
+ NET_NFC_MESSAGE_LLCP_CONNECT, /**< Type: Response Event. <br> "net_nfc_connect_llcp_with" request is completed and your socket is connected to remote site with url*/
+ NET_NFC_MESSAGE_LLCP_CONNECT_SAP, /**< Type: Response Event.<br> "net_nfc_connect_llcp_with_sap" request is completed and your socket is connected to remote site with sap number*/
+ NET_NFC_MESSAGE_LLCP_SEND, /**< Type: Response Event,<br> "net_nfc_send_llcp" operation is completed (connection mode)*/
+ NET_NFC_MESSAGE_LLCP_SEND_TO, /**< Type: Response Event,<br> "net_nfc_send_llcp_to"operation is completed (connectionless mode)*/
+ NET_NFC_MESSAGE_LLCP_RECEIVE, /**< Type: Response Event,<br> "net_nfc_receive_llcp" operation is completed (connection mode)
+ <br> data pointer contains received data (Cast to data_h)*/
+ NET_NFC_MESSAGE_LLCP_RECEIVE_FROM, /**< Type: Response Event,<br> "net_nfc_receive_llcp_from" operation is completed (connectionless mode)*/
+ NET_NFC_MESSAGE_LLCP_DISCONNECT, /**< Type: Response Event,<br> "net_nfc_disconnect_llcp" request is completed */
+ NET_NFC_MESSAGE_LLCP_ERROR, /**< Type: Notify Event,<br> when the socket is disconnected, you may receive this event */
+ NET_NFC_MESSAGE_LLCP_CONNECT_REQ, /**< Type: Notify Event,<br> when the peer requests connect, you may receive this event */
+ NET_NFC_MESSAGE_LLCP_ACCEPT, /**< Type: Response Event <br> this event indicates "net_nfc_accept_llcp" requested is completed*/
+ NET_NFC_MESSAGE_LLCP_REJECT, /**< Type: Response Event <br> this event indicates "net_nfc_reject_llcp" requested is completed*/
+ NET_NFC_MESSAGE_LLCP_REJECTED, /**< Type: Notify Event,<br> when the socket is rejected, you may receive this event */
+ NET_NFC_MESSAGE_LLCP_CLOSE, /**< Type: Response Event,<br> "net_nfc_close_llcp_socket" request is completed */
+
+} net_nfc_llcp_message_e;
+
+typedef enum
+{
+ NET_NFC_LLCP_SOCKET_TYPE_CONNECTIONORIENTED,
+ NET_NFC_LLCP_SOCKET_TYPE_CONNECTIONLESS,
+} net_nfc_socket_type_e;
+
+typedef enum
+{
+ NET_NFC_SNEP = 0x00,
+ NET_NFC_NPP,
+} llcp_app_protocol_e;
+
+typedef struct _data_s *data_h;
+
+typedef struct _ndef_record_s *ndef_record_h;
+
+typedef struct _ndef_message_s *ndef_message_h;
+
+typedef struct _net_nfc_target_info_s *net_nfc_target_info_h;
+
+typedef uint32_t net_nfc_traceive_cmd;
+
+typedef struct _net_nfc_llcp_config_info_s *net_nfc_llcp_config_info_h;
+
+typedef struct _net_nfc_llcp_socket_option_s *net_nfc_llcp_socket_option_h;
+
+typedef struct _net_nfc_target_handle_s *net_nfc_target_handle_h;
+
+typedef struct _net_nfc_connection_handover_info_s *net_nfc_connection_handover_info_h;
+
+typedef uint8_t sap_t;
+
+typedef uint32_t net_nfc_llcp_socket_t;
+
+typedef void *net_nfc_snep_handle_h;
+
+// LLCP Callback
+typedef void (*net_nfc_llcp_socket_cb)(net_nfc_llcp_message_e message, net_nfc_error_e result, void *data, void *user_data, void *trans_data);
+
+// Main Callback
+typedef void (*net_nfc_response_cb)(net_nfc_message_e message, net_nfc_error_e result, void *data, void *user_param, void *trans_data);
+
+typedef void (*net_nfc_internal_se_response_cb)(net_nfc_message_e message, net_nfc_error_e result, void *data, void *user_param, void *trans_data);
+
+typedef void (* net_nfc_set_activation_completed_cb)(net_nfc_error_e error, void *user_data);
+
+// for data exchanger
+
+typedef enum
+{
+ NET_NFC_EXCHANGER_DATA_REQUESTED = 0x00,
+ NET_NFC_EXCHANGER_TRANSFER_COMPLETED,
+ NET_NFC_EXCHANGER_TRANSFER_FAILED,
+} net_nfc_exchanger_event_e;
+
+typedef enum
+{
+ NET_NFC_EXCHANGER_RAW,
+} net_nfc_exchanger_data_type_e;
+
+typedef struct _net_nfc_exchanger_data_s *net_nfc_exchanger_data_h;
+
+typedef net_nfc_exchanger_data_h (*net_nfc_exchanger_cb)(net_nfc_exchanger_event_e event, void *user_param);
+
+typedef enum
+{
+ NET_NFC_CONN_HANDOVER_CARRIER_BT = 0x00,
+ NET_NFC_CONN_HANDOVER_CARRIER_WIFI_BSS, /* infrastructure */
+ NET_NFC_CONN_HANDOVER_CARRIER_WIFI_IBSS, /* add hoc */
+ NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN,
+} net_nfc_conn_handover_carrier_type_e;
+
+typedef enum
+{
+ NET_NFC_CONN_HANDOVER_CARRIER_INACTIVATE = 0x00,
+ NET_NFC_CONN_HANDOVER_CARRIER_ACTIVATE,
+ NET_NFC_CONN_HANDOVER_CARRIER_ACTIVATING,
+ NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN_STATUS,
+} net_nfc_conn_handover_carrier_state_e;
+
+typedef struct _net_nfc_conn_handover_carrier_info_s *net_nfc_conn_handover_carrier_info_h;
+typedef struct _net_nfc_conn_handover_info_s *net_nfc_conn_handover_info_h;
+
+#define MIFARE_KEY_DEFAULT {(uint8_t)0xFF,(uint8_t)0xFF,(uint8_t)0xFF,(uint8_t)0xFF,(uint8_t)0xFF,(uint8_t)0xFF}
+#define MIFARE_KEY_APPLICATION_DIRECTORY {(uint8_t)0xA0,(uint8_t)0xA1,(uint8_t)0xA2,(uint8_t)0xA3,(uint8_t)0xA4,(uint8_t)0xA5}
+#define MIFARE_KEY_NET_NFC_FORUM {(uint8_t)0xD3,(uint8_t)0xF7,(uint8_t)0xD3,(uint8_t)0xF7,(uint8_t)0xD3,(uint8_t)0xF7}
+#define MIFARE_KEY_LENGTH 6
+
+typedef enum
+{
+ NET_NFC_FELICA_POLL_NO_REQUEST = 0x00,
+ NET_NFC_FELICA_POLL_SYSTEM_CODE_REQUEST,
+ NET_NFC_FELICA_POLL_COMM_SPEED_REQUEST,
+ NET_NFC_FELICA_POLL_MAX = 0xFF,
+} net_nfc_felica_poll_request_code_e;
+
+/**
+ WIFI configuration key enums for connection handover.
+ */
+
+typedef enum
+{
+ NET_NFC_WIFI_ATTRIBUTE_VERSION = 0x104A,
+ NET_NFC_WIFI_ATTRIBUTE_CREDENTIAL = 0x100E,
+ NET_NFC_WIFI_ATTRIBUTE_NET_INDEX = 0x1026,
+ NET_NFC_WIFI_ATTRIBUTE_SSID = 0x1045,
+ NET_NFC_WIFI_ATTRIBUTE_AUTH_TYPE = 0x1003, /*< WPA2PSK 0x0020 */
+ NET_NFC_WIFI_ATTRIBUTE_ENC_TYPE = 0x100F, /*< AES 0x0008 */
+ NET_NFC_WIFI_ATTRIBUTE_NET_KEY = 0x1027,
+ NET_NFC_WIFI_ATTRIBUTE_MAC_ADDR = 0x1020,
+ NET_NFC_WIFI_ATTRIBUTE_CHANNEL = 0x1001, /* Channel number - based on IEEE */
+ NET_NFC_WIFI_ATTRIBUTE_VEN_EXT = 0x1049,
+ NET_NFC_WIFI_ATTRIBUTE_VERSION2 = 0x00,
+} net_nfc_carrier_wifi_attribute_e;
+
+typedef enum
+{
+ NET_NFC_BT_ATTRIBUTE_UUID16_PART = 0x02, /* More 16-bit UUIDs available */
+ NET_NFC_BT_ATTRIBUTE_UUID16 = 0x03, /* Complete list of 16-bit UUIDs */
+ NET_NFC_BT_ATTRIBUTE_UUID32_PART = 0x04, /* More 32-bit UUIDs available */
+ NET_NFC_BT_ATTRIBUTE_UUID32 = 0x05, /* Complete list of 32-bit UUIDs */
+ NET_NFC_BT_ATTRIBUTE_UUID128_PART = 0x06, /* More 128-bit UUIDs available */
+ NET_NFC_BT_ATTRIBUTE_UUID128 = 0x07, /* Complete list of 128-bit UUIDs */
+ NET_NFC_BT_ATTRIBUTE_NAME_PART = 0x08, /* Shortened local name */
+ NET_NFC_BT_ATTRIBUTE_NAME = 0x09, /* Complete local name */
+ NET_NFC_BT_ATTRIBUTE_TXPOWER = 0x0a, /* TX Power level */
+ NET_NFC_BT_ATTRIBUTE_OOB_COD = 0x0d, /* SSP OOB Class of Device */
+ NET_NFC_BT_ATTRIBUTE_OOB_HASH_C = 0x0e, /* SSP OOB Hash C */
+ NET_NFC_BT_ATTRIBUTE_OOB_HASH_R = 0x0f, /* SSP OOB Randomizer R */
+ NET_NFC_BT_ATTRIBUTE_ID = 0x10, /* Device ID */
+ NET_NFC_BT_ATTRIBUTE_MANUFACTURER = 0xFF, /* Manufacturer Specific Data */
+ NET_NFC_BT_ATTRIBUTE_ADDRESS = 0xF0, /* Bluetooth device Address */
+} net_nfc_handover_bt_attribute_e;
+
+typedef struct _net_nfc_carrier_config_s *net_nfc_carrier_config_h;
+typedef struct _net_nfc_carrier_property_s *net_nfc_property_group_h;
+
+typedef enum
+{
+ NET_NFC_SE_TYPE_NONE = 0x00,/**< Invalid */
+ NET_NFC_SE_TYPE_ESE = 0x01,/**< SmartMX */
+ NET_NFC_SE_TYPE_UICC = 0x02,/**< UICC */
+ NET_NFC_SE_TYPE_SDCARD = 0x03, /* SDCard type is not currently supported */
+} net_nfc_se_type_e;
+
+typedef enum
+{
+ NET_NFC_SIGN_TYPE_NO_SIGN = 0,
+ NET_NFC_SIGN_TYPE_PKCS_1,
+ NET_NFC_SIGN_TYPE_PKCS_1_V_1_5,
+ NET_NFC_SIGN_TYPE_DSA,
+ NET_NFC_SIGN_TYPE_ECDSA,
+ NET_NFC_MAX_SIGN_TYPE,
+} net_nfc_sign_type_t;
+
+typedef enum
+{
+ NET_NFC_CERT_FORMAT_X_509 = 0,
+ NET_NFC_CERT_FORMAT_X9_86,
+ NET_NFC_MAX_CERT_FORMAT,
+} net_nfc_cert_format_t;
+
+typedef enum
+{
+ NET_NFC_SNEP_GET = 1,
+ NET_NFC_SNEP_PUT = 2,
+} net_nfc_snep_type_t;
+
+typedef enum
+{
+ NET_NFC_LLCP_REGISTERED = -1,
+ NET_NFC_LLCP_UNREGISTERED = -2,
+ NET_NFC_LLCP_START = -3,
+ NET_NFC_LLCP_STOP = -4,
+}
+net_nfc_llcp_state_t;
+
+typedef enum
+{
+ NET_NFC_CARD_EMELATION_ENABLE = 0,
+ NET_NFC_CARD_EMULATION_DISABLE,
+}
+net_nfc_card_emulation_mode_t;
+
+#ifdef __cplusplus
+}
+#endif
+
+/**
+ @}
+ */
+
+#endif //__NET_NFC_TYPEDEF_H__
--- /dev/null
+/*
+ * Copyright (C) 2010 NXP Semiconductors
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_TYPEDEF_INTERNAL_H__
+#define __NET_NFC_TYPEDEF_INTERNAL_H__
+
+#include "net_nfc_typedef.h"
+
+typedef enum
+{
+ NET_NFC_POLL_START = 0x01,
+ NET_NFC_POLL_STOP,
+} net_nfc_detect_mode_e;
+
+/**
+ This structure is just data, to express bytes array
+ */
+typedef struct _data_s
+{
+ uint8_t *buffer;
+ uint32_t length;
+} data_s;
+
+typedef struct _net_nfc_data_t
+{
+ uint32_t length;
+ uint8_t buffer[0];
+} net_nfc_data_s;
+
+typedef enum _net_nfc_connection_type_e
+{
+ NET_NFC_TAG_CONNECTION = 0x00,
+ NET_NFC_P2P_CONNECTION_TARGET,
+ NET_NFC_P2P_CONNECTION_INITIATOR,
+ NET_NFC_SE_CONNECTION
+} net_nfc_connection_type_e;
+
+typedef struct _net_nfc_target_handle_s
+{
+ uint32_t connection_id;
+ net_nfc_connection_type_e connection_type;
+ net_nfc_target_type_e target_type;
+ /*++npp++*/
+ llcp_app_protocol_e app_type;
+ /*--npp--*/
+} net_nfc_target_handle_s;
+
+typedef struct _net_nfc_current_target_info_s
+{
+ net_nfc_target_handle_s *handle;
+ uint32_t devType;
+ int number_of_keys;
+ net_nfc_data_s target_info_values;
+}net_nfc_current_target_info_s;
+
+typedef struct _net_nfc_llcp_config_info_s
+{
+ uint16_t miu; /** The remote Maximum Information Unit (NOTE: this is MIU, not MIUX !)*/
+ uint16_t wks; /** The remote Well-Known Services*/
+ uint8_t lto; /** The remote Link TimeOut (in 1/100s)*/
+ uint8_t option; /** The remote options*/
+} net_nfc_llcp_config_info_s;
+
+typedef struct _net_nfc_llcp_socket_option_s
+{
+ uint16_t miu; /** The remote Maximum Information Unit */
+ uint8_t rw; /** The Receive Window size (4 bits)*/
+ net_nfc_socket_type_e type;
+} net_nfc_llcp_socket_option_s;
+
+typedef struct _net_nfc_llcp_internal_socket_s
+{
+ uint16_t miu; /** The remote Maximum Information Unit */
+ uint8_t rw; /** The Receive Window size (4 bits)*/
+ net_nfc_socket_type_e type;
+ net_nfc_llcp_socket_t oal_socket;
+ net_nfc_llcp_socket_t client_socket;
+ sap_t sap;
+ uint8_t *service_name;
+ net_nfc_target_handle_s *device_id;
+ net_nfc_llcp_socket_cb cb;
+ bool close_requested;
+ void *register_param; /* void param that has been registered in callback register time */
+} net_nfc_llcp_internal_socket_s;
+
+/**
+ ndef_record_s structure has the NDEF record data. it is only a record not a message
+ */
+typedef struct _record_s
+{
+ uint8_t MB :1;
+ uint8_t ME :1;
+ uint8_t CF :1;
+ uint8_t SR :1;
+ uint8_t IL :1;
+ uint8_t TNF :3;
+ data_s type_s;
+ data_s id_s;
+ data_s payload_s;
+ struct _record_s *next;
+} ndef_record_s;
+
+/**
+ NDEF message it has record counts and records (linked listed form)
+ */
+typedef struct _ndef_message_s
+{
+ uint32_t recordCount;
+ ndef_record_s *records; // linked list
+} ndef_message_s;
+
+/**
+ Enum value to stop or start the discovery mode
+ */
+
+#define NET_NFC_MAX_UID_LENGTH 0x0AU /**< Maximum UID length expected */
+#define NET_NFC_MAX_ATR_LENGTH 0x30U /**< Maximum ATR_RES (General Bytes) */
+#define NET_NFC_ATQA_LENGTH 0x02U /**< ATQA length */
+#define NET_NFC_ATQB_LENGTH 0x0BU /**< ATQB length */
+
+#define NET_NFC_PUPI_LENGTH 0x04U /**< PUPI length */
+#define NET_NFC_APP_DATA_B_LENGTH 0x04U /**< Application Data length for Type B */
+#define NET_NFC_PROT_INFO_B_LENGTH 0x03U /**< Protocol info length for Type B */
+
+#define NET_NFC_MAX_ATR_LENGTH 0x30U /**< Maximum ATR_RES (General Bytes) */
+#define NET_NFC_MAX_UID_LENGTH 0x0AU /**< Maximum UID length expected */
+#define NET_NFC_FEL_ID_LEN 0x08U /**< Felica current ID Length */
+#define NET_NFC_FEL_PM_LEN 0x08U /**< Felica current PM Length */
+#define NET_NFC_FEL_SYS_CODE_LEN 0x02U /**< Felica System Code Length */
+
+#define NET_NFC_15693_UID_LENGTH 0x08U /**< Length of the Inventory bytes for */
+
+typedef struct _net_nfc_sIso14443AInfo_t
+{
+ uint8_t Uid[NET_NFC_MAX_UID_LENGTH]; /**< UID information of the TYPE A Tag Discovered */
+ uint8_t UidLength; /**< UID information length, shall not be greater than NET_NFC_MAX_UID_LENGTH i.e., 10 */
+ uint8_t AppData[NET_NFC_MAX_ATR_LENGTH]; /**< Application data information of the tag discovered (= Historical bytes for type A) */
+ uint8_t AppDataLength; /**< Application data length */
+ uint8_t Sak; /**< SAK informationof the TYPE A Tag Discovered */
+ uint8_t AtqA[NET_NFC_ATQA_LENGTH]; /**< ATQA informationof the TYPE A Tag Discovered */
+ uint8_t MaxDataRate; /**< Maximum data rate supported by the TYPE A Tag Discovered */
+ uint8_t Fwi_Sfgt; /**< Frame waiting time and start up frame guard time as defined in ISO/IEC 14443-4[7] for type A */
+} net_nfc_sIso14443AInfo_t;
+
+/** \ingroup grp_hal_nfci
+ *
+ * \brief Remote Device Reader B RF Gate Information Container
+ *
+ * The <em> Reader B structure </em> includes the available information
+ * related to the discovered ISO14443B remote device. This information
+ * is updated for every device discovery.
+ * \note None.
+ *
+ */
+typedef struct _net_nfc_sIso14443BInfo_t
+{
+ union net_nfc_uAtqBInfo
+ {
+ struct net_nfc_sAtqBInfo
+ {
+ uint8_t Pupi[NET_NFC_PUPI_LENGTH]; /**< PUPI information of the TYPE B Tag Discovered */
+ uint8_t AppData[NET_NFC_APP_DATA_B_LENGTH]; /**< Application Data of the TYPE B Tag Discovered */
+ uint8_t ProtInfo[NET_NFC_PROT_INFO_B_LENGTH]; /**< Protocol Information of the TYPE B Tag Discovered */
+ } AtqResInfo;
+ uint8_t AtqRes[NET_NFC_ATQB_LENGTH]; /**< ATQB Response Information of TYPE B Tag Discovered */
+ } AtqB;
+
+ uint8_t HiLayerResp[NET_NFC_MAX_ATR_LENGTH]; /**< Higher Layer Response information in answer to ATRRIB Command for Type B */
+ uint8_t HiLayerRespLength; /**< Higher Layer Response length */
+ uint8_t Afi; /**< Application Family Identifier of TYPE B Tag Discovered */
+ uint8_t MaxDataRate; /**< Maximum data rate supported by the TYPE B Tag Discovered */
+} net_nfc_sIso14443BInfo_t;
+
+/** \ingroup grp_hal_nfci
+ *
+ * \brief Remote Device Reader B prime RF Gate Information Container
+ *
+ */
+typedef struct _net_nfc_sIso14443BPrimeInfo_t
+{
+ void *BPrimeCtxt;
+} net_nfc_sIso14443BPrimeInfo_t;
+
+/** \ingroup grp_hal_nfci
+ *
+ * \brief Remote Device Jewel Reader RF Gate Information Container
+ *
+ * The <em> Jewel Reader structure </em> includes the available information
+ * related to the discovered Jewel remote device. This information
+ * is updated for every device discovery.
+ * \note None.
+ *
+ */
+typedef struct _net_nfc_sJewelInfo_t
+{
+ uint8_t Uid[NET_NFC_MAX_UID_LENGTH]; /**< UID information of the TYPE A Tag Discovered */
+ uint8_t UidLength; /**< UID information length, shall not be greater than NET_NFC_MAX_UID_LENGTH i.e., 10 */
+ uint8_t HeaderRom0; /**< Header Rom byte zero */
+ uint8_t HeaderRom1; /**< Header Rom byte one */
+
+} net_nfc_sJewelInfo_t;
+
+/** \ingroup grp_hal_nfci
+ *
+ * \brief Remote Device Felica Reader RF Gate Information Container
+ *
+ * The <em> Felica Reader structure </em> includes the available information
+ * related to the discovered Felica remote device. This information
+ * is updated for every device discovery.
+ * \note None.
+ *
+ */
+typedef struct _net_nfc_sFelicaInfo_t
+{
+ uint8_t IDm[(NET_NFC_FEL_ID_LEN + 2)]; /**< Current ID of Felica tag */
+ uint8_t IDmLength; /**< IDm length, shall not be greater than NET_NFC_FEL_ID_LEN i.e., 8 */
+ uint8_t PMm[NET_NFC_FEL_PM_LEN]; /**< Current PM of Felica tag */
+ uint8_t SystemCode[NET_NFC_FEL_SYS_CODE_LEN]; /**< System code of Felica tag */
+} net_nfc_sFelicaInfo_t;
+
+/** \ingroup grp_hal_nfci
+ *
+ * \brief Remote Device Reader 15693 RF Gate Information Container
+ *
+ * The <em> Reader A structure </em> includes the available information
+ * related to the discovered ISO15693 remote device. This information
+ * is updated for every device discovery.
+ * \note None.
+ *
+ */
+
+typedef struct _net_nfc_sIso15693Info_t
+{
+ uint8_t Uid[NET_NFC_15693_UID_LENGTH]; /**< UID information of the 15693 Tag Discovered */
+ uint8_t UidLength; /**< UID information length, shall not be greater than NET_NFC_15693_UID_LENGTH i.e., 8 */
+ uint8_t Dsfid; /**< DSF information of the 15693 Tag Discovered */
+ uint8_t Flags; /**< Information about the Flags in the 15693 Tag Discovered */
+ uint8_t Afi; /**< Application Family Identifier of 15693 Tag Discovered */
+} net_nfc_sIso15693Info_t;
+
+/** \ingroup grp_hal_nfci
+ *
+ * \brief NFC Data Rate Supported between the Reader and the Target
+ *
+ * The <em> \ref Halnet_nfc_eDataRate enum </em> lists all the Data Rate
+ * values to be used to determine the rate at which the data is transmitted
+ * to the target.
+ *
+ * \note None.
+ */
+
+/** \ingroup grp_hal_nfci
+ *
+ * \brief NFCIP1 Data rates
+ *
+ */
+typedef enum net_nfc_eDataRate_t
+{
+ net_nfc_eDataRate_106 = 0x00U,
+ net_nfc_eDataRate_212,
+ net_nfc_eDataRate_424,
+ net_nfc_eDataRate_RFU
+} net_nfc_eDataRate_t;
+
+/** \ingroup grp_hal_nfci
+ *
+ * \brief NFCIP1 Gate Information Container
+ *
+ * The <em> NFCIP1 structure </em> includes the available information
+ * related to the discovered NFCIP1 remote device. This information
+ * is updated for every device discovery.
+ * \note None.
+ *
+ */
+typedef struct _net_nfc_sNfcIPInfo_t
+{
+ /* Contains the random NFCID3I conveyed with the ATR_REQ.
+ always 10 bytes length
+ or contains the random NFCID3T conveyed with the ATR_RES.
+ always 10 bytes length */
+ uint8_t NFCID[NET_NFC_MAX_UID_LENGTH];
+ uint8_t NFCID_Length;
+ /* ATR_RES = General bytes length, Max length = 48 bytes */
+ uint8_t ATRInfo[NET_NFC_MAX_ATR_LENGTH];
+ uint8_t ATRInfo_Length;
+ /**< SAK information of the tag discovered */
+ uint8_t SelRes;
+ /**< ATQA information of the tag discovered */
+ uint8_t SenseRes[NET_NFC_ATQA_LENGTH];
+ /**< Is Detection Mode of the NFCIP Target Active */
+ uint8_t nfcip_Active;
+ /**< Maximum frame length supported by the NFCIP device */
+ uint16_t MaxFrameLength;
+ /**< Data rate supported by the NFCIP device */
+ net_nfc_eDataRate_t nfcip_Datarate;
+
+} net_nfc_sNfcIPInfo_t;
+
+typedef union net_nfc_remoteDevInfo_t
+{
+ net_nfc_sIso14443AInfo_t Iso14443A_Info;
+ net_nfc_sIso14443BInfo_t Iso14443B_Info;
+ net_nfc_sIso14443BPrimeInfo_t Iso14443BPrime_Info;
+ net_nfc_sNfcIPInfo_t NfcIP_Info;
+ net_nfc_sFelicaInfo_t Felica_Info;
+ net_nfc_sJewelInfo_t Jewel_Info;
+ net_nfc_sIso15693Info_t Iso15693_Info;
+} net_nfc_remoteDevInfo_t;
+
+typedef struct _net_nfc_tag_info_s
+{
+ char *key;
+ data_h value;
+} net_nfc_tag_info_s;
+
+typedef struct _net_nfc_target_info_s
+{
+ net_nfc_target_handle_s *handle;
+ net_nfc_target_type_e devType;
+ uint8_t is_ndef_supported;
+ uint8_t ndefCardState;
+ uint32_t maxDataSize;
+ uint32_t actualDataSize;
+ int number_of_keys;
+ net_nfc_tag_info_s *tag_info_list;
+ char **keylist;
+ data_s raw_data;
+} net_nfc_target_info_s;
+
+typedef struct _net_nfc_se_event_info_s
+{
+ data_s aid;
+ data_s param;
+} net_nfc_se_event_info_s;
+
+typedef struct _net_nfc_transceive_info_s
+{
+ uint32_t dev_type;
+ data_s trans_data;
+} net_nfc_transceive_info_s;
+
+typedef struct _net_nfc_connection_handover_info_s
+{
+ net_nfc_conn_handover_carrier_type_e type;
+ data_s data;
+}
+net_nfc_connection_handover_info_s;
+
+typedef enum _client_state_e
+{
+ NET_NFC_CLIENT_INACTIVE_STATE = 0x00,
+ NET_NFC_CLIENT_ACTIVE_STATE,
+} client_state_e;
+
+typedef enum _net_nfc_launch_popup_check_e
+{
+ CHECK_FOREGROUND = 0x00,
+ NO_CHECK_FOREGROUND,
+} net_nfc_launch_popup_check_e;
+
+typedef enum _net_nfc_launch_popup_state_e
+{
+ NET_NFC_LAUNCH_APP_SELECT = 0x00,
+ NET_NFC_NO_LAUNCH_APP_SELECT,
+} net_nfc_launch_popup_state_e;
+
+/* server state */
+#define NET_NFC_SERVER_IDLE 0
+#define NET_NFC_SERVER_DISCOVERY (1 << 1)
+#define NET_NFC_TAG_CONNECTED (1 << 2)
+#define NET_NFC_SE_CONNECTED (1 << 3)
+#define NET_NFC_SNEP_CLIENT_CONNECTED (1 << 4)
+#define NET_NFC_NPP_CLIENT_CONNECTED (1 << 5)
+#define NET_NFC_SNEP_SERVER_CONNECTED (1 << 6)
+#define NET_NFC_NPP_SERVER_CONNECTED (1 << 7)
+
+// these are messages for request
+#define NET_NFC_REQUEST_MSG_HEADER \
+ /* DON'T MODIFY THIS CODE - BEGIN */ \
+ uint32_t length; \
+ uint32_t request_type; \
+ uint32_t client_fd; \
+ uint32_t flags; \
+ uint32_t user_param; \
+ /* DON'T MODIFY THIS CODE - END */
+
+typedef struct _net_nfc_request_msg_t
+{
+ NET_NFC_REQUEST_MSG_HEADER
+} net_nfc_request_msg_t;
+
+typedef struct _net_nfc_request_target_detected_t
+{
+ NET_NFC_REQUEST_MSG_HEADER
+
+ net_nfc_target_handle_s *handle;
+ uint32_t devType;
+ int number_of_keys;
+ net_nfc_data_s target_info_values;
+} net_nfc_request_target_detected_t;
+
+typedef struct _net_nfc_request_se_event_t
+{
+ NET_NFC_REQUEST_MSG_HEADER
+
+ data_s aid;
+ data_s param;
+} net_nfc_request_se_event_t;
+
+typedef struct _net_nfc_request_llcp_msg_t
+{
+ NET_NFC_REQUEST_MSG_HEADER
+
+ uint32_t result;
+ net_nfc_llcp_socket_t llcp_socket;
+} net_nfc_request_llcp_msg_t;
+
+typedef struct _net_nfc_request_listen_socket_t
+{
+ NET_NFC_REQUEST_MSG_HEADER
+
+ uint32_t result;
+ net_nfc_target_handle_s *handle;
+ net_nfc_llcp_socket_t client_socket;
+ uint16_t miu; /** The remote Maximum Information Unit */
+ uint8_t rw; /** The Receive Window size (4 bits)*/
+ net_nfc_socket_type_e type;
+ net_nfc_llcp_socket_t oal_socket;
+ sap_t sap;
+ void *trans_param;
+ net_nfc_data_s service_name;
+} net_nfc_request_listen_socket_t;
+
+typedef struct _net_nfc_request_receive_socket_t
+{
+ NET_NFC_REQUEST_MSG_HEADER
+
+ uint32_t result;
+ net_nfc_target_handle_s *handle;
+ net_nfc_llcp_socket_t client_socket;
+ net_nfc_llcp_socket_t oal_socket;
+ size_t req_length;
+ void *trans_param;
+ net_nfc_data_s data;
+} net_nfc_request_receive_socket_t;
+
+typedef struct _net_nfc_request_receive_from_socket_t
+{
+ NET_NFC_REQUEST_MSG_HEADER
+
+ uint32_t result;
+ net_nfc_target_handle_s *handle;
+ net_nfc_llcp_socket_t client_socket;
+ net_nfc_llcp_socket_t oal_socket;
+ size_t req_length;
+ sap_t sap;
+ void *trans_param;
+ net_nfc_data_s data;
+} net_nfc_request_receive_from_socket_t;
+
+// data exchanger
+typedef struct _net_nfc_exchanger_data_s
+{
+ net_nfc_exchanger_data_type_e type;
+ data_s binary_data; /* this can be binary data */
+} net_nfc_exchanger_data_s;
+
+// these are messages for response
+
+typedef void (*target_detection_listener_cb)(void *data, void *user_param);
+typedef void (*se_transaction_listener_cb)(void *data, void *user_param);
+typedef void (*llcp_event_listener_cb)(void *data, void *user_param);
+
+typedef enum _llcp_event_e
+{
+ LLCP_EVENT_SOCKET_ACCEPTED = 0x1,
+ LLCP_EVENT_SOCKET_ERROR,
+ LLCP_EVENT_DEACTIVATED,
+} llcp_event_e;
+
+typedef struct _net_nfc_stack_information_s
+{
+ uint32_t net_nfc_supported_tagetType;
+ uint32_t net_nfc_fw_version;
+} net_nfc_stack_information_s;
+
+typedef enum _net_nfc_discovery_mode_e
+{
+ NET_NFC_DISCOVERY_MODE_CONFIG = 0x00U,
+ NET_NFC_DISCOVERY_MODE_START,
+ NET_NFC_DISCOVERY_MODE_STOP,
+ NET_NFC_DISCOVERY_MODE_RESUME,
+} net_nfc_discovery_mode_e;
+
+typedef enum _net_nfc_secure_element_type_e
+{
+ SECURE_ELEMENT_TYPE_INVALID = 0x00, /**< Indicates SE type is Invalid */
+ SECURE_ELEMENT_TYPE_ESE = 0x01, /**< Indicates SE type is SmartMX */
+ SECURE_ELEMENT_TYPE_UICC = 0x02, /**<Indicates SE type is UICC */
+ SECURE_ELEMENT_TYPE_UNKNOWN = 0x03 /**< Indicates SE type is Unknown */
+} net_nfc_secure_element_type_e;
+
+typedef enum _net_nfc_secure_element_state_e
+{
+ SECURE_ELEMENT_ACTIVE_STATE = 0x00, /**< state of the SE is active */
+ SECURE_ELEMENT_INACTIVE_STATE = 0x01 /**< state of the SE is In active*/
+
+} net_nfc_secure_element_state_e;
+
+typedef struct _secure_element_info_s
+{
+ net_nfc_target_handle_s *handle;
+ net_nfc_secure_element_type_e secure_element_type;
+ net_nfc_secure_element_state_e secure_element_state;
+
+} net_nfc_secure_element_info_s;
+
+typedef enum _net_nfc_secure_element_mode_e
+{
+ SECURE_ELEMENT_WIRED_MODE = 0x00, /**< Enables Wired Mode communication.This mode shall be applied to */
+ SECURE_ELEMENT_VIRTUAL_MODE, /**< Enables Virtual Mode communication.This can be applied to UICC as well as SmartMX*/
+ SECURE_ELEMENT_OFF_MODE /**< Inactivate SE.This means,put SE in in-active state */
+} net_nfc_secure_element_mode_e;
+
+typedef enum _net_nfc_message_service_e
+{
+ NET_NFC_MESSAGE_SERVICE_RESET = 2000,
+ NET_NFC_MESSAGE_SERVICE_INIT,
+ NET_NFC_MESSAGE_SERVICE_ACTIVATE,
+ NET_NFC_MESSAGE_SERVICE_DEACTIVATE,
+ NET_NFC_MESSAGE_SERVICE_DEINIT,
+ NET_NFC_MESSAGE_SERVICE_STANDALONE_TARGET_DETECTED,
+ NET_NFC_MESSAGE_SERVICE_SE,
+ NET_NFC_MESSAGE_SERVICE_TERMINATION,
+ NET_NFC_MESSAGE_SERVICE_SLAVE_TARGET_DETECTED,
+ NET_NFC_MESSAGE_SERVICE_SLAVE_ESE_DETECTED,
+ NET_NFC_MESSAGE_SERVICE_RESTART_POLLING_LOOP,
+ NET_NFC_MESSAGE_SERVICE_LLCP_LISTEN,
+ NET_NFC_MESSAGE_SERVICE_LLCP_INCOMING,
+ NET_NFC_MESSAGE_SERVICE_LLCP_ACCEPT,
+ NET_NFC_MESSAGE_SERVICE_LLCP_REJECT,
+ NET_NFC_MESSAGE_SERVICE_LLCP_SEND,
+ NET_NFC_MESSAGE_SERVICE_LLCP_SEND_TO,
+ NET_NFC_MESSAGE_SERVICE_LLCP_RECEIVE,
+ NET_NFC_MESSAGE_SERVICE_LLCP_RECEIVE_FROM,
+ NET_NFC_MESSAGE_SERVICE_LLCP_CONNECT,
+ NET_NFC_MESSAGE_SERVICE_LLCP_CONNECT_SAP,
+ NET_NFC_MESSAGE_SERVICE_LLCP_DISCONNECT,
+ NET_NFC_MESSAGE_SERVICE_LLCP_DEACTIVATED,
+ NET_NFC_MESSAGE_SERVICE_LLCP_SOCKET_ERROR,
+ NET_NFC_MESSAGE_SERVICE_LLCP_SOCKET_ACCEPTED_ERROR,
+ NET_NFC_MESSAGE_SERVICE_CHANGE_CLIENT_STATE,
+ NET_NFC_MESSAGE_SERVICE_WATCH_DOG,
+ NET_NFC_MESSAGE_SERVICE_CLEANER,
+ NET_NFC_MESSAGE_SERVICE_SET_LAUNCH_STATE,
+} net_nfc_message_service_e;
+
+typedef enum _net_nfc_se_command_e
+{
+ NET_NFC_SE_CMD_UICC_ON = 0,
+ NET_NFC_SE_CMD_ESE_ON,
+ NET_NFC_SE_CMD_ALL_OFF,
+ NET_NFC_SE_CMD_ALL_ON,
+} net_nfc_se_command_e;
+
+/* connection handover info */
+
+typedef enum
+{
+ NET_NFC_CONN_HANDOVER_ERR_REASON_RESERVED = 0x00,
+ NET_NFC_CONN_HANDOVER_ERR_REASON_TEMP_MEM_CONSTRAINT,
+ NET_NFC_CONN_HANDOVER_ERR_REASON_PERM_MEM_CONSTRAINT,
+ NET_NFC_CONN_HANDOVER_ERR_REASON_CARRIER_SPECIFIC_CONSTRAINT,
+} net_nfc_conn_handover_error_reason_e;
+
+/* WIFI Info */
+typedef struct _net_nfc_carrier_property_s
+{
+ bool is_group;
+ uint16_t attribute;
+ uint16_t length;
+ void *data;
+} net_nfc_carrier_property_s;
+
+typedef struct _net_nfc_carrier_config_s
+{
+ net_nfc_conn_handover_carrier_type_e type;
+ int length;
+ struct _GList *data;
+} net_nfc_carrier_config_s;
+
+typedef struct _net_nfc_sub_field_s
+{
+ uint16_t length;
+ uint8_t value[0];
+}
+__attribute__((packed)) net_nfc_sub_field_s;
+
+typedef struct _net_nfc_signature_record_s
+{
+ uint8_t version;
+ uint8_t sign_type : 7;
+ uint8_t uri_present : 1;
+ net_nfc_sub_field_s signature;
+}
+__attribute__((packed)) net_nfc_signature_record_s;
+
+typedef struct _net_nfc_certificate_chain_s
+{
+ uint8_t num_of_certs : 4;
+ uint8_t cert_format : 3;
+ uint8_t uri_present : 1;
+ uint8_t cert_store[0];
+}
+__attribute__((packed)) net_nfc_certificate_chain_s;
+
+#define SMART_POSTER_RECORD_TYPE "Sp"
+#define URI_RECORD_TYPE "U"
+#define TEXT_RECORD_TYPE "T"
+#define GC_RECORD_TYPE "Gc"
+#define SIGNATURE_RECORD_TYPE "Sig"
+#define CH_REQ_RECORD_TYPE "Hr"
+#define CH_SEL_RECORD_TYPE "Hs"
+#define CH_CAR_RECORD_TYPE "Hc"
+#define COLLISION_DETECT_RECORD_TYPE "cr"
+#define ALTERNATIVE_RECORD_TYPE "ac"
+#define ERROR_RECORD_TYPE "err"
+
+#define URI_SCHEM_FILE "file://"
+
+typedef void (*net_nfc_service_llcp_cb)(net_nfc_llcp_socket_t socket,
+ net_nfc_error_e result, data_s *data, void *extra, void *user_param);
+
+typedef struct _net_nfc_llcp_param_t
+{
+ net_nfc_llcp_socket_t socket;
+ net_nfc_service_llcp_cb cb;
+ data_s data;
+ void *user_param;
+}
+net_nfc_llcp_param_t;
+
+#endif //__NET_NFC_TYPEDEF_INTERNAL_H__
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_UTIL_HANDOVER_H__
+#define __NET_NFC_UTIL_HANDOVER_H__
+
+#include "net_nfc_typedef_internal.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#define CH_MAJOR_VER 1
+#define CH_MINOR_VER 2
+#define CH_VERSION ((CH_MAJOR_VER << 4) | CH_MINOR_VER)
+
+#define CH_SAN "urn:nfc:sn:handover"
+#define CH_SAP 0x11 /* connection handover service access point */
+
+net_nfc_error_e net_nfc_util_create_carrier_config(net_nfc_carrier_config_s **config, net_nfc_conn_handover_carrier_type_e type);
+
+net_nfc_error_e net_nfc_util_add_carrier_config_property(net_nfc_carrier_config_s *config, uint16_t attribute, uint16_t size, uint8_t *data);
+
+net_nfc_error_e net_nfc_util_remove_carrier_config_property(net_nfc_carrier_config_s *config, uint16_t attribute);
+
+net_nfc_error_e net_nfc_util_get_carrier_config_property(net_nfc_carrier_config_s *config, uint16_t attribute, uint16_t *size, uint8_t **data);
+
+net_nfc_error_e net_nfc_util_append_carrier_config_group(net_nfc_carrier_config_s *config, net_nfc_carrier_property_s *group);
+
+net_nfc_error_e net_nfc_util_remove_carrier_config_group(net_nfc_carrier_config_s *config, net_nfc_carrier_property_s *group);
+
+net_nfc_error_e net_nfc_util_get_carrier_config_group(net_nfc_carrier_config_s *config, int index, net_nfc_carrier_property_s **group);
+
+net_nfc_error_e net_nfc_util_free_carrier_config(net_nfc_carrier_config_s *config);
+
+net_nfc_error_e net_nfc_util_create_carrier_config_group(net_nfc_carrier_property_s **group, uint16_t attribute);
+
+net_nfc_error_e net_nfc_util_add_carrier_config_group_property(net_nfc_carrier_property_s *group, uint16_t attribute, uint16_t size, uint8_t *data);
+
+net_nfc_error_e net_nfc_util_get_carrier_config_group_property(net_nfc_carrier_property_s *group, uint16_t attribute, uint16_t *size, uint8_t **data);
+
+net_nfc_error_e net_nfc_util_remove_carrier_config_group_property(net_nfc_carrier_property_s *group, uint16_t attribute);
+
+net_nfc_error_e net_nfc_util_free_carrier_group(net_nfc_carrier_property_s *group);
+
+net_nfc_error_e net_nfc_util_create_ndef_record_with_carrier_config(ndef_record_s **record, net_nfc_carrier_config_s *config);
+
+net_nfc_error_e net_nfc_util_create_carrier_config_from_config_record(net_nfc_carrier_config_s **config, ndef_record_s *record);
+
+net_nfc_error_e net_nfc_util_append_carrier_config_record(ndef_message_s *message, ndef_record_s *record, net_nfc_conn_handover_carrier_state_e power_status);
+
+net_nfc_error_e net_nfc_util_remove_carrier_config_record(ndef_message_s *message, ndef_record_s *record);
+
+net_nfc_error_e net_nfc_util_get_carrier_config_record(ndef_message_s *message, int index, ndef_record_s **record);
+
+net_nfc_error_e net_nfc_util_get_handover_random_number(ndef_message_s *message, unsigned short *random_number);
+
+net_nfc_error_e net_nfc_util_get_alternative_carrier_record_count(ndef_message_s *message, unsigned int *count);
+
+net_nfc_error_e net_nfc_util_get_alternative_carrier_power_status(ndef_message_s *message, int index, net_nfc_conn_handover_carrier_state_e *power_state);
+
+net_nfc_error_e net_nfc_util_set_alternative_carrier_power_status(ndef_message_s *message, int index, net_nfc_conn_handover_carrier_state_e power_status);
+
+net_nfc_error_e net_nfc_util_get_alternative_carrier_type_from_record(ndef_record_s *record, net_nfc_conn_handover_carrier_type_e *type);
+
+/**
+ this function will get carrier type.
+
+ @param[in] carrier_info connection handover carrier info handler
+ @param[in] carrier_type record type. it can be a NET_NFC_CONN_HANDOVER_CARRIER_BT or NET_NFC_CONN_HANDOVER_CARRIER_WIFI or NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN.
+
+ @return return the result of the calling the function
+
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illegal NULL pointer(s)
+ */
+net_nfc_error_e net_nfc_util_get_alternative_carrier_type(ndef_message_s *message, int index, net_nfc_conn_handover_carrier_type_e *power_state);
+
+net_nfc_error_e net_nfc_util_create_handover_request_message(ndef_message_s **message);
+
+net_nfc_error_e net_nfc_util_create_handover_select_message(ndef_message_s **message);
+
+net_nfc_error_e net_nfc_util_create_handover_error_record(ndef_record_s **record, uint8_t reason, uint32_t data);
+
+net_nfc_error_e net_nfc_util_get_selector_power_status(ndef_message_s *message, net_nfc_conn_handover_carrier_state_e *power_state);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif //__NET_NFC_UTIL_HANDOVER_H__
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_UTIL_NDEF_MESSAGE_H__
+#define __NET_NFC_UTIL_NDEF_MESSAGE_H__
+
+#include "net_nfc_typedef_internal.h"
+
+/**
+ * \brief These are the flags specifying the content, structure or purpose of a NDEF Record.
+ * \name NDEF Record Header Flags
+ *
+ * Flags of the first record byte, as defined by the NDEF specification.
+ *
+ */
+/*@{*/
+#define NET_NFC_NDEF_RECORD_MASK_MB 0x80 /**< This marks the begin of a NDEF Message. */
+#define NET_NFC_NDEF_RECORD_MASK_ME 0x40 /**< Set if the record is at the Message End. */
+#define NET_NFC_NDEF_RECORD_MASK_CF 0x20 /**< Chunk Flag: The record is a record chunk only. */
+#define NET_NFC_NDEF_RECORD_MASK_SR 0x10 /**< Short Record: Payload Length is encoded in ONE byte only. */
+#define NET_NFC_NDEF_RECORD_MASK_IL 0x08 /**< The ID Length Field is present. */
+#define NET_NFC_NDEF_RECORD_MASK_TNF 0x07 /**< Type Name Format. */
+/*@}*/
+
+/* Internal:
+ * NDEF Record #defines for constant value
+ */
+
+#define NET_NFC_NDEF_TNF_EMPTY 0x00 /**< Empty Record, no type, ID or payload present. */
+#define NET_NFC_NDEF_TNF_NFCWELLKNOWN 0x01 /**< NFC well-known type (RTD). */
+#define NET_NFC_NDEF_TNF_MEDIATYPE 0x02 /**< Media Type. */
+#define NET_NFC_NDEF_TNF_ABSURI 0x03 /**< Absolute URI. */
+#define NET_NFC_NDEF_TNF_NFCEXT 0x04 /**< Nfc External Type (following the RTD format). */
+#define NET_NFC_NDEF_TNF_UNKNOWN 0x05 /**< Unknown type; Contains no Type information. */
+#define NET_NFC_NDEF_TNF_UNCHANGED 0x06 /**< Unchanged: Used for Chunked Records. */
+#define NET_NFC_NDEF_TNF_RESERVED 0x07 /**< RFU, must not be used. */
+
+/*
+ convert rawdata into ndef message structure
+ */
+net_nfc_error_e net_nfc_util_convert_rawdata_to_ndef_message(data_s *rawdata, ndef_message_s *ndef);
+
+/*
+ this util function converts into rawdata from ndef message structure
+ */
+net_nfc_error_e net_nfc_util_convert_ndef_message_to_rawdata(ndef_message_s *ndef, data_s *rawdata);
+
+/*
+ get total bytes of ndef message in serial form
+ */
+uint32_t net_nfc_util_get_ndef_message_length(ndef_message_s *message);
+
+/*
+ free ndef message. this function also free any defined buffer insdie structures
+ */
+net_nfc_error_e net_nfc_util_free_ndef_message(ndef_message_s *msg);
+
+/*
+ append record into ndef message
+ */
+net_nfc_error_e net_nfc_util_append_record(ndef_message_s *msg, ndef_record_s *record);
+
+/*
+ print out ndef structure value with printf function. this is for just debug purpose
+ */
+void net_nfc_util_print_ndef_message(ndef_message_s *msg);
+
+net_nfc_error_e net_nfc_util_create_ndef_message(ndef_message_s **ndef_message);
+
+net_nfc_error_e net_nfc_util_search_record_by_type(ndef_message_s *ndef_message, net_nfc_record_tnf_e tnf, data_s *type, ndef_record_s **record);
+
+net_nfc_error_e net_nfc_util_append_record_by_index(ndef_message_s *ndef_message, int index, ndef_record_s *record);
+
+net_nfc_error_e net_nfc_util_get_record_by_index(ndef_message_s *ndef_message, int index, ndef_record_s **record);
+
+net_nfc_error_e net_nfc_util_remove_record_by_index(ndef_message_s *ndef_message, int index);
+
+net_nfc_error_e net_nfc_util_search_record_by_id(ndef_message_s *ndef_message, data_s *id, ndef_record_s **record);
+
+#endif //__NET_NFC_UTIL_NDEF_MESSAGE_H__
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_UTIL_NDEF_RECORD_H__
+#define __NET_NFC_UTIL_NDEF_RECORD_H__
+
+#include "net_nfc_typedef_internal.h"
+
+/*
+ create record structure with basic info
+ */
+net_nfc_error_e net_nfc_util_create_record(net_nfc_record_tnf_e recordType, data_s *typeName, data_s *id, data_s *payload, ndef_record_s **record);
+
+/*
+ create text type record
+ */
+net_nfc_error_e net_nfc_util_create_text_type_record(const char *text, const char *lang_code_str, net_nfc_encode_type_e encode, ndef_record_s **record);
+
+/*
+ this utility function help to create uri type record
+ */
+net_nfc_error_e net_nfc_util_create_uri_type_record(const char *uri, net_nfc_schema_type_e protocol_schema, ndef_record_s **record);
+
+/*
+ free ndef record. it free all the buffered data
+ */
+net_nfc_error_e net_nfc_util_free_record(ndef_record_s *record);
+
+/*
+ convert schema enum value to character string.
+ */
+net_nfc_error_e net_nfc_util_set_record_id(ndef_record_s *record, uint8_t *data, int length);
+
+/*
+ get total bytes of ndef record in serial form
+ */
+uint32_t net_nfc_util_get_record_length(ndef_record_s *record);
+
+/*
+ create uri string from record
+ */
+net_nfc_error_e net_nfc_util_create_uri_string_from_uri_record(ndef_record_s *record, char **uri);
+
+#endif //__NET_NFC_UTIL_NDEF_RECORD_H__
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_UTIL_SIGN_RECORD_H__
+#define __NET_NFC_UTIL_SIGN_RECORD_H__
+
+#include "net_nfc_typedef_internal.h"
+
+/*
+ * sign ndef record and ndef message
+ */
+net_nfc_error_e net_nfc_util_sign_records(ndef_message_s *msg, int begin_index, int end_index, char *cert_file, char *password);
+net_nfc_error_e net_nfc_util_sign_ndef_message(ndef_message_s *msg, char *cert_file, char *password);
+
+/*
+ * check validity of ndef record and ndef message
+ */
+net_nfc_error_e net_nfc_util_verify_signature_ndef_message(ndef_message_s *msg);
+net_nfc_error_e net_nfc_util_verify_signature_records(ndef_record_s *begin_record, ndef_record_s *sign_record);
+
+
+#endif //__NET_NFC_UTIL_SIGN_RECORD_H__
+
--- /dev/null
+<!--
+ org.tizen.NfcService
+
+-->
+
+<node>
+ <interface name="org.tizen.NetNfcService.Manager">
+ <!--
+ SetActive
+ -->
+ <method name="SetActive">
+ <arg type="b" name="is_active" direction="in" />
+ <arg type="a(y)" name="privilege" direction="in" />
+ </method>
+
+ <!--
+ GetServerState
+ -->
+ <method name="GetServerState">
+ <arg type="a(y)" name="privilege" direction="in" />
+ <arg type="u" name="state" direction="out" />
+ </method>
+
+
+ <!--
+ Activated
+ -->
+ <signal name="Activated">
+ <arg type="b" name="active" />
+ </signal>
+ </interface>
+
+ <interface name="org.tizen.NetNfcService.Tag">
+ <!--
+ IsConnected
+ -->
+ <method name="IsTagConnected">
+ <arg type="a(y)" name="privilege" direction="in" />
+ <arg type="b" name="is_connected" direction="out" />
+ <arg type="i" name="dev_type" direction="out" />
+ </method>
+
+ <!--
+ GetInfo
+ -->
+ <method name="GetCurrentTagInfo">
+ <arg type="a(y)" name="privilege" direction="in" />
+ <arg type="b" name="is_connected" direction="out" />
+ <arg type="u" name="handle" direction="out" />
+ <arg type="i" name="dev_type" direction="out" />
+ <arg type="b" name="is_ndef_supported" direction="out" />
+ <arg type="y" name="ndef_card_state" direction="out" />
+ <arg type="u" name="max_data_size" direction="out" />
+ <arg type="u" name="actual_data_size" direction="out" />
+ <arg type="u" name="number_of_keys" direction="out" />
+ <arg type="a(y)" name="target_info_values" direction="out" />
+ <arg type="a(y)" name="raw_data" direction="out" />
+ </method>
+
+ <!--
+ GetTagetHandle
+ -->
+ <method name="GetCurrentTargetHandle">
+ <arg type="a(y)" name="privilege" direction="in" />
+ <arg type="b" name="is_connected" direction="out" />
+ <arg type="u" name="handle" direction="out" />
+ <arg type="i" name="dev_type" direction="out" />
+ </method>
+
+ <!--
+ TagDiscovered
+ -->
+ <signal name="TagDiscovered">
+ <arg type="u" name="handle" />
+ <arg type="i" name="dev_type" />
+ <arg type="b" name="is_ndef_supported" />
+ <arg type="y" name="ndef_card_state" />
+ <arg type="u" name="max_data_size" />
+ <arg type="u" name="actual_data_size" />
+ <arg type="u" name="number_of_keys" />
+ <arg type="a(y)" name="target_info_values" />
+ <arg type="a(y)" name="raw_data" />
+ </signal>
+
+ <!--
+ TagDetached
+ -->
+ <signal name="TagDetached">
+ <arg type="u" name="handle" />
+ <arg type="i" name="dev_type" />
+ </signal>
+ </interface>
+
+ <interface name="org.tizen.NetNfcService.Ndef">
+ <!--
+ Read
+ -->
+ <method name="Read">
+ <arg type="u" name="handle" direction="in" />
+ <arg type="a(y)" name="privilege" direction="in" />
+ <arg type="i" name="result" direction="out" />
+ <arg type="a(y)" name="data" direction="out" />
+ </method>
+
+ <!--
+ Write
+ -->
+ <method name="Write">
+ <arg type="u" name="handle" direction="in" />
+ <arg type="a(y)" name="data" direction="in" />
+ <arg type="a(y)" name="privilege" direction="in" />
+ <arg type="i" name="result" direction="out" />
+ </method>
+
+ <!--
+ MakeReadOnly
+ -->
+ <method name="MakeReadOnly">
+ <arg type="u" name="handle" direction="in" />
+ <arg type="a(y)" name="privilege" direction="in" />
+ <arg type="i" name="result" direction="out" />
+ </method>
+
+ <!--
+ Format
+ -->
+ <method name="Format">
+ <arg type="u" name="handle" direction="in" />
+ <arg type="a(y)" name="key" direction="in" />
+ <arg type="a(y)" name="privilege" direction="in" />
+ <arg type="i" name="result" direction="out" />
+ </method>
+ </interface>
+
+ <interface name="org.tizen.NetNfcService.Llcp">
+ <!--
+ Config
+ -->
+ <method name="Config">
+ <arg type="(qqyy)" name="config" direction="in" />
+ <arg type="a(y)" name="privilege" direction="in" />
+ </method>
+ <!--
+ Listen
+ -->
+ <method name="Listen">
+ <arg type="u" name="handle" direction="in" />
+ <arg type="u" name="client_socket" direction="in" />
+ <arg type="u" name="oal_socket" direction="in" />
+ <arg type="q" name="miu" direction="in" />
+ <arg type="y" name="rw" direction="in" />
+ <arg type="i" name="type" direction="in" />
+ <arg type="y" name="sap" direction="in" />
+ <arg type="s" name="service_name" direction="in" />
+ <arg type="a(y)" name="privilege" direction="in" />
+ <arg type="u" name="client_socket" direction="out" />
+ <arg type="u" name="oal_socket" direction="out" />
+ </method>
+
+ <!--
+ Connect
+ -->
+ <method name="Connect">
+ <arg type="u" name="handle" direction="in" />
+ <arg type="u" name="client_socket" direction="in" />
+ <arg type="u" name="oal_socket" direction="in" />
+ <arg type="q" name="miu" direction="in" />
+ <arg type="y" name="rw" direction="in" />
+ <arg type="i" name="type" direction="in" />
+ <arg type="s" name="service_name" direction="in" />
+ <arg type="a(y)" name="privilege" direction="in" />
+ <arg type="u" name="client_socket" direction="out" />
+ <arg type="u" name="oal_socket" direction="out" />
+ </method>
+
+ <!--
+ ConnectSap
+ -->
+ <method name="ConnectSap">
+ <arg type="u" name="handle" direction="in" />
+ <arg type="u" name="client_socket" direction="in" />
+ <arg type="u" name="oal_socket" direction="in" />
+ <arg type="q" name="miu" direction="in" />
+ <arg type="y" name="rw" direction="in" />
+ <arg type="i" name="type" direction="in" />
+ <arg type="y" name="sap" direction="in" />
+ <arg type="a(y)" name="privilege" direction="in" />
+ <arg type="u" name="client_socket" direction="out" />
+ <arg type="u" name="oal_socket" direction="out" />
+ </method>
+
+ <!--
+ Send
+ -->
+ <method name="Send">
+ <arg type="u" name="handle" direction="in" />
+ <arg type="u" name="client_socket" direction="in" />
+ <arg type="u" name="oal_socket" direction="in" />
+ <arg type="a(y)" name="data" direction="in" />
+ <arg type="a(y)" name="privilege" direction="in" />
+ <arg type="u" name="client_socket" direction="out" />
+ </method>
+
+ <!--
+ SendTo
+ -->
+ <method name="SendTo">
+ <arg type="u" name="handle" direction="in" />
+ <arg type="u" name="client_socket" direction="in" />
+ <arg type="u" name="oal_socket" direction="in" />
+ <arg type="y" name="sap" direction="in" />
+ <arg type="a(y)" name="data" direction="in" />
+ <arg type="a(y)" name="privilege" direction="in" />
+ <arg type="u" name="client_socket" direction="out" />
+ </method>
+
+ <!--
+ Receive
+ -->
+ <method name="Receive">
+ <arg type="u" name="handle" direction="in" />
+ <arg type="u" name="client_socket" direction="in" />
+ <arg type="u" name="oal_socket" direction="in" />
+ <arg type="u" name="request_length" direction="in" />
+ <arg type="a(y)" name="privilege" direction="in" />
+ <arg type="a(y)" name="data" direction="out" />
+ </method>
+
+ <!--
+ ReceiveFrom
+ -->
+ <method name="ReceiveFrom">
+ <arg type="u" name="handle" direction="in" />
+ <arg type="u" name="client_socket" direction="in" />
+ <arg type="u" name="oal_socket" direction="in" />
+ <arg type="u" name="request_length" direction="in" />
+ <arg type="a(y)" name="privilege" direction="in" />
+ <arg type="y" name="sap" direction="out" />
+ <arg type="a(y)" name="data" direction="out" />
+ </method>
+
+ <!--
+ Close
+ -->
+ <method name="Close">
+ <arg type="u" name="handle" direction="in" />
+ <arg type="u" name="client_socket" direction="in" />
+ <arg type="u" name="oal_socket" direction="in" />
+ <arg type="a(y)" name="privilege" direction="in" />
+ <arg type="u" name="client_socket" direction="out" />
+ </method>
+
+ <!--
+ Disconnect
+ -->
+ <method name="Disconnect">
+ <arg type="u" name="handle" direction="in" />
+ <arg type="u" name="client_socket" direction="in" />
+ <arg type="u" name="oal_socket" direction="in" />
+ <arg type="a(y)" name="privilege" direction="in" />
+ <arg type="u" name="client_socket" direction="out" />
+ </method>
+
+ <!--
+ Error
+ -->
+ <signal name="Error">
+ <arg type="u" name="handle" />
+ <arg type="u" name="client_socket" />
+ <arg type="u" name="oal_socket" />
+ <arg type="i" name="error" />
+ </signal>
+ </interface>
+
+ <interface name="org.tizen.NetNfcService.P2p">
+ <!--
+ Send
+ -->
+ <method name="Send">
+ <arg type="i" name="type" direction="in" />
+ <arg type="a(y)" name="data" direction="in" />
+ <arg type="u" name="handle" direction="in" />
+ <arg type="a(y)" name="privilege" direction="in" />
+ <arg type="i" name="result" direction="out" />
+ </method>
+
+ <!--
+ Detached
+ -->
+ <signal name="Detached" />
+
+ <!--
+ Discovered
+ -->
+ <signal name="Discovered">
+ <arg type="u" name="handle" />
+ </signal>
+
+ <!--
+ Receive
+ -->
+ <signal name="Received">
+ <arg type="a(y)" name="data" />
+ </signal>
+
+ </interface>
+ <interface name="org.tizen.NetNfcService.Popup">
+ <!--
+ Set
+ -->
+ <method name="Set">
+ <arg type="b" name="state" direction="in" />
+ <arg type="i" name="focus_state" direction="in" />
+ <arg type="a(y)" name="privilege" direction="in" />
+ </method>
+
+ <!--
+ Get
+ -->
+ <method name="Get">
+ <arg type="a(y)" name="privilege" direction="in" />
+ <arg type="b" name="state" direction="out" />
+ </method>
+ </interface>
+
+ <interface name="org.tizen.NetNfcService.SecureElement">
+ <!--
+ Set
+ -->
+ <method name="Set">
+ <arg type="i" name="type" direction="in" />
+ <arg type="a(y)" name="privilege" direction="in" />
+ <arg type="i" name="result" direction="out" />
+ </method>
+
+ <!--
+ OpenSecureElement
+ -->
+ <method name="OpenSecureElement">
+ <arg type="i" name="type" direction="in" />
+ <arg type="a(y)" name="privilege" direction="in" />
+ <arg type="i" name="result" direction="out" />
+ <arg type="u" name="handle" direction="out" />
+ </method>
+
+ <!--
+ CloseSecureElement
+ -->
+ <method name="CloseSecureElement">
+ <arg type="u" name="handle" direction="in" />
+ <arg type="a(y)" name="privilege" direction="in" />
+ <arg type="i" name="result" direction="out" />
+ </method>
+
+ <!--
+ GetAtr
+ -->
+ <method name="GetAtr">
+ <arg type="u" name="handle" direction="in" />
+ <arg type="a(y)" name="privilege" direction="in" />
+ <arg type="i" name="result" direction="out" />
+ <arg type="a(y)" name="atr" direction="out" />
+ </method>
+
+ <!--
+ SendAPDU
+ -->
+ <method name="SendAPDU">
+ <arg type="u" name="handle" direction="in" />
+ <arg type="a(y)" name="data" direction="in" />
+ <arg type="a(y)" name="privilege" direction="in" />
+ <arg type="i" name="result" direction="out" />
+ <arg type="a(y)" name="response" direction="out" />
+ </method>
+
+ <!--
+ EseDetected
+ -->
+ <signal name="EseDetected">
+ <arg type="u" name="handle" />
+ <arg type="i" name="se_type" />
+ <arg type="a(y)" name="data" />
+ </signal>
+
+ <!--
+ SeTypeChanged
+ -->
+ <signal name="SeTypeChanged">
+ <arg type="i" name="se_type" />
+ </signal>
+
+ <!--
+ TransactionEvent
+ -->
+ <signal name="TransactionEvent">
+ <arg type="i" name="se_type" />
+ <arg type="a(y)" name="aid" />
+ <arg type="a(y)" name="param" />
+ </signal>
+ </interface>
+
+ <interface name="org.tizen.NetNfcService.Transceive">
+ <!--
+ TransceiveData
+ -->
+ <method name="TransceiveData">
+ <arg type="u" name="handle" direction="in" />
+ <arg type="u" name="dev_type" direction="in" />
+ <arg type="a(y)" name="data" direction="in" />
+ <arg type="a(y)" name="privilege" direction="in" />
+ <arg type="i" name="result" direction="out" />
+ <arg type="a(y)" name="resp_data" direction="out" />
+ </method>
+ <!--
+ Transceive
+ -->
+ <method name="Transceive">
+ <arg type="u" name="handle" direction="in" />
+ <arg type="u" name="dev_type" direction="in" />
+ <arg type="a(y)" name="data" direction="in" />
+ <arg type="a(y)" name="privilege" direction="in" />
+ <arg type="i" name="result" direction="out" />
+ </method>
+ </interface>
+
+ <interface name="org.tizen.NetNfcService.Handover">
+ <!--
+ Request
+ -->
+ <method name="Request">
+ <arg type="u" name="handle" direction="in" />
+ <arg type="i" name="type" direction="in" />
+ <arg type="a(y)" name="privilege" direction="in" />
+ <arg type="i" name="event" direction="out" />
+ <arg type="i" name="carrier_type" direction="out" />
+ <arg type="a(y)" name="handover_data" direction="out" />
+ </method>
+ </interface>
+
+ <interface name="org.tizen.NetNfcService.Test">
+ <!--
+ SimTest
+ -->
+ <method name="SimTest">
+ <arg type="a(y)" name="privilege" direction="in" />
+ <arg type="i" name="result" direction="out" />
+ </method>
+
+ <!--
+ PrbsTest
+ -->
+ <method name="PrbsTest">
+ <arg type="u" name="tech" direction="in" />
+ <arg type="u" name="rate" direction="in" />
+ <arg type="a(y)" name="privilege" direction="in" />
+ <arg type="i" name="result" direction="out" />
+ </method>
+
+ <!--
+ GetFirmwareVersion
+ -->
+ <method name="GetFirmwareVersion">
+ <arg type="a(y)" name="privilege" direction="in" />
+ <arg type="i" name="result" direction="out" />
+ <arg type="s" name="version" direction="out" />
+ </method>
+
+ <method name="SetEeData">
+ <arg type="u" name="mode" direction="in" />
+ <arg type="u" name="reg_id" direction="in" />
+ <arg type="a(y)" name="data" direction="in" />
+ <arg type="a(y)" name="privilege" direction="in" />
+ <arg type="i" name="result" direction="out" />
+ </method>
+ </interface>
+
+ <interface name="org.tizen.NetNfcService.Snep">
+ <!--
+ Register Server
+ -->
+ <method name="ServerRegister">
+ <arg type="u" name="sap" direction="in" />
+ <arg type="s" name="san" direction="in" />
+ <arg type="u" name="user_data" direction="in" />
+ <arg type="a(y)" name="privilege" direction="in" />
+ <arg type="i" name="result" direction="out" />
+ </method>
+
+ <!--
+ Unregister Server
+ -->
+ <method name="ServerUnregister">
+ <arg type="u" name="sap" direction="in" />
+ <arg type="s" name="san" direction="in" />
+ <arg type="a(y)" name="privilege" direction="in" />
+ <arg type="i" name="result" direction="out" />
+ </method>
+
+ <!--
+ Start Server
+ -->
+ <method name="ServerStart">
+ <arg type="u" name="handle" direction="in" />
+ <arg type="u" name="sap" direction="in" />
+ <arg type="s" name="san" direction="in" />
+ <arg type="u" name="user_data" direction="in" />
+ <arg type="a(y)" name="privilege" direction="in" />
+ <arg type="i" name="result" direction="out" />
+ </method>
+
+ <!--
+ Start Client
+ -->
+ <method name="ClientStart">
+ <arg type="u" name="handle" direction="in" />
+ <arg type="u" name="sap" direction="in" />
+ <arg type="s" name="san" direction="in" />
+ <arg type="u" name="user_data" direction="in" />
+ <arg type="a(y)" name="privilege" direction="in" />
+ <arg type="i" name="result" direction="out" />
+ </method>
+
+ <!--
+ ClientRequest
+ -->
+ <method name="ClientRequest">
+ <arg type="u" name="snep_handle" direction="in" />
+ <arg type="u" name="type" direction="in" />
+ <arg type="a(y)" name="ndef_msg" direction="in" />
+ <arg type="a(y)" name="privilege" direction="in" />
+ <arg type="i" name="result" direction="out" />
+ <arg type="u" name="type" direction="out" />
+ <arg type="a(y)" name="data" direction="out" />
+ </method>
+
+ <!--
+ StopService
+ -->
+ <method name="StopSnep">
+ <arg type="u" name="handle" direction="in" />
+ <arg type="u" name="snep_handle" direction="in" />
+ <arg type="a(y)" name="privilege" direction="in" />
+ <arg type="i" name="result" direction="out" />
+ </method>
+
+ <!--
+ SnepEvent
+ -->
+ <signal name="SnepEvent">
+ <arg type="u" name="handle" />
+ <arg type="u" name="event" />
+ <arg type="i" name="result" />
+ <arg type="a(y)" name="ndef_msg" />
+ <arg type="u" name="user_data" />
+ </signal>
+ </interface>
+
+</node>
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_DEBUG_INTERNAL_H__
+#define __NET_NFC_DEBUG_INTERNAL_H__
+
+#include <stdio.h>
+#include <errno.h>
+#include <time.h>
+#include <sys/time.h>
+#include <libgen.h>
+#include <dlog.h>
+
+#define LOG_SERVER_TAG "NET_NFC_MANAGER"
+#define LOG_CLIENT_TAG "NET_NFC_CLIENT"
+
+#define LOG_COLOR_RED "\033[0;31m"
+#define LOG_COLOR_GREEN "\033[0;32m"
+#define LOG_COLOR_BROWN "\033[0;33m"
+#define LOG_COLOR_BLUE "\033[0;34m"
+#define LOG_COLOR_PURPLE "\033[0;35m"
+#define LOG_COLOR_CYAN "\033[0;36m"
+#define LOG_COLOR_LIGHTBLUE "\033[0;37m"
+#define LOG_COLOR_END "\033[0;m"
+
+#ifndef API
+#define API __attribute__((visibility("default")))
+#endif
+
+
+/* nfc_log_to_file */
+extern FILE *nfc_log_file;
+#define NFC_DLOG_FILE "/opt/usr/share/nfc_debug/nfc_mgr_dlog.txt"
+
+/* tag */
+const char *net_nfc_get_log_tag();
+
+#define NFC_LOGD(format, arg...) SLOG(LOG_DEBUG, net_nfc_get_log_tag(), format, ##arg)
+#define NFC_LOGI(format, arg...) SLOG(LOG_INFO, net_nfc_get_log_tag(), format, ##arg)
+#define NFC_LOGW(format, arg...) SLOG(LOG_WARN, net_nfc_get_log_tag(), format, ##arg)
+#define NFC_LOGE(format, arg...) SLOG(LOG_ERROR, net_nfc_get_log_tag(), format, ##arg)
+
+#ifndef SECURE_LOGD
+#define SECURE_LOGD NFC_LOGD
+#endif
+
+#define DEBUG_MSG_PRINT_BUFFER(buffer, length) \
+ do { \
+ int i = 0, offset = 0; \
+ char temp_buffer[4096] = { 0, }; \
+ NFC_LOGD(LOG_COLOR_BLUE "BUFFER [%d] = {" LOG_COLOR_END, length); \
+ for(; i < length && offset < sizeof(temp_buffer); i++) \
+ { \
+ offset += snprintf(temp_buffer + offset, sizeof(temp_buffer) - offset, " %02x", buffer[i]); \
+ if (i % 16 == 15) \
+ { \
+ NFC_LOGD(LOG_COLOR_BLUE "\t%s" LOG_COLOR_END, temp_buffer); \
+ offset = 0; \
+ } \
+ } \
+ NFC_LOGD(LOG_COLOR_BLUE "\t%s" LOG_COLOR_END, temp_buffer); \
+ NFC_LOGD(LOG_COLOR_BLUE "}" LOG_COLOR_END); \
+ } while(0)
+
+#define DEBUG_MSG_PRINT_BUFFER_CHAR(buffer, length) \
+ do { \
+ int i = 0, offset = 0; \
+ char temp_buffer[4096] = { 0, }; \
+ NFC_LOGD(LOG_COLOR_BLUE "BUFFER [%d] = {" LOG_COLOR_END, length); \
+ for(; i < length && offset < sizeof(temp_buffer); i++) \
+ { \
+ offset += snprintf(temp_buffer + offset, sizeof(temp_buffer) - offset, " %c", buffer[i]); \
+ if (i % 16 == 15) \
+ { \
+ NFC_LOGD(LOG_COLOR_BLUE "\t%s" LOG_COLOR_END, temp_buffer); \
+ offset = 0; \
+ } \
+ } \
+ NFC_LOGD(LOG_COLOR_BLUE "\t%s" LOG_COLOR_END, temp_buffer); \
+ NFC_LOGD(LOG_COLOR_BLUE "}" LOG_COLOR_END); \
+ } while(0)
+
+#define DEBUG_MSG(format, args...) \
+ do { \
+ NFC_LOGD(format, ##args); \
+ if (nfc_log_file) \
+ { \
+ char timeBuf[50]; \
+ time_t rawtime; time (&rawtime); strftime(timeBuf, sizeof(timeBuf), "%m-%d %H:%M:%S", localtime(&rawtime)); \
+ fprintf(nfc_log_file, "\n%s",timeBuf); \
+ fprintf(nfc_log_file, "[D][%s:%d] "format"",__func__, __LINE__, ##args); \
+ fflush(nfc_log_file);\
+ }\
+ } while(0)
+
+#define DEBUG_SERVER_MSG(format, args...) \
+ do {\
+ NFC_LOGD(LOG_COLOR_PURPLE format LOG_COLOR_END, ##args);\
+ if (nfc_log_file) \
+ { \
+ char timeBuf[50]; \
+ time_t rawtime; time (&rawtime); strftime(timeBuf, sizeof(timeBuf), "%m-%d %H:%M:%S", localtime(&rawtime)); \
+ fprintf(nfc_log_file, "\n%s",timeBuf); \
+ fprintf(nfc_log_file, "[S][%s:%d] "format"",__func__, __LINE__, ##args); \
+ fflush(nfc_log_file);\
+ } \
+ } while(0)
+
+#define DEBUG_CLIENT_MSG(format, args...) \
+ do {\
+ NFC_LOGD(LOG_COLOR_CYAN format LOG_COLOR_END, ##args); \
+ if (nfc_log_file) \
+ { \
+ char timeBuf[50]; \
+ time_t rawtime; time (&rawtime); strftime(timeBuf, sizeof(timeBuf), "%m-%d %H:%M:%S", localtime(&rawtime)); \
+ fprintf(nfc_log_file, "\n%s",timeBuf); \
+ fprintf(nfc_log_file, "[C][%s:%d] "format"",__func__, __LINE__, ##args); \
+ fflush(nfc_log_file);\
+ }\
+ } while(0)
+
+#define DEBUG_ERR_MSG(format, args...) \
+ do {\
+ NFC_LOGD(LOG_COLOR_RED format LOG_COLOR_END, ##args);\
+ if (nfc_log_file) \
+ { \
+ char timeBuf[50]; \
+ time_t rawtime; time (&rawtime); strftime(timeBuf, sizeof(timeBuf), "%m-%d %H:%M:%S", localtime(&rawtime)); \
+ fprintf(nfc_log_file, "\n%s",timeBuf); \
+ fprintf(nfc_log_file, "[E][%s:%d] "format"",__func__, __LINE__, ##args); \
+ fflush(nfc_log_file);\
+ } \
+ } while(0)
+
+#define INFO_MSG(format, args...) \
+ do {\
+ NFC_LOGI(LOG_COLOR_GREEN format LOG_COLOR_END, ##args);\
+ if (nfc_log_file) \
+ { \
+ char timeBuf[50]; \
+ time_t rawtime; time (&rawtime); strftime(timeBuf, sizeof(timeBuf), "%m-%d %H:%M:%S", localtime(&rawtime)); \
+ fprintf(nfc_log_file, "\n%s",timeBuf); \
+ fprintf(nfc_log_file, "[I][%s:%d] "format"",__func__, __LINE__, ##args); \
+ fflush(nfc_log_file);\
+ } \
+ } while(0)
+
+#define WARN_MSG(format, args...) \
+ do {\
+ NFC_LOGW(LOG_COLOR_BROWN format LOG_COLOR_END, ##args);\
+ if (nfc_log_file) \
+ { \
+ char timeBuf[50]; \
+ time_t rawtime; time (&rawtime); strftime(timeBuf, sizeof(timeBuf), "%m-%d %H:%M:%S", localtime(&rawtime)); \
+ fprintf(nfc_log_file, "\n%s",timeBuf); \
+ fprintf(nfc_log_file, "[W][%s:%d] "format"",__func__, __LINE__, ##args); \
+ fflush(nfc_log_file);\
+ } \
+ } while(0)
+
+#define PROFILING(str) \
+ do{ \
+ struct timeval mytime;\
+ char buf[128]; = {0};\
+ memset(buf, 0x00, 128);\
+ gettimeofday(&mytime, NULL);\
+ char time_string[128] = {0,};\
+ sprintf(time_string, "%d.%4d", mytime.tv_sec, mytime.tv_usec);\
+ NFC_LOGD(str); \
+ NFC_LOGD("\t time = [%s]", time_string);\
+ } while(0)
+
+#endif //__NET_NFC_DEBUG_INTERNAL_H__
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// libc header
+#include <stdlib.h>
+#include <string.h>
+#include <pthread.h>
+#include <fcntl.h>
+
+// platform header
+#include <bluetooth-api.h>
+#include <vconf.h>
+
+// nfc-manager header
+#include "net_nfc_util_internal.h"
+#include "net_nfc_debug_internal.h"
+#include "net_nfc_oem_controller.h"
+#include "net_nfc_util_defines.h"
+
+static const char *schema[] =
+{
+ "",
+ "http://www.",
+ "https://www.",
+ "http://",
+ "https://",
+ "tel:",
+ "mailto:",
+ "ftp://anonymous:anonymous@",
+ "ftp://ftp.",
+ "ftps://",
+ "sftp://",
+ "smb://",
+ "nfs://",
+ "ftp://",
+ "dav://",
+ "news:",
+ "telnet://",
+ "imap:",
+ "rtsp://",
+ "urn:",
+ "pop:",
+ "sip:",
+ "sips:",
+ "tftp:",
+ "btspp://",
+ "btl2cap://",
+ "btgoep://",
+ "tcpobex://",
+ "irdaobex://",
+ "file://",
+ "urn:epc:id:",
+ "urn:epc:tag:",
+ "urn:epc:pat:",
+ "urn:epc:raw:",
+ "urn:epc:",
+ "urn:epc:nfc:",
+};
+
+static uint8_t *bt_addr = NULL;
+
+/* for log tag */
+#define NET_NFC_MANAGER_NAME "nfc-manager-daemon"
+static const char *log_tag = LOG_CLIENT_TAG;
+extern char *__progname;
+FILE *nfc_log_file;
+
+const char *net_nfc_get_log_tag()
+{
+ return log_tag;
+}
+
+void __attribute__ ((constructor)) lib_init()
+{
+ if (__progname != NULL && strncmp(__progname, NET_NFC_MANAGER_NAME, strlen(NET_NFC_MANAGER_NAME)) == 0)
+ {
+ log_tag = LOG_SERVER_TAG;
+ }
+}
+
+void __attribute__ ((destructor)) lib_fini()
+{
+}
+
+void net_nfc_manager_init_log()
+{
+ nfc_log_file = fopen(NFC_DLOG_FILE, "a+");
+ if (nfc_log_file != NULL)
+ {
+ char timeBuf[50];
+ time_t rawtime;
+
+ time (&rawtime);
+ strftime(timeBuf, sizeof(timeBuf), "%m-%d %H:%M:%S", localtime(&rawtime));
+ fprintf(nfc_log_file, "\n%s",timeBuf);
+ fprintf(nfc_log_file, "========== log begin, pid [%d] =========", getpid());
+ fflush(nfc_log_file);
+ }
+ else
+ {
+ fprintf(stderr, "\n\nfopen error\n\n");
+ }
+}
+
+void net_nfc_manager_fini_log()
+{
+ if (nfc_log_file != NULL)
+ {
+ char timeBuf[50];
+ time_t rawtime;
+
+ time (&rawtime);
+ strftime(timeBuf, sizeof(timeBuf), "%m-%d %H:%M:%S", localtime(&rawtime));
+ fprintf(nfc_log_file, "\n%s",timeBuf);
+ fprintf(nfc_log_file, "=========== log end, pid [%d] ==========", getpid());
+ fflush(nfc_log_file);
+ fclose(nfc_log_file);
+ nfc_log_file = NULL;
+ }
+}
+
+API void __net_nfc_util_free_mem(void **mem, char *filename, unsigned int line)
+{
+ if (mem == NULL)
+ {
+ SECURE_LOGD("FILE: %s, LINE:%d, Invalid parameter in mem free util, mem is NULL", filename, line);
+ return;
+ }
+
+ if (*mem == NULL)
+ {
+ SECURE_LOGD("FILE: %s, LINE:%d, Invalid Parameter in mem free util, *mem is NULL", filename, line);
+ return;
+ }
+
+ g_free(*mem);
+ *mem = NULL;
+}
+
+API void __net_nfc_util_alloc_mem(void **mem, int size, char *filename, unsigned int line)
+{
+ if (mem == NULL || size <= 0)
+ {
+ SECURE_LOGD("FILE: %s, LINE:%d, Invalid parameter in mem alloc util, mem [%p], size [%d]", filename, line, mem, size);
+ return;
+ }
+
+ if (*mem != NULL)
+ {
+ SECURE_LOGD("FILE: %s, LINE:%d, WARNING: Pointer is not NULL, mem [%p]", filename, line, *mem);
+ }
+
+ *mem = g_malloc0(size);
+
+ if (*mem == NULL)
+ {
+ SECURE_LOGD("FILE: %s, LINE:%d, Allocation is failed, size [%d]", filename, line, size);
+ }
+}
+
+API void __net_nfc_util_strdup(char **output, const char *origin, char *filename, unsigned int line)
+{
+ if (output == NULL || origin == NULL)
+ {
+ SECURE_LOGD("FILE: %s, LINE:%d, Invalid parameter in strdup, output [%p], origin [%p]", filename, line, output, origin);
+ return;
+ }
+
+ if (*output != NULL)
+ {
+ SECURE_LOGD("FILE: %s, LINE:%d, WARNING: Pointer is not NULL, mem [%p]", filename, line, *output);
+ }
+
+ *output = g_strdup(origin);
+
+ if (*output == NULL)
+ {
+ SECURE_LOGD("FILE: %s, LINE:%d, strdup failed", filename, line);
+ }
+}
+
+API bool net_nfc_util_alloc_data(data_s *data, uint32_t length)
+{
+ if (data == NULL || length == 0)
+ return false;
+
+ _net_nfc_util_alloc_mem(data->buffer, length);
+ if (data->buffer == NULL)
+ return false;
+
+ data->length = length;
+
+ return true;
+}
+
+API bool net_nfc_util_duplicate_data(data_s *dest, net_nfc_data_s *src)
+{
+ if (dest == NULL || src == NULL || src->length == 0)
+ return false;
+
+ if (net_nfc_util_alloc_data(dest, src->length) == false)
+ return false;
+
+ memcpy(dest->buffer, src->buffer, dest->length);
+
+ return true;
+}
+
+API void net_nfc_util_free_data(data_s *data)
+{
+ if (data == NULL || data->buffer == NULL)
+ return;
+
+ _net_nfc_util_free_mem(data->buffer);
+ data->length = 0;
+}
+
+net_nfc_conn_handover_carrier_state_e net_nfc_util_get_cps(net_nfc_conn_handover_carrier_type_e carrier_type)
+{
+ net_nfc_conn_handover_carrier_state_e cps = NET_NFC_CONN_HANDOVER_CARRIER_INACTIVATE;
+
+ if (carrier_type == NET_NFC_CONN_HANDOVER_CARRIER_BT)
+ {
+ int ret = bluetooth_check_adapter();
+
+ switch (ret)
+ {
+ case BLUETOOTH_ADAPTER_ENABLED :
+ cps = NET_NFC_CONN_HANDOVER_CARRIER_ACTIVATE;
+ break;
+
+ case BLUETOOTH_ADAPTER_CHANGING_ENABLE :
+ cps = NET_NFC_CONN_HANDOVER_CARRIER_ACTIVATING;
+ break;
+
+ case BLUETOOTH_ADAPTER_DISABLED :
+ case BLUETOOTH_ADAPTER_CHANGING_DISABLE :
+ case BLUETOOTH_ERROR_NO_RESOURCES :
+ default :
+ cps = NET_NFC_CONN_HANDOVER_CARRIER_INACTIVATE;
+ break;
+ }
+ }
+ else if (carrier_type == NET_NFC_CONN_HANDOVER_CARRIER_WIFI_BSS)
+ {
+ int wifi_state = 0;
+
+ vconf_get_int(VCONFKEY_WIFI_STATE, &wifi_state);
+
+ switch (wifi_state)
+ {
+ case VCONFKEY_WIFI_UNCONNECTED :
+ case VCONFKEY_WIFI_CONNECTED :
+ case VCONFKEY_WIFI_TRANSFER :
+ cps = NET_NFC_CONN_HANDOVER_CARRIER_ACTIVATE;
+ break;
+
+ case VCONFKEY_WIFI_OFF :
+ default :
+ cps = NET_NFC_CONN_HANDOVER_CARRIER_INACTIVATE;
+ break;
+ }
+ }
+
+ return cps;
+}
+
+uint8_t *net_nfc_util_get_local_bt_address()
+{
+ if (bt_addr != NULL)
+ {
+ return bt_addr;
+ }
+
+ _net_nfc_util_alloc_mem(bt_addr, BLUETOOTH_ADDRESS_LENGTH);
+ if (bt_addr != NULL)
+ {
+ if (net_nfc_util_get_cps(NET_NFC_CONN_HANDOVER_CARRIER_BT) != NET_NFC_CONN_HANDOVER_CARRIER_ACTIVATE)
+ {
+ // bt power is off. so get bt address from configuration file.
+ FILE *fp = NULL;
+
+ if ((fp = fopen(HIDDEN_BT_ADDR_FILE, "r")) != NULL)
+ {
+ unsigned char temp[BLUETOOTH_ADDRESS_LENGTH * 2] = { 0, };
+
+ int ch;
+ int count = 0;
+ int i = 0;
+
+ while ((ch = fgetc(fp)) != EOF && count < BLUETOOTH_ADDRESS_LENGTH * 2)
+ {
+ if (((ch >= '0') && (ch <= '9')))
+ {
+ temp[count++] = ch - '0';
+ }
+ else if (((ch >= 'a') && (ch <= 'z')))
+ {
+ temp[count++] = ch - 'a' + 10;
+ }
+ else if (((ch >= 'A') && (ch <= 'Z')))
+ {
+ temp[count++] = ch - 'A' + 10;
+ }
+ }
+
+ for (; i < BLUETOOTH_ADDRESS_LENGTH; i++)
+ {
+ bt_addr[i] = temp[i * 2] << 4 | temp[i * 2 + 1];
+ }
+
+ fclose(fp);
+ }
+ }
+ else
+ {
+ bluetooth_device_address_t local_address;
+
+ memset(&local_address, 0x00, sizeof(bluetooth_device_address_t));
+
+ bluetooth_get_local_address(&local_address);
+
+ memcpy(bt_addr, &local_address.addr, BLUETOOTH_ADDRESS_LENGTH);
+ }
+ }
+
+ return bt_addr;
+}
+
+void net_nfc_util_enable_bluetooth(void)
+{
+ bluetooth_enable_adapter();
+}
+
+bool net_nfc_util_strip_string(char *buffer, int buffer_length)
+{
+ bool result = false;
+ char *temp = NULL;
+ int i = 0;
+
+ _net_nfc_util_alloc_mem(temp, buffer_length);
+ if (temp == NULL)
+ {
+ return result;
+ }
+
+ for (; i < buffer_length; i++)
+ {
+ if (buffer[i] != ' ' && buffer[i] != '\t')
+ break;
+ }
+
+ if (i < buffer_length)
+ {
+ memcpy(temp, &buffer[i], buffer_length - i);
+ memset(buffer, 0x00, buffer_length);
+
+ memcpy(buffer, temp, buffer_length - i);
+
+ result = true;
+ }
+ else
+ {
+ result = false;
+ }
+
+ _net_nfc_util_free_mem(temp);
+
+ return true;
+}
+
+static uint16_t _net_nfc_util_update_CRC(uint8_t ch, uint16_t *lpwCrc)
+{
+ ch = (ch ^ (uint8_t)((*lpwCrc) & 0x00FF));
+ ch = (ch ^ (ch << 4));
+ *lpwCrc = (*lpwCrc >> 8) ^ ((uint16_t)ch << 8) ^ ((uint16_t)ch << 3) ^ ((uint16_t)ch >> 4);
+ return (*lpwCrc);
+}
+
+void net_nfc_util_compute_CRC(CRC_type_e CRC_type, uint8_t *buffer, uint32_t length)
+{
+ uint8_t chBlock = 0;
+ int msg_length = length - 2;
+ uint8_t *temp = buffer;
+
+ // default is CRC_B
+ uint16_t wCrc = 0xFFFF; /* ISO/IEC 13239 (formerly ISO/IEC 3309) */
+
+ switch (CRC_type)
+ {
+ case CRC_A :
+ wCrc = 0x6363;
+ break;
+
+ case CRC_B :
+ wCrc = 0xFFFF;
+ break;
+ }
+
+ do
+ {
+ chBlock = *buffer++;
+ _net_nfc_util_update_CRC(chBlock, &wCrc);
+ }
+ while (--msg_length > 0);
+
+ if (CRC_type == CRC_B)
+ {
+ wCrc = ~wCrc; /* ISO/IEC 13239 (formerly ISO/IEC 3309) */
+ }
+
+ temp[length - 2] = (uint8_t)(wCrc & 0xFF);
+ temp[length - 1] = (uint8_t)((wCrc >> 8) & 0xFF);
+}
+
+const char *net_nfc_util_get_schema_string(int index)
+{
+ if (index == 0 || index >= NET_NFC_SCHEMA_MAX)
+ return NULL;
+ else
+ return schema[index];
+}
+
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_UTIL_DEFINES_H__
+#define __NET_NFC_UTIL_DEFINES_H__
+
+#define NET_NFC_UTIL_MSG_TYPE_REQUEST 0
+#define NET_NFC_UTIL_MSG_TYPE_RESPONSE 1
+
+#define CONN_HANDOVER_BT_CARRIER_MIME_NAME "application/vnd.bluetooth.ep.oob"
+#define CONN_HANDOVER_WIFI_BSS_CARRIER_MIME_NAME "application/vnd.wfa.wsc"
+#define CONN_HANDOVER_WIFI_IBSS_CARRIER_MIME_NAME "application/vnd.wfa.wsc;mode=ibss"
+
+#define BLUETOOTH_ADDRESS_LENGTH 6
+#define HIDDEN_BT_ADDR_FILE "/opt/etc/.bd_addr"
+
+#endif //__NET_NFC_UTIL_DEFINES_H__
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// libc header
+
+// platform header
+
+// nfc-manager header
+#include "net_nfc_debug_internal.h"
+#include "net_nfc_util_internal.h"
+#include "net_nfc_util_gdbus_internal.h"
+
+void net_nfc_util_gdbus_variant_to_buffer(GVariant *variant, uint8_t **buffer,
+ size_t *length)
+{
+ GVariantIter *iter;
+ guint8 *buf = NULL;
+ guint size = 0;
+
+ if (variant == NULL)
+ return;
+
+ g_variant_get(variant, "a(y)", &iter);
+
+ size = g_variant_iter_n_children(iter);
+ buf = g_new0(guint8, size);
+ if (buf != NULL)
+ {
+ guint8 element;
+ guint i;
+
+ i = 0;
+ while (g_variant_iter_loop(iter, "(y)", &element))
+ {
+ *(buf + i) = element;
+ i++;
+ }
+
+ g_variant_iter_free(iter);
+
+ if (length)
+ *length = size;
+
+ if (buffer)
+ *buffer = buf;
+ else
+ g_free(buf);
+ }
+}
+
+data_s *net_nfc_util_gdbus_variant_to_data(GVariant *variant)
+{
+ GVariantIter *iter;
+ guint8 *buf = NULL;
+ guint size = 0;
+ data_s *result = NULL;
+
+ if (variant == NULL)
+ return result;
+
+ g_variant_get(variant, "a(y)", &iter);
+
+ size = g_variant_iter_n_children(iter);
+ buf = g_new0(guint8, size);
+ if (buf != NULL)
+ {
+ guint i;
+ guint8 element;
+
+ i = 0;
+ while (g_variant_iter_loop(iter, "(y)", &element))
+ {
+ *(buf + i) = element;
+ i++;
+ }
+
+ g_variant_iter_free(iter);
+
+ result = g_new0(data_s, 1);
+ if (result != NULL)
+ {
+ result->buffer = buf;
+ result->length = size;
+ }
+ else
+ {
+ g_free(buf);
+ }
+ }
+
+ return result;
+}
+
+void net_nfc_util_gdbus_variant_to_data_s(GVariant *variant, data_s *data)
+{
+ GVariantIter *iter;
+
+ guint8 element;
+ guint8 *buf = NULL;
+
+ guint size = 0;
+
+ if (data == NULL)
+ return;
+
+ data->buffer = NULL;
+ data->length = 0;
+
+ if (variant == NULL)
+ {
+ return;
+ }
+
+ g_variant_get(variant, "a(y)", &iter);
+
+ size = g_variant_iter_n_children(iter);
+ buf = g_new0(guint8, size);
+ if (buf != NULL)
+ {
+ guint i = 0;
+
+ while (g_variant_iter_loop(iter, "(y)", &element))
+ {
+ *(buf + i) = element;
+ i++;
+ }
+
+ g_variant_iter_free(iter);
+
+ data->length = size;
+ data->buffer = buf;
+ }
+}
+
+GVariant *net_nfc_util_gdbus_buffer_to_variant(const uint8_t *buffer,
+ size_t length)
+{
+ GVariantBuilder builder;
+
+ g_variant_builder_init(&builder, G_VARIANT_TYPE("a(y)"));
+
+ if (buffer && length > 0)
+ {
+ int i;
+
+ for(i = 0; i < length; i++)
+ g_variant_builder_add(&builder, "(y)", *(buffer + i));
+ }
+
+ return g_variant_builder_end(&builder);
+}
+
+GVariant *net_nfc_util_gdbus_data_to_variant(const data_s *data)
+{
+ if (data != NULL)
+ {
+ return net_nfc_util_gdbus_buffer_to_variant(data->buffer,
+ data->length);
+ }
+ else
+ {
+ return net_nfc_util_gdbus_buffer_to_variant(NULL, 0);
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_UTIL_GDBUS_INTERNAL_H__
+#define __NET_NFC_UTIL_GDBUS_INTERNAL_H__
+
+#include <glib.h>
+
+#include "net_nfc_typedef_internal.h"
+
+void net_nfc_util_gdbus_variant_to_buffer(GVariant *variant, uint8_t **buffer,
+ size_t *length);
+
+data_s *net_nfc_util_gdbus_variant_to_data(GVariant *variant);
+
+void net_nfc_util_gdbus_variant_to_data_s(GVariant *variant, data_s *data);
+
+GVariant *net_nfc_util_gdbus_buffer_to_variant(const uint8_t *buffer,
+ size_t length);
+
+GVariant *net_nfc_util_gdbus_data_to_variant(const data_s *data);
+
+#endif //__NET_NFC_UTIL_GDBUS_INTERNAL_H__
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#include <glib.h>
+
+#include "net_nfc_typedef_internal.h"
+#include "net_nfc_debug_internal.h"
+#include "net_nfc_util_defines.h"
+#include "net_nfc_util_internal.h"
+#include "net_nfc_util_ndef_record.h"
+#include "net_nfc_util_ndef_message.h"
+#include "net_nfc_util_handover.h"
+
+typedef struct _search_index
+{
+ int target;
+ int current;
+ void *found;
+} search_index;
+
+static int __property_equal_to(gconstpointer key1, gconstpointer key2)
+{
+ net_nfc_carrier_property_s *arg1 = (net_nfc_carrier_property_s *)key1;
+ net_nfc_carrier_property_s *arg2 = (net_nfc_carrier_property_s *)key2;
+
+ if (arg1->attribute < arg2->attribute)
+ {
+ return -1;
+ }
+ else if (arg1->attribute > arg2->attribute)
+ {
+ return 1;
+ }
+ else
+ {
+ return 0;
+ }
+}
+
+static net_nfc_carrier_property_s *__find_property_by_attrubute(GList *list, uint16_t attribute)
+{
+ GList *found = NULL;
+ net_nfc_carrier_property_s temp;
+
+ temp.attribute = attribute;
+ found = g_list_find_custom(list, &temp, __property_equal_to);
+
+ if (found == NULL)
+ {
+ return NULL;
+ }
+
+ return (net_nfc_carrier_property_s *)found->data;
+}
+
+static void __find_nth_group(gpointer data, gpointer user_data)
+{
+ net_nfc_carrier_property_s *info = (net_nfc_carrier_property_s *)data;
+ search_index *nth = (search_index *)user_data;
+
+ if (info == NULL || user_data == NULL)
+ return;
+
+ if (info->is_group)
+ {
+ if (nth->current == nth->target)
+ {
+ nth->found = data;
+ }
+ nth->current++;
+ }
+}
+
+static void __free_all_data(gpointer data, gpointer user_data)
+{
+ net_nfc_carrier_property_s *info = (net_nfc_carrier_property_s *)data;
+
+ if (info == NULL)
+ return;
+
+ if (info->is_group)
+ {
+ DEBUG_MSG("FREE: group is found");
+ net_nfc_util_free_carrier_group((net_nfc_carrier_property_s *)info);
+ }
+ else
+ {
+ DEBUG_MSG("FREE: element is found ATTRIB:0x%X length:%d", info->attribute, info->length);
+ _net_nfc_util_free_mem(info->data);
+ _net_nfc_util_free_mem(info);
+ }
+}
+
+static net_nfc_error_e __net_nfc_util_create_connection_handover_collsion_resolution_record(ndef_record_s **record)
+{
+ uint32_t state = 0;
+ data_s typeName = { 0 };
+ data_s payload = { 0 };
+ uint8_t rand_buffer[2] = { 0, 0 };
+ uint16_t random_num;
+
+ if (record == NULL)
+ return NET_NFC_NULL_PARAMETER;
+
+ state = (uint32_t)time(NULL);
+ random_num = (unsigned short)rand_r(&state);
+
+ typeName.buffer = (uint8_t *)COLLISION_DETECT_RECORD_TYPE;
+ typeName.length = strlen(COLLISION_DETECT_RECORD_TYPE);
+
+ rand_buffer[0] = (random_num & 0xff00) >> 8; // MSB
+ rand_buffer[1] = (random_num & 0x00ff); // LSB
+
+ payload.buffer = rand_buffer;
+ payload.length = 2;
+
+ DEBUG_MSG("rand number = [0x%x] [0x%x] => [0x%x]", payload.buffer[0], payload.buffer[1], random_num);
+
+ return net_nfc_util_create_record(NET_NFC_RECORD_WELL_KNOWN_TYPE, &typeName, NULL, &payload, record);
+}
+
+static int __net_nfc_get_size_of_attribute(int attribute)
+{
+ switch (attribute)
+ {
+ case NET_NFC_BT_ATTRIBUTE_UUID16_PART :
+ case NET_NFC_BT_ATTRIBUTE_UUID16 :
+ case NET_NFC_BT_ATTRIBUTE_UUID32_PART :
+ case NET_NFC_BT_ATTRIBUTE_UUID32 :
+ case NET_NFC_BT_ATTRIBUTE_UUID128_PART :
+ case NET_NFC_BT_ATTRIBUTE_UUID128 :
+ case NET_NFC_BT_ATTRIBUTE_NAME_PART :
+ case NET_NFC_BT_ATTRIBUTE_NAME :
+ case NET_NFC_BT_ATTRIBUTE_TXPOWER :
+ case NET_NFC_BT_ATTRIBUTE_OOB_COD :
+ case NET_NFC_BT_ATTRIBUTE_OOB_HASH_C :
+ case NET_NFC_BT_ATTRIBUTE_OOB_HASH_R :
+ case NET_NFC_BT_ATTRIBUTE_ID :
+ case NET_NFC_BT_ATTRIBUTE_MANUFACTURER :
+ case NET_NFC_BT_ATTRIBUTE_ADDRESS :
+ // case NET_NFC_WIFI_ATTRIBUTE_VERSION2:
+ return 1;
+
+ default :
+ return 2;
+ }
+}
+
+net_nfc_error_e net_nfc_util_create_carrier_config(net_nfc_carrier_config_s **config, net_nfc_conn_handover_carrier_type_e type)
+{
+ if (config == NULL)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ if (type < 0 || type >= NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN)
+ {
+ return NET_NFC_OUT_OF_BOUND;
+ }
+
+ _net_nfc_util_alloc_mem(*config, sizeof(net_nfc_carrier_config_s));
+ if (*config == NULL)
+ {
+ return NET_NFC_ALLOC_FAIL;
+ }
+
+ (*config)->type = type;
+ (*config)->length = 0;
+
+ return NET_NFC_OK;
+}
+
+net_nfc_error_e net_nfc_util_add_carrier_config_property(net_nfc_carrier_config_s *config, uint16_t attribute, uint16_t size, uint8_t * data)
+{
+ net_nfc_carrier_property_s *elem = NULL;
+
+ DEBUG_MSG("ADD property: [ATTRIB:0x%X, SIZE:%d]", attribute, size);
+
+ if (config == NULL || data == NULL)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ if (__find_property_by_attrubute(config->data, attribute) != NULL)
+ {
+ return NET_NFC_ALREADY_REGISTERED;
+ }
+
+ _net_nfc_util_alloc_mem(elem, sizeof (net_nfc_carrier_property_s));
+ if (elem == NULL)
+ {
+ return NET_NFC_ALLOC_FAIL;
+ }
+ elem->attribute = attribute;
+ elem->length = size;
+ elem->is_group = false;
+
+ _net_nfc_util_alloc_mem(elem->data, size);
+ if (elem->data == NULL)
+ {
+ _net_nfc_util_free_mem(elem);
+ return NET_NFC_ALLOC_FAIL;
+ }
+ memcpy(elem->data, data, size);
+
+ config->data = g_list_append(config->data, elem);
+ config->length += size + 2 * __net_nfc_get_size_of_attribute(attribute);
+
+ DEBUG_MSG("ADD completed total length %d", config->length);
+
+ return NET_NFC_OK;
+}
+
+net_nfc_error_e net_nfc_util_remove_carrier_config_property(net_nfc_carrier_config_s *config, uint16_t attribute)
+{
+ net_nfc_carrier_property_s *elem = NULL;
+
+ if (config == NULL)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ elem = __find_property_by_attrubute(config->data, attribute);
+ if (elem == NULL)
+ {
+ return NET_NFC_NO_DATA_FOUND;
+ }
+
+ config->data = g_list_remove(config->data, elem);
+ config->length -= (elem->length + 2 * __net_nfc_get_size_of_attribute(attribute));
+
+ if (elem->is_group)
+ {
+ net_nfc_util_free_carrier_group((net_nfc_carrier_property_s *)elem);
+ }
+ else
+ {
+ _net_nfc_util_free_mem(elem->data);
+ _net_nfc_util_free_mem(elem);
+ }
+
+ return NET_NFC_OK;
+}
+
+net_nfc_error_e net_nfc_util_get_carrier_config_property(net_nfc_carrier_config_s *config, uint16_t attribute, uint16_t * size, uint8_t ** data)
+{
+ net_nfc_carrier_property_s *elem = NULL;
+
+ if (config == NULL || size == NULL || data == NULL)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ elem = __find_property_by_attrubute(config->data, attribute);
+ if (elem == NULL)
+ {
+ *size = 0;
+ *data = NULL;
+ return NET_NFC_NO_DATA_FOUND;
+ }
+
+ *size = elem->length;
+ if (elem->is_group)
+ {
+ *data = NULL;
+ }
+ else
+ {
+ *data = elem->data;
+ }
+
+ return NET_NFC_OK;
+}
+
+net_nfc_error_e net_nfc_util_append_carrier_config_group(net_nfc_carrier_config_s *config, net_nfc_carrier_property_s *group)
+{
+ if (config == NULL || group == NULL)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+ if (g_list_find(config->data, group) != NULL)
+ {
+ return NET_NFC_ALREADY_REGISTERED;
+ }
+
+ config->data = g_list_append(config->data, group);
+ config->length += group->length;
+
+ return NET_NFC_OK;
+}
+
+net_nfc_error_e net_nfc_util_remove_carrier_config_group(net_nfc_carrier_config_s *config, net_nfc_carrier_property_s *group)
+{
+ if (config == NULL || group == NULL)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ if (g_list_find(config->data, group) != NULL)
+ {
+ return NET_NFC_NO_DATA_FOUND;
+ }
+
+ config->length -= group->length;
+ config->data = g_list_remove(config->data, group);
+
+ net_nfc_util_free_carrier_group((net_nfc_carrier_property_s *)group);
+
+ return NET_NFC_OK;
+}
+
+net_nfc_error_e net_nfc_util_get_carrier_config_group(net_nfc_carrier_config_s *config, int index, net_nfc_carrier_property_s **group)
+{
+ search_index result;
+
+ if (config == NULL || group == NULL)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ if (index < 0)
+ {
+ return NET_NFC_OUT_OF_BOUND;
+ }
+
+ result.current = 0;
+ result.target = index;
+ result.found = NULL;
+
+ g_list_foreach(config->data, __find_nth_group, &result);
+
+ if (result.found == NULL)
+ {
+ return NET_NFC_NO_DATA_FOUND;
+ }
+ *group = (net_nfc_carrier_property_s *)result.found;
+
+ return NET_NFC_OK;
+}
+
+net_nfc_error_e net_nfc_util_free_carrier_config(net_nfc_carrier_config_s *config)
+{
+ if (config == NULL)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ g_list_foreach(config->data, __free_all_data, NULL);
+ g_list_free(config->data);
+
+ _net_nfc_util_free_mem(config);
+
+ return NET_NFC_OK;
+}
+
+net_nfc_error_e net_nfc_util_create_carrier_config_group(net_nfc_carrier_property_s **group, uint16_t attribute)
+{
+ if (group == NULL)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ _net_nfc_util_alloc_mem(*group, sizeof(net_nfc_carrier_property_s));
+ if (*group == NULL)
+ {
+ return NET_NFC_ALLOC_FAIL;
+ }
+
+ (*group)->attribute = attribute;
+ (*group)->is_group = true;
+
+ return NET_NFC_OK;
+}
+
+net_nfc_error_e net_nfc_util_add_carrier_config_group_property(net_nfc_carrier_property_s *group, uint16_t attribute, uint16_t size, uint8_t *data)
+{
+ net_nfc_carrier_property_s *elem = NULL;
+
+ DEBUG_MSG("ADD group property: [ATTRIB:0x%X, SIZE:%d]", attribute, size);
+
+ if (group == NULL || data == NULL)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ if (__find_property_by_attrubute((GList *)group->data, attribute) != NULL)
+ {
+ return NET_NFC_ALREADY_REGISTERED;
+ }
+
+ _net_nfc_util_alloc_mem(elem, sizeof (net_nfc_carrier_property_s));
+ if (elem == NULL)
+ {
+ return NET_NFC_ALLOC_FAIL;
+ }
+ elem->attribute = attribute;
+ elem->length = size;
+ elem->is_group = false;
+
+ _net_nfc_util_alloc_mem(elem->data, size);
+ if (elem->data == NULL)
+ {
+ _net_nfc_util_free_mem(elem);
+ return NET_NFC_ALLOC_FAIL;
+ }
+ memcpy(elem->data, data, size);
+ group->length += size + 2 * __net_nfc_get_size_of_attribute(attribute);
+ group->data = g_list_append((GList *)(group->data), elem);
+
+ DEBUG_MSG("ADD group completed total length %d", group->length);
+
+ return NET_NFC_OK;
+}
+
+net_nfc_error_e net_nfc_util_get_carrier_config_group_property(net_nfc_carrier_property_s *group, uint16_t attribute, uint16_t *size, uint8_t ** data)
+{
+ net_nfc_carrier_property_s *elem = NULL;
+
+ if (group == NULL || size == NULL || data == NULL)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ elem = __find_property_by_attrubute((GList*)(group->data), attribute);
+ if (elem == NULL)
+ {
+ *size = 0;
+ *data = NULL;
+ return NET_NFC_NO_DATA_FOUND;
+ }
+
+ *size = elem->length;
+ *data = elem->data;
+
+ return NET_NFC_OK;
+}
+
+net_nfc_error_e net_nfc_util_remove_carrier_config_group_property(net_nfc_carrier_property_s *group, uint16_t attribute)
+{
+ net_nfc_carrier_property_s *elem = NULL;
+
+ if (group == NULL)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ elem = __find_property_by_attrubute((GList*)(group->data), attribute);
+ if (elem == NULL)
+ {
+ return NET_NFC_NO_DATA_FOUND;
+ }
+ group->length -= elem->length;
+ group->data = g_list_remove((GList*)(group->data), elem);
+
+ _net_nfc_util_free_mem(elem->data);
+ _net_nfc_util_free_mem(elem);
+
+ return NET_NFC_OK;
+
+}
+
+net_nfc_error_e net_nfc_util_free_carrier_group(net_nfc_carrier_property_s *group)
+{
+ if (group == NULL)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+ g_list_foreach((GList*)(group->data), __free_all_data, NULL);
+ g_list_free((GList*)(group->data));
+
+ _net_nfc_util_free_mem(group);
+
+ return NET_NFC_OK;
+}
+
+static void __make_serial_wifi(gpointer data, gpointer user_data)
+{
+ net_nfc_carrier_property_s *info = (net_nfc_carrier_property_s *)data;
+ data_s *payload = (data_s *)user_data;
+ uint8_t *current;
+ int inc = 0;
+
+ if (info == NULL || user_data == NULL)
+ return;
+
+ current = payload->buffer + payload->length;
+ inc = __net_nfc_get_size_of_attribute(info->attribute);
+
+ if (info->is_group)
+ {
+ DEBUG_MSG("[WIFI]Found Group make recursive");
+ *(uint16_t *)current = info->attribute;
+ *(uint16_t *)(current + inc) = info->length;
+ payload->length += (inc + inc);
+ g_list_foreach((GList *)info->data, __make_serial_wifi, payload);
+ }
+ else
+ {
+ DEBUG_MSG("[WIFI]Element is found attrib:0x%X length:%d current:%d", info->attribute, info->length, payload->length);
+ *(uint16_t *)current = info->attribute;
+ *(uint16_t *)(current + inc) = info->length;
+ memcpy(current + inc + inc, info->data, info->length);
+ payload->length += (inc + inc + info->length);
+ }
+}
+
+static void __make_serial_bt(gpointer data, gpointer user_data)
+{
+ net_nfc_carrier_property_s *info = (net_nfc_carrier_property_s *)data;
+ data_s *payload = (data_s *)user_data;
+ uint8_t *current;
+ int inc = 0;
+
+ if (info == NULL || user_data == NULL)
+ return;
+
+ current = payload->buffer + payload->length; /* payload->length is zero */
+
+ if (info->is_group)
+ {
+ DEBUG_MSG("[BT]Found Group. call recursive");
+ g_list_foreach((GList *)info->data, __make_serial_bt, payload);
+ }
+ else
+ {
+ if (info->attribute != NET_NFC_BT_ATTRIBUTE_ADDRESS)
+ {
+ DEBUG_MSG("[BT]Element is found attrib:0x%X length:%d current:%d", info->attribute, info->length, payload->length);
+ inc = __net_nfc_get_size_of_attribute(info->attribute);
+ *current = info->length + 1;
+ *(current + inc) = info->attribute;
+ memcpy(current + inc + inc, info->data, info->length);
+ payload->length += (inc + inc + info->length);
+ }
+ else
+ {
+ DEBUG_MSG("[BT]BT address is found length:%d", info->length);
+ memcpy(current, info->data, info->length);
+ payload->length += (info->length);
+ }
+ }
+}
+
+net_nfc_error_e net_nfc_util_create_ndef_record_with_carrier_config(ndef_record_s **record, net_nfc_carrier_config_s *config)
+{
+ data_s payload = { NULL, 0 };
+ data_s record_type = { NULL, 0 };
+
+ if (record == NULL || config == NULL)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ _net_nfc_util_alloc_mem(payload.buffer, config->length);
+ if (payload.buffer == NULL)
+ {
+ return NET_NFC_ALLOC_FAIL;
+ }
+ payload.length = 0; /* this should be zero because this will be used as current position of data written */
+
+ if (config->type == NET_NFC_CONN_HANDOVER_CARRIER_WIFI_BSS)
+ {
+ record_type.buffer = (uint8_t *)CONN_HANDOVER_WIFI_BSS_CARRIER_MIME_NAME;
+ record_type.length = strlen(CONN_HANDOVER_WIFI_BSS_CARRIER_MIME_NAME);
+ g_list_foreach(config->data, __make_serial_wifi, &payload);
+ }
+ else if (config->type == NET_NFC_CONN_HANDOVER_CARRIER_WIFI_IBSS)
+ {
+ record_type.buffer = (uint8_t *)CONN_HANDOVER_WIFI_IBSS_CARRIER_MIME_NAME;
+ record_type.length = strlen(CONN_HANDOVER_WIFI_IBSS_CARRIER_MIME_NAME);
+ g_list_foreach(config->data, __make_serial_wifi, &payload);
+ }
+ else if (config->type == NET_NFC_CONN_HANDOVER_CARRIER_BT)
+ {
+ record_type.buffer = (uint8_t *)CONN_HANDOVER_BT_CARRIER_MIME_NAME;
+ record_type.length = strlen(CONN_HANDOVER_BT_CARRIER_MIME_NAME);
+ payload.buffer += 2; /* OOB total length */
+ g_list_foreach(config->data, __make_serial_bt, &payload);
+ payload.buffer -= 2; /* return to original */
+ payload.length += 2;
+ payload.buffer[0] = payload.length & 0xFF;
+ payload.buffer[1] = (payload.length >> 8) & 0xFF;
+ }
+ else
+ {
+ return NET_NFC_NOT_SUPPORTED;
+ }
+
+ DEBUG_MSG("payload length = %d", payload.length);
+
+ return net_nfc_util_create_record(NET_NFC_RECORD_MIME_TYPE, &record_type, NULL, &payload, record);
+}
+
+static net_nfc_error_e __net_nfc_get_list_from_serial_for_wifi(GList **list, uint8_t *data, uint32_t length)
+{
+ uint8_t *current = data;
+ uint8_t *last = current + length;
+
+ while (current < last)
+ {
+ net_nfc_carrier_property_s *elem = NULL;
+ _net_nfc_util_alloc_mem(elem, sizeof(net_nfc_carrier_property_s));
+ if (elem == NULL)
+ {
+ return NET_NFC_ALLOC_FAIL;
+ }
+ elem->attribute = current[0]<<8|current[1];
+ elem->length = current[2]<<8|current[3];
+
+ if (elem->attribute == NET_NFC_WIFI_ATTRIBUTE_CREDENTIAL)
+ {
+ __net_nfc_get_list_from_serial_for_wifi(list, (current + 4), elem->length);
+ elem->is_group = true;
+ }
+ else
+ {
+ _net_nfc_util_alloc_mem(elem->data, elem->length);
+ if (elem->data == NULL)
+ {
+ _net_nfc_util_free_mem(elem);
+ return NET_NFC_ALLOC_FAIL;
+ }
+ memcpy(elem->data, (current + 4), elem->length);
+ elem->is_group = false;
+ }
+ *list = g_list_append(*list, elem);
+ current += (4 + elem->length);
+ }
+
+ return NET_NFC_OK;
+}
+
+net_nfc_error_e __net_nfc_get_list_from_serial_for_bt(GList **list, uint8_t *data, uint32_t length)
+{
+ net_nfc_carrier_property_s *elem = NULL;
+ uint8_t *current = data;
+ uint8_t *last = NULL;
+
+ current += 2; /* remove oob data length two bytes length*/
+ length -= 2;
+
+ _net_nfc_util_alloc_mem(elem, sizeof(net_nfc_carrier_property_s));
+ if (elem == NULL)
+ {
+ return NET_NFC_ALLOC_FAIL;
+ }
+ elem->attribute = (uint16_t)NET_NFC_BT_ATTRIBUTE_ADDRESS;
+ elem->length = 6; /* BT address length is always 6 */
+
+ _net_nfc_util_alloc_mem(elem->data, elem->length);
+ if (elem->data == NULL)
+ {
+ _net_nfc_util_free_mem(elem);
+ return NET_NFC_ALLOC_FAIL;
+ }
+ memcpy(elem->data, current, elem->length);
+ elem->is_group = false;
+
+ current += 6; /* BT address length is always 6 */
+ length -= 6; /* substracted by 6 (Address length)*/
+ *list = g_list_append(*list, elem);
+
+ last = current + length;
+
+ while (current < last)
+ {
+ _net_nfc_util_alloc_mem(elem, sizeof(net_nfc_carrier_property_s));
+ if (elem == NULL)
+ {
+ return NET_NFC_ALLOC_FAIL;
+ }
+ elem->length = *((uint8_t *)current) - 1;
+ elem->attribute = *((uint8_t *)(++current));
+
+ _net_nfc_util_alloc_mem(elem->data, elem->length);
+ if (elem->data == NULL)
+ {
+ _net_nfc_util_free_mem(elem);
+ return NET_NFC_ALLOC_FAIL;
+ }
+ memcpy(elem->data, (++current), elem->length);
+ elem->is_group = false;
+
+ current += elem->length;
+ *list = g_list_append(*list, elem);
+ }
+
+ return NET_NFC_OK;
+}
+
+net_nfc_error_e net_nfc_util_create_carrier_config_from_config_record(net_nfc_carrier_config_s **config, ndef_record_s *record)
+{
+ net_nfc_error_e result = NET_NFC_OK;
+ net_nfc_conn_handover_carrier_type_e type;
+
+ if (record == NULL || config == NULL)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ if (strncmp((char *)record->type_s.buffer, CONN_HANDOVER_WIFI_BSS_CARRIER_MIME_NAME, record->type_s.length) == 0)
+ {
+ type = NET_NFC_CONN_HANDOVER_CARRIER_WIFI_BSS;
+ }
+ else if (strncmp((char *)record->type_s.buffer, CONN_HANDOVER_WIFI_IBSS_CARRIER_MIME_NAME, record->type_s.length) == 0)
+ {
+ type = NET_NFC_CONN_HANDOVER_CARRIER_WIFI_IBSS;
+ }
+ else if (strncmp((char *)record->type_s.buffer, CONN_HANDOVER_BT_CARRIER_MIME_NAME, record->type_s.length) == 0)
+ {
+ type = NET_NFC_CONN_HANDOVER_CARRIER_BT;
+ }
+ else
+ {
+ DEBUG_MSG("Record type is not config type");
+ return NET_NFC_INVALID_FORMAT;
+ }
+
+ result = net_nfc_util_create_carrier_config(config, type);
+ if (*config == NULL)
+ {
+ return NET_NFC_ALLOC_FAIL;
+ }
+
+ switch ((*config)->type)
+ {
+ case NET_NFC_CONN_HANDOVER_CARRIER_WIFI_BSS :
+ case NET_NFC_CONN_HANDOVER_CARRIER_WIFI_IBSS :
+ result = __net_nfc_get_list_from_serial_for_wifi((GList **)&((*config)->data), record->payload_s.buffer, record->payload_s.length);
+ break;
+ case NET_NFC_CONN_HANDOVER_CARRIER_BT :
+ result = __net_nfc_get_list_from_serial_for_bt((GList **)&((*config)->data), record->payload_s.buffer, record->payload_s.length);
+ break;
+ case NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN :
+ result = NET_NFC_NOT_SUPPORTED;
+ break;
+ }
+
+ if (result != NET_NFC_OK)
+ {
+ net_nfc_util_free_carrier_config((net_nfc_carrier_config_s *)*config);
+ }
+
+ return result;
+}
+
+net_nfc_error_e net_nfc_util_create_handover_request_message(ndef_message_s **message)
+{
+ ndef_message_s *inner_message = NULL;
+ net_nfc_error_e error;
+ ndef_record_s *record = NULL;
+ data_s type = { NULL, 0 };
+ data_s payload = { NULL, 0 };
+ int size = 0;
+
+ if (message == NULL)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ error = net_nfc_util_create_ndef_message(message);
+ if (error != NET_NFC_OK)
+ {
+ return error;
+ }
+
+ error = net_nfc_util_create_ndef_message(&inner_message);
+ if (error != NET_NFC_OK)
+ {
+ net_nfc_util_free_ndef_message(*message);
+ *message = NULL;
+
+ return error;
+ }
+
+ __net_nfc_util_create_connection_handover_collsion_resolution_record(&record);
+ net_nfc_util_append_record(inner_message, record);
+
+ size = net_nfc_util_get_ndef_message_length(inner_message) + 1;
+ _net_nfc_util_alloc_mem(payload.buffer, size);
+ if (payload.buffer == NULL)
+ {
+ net_nfc_util_free_ndef_message(inner_message);
+ net_nfc_util_free_ndef_message(*message);
+ *message = NULL;
+
+ return NET_NFC_ALLOC_FAIL;
+ }
+ payload.length = size;
+
+ uint8_t version = CH_VERSION;
+
+ (payload.buffer)[0] = version;
+ (payload.buffer)++;
+ (payload.length)--;
+
+ error = net_nfc_util_convert_ndef_message_to_rawdata(inner_message, &payload);
+ if (error != NET_NFC_OK)
+ {
+ _net_nfc_util_free_mem(payload.buffer);
+ net_nfc_util_free_ndef_message(inner_message);
+ net_nfc_util_free_ndef_message(*message);
+ *message = NULL;
+
+ return error;
+ }
+
+ net_nfc_util_free_ndef_message(inner_message);
+ (payload.buffer)--;
+ (payload.length)++;
+
+ type.buffer = (uint8_t *)CH_REQ_RECORD_TYPE;
+ type.length = strlen(CH_REQ_RECORD_TYPE);
+
+ net_nfc_util_create_record(NET_NFC_RECORD_WELL_KNOWN_TYPE, &type, NULL, &payload, &record);
+ net_nfc_util_append_record(*message, record);
+
+ _net_nfc_util_free_mem(payload.buffer);
+
+ return NET_NFC_OK;
+}
+
+net_nfc_error_e net_nfc_util_create_handover_select_message(ndef_message_s **message)
+{
+ net_nfc_error_e error = NET_NFC_OK;
+ ndef_record_s *record = NULL;
+ data_s type = { NULL, 0 };
+ data_s payload = { NULL, 0 };
+
+ if (message == NULL)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ error = net_nfc_util_create_ndef_message(message);
+ if (error != NET_NFC_OK)
+ {
+ return error;
+ }
+
+ _net_nfc_util_alloc_mem(payload.buffer, 1);
+ if (payload.buffer == NULL)
+ {
+ net_nfc_util_free_ndef_message(*message);
+ return NET_NFC_ALLOC_FAIL;
+ }
+ payload.length = (uint32_t)1;
+
+ (payload.buffer)[0] = CH_VERSION;
+
+ type.buffer = (uint8_t*)CH_SEL_RECORD_TYPE;
+ type.length = strlen(CH_SEL_RECORD_TYPE);
+
+ net_nfc_util_create_record(NET_NFC_RECORD_WELL_KNOWN_TYPE, &type, NULL, &payload, &record);
+ net_nfc_util_append_record(*message, record);
+
+ _net_nfc_util_free_mem(payload.buffer);
+
+ return NET_NFC_OK;
+}
+
+net_nfc_error_e net_nfc_util_create_handover_error_record(ndef_record_s **record, uint8_t reason, uint32_t data)
+{
+ data_s type;
+ data_s payload;
+ int size = 1;
+
+ switch (reason)
+ {
+ case 0x01 :
+ size += 1;
+ break;
+ case 0x02 :
+ size += 4;
+ break;
+ case 0x03 :
+ size += 1;
+ break;
+ }
+
+ _net_nfc_util_alloc_mem(payload.buffer, size);
+ if (payload.buffer == NULL)
+ {
+ return NET_NFC_ALLOC_FAIL;
+ }
+ payload.length = size;
+
+ type.buffer = (uint8_t *)ERROR_RECORD_TYPE;
+ type.length = strlen(ERROR_RECORD_TYPE);
+
+ net_nfc_util_create_record(NET_NFC_RECORD_WELL_KNOWN_TYPE, &type, NULL, &payload, (ndef_record_s **)record);
+
+ _net_nfc_util_free_mem(payload.buffer);
+
+ return NET_NFC_OK;
+}
+
+/* inner_msg should be freed after using */
+
+static net_nfc_error_e __net_nfc_get_inner_message(ndef_message_s *message, ndef_message_s *inner_msg)
+{
+ net_nfc_error_e error;
+ ndef_record_s *inner_record = NULL;
+
+ if (message == NULL || inner_msg == NULL)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ inner_record = message->records;
+ if (inner_record == NULL)
+ {
+ // This message is not connection handover message
+ return NET_NFC_INVALID_FORMAT;
+ }
+
+ if (strncmp((char*)(inner_record->type_s.buffer), CH_REQ_RECORD_TYPE, (size_t)(inner_record->type_s.length)) != 0
+ && strncmp((char*)(inner_record->type_s.buffer), CH_SEL_RECORD_TYPE, (size_t)(inner_record->type_s.length)) != 0)
+ {
+ // This message is not connection handover message
+ return NET_NFC_INVALID_FORMAT;
+ }
+
+ if (inner_record->payload_s.length > 1)
+ {
+ /* There is Alternative Carrier Record or Collision Res. Rec. */
+ (inner_record->payload_s.buffer)++; /* version */
+ (inner_record->payload_s.length)--;
+ error = net_nfc_util_convert_rawdata_to_ndef_message(&(inner_record->payload_s), inner_msg);
+ (inner_record->payload_s.buffer)--;
+ (inner_record->payload_s.length)++;
+ }
+ else
+ {
+ error = NET_NFC_NO_DATA_FOUND;
+ }
+
+ return error;
+}
+
+static net_nfc_error_e __net_nfc_replace_inner_message(ndef_message_s *message, ndef_message_s *inner_msg)
+{
+ net_nfc_error_e error;
+ ndef_record_s *inner_record = NULL;
+
+ if (message == NULL || inner_msg == NULL)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ inner_record = message->records;
+ if (inner_record == NULL)
+ {
+ // This message is not connection handover message
+ DEBUG_ERR_MSG("inner_record == NULL");
+ return NET_NFC_INVALID_FORMAT;
+ }
+
+ if (strncmp((char *)(inner_record->type_s.buffer), CH_REQ_RECORD_TYPE, (size_t)(inner_record->type_s.length)) != 0
+ && strncmp((char *)(inner_record->type_s.buffer), CH_SEL_RECORD_TYPE, (size_t)(inner_record->type_s.length)) != 0)
+ {
+ // This message is not connection handover message
+ DEBUG_ERR_MSG("unknown type [%s]", inner_record->type_s.buffer);
+ return NET_NFC_INVALID_FORMAT;
+ }
+
+ if (inner_record->payload_s.length >= 1)
+ {
+ /* There is Alternative Carrier Record or Collision Res. Rec. */
+ data_s tdata = { NULL, 0 };
+ int inner_length;
+
+ inner_length = net_nfc_util_get_ndef_message_length(inner_msg);
+
+ _net_nfc_util_alloc_mem(tdata.buffer, inner_length + 1);
+ if (tdata.buffer == NULL)
+ {
+ return NET_NFC_ALLOC_FAIL;
+ }
+
+ (tdata.buffer)++;
+ tdata.length = inner_length;
+ error = net_nfc_util_convert_ndef_message_to_rawdata(inner_msg, &tdata);
+ if (error == NET_NFC_OK)
+ {
+ (tdata.buffer)--;
+ (tdata.length)++;
+ (tdata.buffer)[0] = (inner_record->payload_s.buffer)[0];
+ _net_nfc_util_free_mem(inner_record->payload_s.buffer);
+ inner_record->payload_s.buffer = tdata.buffer;
+ inner_record->payload_s.length = tdata.length;
+ }
+ else
+ {
+ DEBUG_ERR_MSG("net_nfc_util_convert_ndef_message_to_rawdata failed [%d]", error);
+ _net_nfc_util_free_mem(tdata.buffer);
+ }
+ }
+ else
+ {
+ DEBUG_ERR_MSG("inner_record->payload_s.length(%d) < 1 ", inner_record->payload_s.length);
+ error = NET_NFC_INVALID_FORMAT;
+ }
+
+ return error;
+}
+
+net_nfc_error_e net_nfc_util_append_carrier_config_record(ndef_message_s *message, ndef_record_s *record, net_nfc_conn_handover_carrier_state_e power_status)
+{
+ ndef_message_s *inner_msg = NULL;
+ ndef_record_s *carrier_rec = NULL;
+ data_s payload = { NULL, 0 };
+ data_s type = { NULL, 0 };
+ int config_ref_count = 0;
+ net_nfc_error_e error;
+ uint8_t buffer[256] = { 0, };
+#if 0
+ int i;
+#endif
+ int offset;
+ uint8_t id;
+
+ if (message == NULL || record == NULL)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ if ((error = net_nfc_util_create_ndef_message(&inner_msg)) != NET_NFC_OK)
+ {
+ DEBUG_ERR_MSG("net_nfc_util_create_ndef_message failed [%d]", error);
+
+ return error;
+ }
+
+ if ((error = __net_nfc_get_inner_message(message, inner_msg)) == NET_NFC_OK)
+ {
+ int idx = 1;
+ ndef_record_s *last_rec = inner_msg->records;
+
+ for (; idx < inner_msg->recordCount; idx++)
+ {
+ last_rec = last_rec->next;
+ }
+
+ if (strncmp((char *)last_rec->type_s.buffer, COLLISION_DETECT_RECORD_TYPE, (size_t)last_rec->type_s.length) == 0)
+ {
+ config_ref_count = 0;
+ }
+ else if (strncmp((char *)last_rec->type_s.buffer, ALTERNATIVE_RECORD_TYPE, (size_t)last_rec->type_s.length) == 0)
+ {
+ memcpy(buffer, last_rec->payload_s.buffer, last_rec->payload_s.length);
+ config_ref_count = last_rec->payload_s.buffer[1];
+ }
+ }
+ else
+ {
+ /* selector record type can include empty inner message. so that case, we will continue */
+ if (message->records != NULL &&
+ memcmp((char *)message->records->type_s.buffer, CH_SEL_RECORD_TYPE, (size_t)message->records->type_s.length) != 0)
+ {
+ DEBUG_ERR_MSG("ERROR [%d]", error);
+
+ net_nfc_util_free_ndef_message(inner_msg);
+
+ return error;
+ }
+ }
+
+ type.buffer = (uint8_t *)ALTERNATIVE_RECORD_TYPE;
+ type.length = strlen(ALTERNATIVE_RECORD_TYPE);
+
+ config_ref_count++;
+ offset = 0;
+ // id = '0' + config_ref_count;
+ id = 'b';
+
+ /* carrier flag */
+ buffer[offset++] = (uint8_t)(power_status & 0x3); /* first byte, power status */
+
+ /* carrier data ref. len */
+ buffer[offset++] = config_ref_count;
+
+ /* carrier data ref. */
+ offset += (config_ref_count - 1);
+ buffer[offset++] = id;
+
+ /* FIXME */
+ /* aux data ref. len */
+ buffer[offset++] = 0;
+#if 0 /* FIXME */
+ /* carrier data ref. */
+ for (i = 0; i < 0; i++)
+ {
+ buffer[offset++] = 0;
+ }
+#endif
+ payload.buffer = buffer;
+ payload.length = offset;
+
+ error = net_nfc_util_create_record(NET_NFC_RECORD_WELL_KNOWN_TYPE, &type, NULL, &payload, &carrier_rec);
+ if (error != NET_NFC_OK)
+ {
+ DEBUG_ERR_MSG("net_nfc_util_create_record failed [%d]", error);
+
+ net_nfc_util_free_ndef_message(inner_msg);
+
+ return error;
+ }
+
+ error = net_nfc_util_append_record(inner_msg, carrier_rec);
+ if (error != NET_NFC_OK)
+ {
+ DEBUG_ERR_MSG("net_nfc_util_create_record failed [%d]", error);
+
+ net_nfc_util_free_record(carrier_rec);
+ net_nfc_util_free_ndef_message(inner_msg);
+
+ return error;
+ }
+
+ error = __net_nfc_replace_inner_message(message, inner_msg);
+ net_nfc_util_free_ndef_message(inner_msg);
+ if (error != NET_NFC_OK)
+ {
+ DEBUG_ERR_MSG("__net_nfc_replace_inner_message failed [%d]", error);
+
+ return error;
+ }
+
+ /* set record id to record that will be appended to ndef message */
+ error = net_nfc_util_set_record_id((ndef_record_s *)record, &id, sizeof(id));
+ if (error != NET_NFC_OK)
+ {
+ DEBUG_ERR_MSG("net_nfc_util_set_record_id failed [%d]", error);
+
+ return error;
+ }
+
+ error = net_nfc_util_append_record(message, (ndef_record_s *)record);
+ if (error != NET_NFC_OK)
+ {
+ DEBUG_ERR_MSG("net_nfc_util_append_record failed [%d]", error);
+
+ return error;
+ }
+
+ return NET_NFC_OK;
+}
+
+net_nfc_error_e net_nfc_util_remove_carrier_config_record(ndef_message_s *message, ndef_record_s *record)
+{
+ ndef_message_s *inner_msg = NULL;
+ int idx = 0;
+ int saved_idx = 0;
+ net_nfc_error_e error;
+ ndef_record_s *current = NULL;
+ ndef_record_s *record_priv = (ndef_record_s *)record;
+
+ if (message == NULL || record == NULL)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ current = message->records;
+
+ for (idx = 0; idx < message->recordCount; idx++)
+ {
+ if (current == record)
+ {
+ break;
+ }
+ current = current->next;
+ }
+
+ if (current == NULL || idx == message->recordCount)
+ {
+ DEBUG_MSG("The reference is not found in config records");
+
+ return NET_NFC_NO_DATA_FOUND;
+ }
+ saved_idx = idx;
+
+ if ((error = net_nfc_util_create_ndef_message(&inner_msg)) != NET_NFC_OK)
+ {
+ DEBUG_MSG("net_nfc_util_create_ndef_message failed [%d]", error);
+
+ return error;
+ }
+
+ if ((error = __net_nfc_get_inner_message(message, inner_msg)) == NET_NFC_OK)
+ {
+ current = inner_msg->records;
+
+ for (idx = 0; idx < inner_msg->recordCount; idx++, current = current->next)
+ {
+ if (strncmp((char *)current->type_s.buffer, ALTERNATIVE_RECORD_TYPE, (size_t)current->type_s.length) == 0)
+ {
+ if ((uint32_t)(current->payload_s.buffer[1]) == record_priv->id_s.length &&
+ strncmp((char *)(current->payload_s.buffer + 2), (char*)(record_priv->id_s.buffer), (size_t)current->payload_s.buffer[1]) == 0)
+ {
+ // comparing the instance
+ break;
+ }
+ }
+ }
+
+ if (current == NULL || idx == message->recordCount)
+ {
+ DEBUG_MSG("The reference is not found in inner message");
+
+ error = NET_NFC_NO_DATA_FOUND;
+ }
+ else
+ {
+ net_nfc_util_remove_record_by_index(inner_msg, idx);
+ __net_nfc_replace_inner_message(message, inner_msg);
+
+ // remove the record only if the inner record is found.
+ net_nfc_util_remove_record_by_index(message, saved_idx);
+ }
+ }
+
+ net_nfc_util_free_ndef_message(inner_msg);
+
+ return error;
+}
+
+net_nfc_error_e net_nfc_util_get_carrier_config_record(ndef_message_s *message, int index, ndef_record_s** record)
+{
+ ndef_message_s *inner_msg = NULL;
+ data_s id;
+ net_nfc_error_e error;
+ ndef_record_s *current = NULL;
+ int idx = 0;
+ int current_idx = 0;
+
+ if (message == NULL || record == NULL)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ if ((error = net_nfc_util_create_ndef_message(&inner_msg)) != NET_NFC_OK)
+ {
+ DEBUG_MSG("net_nfc_util_create_ndef_message failed [%d]", error);
+
+ return error;
+ }
+
+ if ((error = __net_nfc_get_inner_message(message, inner_msg)) == NET_NFC_OK)
+ {
+ current = inner_msg->records;
+ for (idx = 0; idx < inner_msg->recordCount; idx++)
+ {
+ if (strncmp((char*)current->type_s.buffer, ALTERNATIVE_RECORD_TYPE, (size_t)current->type_s.length) == 0)
+ {
+ if (current_idx == index)
+ break;
+ current_idx++;
+ }
+ current = current->next;
+ }
+
+ if (current == NULL || idx == message->recordCount)
+ {
+ DEBUG_MSG("The reference is not found in inner message");
+
+ error = NET_NFC_NO_DATA_FOUND;
+ }
+ else
+ {
+ id.buffer = (current->payload_s.buffer) + 2;
+ id.length = current->payload_s.buffer[1];
+
+ error = net_nfc_util_search_record_by_id(message, &id, record);
+ }
+ }
+
+ net_nfc_util_free_ndef_message(inner_msg);
+
+ return error;
+}
+
+net_nfc_error_e net_nfc_util_get_handover_random_number(ndef_message_s *message, unsigned short *random_number)
+{
+ net_nfc_error_e error;
+ ndef_message_s *inner_msg = NULL;
+ ndef_record_s *cr_record = NULL;
+
+ if (message == NULL)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ if ((error = net_nfc_util_create_ndef_message(&inner_msg)) != NET_NFC_OK)
+ {
+ DEBUG_MSG("net_nfc_util_create_ndef_message failed [%d]", error);
+
+ return error;
+ }
+
+ if ((error = __net_nfc_get_inner_message(message, inner_msg)) == NET_NFC_OK)
+ {
+ cr_record = inner_msg->records;
+ if (strncmp((char*)cr_record->type_s.buffer, COLLISION_DETECT_RECORD_TYPE, (size_t)cr_record->type_s.length) != 0
+ || cr_record->payload_s.length < 2)
+ {
+ DEBUG_MSG("There is no Collision resolution record");
+
+ error = NET_NFC_INVALID_FORMAT;
+ }
+ else
+ {
+ *random_number = ((unsigned short)cr_record->payload_s.buffer[0] << 8) | (unsigned short)(cr_record->payload_s.buffer[1]);
+ }
+ }
+
+ net_nfc_util_free_ndef_message(inner_msg);
+
+ return error;
+}
+
+net_nfc_error_e net_nfc_util_get_alternative_carrier_record_count(ndef_message_s *message, unsigned int *count)
+{
+ net_nfc_error_e error;
+ ndef_message_s *inner_msg = NULL;
+ ndef_record_s *current = NULL;
+ int idx;
+
+ if (message == NULL || count == 0)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ if ((error = net_nfc_util_create_ndef_message(&inner_msg)) != NET_NFC_OK)
+ {
+ DEBUG_MSG("net_nfc_util_create_ndef_message failed [%d]", error);
+
+ return error;
+ }
+
+ *count = 0;
+
+ if ((error = __net_nfc_get_inner_message(message, inner_msg)) == NET_NFC_OK)
+ {
+ current = inner_msg->records;
+ for (idx = 0; idx < inner_msg->recordCount; idx++)
+ {
+ if (strncmp((char *)current->type_s.buffer, ALTERNATIVE_RECORD_TYPE, (size_t)current->type_s.length) == 0)
+ {
+ (*count)++;
+ }
+ current = current->next;
+ }
+ }
+
+ net_nfc_util_free_ndef_message(inner_msg);
+
+ return error;
+}
+
+net_nfc_error_e net_nfc_util_get_alternative_carrier_power_status(ndef_message_s *message, int index, net_nfc_conn_handover_carrier_state_e *power_state)
+{
+ net_nfc_error_e error;
+ ndef_message_s *inner_msg = NULL;
+ ndef_record_s *current = NULL;
+ int idx;
+ int idx_count = 0;
+
+ if (message == NULL)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ if (index < 0)
+ {
+ return NET_NFC_OUT_OF_BOUND;
+ }
+
+ if ((error = net_nfc_util_create_ndef_message(&inner_msg)) != NET_NFC_OK)
+ {
+ DEBUG_MSG("net_nfc_util_create_ndef_message failed [%d]", error);
+
+ return error;
+ }
+
+ if ((error = __net_nfc_get_inner_message(message, inner_msg)) == NET_NFC_OK)
+ {
+ error = NET_NFC_OUT_OF_BOUND;
+ current = inner_msg->records;
+ for (idx = 0; idx < inner_msg->recordCount; idx++)
+ {
+ if (strncmp((char *)current->type_s.buffer, ALTERNATIVE_RECORD_TYPE, (size_t)current->type_s.length) == 0)
+ {
+ if (idx_count == index)
+ {
+ *power_state = current->payload_s.buffer[0] & 0x3;
+ error = NET_NFC_OK;
+ break;
+ }
+ idx_count++;
+ }
+ current = current->next;
+ }
+ }
+
+ net_nfc_util_free_ndef_message(inner_msg);
+
+ return error;
+}
+
+net_nfc_error_e net_nfc_util_set_alternative_carrier_power_status(ndef_message_s *message, int index, net_nfc_conn_handover_carrier_state_e power_status)
+{
+ net_nfc_error_e error;
+ ndef_message_s *inner_msg = NULL;
+
+ if (message == NULL)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+ if (index < 0)
+ {
+ return NET_NFC_OUT_OF_BOUND;
+ }
+
+ if ((error = net_nfc_util_create_ndef_message(&inner_msg)) != NET_NFC_OK)
+ {
+ DEBUG_MSG("net_nfc_util_create_ndef_message failed [%d]", error);
+
+ return error;
+ }
+
+ if ((error = __net_nfc_get_inner_message(message, inner_msg)) == NET_NFC_OK)
+ {
+ int idx;
+ int idx_count = 0;
+ ndef_record_s *current = inner_msg->records;
+
+ error = NET_NFC_OUT_OF_BOUND;
+ for (idx = 0; idx < inner_msg->recordCount; idx++, current = current->next)
+ {
+ if (strncmp((char *)current->type_s.buffer, ALTERNATIVE_RECORD_TYPE, (size_t)current->type_s.length) == 0)
+ {
+ if (idx_count == index)
+ {
+ current->payload_s.buffer[0] = (power_status & 0x3) | (current->payload_s.buffer[0] & 0xFC);
+
+ __net_nfc_replace_inner_message(message, inner_msg);
+ error = NET_NFC_OK;
+ break;
+ }
+ idx_count++;
+ }
+ }
+ }
+
+ net_nfc_util_free_ndef_message(inner_msg);
+
+ return error;
+}
+
+net_nfc_error_e net_nfc_util_get_alternative_carrier_type_from_record(ndef_record_s *record, net_nfc_conn_handover_carrier_type_e *type)
+{
+ if (strncmp((char *)record->type_s.buffer, CONN_HANDOVER_BT_CARRIER_MIME_NAME, (size_t)record->type_s.length) == 0)
+ {
+ *type = NET_NFC_CONN_HANDOVER_CARRIER_BT;
+ }
+ else if (strncmp((char *)record->type_s.buffer, CONN_HANDOVER_WIFI_BSS_CARRIER_MIME_NAME, (size_t)record->type_s.length) == 0)
+ {
+ *type = NET_NFC_CONN_HANDOVER_CARRIER_WIFI_BSS;
+ }
+ else if (strncmp((char *)record->type_s.buffer, CONN_HANDOVER_WIFI_IBSS_CARRIER_MIME_NAME, (size_t)record->type_s.length) == 0)
+ {
+ *type = NET_NFC_CONN_HANDOVER_CARRIER_WIFI_IBSS;
+ }
+ else
+ {
+ *type = NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN;
+ }
+
+ return NET_NFC_OK;
+}
+
+net_nfc_error_e net_nfc_util_get_alternative_carrier_type(ndef_message_s *message, int index, net_nfc_conn_handover_carrier_type_e *type)
+{
+ ndef_record_s *record = NULL;
+ net_nfc_error_e error;
+
+ error = net_nfc_util_get_carrier_config_record(message, index, (ndef_record_s **)&record);
+ if (error != NET_NFC_OK)
+ {
+ return error;
+ }
+
+ return net_nfc_util_get_alternative_carrier_type_from_record(record, type);
+}
+
+net_nfc_error_e net_nfc_util_get_selector_power_status(ndef_message_s *message, net_nfc_conn_handover_carrier_state_e *power_state)
+{
+ net_nfc_error_e error;
+ ndef_message_s *inner_msg = NULL;
+ ndef_record_s *current = NULL;
+ int idx;
+ net_nfc_conn_handover_carrier_state_e selector_state = NET_NFC_CONN_HANDOVER_CARRIER_INACTIVATE;
+
+ if (message == NULL)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ if ((error = net_nfc_util_create_ndef_message(&inner_msg)) == NET_NFC_OK)
+ {
+ if ((error = __net_nfc_get_inner_message(message, inner_msg)) == NET_NFC_OK)
+ {
+ if (inner_msg->recordCount > 1)
+ {
+ current = inner_msg->records;
+ for (idx = 0; idx < inner_msg->recordCount; idx++)
+ {
+ if (strncmp((char *)current->type_s.buffer, ALTERNATIVE_RECORD_TYPE, (size_t)current->type_s.length) == 0)
+ {
+ if (((current->payload_s.buffer[0] & 0x3) == NET_NFC_CONN_HANDOVER_CARRIER_ACTIVATE) || ((current->payload_s.buffer[0] & 0x3) == NET_NFC_CONN_HANDOVER_CARRIER_ACTIVATING))
+ {
+ selector_state = NET_NFC_CONN_HANDOVER_CARRIER_ACTIVATE;
+ break;
+ }
+ }
+ current = current->next;
+ }
+ }
+ else
+ {
+ /* always activate when ac is only one */
+ selector_state = NET_NFC_CONN_HANDOVER_CARRIER_ACTIVATE;
+ }
+
+ *power_state = selector_state;
+ }
+ else
+ {
+ DEBUG_ERR_MSG("_net_nfc_util_create_ndef_message failed [%d]", error);
+ }
+
+ net_nfc_util_free_ndef_message(inner_msg);
+ }
+ else
+ {
+ DEBUG_ERR_MSG("_net_nfc_util_create_ndef_message failed [%d]", error);
+ error = NET_NFC_ALLOC_FAIL;
+ }
+
+ return error;
+}
+
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_UTIL_INTERNAL_H__
+#define __NET_NFC_UTIL_INTERNAL_H__
+
+#include <stdio.h>
+#include <libgen.h>
+#include <netinet/in.h>
+
+#include "net_nfc_typedef_internal.h"
+
+#define NET_NFC_MANAGER_DATA_PATH "/opt/data/nfc-manager-daemon"
+#define NET_NFC_MANAGER_DATA_PATH_MESSAGE "message"
+#define NET_NFC_MANAGER_NDEF_FILE_NAME "ndef-message.txt"
+
+#define NET_NFC_REVERSE_ORDER_6_BYTES(__array) \
+ do \
+ { \
+ uint16_t __x = htons(*(uint16_t *)(__array + 4)); \
+ *(uint32_t *)(__array + 2) = htonl(*(uint32_t *)(__array)); \
+ *(uint16_t *)(__array) = __x; \
+ } while (0)
+
+#define NET_NFC_REVERSE_ORDER_16_BYTES(array) \
+ do \
+ { \
+ uint32_t __x1 = htonl(*(uint32_t *)(array + 12)); \
+ uint32_t __x2 = htonl(*(uint32_t *)(array + 8)); \
+ *(uint32_t *)(array + 8) = htonl(*(uint32_t *)(array + 4)); \
+ *(uint32_t *)(array + 12) = htonl(*(uint32_t *)(array)); \
+ *(uint32_t *)(array) = __x1; \
+ *(uint32_t *)(array + 4) = __x2; \
+ } while (0)
+
+typedef enum
+{
+ CRC_A = 0x00,
+ CRC_B,
+} CRC_type_e;
+
+void net_nfc_manager_init_log();
+void net_nfc_manager_fini_log();
+
+/* Memory utils */
+/* allocation memory */
+void __net_nfc_util_alloc_mem(void **mem, int size, char *filename, unsigned int line);
+#define _net_nfc_util_alloc_mem(mem,size) __net_nfc_util_alloc_mem((void **)&mem,size, basename(__FILE__), __LINE__)
+
+/* allocation memory */
+void __net_nfc_util_strdup(char **output, const char *origin, char *filename, unsigned int line);
+#define _net_nfc_util_strdup(output, origin) __net_nfc_util_strdup(&output, origin, basename(__FILE__), __LINE__)
+
+/* free memory, after free given memory it set NULL. Before proceed free, this function also check NULL */
+void __net_nfc_util_free_mem(void **mem, char *filename, unsigned int line);
+#define _net_nfc_util_free_mem(mem) __net_nfc_util_free_mem((void **)&mem, basename(__FILE__), __LINE__)
+
+bool net_nfc_util_alloc_data(data_s *data, uint32_t length);
+bool net_nfc_util_duplicate_data(data_s *dest, net_nfc_data_s *src);
+void net_nfc_util_free_data(data_s *data);
+
+net_nfc_conn_handover_carrier_state_e net_nfc_util_get_cps(net_nfc_conn_handover_carrier_type_e carrier_type);
+
+uint8_t *net_nfc_util_get_local_bt_address();
+void net_nfc_util_enable_bluetooth(void);
+
+bool net_nfc_util_strip_string(char *buffer, int buffer_length);
+
+void net_nfc_util_compute_CRC(CRC_type_e CRC_type, uint8_t *buffer, uint32_t length);
+
+const char *net_nfc_util_get_schema_string(int index);
+
+#endif //__NET_NFC_UTIL_INTERNAL_H__
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stddef.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <stdarg.h>
+#include <string.h>
+#include <fcntl.h>
+
+#include "net_nfc_debug_internal.h"
+
+int net_nfc_util_get_va_list_length(va_list list)
+{
+ int length = 0;
+
+ while (va_arg(list, void *) != 0)
+ {
+ length += (sizeof(int) + va_arg(list, int));
+ }
+
+ return length;
+}
+
+int net_nfc_util_fill_va_list(uint8_t *buffer, int length, va_list list)
+{
+ uint8_t *data = NULL;
+ int len = 0;
+ int current = 0;
+
+ while (current < length && (data = va_arg(list, void *)) != NULL)
+ {
+ if ((len = va_arg(list, int)) > 0)
+ {
+ memcpy(buffer + current, &len, sizeof(len));
+ current += sizeof(len);
+
+ memcpy(buffer + current, data, len);
+ current += len;
+ }
+ }
+
+ return current;
+}
+
+void net_nfc_util_set_non_block_socket(int socket)
+{
+ DEBUG_SERVER_MSG("set non block socket");
+
+ int flags = fcntl(socket, F_GETFL);
+ flags |= O_NONBLOCK;
+
+ if (fcntl(socket, F_SETFL, flags) < 0)
+ {
+ DEBUG_ERR_MSG("fcntl, executing nonblock error");
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_UTIL_IPC_H__
+#define __NET_NFC_UTIL_IPC_H__
+
+#define NET_NFC_SERVER_ADDRESS "127.0.0.1"
+#define NET_NFC_SERVER_PORT 3000
+#define NET_NFC_SERVER_DOMAIN "/tmp/nfc-manager-server-domain"
+
+#define NET_NFC_MAX_MESSAGE_LENGTH (1024 * 512)
+
+#define NET_NFC_FLAGS_SYNC_CALL (1 << 0)
+#define NET_NFC_FLAGS_NO_RESPONSE (1 << 1)
+
+#define NET_NFC_IS_FLAGS_SET(__var, __flag) (((__var) & (__flag)) == (__flag))
+#define NET_NFC_SET_FLAGS(__var, __flag) (__var) |= (__flag)
+#define NET_NFC_UNSET_FLAGS(__var, __flag) (__var) &= ~(__flag)
+
+#define NET_NFC_FLAGS_SET_SYNC_CALL(__var) NET_NFC_SET_FLAGS(__var, NET_NFC_FLAGS_SYNC_CALL)
+#define NET_NFC_FLAGS_UNSET_SYNC_CALL(__var) NET_NFC_UNSET_FLAGS(__var, NET_NFC_FLAGS_SYNC_CALL)
+#define NET_NFC_FLAGS_IS_SYNC_CALL(__var) NET_NFC_IS_FLAGS_SET(__var, NET_NFC_FLAGS_SYNC_CALL)
+
+#define NET_NFC_FLAGS_SET_NO_RESPONSE(__var) NET_NFC_SET_FLAGS(__var, NET_NFC_FLAGS_NO_RESPONSE)
+#define NET_NFC_FLAGS_UNSET_NO_RESPONSE(__var) NET_NFC_UNSET_FLAGS(__var, NET_NFC_FLAGS_NO_RESPONSE)
+#define NET_NFC_FLAGS_IS_NO_RESPONSE(__var) NET_NFC_IS_FLAGS_SET(__var, NET_NFC_FLAGS_NO_RESPONSE)
+
+int net_nfc_util_get_va_list_length(va_list list);
+int net_nfc_util_fill_va_list(uint8_t *buffer, int length, va_list list);
+void net_nfc_util_set_non_block_socket(int socket);
+
+#endif //__NET_NFC_UTIL_IPC_H__
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#include "net_nfc_debug_internal.h"
+#include "net_nfc_util_defines.h"
+#include "net_nfc_util_internal.h"
+#include "net_nfc_util_ndef_message.h"
+#include "net_nfc_util_ndef_record.h"
+
+static net_nfc_error_e __net_nfc_repair_record_flags(ndef_message_s *ndef_message);
+
+net_nfc_error_e net_nfc_util_convert_rawdata_to_ndef_message(data_s *rawdata, ndef_message_s *ndef)
+{
+ ndef_record_s *newRec = NULL;
+ ndef_record_s *prevRec = NULL;
+ uint8_t *current = NULL;
+ uint8_t *last = NULL;
+ uint8_t ndef_header = 0;
+ net_nfc_error_e result = NET_NFC_OK;
+
+ if (rawdata == NULL || ndef == NULL)
+ return NET_NFC_NULL_PARAMETER;
+
+ current = rawdata->buffer;
+ last = current + rawdata->length;
+
+ if(rawdata->length < 3)
+ return NET_NFC_INVALID_FORMAT;
+
+ for(ndef->recordCount = 0; current < last; ndef->recordCount++)
+ {
+ ndef_header = *current++;
+
+ if(ndef->recordCount == 0)
+ {
+ /* first record has MB field */
+ if((ndef_header & NET_NFC_NDEF_RECORD_MASK_MB) == 0)
+ return NET_NFC_INVALID_FORMAT;
+
+ /* first record should not be a chunked record */
+ if((ndef_header & NET_NFC_NDEF_RECORD_MASK_TNF) == NET_NFC_NDEF_TNF_UNCHANGED)
+ return NET_NFC_INVALID_FORMAT;
+ }
+
+ _net_nfc_util_alloc_mem(newRec, sizeof(ndef_record_s));
+ if (newRec == NULL)
+ {
+ result = NET_NFC_ALLOC_FAIL;
+ goto error;
+ }
+
+ /* ndef header set */
+ if (ndef_header & NET_NFC_NDEF_RECORD_MASK_MB)
+ {
+ newRec->MB = 1;
+ }
+ if (ndef_header & NET_NFC_NDEF_RECORD_MASK_ME)
+ {
+ newRec->ME = 1;
+ }
+ if (ndef_header & NET_NFC_NDEF_RECORD_MASK_CF)
+ {
+ newRec->CF = 1;
+ }
+ if (ndef_header & NET_NFC_NDEF_RECORD_MASK_SR)
+ {
+ newRec->SR = 1;
+ }
+ if (ndef_header & NET_NFC_NDEF_RECORD_MASK_IL)
+ {
+ newRec->IL = 1;
+ }
+
+ newRec->TNF = ndef_header & NET_NFC_NDEF_RECORD_MASK_TNF;
+
+ newRec->type_s.length = *current++;
+
+ /* SR = 1 -> payload is 1 byte, SR = 0 -> payload is 4 bytes */
+ if(ndef_header & NET_NFC_NDEF_RECORD_MASK_SR)
+ {
+ newRec->payload_s.length = *current++;
+ }
+ else
+ {
+ newRec->payload_s.length = (uint32_t)((*current) << 24);
+ current++;
+
+ newRec->payload_s.length += (uint32_t)((*current) << 16);
+ current++;
+
+ newRec->payload_s.length += (uint32_t)((*current) << 8);
+ current++;
+
+ newRec->payload_s.length += (uint32_t)((*current));
+ current++;
+ }
+
+ /* ID length check */
+ if(ndef_header & NET_NFC_NDEF_RECORD_MASK_IL)
+ {
+ newRec->id_s.length = *current++;
+ }
+ else
+ {
+ newRec->id_s.length = 0;
+ }
+
+ /* to do : chunked record */
+
+
+ /* empty record check */
+ if((ndef_header & NET_NFC_NDEF_RECORD_MASK_TNF) == NET_NFC_NDEF_TNF_EMPTY)
+ {
+ if(newRec->type_s.length != 0 || newRec->id_s.length != 0 || newRec->payload_s.length != 0)
+ {
+ result = NET_NFC_INVALID_FORMAT;
+ goto error;
+ }
+ }
+
+ if((ndef_header & NET_NFC_NDEF_RECORD_MASK_TNF) == NET_NFC_NDEF_TNF_UNKNOWN)
+ {
+ if(newRec->type_s.length != 0)
+ {
+ result = NET_NFC_INVALID_FORMAT;
+ goto error;
+ }
+ }
+
+ /* put Type buffer */
+ if(newRec->type_s.length > 0)
+ {
+ _net_nfc_util_alloc_mem(newRec->type_s.buffer, newRec->type_s.length);
+ if (newRec->type_s.buffer == NULL)
+ {
+ result = NET_NFC_ALLOC_FAIL;
+ goto error;
+ }
+
+ memcpy(newRec->type_s.buffer, current, newRec->type_s.length);
+ current += newRec->type_s.length;
+ }
+ else
+ {
+ newRec->type_s.buffer = NULL;
+ }
+
+ /* put ID buffer */
+ if(newRec->id_s.length > 0)
+ {
+ _net_nfc_util_alloc_mem(newRec->id_s.buffer, newRec->id_s.length);
+ if (newRec->id_s.buffer == NULL)
+ {
+ result = NET_NFC_ALLOC_FAIL;
+ goto error;
+ }
+
+ memcpy(newRec->id_s.buffer, current, newRec->id_s.length);
+ current += newRec->id_s.length;
+ }
+ else
+ {
+ newRec->id_s.buffer = NULL;
+ }
+
+ /* put Payload buffer */
+ if(newRec->payload_s.length > 0)
+ {
+ _net_nfc_util_alloc_mem(newRec->payload_s.buffer, newRec->payload_s.length);
+ if (newRec->payload_s.buffer == NULL)
+ {
+ result = NET_NFC_ALLOC_FAIL;
+ goto error;
+ }
+
+ memcpy(newRec->payload_s.buffer, current, newRec->payload_s.length);
+ current += newRec->payload_s.length;
+ }
+ else
+ {
+ newRec->payload_s.buffer = NULL;
+ }
+
+ if (ndef->recordCount == 0)
+ ndef->records = newRec;
+ else
+ prevRec->next = newRec;
+
+ prevRec = newRec;
+ newRec = NULL;
+
+ if(ndef_header & NET_NFC_NDEF_RECORD_MASK_ME)
+ {
+ break;
+ }
+ }
+
+ ndef->recordCount++;
+
+ if((current != last) || ((ndef_header & NET_NFC_NDEF_RECORD_MASK_ME) == 0))
+ {
+ result = NET_NFC_INVALID_FORMAT;
+ goto error;
+ }
+
+ return NET_NFC_OK;
+
+error:
+
+ DEBUG_ERR_MSG("parser error");
+
+ if (newRec)
+ {
+ _net_nfc_util_free_mem(newRec->type_s.buffer);
+ _net_nfc_util_free_mem(newRec->id_s.buffer);
+ _net_nfc_util_free_mem(newRec->payload_s.buffer);
+ _net_nfc_util_free_mem(newRec);
+ }
+
+ prevRec = ndef->records;
+
+ while(prevRec)
+ {
+ ndef_record_s *tmpRec = NULL;
+
+ _net_nfc_util_free_mem(prevRec->type_s.buffer);
+ _net_nfc_util_free_mem(prevRec->id_s.buffer);
+ _net_nfc_util_free_mem(prevRec->payload_s.buffer);
+
+ tmpRec = prevRec->next;
+ _net_nfc_util_free_mem(prevRec);
+ prevRec = tmpRec;
+ }
+
+ ndef->records = NULL;
+
+ return result;
+}
+
+net_nfc_error_e net_nfc_util_convert_ndef_message_to_rawdata(ndef_message_s *ndef, data_s *rawdata)
+{
+ ndef_record_s *record = NULL;
+ uint8_t *current = NULL;
+ uint8_t ndef_header;
+
+ if (rawdata == NULL || ndef == NULL)
+ return NET_NFC_NULL_PARAMETER;
+
+ record = ndef->records;
+ current = rawdata->buffer;
+
+ while(record)
+ {
+ ndef_header = 0x00;
+
+ if(record->MB)
+ ndef_header |= NET_NFC_NDEF_RECORD_MASK_MB;
+ if(record->ME)
+ ndef_header |= NET_NFC_NDEF_RECORD_MASK_ME;
+ if(record->CF)
+ ndef_header |= NET_NFC_NDEF_RECORD_MASK_CF;
+ if(record->SR)
+ ndef_header |= NET_NFC_NDEF_RECORD_MASK_SR;
+ if(record->IL)
+ ndef_header |= NET_NFC_NDEF_RECORD_MASK_IL;
+
+ ndef_header |= record->TNF;
+
+ *current++ = ndef_header;
+
+ /* check empty record */
+ if(record->TNF == NET_NFC_NDEF_TNF_EMPTY)
+ {
+ /* set type length to zero */
+ *current++ = 0x00;
+
+ /* set payload length to zero */
+ *current++ = 0x00;
+
+ /* set ID length to zero */
+ if(record->IL)
+ {
+ *current++ = 0x00;
+ }
+
+ record = record->next;
+
+ continue;
+ }
+
+ /* set type length */
+ if(record->TNF == NET_NFC_NDEF_TNF_UNKNOWN || record->TNF == NET_NFC_NDEF_TNF_UNCHANGED)
+ {
+ *current++ = 0x00;
+ }
+ else
+ {
+ *current++ = record->type_s.length;
+ }
+
+ /* set payload length */
+ if(record->SR)
+ {
+ *current++ = (uint8_t)(record->payload_s.length & 0x000000FF);
+ }
+ else
+ {
+ *current++ = (uint8_t)((record->payload_s.length & 0xFF000000) >> 24);
+ *current++ = (uint8_t)((record->payload_s.length & 0x00FF0000) >> 16);
+ *current++ = (uint8_t)((record->payload_s.length & 0x0000FF00) >> 8);
+ *current++ = (uint8_t)(record->payload_s.length & 0x000000FF) ;
+ }
+
+ /* set ID length */
+ if(record->IL)
+ {
+ *current++ = record->id_s.length;
+ }
+
+ /* set type buffer */
+ if((record->TNF != NET_NFC_NDEF_TNF_UNKNOWN) && (record->TNF != NET_NFC_NDEF_TNF_UNCHANGED))
+ {
+ memcpy(current, record->type_s.buffer, record->type_s.length);
+ current += record->type_s.length;
+ }
+
+ /* set ID buffer */
+ memcpy(current, record->id_s.buffer, record->id_s.length);
+ current += record->id_s.length;
+
+ /* set payload buffer */
+ memcpy(current, record->payload_s.buffer, record->payload_s.length);
+ current += record->payload_s.length;
+
+ record = record->next;
+ }
+
+ return NET_NFC_OK;
+}
+
+net_nfc_error_e net_nfc_util_append_record(ndef_message_s *msg, ndef_record_s *record)
+{
+ if (msg == NULL || record == NULL)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ if (msg->recordCount == 0)
+ {
+ // set short message and append
+ record->MB = 1;
+ record->ME = 1;
+ record->next = NULL;
+
+ msg->records = record;
+
+ msg->recordCount++;
+
+ DEBUG_MSG("record is added to NDEF message :: count [%d]", msg->recordCount);
+ }
+ else
+ {
+ ndef_record_s *current = NULL;
+ ndef_record_s *prev = NULL;
+
+ // set flag :: this record is FIRST
+ current = msg->records;
+
+ if (current != NULL)
+ {
+ // first node
+ current->MB = 1;
+ current->ME = 0;
+
+ prev = current;
+
+ // second node
+ current = current->next;
+
+ while (current != NULL)
+ {
+ current->MB = 0;
+ current->ME = 0;
+ prev = current;
+ current = current->next;
+ }
+
+ // set flag :: this record is END
+ record->MB = 0;
+ record->ME = 1;
+
+ prev->next = record;
+ msg->recordCount++;
+ }
+
+ }
+
+ return NET_NFC_OK;
+}
+
+uint32_t net_nfc_util_get_ndef_message_length(ndef_message_s *message)
+{
+ ndef_record_s *current;
+ int total = 0;
+
+ if (message == NULL)
+ return 0;
+
+ current = message->records;
+
+ while (current != NULL)
+ {
+ total += net_nfc_util_get_record_length(current);
+ current = current->next;
+ }
+
+ return total;
+}
+
+void net_nfc_util_print_ndef_message(ndef_message_s *msg)
+{
+ int idx = 0, idx2 = 0;
+ ndef_record_s *current = NULL;
+ char buffer[1024];
+
+ if (msg == NULL)
+ {
+ return;
+ }
+
+ // 123456789012345678901234567890123456789012345678901234567890
+ DEBUG_MSG("========== NDEF Message ====================================\n");
+ DEBUG_MSG("Total NDEF Records count: %d\n", msg->recordCount);
+ current = msg->records;
+ for (idx = 0; idx < msg->recordCount; idx++)
+ {
+ if (current == NULL)
+ {
+ DEBUG_ERR_MSG("Message Record is NULL!! unexpected error");
+ DEBUG_MSG("============================================================\n");
+ return;
+ }
+ DEBUG_MSG("---------- Record -----------------------------------------\n");
+ DEBUG_MSG("MB:%d ME:%d CF:%d SR:%d IL:%d TNF:0x%02X\n",
+ current->MB, current->ME, current->CF, current->SR, current->IL, current->TNF);
+ DEBUG_MSG("TypeLength:%d PayloadLength:%d IDLength:%d\n",
+ current->type_s.length, current->payload_s.length, current->id_s.length);
+ if (current->type_s.buffer != NULL)
+ {
+ memcpy(buffer, current->type_s.buffer, current->type_s.length);
+ buffer[current->type_s.length] = '\0';
+ DEBUG_MSG("Type: %s\n", buffer);
+ }
+ if (current->id_s.buffer != NULL)
+ {
+ memcpy(buffer, current->id_s.buffer, current->id_s.length);
+ buffer[current->id_s.length] = '\0';
+ SECURE_LOGD("ID: %s\n", buffer);
+ }
+ if (current->payload_s.buffer != NULL)
+ {
+ DEBUG_MSG("Payload: ");
+ for (idx2 = 0; idx2 < current->payload_s.length; idx2++)
+ {
+ if (idx2 % 16 == 0)
+ DEBUG_MSG("\n\t");
+ DEBUG_MSG("%02X ", current->payload_s.buffer[idx2]);
+ }
+ DEBUG_MSG("\n");
+ }
+ current = current->next;
+ }
+ // 123456789012345678901234567890123456789012345678901234567890
+ DEBUG_MSG("============================================================\n");
+
+}
+
+net_nfc_error_e net_nfc_util_free_ndef_message(ndef_message_s *msg)
+{
+ int idx = 0;
+ ndef_record_s *prev, *current;
+
+ if (msg == NULL)
+ return NET_NFC_NULL_PARAMETER;
+
+ current = msg->records;
+
+ for (idx = 0; idx < msg->recordCount; idx++)
+ {
+ if (current == NULL)
+ break;
+
+ prev = current;
+ current = current->next;
+
+ net_nfc_util_free_record(prev);
+ }
+
+ _net_nfc_util_free_mem(msg);
+
+ return NET_NFC_OK;
+}
+
+net_nfc_error_e net_nfc_util_create_ndef_message(ndef_message_s **ndef_message)
+{
+ if (ndef_message == NULL) {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ _net_nfc_util_alloc_mem(*ndef_message, sizeof(ndef_message_s));
+ if (*ndef_message == NULL) {
+ return NET_NFC_ALLOC_FAIL;
+ }
+
+ return NET_NFC_OK;
+}
+
+net_nfc_error_e net_nfc_util_remove_record_by_index(ndef_message_s *ndef_message, int index)
+{
+ int current_idx = 0;
+ ndef_record_s *prev;
+ ndef_record_s *next;
+ ndef_record_s *current;
+
+ if (ndef_message == NULL)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ if (index < 0 || index >= ndef_message->recordCount)
+ {
+ return NET_NFC_OUT_OF_BOUND;
+ }
+
+ if (index == 0)
+ {
+ current = ndef_message->records;
+ next = ndef_message->records->next;
+ ndef_message->records = next;
+ }
+ else
+ {
+ prev = ndef_message->records;
+ for (; current_idx < index - 1; current_idx++)
+ {
+ prev = prev->next;
+ if (prev == NULL)
+ {
+ return NET_NFC_INVALID_FORMAT;
+ }
+ }
+ current = prev->next;
+ if (current == NULL)
+ {
+ return NET_NFC_INVALID_FORMAT;
+ }
+ next = current->next;
+ prev->next = next;
+ }
+
+ net_nfc_util_free_record(current);
+ (ndef_message->recordCount)--;
+
+ return __net_nfc_repair_record_flags(ndef_message);
+}
+
+net_nfc_error_e net_nfc_util_get_record_by_index(ndef_message_s *ndef_message, int index, ndef_record_s **record)
+{
+ ndef_record_s *current;
+ int idx = 0;
+
+ if (ndef_message == NULL || record == NULL)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ if (index < 0 || index >= ndef_message->recordCount)
+ {
+ return NET_NFC_OUT_OF_BOUND;
+ }
+
+ current = ndef_message->records;
+
+ for (; current != NULL && idx < index; idx++)
+ {
+ current = current->next;
+ }
+
+ *record = current;
+
+ return NET_NFC_OK;
+}
+
+net_nfc_error_e net_nfc_util_append_record_by_index(ndef_message_s *ndef_message, int index, ndef_record_s *record)
+{
+ int idx = 0;
+ ndef_record_s *prev;
+ ndef_record_s *next;
+
+ if (ndef_message == NULL || record == NULL)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ if (index < 0 || index > ndef_message->recordCount)
+ {
+ return NET_NFC_OUT_OF_BOUND;
+ }
+
+ prev = ndef_message->records;
+
+ if (index == 0)
+ {
+ ndef_message->records = record;
+ record->next = prev;
+ }
+ else
+ {
+ for (; idx < index - 1; idx++)
+ {
+ prev = prev->next;
+ if (prev == NULL)
+ {
+ return NET_NFC_INVALID_FORMAT;
+ }
+ }
+ next = prev->next;
+ prev->next = record;
+ record->next = next;
+ }
+ (ndef_message->recordCount)++;
+
+ return __net_nfc_repair_record_flags(ndef_message);
+}
+
+net_nfc_error_e net_nfc_util_search_record_by_type(ndef_message_s *ndef_message, net_nfc_record_tnf_e tnf, data_s *type, ndef_record_s **record)
+{
+ int idx = 0;
+ ndef_record_s *tmp_record;
+ uint32_t type_length;
+ uint8_t *buf;
+
+ if (ndef_message == NULL || type == NULL || record == NULL)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ type_length = type->length;
+ buf = type->buffer;
+
+ /* remove prefix of nfc specific urn */
+ if (type_length > 12)
+ {
+ if (memcmp(buf, "urn:nfc:ext:", 12) == 0 ||
+ memcmp(buf, "urn:nfc:wkt:", 12) == 0)
+ {
+ buf += 12;
+ type_length -= 12;
+ }
+ }
+
+ tmp_record = ndef_message->records;
+
+ for (; idx < ndef_message->recordCount; idx++)
+ {
+ if (tmp_record == NULL)
+ {
+ *record = NULL;
+
+ return NET_NFC_INVALID_FORMAT;
+ }
+
+ if (tmp_record->TNF == tnf &&
+ type_length == tmp_record->type_s.length &&
+ memcmp(buf, tmp_record->type_s.buffer, type_length) == 0)
+ {
+ *record = tmp_record;
+
+ return NET_NFC_OK;
+ }
+
+ tmp_record = tmp_record->next;
+ }
+
+ return NET_NFC_NO_DATA_FOUND;
+}
+
+net_nfc_error_e net_nfc_util_search_record_by_id(ndef_message_s *ndef_message, data_s *id, ndef_record_s **record)
+{
+ int idx = 0;
+ ndef_record_s *record_in_msg;
+ uint32_t id_length;
+ uint8_t *buf;
+
+ if (ndef_message == NULL || id == NULL || record == NULL)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ id_length = id->length;
+ buf = id->buffer;
+
+ record_in_msg = ndef_message->records;
+
+ for (; idx < ndef_message->recordCount; idx++)
+ {
+ if (record_in_msg == NULL)
+ {
+ *record = NULL;
+
+ return NET_NFC_INVALID_FORMAT;
+ }
+ if (id_length == record_in_msg->id_s.length &&
+ memcmp(buf, record_in_msg->id_s.buffer, id_length) == 0)
+ {
+ *record = record_in_msg;
+
+ return NET_NFC_OK;
+ }
+
+ record_in_msg = record_in_msg->next;
+ }
+
+ return NET_NFC_NO_DATA_FOUND;
+}
+
+static net_nfc_error_e __net_nfc_repair_record_flags(ndef_message_s *ndef_message)
+{
+ int idx = 0;
+ ndef_record_s *record;
+
+ if (ndef_message == NULL)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ record = ndef_message->records;
+
+ if (ndef_message->recordCount == 1)
+ {
+ if (record == NULL)
+ {
+ return NET_NFC_INVALID_FORMAT;
+ }
+
+ record->MB = 1;
+ record->ME = 1;
+
+ return NET_NFC_OK;
+ }
+
+ for (idx = 0; idx < ndef_message->recordCount; idx++)
+ {
+ if (record == NULL)
+ {
+ return NET_NFC_INVALID_FORMAT;
+ }
+
+ if (idx == 0)
+ {
+ record->MB = 1;
+ record->ME = 0;
+ }
+ else if (idx == ndef_message->recordCount - 1)
+ {
+ record->MB = 0;
+ record->ME = 1;
+ }
+ else
+ {
+ record->MB = 0;
+ record->ME = 0;
+ }
+ record = record->next;
+ }
+
+ return NET_NFC_OK;
+}
+
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "net_nfc_debug_internal.h"
+#include "net_nfc_util_defines.h"
+#include "net_nfc_util_internal.h"
+#include "net_nfc_util_ndef_message.h"
+#include "net_nfc_util_ndef_record.h"
+
+net_nfc_error_e net_nfc_util_free_record(ndef_record_s *record)
+{
+ if (record == NULL)
+ return NET_NFC_NULL_PARAMETER;
+
+ if (record->type_s.buffer != NULL)
+ _net_nfc_util_free_mem(record->type_s.buffer);
+ if (record->id_s.buffer != NULL)
+ _net_nfc_util_free_mem(record->id_s.buffer);
+ if (record->payload_s.buffer != NULL)
+ _net_nfc_util_free_mem(record->payload_s.buffer);
+
+ _net_nfc_util_free_mem(record);
+
+ return NET_NFC_OK;
+}
+
+net_nfc_error_e net_nfc_util_create_record(net_nfc_record_tnf_e recordType, data_s *typeName, data_s *id, data_s *payload, ndef_record_s **record)
+{
+ ndef_record_s *record_temp = NULL;
+
+ if (typeName == NULL || payload == NULL || record == NULL)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ if (recordType < NET_NFC_RECORD_EMPTY || recordType > NET_NFC_RECORD_UNCHAGNED)
+ {
+ return NET_NFC_OUT_OF_BOUND;
+ }
+
+ /* empty_tag */
+ if (recordType == NET_NFC_RECORD_EMPTY)
+ {
+ if ((typeName->buffer != NULL) || (payload->buffer != NULL) || (id->buffer != NULL) || (typeName->length != 0) || (payload->length != 0) || (id->length != 0))
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ _net_nfc_util_alloc_mem(record_temp, sizeof(ndef_record_s));
+ if (record_temp == NULL)
+ {
+ return NET_NFC_ALLOC_FAIL;
+ }
+
+ // set type name and length and TNF field
+ record_temp->TNF = recordType;
+ record_temp->type_s.length = typeName->length;
+
+ if(record_temp->type_s.length > 0)
+ {
+ _net_nfc_util_alloc_mem(record_temp->type_s.buffer, record_temp->type_s.length);
+ if (record_temp->type_s.buffer == NULL)
+ {
+ _net_nfc_util_free_mem(record_temp);
+
+ return NET_NFC_ALLOC_FAIL;
+ }
+
+ memcpy(record_temp->type_s.buffer, typeName->buffer, record_temp->type_s.length);
+ }
+ else
+ {
+ record_temp->type_s.buffer = NULL;
+ record_temp->type_s.length = 0;
+ }
+
+ // set payload
+ record_temp->payload_s.length = payload->length;
+ if(payload->length >0)
+ {
+ _net_nfc_util_alloc_mem(record_temp->payload_s.buffer, record_temp->payload_s.length);
+ if (record_temp->payload_s.buffer == NULL)
+ {
+ _net_nfc_util_free_mem(record_temp->type_s.buffer);
+ _net_nfc_util_free_mem(record_temp);
+
+ return NET_NFC_ALLOC_FAIL;
+ }
+
+ memcpy(record_temp->payload_s.buffer, payload->buffer, record_temp->payload_s.length);
+ }
+ else
+ {
+ record_temp->payload_s.buffer = NULL;
+ record_temp->payload_s.length = 0;
+ }
+
+ if (payload->length < 256)
+ {
+ record_temp->SR = 1;
+ }
+ else
+ {
+ record_temp->SR = 0;
+ }
+
+ // set id and id length and IL field
+ if (id != NULL && id->buffer != NULL && id->length > 0)
+ {
+ record_temp->id_s.length = id->length;
+ _net_nfc_util_alloc_mem(record_temp->id_s.buffer, record_temp->id_s.length);
+ if (record_temp->id_s.buffer == NULL)
+ {
+ _net_nfc_util_free_mem(record_temp->payload_s.buffer);
+ _net_nfc_util_free_mem(record_temp->type_s.buffer);
+ _net_nfc_util_free_mem(record_temp);
+
+ return NET_NFC_ALLOC_FAIL;
+ }
+
+ memcpy(record_temp->id_s.buffer, id->buffer, record_temp->id_s.length);
+ record_temp->IL = 1;
+ }
+ else
+ {
+ record_temp->IL = 0;
+ record_temp->id_s.buffer = NULL;
+ record_temp->id_s.length = 0;
+ }
+
+ // this is default value
+ record_temp->MB = 1;
+ record_temp->ME = 1;
+
+ record_temp->next = NULL;
+
+ *record = record_temp;
+
+ return NET_NFC_OK;
+}
+
+net_nfc_error_e net_nfc_util_create_uri_type_record(const char *uri, net_nfc_schema_type_e protocol_schema, ndef_record_s **record)
+{
+ net_nfc_error_e error;
+ data_s type_data;
+ data_s payload_data = { NULL, 0 };
+
+ if (uri == NULL)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ payload_data.length = strlen((char *)uri) + 1;
+ if (payload_data.length == 1)
+ {
+ return NET_NFC_INVALID_PARAM;
+ }
+
+ _net_nfc_util_alloc_mem(payload_data.buffer, payload_data.length);
+ if (payload_data.buffer == NULL)
+ {
+ return NET_NFC_ALLOC_FAIL;
+ }
+
+ payload_data.buffer[0] = protocol_schema; /* first byte of payload is protocol scheme */
+ memcpy(payload_data.buffer + 1, uri, payload_data.length - 1);
+
+ type_data.length = 1;
+ type_data.buffer = (uint8_t *)URI_RECORD_TYPE;
+
+ error = net_nfc_util_create_record(NET_NFC_RECORD_WELL_KNOWN_TYPE, &type_data, NULL, &payload_data, record);
+
+ _net_nfc_util_free_mem(payload_data.buffer);
+
+ return error;
+}
+
+net_nfc_error_e net_nfc_util_create_text_type_record(const char *text, const char *lang_code_str, net_nfc_encode_type_e encode, ndef_record_s **record)
+{
+ data_s type_data;
+ data_s payload_data;
+ int controll_byte;
+ int offset = 0;
+
+ if (text == NULL || lang_code_str == NULL)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ if ((encode < NET_NFC_ENCODE_UTF_8 || encode > NET_NFC_ENCODE_UTF_16))
+ {
+ return NET_NFC_OUT_OF_BOUND;
+ }
+
+ payload_data.length = strlen((char *)text) + strlen(lang_code_str) + 1;
+
+ _net_nfc_util_alloc_mem(payload_data.buffer, payload_data.length);
+ if (payload_data.buffer == NULL)
+ {
+ return NET_NFC_ALLOC_FAIL;
+ }
+
+ controll_byte = strlen(lang_code_str) & 0x3F;
+ if (encode == NET_NFC_ENCODE_UTF_16)
+ {
+ controll_byte = controll_byte | 0x80;
+ }
+
+ payload_data.buffer[0] = controll_byte;
+
+ offset = 1;
+ memcpy(payload_data.buffer + offset, lang_code_str, strlen(lang_code_str));
+
+ offset = offset + strlen(lang_code_str);
+ memcpy(payload_data.buffer + offset, (char *)text, strlen((char *)text));
+
+ type_data.length = 1;
+ type_data.buffer = (uint8_t *)TEXT_RECORD_TYPE;
+
+ net_nfc_util_create_record(NET_NFC_RECORD_WELL_KNOWN_TYPE, &type_data, NULL, &payload_data, record);
+
+ _net_nfc_util_free_mem(payload_data.buffer);
+
+ return NET_NFC_OK;
+}
+
+net_nfc_error_e net_nfc_util_set_record_id(ndef_record_s *record, uint8_t *data, int length)
+{
+ if (record == NULL || data == NULL)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ if (length < 1)
+ {
+ return NET_NFC_OUT_OF_BOUND;
+ }
+
+ if (record->id_s.buffer != NULL && record->id_s.length > 0)
+ {
+ _net_nfc_util_free_mem(record->id_s.buffer);
+ }
+
+ _net_nfc_util_alloc_mem(record->id_s.buffer, length);
+ if (record->id_s.buffer == NULL)
+ {
+ return NET_NFC_ALLOC_FAIL;
+ }
+ memcpy(record->id_s.buffer, data, length);
+ record->id_s.length = length;
+ record->IL = 1;
+
+ return NET_NFC_OK;
+}
+
+uint32_t net_nfc_util_get_record_length(ndef_record_s *Record)
+{
+ uint32_t RecordLength = 1;
+
+ if (Record == NULL)
+ return 0;
+
+ /* Type length is present only for following TNF
+ NET_NFC_TNF_NFCWELLKNOWN
+ NET_NFC_TNF_MEDIATYPE
+ SLP_FRINET_NFC_NDEFRECORD_TNF_ABSURI
+ SLP_FRINET_NFC_NDEFRECORD_TNF_NFCEXT
+ */
+
+ /* ++ is for the Type Length Byte */
+ RecordLength++;
+ if (Record->TNF != NET_NFC_NDEF_TNF_EMPTY &&
+ Record->TNF != NET_NFC_NDEF_TNF_UNKNOWN &&
+ Record->TNF != NET_NFC_NDEF_TNF_UNCHANGED)
+ {
+ RecordLength += Record->type_s.length;
+ }
+
+ /* to check if payloadlength is 8bit or 32bit*/
+ if (Record->SR != 0)
+ {
+ /* ++ is for the Payload Length Byte */
+ RecordLength++;/* for short record*/
+ }
+ else
+ {
+ /* + NET_NFC_NDEF_NORMAL_RECORD_BYTE is for the Payload Length Byte */
+ RecordLength += 4;
+ }
+
+ /* for non empty record */
+ if (Record->TNF != NET_NFC_NDEF_TNF_EMPTY)
+ {
+ RecordLength += Record->payload_s.length;
+ }
+
+ /* ID and IDlength are present only if IL flag is set*/
+ if (Record->IL != 0)
+ {
+ RecordLength += Record->id_s.length;
+ /* ++ is for the ID Length Byte */
+ RecordLength++;
+ }
+
+ return RecordLength;
+}
+
+net_nfc_error_e net_nfc_util_create_uri_string_from_uri_record(ndef_record_s *record, char **uri)
+{
+ net_nfc_error_e result = NET_NFC_OK;
+
+ if (record == NULL || uri == NULL)
+ {
+ return NET_NFC_INVALID_PARAM;
+ }
+
+ *uri = NULL;
+
+ if (record->TNF == NET_NFC_RECORD_WELL_KNOWN_TYPE &&
+ (record->type_s.length == 1 && record->type_s.buffer[0] == 'U'))
+ {
+ data_s *payload = &record->payload_s;
+
+ if (payload->length > 0)
+ {
+ int length = 0;
+ const char *scheme = NULL;
+
+ /* buffer length include a schema byte.
+ * so it does not need to allocate one more byte for string. */
+ if ((scheme = net_nfc_util_get_schema_string(payload->buffer[0])) != NULL)
+ {
+ length = strlen(scheme);
+ }
+
+ *uri = (char *)calloc(1, length + payload->length);
+ if (*uri != NULL)
+ {
+ if (length > 0)
+ memcpy(*uri, scheme, length);
+ memcpy(*uri + length, payload->buffer + 1, payload->length - 1);
+ }
+ else
+ {
+ result = NET_NFC_ALLOC_FAIL;
+ }
+ }
+ else
+ {
+ DEBUG_ERR_MSG("invalid payload in record");
+ }
+ }
+ else if (record->TNF == NET_NFC_RECORD_URI)
+ {
+ data_s *type = &record->type_s;
+
+ if (type->length > 0)
+ {
+ *uri = (char *)calloc(1, type->length + 1);
+
+ if (*uri != NULL)
+ {
+ memcpy(*uri, type->buffer, type->length);
+ }
+ else
+ {
+ result = NET_NFC_ALLOC_FAIL;
+ }
+ }
+ }
+ else
+ {
+ DEBUG_ERR_MSG("no uri record");
+ result = NET_NFC_NDEF_RECORD_IS_NOT_EXPECTED_TYPE;
+ }
+
+ return result;
+}
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#include <openssl/evp.h>
+#include <openssl/engine.h>
+#include <openssl/pkcs12.h>
+#include <openssl/pem.h>
+
+#include "net_nfc_typedef_internal.h"
+#include "net_nfc_debug_internal.h"
+#include "net_nfc_util_internal.h"
+#include "net_nfc_util_openssl_internal.h"
+
+//static X509 *_load_certificate_from_file(const char *file)
+//{
+// X509 *x509 = NULL;
+// BIO *cert = NULL;
+//
+// cert = BIO_new(BIO_s_file());
+// if (cert != NULL)
+// {
+// if (BIO_read_filename(cert, file) > 0)
+// {
+// x509 = PEM_read_bio_X509_AUX(cert, NULL, NULL, NULL);
+// }
+//
+// BIO_free(cert);
+// }
+//
+// return x509;
+//}
+
+static X509 *_load_certificate_from_mem(int format, uint8_t *buffer, uint32_t length, char *password)
+{
+ X509 *x509 = NULL;
+ BIO *mem = NULL;
+
+ mem = BIO_new_mem_buf(buffer, length);
+ if (mem != NULL)
+ {
+ switch (format)
+ {
+ case 0 :
+ x509 = d2i_X509_bio(mem, NULL);
+ break;
+
+ case 1 :
+ x509 = PEM_read_bio_X509(mem, NULL, NULL, NULL);
+ break;
+
+ case 2 :
+ {
+ PKCS12 *p12 = d2i_PKCS12_bio(mem, NULL);
+ PKCS12_parse(p12, password, NULL, &x509, NULL);
+ PKCS12_free(p12);
+ }
+ break;
+ }
+
+ BIO_free(mem);
+ }
+ else
+ {
+ DEBUG_ERR_MSG("X509_LOOKUP_load_file failed");
+ }
+
+ return x509;
+}
+
+//int net_nfc_util_openssl_verify_certificate(const char* certfile, const char* CAfile)
+//{
+// int ret = 0;
+// X509_STORE *cert_ctx = NULL;
+// X509_LOOKUP *lookup = NULL;
+//
+// cert_ctx = X509_STORE_new();
+// if (cert_ctx != NULL)
+// {
+// OpenSSL_add_all_algorithms();
+//
+// lookup = X509_STORE_add_lookup(cert_ctx, X509_LOOKUP_file());
+// if (lookup != NULL)
+// {
+// if (X509_LOOKUP_load_file(lookup, CAfile, X509_FILETYPE_PEM) == true)
+// {
+// lookup = X509_STORE_add_lookup(cert_ctx, X509_LOOKUP_hash_dir());
+// if (lookup != NULL)
+// {
+// X509_LOOKUP_add_dir(lookup, NULL, X509_FILETYPE_DEFAULT);
+//
+// ret = _verify_certificate_file(cert_ctx, certfile);
+// }
+// else
+// {
+// DEBUG_ERR_MSG("X509_STORE_add_lookup failed");
+// }
+// }
+// else
+// {
+// DEBUG_ERR_MSG("X509_LOOKUP_load_file failed");
+// }
+// }
+// else
+// {
+// DEBUG_ERR_MSG("X509_STORE_add_lookup failed");
+// }
+//
+// X509_STORE_free(cert_ctx);
+// }
+// else
+// {
+// DEBUG_ERR_MSG("X509_STORE_new failed");
+// }
+//
+// return ret;
+//}
+
+net_nfc_openssl_verify_context_s *net_nfc_util_openssl_init_verify_certificate(void)
+{
+ net_nfc_openssl_verify_context_s *result = NULL;
+
+ _net_nfc_util_alloc_mem(result, sizeof(net_nfc_openssl_verify_context_s));
+ if (result != NULL)
+ {
+ result->store = X509_STORE_new();
+ if (result->store != NULL)
+ {
+ OpenSSL_add_all_algorithms();
+ }
+ else
+ {
+ DEBUG_ERR_MSG("X509_STORE_new failed");
+ }
+ }
+ else
+ {
+ DEBUG_ERR_MSG("alloc failed [%d]", sizeof(net_nfc_openssl_verify_context_s));
+ }
+
+ return result;
+}
+
+void net_nfc_util_openssl_release_verify_certificate(net_nfc_openssl_verify_context_s *context)
+{
+ if (context != NULL)
+ {
+ if (context->signer_cert != NULL)
+ X509_free(context->signer_cert);
+
+ if (context->store != NULL)
+ X509_STORE_free(context->store);
+
+ _net_nfc_util_free_mem(context);
+ }
+}
+
+bool net_nfc_util_openssl_add_certificate_of_signer(net_nfc_openssl_verify_context_s *context, uint8_t *buffer, uint32_t length)
+{
+ bool result = false;
+
+ if (context->signer_cert != NULL)
+ {
+ X509_free(context->signer_cert);
+ context->signer_cert = NULL;
+ }
+
+ context->signer_cert = _load_certificate_from_mem(1, buffer, length, NULL);
+ if (context->signer_cert != NULL)
+ result = true;
+
+ return result;
+}
+
+bool net_nfc_util_openssl_add_certificate_of_ca(net_nfc_openssl_verify_context_s *context, uint8_t *buffer, uint32_t length)
+{
+ bool result = false;
+ X509 *x509 = NULL;
+
+ x509 = _load_certificate_from_mem(1, buffer, length, NULL);
+ if (x509 != NULL)
+ {
+ if (X509_STORE_add_cert(context->store, x509))
+ {
+ result = true;
+ }
+ }
+
+ return result;
+}
+
+int net_nfc_util_openssl_verify_certificate(net_nfc_openssl_verify_context_s *context)
+{
+ int result = 0;
+ X509_STORE_CTX *store_ctx = NULL;
+
+ store_ctx = X509_STORE_CTX_new();
+ if (store_ctx != NULL)
+ {
+ X509_STORE_set_flags(context->store, 0);
+ if (X509_STORE_CTX_init(store_ctx, context->store, context->signer_cert, 0) == true)
+ {
+ result = X509_verify_cert(store_ctx);
+ }
+ else
+ {
+ DEBUG_ERR_MSG("X509_STORE_CTX_init failed");
+ }
+
+ X509_STORE_CTX_free(store_ctx);
+ }
+ else
+ {
+ DEBUG_ERR_MSG("X509_STORE_CTX_new failed");
+ }
+
+ return result;
+}
+
+int _password_callback(char *buf, int bufsiz, int verify, void *data)
+{
+ int res = 0;
+ const char *password = (char *)data;
+
+ if (password)
+ {
+ res = strlen(password);
+ if (res > bufsiz)
+ res = bufsiz;
+ memcpy(buf, password, res);
+ return res;
+ }
+
+ return res;
+}
+
+static int _load_pkcs12(BIO *in, const char *password, EVP_PKEY **pkey, X509 **cert, STACK_OF(X509) **ca)
+{
+ int ret = 0;
+ PKCS12 *p12 = NULL;
+
+ if ((p12 = d2i_PKCS12_bio(in, NULL)) != NULL)
+ {
+ if (PKCS12_verify_mac(p12, password, strlen(password)) == true)
+ {
+ ret = PKCS12_parse(p12, password, pkey, cert, ca);
+ }
+ else
+ {
+ DEBUG_ERR_MSG("Mac verify error (wrong password?) in PKCS12 file");
+ }
+
+ PKCS12_free(p12);
+ }
+ else
+ {
+ DEBUG_ERR_MSG("Error loading PKCS12 file");
+ }
+
+ return ret;
+}
+
+EVP_PKEY *_load_key(const char *file, int format, const char *pass, ENGINE *e)
+{
+ BIO *key = NULL;
+ EVP_PKEY *pkey = NULL;
+
+ if (file == NULL)
+ {
+ DEBUG_ERR_MSG("no keyfile specified\n");
+ return pkey;
+ }
+
+ if (format == OPENSSL_FORMAT_ENGINE)
+ {
+ if (e != NULL)
+ {
+ pkey = ENGINE_load_private_key(e, file, NULL/*ui_method*/, (void *)pass);
+ if (!pkey)
+ {
+ DEBUG_ERR_MSG("cannot load key from engine");
+ }
+ }
+ else
+ {
+ DEBUG_ERR_MSG("no engine specified");
+ }
+ }
+ else
+ {
+ if ((key = BIO_new(BIO_s_file())) != NULL)
+ {
+ if (BIO_read_filename(key,file) > 0)
+ {
+ switch (format)
+ {
+ case OPENSSL_FORMAT_ASN1 :
+ pkey = d2i_PrivateKey_bio(key, NULL);
+ break;
+
+ case OPENSSL_FORMAT_PEM :
+ pkey = PEM_read_bio_PrivateKey(key, NULL, (pem_password_cb *)_password_callback, (void *)pass);
+ break;
+
+ case OPENSSL_FORMAT_PKCS12 :
+ if (_load_pkcs12(key, pass, &pkey, NULL, NULL) == false)
+ {
+ DEBUG_ERR_MSG("_load_pkcs12 failed");
+ }
+ break;
+
+ case OPENSSL_FORMAT_MSBLOB :
+ pkey = b2i_PrivateKey_bio(key);
+ break;
+
+ case OPENSSL_FORMAT_PVK :
+ pkey = b2i_PVK_bio(key, (pem_password_cb *)_password_callback, (void *)pass);
+ break;
+
+ default :
+ DEBUG_ERR_MSG("bad input format specified for key file");
+ break;
+ }
+ }
+ else
+ {
+ DEBUG_ERR_MSG("Error opening %s", file);
+ }
+
+ BIO_free(key);
+ }
+ else
+ {
+ DEBUG_ERR_MSG("BIO_new failed");
+ }
+ }
+
+ return pkey;
+}
+
+EVP_PKEY *_load_pubkey(const char *file, int format, const char *pass, ENGINE *e, const char *key_descrip)
+{
+ BIO *key = NULL;
+ EVP_PKEY *pkey = NULL;
+
+ if (file == NULL)
+ {
+ DEBUG_ERR_MSG("no keyfile specified");
+ return pkey;
+ }
+
+ if (format == OPENSSL_FORMAT_ENGINE)
+ {
+ if (e != NULL)
+ {
+ pkey = ENGINE_load_public_key(e, file, NULL/*ui_method*/, (void *)pass);
+ }
+ else
+ {
+ DEBUG_ERR_MSG("no engine specified");
+ }
+ }
+ else
+ {
+ if ((key = BIO_new(BIO_s_file())) != NULL)
+ {
+ if (BIO_read_filename(key,file) <= 0)
+ {
+ switch (format)
+ {
+ case OPENSSL_FORMAT_ASN1 :
+ pkey = d2i_PUBKEY_bio(key, NULL);
+ break;
+
+ case OPENSSL_FORMAT_ASN1RSA :
+ {
+ RSA *rsa;
+ rsa = d2i_RSAPublicKey_bio(key, NULL);
+ if (rsa)
+ {
+ pkey = EVP_PKEY_new();
+ if (pkey)
+ EVP_PKEY_set1_RSA(pkey, rsa);
+ RSA_free(rsa);
+ }
+ else
+ pkey = NULL;
+ }
+ break;
+
+ case OPENSSL_FORMAT_PEMRSA :
+ {
+ RSA *rsa;
+ rsa = PEM_read_bio_RSAPublicKey(key, NULL, (pem_password_cb *)_password_callback, (void *)pass);
+ if (rsa)
+ {
+ pkey = EVP_PKEY_new();
+ if (pkey)
+ EVP_PKEY_set1_RSA(pkey, rsa);
+ RSA_free(rsa);
+ }
+ else
+ pkey = NULL;
+ }
+ break;
+
+ case OPENSSL_FORMAT_PEM :
+ pkey = PEM_read_bio_PUBKEY(key, NULL, (pem_password_cb *)_password_callback, (void *)pass);
+ break;
+
+ case OPENSSL_FORMAT_MSBLOB :
+ pkey = b2i_PublicKey_bio(key);
+ break;
+
+ default :
+ DEBUG_ERR_MSG("bad input format specified for key file");
+ break;
+ }
+ }
+ else
+ {
+ DEBUG_ERR_MSG("Error opening %s %s", key_descrip, file);
+ }
+
+ BIO_free(key);
+ }
+ else
+ {
+ DEBUG_ERR_MSG("BIO_new failed");
+ }
+ }
+
+ return pkey;
+}
+
+int net_nfc_util_openssl_sign_buffer(uint32_t type, uint8_t *buffer, uint32_t length, char *key_file, char *password, uint8_t *sign, uint32_t *sign_len)
+{
+ int result = 0;
+ const EVP_MD *md = NULL;
+ ENGINE *engine;
+ EVP_PKEY *pkey;
+
+ OpenSSL_add_all_algorithms();
+
+ /* md context */
+ EVP_MD_CTX ctx = { 0, };
+ EVP_PKEY_CTX *pctx = NULL;
+
+ switch (type)
+ {
+ case 0 :
+ result = 0;
+ return result;
+
+ /* RSASSA-PSS, RSASSA-PKCS1-v1_5 */
+ case 1 :
+ case 2 :
+ /* md */
+ md = EVP_get_digestbyname("sha1");
+
+ /* engine */
+ engine = ENGINE_get_default_RSA();
+ break;
+
+ /* DSA */
+ case 3 :
+ /* md */
+ //md = EVP_get_digestbyname("sha1");
+ /* engine */
+ engine = ENGINE_get_default_DSA();
+ break;
+
+ /* ECDSA */
+ case 4 :
+ /* md */
+ md = EVP_get_digestbyname("sha1");
+
+ /* engine */
+ engine = ENGINE_get_default_ECDSA();
+ break;
+
+ default :
+ result = -1;
+ return result;
+ }
+
+ /* pkey */
+ pkey = _load_key(key_file, OPENSSL_FORMAT_PKCS12, password, NULL);
+
+ EVP_DigestSignInit(&ctx, &pctx, md, engine, pkey);
+ EVP_DigestSignUpdate(&ctx, buffer, length);
+ EVP_DigestSignFinal(&ctx, sign, sign_len);
+
+ return result;
+}
+
+int net_nfc_util_openssl_verify_signature(uint32_t type, uint8_t *buffer, uint32_t length, uint8_t *cert, uint32_t cert_len, uint8_t *sign, uint32_t sign_len)
+{
+ int result = 0;
+ const EVP_MD *md = NULL;
+ ENGINE *engine;
+ EVP_PKEY *pkey;
+
+ OpenSSL_add_all_algorithms();
+
+ /* md context */
+ EVP_MD_CTX ctx = { 0, };
+ EVP_PKEY_CTX *pctx = NULL;
+
+ switch (type)
+ {
+ case 0 :
+ result = 0;
+ return result;
+
+ /* RSASSA-PSS, RSASSA-PKCS1-v1_5 */
+ case 1 :
+ case 2 :
+ /* md */
+ md = EVP_get_digestbyname("sha1");
+
+ /* engine */
+ engine = ENGINE_get_default_RSA();
+ break;
+
+ /* DSA */
+ case 3 :
+ /* md */
+ //md = EVP_get_digestbyname("sha1");
+ /* engine */
+ engine = ENGINE_get_default_DSA();
+ break;
+
+ /* ECDSA */
+ case 4 :
+ /* md */
+ md = EVP_get_digestbyname("sha1");
+
+ /* engine */
+ engine = ENGINE_get_default_ECDSA();
+ break;
+
+ default :
+ result = -1;
+ return result;
+ }
+
+ /* pkey */
+ X509 *x509 = _load_certificate_from_mem(0, cert, cert_len, NULL);
+ pkey = X509_PUBKEY_get(X509_get_X509_PUBKEY(x509));
+ X509_free(x509);
+
+ EVP_DigestVerifyInit(&ctx, &pctx, md, engine, pkey);
+ EVP_DigestVerifyUpdate(&ctx, buffer, length);
+ result = EVP_DigestVerifyFinal(&ctx, sign, sign_len);
+
+ DEBUG_MSG("EVP_DigestVerifyFinal returns %d", result);
+
+ return result;
+}
+
+#if 0
+int net_nfc_util_get_cert_list_from_file(char *file_name, char *password, uint8_t **buffer, uint32_t *length, uint32_t *cert_count)
+{
+ int result = 0;
+ BIO *bio = NULL;
+
+ bio = BIO_new(BIO_s_file());
+ if (bio != NULL)
+ {
+ if (BIO_read_filename(bio, file_name) > 0)
+ {
+ STACK_OF(X509_INFO) *xis = NULL;
+
+ if ((xis = PEM_X509_INFO_read_bio(bio, NULL, (pem_password_cb *)_password_callback, password)) != NULL)
+ {
+ X509_INFO *xi;
+ int i;
+ uint32_t temp_len = 0;
+ uint8_t *temp_buf = NULL;
+ uint32_t offset = 0;
+ uint32_t count = 0;
+
+ for (i = 0; i < sk_X509_INFO_num(xis); i++)
+ {
+ xi = sk_X509_INFO_value(xis, i);
+ if (xi->x509)
+ {
+ int32_t ret = 0;
+
+ if ((ret = i2d_X509(xi->x509, NULL)) > 0)
+ {
+ temp_len += (ret + 2);
+ }
+ }
+ }
+
+ DEBUG_MSG("count = %d, length = %d", sk_X509_INFO_num(xis), temp_len);
+ *length = temp_len;
+ _net_nfc_util_alloc_mem(*buffer, temp_len);
+
+ for (i = 0; i < sk_X509_INFO_num(xis); i++)
+ {
+ xi = sk_X509_INFO_value(xis, i);
+ if (xi->x509)
+ {
+ temp_buf = NULL;
+
+ if ((temp_len = i2d_X509(xi->x509, &temp_buf)) > 0)
+ {
+ *(uint16_t *)(*buffer + offset) = temp_len;
+ offset += sizeof(uint16_t);
+
+ memcpy(*buffer + offset, temp_buf, temp_len);
+ offset += temp_len;
+
+ count++;
+ }
+ }
+ }
+
+ *cert_count = count;
+
+ sk_X509_INFO_pop_free(xis, X509_INFO_free);
+ }
+ else
+ {
+ DEBUG_ERR_MSG("PEM_X509_INFO_read_bio failed");
+ }
+ }
+
+ BIO_free(bio);
+ }
+
+ return result;
+}
+#endif
+
+/* TODO : DER?? PEM?? */
+int net_nfc_util_get_cert_list_from_file(char *file_name, char *password, uint8_t **buffer, uint32_t *length, uint32_t *cert_count)
+{
+ int result = 0;
+ BIO *bio = NULL;
+
+ bio = BIO_new(BIO_s_file());
+ if (bio != NULL)
+ {
+ if (BIO_read_filename(bio, file_name) > 0)
+ {
+ EVP_PKEY *pkey = NULL;
+ X509 *x509 = NULL;
+ STACK_OF(X509) *ca = NULL;
+
+ if (_load_pkcs12(bio, password, &pkey, &x509, &ca) != 0)
+ {
+ X509 *temp_x509;
+ int i;
+ uint32_t temp_len = 0;
+ uint8_t *temp_buf = NULL;
+ uint32_t offset = 0;
+ uint32_t count = 0;
+ int32_t ret = 0;
+
+ if ((ret = i2d_X509(x509, NULL)) > 0)
+ {
+ temp_len += (ret + 2);
+ }
+
+ for (i = 0; i < sk_X509_num(ca); i++)
+ {
+ temp_x509 = sk_X509_value(ca, i);
+ if (temp_x509)
+ {
+ if ((ret = i2d_X509(temp_x509, NULL)) > 0)
+ {
+ temp_len += (ret + 2);
+ }
+ }
+ }
+
+ DEBUG_MSG("count = %d, length = %d", sk_X509_num(ca) + 1, temp_len);
+ *length = temp_len;
+ _net_nfc_util_alloc_mem(*buffer, temp_len);
+
+ if ((temp_len = i2d_X509(x509, &temp_buf)) > 0)
+ {
+ *(uint16_t *)(*buffer + offset) = temp_len;
+ offset += sizeof(uint16_t);
+
+ memcpy(*buffer + offset, temp_buf, temp_len);
+ offset += temp_len;
+
+ count++;
+ }
+
+ for (i = 0; i < sk_X509_num(ca); i++)
+ {
+ temp_x509 = sk_X509_value(ca, i);
+ if (temp_x509)
+ {
+ temp_buf = NULL;
+
+ if ((temp_len = i2d_X509(temp_x509, &temp_buf)) > 0)
+ {
+ *(uint16_t *)(*buffer + offset) = temp_len;
+ offset += sizeof(uint16_t);
+
+ memcpy(*buffer + offset, temp_buf, temp_len);
+ offset += temp_len;
+
+ count++;
+ }
+ }
+ }
+
+ *cert_count = count;
+
+ sk_X509_pop_free(ca, X509_free);
+ }
+ else
+ {
+ DEBUG_ERR_MSG("PEM_X509_INFO_read_bio failed");
+ }
+ }
+
+ BIO_free(bio);
+ }
+
+ return result;
+}
+
+bool net_nfc_util_openssl_encode_base64(const uint8_t *buffer, const uint32_t buf_len, char *result, uint32_t max_len, bool new_line_char)
+{
+ bool ret = false;
+ BUF_MEM *bptr;
+ BIO *b64, *bmem;
+
+ if (buffer == NULL || buf_len == 0)
+ {
+ return ret;
+ }
+
+ b64 = BIO_new(BIO_f_base64());
+ bmem = BIO_new(BIO_s_mem());
+
+ if (new_line_char == false)
+ BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL);
+
+ b64 = BIO_push(b64, bmem);
+
+ BIO_write(b64, buffer, buf_len);
+ BIO_flush(b64);
+ BIO_get_mem_ptr(b64, &bptr);
+
+ if (max_len >= bptr->length)
+ {
+ memcpy(result, bptr->data, bptr->length);
+ result[bptr->length] = 0;
+ ret = true;
+ }
+ else
+ {
+ DEBUG_ERR_MSG("not enough result buffer");
+ }
+
+ BIO_free_all(b64);
+
+ return ret;
+}
+
+bool net_nfc_util_openssl_decode_base64(const char *buffer, uint8_t *result, uint32_t *out_len, bool new_line_char)
+{
+ bool ret = false;
+ unsigned int length = 0;
+ char *temp;
+
+ if (buffer == NULL || (length = strlen(buffer)) == 0)
+ {
+ return ret;
+ }
+
+ _net_nfc_util_alloc_mem(temp, length);
+ if (temp != NULL)
+ {
+ BIO *b64, *bmem;
+
+ b64 = BIO_new(BIO_f_base64());
+ bmem = BIO_new_mem_buf((void *)buffer, length);
+ if (new_line_char == false)
+ BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL);
+ bmem = BIO_push(b64, bmem);
+
+ length = BIO_read(bmem, temp, length);
+
+ BIO_free_all(bmem);
+
+ if (*out_len > length)
+ {
+ *out_len = length;
+ memcpy(result, temp, *out_len);
+ ret = true;
+ }
+ else
+ {
+ DEBUG_ERR_MSG("not enough result buffer");
+ }
+
+ _net_nfc_util_free_mem(temp);
+ }
+ else
+ {
+ DEBUG_ERR_MSG("alloc failed");
+ }
+
+ return ret;
+}
+
+bool net_nfc_util_openssl_digest(const char *algorithm, const uint8_t *buffer, const uint32_t buf_len, uint8_t *result, uint32_t *out_len)
+{
+ const EVP_MD *md;
+ unsigned char *temp;
+ bool ret = false;
+
+ if (algorithm == NULL || buffer == NULL || buf_len == 0)
+ {
+ return ret;
+ }
+
+ OpenSSL_add_all_digests();
+
+ if ((md = EVP_get_digestbyname(algorithm)) != NULL)
+ {
+ _net_nfc_util_alloc_mem(temp, EVP_MAX_MD_SIZE);
+ if (temp != NULL)
+ {
+ EVP_MD_CTX mdCtx;
+ unsigned int resultLen = 0;
+
+ memset(temp, 0, EVP_MAX_MD_SIZE);
+
+ EVP_DigestInit(&mdCtx, md);
+ if (EVP_DigestUpdate(&mdCtx, buffer, buf_len) != 0)
+ {
+ DEBUG_ERR_MSG("EVP_DigestUpdate failed");
+ }
+ EVP_DigestFinal(&mdCtx, temp, &resultLen);
+
+ if (*out_len >= resultLen)
+ {
+ *out_len = resultLen;
+ memcpy(result, temp, *out_len);
+ ret = true;
+ }
+ else
+ {
+ DEBUG_ERR_MSG("not enough result buffer");
+ }
+
+ _net_nfc_util_free_mem(temp);
+ }
+ else
+ {
+ DEBUG_ERR_MSG("alloc failed");
+ }
+ }
+ else
+ {
+ DEBUG_ERR_MSG("EVP_get_digestbyname(\"%s\") returns NULL", algorithm);
+ }
+
+ return ret;
+}
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_UTIL_OPENSSL_INTERNAL_H__
+#define __NET_NFC_UTIL_OPENSSL_INTERNAL_H__
+
+#include <openssl/x509.h>
+
+enum
+{
+ OPENSSL_FORMAT_UNDEF,
+ OPENSSL_FORMAT_ASN1,
+ OPENSSL_FORMAT_TEXT,
+ OPENSSL_FORMAT_PEM,
+ OPENSSL_FORMAT_NETSCAPE,
+ OPENSSL_FORMAT_PKCS12,
+ OPENSSL_FORMAT_SMIME,
+ OPENSSL_FORMAT_ENGINE,
+ OPENSSL_FORMAT_IISSGC,
+ OPENSSL_FORMAT_PEMRSA,
+ OPENSSL_FORMAT_ASN1RSA,
+ OPENSSL_FORMAT_MSBLOB,
+ OPENSSL_FORMAT_PVK,
+};
+
+typedef struct _net_nfc_openssl_verify_context_s
+{
+ X509 *signer_cert;
+ X509_STORE *store;
+ X509_STORE_CTX *store_ctx;
+}
+net_nfc_openssl_verify_context_s;
+
+typedef net_nfc_openssl_verify_context_s *net_nfc_openssl_verify_context_h;
+
+net_nfc_openssl_verify_context_h net_nfc_util_openssl_init_verify_certificate(void);
+bool net_nfc_util_openssl_add_certificate_of_signer(net_nfc_openssl_verify_context_h context, uint8_t *buffer, uint32_t length);
+bool net_nfc_util_openssl_add_certificate_of_ca(net_nfc_openssl_verify_context_h context, uint8_t *buffer, uint32_t length);
+int net_nfc_util_openssl_verify_certificate(net_nfc_openssl_verify_context_h context);
+void net_nfc_util_openssl_release_verify_certificate(net_nfc_openssl_verify_context_h context);
+
+int net_nfc_util_openssl_sign_buffer(uint32_t type, uint8_t *buffer, uint32_t length, char *key_file, char *password, uint8_t *sign, uint32_t *sign_len);
+int net_nfc_util_openssl_verify_signature(uint32_t type, uint8_t *buffer, uint32_t length, uint8_t *cert, uint32_t cert_len, uint8_t *sign, uint32_t sign_len);
+int net_nfc_util_get_cert_list_from_file(char *file_name, char *password, uint8_t **buffer, uint32_t *length, uint32_t *cert_count);
+
+
+bool net_nfc_util_openssl_encode_base64(const uint8_t *buffer, const uint32_t buf_len, char *result, uint32_t max_len, bool new_line_char);
+bool net_nfc_util_openssl_decode_base64(const char *buffer, uint8_t *result, uint32_t *out_len, bool new_line_char);
+bool net_nfc_util_openssl_digest(const char *algorithm, const uint8_t *buffer, const uint32_t buf_len, uint8_t *result, uint32_t *out_len);
+
+#endif //__NET_NFC_UTIL_OPENSSL_INTERNAL_H__
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#include <sys/param.h>
+
+#include "net_nfc_debug_internal.h"
+#include "net_nfc_util_defines.h"
+#include "net_nfc_util_internal.h"
+#include "net_nfc_util_ndef_message.h"
+#include "net_nfc_util_ndef_record.h"
+#include "net_nfc_util_openssl_internal.h"
+#include "net_nfc_util_sign_record.h"
+
+#define IS_SIGN_RECORD(__x) \
+ (((__x)->TNF == NET_NFC_RECORD_WELL_KNOWN_TYPE) && \
+ ((__x)->type_s.length == 3) && \
+ (memcmp((__x)->type_s.buffer, "Sig", 3) == 0))
+
+#define IS_EMPTY_RECORD(__x) \
+ ((__x->TNF == NET_NFC_RECORD_EMPTY))
+
+#define __FILL_SUB_FIELD(__dst, __buf, __len) \
+ (__dst)->length = (__len); \
+ memcpy((__dst)->value, (__buf), (__dst)->length);
+
+#define __NEXT_SUB_FIELD(__dst) ((__dst)->value + (__dst)->length)
+
+bool _get_records_data_buffer(ndef_record_s *begin_record, ndef_record_s *end_record, uint8_t **buffer, uint32_t *length)
+{
+ bool result = false;
+ uint32_t len = 0;
+ ndef_record_s *current_record = NULL;
+
+ if (begin_record == NULL || begin_record == end_record)
+ return result;
+
+ /* count total buffer length */
+ current_record = begin_record;
+ len = 0;
+
+ while (current_record != NULL && current_record != end_record)
+ {
+ /* type length */
+ if (current_record->type_s.buffer != NULL && current_record->type_s.length > 0)
+ len += current_record->type_s.length;
+
+ /* ID length */
+ if (current_record->id_s.buffer != NULL && current_record->id_s.length > 0)
+ len += current_record->id_s.length;
+
+ /* payload length */
+ if (current_record->payload_s.buffer != NULL && current_record->payload_s.length > 0)
+ len += current_record->payload_s.length;
+
+ current_record = current_record->next;
+ }
+
+ if (len > 0)
+ {
+ uint8_t *buf = NULL;
+
+ _net_nfc_util_alloc_mem(buf, len);
+ if (buf != NULL)
+ {
+ uint32_t offset = 0;
+
+ current_record = begin_record;
+
+ while (offset < len && current_record != NULL && current_record != end_record)
+ {
+ /* type length */
+ if (current_record->type_s.buffer != NULL && current_record->type_s.length > 0)
+ {
+ memcpy(buf + offset, current_record->type_s.buffer, MIN(current_record->type_s.length, len - offset));
+ offset += MIN(current_record->type_s.length, len - offset);
+ }
+
+ /* ID length */
+ if (current_record->id_s.buffer != NULL && current_record->id_s.length > 0)
+ {
+ memcpy(buf + offset, current_record->id_s.buffer, MIN(current_record->id_s.length, len - offset));
+ offset += MIN(current_record->id_s.length, len - offset);
+ }
+
+ /* payload length */
+ if (current_record->payload_s.buffer != NULL && current_record->payload_s.length > 0)
+ {
+ memcpy(buf + offset, current_record->payload_s.buffer, MIN(current_record->payload_s.length, len - offset));
+ offset += MIN(current_record->payload_s.length, len - offset);
+ }
+
+ current_record = current_record->next;
+ }
+
+ *buffer = buf;
+ *length = offset;
+
+ result = true;
+ }
+ }
+
+ return result;
+}
+
+net_nfc_error_e net_nfc_util_verify_signature_records(ndef_record_s *begin_record, ndef_record_s *sign_record)
+{
+ net_nfc_error_e result = NET_NFC_UNKNOWN_ERROR;
+ uint8_t *buffer = NULL;
+ uint32_t length = 0;
+
+ if (begin_record == NULL || sign_record == NULL || begin_record == sign_record)
+ return NET_NFC_INVALID_PARAM;
+
+ /* get signed data */
+ if (_get_records_data_buffer(begin_record, sign_record, &buffer, &length) == true)
+ {
+ uint8_t *signature = NULL;
+ uint32_t sign_len = 0;
+ net_nfc_signature_record_s *sign_info = NULL;
+ net_nfc_certificate_chain_s *chain_info = NULL;
+
+ /* parse signature info */
+ sign_info = (net_nfc_signature_record_s *)sign_record->payload_s.buffer;
+
+ DEBUG_MSG("record version : %d", sign_info->version);
+ DEBUG_MSG("signature URI present? : %s", sign_info->uri_present ? "true" : "false");
+ DEBUG_MSG("signature type : %d", sign_info->sign_type);
+ DEBUG_MSG("signature length : %d", sign_info->signature.length);
+
+ if (sign_info->uri_present == true)
+ {
+ /* TODO */
+ /* receive the signature data directed by uri */
+ DEBUG_ERR_MSG("NOT IMPLEMENTED (sign_info->uri_present == true)");
+ _net_nfc_util_free_mem(buffer);
+ return result;
+ }
+ else
+ {
+ signature = sign_info->signature.value;
+ sign_len = sign_info->signature.length;
+ }
+
+ /* parse certificate chain info */
+ chain_info = (net_nfc_certificate_chain_s *)__NEXT_SUB_FIELD(&(sign_info->signature));
+
+ SECURE_LOGD("certificate URI present? : %s", chain_info->uri_present ? "true" : "false");
+ DEBUG_MSG("certificate format : %d", chain_info->cert_format);
+ DEBUG_MSG("number of certificates : %d", chain_info->num_of_certs);
+
+ if (chain_info->num_of_certs > 0)
+ {
+ net_nfc_sub_field_s *data_info = NULL;
+
+ data_info = (net_nfc_sub_field_s *)chain_info->cert_store;
+ DEBUG_MSG("certficate length : %d", data_info->length);
+
+ // DEBUG_MSG_PRINT_BUFFER(data_info->value, data_info->length);
+
+ /* the first certificate is signer's one
+ * verify signature of content */
+ if (net_nfc_util_openssl_verify_signature(sign_info->sign_type, buffer, length, data_info->value, data_info->length, sign_info->signature.value, sign_info->signature.length) == true)
+ {
+ if (chain_info->num_of_certs > 1)
+ {
+ int32_t i = 0;
+ net_nfc_openssl_verify_context_h context = NULL;
+
+ /* initialize context of verifying certificate */
+ context = net_nfc_util_openssl_init_verify_certificate();
+
+ /* add signer's certificate */
+ net_nfc_util_openssl_add_certificate_of_signer(context, data_info->value, data_info->length);
+
+ /* verify certificate using certificate chain */
+ for (i = 1, data_info = (net_nfc_sub_field_s *)__NEXT_SUB_FIELD(data_info);
+ i < chain_info->num_of_certs;
+ i++, data_info = (net_nfc_sub_field_s *)__NEXT_SUB_FIELD(data_info))
+ {
+ DEBUG_MSG("certficate length : %d", data_info->length);
+ //DEBUG_MSG_PRINT_BUFFER(data_info->value, data_info->length);
+
+ net_nfc_util_openssl_add_certificate_of_ca(context, data_info->value, data_info->length);
+ }
+
+ /* if the CA_Uri is present, continue adding certificate from uri */
+ if (chain_info->uri_present == true)
+ {
+ /* TODO : Need to implement */
+ DEBUG_ERR_MSG("NOT IMPLEMENTED (found_root == false && chain_info->uri_present == true)");
+ net_nfc_util_openssl_release_verify_certificate(context);
+ _net_nfc_util_free_mem(buffer);
+ return result;
+
+ //DEBUG_MSG("certficate length : %d", data_info->length);
+ //DEBUG_MSG_PRINT_BUFFER(data_info->value, data_info->length);
+ }
+
+ /* verify buffer with cert chain and signature bytes */
+ if (net_nfc_util_openssl_verify_certificate(context) == true)
+ result = NET_NFC_OK;
+
+ net_nfc_util_openssl_release_verify_certificate(context);
+ }
+ else
+ {
+ /* TODO : test certificate??? */
+ result = NET_NFC_OK;
+ }
+
+ DEBUG_MSG("verifying signature %d", result);
+ }
+ else
+ {
+ DEBUG_ERR_MSG("verifying signature failed");
+ }
+ }
+ else
+ {
+ DEBUG_ERR_MSG("certificate not found");
+ }
+
+ _net_nfc_util_free_mem(buffer);
+ }
+ else
+ {
+ if(buffer != NULL)
+ {
+ _net_nfc_util_free_mem(buffer);
+ }
+ DEBUG_ERR_MSG("_get_records_data_buffer failed");
+ }
+
+ return result;
+}
+
+net_nfc_error_e net_nfc_util_verify_signature_ndef_message(ndef_message_s *msg)
+{
+ net_nfc_error_e result = NET_NFC_UNKNOWN_ERROR;
+ ndef_record_s *begin_record = NULL;
+ ndef_record_s *current_record = NULL;
+
+ begin_record = msg->records;
+ current_record = msg->records;
+
+ while (current_record != NULL)
+ {
+ if (begin_record == NULL)
+ {
+ begin_record = current_record;
+ }
+
+ if (IS_EMPTY_RECORD(current_record))
+ {
+ begin_record = NULL;
+ }
+ else if (IS_SIGN_RECORD(current_record))
+ {
+ result = net_nfc_util_verify_signature_records(begin_record, current_record);
+
+ begin_record = NULL;
+ }
+
+ current_record = current_record->next;
+ }
+
+ return result;
+}
+
+/*
+ * sign method
+ */
+net_nfc_error_e net_nfc_util_sign_records(ndef_message_s *msg, int begin_index, int end_index, char *cert_file, char *password)
+{
+ net_nfc_error_e result = NET_NFC_UNKNOWN_ERROR;
+ ndef_record_s *begin_record = NULL, *end_record = NULL, *record = NULL;
+ data_s payload = { NULL, 0 };
+ uint8_t *data_buffer = NULL;
+ uint32_t data_len = 0;
+ uint8_t signature[1024] = { 0, };
+ uint32_t sign_len = sizeof(signature);
+ uint8_t *cert_buffer = NULL;
+ uint32_t cert_len = 0;
+ uint32_t cert_count = 0;
+
+ net_nfc_util_get_record_by_index(msg, begin_index, &begin_record);
+ net_nfc_util_get_record_by_index(msg, end_index, &end_record);
+
+ DEBUG_MSG("total record count : %d, begin_index : %d, end_index : %d", msg->recordCount, begin_index, end_index);
+
+ /* get target data */
+ _get_records_data_buffer(begin_record, end_record->next, &data_buffer, &data_len);
+
+ DEBUG_MSG_PRINT_BUFFER(data_buffer, data_len);
+
+ net_nfc_util_openssl_sign_buffer(NET_NFC_SIGN_TYPE_PKCS_1, data_buffer, data_len, cert_file, password, signature, &sign_len);
+
+ /* get cert chain */
+ net_nfc_util_get_cert_list_from_file(cert_file, password, &cert_buffer, &cert_len, &cert_count);
+
+ /* create payload */
+ payload.length = sizeof(net_nfc_signature_record_s) + sign_len + sizeof(net_nfc_certificate_chain_s) + cert_len;
+
+ _net_nfc_util_alloc_mem(payload.buffer, payload.length);
+
+ net_nfc_signature_record_s *sign_record = (net_nfc_signature_record_s *)payload.buffer;
+ sign_record->version = 1;
+ sign_record->uri_present = 0;
+ sign_record->sign_type = NET_NFC_SIGN_TYPE_PKCS_1;
+
+ if (sign_record->uri_present)
+ {
+ /* TODO */
+ }
+ else
+ {
+ __FILL_SUB_FIELD(&(sign_record->signature), signature, sign_len);
+ }
+
+ net_nfc_certificate_chain_s *chain = (net_nfc_certificate_chain_s *)__NEXT_SUB_FIELD(&(sign_record->signature));
+ if (cert_count < 16)
+ {
+ chain->uri_present = 0;
+ }
+ else
+ {
+ chain->uri_present = 1;
+ }
+
+ chain->cert_format = NET_NFC_CERT_FORMAT_X_509;
+ chain->num_of_certs = cert_count;
+ memcpy(chain->cert_store, cert_buffer, cert_len);
+
+ if (chain->uri_present)
+ {
+ /* TODO */
+ DEBUG_ERR_MSG("num_of_certs is greater than 15 [%d]", cert_count);
+ }
+
+ /* create record */
+ data_s type = { (uint8_t *)"Sig", 3 };
+
+ net_nfc_util_create_record(NET_NFC_RECORD_WELL_KNOWN_TYPE, &type, NULL, &payload, &record);
+
+ /* get last record index */
+ net_nfc_util_append_record_by_index(msg, end_index + 1, record);
+
+ _net_nfc_util_free_mem(payload.buffer);
+ _net_nfc_util_free_mem(cert_buffer);
+ _net_nfc_util_free_mem(data_buffer);
+
+ return result;
+}
+
+net_nfc_error_e net_nfc_util_sign_ndef_message(ndef_message_s *msg, char *cert_file, char *password)
+{
+ net_nfc_error_e result = NET_NFC_UNKNOWN_ERROR;
+
+ if (msg->recordCount > 0)
+ {
+ net_nfc_util_sign_records(msg, 0, msg->recordCount - 1, cert_file, password);
+
+ result = NET_NFC_OK;
+ }
+
+ return result;
+}
--- /dev/null
+prefix=@PREFIX@
+exec_prefix=${prefix}/bin
+libdir=@LIB_INSTALL_DIR@
+includedir=@INCLUDE_INSTALL_DIR@/@NFC_COMMON@
+
+Name: @NFC_COMMON@
+Description: NFC Common Library
+Version: @FULLVER@
+Requires:
+Libs: -L${libdir} -l@NFC_COMMON@
+Cflags: -I${includedir}
--- /dev/null
+LINK_DIRECTORIES(${CMAKE_BINARY_DIR})
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/common/)
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/common/include)
+
+SET(NFC_DAEMON "nfc-manager-daemon")
+
+FILE(GLOB DAEMON_SRCS *.c)
+
+pkg_check_modules(daemon_pkgs REQUIRED aul glib-2.0 gio-unix-2.0 security-server
+ vconf dlog tapi appsvc libcurl bluetooth-api libssl svi capi-media-wav-player
+ pkgmgr pkgmgr-info capi-network-wifi ecore-x pmapi)
+
+FOREACH(flag ${daemon_pkgs_CFLAGS})
+ SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+
+ADD_EXECUTABLE(${NFC_DAEMON} ${DAEMON_SRCS})
+TARGET_LINK_LIBRARIES(${NFC_DAEMON} ${daemon_pkgs_LDFLAGS} pthread dl rt nfc-common)
+
+INSTALL(TARGETS ${NFC_DAEMON} DESTINATION bin)
+
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/org.tizen.NetNfcService.service DESTINATION share/dbus-1/services)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/nfc-manager.xml DESTINATION share/packages)
+INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/sounds DESTINATION share/nfc-manager-daemon)
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include <glib.h>
+#include <gio/gio.h>
+#include <vconf.h>
+
+#include "net_nfc_debug_internal.h"
+#include "net_nfc_util_internal.h"
+#include "net_nfc_gdbus.h"
+#include "net_nfc_server.h"
+#include "net_nfc_server_common.h"
+#include "net_nfc_server_vconf.h"
+#include "net_nfc_server_manager.h"
+#include "net_nfc_server_util.h"
+#include "net_nfc_server_controller.h"
+#include "net_nfc_server_tag.h"
+#include "net_nfc_server_ndef.h"
+#include "net_nfc_server_llcp.h"
+#include "net_nfc_server_p2p.h"
+#include "net_nfc_server_transceive.h"
+#include "net_nfc_server_test.h"
+#include "net_nfc_server_handover.h"
+#include "net_nfc_server_se.h"
+#include "net_nfc_server_snep.h"
+#include "net_nfc_server_system_handler.h"
+#include "net_nfc_server_context.h"
+
+static gboolean use_daemon = FALSE;
+static GMainLoop *loop = NULL;
+
+static GDBusConnection *connection = NULL;
+static guint subscribe_id;
+
+GOptionEntry option_entries[] = {
+ { "daemon", 'd', 0, G_OPTION_ARG_NONE, &use_daemon,
+ "Use Daemon mode", NULL },
+ { NULL }
+};
+
+pid_t net_nfc_server_gdbus_get_pid(const char *name)
+{
+ guint pid = 0;
+ GError *error = NULL;
+ GVariant *_ret;
+
+ _ret = g_dbus_connection_call_sync(connection,
+ "org.freedesktop.DBus",
+ "/org/freedesktop/DBus",
+ "org.freedesktop.DBus",
+ "GetConnectionUnixProcessID",
+ g_variant_new("(s)", name),
+ NULL,
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ &error);
+ if (_ret != NULL) {
+ g_variant_get(_ret, "(u)", &pid);
+ g_variant_unref(_ret);
+ }
+
+ return pid;
+}
+
+static void _name_owner_changed(GDBusProxy *proxy,
+ const gchar *name, const gchar *old_owner,
+ const gchar *new_owner, void *user_data)
+{
+ if (name == NULL || old_owner == NULL || new_owner == NULL) {
+ DEBUG_ERR_MSG("invalid parameter");
+
+ return;
+ }
+
+ if (strlen(new_owner) == 0) {
+ if (net_nfc_server_gdbus_check_client_is_running(old_owner)) {
+ /* unregister service */
+ net_nfc_server_llcp_unregister_services(old_owner);
+
+ /* remove client context */
+ net_nfc_server_gdbus_cleanup_client_context(old_owner);
+ }
+ }
+}
+
+static void _on_name_owner_changed(GDBusConnection *connection,
+ const gchar *sender_name, const gchar *object_path,
+ const gchar *interface_name, const gchar *signal_name,
+ GVariant *parameters, gpointer user_data)
+{
+ gchar *name;
+ gchar *old_owner;
+ gchar *new_owner;
+
+ g_variant_get(parameters,
+ "(sss)",
+ &name,
+ &old_owner,
+ &new_owner);
+
+ _name_owner_changed((GDBusProxy *)connection,
+ name, old_owner, new_owner, user_data);
+}
+
+static void _subscribe_name_owner_changed_event()
+{
+ if (connection == NULL)
+ return;
+
+ /* subscribe signal */
+ subscribe_id = g_dbus_connection_signal_subscribe(connection,
+ "org.freedesktop.DBus", /* bus name */
+ "org.freedesktop.DBus", /* interface */
+ "NameOwnerChanged", /* member */
+ "/org/freedesktop/DBus", /* path */
+ NULL, /* arg0 */
+ G_DBUS_SIGNAL_FLAGS_NONE,
+ _on_name_owner_changed,
+ NULL, NULL);
+}
+
+static void _unsubscribe_name_owner_changed_event()
+{
+ if (connection == NULL)
+ return;
+
+ /* subscribe signal */
+ if (subscribe_id > 0) {
+ g_dbus_connection_signal_unsubscribe(connection, subscribe_id);
+ }
+}
+
+static void net_nfc_server_gdbus_init(void)
+{
+ GError *error = NULL;
+
+ if (connection)
+ g_object_unref(connection);
+
+ connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
+ if (connection == NULL)
+ {
+ DEBUG_ERR_MSG("Can not get connection %s", error->message);
+ g_error_free (error);
+ return;
+ }
+
+ net_nfc_server_gdbus_init_client_context();
+
+ if (net_nfc_server_manager_init(connection) == FALSE)
+ {
+ DEBUG_ERR_MSG("Can not init manager");
+ return;
+ }
+
+ if (net_nfc_server_tag_init(connection) == FALSE)
+ {
+ DEBUG_ERR_MSG("Can not init tag");
+ return;
+ }
+
+ if (net_nfc_server_ndef_init(connection) == FALSE)
+ {
+ DEBUG_ERR_MSG("Can not init ndef");
+ return;
+ }
+
+ if (net_nfc_server_llcp_init(connection) == FALSE)
+ {
+ DEBUG_ERR_MSG("Can not init llcp");
+ return;
+ }
+
+ if (net_nfc_server_p2p_init(connection) == FALSE)
+ {
+ DEBUG_ERR_MSG("Can not init tag");
+ return;
+ }
+
+ if (net_nfc_server_transceive_init(connection) == FALSE)
+ {
+ DEBUG_ERR_MSG("Can not initialize transceive");
+ return;
+ }
+
+ if (net_nfc_server_test_init(connection) == FALSE)
+ {
+ DEBUG_ERR_MSG("Can not init Test");
+ return;
+ }
+
+ if (net_nfc_server_handover_init(connection) == FALSE)
+ {
+ DEBUG_ERR_MSG("Can not initialize transceive");
+ return;
+ }
+
+ if (net_nfc_server_se_init(connection) == FALSE)
+ {
+ DEBUG_ERR_MSG("Can not init Test");
+ return;
+ }
+
+ if (net_nfc_server_snep_init(connection) == FALSE)
+ {
+ DEBUG_ERR_MSG("Can not init controller thread");
+ return;
+ }
+
+ if (net_nfc_server_system_handler_init(connection) == FALSE)
+ {
+ DEBUG_ERR_MSG("Can not init controller thread");
+ return;
+ }
+
+ if (net_nfc_server_controller_thread_init() == FALSE)
+ {
+ DEBUG_ERR_MSG("Can not init controller thread");
+ return;
+ }
+
+ _subscribe_name_owner_changed_event();
+}
+
+static void net_nfc_server_gdbus_deinit(void)
+{
+ _unsubscribe_name_owner_changed_event();
+
+ net_nfc_server_manager_deinit();
+ net_nfc_server_tag_deinit();
+ net_nfc_server_ndef_deinit();
+ net_nfc_server_llcp_deinit();
+ net_nfc_server_transceive_deinit();
+ net_nfc_server_test_deinit();
+ net_nfc_server_handover_deinit();
+ net_nfc_server_se_deinit();
+ net_nfc_server_snep_deinit();
+ net_nfc_server_system_handler_deinit();
+
+ net_nfc_server_gdbus_deinit_client_context();
+
+ net_nfc_server_controller_thread_deinit();
+
+ if (connection)
+ {
+ g_object_unref(connection);
+ connection = NULL;
+ }
+}
+
+void net_nfc_manager_quit()
+{
+ DEBUG_MSG("net_nfc_manager_quit kill the nfc-manager daemon!!");
+
+ if (loop != NULL)
+ g_main_loop_quit(loop);
+}
+
+static void on_bus_acquired(GDBusConnection *connection, const gchar *path,
+ gpointer user_data)
+{
+ gint state;
+
+ DEBUG_MSG("bus path : %s", path);
+
+ net_nfc_server_gdbus_init();
+
+ net_nfc_server_controller_init();
+
+ if (vconf_get_bool(VCONFKEY_NFC_STATE, &state) != 0)
+ {
+ DEBUG_MSG("VCONFKEY_NFC_STATE is not exist");
+ net_nfc_manager_quit();
+
+ return;
+ }
+
+ net_nfc_server_vconf_init();
+
+ if (state == 1)
+ net_nfc_server_manager_set_active(TRUE);
+#ifndef ESE_ALWAYS_ON
+ else if (use_daemon == TRUE)
+ net_nfc_server_controller_deinit();
+#endif
+}
+
+static void on_name_acquired(GDBusConnection *connection, const gchar *name,
+ gpointer user_data)
+{
+ DEBUG_SERVER_MSG("name : %s", name);
+}
+
+static void on_name_lost(GDBusConnection *connnection, const gchar *name,
+ gpointer user_data)
+{
+ DEBUG_SERVER_MSG("name : %s", name);
+
+ net_nfc_manager_quit();
+}
+
+
+int main(int argc, char *argv[])
+{
+
+ void *handle = NULL;
+ guint id = 0;
+ gboolean use_daemon = FALSE;
+ GOptionContext *option_context;
+ GError *error = NULL;
+
+ option_context = g_option_context_new("Nfc manager");
+ g_option_context_add_main_entries(option_context, option_entries, NULL);
+
+ if (g_option_context_parse(option_context, &argc, &argv, &error) == FALSE)
+ {
+ DEBUG_ERR_MSG("can not parse option: %s", error->message);
+ g_error_free(error);
+
+ g_option_context_free(option_context);
+ return 0;
+ }
+
+ DEBUG_SERVER_MSG("start nfc manager");
+ DEBUG_SERVER_MSG("use_daemon : %d", use_daemon);
+
+ net_nfc_manager_init_log();
+
+ net_nfc_app_util_clean_storage(MESSAGE_STORAGE);
+
+ handle = net_nfc_controller_onload();
+ if (handle == NULL)
+ {
+ DEBUG_ERR_MSG("load plugin library is failed");
+
+ if (vconf_set_bool(VCONFKEY_NFC_FEATURE, VCONFKEY_NFC_FEATURE_OFF) != 0)
+ DEBUG_ERR_MSG("VCONFKEY_NFC_FEATURE set to %d failed", VCONFKEY_NFC_FEATURE_OFF);
+
+ if (vconf_set_bool(VCONFKEY_NFC_STATE, 0) != 0)
+ DEBUG_ERR_MSG("VCONFKEY_NFC_STATE set to %d failed", 0);
+
+ goto EXIT;
+ }
+
+ if (vconf_set_bool(VCONFKEY_NFC_FEATURE, VCONFKEY_NFC_FEATURE_ON) != 0)
+ DEBUG_ERR_MSG("VCONFKEY_NFC_FEATURE set to %d failed", VCONFKEY_NFC_FEATURE_ON);
+
+ id = g_bus_own_name(G_BUS_TYPE_SYSTEM,
+ "org.tizen.NetNfcService",
+ G_BUS_NAME_OWNER_FLAGS_NONE,
+ on_bus_acquired,
+ on_name_acquired,
+ on_name_lost,
+ NULL,
+ NULL);
+
+ loop = g_main_loop_new(NULL, FALSE);
+ g_main_loop_run(loop);
+
+EXIT :
+ net_nfc_server_vconf_deinit();
+ net_nfc_server_controller_deinit();
+ net_nfc_server_gdbus_deinit();
+
+ if (id)
+ g_bus_unown_name(id);
+
+ net_nfc_controller_unload(handle);
+
+ net_nfc_manager_fini_log();
+
+ g_option_context_free(option_context);
+
+ return 0;
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_SERVER_H__
+#define __NET_NFC_SERVER_H__
+
+pid_t net_nfc_server_gdbus_get_pid(const char *name);
+
+void net_nfc_manager_quit();
+
+
+#endif //__NET_NFC_SERVER_H__
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <vconf.h>
+
+#include "net_nfc_debug_internal.h"
+#include "net_nfc_util_internal.h"
+#include "net_nfc_server.h"
+#include "net_nfc_server_util.h"
+#include "net_nfc_server_controller.h"
+#include "net_nfc_server_common.h"
+#include "net_nfc_server_tag.h"
+#include "net_nfc_server_llcp.h"
+#include "net_nfc_server_se.h"
+
+
+typedef struct _ControllerFuncData ControllerFuncData;
+
+struct _ControllerFuncData
+{
+ net_nfc_server_controller_func func;
+ gpointer data;
+};
+
+static gpointer controller_thread_func(gpointer user_data);
+
+static void controller_async_queue_free_func(gpointer user_data);
+
+static void controller_thread_deinit_thread_func(gpointer user_data);
+
+static void controller_target_detected_cb(void *info,
+ void *user_context);
+
+static void controller_se_transaction_cb(void *info,
+ void *user_context);
+
+static void controller_llcp_event_cb(void *info,
+ void *user_context);
+
+static void controller_init_thread_func(gpointer user_data);
+
+#ifndef ESE_ALWAYS_ON
+static void controller_deinit_thread_func(gpointer user_data);
+#endif
+
+static void restart_polling_loop_thread_func(gpointer user_data);
+
+static GAsyncQueue *controller_async_queue = NULL;
+
+static GThread *controller_thread = NULL;
+
+static gboolean controller_is_running = FALSE;
+
+static guint32 server_state = NET_NFC_SERVER_IDLE;
+
+
+static gpointer controller_thread_func(gpointer user_data)
+{
+ if (controller_async_queue == NULL)
+ {
+ g_thread_exit(NULL);
+ return NULL;
+ }
+
+ controller_is_running = TRUE;
+ while(controller_is_running)
+ {
+ ControllerFuncData *func_data;
+
+ func_data = g_async_queue_pop(controller_async_queue);
+ if (func_data->func)
+ func_data->func(func_data->data);
+
+ g_free(func_data);
+ }
+
+ g_thread_exit(NULL);
+ return NULL;
+}
+
+static void controller_async_queue_free_func(gpointer user_data)
+{
+ g_free(user_data);
+}
+
+static void controller_thread_deinit_thread_func(gpointer user_data)
+{
+ controller_is_running = FALSE;
+}
+
+/* FIXME: it works as broadcast only now */
+static void controller_target_detected_cb(void *info,
+ void *user_context)
+{
+ net_nfc_request_target_detected_t *req =
+ (net_nfc_request_target_detected_t *)info;
+
+ g_assert(info != NULL);
+
+ if (req->request_type == NET_NFC_MESSAGE_SERVICE_RESTART_POLLING_LOOP)
+ {
+ net_nfc_server_restart_polling_loop();
+ }
+ else
+ {
+ net_nfc_server_set_target_info(info);
+
+ if (req->devType != NET_NFC_UNKNOWN_TARGET) {
+ if (req->devType == NET_NFC_NFCIP1_TARGET ||
+ req->devType == NET_NFC_NFCIP1_INITIATOR) {
+ /* llcp target detected */
+ net_nfc_server_llcp_target_detected(info);
+ } else {
+ /* tag target detected */
+ net_nfc_server_tag_target_detected(info);
+ }
+ }
+
+ /* If target detected, sound should be played. */
+ net_nfc_manager_util_play_sound(NET_NFC_TASK_START);
+ }
+
+ /* FIXME : should be removed when plugins would be fixed*/
+ _net_nfc_util_free_mem(info);
+}
+
+/* FIXME : net_nfc_dispatcher_queue_push() need to be removed */
+static void controller_se_transaction_cb(void *info,
+ void *user_context)
+{
+ net_nfc_request_se_event_t *req = (net_nfc_request_se_event_t *)info;
+
+ g_assert(info != NULL);
+
+ req->user_param = (uint32_t)user_context;
+
+ switch(req->request_type)
+ {
+ case NET_NFC_MESSAGE_SERVICE_SLAVE_ESE_DETECTED :
+ net_nfc_server_se_detected(req);
+ break;
+
+ case NET_NFC_MESSAGE_SE_START_TRANSACTION :
+ net_nfc_server_se_transaction_received(req);
+ break;
+
+ default :
+ break;
+ }
+}
+
+/* FIXME : net_nfc_dispatcher_queue_push() need to be removed */
+static void controller_llcp_event_cb(void *info,
+ void *user_context)
+{
+ net_nfc_request_llcp_msg_t *req_llcp_msg;
+ net_nfc_request_msg_t *req_msg;
+
+ if (info == NULL)
+ {
+ DEBUG_ERR_MSG("can not get llcp_event info");
+ return;
+ }
+
+ req_llcp_msg = (net_nfc_request_llcp_msg_t *)info;
+ req_llcp_msg->user_param = (uint32_t) user_context;
+
+ req_msg = (net_nfc_request_msg_t *)req_llcp_msg;
+
+ switch (req_msg->request_type)
+ {
+ case NET_NFC_MESSAGE_SERVICE_LLCP_DEACTIVATED:
+ net_nfc_server_llcp_deactivated(req_msg);
+ break;
+ case NET_NFC_MESSAGE_SERVICE_LLCP_LISTEN:
+ net_nfc_server_llcp_listen(req_msg);
+ break;
+ case NET_NFC_MESSAGE_SERVICE_LLCP_SOCKET_ERROR:
+ case NET_NFC_MESSAGE_SERVICE_LLCP_SOCKET_ACCEPTED_ERROR:
+ net_nfc_server_llcp_socket_error(req_msg);
+ break;
+ case NET_NFC_MESSAGE_SERVICE_LLCP_SEND:
+ case NET_NFC_MESSAGE_SERVICE_LLCP_SEND_TO:
+ net_nfc_server_llcp_send(req_msg);
+ break;
+ case NET_NFC_MESSAGE_SERVICE_LLCP_RECEIVE:
+ net_nfc_server_llcp_receive(req_msg);
+ break;
+ case NET_NFC_MESSAGE_SERVICE_LLCP_RECEIVE_FROM:
+ net_nfc_server_llcp_receive_from(req_msg);
+ break;
+ case NET_NFC_MESSAGE_SERVICE_LLCP_CONNECT:
+ case NET_NFC_MESSAGE_SERVICE_LLCP_CONNECT_SAP:
+ net_nfc_server_llcp_connect(req_msg);
+ break;
+ case NET_NFC_MESSAGE_SERVICE_LLCP_DISCONNECT:
+ net_nfc_server_llcp_disconnect(req_msg);
+ break;
+ case NET_NFC_MESSAGE_SERVICE_LLCP_ACCEPT: /* currently not used */
+ break;
+ default:
+ break;
+ }
+}
+
+static void controller_init_thread_func(gpointer user_data)
+{
+ net_nfc_error_e result;
+
+ if (net_nfc_controller_init(&result) == false)
+ {
+ DEBUG_ERR_MSG("%s failed [%d]",
+ "net_nfc_controller_init",
+ result);
+
+ net_nfc_manager_quit();
+ return;
+ }
+
+ DEBUG_SERVER_MSG("%s success [%d]",
+ "net_nfc_controller_init",
+ result);
+
+ if (net_nfc_controller_register_listener(controller_target_detected_cb,
+ controller_se_transaction_cb,
+ controller_llcp_event_cb,
+ &result) == false)
+ {
+ DEBUG_ERR_MSG("%s failed [%d]",
+ "net_nfc_contorller_register_listener",
+ result);
+ }
+ else
+ {
+ DEBUG_SERVER_MSG("%s success !!",
+ "net_nfc_contorller_register_listener");
+ }
+
+ if (net_nfc_server_llcp_set_config(NULL) == NET_NFC_OK)
+ DEBUG_SERVER_MSG("llcp is enabled !!");
+ else
+ DEBUG_ERR_MSG("net_nfc_server_llcp_set config failed");
+}
+
+#ifndef ESE_ALWAYS_ON
+static void controller_deinit_thread_func(gpointer user_data)
+{
+ net_nfc_error_e result;
+
+ net_nfc_controller_configure_discovery(NET_NFC_DISCOVERY_MODE_CONFIG,
+ NET_NFC_ALL_DISABLE,
+ &result);
+
+ net_nfc_server_free_target_info();
+
+ if (net_nfc_controller_deinit() == false)
+ {
+ DEBUG_ERR_MSG("%s is failed %d",
+ "net_nfc_controller_deinit",
+ result);
+ return;
+ }
+
+ DEBUG_SERVER_MSG("%s success [%d]",
+ "net_nfc_controller_deinit",
+ result);
+
+ net_nfc_manager_quit();
+}
+#endif
+
+static void restart_polling_loop_thread_func(gpointer user_data)
+{
+
+ gint state = 0;
+ gint pm_state = 0;
+
+ net_nfc_error_e result;
+
+ if (vconf_get_bool(VCONFKEY_NFC_STATE, &state) != 0)
+ DEBUG_ERR_MSG("%s does not exist", "VCONFKEY_NFC_STATE");
+ if (state == 0)
+ return;
+
+ if (vconf_get_int(VCONFKEY_PM_STATE, &pm_state) != 0)
+ DEBUG_ERR_MSG("%s does not exist", "VCONFKEY_PM_STATE");
+
+
+ DEBUG_SERVER_MSG("net_nfc_service_restart_polling, state = [%d]",
+ pm_state);
+
+
+ if (pm_state == VCONFKEY_PM_STATE_NORMAL)
+ {
+ if (net_nfc_controller_configure_discovery(
+ NET_NFC_DISCOVERY_MODE_CONFIG,
+ NET_NFC_ALL_ENABLE,
+ &result) == true)
+ {
+ DEBUG_SERVER_MSG("polling enable");
+ }
+
+ return;
+ }
+
+ if (pm_state == VCONFKEY_PM_STATE_LCDOFF)
+ {
+ if (net_nfc_controller_configure_discovery(
+ NET_NFC_DISCOVERY_MODE_CONFIG,
+ NET_NFC_ALL_DISABLE,
+ &result) == true)
+ {
+ DEBUG_SERVER_MSG("polling disabled");
+ }
+
+ return;
+ }
+}
+
+gboolean net_nfc_server_controller_thread_init(void)
+{
+ GError *error = NULL;
+
+ controller_async_queue = g_async_queue_new_full(
+ controller_async_queue_free_func);
+
+ controller_thread = g_thread_try_new("controller_thread",
+ controller_thread_func,
+ NULL,
+ &error);
+
+ if (controller_thread == NULL)
+ {
+ DEBUG_ERR_MSG("can not create controller thread: %s",
+ error->message);
+ g_error_free(error);
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+void net_nfc_server_controller_thread_deinit(void)
+{
+ if(net_nfc_server_controller_async_queue_push(
+ controller_thread_deinit_thread_func,
+ NULL)==FALSE)
+ {
+ DEBUG_ERR_MSG("Failed to push onto the queue");
+ }
+
+ g_thread_join(controller_thread);
+ controller_thread = NULL;
+
+ g_async_queue_unref(controller_async_queue);
+ controller_async_queue = NULL;
+}
+
+void net_nfc_server_controller_init(void)
+{
+ if(net_nfc_server_controller_async_queue_push(
+ controller_init_thread_func,
+ NULL)==FALSE)
+ {
+ DEBUG_ERR_MSG("Failed to push onto the queue");
+ }
+}
+
+#ifndef ESE_ALWAYS_ON
+void net_nfc_server_controller_deinit(void)
+{
+ net_nfc_server_controller_async_queue_push(
+ controller_deinit_thread_func,
+ NULL);
+}
+#endif
+
+gboolean net_nfc_server_controller_async_queue_push(
+ net_nfc_server_controller_func func,
+ gpointer user_data)
+{
+ ControllerFuncData *func_data;
+
+ if(controller_async_queue == NULL)
+ {
+ DEBUG_ERR_MSG("controller_async_queue is not initialized");
+ return FALSE;
+ }
+
+ func_data = g_new0(ControllerFuncData, 1);
+ func_data->func = func;
+ func_data->data = user_data;
+
+ g_async_queue_push(controller_async_queue, func_data);
+
+ return TRUE;
+}
+
+void net_nfc_server_restart_polling_loop(void)
+{
+ if(net_nfc_server_controller_async_queue_push(
+ restart_polling_loop_thread_func,
+ NULL) == FALSE)
+ {
+ DEBUG_ERR_MSG("Failed to push onto the queue");
+ }
+}
+
+void net_nfc_server_set_state(guint32 state)
+{
+ if (state == NET_NFC_SERVER_IDLE)
+ server_state &= NET_NFC_SERVER_IDLE;
+ else
+ server_state |= state;
+}
+
+void net_nfc_server_unset_state(guint32 state)
+{
+ server_state &= ~state;
+}
+
+guint32 net_nfc_server_get_state(void)
+{
+ return server_state;
+}
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_SERVER_COMMON_H__
+#define __NET_NFC_SERVER_COMMON_H__
+
+#include <glib.h>
+
+#include "net_nfc_typedef.h"
+
+typedef void (*net_nfc_server_controller_func)(gpointer user_data);
+
+gboolean net_nfc_server_controller_thread_init(void);
+
+void net_nfc_server_controller_thread_deinit(void);
+
+void net_nfc_server_controller_init(void);
+#ifndef ESE_ALWAYS_ON
+void net_nfc_server_controller_deinit(void);
+#endif
+gboolean net_nfc_server_controller_async_queue_push(
+ net_nfc_server_controller_func func,
+ gpointer user_data);
+
+void net_nfc_server_restart_polling_loop(void);
+
+void net_nfc_server_set_state(guint32 state);
+
+void net_nfc_server_unset_state(guint32 state);
+
+guint32 net_nfc_server_get_state(void);
+
+#endif //__NET_NFC_SERVER_COMMON_H__
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <unistd.h>
+#include <glib.h>
+
+#include "vconf.h"
+#ifdef SECURITY_SERVER
+#include "security-server.h"
+#endif
+
+#include "net_nfc_server.h"
+#include "net_nfc_debug_internal.h"
+#include "net_nfc_util_internal.h"
+#include "net_nfc_util_defines.h"
+#include "net_nfc_util_gdbus_internal.h"
+#include "net_nfc_server.h"
+#include "net_nfc_server_context.h"
+
+
+static GHashTable *client_contexts;
+static pthread_mutex_t context_lock = PTHREAD_MUTEX_INITIALIZER;
+
+static void _cleanup_client_context(gpointer data)
+{
+ net_nfc_client_context_info_t *info = data;
+
+ if (info != NULL)
+ {
+ g_free(info->id);
+ g_free(info);
+ }
+}
+
+void net_nfc_server_gdbus_init_client_context()
+{
+ pthread_mutex_lock(&context_lock);
+
+ if (client_contexts == NULL)
+ client_contexts = g_hash_table_new(g_str_hash, g_str_equal);
+
+ pthread_mutex_unlock(&context_lock);
+}
+
+void net_nfc_server_gdbus_deinit_client_context()
+{
+ pthread_mutex_lock(&context_lock);
+
+ if (client_contexts != NULL) {
+ g_hash_table_destroy(client_contexts);
+ client_contexts = NULL;
+ }
+
+ pthread_mutex_unlock(&context_lock);
+}
+
+/* TODO */
+bool net_nfc_server_gdbus_check_privilege(GDBusMethodInvocation *invocation,
+ GVariant *privilege,
+ const char *object,
+ const char *right)
+{
+#ifdef SECURITY_SERVER
+ data_s priv = { NULL, 0 };
+ int result;
+
+ if (privilege == NULL || object == NULL || right == NULL) {
+ return false;
+ }
+
+ net_nfc_util_gdbus_variant_to_data_s(privilege, &priv);
+
+ result = security_server_check_privilege_by_cookie((char *)priv.buffer,
+ object, right);
+
+ net_nfc_util_free_data(&priv);
+
+ if (result < 0) {
+ DEBUG_ERR_MSG("permission denied : \"%s\", \"%s\"", object, right);
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.Privilege",
+ "Permission denied");
+
+ return false;
+ }
+#endif
+ const char *id = g_dbus_method_invocation_get_sender(invocation);
+
+ net_nfc_server_gdbus_add_client_context(id,
+ NET_NFC_CLIENT_ACTIVE_STATE);
+
+ return true;
+}
+
+size_t net_nfc_server_gdbus_get_client_count_no_lock()
+{
+ return g_hash_table_size(client_contexts);
+}
+
+size_t net_nfc_server_gdbus_get_client_count()
+{
+ size_t result;
+
+ pthread_mutex_lock(&context_lock);
+
+ result = net_nfc_server_gdbus_get_client_count_no_lock();
+
+ pthread_mutex_unlock(&context_lock);
+
+ return result;
+}
+
+net_nfc_client_context_info_t *net_nfc_server_gdbus_get_client_context_no_lock(
+ const char *id)
+{
+ net_nfc_client_context_info_t *result;
+
+ result = g_hash_table_lookup(client_contexts, id);
+
+ return result;
+}
+
+net_nfc_client_context_info_t *net_nfc_server_gdbus_get_client_context(
+ const char *id)
+{
+ net_nfc_client_context_info_t *result;
+
+ pthread_mutex_lock(&context_lock);
+
+ result = net_nfc_server_gdbus_get_client_context_no_lock(id);
+
+ pthread_mutex_unlock(&context_lock);
+
+ return result;
+}
+
+void net_nfc_server_gdbus_add_client_context(const char *id,
+ client_state_e state)
+{
+ pthread_mutex_lock(&context_lock);
+
+ if (net_nfc_server_gdbus_get_client_context_no_lock(id) == NULL)
+ {
+ net_nfc_client_context_info_t *info = NULL;
+
+ info = g_new0(net_nfc_client_context_info_t, 1);
+ if (info != NULL)
+ {
+ pid_t pid;
+
+ pid = net_nfc_server_gdbus_get_pid(id);
+ DEBUG_SERVER_MSG("added client id : [%s], pid [%d]", id, pid);
+
+ info->id = g_strdup(id);
+ info->pid = pid;
+ info->pgid = getpgid(pid);
+ info->state = state;
+ info->launch_popup_state = NET_NFC_LAUNCH_APP_SELECT;
+ info->launch_popup_state_no_check = NET_NFC_LAUNCH_APP_SELECT;
+
+ g_hash_table_insert(client_contexts,
+ (gpointer)info->id,
+ (gpointer)info);
+
+ DEBUG_SERVER_MSG("current client count = [%d]",
+ net_nfc_server_gdbus_get_client_count_no_lock());
+ }
+ else
+ {
+ DEBUG_ERR_MSG("alloc failed");
+ }
+ }
+
+ pthread_mutex_unlock(&context_lock);
+}
+
+void net_nfc_server_gdbus_cleanup_client_context(const char *id)
+{
+ net_nfc_client_context_info_t *info;
+
+ pthread_mutex_lock(&context_lock);
+
+ info = net_nfc_server_gdbus_get_client_context_no_lock(id);
+ if (info != NULL)
+ {
+ DEBUG_SERVER_MSG("clean up client context, [%s, %d]", info->id,
+ info->pid);
+
+ g_hash_table_remove(client_contexts, id);
+
+ _cleanup_client_context(info);
+
+ DEBUG_SERVER_MSG("current client count = [%d]",
+ net_nfc_server_gdbus_get_client_count_no_lock());
+
+ ///* TODO : exit when no client */
+ //if (net_nfc_server_gdbus_get_client_count_no_lock() == 0)
+ //{
+ // /* terminate service */
+ // net_nfc_manager_quit();
+ //}
+ }
+
+ pthread_mutex_unlock(&context_lock);
+}
+
+void net_nfc_server_gdbus_for_each_client_context(
+ net_nfc_server_gdbus_for_each_client_cb cb,
+ void *user_param)
+{
+ GHashTableIter iter;
+ char *id;
+ net_nfc_client_context_info_t *info;
+
+ if (cb == NULL)
+ return;
+
+ pthread_mutex_lock(&context_lock);
+
+ g_hash_table_iter_init(&iter, client_contexts);
+ while (g_hash_table_iter_next(&iter, (gpointer *)&id,
+ (gpointer *)&info) == true) {
+ cb(info, user_param);
+ }
+
+ pthread_mutex_unlock(&context_lock);
+}
+
+bool net_nfc_server_gdbus_check_client_is_running(const char *id)
+{
+ return (net_nfc_server_gdbus_get_client_context(id) != NULL);
+}
+
+client_state_e net_nfc_server_gdbus_get_client_state(const char *id)
+{
+ net_nfc_client_context_info_t *info;
+ client_state_e state = NET_NFC_CLIENT_INACTIVE_STATE;
+
+ pthread_mutex_lock(&context_lock);
+
+ info = net_nfc_server_gdbus_get_client_context_no_lock(id);
+ if (info != NULL) {
+ state = info->state;
+ }
+
+ pthread_mutex_unlock(&context_lock);
+
+ return state;
+}
+
+void net_nfc_server_gdbus_set_client_state(const char *id, client_state_e state)
+{
+ net_nfc_client_context_info_t *info;
+
+ pthread_mutex_lock(&context_lock);
+
+ info = net_nfc_server_gdbus_get_client_context_no_lock(id);
+ if (info != NULL) {
+ info->state = state;
+ }
+
+ pthread_mutex_unlock(&context_lock);
+}
+
+void net_nfc_server_gdbus_set_launch_state(const char *id,
+ net_nfc_launch_popup_state_e popup_state,
+ net_nfc_launch_popup_check_e check_foreground)
+{
+ net_nfc_client_context_info_t *info;
+
+ pthread_mutex_lock(&context_lock);
+
+ info = net_nfc_server_gdbus_get_client_context_no_lock(id);
+ if (info != NULL) {
+ if (check_foreground == CHECK_FOREGROUND) {
+ info->launch_popup_state = popup_state;
+ } else {
+ info->launch_popup_state_no_check = popup_state;
+ }
+ }
+
+ pthread_mutex_unlock(&context_lock);
+}
+
+net_nfc_launch_popup_state_e net_nfc_server_gdbus_get_launch_state(
+ const char *id)
+{
+ net_nfc_client_context_info_t *info;
+ net_nfc_launch_popup_state_e result = NET_NFC_LAUNCH_APP_SELECT;
+
+ pthread_mutex_lock(&context_lock);
+
+ info = net_nfc_server_gdbus_get_client_context_no_lock(id);
+ if (info != NULL) {
+ if (info->launch_popup_state_no_check ==
+ NET_NFC_NO_LAUNCH_APP_SELECT) {
+ result = NET_NFC_NO_LAUNCH_APP_SELECT;
+ } else {
+ result = info->launch_popup_state;
+ }
+ }
+
+ pthread_mutex_unlock(&context_lock);
+
+ return result;
+}
+
+net_nfc_launch_popup_state_e net_nfc_server_gdbus_get_client_popup_state(
+ pid_t pid)
+{
+ GHashTableIter iter;
+ char *id;
+ net_nfc_launch_popup_state_e state = NET_NFC_LAUNCH_APP_SELECT;
+ net_nfc_client_context_info_t *info = NULL, *temp;
+
+ pthread_mutex_lock(&context_lock);
+
+ g_hash_table_iter_init(&iter, client_contexts);
+ while (g_hash_table_iter_next(&iter, (gpointer *)&id,
+ (gpointer *)&temp) == true) {
+ if (temp->launch_popup_state_no_check ==
+ NET_NFC_NO_LAUNCH_APP_SELECT) {
+ state = NET_NFC_NO_LAUNCH_APP_SELECT;
+ break;
+ }
+
+ if (temp->pgid == pid) {
+ info = temp;
+ break;
+ }
+ }
+
+ if (info != NULL) {
+ state = info->launch_popup_state;
+ }
+
+ pthread_mutex_unlock(&context_lock);
+
+ return state;
+}
+
+void net_nfc_server_gdbus_increase_se_count(const char *id)
+{
+ net_nfc_client_context_info_t *info;
+
+ pthread_mutex_lock(&context_lock);
+
+ info = net_nfc_server_gdbus_get_client_context_no_lock(id);
+ if (info != NULL) {
+ info->ref_se++;
+ }
+
+ pthread_mutex_unlock(&context_lock);
+}
+
+void net_nfc_server_gdbus_decrease_se_count(const char *id)
+{
+ net_nfc_client_context_info_t *info;
+
+ pthread_mutex_lock(&context_lock);
+
+ info = net_nfc_server_gdbus_get_client_context_no_lock(id);
+ if (info != NULL) {
+ info->ref_se--;
+ }
+
+ pthread_mutex_unlock(&context_lock);
+}
+
+bool net_nfc_server_gdbus_is_server_busy()
+{
+ bool result = false;
+
+ pthread_mutex_lock(&context_lock);
+
+ if (g_hash_table_size(client_contexts) > 0) {
+ GHashTableIter iter;
+ char *id;
+ net_nfc_client_context_info_t *info;
+
+ g_hash_table_iter_init(&iter, client_contexts);
+ while (g_hash_table_iter_next(&iter, (gpointer *)&id,
+ (gpointer *)&info) == true) {
+ if (info->ref_se > 0) {
+ result = true;
+ break;
+ }
+ }
+ }
+
+ pthread_mutex_unlock(&context_lock);
+
+ return result;
+}
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_SERVER_CONTEXT_H__
+#define __NET_NFC_SERVER_CONTEXT_H__
+
+#include <unistd.h>
+#include <glib.h>
+#include <gio/gio.h>
+
+#include "net_nfc_typedef_internal.h"
+
+typedef struct _net_nfc_client_context_info_t
+{
+ /* Permanent property */
+ char *id;
+ pid_t pid;
+ pid_t pgid;
+
+ /* changed by client state */
+ int ref_se;
+ client_state_e state;
+ net_nfc_launch_popup_state_e launch_popup_state;
+ net_nfc_launch_popup_state_e launch_popup_state_no_check;
+
+} net_nfc_client_context_info_t;
+
+typedef void (*net_nfc_server_gdbus_for_each_client_cb)(
+ net_nfc_client_context_info_t *client, void *user_param);
+
+void net_nfc_server_gdbus_init_client_context();
+
+void net_nfc_server_gdbus_deinit_client_context();
+
+bool net_nfc_server_gdbus_check_privilege(GDBusMethodInvocation *invocation,
+ GVariant *privilege,
+ const char *object,
+ const char *right);
+
+void net_nfc_server_gdbus_add_client_context(const char *id,
+ client_state_e state);
+
+void net_nfc_server_gdbus_cleanup_client_context(const char *id);
+
+net_nfc_client_context_info_t *net_nfc_server_gdbus_get_client_context(
+ const char *id);
+
+size_t net_nfc_server_gdbus_get_client_count();
+
+void net_nfc_server_gdbus_for_each_client_context(
+ net_nfc_server_gdbus_for_each_client_cb cb,
+ void *user_param);
+
+bool net_nfc_server_gdbus_check_client_is_running(const char *id);
+
+client_state_e net_nfc_server_gdbus_get_client_state(
+ const char *id);
+
+void net_nfc_server_gdbus_set_client_state(const char *id,
+ client_state_e state);
+
+void net_nfc_server_gdbus_set_launch_state(const char *id,
+ net_nfc_launch_popup_state_e popup_state,
+ net_nfc_launch_popup_check_e check_foreground);
+
+net_nfc_launch_popup_state_e net_nfc_server_gdbus_get_launch_state(
+ const char *id);
+
+net_nfc_launch_popup_state_e net_nfc_server_gdbus_get_client_popup_state(
+ pid_t pid);
+
+void net_nfc_server_gdbus_increase_se_count(const char *id);
+void net_nfc_server_gdbus_decrease_se_count(const char *id);
+
+bool net_nfc_server_gdbus_is_server_busy();
+
+#endif //__NET_NFC_SERVER_CONTEXT_H__
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#define _GNU_SOURCE
+#include <linux/limits.h>
+#include <stdio.h>
+#include <dlfcn.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <dirent.h>
+#include <string.h>
+#include <errno.h>
+
+#include <pmapi.h>/*for pm lock*/
+
+#include "net_nfc_oem_controller.h"
+#include "net_nfc_server_controller.h"
+#include "net_nfc_util_internal.h"
+#include "net_nfc_debug_internal.h"
+#include "net_nfc_server_tag.h"
+
+#define NET_NFC_OEM_LIBRARY_PATH "/usr/lib/libnfc-plugin.so"
+#define NET_NFC_DEFAULT_PLUGIN "libnfc-plugin.so"
+
+
+static net_nfc_oem_interface_s g_interface;
+
+static void *net_nfc_controller_load_file(const char *dir_path,
+ const char *filename)
+{
+ void *handle = NULL;
+ char path[PATH_MAX] = { '\0' };
+ struct stat st;
+
+ net_nfc_error_e result;
+
+ bool (*onload)(net_nfc_oem_interface_s *interfaces);
+
+ snprintf(path, PATH_MAX, "%s/%s", dir_path, filename);
+ DEBUG_SERVER_MSG("path : %s", path);
+
+ if (stat(path, &st) == -1) {
+ DEBUG_ERR_MSG("stat failed : file not found");
+ goto ERROR;
+ }
+
+ if (S_ISREG(st.st_mode) == 0) {
+ DEBUG_ERR_MSG("S_ISREG(st.st_mode) == 0");
+ goto ERROR;
+ }
+
+ handle = dlopen(path, RTLD_LAZY);
+ if (handle == NULL) {
+ char buffer[1024];
+ DEBUG_ERR_MSG("dlopen failed, [%d] : %s",
+ errno, strerror_r(errno, buffer, sizeof(buffer)));
+ goto ERROR;
+ }
+
+ onload = dlsym(handle, "onload");
+ if (onload == NULL) {
+ char buffer[1024];
+ DEBUG_ERR_MSG("dlsym failed, [%d] : %s",
+ errno, strerror_r(errno, buffer, sizeof(buffer)));
+ goto ERROR;
+ }
+
+ memset(&g_interface, 0, sizeof(g_interface));
+ if (onload(&g_interface) == false) {
+ DEBUG_ERR_MSG("onload failed");
+ goto ERROR;
+ }
+
+ if (net_nfc_controller_support_nfc(&result) == false) {
+ DEBUG_ERR_MSG("net_nfc_controller_support_nfc failed, [%d]",
+ result);
+ goto ERROR;
+ }
+
+ return handle;
+
+ERROR :
+ if (handle != NULL) {
+ dlclose(handle);
+ }
+
+ return NULL;
+}
+
+void *net_nfc_controller_onload()
+{
+ DIR *dirp;
+ struct dirent *dir;
+
+ void *handle = NULL;
+
+ dirp = opendir(NFC_MANAGER_MODULEDIR);
+ if (dirp == NULL)
+ {
+ DEBUG_ERR_MSG("Can not open directory %s",
+ NFC_MANAGER_MODULEDIR);
+ return NULL;
+ }
+
+ while ((dir = readdir(dirp)))
+ {
+ if ((strcmp(dir->d_name, ".") == 0) ||
+ (strcmp(dir->d_name, "..") == 0))
+ {
+ continue;
+ }
+
+ /* check ".so" suffix */
+ if (strcmp(dir->d_name + (strlen(dir->d_name) - strlen(".so")),
+ ".so") != 0)
+ continue;
+
+ /* check default plugin later */
+ if (strcmp(dir->d_name, NET_NFC_DEFAULT_PLUGIN) == 0)
+ continue;
+
+ handle = net_nfc_controller_load_file(NFC_MANAGER_MODULEDIR,
+ dir->d_name);
+ if (handle)
+ {
+ SECURE_LOGD("Successfully loaded : %s",
+ dir->d_name);
+ closedir(dirp);
+ return handle;
+ }
+ }
+
+ closedir(dirp);
+
+ /* load default plugin */
+ handle = net_nfc_controller_load_file(NFC_MANAGER_MODULEDIR,
+ NET_NFC_DEFAULT_PLUGIN);
+
+ if (handle)
+ {
+ DEBUG_SERVER_MSG("loaded default plugin : %s",
+ NET_NFC_DEFAULT_PLUGIN);
+ return handle;
+ }
+ else
+ {
+ DEBUG_ERR_MSG("can not load default plugin : %s",
+ NET_NFC_DEFAULT_PLUGIN);
+ return NULL;
+ }
+}
+
+bool net_nfc_controller_unload(void *handle)
+{
+ memset(&g_interface, 0x00, sizeof(net_nfc_oem_interface_s));
+
+ if (handle != NULL)
+ {
+ dlclose(handle);
+ handle = NULL;
+ }
+ return true;
+}
+
+bool net_nfc_controller_init(net_nfc_error_e *result)
+{
+ if (g_interface.init != NULL)
+ {
+ return g_interface.init(result);
+ }
+ else
+ {
+ *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;
+ DEBUG_SERVER_MSG("interface is null");
+ return false;
+ }
+}
+
+bool net_nfc_controller_deinit(void)
+{
+ if (g_interface.deinit != NULL)
+ {
+ return g_interface.deinit();
+ }
+ else
+ {
+ DEBUG_SERVER_MSG("interface is null");
+ return false;
+ }
+}
+
+bool net_nfc_controller_register_listener(target_detection_listener_cb target_detection_listener,
+ se_transaction_listener_cb se_transaction_listener, llcp_event_listener_cb llcp_event_listener, net_nfc_error_e *result)
+{
+ if (g_interface.register_listener != NULL)
+ {
+ return g_interface.register_listener(target_detection_listener, se_transaction_listener, llcp_event_listener, result);
+ }
+ else
+ {
+ *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;
+ DEBUG_SERVER_MSG("interface is null");
+ return false;
+ }
+}
+
+bool net_nfc_controller_unregister_listener()
+{
+ if (g_interface.unregister_listener != NULL)
+ {
+ return g_interface.unregister_listener();
+ }
+ else
+ {
+ DEBUG_SERVER_MSG("interface is null");
+ return false;
+ }
+}
+
+bool net_nfc_controller_get_firmware_version(data_s **data, net_nfc_error_e *result)
+{
+ if (g_interface.get_firmware_version != NULL)
+ {
+ return g_interface.get_firmware_version(data, result);
+ }
+ else
+ {
+ *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;
+ DEBUG_SERVER_MSG("interface is null");
+ return false;
+ }
+}
+
+bool net_nfc_controller_check_firmware_version(net_nfc_error_e *result)
+{
+ if (g_interface.check_firmware_version != NULL)
+ {
+ return g_interface.check_firmware_version(result);
+ }
+ else
+ {
+ *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;
+ DEBUG_SERVER_MSG("interface is null");
+ return false;
+ }
+}
+
+bool net_nfc_controller_update_firmware(net_nfc_error_e *result)
+{
+ if (g_interface.update_firmeware != NULL)
+ {
+ return g_interface.update_firmeware(result);
+ }
+ else
+ {
+ *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;
+ DEBUG_SERVER_MSG("interface is null");
+ return false;
+ }
+}
+
+bool net_nfc_controller_get_stack_information(net_nfc_stack_information_s *stack_info, net_nfc_error_e *result)
+{
+ if (g_interface.get_stack_information != NULL)
+ {
+ return g_interface.get_stack_information(stack_info, result);
+ }
+ else
+ {
+ *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;
+ DEBUG_SERVER_MSG("interface is null");
+ return false;
+ }
+}
+
+bool net_nfc_controller_configure_discovery(net_nfc_discovery_mode_e mode, net_nfc_event_filter_e config, net_nfc_error_e *result)
+{
+ if (g_interface.configure_discovery != NULL)
+ {
+ return g_interface.configure_discovery(mode, config, result);
+ }
+ else
+ {
+ *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;
+ DEBUG_SERVER_MSG("interface is null");
+ return false;
+ }
+}
+
+bool net_nfc_controller_get_secure_element_list(net_nfc_secure_element_info_s *list, int *count, net_nfc_error_e *result)
+{
+ if (g_interface.get_secure_element_list != NULL)
+ {
+ return g_interface.get_secure_element_list(list, count, result);
+ }
+ else
+ {
+ *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;
+ DEBUG_SERVER_MSG("interface is null");
+ return false;
+ }
+}
+
+bool net_nfc_controller_set_secure_element_mode(net_nfc_secure_element_type_e element_type, net_nfc_secure_element_mode_e mode, net_nfc_error_e *result)
+{
+ if (g_interface.set_secure_element_mode != NULL)
+ {
+ return g_interface.set_secure_element_mode(element_type, mode, result);
+ }
+ else
+ {
+ *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;
+ DEBUG_SERVER_MSG("interface is null");
+ return false;
+ }
+}
+
+bool net_nfc_controller_secure_element_open(net_nfc_secure_element_type_e element_type, net_nfc_target_handle_s **handle, net_nfc_error_e *result)
+{
+ int ret_val = 0;
+
+ ret_val = pm_lock_state(LCD_NORMAL, GOTO_STATE_NOW, 0);
+
+ DEBUG_SERVER_MSG("pm_lock_state [%d]!!", ret_val);
+
+ if (g_interface.secure_element_open != NULL)
+ {
+ return g_interface.secure_element_open(element_type, handle, result);
+ }
+ else
+ {
+ *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;
+ DEBUG_SERVER_MSG("interface is null");
+ return false;
+ }
+}
+
+bool net_nfc_controller_secure_element_get_atr(net_nfc_target_handle_s *handle, data_s **atr, net_nfc_error_e *result)
+{
+ if (g_interface.secure_element_get_atr != NULL)
+ {
+ return g_interface.secure_element_get_atr(handle, atr, result);
+ }
+ else
+ {
+ *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;
+ DEBUG_SERVER_MSG("interface is null");
+ return false;
+ }
+}
+
+bool net_nfc_controller_secure_element_send_apdu(net_nfc_target_handle_s *handle, data_s *command, data_s **response, net_nfc_error_e *result)
+{
+ if (g_interface.secure_element_send_apdu != NULL)
+ {
+ return g_interface.secure_element_send_apdu(handle, command, response, result);
+ }
+ else
+ {
+ *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;
+ DEBUG_SERVER_MSG("interface is null");
+ return false;
+ }
+}
+
+bool net_nfc_controller_secure_element_close(net_nfc_target_handle_s *handle, net_nfc_error_e *result)
+{
+ int ret_val = 0;
+
+ ret_val = pm_unlock_state(LCD_NORMAL, PM_RESET_TIMER);
+ DEBUG_SERVER_MSG("pm_unlock_state [%d]!!", ret_val);
+
+ if (g_interface.secure_element_close != NULL)
+ {
+ return g_interface.secure_element_close(handle, result);
+ }
+ else
+ {
+ *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;
+ DEBUG_SERVER_MSG("interface is null");
+ return false;
+ }
+}
+
+bool net_nfc_controller_check_target_presence(net_nfc_target_handle_s *handle, net_nfc_error_e *result)
+{
+ if (g_interface.check_presence != NULL)
+ {
+ return g_interface.check_presence(handle, result);
+ }
+ else
+ {
+ *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;
+ DEBUG_SERVER_MSG("interface is null");
+ return false;
+ }
+}
+
+bool net_nfc_controller_connect(net_nfc_target_handle_s *handle, net_nfc_error_e *result)
+{
+ int ret_val = 0;
+
+ ret_val = pm_lock_state(LCD_NORMAL, GOTO_STATE_NOW, 0);
+
+ DEBUG_SERVER_MSG("net_nfc_controller_connect pm_lock_state [%d]!!", ret_val);
+
+ if (g_interface.connect != NULL)
+ {
+ return g_interface.connect(handle, result);
+ }
+ else
+ {
+ *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;
+ DEBUG_SERVER_MSG("interface is null");
+ return false;
+ }
+}
+
+bool net_nfc_controller_disconnect(net_nfc_target_handle_s *handle, net_nfc_error_e *result)
+{
+ int ret_val = 0;
+
+ ret_val = pm_unlock_state(LCD_NORMAL, PM_RESET_TIMER);
+
+ DEBUG_ERR_MSG("net_nfc_controller_disconnect pm_lock_state [%d]!!", ret_val);
+
+ if (g_interface.disconnect != NULL)
+ {
+ net_nfc_server_free_target_info();
+
+ return g_interface.disconnect(handle, result);
+ }
+ else
+ {
+ *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;
+ DEBUG_SERVER_MSG("interface is null");
+ return false;
+ }
+}
+
+bool net_nfc_controller_check_ndef(net_nfc_target_handle_s *handle, uint8_t *ndef_card_state, int *max_data_size, int *real_data_size, net_nfc_error_e *result)
+{
+ if (g_interface.check_ndef != NULL)
+ {
+ return g_interface.check_ndef(handle, ndef_card_state, max_data_size, real_data_size, result);
+ }
+ else
+ {
+ *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;
+ DEBUG_SERVER_MSG("interface is null");
+ return false;
+ }
+}
+
+bool net_nfc_controller_read_ndef(net_nfc_target_handle_s *handle, data_s **data, net_nfc_error_e *result)
+{
+ if (g_interface.read_ndef != NULL)
+ {
+ return g_interface.read_ndef(handle, data, result);
+ }
+ else
+ {
+ *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;
+ DEBUG_SERVER_MSG("interface is null");
+ return false;
+ }
+}
+
+bool net_nfc_controller_write_ndef(net_nfc_target_handle_s *handle, data_s *data,
+ net_nfc_error_e *result)
+{
+ if (g_interface.write_ndef != NULL)
+ {
+ return g_interface.write_ndef(handle, data, result);
+ }
+ else
+ {
+ *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;
+ DEBUG_SERVER_MSG("interface is null");
+ return false;
+ }
+}
+
+bool net_nfc_controller_make_read_only_ndef(net_nfc_target_handle_s *handle,
+ net_nfc_error_e *result)
+{
+ if (g_interface.make_read_only_ndef != NULL)
+ {
+ return g_interface.make_read_only_ndef(handle, result);
+ }
+ else
+ {
+ *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;
+ DEBUG_SERVER_MSG("interface is null");
+ return false;
+ }
+}
+
+bool net_nfc_controller_format_ndef(net_nfc_target_handle_s *handle,
+ data_s *secure_key, net_nfc_error_e *result)
+{
+ if (g_interface.format_ndef != NULL)
+ {
+ return g_interface.format_ndef(handle, secure_key, result);
+ }
+ else
+ {
+ *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;
+ DEBUG_SERVER_MSG("interface is null");
+ return false;
+ }
+}
+
+bool net_nfc_controller_transceive(net_nfc_target_handle_s *handle,
+ net_nfc_transceive_info_s *info, data_s **data, net_nfc_error_e *result)
+{
+ if (g_interface.transceive != NULL)
+ {
+ return g_interface.transceive(handle, info, data, result);
+ }
+ else
+ {
+ *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;
+ DEBUG_SERVER_MSG("interface is null");
+ return false;
+ }
+}
+
+bool net_nfc_controller_exception_handler()
+{
+ if (g_interface.exception_handler != NULL)
+ {
+ return g_interface.exception_handler();
+ }
+ else
+ {
+ DEBUG_SERVER_MSG("interface is null");
+ return false;
+ }
+}
+
+bool net_nfc_controller_is_ready(net_nfc_error_e *result)
+{
+ if (g_interface.is_ready != NULL)
+ {
+ return g_interface.is_ready(result);
+ }
+ else
+ {
+ *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;
+ DEBUG_SERVER_MSG("interface is null");
+ return false;
+ }
+}
+
+bool net_nfc_controller_llcp_config(net_nfc_llcp_config_info_s *config,
+ net_nfc_error_e *result)
+{
+ if (g_interface.config_llcp != NULL)
+ {
+ return g_interface.config_llcp(config, result);
+ }
+ else
+ {
+ *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;
+ DEBUG_SERVER_MSG("interface is null");
+ return false;
+ }
+}
+bool net_nfc_controller_llcp_check_llcp(net_nfc_target_handle_s *handle,
+ net_nfc_error_e *result)
+{
+ if (g_interface.check_llcp_status != NULL)
+ {
+ return g_interface.check_llcp_status(handle, result);
+ }
+ else
+ {
+ *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;
+ DEBUG_SERVER_MSG("interface is null");
+ return false;
+ }
+}
+bool net_nfc_controller_llcp_activate_llcp(net_nfc_target_handle_s *handle,
+ net_nfc_error_e *result)
+{
+ if (g_interface.activate_llcp != NULL)
+ {
+ return g_interface.activate_llcp(handle, result);
+ }
+ else
+ {
+ *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;
+ DEBUG_SERVER_MSG("interface is null");
+ return false;
+ }
+}
+
+static GSList *llcp_sockets;
+
+static gint _compare_socket_info(gconstpointer a, gconstpointer b)
+{
+ int result;
+ socket_info_t *info = (socket_info_t *)a;
+
+ if (info->socket == (net_nfc_llcp_socket_t)b)
+ result = 0;
+ else
+ result = -1;
+
+ return result;
+}
+
+socket_info_t *_get_socket_info(net_nfc_llcp_socket_t socket)
+{
+ socket_info_t *result;
+ GSList *item;
+
+ item = g_slist_find_custom(llcp_sockets, GUINT_TO_POINTER(socket),
+ _compare_socket_info);
+ if (item != NULL) {
+ result = (socket_info_t *)item->data;
+ } else {
+ result = NULL;
+ }
+
+ return result;
+}
+
+socket_info_t *_add_socket_info(net_nfc_llcp_socket_t socket)
+{
+ socket_info_t *result;
+
+ _net_nfc_util_alloc_mem(result, sizeof(*result));
+ if (result != NULL) {
+ result->socket = socket;
+
+ llcp_sockets = g_slist_append(llcp_sockets, result);
+ }
+
+ return result;
+}
+
+static void _remove_socket_info(net_nfc_llcp_socket_t socket)
+{
+ GSList *item;
+
+ item = g_slist_find_custom(llcp_sockets, GUINT_TO_POINTER(socket),
+ _compare_socket_info);
+ if (item != NULL) {
+ llcp_sockets = g_slist_remove_link(llcp_sockets, item);
+ free(item->data);
+ }
+}
+
+void net_nfc_controller_llcp_socket_error_cb(net_nfc_llcp_socket_t socket,
+ net_nfc_error_e result, void *data, void *user_param)
+{
+ socket_info_t *info;
+
+ info = _get_socket_info(socket);
+ if (info != NULL) {
+ if (info->err_cb != NULL) {
+ info->err_cb(socket, result, NULL, NULL, info->err_param);
+ }
+
+ _remove_socket_info(socket);
+ }
+}
+
+bool net_nfc_controller_llcp_create_socket(net_nfc_llcp_socket_t *socket,
+ net_nfc_socket_type_e socketType, uint16_t miu, uint8_t rw, net_nfc_error_e *result,
+ net_nfc_service_llcp_cb cb, void *user_param)
+{
+ if (g_interface.create_llcp_socket != NULL)
+ {
+ bool ret;
+ socket_info_t *info;
+
+ info = _add_socket_info(-1);
+ if (info == NULL) {
+ DEBUG_ERR_MSG("_net_nfc_util_alloc_mem failed");
+ *result = NET_NFC_ALLOC_FAIL;
+ return false;
+ }
+
+ ret = g_interface.create_llcp_socket(socket, socketType, miu, rw, result, NULL);
+ if (ret == true) {
+ info->socket = *socket;
+ info->err_cb = cb;
+ info->err_param = user_param;
+ } else {
+ _remove_socket_info(-1);
+ }
+
+ return ret;
+ }
+ else
+ {
+ *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;
+ DEBUG_SERVER_MSG("interface is null");
+ return false;
+ }
+}
+
+bool net_nfc_controller_llcp_bind(net_nfc_llcp_socket_t socket,
+ uint8_t service_access_point, net_nfc_error_e *result)
+{
+ if (g_interface.bind_llcp_socket != NULL)
+ {
+ return g_interface.bind_llcp_socket(socket, service_access_point, result);
+ }
+ else
+ {
+ *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;
+ DEBUG_SERVER_MSG("interface is null");
+ return false;
+ }
+}
+
+void net_nfc_controller_llcp_incoming_cb(net_nfc_llcp_socket_t socket,
+ net_nfc_error_e result, void *data, void *user_param)
+{
+ socket_info_t *info = (socket_info_t *)user_param;
+
+ info = _get_socket_info(info->socket);
+ if (info != NULL) {
+ if (_add_socket_info(socket) != NULL) {
+ if (info->work_cb != NULL) {
+ info->work_cb(socket, result, NULL, NULL,
+ info->work_param);
+ }
+ } else {
+ DEBUG_ERR_MSG("_net_nfc_util_alloc_mem failed");
+ }
+ }
+}
+
+bool net_nfc_controller_llcp_listen(net_nfc_target_handle_s* handle,
+ uint8_t *service_access_name, net_nfc_llcp_socket_t socket, net_nfc_error_e *result,
+ net_nfc_service_llcp_cb cb, void *user_param)
+{
+ if (g_interface.listen_llcp_socket != NULL)
+ {
+ socket_info_t *info;
+
+ info = _get_socket_info(socket);
+ if (info == NULL) {
+ DEBUG_ERR_MSG("_get_socket_info failed");
+ *result = NET_NFC_INVALID_HANDLE;
+ return false;
+ }
+
+ info->work_cb = cb;
+ info->work_param = user_param;
+
+ return g_interface.listen_llcp_socket(handle, service_access_name, socket, result, info);
+ }
+ else
+ {
+ *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;
+ DEBUG_SERVER_MSG("interface is null");
+ return false;
+ }
+}
+
+bool net_nfc_controller_llcp_accept(net_nfc_llcp_socket_t socket,
+ net_nfc_error_e *result, net_nfc_service_llcp_cb cb, void *user_param)
+{
+ if (g_interface.accept_llcp_socket != NULL)
+ {
+ socket_info_t *info;
+
+ info = _get_socket_info(socket);
+ if (info == NULL) {
+ DEBUG_ERR_MSG("_get_socket_info failed");
+ *result = NET_NFC_INVALID_HANDLE;
+ return false;
+ }
+
+ info->err_cb = cb;
+ info->err_param = user_param;
+
+ return g_interface.accept_llcp_socket(socket, result, NULL);
+ }
+ else
+ {
+ *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;
+ DEBUG_SERVER_MSG("interface is null");
+ return false;
+ }
+}
+
+bool net_nfc_controller_llcp_reject(net_nfc_target_handle_s *handle,
+ net_nfc_llcp_socket_t socket, net_nfc_error_e *result)
+{
+ if (g_interface.reject_llcp != NULL)
+ {
+ bool ret;
+
+ ret = g_interface.reject_llcp(handle, socket, result);
+ if (ret == true) {
+ _remove_socket_info(socket);
+ }
+
+ return ret;
+ }
+ else
+ {
+ *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;
+ DEBUG_SERVER_MSG("interface is null");
+ return false;
+ }
+}
+
+void net_nfc_controller_llcp_connected_cb(net_nfc_llcp_socket_t socket,
+ net_nfc_error_e result, void *data, void *user_param)
+{
+ net_nfc_llcp_param_t *param = (net_nfc_llcp_param_t *)user_param;
+
+ if (param == NULL)
+ return;
+
+ if (param->cb != NULL) {
+ param->cb(param->socket, result, NULL, NULL, param->user_param);
+ }
+
+ _net_nfc_util_free_mem(param);
+}
+
+bool net_nfc_controller_llcp_connect_by_url(net_nfc_target_handle_s *handle,
+ net_nfc_llcp_socket_t socket, uint8_t *service_access_name, net_nfc_error_e *result,
+ net_nfc_service_llcp_cb cb, void *user_param)
+{
+ int ret_val = 0;
+
+ ret_val = pm_lock_state(LCD_NORMAL, GOTO_STATE_NOW, 0);
+
+ DEBUG_SERVER_MSG("net_nfc_controller_llcp_connect_by_url pm_lock_state [%d]!!", ret_val);
+
+ if (g_interface.connect_llcp_by_url != NULL)
+ {
+ net_nfc_llcp_param_t *param = NULL;
+
+ _net_nfc_util_alloc_mem(param, sizeof(*param));
+ if (param == NULL) {
+ DEBUG_ERR_MSG("_net_nfc_util_alloc_mem failed");
+ *result = NET_NFC_ALLOC_FAIL;
+ return false;
+ }
+
+ param->socket = socket;
+ param->cb = cb;
+ param->user_param = user_param;
+
+ return g_interface.connect_llcp_by_url(handle, socket, service_access_name, result, param);
+ }
+ else
+ {
+ *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;
+ DEBUG_SERVER_MSG("interface is null");
+ return false;
+ }
+}
+
+bool net_nfc_controller_llcp_connect(net_nfc_target_handle_s *handle,
+ net_nfc_llcp_socket_t socket, uint8_t service_access_point, net_nfc_error_e *result,
+ net_nfc_service_llcp_cb cb, void *user_param)
+{
+ int ret_val = 0;
+
+ ret_val = pm_lock_state(LCD_NORMAL, GOTO_STATE_NOW, 0);
+
+ DEBUG_SERVER_MSG("net_nfc_controller_llcp_connect pm_lock_state [%d]!!", ret_val);
+
+ if (g_interface.connect_llcp != NULL)
+ {
+ net_nfc_llcp_param_t *param = NULL;
+
+ _net_nfc_util_alloc_mem(param, sizeof(*param));
+ if (param == NULL) {
+ DEBUG_ERR_MSG("_net_nfc_util_alloc_mem failed");
+ *result = NET_NFC_ALLOC_FAIL;
+ return false;
+ }
+
+ param->socket = socket;
+ param->cb = cb;
+ param->user_param = user_param;
+
+ return g_interface.connect_llcp(handle, socket, service_access_point, result, param);
+ }
+ else
+ {
+ *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;
+ DEBUG_SERVER_MSG("interface is null");
+ return false;
+ }
+}
+
+void net_nfc_controller_llcp_disconnected_cb(net_nfc_llcp_socket_t socket,
+ net_nfc_error_e result, void *data, void *user_param)
+{
+ net_nfc_llcp_param_t *param = (net_nfc_llcp_param_t *)user_param;
+
+ if (param == NULL)
+ return;
+
+ if (param->cb != NULL) {
+ param->cb(param->socket, result, NULL, NULL, param->user_param);
+ }
+
+ _net_nfc_util_free_mem(param);
+}
+
+bool net_nfc_controller_llcp_disconnect(net_nfc_target_handle_s *handle,
+ net_nfc_llcp_socket_t socket, net_nfc_error_e *result, net_nfc_service_llcp_cb cb,
+ void *user_param)
+{
+ int ret_val = 0;
+
+ ret_val = pm_unlock_state(LCD_NORMAL, PM_RESET_TIMER);
+
+ DEBUG_SERVER_MSG("net_nfc_controller_llcp_disconnect pm_unlock_state [%d]!!", ret_val);
+
+ if (g_interface.disconnect_llcp != NULL)
+ {
+ net_nfc_llcp_param_t *param = NULL;
+
+ _net_nfc_util_alloc_mem(param, sizeof(*param));
+ if (param == NULL) {
+ DEBUG_ERR_MSG("_net_nfc_util_alloc_mem failed");
+ *result = NET_NFC_ALLOC_FAIL;
+ return false;
+ }
+
+ param->socket = socket;
+ param->cb = cb;
+ param->user_param = user_param;
+
+ return g_interface.disconnect_llcp(handle, socket, result, param);
+ }
+ else
+ {
+ *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;
+ DEBUG_SERVER_MSG("interface is null");
+ return false;
+ }
+}
+
+bool net_nfc_controller_llcp_socket_close(net_nfc_llcp_socket_t socket,
+ net_nfc_error_e *result)
+{
+ if (g_interface.close_llcp_socket != NULL)
+ {
+ return g_interface.close_llcp_socket(socket, result);
+ }
+ else
+ {
+ *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;
+ DEBUG_SERVER_MSG("interface is null");
+ return false;
+ }
+}
+
+void net_nfc_controller_llcp_received_cb(net_nfc_llcp_socket_t socket,
+ net_nfc_error_e result, void *data, void *user_param)
+{
+ net_nfc_llcp_param_t *param = (net_nfc_llcp_param_t *)user_param;
+
+ if (param == NULL)
+ return;
+
+ if (param->cb != NULL) {
+ param->cb(param->socket, result, ¶m->data, data, param->user_param);
+ }
+
+ if (param->data.buffer != NULL) {
+ _net_nfc_util_free_mem(param->data.buffer);
+ }
+ _net_nfc_util_free_mem(param);
+}
+
+bool net_nfc_controller_llcp_recv(net_nfc_target_handle_s *handle,
+ net_nfc_llcp_socket_t socket, uint32_t max_len, net_nfc_error_e *result,
+ net_nfc_service_llcp_cb cb, void *user_param)
+{
+ if (g_interface.recv_llcp != NULL)
+ {
+ net_nfc_llcp_param_t *param = NULL;
+
+ _net_nfc_util_alloc_mem(param, sizeof(*param));
+ if (param == NULL) {
+ DEBUG_ERR_MSG("_net_nfc_util_alloc_mem failed");
+ *result = NET_NFC_ALLOC_FAIL;
+ return false;
+ }
+
+ param->socket = socket;
+ param->cb = cb;
+ if (max_len > 0) {
+ _net_nfc_util_alloc_mem(param->data.buffer, max_len);
+ if (param->data.buffer == NULL) {
+ DEBUG_ERR_MSG("_net_nfc_util_alloc_mem failed");
+ _net_nfc_util_free_mem(param);
+ *result = NET_NFC_ALLOC_FAIL;
+ return false;
+ }
+ param->data.length = max_len;
+ }
+ param->user_param = user_param;
+
+ return g_interface.recv_llcp(handle, socket, ¶m->data, result, param);
+ }
+ else
+ {
+ *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;
+ DEBUG_SERVER_MSG("interface is null");
+ return false;
+ }
+}
+
+void net_nfc_controller_llcp_sent_cb(net_nfc_llcp_socket_t socket,
+ net_nfc_error_e result, void *data, void *user_param)
+{
+ net_nfc_llcp_param_t *param = (net_nfc_llcp_param_t *)user_param;
+
+ if (param == NULL)
+ return;
+
+ if (param->cb != NULL) {
+ param->cb(param->socket, result, NULL, NULL, param->user_param);
+ }
+
+ _net_nfc_util_free_mem(param);
+}
+
+bool net_nfc_controller_llcp_send(net_nfc_target_handle_s *handle,
+ net_nfc_llcp_socket_t socket, data_s *data, net_nfc_error_e *result,
+ net_nfc_service_llcp_cb cb, void *user_param)
+{
+ if (g_interface.send_llcp != NULL)
+ {
+ net_nfc_llcp_param_t *param = NULL;
+
+ _net_nfc_util_alloc_mem(param, sizeof(*param));
+ if (param == NULL) {
+ DEBUG_ERR_MSG("_net_nfc_util_alloc_mem failed");
+ *result = NET_NFC_ALLOC_FAIL;
+ return false;
+ }
+
+ param->socket = socket;
+ param->cb = cb;
+ param->user_param = user_param;
+
+ return g_interface.send_llcp(handle, socket, data, result, param);
+ }
+ else
+ {
+ *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;
+ DEBUG_SERVER_MSG("interface is null");
+ return false;
+ }
+}
+bool net_nfc_controller_llcp_recv_from(net_nfc_target_handle_s *handle,
+ net_nfc_llcp_socket_t socket, uint32_t max_len, net_nfc_error_e *result,
+ net_nfc_service_llcp_cb cb, void *user_param)
+{
+ if (g_interface.recv_from_llcp != NULL)
+ {
+ net_nfc_llcp_param_t *param = NULL;
+
+ _net_nfc_util_alloc_mem(param, sizeof(*param));
+ if (param == NULL) {
+ DEBUG_ERR_MSG("_net_nfc_util_alloc_mem failed");
+ *result = NET_NFC_ALLOC_FAIL;
+ return false;
+ }
+
+ param->socket = socket;
+ param->cb = cb;
+ if (max_len > 0) {
+ _net_nfc_util_alloc_mem(param->data.buffer, max_len);
+ if (param->data.buffer == NULL) {
+ DEBUG_ERR_MSG("_net_nfc_util_alloc_mem failed");
+ _net_nfc_util_free_mem(param);
+ *result = NET_NFC_ALLOC_FAIL;
+ return false;
+ }
+ param->data.length = max_len;
+ }
+ param->user_param = user_param;
+
+ return g_interface.recv_from_llcp(handle, socket, ¶m->data, result, param);
+ }
+ else
+ {
+ *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;
+ DEBUG_SERVER_MSG("interface is null");
+ return false;
+ }
+}
+bool net_nfc_controller_llcp_send_to(net_nfc_target_handle_s *handle,
+ net_nfc_llcp_socket_t socket, data_s *data, uint8_t service_access_point,
+ net_nfc_error_e *result, net_nfc_service_llcp_cb cb, void *user_param)
+{
+ if (g_interface.send_to_llcp != NULL)
+ {
+ net_nfc_llcp_param_t *param = NULL;
+
+ _net_nfc_util_alloc_mem(param, sizeof(*param));
+ if (param == NULL) {
+ DEBUG_ERR_MSG("_net_nfc_util_alloc_mem failed");
+ *result = NET_NFC_ALLOC_FAIL;
+ return false;
+ }
+
+ param->socket = socket;
+ param->cb = cb;
+ param->user_param = user_param;
+
+ return g_interface.send_to_llcp(handle, socket, data, service_access_point, result, param);
+ }
+ else
+ {
+ *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;
+ DEBUG_SERVER_MSG("interface is null");
+ return false;
+ }
+}
+
+bool net_nfc_controller_llcp_get_remote_config(net_nfc_target_handle_s *handle,
+ net_nfc_llcp_config_info_s *config, net_nfc_error_e *result)
+{
+ if (g_interface.get_remote_config != NULL)
+ {
+ return g_interface.get_remote_config(handle, config, result);
+ }
+ else
+ {
+ *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;
+ DEBUG_SERVER_MSG("interface is null");
+ return false;
+ }
+}
+bool net_nfc_controller_llcp_get_remote_socket_info(net_nfc_target_handle_s *handle,
+ net_nfc_llcp_socket_t socket, net_nfc_llcp_socket_option_s *option, net_nfc_error_e *result)
+{
+ if (g_interface.get_remote_socket_info != NULL)
+ {
+ return g_interface.get_remote_socket_info(handle, socket, option, result);
+ }
+ else
+ {
+ *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;
+ DEBUG_SERVER_MSG("interface is null");
+ return false;
+ }
+
+}
+
+bool net_nfc_controller_sim_test(net_nfc_error_e *result)
+{
+ if (g_interface.sim_test != NULL)
+ {
+ return g_interface.sim_test(result);
+ }
+ else
+ {
+ *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;
+ DEBUG_SERVER_MSG("interface is null");
+ return false;
+ }
+}
+
+bool net_nfc_controller_prbs_test(net_nfc_error_e *result, uint32_t tech, uint32_t rate)
+{
+ if (g_interface.prbs_test != NULL)
+ {
+ return g_interface.prbs_test(result, tech, rate);
+ }
+ else
+ {
+ *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;
+ DEBUG_SERVER_MSG("interface is null");
+ return false;
+ }
+}
+
+bool net_nfc_controller_test_mode_on(net_nfc_error_e *result)
+{
+ if (g_interface.test_mode_on != NULL)
+ {
+ return g_interface.test_mode_on(result);
+ }
+ else
+ {
+ *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;
+ DEBUG_SERVER_MSG("interface is null");
+ return false;
+ }
+}
+
+bool net_nfc_controller_test_mode_off(net_nfc_error_e *result)
+{
+ if (g_interface.test_mode_off != NULL)
+ {
+ return g_interface.test_mode_off(result);
+ }
+ else
+ {
+ *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;
+ DEBUG_SERVER_MSG("interface is null");
+ return false;
+ }
+}
+
+bool net_nfc_controller_support_nfc(net_nfc_error_e *result)
+{
+ if (g_interface.support_nfc != NULL)
+ {
+ return g_interface.support_nfc(result);
+ }
+ else
+ {
+ *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;
+ DEBUG_SERVER_MSG("interface is null");
+ return false;
+ }
+}
+
+bool net_nfc_controller_eedata_register_set(net_nfc_error_e *result,
+ uint32_t mode, uint32_t reg_id, data_s *data)
+{
+ if (g_interface.eedata_register_set != NULL)
+ {
+ return g_interface.eedata_register_set(result, mode, reg_id, data);
+ }
+ else
+ {
+ *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;
+ DEBUG_SERVER_MSG("interface is null");
+ return false;
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_SERVER_CONTROLLER_H__
+#define __NET_NFC_SERVER_CONTROLLER_H__
+
+#include "net_nfc_typedef_internal.h"
+
+typedef struct _socket_info_t
+{
+ net_nfc_llcp_socket_t socket;
+ net_nfc_service_llcp_cb err_cb;
+ net_nfc_service_llcp_cb work_cb;
+ void *err_param;
+ void *work_param;
+}
+socket_info_t;
+
+/* common api */
+void *net_nfc_controller_onload(void);
+bool net_nfc_controller_unload(void *handle);
+bool net_nfc_controller_init(net_nfc_error_e *result);
+bool net_nfc_controller_deinit(void);
+bool net_nfc_controller_register_listener(target_detection_listener_cb target_detection_listener, se_transaction_listener_cb se_transaction_listener, llcp_event_listener_cb llcp_event_listener, net_nfc_error_e* result);
+bool net_nfc_controller_unregister_listener(void);
+bool net_nfc_controller_support_nfc(net_nfc_error_e *result);
+bool net_nfc_controller_get_firmware_version(data_s **data, net_nfc_error_e *result);
+bool net_nfc_controller_check_firmware_version(net_nfc_error_e *result);
+bool net_nfc_controller_update_firmware(net_nfc_error_e *result);
+bool net_nfc_controller_get_stack_information(net_nfc_stack_information_s *stack_info, net_nfc_error_e *result);
+bool net_nfc_controller_configure_discovery (net_nfc_discovery_mode_e mode, net_nfc_event_filter_e config, net_nfc_error_e *result);
+bool net_nfc_controller_check_target_presence(net_nfc_target_handle_s *handle, net_nfc_error_e *result);
+bool net_nfc_controller_connect(net_nfc_target_handle_s *handle, net_nfc_error_e *result);
+bool net_nfc_controller_disconnect(net_nfc_target_handle_s *handle, net_nfc_error_e *result);
+bool net_nfc_controller_check_ndef(net_nfc_target_handle_s *handle, uint8_t *ndef_card_state, int *max_data_size, int *real_data_size, net_nfc_error_e *result);
+bool net_nfc_controller_read_ndef(net_nfc_target_handle_s *handle, data_s **data, net_nfc_error_e *result);
+bool net_nfc_controller_write_ndef(net_nfc_target_handle_s *handle, data_s *data, net_nfc_error_e *result);
+bool net_nfc_controller_make_read_only_ndef(net_nfc_target_handle_s *handle, net_nfc_error_e *result);
+bool net_nfc_controller_format_ndef(net_nfc_target_handle_s *handle, data_s *secure_key, net_nfc_error_e *result);
+bool net_nfc_controller_transceive (net_nfc_target_handle_s *handle, net_nfc_transceive_info_s *info, data_s **data, net_nfc_error_e *result);
+bool net_nfc_controller_exception_handler(void);
+bool net_nfc_controller_is_ready(net_nfc_error_e *result);
+
+/* llcp api */
+bool net_nfc_controller_llcp_config(net_nfc_llcp_config_info_s *config, net_nfc_error_e *result);
+bool net_nfc_controller_llcp_check_llcp(net_nfc_target_handle_s *handle, net_nfc_error_e *result);
+bool net_nfc_controller_llcp_activate_llcp(net_nfc_target_handle_s *handle, net_nfc_error_e *result);
+bool net_nfc_controller_llcp_create_socket(net_nfc_llcp_socket_t *socket, net_nfc_socket_type_e socketType, uint16_t miu, uint8_t rw, net_nfc_error_e *result, net_nfc_service_llcp_cb cb, void *user_param);
+bool net_nfc_controller_llcp_bind(net_nfc_llcp_socket_t socket, uint8_t service_access_point, net_nfc_error_e *result);
+bool net_nfc_controller_llcp_listen(net_nfc_target_handle_s* handle, uint8_t *service_access_name, net_nfc_llcp_socket_t socket, net_nfc_error_e *result, net_nfc_service_llcp_cb cb, void *user_param);
+bool net_nfc_controller_llcp_accept(net_nfc_llcp_socket_t socket, net_nfc_error_e *result, net_nfc_service_llcp_cb cb, void *user_param);
+bool net_nfc_controller_llcp_connect_by_url(net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, uint8_t *service_access_name, net_nfc_error_e *result, net_nfc_service_llcp_cb cb, void *user_param);
+bool net_nfc_controller_llcp_connect(net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, uint8_t service_access_point, net_nfc_error_e *result, net_nfc_service_llcp_cb cb, void *user_param);
+bool net_nfc_controller_llcp_disconnect(net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, net_nfc_error_e *result, net_nfc_service_llcp_cb cb, void *user_param);
+bool net_nfc_controller_llcp_socket_close(net_nfc_llcp_socket_t socket, net_nfc_error_e *result);
+bool net_nfc_controller_llcp_recv(net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, uint32_t max_len, net_nfc_error_e *result, net_nfc_service_llcp_cb cb, void *user_param);
+bool net_nfc_controller_llcp_send(net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, data_s *data, net_nfc_error_e *result, net_nfc_service_llcp_cb cb, void *user_param);
+bool net_nfc_controller_llcp_recv_from(net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, uint32_t max_len, net_nfc_error_e *result, net_nfc_service_llcp_cb cb, void *user_param);
+bool net_nfc_controller_llcp_send_to(net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, data_s *data, uint8_t service_access_point, net_nfc_error_e *result, net_nfc_service_llcp_cb cb, void *user_param);
+bool net_nfc_controller_llcp_reject(net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, net_nfc_error_e *result);
+bool net_nfc_controller_llcp_get_remote_config (net_nfc_target_handle_s *handle, net_nfc_llcp_config_info_s *config, net_nfc_error_e *result);
+bool net_nfc_controller_llcp_get_remote_socket_info (net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, net_nfc_llcp_socket_option_s *option, net_nfc_error_e *result);
+
+void net_nfc_controller_llcp_socket_error_cb(net_nfc_llcp_socket_t socket,
+ net_nfc_error_e result, void *data, void *user_param);
+void net_nfc_controller_llcp_incoming_cb(net_nfc_llcp_socket_t socket,
+ net_nfc_error_e result, void *data, void *user_param);
+void net_nfc_controller_llcp_connected_cb(net_nfc_llcp_socket_t socket,
+ net_nfc_error_e result, void *data, void *user_param);
+void net_nfc_controller_llcp_disconnected_cb(net_nfc_llcp_socket_t socket,
+ net_nfc_error_e result, void *data, void *user_param);
+void net_nfc_controller_llcp_received_cb(net_nfc_llcp_socket_t socket,
+ net_nfc_error_e result, void *data, void *user_param);
+void net_nfc_controller_llcp_sent_cb(net_nfc_llcp_socket_t socket,
+ net_nfc_error_e result, void *data, void *user_param);
+
+/* secure element api */
+bool net_nfc_controller_secure_element_open(net_nfc_secure_element_type_e element_type, net_nfc_target_handle_s **handle, net_nfc_error_e *result);
+bool net_nfc_controller_secure_element_get_atr(net_nfc_target_handle_s *handle, data_s **atr, net_nfc_error_e *result);
+bool net_nfc_controller_secure_element_send_apdu(net_nfc_target_handle_s *handle, data_s *command, data_s **response, net_nfc_error_e *result);
+bool net_nfc_controller_secure_element_close(net_nfc_target_handle_s *handle, net_nfc_error_e *result);
+bool net_nfc_controller_get_secure_element_list(net_nfc_secure_element_info_s* list, int* count, net_nfc_error_e* result);
+bool net_nfc_controller_set_secure_element_mode(net_nfc_secure_element_type_e element_type, net_nfc_secure_element_mode_e mode, net_nfc_error_e* result);
+
+/* test api */
+bool net_nfc_controller_sim_test(net_nfc_error_e *result);
+bool net_nfc_controller_prbs_test(net_nfc_error_e *result , uint32_t tech , uint32_t rate);
+bool net_nfc_controller_test_mode_on(net_nfc_error_e *result);
+bool net_nfc_controller_test_mode_off(net_nfc_error_e *result);
+bool net_nfc_test_sim(void);
+bool net_nfc_controller_eedata_register_set(net_nfc_error_e *result , uint32_t mode , uint32_t reg_id , data_s *data);
+
+socket_info_t *_get_socket_info(net_nfc_llcp_socket_t socket);
+socket_info_t *_add_socket_info(net_nfc_llcp_socket_t socket);
+
+#endif //__NET_NFC_SERVER_CONTROLLER_H__
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#include "net_nfc_server_common.h"
+#include "net_nfc_server_process_handover.h"
+#include "net_nfc_server_handover.h"
+#include "net_nfc_debug_internal.h"
+#include "net_nfc_server_controller.h"
+#include "net_nfc_util_gdbus_internal.h"
+#include "net_nfc_server_context.h"
+
+static NetNfcGDbusHandover *handover_skeleton = NULL;
+
+static void handover_request_thread_func(gpointer user_data);
+
+static gboolean handover_handle_request(NetNfcGDbusHandover *hdover,
+ GDBusMethodInvocation *invocation,
+ guint32 arg_handle,
+ gint32 arg_type,
+ GVariant *smack_privilege,
+ gpointer user_data);
+
+static void handover_request_thread_func(gpointer user_data)
+{
+ HandoverRequestData *handover_data;
+ net_nfc_target_handle_s *handle;
+ net_nfc_error_e error = NET_NFC_OK;
+
+ handover_data = (HandoverRequestData *)user_data;
+
+ if (handover_data == NULL)
+ {
+ DEBUG_ERR_MSG("cannot send Handover data");
+
+ return;
+ }
+
+ if (handover_data->handoverobj == NULL)
+ {
+ DEBUG_ERR_MSG("can not get Handover object");
+
+ if (handover_data->invocation)
+ {
+ g_dbus_method_invocation_return_dbus_error(
+ handover_data->invocation,
+ "org.tizen.NetNfcService.Handover.DataError",
+ "Handover invocation is NULL");
+
+ g_object_unref(handover_data->invocation);
+ }
+
+ g_free(handover_data);
+
+ return;
+ }
+
+ handle = GUINT_TO_POINTER(handover_data->handle);
+
+ if ((error = net_nfc_server_handover_default_client_start(
+ handle,
+ (void *)handover_data)) != NET_NFC_OK)
+ {
+ if (handover_data->invocation)
+ {
+ g_dbus_method_invocation_return_dbus_error(
+ handover_data->invocation,
+ "org.tizen.NetNfcService.Handover.SendError",
+ "handover operation unsuccessfull");
+
+ g_object_unref(handover_data->invocation);
+ }
+
+ g_object_unref(handover_data->handoverobj);
+ g_free(handover_data);
+ }
+}
+
+static gboolean handover_handle_request(NetNfcGDbusHandover *hdover,
+ GDBusMethodInvocation *invocation,
+ guint32 arg_handle,
+ gint32 arg_type,
+ GVariant *smack_privilege,
+ gpointer user_data)
+{
+ HandoverRequestData *data;
+
+ INFO_MSG(">>> REQUEST from [%s]",
+ g_dbus_method_invocation_get_sender(invocation));
+
+ /* check privilege and update client context */
+ if (net_nfc_server_gdbus_check_privilege(invocation,
+ smack_privilege,
+ "nfc-manager::p2p",
+ "rw") == false) {
+ DEBUG_ERR_MSG("permission denied, and finished request");
+
+ return TRUE;
+ }
+
+ data = g_new0(HandoverRequestData,1);
+ if(data == NULL)
+ {
+ DEBUG_ERR_MSG("Memory allocation failed");
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.AllocationError",
+ "Can not allocate memory");
+ return FALSE;
+ }
+
+ data->handoverobj = g_object_ref(hdover);
+ data->handle = arg_handle;
+ data->type = arg_type;
+ data->invocation = g_object_ref(invocation);
+
+ if (net_nfc_server_controller_async_queue_push(
+ handover_request_thread_func, data) == FALSE)
+ {
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.Handover.ThreadError",
+ "can not push to controller thread");
+
+ g_object_unref(data->handoverobj);
+ g_object_unref(data->invocation);
+ g_free(data);
+
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+gboolean net_nfc_server_handover_init(GDBusConnection *connection)
+{
+ GError *error = NULL;
+
+ if (handover_skeleton)
+ g_object_unref(handover_skeleton);
+
+ handover_skeleton = net_nfc_gdbus_handover_skeleton_new();
+
+ g_signal_connect(handover_skeleton,
+ "handle-request",
+ G_CALLBACK(handover_handle_request),
+ NULL);
+
+ if (g_dbus_interface_skeleton_export(
+ G_DBUS_INTERFACE_SKELETON(handover_skeleton),
+ connection,
+ "/org/tizen/NetNfcService/Handover",
+ &error) == FALSE)
+ {
+ g_error_free(error);
+ g_object_unref(handover_skeleton);
+ handover_skeleton = NULL;
+
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+void net_nfc_server_handover_deinit(void)
+{
+ if (handover_skeleton)
+ {
+ g_object_unref(handover_skeleton);
+ handover_skeleton = NULL;
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_SERVER_HANDOVER_H__
+#define __NET_NFC_SERVER_HANDOVER_H__
+
+#include <gio/gio.h>
+#include "net_nfc_gdbus.h"
+#include "net_nfc_typedef_internal.h"
+
+
+typedef struct _HandoverRequestData HandoverRequestData;
+
+struct _HandoverRequestData
+{
+ NetNfcGDbusHandover *handoverobj;
+ GDBusMethodInvocation *invocation;
+ guint32 handle;
+ gint32 type;
+ data_s *data;
+};
+
+gboolean net_nfc_server_handover_init(GDBusConnection *connection);
+
+void net_nfc_server_handover_deinit(void);
+
+
+#endif //__NET_NFC_SERVER_HANDOVER_H__
--- /dev/null
+/*
+ * Copyright (c) 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include <glib.h>
+
+#include "net_nfc_debug_internal.h"
+#include "net_nfc_util_internal.h"
+#include "net_nfc_util_handover.h"
+#include "net_nfc_util_ndef_message.h"
+#include "net_nfc_util_ndef_record.h"
+#include "net_nfc_server_llcp.h"
+#include "net_nfc_server_handover_bss.h"
+
+static int _net_nfc_handover_bss_process_carrier_record(
+ net_nfc_handover_bss_process_context_t *context);
+
+int _net_nfc_handover_bss_convert_security_type(int value)
+{
+ int retval = 0;
+ switch (value)
+ {
+ case 0x0001: /* Open */
+ retval = WIFI_SECURITY_TYPE_NONE;
+ break;
+ case 0x0002: /* WPA - Personal */
+ retval = WIFI_SECURITY_TYPE_WPA_PSK;
+ break;
+ case 0x0004: /* WPA - Shared */
+ retval = WIFI_SECURITY_TYPE_WEP;
+ break;
+ case 0x0008: /* WPA - Enterprise */
+ case 0x0010: /* WPA2 - Enterprise */
+ retval = WIFI_SECURITY_TYPE_EAP;
+ break;
+ case 0x0020: /* WPA2 - Personal */
+ retval = WIFI_SECURITY_TYPE_WPA_PSK;
+ break;
+ default:
+ DEBUG_ERR_MSG("Invalid security Type");
+ retval = 0;
+ }
+ return retval;
+}
+
+int _net_nfc_handover_bss_convert_encryption_type (int enc_type)
+{
+ int retval = 0;
+ switch (enc_type)
+ {
+ case 0x0001: /* None */
+ retval = WIFI_ENCRYPTION_TYPE_NONE;
+ break;
+ case 0x0002: /* WEP */
+ retval = WIFI_ENCRYPTION_TYPE_WEP;
+ break;
+ case 0x0004: /* TKIP */
+ retval = WIFI_ENCRYPTION_TYPE_TKIP;
+ break;
+ case 0x0008: /* AES */
+ retval = WIFI_ENCRYPTION_TYPE_AES;
+ break;
+ case 0x000C: /* TKIP + AES */
+ retval = WIFI_ENCRYPTION_TYPE_TKIP_AES_MIXED;
+ break;
+ default:
+ DEBUG_ERR_MSG("Invalid Encryption type");
+ retval = 0;
+ }
+ return retval;
+}
+
+wifi_ap_h
+_net_nfc_handover_bss_create_ap(net_nfc_carrier_config_s *config)
+{
+ wifi_ap_h ap_handle = NULL;
+ data_s temp = { NULL, 0 };
+ int err = WIFI_ERROR_NONE;
+
+ // Sets SSID
+ err = net_nfc_util_get_carrier_config_property(config,
+ NET_NFC_WIFI_ATTRIBUTE_SSID,(uint16_t *)&temp.length, &temp.buffer);
+ DEBUG_SERVER_MSG("SSID = [%s] err %d",temp.buffer, err);
+ err = wifi_ap_create((char*)temp.buffer, &ap_handle);
+ if(err != WIFI_ERROR_NONE)
+ {
+ DEBUG_ERR_MSG("Failed to create AP information %d",err);
+ goto error;
+ }
+
+ // Sets Authentication Type
+ net_nfc_util_get_carrier_config_property(config,
+ NET_NFC_WIFI_ATTRIBUTE_AUTH_TYPE,(uint16_t *)&temp.length, &temp.buffer);
+ if(temp.length == 2)
+ {
+ uint16_t securitytype = temp.buffer[0] <<8 | temp.buffer[1];
+ DEBUG_MSG("wifi_ap_set_security_type %x", securitytype);
+ err = wifi_ap_set_security_type(ap_handle,
+ _net_nfc_handover_bss_convert_security_type(securitytype));
+ if(err != WIFI_ERROR_NONE)
+ {
+ DEBUG_ERR_MSG("set security type failed");
+ goto error;
+ }
+ }
+ else
+ {
+ DEBUG_ERR_MSG("Invalid authentication length");
+ goto error;
+ }
+ net_nfc_util_get_carrier_config_property(config,
+ NET_NFC_WIFI_ATTRIBUTE_NET_KEY,(uint16_t *)&temp.length, &temp.buffer);
+
+ // Sets Network Key
+ err = wifi_ap_set_passphrase(ap_handle,(char*)temp.buffer);
+ if(err != WIFI_ERROR_NONE)
+ {
+ DEBUG_ERR_MSG("Failed to set passphrase");
+ goto error;
+ }
+ // Sets encryption Type
+ net_nfc_util_get_carrier_config_property(config,
+ NET_NFC_WIFI_ATTRIBUTE_ENC_TYPE,(uint16_t *)&temp.length, &temp.buffer);
+ if(temp.length == 2)
+ {
+ uint16_t enc_type = temp.buffer[0] <<8 | temp.buffer[1];
+ DEBUG_MSG("wifi_ap_set_encryption_type %x", enc_type);
+ err = wifi_ap_set_encryption_type(ap_handle,
+ _net_nfc_handover_bss_convert_encryption_type(enc_type));
+ }
+ else
+ {
+ DEBUG_ERR_MSG("Invalid Encryption length");
+ goto error;
+ }
+ return ap_handle;
+error:
+ if(ap_handle != NULL)
+ {
+ wifi_ap_destroy(ap_handle);
+ }
+ return NULL;
+}
+
+void
+_net_nfc_handover_bss_on_wifi_activated(wifi_error_e errorCode, void* user_data)
+{
+ net_nfc_handover_bss_process_context_t *context = user_data;
+ if(context == NULL)
+ {
+ DEBUG_ERR_MSG("Invalid context");
+ context->result = NET_NFC_OPERATION_FAIL;
+ }
+ if (errorCode == WIFI_ERROR_NONE)
+ {
+ DEBUG_ERR_MSG("WIFI activated succesfully");
+ context->result = NET_NFC_OK;
+ }
+ else
+ {
+ DEBUG_ERR_MSG("Failed to activate WIFI");
+ context->result = NET_NFC_OPERATION_FAIL;
+ }
+}
+
+bool
+_net_nfc_handover_bss_wifi_for_each_access_point_found(
+ wifi_ap_h ap_handle, void *user_data)
+{
+ data_s temp_ssid = { NULL, 0 };
+ int err = WIFI_ERROR_NONE;
+ char* essid = NULL;
+ net_nfc_handover_bss_process_context_t *context = user_data;
+
+ if(context == NULL)
+ {
+ DEBUG_ERR_MSG("Invalid context");
+ context->result = NET_NFC_OPERATION_FAIL;
+ context->step = NET_NFC_LLCP_STEP_RETURN;
+ g_idle_add(
+ (GSourceFunc)_net_nfc_handover_bss_process_carrier_record,
+ (gpointer)context);
+ return false;
+ }
+
+ wifi_ap_clone(&context->ap_handle, ap_handle);
+ err = net_nfc_util_get_carrier_config_property(context->config,
+ NET_NFC_WIFI_ATTRIBUTE_SSID,(uint16_t *)&temp_ssid.length,
+ &temp_ssid.buffer);
+
+ if(err != WIFI_ERROR_NONE)
+ {
+ DEBUG_ERR_MSG("Wifi get carrier config failed");
+ context->result = NET_NFC_OPERATION_FAIL;
+ context->step = NET_NFC_LLCP_STEP_RETURN;
+ g_idle_add(
+ (GSourceFunc)_net_nfc_handover_bss_process_carrier_record,
+ (gpointer)context);
+ return false;
+ }
+
+ wifi_ap_get_essid(ap_handle, &essid);
+ DEBUG_MSG("Scan Result Ap essid [%s]",essid);
+ if(memcmp(temp_ssid.buffer, essid,temp_ssid.length) == 0)
+ {
+ return false;
+ }
+ else
+ {
+ wifi_ap_destroy(context->ap_handle);
+ context->ap_handle = NULL;
+ }
+ return true;
+}
+
+void
+_net_nfc_handover_bss_on_wifi_bgscan_completed(wifi_error_e errorCode,
+ void* user_data)
+{
+ int err = WIFI_ERROR_NONE;
+ net_nfc_handover_bss_process_context_t *context = user_data;
+
+ if(context == NULL)
+ {
+ DEBUG_ERR_MSG("Invalid context");
+ context->result = NET_NFC_OPERATION_FAIL;
+ context->step = NET_NFC_LLCP_STEP_RETURN;
+ g_idle_add(
+ (GSourceFunc)_net_nfc_handover_bss_process_carrier_record,
+ (gpointer)context);
+ return false;
+ }
+
+ if(errorCode != WIFI_ERROR_NONE)
+ {
+ DEBUG_ERR_MSG("Wifi scan failed");
+ context->result = NET_NFC_OPERATION_FAIL;
+ context->step = NET_NFC_LLCP_STEP_RETURN;
+ g_idle_add(
+ (GSourceFunc)_net_nfc_handover_bss_process_carrier_record,
+ (gpointer)context);
+ }
+ else
+ {
+ net_nfc_util_create_carrier_config_from_config_record(
+ &context->config, context->carrier);
+ context->ap_handle = NULL;
+ err = wifi_foreach_found_aps(
+ _net_nfc_handover_bss_wifi_for_each_access_point_found,
+ context);
+ if(err != WIFI_ERROR_NONE)
+ {
+ DEBUG_ERR_MSG("wifi_foreach_found_aps failed Err[%x]",err);
+ context->result = NET_NFC_OPERATION_FAIL;
+ context->step = NET_NFC_LLCP_STEP_RETURN;
+ g_idle_add(
+ (GSourceFunc)_net_nfc_handover_bss_process_carrier_record,
+ (gpointer)context);
+ }
+ if(context->ap_handle == NULL)
+ {
+ wifi_encryption_type_e enc_type;
+ wifi_security_type_e sec_type;
+ DEBUG_MSG("It's Hidden AP");
+ context->ap_handle = _net_nfc_handover_bss_create_ap(
+ context->config);
+ wifi_ap_get_encryption_type(context->ap_handle, &enc_type);
+ DEBUG_MSG("Encryption type %x",enc_type);
+ wifi_ap_get_security_type(context->ap_handle, &sec_type);
+ DEBUG_MSG("Authentication type %x", sec_type);
+ }
+ else
+ {
+ data_s temp = { NULL, 0 };
+ wifi_encryption_type_e enc_type = WIFI_ENCRYPTION_TYPE_NONE;
+ wifi_security_type_e sec_type = WIFI_SECURITY_TYPE_NONE;
+ //set passkey
+ net_nfc_util_get_carrier_config_property(context->config,
+ NET_NFC_WIFI_ATTRIBUTE_NET_KEY,(uint16_t *)&temp.length,
+ &temp.buffer);
+
+ DEBUG_ERR_MSG("Network Key %s",temp.buffer);
+ // Sets Network Key
+ err = wifi_ap_set_passphrase(context->ap_handle,
+ (char*)temp.buffer);
+
+ wifi_ap_get_encryption_type(context->ap_handle, &enc_type);
+ DEBUG_MSG("Encryption type %x",enc_type);
+ wifi_ap_get_security_type(context->ap_handle, &sec_type);
+ DEBUG_MSG("Authentication type %x", sec_type);
+ }
+ context->step = NET_NFC_LLCP_STEP_03;
+ g_idle_add(
+ (GSourceFunc)_net_nfc_handover_bss_process_carrier_record,
+ (gpointer)context);
+
+ }
+}
+
+void
+_net_nfc_handover_bss_on_wifi_scan_completed(wifi_error_e errorCode,
+ void* user_data)
+{
+ int err = WIFI_ERROR_NONE;
+ net_nfc_handover_bss_process_context_t *context = user_data;
+
+ if(context == NULL)
+ {
+ DEBUG_ERR_MSG("Invalid context");
+ context->result = NET_NFC_OPERATION_FAIL;
+ context->step = NET_NFC_LLCP_STEP_RETURN;
+ g_idle_add(
+ (GSourceFunc)_net_nfc_handover_bss_process_carrier_record,
+ (gpointer)context);
+ return false;
+ }
+
+ if(errorCode != WIFI_ERROR_NONE)
+ {
+ DEBUG_ERR_MSG("Wifi scan failed");
+ context->result = NET_NFC_OPERATION_FAIL;
+ context->step = NET_NFC_LLCP_STEP_RETURN;
+ g_idle_add(
+ (GSourceFunc)_net_nfc_handover_bss_process_carrier_record,
+ (gpointer)context);
+ }
+ else
+ {
+ net_nfc_util_create_carrier_config_from_config_record(
+ &context->config, context->carrier);
+ context->ap_handle = NULL;
+ err = wifi_foreach_found_aps(
+ _net_nfc_handover_bss_wifi_for_each_access_point_found,
+ context);
+ if(err != WIFI_ERROR_NONE)
+ {
+ DEBUG_ERR_MSG("wifi_foreach_found_aps failed Err[%x]",err);
+ context->result = NET_NFC_OPERATION_FAIL;
+ context->step = NET_NFC_LLCP_STEP_RETURN;
+ g_idle_add(
+ (GSourceFunc)_net_nfc_handover_bss_process_carrier_record,
+ (gpointer)context);
+
+ }
+ if(context->ap_handle == NULL)
+ {
+ wifi_encryption_type_e enc_type;
+ wifi_security_type_e sec_type;
+ DEBUG_MSG("It's Hidden AP");
+ context->ap_handle = _net_nfc_handover_bss_create_ap(
+ context->config);
+ wifi_ap_get_encryption_type(context->ap_handle, &enc_type);
+ DEBUG_MSG("Encryption type %x",enc_type);
+ wifi_ap_get_security_type(context->ap_handle, &sec_type);
+ DEBUG_MSG("Authentication type %x", sec_type);
+ }
+ else
+ {
+ data_s temp = { NULL, 0 };
+ wifi_encryption_type_e enc_type = WIFI_ENCRYPTION_TYPE_NONE;
+ wifi_security_type_e sec_type = WIFI_SECURITY_TYPE_NONE;
+ //set passkey
+ net_nfc_util_get_carrier_config_property(context->config,
+ NET_NFC_WIFI_ATTRIBUTE_NET_KEY,(uint16_t *)&temp.length,
+ &temp.buffer);
+
+ DEBUG_ERR_MSG("Network Key %s",temp.buffer);
+ // Sets Network Key
+ err = wifi_ap_set_passphrase(context->ap_handle,(char*)temp.buffer);
+
+ wifi_ap_get_encryption_type(context->ap_handle, &enc_type);
+ DEBUG_MSG("Encryption type %x",enc_type);
+ wifi_ap_get_security_type(context->ap_handle, &sec_type);
+ DEBUG_MSG("Authentication type %x", sec_type);
+ }
+ context->step = NET_NFC_LLCP_STEP_03;
+ g_idle_add(
+ (GSourceFunc)_net_nfc_handover_bss_process_carrier_record,
+ (gpointer)context);
+
+ }
+
+}
+
+void
+_net_nfc_handover_bss_on_wifi_connected(wifi_error_e errorCode, void* user_data)
+{
+ net_nfc_handover_bss_process_context_t *context = user_data;
+
+ if(context == NULL)
+ {
+ DEBUG_ERR_MSG("Invalid context");
+ context->result = NET_NFC_OPERATION_FAIL;
+ context->step = NET_NFC_LLCP_STEP_RETURN;
+ g_idle_add(
+ (GSourceFunc)_net_nfc_handover_bss_process_carrier_record,
+ (gpointer)context);
+ return false;
+ }
+
+ if(errorCode == WIFI_ERROR_NONE)
+ {
+ DEBUG_ERR_MSG("WIFI Connected succesfully");
+ context->result = NET_NFC_OK;
+ }
+ else
+ {
+ DEBUG_ERR_MSG("Failed to connect WIFI");
+ context->result = NET_NFC_OPERATION_FAIL;
+ }
+ context->step = NET_NFC_LLCP_STEP_RETURN;
+ g_idle_add(
+ (GSourceFunc)_net_nfc_handover_bss_process_carrier_record,
+ (gpointer)context);
+}
+
+static int _net_nfc_handover_bss_process_carrier_record(
+ net_nfc_handover_bss_process_context_t *context)
+{
+ LOGD("[%s:%d] START", __func__, __LINE__);
+
+ if(context == NULL)
+ {
+ DEBUG_ERR_MSG("Invalid context");
+ DEBUG_ERR_MSG("Handover Failed");
+ return -1;
+ }
+
+ if (context->result != NET_NFC_OK && context->result != NET_NFC_BUSY)
+ {
+ DEBUG_ERR_MSG("context->result is error"
+ " [%d]", context->result);
+ context->step = NET_NFC_LLCP_STEP_RETURN;
+ }
+
+ switch (context->step)
+ {
+ case NET_NFC_LLCP_STEP_01 :
+ {
+ int err = WIFI_ERROR_NONE;
+ DEBUG_MSG("STEP [1]");
+ err = wifi_initialize();
+ /* WIFI returns WIFI_ERROR_INVALID_OPERATION in case already
+ * initialized*/
+ if (err == WIFI_ERROR_NONE || err == WIFI_ERROR_INVALID_OPERATION)
+ {
+ bool val = false;
+
+ err = wifi_is_activated(&val);
+ /* next step */
+
+ if (val == false)
+ {
+ context->result = NET_NFC_OK;
+ wifi_set_background_scan_cb(
+ _net_nfc_handover_bss_on_wifi_bgscan_completed, context);
+ wifi_activate(
+ _net_nfc_handover_bss_on_wifi_activated, context);
+ }
+ else
+ {
+ /* do next step */
+ DEBUG_MSG("Wifi is enabled already, go next step");
+ context->result = NET_NFC_OK;
+ context->step = NET_NFC_LLCP_STEP_02;
+ g_idle_add((GSourceFunc)
+ _net_nfc_handover_bss_process_carrier_record,
+ (gpointer)context);
+ }
+ }
+ else
+ {
+ DEBUG_ERR_MSG("Wifi init failed");
+ context->result = NET_NFC_OPERATION_FAIL;
+ context->step = NET_NFC_LLCP_STEP_RETURN;
+ g_idle_add(
+ (GSourceFunc)_net_nfc_handover_bss_process_carrier_record,
+ (gpointer)context);
+ }
+ }
+ break;
+
+ case NET_NFC_LLCP_STEP_02 :
+ {
+
+ int err = WIFI_ERROR_NONE;
+ DEBUG_MSG("STEP [2]");
+ err = wifi_scan(_net_nfc_handover_bss_on_wifi_scan_completed,
+ context);
+ if(err != WIFI_ERROR_NONE)
+ {
+ DEBUG_ERR_MSG("Wifi scan failed");
+ context->result = NET_NFC_OPERATION_FAIL;
+ context->step = NET_NFC_LLCP_STEP_RETURN;
+ g_idle_add(
+ (GSourceFunc)_net_nfc_handover_bss_process_carrier_record,
+ (gpointer)context);
+ }
+ }
+
+ break;
+ case NET_NFC_LLCP_STEP_03 :
+ {
+ DEBUG_MSG("Connect with WIFI");
+ int err = wifi_connect(context->ap_handle,
+ _net_nfc_handover_bss_on_wifi_connected, context);
+ DEBUG_MSG("Connect with WIFI err [%x]",err);
+ if(err != WIFI_ERROR_NONE)
+ {
+ DEBUG_ERR_MSG("Wifi Connect failed");
+ context->result = NET_NFC_OPERATION_FAIL;
+ context->step = NET_NFC_LLCP_STEP_RETURN;
+ g_idle_add(
+ (GSourceFunc)_net_nfc_handover_bss_process_carrier_record,
+ (gpointer)context);
+ }
+ }
+ break;
+ case NET_NFC_LLCP_STEP_RETURN :
+ {
+ DEBUG_MSG("STEP return");
+ if(context->result == NET_NFC_OK)
+ {
+ DEBUG_MSG("Handover completed succesfully");
+ }
+ else
+ {
+ DEBUG_ERR_MSG("Handover Failed");
+ }
+ wifi_deinitialize();
+ }
+ break;
+
+ default :
+ break;
+ }
+
+ LOGD("[%s:%d] END", __func__, __LINE__);
+
+ return 0;
+}
+
+net_nfc_error_e net_nfc_server_handover_bss_process_carrier_record(
+ ndef_record_s *record,
+ net_nfc_server_handover_process_carrier_record_cb cb,
+ void *user_param)
+{
+ net_nfc_error_e result = NET_NFC_OK;
+ net_nfc_handover_bss_process_context_t *context = NULL;
+
+ _net_nfc_util_alloc_mem(context, sizeof(*context));
+ if (context != NULL)
+ {
+ context->cb = cb;
+ context->user_param = user_param;
+ context->step = NET_NFC_LLCP_STEP_01;
+ net_nfc_util_create_record(record->TNF, &record->type_s,
+ &record->id_s, &record->payload_s, &context->carrier);
+
+ g_idle_add(
+ (GSourceFunc)_net_nfc_handover_bss_process_carrier_record,
+ (gpointer)context);
+ }
+ else
+ {
+ result = NET_NFC_ALLOC_FAIL;
+ }
+
+ return result;
+}
--- /dev/null
+/*
+ * Copyright (c) 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_SERVER_HANDOVER_BSS_H__
+#define __NET_NFC_SERVER_HANDOVER_BSS_H__
+
+#include <wifi.h>
+
+#include "net_nfc_typedef_internal.h"
+#include "net_nfc_server_handover_bt.h"
+
+typedef struct _net_nfc_handover_bss_process_context_t
+{
+ int step;
+ net_nfc_error_e result;
+ net_nfc_server_handover_process_carrier_record_cb cb;
+ ndef_record_s *carrier;
+ data_s data;
+ void *user_param;
+ wifi_ap_h ap_handle;
+ net_nfc_carrier_config_s *config;
+}
+net_nfc_handover_bss_process_context_t;
+
+net_nfc_error_e net_nfc_server_handover_bss_process_carrier_record(
+ ndef_record_s *record,
+ net_nfc_server_handover_process_carrier_record_cb cb,
+ void *user_param);
+
+#endif //__NET_NFC_SERVER_HANDOVER_BSS_H__
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "bluetooth-api.h"
+#include "net_nfc_debug_internal.h"
+#include "net_nfc_util_internal.h"
+#include "net_nfc_util_ndef_message.h"
+#include "net_nfc_util_ndef_record.h"
+#include "net_nfc_util_handover.h"
+#include "net_nfc_server_handover_bt.h"
+#include "net_nfc_server_llcp.h"
+
+
+typedef struct _net_nfc_handover_bt_get_context_t
+{
+ int step;
+ net_nfc_error_e result;
+ net_nfc_conn_handover_carrier_state_e cps;
+ net_nfc_server_handover_get_carrier_record_cb cb;
+ ndef_record_s *carrier;
+ uint32_t aux_data_count;
+ ndef_record_s *aux_data;
+ void *user_param;
+}
+net_nfc_handover_bt_get_context_t;
+
+typedef struct _net_nfc_handover_bt_process_context_t
+{
+ int step;
+ net_nfc_error_e result;
+ net_nfc_server_handover_process_carrier_record_cb cb;
+ ndef_record_s *carrier;
+ data_s data;
+ bluetooth_device_address_t addr;
+ void *user_param;
+}
+net_nfc_handover_bt_process_context_t;
+
+
+static int _net_nfc_handover_bt_get_carrier_record(
+ net_nfc_handover_bt_get_context_t *context);
+static int _net_nfc_handover_bt_process_carrier_record(
+ net_nfc_handover_bt_process_context_t *context);
+
+
+static net_nfc_error_e _net_nfc_handover_bt_get_oob_data(
+ net_nfc_carrier_config_s *config,
+ bt_oob_data_t *oob)
+{
+ net_nfc_error_e result = NET_NFC_UNKNOWN_ERROR;
+ data_s hash = { NULL, 0 };
+ data_s randomizer = { NULL, 0 };
+
+ LOGD("[%s:%d] START", __func__, __LINE__);
+
+ if (config == NULL || oob == NULL)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ memset(oob, 0, sizeof(bt_oob_data_t));
+
+ if ((result = net_nfc_util_get_carrier_config_property(
+ config,
+ NET_NFC_BT_ATTRIBUTE_OOB_HASH_C,
+ (uint16_t *)&hash.length,
+ &hash.buffer)) == NET_NFC_OK)
+ {
+ if (hash.length == 16)
+ {
+ DEBUG_MSG("hash.length == 16");
+
+ NET_NFC_REVERSE_ORDER_16_BYTES(hash.buffer);
+
+ oob->hash_len = MIN(sizeof(oob->hash), hash.length);
+ memcpy(oob->hash, hash.buffer, oob->hash_len);
+ }
+ else
+ {
+ DEBUG_ERR_MSG("hash.length error : [%d] bytes", hash.length);
+ }
+ }
+
+ if ((result = net_nfc_util_get_carrier_config_property(
+ config,
+ NET_NFC_BT_ATTRIBUTE_OOB_HASH_R,
+ (uint16_t *)&randomizer.length,
+ &randomizer.buffer)) == NET_NFC_OK)
+ {
+ if (randomizer.length == 16)
+ {
+ DEBUG_MSG("randomizer.length == 16");
+
+ NET_NFC_REVERSE_ORDER_16_BYTES(randomizer.buffer);
+
+ oob->randomizer_len = MIN(sizeof(oob->randomizer), randomizer.length);
+ memcpy(oob->randomizer, randomizer.buffer, oob->randomizer_len);
+ }
+ else
+ {
+ DEBUG_ERR_MSG("randomizer.length error :"
+ " [%d] bytes", randomizer.length);
+ }
+ }
+
+ LOGD("[%s:%d] END", __func__, __LINE__);
+
+ return result;
+}
+
+static void _net_nfc_handover_bt_get_carrier_config_cb(
+ int event,
+ bluetooth_event_param_t *param,
+ void *user_data)
+{
+ net_nfc_handover_bt_get_context_t *context =
+ (net_nfc_handover_bt_get_context_t *)user_data;
+
+ LOGD("[%s] START", __func__);
+
+ if (context == NULL)
+ {
+ DEBUG_SERVER_MSG("user_data is null");
+ LOGD("[%s] END", __func__);
+ return;
+ }
+
+ switch (event)
+ {
+ case BLUETOOTH_EVENT_ENABLED :
+ DEBUG_SERVER_MSG("BLUETOOTH_EVENT_ENABLED");
+ if (context->step == NET_NFC_LLCP_STEP_02)
+ {
+ _net_nfc_handover_bt_get_carrier_record(context);
+ }
+ else
+ {
+ DEBUG_SERVER_MSG("step is incorrect");
+ }
+ break;
+
+ case BLUETOOTH_EVENT_DISABLED :
+ DEBUG_SERVER_MSG("BLUETOOTH_EVENT_DISABLED");
+ break;
+
+ default :
+ DEBUG_SERVER_MSG("unhandled bt event [%d],"
+ "[0x%04x]", event, param->result);
+ break;
+ }
+
+ LOGD("[%s] END", __func__);
+}
+
+static net_nfc_error_e _net_nfc_handover_bt_create_config_record(
+ ndef_record_s **record)
+{
+ bluetooth_device_address_t bt_addr = { { 0, } };
+ net_nfc_carrier_config_s *config = NULL;
+ net_nfc_error_e result;
+
+ /* append config to ndef message */
+ if ((result = bluetooth_get_local_address(&bt_addr))
+ == BLUETOOTH_ERROR_NONE)
+ {
+ if ((result = net_nfc_util_create_carrier_config(
+ &config,
+ NET_NFC_CONN_HANDOVER_CARRIER_BT)) == NET_NFC_OK)
+ {
+ bt_oob_data_t oob = { { 0 }, };
+
+ NET_NFC_REVERSE_ORDER_6_BYTES(bt_addr.addr);
+
+ if ((result = net_nfc_util_add_carrier_config_property(
+ config,
+ NET_NFC_BT_ATTRIBUTE_ADDRESS,
+ sizeof(bt_addr.addr), bt_addr.addr)) != NET_NFC_OK)
+ {
+ DEBUG_ERR_MSG("net_nfc_util_add_carrier"
+ "_config_property failed"
+ "[%d]", result);
+ }
+
+ /* get oob data */
+ if (bluetooth_oob_read_local_data(&oob) == BLUETOOTH_ERROR_NONE)
+ {
+ if (oob.hash_len == 16 && oob.randomizer_len == 16)
+ {
+ DEBUG_SERVER_MSG("oob.hash_len "
+ "[%d]", oob.hash_len);
+ DEBUG_SERVER_MSG("oob.randomizer_len"
+ " [%d]", oob.randomizer_len);
+
+ NET_NFC_REVERSE_ORDER_16_BYTES(oob.hash);
+
+ if ((result =
+ net_nfc_util_add_carrier_config_property(
+ config,
+ NET_NFC_BT_ATTRIBUTE_OOB_HASH_C,
+ oob.hash_len, oob.hash)) != NET_NFC_OK)
+ {
+ DEBUG_ERR_MSG("net_nfc_util_add_carrier"
+ "_config_property failed"
+ " [%d]",result);
+ }
+
+ NET_NFC_REVERSE_ORDER_16_BYTES(oob.randomizer);
+
+ if ((result = net_nfc_util_add_carrier_config_property(
+ config,
+ NET_NFC_BT_ATTRIBUTE_OOB_HASH_R,
+ oob.randomizer_len,
+ oob.randomizer)) != NET_NFC_OK)
+ {
+ DEBUG_ERR_MSG("net_nfc_util_add_carrier"
+ "_config_property failed"
+ " [%d]",result);
+ }
+ }
+ else
+ {
+ DEBUG_ERR_MSG("abnormal oob data, skip... [%d]", result);
+ }
+ }
+
+ if ((result = net_nfc_util_create_ndef_record_with_carrier_config(
+ record,
+ config)) != NET_NFC_OK)
+ {
+ DEBUG_ERR_MSG("net_nfc_util_create_ndef_record"
+ "_with_carrier_config failed"
+ "[%d]",result);
+ }
+
+ net_nfc_util_free_carrier_config(config);
+ }
+ else
+ {
+ DEBUG_ERR_MSG("net_nfc_util_create_carrier_config failed "
+ "[%d]", result);
+ }
+ }
+ else
+ {
+ DEBUG_ERR_MSG("bluetooth_get_local_address failed"
+ " [%d]", result);
+ result = NET_NFC_OPERATION_FAIL;
+ }
+
+ return result;
+}
+
+static int _net_nfc_handover_bt_get_carrier_record(
+ net_nfc_handover_bt_get_context_t *context)
+{
+ LOGD("[%s:%d] START", __func__, __LINE__);
+
+ if (context->result != NET_NFC_OK && context->result != NET_NFC_BUSY)
+ {
+ DEBUG_ERR_MSG("context->result is error"
+ " [%d]", context->result);
+
+ context->step = NET_NFC_LLCP_STEP_RETURN;
+ }
+
+ switch (context->step)
+ {
+ case NET_NFC_LLCP_STEP_01 :
+ DEBUG_MSG("STEP [1]");
+
+ if (bluetooth_register_callback(
+ _net_nfc_handover_bt_get_carrier_config_cb,
+ context) >= BLUETOOTH_ERROR_NONE)
+ {
+ context->step = NET_NFC_LLCP_STEP_02;
+ context->result = NET_NFC_OK;
+
+ if (bluetooth_check_adapter() != BLUETOOTH_ADAPTER_ENABLED)
+ {
+ bluetooth_enable_adapter();
+ }
+ else
+ {
+ DEBUG_MSG("bluetooth is enabled already");
+
+ /* do next step */
+ g_idle_add((GSourceFunc)
+ _net_nfc_handover_bt_get_carrier_record,
+ (gpointer)context);
+ }
+ }
+ else
+ {
+ DEBUG_ERR_MSG("bluetooth_register_callback failed");
+
+ context->step = NET_NFC_LLCP_STEP_RETURN;
+ context->result = NET_NFC_OPERATION_FAIL;
+
+ g_idle_add((GSourceFunc)
+ _net_nfc_handover_bt_get_carrier_record,
+ (gpointer)context);
+ }
+ break;
+
+ case NET_NFC_LLCP_STEP_02 :
+ DEBUG_MSG("STEP [2]");
+
+ context->step = NET_NFC_LLCP_STEP_RETURN;
+
+ /* append config to ndef message */
+ if ((context->result =
+ _net_nfc_handover_bt_create_config_record(
+ &context->carrier)) != NET_NFC_OK)
+ {
+ DEBUG_ERR_MSG("_ch_create_bt_config_record failed"
+ "[%d]", context->result);
+ }
+
+ /* complete and return to upper step */
+ g_idle_add((GSourceFunc)
+ _net_nfc_handover_bt_get_carrier_record,
+ (gpointer)context);
+ break;
+
+ case NET_NFC_LLCP_STEP_RETURN :
+ DEBUG_MSG("STEP return");
+
+ /* unregister current callback */
+ bluetooth_unregister_callback();
+
+ /* complete and return to upper step */
+ context->cb(context->result,
+ context->cps,
+ context->carrier,
+ context->aux_data_count,
+ context->aux_data,
+ context->user_param);
+ break;
+
+ default :
+ break;
+ }
+
+ LOGD("[%s:%d] END", __func__, __LINE__);
+
+ return 0;
+}
+
+net_nfc_error_e net_nfc_server_handover_bt_get_carrier_record(
+ net_nfc_server_handover_get_carrier_record_cb cb,
+ void *user_param)
+{
+ net_nfc_error_e result = NET_NFC_OK;
+ net_nfc_handover_bt_get_context_t *context = NULL;
+
+ _net_nfc_util_alloc_mem(context, sizeof(*context));
+ if (context != NULL)
+ {
+ context->cb = cb;
+ context->user_param = user_param;
+ context->step = NET_NFC_LLCP_STEP_01;
+ /* TODO : check cps of bt */
+ context->cps = NET_NFC_CONN_HANDOVER_CARRIER_ACTIVATE;
+
+ g_idle_add((GSourceFunc)_net_nfc_handover_bt_get_carrier_record,
+ (gpointer)context);
+ }
+ else
+ {
+ result = NET_NFC_ALLOC_FAIL;
+ }
+
+ return result;
+}
+
+static bool _net_nfc_handover_bt_check_bond_device(
+ bluetooth_device_address_t *address)
+{
+ bool result = false;
+ int ret;
+ GPtrArray *devinfo = NULL;
+
+ LOGD("[%s] START", __func__);
+
+ /* allocate the g_pointer_array */
+ devinfo = g_ptr_array_new();
+
+ ret = bluetooth_get_bonded_device_list(&devinfo);
+ if (ret == BLUETOOTH_ERROR_NONE)
+ {
+ int i;
+ bluetooth_device_info_t *ptr;
+
+ DEBUG_SERVER_MSG("g pointer array count :"
+ " [%d]", devinfo->len);
+
+ for (i = 0; i < devinfo->len; i++)
+ {
+ ptr = g_ptr_array_index(devinfo, i);
+ if (ptr != NULL)
+ {
+ SECURE_LOGD("Name [%s]", ptr->device_name.name);
+ DEBUG_SERVER_MSG("Major Class [%d]",
+ ptr->device_class.major_class);
+ DEBUG_SERVER_MSG("Minor Class [%d]",
+ ptr->device_class.minor_class);
+ DEBUG_SERVER_MSG("Service Class [%d]",
+ ptr->device_class.service_class);
+ DEBUG_SERVER_MSG("%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X",
+ ptr->device_address.addr[0],
+ ptr->device_address.addr[1],
+ ptr->device_address.addr[2],
+ ptr->device_address.addr[3],
+ ptr->device_address.addr[4],
+ ptr->device_address.addr[5]);
+
+ /* compare selector address */
+ if (memcmp(&(ptr->device_address),
+ address,
+ sizeof(ptr->device_address)) == 0)
+ {
+ DEBUG_SERVER_MSG("Found!!!");
+ result = true;
+ break;
+ }
+ }
+ }
+ }
+ else
+ {
+ DEBUG_ERR_MSG("bluetooth_get_bonded_device_list failed with"
+ " [%d]", ret);
+ }
+
+ /* free g_pointer_array */
+ g_ptr_array_free(devinfo, TRUE);
+
+ LOGD("[%s] END", __func__);
+
+ return result;
+}
+
+static void _net_nfc_handover_bt_process_carrier_record_cb(
+ int event,
+ bluetooth_event_param_t *param,
+ void *user_data)
+{
+ net_nfc_handover_bt_process_context_t *context =
+ (net_nfc_handover_bt_process_context_t *)user_data;
+
+ LOGD("[%s] START", __func__);
+
+ if (context == NULL)
+ {
+ DEBUG_SERVER_MSG("user_data is null");
+ LOGD("[%s] END", __func__);
+ return;
+ }
+
+ switch (event)
+ {
+ case BLUETOOTH_EVENT_ENABLED :
+ DEBUG_SERVER_MSG("BLUETOOTH_EVENT_ENABLED");
+ if (context->step == NET_NFC_LLCP_STEP_02)
+ {
+ _net_nfc_handover_bt_process_carrier_record(context);
+ }
+ else
+ {
+ DEBUG_SERVER_MSG("step is incorrect");
+ }
+ break;
+
+ case BLUETOOTH_EVENT_DISABLED :
+ DEBUG_SERVER_MSG("BLUETOOTH_EVENT_DISABLED");
+ break;
+
+ case BLUETOOTH_EVENT_BONDING_FINISHED :
+ DEBUG_SERVER_MSG("BLUETOOTH_EVENT_BONDING_FINISHED, result "
+ "[0x%04x]", param->result);
+ if (context->step == NET_NFC_LLCP_STEP_03)
+ {
+ if (param->result < BLUETOOTH_ERROR_NONE)
+ {
+ DEBUG_ERR_MSG("bond failed");
+ context->result = NET_NFC_OPERATION_FAIL;
+ }
+
+ _net_nfc_handover_bt_process_carrier_record(context);
+ }
+ else
+ {
+ DEBUG_SERVER_MSG("step is incorrect");
+ }
+ break;
+
+ default :
+ DEBUG_SERVER_MSG("unhandled bt event [%d],"
+ "[0x%04x]", event, param->result);
+ break;
+ }
+
+ LOGD("[%s] END", __func__);
+}
+
+static int _net_nfc_handover_bt_process_carrier_record(
+ net_nfc_handover_bt_process_context_t *context)
+{
+ LOGD("[%s:%d] START", __func__, __LINE__);
+
+ if (context->result != NET_NFC_OK && context->result != NET_NFC_BUSY)
+ {
+ DEBUG_ERR_MSG("context->result is error"
+ " [%d]", context->result);
+ context->step = NET_NFC_LLCP_STEP_RETURN;
+ }
+
+ switch (context->step)
+ {
+ case NET_NFC_LLCP_STEP_01 :
+ DEBUG_MSG("STEP [1]");
+
+ if (bluetooth_register_callback(
+ _net_nfc_handover_bt_process_carrier_record_cb,
+ context) >= BLUETOOTH_ERROR_NONE)
+ {
+ /* next step */
+ context->step = NET_NFC_LLCP_STEP_02;
+
+ if (bluetooth_check_adapter() != BLUETOOTH_ADAPTER_ENABLED)
+ {
+ context->result = NET_NFC_OK;
+ bluetooth_enable_adapter();
+ }
+ else
+ {
+ /* do next step */
+ DEBUG_MSG("BT is enabled already, go next step");
+ context->result = NET_NFC_OK;
+
+ g_idle_add((GSourceFunc)
+ _net_nfc_handover_bt_process_carrier_record,
+ (gpointer)context);
+ }
+ }
+ else
+ {
+ DEBUG_ERR_MSG("bluetooth_register_callback failed");
+ context->result = NET_NFC_OPERATION_FAIL;
+
+ g_idle_add(
+ (GSourceFunc)_net_nfc_handover_bt_process_carrier_record,
+ (gpointer)context);
+ }
+ break;
+
+ case NET_NFC_LLCP_STEP_02 :
+ {
+ net_nfc_carrier_config_s *config;
+ data_s temp = { NULL, 0 };
+
+ DEBUG_MSG("STEP [2]");
+
+ net_nfc_util_create_carrier_config_from_config_record(
+ &config,
+ context->carrier);
+
+ net_nfc_util_get_carrier_config_property(config,
+ NET_NFC_BT_ATTRIBUTE_ADDRESS,
+ (uint16_t *)&temp.length, &temp.buffer);
+
+ if (temp.length == 6)
+ {
+ NET_NFC_REVERSE_ORDER_6_BYTES(temp.buffer);
+
+ memcpy(context->addr.addr,
+ temp.buffer,
+ MIN(sizeof(context->addr.addr),
+ temp.length));
+
+ if (_net_nfc_handover_bt_check_bond_device
+ (&context->addr) == true)
+ {
+ DEBUG_SERVER_MSG("already paired with"
+ " [%02x:%02x:%02x:%02x:%02x:%02x]",
+ context->addr.addr[0],
+ context->addr.addr[1],
+ context->addr.addr[2],
+ context->addr.addr[3],
+ context->addr.addr[4],
+ context->addr.addr[5]);
+
+ /* return */
+ context->step = NET_NFC_LLCP_STEP_RETURN;
+ context->result = NET_NFC_OK;
+ }
+ else
+ {
+ bt_oob_data_t oob = { { 0 } , };
+
+ if (_net_nfc_handover_bt_get_oob_data(
+ config,
+ &oob) == NET_NFC_OK)
+ {
+ /* set oob data */
+ bluetooth_oob_add_remote_data(
+ &context->addr,
+ &oob);
+ }
+
+ /* pair and send reponse */
+ context->result = NET_NFC_OK;
+ context->step = NET_NFC_LLCP_STEP_RETURN;
+ }
+ }
+ else
+ {
+ DEBUG_ERR_MSG("bluetooth address is invalid."
+ " [%d] bytes", temp.length);
+
+ context->step = NET_NFC_LLCP_STEP_RETURN;
+ context->result = NET_NFC_OPERATION_FAIL;
+ }
+
+ net_nfc_util_free_carrier_config(config);
+
+ g_idle_add(
+ (GSourceFunc)_net_nfc_handover_bt_process_carrier_record,
+ (gpointer)context);
+ }
+ break;
+
+ case NET_NFC_LLCP_STEP_RETURN :
+ {
+ DEBUG_MSG("STEP return");
+ data_s data = { context->addr.addr,
+ sizeof(context->addr.addr) };
+
+ /* unregister bluetooth callback */
+ bluetooth_unregister_callback();
+
+ context->cb(context->result,
+ NET_NFC_CONN_HANDOVER_CARRIER_BT,
+ &data,
+ context->user_param);
+ }
+ break;
+
+ default :
+ break;
+ }
+
+ LOGD("[%s:%d] END", __func__, __LINE__);
+
+ return 0;
+}
+
+net_nfc_error_e net_nfc_server_handover_bt_process_carrier_record(
+ ndef_record_s *record,
+ net_nfc_server_handover_process_carrier_record_cb cb,
+ void *user_param)
+{
+ net_nfc_error_e result = NET_NFC_OK;
+ net_nfc_handover_bt_process_context_t *context = NULL;
+
+ _net_nfc_util_alloc_mem(context, sizeof(*context));
+ if (context != NULL)
+ {
+ context->cb = cb;
+ context->user_param = user_param;
+ context->step = NET_NFC_LLCP_STEP_01;
+ net_nfc_util_create_record(record->TNF, &record->type_s,
+ &record->id_s, &record->payload_s, &context->carrier);
+
+ g_idle_add(
+ (GSourceFunc)_net_nfc_handover_bt_process_carrier_record,
+ (gpointer)context);
+ }
+ else
+ {
+ result = NET_NFC_ALLOC_FAIL;
+ }
+
+ return result;
+}
+
+static void _net_nfc_handover_bt_post_process_cb(int event,
+ bluetooth_event_param_t *param, void *user_data)
+{
+ net_nfc_handover_bt_process_context_t *context =
+ (net_nfc_handover_bt_process_context_t *)user_data;
+
+ LOGD("[%s] START", __func__);
+
+ if (context == NULL)
+ {
+ DEBUG_SERVER_MSG("user_data is null");
+ LOGD("[%s] END", __func__);
+ return;
+ }
+
+ switch (event)
+ {
+ case BLUETOOTH_EVENT_ENABLED :
+ DEBUG_SERVER_MSG("BLUETOOTH_EVENT_ENABLED");
+ break;
+
+ case BLUETOOTH_EVENT_DISABLED :
+ DEBUG_SERVER_MSG("BLUETOOTH_EVENT_DISABLED");
+ break;
+
+ case BLUETOOTH_EVENT_BONDING_FINISHED :
+ DEBUG_SERVER_MSG("BLUETOOTH_EVENT_BONDING_FINISHED,"
+ " result [0x%04x]",param->result);
+
+ if (param->result < BLUETOOTH_ERROR_NONE)
+ {
+ DEBUG_ERR_MSG("bond failed");
+ context->result = NET_NFC_OPERATION_FAIL;
+ }
+ else
+ {
+ context->result = NET_NFC_OK;
+ }
+
+ context->cb(context->result,
+ NET_NFC_CONN_HANDOVER_CARRIER_BT,
+ NULL,
+ context->user_param);
+ break;
+
+ default :
+ DEBUG_SERVER_MSG("unhandled bt event"
+ " [%d], [0x%04x]", event, param->result);
+ break;
+ }
+
+ LOGD("[%s] END", __func__);
+}
+
+net_nfc_error_e net_nfc_server_handover_bt_post_process(
+ data_s *data,
+ net_nfc_server_handover_process_carrier_record_cb cb,
+ void *user_param)
+{
+ net_nfc_error_e result = NET_NFC_OK;
+ net_nfc_handover_bt_process_context_t *context = NULL;
+
+ _net_nfc_util_alloc_mem(context, sizeof(*context));
+ if (context != NULL)
+ {
+ bluetooth_device_address_t bt_addr;
+
+ context->cb = cb;
+ context->user_param = user_param;
+
+ memcpy(&bt_addr.addr, data->buffer, sizeof(bt_addr.addr));
+
+ if (bluetooth_register_callback(
+ _net_nfc_handover_bt_post_process_cb,
+ context) >= BLUETOOTH_ERROR_NONE)
+ {
+ bluetooth_bond_device(&bt_addr);
+ }
+ else
+ {
+ _net_nfc_util_free_mem(context);
+ result = NET_NFC_OPERATION_FAIL;
+ }
+ }
+ else
+ {
+ result = NET_NFC_ALLOC_FAIL;
+ }
+
+ return result;
+}
+
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_SERVER_HANDOVER_BT_H__
+#define __NET_NFC_SERVER_HANDOVER_BT_H__
+
+#include "net_nfc_typedef_internal.h"
+
+typedef void (*net_nfc_server_handover_get_carrier_record_cb)(
+ net_nfc_error_e result,
+ net_nfc_conn_handover_carrier_state_e cps,
+ ndef_record_s *carrier,
+ uint32_t aux_data_count,
+ ndef_record_s *aux_data,
+ void *user_param);
+
+typedef void (*net_nfc_server_handover_process_carrier_record_cb)(
+ net_nfc_error_e result,
+ net_nfc_conn_handover_carrier_type_e type,
+ data_s *data,
+ void *user_param);
+
+/* alternative carrier functions */
+net_nfc_error_e net_nfc_server_handover_bt_get_carrier_record(
+ net_nfc_server_handover_get_carrier_record_cb cb, void *user_param);
+
+net_nfc_error_e net_nfc_server_handover_bt_process_carrier_record(
+ ndef_record_s *record, net_nfc_server_handover_process_carrier_record_cb cb,
+ void *user_param);
+
+net_nfc_error_e net_nfc_server_handover_bt_post_process(data_s *data,
+ net_nfc_server_handover_process_carrier_record_cb cb,
+ void *user_param);
+
+#endif //__NET_NFC_SERVER_HANDOVER_BT_H__
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include <pmapi.h>/*for pm lock*/
+
+#include "net_nfc_gdbus.h"
+#include "net_nfc_server_common.h"
+#include "net_nfc_server_p2p.h"
+#include "net_nfc_server_llcp.h"
+
+#include "net_nfc_server_process_snep.h"
+#include "net_nfc_server_process_npp.h"
+#include "net_nfc_server_process_handover.h"
+#include "net_nfc_server_tag.h"
+
+#include "net_nfc_debug_internal.h"
+#include "net_nfc_server_controller.h"
+#include "net_nfc_util_gdbus_internal.h"
+#include "net_nfc_server_context.h"
+
+/* default llcp configurations */
+#define NET_NFC_LLCP_MIU 128
+#define NET_NFC_LLCP_WKS 1
+#define NET_NFC_LLCP_LTO 10
+#define NET_NFC_LLCP_OPT 0
+
+static NetNfcGDbusLlcp *llcp_skeleton = NULL;
+
+static net_nfc_llcp_config_info_s llcp_config =
+{
+ NET_NFC_LLCP_MIU,
+ NET_NFC_LLCP_WKS,
+ NET_NFC_LLCP_LTO,
+ NET_NFC_LLCP_OPT,
+};
+
+typedef struct _LlcpData LlcpData;
+
+struct _LlcpData
+{
+ NetNfcGDbusLlcp *llcp;
+ GDBusMethodInvocation *invocation;
+};
+
+typedef struct _LlcpConfigData LlcpConfigData;
+
+struct _LlcpConfigData
+{
+ NetNfcGDbusLlcp *llcp;
+ GDBusMethodInvocation *invocation;
+
+ guint16 miu;
+ guint16 wks;
+ guint8 lto;
+ guint8 option;
+};
+
+typedef struct _LlcpListenData LlcpListenData;
+
+struct _LlcpListenData
+{
+ NetNfcGDbusLlcp *llcp;
+ GDBusMethodInvocation *invocation;
+
+ guint32 handle;
+ guint32 client_socket;
+ guint32 oal_socket;
+ guint16 miu;
+ guint8 rw;
+ guint type;
+ guint sap;
+ gchar *service_name;
+};
+
+typedef struct _LlcpConnectData LlcpConnectData;
+
+struct _LlcpConnectData
+{
+ NetNfcGDbusLlcp *llcp;
+ GDBusMethodInvocation *invocation;
+
+ guint32 handle;
+ guint32 client_socket;
+ guint32 oal_socket;
+ guint16 miu;
+ guint8 rw;
+ guint type;
+ gchar *service_name;
+};
+
+typedef struct _LlcpConnectSapData LlcpConnectSapData;
+
+struct _LlcpConnectSapData
+{
+ NetNfcGDbusLlcp *llcp;
+ GDBusMethodInvocation *invocation;
+
+ guint32 handle;
+ guint32 client_socket;
+ guint32 oal_socket;
+ guint16 miu;
+ guint8 rw;
+ guint type;
+ guint sap;
+};
+
+typedef struct _LlcpSendData LlcpSendData;
+
+struct _LlcpSendData
+{
+ NetNfcGDbusLlcp *llcp;
+ GDBusMethodInvocation *invocation;
+
+ guint32 handle;
+ guint32 client_socket;
+ guint32 oal_socket;
+
+ data_s *data;
+};
+
+typedef struct _LlcpSendToData LlcpSendToData;
+
+struct _LlcpSendToData
+{
+ NetNfcGDbusLlcp *llcp;
+ GDBusMethodInvocation *invocation;
+
+ guint32 handle;
+ guint32 client_socket;
+ guint32 oal_socket;
+ guint8 sap;
+
+ data_s *data;
+};
+
+typedef struct _LlcpReceiveData LlcpReceiveData;
+
+struct _LlcpReceiveData
+{
+ NetNfcGDbusLlcp *llcp;
+ GDBusMethodInvocation *invocation;
+
+ guint32 handle;
+ guint32 client_socket;
+ guint32 oal_socket;
+ guint32 req_length;
+};
+
+typedef struct _LlcpCloseData LlcpCloseData;
+
+struct _LlcpCloseData
+{
+ NetNfcGDbusLlcp *llcp;
+ GDBusMethodInvocation *invocation;
+
+ guint32 handle;
+ guint32 client_socket;
+ guint32 oal_socket;
+};
+
+typedef struct _LlcpDisconnectData LlcpDisconnectData;
+
+struct _LlcpDisconnectData
+{
+ NetNfcGDbusLlcp *llcp;
+ GDBusMethodInvocation *invocation;
+
+ guint32 handle;
+ guint32 client_socket;
+ guint32 oal_socket;
+};
+
+/* server_side */
+typedef struct _ServerLlcpData ServerLlcpData;
+
+struct _ServerLlcpData
+{
+ NetNfcGDbusLlcp *llcp;
+ net_nfc_request_msg_t *req_msg;
+};
+
+typedef struct _LlcpSimpleData LlcpSimpleData;
+
+struct _LlcpSimpleData
+{
+ net_nfc_target_handle_s *handle;
+ net_nfc_llcp_socket_t socket;
+ guint32 miu;
+ net_nfc_server_llcp_callback callback;
+ net_nfc_server_llcp_callback error_callback;
+ gpointer user_data;
+};
+
+
+static void llcp_add_async_queue(net_nfc_request_msg_t *req_msg,
+ net_nfc_server_controller_func func);
+
+static void llcp_socket_error_cb(net_nfc_llcp_socket_t socket,
+ net_nfc_error_e result,
+ data_s *data,
+ void *extra,
+ void *user_param);
+
+static void llcp_listen_cb(net_nfc_llcp_socket_t socket,
+ net_nfc_error_e result,
+ data_s *data,
+ void *extra,
+ void *user_param);
+
+static void llcp_connect_by_url_cb(net_nfc_llcp_socket_t socket,
+ net_nfc_error_e result,
+ data_s *data,
+ void *extra,
+ void *user_param);
+
+static void llcp_connect_cb(net_nfc_llcp_socket_t socket,
+ net_nfc_error_e result,
+ data_s *data,
+ void *extra,
+ void *user_param);
+
+static void llcp_send_cb(net_nfc_llcp_socket_t socket,
+ net_nfc_error_e result,
+ data_s *data,
+ void *extra,
+ void *user_param);
+
+static void llcp_receive_cb(net_nfc_llcp_socket_t socket,
+ net_nfc_error_e result,
+ data_s *data,
+ void *extra,
+ void *user_param);
+
+static void llcp_receive_from_cb(net_nfc_llcp_socket_t socket,
+ net_nfc_error_e result,
+ data_s *data,
+ void *extra,
+ void *user_param);
+
+static void llcp_disconnect_cb(net_nfc_llcp_socket_t socket,
+ net_nfc_error_e result,
+ data_s *data,
+ void *extra,
+ void *user_param);
+
+/* client method */
+static void llcp_handle_config_thread_func(gpointer user_data);
+
+static void llcp_handle_listen_thread_func(gpointer user_data);
+
+static void llcp_handle_connect_thread_func(gpointer user_data);
+
+static void llcp_handle_connect_sap_thread_func(gpointer user_data);
+
+static void llcp_handle_send_thread_func(gpointer user_data);
+
+static void llcp_handle_send_to_thread_func(gpointer user_data);
+
+static void llcp_handle_receive_thread_func(gpointer user_data);
+
+static void llcp_handle_receive_from_thread_func(gpointer user_data);
+
+static void llcp_handle_close_thread_func(gpointer user_data);
+
+static void llcp_handle_disconnect_thread_func(gpointer user_data);
+
+/* methods */
+static gboolean llcp_handle_config(NetNfcGDbusLlcp *llcp,
+ GDBusMethodInvocation *invocation,
+ GVariant *arg_config,
+ GVariant *smack_privilege,
+ gpointer user_data);
+
+static gboolean llcp_handle_listen(NetNfcGDbusLlcp *llcp,
+ GDBusMethodInvocation *invocation,
+ guint32 arg_handle,
+ guint32 arg_client_socket,
+ guint32 arg_oal_socket,
+ guint16 arg_miu,
+ guint8 arg_rw,
+ gint32 arg_type,
+ guint8 arg_sap,
+ const gchar *arg_service_name,
+ GVariant *smack_privilege,
+ gpointer user_data);
+
+static gboolean llcp_handle_connect(NetNfcGDbusLlcp *llcp,
+ GDBusMethodInvocation *invocation,
+ guint32 arg_handle,
+ guint32 arg_client_socket,
+ guint32 arg_oal_socket,
+ guint16 arg_miu,
+ guint8 arg_rw,
+ gint32 arg_type,
+ const gchar *arg_service_name,
+ GVariant *smack_privilege,
+ gpointer user_data);
+
+static gboolean llcp_handle_connect_sap(NetNfcGDbusLlcp *llcp,
+ GDBusMethodInvocation *invocation,
+ guint32 arg_handle,
+ guint32 arg_client_socket,
+ guint32 arg_oal_socket,
+ guint16 arg_miu,
+ guint8 arg_rw,
+ gint32 arg_type,
+ guint8 arg_sap,
+ GVariant *smack_privilege,
+ gpointer user_data);
+
+static gboolean llcp_handle_send(NetNfcGDbusLlcp *llcp,
+ GDBusMethodInvocation *invocation,
+ guint32 arg_handle,
+ guint32 arg_client_socket,
+ guint32 arg_oal_socket,
+ GVariant *arg_data,
+ GVariant *smack_privilege,
+ gpointer user_data);
+
+static gboolean llcp_handle_send_to(NetNfcGDbusLlcp *llcp,
+ GDBusMethodInvocation *invocation,
+ guint32 arg_handle,
+ guint32 arg_client_socket,
+ guint32 arg_oal_socket,
+ guint8 arg_sap,
+ GVariant *arg_data,
+ GVariant *smack_privilege,
+ gpointer user_data);
+
+static gboolean llcp_handle_receive(NetNfcGDbusLlcp *llcp,
+ GDBusMethodInvocation *invocation,
+ guint32 arg_handle,
+ guint32 arg_client_socket,
+ guint32 arg_oal_socket,
+ guint32 arg_req_length,
+ GVariant *smack_privilege,
+ gpointer user_data);
+
+static gboolean llcp_handle_receive_from(NetNfcGDbusLlcp *llcp,
+ GDBusMethodInvocation *invocation,
+ guint32 arg_handle,
+ guint32 arg_client_socket,
+ guint32 arg_oal_socket,
+ guint32 arg_req_length,
+ GVariant *smack_privilege,
+ gpointer user_data);
+
+static gboolean llcp_handle_close(NetNfcGDbusLlcp *llcp,
+ GDBusMethodInvocation *invocation,
+ guint32 arg_handle,
+ guint32 arg_client_socket,
+ guint32 arg_oal_socket,
+ GVariant *smack_privilege,
+ gpointer user_data);
+
+static gboolean llcp_handle_disconnect(NetNfcGDbusLlcp *llcp,
+ GDBusMethodInvocation *invocation,
+ guint32 arg_handle,
+ guint32 arg_client_socket,
+ guint32 arg_oal_socket,
+ GVariant *smack_privilege,
+ gpointer user_data);
+
+
+/* server side */
+static void llcp_deactivated_thread_func(gpointer user_data);
+
+static void llcp_listen_thread_func(gpointer user_data);
+
+static void llcp_socket_error_thread_func(gpointer user_data);
+
+static void llcp_send_thread_func(gpointer user_data);
+
+static void llcp_receive_thread_func(gpointer user_data);
+
+static void llcp_receive_from_thread_func(gpointer user_data);
+
+static void llcp_connect_thread_func(gpointer user_data);
+
+static void llcp_disconnect_thread_func(gpointer user_data);
+
+/* simple */
+static void llcp_simple_socket_error_cb(net_nfc_llcp_socket_t socket,
+ net_nfc_error_e result,
+ data_s *data,
+ void *extra,
+ void *user_param);
+
+static void llcp_simple_listen_cb(net_nfc_llcp_socket_t socket,
+ net_nfc_error_e result,
+ data_s *data,
+ void *extra,
+ void *user_param);
+
+static void llcp_simple_connect_cb(net_nfc_llcp_socket_t socket,
+ net_nfc_error_e result,
+ data_s *data,
+ void *extra,
+ void *user_param);
+
+static void llcp_simple_server_error_cb(net_nfc_llcp_socket_t socket,
+ net_nfc_error_e result,
+ data_s *data,
+ void *extra,
+ void *user_param);
+
+static void llcp_simple_send_cb(net_nfc_llcp_socket_t socket,
+ net_nfc_error_e result,
+ data_s *data,
+ void *extra,
+ void *user_param);
+
+static void llcp_simple_receive_cb(net_nfc_llcp_socket_t socket,
+ net_nfc_error_e result,
+ data_s *data,
+ void *extra,
+ void *user_param);
+
+
+static void llcp_add_async_queue(net_nfc_request_msg_t *req_msg,
+ net_nfc_server_controller_func func)
+{
+ ServerLlcpData *data = NULL;
+
+ if (llcp_skeleton == NULL)
+ {
+ DEBUG_ERR_MSG("%s is not initialized",
+ "net_nfc_server_llcp");
+ return;
+ }
+
+ if (req_msg == NULL)
+ {
+ DEBUG_ERR_MSG("req msg is null");
+ }
+
+ data = g_new0(ServerLlcpData, 1);
+ if(data == NULL)
+ {
+ DEBUG_ERR_MSG("Memory allocation failed");
+ return;
+ }
+ data->llcp = g_object_ref(llcp_skeleton);
+ data->req_msg = req_msg;
+
+ if (net_nfc_server_controller_async_queue_push(func, data) == FALSE)
+ {
+ DEBUG_ERR_MSG("can not push to controller thread");
+
+ if (data)
+ {
+ g_object_unref(data->llcp);
+ g_free(data->req_msg);
+ g_free(data);
+ }
+ }
+}
+
+static void llcp_socket_error_cb(net_nfc_llcp_socket_t socket,
+ net_nfc_error_e result,
+ data_s *data,
+ void *extra,
+ void *user_param)
+{
+ LlcpData *llcp_data;
+
+ llcp_data = (LlcpData *)user_param;
+
+ if (llcp_data->invocation)
+ {
+ g_dbus_method_invocation_return_dbus_error(
+ llcp_data->invocation,
+ "org.tizen.NetNfcService.SocketError",
+ "socket error");
+
+ g_object_unref(llcp_data->invocation);
+ }
+
+ if (llcp_data->llcp)
+ g_object_unref(llcp_data->llcp);
+
+ g_free(llcp_data);
+}
+
+static void llcp_listen_cb(net_nfc_llcp_socket_t socket,
+ net_nfc_error_e result,
+ data_s *data,
+ void *extra,
+ void *user_param)
+{
+ LlcpListenData *llcp_data;
+
+ llcp_data = (LlcpListenData *)user_param;
+
+ if (llcp_data == NULL)
+ return;
+
+ if (llcp_data->llcp)
+ {
+
+ if (llcp_data->invocation)
+ {
+ net_nfc_gdbus_llcp_complete_listen(llcp_data->llcp,
+ llcp_data->invocation,
+ llcp_data->client_socket,
+ socket);
+ g_object_unref(llcp_data->invocation);
+ }
+
+ g_object_unref(llcp_data->llcp);
+ }
+
+ g_free(llcp_data->service_name);
+ g_free(llcp_data);
+}
+
+static void llcp_connect_by_url_cb(net_nfc_llcp_socket_t socket,
+ net_nfc_error_e result,
+ data_s *data,
+ void *extra,
+ void *user_param)
+{
+ LlcpConnectData *llcp_data;
+
+ llcp_data = (LlcpConnectData *)user_param;
+
+ if (llcp_data == NULL)
+ return;
+
+ if (llcp_data->llcp)
+ {
+
+ if (llcp_data->invocation)
+ {
+ net_nfc_gdbus_llcp_complete_connect(llcp_data->llcp,
+ llcp_data->invocation,
+ llcp_data->client_socket,
+ socket);
+ g_object_unref(llcp_data->invocation);
+ }
+
+ g_object_unref(llcp_data->llcp);
+ }
+
+ g_free(llcp_data->service_name);
+ g_free(llcp_data);
+}
+
+static void llcp_connect_cb(net_nfc_llcp_socket_t socket,
+ net_nfc_error_e result,
+ data_s *data,
+ void *extra,
+ void *user_param)
+{
+ LlcpConnectSapData *llcp_data;
+
+ llcp_data = (LlcpConnectSapData *)user_param;
+
+ if (llcp_data == NULL)
+ return;
+
+ if (llcp_data->llcp)
+ {
+
+ if (llcp_data->invocation)
+ {
+ net_nfc_gdbus_llcp_complete_connect_sap(
+ llcp_data->llcp,
+ llcp_data->invocation,
+ llcp_data->client_socket,
+ socket);
+ g_object_unref(llcp_data->invocation);
+ }
+
+ g_object_unref(llcp_data->llcp);
+ }
+
+ g_free(llcp_data);
+}
+
+static void llcp_send_cb(net_nfc_llcp_socket_t socket,
+ net_nfc_error_e result,
+ data_s *data,
+ void *extra,
+ void *user_param)
+{
+ LlcpData *llcp_data;
+
+ llcp_data = (LlcpData *)user_param;
+
+ if (llcp_data == NULL)
+ return;
+
+ if (llcp_data->llcp)
+ {
+
+ if (llcp_data->invocation)
+ {
+ net_nfc_gdbus_llcp_complete_send(
+ llcp_data->llcp,
+ llcp_data->invocation,
+ socket);
+ g_object_unref(llcp_data->invocation);
+ }
+
+ g_object_unref(llcp_data->llcp);
+ }
+
+ g_free(llcp_data);
+}
+
+static void llcp_receive_cb(net_nfc_llcp_socket_t socket,
+ net_nfc_error_e result,
+ data_s *data,
+ void *extra,
+ void *user_param)
+{
+ LlcpData *llcp_data;
+
+ llcp_data = (LlcpData *)user_param;
+
+ if (llcp_data == NULL)
+ return;
+
+ if (llcp_data->llcp)
+ {
+ if (llcp_data->invocation)
+ {
+ GVariant *variant;
+
+ variant = net_nfc_util_gdbus_data_to_variant(data);
+ net_nfc_gdbus_llcp_complete_receive(
+ llcp_data->llcp,
+ llcp_data->invocation,
+ variant);
+
+ g_object_unref(llcp_data->invocation);
+ }
+
+ g_object_unref(llcp_data->llcp);
+ }
+
+ g_free(llcp_data);
+}
+
+static void llcp_receive_from_cb(net_nfc_llcp_socket_t socket,
+ net_nfc_error_e result,
+ data_s *data,
+ void *extra,
+ void *user_param)
+{
+ LlcpData *llcp_data;
+
+ llcp_data = (LlcpData *)user_param;
+
+ if (llcp_data == NULL)
+ return;
+
+ if (llcp_data->llcp)
+ {
+
+ if (llcp_data->invocation)
+ {
+ GVariant *variant;
+
+ variant = net_nfc_util_gdbus_data_to_variant(data);
+ net_nfc_gdbus_llcp_complete_receive_from(
+ llcp_data->llcp,
+ llcp_data->invocation,
+ (guint8) (int)extra,
+ variant);
+
+ g_object_unref(llcp_data->invocation);
+ }
+
+ g_object_unref(llcp_data->llcp);
+ }
+
+ g_free(llcp_data);
+}
+
+
+static void llcp_disconnect_cb(net_nfc_llcp_socket_t socket,
+ net_nfc_error_e result,
+ data_s *data,
+ void *extra,
+ void *user_param)
+{
+ LlcpData *llcp_data;
+
+ llcp_data = (LlcpData *)user_param;
+
+ if (llcp_data == NULL)
+ return;
+
+ if (llcp_data->llcp)
+ {
+
+ if (llcp_data->invocation)
+ {
+ net_nfc_gdbus_llcp_complete_disconnect(
+ llcp_data->llcp,
+ llcp_data->invocation,
+ socket);
+
+ g_object_unref(llcp_data->invocation);
+ }
+
+ g_object_unref(llcp_data->llcp);
+ }
+
+ g_free(llcp_data);
+}
+
+
+static void llcp_handle_config_thread_func(gpointer user_data)
+{
+ LlcpConfigData *data;
+
+ net_nfc_llcp_config_info_s config;
+
+ data = (LlcpConfigData *)user_data;
+
+ if (data == NULL)
+ {
+ DEBUG_ERR_MSG("can not get LlcpConfigData");
+ return;
+ }
+
+ if (data->llcp == NULL)
+ {
+ DEBUG_ERR_MSG("can not get llcp");
+ if (data->invocation)
+ {
+ g_dbus_method_invocation_return_dbus_error(
+ data->invocation,
+ "org.tizen.NetNfcService.ConfigError",
+ "can not get llcp");
+
+ g_object_unref(data->invocation);
+ }
+ g_free(data);
+
+ return;
+ }
+
+ config.miu = data->miu;
+ config.wks = data->wks;
+ config.lto = data->lto;
+ config.option = data->option;
+
+ if (net_nfc_server_llcp_set_config(&config) != NET_NFC_OK)
+ {
+ if (data->invocation)
+ {
+ g_dbus_method_invocation_return_dbus_error(
+ data->invocation,
+ "org.tizen.NetNfcService.ConfigError",
+ "can not get llcp");
+
+ g_object_unref(data->invocation);
+ }
+
+ g_object_unref(data->llcp);
+ g_free(data);
+ return;
+ }
+
+ if (data->invocation)
+ {
+ net_nfc_gdbus_llcp_complete_config(data->llcp,
+ data->invocation);
+
+ g_object_unref(data->invocation);
+ }
+
+ g_object_unref(data->llcp);
+ g_free(data);
+
+ return;
+}
+
+static void llcp_handle_listen_thread_func(gpointer user_data)
+{
+ LlcpListenData *data;
+ LlcpData *error_data;
+
+ net_nfc_llcp_socket_t socket = -1;
+ net_nfc_error_e result = NET_NFC_OK;
+
+ data = (LlcpListenData *)user_data;
+
+ if (data == NULL)
+ {
+ DEBUG_ERR_MSG("can not get LlcpListenData");
+ return;
+ }
+
+ if (data->llcp == NULL)
+ {
+ DEBUG_ERR_MSG("can not get llcp");
+ if (data->invocation)
+ {
+ g_dbus_method_invocation_return_dbus_error(
+ data->invocation,
+ "org.tizen.NetNfcService.ListenError",
+ "can not get llcp");
+
+ g_object_unref(data->invocation);
+ }
+
+ g_free(data->service_name);
+ g_free(data);
+
+ return;
+ }
+
+ error_data = g_new0(LlcpData, 1);
+ if(error_data == NULL)
+ {
+ DEBUG_ERR_MSG("Memory allocation failed");
+ g_dbus_method_invocation_return_dbus_error(data->invocation,
+ "org.tizen.NetNfcService.AllocationError",
+ "Can not allocate memory");
+ return;
+ }
+ error_data->llcp = g_object_ref(data->llcp);
+ error_data->invocation = g_object_ref(data->invocation);
+
+ if (net_nfc_controller_llcp_create_socket(&socket,
+ data->type,
+ data->miu,
+ data->rw,
+ &result,
+ llcp_socket_error_cb,
+ error_data) == false)
+ {
+ DEBUG_ERR_MSG("%s fiailed [%d]",
+ "net_nfc_controller_llcp_create_socket" ,result);
+
+ if (data->invocation)
+ {
+ g_dbus_method_invocation_return_dbus_error(
+ data->invocation,
+ "org.tizen.NetNfcService.ListenError",
+ "can not create socket");
+
+ g_object_unref(data->invocation);
+ }
+
+ g_object_unref(data->llcp);
+
+ g_free(data->service_name);
+ g_free(data);
+
+ g_free(error_data);
+
+ return;
+ }
+
+ if (net_nfc_controller_llcp_bind(socket,
+ data->sap,
+ &result) == false)
+ {
+ DEBUG_ERR_MSG("%s fiailed [%d]",
+ "net_nfc_controller_llcp_create_socket" ,result);
+
+ if (data->invocation)
+ {
+ g_dbus_method_invocation_return_dbus_error(
+ data->invocation,
+ "org.tizen.NetNfcService.ListenError",
+ "can not bind socket");
+
+ g_object_unref(data->invocation);
+ }
+
+ g_object_unref(data->llcp);
+
+ g_free(data->service_name);
+ g_free(data);
+
+ g_free(error_data);
+
+ if (socket != -1)
+ net_nfc_controller_llcp_socket_close(socket, &result);
+
+ return;
+ }
+
+ DEBUG_SERVER_MSG("OAL socket in Listen : %d\n", socket);
+
+ if (net_nfc_controller_llcp_listen(GUINT_TO_POINTER(data->handle),
+ (uint8_t *)data->service_name,
+ socket,
+ &result,
+ llcp_listen_cb,
+ data) == false)
+ {
+ DEBUG_ERR_MSG("%s failed [%d]",
+ "net_nfc_controller_llcp_listen",
+ result);
+
+ if (data->invocation)
+ {
+ g_dbus_method_invocation_return_dbus_error(
+ data->invocation,
+ "org.tizen.NetNfcService.ListenError",
+ "can not listen socket");
+
+ g_object_unref(data->invocation);
+ }
+
+ g_object_unref(data->llcp);
+
+ g_free(data->service_name);
+ g_free(data);
+
+ g_free(error_data);
+
+ if (socket != -1)
+ net_nfc_controller_llcp_socket_close(socket, &result);
+ }
+}
+
+static void llcp_handle_connect_thread_func(gpointer user_data)
+{
+ LlcpConnectData *data;
+ LlcpData *error_data;
+
+ net_nfc_llcp_socket_t socket = -1;
+ net_nfc_error_e result = NET_NFC_OK;
+
+ data = (LlcpConnectData *)user_data;
+
+ if (data == NULL)
+ {
+ DEBUG_ERR_MSG("can not get LlcpListenData");
+ return;
+ }
+
+ if (data->llcp == NULL)
+ {
+ DEBUG_ERR_MSG("can not get llcp");
+ if (data->invocation)
+ {
+ g_dbus_method_invocation_return_dbus_error(
+ data->invocation,
+ "org.tizen.NetNfcService.ConnectError",
+ "can not get llcp");
+
+ g_object_unref(data->invocation);
+ }
+
+ g_free(data->service_name);
+ g_free(data);
+
+ return;
+ }
+
+ error_data = g_new0(LlcpData, 1);
+ if(error_data == NULL)
+ {
+ DEBUG_ERR_MSG("Memory allocation failed");
+ g_dbus_method_invocation_return_dbus_error(data->invocation,
+ "org.tizen.NetNfcService.AllocationError",
+ "Can not allocate memory");
+ return;
+ }
+ error_data->llcp = g_object_ref(data->llcp);
+ error_data->invocation = g_object_ref(data->invocation);
+
+ if (net_nfc_controller_llcp_create_socket(&socket,
+ data->type,
+ data->miu,
+ data->rw,
+ &result,
+ llcp_socket_error_cb,
+ error_data) == false)
+ {
+ DEBUG_ERR_MSG("%s fiailed [%d]",
+ "net_nfc_controller_llcp_create_socket" ,result);
+
+ if (data->invocation)
+ {
+ g_dbus_method_invocation_return_dbus_error(
+ data->invocation,
+ "org.tizen.NetNfcService.ConnectError",
+ "can not create socket");
+
+ g_object_unref(data->invocation);
+ }
+
+ g_object_unref(data->llcp);
+
+ g_free(data->service_name);
+ g_free(data);
+
+ g_free(error_data);
+
+ return;
+ }
+
+ DEBUG_SERVER_MSG("OAL socket in Listen :%d", socket);
+
+ if (net_nfc_controller_llcp_connect_by_url(
+ GUINT_TO_POINTER(data->handle),
+ socket,
+ (uint8_t *)data->service_name,
+ &result,
+ llcp_connect_by_url_cb,
+ data) == false)
+ {
+ DEBUG_ERR_MSG("%s failed, [%d]",
+ "net_nfc_controller_llcp_connect_by_url",
+ result);
+
+ if (data->invocation)
+ {
+ g_dbus_method_invocation_return_dbus_error(
+ data->invocation,
+ "org.tizen.NetNfcService.ConnectError",
+ "can not listen socket");
+
+ g_object_unref(data->invocation);
+ }
+
+ g_object_unref(data->llcp);
+
+ g_free(data->service_name);
+ g_free(data);
+
+ g_free(error_data);
+
+ if (socket != -1)
+ net_nfc_controller_llcp_socket_close(socket, &result);
+ }
+}
+
+static void llcp_handle_connect_sap_thread_func(gpointer user_data)
+{
+ LlcpConnectSapData *data;
+ LlcpData *error_data;
+
+ net_nfc_llcp_socket_t socket = -1;
+ net_nfc_error_e result = NET_NFC_OK;
+
+ data = (LlcpConnectSapData *)user_data;
+
+ if (data == NULL)
+ {
+ DEBUG_ERR_MSG("can not get LlcpConnectSapData");
+ return;
+ }
+
+ if (data->llcp == NULL)
+ {
+ DEBUG_ERR_MSG("can not get llcp");
+ if (data->invocation)
+ {
+ g_dbus_method_invocation_return_dbus_error(
+ data->invocation,
+ "org.tizen.NetNfcService.ConnectSapError",
+ "can not get llcp");
+
+ g_object_unref(data->invocation);
+ }
+
+ g_free(data);
+
+ return;
+ }
+
+ error_data = g_new0(LlcpData, 1);
+ if(error_data == NULL)
+ {
+ DEBUG_ERR_MSG("Memory allocation failed");
+ g_dbus_method_invocation_return_dbus_error(data->invocation,
+ "org.tizen.NetNfcService.AllocationError",
+ "Can not allocate memory");
+ return;
+ }
+ error_data->llcp = g_object_ref(data->llcp);
+ error_data->invocation = g_object_ref(data->invocation);
+
+ if (net_nfc_controller_llcp_create_socket(&socket,
+ data->type,
+ data->miu,
+ data->rw,
+ &result,
+ llcp_socket_error_cb,
+ error_data) == false)
+ {
+ DEBUG_ERR_MSG("%s fiailed [%d]",
+ "net_nfc_controller_llcp_create_socket" ,result);
+
+ if (data->invocation)
+ {
+ g_dbus_method_invocation_return_dbus_error(
+ data->invocation,
+ "org.tizen.NetNfcService.ConnectSapError",
+ "can not create socket");
+
+ g_object_unref(data->invocation);
+ }
+
+ g_object_unref(data->llcp);
+
+ g_free(data);
+
+ g_free(error_data);
+
+ return;
+ }
+
+ DEBUG_SERVER_MSG("OAL socket in Listen :%d", socket);
+
+ if (net_nfc_controller_llcp_connect(GUINT_TO_POINTER(data->handle),
+ socket,
+ data->sap,
+ &result,
+ llcp_connect_cb,
+ data) == false)
+ {
+ DEBUG_ERR_MSG("%s failed, [%d]",
+ "net_nfc_controller_llcp_connect",
+ result);
+
+ if (data->invocation)
+ {
+ g_dbus_method_invocation_return_dbus_error(
+ data->invocation,
+ "org.tizen.NetNfcService.ConnectSapError",
+ "can not connect socket");
+
+ g_object_unref(data->invocation);
+ }
+
+ g_object_unref(data->llcp);
+
+ g_free(data);
+
+ g_free(error_data);
+
+ if (socket != -1)
+ net_nfc_controller_llcp_socket_close(socket, &result);
+
+ }
+}
+
+static void llcp_handle_send_thread_func(gpointer user_data)
+{
+ LlcpSendData *data;
+ LlcpData *llcp_data;
+
+ net_nfc_error_e result = NET_NFC_OK;
+
+ data = (LlcpSendData *)user_data;
+
+ if (data == NULL)
+ {
+ DEBUG_ERR_MSG("can not get LlcpSendData");
+ return;
+ }
+
+ if (data->llcp == NULL)
+ {
+ DEBUG_ERR_MSG("can not get llcp");
+ if (data->invocation)
+ {
+ g_dbus_method_invocation_return_dbus_error(
+ data->invocation,
+ "org.tizen.NetNfcService.SendError",
+ "can not get llcp");
+
+ g_object_unref(data->invocation);
+ }
+
+ if (data->data)
+ {
+ g_free(data->data->buffer);
+ g_free(data->data);
+ }
+
+ g_free(data);
+
+ return;
+ }
+
+ llcp_data = g_new0(LlcpData, 1);
+ if(llcp_data == NULL)
+ {
+ DEBUG_ERR_MSG("Memory allocation failed");
+ g_dbus_method_invocation_return_dbus_error(data->invocation,
+ "org.tizen.NetNfcService.AllocationError",
+ "Can not allocate memory");
+ return;
+ }
+ llcp_data->llcp = g_object_ref(data->llcp);
+ llcp_data->invocation = g_object_ref(data->invocation);
+
+ if (net_nfc_controller_llcp_send(GUINT_TO_POINTER(data->handle),
+ data->oal_socket,
+ data->data,
+ &result,
+ llcp_send_cb,
+ llcp_data) == false)
+ {
+ DEBUG_ERR_MSG("%s failed, [%d]",
+ "net_nfc_controller_llcp_send",
+ result);
+
+ if (data->invocation)
+ {
+ g_dbus_method_invocation_return_dbus_error(
+ data->invocation,
+ "org.tizen.NetNfcService.SendError",
+ "can not send socket");
+
+ g_object_unref(data->invocation);
+ }
+
+ g_object_unref(data->llcp);
+
+ if (data->data)
+ {
+ g_free(data->data->buffer);
+ g_free(data->data);
+ }
+
+ g_free(data);
+
+ g_free(llcp_data);
+
+ return;
+ }
+
+ g_object_unref(data->llcp);
+ g_object_unref(data->invocation);
+
+ if (data->data)
+ {
+ g_free(data->data->buffer);
+ g_free(data->data);
+ }
+
+ g_free(data);
+
+ g_free(llcp_data);
+}
+
+static void llcp_handle_send_to_thread_func(gpointer user_data)
+{
+ LlcpSendToData *data;
+ LlcpData *llcp_data;
+
+ net_nfc_error_e result = NET_NFC_OK;
+
+ data = (LlcpSendToData *)user_data;
+
+ if (data == NULL)
+ {
+ DEBUG_ERR_MSG("can not get LlcpSendToData");
+ return;
+ }
+
+ if (data->llcp == NULL)
+ {
+ DEBUG_ERR_MSG("can not get llcp");
+ if (data->invocation)
+ {
+ g_dbus_method_invocation_return_dbus_error(
+ data->invocation,
+ "org.tizen.NetNfcService.SendToError",
+ "can not get llcp");
+
+ g_object_unref(data->invocation);
+ }
+
+ if (data->data)
+ {
+ g_free(data->data->buffer);
+ g_free(data->data);
+ }
+
+ g_free(data);
+
+ return;
+ }
+
+ llcp_data = g_new0(LlcpData, 1);
+ if(llcp_data == NULL)
+ {
+ DEBUG_ERR_MSG("Memory allocation failed");
+ g_dbus_method_invocation_return_dbus_error(data->invocation,
+ "org.tizen.NetNfcService.AllocationError",
+ "Can not allocate memory");
+ return;
+ }
+ llcp_data->llcp = g_object_ref(data->llcp);
+ llcp_data->invocation = g_object_ref(data->invocation);
+
+ if (net_nfc_controller_llcp_send_to(GUINT_TO_POINTER(data->handle),
+ data->oal_socket,
+ data->data,
+ data->sap,
+ &result,
+ llcp_send_cb,
+ llcp_data) == false)
+ {
+ DEBUG_ERR_MSG("%s failed, [%d]",
+ "net_nfc_controller_llcp_send_to",
+ result);
+
+ if (data->invocation)
+ {
+ g_dbus_method_invocation_return_dbus_error(
+ data->invocation,
+ "org.tizen.NetNfcService.SendToError",
+ "can not send socket");
+
+ g_object_unref(data->invocation);
+ }
+
+ g_object_unref(data->llcp);
+
+ if (data->data)
+ {
+ g_free(data->data->buffer);
+ g_free(data->data);
+ }
+
+ g_free(data);
+
+ g_free(llcp_data);
+
+ return;
+ }
+
+ g_object_unref(data->llcp);
+ g_object_unref(data->invocation);
+
+ if (data->data)
+ {
+ g_free(data->data->buffer);
+ g_free(data->data);
+ }
+
+ g_free(data);
+
+ g_free(llcp_data);
+}
+
+static void llcp_handle_receive_thread_func(gpointer user_data)
+{
+ LlcpReceiveData *data;
+ LlcpData *llcp_data;
+
+ net_nfc_error_e result = NET_NFC_OK;
+
+ data = (LlcpReceiveData *)user_data;
+
+ if (data == NULL)
+ {
+ DEBUG_ERR_MSG("can not get LlcpReceiveData");
+ return;
+ }
+
+ if (data->llcp == NULL)
+ {
+ DEBUG_ERR_MSG("can not get llcp");
+ if (data->invocation)
+ {
+ g_dbus_method_invocation_return_dbus_error(
+ data->invocation,
+ "org.tizen.NetNfcService.ReceiveError",
+ "can not get llcp");
+
+ g_object_unref(data->invocation);
+ }
+
+ g_free(data);
+
+ return;
+ }
+
+ llcp_data = g_new0(LlcpData, 1);
+ if(llcp_data == NULL)
+ {
+ DEBUG_ERR_MSG("Memory allocation failed");
+ g_dbus_method_invocation_return_dbus_error(data->invocation,
+ "org.tizen.NetNfcService.AllocationError",
+ "Can not allocate memory");
+ return;
+ }
+ llcp_data->llcp = g_object_ref(data->llcp);
+ llcp_data->invocation = g_object_ref(data->invocation);
+
+ if (net_nfc_controller_llcp_recv(GUINT_TO_POINTER(data->handle),
+ data->oal_socket,
+ data->req_length,
+ &result,
+ llcp_receive_cb,
+ llcp_data) == false)
+ {
+ DEBUG_ERR_MSG("%s failed, [%d]",
+ "net_nfc_controller_llcp_receive",
+ result);
+
+ if (data->invocation)
+ {
+ g_dbus_method_invocation_return_dbus_error(
+ data->invocation,
+ "org.tizen.NetNfcService.ReceiveError",
+ "can not receive");
+
+ g_object_unref(data->invocation);
+ }
+
+ g_object_unref(data->llcp);
+ g_free(data);
+
+ g_free(llcp_data);
+
+ return;
+ }
+
+ g_object_unref(data->llcp);
+ g_object_unref(data->invocation);
+
+ g_free(data);
+
+ g_free(llcp_data);
+}
+
+static void llcp_handle_receive_from_thread_func(gpointer user_data)
+{
+ LlcpReceiveData *data;
+ LlcpData *llcp_data;
+
+ net_nfc_error_e result = NET_NFC_OK;
+
+ data = (LlcpReceiveData *)user_data;
+
+ if (data == NULL)
+ {
+ DEBUG_ERR_MSG("can not get LlcpReceiveData");
+ return;
+ }
+
+ if (data->llcp == NULL)
+ {
+ DEBUG_ERR_MSG("can not get llcp");
+ if (data->invocation)
+ {
+ g_dbus_method_invocation_return_dbus_error(
+ data->invocation,
+ "org.tizen.NetNfcService.ReceiveFromError",
+ "can not get llcp");
+
+ g_object_unref(data->invocation);
+ }
+
+ g_free(data);
+
+ return;
+ }
+
+ llcp_data = g_new0(LlcpData, 1);
+ if(llcp_data == NULL)
+ {
+ DEBUG_ERR_MSG("Memory allocation failed");
+ g_dbus_method_invocation_return_dbus_error(data->invocation,
+ "org.tizen.NetNfcService.AllocationError",
+ "Can not allocate memory");
+ return;
+ }
+ llcp_data->llcp = g_object_ref(data->llcp);
+ llcp_data->invocation = g_object_ref(data->invocation);
+
+ if (net_nfc_controller_llcp_recv_from(GUINT_TO_POINTER(data->handle),
+ data->oal_socket,
+ data->req_length,
+ &result,
+ llcp_receive_from_cb,
+ llcp_data) == false)
+ {
+ DEBUG_ERR_MSG("%s failed, [%d]",
+ "net_nfc_controller_llcp_receive",
+ result);
+
+ if (data->invocation)
+ {
+ g_dbus_method_invocation_return_dbus_error(
+ data->invocation,
+ "org.tizen.NetNfcService.ReceiveFromError",
+ "can not receive");
+
+ g_object_unref(data->invocation);
+ }
+
+ g_object_unref(data->llcp);
+ g_free(data);
+
+ g_free(llcp_data);
+
+ return;
+ }
+
+ g_object_unref(data->llcp);
+ g_object_unref(data->invocation);
+
+ g_free(data);
+
+ g_free(llcp_data);
+}
+
+static void llcp_handle_close_thread_func(gpointer user_data)
+{
+ LlcpCloseData *data;
+
+ net_nfc_error_e result = NET_NFC_OK;
+
+ data = (LlcpCloseData *)user_data;
+
+ if (data == NULL)
+ {
+ DEBUG_ERR_MSG("can not get LlcpCloseData");
+ return;
+ }
+
+ if (data->llcp == NULL)
+ {
+ DEBUG_ERR_MSG("can not get llcp");
+ if (data->invocation)
+ {
+ g_dbus_method_invocation_return_dbus_error(
+ data->invocation,
+ "org.tizen.NetNfcService.CloseError",
+ "can not get llcp");
+
+ g_object_unref(data->invocation);
+ }
+
+ g_free(data);
+
+ return;
+ }
+
+ net_nfc_controller_llcp_socket_close(data->oal_socket,
+ &result);
+
+ net_nfc_gdbus_llcp_complete_close(data->llcp,
+ data->invocation,
+ data->client_socket);
+}
+
+static void llcp_handle_disconnect_thread_func(gpointer user_data)
+{
+ LlcpDisconnectData *data;
+ LlcpData *llcp_data;
+ int ret_val = 0;
+
+ net_nfc_error_e result = NET_NFC_OK;
+
+ data = (LlcpDisconnectData *)user_data;
+
+ if (data == NULL)
+ {
+ DEBUG_ERR_MSG("can not get LlcpDisconnectData");
+ return;
+ }
+
+ if (data->llcp == NULL)
+ {
+ DEBUG_ERR_MSG("can not get llcp");
+ if (data->invocation)
+ {
+ g_dbus_method_invocation_return_dbus_error(
+ data->invocation,
+ "org.tizen.NetNfcService.DisconnectError",
+ "can not get llcp");
+
+ g_object_unref(data->invocation);
+ }
+
+ g_free(data);
+
+ return;
+ }
+
+ if(GUINT_TO_POINTER(data->handle) == 0)
+ {
+ net_nfc_server_free_target_info();
+ ret_val = pm_unlock_state(LCD_NORMAL, PM_RESET_TIMER);
+ DEBUG_SERVER_MSG("net_nfc_controller_disconnect pm_unlock_state"
+ "[%d]!!", ret_val);
+ }
+
+ llcp_data = g_new0(LlcpData, 1);
+ if(llcp_data == NULL)
+ {
+ DEBUG_ERR_MSG("Memory allocation failed");
+ return;
+ }
+ llcp_data->llcp = g_object_ref(data->llcp);
+ llcp_data->invocation = g_object_ref(data->invocation);
+
+ if (net_nfc_controller_llcp_disconnect(GUINT_TO_POINTER(data->handle),
+ data->oal_socket,
+ &result,
+ llcp_disconnect_cb,
+ llcp_data) == false)
+ {
+ DEBUG_ERR_MSG("%s failed, [%d]",
+ "net_nfc_controller_llcp_receive",
+ result);
+
+ if (data->invocation)
+ {
+ g_dbus_method_invocation_return_dbus_error(
+ data->invocation,
+ "org.tizen.NetNfcService.DisconnectError",
+ "can not disconnect socket");
+
+ g_object_unref(data->invocation);
+ }
+
+ g_object_unref(data->llcp);
+ g_free(data);
+
+ g_free(llcp_data);
+
+ return;
+ }
+
+ g_object_unref(data->llcp);
+ g_object_unref(data->invocation);
+
+ g_free(data);
+
+ g_free(llcp_data);
+}
+
+
+static gboolean llcp_handle_config(NetNfcGDbusLlcp *llcp,
+ GDBusMethodInvocation *invocation,
+ GVariant *arg_config,
+ GVariant *smack_privilege,
+ gpointer user_data)
+{
+ LlcpConfigData *data;
+
+ INFO_MSG(">>> REQUEST from [%s]",
+ g_dbus_method_invocation_get_sender(invocation));
+
+ /* check privilege and update client context */
+ if (net_nfc_server_gdbus_check_privilege(invocation,
+ smack_privilege,
+ "nfc-manager::p2p",
+ "w") == false) {
+ DEBUG_ERR_MSG("permission denied, and finished request");
+
+ return TRUE;
+ }
+
+ data = g_new0(LlcpConfigData, 1);
+ if(data == NULL)
+ {
+ DEBUG_ERR_MSG("Memory allocation failed");
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.AllocationError",
+ "Can not allocate memory");
+ return FALSE;
+ }
+ data->llcp = g_object_ref(llcp);
+ data->invocation = g_object_ref(invocation);
+
+ g_variant_get(arg_config,
+ "(qqyy)",
+ &data->miu,
+ &data->wks,
+ &data->lto,
+ &data->option);
+
+ if (net_nfc_server_controller_async_queue_push(
+ llcp_handle_config_thread_func,
+ data) == FALSE)
+ {
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.ThreadError",
+ "can not push to controller thread");
+ g_object_unref(data->llcp);
+ g_object_unref(data->invocation);
+
+ g_free(data);
+
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+static gboolean llcp_handle_listen(NetNfcGDbusLlcp *llcp,
+ GDBusMethodInvocation *invocation,
+ guint32 arg_handle,
+ guint32 arg_client_socket,
+ guint32 arg_oal_socket,
+ guint16 arg_miu,
+ guint8 arg_rw,
+ gint32 arg_type,
+ guint8 arg_sap,
+ const gchar *arg_service_name,
+ GVariant *smack_privilege,
+ gpointer user_data)
+{
+ LlcpListenData *data;
+
+ INFO_MSG(">>> REQUEST from [%s]",
+ g_dbus_method_invocation_get_sender(invocation));
+
+ /* check privilege and update client context */
+ if (net_nfc_server_gdbus_check_privilege(invocation,
+ smack_privilege,
+ "nfc-manager::p2p",
+ "rw") == false) {
+ DEBUG_ERR_MSG("permission denied, and finished request");
+
+ return TRUE;
+ }
+
+ data = g_new0(LlcpListenData, 1);
+ if(data == NULL)
+ {
+ DEBUG_ERR_MSG("Memory allocation failed");
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.AllocationError",
+ "Can not allocate memory");
+ return FALSE;
+ }
+ data->llcp = g_object_ref(llcp);
+ data->invocation = g_object_ref(invocation);
+ data->handle = arg_handle;
+ data->client_socket = arg_client_socket;
+ data->oal_socket = arg_oal_socket;
+ data->miu = arg_miu;
+ data->rw = arg_rw;
+ data->type = arg_type;
+ data->sap = arg_sap;
+ data->service_name = g_strdup(arg_service_name);
+
+ if (net_nfc_server_controller_async_queue_push(
+ llcp_handle_listen_thread_func,
+ data) == FALSE)
+ {
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.ThreadError",
+ "can not push to controller thread");
+
+ g_object_unref(data->llcp);
+ g_object_unref(data->invocation);
+
+ g_free(data->service_name);
+ g_free(data);
+
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+static gboolean llcp_handle_connect(NetNfcGDbusLlcp *llcp,
+ GDBusMethodInvocation *invocation,
+ guint32 arg_handle,
+ guint32 arg_client_socket,
+ guint32 arg_oal_socket,
+ guint16 arg_miu,
+ guint8 arg_rw,
+ gint32 arg_type,
+ const gchar *arg_service_name,
+ GVariant *smack_privilege,
+ gpointer user_data)
+{
+ LlcpConnectData *data;
+
+ INFO_MSG(">>> REQUEST from [%s]",
+ g_dbus_method_invocation_get_sender(invocation));
+
+ /* check privilege and update client context */
+ if (net_nfc_server_gdbus_check_privilege(invocation,
+ smack_privilege,
+ "nfc-manager::p2p",
+ "rw") == false) {
+ DEBUG_ERR_MSG("permission denied, and finished request");
+
+ return TRUE;
+ }
+
+ data = g_new0(LlcpConnectData, 1);
+ if(data == NULL)
+ {
+ DEBUG_ERR_MSG("Memory allocation failed");
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.AllocationError",
+ "Can not allocate memory");
+ return FALSE;
+ }
+ data->llcp = g_object_ref(llcp);
+ data->invocation = g_object_ref(invocation);
+ data->handle = arg_handle;
+ data->client_socket = arg_client_socket;
+ data->oal_socket = arg_oal_socket;
+ data->miu = arg_miu;
+ data->rw = arg_rw;
+ data->type = arg_type;
+ data->service_name = g_strdup(arg_service_name);
+
+ if (net_nfc_server_controller_async_queue_push(
+ llcp_handle_connect_thread_func,
+ data) == FALSE)
+ {
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.ThreadError",
+ "can not push to controller thread");
+
+ g_object_unref(data->llcp);
+ g_object_unref(data->invocation);
+
+ g_free(data->service_name);
+ g_free(data);
+
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+static gboolean llcp_handle_connect_sap(NetNfcGDbusLlcp *llcp,
+ GDBusMethodInvocation *invocation,
+ guint32 arg_handle,
+ guint32 arg_client_socket,
+ guint32 arg_oal_socket,
+ guint16 arg_miu,
+ guint8 arg_rw,
+ gint32 arg_type,
+ guint8 arg_sap,
+ GVariant *smack_privilege,
+ gpointer user_data)
+{
+ LlcpConnectSapData *data;
+
+ INFO_MSG(">>> REQUEST from [%s]",
+ g_dbus_method_invocation_get_sender(invocation));
+
+ /* check privilege and update client context */
+ if (net_nfc_server_gdbus_check_privilege(invocation,
+ smack_privilege,
+ "nfc-manager::p2p",
+ "rw") == false) {
+ DEBUG_ERR_MSG("permission denied, and finished request");
+
+ return TRUE;
+ }
+
+ data = g_new0(LlcpConnectSapData, 1);
+ if(data == NULL)
+ {
+ DEBUG_ERR_MSG("Memory allocation failed");
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.AllocationError",
+ "Can not allocate memory");
+ return FALSE;
+ }
+ data->llcp = g_object_ref(llcp);
+ data->invocation = g_object_ref(invocation);
+ data->handle = arg_handle;
+ data->client_socket = arg_client_socket;
+ data->oal_socket = arg_oal_socket;
+ data->miu = arg_miu;
+ data->rw = arg_rw;
+ data->type = arg_type;
+ data->sap = arg_sap;
+
+ if(net_nfc_server_controller_async_queue_push(
+ llcp_handle_connect_sap_thread_func,
+ data) == FALSE)
+ {
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.ThreadError",
+ "can not push to controller thread");
+
+ g_object_unref(data->llcp);
+ g_object_unref(data->invocation);
+
+ g_free(data);
+
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+static gboolean llcp_handle_send(NetNfcGDbusLlcp *llcp,
+ GDBusMethodInvocation *invocation,
+ guint32 arg_handle,
+ guint32 arg_client_socket,
+ guint32 arg_oal_socket,
+ GVariant *arg_data,
+ GVariant *smack_privilege,
+ gpointer user_data)
+{
+ LlcpSendData *data;
+
+ INFO_MSG(">>> REQUEST from [%s]",
+ g_dbus_method_invocation_get_sender(invocation));
+
+ /* check privilege and update client context */
+ if (net_nfc_server_gdbus_check_privilege(invocation,
+ smack_privilege,
+ "nfc-manager::p2p",
+ "w") == false) {
+ DEBUG_ERR_MSG("permission denied, and finished request");
+
+ return TRUE;
+ }
+
+ data = g_new0(LlcpSendData, 1);
+ if(data == NULL)
+ {
+ DEBUG_ERR_MSG("Memory allocation failed");
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.AllocationError",
+ "Can not allocate memory");
+ return FALSE;
+ }
+ data->llcp = g_object_ref(llcp);
+ data->invocation = g_object_ref(invocation);
+ data->handle = arg_handle;
+ data->client_socket = arg_client_socket;
+ data->oal_socket = arg_oal_socket;
+
+ data->data = net_nfc_util_gdbus_variant_to_data(arg_data);
+
+ if (net_nfc_server_controller_async_queue_push(
+ llcp_handle_send_thread_func,
+ data) == FALSE)
+ {
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.ThreadError",
+ "can not push to controller thread");
+
+ g_object_unref(data->llcp);
+ g_object_unref(data->invocation);
+
+ if (data->data != NULL)
+ {
+ g_free(data->data->buffer);
+ g_free(data->data);
+ }
+
+ g_free(data);
+
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+static gboolean llcp_handle_send_to(NetNfcGDbusLlcp *llcp,
+ GDBusMethodInvocation *invocation,
+ guint32 arg_handle,
+ guint32 arg_client_socket,
+ guint32 arg_oal_socket,
+ guint8 arg_sap,
+ GVariant *arg_data,
+ GVariant *smack_privilege,
+ gpointer user_data)
+{
+ LlcpSendToData *data;
+
+ INFO_MSG(">>> REQUEST from [%s]",
+ g_dbus_method_invocation_get_sender(invocation));
+
+ /* check privilege and update client context */
+ if (net_nfc_server_gdbus_check_privilege(invocation,
+ smack_privilege,
+ "nfc-manager::p2p",
+ "rw") == false) {
+ DEBUG_ERR_MSG("permission denied, and finished request");
+
+ return TRUE;
+ }
+
+ data = g_new0(LlcpSendToData, 1);
+ if(data == NULL)
+ {
+ DEBUG_ERR_MSG("Memory allocation failed");
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.AllocationError",
+ "Can not allocate memory");
+ return FALSE;
+ }
+ data->llcp = g_object_ref(llcp);
+ data->invocation = g_object_ref(invocation);
+ data->handle = arg_handle;
+ data->client_socket = arg_client_socket;
+ data->oal_socket = arg_oal_socket;
+ data->sap = arg_sap;
+
+ data->data = net_nfc_util_gdbus_variant_to_data(arg_data);
+
+ if(net_nfc_server_controller_async_queue_push(
+ llcp_handle_send_to_thread_func,
+ data) == FALSE)
+ {
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.ThreadError",
+ "can not push to controller thread");
+
+ g_object_unref(data->llcp);
+ g_object_unref(data->invocation);
+
+ if (data->data != NULL)
+ {
+ g_free(data->data->buffer);
+ g_free(data->data);
+ }
+
+ g_free(data);
+
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+static gboolean llcp_handle_receive(NetNfcGDbusLlcp *llcp,
+ GDBusMethodInvocation *invocation,
+ guint32 arg_handle,
+ guint32 arg_client_socket,
+ guint32 arg_oal_socket,
+ guint32 arg_req_length,
+ GVariant *smack_privilege,
+ gpointer user_data)
+{
+ LlcpReceiveData *data;
+
+ INFO_MSG(">>> REQUEST from [%s]",
+ g_dbus_method_invocation_get_sender(invocation));
+
+ /* check privilege and update client context */
+ if (net_nfc_server_gdbus_check_privilege(invocation,
+ smack_privilege,
+ "nfc-manager::p2p",
+ "w") == false) {
+ DEBUG_ERR_MSG("permission denied, and finished request");
+
+ return TRUE;
+ }
+
+ data = g_new0(LlcpReceiveData, 1);
+ if(data == NULL)
+ {
+ DEBUG_ERR_MSG("Memory allocation failed");
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.AllocationError",
+ "Can not allocate memory");
+ return FALSE;
+ }
+ data->llcp = g_object_ref(llcp);
+ data->invocation = g_object_ref(invocation);
+ data->handle = arg_handle;
+ data->client_socket = arg_client_socket;
+ data->oal_socket = arg_oal_socket;
+ data->req_length = arg_req_length;
+
+ if(net_nfc_server_controller_async_queue_push(
+ llcp_handle_receive_thread_func,
+ data) == FALSE)
+ {
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.ThreadError",
+ "can not push to controller thread");
+
+ g_object_unref(data->llcp);
+ g_object_unref(data->invocation);
+
+ g_free(data);
+
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+static gboolean llcp_handle_receive_from(NetNfcGDbusLlcp *llcp,
+ GDBusMethodInvocation *invocation,
+ guint32 arg_handle,
+ guint32 arg_client_socket,
+ guint32 arg_oal_socket,
+ guint32 arg_req_length,
+ GVariant *smack_privilege,
+ gpointer user_data)
+{
+ LlcpReceiveData *data;
+
+ INFO_MSG(">>> REQUEST from [%s]",
+ g_dbus_method_invocation_get_sender(invocation));
+
+ /* check privilege and update client context */
+ if (net_nfc_server_gdbus_check_privilege(invocation,
+ smack_privilege,
+ "nfc-manager::p2p",
+ "w") == false) {
+ DEBUG_ERR_MSG("permission denied, and finished request");
+
+ return TRUE;
+ }
+
+ data = g_new0(LlcpReceiveData, 1);
+ if(data == NULL)
+ {
+ DEBUG_ERR_MSG("Memory allocation failed");
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.AllocationError",
+ "Can not allocate memory");
+ return FALSE;
+ }
+ data->llcp = g_object_ref(llcp);
+ data->invocation = g_object_ref(invocation);
+ data->handle = arg_handle;
+ data->client_socket = arg_client_socket;
+ data->oal_socket = arg_oal_socket;
+ data->req_length = arg_req_length;
+
+ if(net_nfc_server_controller_async_queue_push(
+ llcp_handle_receive_from_thread_func,
+ data) == FALSE)
+ {
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.ThreadError",
+ "can not push to controller thread");
+
+ g_object_unref(data->llcp);
+ g_object_unref(data->invocation);
+
+ g_free(data);
+
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+static gboolean llcp_handle_close(NetNfcGDbusLlcp *llcp,
+ GDBusMethodInvocation *invocation,
+ guint32 arg_handle,
+ guint32 arg_client_socket,
+ guint32 arg_oal_socket,
+ GVariant *smack_privilege,
+ gpointer user_data)
+{
+ LlcpCloseData *data;
+
+ INFO_MSG(">>> REQUEST from [%s]",
+ g_dbus_method_invocation_get_sender(invocation));
+
+ /* check privilege and update client context */
+ if (net_nfc_server_gdbus_check_privilege(invocation,
+ smack_privilege,
+ "nfc-manager::p2p",
+ "w") == false) {
+ DEBUG_ERR_MSG("permission denied, and finished request");
+
+ return TRUE;
+ }
+
+ data = g_new0(LlcpCloseData, 1);
+ if(data == NULL)
+ {
+ DEBUG_ERR_MSG("Memory allocation failed");
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.AllocationError",
+ "Can not allocate memory");
+ return FALSE;
+ }
+ data->llcp = g_object_ref(llcp);
+ data->invocation = g_object_ref(invocation);
+ data->handle = arg_handle;
+ data->client_socket = arg_client_socket;
+ data->oal_socket = arg_oal_socket;
+
+ if (net_nfc_server_controller_async_queue_push(
+ llcp_handle_close_thread_func,
+ data) == FALSE)
+ {
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.ThreadError",
+ "can not push to controller thread");
+
+ g_object_unref(data->llcp);
+ g_object_unref(data->invocation);
+
+ g_free(data);
+
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+static gboolean llcp_handle_disconnect(NetNfcGDbusLlcp *llcp,
+ GDBusMethodInvocation *invocation,
+ guint32 arg_handle,
+ guint32 arg_client_socket,
+ guint32 arg_oal_socket,
+ GVariant *smack_privilege,
+ gpointer user_data)
+{
+ LlcpDisconnectData *data;
+
+ INFO_MSG(">>> REQUEST from [%s]",
+ g_dbus_method_invocation_get_sender(invocation));
+
+ /* check privilege and update client context */
+ if (net_nfc_server_gdbus_check_privilege(invocation,
+ smack_privilege,
+ "nfc-manager::p2p",
+ "w") == false) {
+ DEBUG_ERR_MSG("permission denied, and finished request");
+
+ return TRUE;
+ }
+
+ data = g_new0(LlcpDisconnectData, 1);
+ if(data == NULL)
+ {
+ DEBUG_ERR_MSG("Memory allocation failed");
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.AllocationError",
+ "Can not allocate memory");
+ return FALSE;
+ }
+ data->llcp = g_object_ref(llcp);
+ data->invocation = g_object_ref(invocation);
+ data->handle = arg_handle;
+ data->client_socket = arg_client_socket;
+ data->oal_socket = arg_oal_socket;
+
+ if (net_nfc_server_controller_async_queue_push(
+ llcp_handle_disconnect_thread_func,
+ data) == FALSE)
+ {
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.ThreadError",
+ "can not push to controller thread");
+
+ g_object_unref(data->llcp);
+ g_object_unref(data->invocation);
+
+ g_free(data);
+
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+
+static void llcp_deactivated_thread_func(gpointer user_data)
+{
+ ServerLlcpData *data;
+
+ net_nfc_request_llcp_msg_t *req_llcp_msg;
+ net_nfc_target_handle_s *handle;
+
+ data = (ServerLlcpData *)user_data;
+
+ if (data == NULL)
+ {
+ DEBUG_ERR_MSG("can not get ServerLlcpData");
+
+ return;
+ }
+
+ if (data->llcp == NULL)
+ {
+ DEBUG_ERR_MSG("can not get llcp");
+
+ g_free(data->req_msg);
+ g_free(data);
+
+ return;
+ }
+
+ if (data->req_msg == NULL)
+ {
+ DEBUG_ERR_MSG("can not get request msg");
+
+ g_object_unref(data->llcp);
+ g_free(data);
+
+ return;
+ }
+
+ req_llcp_msg = (net_nfc_request_llcp_msg_t *)data->req_msg;
+
+ handle = (net_nfc_target_handle_s *)req_llcp_msg->user_param;
+ if (handle == NULL)
+ {
+ DEBUG_SERVER_MSG(
+ "the target ID = [0x%p] was not connected before."
+ "current device may be a TARGET", handle);
+ }
+ else
+ {
+ net_nfc_error_e result = NET_NFC_OK;
+
+ if (net_nfc_controller_disconnect(handle, &result) == false)
+ {
+ if (result != NET_NFC_NOT_CONNECTED)
+ {
+ net_nfc_controller_exception_handler();
+ }
+ else
+ {
+ DEBUG_SERVER_MSG("target was not connected.");
+ }
+ }
+
+ net_nfc_server_set_state(NET_NFC_SERVER_IDLE);
+ }
+
+ /* send p2p detatch */
+ net_nfc_server_p2p_detached();
+
+ g_object_unref(data->llcp);
+
+ g_free(data->req_msg);
+ g_free(data);
+}
+
+static void llcp_listen_thread_func(gpointer user_data)
+{
+ ServerLlcpData *data;
+
+ socket_info_t *info = NULL;
+ net_nfc_request_listen_socket_t *listen_socket;
+
+ data = (ServerLlcpData *)user_data;
+
+ if (data == NULL)
+ {
+ DEBUG_ERR_MSG("can not get ServerLlcpData");
+ return;
+ }
+
+ if (data->llcp == NULL)
+ {
+ DEBUG_ERR_MSG("can not get llcp");
+
+ g_free(data->req_msg);
+ g_free(data);
+
+ return;
+ }
+
+ if (data->req_msg == NULL)
+ {
+ DEBUG_ERR_MSG("can not get request msg");
+
+ g_object_unref(data->llcp);
+ g_free(data);
+
+ return;
+ }
+
+ listen_socket = (net_nfc_request_listen_socket_t *)data->req_msg;
+
+ info = (socket_info_t *)listen_socket->user_param;
+ info = _get_socket_info(info->socket);
+
+ if (info != NULL)
+ {
+ if (_add_socket_info(listen_socket->client_socket) != NULL)
+ {
+ if (info->work_cb != NULL)
+ {
+ info->work_cb(listen_socket->client_socket,
+ listen_socket->result, NULL, NULL,info->work_param);
+ }
+ }
+ else
+ {
+ DEBUG_ERR_MSG("_net_nfc_util_alloc_mem failed");
+ }
+ }
+
+ g_object_unref(data->llcp);
+
+ g_free(data->req_msg);
+ g_free(data);
+}
+
+static void llcp_socket_error_thread_func(gpointer user_data)
+{
+ ServerLlcpData *data;
+
+ net_nfc_request_llcp_msg_t *req_llcp_msg;
+ net_nfc_llcp_param_t *param;
+
+ data = (ServerLlcpData *)user_data;
+
+ if (data == NULL)
+ {
+ DEBUG_ERR_MSG("can not get ServerLlcpData");
+ return;
+ }
+
+ if (data->llcp == NULL)
+ {
+ DEBUG_ERR_MSG("can not get llcp");
+
+ g_free(data->req_msg);
+ g_free(data);
+
+ return;
+ }
+
+ if (data->req_msg == NULL)
+ {
+ DEBUG_ERR_MSG("can not get request msg");
+
+ g_object_unref(data->llcp);
+ g_free(data);
+
+ return;
+ }
+
+ req_llcp_msg = (net_nfc_request_llcp_msg_t *)data->req_msg;
+ param = (net_nfc_llcp_param_t *)req_llcp_msg->user_param;
+
+ if (param)
+ {
+ if (param->cb)
+ {
+ param->cb(req_llcp_msg->llcp_socket,
+ req_llcp_msg->result,
+ NULL,
+ NULL,
+ param->user_param);
+ }
+
+ g_free(param);
+ }
+
+ g_object_unref(data->llcp);
+
+ g_free(data->req_msg);
+ g_free(data);
+}
+
+static void llcp_send_thread_func(gpointer user_data)
+{
+ ServerLlcpData *data;
+
+ net_nfc_request_llcp_msg_t *req_llcp_msg;
+ net_nfc_llcp_param_t *param;
+
+ data = (ServerLlcpData *)user_data;
+
+ if (data == NULL)
+ {
+ DEBUG_ERR_MSG("can not get ServerLlcpData");
+
+ return;
+ }
+
+ if (data->llcp == NULL)
+ {
+ DEBUG_ERR_MSG("can not get llcp");
+
+ g_free(data->req_msg);
+ g_free(data);
+
+ return;
+ }
+
+ if (data->req_msg == NULL)
+ {
+ DEBUG_ERR_MSG("can not get request msg");
+
+ g_object_unref(data->llcp);
+ g_free(data);
+
+ return;
+ }
+
+ req_llcp_msg = (net_nfc_request_llcp_msg_t *)data->req_msg;
+ param = (net_nfc_llcp_param_t *)req_llcp_msg->user_param;
+
+ if (param)
+ {
+ if (param->cb)
+ {
+ param->cb(param->socket,
+ req_llcp_msg->result,
+ NULL,
+ NULL,
+ param->user_param);
+ }
+
+ g_free(param);
+ }
+
+ g_object_unref(data->llcp);
+
+ g_free(data->req_msg);
+ g_free(data);
+}
+
+static void llcp_receive_thread_func(gpointer user_data)
+{
+ ServerLlcpData *data;
+
+ net_nfc_request_receive_socket_t *req_receive_socket;
+ net_nfc_llcp_param_t *param;
+
+ data = (ServerLlcpData *)user_data;
+
+ if (data == NULL)
+ {
+ DEBUG_ERR_MSG("can not get ServerLlcpData");
+
+ return;
+ }
+
+ if (data->llcp == NULL)
+ {
+ DEBUG_ERR_MSG("can not get llcp");
+
+ g_free(data->req_msg);
+ g_free(data);
+
+ return;
+ }
+
+ if (data->req_msg == NULL)
+ {
+ DEBUG_ERR_MSG("can not get request msg");
+
+ g_object_unref(data->llcp);
+ g_free(data);
+
+ return;
+ }
+
+ req_receive_socket = (net_nfc_request_receive_socket_t *)data->req_msg;
+ param = (net_nfc_llcp_param_t *)req_receive_socket->user_param;
+
+ if (param)
+ {
+ if (param->cb)
+ {
+ param->cb(param->socket,
+ req_receive_socket->result,
+ ¶m->data,
+ NULL,
+ param->user_param);
+ }
+
+ if (param->data.buffer)
+ g_free(param->data.buffer);
+
+ g_free(param);
+ }
+
+ g_object_unref(data->llcp);
+
+ g_free(data->req_msg);
+ g_free(data);
+}
+
+static void llcp_receive_from_thread_func(gpointer user_data)
+{
+ ServerLlcpData *data;
+
+ net_nfc_request_receive_from_socket_t *req_receive_from_socket;
+ net_nfc_llcp_param_t *param;
+
+ data = (ServerLlcpData *)user_data;
+
+ if (data == NULL)
+ {
+ DEBUG_ERR_MSG("can not get ServerLlcpData");
+
+ return;
+ }
+
+ if (data->llcp == NULL)
+ {
+ DEBUG_ERR_MSG("can not get llcp");
+
+ g_free(data->req_msg);
+ g_free(data);
+
+ return;
+ }
+
+ if (data->req_msg == NULL)
+ {
+ DEBUG_ERR_MSG("can not get request msg");
+
+ g_object_unref(data->llcp);
+ g_free(data);
+
+ return;
+ }
+
+ req_receive_from_socket = (net_nfc_request_receive_from_socket_t *)
+ data->req_msg;
+ param = (net_nfc_llcp_param_t *)req_receive_from_socket->user_param;
+
+ if (param)
+ {
+ if (param->cb)
+ {
+ param->cb(param->socket,
+ req_receive_from_socket->result,
+ ¶m->data,
+ (void *)(int)req_receive_from_socket->sap,
+ param->user_param);
+ }
+
+ if (param->data.buffer)
+ g_free(param->data.buffer);
+
+ g_free(param);
+ }
+
+ g_object_unref(data->llcp);
+
+ g_free(data->req_msg);
+ g_free(data);
+}
+
+static void llcp_connect_thread_func(gpointer user_data)
+{
+ ServerLlcpData *data;
+
+ net_nfc_request_llcp_msg_t *req_llcp_msg;
+ net_nfc_llcp_param_t *param;
+
+ data = (ServerLlcpData *)user_data;
+
+ if (data == NULL)
+ {
+ DEBUG_ERR_MSG("can not get ServerLlcpData");
+
+ return;
+ }
+
+ if (data->llcp == NULL)
+ {
+ DEBUG_ERR_MSG("can not get llcp");
+
+ g_free(data->req_msg);
+ g_free(data);
+
+ return;
+ }
+
+ if (data->req_msg == NULL)
+ {
+ DEBUG_ERR_MSG("can not get request msg");
+
+ g_object_unref(data->llcp);
+ g_free(data);
+
+ return;
+ }
+
+ req_llcp_msg = (net_nfc_request_llcp_msg_t *)data->req_msg;
+ param = (net_nfc_llcp_param_t *)req_llcp_msg->user_param;
+
+ if (param)
+ {
+ if (param->cb)
+ {
+ param->cb(param->socket,
+ req_llcp_msg->result,
+ NULL,
+ NULL,
+ param->user_param);
+ }
+
+ g_free(param);
+ }
+
+ g_object_unref(data->llcp);
+
+ g_free(data->req_msg);
+ g_free(data);
+}
+
+static void llcp_disconnect_thread_func(gpointer user_data)
+{
+ ServerLlcpData *data;
+
+ net_nfc_request_llcp_msg_t *req_llcp_msg;
+ net_nfc_llcp_param_t *param;
+
+ data = (ServerLlcpData *)user_data;
+
+ if (data == NULL)
+ {
+ DEBUG_ERR_MSG("can not get ServerLlcpData");
+
+ return;
+ }
+
+ if (data->llcp == NULL)
+ {
+ DEBUG_ERR_MSG("can not get llcp");
+
+ g_free(data->req_msg);
+ g_free(data);
+
+ return;
+ }
+
+ if (data->req_msg == NULL)
+ {
+ DEBUG_ERR_MSG("can not get request msg");
+
+ g_object_unref(data->llcp);
+ g_free(data);
+
+ return;
+ }
+
+ req_llcp_msg = (net_nfc_request_llcp_msg_t *)data->req_msg;
+ param = (net_nfc_llcp_param_t *)req_llcp_msg->user_param;
+
+ if (param)
+ {
+ if (param->cb)
+ {
+ param->cb(param->socket,
+ req_llcp_msg->result,
+ NULL,
+ NULL,
+ param->user_param);
+ }
+
+ g_free(param);
+ }
+
+ g_object_unref(data->llcp);
+
+ g_free(data->req_msg);
+ g_free(data);
+}
+
+static void llcp_simple_socket_error_cb(net_nfc_llcp_socket_t socket,
+ net_nfc_error_e result,
+ data_s *data,
+ void *extra,
+ void *user_param)
+{
+ LlcpSimpleData *simple_data;
+
+ simple_data = (LlcpSimpleData *)user_param;
+
+ if (simple_data->error_callback)
+ {
+ simple_data->error_callback(result,
+ simple_data->handle,
+ socket,
+ data,
+ simple_data->user_data);
+ }
+
+ g_free(simple_data);
+}
+
+static void llcp_simple_listen_cb(net_nfc_llcp_socket_t socket,
+ net_nfc_error_e result,
+ data_s *data,
+ void *extra,
+ void *user_param)
+{
+ LlcpSimpleData *simple_data;
+
+ simple_data = (LlcpSimpleData *)user_param;
+
+ if (result != NET_NFC_OK) {
+ DEBUG_ERR_MSG("listen socket failed, [%d]", result);
+ }
+
+ if (simple_data->callback)
+ {
+ simple_data->callback(result,
+ simple_data->handle,
+ socket,
+ data,
+ simple_data->user_data);
+ }
+
+ g_free(simple_data);
+}
+
+static void llcp_simple_connect_cb(net_nfc_llcp_socket_t socket,
+ net_nfc_error_e result,
+ data_s *data,
+ void *extra,
+ void *user_param)
+{
+ LlcpSimpleData *simple_data;
+
+ simple_data = (LlcpSimpleData *)user_param;
+
+ if (result != NET_NFC_OK) {
+ DEBUG_ERR_MSG("connect socket failed, [%d]", result);
+ }
+
+ if (simple_data->callback)
+ {
+ simple_data->callback(result,
+ simple_data->handle,
+ socket,
+ data,
+ simple_data->user_data);
+ }
+
+ g_free(simple_data);
+}
+
+static void llcp_simple_server_error_cb(net_nfc_llcp_socket_t socket,
+ net_nfc_error_e result,
+ data_s *data,
+ void *extra,
+ void *user_param)
+{
+ LlcpSimpleData *simple_data;
+
+ simple_data = (LlcpSimpleData *)user_param;
+
+ if (simple_data->error_callback)
+ {
+ simple_data->error_callback(result,
+ simple_data->handle,
+ socket,
+ data,
+ simple_data->user_data);
+ }
+
+ g_free(simple_data);
+}
+
+static void llcp_simple_send_cb(net_nfc_llcp_socket_t socket,
+ net_nfc_error_e result,
+ data_s *data,
+ void *extra,
+ void *user_param)
+{
+ LlcpSimpleData *simple_data;
+
+ simple_data = (LlcpSimpleData *)user_param;
+
+ if (simple_data->callback)
+ {
+ simple_data->callback(result,
+ simple_data->handle,
+ socket,
+ data,
+ simple_data->user_data);
+ }
+
+ g_free(simple_data);
+}
+
+static void llcp_simple_receive_cb(net_nfc_llcp_socket_t socket,
+ net_nfc_error_e result,
+ data_s *data,
+ void *extra,
+ void *user_param)
+{
+ LlcpSimpleData *simple_data;
+
+ simple_data = (LlcpSimpleData *)user_param;
+
+ if (simple_data->callback)
+ {
+ simple_data->callback(result,
+ simple_data->handle,
+ socket,
+ data,
+ simple_data->user_data);
+ }
+
+ g_free(simple_data);
+}
+
+/* Public Function */
+gboolean net_nfc_server_llcp_init(GDBusConnection *connection)
+{
+ GError *error = NULL;
+
+ if (llcp_skeleton)
+ g_object_unref(llcp_skeleton);
+
+ llcp_skeleton = net_nfc_gdbus_llcp_skeleton_new();
+
+ g_signal_connect(llcp_skeleton,
+ "handle-config",
+ G_CALLBACK(llcp_handle_config),
+ NULL);
+
+ g_signal_connect(llcp_skeleton,
+ "handle-listen",
+ G_CALLBACK(llcp_handle_listen),
+ NULL);
+
+ g_signal_connect(llcp_skeleton,
+ "handle-connect",
+ G_CALLBACK(llcp_handle_connect),
+ NULL);
+
+ g_signal_connect(llcp_skeleton,
+ "handle-connect-sap",
+ G_CALLBACK(llcp_handle_connect_sap),
+ NULL);
+
+ g_signal_connect(llcp_skeleton,
+ "handle-send",
+ G_CALLBACK(llcp_handle_send),
+ NULL);
+
+ g_signal_connect(llcp_skeleton,
+ "handle-send-to",
+ G_CALLBACK(llcp_handle_send_to),
+ NULL);
+
+ g_signal_connect(llcp_skeleton,
+ "handle-receive",
+ G_CALLBACK(llcp_handle_receive),
+ NULL);
+
+ g_signal_connect(llcp_skeleton,
+ "handle-receive-from",
+ G_CALLBACK(llcp_handle_receive_from),
+ NULL);
+
+ g_signal_connect(llcp_skeleton,
+ "handle-close",
+ G_CALLBACK(llcp_handle_close),
+ NULL);
+
+ g_signal_connect(llcp_skeleton,
+ "handle-disconnect",
+ G_CALLBACK(llcp_handle_disconnect),
+ NULL);
+
+ if(g_dbus_interface_skeleton_export(
+ G_DBUS_INTERFACE_SKELETON(llcp_skeleton),
+ connection,
+ "/org/tizen/NetNfcService/Llcp",
+ &error) == FALSE)
+ {
+ g_error_free(error);
+ g_object_unref(llcp_skeleton);
+ llcp_skeleton = NULL;
+
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+void net_nfc_server_llcp_deinit(void)
+{
+ if (llcp_skeleton)
+ {
+ g_object_unref(llcp_skeleton);
+ llcp_skeleton = NULL;
+ }
+}
+
+void net_nfc_server_llcp_deactivated(net_nfc_request_msg_t *req_msg)
+{
+ llcp_add_async_queue(req_msg, llcp_deactivated_thread_func);
+}
+
+void net_nfc_server_llcp_listen(net_nfc_request_msg_t *req_msg)
+{
+ llcp_add_async_queue(req_msg, llcp_listen_thread_func);
+}
+
+void net_nfc_server_llcp_socket_error(net_nfc_request_msg_t *req_msg)
+{
+ llcp_add_async_queue(req_msg, llcp_socket_error_thread_func);
+}
+
+void net_nfc_server_llcp_send(net_nfc_request_msg_t *req_msg)
+{
+ llcp_add_async_queue(req_msg, llcp_send_thread_func);
+}
+
+void net_nfc_server_llcp_receive(net_nfc_request_msg_t *req_msg)
+{
+ llcp_add_async_queue(req_msg, llcp_receive_thread_func);
+}
+
+void net_nfc_server_llcp_receive_from(net_nfc_request_msg_t *req_msg)
+{
+ llcp_add_async_queue(req_msg, llcp_receive_from_thread_func);
+}
+
+void net_nfc_server_llcp_connect(net_nfc_request_msg_t *req_msg)
+{
+ llcp_add_async_queue(req_msg, llcp_connect_thread_func);
+}
+
+void net_nfc_server_llcp_disconnect(net_nfc_request_msg_t *req_msg)
+{
+ llcp_add_async_queue(req_msg, llcp_disconnect_thread_func);
+}
+
+net_nfc_error_e net_nfc_server_llcp_set_config(
+ net_nfc_llcp_config_info_s *config)
+{
+ net_nfc_error_e result;
+
+ if (config == NULL)
+ {
+ net_nfc_controller_llcp_config(&llcp_config, &result);
+ return result;
+ }
+
+ net_nfc_controller_llcp_config(config, &result);
+ memcpy(&llcp_config, config, sizeof(llcp_config));
+
+ return result;
+}
+
+guint16 net_nfc_server_llcp_get_miu(void)
+{
+ return llcp_config.miu;
+}
+
+guint16 net_nfc_server_llcp_get_wks(void)
+{
+ return llcp_config.wks;
+}
+
+guint8 net_nfc_server_llcp_get_lto(void)
+{
+ return llcp_config.lto;
+}
+
+guint8 net_nfc_server_llcp_get_option(void)
+{
+ return llcp_config.option;
+}
+
+net_nfc_error_e net_nfc_server_llcp_simple_server(
+ net_nfc_target_handle_s *handle,
+ const char *san,
+ sap_t sap,
+ net_nfc_server_llcp_callback callback,
+ net_nfc_server_llcp_callback error_callback,
+ gpointer user_data)
+{
+ net_nfc_error_e result = NET_NFC_OK;
+
+ net_nfc_llcp_socket_t socket = -1;
+ net_nfc_llcp_config_info_s config;
+
+ LlcpSimpleData *simple_data = NULL;
+
+ if (handle == NULL)
+ return NET_NFC_NULL_PARAMETER;
+
+ if (san == NULL)
+ return NET_NFC_NULL_PARAMETER;
+
+ if (net_nfc_controller_llcp_get_remote_config(handle,
+ &config,
+ &result) == false)
+ {
+ DEBUG_ERR_MSG("%s failed [%d]",
+ "net_nfc_controller_llcp_get_remote_config",
+ result);
+ return result;
+ }
+
+ simple_data = g_new0(LlcpSimpleData, 1);
+ if(simple_data == NULL)
+ {
+ DEBUG_ERR_MSG("Memory allocation failed");
+
+ return NET_NFC_ALLOC_FAIL;
+ }
+ simple_data->handle = handle;
+ simple_data->callback = callback;
+ simple_data->error_callback = error_callback;
+ simple_data->user_data = user_data;
+
+ simple_data->miu = MIN(config.miu, net_nfc_server_llcp_get_miu());
+
+ if (net_nfc_controller_llcp_create_socket(&socket,
+ NET_NFC_LLCP_SOCKET_TYPE_CONNECTIONORIENTED,
+ simple_data->miu,
+ 1,
+ &result,
+ llcp_simple_socket_error_cb,
+ simple_data) == false)
+ {
+ DEBUG_ERR_MSG("%s failed [%d]",
+ "net_nfc_controller_llcp_create_socket",
+ result);
+
+ g_free(simple_data);
+ return result;
+ }
+
+ simple_data->socket = socket;
+
+ if (net_nfc_controller_llcp_bind(socket,
+ sap,
+ &result) == false)
+ {
+ DEBUG_ERR_MSG("%s failed [%d]",
+ "nte_nfc_controller_llcp_bind",
+ result);
+
+ if (simple_data->socket != 1)
+ net_nfc_controller_llcp_socket_close(socket, &result);
+
+ g_free(simple_data);
+
+ return result;
+ }
+
+ if (net_nfc_controller_llcp_listen(handle,
+ (uint8_t *)san,
+ socket,
+ &result,
+ llcp_simple_listen_cb,
+ simple_data) == false)
+ {
+ DEBUG_ERR_MSG("%s failed [%d]",
+ "net_nfc_controller_llcp_listen",
+ result);
+
+ if (simple_data->socket != 1)
+ {
+ net_nfc_controller_llcp_socket_close(
+ simple_data->socket,
+ &result);
+ }
+
+ g_free(simple_data);
+
+ return result;
+
+ }
+
+ DEBUG_SERVER_MSG("result [%d]", result);
+
+ if (result == NET_NFC_BUSY)
+ result = NET_NFC_OK;
+
+ return result;
+}
+
+net_nfc_error_e net_nfc_server_llcp_simple_client(
+ net_nfc_target_handle_s *handle,
+ const char *san,
+ sap_t sap,
+ net_nfc_server_llcp_callback callback,
+ net_nfc_server_llcp_callback error_callback,
+ gpointer user_data)
+{
+ net_nfc_error_e result = NET_NFC_OK;
+
+ net_nfc_llcp_socket_t socket = -1;
+ net_nfc_llcp_config_info_s config;
+
+ LlcpSimpleData *simple_data = NULL;
+
+ if (handle == NULL)
+ return NET_NFC_NULL_PARAMETER;
+
+ if (net_nfc_controller_llcp_get_remote_config(handle,
+ &config,
+ &result) == false)
+ {
+ DEBUG_ERR_MSG("%s failed [%d]",
+ "net_nfc_controller_llcp_get_remote_config",
+ result);
+ return result;
+ }
+
+ simple_data = g_new0(LlcpSimpleData, 1);
+
+ simple_data->handle = handle;
+ simple_data->callback = callback;
+ simple_data->error_callback = error_callback;
+ simple_data->user_data = user_data;
+
+ simple_data->miu = MIN(config.miu, net_nfc_server_llcp_get_miu());
+
+ if (net_nfc_controller_llcp_create_socket(&socket,
+ NET_NFC_LLCP_SOCKET_TYPE_CONNECTIONORIENTED,
+ simple_data->miu,
+ 1,
+ &result,
+ llcp_simple_socket_error_cb,
+ simple_data) == false)
+ {
+ DEBUG_ERR_MSG("%s failed [%d]",
+ "net_nfc_controller_llcp_create_socket",
+ result);
+
+ g_free(simple_data);
+ return result;
+ }
+
+ simple_data->socket = socket;
+
+ if (san == NULL)
+ {
+ if (net_nfc_controller_llcp_connect(handle,
+ simple_data->socket,
+ sap,
+ &result,
+ llcp_simple_connect_cb,
+ simple_data) == false)
+ {
+ DEBUG_ERR_MSG("%s failed [%d]",
+ "net_nfc_controller_llcp_connect",
+ result);
+
+ if (simple_data->socket != -1)
+ {
+ net_nfc_controller_llcp_socket_close(
+ simple_data->socket,
+ &result);
+ }
+
+ g_free(simple_data);
+
+ return result;
+ }
+
+ }
+ else
+ {
+ if (net_nfc_controller_llcp_connect_by_url(handle,
+ simple_data->socket,
+ (uint8_t *)san,
+ &result,
+ llcp_simple_connect_cb,
+ simple_data) == false)
+ {
+ DEBUG_ERR_MSG("%s failed [%d]",
+ "net_nfc_controller_llcp_connect_by_url",
+ result);
+
+ if (simple_data->socket != -1)
+ {
+ net_nfc_controller_llcp_socket_close(
+ simple_data->socket,
+ &result);
+ }
+
+ g_free(simple_data);
+
+ return result;
+ }
+ }
+
+ DEBUG_SERVER_MSG("result [%d]", result);
+
+ if (result == NET_NFC_BUSY)
+ result = NET_NFC_OK;
+
+ return result;
+}
+
+net_nfc_error_e net_nfc_server_llcp_simple_accept(
+ net_nfc_target_handle_s *handle,
+ net_nfc_llcp_socket_t socket,
+ net_nfc_server_llcp_callback error_callback,
+ gpointer user_data)
+{
+ net_nfc_error_e result = NET_NFC_OK;
+
+ LlcpSimpleData *simple_data;
+
+ simple_data = g_new0(LlcpSimpleData, 1);
+ if(simple_data == NULL)
+ {
+ DEBUG_ERR_MSG("Memory allocation failed");
+
+ return NET_NFC_ALLOC_FAIL;
+ }
+ simple_data->handle = handle;
+ simple_data->socket = socket;
+ simple_data->error_callback = error_callback;
+ simple_data->user_data = user_data;
+
+ if (net_nfc_controller_llcp_accept(socket,
+ &result,
+ llcp_simple_server_error_cb,
+ simple_data) == false)
+ {
+ DEBUG_ERR_MSG("%s failed [%d]",
+ "net_nfc_controller_llcp_accept",
+ result);
+ }
+
+ if (result == NET_NFC_BUSY)
+ result = NET_NFC_OK;
+
+ return result;
+}
+
+net_nfc_error_e net_nfc_server_llcp_simple_send(
+ net_nfc_target_handle_s *handle,
+ net_nfc_llcp_socket_t socket,
+ data_s *data,
+ net_nfc_server_llcp_callback callback,
+ gpointer user_data)
+{
+ net_nfc_error_e result = NET_NFC_OK;
+
+ LlcpSimpleData *simple_data;
+
+ simple_data = g_new0(LlcpSimpleData, 1);
+ if(simple_data == NULL)
+ {
+ DEBUG_ERR_MSG("Memory allocation failed");
+
+ return NET_NFC_ALLOC_FAIL;
+ }
+ simple_data->handle = handle;
+ simple_data->socket = socket;
+ simple_data->callback = callback;
+ simple_data->user_data = user_data;
+
+ if (net_nfc_controller_llcp_send(handle,
+ socket,
+ data,
+ &result,
+ llcp_simple_send_cb,
+ simple_data) == false)
+ {
+ DEBUG_ERR_MSG("%s failed [%d]",
+ "net_nfc_controller_llcp_send",
+ result);
+ }
+
+ if (result == NET_NFC_BUSY)
+ result = NET_NFC_OK;
+
+ return result;
+}
+
+net_nfc_error_e net_nfc_server_llcp_simple_receive(
+ net_nfc_target_handle_s *handle,
+ net_nfc_llcp_socket_t socket,
+ net_nfc_server_llcp_callback callback,
+ gpointer user_data)
+{
+ net_nfc_error_e result = NET_NFC_OK;
+
+ LlcpSimpleData *simple_data;
+
+ simple_data = g_new0(LlcpSimpleData, 1);
+ if(simple_data == NULL)
+ {
+ DEBUG_ERR_MSG("Memory allocation failed");
+
+ return NET_NFC_ALLOC_FAIL;
+ }
+ simple_data->handle = handle;
+ simple_data->socket = socket;
+ simple_data->callback = callback;
+ simple_data->user_data = user_data;
+
+ if (net_nfc_controller_llcp_recv(handle,
+ socket,
+ net_nfc_server_llcp_get_miu(),
+ &result,
+ llcp_simple_receive_cb,
+ simple_data) == false)
+ {
+ DEBUG_ERR_MSG("%s failed [%d]",
+ "net_nfc_controller_llcp_send",
+ result);
+ }
+
+ if (result == NET_NFC_BUSY)
+ result = NET_NFC_OK;
+
+ return result;
+}
+
+typedef struct _service_t
+{
+ uint32_t sap;
+ char *san;
+ char *id;
+ net_nfc_server_llcp_activate_cb cb;
+ void *user_data;
+}
+service_t;
+
+static GHashTable *service_table;
+
+static void _llcp_init()
+{
+ if (service_table == NULL)
+ service_table = g_hash_table_new(NULL, NULL);
+}
+
+inline static service_t *_llcp_find_service(uint32_t sap)
+{
+ return (service_t *)g_hash_table_lookup(service_table,
+ (gconstpointer)sap);
+}
+
+static net_nfc_error_e _llcp_add_service(const char *id, uint32_t sap,
+ const char *san, net_nfc_server_llcp_activate_cb cb, void *user_data)
+{
+ service_t *service = NULL;
+ net_nfc_error_e result;
+
+ if (cb == NULL) {
+ DEBUG_ERR_MSG("callback is mandatory");
+
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ _llcp_init();
+
+ if (_llcp_find_service(sap) == NULL) {
+ DEBUG_SERVER_MSG("new service, sap [%d]", sap);
+
+ service = g_new0(service_t, 1);
+ if (service != NULL) {
+ service->sap = sap;
+ if (san != NULL && strlen(san) > 0) {
+ service->san = g_strdup(san);
+ }
+ if (id != NULL && strlen(id) > 0) {
+ service->id = g_strdup(id);
+ }
+ service->cb = cb;
+ service->user_data = user_data;
+
+ g_hash_table_insert(service_table, (gpointer)sap,
+ (gpointer)service);
+
+ result = NET_NFC_OK;
+ } else {
+ DEBUG_ERR_MSG("alloc failed");
+
+ result = NET_NFC_ALLOC_FAIL;
+ }
+ } else {
+ DEBUG_ERR_MSG("already registered");
+
+ result = NET_NFC_ALREADY_REGISTERED;
+ }
+
+ return result;
+}
+
+static void _llcp_remove_service(uint32_t sap)
+{
+ service_t *service = NULL;
+
+ service = _llcp_find_service(sap);
+ if (service != NULL) {
+ g_free(service->san);
+ g_free(service->id);
+ g_free(service);
+
+ g_hash_table_remove(service_table, (gconstpointer)sap);
+ }
+}
+
+static void _llcp_remove_services(const char *id)
+{
+ GHashTableIter iter;
+ gpointer key;
+ service_t *service;
+
+ if (service_table == NULL)
+ return;
+
+ g_hash_table_iter_init (&iter, service_table);
+
+ while (g_hash_table_iter_next (&iter, &key, (gpointer)&service)) {
+ if (id == NULL || strcmp(service->id, id) == 0) {
+ g_free(service->san);
+ g_free(service->id);
+ g_free(service);
+
+ g_hash_table_iter_remove(&iter);
+ }
+ }
+}
+
+static void _llcp_start_services_cb(gpointer key, gpointer value,
+ gpointer user_data)
+{
+ service_t *service = (service_t *)value;
+
+ /* TODO : start service */
+ if (service != NULL && service->cb != NULL) {
+ service->cb(NET_NFC_LLCP_START,
+ (net_nfc_target_handle_s *)user_data,
+ service->sap,
+ service->san, service->user_data);
+ }
+}
+
+static void _llcp_start_services(net_nfc_target_handle_s *handle)
+{
+ g_hash_table_foreach(service_table, _llcp_start_services_cb, handle);
+}
+
+net_nfc_error_e net_nfc_server_llcp_register_service(const char *id,
+ sap_t sap, const char *san, net_nfc_server_llcp_activate_cb cb,
+ void *user_param)
+{
+ return _llcp_add_service(id, sap, san, cb, user_param);
+}
+
+net_nfc_error_e net_nfc_server_llcp_unregister_service(const char *id,
+ sap_t sap, const char *san)
+{
+ net_nfc_error_e result;
+ service_t *service;
+
+ service = _llcp_find_service(sap);
+ if (service != NULL) {
+ /* invoke callback */
+ service->cb(NET_NFC_LLCP_UNREGISTERED, NULL, service->sap,
+ service->san, service->user_data);
+
+ _llcp_remove_service(sap);
+
+ result = NET_NFC_OK;
+ } else {
+ DEBUG_ERR_MSG("service is not registered");
+
+ result = NET_NFC_NOT_REGISTERED;
+ }
+
+ return result;
+}
+
+net_nfc_error_e net_nfc_server_llcp_unregister_services(const char *id)
+{
+ _llcp_remove_services(id);
+
+ return NET_NFC_OK;
+}
+
+net_nfc_error_e net_nfc_server_llcp_unregister_all()
+{
+ GHashTableIter iter;
+ gpointer key;
+ service_t *service;
+
+ if (service_table == NULL)
+ return NET_NFC_OK;
+
+ g_hash_table_iter_init(&iter, service_table);
+
+ while (g_hash_table_iter_next(&iter, &key, (gpointer)&service)) {
+ service->cb(NET_NFC_LLCP_UNREGISTERED, NULL, service->sap,
+ service->san, service->user_data);
+
+ g_free(service->san);
+ g_free(service->id);
+ g_free(service);
+
+ g_hash_table_iter_remove(&iter);
+ }
+
+ return NET_NFC_OK;
+}
+
+net_nfc_error_e net_nfc_server_llcp_start_registered_services(
+ net_nfc_target_handle_s *handle)
+{
+ _llcp_start_services(handle);
+
+ return NET_NFC_OK;
+}
+
+static void net_nfc_server_llcp_process(gpointer user_data)
+{
+ net_nfc_current_target_info_s *target;
+#if 0
+ net_nfc_error_e result;
+#endif
+ net_nfc_target_handle_s *handle;
+ net_nfc_target_type_e dev_type;
+
+ target = net_nfc_server_get_target_info();
+
+ g_assert(target != NULL); /* raise exception!!! what;s wrong?? */
+
+ handle = target->handle;
+ dev_type = target->devType;
+
+ DEBUG_SERVER_MSG("connection type = [%d]", handle->connection_type);
+#if 0
+ if (dev_type == NET_NFC_NFCIP1_TARGET)
+ {
+ DEBUG_SERVER_MSG("LLCP : target, try to connect");
+
+ if (net_nfc_controller_connect(handle, &result) == false)
+ {
+ DEBUG_SERVER_MSG("%s is failed, [%d]",
+ "net_nfc_controller_connect",
+ result);
+
+ if (net_nfc_controller_configure_discovery(
+ NET_NFC_DISCOVERY_MODE_RESUME,
+ NET_NFC_ALL_ENABLE,
+ &result) == false)
+ {
+ DEBUG_ERR_MSG("%s is failed [%d]",
+ "net_nfc_controller_configure_discovery",
+ result);
+
+ net_nfc_controller_exception_handler();
+ }
+
+ return;
+ }
+ }
+
+ DEBUG_SERVER_MSG("check LLCP");
+
+ if (net_nfc_controller_llcp_check_llcp(handle, &result) == false)
+ {
+ DEBUG_ERR_MSG("%s is failed [%d]",
+ "net_nfc_controller_llcp_check_llcp",
+ result);
+
+ return;
+ }
+
+ DEBUG_SERVER_MSG("activate LLCP");
+
+ if (net_nfc_controller_llcp_activate_llcp(handle, &result) == false)
+ {
+ DEBUG_ERR_MSG("%s is failed [%d]",
+ "net_nfc_controller_llcp_activate_llcp",
+ result);
+
+ return;
+ }
+#endif
+ net_nfc_server_llcp_start_registered_services(handle);
+
+ net_nfc_server_p2p_discovered(handle);
+}
+
+void net_nfc_server_llcp_target_detected(void *info)
+{
+ if (net_nfc_server_controller_async_queue_push(
+ net_nfc_server_llcp_process, NULL) == FALSE)
+ {
+ DEBUG_ERR_MSG("can not push to controller thread");
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_SERVER_LLCP_H__
+#define __NET_NFC_SERVER_LLCP_H__
+
+#include <gio/gio.h>
+
+#include "net_nfc_typedef_internal.h"
+
+/* define */
+/* Service Name should be followed naming rule. */
+// service access name
+#define SDP_SAN "urn:nfc:sn:sdp"
+#define IP_SAN "urn:nfc:sn:ip"
+#define OBEX_SAN "urn:nfc:sn:obex"
+
+#define SDP_SAP 1 /* service discovery protocol service access point */
+#define IP_SAP 2 /* Internet protocol service access point */
+#define OBEX_SAP 3 /* object exchange service access point */
+
+#define GET_MAJOR_VER(__x) (((__x) >> 4) & 0x0F)
+#define GET_MINOR_VER(__x) ((__x) & 0x0F)
+
+/* default llcp configurations */
+#define NET_NFC_LLCP_MIU 128
+#define NET_NFC_LLCP_WKS 1
+#define NET_NFC_LLCP_LTO 10
+#define NET_NFC_LLCP_OPT 0
+
+typedef enum
+{
+ NET_NFC_LLCP_IDLE = 0,
+ NET_NFC_LLCP_STEP_01 = 0xFFFF,
+ NET_NFC_LLCP_STEP_02,
+ NET_NFC_LLCP_STEP_03,
+ NET_NFC_LLCP_STEP_04,
+ NET_NFC_LLCP_STEP_05,
+ NET_NFC_LLCP_STEP_06,
+ NET_NFC_LLCP_STEP_07,
+ NET_NFC_LLCP_STEP_08,
+ NET_NFC_LLCP_STEP_09,
+ NET_NFC_LLCP_STEP_10,
+ NET_NFC_LLCP_STEP_11,
+ NET_NFC_LLCP_STEP_12,
+ NET_NFC_LLCP_STEP_13,
+ NET_NFC_LLCP_STEP_14,
+ NET_NFC_LLCP_STEP_15,
+ NET_NFC_LLCP_STEP_16,
+ NET_NFC_LLCP_STEP_17,
+ NET_NFC_LLCP_STEP_18,
+ NET_NFC_LLCP_STEP_19,
+ NET_NFC_LLCP_STEP_20,
+ NET_NFC_LLCP_STEP_RETURN,
+ NET_NFC_STATE_SOCKET_ERROR,
+ NET_NFC_STATE_ERROR,
+} net_nfc_state_e;
+
+typedef void (*net_nfc_server_llcp_callback) (net_nfc_error_e result,
+ net_nfc_target_handle_s *handle,
+ net_nfc_llcp_socket_t socket,
+ data_s *data,
+ gpointer user_data);
+
+typedef void (*net_nfc_server_llcp_activate_cb)(
+ int event,
+ net_nfc_target_handle_s *handle,
+ uint32_t sap,
+ const char *san,
+ void *user_param);
+
+gboolean net_nfc_server_llcp_init(GDBusConnection *connection);
+
+void net_nfc_server_llcp_deinit(void);
+
+/* server side */
+void net_nfc_server_llcp_deactivated(net_nfc_request_msg_t *req_msg);
+
+void net_nfc_server_llcp_listen(net_nfc_request_msg_t *req_msg);
+
+void net_nfc_server_llcp_socket_error(net_nfc_request_msg_t *req_msg);
+
+void net_nfc_server_llcp_socket_accepted_error(net_nfc_request_msg_t *req_msg);
+
+void net_nfc_server_llcp_send(net_nfc_request_msg_t *req_msg);
+
+void net_nfc_server_llcp_receive(net_nfc_request_msg_t *req_msg);
+
+void net_nfc_server_llcp_receive_from(net_nfc_request_msg_t *req_msg);
+
+void net_nfc_server_llcp_connect(net_nfc_request_msg_t *req_msg);
+
+void net_nfc_server_llcp_disconnect(net_nfc_request_msg_t *req_msg);
+
+net_nfc_error_e net_nfc_server_llcp_set_config(
+ net_nfc_llcp_config_info_s *config);
+
+guint16 net_nfc_server_llcp_get_miu(void);
+
+guint16 net_nfc_server_llcp_get_wks(void);
+
+guint8 net_nfc_server_llcp_get_lto(void);
+
+guint8 net_nfc_server_llcp_get_option(void);
+
+void net_nfc_server_llcp_target_detected(void *info);
+
+net_nfc_error_e net_nfc_server_llcp_simple_server(
+ net_nfc_target_handle_s *handle,
+ const char *san,
+ sap_t sap,
+ net_nfc_server_llcp_callback callback,
+ net_nfc_server_llcp_callback error_callback,
+ gpointer user_data);
+
+net_nfc_error_e net_nfc_server_llcp_simple_client(
+ net_nfc_target_handle_s *handle,
+ const char *san,
+ sap_t sap,
+ net_nfc_server_llcp_callback callback,
+ net_nfc_server_llcp_callback error_callback,
+ gpointer user_data);
+
+net_nfc_error_e net_nfc_server_llcp_simple_accept(
+ net_nfc_target_handle_s *handle,
+ net_nfc_llcp_socket_t socket,
+ net_nfc_server_llcp_callback error_callback,
+ gpointer user_data);
+
+net_nfc_error_e net_nfc_server_llcp_simple_send(
+ net_nfc_target_handle_s *handle,
+ net_nfc_llcp_socket_t socket,
+ data_s *data,
+ net_nfc_server_llcp_callback callback,
+ gpointer user_data);
+
+net_nfc_error_e net_nfc_server_llcp_simple_receive(
+ net_nfc_target_handle_s *handle,
+ net_nfc_llcp_socket_t socket,
+ net_nfc_server_llcp_callback callback,
+ gpointer user_data);
+
+net_nfc_error_e net_nfc_server_llcp_register_service(const char *id,
+ sap_t sap, const char *san, net_nfc_server_llcp_activate_cb cb,
+ void *user_param);
+
+net_nfc_error_e net_nfc_server_llcp_unregister_service(const char *id,
+ sap_t sap, const char *san);
+
+net_nfc_error_e net_nfc_server_llcp_unregister_services(const char *id);
+
+net_nfc_error_e net_nfc_server_llcp_unregister_all();
+
+net_nfc_error_e net_nfc_server_llcp_start_registered_services(
+ net_nfc_target_handle_s *handle);
+
+#endif //__NET_NFC_SERVER_LLCP_H__
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <vconf.h>
+
+#include "net_nfc_typedef.h"
+
+#include "net_nfc_gdbus.h"
+#include "net_nfc_server_common.h"
+#include "net_nfc_server_manager.h"
+#include "net_nfc_server_tag.h"
+
+#include "net_nfc_typedef_internal.h"
+#include "net_nfc_debug_internal.h"
+#include "net_nfc_server_controller.h"
+#include "net_nfc_server.h"
+#include "net_nfc_server_se.h"
+#include "net_nfc_server_llcp.h"
+#include "net_nfc_server_process_snep.h"
+#include "net_nfc_server_process_npp.h"
+#include "net_nfc_server_process_handover.h"
+#include "net_nfc_server_context.h"
+
+typedef struct _ManagerData ManagerData;
+
+struct _ManagerData
+{
+ NetNfcGDbusManager *manager;
+ GDBusMethodInvocation *invocation;
+};
+
+typedef struct _ManagerActivationData ManagerActivationData;
+
+struct _ManagerActivationData
+{
+ NetNfcGDbusManager *manager;
+ GDBusMethodInvocation *invocation;
+ gboolean is_active;
+};
+
+typedef struct _ManagerPrbsData ManagerPrbsData;
+
+struct _ManagerPrbsData
+{
+ NetNfcGDbusManager *manager;
+ GDBusMethodInvocation *invocation;
+ guint32 tech;
+ guint32 rate;
+};
+
+typedef struct _ServerManagerActivationData ServerManagerActivationData;
+
+struct _ServerManagerActivationData
+{
+ NetNfcGDbusManager *manager;
+ gboolean is_active;
+};
+
+
+static NetNfcGDbusManager *manager_skeleton = NULL;
+
+static gboolean manager_active(void);
+
+static gboolean manager_deactive(void);
+
+static void manager_handle_active_thread_func(gpointer user_data);
+
+static gboolean manager_handle_set_active(NetNfcGDbusManager *manager,
+ GDBusMethodInvocation *invocation,
+ gboolean arg_is_active,
+ GVariant *smack_privilege,
+ gpointer user_data);
+
+static gboolean manager_handle_get_server_state(NetNfcGDbusManager *manager,
+ GDBusMethodInvocation *invocation,
+ GVariant *smack_privilege,
+ gpointer user_data);
+
+
+static void manager_active_thread_func(gpointer user_data);
+
+
+/* reimplementation of net_nfc_service_init()*/
+static gboolean manager_active(void)
+{
+ net_nfc_error_e result;
+
+ if (net_nfc_controller_is_ready(&result) == false)
+ {
+ DEBUG_ERR_MSG("%s failed [%d]",
+ "net_nfc_cotroller_is_ready", result);
+ return FALSE;
+ }
+
+ result = net_nfc_server_se_change_se(SECURE_ELEMENT_TYPE_UICC);
+
+ /* register default snep server */
+ net_nfc_server_snep_default_server_register();
+
+ /* register default npp server */
+ net_nfc_server_npp_default_server_register();
+
+ /* register default handover server */
+ net_nfc_server_handover_default_server_register();
+
+ if (net_nfc_controller_configure_discovery(
+ NET_NFC_DISCOVERY_MODE_START,
+ NET_NFC_ALL_ENABLE,
+ &result) == false)
+ {
+ DEBUG_ERR_MSG("%s is failed %d",
+ "net_nfc_controller_configure_discovery",
+ result);
+ return FALSE;
+ }
+
+ /* vconf on */
+ if (vconf_set_bool(VCONFKEY_NFC_STATE, TRUE) != 0)
+ {
+ DEBUG_ERR_MSG("%s is failed", "vconf_set_bool");
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+/* reimplementation of net_nfc_service_deinit()*/
+static gboolean manager_deactive(void)
+{
+ net_nfc_error_e result;
+
+ if (net_nfc_controller_is_ready(&result) == false)
+ {
+ DEBUG_ERR_MSG("%s failed [%d]",
+ "net_nfc_cotroller_is_ready", result);
+ return FALSE;
+ }
+
+ /* unregister all services */
+ net_nfc_server_llcp_unregister_all();
+
+ result = net_nfc_server_se_change_se(SECURE_ELEMENT_TYPE_INVALID);
+
+ if (net_nfc_controller_configure_discovery(
+ NET_NFC_DISCOVERY_MODE_STOP,
+ NET_NFC_ALL_DISABLE,
+ &result) == false)
+ {
+ DEBUG_ERR_MSG("%s is failed %d",
+ "net_nfc_controller_configure_discovery",
+ result);
+ return FALSE;
+ }
+
+ /* vconf off */
+ if (vconf_set_bool(VCONFKEY_NFC_STATE, FALSE) != 0)
+ {
+ DEBUG_ERR_MSG("%s is failed", "vconf_set_bool");
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+static void manager_handle_active_thread_func(gpointer user_data)
+{
+ gboolean ret;
+
+ ManagerActivationData *data;
+
+ data = (ManagerActivationData *)user_data;
+
+ if (data == NULL)
+ {
+ DEBUG_ERR_MSG("can not get ManagerActivationData");
+ return;
+ }
+
+ if (data->is_active)
+ ret = manager_active();
+ else
+ ret = manager_deactive();
+
+ if (data->manager == NULL)
+ {
+ DEBUG_ERR_MSG("can not get manager");
+
+ if(data->invocation)
+ {
+ g_dbus_method_invocation_return_dbus_error(
+ data->invocation,
+ "org.tizen.NetNfcService.SetActiveError",
+ "Can not get manager");
+
+ g_object_unref(data->invocation);
+ }
+
+ g_free(data);
+ return;
+ }
+
+ if (ret == FALSE)
+ {
+ if (data->invocation)
+ {
+ g_dbus_method_invocation_return_dbus_error(
+ data->invocation,
+ "org.tizen.NetNfcService.SetActiveError",
+ "Can not set activation");
+
+ g_object_unref(data->invocation);
+ }
+
+ g_object_unref(data->manager);
+ g_free(data);
+
+ return;
+ }
+
+ net_nfc_gdbus_manager_emit_activated(data->manager,
+ data->is_active);
+
+ if (data->invocation)
+ {
+ net_nfc_gdbus_manager_complete_set_active(data->manager,
+ data->invocation);
+
+ g_object_unref(data->invocation);
+ }
+
+ g_object_unref(data->manager);
+ g_free(data);
+
+ /* shutdown process if it doesn't need */
+ if (data->is_active == false &&
+ net_nfc_server_gdbus_is_server_busy() == false) {
+
+ net_nfc_manager_quit();
+ }
+}
+
+
+static gboolean manager_handle_set_active(NetNfcGDbusManager *manager,
+ GDBusMethodInvocation *invocation,
+ gboolean arg_is_active,
+ GVariant *smack_privilege,
+ gpointer user_data)
+{
+ ManagerActivationData *data;
+
+ INFO_MSG(">>> REQUEST from [%s]",
+ g_dbus_method_invocation_get_sender(invocation));
+
+ /* check privilege and update client context */
+ if (net_nfc_server_gdbus_check_privilege(invocation,
+ smack_privilege,
+ "nfc-manager::admin",
+ "rw") == false) {
+ DEBUG_ERR_MSG("permission denied, and finished request");
+
+ return TRUE;
+ }
+
+ DEBUG_SERVER_MSG("is_active %d", arg_is_active);
+
+ data = g_new0(ManagerActivationData, 1);
+ if(data == NULL)
+ {
+ DEBUG_ERR_MSG("Memory allocation failed");
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.AllocationError",
+ "Can not allocate memory");
+ return FALSE;
+ }
+
+ data->manager = g_object_ref(manager);
+ data->invocation = g_object_ref(invocation);
+ data->is_active = arg_is_active;
+
+ if (net_nfc_server_controller_async_queue_push(
+ manager_handle_active_thread_func,
+ data) == FALSE)
+ {
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.ThreadError",
+ "can not push to controller thread");
+ if (data)
+ {
+ g_object_unref(data->manager);
+ g_object_unref(data->invocation);
+
+ g_free(data);
+ }
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+static gboolean manager_handle_get_server_state(NetNfcGDbusManager *manager,
+ GDBusMethodInvocation *invocation,
+ GVariant *smack_privilege,
+ gpointer user_data)
+{
+ guint32 state;
+
+ INFO_MSG(">>> REQUEST from [%s]",
+ g_dbus_method_invocation_get_sender(invocation));
+
+ /* check privilege and update client context */
+ if (net_nfc_server_gdbus_check_privilege(invocation,
+ smack_privilege,
+ "nfc-manager::admin",
+ "r") == false) {
+ DEBUG_ERR_MSG("permission denied, and finished request");
+
+ return TRUE;
+ }
+
+ state = net_nfc_server_get_state();
+
+ net_nfc_gdbus_manager_complete_get_server_state(manager,
+ invocation,
+ state);
+ return TRUE;
+}
+
+/* server side */
+static void manager_active_thread_func(gpointer user_data)
+{
+ ServerManagerActivationData *data;
+
+ gboolean ret = FALSE;
+
+ data = (ServerManagerActivationData *)user_data;
+
+ if (data == NULL)
+ {
+ DEBUG_ERR_MSG("can not get ServerManagerActivationData");
+ return;
+ }
+
+ if (data->is_active)
+ ret = manager_active();
+ else
+ ret = manager_deactive();
+
+ if (ret == FALSE)
+ {
+ DEBUG_ERR_MSG("can not set activation");
+ g_free(data);
+ return;
+ }
+
+ net_nfc_gdbus_manager_emit_activated(data->manager,
+ data->is_active);
+
+ g_free(data);
+}
+
+gboolean net_nfc_server_manager_init(GDBusConnection *connection)
+{
+ GError *error = NULL;
+
+ if (manager_skeleton)
+ g_object_unref(manager_skeleton);
+
+ manager_skeleton = net_nfc_gdbus_manager_skeleton_new();
+
+ g_signal_connect(manager_skeleton,
+ "handle-set-active",
+ G_CALLBACK(manager_handle_set_active),
+ NULL);
+
+ g_signal_connect(manager_skeleton,
+ "handle-get-server-state",
+ G_CALLBACK(manager_handle_get_server_state),
+ NULL);
+
+ if (g_dbus_interface_skeleton_export(
+ G_DBUS_INTERFACE_SKELETON(manager_skeleton),
+ connection,
+ "/org/tizen/NetNfcService/Manager",
+ &error) == FALSE)
+ {
+ DEBUG_ERR_MSG("Can not skeleton_export %s", error->message);
+
+ g_error_free(error);
+ g_object_unref(manager_skeleton);
+
+ manager_skeleton = NULL;
+
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+void net_nfc_server_manager_deinit(void)
+{
+ if (manager_skeleton)
+ {
+ g_object_unref(manager_skeleton);
+ manager_skeleton = NULL;
+ }
+}
+
+void net_nfc_server_manager_set_active(gboolean is_active)
+{
+ ServerManagerActivationData *data;
+
+ if (manager_skeleton == NULL)
+ {
+ DEBUG_ERR_MSG("%s is not initialized",
+ "net_nfc_server_manager");
+ return;
+ }
+
+ DEBUG_SERVER_MSG("is_active %d", is_active);
+
+ data = g_new0(ServerManagerActivationData, 1);
+
+ if(data == NULL)
+ {
+ DEBUG_ERR_MSG("Memory allocation failed");
+ return;
+ }
+
+ data->manager = g_object_ref(manager_skeleton);
+ data->is_active = is_active;
+
+ if (net_nfc_server_controller_async_queue_push(
+ manager_active_thread_func,
+ data) == FALSE)
+ {
+ DEBUG_ERR_MSG("can not push to controller thread");
+
+ if (data)
+ {
+ g_object_unref(data->manager);
+
+ g_free(data);
+ }
+ }
+
+ return;
+}
+
+bool net_nfc_server_manager_get_active()
+{
+ int value;
+
+ if (vconf_get_bool(VCONFKEY_NFC_STATE, &value) < 0)
+ return false;
+
+ return (!!value);
+}
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_SERVER_MANAGER_H__
+#define __NET_NFC_SERVER_MANAGER_H__
+
+#include <gio/gio.h>
+
+gboolean net_nfc_server_manager_init(GDBusConnection *connection);
+
+void net_nfc_server_manager_deinit(void);
+
+void net_nfc_server_manager_set_active(gboolean is_active);
+
+bool net_nfc_server_manager_get_active();
+
+#endif //__NET_NFC_SERVER_MANAGER_H__
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "net_nfc_typedef_internal.h"
+#include "net_nfc_debug_internal.h"
+#include "net_nfc_util_internal.h"
+#include "net_nfc_util_gdbus_internal.h"
+#include "net_nfc_server_controller.h"
+#include "net_nfc_gdbus.h"
+
+#include "net_nfc_server_common.h"
+#include "net_nfc_server_context.h"
+#include "net_nfc_server_tag.h"
+#include "net_nfc_server_ndef.h"
+
+typedef struct _ReadData ReadData;
+
+struct _ReadData
+{
+ NetNfcGDbusNdef *ndef;
+ GDBusMethodInvocation *invocation;
+ guint32 handle;
+};
+
+typedef struct _WriteData WriteData;
+
+struct _WriteData
+{
+ NetNfcGDbusNdef *ndef;
+ GDBusMethodInvocation *invocation;
+ guint32 handle;
+ data_s data;
+};
+
+typedef struct _MakeReadOnlyData MakeReadOnlyData;
+
+struct _MakeReadOnlyData
+{
+ NetNfcGDbusNdef *ndef;
+ GDBusMethodInvocation *invocation;
+ guint32 handle;
+};
+
+typedef struct _FormatData FormatData;
+
+struct _FormatData
+{
+ NetNfcGDbusNdef *ndef;
+ GDBusMethodInvocation *invocation;
+ guint32 handle;
+ data_s key;
+};
+
+
+static NetNfcGDbusNdef *ndef_skeleton = NULL;
+
+static void ndef_read_thread_func(gpointer user_data);
+
+static void ndef_write_thread_func(gpointer user_data);
+
+static void ndef_make_read_only_thread_func(gpointer user_data);
+
+static void ndef_format_thread_func(gpointer user_data);
+
+/* methods */
+static gboolean ndef_handle_read(NetNfcGDbusNdef *ndef,
+ GDBusMethodInvocation *invocation,
+ guint32 arg_handle,
+ GVariant *smack_privilege,
+ gpointer user_data);
+
+static gboolean ndef_handle_write(NetNfcGDbusNdef *ndef,
+ GDBusMethodInvocation *invocation,
+ guint32 arg_handle,
+ GVariant *arg_data,
+ GVariant *smack_privilege,
+ gpointer user_data);
+
+static gboolean ndef_handle_make_read_only(NetNfcGDbusNdef *ndef,
+ GDBusMethodInvocation *invocation,
+ guint32 arg_handle,
+ GVariant *smack_privilege,
+ gpointer user_data);
+
+static gboolean ndef_handle_format(NetNfcGDbusNdef *ndef,
+ GDBusMethodInvocation *invocation,
+ guint32 arg_handle,
+ GVariant *arg_key,
+ GVariant *smack_privilege,
+ gpointer user_data);
+
+
+static void ndef_read_thread_func(gpointer user_data)
+{
+ ReadData *data = user_data;
+
+ net_nfc_target_handle_s *handle;
+ net_nfc_error_e result;
+ data_s *read_data = NULL;
+ GVariant *data_variant;
+
+ g_assert(data != NULL);
+ g_assert(data->ndef != NULL);
+ g_assert(data->invocation != NULL);
+
+ handle = GUINT_TO_POINTER(data->handle);
+
+ if (net_nfc_server_target_connected(handle) == true) {
+ net_nfc_controller_read_ndef(handle, &read_data, &result);
+ } else {
+ result = NET_NFC_TARGET_IS_MOVED_AWAY;
+ }
+
+ data_variant = net_nfc_util_gdbus_data_to_variant(read_data);
+
+ net_nfc_gdbus_ndef_complete_read(data->ndef,
+ data->invocation,
+ (gint)result,
+ data_variant);
+
+ if (read_data) {
+ net_nfc_util_free_data(read_data);
+ g_free(read_data);
+ }
+
+ g_object_unref(data->invocation);
+ g_object_unref(data->ndef);
+
+ g_free(data);
+}
+
+static void ndef_write_thread_func(gpointer user_data)
+{
+ WriteData *data = user_data;
+
+ net_nfc_target_handle_s *handle;
+ net_nfc_error_e result;
+
+ g_assert(data != NULL);
+ g_assert(data->ndef != NULL);
+ g_assert(data->invocation != NULL);
+
+ handle = GUINT_TO_POINTER(data->handle);
+
+ if (net_nfc_server_target_connected(handle) == true) {
+ net_nfc_controller_write_ndef(handle, &data->data, &result);
+ } else {
+ result = NET_NFC_TARGET_IS_MOVED_AWAY;
+ }
+
+ net_nfc_gdbus_ndef_complete_write(data->ndef,
+ data->invocation,
+ (gint)result);
+
+ net_nfc_util_free_data(&data->data);
+
+ g_object_unref(data->invocation);
+ g_object_unref(data->ndef);
+
+ g_free(data);
+}
+
+static void ndef_make_read_only_thread_func(gpointer user_data)
+{
+ MakeReadOnlyData *data = user_data;
+
+ net_nfc_target_handle_s *handle;
+ net_nfc_error_e result;
+
+ g_assert(data != NULL);
+ g_assert(data->ndef != NULL);
+ g_assert(data->invocation != NULL);
+
+ handle = GUINT_TO_POINTER(data->handle);
+
+ if (net_nfc_server_target_connected(handle) == true) {
+ net_nfc_controller_make_read_only_ndef(handle, &result);
+ } else {
+ result = NET_NFC_TARGET_IS_MOVED_AWAY;
+ }
+
+ net_nfc_gdbus_ndef_complete_make_read_only(data->ndef,
+ data->invocation,
+ (gint)result);
+
+ g_object_unref(data->invocation);
+ g_object_unref(data->ndef);
+
+ g_free(data);
+}
+
+static void ndef_format_thread_func(gpointer user_data)
+{
+ FormatData *data = user_data;
+
+ net_nfc_target_handle_s *handle;
+ net_nfc_error_e result;
+
+ g_assert(data != NULL);
+ g_assert(data->ndef != NULL);
+ g_assert(data->invocation != NULL);
+
+ handle = GUINT_TO_POINTER(data->handle);
+
+ if (net_nfc_server_target_connected(handle) == true) {
+ net_nfc_controller_format_ndef(handle, &data->key, &result);
+ } else {
+ result = NET_NFC_TARGET_IS_MOVED_AWAY;
+ }
+
+ net_nfc_gdbus_ndef_complete_format(data->ndef,
+ data->invocation,
+ (gint)result);
+
+ net_nfc_util_free_data(&data->key);
+
+ g_object_unref(data->invocation);
+ g_object_unref(data->ndef);
+
+ g_free(data);
+}
+
+static gboolean ndef_handle_read(NetNfcGDbusNdef *ndef,
+ GDBusMethodInvocation *invocation,
+ guint32 arg_handle,
+ GVariant *smack_privilege,
+ gpointer user_data)
+{
+ ReadData *data;
+ gboolean result;
+
+ INFO_MSG(">>> REQUEST from [%s]",
+ g_dbus_method_invocation_get_sender(invocation));
+
+ /* check privilege and update client context */
+ if (net_nfc_server_gdbus_check_privilege(invocation,
+ smack_privilege,
+ "nfc-manager::tag",
+ "r") == false) {
+ DEBUG_ERR_MSG("permission denied, and finished request");
+
+ return FALSE;
+ }
+
+ data = g_new0(ReadData, 1);
+ if (data == NULL)
+ {
+ DEBUG_ERR_MSG("Memory allocation failed");
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.AllocationError",
+ "Can not allocate memory");
+
+ return FALSE;
+ }
+
+ data->ndef = g_object_ref(ndef);
+ data->invocation = g_object_ref(invocation);
+ data->handle = arg_handle;
+
+ result = net_nfc_server_controller_async_queue_push(
+ ndef_read_thread_func,
+ data);
+ if (result == FALSE)
+ {
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.Ndef.ThreadError",
+ "can not push to controller thread");
+
+ g_object_unref(data->invocation);
+ g_object_unref(data->ndef);
+
+ g_free(data);
+ }
+
+ return result;
+}
+
+static gboolean ndef_handle_write(NetNfcGDbusNdef *ndef,
+ GDBusMethodInvocation *invocation,
+ guint32 arg_handle,
+ GVariant *arg_data,
+ GVariant *smack_privilege,
+ gpointer user_data)
+{
+ WriteData *data;
+ gboolean result;
+
+ INFO_MSG(">>> REQUEST from [%s]",
+ g_dbus_method_invocation_get_sender(invocation));
+
+ /* check privilege and update client context */
+ if (net_nfc_server_gdbus_check_privilege(invocation,
+ smack_privilege,
+ "nfc-manager::tag",
+ "w") == false) {
+ DEBUG_ERR_MSG("permission denied, and finished request");
+
+ return FALSE;
+ }
+
+ data = g_new0(WriteData, 1);
+ if (data == NULL)
+ {
+ DEBUG_ERR_MSG("Memory allocation failed");
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.AllocationError",
+ "Can not allocate memory");
+
+ return FALSE;
+ }
+
+ data->ndef = g_object_ref(ndef);
+ data->invocation = g_object_ref(invocation);
+ data->handle = arg_handle;
+
+ net_nfc_util_gdbus_variant_to_data_s(arg_data, &data->data);
+
+ result = net_nfc_server_controller_async_queue_push(
+ ndef_write_thread_func,
+ data);
+ if (result == FALSE)
+ {
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.Ndef.ThreadError",
+ "can not push to controller thread");
+
+ net_nfc_util_free_data(&data->data);
+
+ g_object_unref(data->invocation);
+ g_object_unref(data->ndef);
+
+ g_free(data);
+ }
+
+ return result;
+}
+
+static gboolean ndef_handle_make_read_only(NetNfcGDbusNdef *ndef,
+ GDBusMethodInvocation *invocation,
+ guint32 arg_handle,
+ GVariant *smack_privilege,
+ gpointer user_data)
+{
+ MakeReadOnlyData *data;
+ gboolean result;
+
+ INFO_MSG(">>> REQUEST from [%s]",
+ g_dbus_method_invocation_get_sender(invocation));
+
+ /* check privilege and update client context */
+ if (net_nfc_server_gdbus_check_privilege(invocation,
+ smack_privilege,
+ "nfc-manager::tag",
+ "w") == false) {
+ DEBUG_ERR_MSG("permission denied, and finished request");
+
+ return FALSE;
+ }
+
+ data = g_new0(MakeReadOnlyData, 1);
+ if (data == NULL)
+ {
+ DEBUG_ERR_MSG("Memory allocation failed");
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.AllocationError",
+ "Can not allocate memory");
+
+ return FALSE;
+ }
+
+ data->ndef = g_object_ref(ndef);
+ data->invocation = g_object_ref(invocation);
+ data->handle = arg_handle;
+
+ result = net_nfc_server_controller_async_queue_push(
+ ndef_make_read_only_thread_func,
+ data);
+ if (result == FALSE)
+ {
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.Ndef.ThreadError",
+ "can not push to controller thread");
+
+ g_object_unref(data->invocation);
+ g_object_unref(data->ndef);
+
+ g_free(data);
+ }
+
+ return result;
+}
+
+static gboolean ndef_handle_format(NetNfcGDbusNdef *ndef,
+ GDBusMethodInvocation *invocation,
+ guint32 arg_handle,
+ GVariant *arg_key,
+ GVariant *smack_privilege,
+ gpointer user_data)
+{
+ FormatData *data;
+ gboolean result;
+
+ INFO_MSG(">>> REQUEST from [%s]",
+ g_dbus_method_invocation_get_sender(invocation));
+
+ /* check privilege and update client context */
+ if (net_nfc_server_gdbus_check_privilege(invocation,
+ smack_privilege,
+ "nfc-manager::tag",
+ "w") == false) {
+ DEBUG_ERR_MSG("permission denied, and finished request");
+
+ return FALSE;
+ }
+
+ data = g_new0(FormatData, 1);
+ if (data == NULL)
+ {
+ DEBUG_ERR_MSG("Memory allocation failed");
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.AllocationError",
+ "Can not allocate memory");
+
+ return FALSE;
+ }
+
+ data->ndef = g_object_ref(ndef);
+ data->invocation = g_object_ref(invocation);
+ data->handle = arg_handle;
+ net_nfc_util_gdbus_variant_to_data_s(arg_key, &data->key);
+
+ result = net_nfc_server_controller_async_queue_push(
+ ndef_format_thread_func,
+ data);
+ if (result == FALSE)
+ {
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.Ndef.ThreadError",
+ "can not push to controller thread");
+
+ net_nfc_util_free_data(&data->key);
+
+ g_object_unref(data->invocation);
+ g_object_unref(data->ndef);
+
+ g_free(data);
+ }
+
+ return result;
+}
+
+gboolean net_nfc_server_ndef_init(GDBusConnection *connection)
+{
+ gboolean result;
+ GError *error = NULL;
+
+ if (ndef_skeleton)
+ net_nfc_server_ndef_deinit();
+
+ ndef_skeleton = net_nfc_gdbus_ndef_skeleton_new();
+
+ g_signal_connect(ndef_skeleton,
+ "handle-read",
+ G_CALLBACK(ndef_handle_read),
+ NULL);
+
+ g_signal_connect(ndef_skeleton,
+ "handle-write",
+ G_CALLBACK(ndef_handle_write),
+ NULL);
+
+ g_signal_connect(ndef_skeleton,
+ "handle-make-read-only",
+ G_CALLBACK(ndef_handle_make_read_only),
+ NULL);
+
+ g_signal_connect(ndef_skeleton,
+ "handle-format",
+ G_CALLBACK(ndef_handle_format),
+ NULL);
+
+ result = g_dbus_interface_skeleton_export(
+ G_DBUS_INTERFACE_SKELETON(ndef_skeleton),
+ connection,
+ "/org/tizen/NetNfcService/Ndef",
+ &error);
+ if (result == FALSE)
+ {
+ g_error_free(error);
+
+ net_nfc_server_ndef_deinit();
+ }
+
+ return TRUE;
+}
+
+void net_nfc_server_ndef_deinit(void)
+{
+ if (ndef_skeleton)
+ {
+ g_object_unref(ndef_skeleton);
+ ndef_skeleton = NULL;
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_SERVER_NDEF_H__
+#define __NET_NFC_SERVER_NDEF_H__
+
+#include <gio/gio.h>
+
+gboolean net_nfc_server_ndef_init(GDBusConnection *connection);
+
+void net_nfc_server_ndef_deinit(void);
+
+#endif //__NET_NFC_SERVER_NDEF_H__
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "net_nfc_debug_internal.h"
+#include "net_nfc_util_internal.h"
+#include "net_nfc_util_gdbus_internal.h"
+#include "net_nfc_server_controller.h"
+#include "net_nfc_gdbus.h"
+#include "net_nfc_server_common.h"
+#include "net_nfc_server_context.h"
+#include "net_nfc_server_process_snep.h"
+#include "net_nfc_server_p2p.h"
+
+
+typedef struct _P2pSendData P2pSendData;
+
+struct _P2pSendData
+{
+ NetNfcGDbusP2p *p2p;
+ GDBusMethodInvocation *invocation;
+ gint32 type;
+ net_nfc_target_handle_s *p2p_handle;
+ data_s data;
+};
+
+static void p2p_send_data_thread_func(gpointer user_data);
+
+static gboolean p2p_handle_send(NetNfcGDbusP2p *p2p,
+ GDBusMethodInvocation *invocation,
+ gint32 arg_type,
+ GVariant *arg_data,
+ guint32 handle,
+ GVariant *smack_privilege,
+ gpointer user_data);
+
+static NetNfcGDbusP2p *p2p_skeleton = NULL;
+
+static void p2p_send_data_thread_func(gpointer user_data)
+{
+ P2pSendData *p2p_data = (P2pSendData *)user_data;
+ net_nfc_error_e result;
+
+ g_assert(p2p_data != NULL);
+ g_assert(p2p_data->p2p != NULL);
+ g_assert(p2p_data->invocation != NULL);
+
+ result = net_nfc_server_snep_default_client_start(
+ p2p_data->p2p_handle,
+ SNEP_REQ_PUT,
+ &p2p_data->data,
+ -1,
+ p2p_data);
+ if (result != NET_NFC_OK)
+ {
+ net_nfc_gdbus_p2p_complete_send(p2p_data->p2p,
+ p2p_data->invocation,
+ (gint)result);
+
+ net_nfc_util_free_data(&p2p_data->data);
+
+ g_object_unref(p2p_data->invocation);
+ g_object_unref(p2p_data->p2p);
+
+ g_free(p2p_data);
+ }
+}
+
+static gboolean p2p_handle_send(NetNfcGDbusP2p *p2p,
+ GDBusMethodInvocation *invocation,
+ gint32 arg_type,
+ GVariant *arg_data,
+ guint32 handle,
+ GVariant *smack_privilege,
+ gpointer user_data)
+{
+ gboolean result;
+ P2pSendData *data;
+
+ INFO_MSG(">>> REQUEST from [%s]",
+ g_dbus_method_invocation_get_sender(invocation));
+
+ /* check privilege and update client context */
+ if (net_nfc_server_gdbus_check_privilege(invocation,
+ smack_privilege,
+ "nfc-manager::p2p",
+ "w") == false) {
+ DEBUG_ERR_MSG("permission denied, and finished request");
+
+ return FALSE;
+ }
+
+ data = g_new0(P2pSendData, 1);
+ if(data == NULL)
+ {
+ DEBUG_ERR_MSG("Memory allocation failed");
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.AllocationError",
+ "Can not allocate memory");
+
+ return FALSE;
+ }
+
+ data->p2p = g_object_ref(p2p);
+ data->invocation = g_object_ref(invocation);
+ data->type = arg_type;
+ data->p2p_handle = GUINT_TO_POINTER(handle);
+ net_nfc_util_gdbus_variant_to_data_s(arg_data, &data->data);
+
+ result = net_nfc_server_controller_async_queue_push(
+ p2p_send_data_thread_func, data);
+ if (result == FALSE)
+ {
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.P2p.ThreadError",
+ "can not push to controller thread");
+
+ net_nfc_util_free_data(&data->data);
+
+ g_object_unref(data->invocation);
+ g_object_unref(data->p2p);
+
+ g_free(data);
+ }
+
+ return result;
+}
+
+
+gboolean net_nfc_server_p2p_init(GDBusConnection *connection)
+{
+ gboolean result;
+ GError *error = NULL;
+
+ if (p2p_skeleton)
+ net_nfc_server_p2p_deinit();
+
+ p2p_skeleton = net_nfc_gdbus_p2p_skeleton_new();
+
+ g_signal_connect(p2p_skeleton,
+ "handle-send",
+ G_CALLBACK(p2p_handle_send),
+ NULL);
+
+ result = g_dbus_interface_skeleton_export(
+ G_DBUS_INTERFACE_SKELETON(p2p_skeleton),
+ connection,
+ "/org/tizen/NetNfcService/P2p",
+ &error);
+ if (result == FALSE)
+ {
+ g_error_free(error);
+
+ net_nfc_server_p2p_deinit();
+ }
+
+ return result;
+}
+
+void net_nfc_server_p2p_deinit(void)
+{
+ if (p2p_skeleton)
+ {
+ g_object_unref(p2p_skeleton);
+ p2p_skeleton = NULL;
+ }
+}
+
+void net_nfc_server_p2p_detached(void)
+{
+ if (p2p_skeleton == NULL)
+ {
+ DEBUG_ERR_MSG("p2p_skeleton is not initialized");
+
+ return;
+ }
+
+ DEBUG_ERR_MSG("p2p detached signal");
+
+ net_nfc_gdbus_p2p_emit_detached(p2p_skeleton);
+}
+
+void net_nfc_server_p2p_discovered(net_nfc_target_handle_h handle)
+{
+ if (p2p_skeleton == NULL)
+ {
+ DEBUG_ERR_MSG("p2p_skeleton is not initialized");
+
+ return;
+ }
+
+ DEBUG_ERR_MSG("Emitting p2p discovered signal");
+
+ net_nfc_gdbus_p2p_emit_discovered(p2p_skeleton,
+ GPOINTER_TO_UINT(handle));
+}
+
+void net_nfc_server_p2p_received(data_h user_data)
+{
+ GVariant *arg_data;
+
+ if (p2p_skeleton == NULL)
+ {
+ DEBUG_ERR_MSG("p2p_skeleton is not initialized");
+
+ return;
+ }
+
+ arg_data = net_nfc_util_gdbus_data_to_variant((data_s *)user_data);
+
+ net_nfc_gdbus_p2p_emit_received(p2p_skeleton, arg_data);
+}
+
+void net_nfc_server_p2p_data_sent(net_nfc_error_e result,
+ gpointer user_data)
+{
+ P2pSendData *data = (P2pSendData *)user_data;
+
+ g_assert(data != NULL);
+ g_assert(data->p2p != NULL);
+ g_assert(data->invocation != NULL);
+
+ net_nfc_gdbus_p2p_complete_send(data->p2p,
+ data->invocation,
+ (gint)result);
+
+ net_nfc_util_free_data(&data->data);
+
+ g_object_unref(data->invocation);
+ g_object_unref(data->p2p);
+
+ g_free(data);
+}
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_SERVER_P2P_H__
+#define __NET_NFC_SERVER_P2P_H__
+
+#include <gio/gio.h>
+
+#include "net_nfc_typedef_internal.h"
+
+gboolean net_nfc_server_p2p_init(GDBusConnection *connection);
+
+void net_nfc_server_p2p_deinit(void);
+
+/* server side */
+void net_nfc_server_p2p_detached(void);
+
+void net_nfc_server_p2p_discovered(net_nfc_target_handle_h handle);
+
+void net_nfc_server_p2p_received(data_h user_data);
+
+void net_nfc_server_p2p_data_sent(net_nfc_error_e result, gpointer user_data);
+
+#endif //__NET_NFC_SERVER_P2P_H__
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "bluetooth-api.h"
+#include "net_nfc_server_handover.h"
+#include "net_nfc_debug_internal.h"
+#include "net_nfc_util_internal.h"
+#include "net_nfc_util_ndef_message.h"
+#include "net_nfc_util_ndef_record.h"
+#include "net_nfc_util_handover.h"
+#include "net_nfc_server_controller.h"
+#include "net_nfc_server_llcp.h"
+#include "net_nfc_server_process_handover.h"
+#include "net_nfc_server_process_snep.h"
+#include "net_nfc_util_gdbus_internal.h"
+#include "net_nfc_server_handover_bss.h"
+#include "net_nfc_server_handover_bt.h"
+
+typedef void (*_net_nfc_server_handover_create_carrier_msg_cb)(
+ net_nfc_error_e result,
+ ndef_message_s *selector,
+ void *user_param);
+
+typedef struct _net_nfc_handover_context_t
+{
+ net_nfc_target_handle_s *handle;
+ net_nfc_error_e result;
+ net_nfc_llcp_socket_t socket;
+ uint32_t state;
+ net_nfc_conn_handover_carrier_type_e type;
+ data_s data;
+ ndef_record_s *record;
+ void *user_param;
+}
+net_nfc_handover_context_t;
+
+#define NET_NFC_CH_CONTEXT net_nfc_target_handle_s *handle;\
+ net_nfc_llcp_socket_t socket;\
+ net_nfc_error_e result;\
+ int step;\
+ net_nfc_conn_handover_carrier_type_e type;\
+ void *user_param;
+
+typedef struct _net_nfc_server_handover_create_config_context_t
+{
+ NET_NFC_CH_CONTEXT;
+
+ _net_nfc_server_handover_create_carrier_msg_cb cb;
+ net_nfc_conn_handover_carrier_type_e current_type;
+ ndef_message_s *ndef_message;
+ ndef_message_s *requester; /* for low power selector */
+
+ ndef_record_s *record;
+}
+net_nfc_server_handover_create_config_context_t;
+
+typedef struct _net_nfc_server_handover_process_config_context_t
+{
+ NET_NFC_CH_CONTEXT;
+
+ net_nfc_server_handover_process_carrier_record_cb cb;
+}net_nfc_server_handover_process_config_context_t;
+
+
+
+static void _net_nfc_server_handover_send_response(void *user_param,
+ data_h ac_data,
+ net_nfc_error_e result);
+
+static void _net_nfc_server_handover_client_process(
+ net_nfc_handover_context_t *context);
+
+static void _net_nfc_server_handover_client_error_cb(
+ net_nfc_error_e result,
+ net_nfc_target_handle_s *handle,
+ net_nfc_llcp_socket_t socket,
+ data_s *data,
+ void *user_param);
+
+static void _net_nfc_server_handover_client_connected_cb(
+ net_nfc_error_e result,
+ net_nfc_target_handle_s *handle,
+ net_nfc_llcp_socket_t socket,
+ data_s *data,
+ void *user_param);
+
+static void _net_nfc_server_handover_get_response_process(
+ net_nfc_handover_context_t *context);
+
+static int _net_nfc_server_handover_append_wifi_carrier_config(
+ net_nfc_server_handover_create_config_context_t *context);
+
+static net_nfc_error_e
+_net_nfc_server_handover_create_requester_from_rawdata(
+ ndef_message_s **requestor,
+ data_s *data);
+
+static net_nfc_error_e
+_net_nfc_server_handover_create_requester_carrier_configs(
+ net_nfc_conn_handover_carrier_type_e type,
+ void *cb,
+ void *user_param);
+
+static bool _net_nfc_server_handover_check_hr_record_validation(
+ ndef_message_s *message);
+
+static bool _net_nfc_server_handover_check_hs_record_validation(
+ ndef_message_s *message);
+
+static net_nfc_error_e
+_net_nfc_server_handover_create_selector_carrier_configs(
+ net_nfc_conn_handover_carrier_type_e type,
+ void *cb,
+ void *user_param);
+
+static int _net_nfc_server_handover_iterate_create_carrier_configs(
+ net_nfc_server_handover_create_config_context_t *context);
+
+static int _net_nfc_server_handover_iterate_carrier_configs_to_next(
+ net_nfc_server_handover_create_config_context_t *context);
+
+static int _net_nfc_server_handover_iterate_carrier_configs_step(
+ net_nfc_server_handover_create_config_context_t *context);
+
+static void _net_nfc_server_handover_server_process(
+ net_nfc_handover_context_t *context);
+
+static net_nfc_error_e
+_net_nfc_server_handover_create_low_power_selector_message(
+ ndef_message_s *request_msg,
+ ndef_message_s *select_msg);
+
+////////////////////////////////////////////////////////////////////////////
+
+static void _net_nfc_server_handover_send_response(
+ void *user_param,
+ data_h ac_data,
+ net_nfc_error_e result)
+{
+ HandoverRequestData *handover_data = NULL;
+ guint32 resp_event;
+ guint32 resp_type;
+ GVariant* data = NULL;
+
+ handover_data = (HandoverRequestData*)user_param;
+
+ data = net_nfc_util_gdbus_data_to_variant(ac_data);
+
+ resp_type = NET_NFC_MESSAGE_CONNECTION_HANDOVER;
+
+ if (result == NET_NFC_OK)
+ resp_event = NET_NFC_EXCHANGER_TRANSFER_COMPLETED;
+ else
+ resp_event = NET_NFC_EXCHANGER_TRANSFER_FAILED;
+
+ if (handover_data->invocation)
+ {
+ net_nfc_gdbus_handover_complete_request(
+ handover_data->handoverobj,
+ handover_data->invocation,
+ resp_event,
+ resp_type,
+ data);
+
+ g_object_unref(handover_data->invocation);
+ }
+
+ if (handover_data->data)
+ {
+ g_free(handover_data->data->buffer);
+ g_free(handover_data->data);
+ }
+
+ g_object_unref(handover_data->handoverobj);
+ g_free(handover_data);
+
+}
+
+static net_nfc_error_e _net_nfc_server_handover_convert_ndef_message_to_data(
+ ndef_message_s *msg,
+ data_s *data)
+{
+ net_nfc_error_e result;
+ uint32_t length;
+
+ if (msg == NULL || data == NULL)
+ {
+ return NET_NFC_INVALID_PARAM;
+ }
+
+ length = net_nfc_util_get_ndef_message_length(msg);
+ if (length > 0)
+ {
+ net_nfc_util_alloc_data(data, length);
+ result = net_nfc_util_convert_ndef_message_to_rawdata(msg, data);
+ }
+ else
+ {
+ result = NET_NFC_INVALID_PARAM;
+ }
+
+ return result;
+}
+
+static void _net_nfc_server_handover_bt_get_carrier_record_cb(
+ net_nfc_error_e result,
+ net_nfc_conn_handover_carrier_state_e cps,
+ ndef_record_s *carrier,
+ uint32_t aux_data_count,
+ ndef_record_s *aux_data,
+ void *user_param)
+{
+ net_nfc_server_handover_create_config_context_t *context =
+ (net_nfc_server_handover_create_config_context_t *)user_param;
+
+ /* append record to ndef message */
+ if (result == NET_NFC_OK)
+ {
+ ndef_record_s *record;
+
+ /* FIXME : copy record and append */
+ net_nfc_util_create_record(carrier->TNF,
+ &carrier->type_s,
+ &carrier->id_s,
+ &carrier->payload_s,
+ &record);
+
+ if ((result = net_nfc_util_append_carrier_config_record(
+ context->ndef_message,
+ record,
+ cps)) == NET_NFC_OK)
+ {
+ DEBUG_SERVER_MSG("net_nfc_util_append_carrier"
+ "_config_record success");
+ }
+ else
+ {
+ DEBUG_ERR_MSG("net_nfc_util_append_carrier"
+ "_config_record failed [%d]",
+ result);
+ net_nfc_util_free_record(record);
+ }
+
+ g_idle_add(
+ (GSourceFunc)_net_nfc_server_handover_iterate_carrier_configs_to_next,
+ (gpointer)context);
+ }
+
+ /* don't free context */
+}
+
+static void _net_nfc_server_handover_bt_process_carrier_record_cb(
+ net_nfc_error_e result,
+ net_nfc_conn_handover_carrier_type_e type,
+ data_s *data,
+ void *user_param)
+{
+ net_nfc_server_handover_process_config_context_t *context =
+ (net_nfc_server_handover_process_config_context_t *)user_param;
+
+ if (result == NET_NFC_OK)
+ {
+ if (context->cb != NULL)
+ {
+ context->cb(result, type, data, context->user_param);
+ }
+ }
+ else
+ {
+ DEBUG_ERR_MSG("_handover_bt_process_carrier_record failed [%d]",
+ result);
+ }
+
+ _net_nfc_util_free_mem(context);
+}
+
+
+net_nfc_error_e _net_nfc_server_handover_get_carrier_record_by_priority_order(
+ ndef_message_s *request,
+ ndef_record_s **record)
+{
+ net_nfc_error_e result;
+ unsigned int carrier_count = 0;
+
+ LOGD("[%s] START", __func__);
+
+ if (request == NULL || record == NULL)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ *record = NULL;
+
+ if ((result = net_nfc_util_get_alternative_carrier_record_count(
+ request,
+ &carrier_count)) == NET_NFC_OK)
+ {
+ int idx, priority;
+ net_nfc_conn_handover_carrier_type_e carrier_type =
+ NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN;
+
+ for (priority = NET_NFC_CONN_HANDOVER_CARRIER_BT;*record == NULL
+ && priority < NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN;priority++)
+ {
+ /* check each carrier record and create matched record */
+ for (idx = 0; idx < carrier_count; idx++)
+ {
+ if ((net_nfc_util_get_alternative_carrier_type(
+ request,
+ idx,
+ &carrier_type)== NET_NFC_OK)
+ && (carrier_type == priority))
+ {
+ DEBUG_SERVER_MSG("selected carrier type"
+ " = [%d]", carrier_type);
+ net_nfc_util_get_carrier_config_record(
+ request,
+ idx,
+ record);
+ result = NET_NFC_OK;
+ break;
+ }
+ }
+ }
+ }
+ else
+ {
+ DEBUG_ERR_MSG("net_nfc_util_get_alternative_carrier"
+ "_record_count failed");
+ }
+
+ LOGD("[%s] END", __func__);
+
+ return result;
+}
+
+static net_nfc_error_e _net_nfc_server_handover_create_requester_from_rawdata(
+ ndef_message_s **requestor,
+ data_s *data)
+{
+ net_nfc_error_e result;
+
+ if (requestor == NULL)
+ return NET_NFC_NULL_PARAMETER;
+
+ *requestor = NULL;
+
+ result = net_nfc_util_create_ndef_message(requestor);
+ if (result == NET_NFC_OK)
+ {
+ result = net_nfc_util_convert_rawdata_to_ndef_message(data,
+ *requestor);
+
+ if (result == NET_NFC_OK)
+ {
+ if (_net_nfc_server_handover_check_hr_record_validation(
+ *requestor) == true)
+ {
+ result = NET_NFC_OK;
+ }
+ else
+ {
+ DEBUG_ERR_MSG("record is not valid or"
+ " is not available");
+ net_nfc_util_free_ndef_message(*requestor);
+ result = NET_NFC_INVALID_PARAM;
+ }
+ }
+ else
+ {
+ DEBUG_ERR_MSG("_net_nfc_ndef_rawdata_to_ndef"
+ "failed [%d]",result);
+ }
+ } else {
+ DEBUG_ERR_MSG("net_nfc_util_create_ndef_message failed [%d]",
+ result);
+ }
+
+ return result;
+}
+
+net_nfc_error_e _net_nfc_server_handover_create_selector_from_rawdata(
+ ndef_message_s **selector,
+ data_s *data)
+{
+ net_nfc_error_e result;
+
+ if (selector == NULL)
+ return NET_NFC_NULL_PARAMETER;
+
+ *selector = NULL;
+
+ if ((result = net_nfc_util_create_ndef_message(selector))
+ == NET_NFC_OK)
+ {
+ if ((result = net_nfc_util_convert_rawdata_to_ndef_message(data,
+ *selector)) == NET_NFC_OK)
+ {
+
+ /* if record is not Hs record, then */
+ if (_net_nfc_server_handover_check_hs_record_validation(
+ *selector) == true)
+ {
+ result = NET_NFC_OK;
+ }
+ else
+ {
+ DEBUG_ERR_MSG("record is not valid or is "
+ "not available");
+ net_nfc_util_free_ndef_message(*selector);
+ result = NET_NFC_INVALID_PARAM;
+ }
+ }
+ else
+ {
+ DEBUG_ERR_MSG("_net_nfc_ndef_rawdata_to_ndef"
+ " failed [%d]",result);
+ }
+ }
+ else
+ {
+ DEBUG_ERR_MSG("_net_nfc_util_create_ndef_message"
+ " failed [%d]",result);
+ }
+
+ return result;
+}
+
+static bool _net_nfc_server_handover_check_hr_record_validation(
+ ndef_message_s *message)
+{
+ unsigned int count;
+ ndef_record_s *rec;
+
+ LOGD("[%s] START", __func__);
+
+ if (message == NULL)
+ return false;
+
+ rec = (ndef_record_s *)message->records;
+
+ if (memcmp(rec->type_s.buffer, CH_REQ_RECORD_TYPE,
+ rec->type_s.length) != 0)
+ {
+ DEBUG_ERR_MSG("This is not connection handover"
+ " request message");
+ goto ERROR;
+ }
+
+ if (rec->payload_s.buffer[0] != CH_VERSION)
+ {
+ DEBUG_ERR_MSG("connection handover version is not matched");
+ goto ERROR;
+ }
+
+ if (net_nfc_util_get_alternative_carrier_record_count(message, &count)
+ != NET_NFC_OK || count == 0)
+ {
+ DEBUG_ERR_MSG("there is no carrier reference");
+ goto ERROR;
+ }
+
+ LOGD("[%s] END", __func__);
+
+ return true;
+
+ERROR :
+ LOGD("[%s] END", __func__);
+
+ return false;
+}
+
+static bool _net_nfc_server_handover_check_hs_record_validation(
+ ndef_message_s *message)
+{
+ unsigned int count;
+ ndef_record_s *rec;
+
+ LOGD("[%s] START", __func__);
+
+ if (message == NULL)
+ return false;
+
+ rec = (ndef_record_s *)message->records;
+
+ if (memcmp(rec->type_s.buffer, CH_SEL_RECORD_TYPE,
+ rec->type_s.length) != 0)
+ {
+ DEBUG_ERR_MSG("This is not connection handover"
+ " request message");
+ goto ERROR;
+ }
+
+ if (net_nfc_util_get_alternative_carrier_record_count(
+ message,&count)!= NET_NFC_OK || count == 0)
+ {
+ DEBUG_ERR_MSG("there is no carrrier reference");
+ goto ERROR;
+ }
+
+ /* check version */
+ if (rec->payload_s.buffer[0] != CH_VERSION)
+ {
+ DEBUG_ERR_MSG("connection handover version"
+ " is not matched");
+ goto ERROR;
+ }
+
+ LOGD("[%s] END", __func__);
+
+ return true;
+
+ERROR :
+ LOGD("[%s] END", __func__);
+
+ return false;
+}
+
+static int _net_nfc_server_handover_iterate_carrier_configs_step(
+ net_nfc_server_handover_create_config_context_t *context)
+{
+ LOGD("[%s:%d] START", __func__, __LINE__);
+
+ if (context == NULL)
+ {
+ return 0;
+ }
+
+ if (context->cb != NULL)
+ {
+ context->cb(NET_NFC_OK, context->ndef_message,
+ context->user_param);
+ }
+
+ if (context->ndef_message != NULL)
+ {
+ net_nfc_util_free_ndef_message(context->ndef_message);
+ }
+
+ _net_nfc_util_free_mem(context);
+
+ LOGD("[%s:%d] END", __func__, __LINE__);
+
+ return 0;
+}
+
+static int _net_nfc_server_handover_append_wifi_carrier_config(
+ net_nfc_server_handover_create_config_context_t *context)
+{
+ LOGD("[%s:%d] START", __func__, __LINE__);
+
+ switch (context->step)
+ {
+ case NET_NFC_LLCP_STEP_01 :
+ DEBUG_MSG("STEP [1]");
+
+ context->step = NET_NFC_LLCP_STEP_02;
+ break;
+
+ case NET_NFC_LLCP_STEP_02 :
+ DEBUG_MSG("STEP [2]");
+
+ context->step = NET_NFC_LLCP_STEP_03;
+ break;
+
+ case NET_NFC_LLCP_STEP_03 :
+ DEBUG_MSG("STEP [3]");
+
+ context->step = NET_NFC_LLCP_STEP_RETURN;
+ break;
+
+ case NET_NFC_LLCP_STEP_RETURN :
+ DEBUG_MSG("STEP return");
+
+ /* complete and return to upper step */
+ g_idle_add(
+ (GSourceFunc)_net_nfc_server_handover_iterate_carrier_configs_to_next,
+ (gpointer)context);
+ break;
+
+ default :
+ break;
+ }
+
+ LOGD("[%s:%d] END", __func__, __LINE__);
+
+ return 0;
+}
+
+static int _net_nfc_server_handover_iterate_carrier_configs_to_next(
+ net_nfc_server_handover_create_config_context_t *context)
+{
+ if (context->result == NET_NFC_OK || context->result == NET_NFC_BUSY)
+ {
+ if (context->type == NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN)
+ {
+ if (context->current_type <
+ NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN)
+ {
+ context->current_type++;
+ }
+ }
+ else
+ {
+ context->current_type =
+ NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN;
+ }
+
+ g_idle_add(
+ (GSourceFunc)_net_nfc_server_handover_iterate_create_carrier_configs,
+ (gpointer)context);
+ }
+ else
+ {
+ DEBUG_ERR_MSG("context->result is error [%d]", context->result);
+
+ g_idle_add(
+ (GSourceFunc)_net_nfc_server_handover_iterate_carrier_configs_step,
+ (gpointer)context);
+ }
+
+ return 0;
+}
+
+static int _net_nfc_server_handover_iterate_create_carrier_configs(
+ net_nfc_server_handover_create_config_context_t *context)
+{
+ LOGD("[%s:%d] START", __func__, __LINE__);
+
+ switch (context->current_type)
+ {
+ case NET_NFC_CONN_HANDOVER_CARRIER_BT :
+ DEBUG_MSG("[NET_NFC_CONN_HANDOVER_CARRIER_BT]");
+ net_nfc_server_handover_bt_get_carrier_record(
+ _net_nfc_server_handover_bt_get_carrier_record_cb,
+ context);
+ break;
+
+ // case NET_NFC_CONN_HANDOVER_CARRIER_WIFI_BSS :
+ // DEBUG_MSG("[NET_NFC_CONN_HANDOVER_CARRIER_WIFI_BSS]");
+ // g_idle_add(
+ // (GSourceFunc)net_nfc_service_llcp_handover_append_wifi_carrier_config,
+ // context);
+ // break;
+
+ // case NET_NFC_CONN_HANDOVER_CARRIER_WIFI_IBSS :
+ // DEBUG_MSG("[NET_NFC_CONN_HANDOVER_CARRIER_WIFI_BSS]");
+ // g_idle_add(
+ // (GSourceFunc)_net_nfc_server_handover_append_wifi_carrier_config,
+ // context);
+ // break;
+
+ case NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN :
+ DEBUG_MSG("[NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN]");
+ g_idle_add(
+ (GSourceFunc)_net_nfc_server_handover_iterate_carrier_configs_step,
+ (gpointer)context);
+ break;
+
+ default :
+ DEBUG_MSG("[unknown : %d]", context->current_type);
+ g_idle_add(
+ (GSourceFunc)_net_nfc_server_handover_iterate_carrier_configs_step,
+ (gpointer)context);
+ break;
+ }
+
+ LOGD("[%s:%d] END", __func__, __LINE__);
+
+ return 0;
+}
+
+static net_nfc_error_e _net_nfc_server_handover_create_requester_carrier_configs(
+ net_nfc_conn_handover_carrier_type_e type,
+ void *cb,
+ void *user_param)
+{
+ net_nfc_error_e result = NET_NFC_OK;
+ net_nfc_server_handover_create_config_context_t *context = NULL;
+
+ LOGD("[%s:%d] START", __func__, __LINE__);
+
+ _net_nfc_util_alloc_mem(context, sizeof(*context));
+ if (context != NULL)
+ {
+ context->type = type;
+ if (type == NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN)
+ {
+ context->current_type =
+ NET_NFC_CONN_HANDOVER_CARRIER_BT;
+ }
+ else
+ context->current_type = context->type;
+
+ context->cb = cb;
+ context->user_param = user_param;
+ net_nfc_util_create_handover_request_message(
+ &context->ndef_message);
+
+ /* append carrier record */
+ g_idle_add(
+ (GSourceFunc)_net_nfc_server_handover_iterate_create_carrier_configs,
+ (gpointer)context);
+ }
+ else
+ {
+ DEBUG_ERR_MSG("alloc failed");
+ result = NET_NFC_ALLOC_FAIL;
+ }
+
+ LOGD("[%s:%d] END", __func__, __LINE__);
+
+ return result;
+}
+
+static net_nfc_error_e _net_nfc_server_handover_create_selector_carrier_configs(
+ net_nfc_conn_handover_carrier_type_e type,
+ void *cb,
+ void *user_param)
+{
+ net_nfc_error_e result = NET_NFC_OK;
+ net_nfc_server_handover_create_config_context_t *context = NULL;
+
+ LOGD("[%s:%d] START", __func__, __LINE__);
+
+ _net_nfc_util_alloc_mem(context, sizeof(*context));
+ if (context != NULL)
+ {
+ context->type = type;
+ if (type == NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN)
+ context->current_type = NET_NFC_CONN_HANDOVER_CARRIER_BT;
+ else
+ context->current_type = context->type;
+
+ context->cb = cb;
+ context->user_param = user_param;
+ net_nfc_util_create_handover_select_message(
+ &context->ndef_message);
+
+ /* append carrier record */
+ g_idle_add(
+ (GSourceFunc)_net_nfc_server_handover_iterate_create_carrier_configs,
+ (gpointer)context);
+ }
+ else
+ {
+ DEBUG_ERR_MSG("alloc failed");
+ result = NET_NFC_ALLOC_FAIL;
+ }
+
+ LOGD("[%s:%d] END", __func__, __LINE__);
+
+ return result;
+}
+
+ static net_nfc_error_e
+_net_nfc_server_handover_create_low_power_selector_message(
+ ndef_message_s *request_msg,
+ ndef_message_s *select_msg)
+{
+ net_nfc_error_e result = NET_NFC_UNKNOWN_ERROR;
+ unsigned int carrier_count = 0;
+
+ LOGD("[%s] START", __func__);
+
+ if (request_msg == NULL || select_msg == NULL)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ if ((result = net_nfc_util_get_alternative_carrier_record_count(
+ request_msg,
+ &carrier_count)) == NET_NFC_OK)
+ {
+ int idx;
+ ndef_record_s *carrier_record = NULL;
+ net_nfc_conn_handover_carrier_type_e carrier_type =
+ NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN;
+
+ /* check each carrier record and create matched record */
+ for (idx = 0; idx < carrier_count; idx++)
+ {
+ if ((net_nfc_util_get_alternative_carrier_type(
+ request_msg,idx,&carrier_type) != NET_NFC_OK) ||
+ (carrier_type == NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN))
+ {
+ DEBUG_ERR_MSG("net_nfc_util_get_alternative"
+ "_carrier_type failed or unknown");
+ continue;
+ }
+
+ DEBUG_SERVER_MSG("carrier type = [%d]", carrier_type);
+
+ /* add temporary config record */
+ {
+ net_nfc_carrier_config_s *config = NULL;
+
+ if ((result = net_nfc_util_create_carrier_config(
+ &config,carrier_type)) == NET_NFC_OK)
+ {
+ if ((result =
+ net_nfc_util_create_ndef_record_with_carrier_config(
+ &carrier_record,config)) == NET_NFC_OK)
+ {
+ DEBUG_SERVER_MSG("net_nfc_util_create_ndef_record_"
+ "with_carrier_config success");
+ }
+ else
+ {
+ DEBUG_ERR_MSG("create_ndef_record_with_carrier_config "
+ "failed [%d]", result);
+ net_nfc_util_free_carrier_config(config);
+ continue;
+ }
+
+ net_nfc_util_free_carrier_config(config);
+ }
+ else
+ {
+ DEBUG_ERR_MSG("net_nfc_util_get_local_bt_address return NULL");
+ continue;
+ }
+ }
+
+ /* append carrier configure record to selector message */
+ if ((result = net_nfc_util_append_carrier_config_record(
+ select_msg,
+ carrier_record,
+ NET_NFC_CONN_HANDOVER_CARRIER_INACTIVATE)) == NET_NFC_OK)
+ {
+ DEBUG_SERVER_MSG("net_nfc_util_append_carrier_config_record success");
+ }
+ else
+ {
+ DEBUG_ERR_MSG("net_nfc_util_append_carrier_config_record"
+ " failed [%d]", result);
+
+ net_nfc_util_free_record(carrier_record);
+ }
+ }
+
+ result = NET_NFC_OK;
+ }
+ else
+ {
+ DEBUG_ERR_MSG("net_nfc_util_get_alternative_carrier_record_count failed");
+ }
+
+ LOGD("[%s] END", __func__);
+
+ return result;
+}
+
+net_nfc_error_e _net_nfc_server_handover_process_carrier_record(
+ ndef_record_s *carrier,
+ void *cb,
+ void *user_param)
+{
+ net_nfc_error_e result = NET_NFC_OK;
+ net_nfc_server_handover_process_config_context_t *context = NULL;
+
+ LOGD("[%s:%d] START", __func__, __LINE__);
+
+ _net_nfc_util_alloc_mem(context, sizeof(*context));
+ if (context != NULL)
+ {
+ net_nfc_conn_handover_carrier_type_e type;
+
+ net_nfc_util_get_alternative_carrier_type_from_record(
+ carrier,
+ &type);
+
+ context->type = type;
+ context->user_param = user_param;
+ context->cb = cb;
+ context->step = NET_NFC_LLCP_STEP_01;
+
+ /* process carrier record */
+ switch (type)
+ {
+ case NET_NFC_CONN_HANDOVER_CARRIER_BT :
+ DEBUG_MSG("[NET_NFC_CONN_HANDOVER_CARRIER_BT]");
+ net_nfc_server_handover_bt_process_carrier_record(
+ carrier,
+ _net_nfc_server_handover_bt_process_carrier_record_cb,
+ context);
+ break;
+
+ case NET_NFC_CONN_HANDOVER_CARRIER_WIFI_BSS :
+ DEBUG_MSG("[NET_NFC_CONN_HANDOVER_CARRIER_WIFI_BSS]");
+ net_nfc_server_handover_bss_process_carrier_record(
+ carrier,
+ NULL,
+ NULL);
+ _net_nfc_util_free_mem(context);
+ break;
+
+ case NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN :
+ DEBUG_MSG("[NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN]");
+ _net_nfc_util_free_mem(context);
+ break;
+
+ default :
+ DEBUG_MSG("[unknown]");
+ _net_nfc_util_free_mem(context);
+ break;
+ }
+ }
+ else
+ {
+ DEBUG_ERR_MSG("alloc failed");
+ result = NET_NFC_ALLOC_FAIL;
+ }
+
+ LOGD("[%s:%d] END", __func__, __LINE__);
+
+ return result;
+}
+
+#if 0
+static net_nfc_error_e _net_nfc_server_handover_snep_client_cb(
+ net_nfc_snep_handle_h handle,
+ net_nfc_error_e result,
+ uint32_t type,
+ data_s *data,
+ void *user_param)
+{
+ _net_nfc_server_handover_client_context_t *context =
+ (_net_nfc_server_handover_client_context_t *)user_param;
+
+ DEBUG_SERVER_MSG("type [%d], result [%d], data [%p], user_param [%p]",
+ type, result, data, user_param);
+
+ switch (type) {
+ case SNEP_RESP_SUCCESS :
+ {
+ ndef_message_s *selector;
+
+ result = _net_nfc_server_handover_create_selector_from_rawdata(
+ &selector,
+ data);
+ if (result == NET_NFC_OK) {
+ if (false /* is low power ??? */) {
+ result =
+ _net_nfc_server_handover_process_selector_msg(
+ selector,
+ user_param);
+ } else {
+ result =
+ _net_nfc_server_handover_process_selector_msg(
+ selector,
+ user_param);
+ }
+
+ if (result != NET_NFC_OK) {
+ DEBUG_ERR_MSG("_net_nfc_server_handover_process"
+ "_selector_msg failed [%d]",result);
+ if (context->cb != NULL) {
+ context->cb(result,
+ context->type,
+ NULL,
+ context->user_param);
+ }
+ _net_nfc_util_free_mem(context);
+ }
+
+ net_nfc_util_free_ndef_message(selector);
+ } else {
+ DEBUG_ERR_MSG("_net_nfc_server_handover_create"
+ "_selector_from_rawdata failed [%d]",result);
+ if (context->cb != NULL) {
+ context->cb(result,
+ context->type,
+ NULL,
+ context->user_param);
+ }
+ _net_nfc_util_free_mem(context);
+ }
+ }
+ break;
+
+ case SNEP_RESP_BAD_REQ :
+ case SNEP_RESP_EXCESS_DATA :
+ case SNEP_RESP_NOT_FOUND :
+ case SNEP_RESP_NOT_IMPLEMENT :
+ case SNEP_RESP_REJECT :
+ case SNEP_RESP_UNSUPPORTED_VER :
+ default :
+ {
+ DEBUG_ERR_MSG("error response [0x%02x]", type);
+ if (context->cb != NULL) {
+ context->cb(result, context->type, NULL,
+ context->user_param);
+ }
+ _net_nfc_util_free_mem(context);
+ }
+ break;
+ }
+
+ return result;
+}
+
+
+static void _net_nfc_server_handover_create_requester_carrier_configs_cb(
+ net_nfc_error_e result,
+ ndef_message_s *msg,
+ void *user_param)
+{
+ _net_nfc_server_handover_client_context_t *context =
+ (_net_nfc_server_handover_client_context_t *)user_param;
+ data_s data;
+
+ if (context == NULL)
+ {
+ return;
+ }
+
+ if (msg != NULL) {
+ /* convert ndef message */
+ if ((result = _net_nfc_server_handover_convert_ndef_message_to_data(msg,
+ &data)) == NET_NFC_OK) {
+ net_nfc_service_snep_client(context->handle,
+ SNEP_SAN,
+ 0,
+ SNEP_REQ_GET,
+ &data,
+ _net_nfc_server_handover_snep_client_cb,
+ context);
+
+ net_nfc_util_free_data(&data);
+ }
+ else
+ {
+ DEBUG_ERR_MSG("_net_nfc_server_handover_convert"
+ "_ndef_message_to_datafailed [%d]",result);
+ if (context->cb != NULL)
+ {
+ context->cb(result,
+ context->type,
+ NULL,
+ context->user_param);
+ }
+ _net_nfc_util_free_mem(context);
+ }
+ }
+ else
+ {
+ DEBUG_ERR_MSG("null param, [%d]", result);
+ if (context->cb != NULL)
+ {
+ context->cb(result,
+ context->type,
+ NULL,
+ context->user_param);
+ }
+ _net_nfc_util_free_mem(context);
+ }
+}
+#endif
+
+
+#if 0
+
+static void _net_nfc_server_handover_server_create_carrier_configs_cb(
+ net_nfc_error_e result,
+ ndef_message_s *selector,
+ void *user_param)
+{
+ _net_nfc_server_handover_create_config_context_t *context =
+ (_net_nfc_server_handover_create_config_context_t *)user_param;
+ data_s data;
+
+ if (context == NULL)
+ {
+ return;
+ }
+
+ if (result == NET_NFC_OK)
+ {
+ result = _net_nfc_server_handover_convert_ndef_message_to_data(
+ selector,
+ &data);
+
+ if (result == NET_NFC_OK)
+ {
+ /* process message */
+ _net_nfc_server_handover_process_carrier_record(
+ context->record,
+ NULL,
+ NULL);
+
+ result = net_nfc_service_snep_server_send_get_response(
+ context->user_param,
+ &data);
+ if (result != NET_NFC_OK)
+ {
+ DEBUG_ERR_MSG("net_nfc_service_snep_server"
+ "_send_get_response failed [%d]",result);
+ }
+ net_nfc_util_free_data(&data);
+ }
+ else
+ {
+ DEBUG_ERR_MSG("_net_nfc_server_handover_convert_ndef_message_to_data"
+ "failed [%d]",result);
+ }
+ }
+ else
+ {
+ DEBUG_ERR_MSG("_net_nfc_server_handover_create_selector_msg"
+ "failed [%d]",result);
+ }
+
+ _net_nfc_util_free_mem(context);
+}
+
+static net_nfc_error_e _net_nfc_server_handover_create_selector_msg(
+ net_nfc_snep_handle_h handle,
+ ndef_message_s *request,
+ void *user_param)
+{
+ net_nfc_error_e result;
+ uint32_t count;
+
+ net_nfc_manager_util_play_sound(NET_NFC_TASK_END);
+
+ /* get requester message */
+ if ((result = net_nfc_util_get_alternative_carrier_record_count(
+ request,
+ &count)) == NET_NFC_OK)
+ {
+ if (1/* power state */ || count == 1)
+ {
+ ndef_record_s *record = NULL;
+
+ /* fill alternative carrier information */
+ if ((result =
+ _net_nfc_server_handover_get_carrier_record_by_priority_order(
+ request,
+ &record)) == NET_NFC_OK)
+ {
+ net_nfc_conn_handover_carrier_type_e type =
+ NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN;
+
+ if ((result = net_nfc_util_get_alternative_carrier_type_from_record(
+ record,
+ &type)) == NET_NFC_OK)
+ {
+ _net_nfc_server_handover_create_config_context_t *context = NULL;
+
+ _net_nfc_util_alloc_mem(context, sizeof(*context));
+
+ context->user_param = handle;
+
+ net_nfc_util_create_record(record->TNF,
+ &record->type_s, &record->id_s,
+ &record->payload_s,
+ &context->record);
+
+ if ((result = _net_nfc_server_handover_create_selector_carrier_configs(
+ type,
+ _net_nfc_server_handover_server_create_carrier_configs_cb,
+ context)) != NET_NFC_OK)
+ {
+ DEBUG_ERR_MSG("_create_selector_carrier_configs "
+ "failed [%d]", result);
+ }
+ }
+ else
+ {
+ DEBUG_ERR_MSG("get_alternative_carrier_type_from_record "
+ "failed [%d]", result);
+ }
+ }
+ else
+ {
+ DEBUG_ERR_MSG("r_get_carrier_record_by_priority_order"
+ " failed [%d]", result);
+ }
+ }
+ else /* low power && count > 1 */
+ {
+ ndef_message_s selector;
+
+ if ((result = _net_nfc_server_handover_create_low_power_selector_message(
+ request,
+ &selector)) == NET_NFC_OK)
+ {
+ _net_nfc_server_handover_server_create_carrier_configs_cb(
+ NET_NFC_OK,
+ &selector,
+ user_param);
+
+ net_nfc_util_free_ndef_message(&selector);
+ }
+ else
+ {
+ DEBUG_ERR_MSG("_create_low_power_selector_message"
+ "failed [%d]", result);
+ }
+ }
+ }
+ else
+ {
+ DEBUG_ERR_MSG("net_nfc_util_get_alternative_carrier_record_count"
+ "failed [%d]", result);
+ }
+
+ return result;
+}
+
+
+static net_nfc_error_e _net_nfc_server_handover_create_server_cb(
+ net_nfc_snep_handle_h handle,
+ net_nfc_error_e result,
+ uint32_t type,
+ data_s *data,
+ void *user_param)
+{
+ DEBUG_SERVER_MSG("type [0x%02x], result [%d], data [%p], user_param [%p]",
+ type, result, data, user_param);
+
+ if (result != NET_NFC_OK || data == NULL || data->buffer == NULL)
+ {
+ /* restart */
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ switch (type)
+ {
+ case SNEP_REQ_GET :
+ {
+ ndef_message_s *request;
+
+ /* TODO : send select response to requester */
+ result =
+ _net_nfc_server_handover_create_requester_from_rawdata(
+ &request,
+ data);
+ if (result == NET_NFC_OK) {
+ if (1/* TODO : check version */)
+ {
+ _net_nfc_server_handover_create_selector_msg(
+ handle,
+ request,
+ user_param);
+ }
+ else
+ {
+ DEBUG_ERR_MSG("not supported version [0x%x]",
+ result);
+
+ result = NET_NFC_NOT_SUPPORTED;
+ }
+
+ net_nfc_util_free_ndef_message(request);
+ }
+ else
+ {
+ DEBUG_ERR_MSG("_net_nfc_server_handover_create"
+ "_requester_from_rawdata failed [%d]",result);
+ }
+ }
+ break;
+
+ case SNEP_REQ_PUT :
+ DEBUG_ERR_MSG("PUT request doesn't supported");
+ result = NET_NFC_NOT_SUPPORTED;
+ break;
+
+ default :
+ DEBUG_ERR_MSG("error [%d]", result);
+ break;
+ }
+
+ return result;
+}
+#else
+
+
+
+static net_nfc_error_e _net_nfc_server_handover_select_carrier_record(
+ ndef_message_s *request,
+ net_nfc_conn_handover_carrier_type_e *type,
+ ndef_record_s **record)
+{
+ net_nfc_error_e result;
+ uint32_t count;
+
+ *record = NULL;
+ *type = NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN;
+
+ /* get requester message */
+ if ((result = net_nfc_util_get_alternative_carrier_record_count(request,
+ &count)) == NET_NFC_OK)
+ {
+ if (1/* power state */ || count == 1)
+ {
+ ndef_record_s *temp;
+
+ /* fill alternative carrier information */
+ if ((result =
+ _net_nfc_server_handover_get_carrier_record_by_priority_order(
+ request,
+ &temp)) == NET_NFC_OK)
+ {
+ if ((result =
+ net_nfc_util_get_alternative_carrier_type_from_record(
+ temp,
+ type)) == NET_NFC_OK)
+ {
+ net_nfc_util_create_record(temp->TNF,
+ &temp->type_s, &temp->id_s,
+ &temp->payload_s,
+ record);
+ }
+ else
+ {
+ DEBUG_ERR_MSG("net_nfc_util_get_alternative"
+ "_carrier_type_from_record failed [%d]", result);
+ }
+ }
+ else
+ {
+ DEBUG_ERR_MSG("_handover_get_carrier_record"
+ "_by_priority_order failed [%d]", result);
+ }
+ }
+ else /* low power && count > 1 */
+ {
+ result = NET_NFC_INVALID_STATE;
+ }
+ }
+ else
+ {
+ DEBUG_ERR_MSG("net_nfc_util_get_alternative_carrier_record_count "
+ "failed [%d]", result);
+ }
+
+ return result;
+}
+
+#endif
+
+static void _net_nfc_server_handover_create_carrier_configs_2_cb(
+ net_nfc_error_e result,
+ ndef_message_s *selector,
+ void *user_param)
+{
+ net_nfc_handover_context_t *context =
+ (net_nfc_handover_context_t *)user_param;
+
+ DEBUG_SERVER_MSG("_net_nfc_server_handover_server_create_carrier_config_cb"
+ "result [%d]",result);
+
+ if (context == NULL)
+ {
+ return;
+ }
+
+ context->result = result;
+
+ if (result == NET_NFC_OK) {
+ result = _net_nfc_server_handover_convert_ndef_message_to_data(
+ selector,
+ &context->data);
+
+ DEBUG_SERVER_MSG("selector message created, length [%d]",
+ context->data.length);
+
+ context->state = NET_NFC_LLCP_STEP_03;
+ }
+ else
+ {
+ DEBUG_ERR_MSG("_net_nfc_server_handover_create_selector_msg failed [%d]",
+ result);
+ context->state = NET_NFC_MESSAGE_LLCP_ERROR;
+ }
+
+ _net_nfc_server_handover_get_response_process(context);
+}
+
+static void _net_nfc_server_handover_process_carrier_record_2_cb(
+ net_nfc_error_e result,
+ net_nfc_conn_handover_carrier_type_e type,
+ data_s *data,
+ void *user_param)
+{
+ net_nfc_handover_context_t *context =
+ (net_nfc_handover_context_t *)user_param;
+
+ DEBUG_SERVER_MSG("_net_nfc_server_handover_server_process_carrier_record_cb"
+ "result [%d]",result);
+
+ context->result = result;
+ if (result == NET_NFC_OK)
+ {
+ context->state = NET_NFC_LLCP_STEP_04;
+ }
+ else
+ {
+ context->state = NET_NFC_MESSAGE_LLCP_ERROR;
+ }
+
+ context->data.length = data->length;
+ _net_nfc_util_alloc_mem(context->data.buffer, context->data.length);
+ memcpy(context->data.buffer, data->buffer, context->data.length);
+
+
+ _net_nfc_server_handover_server_process(context);
+}
+
+static void _net_nfc_server_handover_get_response_process(
+ net_nfc_handover_context_t *context)
+{
+ net_nfc_error_e result;
+
+ if (context == NULL)
+ {
+ return;
+ }
+
+ switch (context->state)
+ {
+ case NET_NFC_LLCP_STEP_02 :
+ DEBUG_SERVER_MSG("NET_NFC_LLCP_STEP_02");
+
+ result = _net_nfc_server_handover_create_selector_carrier_configs(
+ context->type,
+ _net_nfc_server_handover_create_carrier_configs_2_cb,
+ context);
+
+ if (result != NET_NFC_OK)
+ {
+ DEBUG_ERR_MSG("_net_nfc_server_handover_create_"
+ "selector_carrier_config failed [%d]",result);
+ }
+ break;
+
+ case NET_NFC_LLCP_STEP_03 :
+ DEBUG_SERVER_MSG("NET_NFC_LLCP_STEP_03");
+
+ result = _net_nfc_server_handover_process_carrier_record(
+ context->record,
+ _net_nfc_server_handover_process_carrier_record_2_cb,
+ context);
+
+ if (result != NET_NFC_OK)
+ {
+ DEBUG_ERR_MSG("_net_nfc_server_handover_process_carrier_record"
+ "failed [%d]",result);
+ }
+ break;
+
+ case NET_NFC_LLCP_STEP_04 :
+ DEBUG_SERVER_MSG("NET_NFC_LLCP_STEP_04");
+
+ /* response select message */
+ result = net_nfc_server_snep_server_send_get_response(
+ (net_nfc_snep_handle_h)context->handle,
+ &context->data);
+ break;
+
+ case NET_NFC_STATE_ERROR :
+ DEBUG_SERVER_MSG("NET_NFC_STATE_ERROR");
+ break;
+
+ default :
+ DEBUG_ERR_MSG("NET_NFC_LLCP_STEP_??");
+ /* TODO */
+ break;
+ }
+}
+
+static bool _net_nfc_server_handover_get_response_cb(
+ net_nfc_snep_handle_h handle,
+ uint32_t type,
+ uint32_t max_len,
+ data_s *data,
+ void *user_param)
+{
+ net_nfc_error_e result;
+ ndef_message_s *request;
+
+ DEBUG_SERVER_MSG("type [%d], data [%p], user_param [%p]",
+ type, data, user_param);
+
+ if (data == NULL || data->buffer == NULL)
+ {
+ /* restart */
+ return false;
+ }
+
+ /* TODO : send select response to requester */
+ result = _net_nfc_server_handover_create_requester_from_rawdata(
+ &request,
+ data);
+
+ if (result == NET_NFC_OK)
+ {
+ net_nfc_conn_handover_carrier_type_e type;
+ ndef_record_s *record;
+
+ if (_net_nfc_server_handover_select_carrier_record(
+ request,
+ &type,
+ &record) == NET_NFC_OK)
+ {
+ net_nfc_handover_context_t *context = NULL;
+
+ _net_nfc_util_alloc_mem(context, sizeof(*context));
+
+ if (context != NULL)
+ {
+ context->handle = (void *)handle;
+ context->type = type;
+ context->user_param = user_param;
+ context->state = NET_NFC_LLCP_STEP_02;
+
+ net_nfc_util_create_record(record->TNF,
+ &record->type_s,
+ &record->id_s,
+ &record->payload_s,
+ &context->record);
+
+ _net_nfc_server_handover_get_response_process(context);
+ }
+ else
+ {
+ DEBUG_ERR_MSG("_net_nfc_util_alloc_mem failed");
+ result = NET_NFC_ALLOC_FAIL;
+ }
+ }
+ else
+ {
+ /* low power */
+ }
+
+ net_nfc_util_free_ndef_message(request);
+ }
+ else
+ {
+ DEBUG_SERVER_MSG("it is not handover requester message, [%d]",
+ result);
+ }
+
+ return (result == NET_NFC_OK);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+static void _net_nfc_server_handover_server_process_carrier_record_cb(
+ net_nfc_error_e result,
+ net_nfc_conn_handover_carrier_type_e type,
+ data_s *data,
+ void *user_param)
+{
+ net_nfc_handover_context_t *context =
+ (net_nfc_handover_context_t *)user_param;
+
+ DEBUG_SERVER_MSG("_net_nfc_server_handover_server_process"
+ "_carrier_record_cb result [%d]",result);
+
+ context->result = result;
+ if (result == NET_NFC_OK)
+ {
+ context->state = NET_NFC_LLCP_STEP_04;
+ }
+ else
+ {
+ context->state = NET_NFC_MESSAGE_LLCP_ERROR;
+ }
+
+ _net_nfc_server_handover_server_process(context);
+}
+
+static void _net_nfc_server_handover_server_create_carrier_config_cb(
+ net_nfc_error_e result,
+ ndef_message_s *selector,
+ void *user_param)
+{
+ net_nfc_handover_context_t *context =
+ (net_nfc_handover_context_t *)user_param;
+
+ DEBUG_SERVER_MSG("_net_nfc_server_handover_server_create"
+ "_carrier_config_cb,result [%d]",result);
+
+ if (context == NULL)
+ {
+ return;
+ }
+
+ context->result = result;
+
+ if (result == NET_NFC_OK)
+ {
+ result = _net_nfc_server_handover_convert_ndef_message_to_data(
+ selector,
+ &context->data);
+ DEBUG_SERVER_MSG("selector message created, length [%d]",
+ context->data.length);
+ context->state = NET_NFC_LLCP_STEP_03;
+ }
+ else
+ {
+ DEBUG_ERR_MSG("_net_nfc_server_handover_create_selector_msg"
+ " failed [%d]", result);
+ context->state = NET_NFC_MESSAGE_LLCP_ERROR;
+ }
+
+ _net_nfc_server_handover_server_process(context);
+}
+
+static void _net_nfc_server_handover_server_recv_cb(
+ net_nfc_error_e result,
+ net_nfc_target_handle_s *handle,
+ net_nfc_llcp_socket_t socket,
+ data_s *data,
+ void *user_param)
+{
+ net_nfc_handover_context_t *context =
+ (net_nfc_handover_context_t *)user_param;
+ ndef_message_s *request;
+
+ DEBUG_SERVER_MSG("_net_nfc_server_handover_server_recv_cb,"
+ " socket [%x], result [%d]", socket, result);
+
+ context->result = result;
+
+ if (result == NET_NFC_OK)
+ {
+ result = _net_nfc_server_handover_create_requester_from_rawdata(
+ &request,
+ data);
+
+ if (result == NET_NFC_OK)
+ {
+ ndef_record_s *record;
+
+ if (_net_nfc_server_handover_select_carrier_record(
+ request,
+ &context->type,
+ &record) == NET_NFC_OK)
+ {
+ net_nfc_util_create_record(record->TNF,
+ &record->type_s, &record->id_s,
+ &record->payload_s,
+ &context->record);
+
+ context->state = NET_NFC_LLCP_STEP_02;
+ }
+ else
+ {
+ /* low power */
+ context->state = NET_NFC_LLCP_STEP_06;
+ }
+
+ net_nfc_util_free_ndef_message(request);
+ }
+ else
+ {
+ DEBUG_ERR_MSG("_net_nfc_server_handover_create"
+ "_requester_from_rawdata failed [%d]",result);
+ context->state = NET_NFC_MESSAGE_LLCP_ERROR;
+ }
+ }
+ else
+ {
+ DEBUG_ERR_MSG("net_nfc_server_llcp_simple_receive failed [%d]",
+ result);
+ context->state = NET_NFC_MESSAGE_LLCP_ERROR;
+ }
+
+ _net_nfc_server_handover_server_process(context);
+}
+
+static void _net_nfc_server_handover_server_send_cb(net_nfc_error_e result,
+ net_nfc_target_handle_s *handle,
+ net_nfc_llcp_socket_t socket,
+ data_s *data,
+ void *user_param)
+{
+ net_nfc_handover_context_t *context =
+ (net_nfc_handover_context_t *)user_param;
+
+ DEBUG_SERVER_MSG("_net_nfc_server_handover_server_send_cb"
+ " socket [%x], result [%d]", socket, result);
+
+ context->result = result;
+
+ if (result == NET_NFC_OK)
+ {
+ context->state = NET_NFC_LLCP_STEP_01;
+ net_nfc_util_free_data(&context->data);
+ net_nfc_util_free_record(context->record);
+ context->record = NULL;
+ }
+ else
+ {
+ DEBUG_ERR_MSG("net_nfc_server_llcp_simple_send failed [%d]",
+ result);
+ context->state = NET_NFC_MESSAGE_LLCP_ERROR;
+ }
+
+ _net_nfc_server_handover_server_process(context);
+}
+
+static void _net_nfc_server_handover_server_process(
+ net_nfc_handover_context_t *context)
+{
+ if (context == NULL)
+ {
+ return;
+ }
+
+ switch (context->state)
+ {
+ case NET_NFC_LLCP_STEP_01 :
+ DEBUG_SERVER_MSG("NET_NFC_LLCP_STEP_01");
+
+ /* receive request message */
+ net_nfc_server_llcp_simple_receive(context->handle,
+ context->socket,
+ _net_nfc_server_handover_server_recv_cb,
+ context);
+ break;
+
+ case NET_NFC_LLCP_STEP_02 :
+ DEBUG_SERVER_MSG("NET_NFC_LLCP_STEP_02");
+
+ context->result = _net_nfc_server_handover_create_selector_carrier_configs(
+ context->type,
+ _net_nfc_server_handover_server_create_carrier_config_cb,
+ context);
+
+ if (context->result != NET_NFC_OK)
+ {
+ DEBUG_ERR_MSG("_net_nfc_server_handover_create_selector"
+ "_carrier_configs failed [%d]", context->result);
+ }
+ break;
+
+ case NET_NFC_LLCP_STEP_03 :
+ DEBUG_SERVER_MSG("NET_NFC_LLCP_STEP_03");
+
+ context->result = _net_nfc_server_handover_process_carrier_record(
+ context->record,
+ _net_nfc_server_handover_server_process_carrier_record_cb,
+ context);
+ if (context->result != NET_NFC_OK)
+ {
+ DEBUG_ERR_MSG("_net_nfc_server_handover_process_carrier_"
+ "record failed [%d]",context->result);
+ }
+ break;
+
+ case NET_NFC_LLCP_STEP_04 :
+ DEBUG_SERVER_MSG("NET_NFC_LLCP_STEP_04");
+
+ /* send select message */
+ net_nfc_server_llcp_simple_send(
+ context->handle,
+ context->socket,
+ &context->data,
+ _net_nfc_server_handover_server_send_cb,
+ context);
+ break;
+
+ case NET_NFC_STATE_ERROR :
+ DEBUG_SERVER_MSG("NET_NFC_STATE_ERROR");
+
+ /* error, invoke callback */
+ DEBUG_ERR_MSG("handover_server failed, [%d]",
+ context->result);
+
+ /* restart?? */
+ break;
+
+ default :
+ DEBUG_ERR_MSG("NET_NFC_LLCP_STEP_??");
+ /* TODO */
+ break;
+ }
+}
+
+static void _net_nfc_server_handover_server_error_cb(
+ net_nfc_error_e result,
+ net_nfc_target_handle_s *handle,
+ net_nfc_llcp_socket_t socket,
+ data_s *data,
+ void *user_param)
+{
+ net_nfc_handover_context_t *context =
+ (net_nfc_handover_context_t *)user_param;
+
+ DEBUG_ERR_MSG("result [%d], socket [%x], user_param [%p]",
+ result, socket, user_param);
+
+ if (context == NULL)
+ {
+ return;
+ }
+
+ net_nfc_controller_llcp_socket_close(socket, &result);
+
+ net_nfc_util_free_record(context->record);
+ net_nfc_util_free_data(&context->data);
+ _net_nfc_util_free_mem(user_param);
+}
+
+static void _net_nfc_server_handover_server_incomming_cb(
+ net_nfc_error_e result,
+ net_nfc_target_handle_s *handle,
+ net_nfc_llcp_socket_t socket,
+ data_s *data,
+ void *user_param)
+{
+ DEBUG_SERVER_MSG("result [%d], socket [%x], user_param [%p]",
+ result, socket, user_param);
+
+ net_nfc_handover_context_t *accept_context = NULL;
+
+ _net_nfc_util_alloc_mem(accept_context, sizeof(*accept_context));
+ if (accept_context == NULL)
+ {
+ DEBUG_ERR_MSG("_net_nfc_util_alloc_mem failed");
+
+ result = NET_NFC_ALLOC_FAIL;
+ goto ERROR;
+ }
+
+ accept_context->handle = handle;
+ accept_context->socket = socket;
+ accept_context->state = NET_NFC_LLCP_STEP_01;
+
+ result = net_nfc_server_llcp_simple_accept(
+ handle,
+ socket,
+ _net_nfc_server_handover_server_error_cb,
+ accept_context);
+
+ if (result != NET_NFC_OK)
+ {
+ DEBUG_ERR_MSG("net_nfc_server_llcp_simple_accept failed, [%d]",
+ result);
+
+ goto ERROR;
+ }
+
+ _net_nfc_server_handover_server_process(accept_context);
+
+ return;
+
+ERROR :
+ if (accept_context != NULL)
+ {
+ _net_nfc_util_free_mem(accept_context);
+ }
+
+ net_nfc_controller_llcp_socket_close(socket, &result);
+
+ /* TODO : restart ?? */
+}
+
+net_nfc_error_e net_nfc_server_handover_default_server_start(
+ net_nfc_target_handle_s *handle)
+{
+ net_nfc_error_e result;
+
+ /* start default handover server using snep */
+ result =
+ net_nfc_server_snep_default_server_register_get_response_cb(
+ _net_nfc_server_handover_get_response_cb,
+ NULL);
+
+ /* start default handover server */
+ result = net_nfc_server_llcp_simple_server(
+ handle,
+ CH_SAN,
+ CH_SAP,
+ _net_nfc_server_handover_server_incomming_cb,
+ _net_nfc_server_handover_server_error_cb,
+ NULL);
+
+ if (result == NET_NFC_OK)
+ {
+ DEBUG_SERVER_MSG("start handover server, san [%s], sap [%d]",
+ CH_SAN,CH_SAP);
+ }
+ else
+ {
+ DEBUG_ERR_MSG("net_nfc_server_llcp_simple_server failed, [%d]",
+ result);
+ }
+
+ return result;
+}
+
+static void _handover_default_activate_cb(int event,
+ net_nfc_target_handle_s *handle,
+ uint32_t sap, const char *san, void *user_param)
+{
+ net_nfc_error_e result;
+
+ DEBUG_SERVER_MSG("event [%d], handle [%p], sap [%d], san [%s]",
+ event, handle, sap, san);
+
+ if (event == NET_NFC_LLCP_START) {
+ /* start default handover server using snep */
+ result = net_nfc_server_snep_default_server_register_get_response_cb(
+ _net_nfc_server_handover_get_response_cb, NULL);
+
+ /* start default handover server */
+ result = net_nfc_server_llcp_simple_server(handle,
+ CH_SAN, CH_SAP,
+ _net_nfc_server_handover_server_incomming_cb,
+ _net_nfc_server_handover_server_error_cb, NULL);
+
+ if (result == NET_NFC_OK) {
+ DEBUG_SERVER_MSG("start handover server, san [%s], sap [%d]",
+ CH_SAN, CH_SAP);
+ } else {
+ DEBUG_ERR_MSG("net_nfc_service_llcp_server failed, [%d]",
+ result);
+ }
+ } else if (event == NET_NFC_LLCP_UNREGISTERED) {
+ /* unregister server, do nothing */
+ }
+}
+
+net_nfc_error_e net_nfc_server_handover_default_server_register()
+{
+ char id[20];
+
+ /* TODO : make id, */
+ snprintf(id, sizeof(id), "%d", getpid());
+
+ /* start default snep server */
+ return net_nfc_server_llcp_register_service(id,
+ CH_SAP,
+ CH_SAN,
+ _handover_default_activate_cb,
+ NULL);
+}
+
+net_nfc_error_e net_nfc_server_handover_default_server_unregister()
+{
+ char id[20];
+
+ /* TODO : make id, */
+ snprintf(id, sizeof(id), "%d", getpid());
+
+ /* start default snep server */
+ return net_nfc_server_llcp_unregister_service(id,
+ CH_SAP,
+ CH_SAN);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+
+static void _net_nfc_server_handover_client_post_process_cb(
+ net_nfc_error_e result,
+ net_nfc_conn_handover_carrier_type_e type,
+ data_s *data,
+ void *user_param)
+{
+ net_nfc_handover_context_t *context =
+ (net_nfc_handover_context_t *)user_param;
+
+ if (context == NULL)
+ {
+ return;
+ }
+
+ context->state = NET_NFC_LLCP_STEP_RETURN;
+
+ _net_nfc_server_handover_client_process(context);
+}
+
+static void _net_nfc_server_handover_client_process_carrier_record_cb(
+ net_nfc_error_e result,
+ net_nfc_conn_handover_carrier_type_e type,
+ data_s *data,
+ void *user_param)
+{
+ net_nfc_handover_context_t *context =
+ (net_nfc_handover_context_t *)user_param;
+
+ DEBUG_SERVER_MSG("_net_nfc_server_handover_server_process"
+ "_carrier_record_cb,result [%d]",result);
+
+ context->result = result;
+
+ net_nfc_util_free_data(&context->data);
+
+ if (result == NET_NFC_OK)
+ {
+ net_nfc_util_alloc_data(&context->data, data->length);
+ memcpy(context->data.buffer, data->buffer, data->length);
+
+ context->state = NET_NFC_LLCP_STEP_05;
+ }
+ else
+ {
+ context->state = NET_NFC_MESSAGE_LLCP_ERROR;
+ }
+
+ _net_nfc_server_handover_client_process(context);
+}
+
+static void _net_nfc_server_handover_client_recv_cb(
+ net_nfc_error_e result,
+ net_nfc_target_handle_s *handle,
+ net_nfc_llcp_socket_t socket,
+ data_s *data,
+ void *user_param)
+{
+ net_nfc_handover_context_t *context =
+ (net_nfc_handover_context_t *)user_param;
+
+ if (context == NULL)
+ {
+ return;
+ }
+
+ context->result = result;
+
+ if (result == NET_NFC_OK)
+ {
+ ndef_message_s *selector;
+ ndef_record_s *record;
+
+ result = _net_nfc_server_handover_create_selector_from_rawdata(
+ &selector,
+ data);
+
+ if (result == NET_NFC_OK)
+ {
+ result =
+ _net_nfc_server_handover_get_carrier_record_by_priority_order(
+ selector,
+ &record);
+
+ if (result == NET_NFC_OK)
+ {
+ net_nfc_util_create_record(
+ record->TNF,
+ &record->type_s, &record->id_s,
+ &record->payload_s,
+ &context->record);
+
+ context->state = NET_NFC_LLCP_STEP_04;
+ }
+ else
+ {
+ DEBUG_ERR_MSG("_get_carrier_record_by_priority_order"
+ " failed, [%d]",result);
+ context->state = NET_NFC_STATE_ERROR;
+ }
+ }
+ else
+ {
+ DEBUG_ERR_MSG("_net_nfc_server_handover_create"
+ "_selector_from_rawdata failed, [%d]",result);
+ context->state = NET_NFC_STATE_ERROR;
+ }
+ }
+ else
+ {
+ DEBUG_ERR_MSG("net_nfc_server_llcp_simple_receive failed, [%d]",
+ result);
+ context->state = NET_NFC_STATE_ERROR;
+ }
+
+ _net_nfc_server_handover_client_process(context);
+}
+
+static void _net_nfc_server_handover_client_send_cb(
+ net_nfc_error_e result,
+ net_nfc_target_handle_s *handle,
+ net_nfc_llcp_socket_t socket,
+ data_s *data,
+ void *user_param)
+{
+ net_nfc_handover_context_t *context =
+ (net_nfc_handover_context_t *)user_param;
+
+ if (context == NULL)
+ {
+ return;
+ }
+
+ context->result = result;
+
+ net_nfc_util_free_data(&context->data);
+
+ if (result == NET_NFC_OK)
+ {
+ context->state = NET_NFC_LLCP_STEP_03;
+ }
+ else
+ {
+ DEBUG_ERR_MSG("net_nfc_server_llcp_simple_client failed, [%d]",
+ result);
+ context->state = NET_NFC_STATE_ERROR;
+ }
+
+ _net_nfc_server_handover_client_process(context);
+}
+
+static void _net_nfc_server_handover_client_create_carrier_configs_cb(
+ net_nfc_error_e result,
+ ndef_message_s *msg,
+ void *user_param)
+{
+ net_nfc_handover_context_t *context =
+ (net_nfc_handover_context_t *)user_param;
+
+ if (context == NULL) {
+ return;
+ }
+
+ context->result = result;
+
+ if (msg != NULL)
+ {
+ if ((result =
+ _net_nfc_server_handover_convert_ndef_message_to_data(
+ msg,
+ &context->data)) == NET_NFC_OK)
+ {
+ context->state = NET_NFC_LLCP_STEP_02;
+ }
+ else
+ {
+ DEBUG_ERR_MSG("_net_nfc_server_handover_convert_ndef_"
+ "message_to_data failed [%d]",result);
+ context->state = NET_NFC_STATE_ERROR;
+ context->result = result;
+ }
+ }
+ else
+ {
+ DEBUG_ERR_MSG("null param, [%d]", result);
+ context->state = NET_NFC_STATE_ERROR;
+ context->result = result;
+ }
+
+ _net_nfc_server_handover_client_process(context);
+}
+
+
+////////////////////////////////////////////////////////////////////////////////
+static void _net_nfc_server_handover_client_process(
+ net_nfc_handover_context_t *context)
+{
+ net_nfc_error_e result;
+
+ if (context == NULL)
+ {
+ return;
+ }
+
+ switch (context->state)
+ {
+ case NET_NFC_LLCP_STEP_01 :
+ DEBUG_SERVER_MSG("NET_NFC_LLCP_STEP_01");
+
+ if ((result = _net_nfc_server_handover_create_requester_carrier_configs(
+ context->type,
+ _net_nfc_server_handover_client_create_carrier_configs_cb,
+ context)) != NET_NFC_OK)
+ {
+ DEBUG_ERR_MSG("_net_nfc_server_handover_create_requester"
+ "_carrier_configs failed [%d]",result);
+ }
+ break;
+
+ case NET_NFC_LLCP_STEP_02 :
+ DEBUG_SERVER_MSG("NET_NFC_LLCP_STEP_02");
+
+ /* send request */
+ net_nfc_server_llcp_simple_send(
+ context->handle,
+ context->socket,
+ &context->data,
+ _net_nfc_server_handover_client_send_cb,
+ context);
+ break;
+
+ case NET_NFC_LLCP_STEP_03 :
+ DEBUG_SERVER_MSG("NET_NFC_LLCP_STEP_03");
+
+ /* receive response */
+ net_nfc_server_llcp_simple_receive(context->handle,
+ context->socket,
+ _net_nfc_server_handover_client_recv_cb,
+ context);
+ break;
+
+ case NET_NFC_LLCP_STEP_04 :
+ DEBUG_SERVER_MSG("NET_NFC_LLCP_STEP_04");
+
+ result = _net_nfc_server_handover_process_carrier_record(
+ context->record,
+ _net_nfc_server_handover_client_process_carrier_record_cb,
+ context);
+
+ if (result != NET_NFC_OK)
+ {
+ DEBUG_ERR_MSG("_net_nfc_server_handover_process_carrier_record"
+ "failed [%d]",result);
+ }
+ break;
+
+ case NET_NFC_LLCP_STEP_05 :
+ DEBUG_SERVER_MSG("NET_NFC_LLCP_STEP_05");
+
+ /* start post process */
+ if (context->type == NET_NFC_CONN_HANDOVER_CARRIER_BT)
+ {
+ net_nfc_server_handover_bt_post_process(
+ &context->data,
+ _net_nfc_server_handover_client_post_process_cb,
+ context);
+ }
+ else
+ {
+ DEBUG_ERR_MSG("not supported...");
+ }
+ break;
+
+ case NET_NFC_LLCP_STEP_RETURN :
+ DEBUG_SERVER_MSG("NET_NFC_LLCP_STEP_RETURN");
+
+ /* complete and invoke callback */
+ _net_nfc_server_handover_send_response(
+ context->user_param,
+ &context->data,
+ context->result);
+
+ net_nfc_util_free_data(&context->data);
+ net_nfc_util_free_record(context->record);
+ _net_nfc_util_free_mem(context);
+ break;
+
+ case NET_NFC_STATE_ERROR :
+ default :
+ DEBUG_ERR_MSG("NET_NFC_STATE_ERROR");
+
+ _net_nfc_server_handover_send_response(
+ context->user_param,
+ NULL,
+ context->result);
+ break;
+ }
+}
+
+
+
+static void _net_nfc_server_handover_client_connected_cb(
+ net_nfc_error_e result,
+ net_nfc_target_handle_s *handle,
+ net_nfc_llcp_socket_t socket,
+ data_s *data,
+ void *user_param)
+{
+ DEBUG_SERVER_MSG("result [%d], socket [%x], user_param [%p]",
+ result, socket, user_param);
+
+ if (result == NET_NFC_OK)
+ {
+ net_nfc_handover_context_t *context = NULL;
+ _net_nfc_util_alloc_mem(context, sizeof(*context));
+
+ if (context != NULL)
+ {
+ context->handle = handle;
+ context->socket = socket;
+ context->state = NET_NFC_LLCP_STEP_01;
+ context->user_param = user_param;
+ _net_nfc_server_handover_client_process(context);
+ }
+ else
+ {
+ DEBUG_ERR_MSG("_net_nfc_util_alloc_mem failed");
+ result = NET_NFC_ALLOC_FAIL;
+ }
+ }
+ else
+ {
+ DEBUG_ERR_MSG("net_nfc_server_llcp_simple_client"
+ " failed, [%d]", result);
+ }
+}
+
+static void _net_nfc_server_handover_client_error_cb(
+ net_nfc_error_e result,
+ net_nfc_target_handle_s *handle,
+ net_nfc_llcp_socket_t socket,
+ data_s *data,
+ void *user_param)
+{
+
+ DEBUG_ERR_MSG("result [%d], socket [%x], user_param [%p]",
+ result, socket, user_param);
+
+ if (false)
+ {
+ _net_nfc_server_handover_send_response(user_param, NULL, result);
+ }
+
+ net_nfc_controller_llcp_socket_close(socket, &result);
+}
+
+
+net_nfc_error_e net_nfc_server_handover_default_client_start(
+ net_nfc_target_handle_s *handle,
+ void *user_data)
+{
+ net_nfc_error_e result;
+
+ result = net_nfc_server_llcp_simple_client(
+ handle,
+ CH_SAN,
+ CH_SAP,
+ _net_nfc_server_handover_client_connected_cb,
+ _net_nfc_server_handover_client_error_cb,
+ user_data);
+
+ if (result != NET_NFC_OK)
+ {
+ DEBUG_ERR_MSG("net_nfc_server_llcp_simple_client"
+ " failed, [%d]",result);
+ }
+
+ return result;
+}
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_SERVER_PROCESS_HANDOVER_H__
+#define __NET_NFC_SERVER_PROCESS_HANDOVER_H__
+
+#include "net_nfc_typedef_internal.h"
+
+net_nfc_error_e net_nfc_server_handover_default_server_start(
+ net_nfc_target_handle_s *handle);
+
+net_nfc_error_e net_nfc_server_handover_default_client_start(
+ net_nfc_target_handle_s *handle,
+ void *user_data);
+
+net_nfc_error_e net_nfc_server_handover_default_server_register();
+
+net_nfc_error_e net_nfc_server_handover_default_server_unregister();
+
+net_nfc_error_e _net_nfc_server_handover_create_selector_from_rawdata(
+ ndef_message_s **selector,
+ data_s *data);
+
+net_nfc_error_e
+_net_nfc_server_handover_get_carrier_record_by_priority_order(
+ ndef_message_s *request,
+ ndef_record_s **record);
+
+net_nfc_error_e _net_nfc_server_handover_process_carrier_record(
+ ndef_record_s *carrier,
+ void *cb,
+ void *user_param);
+
+#endif //__NET_NFC_SERVER_PROCESS_HANDOVER_H__
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include <arpa/inet.h>
+
+#include "net_nfc_debug_internal.h"
+#include "net_nfc_server_p2p.h"
+#include "net_nfc_server_llcp.h"
+#include "net_nfc_server_controller.h"
+#include "net_nfc_server_util.h"
+#include "net_nfc_server_process_npp.h"
+
+typedef struct _net_nfc_npp_entity_t
+{
+ uint8_t op;
+ uint32_t length;
+ uint8_t data[0];
+}
+__attribute__ ((packed)) net_nfc_npp_entity_t;
+
+typedef struct _net_nfc_npp_msg_t
+{
+ uint8_t version;
+ uint32_t entity_count;
+ net_nfc_npp_entity_t entity[0];
+}
+__attribute__ ((packed)) net_nfc_npp_msg_t;
+
+typedef struct _NppData NppData;
+
+struct _NppData
+{
+ net_nfc_target_handle_s *handle;
+ net_nfc_llcp_socket_t socket;
+ uint32_t type;
+ data_s data;
+ net_nfc_server_npp_callback callback;
+ gpointer user_data;
+};
+
+typedef struct _NppClientStartData NppClientStartData;
+
+struct _NppClientStartData
+{
+ net_nfc_target_handle_s *handle;
+ int client;
+ gpointer user_data;
+};
+
+#define NPP_SAN "com.android.npp"
+#define NPP_SAP 0x10
+
+#define NPP_HEADER_LEN (sizeof(net_nfc_npp_msg_t))
+#define NPP_ENTITY_HEADER_LEN (sizeof(net_nfc_npp_entity_t))
+
+#define NPP_MAJOR_VER 0
+#define NPP_MINOR_VER 1
+#define NPP_VERSION ((NPP_MAJOR_VER << 4) | NPP_MINOR_VER)
+
+#define NPP_NDEF_ENTRY 0x00000001
+#define NPP_ACTION_CODE 0x01
+
+static net_nfc_error_e npp_create_message(data_s *data,
+ data_s *message);
+
+/* server */
+static void npp_server_receive_cb(net_nfc_error_e result,
+ net_nfc_target_handle_s *handle,
+ net_nfc_llcp_socket_t socket,
+ data_s *data,
+ gpointer user_data);
+
+static void npp_server_process(NppData *npp_data);
+
+static void npp_listen_cb(net_nfc_error_e result,
+ net_nfc_target_handle_s *handle,
+ net_nfc_llcp_socket_t socket,
+ data_s *data,
+ gpointer user_data);
+
+/* client */
+static void npp_client_disconnected_cb(net_nfc_llcp_socket_t socket,
+ net_nfc_error_e result,
+ data_s *data,
+ void *extra,
+ void *user_param);
+
+static void npp_client_send_cb(net_nfc_error_e result,
+ net_nfc_target_handle_s *handle,
+ net_nfc_llcp_socket_t socket,
+ data_s *data,
+ gpointer user_data);
+
+static void npp_client_process(NppData *npp_data);
+
+static void npp_connected_cb(net_nfc_error_e result,
+ net_nfc_target_handle_s *handle,
+ net_nfc_llcp_socket_t socket,
+ data_s *data,
+ gpointer user_data);
+
+static void npp_socket_error_cb(net_nfc_error_e result,
+ net_nfc_target_handle_s *handle,
+ net_nfc_llcp_socket_t socket,
+ data_s *data,
+ gpointer user_data);
+
+static void npp_default_server_cb(net_nfc_error_e result,
+ data_s *data,
+ gpointer user_data);
+
+static void npp_default_client_cb(net_nfc_error_e result,
+ data_s *data,
+ gpointer user_data);
+
+static net_nfc_error_e npp_create_message(data_s *data,
+ data_s *message)
+{
+ uint32_t length = NPP_HEADER_LEN;
+ net_nfc_npp_msg_t *msg;
+
+ if (data != NULL)
+ length += NPP_ENTITY_HEADER_LEN + data->length;
+
+ message->buffer = g_new0(uint8_t, length);
+ message->length = length;
+
+ msg = (net_nfc_npp_msg_t *)message->buffer;
+ msg->version = NPP_VERSION;
+
+ if (data != NULL)
+ {
+ net_nfc_npp_entity_t *entity;
+
+ DEBUG_SERVER_MSG("data->length [%d]", data->length);
+
+ msg->entity_count = htonl(1);
+
+ entity = msg->entity;
+
+ entity->op = NPP_ACTION_CODE;
+ entity->length = htonl(data->length);
+ /* copy ndef information to response msg */
+ memcpy(entity->data, data->buffer, data->length);
+ }
+ else
+ {
+ msg->entity_count = 0;
+ }
+
+ return NET_NFC_OK;
+}
+
+static void npp_server_receive_cb(net_nfc_error_e result,
+ net_nfc_target_handle_s *handle,
+ net_nfc_llcp_socket_t socket,
+ data_s *data,
+ gpointer user_data)
+{
+ NppData *npp_data;
+
+ net_nfc_npp_msg_t *message;
+ net_nfc_npp_entity_t *entity;
+
+ data_s ndef_msg = { NULL, 0 };
+
+ uint32_t length;
+ uint32_t entity_count;
+ uint32_t i;
+
+ npp_data = (NppData *)user_data;
+
+ if (npp_data == NULL)
+ return;
+
+ if (result != NET_NFC_OK)
+ {
+ DEBUG_ERR_MSG("error [%d]", result);
+
+ if(npp_data->callback)
+ npp_data->callback(result, NULL, npp_data->user_data);
+
+ g_free(npp_data);
+ return;
+ }
+
+ if (data == NULL)
+ {
+ DEBUG_ERR_MSG("data is NULL");
+
+ if(npp_data->callback)
+ {
+ npp_data->callback(NET_NFC_INVALID_PARAM,
+ NULL,
+ npp_data->user_data);
+ }
+
+ g_free(npp_data);
+ return;
+ }
+
+ if (data->buffer == NULL || data->length == 0)
+ {
+ DEBUG_ERR_MSG("Wrong data");
+
+ if(npp_data->callback)
+ {
+ npp_data->callback(NET_NFC_INVALID_PARAM,
+ NULL,
+ npp_data->user_data);
+ }
+
+ g_free(npp_data);
+ return;
+ }
+
+ message = (net_nfc_npp_msg_t *)data->buffer;
+
+ if (data->length < NPP_HEADER_LEN)
+ {
+ DEBUG_ERR_MSG("too short data, length [%d]",
+ data->length);
+ /* FIXME!!! what should I do. */
+ if(npp_data->callback)
+ {
+ npp_data->callback(NET_NFC_INVALID_PARAM,
+ NULL,
+ npp_data->user_data);
+ }
+
+ g_free(npp_data);
+ return;
+ }
+
+ if (GET_MAJOR_VER(message->version) > NPP_MAJOR_VER ||
+ GET_MINOR_VER(message->version > NPP_MINOR_VER))
+ {
+ DEBUG_ERR_MSG("not supported version, version [0x%02x]",
+ message->version);
+
+ if(npp_data->callback)
+ {
+ npp_data->callback(NET_NFC_NOT_SUPPORTED,
+ NULL,
+ npp_data->user_data);
+ }
+
+ g_free(npp_data);
+ return;
+ }
+
+ entity_count = htonl(message->entity_count);
+
+ if (entity_count > NPP_NDEF_ENTRY)
+ {
+ DEBUG_ERR_MSG("too many entities, [%d]",
+ message->entity_count);
+
+ if(npp_data->callback)
+ {
+ npp_data->callback(NET_NFC_INVALID_PARAM,
+ NULL,
+ npp_data->user_data);
+ }
+
+ g_free(npp_data);
+ return;
+ }
+
+ for (i = 0; i < entity_count; i++)
+ {
+ entity = (message->entity + i);
+
+ if (entity->op != NPP_ACTION_CODE) {
+ DEBUG_ERR_MSG("not supported action code, [0x%02x]",
+ entity->op);
+
+ if(npp_data->callback)
+ {
+ npp_data->callback(NET_NFC_INVALID_PARAM,
+ NULL,
+ npp_data->user_data);
+ }
+
+ g_free(npp_data);
+ return;
+ }
+
+ length = htonl(entity->length);
+
+ DEBUG_SERVER_MSG("action code [0x%02x], length [%d]",
+ entity->op, length);
+
+ if (length > 0)
+ {
+ /* buffer create */
+ ndef_msg.buffer = g_new0(uint8_t, length);
+ ndef_msg.length = length;
+
+ memcpy(ndef_msg.buffer, entity->data, length);
+ }
+ }
+
+ if (npp_data->callback)
+ npp_data->callback(result, &ndef_msg, npp_data->user_data);
+
+ g_free(ndef_msg.buffer);
+ g_free(npp_data);
+}
+
+
+static void npp_server_process(NppData *npp_data)
+{
+ net_nfc_error_e result;
+ if (npp_data == NULL)
+ return;
+
+ /* receive request */
+ result = net_nfc_server_llcp_simple_receive(npp_data->handle,
+ npp_data->socket,
+ npp_server_receive_cb,
+ npp_data);
+ if (result != NET_NFC_OK)
+ {
+ if (npp_data->callback)
+ npp_data->callback(result, NULL, npp_data->user_data);
+
+ g_free(npp_data);
+ }
+}
+
+static void npp_listen_cb(net_nfc_error_e result,
+ net_nfc_target_handle_s *handle,
+ net_nfc_llcp_socket_t socket,
+ data_s *data,
+ gpointer user_data)
+{
+ NppData *npp_data;
+ NppData *accept_data;
+
+ npp_data = (NppData *)user_data;
+ if (npp_data == NULL)
+ return;
+
+ DEBUG_SERVER_MSG("npp_listen_cb, incoming socket [%#x], result [%d]",
+ socket, result);
+
+ if (result != NET_NFC_OK)
+ {
+ DEBUG_ERR_MSG("listen failed [%d]", result);
+
+ if (npp_data->callback)
+ npp_data->callback(result, NULL, npp_data->user_data);
+
+ g_free(npp_data);
+ return;
+ }
+
+ /* start npp server */
+ accept_data = g_new0(NppData, 1);
+
+ accept_data->handle = npp_data->handle;
+ accept_data->socket = socket;
+ accept_data->callback = npp_data->callback;
+ accept_data->user_data = npp_data->user_data;
+
+ result = net_nfc_server_llcp_simple_accept(handle,
+ socket,
+ npp_socket_error_cb,
+ accept_data);
+ if (result != NET_NFC_OK)
+ {
+ DEBUG_ERR_MSG("%s failed",
+ "net_nfc_server_llcp_simple_accept");
+
+ if (npp_data->callback)
+ npp_data->callback(result, NULL, npp_data->user_data);
+
+ g_free(npp_data);
+ g_free(accept_data);
+
+ return;
+ }
+
+ DEBUG_SERVER_MSG("socket [%x] accepted.. waiting for request message",
+ socket);
+
+ npp_server_process(accept_data);
+ g_free(npp_data);
+}
+
+/* client */
+static void npp_client_disconnected_cb(net_nfc_llcp_socket_t socket,
+ net_nfc_error_e result,
+ data_s *data,
+ void *extra,
+ void *user_param)
+{
+ DEBUG_SERVER_MSG("disconnected! [%d]", result);
+}
+
+static void npp_client_send_cb(net_nfc_error_e result,
+ net_nfc_target_handle_s *handle,
+ net_nfc_llcp_socket_t socket,
+ data_s *data,
+ gpointer user_data)
+{
+ NppData *npp_data;
+
+ npp_data = (NppData *)user_data;
+ if (npp_data == NULL)
+ return;
+
+ DEBUG_SERVER_MSG("send complete... [%d]", result);
+
+ if (npp_data->callback)
+ {
+ npp_data->callback(result, NULL, npp_data->user_data);
+ }
+
+ net_nfc_controller_llcp_disconnect(npp_data->handle,
+ npp_data->socket,
+ &result,
+ npp_client_disconnected_cb,
+ NULL);
+
+ g_free(npp_data->data.buffer);
+ g_free(npp_data);
+
+}
+
+static void npp_client_process(NppData *npp_data)
+{
+ net_nfc_error_e result;
+ data_s data;
+
+ if (npp_data == NULL)
+ return;
+
+ result = npp_create_message(&npp_data->data, &data);
+ if (result != NET_NFC_OK)
+ {
+ DEBUG_ERR_MSG("%s failed [%d]", "npp_create_message", result);
+
+ if (npp_data->callback)
+ npp_data->callback(result, NULL, npp_data->user_data);
+
+ g_free(npp_data->data.buffer);
+ g_free(npp_data);
+
+ return;
+ }
+
+ /* send request */
+ result = net_nfc_server_llcp_simple_send(npp_data->handle,
+ npp_data->socket,
+ &data,
+ npp_client_send_cb,
+ npp_data);
+ if (result != NET_NFC_OK)
+ {
+ DEBUG_ERR_MSG("%s failed [%d]",
+ "net_nfc_server_llcp_simple_send",
+ result);
+
+ if (npp_data->callback)
+ npp_data->callback(result, NULL, npp_data->user_data);
+
+ g_free(npp_data->data.buffer);
+ g_free(npp_data);
+
+ }
+
+ g_free(data.buffer);
+}
+
+static void npp_connected_cb(net_nfc_error_e result,
+ net_nfc_target_handle_s *handle,
+ net_nfc_llcp_socket_t socket,
+ data_s *data,
+ gpointer user_data)
+{
+ NppData *npp_data;
+
+ npp_data = (NppData *)user_data;
+ if (npp_data == NULL)
+ return;
+
+ if (result != NET_NFC_OK)
+ {
+ DEBUG_ERR_MSG("connect socket failed, [%d]", result);
+
+ if (npp_data->callback)
+ npp_data->callback(result, NULL, npp_data->user_data);
+
+ g_free(npp_data->data.buffer);
+ g_free(npp_data);
+
+ return;
+ }
+
+ /*start npp client */
+ DEBUG_SERVER_MSG("socket [%x] connected, send request message.",
+ socket);
+ npp_data->socket = socket;
+
+ npp_client_process(npp_data);
+ return;
+}
+
+static void npp_socket_error_cb(net_nfc_error_e result,
+ net_nfc_target_handle_s *handle,
+ net_nfc_llcp_socket_t socket,
+ data_s *data,
+ gpointer user_data)
+{
+ NppData *npp_data;
+
+ DEBUG_SERVER_MSG("socket [%x], result [%d]", socket, result);
+
+ npp_data = (NppData *)user_data;
+ if (npp_data == NULL)
+ return;
+
+ if (npp_data->callback)
+ npp_data->callback(result, NULL, npp_data->user_data);
+
+ g_free(npp_data->data.buffer);
+ g_free(npp_data);
+}
+
+static void npp_default_server_cb(net_nfc_error_e result,
+ data_s *data,
+ gpointer user_data)
+{
+ DEBUG_SERVER_MSG("result [%d], data [%p], user_data [%p]",
+ result, data, user_data);
+
+ if (data == NULL)
+ {
+ DEBUG_ERR_MSG("npp server receive failed, [%d]", result);
+ return;
+ }
+
+ if (data->buffer == NULL)
+ {
+ DEBUG_ERR_MSG("npp server receive failed, [%d]", result);
+ return;
+ }
+
+ net_nfc_server_p2p_received(data);
+ net_nfc_app_util_process_ndef(data);
+}
+
+static void npp_default_client_cb(net_nfc_error_e result,
+ data_s *data,
+ gpointer user_data)
+{
+ NppClientStartData *npp_client_data;
+
+ DEBUG_SERVER_MSG("result [%d], data [%p], user_data [%p]",
+ result, data, user_data);
+
+ if (user_data == NULL)
+ return;
+
+ npp_client_data = (NppClientStartData *)user_data;
+
+ net_nfc_server_p2p_data_sent(result, npp_client_data->user_data);
+
+ g_free(npp_client_data);
+}
+
+/* public apis */
+net_nfc_error_e net_nfc_server_npp_server(net_nfc_target_handle_s *handle,
+ char *san,
+ sap_t sap,
+ net_nfc_server_npp_callback callback,
+ gpointer user_data)
+{
+ net_nfc_error_e result = NET_NFC_OK;
+
+ NppData *npp_data = NULL;
+
+ if (handle == NULL)
+ {
+ DEBUG_ERR_MSG("handle is NULL");
+ return FALSE;
+ }
+
+ if (san == NULL)
+ {
+ DEBUG_ERR_MSG("san is NULL");
+ return FALSE;
+ }
+
+ npp_data = g_new0(NppData, 1);
+
+ npp_data->handle = handle;
+ npp_data->callback = callback;
+ npp_data->user_data = user_data;
+
+ result = net_nfc_server_llcp_simple_server(handle,
+ san,
+ sap,
+ npp_listen_cb,
+ npp_socket_error_cb,
+ npp_data);
+ if (result != NET_NFC_OK)
+ {
+ DEBUG_ERR_MSG("%s failed",
+ "net_nfc_server_llcp_simple_server");
+
+ if (npp_data->callback)
+ npp_data->callback(result, NULL, npp_data->user_data);
+
+ g_free(npp_data);
+
+ return FALSE;
+ }
+
+ DEBUG_SERVER_MSG("start npp server, san [%s], sap [%d]", san, sap);
+
+ return result;
+}
+
+net_nfc_error_e net_nfc_server_npp_client(net_nfc_target_handle_s *handle,
+ char *san,
+ sap_t sap,
+ data_s *data,
+ net_nfc_server_npp_callback callback,
+ gpointer user_data)
+{
+ net_nfc_error_e result = NET_NFC_OK;;
+ net_nfc_llcp_config_info_s config;
+
+ NppData *npp_data;
+
+ if (handle == NULL)
+ {
+ DEBUG_ERR_MSG("handle is NULL");
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ if(net_nfc_controller_llcp_get_remote_config(handle,
+ &config,
+ &result) == false)
+ {
+ DEBUG_ERR_MSG("%s failed [%d]",
+ "net_nfc_controller_llcp_get_remote_config",
+ result);
+
+ return result;
+ }
+
+ if (config.miu <
+ data->length + NPP_HEADER_LEN + NPP_ENTITY_HEADER_LEN)
+ {
+ DEBUG_ERR_MSG("too large message, max [%d], request [%d]",
+ config.miu - (NPP_HEADER_LEN + NPP_ENTITY_HEADER_LEN),
+ data->length);
+
+ return NET_NFC_INSUFFICIENT_STORAGE;
+ }
+
+ npp_data = g_new0(NppData, 1);
+
+ npp_data->handle = handle;
+ npp_data->callback = callback;
+ npp_data->user_data = user_data;
+
+ npp_data->data.buffer = g_new0(uint8_t, data->length);
+ npp_data->data.length = data->length;
+
+ result = net_nfc_server_llcp_simple_client(handle,
+ san,
+ sap,
+ npp_connected_cb,
+ npp_socket_error_cb,
+ npp_data);
+ if (result != NET_NFC_OK)
+ {
+ DEBUG_ERR_MSG("%s failed",
+ "net_nfc_server_llcp_simple_client");
+
+ if (npp_data->callback)
+ {
+ npp_data->callback(NET_NFC_UNKNOWN_ERROR,
+ NULL,
+ npp_data->user_data);
+ }
+
+ g_free(npp_data->data.buffer);
+ g_free(npp_data);
+
+ return result;
+ }
+
+ if (san != NULL)
+ {
+ DEBUG_SERVER_MSG("start npp client, san [%s], result [%d]",
+ san, result);
+ }
+ else
+ {
+ DEBUG_SERVER_MSG("start npp client, sap [%d], result [%d]",
+ sap, result);
+ }
+
+ return result;
+}
+
+net_nfc_error_e net_nfc_server_npp_default_server_start(
+ net_nfc_target_handle_s *handle)
+{
+ /* start default npp server */
+ return net_nfc_server_npp_server(handle,
+ NPP_SAN,
+ NPP_SAP,
+ npp_default_server_cb,
+ (gpointer)1234);
+}
+
+static void _npp_default_activate_cb(int event,
+ net_nfc_target_handle_s *handle,
+ uint32_t sap, const char *san, void *user_param)
+{
+ net_nfc_error_e result;
+
+ DEBUG_SERVER_MSG("event [%d], handle [%p], sap [%d], san [%s]",
+ event, handle, sap, san);
+
+ if (event == NET_NFC_LLCP_START) {
+ /* start default npp server */
+ result = net_nfc_server_npp_server(handle, (char *)san, sap,
+ npp_default_server_cb, user_param);
+ if (result != NET_NFC_OK) {
+ DEBUG_ERR_MSG("net_nfc_server_npp_server failed, [%d]",
+ result);
+ }
+ } else if (event == NET_NFC_LLCP_UNREGISTERED) {
+ /* unregister server, do nothing */
+ }
+}
+
+net_nfc_error_e net_nfc_server_npp_default_server_register()
+{
+ char id[20];
+
+ /* TODO : make id, */
+ snprintf(id, sizeof(id), "%d", getpid());
+
+ /* start default npp server */
+ return net_nfc_server_llcp_register_service(id,
+ NPP_SAP,
+ NPP_SAN,
+ _npp_default_activate_cb,
+ NULL);
+}
+
+net_nfc_error_e net_nfc_server_npp_default_server_unregister()
+{
+ char id[20];
+
+ /* TODO : make id, */
+ snprintf(id, sizeof(id), "%d", getpid());
+
+ /* start default npp server */
+ return net_nfc_server_llcp_unregister_service(id,
+ NPP_SAP,
+ NPP_SAN);
+}
+
+net_nfc_error_e net_nfc_server_npp_default_client_start(
+ net_nfc_target_handle_s *handle,
+ data_s *data,
+ int client,
+ gpointer user_data)
+{
+ NppClientStartData *npp_client_data;
+
+ net_nfc_error_e result = NET_NFC_OK;
+
+ if (handle == NULL)
+ {
+ DEBUG_ERR_MSG("handle is NULL");
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ if (data == NULL)
+ {
+ DEBUG_ERR_MSG("data is NULL");
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ if (data->buffer == NULL)
+ {
+ DEBUG_ERR_MSG("data->buffer is NULL");
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ npp_client_data = g_new0(NppClientStartData, 1);
+
+ npp_client_data->handle = handle;
+ npp_client_data->client = client;
+ npp_client_data->user_data = user_data;
+
+ result = net_nfc_server_npp_client(handle,
+ NPP_SAN,
+ NPP_SAP,
+ data,
+ npp_default_client_cb,
+ npp_client_data);
+
+ if (result != NET_NFC_OK)
+ {
+ DEBUG_ERR_MSG("net_nfc_server_client failed");
+ g_free(npp_client_data);
+ }
+
+ return result;
+}
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_SERVER_PROCESS_NPP_H__
+#define __NET_NFC_SERVER_PROCESS_NPP_H__
+
+#include <glib.h>
+
+#include "net_nfc_typedef.h"
+#include "net_nfc_typedef_internal.h"
+
+typedef void (*net_nfc_server_npp_callback) (net_nfc_error_e result,
+ data_s *data,
+ gpointer user_data);
+
+net_nfc_error_e net_nfc_server_npp_server(net_nfc_target_handle_s *handle,
+ char *san,
+ sap_t sap,
+ net_nfc_server_npp_callback callback,
+ gpointer user_data);
+
+net_nfc_error_e net_nfc_server_npp_client(net_nfc_target_handle_s *handle,
+ char *san,
+ sap_t sap,
+ data_s *data,
+ net_nfc_server_npp_callback callback,
+ gpointer user_data);
+
+net_nfc_error_e net_nfc_server_npp_default_server_start(
+ net_nfc_target_handle_s *handle);
+
+net_nfc_error_e net_nfc_server_npp_default_client_start(
+ net_nfc_target_handle_s *handle,
+ data_s *data,
+ int client,
+ gpointer user_data);
+
+net_nfc_error_e net_nfc_server_npp_default_server_register();
+
+net_nfc_error_e net_nfc_server_npp_default_server_unregister();
+
+#endif //__NET_NFC_SERVER_PROCESS_NPP_H__
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <glib.h>
+#include "net_nfc_debug_internal.h"
+#include "net_nfc_util_defines.h"
+#include "net_nfc_util_internal.h"
+#include "net_nfc_util_gdbus_internal.h"
+#include "net_nfc_server_llcp.h"
+#include "net_nfc_server_p2p.h"
+#include "net_nfc_server_controller.h"
+#include "net_nfc_server_snep.h"
+#include "net_nfc_server_util.h"
+#include "net_nfc_server_process_snep.h"
+
+
+typedef struct _net_nfc_server_snep_msg_t
+{
+ uint8_t version;
+ uint8_t op;
+ uint32_t length;
+ uint8_t data[0];
+}
+__attribute__ ((packed)) net_nfc_server_snep_msg_t;
+
+typedef struct _net_nfc_server_snep_get_msg_t
+{
+ uint32_t length;
+ uint8_t data[0];
+}
+__attribute__ ((packed)) net_nfc_server_snep_get_msg_t;
+
+typedef struct _net_nfc_server_cb_data_t
+{
+ net_nfc_server_snep_listen_cb cb;
+ void *user_param;
+}
+net_nfc_server_cb_data_t;
+
+typedef struct _net_nfc_server_snep_context_t
+{
+ net_nfc_target_handle_s *handle;
+ net_nfc_error_e result;
+ net_nfc_llcp_socket_t socket;
+ uint32_t state;
+ uint32_t type;
+ data_s data;
+ net_nfc_server_snep_cb cb;
+ void *user_param;
+ GQueue queue;
+}
+net_nfc_server_snep_context_t;
+
+typedef struct _net_nfc_server_snep_job_t
+{
+ net_nfc_server_snep_context_t *context;
+ net_nfc_target_handle_s *handle;
+ net_nfc_error_e result;
+ net_nfc_llcp_socket_t socket;
+ uint32_t state;
+ uint32_t type;
+ data_s data;
+ net_nfc_server_snep_cb cb;
+ void *user_param;
+}
+net_nfc_server_snep_job_t;
+
+
+typedef struct __net_nfc_server_snep_server_context_t
+{
+ net_nfc_target_handle_s *handle;
+ int client;
+ void *user_param;
+}
+_net_nfc_server_snep_server_context_t;
+
+typedef struct __net_nfc_server_snep_service_context_t
+{
+ net_nfc_target_handle_s *handle;
+ int client;
+ uint32_t type;
+ data_s data;
+ void *user_param;
+}
+_net_nfc_server_snep_service_context_t;
+
+typedef void (*_net_nfc_server_snep_operation_cb)(
+ net_nfc_error_e result,
+ uint32_t type,
+ data_s *data,
+ void *user_param);
+
+typedef struct _net_nfc_server_snep_op_context_t
+{
+ net_nfc_target_handle_s *handle;
+ net_nfc_error_e result;
+ int socket;
+ uint32_t state;
+ uint32_t type;
+ uint32_t current;
+ uint16_t miu;
+ data_s data;
+ uint32_t offset;
+ _net_nfc_server_snep_operation_cb cb;
+ void *user_param;
+}
+
+net_nfc_server_snep_op_context_t;
+
+#define SNEP_MAJOR_VER 1
+#define SNEP_MINOR_VER 0
+#define SNEP_VERSION ((SNEP_MAJOR_VER << 4) | SNEP_MINOR_VER)
+
+#define SNEP_HEADER_LEN (sizeof(net_nfc_server_snep_msg_t))
+#define SNEP_MAX_LEN (SNEP_HEADER_LEN + 1024 * 10)
+
+#define SNEP_REQUEST (0)
+#define SNEP_RESPONSE (0x80)
+
+#define SNEP_PAIR_OP(__x) ((__x) ^ SNEP_RESPONSE)
+#define SNEP_MAKE_PAIR_OP(__x, __y) ((SNEP_PAIR_OP(__x) & SNEP_RESPONSE) | (__y))
+
+#define IS_SNEP_REQ(__x) (((__x) & SNEP_RESPONSE) == SNEP_REQUEST)
+#define IS_SNEP_RES(__x) (((__x) & SNEP_RESPONSE) == SNEP_RESPONSE)
+
+static GList *list_listen_cb = NULL;
+
+static void _net_nfc_server_snep_recv(
+ net_nfc_server_snep_op_context_t *context);
+
+static void _net_nfc_server_snep_send(
+ net_nfc_server_snep_op_context_t *context);
+
+static net_nfc_error_e net_nfc_server_snep_recv(
+ net_nfc_target_handle_s *handle,
+ net_nfc_llcp_socket_t socket,
+ _net_nfc_server_snep_operation_cb cb,
+ void *user_param);
+
+static net_nfc_error_e net_nfc_server_snep_send(
+ net_nfc_target_handle_s *handle,
+ net_nfc_llcp_socket_t socket,
+ uint32_t type,
+ data_s *data,
+ _net_nfc_server_snep_operation_cb cb,
+ void *user_param);
+
+
+static void _net_nfc_server_snep_client_process(
+ net_nfc_server_snep_job_t *job);
+
+static void _net_nfc_server_snep_server_process(
+ net_nfc_server_snep_context_t *context);
+
+/**********************************************************************/
+static bool _net_nfc_server_snep_add_get_response_cb(
+ net_nfc_server_snep_listen_cb cb,
+ void *user_param)
+{
+ net_nfc_server_cb_data_t *data = NULL;
+ bool result = false;
+
+ _net_nfc_util_alloc_mem(data, sizeof(*data));
+ if (data != NULL)
+ {
+ data->cb = cb;
+ data->user_param = user_param;
+
+ list_listen_cb = g_list_append(list_listen_cb, data);
+ if (list_listen_cb != NULL)
+ {
+ result = true;
+ }
+ else
+ {
+ DEBUG_ERR_MSG("g_list_append failed");
+ }
+ }
+ else
+ {
+ DEBUG_ERR_MSG("_net_nfc_util_alloc_mem failed");
+ }
+
+ return result;
+}
+
+static gint _net_nfc_server_snep_compare_func_cb(
+ gconstpointer a,
+ gconstpointer b)
+{
+ net_nfc_server_cb_data_t *data = (net_nfc_server_cb_data_t *)a;
+
+ if (data->cb == (void *)b)
+ return 0;
+ else
+ return 1;
+}
+
+static void _net_nfc_server_snep_del_get_response_cb(
+ net_nfc_server_snep_listen_cb cb)
+{
+ GList *list;
+
+ list = g_list_find_custom(list_listen_cb,
+ cb,
+ _net_nfc_server_snep_compare_func_cb);
+
+ if (list != NULL)
+ list_listen_cb = g_list_delete_link(list_listen_cb, list);
+}
+
+static bool _net_nfc_server_snep_process_get_response_cb(
+ net_nfc_target_handle_s *handle,
+ data_s *data,
+ uint32_t max_len)
+{
+ GList *list = list_listen_cb;
+
+ while (list != NULL && list->data != NULL)
+ {
+ net_nfc_server_cb_data_t *cb_data =
+ (net_nfc_server_cb_data_t *)list->data;
+
+ if (cb_data->cb != NULL)
+ {
+ DEBUG_SERVER_MSG("invoke callback [%p]", cb_data->cb);
+ if (cb_data->cb(handle,
+ SNEP_REQ_GET,
+ max_len,
+ data,
+ cb_data->user_param) == true)
+ return true;
+ }
+ }
+
+ return false;
+}
+
+ static net_nfc_server_snep_op_context_t *
+_net_nfc_server_snep_create_send_context(uint32_t type,
+ net_nfc_target_handle_s *handle,
+ net_nfc_llcp_socket_t socket,
+ data_s *data,
+ void *cb,
+ void *user_param)
+{
+ net_nfc_server_snep_op_context_t *context = NULL;
+ uint32_t data_len = 0;
+ net_nfc_server_snep_msg_t *msg;
+ net_nfc_llcp_config_info_s config;
+ net_nfc_error_e result;
+
+ if (net_nfc_controller_llcp_get_remote_config(handle,
+ &config, &result) == false)
+ {
+ DEBUG_ERR_MSG("net_nfc_controller_llcp_get_remote_config failed, [%d]",
+ result);
+
+ return NULL;
+ }
+
+ _net_nfc_util_alloc_mem(context, sizeof(*context));
+ if (context == NULL)
+ {
+ return NULL;
+ }
+
+ if (type == SNEP_REQ_GET)
+ {
+ data_len = sizeof(net_nfc_server_snep_msg_t);
+ }
+
+ if (data != NULL)
+ {
+ data_len += data->length;
+ }
+
+ net_nfc_util_alloc_data(&context->data, SNEP_HEADER_LEN + data_len);
+ if (context->data.buffer == NULL)
+ {
+ _net_nfc_util_free_mem(context);
+ return NULL;
+ }
+
+ msg = (net_nfc_server_snep_msg_t *)context->data.buffer;
+
+ msg->version = SNEP_VERSION;
+ msg->op = type;
+
+ if (data_len > 0)
+ {
+ uint8_t *buffer;
+
+ msg->length = htonl(data_len);
+
+ if (type == SNEP_REQ_GET)
+ {
+ net_nfc_server_snep_msg_t *get_msg =
+ (net_nfc_server_snep_msg_t *)msg->data;
+
+ get_msg->length = htonl(SNEP_MAX_LEN);
+ buffer = get_msg->data;
+ }
+ else
+ {
+ buffer = msg->data;
+ }
+
+ if (data != NULL && data->buffer != NULL)
+ {
+ DEBUG_SERVER_MSG("data->length [%d]", data->length);
+
+ /* copy ndef information to response msg */
+ memcpy(buffer, data->buffer, data->length);
+ }
+ }
+
+ context->handle = handle;
+ context->type = type;
+ context->state = NET_NFC_LLCP_STEP_01;
+ context->socket = socket;
+ context->cb = cb;
+ context->user_param = user_param;
+ context->miu = MIN(config.miu, net_nfc_server_llcp_get_miu());
+
+ return context;
+}
+
+ static net_nfc_server_snep_op_context_t *
+_net_nfc_server_snep_create_recv_context(
+ net_nfc_target_handle_s *handle,
+ net_nfc_llcp_socket_t socket,
+ void *cb,
+ void *user_param)
+{
+ net_nfc_server_snep_op_context_t *context = NULL;
+ net_nfc_llcp_config_info_s config;
+ net_nfc_error_e result;
+
+ if (net_nfc_controller_llcp_get_remote_config(handle,
+ &config,
+ &result) == false)
+ {
+ DEBUG_ERR_MSG("net_nfc_controller_llcp_get_remote_config failed, [%d]",
+ result);
+ return NULL;
+ }
+
+ _net_nfc_util_alloc_mem(context, sizeof(*context));
+
+ if (context == NULL)
+ return NULL;
+
+ context->handle = handle;
+ context->state = NET_NFC_LLCP_STEP_01;
+ context->socket = socket;
+ context->cb = cb;
+ context->user_param = user_param;
+ context->miu = MIN(config.miu, net_nfc_server_llcp_get_miu());
+
+ return context;
+}
+
+static void _net_nfc_server_snep_destory_context(
+ net_nfc_server_snep_op_context_t *context)
+{
+ if (context != NULL)
+ {
+ if (context->data.buffer != NULL)
+ net_nfc_util_free_data(&context->data);
+
+ _net_nfc_util_free_mem(context);
+ }
+}
+
+static void _net_nfc_server_recv_fragment_cb(
+ net_nfc_llcp_socket_t socket,
+ net_nfc_error_e result,
+ data_s *data,
+ void *extra,
+ void *user_param)
+{
+ net_nfc_server_snep_op_context_t *context =
+ (net_nfc_server_snep_op_context_t *)user_param;
+ uint8_t *buffer;
+ uint32_t length;
+
+ DEBUG_SERVER_MSG("_net_nfc_server_recv_fragment_cb,"
+ " socket [%x], result [%d]",socket, result);
+
+ if (context == NULL)
+ return;
+
+ context->result = result;
+
+ if (result != NET_NFC_OK)
+ {
+ DEBUG_ERR_MSG("error [%d]", result);
+ context->state = NET_NFC_STATE_ERROR;
+ goto END;
+ }
+
+ if (data == NULL || data->buffer == NULL || data->length == 0)
+ {
+ DEBUG_ERR_MSG("invalid response");
+ context->state = NET_NFC_STATE_ERROR;
+ goto END;
+ }
+
+ if (context->state == NET_NFC_LLCP_STEP_01)
+ {
+ net_nfc_server_snep_msg_t *msg =
+ (net_nfc_server_snep_msg_t *)data->buffer;
+
+ if (data->length < SNEP_HEADER_LEN)
+ {
+ DEBUG_ERR_MSG("too short data, length [%d]",
+ data->length);
+ /* FIXME!!! what should I do. */
+ context->type = SNEP_RESP_BAD_REQ;
+ context->state = NET_NFC_STATE_ERROR;
+ context->result = NET_NFC_BUFFER_TOO_SMALL;
+ goto END;
+ }
+
+ length = htonl(msg->length);
+
+ if (length > SNEP_MAX_LEN)
+ {
+ DEBUG_ERR_MSG("too long snep message, length [%d]",
+ length);
+ if (IS_SNEP_REQ(msg->op))
+ {
+ context->type = SNEP_RESP_EXCESS_DATA;
+ }
+ else
+ {
+ context->type = SNEP_REQ_REJECT;
+ }
+ context->state = NET_NFC_LLCP_STEP_04;
+ context->result = NET_NFC_INSUFFICIENT_STORAGE;
+ goto END;
+ }
+
+ if (IS_SNEP_REQ(msg->op) &&
+ GET_MAJOR_VER(msg->version) > SNEP_MAJOR_VER)
+ {
+ DEBUG_ERR_MSG("not supported version, version [0x%02x]",
+ msg->version);
+ context->type = SNEP_RESP_UNSUPPORTED_VER;
+ context->state = NET_NFC_LLCP_STEP_04;
+ context->result = NET_NFC_NOT_SUPPORTED;
+ goto END;
+ }
+
+ if (length > 0)
+ {
+ /* buffer create */
+ net_nfc_util_alloc_data(&context->data, length);
+ if (context->data.buffer == NULL)
+ {
+ DEBUG_ERR_MSG("net_nfc_util_alloc_data failed");
+ if (IS_SNEP_REQ(msg->op))
+ {
+ context->type = SNEP_RESP_REJECT;
+ }
+ else
+ {
+ context->type = SNEP_REQ_REJECT;
+ }
+ context->state = NET_NFC_LLCP_STEP_04;
+ context->result = NET_NFC_ALLOC_FAIL;
+ goto END;
+ }
+ }
+
+ DEBUG_SERVER_MSG("incoming message, type [0x%02x], length [%d]",
+ msg->op, length);
+
+ context->type = msg->op;
+ buffer = msg->data;
+ length = data->length - SNEP_HEADER_LEN;
+ context->state = NET_NFC_LLCP_STEP_02;
+ }
+ else
+ {
+ buffer = data->buffer;
+ length = data->length;
+ context->state = NET_NFC_LLCP_STEP_03;
+ }
+
+ if (context->data.length > 0)
+ {
+ /* copy data */
+ memcpy(context->data.buffer + context->offset,
+ buffer, length);
+ context->offset += length;
+
+ DEBUG_SERVER_MSG("receive progress... [%d|%d]",
+ context->offset, context->data.length);
+
+ if (context->offset >= context->data.length)
+ context->state = NET_NFC_LLCP_STEP_RETURN;
+
+ }
+ else
+ {
+ DEBUG_SERVER_MSG("receive complete... [no ndef message]");
+ context->state = NET_NFC_LLCP_STEP_RETURN;
+ }
+
+END :
+ _net_nfc_server_snep_recv(context);
+}
+
+
+static void _net_nfc_server_recv_fragment(
+ net_nfc_server_snep_op_context_t *context)
+{
+ net_nfc_error_e result;
+
+ DEBUG_SERVER_MSG("socket [%x] waiting data.....", context->socket);
+
+ if (net_nfc_controller_llcp_recv(
+ context->handle,
+ context->socket,
+ context->miu,
+ &result,
+ _net_nfc_server_recv_fragment_cb,
+ context) == false)
+ {
+ DEBUG_ERR_MSG("net_nfc_controller_llcp_recv failed, [%d]", result);
+ context->state = NET_NFC_STATE_ERROR;
+ context->result = result;
+ _net_nfc_server_snep_recv(context);
+ }
+}
+
+
+void _net_nfc_server_snep_recv_send_cb(
+ net_nfc_error_e result,
+ uint32_t type,
+ data_s *data,
+ void *user_param)
+{
+ net_nfc_server_snep_op_context_t *context =
+ (net_nfc_server_snep_op_context_t *)user_param;
+
+ DEBUG_SERVER_MSG("_net_nfc_server_snep_recv_send_cb, result [%d]", result);
+
+ if (context == NULL)/* TODO */
+ return;
+
+ if (result == NET_NFC_OK)
+ context->state = NET_NFC_LLCP_STEP_03;
+ else
+ {
+ DEBUG_ERR_MSG("net_nfc_server_snep_send failed, [0x%x][%d]",
+ type, result);
+ context->state = NET_NFC_STATE_ERROR;
+ context->result = result;
+ }
+
+ _net_nfc_server_snep_recv(context);
+}
+
+void _net_nfc_server_snep_recv_send_reject_cb(
+ net_nfc_error_e result,
+ uint32_t type,
+ data_s *data,
+ void *user_param)
+{
+ net_nfc_server_snep_op_context_t *context =
+ (net_nfc_server_snep_op_context_t *)user_param;
+
+ DEBUG_SERVER_MSG("_net_nfc_server_snep_recv_send_reject_cb,"
+ " result [%d]", result);
+
+ if (context == NULL)/* TODO */
+ return;
+
+ context->state = NET_NFC_LLCP_STEP_RETURN;
+
+ if (result != NET_NFC_OK)
+ {
+ DEBUG_ERR_MSG("net_nfc_server_snep_send failed, [0x%x][%d]",
+ type, result);
+ }
+
+ _net_nfc_server_snep_recv(context);
+}
+
+static void _net_nfc_server_snep_recv(
+ net_nfc_server_snep_op_context_t *context)
+{
+ if (context == NULL)
+ return;
+
+ switch (context->state)
+ {
+ case NET_NFC_LLCP_STEP_01 :
+ case NET_NFC_LLCP_STEP_03 :
+ DEBUG_SERVER_MSG("NET_NFC_LLCP_STEP_%02d",
+ context->state - NET_NFC_LLCP_STEP_01 + 1);
+
+ /* receive fragment */
+ _net_nfc_server_recv_fragment(context);
+ break;
+
+ case NET_NFC_LLCP_STEP_02 :
+ {
+ uint8_t op = context->type;
+
+ DEBUG_SERVER_MSG("NET_NFC_LLCP_STEP_02");
+
+ /* make correct request/response code */
+ op = SNEP_MAKE_PAIR_OP(op, SNEP_REQ_CONTINUE);
+
+ /* send response */
+ net_nfc_server_snep_send(
+ context->handle,
+ context->socket,
+ op,
+ NULL,
+ _net_nfc_server_snep_recv_send_cb, context);
+ }
+ break;
+
+ case NET_NFC_LLCP_STEP_04 :
+ {
+ DEBUG_SERVER_MSG("NET_NFC_LLCP_STEP_04");
+
+ /* send response */
+ net_nfc_server_snep_send(
+ context->handle,
+ context->socket,
+ context->type, NULL,
+ _net_nfc_server_snep_recv_send_reject_cb, context);
+ }
+ break;
+
+ case NET_NFC_LLCP_STEP_RETURN :
+ {
+ DEBUG_SERVER_MSG("NET_NFC_LLCP_STEP_RETURN");
+
+ /* complete and invoke callback */
+ context->cb(
+ context->result,
+ context->type,
+ &context->data,
+ context->user_param);
+
+ _net_nfc_server_snep_destory_context(context);
+ }
+ break;
+
+ case NET_NFC_STATE_ERROR :
+ default :
+ DEBUG_ERR_MSG("NET_NFC_STATE_ERROR");
+
+ /* error, invoke callback */
+ DEBUG_ERR_MSG("net_nfc_server_snep_recv failed, [%d]",
+ context->result);
+
+ context->cb(
+ context->result,
+ context->type,
+ NULL,
+ context->user_param);
+
+ _net_nfc_server_snep_destory_context(context);
+
+ break;
+ }
+}
+
+ static net_nfc_error_e
+net_nfc_server_snep_recv(
+ net_nfc_target_handle_s *handle,
+ net_nfc_llcp_socket_t socket,
+ _net_nfc_server_snep_operation_cb cb,
+ void *user_param)
+{
+ net_nfc_server_snep_op_context_t *context;
+ net_nfc_error_e result = NET_NFC_OK;
+
+ /* create context */
+ context = _net_nfc_server_snep_create_recv_context(
+ handle,
+ socket,
+ cb,
+ user_param);
+
+ if (context != NULL)/* send response */
+ _net_nfc_server_snep_recv(context);
+ else
+ result = NET_NFC_ALLOC_FAIL;
+
+ return result;
+}
+
+static void _net_nfc_server_send_fragment_cb(
+ net_nfc_llcp_socket_t socket,
+ net_nfc_error_e result,
+ data_s *data,
+ void *extra,
+ void *user_param)
+{
+ net_nfc_server_snep_op_context_t *context =
+ (net_nfc_server_snep_op_context_t *)user_param;
+
+ DEBUG_SERVER_MSG("_net_nfc_server_send_fragment_cb,"
+ " socket [%x], result [%d]",socket, result);
+
+ if (context == NULL)
+ return;
+
+ context->result = result;
+
+ if (result == NET_NFC_OK)
+ {
+ DEBUG_SERVER_MSG("send progress... [%d|%d]",
+ context->offset, context->data.length);
+ if (context->offset < context->data.length)
+ {
+ if (context->state == NET_NFC_LLCP_STEP_01)
+ {
+ /* first fragment */
+ context->state = NET_NFC_LLCP_STEP_02;
+ }
+ else
+ {
+ context->state = NET_NFC_LLCP_STEP_03;
+ }
+ }
+ else
+ {
+ context->state = NET_NFC_LLCP_STEP_RETURN;
+ }
+ }
+ else
+ {
+ DEBUG_ERR_MSG("net_nfc_controller_llcp_send failed, [%d]",
+ result);
+ context->state = NET_NFC_STATE_ERROR;
+ }
+ _net_nfc_server_snep_send(context);
+}
+
+static void _net_nfc_server_send_fragment(
+ net_nfc_server_snep_op_context_t *context)
+{
+ data_s req_msg;
+ uint32_t remain_len;
+ net_nfc_error_e result;
+
+ if (context == NULL)
+ return;
+
+ /* calc remain buffer length */
+ remain_len = context->data.length - context->offset;
+
+ req_msg.length = (remain_len < context->miu) ? remain_len : context->miu;
+ req_msg.buffer = context->data.buffer + context->offset;
+
+ DEBUG_SERVER_MSG("try to send data, socket [%x], offset [%d],"
+ " current [%d], remain [%d]",context->socket, context->offset,
+ req_msg.length, remain_len - req_msg.length);
+
+ context->offset += req_msg.length;
+
+ if (net_nfc_controller_llcp_send(context->handle,
+ context->socket,
+ &req_msg,
+ &result,
+ _net_nfc_server_send_fragment_cb,
+ context) == false)
+ {
+ DEBUG_ERR_MSG("net_nfc_controller_llcp_send failed, [%d]",
+ result);
+ context->state = NET_NFC_STATE_ERROR;
+ context->result = result;
+ _net_nfc_server_snep_send(context);
+ }
+}
+
+void _net_nfc_server_snep_send_recv_cb(
+ net_nfc_error_e result,
+ uint32_t type,
+ data_s *data,
+ void *user_param)
+{
+ net_nfc_server_snep_op_context_t *context =
+ (net_nfc_server_snep_op_context_t *)user_param;
+
+ DEBUG_SERVER_MSG("_net_nfc_server_snep_send_recv_cb,"
+ " result [%d]", result);
+
+ if (context == NULL)/* TODO */
+ return;
+
+ DEBUG_SERVER_MSG("received message, type [%d]", type);
+
+ context->result = result;
+ context->type = type;
+
+ switch (type)
+ {
+ case SNEP_REQ_CONTINUE :
+ case SNEP_RESP_CONT :
+ context->state = NET_NFC_LLCP_STEP_03;
+ break;
+
+ case SNEP_REQ_REJECT :
+ case SNEP_RESP_REJECT :
+ context->state = NET_NFC_STATE_ERROR;
+ context->result = NET_NFC_LLCP_SOCKET_FRAME_REJECTED;
+ break;
+
+ case SNEP_RESP_NOT_FOUND :
+ context->state = NET_NFC_STATE_ERROR;
+ context->result = NET_NFC_NO_DATA_FOUND;
+ break;
+
+ case SNEP_RESP_EXCESS_DATA :
+ context->state = NET_NFC_STATE_ERROR;
+ context->result = NET_NFC_INSUFFICIENT_STORAGE;
+ break;
+
+ case SNEP_RESP_BAD_REQ :
+ context->state = NET_NFC_STATE_ERROR;
+ context->result = NET_NFC_INVALID_FORMAT;
+ break;
+
+ case SNEP_RESP_NOT_IMPLEMENT :
+ case SNEP_RESP_UNSUPPORTED_VER :
+ context->state = NET_NFC_STATE_ERROR;
+ context->result = NET_NFC_NOT_ALLOWED_OPERATION;
+ break;
+
+ default :
+ context->state = NET_NFC_STATE_ERROR;
+ context->result = NET_NFC_OPERATION_FAIL;
+ break;
+ }
+
+ _net_nfc_server_snep_send(context);
+}
+
+static void _net_nfc_server_snep_send(
+ net_nfc_server_snep_op_context_t *context)
+{
+ if (context == NULL)
+ {
+ return;
+ }
+
+ switch (context->state)
+ {
+ case NET_NFC_LLCP_STEP_01 :
+ case NET_NFC_LLCP_STEP_03 :
+ DEBUG_SERVER_MSG("NET_NFC_LLCP_STEP_%02d",
+ context->state - NET_NFC_LLCP_STEP_01 + 1);
+
+ /* send fragment */
+ _net_nfc_server_send_fragment(context);
+ break;
+
+ case NET_NFC_LLCP_STEP_02 :
+ DEBUG_SERVER_MSG("NET_NFC_LLCP_STEP_02");
+
+ /* receive response */
+ net_nfc_server_snep_recv(
+ context->handle,
+ context->socket,
+ _net_nfc_server_snep_send_recv_cb,
+ context);
+ break;
+
+ case NET_NFC_LLCP_STEP_RETURN :
+ DEBUG_SERVER_MSG("NET_NFC_LLCP_STEP_RETURN");
+
+ /* complete and invoke callback */
+ context->cb(
+ context->result,
+ context->type,
+ NULL,
+ context->user_param);
+
+ _net_nfc_server_snep_destory_context(context);
+ break;
+
+ case NET_NFC_STATE_ERROR :
+ DEBUG_ERR_MSG("NET_NFC_STATE_ERROR");
+
+ /* error, invoke callback */
+ DEBUG_ERR_MSG("net_nfc_server_snep_send failed, [%d]",
+ context->result);
+
+ context->cb(
+ context->result,
+ context->type,
+ NULL,
+ context->user_param);
+
+ _net_nfc_server_snep_destory_context(context);
+ break;
+
+ default :
+ DEBUG_ERR_MSG("NET_NFC_LLCP_STEP_??");
+
+ context->cb(NET_NFC_OPERATION_FAIL,
+ context->type,
+ NULL,
+ context->user_param);
+
+ _net_nfc_server_snep_destory_context(context);
+ break;
+ }
+}
+
+net_nfc_error_e net_nfc_server_snep_send(
+ net_nfc_target_handle_s *handle,
+ net_nfc_llcp_socket_t socket,
+ uint32_t type,
+ data_s *data,
+ _net_nfc_server_snep_operation_cb cb,
+ void *user_param)
+{
+ net_nfc_server_snep_op_context_t *context;
+ net_nfc_error_e result = NET_NFC_OK;
+
+ /* create context */
+ context = _net_nfc_server_snep_create_send_context(
+ type,
+ handle,
+ socket,
+ data,
+ cb,
+ user_param);
+
+ if (context != NULL)
+ {
+ /* send response */
+ _net_nfc_server_snep_send(context);
+ }
+ else
+ {
+ result = NET_NFC_ALLOC_FAIL;
+ }
+
+ return result;
+}
+
+static void _net_nfc_server_snep_server_recv_cb(
+ net_nfc_error_e result,
+ uint32_t type,
+ data_s *data,
+ void *user_param)
+{
+ net_nfc_server_snep_context_t *context =
+ (net_nfc_server_snep_context_t *)user_param;
+
+ DEBUG_SERVER_MSG("_net_nfc_server_snep_server_recv_cb"
+ "result [%d]", result);
+
+ if (context == NULL)
+ {
+ /* TODO */
+ return;
+ }
+
+ context->result = result;
+ context->type = type;
+
+ if (result == NET_NFC_OK && data != NULL && data->buffer != NULL)
+ {
+ DEBUG_SERVER_MSG("received message, type [%d], length [%d]",
+ type, data->length);
+
+ net_nfc_util_alloc_data(&context->data, data->length);
+ if (context->data.buffer != NULL)
+ {
+ memcpy(context->data.buffer,
+ data->buffer, data->length);
+
+ switch (type)
+ {
+ case SNEP_REQ_GET :
+ context->state = NET_NFC_LLCP_STEP_02;
+ break;
+
+ case SNEP_REQ_PUT :
+ context->state = NET_NFC_LLCP_STEP_04;
+ break;
+
+ default :
+ DEBUG_ERR_MSG("invalid request, [%d]", type);
+ context->state = NET_NFC_STATE_ERROR;
+ context->result = NET_NFC_NOT_ALLOWED_OPERATION;
+ break;
+ }
+ }
+ else
+ {
+ DEBUG_ERR_MSG("net_nfc_util_alloc_data failed");
+ /* TODO */
+ context->state = NET_NFC_STATE_ERROR;
+ context->result = NET_NFC_ALLOC_FAIL;
+ }
+ }
+ else
+ {
+ DEBUG_ERR_MSG("net_nfc_server_snep_recv failed, [%d]", result);
+ context->type = type;
+ context->state = NET_NFC_STATE_ERROR;
+ }
+
+ _net_nfc_server_snep_server_process(context);
+}
+
+
+static void _net_nfc_server_snep_server_send_cb(net_nfc_error_e result,
+ uint32_t type,
+ data_s *data,
+ void *user_param)
+{
+ net_nfc_server_snep_context_t *context =
+ (net_nfc_server_snep_context_t *)user_param;
+
+ DEBUG_SERVER_MSG("_net_nfc_server_snep_server_send_cb"
+ ", result [%d]", result);
+
+ if (context == NULL)/* TODO */
+ return;
+
+ context->result = result;
+
+ if (result == NET_NFC_OK)
+ {
+ DEBUG_SERVER_MSG("server process success. and restart....");
+
+ /* restart */
+ net_nfc_util_free_data(&context->data);
+ context->state = NET_NFC_LLCP_STEP_01;
+ }
+ else
+ {
+ DEBUG_ERR_MSG("net_nfc_server_snep_send failed, [%d]", result);
+ context->state = NET_NFC_STATE_ERROR;
+ }
+
+ _net_nfc_server_snep_server_process(context);
+}
+
+
+static void _net_nfc_server_snep_server_process(
+ net_nfc_server_snep_context_t *context)
+{
+ if (context == NULL)
+ return;
+
+ switch (context->state)
+ {
+ case NET_NFC_LLCP_STEP_01 :
+ DEBUG_SERVER_MSG("NET_NFC_LLCP_STEP_01");
+
+ /* receive request */
+ net_nfc_server_snep_recv(
+ context->handle,
+ context->socket,
+ _net_nfc_server_snep_server_recv_cb,
+ context);
+ break;
+
+ case NET_NFC_LLCP_STEP_02 :
+ DEBUG_SERVER_MSG("NET_NFC_LLCP_STEP_02");
+
+ context->state = NET_NFC_LLCP_STEP_03;
+
+ if (context->cb == NULL ||
+ context->cb((net_nfc_snep_handle_h)context,
+ context->result,
+ context->type,
+ &context->data,
+ context->user_param) != NET_NFC_OK)
+ {
+ /* there is no response for GET request */
+ DEBUG_ERR_MSG("there is no response for GET request");
+
+ /* receive request */
+ net_nfc_server_snep_send(context->handle,
+ context->socket,
+ SNEP_RESP_NOT_FOUND,
+ NULL,
+ _net_nfc_server_snep_server_send_cb,
+ context);
+ }
+ break;
+
+ case NET_NFC_LLCP_STEP_03 :
+ DEBUG_SERVER_MSG("NET_NFC_LLCP_STEP_03");
+
+ /* receive request */
+ net_nfc_server_snep_send(context->handle,
+ context->socket,
+ SNEP_RESP_SUCCESS,
+ &context->data,
+ _net_nfc_server_snep_server_send_cb,
+ context);
+ break;
+
+ case NET_NFC_LLCP_STEP_04 :
+ DEBUG_SERVER_MSG("NET_NFC_LLCP_STEP_04");
+
+ if (context->cb != NULL)
+ {
+ /* complete and invoke callback */
+ context->cb(
+ (net_nfc_snep_handle_h)context,
+ NET_NFC_OK,
+ context->type,
+ &context->data,
+ context->user_param);
+ }
+
+ /* receive request */
+ net_nfc_server_snep_send(context->handle,
+ context->socket,
+ SNEP_RESP_SUCCESS,
+ NULL,
+ _net_nfc_server_snep_server_send_cb,
+ context);
+ break;
+
+ case NET_NFC_LLCP_STEP_10 : /* server error, and need to send error code to client */
+ {
+ /* FIXME : */
+ }
+ break;
+
+ case NET_NFC_STATE_ERROR :
+ DEBUG_SERVER_MSG("NET_NFC_STATE_ERROR");
+
+ /* error, invoke callback */
+ DEBUG_ERR_MSG("_snep_server_recv failed, [%d]",
+ context->result);
+
+ if (context->cb != NULL)
+ {
+ context->cb((net_nfc_snep_handle_h)context,
+ context->result,
+ context->type,
+ NULL,
+ context->user_param);
+ }
+
+ /* restart?? */
+ break;
+
+ default :
+ DEBUG_ERR_MSG("NET_NFC_LLCP_STEP_??");
+ /* TODO */
+ break;
+ }
+}
+
+
+static void _net_nfc_server_snep_clear_queue(
+ gpointer data,
+ gpointer user_data)
+{
+ net_nfc_server_snep_job_t *job = (net_nfc_server_snep_job_t *)data;
+
+ if (job != NULL)
+ {
+ if (job->cb != NULL)
+ {
+ job->cb((net_nfc_snep_handle_h)job->context,
+ NET_NFC_OPERATION_FAIL, job->type,
+ NULL, job->user_param);
+ }
+
+ if (job->data.buffer != NULL)
+ {
+ net_nfc_util_free_data(&job->data);
+ }
+
+ _net_nfc_util_free_mem(job);
+ }
+}
+
+
+static void _net_nfc_server_snep_incomming_socket_error_cb(
+ net_nfc_error_e result,
+ net_nfc_target_handle_s *handle,
+ net_nfc_llcp_socket_t socket,
+ data_s *data,
+ void *user_param)
+{
+ net_nfc_server_snep_context_t *context =
+ (net_nfc_server_snep_context_t *)user_param;
+
+ DEBUG_SERVER_MSG("_net_nfc_server_snep_incomming_socket_error_cb,"
+ " socket [%x], result [%d]",socket, result);
+
+ if (context == NULL)
+ {
+ return;
+ }
+
+ if (context->data.buffer != NULL)
+ {
+ net_nfc_util_free_data(&context->data);
+ }
+
+ g_queue_foreach(&context->queue,
+ _net_nfc_server_snep_clear_queue,
+ NULL);
+
+ _net_nfc_util_free_mem(context);
+}
+
+
+static void _net_nfc_server_snep_socket_error_cb(
+ net_nfc_error_e result,
+ net_nfc_target_handle_s *handle,
+ net_nfc_llcp_socket_t socket,
+ data_s *data,
+ void *user_param)
+{
+ net_nfc_server_snep_context_t *context =
+ (net_nfc_server_snep_context_t *)user_param;
+
+ DEBUG_SERVER_MSG("_net_nfc_server_snep_socket_error_cb"
+ " socket [%x], result [%d]",socket, result);
+
+ if (context == NULL)
+ {
+ return;
+ }
+
+ if (context->cb != NULL)
+ {
+ context->cb((net_nfc_snep_handle_h)context,
+ result,
+ NET_NFC_LLCP_STOP,
+ NULL,
+ context->user_param);
+ }
+
+ /*net_nfc_controller_llcp_socket_close(socket, &result);*/
+
+ if (context->data.buffer != NULL)
+ {
+ net_nfc_util_free_data(&context->data);
+ }
+
+ g_queue_foreach(&context->queue,
+ _net_nfc_server_snep_clear_queue,
+ NULL);
+
+ _net_nfc_util_free_mem(context);
+}
+
+
+static void _net_nfc_server_snep_incoming_cb(
+ net_nfc_error_e result,
+ net_nfc_target_handle_s *handle,
+ net_nfc_llcp_socket_t socket,
+ data_s *data,
+ void *user_param)
+{
+ net_nfc_server_snep_context_t *context =
+ (net_nfc_server_snep_context_t *)user_param;
+ net_nfc_server_snep_context_t *accept_context = NULL;
+
+ if (context == NULL)
+ {
+ return;
+ }
+
+ DEBUG_SERVER_MSG("_net_nfc_server_snep_incoming_cb,"
+ " incoming socket [%x], result [%d]",socket, result);
+
+ if (result != NET_NFC_OK)
+ {
+ DEBUG_ERR_MSG("listen socket failed, [%d]", result);
+
+ goto ERROR;
+ }
+
+ /* start snep server */
+ _net_nfc_util_alloc_mem(accept_context, sizeof(*accept_context));
+
+ if (accept_context == NULL)
+ {
+ DEBUG_ERR_MSG("_net_nfc_util_alloc_mem failed");
+ result = NET_NFC_ALLOC_FAIL;
+
+ goto ERROR;
+ }
+
+ accept_context->handle = context->handle;
+ accept_context->socket = socket;
+ accept_context->cb = context->cb;
+ accept_context->user_param = context->user_param;
+ accept_context->state = NET_NFC_LLCP_STEP_01;
+
+ result = net_nfc_server_llcp_simple_accept(handle,
+ socket,
+ _net_nfc_server_snep_incomming_socket_error_cb,
+ accept_context);
+
+ if (result != NET_NFC_OK)
+ {
+ DEBUG_ERR_MSG("net_nfc_server_llcp_simple_accept failed, [%d]",
+ result);
+ goto ERROR;
+ }
+
+ DEBUG_SERVER_MSG("socket [%x] accepted.. waiting for request message",
+ socket);
+
+ _net_nfc_server_snep_server_process(accept_context);
+
+ return;
+
+ERROR :
+ if (accept_context != NULL)
+ {
+ _net_nfc_util_free_mem(accept_context);
+ }
+
+ if (context->cb != NULL)
+ {
+ context->cb((net_nfc_snep_handle_h)context,
+ result,
+ context->type,
+ NULL,
+ context->user_param);
+ }
+}
+
+net_nfc_error_e net_nfc_server_snep_server(
+ net_nfc_target_handle_s *handle,
+ const char *san,
+ sap_t sap,
+ net_nfc_server_snep_cb cb,
+ void *user_param)
+{
+ net_nfc_error_e result;
+ net_nfc_server_snep_context_t *context = NULL;
+
+ if (handle == NULL || san == NULL)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ _net_nfc_util_alloc_mem(context, sizeof(*context));
+
+ if (context == NULL)
+ {
+ DEBUG_ERR_MSG("_create_snep_context failed");
+ result = NET_NFC_ALLOC_FAIL;
+ goto ERROR;
+ }
+ context->handle = handle;
+ context->cb = cb;
+ context->user_param = user_param;
+ context->state = NET_NFC_LLCP_STEP_01;
+
+ result = net_nfc_server_llcp_simple_server(handle,
+ san,
+ sap,
+ _net_nfc_server_snep_incoming_cb,
+ _net_nfc_server_snep_socket_error_cb,
+ context);
+
+ if (result != NET_NFC_OK)
+ {
+ DEBUG_ERR_MSG("net_nfc_server_llcp_simple_server failed, [%d]",
+ result);
+ goto ERROR;
+ }
+
+ DEBUG_SERVER_MSG("start snep server, san [%s], sap [%d]",
+ san, sap);
+ return result;
+
+ERROR :
+ if (context != NULL)
+ _net_nfc_util_free_mem(context);
+
+ return result;
+}
+
+net_nfc_error_e net_nfc_server_snep_server_send_get_response(
+ net_nfc_snep_handle_h snep_handle,
+ data_s *data)
+{
+ net_nfc_server_snep_context_t *context =
+ (net_nfc_server_snep_context_t *)snep_handle;
+ net_nfc_error_e result = NET_NFC_OK;
+
+ if (context == NULL/* && check valid handle */)
+ {
+ DEBUG_ERR_MSG("invalid handle");
+ return NET_NFC_INVALID_PARAM;
+ }
+
+ DEBUG_SERVER_MSG("send get response, socket [%x]", context->socket);
+
+ /* check correct status */
+ if (context->type == SNEP_REQ_GET)
+ {
+ if (context->data.buffer != NULL)
+ net_nfc_util_free_data(&context->data);
+
+ if (data != NULL)
+ {
+ context->type = SNEP_RESP_SUCCESS;
+
+ if (net_nfc_util_alloc_data(&context->data, data->length) == true)
+ {
+ memcpy(context->data.buffer, data->buffer,
+ data->length);
+ }
+ else
+ {
+ DEBUG_ERR_MSG("net_nfc_util_alloc_data failed");
+ result = NET_NFC_ALLOC_FAIL;
+ }
+ }
+ else
+ {
+ /* not found */
+ context->type = SNEP_RESP_NOT_FOUND;
+ }
+
+ _net_nfc_server_snep_server_process(context);
+ }
+ else
+ {
+ DEBUG_ERR_MSG("incorrect handle state");
+ result = NET_NFC_INVALID_STATE;
+ }
+
+ return result;
+}
+
+static void _net_nfc_server_snep_client_send_cb(
+ net_nfc_error_e result,
+ uint32_t type,
+ data_s *data,
+ void *user_param)
+{
+ net_nfc_server_snep_job_t*job =
+ (net_nfc_server_snep_job_t *)user_param;
+
+ if (job == NULL)
+ {
+ /* TODO */
+ return;
+ }
+
+ job->type = type;
+ job->result = result;
+
+ if (result == NET_NFC_OK)
+ {
+ job->state = NET_NFC_LLCP_STEP_02;
+
+ net_nfc_util_free_data(&job->data);
+ }
+ else
+ {
+ DEBUG_ERR_MSG("net_nfc_server_snep_send failed, [%d]", result);
+ job->state = NET_NFC_STATE_ERROR;
+ }
+
+ _net_nfc_server_snep_client_process(job);
+}
+
+static void _net_nfc_server_snep_client_recv_cb(
+ net_nfc_error_e result,
+ uint32_t type,
+ data_s *data,
+ void *user_param)
+{
+ net_nfc_server_snep_job_t *job =
+ (net_nfc_server_snep_job_t *)user_param;
+
+ if (job == NULL)
+ {
+ /* TODO */
+ return;
+ }
+
+ job->type = type;
+ job->result = result;
+
+ if (result == NET_NFC_OK)
+ {
+ if (type == SNEP_RESP_SUCCESS)
+ {
+ job->state = NET_NFC_LLCP_STEP_RETURN;
+ if (data != NULL && data->buffer != NULL)
+ {
+ net_nfc_util_alloc_data(&job->data, data->length);
+ if (job->data.buffer != NULL)
+ {
+ memcpy(job->data.buffer, data->buffer,
+ data->length);
+ }
+ else
+ {
+ DEBUG_ERR_MSG("net_nfc_util_alloc_data failed");
+ job->state = NET_NFC_STATE_ERROR;
+ job->result = NET_NFC_ALLOC_FAIL;
+ }
+ }
+ }
+ else
+ {
+ /* TODO */
+ DEBUG_ERR_MSG("invalid request, [0x%x]", type);
+ job->state = NET_NFC_STATE_ERROR;
+ job->result = NET_NFC_NOT_ALLOWED_OPERATION;
+ }
+ }
+ else
+ {
+
+ DEBUG_ERR_MSG("net_nfc_server_snep_recv failed, [%d]", result);
+ job->state = NET_NFC_STATE_ERROR;
+ }
+
+ _net_nfc_server_snep_client_process(job);
+}
+
+
+static void _net_nfc_server_snep_client_do_job(net_nfc_server_snep_context_t *context)
+{
+ if (context->state == NET_NFC_LLCP_IDLE &&
+ g_queue_is_empty(&context->queue) == false) {
+ net_nfc_server_snep_job_t *job;
+
+ job = g_queue_pop_head(&context->queue);
+ if (job != NULL) {
+ context->state = NET_NFC_LLCP_STEP_01;
+ job->state = NET_NFC_LLCP_STEP_01;
+ _net_nfc_server_snep_client_process(job);
+ }
+ }
+}
+
+static void _net_nfc_server_snep_client_process(
+ net_nfc_server_snep_job_t *job)
+{
+ bool finish = false;
+
+ if (job == NULL)
+ {
+ return;
+ }
+
+ switch (job->state)
+ {
+ case NET_NFC_LLCP_STEP_01 :
+ DEBUG_SERVER_MSG("NET_NFC_LLCP_STEP_01");
+
+ /* send request */
+ net_nfc_server_snep_send(job->handle,
+ job->socket,
+ job->type,
+ &job->data,
+ _net_nfc_server_snep_client_send_cb,
+ job);
+ break;
+
+ case NET_NFC_LLCP_STEP_02 :
+ DEBUG_SERVER_MSG("NET_NFC_LLCP_STEP_02");
+
+ /* receive response */
+ net_nfc_server_snep_recv(job->handle,
+ job->socket,
+ _net_nfc_server_snep_client_recv_cb,
+ job);
+ break;
+
+ case NET_NFC_LLCP_STEP_RETURN :
+ DEBUG_SERVER_MSG("NET_NFC_LLCP_STEP_RETURN");
+
+ /* complete and invoke callback */
+ if (job->cb != NULL)
+ {
+ job->cb((net_nfc_snep_handle_h)job->context,
+ NET_NFC_OK,
+ job->type,
+ &job->data,
+ job->user_param);
+ }
+
+ /* finish job */
+ finish = true;
+ break;
+
+ case NET_NFC_STATE_ERROR :
+ default :
+ DEBUG_ERR_MSG("NET_NFC_STATE_ERROR");
+
+ /* error, invoke callback */
+ DEBUG_ERR_MSG("_snep_server_send failed, [%d]",
+ job->result);
+ if (job->cb != NULL)
+ {
+ job->cb((net_nfc_snep_handle_h)job->context,
+ job->result,
+ job->type,
+ &job->data,
+ job->user_param);
+ }
+
+ /* finish job */
+ finish = true;
+ break;
+ }
+
+ if (finish == true)
+ {
+ net_nfc_server_snep_context_t *context = job->context;
+
+ if (job->data.buffer != NULL)
+ {
+ net_nfc_util_free_data(&job->data);
+ }
+
+ _net_nfc_util_free_mem(job);
+
+ context->state = NET_NFC_LLCP_IDLE;
+
+ _net_nfc_server_snep_client_do_job(context);
+ }
+}
+
+static void _net_nfc_server_snep_connected_cb(
+ net_nfc_error_e result,
+ net_nfc_target_handle_s *handle,
+ net_nfc_llcp_socket_t socket,
+ data_s *data,
+ void *user_param)
+{
+ net_nfc_server_snep_context_t *context =
+ (net_nfc_server_snep_context_t *)user_param;
+
+ if (context == NULL)
+ {
+ return;
+ }
+
+ context->socket = socket;
+
+ if (result == NET_NFC_OK)
+ {
+ /* start snep client */
+ DEBUG_SERVER_MSG("socket [%x] connected. send message",
+ socket);
+ }
+ else
+ {
+ DEBUG_ERR_MSG("connect socket failed, [%d]", result);
+ }
+
+ if (context->cb != NULL)
+ {
+ context->cb((net_nfc_snep_handle_h)context,
+ result,
+ NET_NFC_LLCP_START,
+ NULL,
+ context->user_param);
+ }
+}
+
+net_nfc_error_e net_nfc_server_snep_client(
+ net_nfc_target_handle_s *handle,
+ const char *san,
+ sap_t sap,
+ net_nfc_server_snep_cb cb,
+ void *user_param)
+{
+ net_nfc_error_e result;
+ net_nfc_server_snep_context_t *context = NULL;
+
+ if (handle == NULL)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ _net_nfc_util_alloc_mem(context, sizeof(*context));
+ if (context == NULL)
+ {
+ DEBUG_ERR_MSG("_net_nfc_util_alloc_mem failed");
+ result = NET_NFC_ALLOC_FAIL;
+
+ goto ERROR;
+ }
+ context->handle = handle;
+ context->cb = cb;
+ context->user_param = user_param;
+
+ result = net_nfc_server_llcp_simple_client(handle,
+ san,
+ sap,
+ _net_nfc_server_snep_connected_cb,
+ _net_nfc_server_snep_socket_error_cb,
+ context);
+
+ if (result != NET_NFC_OK)
+ {
+ DEBUG_ERR_MSG("net_nfc_server_llcp_simple_client failed, [%d]",
+ result);
+
+ goto ERROR;
+ }
+ if (san != NULL)
+ DEBUG_SERVER_MSG("start snep client, san [%s]",
+ san);
+ else
+ DEBUG_SERVER_MSG("start snep client, sap [%d]",
+ sap);
+
+ return result;
+
+ERROR :
+ if (context != NULL)
+ {
+ if (context->data.buffer != NULL)
+ {
+ net_nfc_util_free_data(&context->data);
+ }
+ _net_nfc_util_free_mem(context);
+ }
+
+ return result;
+}
+
+
+net_nfc_error_e net_nfc_server_snep_client_request(
+ net_nfc_snep_handle_h snep,
+ uint8_t type,
+ data_s *data,
+ net_nfc_server_snep_cb cb,
+ void *user_param)
+{
+ net_nfc_server_snep_context_t *context = (net_nfc_server_snep_context_t *)snep;
+ net_nfc_error_e result = NET_NFC_OK;
+ net_nfc_server_snep_job_t *job;
+
+ if (context == NULL || data == NULL || data->buffer == NULL)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ /* check type */
+ _net_nfc_util_alloc_mem(job, sizeof(*job));
+ if (job != NULL)
+ {
+ net_nfc_util_alloc_data(&job->data, data->length);
+ if (job->data.buffer != NULL)
+ {
+ memcpy(job->data.buffer, data->buffer, data->length);
+ }
+ job->type = type;
+ job->cb = cb;
+ job->user_param = user_param;
+
+ job->context = context;
+ job->handle = context->handle;
+ job->socket = context->socket;
+
+ g_queue_push_tail(&context->queue, job);
+ }
+ else
+ {
+ return NET_NFC_ALLOC_FAIL;
+ }
+
+ INFO_MSG("enqueued jobs [%d]", g_queue_get_length(&context->queue));
+
+ /* if client is idle, starts sending request */
+ if (context->state == NET_NFC_LLCP_IDLE)
+ {
+ _net_nfc_server_snep_client_do_job(context);
+ } else {
+ INFO_MSG("client is working. this job will be enqueued");
+ }
+
+ return result;
+}
+
+static net_nfc_error_e _net_nfc_server_default_server_cb_(
+ net_nfc_snep_handle_h handle,
+ net_nfc_error_e result,
+ uint32_t type,
+ data_s *data,
+ void *user_param)
+{
+ DEBUG_SERVER_MSG("type [%d], result [%d], data [%p], user_param [%p]",
+ type, result, data, user_param);
+
+ if (result != NET_NFC_OK || data == NULL || data->buffer == NULL)
+ {
+ /* restart */
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ switch (type)
+ {
+ case SNEP_REQ_GET:
+ {
+ net_nfc_server_snep_get_msg_t *msg =
+ (net_nfc_server_snep_get_msg_t *)data->buffer;
+
+
+ uint32_t max_len = htonl(msg->length);
+ data_s get_msg = { msg->data,data->length - sizeof(msg->length)};
+
+ DEBUG_SERVER_MSG("GET : acceptable max_len [%d], message [%d]",
+ max_len, data->length - sizeof(msg->length));
+
+
+ if (_net_nfc_server_snep_process_get_response_cb(handle, &get_msg, max_len))
+ {
+ result = NET_NFC_OK;
+ }
+ else
+ {
+ result = NET_NFC_NOT_SUPPORTED;
+ }
+ }
+ break;
+
+ case SNEP_REQ_PUT :
+ {
+ net_nfc_server_p2p_received(data);
+ net_nfc_app_util_process_ndef(data);;
+
+ result = NET_NFC_OK;
+ }
+ break;
+
+ default :
+ DEBUG_ERR_MSG("error [%d]", result);
+ break;
+ }
+
+ return result;
+}
+
+
+static net_nfc_error_e _net_nfc_server_default_client_cb_(
+ net_nfc_snep_handle_h handle,
+ net_nfc_error_e result,
+ uint32_t type,
+ data_s *data,
+ void *user_param)
+{
+ _net_nfc_server_snep_service_context_t *context =
+ (_net_nfc_server_snep_service_context_t*)user_param;
+
+ DEBUG_SERVER_MSG("type [%d], result [%d], data [%p]",
+ type, result, data);
+
+ if (user_param == NULL)
+ return NET_NFC_NULL_PARAMETER;;
+
+ switch (type)
+ {
+ case SNEP_RESP_SUCCESS :
+ case SNEP_RESP_BAD_REQ :
+ case SNEP_RESP_EXCESS_DATA :
+ case SNEP_RESP_NOT_FOUND :
+ case SNEP_RESP_NOT_IMPLEMENT :
+ case SNEP_RESP_REJECT :
+ case SNEP_RESP_UNSUPPORTED_VER :
+ context = (_net_nfc_server_snep_service_context_t *)user_param;
+
+ net_nfc_server_p2p_data_sent(result,
+ context->user_param);
+
+ _net_nfc_util_free_mem(context);
+ break;
+
+ default :
+ DEBUG_ERR_MSG("error [%d]", result);
+ break;
+ }
+
+ return result;
+}
+
+
+static net_nfc_error_e _net_nfc_server_default_client_connected_cb_(
+ net_nfc_snep_handle_h handle,
+ net_nfc_error_e result,
+ uint32_t type,
+ data_s *data,
+ void *user_param)
+{
+ _net_nfc_server_snep_service_context_t *context =
+ (_net_nfc_server_snep_service_context_t *)user_param;
+
+ DEBUG_SERVER_MSG("type [%d], result [%d], data [%p], user_param [%p]",
+ type, result, data, user_param);
+
+ if (context == NULL)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ if (result == NET_NFC_OK)
+ {
+ net_nfc_server_snep_client_request(handle,
+ context->type,
+ &context->data,
+ _net_nfc_server_default_client_cb_,
+ context);
+ }
+ else
+ {
+ if (context->data.buffer != NULL)
+ {
+ net_nfc_util_free_data(&context->data);
+ }
+ _net_nfc_util_free_mem(context);
+ }
+
+ return result;
+}
+
+
+net_nfc_error_e net_nfc_server_snep_default_server_start(
+ net_nfc_target_handle_s *handle)
+{
+ /* start default snep server, register your callback */
+ return net_nfc_server_snep_server(handle,
+ SNEP_SAN,
+ SNEP_SAP,
+ _net_nfc_server_default_server_cb_,
+ (void *)1234);
+}
+
+
+net_nfc_error_e net_nfc_server_snep_default_client_start(
+ net_nfc_target_handle_s *handle,
+ int type,
+ data_s *data,
+ int client,
+ void *user_param)
+{
+ _net_nfc_server_snep_service_context_t *context = NULL;
+
+ _net_nfc_util_alloc_mem(context, sizeof(*context));
+ if (context != NULL)
+ {
+ context->handle = handle;
+ context->client = client;
+ context->user_param = user_param;
+ context->type = type;
+ net_nfc_util_alloc_data(&context->data, data->length);
+ if (context->data.buffer != NULL)
+ {
+ memcpy(context->data.buffer, data->buffer,
+ data->length);
+ context->data.length = data->length;
+ }
+ /* start default snep client, register your callback */
+ return net_nfc_server_snep_client(handle,
+ SNEP_SAN,
+ SNEP_SAP,
+ _net_nfc_server_default_client_connected_cb_,
+ context);
+ }
+ else
+ {
+ return NET_NFC_ALLOC_FAIL;
+ }
+}
+
+ net_nfc_error_e
+net_nfc_server_snep_default_server_register_get_response_cb(
+ net_nfc_server_snep_listen_cb cb,
+ void *user_param)
+{
+ net_nfc_error_e result;
+
+ if (_net_nfc_server_snep_add_get_response_cb(cb, user_param) == true)
+ {
+ result = NET_NFC_OK;
+ }
+ else
+ {
+ result = NET_NFC_ALREADY_REGISTERED;
+ }
+
+ return result;
+}
+
+ net_nfc_error_e
+net_nfc_server_snep_default_server_unregister_get_response_cb(
+ net_nfc_server_snep_listen_cb cb)
+{
+ _net_nfc_server_snep_del_get_response_cb(cb);
+
+ return NET_NFC_OK;
+}
+
+net_nfc_error_e net_nfc_server_snep_default_server_send_get_response(
+ net_nfc_snep_handle_h snep_handle, data_s *data)
+{
+ net_nfc_server_snep_context_t *context =
+ (net_nfc_server_snep_context_t *)snep_handle;
+ net_nfc_error_e result = NET_NFC_OK;
+
+ if (context == NULL/* && check valid handle */)
+ {
+ DEBUG_ERR_MSG("invalid handle");
+ return NET_NFC_INVALID_PARAM;
+ }
+
+ /* check correct status */
+ if (context->type == SNEP_REQ_GET &&
+ context->state == NET_NFC_LLCP_STEP_03)
+ {
+ net_nfc_server_snep_server_send_get_response(snep_handle, data);
+ }
+ else
+ {
+ DEBUG_ERR_MSG("incorrect handle state");
+ result = NET_NFC_INVALID_STATE;
+ }
+
+ return result;
+}
+
+static void _snep_default_activate_cb(int event,
+ net_nfc_target_handle_s *handle,
+ uint32_t sap, const char *san, void *user_param)
+{
+ net_nfc_error_e result;
+
+ DEBUG_SERVER_MSG("event [%d], handle [%p], sap [%d], san [%s]",
+ event, handle, sap, san);
+
+ if (event == NET_NFC_LLCP_START) {
+ /* start snep server */
+ result = net_nfc_server_snep_server(handle, (char *)san, sap,
+ _net_nfc_server_default_server_cb_, user_param);
+ if (result != NET_NFC_OK) {
+ DEBUG_ERR_MSG("net_nfc_service_snep_server failed, [%d]",
+ result);
+ }
+ } else if (event == NET_NFC_LLCP_UNREGISTERED) {
+ /* unregister server, do nothing */
+ }
+}
+
+net_nfc_error_e net_nfc_server_snep_default_server_register()
+{
+ char id[20];
+
+ /* TODO : make id, */
+ snprintf(id, sizeof(id), "%d", getpid());
+
+ /* start default snep server */
+ return net_nfc_server_llcp_register_service(id,
+ SNEP_SAP,
+ SNEP_SAN,
+ _snep_default_activate_cb,
+ NULL);
+}
+
+net_nfc_error_e net_nfc_server_snep_default_server_unregister()
+{
+ char id[20];
+
+ /* TODO : make id, */
+ snprintf(id, sizeof(id), "%d", getpid());
+
+ /* start default snep server */
+ return net_nfc_server_llcp_unregister_service(id,
+ SNEP_SAP,
+ SNEP_SAN);
+}
+
+net_nfc_error_e net_nfc_server_snep_parse_get_request(data_s *request,
+ size_t *max_len, data_s *message)
+{
+ net_nfc_server_snep_msg_t *msg = NULL;
+
+ if (request == NULL || request->buffer == NULL ||
+ request->length == 0 || max_len == NULL || message == NULL) {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ msg = (net_nfc_server_snep_msg_t *)request->buffer;
+
+ *max_len = htonl(msg->length);
+
+ message->buffer = msg->data;
+ message->length = request->length - sizeof(msg->length);
+
+ DEBUG_SERVER_MSG("GET : acceptable max_len [%d], message [%d]",
+ *max_len, request->length - sizeof(msg->length));
+
+ return NET_NFC_OK;
+}
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_SERVER_PROCESS_SNEP_H__
+#define __NET_NFC_SERVER_PROCESS_SNEP_H__
+
+#include "net_nfc_gdbus.h"
+#include "net_nfc_typedef_internal.h"
+
+#define SNEP_SAN "urn:nfc:sn:snep"
+#define SNEP_SAP 4
+
+typedef enum
+{
+ SNEP_REQ_CONTINUE = 0x00,
+ SNEP_REQ_GET = 0x01,
+ SNEP_REQ_PUT = 0x02,
+ SNEP_REQ_REJECT = 0x7F,
+ SNEP_RESP_CONT = 0x80,
+ SNEP_RESP_SUCCESS = 0x81,
+ SNEP_RESP_NOT_FOUND = 0xC0,
+ SNEP_RESP_EXCESS_DATA = 0xC1,
+ SNEP_RESP_BAD_REQ = 0xC2,
+ SNEP_RESP_NOT_IMPLEMENT = 0xE0,
+ SNEP_RESP_UNSUPPORTED_VER = 0xE1,
+ SNEP_RESP_REJECT = 0xFF,
+} snep_command_field_e;
+
+typedef bool (*net_nfc_server_snep_listen_cb)(net_nfc_snep_handle_h handle,
+ uint32_t type,
+ uint32_t max_len,
+ data_s *data,
+ void *user_param);
+
+typedef net_nfc_error_e (*net_nfc_server_snep_cb)(net_nfc_snep_handle_h handle,
+ net_nfc_error_e result,
+ uint32_t type,
+ data_s *data,
+ void *user_param);
+
+net_nfc_error_e net_nfc_server_snep_server(
+ net_nfc_target_handle_s *handle,
+ const char *san,
+ sap_t sap,
+ net_nfc_server_snep_cb cb,
+ void *user_param);
+
+net_nfc_error_e net_nfc_server_snep_client(
+ net_nfc_target_handle_s *handle,
+ const char *san,
+ sap_t sap,
+ net_nfc_server_snep_cb cb,
+ void *user_param);
+
+net_nfc_error_e net_nfc_server_snep_server_send_get_response(
+ net_nfc_snep_handle_h snep_handle,
+ data_s *data);
+
+net_nfc_error_e net_nfc_server_snep_client_request(
+ net_nfc_snep_handle_h snep,
+ uint8_t type,
+ data_s *data,
+ net_nfc_server_snep_cb cb,
+ void *user_param);
+
+net_nfc_error_e net_nfc_server_snep_default_server_start(
+ net_nfc_target_handle_s *handle);
+
+net_nfc_error_e net_nfc_server_snep_default_client_start(
+ net_nfc_target_handle_s *handle,
+ int type,
+ data_s *data,
+ int client,
+ void *user_param);
+
+net_nfc_error_e
+net_nfc_server_snep_default_server_register_get_response_cb(
+ net_nfc_server_snep_listen_cb cb,
+ void *user_param);
+
+net_nfc_error_e
+net_nfc_server_snep_default_server_unregister_get_response_cb(
+ net_nfc_server_snep_listen_cb cb);
+
+net_nfc_error_e
+net_nfc_server_snep_default_server_send_get_response(
+ net_nfc_snep_handle_h snep_handle,
+ data_s *data);
+
+net_nfc_error_e net_nfc_server_snep_default_server_register();
+
+net_nfc_error_e net_nfc_server_snep_default_server_unregister();
+
+net_nfc_error_e net_nfc_server_snep_parse_get_request(data_s *request,
+ size_t *max_len, data_s *message);
+
+#endif //__NET_NFC_SERVER_PROCESS_SNEP_H__
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include <vconf.h>
+#include <tapi_common.h>
+#include <ITapiSim.h>
+
+#include "net_nfc_typedef_internal.h"
+#include "net_nfc_debug_internal.h"
+#include "net_nfc_util_internal.h"
+#include "net_nfc_util_gdbus_internal.h"
+#include "net_nfc_gdbus.h"
+#include "net_nfc_server.h"
+#include "net_nfc_server_common.h"
+#include "net_nfc_server_context.h"
+#include "net_nfc_server_manager.h"
+#include "net_nfc_server_controller.h"
+#include "net_nfc_server_util.h"
+#include "net_nfc_server_se.h"
+
+
+typedef struct _nfc_se_setting_t
+{
+ bool busy;
+ uint8_t type;
+ uint8_t mode;
+}
+net_nfc_server_se_setting_t;
+
+
+static NetNfcGDbusSecureElement *se_skeleton = NULL;
+#if 0
+static uint8_t gdbus_se_prev_type = SECURE_ELEMENT_TYPE_INVALID;
+static uint8_t gdbus_se_prev_mode = SECURE_ELEMENT_OFF_MODE;
+#endif
+static net_nfc_server_se_setting_t gdbus_se_setting;
+
+/* TODO : make a list for handles */
+static TapiHandle *gdbus_uicc_handle;
+static net_nfc_target_handle_s *gdbus_ese_handle;
+
+/* server_side */
+typedef struct _ServerSeData ServerSeData;
+
+struct _ServerSeData
+{
+ data_s aid;
+ data_s param;
+ guint event;
+};
+
+typedef struct _SeDataSeType SeDataSeType;
+
+struct _SeDataSeType
+{
+ NetNfcGDbusSecureElement *object;
+ GDBusMethodInvocation *invocation;
+ gint se_type;
+};
+
+
+typedef struct _SeDataHandle SeDataHandle;
+
+struct _SeDataHandle
+{
+ NetNfcGDbusSecureElement *object;
+ GDBusMethodInvocation *invocation;
+ net_nfc_target_handle_s* handle;
+};
+
+typedef struct _SeDataApdu SeDataApdu;
+
+struct _SeDataApdu
+{
+ NetNfcGDbusSecureElement *object;
+ GDBusMethodInvocation *invocation;
+ net_nfc_target_handle_s* handle;
+ GVariant *data;
+};
+
+static void se_close_secure_element_thread_func(gpointer user_data);
+
+static void se_get_atr_thread_func(gpointer user_data);
+
+static void se_open_secure_element_thread_func(gpointer user_data);
+
+static void se_send_apdu_thread_func(gpointer user_data);
+
+static void se_set_data_thread_func(gpointer user_data);
+
+static gboolean se_handle_close_secure_element(
+ NetNfcGDbusSecureElement *object,
+ GDBusMethodInvocation *invocation,
+ guint arg_handle,
+ GVariant *smack_privilege);
+
+static gboolean se_handle_get_atr(
+ NetNfcGDbusSecureElement *object,
+ GDBusMethodInvocation *invocation,
+ guint arg_handle,
+ GVariant *smack_privilege);
+
+
+static gboolean se_handle_open_secure_element(
+ NetNfcGDbusSecureElement *object,
+ GDBusMethodInvocation *invocation,
+ gint arg_type,
+ GVariant *smack_privilege);
+
+
+static gboolean se_handle_send_apdu(
+ NetNfcGDbusSecureElement *object,
+ GDBusMethodInvocation *invocation,
+ guint arg_handle,
+ GVariant* apdudata,
+ GVariant *smack_privilege);
+
+static gboolean se_handle_set(
+ NetNfcGDbusSecureElement *object,
+ GDBusMethodInvocation *invocation,
+ gint arg_type,
+ GVariant *smack_privilege);
+
+
+uint8_t net_nfc_server_se_get_se_type()
+{
+ return gdbus_se_setting.type;
+}
+
+uint8_t net_nfc_server_se_get_se_mode()
+{
+ return gdbus_se_setting.mode;
+}
+
+static void net_nfc_server_se_set_se_type(uint8_t type)
+{
+ gdbus_se_setting.type = type;
+}
+
+static void net_nfc_server_se_set_se_mode(uint8_t mode)
+{
+ gdbus_se_setting.mode = mode;
+}
+
+
+/* eSE functions */
+static bool net_nfc_server_se_is_ese_handle(net_nfc_target_handle_s *handle)
+{
+ return (gdbus_ese_handle != NULL &&
+ gdbus_ese_handle == handle);
+}
+
+static void net_nfc_server_se_set_current_ese_handle(
+ net_nfc_target_handle_s *handle)
+{
+ gdbus_ese_handle = handle;
+}
+
+static net_nfc_target_handle_s *net_nfc_server_se_open_ese()
+{
+ if (gdbus_ese_handle == NULL) {
+ net_nfc_error_e result;
+ net_nfc_target_handle_s *handle;
+
+ if (net_nfc_controller_secure_element_open(
+ SECURE_ELEMENT_TYPE_ESE,
+ &handle, &result) == true)
+ {
+ net_nfc_server_se_set_current_ese_handle(handle);
+
+ DEBUG_SERVER_MSG("handle [%p]", handle);
+ }
+ else
+ {
+ DEBUG_ERR_MSG("net_nfc_controller_secure_element_open failed [%d]",
+ result);
+ }
+ }
+
+ return gdbus_ese_handle;
+}
+
+static net_nfc_error_e net_nfc_server_se_close_ese()
+{
+ net_nfc_error_e result = NET_NFC_OK;
+
+ if (gdbus_ese_handle != NULL &&
+ net_nfc_server_gdbus_is_server_busy() == false) {
+ if (net_nfc_controller_secure_element_close(
+ gdbus_ese_handle,
+ &result) == false)
+ {
+ net_nfc_controller_exception_handler();
+ }
+ net_nfc_server_se_set_current_ese_handle(NULL);
+ }
+
+ return result;
+}
+
+
+/* UICC functions */
+static TelSimCardStatus_t _se_uicc_check_state(TapiHandle *handle)
+{
+ TelSimCardStatus_t state = TAPI_SIM_STATUS_UNKNOWN;
+ int b_card_changed = 0;
+ int error;
+
+ error = tel_get_sim_init_info(handle,
+ &state,
+ &b_card_changed);
+ if (error != 0)
+ {
+ DEBUG_ERR_MSG("error = [%d]", error);
+ }
+
+ DEBUG_SERVER_MSG("current sim init state = [%d]", state);
+
+ return state;
+}
+
+static void _se_uicc_status_noti_cb(TapiHandle *handle,
+ const char *noti_id,
+ void *data,
+ void *user_data)
+{
+ TelSimCardStatus_t *status = (TelSimCardStatus_t *)data;
+
+ DEBUG_SERVER_MSG("_se_uicc_status_noti_cb");
+
+ switch (*status) {
+ case TAPI_SIM_STATUS_SIM_INIT_COMPLETED :
+ if (gdbus_se_setting.busy == true)
+ {
+ net_nfc_error_e result;
+
+ DEBUG_SERVER_MSG("TAPI_SIM_STATUS_SIM_INIT_COMPLETED");
+
+ gdbus_se_setting.busy = false;
+
+ net_nfc_controller_set_secure_element_mode(
+ SECURE_ELEMENT_TYPE_UICC,
+ SECURE_ELEMENT_VIRTUAL_MODE, &result);
+ if (result == NET_NFC_OK) {
+ DEBUG_SERVER_MSG(
+ "changed to SECURE_ELEMENT_TYPE_UICC");
+ net_nfc_server_se_set_se_type(
+ SECURE_ELEMENT_TYPE_UICC);
+ net_nfc_server_se_set_se_mode(
+ SECURE_ELEMENT_VIRTUAL_MODE);
+ if (vconf_set_int(VCONFKEY_NFC_SE_TYPE,
+ VCONFKEY_NFC_SE_TYPE_UICC) != 0) {
+ DEBUG_ERR_MSG("vconf_set_int failed");
+ }
+ } else {
+ DEBUG_ERR_MSG(
+ "SECURE_ELEMENT_TYPE_UICC, SECURE_ELEMENT_VIRTUAL_MODE failed [%d]",
+ result);
+ }
+ }
+ break;
+
+ case TAPI_SIM_STATUS_CARD_REMOVED :
+ DEBUG_SERVER_MSG("TAPI_SIM_STATUS_CARD_REMOVED");
+ /* do something */
+ break;
+
+ default:
+ break;
+ }
+}
+
+static void _se_uicc_init(void)
+{
+ char **cpList;
+
+ cpList = tel_get_cp_name_list();
+ if (cpList != NULL) {
+ gdbus_uicc_handle = tel_init(cpList[0]);
+ if (gdbus_uicc_handle != NULL) {
+ tel_register_noti_event(gdbus_uicc_handle,
+ TAPI_NOTI_SIM_STATUS,
+ _se_uicc_status_noti_cb,
+ NULL);
+
+ } else {
+ DEBUG_ERR_MSG("tel_init() failed");
+ }
+ } else {
+ DEBUG_ERR_MSG("tel_get_cp_name_list() failed");
+ }
+}
+
+static void _se_uicc_deinit()
+{
+ tel_deregister_noti_event(gdbus_uicc_handle,
+ TAPI_NOTI_SIM_STATUS);
+
+ tel_deinit(gdbus_uicc_handle);
+
+ gdbus_uicc_handle = NULL;
+}
+
+
+static net_nfc_target_handle_s *_se_uicc_open(void)
+{
+ net_nfc_target_handle_s *result = NULL;
+
+ if (gdbus_uicc_handle != NULL) {
+ TelSimCardStatus_t status;
+
+ status = _se_uicc_check_state(gdbus_uicc_handle);
+ if (status == TAPI_SIM_STATUS_SIM_INIT_COMPLETED) {
+ result = (net_nfc_target_handle_s *)gdbus_uicc_handle;
+ }
+ }
+
+ return result;
+}
+
+static bool _se_is_uicc_handle(net_nfc_target_handle_s *handle)
+{
+ return (gdbus_uicc_handle != NULL &&
+ (TapiHandle *)handle == gdbus_uicc_handle);
+}
+
+static void _se_uicc_close(net_nfc_target_handle_s *handle)
+{
+}
+
+/* SE Functions */
+net_nfc_error_e net_nfc_server_se_change_se(uint8_t type)
+{
+ net_nfc_error_e result = NET_NFC_OK;
+
+ switch (type) {
+ case SECURE_ELEMENT_TYPE_UICC :
+ if (gdbus_se_setting.busy == false) {
+ TelSimCardStatus_t state;
+
+ /*turn off ESE*/
+ net_nfc_controller_set_secure_element_mode(
+ SECURE_ELEMENT_TYPE_ESE,
+ SECURE_ELEMENT_OFF_MODE,
+ &result);
+
+ state = _se_uicc_check_state(gdbus_uicc_handle);
+ if (state == TAPI_SIM_STATUS_SIM_INIT_COMPLETED ||
+ state == TAPI_SIM_STATUS_CARD_NOT_PRESENT ||
+ state == TAPI_SIM_STATUS_CARD_REMOVED) {
+ /*turn on UICC*/
+ net_nfc_controller_set_secure_element_mode(
+ SECURE_ELEMENT_TYPE_UICC,
+ SECURE_ELEMENT_VIRTUAL_MODE, &result);
+ if (result == NET_NFC_OK) {
+ DEBUG_SERVER_MSG(
+ "changed to SECURE_ELEMENT_TYPE_UICC");
+
+ net_nfc_server_se_set_se_type(
+ SECURE_ELEMENT_TYPE_UICC);
+ net_nfc_server_se_set_se_mode(
+ SECURE_ELEMENT_VIRTUAL_MODE);
+
+ if (vconf_set_int(
+ VCONFKEY_NFC_SE_TYPE,
+ VCONFKEY_NFC_SE_TYPE_UICC) != 0)
+ {
+ DEBUG_ERR_MSG("vconf_set_int failed");
+ }
+ } else {
+ DEBUG_ERR_MSG("SECURE_ELEMENT_TYPE_UICC, SECURE_ELEMENT_VIRTUAL_MODE failed [%d]",
+ result);
+ }
+ } else {
+ DEBUG_SERVER_MSG("UICC is not ready. waiting UICC event");
+
+ gdbus_se_setting.busy = true;
+ }
+ } else {
+ DEBUG_SERVER_MSG("Previous request is processing.");
+
+ result = NET_NFC_BUSY;
+ }
+ break;
+
+ case SECURE_ELEMENT_TYPE_ESE :
+ /*turn off UICC*/
+ net_nfc_controller_set_secure_element_mode(
+ SECURE_ELEMENT_TYPE_UICC,
+ SECURE_ELEMENT_OFF_MODE,
+ &result);
+
+ /*turn on ESE*/
+ net_nfc_controller_set_secure_element_mode(
+ SECURE_ELEMENT_TYPE_ESE,
+ SECURE_ELEMENT_VIRTUAL_MODE,
+ &result);
+
+ if (result == NET_NFC_OK) {
+ DEBUG_SERVER_MSG("changed to SECURE_ELEMENT_TYPE_ESE");
+
+ net_nfc_server_se_set_se_type(SECURE_ELEMENT_TYPE_ESE);
+ net_nfc_server_se_set_se_mode(SECURE_ELEMENT_VIRTUAL_MODE);
+
+ if (vconf_set_int(VCONFKEY_NFC_SE_TYPE,
+ VCONFKEY_NFC_SE_TYPE_ESE) != 0) {
+ DEBUG_ERR_MSG("vconf_set_int failed");
+ }
+ } else {
+ DEBUG_ERR_MSG("SECURE_ELEMENT_TYPE_ESE, SECURE_ELEMENT_VIRTUAL_MODE failed [%d]", result);
+ }
+ break;
+
+ default:
+ {
+ net_nfc_error_e result_ese, result_uicc;
+
+ net_nfc_server_se_set_se_type(
+ SECURE_ELEMENT_TYPE_INVALID);
+ net_nfc_server_se_set_se_mode(SECURE_ELEMENT_OFF_MODE);
+
+ /*turn off ESE*/
+ net_nfc_controller_set_secure_element_mode(
+ SECURE_ELEMENT_TYPE_ESE,
+ SECURE_ELEMENT_OFF_MODE,
+ &result_ese);
+
+ /*turn off UICC*/
+ net_nfc_controller_set_secure_element_mode(
+ SECURE_ELEMENT_TYPE_UICC,
+ SECURE_ELEMENT_OFF_MODE,
+ &result_uicc);
+
+ if (result_ese != NET_NFC_INVALID_HANDLE
+ && result_uicc != NET_NFC_INVALID_HANDLE) {
+ DEBUG_SERVER_MSG("SE off all");
+ if (vconf_set_int(VCONFKEY_NFC_SE_TYPE,
+ VCONFKEY_NFC_SE_TYPE_NONE) != 0) {
+ DEBUG_ERR_MSG("vconf_set_int failed");
+ }
+
+ result = NET_NFC_OK;
+ }
+ else
+ {
+ DEBUG_ERR_MSG("ALL OFF failed, ese [%d], uicc [%d]",result_ese, result_uicc);
+
+ result = NET_NFC_INVALID_HANDLE;
+ }
+ }
+ break;
+ }
+
+ return result;
+}
+
+static void se_close_secure_element_thread_func(gpointer user_data)
+{
+ SeDataHandle *detail = (SeDataHandle *)user_data;
+ net_nfc_error_e result;
+
+ g_assert(detail != NULL);
+ g_assert(detail->object != NULL);
+ g_assert(detail->invocation != NULL);
+
+ if (_se_is_uicc_handle(detail->handle) == true)
+ {
+ _se_uicc_close(detail->handle);
+
+ result = NET_NFC_OK;
+ }
+ else if (net_nfc_server_se_is_ese_handle(detail->handle) == true)
+ {
+ /* decrease client reference count */
+ net_nfc_server_gdbus_decrease_se_count(
+ g_dbus_method_invocation_get_sender(
+ detail->invocation));
+
+ result = net_nfc_server_se_close_ese();
+ }
+ else
+ {
+ result = NET_NFC_INVALID_HANDLE;
+ }
+#if 0
+ if ((gdbus_se_prev_type != net_nfc_server_se_get_se_type()) ||
+ (gdbus_se_prev_mode != net_nfc_server_se_get_se_mode()))
+ {
+ /*return back se mode*/
+ net_nfc_controller_set_secure_element_mode(gdbus_se_prev_type,
+ gdbus_se_prev_mode, &result);
+
+ net_nfc_server_se_set_se_type(gdbus_se_prev_type);
+ net_nfc_server_se_set_se_mode(gdbus_se_prev_mode);
+ }
+#endif
+ net_nfc_gdbus_secure_element_complete_close_secure_element(
+ detail->object, detail->invocation, result);
+
+ g_object_unref(detail->invocation);
+ g_object_unref(detail->object);
+
+ g_free(detail);
+
+ /* shutdown process if it doesn't need */
+ if (net_nfc_server_manager_get_active() == false &&
+ net_nfc_server_gdbus_is_server_busy() == false) {
+ net_nfc_manager_quit();
+ }
+}
+
+static gboolean se_handle_close_secure_element(
+ NetNfcGDbusSecureElement *object,
+ GDBusMethodInvocation *invocation,
+ guint arg_handle,
+ GVariant *smack_privilege)
+{
+ SeDataHandle *data;
+ gboolean result;
+
+ INFO_MSG(">>> REQUEST from [%s]",
+ g_dbus_method_invocation_get_sender(invocation));
+
+ /* check privilege and update client context */
+ if (net_nfc_server_gdbus_check_privilege(invocation,
+ smack_privilege,
+ "nfc-manager",
+ "rw") == false) {
+ DEBUG_ERR_MSG("permission denied, and finished request");
+
+ return FALSE;
+ }
+
+ data = g_new0(SeDataHandle, 1);
+ if (data == NULL)
+ {
+ DEBUG_ERR_MSG("Memory allocation failed");
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.AllocationError",
+ "Can not allocate memory");
+
+ return FALSE;
+ }
+
+ data->object = g_object_ref(object);
+ data->invocation = g_object_ref(invocation);
+ data->handle = (net_nfc_target_handle_s *)arg_handle;
+
+ result = net_nfc_server_controller_async_queue_push(
+ se_close_secure_element_thread_func, data);
+ if (result == FALSE)
+ {
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.Se.ThreadError",
+ "can not push to controller thread");
+
+ g_object_unref(data->object);
+ g_object_unref(data->invocation);
+
+ g_free(data);
+ }
+
+ return result;
+}
+
+static void se_get_atr_thread_func(gpointer user_data)
+{
+ SeDataHandle *detail = (SeDataHandle *)user_data;
+ data_s *atr = NULL;
+ GVariant *data;
+ net_nfc_error_e result;
+
+ g_assert(detail != NULL);
+ g_assert(detail->object != NULL);
+ g_assert(detail->invocation != NULL);
+
+ if (_se_is_uicc_handle(detail->handle) == true)
+ {
+ result = NET_NFC_NOT_SUPPORTED;
+ }
+ else if (net_nfc_server_se_is_ese_handle(detail->handle) == true)
+ {
+ net_nfc_controller_secure_element_get_atr(detail->handle, &atr,
+ &result);
+ }
+ else
+ {
+ DEBUG_ERR_MSG("invalid se handle");
+
+ result = NET_NFC_INVALID_HANDLE;
+ }
+
+ data = net_nfc_util_gdbus_data_to_variant(atr);
+
+ net_nfc_gdbus_secure_element_complete_get_atr(
+ detail->object,
+ detail->invocation,
+ result,
+ data);
+
+ if (atr != NULL) {
+ net_nfc_util_free_data(atr);
+ g_free(atr);
+ }
+
+ g_object_unref(detail->invocation);
+ g_object_unref(detail->object);
+
+ g_free(detail);
+}
+
+static gboolean se_handle_get_atr(
+ NetNfcGDbusSecureElement *object,
+ GDBusMethodInvocation *invocation,
+ guint arg_handle,
+ GVariant *smack_privilege)
+{
+ SeDataHandle *data;
+ gboolean result;
+
+ INFO_MSG(">>> REQUEST from [%s]",
+ g_dbus_method_invocation_get_sender(invocation));
+
+ /* check privilege and update client context */
+ if (net_nfc_server_gdbus_check_privilege(invocation,
+ smack_privilege,
+ "nfc-manager",
+ "r") == false) {
+ DEBUG_ERR_MSG("permission denied, and finished request");
+
+ return FALSE;
+ }
+
+ data = g_new0(SeDataHandle, 1);
+ if (data == NULL)
+ {
+ DEBUG_ERR_MSG("Memory allocation failed");
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.AllocationError",
+ "Can not allocate memory");
+
+ return FALSE;
+ }
+
+ data->object = g_object_ref(object);
+ data->invocation = g_object_ref(invocation);
+ data->handle = (net_nfc_target_handle_s *)arg_handle;
+
+ result = net_nfc_server_controller_async_queue_push(
+ se_get_atr_thread_func, data);
+ if (result == FALSE)
+ {
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.Se.ThreadError",
+ "can not push to controller thread");
+
+ g_object_unref(data->object);
+ g_object_unref(data->invocation);
+
+ g_free(data);
+ }
+
+ return result;
+}
+
+static void se_open_secure_element_thread_func(gpointer user_data)
+{
+ SeDataSeType *detail = (SeDataSeType *)user_data;
+ net_nfc_target_handle_s *handle = NULL;
+ net_nfc_error_e result = NET_NFC_OK;
+
+ g_assert(detail != NULL);
+ g_assert(detail->object != NULL);
+ g_assert(detail->invocation != NULL);
+
+#if 0 /* opening SE doesn't affect card emulation */
+ gdbus_se_prev_type = net_nfc_server_se_get_se_type();
+ gdbus_se_prev_mode = net_nfc_server_se_get_se_mode();
+#endif
+
+ if (detail->se_type == SECURE_ELEMENT_TYPE_UICC)
+ {
+#if 0 /* opening SE doesn't affect card emulation */
+ /*off ESE*/
+ net_nfc_controller_set_secure_element_mode(
+ SECURE_ELEMENT_TYPE_ESE,
+ SECURE_ELEMENT_OFF_MODE, &result);
+
+ /*Off UICC. UICC SHOULD not be detected by external reader when
+ being communicated in internal process*/
+ net_nfc_controller_set_secure_element_mode(SECURE_ELEMENT_TYPE_UICC,
+ SECURE_ELEMENT_OFF_MODE, &result);
+
+ net_nfc_server_se_set_se_type(SECURE_ELEMENT_TYPE_UICC);
+ net_nfc_server_se_set_se_mode(SECURE_ELEMENT_OFF_MODE);
+#endif
+ handle = (net_nfc_target_handle_s *)_se_uicc_open();
+ if (handle != NULL)
+ {
+ result = NET_NFC_OK;
+ }
+ else
+ {
+ result = NET_NFC_INVALID_STATE;
+ handle = NULL;
+ }
+ }
+ else if (detail->se_type == SECURE_ELEMENT_TYPE_ESE)
+ {
+#if 0 /* opening SE doesn't affect card emulation */
+ /*off UICC*/
+ net_nfc_controller_set_secure_element_mode(
+ SECURE_ELEMENT_TYPE_UICC,
+ SECURE_ELEMENT_OFF_MODE, &result);
+#endif
+ handle = net_nfc_server_se_open_ese();
+ if (handle != NULL)
+ {
+ result = NET_NFC_OK;
+#if 0 /* opening SE doesn't affect card emulation */
+ net_nfc_server_se_set_se_type(SECURE_ELEMENT_TYPE_ESE);
+ net_nfc_server_se_set_se_mode(SECURE_ELEMENT_WIRED_MODE);
+
+ net_nfc_server_se_set_current_ese_handle(handle);
+#endif
+ DEBUG_SERVER_MSG("handle [%p]", handle);
+
+ /* increase client reference count */
+ net_nfc_server_gdbus_increase_se_count(
+ g_dbus_method_invocation_get_sender(
+ detail->invocation));
+ }
+ else
+ {
+ result = NET_NFC_INVALID_STATE;
+ handle = NULL;
+ }
+ }
+ else
+ {
+ result = NET_NFC_INVALID_PARAM;
+ handle = NULL;
+ }
+
+ net_nfc_gdbus_secure_element_complete_open_secure_element(
+ detail->object,
+ detail->invocation,
+ result,
+ (guint)handle);
+
+ g_object_unref(detail->invocation);
+ g_object_unref(detail->object);
+
+ g_free(detail);
+}
+
+static gboolean se_handle_open_secure_element(
+ NetNfcGDbusSecureElement *object,
+ GDBusMethodInvocation *invocation,
+ gint arg_type,
+ GVariant *smack_privilege)
+{
+ SeDataSeType *data;
+ gboolean result;
+
+ INFO_MSG(">>> REQUEST from [%s]",
+ g_dbus_method_invocation_get_sender(invocation));
+
+ /* check privilege and update client context */
+ if (net_nfc_server_gdbus_check_privilege(invocation,
+ smack_privilege,
+ "nfc-manager",
+ "rw") == false) {
+ DEBUG_ERR_MSG("permission denied, and finished request");
+
+ return FALSE;
+ }
+
+ data = g_new0(SeDataSeType, 1);
+ if (data == NULL)
+ {
+ DEBUG_ERR_MSG("Memory allocation failed");
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.AllocationError",
+ "Can not allocate memory");
+
+ return FALSE;
+ }
+
+ data->object = g_object_ref(object);
+ data->invocation = g_object_ref(invocation);
+ data->se_type= arg_type;
+
+ result = net_nfc_server_controller_async_queue_push(
+ se_open_secure_element_thread_func, data);
+ if (result == FALSE)
+ {
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.Se.ThreadError",
+ "can not push to controller thread");
+
+ g_object_unref(data->object);
+ g_object_unref(data->invocation);
+
+ g_free(data);
+ }
+
+ return result;
+}
+
+static void se_send_apdu_thread_func(gpointer user_data)
+{
+ SeDataApdu *detail = (SeDataApdu *)user_data;
+ data_s apdu_data = { NULL, 0 };
+ data_s *response = NULL;
+ net_nfc_error_e result;
+ GVariant *rspdata = NULL;
+ bool ret;
+
+ g_assert(detail != NULL);
+ g_assert(detail->object != NULL);
+ g_assert(detail->invocation != NULL);
+
+ net_nfc_util_gdbus_variant_to_data_s(detail->data, &apdu_data);
+
+ if (_se_is_uicc_handle(detail->handle) == true)
+ {
+ result = NET_NFC_NOT_SUPPORTED;
+ }
+ else if (net_nfc_server_se_is_ese_handle(detail->handle) == true)
+ {
+ ret = net_nfc_controller_secure_element_send_apdu(detail->handle,
+ &apdu_data, &response, &result);
+ if (false == ret)
+ {
+ DEBUG_ERR_MSG("net_nfc_controller_secure_element_send_apdu() Failed");
+ return;
+ }
+ }
+ else
+ {
+ result = NET_NFC_INVALID_HANDLE;
+ }
+
+ rspdata = net_nfc_util_gdbus_data_to_variant(response);
+
+ net_nfc_gdbus_secure_element_complete_send_apdu(
+ detail->object,
+ detail->invocation,
+ result,
+ rspdata);
+
+ if (response != NULL)
+ {
+ net_nfc_util_free_data(response);
+ g_free(response);
+ }
+
+ net_nfc_util_free_data(&apdu_data);
+
+ g_variant_unref(detail->data);
+
+ g_object_unref(detail->invocation);
+ g_object_unref(detail->object);
+
+ g_free(detail);
+}
+
+static gboolean se_handle_send_apdu(
+ NetNfcGDbusSecureElement *object,
+ GDBusMethodInvocation *invocation,
+ guint arg_handle,
+ GVariant *apdudata,
+ GVariant *smack_privilege)
+{
+ SeDataApdu *data;
+ gboolean result;
+
+ INFO_MSG(">>> REQUEST from [%s]",
+ g_dbus_method_invocation_get_sender(invocation));
+
+ /* check privilege and update client context */
+ if (net_nfc_server_gdbus_check_privilege(invocation,
+ smack_privilege,
+ "nfc-manager",
+ "rw") == false) {
+ DEBUG_ERR_MSG("permission denied, and finished request");
+
+ return FALSE;
+ }
+
+ data = g_new0(SeDataApdu, 1);
+ if (data == NULL)
+ {
+ DEBUG_ERR_MSG("Memory allocation failed");
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.AllocationError",
+ "Can not allocate memory");
+
+ return FALSE;
+ }
+
+ data->object = g_object_ref(object);
+ data->invocation = g_object_ref(invocation);
+ data->handle = (net_nfc_target_handle_s *)arg_handle;
+ data->data = g_variant_ref(apdudata);
+
+ result = net_nfc_server_controller_async_queue_push(
+ se_send_apdu_thread_func, data);
+ if (result == FALSE)
+ {
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.Se.ThreadError",
+ "can not push to controller thread");
+
+ g_variant_unref(data->data);
+
+ g_object_unref(data->object);
+ g_object_unref(data->invocation);
+
+ g_free(data);
+ }
+
+ return result;
+}
+
+static void se_set_data_thread_func(gpointer user_data)
+{
+ SeDataSeType *data = (SeDataSeType *)user_data;
+ gboolean isTypeChanged = FALSE;
+ net_nfc_error_e result = NET_NFC_OK;
+
+ g_assert(data != NULL);
+ g_assert(data->object != NULL);
+ g_assert(data->invocation != NULL);
+
+ if (data->se_type != net_nfc_server_se_get_se_type())
+ {
+ result = net_nfc_server_se_change_se(data->se_type);
+ isTypeChanged = TRUE;
+ }
+
+ net_nfc_gdbus_secure_element_complete_set(data->object,
+ data->invocation, result);
+
+ if (isTypeChanged)
+ net_nfc_gdbus_secure_element_emit_se_type_changed(data->object,
+ data->se_type);
+
+ g_object_unref(data->invocation);
+ g_object_unref(data->object);
+
+ g_free(data);
+}
+
+static gboolean se_handle_set(
+ NetNfcGDbusSecureElement *object,
+ GDBusMethodInvocation *invocation,
+ gint arg_type,
+ GVariant *smack_privilege)
+{
+ SeDataSeType *data;
+ gboolean result;
+
+ INFO_MSG(">>> REQUEST from [%s]",
+ g_dbus_method_invocation_get_sender(invocation));
+
+ /* check privilege and update client context */
+ if (net_nfc_server_gdbus_check_privilege(invocation,
+ smack_privilege,
+ "nfc-manager",
+ "w") == false) {
+ DEBUG_ERR_MSG("permission denied, and finished request");
+
+ return FALSE;
+ }
+
+ data = g_new0(SeDataSeType, 1);
+ if (data == NULL)
+ {
+ DEBUG_ERR_MSG("Memory allocation failed");
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.AllocationError",
+ "Can not allocate memory");
+
+ return FALSE;
+ }
+
+ data->object = g_object_ref(object);
+ data->invocation = g_object_ref(invocation);
+ data->se_type = arg_type;
+
+ result = net_nfc_server_controller_async_queue_push(
+ se_set_data_thread_func, data);
+ if (result == FALSE)
+ {
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.Se.ThreadError",
+ "can not push to controller thread");
+
+ g_object_unref(data->object);
+ g_object_unref(data->invocation);
+
+ g_free(data);
+ }
+
+ return result;
+}
+
+gboolean net_nfc_server_se_init(GDBusConnection *connection)
+{
+ GError *error = NULL;
+ gboolean result;
+
+ if (se_skeleton)
+ g_object_unref(se_skeleton);
+
+ /* initialize UICC */
+ _se_uicc_init();
+
+ se_skeleton = net_nfc_gdbus_secure_element_skeleton_new();
+
+ g_signal_connect(se_skeleton,
+ "handle-set",
+ G_CALLBACK(se_handle_set),
+ NULL);
+ g_signal_connect(se_skeleton,
+ "handle-open-secure-element",
+ G_CALLBACK(se_handle_open_secure_element),
+ NULL);
+
+ g_signal_connect(se_skeleton,
+ "handle-close-secure-element",
+ G_CALLBACK(se_handle_close_secure_element),
+ NULL);
+
+ g_signal_connect(se_skeleton,
+ "handle-get-atr",
+ G_CALLBACK(se_handle_get_atr),
+ NULL);
+
+ g_signal_connect(se_skeleton,
+ "handle-send-apdu",
+ G_CALLBACK(se_handle_send_apdu),
+ NULL);
+
+ result = g_dbus_interface_skeleton_export(
+ G_DBUS_INTERFACE_SKELETON(se_skeleton),
+ connection,
+ "/org/tizen/NetNfcService/SecureElement",
+ &error);
+ if (result == FALSE)
+ {
+ DEBUG_ERR_MSG("can not skeleton_export %s", error->message);
+
+ g_error_free(error);
+
+ net_nfc_server_se_deinit();
+ }
+
+ return result;
+}
+
+void net_nfc_server_se_deinit(void)
+{
+ if (se_skeleton)
+ {
+ g_object_unref(se_skeleton);
+ se_skeleton = NULL;
+
+ /* de-initialize UICC */
+ _se_uicc_deinit();
+ }
+}
+
+static void se_detected_thread_func(gpointer user_data)
+{
+ net_nfc_target_handle_s *handle;
+ uint32_t devType;
+ GVariant *data;
+ net_nfc_error_e result;
+
+ g_assert(user_data != NULL);
+
+ if (se_skeleton == NULL)
+ {
+ DEBUG_ERR_MSG("se skeleton is not initialized");
+
+ g_variant_unref((GVariant *)user_data);
+
+ return;
+ }
+
+ g_variant_get((GVariant *)user_data,
+ "uu@a(y)",
+ (guint *)&handle,
+ &devType,
+ &data);
+
+ net_nfc_server_se_set_current_ese_handle(handle);
+
+ DEBUG_SERVER_MSG("trying to connect to ESE = [0x%p]", handle);
+
+ if (!net_nfc_controller_connect(handle, &result))
+ {
+ DEBUG_SERVER_MSG("connect failed = [%d]", result);
+ }
+
+ net_nfc_gdbus_secure_element_emit_ese_detected(
+ se_skeleton,
+ GPOINTER_TO_UINT(handle),
+ devType,
+ data);
+
+ g_variant_unref((GVariant *)user_data);
+}
+
+static void se_transcation_thread_func(gpointer user_data)
+{
+ ServerSeData *detail = (ServerSeData *)user_data;
+
+ g_assert(user_data != NULL);
+
+ if (detail->event == NET_NFC_MESSAGE_SE_START_TRANSACTION)
+ {
+ DEBUG_SERVER_MSG("launch se app");
+
+ net_nfc_app_util_launch_se_transaction_app(
+ detail->aid.buffer,
+ detail->aid.length,
+ detail->param.buffer,
+ detail->param.length);
+
+ DEBUG_SERVER_MSG("launch se app end");
+ }
+
+ net_nfc_util_free_data(&detail->param);
+ net_nfc_util_free_data(&detail->aid);
+
+ g_free(detail);
+}
+
+void net_nfc_server_se_detected(void *info)
+{
+ net_nfc_request_target_detected_t *se_target =
+ (net_nfc_request_target_detected_t *)info;
+ GVariant *parameter;
+ GVariant *data;
+
+ data = net_nfc_util_gdbus_buffer_to_variant(
+ se_target->target_info_values.buffer,
+ se_target->target_info_values.length);
+
+ parameter = g_variant_new("uu@a(y)",
+ GPOINTER_TO_UINT(se_target->handle),
+ se_target->devType,
+ data);
+ if (parameter != NULL) {
+ if (net_nfc_server_controller_async_queue_push(
+ se_detected_thread_func,
+ parameter) == FALSE) {
+ DEBUG_ERR_MSG("can not push to controller thread");
+
+ g_variant_unref(parameter);
+ }
+ } else {
+ DEBUG_ERR_MSG("g_variant_new failed");
+ }
+
+ /* FIXME : should be removed when plugins would be fixed*/
+ _net_nfc_util_free_mem(info);
+}
+
+void net_nfc_server_se_transaction_received(void *info)
+{
+ net_nfc_request_se_event_t *se_event =
+ (net_nfc_request_se_event_t *)info;
+ ServerSeData *detail;
+
+ detail = g_new0(ServerSeData, 1);
+ if (detail != NULL) {
+ detail->event = se_event->request_type;
+
+ if (se_event->aid.buffer != NULL && se_event->aid.length > 0) {
+ if (net_nfc_util_alloc_data(&detail->aid,
+ se_event->aid.length) == true) {
+ memcpy(detail->aid.buffer, se_event->aid.buffer,
+ se_event->aid.length);
+ }
+ }
+
+ if (se_event->param.buffer != NULL &&
+ se_event->param.length > 0) {
+ if (net_nfc_util_alloc_data(&detail->param,
+ se_event->param.length) == true) {
+ memcpy(detail->param.buffer,
+ se_event->param.buffer,
+ se_event->param.length);
+ }
+ }
+
+ if (net_nfc_server_controller_async_queue_push(
+ se_transcation_thread_func, detail) == FALSE) {
+ DEBUG_ERR_MSG("can not push to controller thread");
+
+ net_nfc_util_free_data(&detail->param);
+ net_nfc_util_free_data(&detail->aid);
+
+ g_free(detail);
+ }
+ } else {
+ DEBUG_ERR_MSG("g_new0 failed");
+ }
+
+ /* FIXME : should be removed when plugins would be fixed*/
+ net_nfc_util_free_data(&se_event->param);
+ net_nfc_util_free_data(&se_event->aid);
+
+ _net_nfc_util_free_mem(info);
+}
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_SERVER_SE_H__
+#define __NET_NFC_SERVER_SE_H__
+
+#include <gio/gio.h>
+
+#include "net_nfc_typedef_internal.h"
+
+
+/***************************************************************/
+
+uint8_t net_nfc_server_se_get_se_type();
+
+uint8_t net_nfc_server_se_get_se_mode();
+
+net_nfc_error_e net_nfc_server_se_change_se(uint8_t type);
+
+/***************************************************************/
+
+gboolean net_nfc_server_se_init(GDBusConnection *connection);
+
+void net_nfc_server_se_deinit(void);
+
+void net_nfc_server_se_detected(void *info);
+
+void net_nfc_server_se_transaction_received(void *info);
+
+#endif //__NET_NFC_SERVER_SE_H__
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <glib.h>
+
+#include "net_nfc_debug_internal.h"
+#include "net_nfc_util_defines.h"
+#include "net_nfc_util_internal.h"
+#include "net_nfc_server_controller.h"
+#include "net_nfc_server_common.h"
+#include "net_nfc_server_llcp.h"
+#include "net_nfc_server_snep.h"
+#include "net_nfc_server_process_snep.h"
+#include "net_nfc_util_gdbus_internal.h"
+#include "net_nfc_server_context.h"
+
+/* declaration */
+static gboolean _handle_start_server(
+ NetNfcGDbusSnep *object,
+ GDBusMethodInvocation *invocation,
+ guint arg_handle,
+ guint arg_sap,
+ const gchar *arg_san,
+ guint arg_user_data,
+ GVariant *arg_privilege);
+
+static gboolean _handle_start_client(
+ NetNfcGDbusSnep *object,
+ GDBusMethodInvocation *invocation,
+ guint arg_handle,
+ guint arg_sap,
+ const gchar *arg_san,
+ guint arg_user_data,
+ GVariant *arg_privilege);
+
+static gboolean _handle_client_send_request(
+ NetNfcGDbusSnep *object,
+ GDBusMethodInvocation *invocation,
+ guint arg_snep_handle,
+ guint arg_type,
+ GVariant *arg_ndef_msg,
+ GVariant *arg_privilege);
+
+static gboolean _handle_stop_snep(
+ NetNfcGDbusSnep *object,
+ GDBusMethodInvocation *invocation,
+ guint arg_handle,
+ guint arg_snep_handle,
+ GVariant *arg_privilege);
+
+static void snep_server_start_thread_func(gpointer user_data);
+
+static void snep_client_start_thread_func(gpointer user_data);
+
+static void snep_client_send_request_thread_func(gpointer user_data);
+
+static void snep_stop_service_thread_func(gpointer user_data);
+
+/* definition */
+static NetNfcGDbusSnep *snep_skeleton = NULL;
+
+static void _emit_snep_event_signal(GVariant *parameter,
+ net_nfc_snep_handle_h handle,
+ net_nfc_error_e result,
+ uint32_t type,
+ data_s *data)
+{
+ GDBusConnection *connection;
+ char *client_id;
+ void *user_data;
+ GVariant *arg_data;
+ GError *error = NULL;
+
+ g_variant_get(parameter, "(usu)",
+ (guint *)&connection,
+ &client_id,
+ (guint *)&user_data);
+
+ arg_data = net_nfc_util_gdbus_data_to_variant(data);
+
+ if (g_dbus_connection_emit_signal(
+ connection,
+ client_id,
+ "/org/tizen/NetNfcService/Snep",
+ "org.tizen.NetNfcService.Snep",
+ "SnepEvent",
+ g_variant_new("(uui@a(y)u)",
+ GPOINTER_TO_UINT(handle),
+ type,
+ (gint)result,
+ arg_data,
+ GPOINTER_TO_UINT(user_data)),
+ &error) == false) {
+ if (error != NULL && error->message != NULL) {
+ DEBUG_ERR_MSG("g_dbus_connection_emit_signal failed : %s", error->message);
+ } else {
+ DEBUG_ERR_MSG("g_dbus_connection_emit_signal failed");
+ }
+ }
+
+ g_free(client_id);
+}
+
+static net_nfc_error_e _snep_server_cb(net_nfc_snep_handle_h handle,
+ net_nfc_error_e result,
+ uint32_t type,
+ data_s *data,
+ void *user_param)
+{
+ GVariant *parameter = (GVariant *)user_param;
+
+ data_s *temp = data;
+
+ DEBUG_SERVER_MSG("type [%d], result [%d], data [%p], user_param [%p]",
+ type, result, data, user_param);
+
+ switch (type)
+ {
+ case SNEP_REQ_GET :
+ {
+ uint32_t max_len = 0;
+
+ net_nfc_server_snep_parse_get_request(data, &max_len,
+ temp);
+ }
+ break;
+
+ case SNEP_REQ_PUT :
+ break;
+
+ default :
+ DEBUG_ERR_MSG("error [%d]", result);
+ break;
+ }
+
+ if (result < NET_NFC_OK) {
+ type = NET_NFC_LLCP_STOP;
+ }
+
+ _emit_snep_event_signal(parameter, handle,
+ result, type, data);
+
+ if (type == NET_NFC_LLCP_STOP) {
+ g_object_unref(parameter);
+ }
+
+ return result;
+}
+
+static void snep_server_start_thread_func(gpointer user_data)
+{
+ NetNfcGDbusSnep *object;
+ GDBusMethodInvocation *invocation;
+ net_nfc_target_handle_s *arg_handle;
+ guint arg_sap;
+ gchar *arg_san;
+ void *arg_user_data;
+ net_nfc_error_e result;
+
+ GVariant *parameter;
+ GDBusConnection *connection;
+
+ if (user_data == NULL)
+ {
+ DEBUG_ERR_MSG("cannot get SNEP client data");
+
+ return;
+ }
+
+ g_variant_get((GVariant *)user_data,
+ "(uuuusu)",
+ (guint *)&object,
+ (guint *)&invocation,
+ (guint *)&arg_handle,
+ &arg_sap,
+ &arg_san,
+ (guint *)&arg_user_data);
+
+ g_assert(object != NULL);
+ g_assert(invocation != NULL);
+
+ connection = g_dbus_method_invocation_get_connection(invocation);
+
+ parameter = g_variant_new("(usu)",
+ GPOINTER_TO_UINT(g_object_ref(connection)),
+ g_dbus_method_invocation_get_sender(invocation),
+ GPOINTER_TO_UINT(arg_user_data));
+ if (parameter != NULL) {
+ result = net_nfc_server_snep_server(arg_handle,
+ arg_san,
+ arg_sap,
+ _snep_server_cb,
+ parameter);
+ if (result != NET_NFC_OK) {
+ DEBUG_ERR_MSG("net_nfc_server_snep_server failed, [%d]",
+ result);
+ g_object_unref(connection);
+
+ g_variant_unref(parameter);
+ }
+ } else {
+ DEBUG_ERR_MSG("g_variant_new failed");
+
+ g_object_unref(connection);
+
+ result = NET_NFC_ALLOC_FAIL;
+ }
+
+ net_nfc_gdbus_snep_complete_server_start(object, invocation, result);
+
+ g_free(arg_san);
+
+ g_variant_unref(user_data);
+}
+
+static gboolean _handle_start_server(
+ NetNfcGDbusSnep *object,
+ GDBusMethodInvocation *invocation,
+ guint arg_handle,
+ guint arg_sap,
+ const gchar *arg_san,
+ guint arg_user_data,
+ GVariant *arg_privilege)
+{
+ GVariant *parameter;
+ gboolean result;
+
+ INFO_MSG(">>> REQUEST from [%s]",
+ g_dbus_method_invocation_get_sender(invocation));
+
+ /* check privilege and update client context */
+ if (net_nfc_server_gdbus_check_privilege(invocation,
+ arg_privilege,
+ "nfc-manager::p2p",
+ "rw") == false) {
+ DEBUG_ERR_MSG("permission denied, and finished request");
+
+ return FALSE;
+ }
+
+ parameter = g_variant_new("(uuuusu)",
+ GPOINTER_TO_UINT(g_object_ref(object)),
+ GPOINTER_TO_UINT(g_object_ref(invocation)),
+ arg_handle,
+ arg_sap,
+ arg_san,
+ arg_user_data);
+
+ if (parameter != NULL)
+ {
+ if ((result = net_nfc_server_controller_async_queue_push(
+ snep_server_start_thread_func, parameter)) == FALSE)
+ {
+ DEBUG_ERR_MSG("net_nfc_server_controller_async_queue_push failed");
+
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.Snep.ThreadError",
+ "can not push to controller thread");
+
+ g_object_unref(invocation);
+ g_object_unref(object);
+
+ g_variant_unref(parameter);
+ }
+ }
+ else
+ {
+ DEBUG_ERR_MSG("g_variant_new failed");
+
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.Snep.MemoryError",
+ "Out of memory");
+
+ result = FALSE;
+ }
+
+ return result;
+}
+
+static net_nfc_error_e _snep_start_client_cb(
+ net_nfc_snep_handle_h handle,
+ net_nfc_error_e result,
+ uint32_t type,
+ data_s *data,
+ void *user_param)
+{
+ GVariant *parameter = (GVariant *)user_param;
+
+ DEBUG_SERVER_MSG("type [%d], result [%d], data [%p], user_param [%p]",
+ type, result, data, user_param);
+
+ _emit_snep_event_signal(parameter, handle, result, type, data);
+
+ if (type == NET_NFC_LLCP_STOP) {
+ g_variant_unref(parameter);
+ }
+
+ return result;
+}
+
+static void snep_client_start_thread_func(gpointer user_data)
+{
+ NetNfcGDbusSnep *object;
+ GDBusMethodInvocation *invocation;
+ net_nfc_target_handle_s *arg_handle;
+ guint arg_sap;
+ gchar *arg_san;
+ void *arg_user_data;
+ net_nfc_error_e result;
+
+ GVariant *parameter;
+ GDBusConnection *connection;
+
+ if (user_data == NULL)
+ {
+ DEBUG_ERR_MSG("cannot get SNEP client data");
+
+ return;
+ }
+
+ g_variant_get((GVariant *)user_data,
+ "(uuuusu)",
+ (guint *)&object,
+ (guint *)&invocation,
+ (guint *)&arg_handle,
+ &arg_sap,
+ &arg_san,
+ (guint *)&arg_user_data);
+
+ g_assert(object != NULL);
+ g_assert(invocation != NULL);
+
+ connection = g_dbus_method_invocation_get_connection(invocation);
+
+ parameter = g_variant_new("(usu)",
+ GPOINTER_TO_UINT(g_object_ref(connection)),
+ g_dbus_method_invocation_get_sender(invocation),
+ GPOINTER_TO_UINT(arg_user_data));
+ if (parameter != NULL) {
+ result = net_nfc_server_snep_client(arg_handle,
+ arg_san,
+ arg_sap,
+ _snep_start_client_cb,
+ parameter);
+ if (result != NET_NFC_OK) {
+ DEBUG_ERR_MSG("net_nfc_server_snep_client failed, [%d]",
+ result);
+ g_object_unref(connection);
+
+ g_variant_unref(parameter);
+ }
+ } else {
+ DEBUG_ERR_MSG("g_variant_new failed");
+
+ g_object_unref(connection);
+
+ result = NET_NFC_ALLOC_FAIL;
+ }
+
+ net_nfc_gdbus_snep_complete_client_start(object, invocation, result);
+
+ g_free(arg_san);
+
+ g_variant_unref(user_data);
+}
+
+static gboolean _handle_start_client(
+ NetNfcGDbusSnep *object,
+ GDBusMethodInvocation *invocation,
+ guint arg_handle,
+ guint arg_sap,
+ const gchar *arg_san,
+ guint arg_user_data,
+ GVariant *arg_privilege)
+{
+ GVariant *parameter;
+ gboolean result;
+
+ INFO_MSG(">>> REQUEST from [%s]",
+ g_dbus_method_invocation_get_sender(invocation));
+
+ /* check privilege and update client context */
+ if (net_nfc_server_gdbus_check_privilege(invocation,
+ arg_privilege,
+ "nfc-manager::p2p",
+ "rw") == false) {
+ DEBUG_ERR_MSG("permission denied, and finished request");
+
+ return FALSE;
+ }
+
+ parameter = g_variant_new("(uuuusu)",
+ GPOINTER_TO_UINT(g_object_ref(object)),
+ GPOINTER_TO_UINT(g_object_ref(invocation)),
+ arg_handle,
+ arg_sap,
+ arg_san,
+ arg_user_data);
+
+ if (parameter != NULL)
+ {
+ if ((result = net_nfc_server_controller_async_queue_push(
+ snep_client_start_thread_func, parameter)) == FALSE)
+ {
+ DEBUG_ERR_MSG("net_nfc_server_controller_async_queue_push failed");
+
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.Snep.ThreadError",
+ "can not push to controller thread");
+
+ g_object_unref(invocation);
+ g_object_unref(object);
+
+ g_object_unref(g_variant_unref);
+ }
+ }
+ else
+ {
+ DEBUG_ERR_MSG("g_variant_new failed");
+
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.Snep.MemoryError",
+ "Out of memory");
+
+ result = FALSE;
+ }
+
+ return result;
+}
+
+static net_nfc_error_e _snep_client_request_cb(
+ net_nfc_snep_handle_h handle,
+ net_nfc_error_e result,
+ net_nfc_snep_type_t type,
+ data_s *data,
+ void *user_param)
+{
+ GVariant *parameter = (GVariant *)user_param;
+
+ DEBUG_SERVER_MSG("type [%d], result [%d], data [%p], user_param [%p]",
+ type, result, data, user_param);
+
+ if (parameter != NULL) {
+ NetNfcGDbusSnep *object;
+ GDBusMethodInvocation *invocation;
+ net_nfc_snep_handle_h arg_snep_handle;
+ net_nfc_snep_type_t arg_type;
+ GVariant *arg_ndef_msg;
+ GVariant *arg_data = NULL;
+
+ g_variant_get(parameter,
+ "(uuuu@a(y))",
+ (guint *)&object,
+ (guint *)&invocation,
+ (guint *)&arg_snep_handle,
+ (guint *)&arg_type,
+ &arg_ndef_msg);
+
+ if (data != NULL && data->buffer != NULL && data->length > 0) {
+ arg_data = net_nfc_util_gdbus_data_to_variant(data);
+ } else {
+ arg_data = net_nfc_util_gdbus_buffer_to_variant(NULL, 0);
+ }
+
+ net_nfc_gdbus_snep_complete_client_request(object,
+ invocation,
+ result,
+ type,
+ arg_data);
+
+ g_variant_unref(arg_ndef_msg);
+
+ g_object_unref(invocation);
+ g_object_unref(object);
+
+ g_variant_unref(parameter);
+
+ result = NET_NFC_OK;
+ } else {
+ result = NET_NFC_NULL_PARAMETER;
+ }
+
+ return result;
+}
+
+static void snep_client_send_request_thread_func(gpointer user_data)
+{
+ NetNfcGDbusSnep *object;
+ GDBusMethodInvocation *invocation;
+ net_nfc_snep_handle_h arg_snep_handle;
+ net_nfc_snep_type_t arg_type;
+ GVariant *arg_ndef_msg;
+ data_s data = { NULL, };
+ net_nfc_error_e result;
+
+ if (user_data == NULL)
+ {
+ DEBUG_ERR_MSG("cannot get SNEP client data");
+
+ return;
+ }
+
+ g_variant_get((GVariant *)user_data,
+ "(uuuu@a(y))",
+ (guint *)&object,
+ (guint *)&invocation,
+ (guint *)&arg_snep_handle,
+ (guint *)&arg_type,
+ &arg_ndef_msg);
+
+ g_assert(object != NULL);
+ g_assert(invocation != NULL);
+
+ net_nfc_util_gdbus_variant_to_data_s(arg_ndef_msg, &data);
+
+ result = net_nfc_server_snep_client_request(arg_snep_handle,
+ arg_type,
+ &data,
+ _snep_client_request_cb,
+ user_data);
+ if (result != NET_NFC_OK)
+ {
+ GVariant *resp;
+
+ DEBUG_ERR_MSG("net_nfc_server_snep_client_request "
+ "failed, [%d]",result);
+
+ resp = net_nfc_util_gdbus_buffer_to_variant(NULL, 0);
+
+ net_nfc_gdbus_snep_complete_client_request(object,
+ invocation, result, NET_NFC_LLCP_STOP, resp);
+
+ g_object_unref(invocation);
+ g_object_unref(object);
+
+ g_variant_unref(user_data);
+ }
+
+ net_nfc_util_free_data(&data);
+
+ g_variant_unref(arg_ndef_msg);
+}
+
+static gboolean _handle_client_send_request(
+ NetNfcGDbusSnep *object,
+ GDBusMethodInvocation *invocation,
+ guint arg_snep_handle,
+ guint arg_type,
+ GVariant *arg_ndef_msg,
+ GVariant *arg_privilege)
+{
+ GVariant *parameter;
+ gboolean result;
+
+ INFO_MSG(">>> REQUEST from [%s]",
+ g_dbus_method_invocation_get_sender(invocation));
+
+ /* check privilege and update client context */
+ if (net_nfc_server_gdbus_check_privilege(invocation,
+ arg_privilege,
+ "nfc-manager::p2p",
+ "rw") == false) {
+ DEBUG_ERR_MSG("permission denied, and finished request");
+
+ return FALSE;
+ }
+
+ parameter = g_variant_new("(uuuu@a(y))",
+ GPOINTER_TO_UINT(g_object_ref(object)),
+ GPOINTER_TO_UINT(g_object_ref(invocation)),
+ arg_snep_handle,
+ arg_type,
+ arg_ndef_msg);
+
+ if (parameter != NULL)
+ {
+ if ((result = net_nfc_server_controller_async_queue_push(
+ snep_client_send_request_thread_func, parameter)) == FALSE)
+ {
+ DEBUG_ERR_MSG("net_nfc_server_controller_async_queue_push failed");
+
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.Snep.ThreadError",
+ "can not push to controller thread");
+
+ g_object_unref(invocation);
+ g_object_unref(object);
+
+ g_variant_unref(parameter);
+ }
+ }
+ else
+ {
+ DEBUG_ERR_MSG("g_variant_new failed");
+
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.Snep.MemoryError",
+ "Out of memory");
+
+ result = FALSE;
+ }
+
+ return result;
+}
+
+static void snep_stop_service_thread_func(gpointer user_data)
+{
+ NetNfcGDbusSnep *object;
+ GDBusMethodInvocation *invocation;
+ net_nfc_target_handle_s *handle;
+ net_nfc_snep_handle_h snep_handle;
+
+ if (user_data == NULL)
+ {
+ DEBUG_ERR_MSG("cannot get SNEP client data");
+
+ return;
+ }
+
+ g_variant_get((GVariant *)user_data,
+ "(uuuu)",
+ (guint *)&object,
+ (guint *)&invocation,
+ (guint *)&handle,
+ (guint *)&snep_handle);
+
+ g_assert(object != NULL);
+ g_assert(invocation != NULL);
+
+ /* TODO :
+ g_dbus_method_invocation_return_dbus_error(
+ invocation,
+ "org.tizen.NetNfcService.Snep.DataError",
+ "Cannot stop SNEP service");
+ */
+
+ net_nfc_gdbus_snep_complete_stop_snep(object,
+ invocation,
+ NET_NFC_OK);
+
+ g_object_unref(invocation);
+ g_object_unref(object);
+
+ g_variant_unref(user_data);
+}
+
+static gboolean _handle_stop_snep(
+ NetNfcGDbusSnep *object,
+ GDBusMethodInvocation *invocation,
+ guint arg_handle,
+ guint arg_snep_handle,
+ GVariant *arg_privilege)
+{
+ GVariant *parameter;
+ gboolean result;
+
+ INFO_MSG(">>> REQUEST from [%s]",
+ g_dbus_method_invocation_get_sender(invocation));
+
+ /* check privilege and update client context */
+ if (net_nfc_server_gdbus_check_privilege(invocation,
+ arg_privilege,
+ "nfc-manager::p2p",
+ "rw") == false) {
+ DEBUG_ERR_MSG("permission denied, and finished request");
+
+ return FALSE;
+ }
+
+ parameter = g_variant_new("(uuuu)",
+ GPOINTER_TO_UINT(g_object_ref(object)),
+ GPOINTER_TO_UINT(g_object_ref(invocation)),
+ arg_handle,
+ arg_snep_handle);
+
+ if (parameter != NULL)
+ {
+ if ((result = net_nfc_server_controller_async_queue_push(
+ snep_stop_service_thread_func, parameter)) == FALSE)
+ {
+ DEBUG_ERR_MSG("net_nfc_server_controller_async_queue_push failed");
+
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.Snep.ThreadError",
+ "can not push to controller thread");
+
+ g_object_unref(invocation);
+ g_object_unref(object);
+
+ g_variant_unref(parameter);
+ }
+ }
+ else
+ {
+ DEBUG_ERR_MSG("g_variant_new failed");
+
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.Snep.MemoryError",
+ "Out of memory");
+
+ result = FALSE;
+ }
+
+ return result;
+}
+
+static void _snep_activate_cb(int event, net_nfc_target_handle_s *handle,
+ uint32_t sap, const char *san, void *user_param)
+{
+ GVariant *parameter = (GVariant *)user_param;
+ net_nfc_error_e result = NET_NFC_OK;
+
+ DEBUG_SERVER_MSG("event [%d], handle [%p], sap [%d], san [%s]",
+ event, handle, sap, san);
+
+ if (event == NET_NFC_LLCP_START) {
+ GDBusConnection *connection;
+ GVariant *param = NULL;
+ char *client_id;
+ void *user_data;
+
+ /* start server */
+ g_variant_get(parameter, "(usu)",
+ (guint *)&connection,
+ &client_id,
+ (guint *)&user_data);
+
+ param = g_variant_new("(usu)",
+ GPOINTER_TO_UINT(g_object_ref(connection)),
+ client_id,
+ GPOINTER_TO_UINT(user_data));
+
+ g_free(client_id);
+
+ result = net_nfc_server_snep_server(handle, (char *)san, sap,
+ _snep_server_cb, param);
+ if (result == NET_NFC_OK) {
+ _emit_snep_event_signal(parameter, handle,
+ result, event, NULL);
+ } else {
+ DEBUG_ERR_MSG("net_nfc_server_snep_server failed, [%d]",
+ result);
+
+ g_variant_unref(param);
+ }
+ } else {
+ _emit_snep_event_signal(parameter, handle,
+ result, NET_NFC_LLCP_UNREGISTERED, NULL);
+
+ /* unregister server */
+ g_variant_unref(parameter);
+ }
+}
+
+static void snep_register_server_thread_func(gpointer user_data)
+{
+ NetNfcGDbusSnep *object;
+ GDBusMethodInvocation *invocation;
+ guint arg_sap;
+ gchar *arg_san;
+ guint arg_user_data;
+
+ net_nfc_error_e result;
+ GVariant *parameter = NULL;
+ GDBusConnection *connection;
+
+ g_assert(user_data != NULL);
+
+ g_variant_get((GVariant *)user_data,
+ "(uuusu)",
+ (guint *)&object,
+ (guint *)&invocation,
+ &arg_sap,
+ &arg_san,
+ &arg_user_data);
+
+ g_assert(object != NULL);
+ g_assert(invocation != NULL);
+
+ connection = g_dbus_method_invocation_get_connection(invocation);
+
+ parameter = g_variant_new("(usu)",
+ GPOINTER_TO_UINT(g_object_ref(connection)),
+ g_dbus_method_invocation_get_sender(invocation),
+ arg_user_data);
+ if (parameter != NULL) {
+ /* register default snep server */
+ result = net_nfc_server_llcp_register_service(
+ g_dbus_method_invocation_get_sender(invocation),
+ arg_sap,
+ arg_san,
+ _snep_activate_cb,
+ parameter);
+ if (result != NET_NFC_OK) {
+ DEBUG_ERR_MSG("net_nfc_service_llcp_register_service failed, [%d]", result);
+ g_object_unref(connection);
+ g_variant_unref(parameter);
+ }
+ } else {
+ result = NET_NFC_ALLOC_FAIL;
+ g_object_unref(connection);
+ }
+
+ net_nfc_gdbus_snep_complete_server_register(object,
+ invocation,
+ result);
+
+ g_free(arg_san);
+
+ g_object_unref(invocation);
+ g_object_unref(object);
+
+ g_variant_unref(user_data);
+}
+
+static gboolean _handle_register_server(
+ NetNfcGDbusSnep *object,
+ GDBusMethodInvocation *invocation,
+ guint arg_sap,
+ const gchar *arg_san,
+ guint arg_user_data,
+ GVariant *arg_privilege)
+{
+ GVariant *parameter;
+ gboolean result;
+
+ INFO_MSG(">>> REQUEST from [%s]",
+ g_dbus_method_invocation_get_sender(invocation));
+
+ /* check privilege and update client context */
+ if (net_nfc_server_gdbus_check_privilege(invocation,
+ arg_privilege,
+ "nfc-manager::p2p",
+ "rw") == false) {
+ DEBUG_ERR_MSG("permission denied, and finished request");
+
+ return FALSE;
+ }
+
+ parameter = g_variant_new("(uuusu)",
+ GPOINTER_TO_UINT(g_object_ref(object)),
+ GPOINTER_TO_UINT(g_object_ref(invocation)),
+ arg_sap,
+ arg_san,
+ arg_user_data);
+
+ if (parameter != NULL)
+ {
+ if ((result = net_nfc_server_controller_async_queue_push(
+ snep_register_server_thread_func, parameter)) == FALSE)
+ {
+ DEBUG_ERR_MSG("net_nfc_server_controller_async_queue_push failed");
+
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.Snep.ThreadError",
+ "can not push to controller thread");
+
+ g_object_unref(invocation);
+ g_object_unref(object);
+
+ g_variant_unref(parameter);
+ }
+ }
+ else
+ {
+ DEBUG_ERR_MSG("g_variant_new failed");
+
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.Snep.MemoryError",
+ "Out of memory");
+
+ result = FALSE;
+ }
+
+ return result;
+}
+
+static void snep_unregister_server_thread_func(gpointer user_data)
+{
+ NetNfcGDbusSnep *object;
+ GDBusMethodInvocation *invocation;
+ guint arg_sap;
+ gchar *arg_san;
+
+ net_nfc_error_e result;
+
+ g_assert(user_data != NULL);
+
+ g_variant_get((GVariant *)user_data,
+ "(uuus)",
+ (guint *)&object,
+ (guint *)&invocation,
+ &arg_sap,
+ &arg_san);
+
+ g_assert(object != NULL);
+ g_assert(invocation != NULL);
+
+ result = net_nfc_server_llcp_unregister_service(
+ g_dbus_method_invocation_get_sender(invocation),
+ arg_sap,
+ arg_san);
+
+ net_nfc_gdbus_snep_complete_server_unregister(object,
+ invocation,
+ result);
+
+ g_free(arg_san);
+
+ g_object_unref(invocation);
+ g_object_unref(object);
+
+ g_variant_unref(user_data);
+}
+
+static gboolean _handle_unregister_server(
+ NetNfcGDbusSnep *object,
+ GDBusMethodInvocation *invocation,
+ guint arg_sap,
+ const gchar *arg_san,
+ GVariant *arg_privilege)
+{
+ GVariant *parameter;
+ gboolean result;
+
+ INFO_MSG(">>> REQUEST from [%s]",
+ g_dbus_method_invocation_get_sender(invocation));
+
+ /* check privilege and update client context */
+ if (net_nfc_server_gdbus_check_privilege(invocation,
+ arg_privilege,
+ "nfc-manager::p2p",
+ "rw") == false) {
+ DEBUG_ERR_MSG("permission denied, and finished request");
+
+ return FALSE;
+ }
+
+ parameter = g_variant_new("(uuus)",
+ GPOINTER_TO_UINT(g_object_ref(object)),
+ GPOINTER_TO_UINT(g_object_ref(invocation)),
+ arg_sap,
+ arg_san);
+
+ if (parameter != NULL)
+ {
+ if ((result = net_nfc_server_controller_async_queue_push(
+ snep_unregister_server_thread_func, parameter)) == FALSE)
+ {
+ DEBUG_ERR_MSG("net_nfc_server_controller_async_queue_push failed");
+
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.Snep.ThreadError",
+ "can not push to controller thread");
+
+ g_object_unref(invocation);
+ g_object_unref(object);
+
+ g_variant_unref(parameter);
+ }
+ }
+ else
+ {
+ DEBUG_ERR_MSG("g_variant_new failed");
+
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.Snep.MemoryError",
+ "Out of memory");
+
+ result = FALSE;
+ }
+
+ return result;
+}
+
+gboolean net_nfc_server_snep_init(GDBusConnection *connection)
+{
+ GError *error = NULL;
+ gboolean result;
+
+ if (snep_skeleton)
+ g_object_unref(snep_skeleton);
+
+ snep_skeleton = net_nfc_gdbus_snep_skeleton_new();
+
+ g_signal_connect(snep_skeleton,
+ "handle-server-register",
+ G_CALLBACK(_handle_register_server),
+ NULL);
+
+ g_signal_connect(snep_skeleton,
+ "handle-server-unregister",
+ G_CALLBACK(_handle_unregister_server),
+ NULL);
+
+ g_signal_connect(snep_skeleton,
+ "handle-server-start",
+ G_CALLBACK(_handle_start_server),
+ NULL);
+
+ g_signal_connect(snep_skeleton,
+ "handle-client-start",
+ G_CALLBACK(_handle_start_client),
+ NULL);
+
+ g_signal_connect(snep_skeleton,
+ "handle-client-request",
+ G_CALLBACK(_handle_client_send_request),
+ NULL);
+
+ g_signal_connect(snep_skeleton,
+ "handle-stop-snep",
+ G_CALLBACK(_handle_stop_snep),
+ NULL);
+
+ result = g_dbus_interface_skeleton_export(
+ G_DBUS_INTERFACE_SKELETON(snep_skeleton),
+ connection,
+ "/org/tizen/NetNfcService/Snep",
+ &error);
+ if (result == FALSE)
+ {
+ g_error_free(error);
+
+ net_nfc_server_snep_deinit();
+ }
+
+ return result;
+}
+
+void net_nfc_server_snep_deinit(void)
+{
+ if (snep_skeleton)
+ {
+ g_object_unref(snep_skeleton);
+ snep_skeleton = NULL;
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_SERVER_SNEP_H__
+#define __NET_NFC_SERVER_SNEP_H__
+
+#include "net_nfc_gdbus.h"
+#include "net_nfc_typedef_internal.h"
+
+gboolean net_nfc_server_snep_init(GDBusConnection *connection);
+
+void net_nfc_server_snep_deinit(void);
+
+#endif //__NET_NFC_SERVER_SNEP_H__
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include "net_nfc_gdbus.h"
+#include "net_nfc_debug_internal.h"
+#include "net_nfc_server_common.h"
+#include "net_nfc_server_context.h"
+#include "net_nfc_server_system_handler.h"
+
+
+static NetNfcGDbusPopup *popup_skeleton = NULL;
+
+static gboolean popup_handle_set(NetNfcGDbusPopup *popup_manager,
+ GDBusMethodInvocation *invocation,
+ gboolean state,
+ gint focus_state,
+ GVariant *smack_privilege,
+ gpointer user_data);
+
+static gboolean popup_handle_get(NetNfcGDbusPopup *popup_manager,
+ GDBusMethodInvocation *invocation,
+ GVariant *smack_privilege,
+ gpointer user_data);
+
+static gboolean popup_handle_set(NetNfcGDbusPopup *popup_manager,
+ GDBusMethodInvocation *invocation,
+ gboolean state,
+ gint focus_state,
+ GVariant *smack_privilege,
+ gpointer user_data)
+{
+ INFO_MSG(">>> REQUEST from [%s]",
+ g_dbus_method_invocation_get_sender(invocation));
+
+ /* check privilege and update client context */
+ if (net_nfc_server_gdbus_check_privilege(invocation,
+ smack_privilege,
+ "nfc-manager",
+ "w") == false) {
+ DEBUG_ERR_MSG("permission denied, and finished request");
+
+ return FALSE;
+ }
+
+ net_nfc_server_gdbus_set_launch_state(
+ g_dbus_method_invocation_get_sender(invocation),
+ state, focus_state);
+
+ net_nfc_gdbus_popup_complete_set(popup_manager, invocation);
+
+ return TRUE;
+}
+
+static gboolean popup_handle_get(NetNfcGDbusPopup *popup_manager,
+ GDBusMethodInvocation *invocation,
+ GVariant *smack_privilege,
+ gpointer user_data)
+{
+ gboolean state;
+
+ INFO_MSG(">>> REQUEST from [%s]",
+ g_dbus_method_invocation_get_sender(invocation));
+
+ /* check privilege and update client context */
+ if (net_nfc_server_gdbus_check_privilege(invocation,
+ smack_privilege,
+ "nfc-manager",
+ "r") == false) {
+ DEBUG_ERR_MSG("permission denied, and finished request");
+
+ return FALSE;
+ }
+
+ state = net_nfc_server_gdbus_get_launch_state(
+ g_dbus_method_invocation_get_sender(invocation));
+
+ net_nfc_gdbus_popup_complete_get(popup_manager, invocation, state);
+
+ return TRUE;
+}
+
+gboolean net_nfc_server_system_handler_init(GDBusConnection *connection)
+{
+ GError *error = NULL;
+ gboolean result;
+
+ if (popup_skeleton)
+ g_object_unref(popup_skeleton);
+
+ popup_skeleton = net_nfc_gdbus_popup_skeleton_new();
+ if (popup_skeleton == NULL)
+ {
+ DEBUG_ERR_MSG("Failed to allocate popup skeleton");
+
+ return FALSE;
+ }
+
+ g_signal_connect(popup_skeleton,
+ "handle-set",
+ G_CALLBACK(popup_handle_set),
+ NULL);
+
+ g_signal_connect(popup_skeleton,
+ "handle-get",
+ G_CALLBACK(popup_handle_get),
+ NULL);
+
+ result = g_dbus_interface_skeleton_export(
+ G_DBUS_INTERFACE_SKELETON(popup_skeleton),
+ connection,
+ "/org/tizen/NetNfcService/Popup",
+ &error);
+ if (result == FALSE)
+ {
+ DEBUG_ERR_MSG("Can not skeleton_export %s", error->message);
+
+ g_error_free(error);
+ g_object_unref(popup_skeleton);
+ popup_skeleton = NULL;
+ }
+
+ return result;
+}
+
+void net_nfc_server_system_handler_deinit(void)
+{
+ if(popup_skeleton)
+ {
+ g_object_unref(popup_skeleton);
+ popup_skeleton = NULL;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_SERVER_SYSTEM_HANDLER_H__
+#define __NET_NFC_SERVER_SYSTEM_HANDLER_H__
+
+#include <gio/gio.h>
+
+gboolean net_nfc_server_system_handler_init(GDBusConnection *connection);
+
+void net_nfc_server_system_handler_deinit(void);
+
+#endif //__NET_NFC_SERVER_SYSTEM_HANDLER_H__
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "net_nfc_debug_internal.h"
+#include "net_nfc_util_internal.h"
+#include "net_nfc_util_gdbus_internal.h"
+#include "net_nfc_gdbus.h"
+#include "net_nfc_server_controller.h"
+#include "net_nfc_server_common.h"
+#include "net_nfc_server_context.h"
+#include "net_nfc_server_util.h"
+#include "net_nfc_server_p2p.h"
+#include "net_nfc_server_process_handover.h"
+#include "net_nfc_util_ndef_record.h"
+#include "net_nfc_server_tag.h"
+
+typedef struct _CurrentTagInfoData CurrentTagInfoData;
+
+struct _CurrentTagInfoData
+{
+ NetNfcGDbusTag *tag;
+ GDBusMethodInvocation *invocation;
+};
+
+typedef struct _WatchDogData WatchDogData;
+
+struct _WatchDogData
+{
+ net_nfc_target_type_e dev_type;
+ net_nfc_target_handle_s *handle;
+};
+
+
+static gboolean tag_is_isp_dep_ndef_formatable(net_nfc_target_handle_s *handle,
+ int dev_type);
+
+static gboolean tag_read_ndef_message(net_nfc_target_handle_s *handle,
+ int dev_type,
+ data_s **read_ndef);
+
+static void tag_watchdog_thread_func(gpointer user_data);
+
+static void tag_get_current_tag_info_thread_func(gpointer user_data);
+
+static void tag_slave_target_detected_thread_func(gpointer user_data);
+
+
+/* methods */
+static gboolean tag_handle_is_tag_connected(NetNfcGDbusTag *tag,
+ GDBusMethodInvocation *invocation,
+ GVariant *smack_privilege,
+ gpointer user_data);
+
+static gboolean tag_handle_get_current_tag_info(NetNfcGDbusTag *tag,
+ GDBusMethodInvocation *invocation,
+ GVariant *smack_privilege,
+ gpointer user_data);
+
+static gboolean tag_handle_get_current_target_handle(NetNfcGDbusTag *tag,
+ GDBusMethodInvocation *invocation,
+ GVariant *smack_privilege,
+ gpointer user_data);
+
+static NetNfcGDbusTag *tag_skeleton = NULL;
+
+static net_nfc_current_target_info_s *current_target_info = NULL;
+
+static gboolean tag_is_isp_dep_ndef_formatable(net_nfc_target_handle_s *handle,
+ int dev_type)
+{
+ uint8_t cmd[] = { 0x90, 0x60, 0x00, 0x00, 0x00 };
+
+ net_nfc_transceive_info_s info;
+ data_s *response = NULL;
+ net_nfc_error_e error = NET_NFC_OK;
+ gboolean result = false;
+
+ info.dev_type = dev_type;
+ info.trans_data.buffer = cmd;
+ info.trans_data.length = sizeof(cmd);
+
+ if (net_nfc_controller_transceive(handle,
+ &info,
+ &response,
+ &error) == false)
+ {
+ DEBUG_ERR_MSG("net_nfc_controller_transceive is failed");
+
+ return result;
+ }
+
+ if (response != NULL)
+ {
+ if (response->length == 9 &&
+ response->buffer[7] == (uint8_t)0x91 &&
+ response->buffer[8] == (uint8_t)0xAF)
+ {
+ result = TRUE;
+ }
+
+ net_nfc_util_free_data(response);
+ g_free(response);
+ }
+ else
+ {
+ DEBUG_ERR_MSG("response is NULL");
+ }
+
+ return result;
+}
+
+static gboolean tag_read_ndef_message(net_nfc_target_handle_s *handle,
+ int dev_type,
+ data_s **read_ndef)
+{
+ net_nfc_error_e result = NET_NFC_OK;
+ data_s *temp = NULL;
+
+ if (handle == NULL)
+ return FALSE;
+
+ if (read_ndef == NULL)
+ return FALSE;
+
+ *read_ndef = NULL;
+
+ if (dev_type == NET_NFC_MIFARE_DESFIRE_PICC)
+ {
+ if (tag_is_isp_dep_ndef_formatable(handle, dev_type) == FALSE)
+ {
+ DEBUG_ERR_MSG(
+ "DESFIRE : ISO-DEP ndef not formatable");
+ return FALSE;
+ }
+
+ DEBUG_SERVER_MSG("DESFIRE : ISO-DEP ndef formatable");
+
+ if (net_nfc_controller_connect(handle, &result) == false)
+ {
+ DEBUG_ERR_MSG("%s failed, & retry polling!!",
+ "net_nfc_controller_connect");
+
+ if (net_nfc_controller_configure_discovery(
+ NET_NFC_DISCOVERY_MODE_RESUME,
+ NET_NFC_ALL_ENABLE,
+ &result) == false)
+ {
+ net_nfc_controller_exception_handler();
+ }
+ return FALSE;
+ }
+ }
+
+ if (net_nfc_controller_read_ndef(handle, &temp, &result) == false)
+ {
+ DEBUG_ERR_MSG("%s failed",
+ "net_nfc_controller_read_ndef");
+ return FALSE;
+ }
+
+ DEBUG_SERVER_MSG("%s success",
+ "net_nfc_controller_read_ndef");
+
+ if (dev_type == NET_NFC_MIFARE_DESFIRE_PICC)
+ {
+ if (net_nfc_controller_connect(handle, &result) == false)
+ {
+ DEBUG_ERR_MSG("%s failed, & retry polling!!",
+ "net_nfc_controller_connect");
+
+ if (net_nfc_controller_configure_discovery(
+ NET_NFC_DISCOVERY_MODE_RESUME,
+ NET_NFC_ALL_ENABLE,
+ &result) == false)
+ {
+ net_nfc_controller_exception_handler();
+ }
+
+ if (temp)
+ {
+ g_free(temp->buffer);
+ g_free(temp);
+ }
+
+ return FALSE;
+ }
+ }
+
+ *read_ndef = temp;
+
+ return TRUE;
+}
+
+static void tag_watchdog_thread_func(gpointer user_data)
+{
+ WatchDogData *watch_dog = (WatchDogData *)user_data;
+ net_nfc_target_handle_s *handle;
+ net_nfc_error_e result = NET_NFC_OK;
+ bool is_present_target = false;
+
+ if (watch_dog == NULL)
+ {
+ DEBUG_ERR_MSG("can not get WatchDogData");
+ return;
+ }
+
+ if (watch_dog->handle == NULL)
+ {
+ DEBUG_ERR_MSG("can not get WatchDogData->handle");
+ return;
+ }
+
+
+ /* IMPORTANT, TEMPORARY : switching context to another thread
+ for give CPU time */
+ g_usleep(10000);
+
+ handle = watch_dog->handle;
+ if (handle->connection_type == NET_NFC_P2P_CONNECTION_TARGET ||
+ handle->connection_type == NET_NFC_TAG_CONNECTION)
+ {
+ is_present_target = net_nfc_controller_check_target_presence(
+ handle, &result);
+ }
+
+ if (is_present_target == true)
+ {
+ if(net_nfc_server_controller_async_queue_push(
+ tag_watchdog_thread_func,
+ watch_dog) == FALSE)
+ {
+ DEBUG_ERR_MSG("can not create watch dog");
+ g_free(watch_dog);
+ }
+ return;
+ }
+
+ if (result != NET_NFC_NOT_INITIALIZED &&
+ result != NET_NFC_INVALID_HANDLE)
+ {
+ if(net_nfc_controller_disconnect(handle, &result) == false)
+ {
+ DEBUG_SERVER_MSG("try to disconnect result = [%d]",
+ result);
+ net_nfc_controller_exception_handler();
+ }
+ }
+
+ net_nfc_server_set_state(NET_NFC_SERVER_IDLE);
+
+ net_nfc_gdbus_tag_emit_tag_detached(tag_skeleton,
+ GPOINTER_TO_UINT(handle),
+ watch_dog->dev_type);
+
+ g_free(watch_dog);
+}
+
+static void tag_get_current_tag_info_thread_func(gpointer user_data)
+{
+ CurrentTagInfoData *info_data =
+ (CurrentTagInfoData *)user_data;
+
+ /* FIXME : net_nfc_current_target_info_s should be removed */
+ net_nfc_current_target_info_s *target_info;
+ net_nfc_error_e result;
+ net_nfc_target_handle_s *handle = NULL;
+ net_nfc_target_type_e dev_type = NET_NFC_UNKNOWN_TARGET;
+ gboolean is_ndef_supported = FALSE;
+ guint8 ndef_card_state = 0;
+ guint32 max_data_size = 0;
+ guint32 actual_data_size = 0;
+ gint number_of_keys = 0;
+ data_s target_info_values = { NULL, 0 };
+ data_s *raw_data = NULL;
+
+ g_assert(info_data != NULL);
+ g_assert(info_data->tag != NULL);
+ g_assert(info_data->invocation != NULL);
+
+ target_info = net_nfc_server_get_target_info();
+ if (target_info != NULL &&
+ target_info->devType != NET_NFC_NFCIP1_TARGET &&
+ target_info->devType != NET_NFC_NFCIP1_INITIATOR)
+ {
+ handle = target_info->handle;
+ number_of_keys = target_info->number_of_keys;
+
+ target_info_values.buffer = target_info->target_info_values.buffer;
+ target_info_values.length = target_info->target_info_values.length;
+
+ dev_type = target_info->devType ;
+
+ if (net_nfc_controller_check_ndef(target_info->handle,
+ &ndef_card_state,
+ (int *)&max_data_size,
+ (int *)&actual_data_size,
+ &result) == true)
+ {
+ is_ndef_supported = TRUE;
+ }
+
+ if (is_ndef_supported)
+ {
+ if (net_nfc_controller_read_ndef(target_info->handle,
+ &raw_data, &result) == true)
+ {
+ DEBUG_SERVER_MSG("%s is success",
+ "net_nfc_controller_read_ndef");
+ }
+ }
+ }
+
+ net_nfc_gdbus_tag_complete_get_current_tag_info(info_data->tag,
+ info_data->invocation,
+ (dev_type != NET_NFC_UNKNOWN_TARGET),
+ GPOINTER_TO_UINT(handle),
+ dev_type,
+ is_ndef_supported,
+ ndef_card_state,
+ max_data_size,
+ actual_data_size,
+ number_of_keys,
+ net_nfc_util_gdbus_data_to_variant(&target_info_values),
+ net_nfc_util_gdbus_data_to_variant(raw_data));
+
+ if (raw_data != NULL) {
+ net_nfc_util_free_data(raw_data);
+ g_free(raw_data);
+ }
+
+ g_object_unref(info_data->invocation);
+ g_object_unref(info_data->tag);
+
+ g_free(info_data);
+}
+
+static void tag_slave_target_detected_thread_func(gpointer user_data)
+{
+ net_nfc_current_target_info_s *target;
+ net_nfc_error_e result = NET_NFC_OK;
+
+ guint32 max_data_size = 0;
+ guint32 actual_data_size = 0;
+ guint8 ndef_card_state = 0;
+ gboolean is_ndef_supported = FALSE;
+
+ GVariant *target_info_values = NULL;
+ GVariant *raw_data = NULL;
+
+ WatchDogData *watch_dog = NULL;
+ bool isHandoverMessage = false;
+
+ target = net_nfc_server_get_target_info();
+
+ g_assert(target != NULL); /* raise exception!!! what;s wrong?? */
+
+ if (tag_skeleton == NULL)
+ {
+ DEBUG_ERR_MSG("tag skeleton is not initialized");
+
+ return;
+ }
+
+ if (net_nfc_controller_connect(target->handle, &result) == false)
+ {
+ DEBUG_ERR_MSG("connect failed & Retry Polling!!");
+
+ if (net_nfc_controller_configure_discovery(
+ NET_NFC_DISCOVERY_MODE_RESUME,
+ NET_NFC_ALL_ENABLE,
+ &result) == false)
+ {
+ net_nfc_controller_exception_handler();
+ }
+
+ return;
+ }
+
+ net_nfc_server_set_state(NET_NFC_TAG_CONNECTED);
+
+ DEBUG_SERVER_MSG("tag is connected");
+
+ target_info_values = net_nfc_util_gdbus_buffer_to_variant(
+ target->target_info_values.buffer,
+ target->target_info_values.length);
+
+ if (net_nfc_controller_check_ndef(target->handle,
+ &ndef_card_state,
+ (int *)&max_data_size,
+ (int *)&actual_data_size,
+ &result) == true)
+ {
+ is_ndef_supported = TRUE;
+ }
+
+ if (is_ndef_supported)
+ {
+ data_s *recv_data = NULL;
+
+ DEBUG_SERVER_MSG("support NDEF");
+
+ if (tag_read_ndef_message(target->handle,
+ target->devType,
+ &recv_data) == TRUE)
+ {
+ ndef_message_s *selector;
+ ndef_record_s *record;
+ ndef_record_s *recordasperpriority;
+ result = _net_nfc_server_handover_create_selector_from_rawdata(
+ &selector,
+ recv_data);
+
+ if (result == NET_NFC_OK)
+ {
+ result =
+ _net_nfc_server_handover_get_carrier_record_by_priority_order(
+ selector,
+ &record);
+ isHandoverMessage = true;
+ if (result == NET_NFC_OK)
+ {
+ net_nfc_util_create_record(
+ record->TNF,
+ &record->type_s, &record->id_s,
+ &record->payload_s,
+ &recordasperpriority);
+
+ _net_nfc_server_handover_process_carrier_record(recordasperpriority, NULL, NULL);
+ }
+ else
+ {
+ DEBUG_ERR_MSG("_get_carrier_record_by_priority_order"
+ " failed, [%d]",result);
+ }
+ }
+ else
+ {
+ net_nfc_app_util_process_ndef(recv_data);
+ raw_data = net_nfc_util_gdbus_data_to_variant(recv_data);
+ }
+ }
+ else
+ {
+ DEBUG_ERR_MSG("net_nfc_controller_read_ndef failed");
+ raw_data = net_nfc_util_gdbus_buffer_to_variant(NULL, 0);
+ }
+ }
+ else
+ {
+ /* raw-data of empty ndef msseages */
+ uint8_t empty[] = { 0xd0, 0x00, 0x00 };
+ data_s empty_data = { empty, sizeof(empty) };
+
+ DEBUG_SERVER_MSG("not support NDEF");
+
+ net_nfc_app_util_process_ndef(&empty_data);
+ raw_data = net_nfc_util_gdbus_data_to_variant(&empty_data);
+ }
+
+ if(isHandoverMessage == false)
+ {
+ /* send TagDiscoverd signal */
+ net_nfc_gdbus_tag_emit_tag_discovered(tag_skeleton,
+ GPOINTER_TO_UINT(target->handle),
+ target->devType,
+ is_ndef_supported,
+ ndef_card_state,
+ max_data_size,
+ actual_data_size,
+ target->number_of_keys,
+ target_info_values,
+ raw_data);
+ }
+
+ /* turn on watch dog */
+ DEBUG_SERVER_MSG("turn on watch dog");
+
+ watch_dog = g_new0(WatchDogData, 1);
+ if(watch_dog == NULL)
+ {
+ DEBUG_ERR_MSG("Memory allocation failed");
+ return;
+ }
+
+ watch_dog->dev_type = target->devType;
+ watch_dog->handle = target->handle;
+
+ if (net_nfc_server_controller_async_queue_push(
+ tag_watchdog_thread_func,
+ watch_dog) == FALSE)
+ {
+ DEBUG_ERR_MSG("can not create watch dog");
+ g_free(watch_dog);
+ return;
+ }
+}
+
+
+static gboolean tag_handle_is_tag_connected(NetNfcGDbusTag *tag,
+ GDBusMethodInvocation *invocation,
+ GVariant *smack_privilege,
+ gpointer user_data)
+{
+ /* FIXME : net_nfc_current_target_info_s should be removed */
+ net_nfc_current_target_info_s *target_info;
+ net_nfc_target_type_e dev_type = NET_NFC_UNKNOWN_TARGET;
+ gboolean is_connected = FALSE;
+
+ INFO_MSG(">>> REQUEST from [%s]",
+ g_dbus_method_invocation_get_sender(invocation));
+
+ /* check privilege and update client context */
+ if (net_nfc_server_gdbus_check_privilege(invocation,
+ smack_privilege,
+ "nfc-manager::tag",
+ "r") == false) {
+ DEBUG_ERR_MSG("permission denied, and finished request");
+
+ return FALSE;
+ }
+
+ target_info = net_nfc_server_get_target_info();
+ if (target_info != NULL)
+ {
+ dev_type = target_info->devType;
+ is_connected = TRUE;
+ }
+
+ net_nfc_gdbus_tag_complete_is_tag_connected(tag,
+ invocation,
+ is_connected,
+ (gint32)dev_type);
+
+ return TRUE;
+}
+
+static gboolean tag_handle_get_current_tag_info(NetNfcGDbusTag *tag,
+ GDBusMethodInvocation *invocation,
+ GVariant *smack_privilege,
+ gpointer user_data)
+{
+ CurrentTagInfoData *info_data;
+ gboolean result;
+
+ INFO_MSG(">>> REQUEST from [%s]",
+ g_dbus_method_invocation_get_sender(invocation));
+
+ /* check privilege and update client context */
+ if (net_nfc_server_gdbus_check_privilege(invocation,
+ smack_privilege,
+ "nfc-manager::tag",
+ "r") == false) {
+ DEBUG_ERR_MSG("permission denied, and finished request");
+
+ return FALSE;
+ }
+
+ info_data = g_new0(CurrentTagInfoData, 1);
+ if (info_data == NULL)
+ {
+ DEBUG_ERR_MSG("Memory allocation failed");
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.AllocationError",
+ "Can not allocate memory");
+
+ return FALSE;
+ }
+
+ info_data->tag = g_object_ref(tag);
+ info_data->invocation = g_object_ref(invocation);
+
+ result = net_nfc_server_controller_async_queue_push(
+ tag_get_current_tag_info_thread_func,
+ info_data);
+ if (result == FALSE)
+ {
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.ThreadError",
+ "can not push to controller thread");
+
+ g_object_unref(info_data->invocation);
+ g_object_unref(info_data->tag);
+
+ g_free(info_data);
+ }
+
+ return result;
+}
+
+static gboolean tag_handle_get_current_target_handle(NetNfcGDbusTag *tag,
+ GDBusMethodInvocation *invocation,
+ GVariant *smack_privilege,
+ gpointer user_data)
+{
+ /* FIXME : net_nfc_current_target_info_s should be removed */
+ net_nfc_current_target_info_s *target_info;
+ net_nfc_target_handle_s *handle = NULL;
+ uint32_t devType = NET_NFC_UNKNOWN_TARGET;
+
+ INFO_MSG(">>> REQUEST from [%s]",
+ g_dbus_method_invocation_get_sender(invocation));
+
+ /* check privilege and update client context */
+ if (net_nfc_server_gdbus_check_privilege(invocation,
+ smack_privilege,
+ "nfc-manager::tag",
+ "r") == false) {
+ DEBUG_ERR_MSG("permission denied, and finished request");
+
+ return FALSE;
+ }
+
+ target_info = net_nfc_server_get_target_info();
+ if (target_info != NULL)
+ {
+ handle = target_info->handle;
+ devType = target_info->devType;
+ }
+
+ net_nfc_gdbus_tag_complete_get_current_target_handle(tag,
+ invocation,
+ (handle != NULL),
+ GPOINTER_TO_UINT(handle),
+ devType);
+
+ return TRUE;
+}
+
+
+gboolean net_nfc_server_tag_init(GDBusConnection *connection)
+{
+ GError *error = NULL;
+ gboolean result;
+
+ if (tag_skeleton)
+ net_nfc_server_tag_deinit();
+
+ tag_skeleton = net_nfc_gdbus_tag_skeleton_new();
+
+ g_signal_connect(tag_skeleton,
+ "handle-is-tag-connected",
+ G_CALLBACK(tag_handle_is_tag_connected),
+ NULL);
+
+ g_signal_connect(tag_skeleton,
+ "handle-get-current-tag-info",
+ G_CALLBACK(tag_handle_get_current_tag_info),
+ NULL);
+
+ g_signal_connect(tag_skeleton,
+ "handle-get-current-target-handle",
+ G_CALLBACK(tag_handle_get_current_target_handle),
+ NULL);
+
+ result = g_dbus_interface_skeleton_export(
+ G_DBUS_INTERFACE_SKELETON(tag_skeleton),
+ connection,
+ "/org/tizen/NetNfcService/Tag",
+ &error);
+ if (result == FALSE)
+ {
+ DEBUG_ERR_MSG("can not skeleton_export %s", error->message);
+
+ g_error_free(error);
+
+ net_nfc_server_tag_deinit();
+ }
+
+ return result;
+}
+
+void net_nfc_server_tag_deinit(void)
+{
+ if (tag_skeleton)
+ {
+ g_object_unref(tag_skeleton);
+ tag_skeleton = NULL;
+ }
+}
+
+void net_nfc_server_set_target_info(void *info)
+{
+ net_nfc_request_target_detected_t *target;
+
+ if (current_target_info)
+ g_free(current_target_info);
+
+ target = (net_nfc_request_target_detected_t *)info;
+
+ current_target_info = g_malloc0(
+ sizeof(net_nfc_current_target_info_s) +
+ target->target_info_values.length);
+
+ current_target_info->handle = target->handle;
+ current_target_info->devType = target->devType;
+
+ if (current_target_info->devType != NET_NFC_NFCIP1_INITIATOR &&
+ current_target_info->devType != NET_NFC_NFCIP1_TARGET)
+ {
+ current_target_info->number_of_keys = target->number_of_keys;
+ current_target_info->target_info_values.length =
+ target->target_info_values.length;
+
+ memcpy(¤t_target_info->target_info_values,
+ &target->target_info_values,
+ current_target_info->target_info_values.length);
+ }
+}
+
+net_nfc_current_target_info_s *net_nfc_server_get_target_info(void)
+{
+ return current_target_info;
+}
+
+gboolean net_nfc_server_target_connected(net_nfc_target_handle_s *handle)
+{
+ if (current_target_info == NULL)
+ return FALSE;
+
+ if (current_target_info->handle != handle)
+ return FALSE;
+
+ return TRUE;
+}
+
+void net_nfc_server_free_target_info(void)
+{
+ g_free(current_target_info);
+ current_target_info = NULL;
+}
+
+void net_nfc_server_tag_target_detected(void *info)
+{
+ if (net_nfc_server_controller_async_queue_push(
+ tag_slave_target_detected_thread_func,
+ NULL) == FALSE)
+ {
+ DEBUG_ERR_MSG("can not push to controller thread");
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_SERVER_TAG_H__
+#define __NET_NFC_SERVER_TAG_H__
+
+#include <gio/gio.h>
+
+#include "net_nfc_typedef_internal.h"
+
+gboolean net_nfc_server_tag_init(GDBusConnection *connection);
+
+void net_nfc_server_tag_deinit(void);
+
+void net_nfc_server_set_target_info(void *info);
+
+net_nfc_current_target_info_s *net_nfc_server_get_target_info(void);
+
+gboolean net_nfc_server_target_connected(net_nfc_target_handle_s *handle);
+
+void net_nfc_server_free_target_info(void);
+
+void net_nfc_server_tag_target_detected(void *info);
+
+#endif //__NET_NFC_SERVER_TAG_H__
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "net_nfc_typedef_internal.h"
+#include "net_nfc_debug_internal.h"
+#include "net_nfc_util_internal.h"
+#include "net_nfc_util_gdbus_internal.h"
+#include "net_nfc_server_controller.h"
+#include "net_nfc_gdbus.h"
+#include "net_nfc_server_common.h"
+#include "net_nfc_server_context.h"
+#include "net_nfc_server_test.h"
+
+typedef struct _TestData TestData;
+
+struct _TestData
+{
+ NetNfcGDbusTest *test;
+ GDBusMethodInvocation *invocation;
+};
+
+typedef struct _TestPrbsData TestPrbsData;
+
+struct _TestPrbsData
+{
+ NetNfcGDbusTest *test;
+ GDBusMethodInvocation *invocation;
+ guint32 tech;
+ guint32 rate;
+};
+
+typedef struct _TestSetEeData TestSetEeData;
+
+struct _TestSetEeData
+{
+ NetNfcGDbusTest *test;
+ GDBusMethodInvocation *invocation;
+
+ guint32 mode;
+ guint32 reg_id;
+ data_s data;
+};
+
+static void test_handle_sim_test_thread_func(gpointer user_data);
+
+static void test_handle_prbs_test_thread_func(gpointer user_data);
+
+static void test_handle_get_firmware_version_thread_func(gpointer user_data);
+
+static void test_handle_set_ee_data_thread_func(gpointer user_data);
+
+
+static gboolean test_handle_sim_test(NetNfcGDbusTest *test,
+ GDBusMethodInvocation *invocation,
+ GVariant *smack_privilege,
+ gpointer user_data);
+
+static gboolean test_handle_prbs_test(NetNfcGDbusTest *test,
+ GDBusMethodInvocation *invocation,
+ guint32 arg_tech,
+ guint32 arg_rate,
+ GVariant *smack_privilege,
+ gpointer user_data);
+
+static gboolean test_handle_get_firmware_version(NetNfcGDbusTest *test,
+ GDBusMethodInvocation *invocation,
+ GVariant *smack_privilege,
+ gpointer user_data);
+
+static gboolean test_handle_set_ee_data(NetNfcGDbusTest *test,
+ GDBusMethodInvocation *invocation,
+ guint32 mode,
+ guint32 reg_id,
+ GVariant *variant,
+ GVariant *smack_privilege,
+ gpointer user_data);
+
+
+static NetNfcGDbusTest *test_skeleton = NULL;
+
+static void test_handle_sim_test_thread_func(gpointer user_data)
+{
+ TestData *data = (TestData *)user_data;
+ net_nfc_error_e result = NET_NFC_OK;
+
+ g_assert(data != NULL);
+ g_assert(data->test != NULL);
+ g_assert(data->invocation != NULL);
+
+ net_nfc_controller_sim_test(&result);
+
+ net_nfc_gdbus_test_complete_sim_test(data->test,
+ data->invocation,
+ (gint)result);
+
+ g_object_unref(data->invocation);
+ g_object_unref(data->test);
+
+ g_free(data);
+}
+
+static void test_handle_prbs_test_thread_func(gpointer user_data)
+{
+ TestPrbsData *data = (TestPrbsData *)user_data;
+ net_nfc_error_e result = NET_NFC_OK;
+
+ g_assert(data != NULL);
+ g_assert(data->test != NULL);
+ g_assert(data->invocation != NULL);
+
+ net_nfc_controller_prbs_test(&result, data->tech, data->rate);
+
+ net_nfc_gdbus_test_complete_prbs_test(data->test,
+ data->invocation,
+ (gint)result);
+
+ g_object_unref(data->invocation);
+ g_object_unref(data->test);
+
+ g_free(data);
+}
+
+static void test_handle_get_firmware_version_thread_func(gpointer user_data)
+{
+ TestData *data = (TestData *)user_data;
+ data_s *tmp_data = NULL;
+ net_nfc_error_e result = NET_NFC_OK;
+ gchar *version = NULL;
+
+ g_assert(data != NULL);
+ g_assert(data->test != NULL);
+ g_assert(data->invocation != NULL);
+
+ net_nfc_controller_get_firmware_version(&tmp_data, &result);
+
+ if (tmp_data)
+ {
+ version = g_new0(gchar, tmp_data->length +1);
+ memcpy((void *)version, tmp_data->buffer, tmp_data->length);
+
+ g_free(tmp_data->buffer);
+ g_free(tmp_data);
+ }
+ else
+ {
+ version = g_strdup("");
+ }
+
+ net_nfc_gdbus_test_complete_get_firmware_version(data->test,
+ data->invocation,
+ (gint)result,
+ version);
+
+ g_free(version);
+
+ g_object_unref(data->invocation);
+ g_object_unref(data->test);
+
+ g_free(data);
+}
+
+static void test_handle_set_ee_data_thread_func(gpointer user_data)
+{
+ TestSetEeData *data = (TestSetEeData *)user_data;
+ net_nfc_error_e result = NET_NFC_OK;
+
+ g_assert(data != NULL);
+ g_assert(data->test != NULL);
+ g_assert(data->invocation != NULL);
+
+ net_nfc_controller_eedata_register_set(&result,
+ data->mode,
+ data->reg_id,
+ &data->data);
+
+ net_nfc_gdbus_test_complete_set_ee_data(data->test,
+ data->invocation,
+ (gint)result);
+
+ net_nfc_util_free_data(&data->data);
+
+ g_object_unref(data->invocation);
+ g_object_unref(data->test);
+
+ g_free(data);
+}
+
+static gboolean test_handle_sim_test(NetNfcGDbusTest *test,
+ GDBusMethodInvocation *invocation,
+ GVariant *smack_privilege,
+ gpointer user_data)
+{
+ TestData *data;
+ gboolean result;
+
+ INFO_MSG(">>> REQUEST from [%s]",
+ g_dbus_method_invocation_get_sender(invocation));
+
+ /* check privilege and update client context */
+ if (net_nfc_server_gdbus_check_privilege(invocation,
+ smack_privilege,
+ "nfc-manager",
+ "rw") == false) {
+ DEBUG_ERR_MSG("permission denied, and finished request");
+
+ return FALSE;
+ }
+
+ DEBUG_SERVER_MSG("sim_test");
+
+ data = g_new0(TestData, 1);
+ if (data == NULL)
+ {
+ DEBUG_ERR_MSG("Memory allocation failed");
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.AllocationError",
+ "Can not allocate memory");
+
+ return FALSE;
+ }
+
+ data->test = g_object_ref(test);
+ data->invocation = g_object_ref(invocation);
+
+ result = net_nfc_server_controller_async_queue_push(
+ test_handle_sim_test_thread_func,
+ data);
+ if (result == FALSE)
+ {
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.ThreadError",
+ "can not push to controller thread");
+
+ g_object_unref(data->invocation);
+ g_object_unref(data->test);
+
+ g_free(data);
+ }
+
+ return result;
+}
+
+static gboolean test_handle_prbs_test(NetNfcGDbusTest *test,
+ GDBusMethodInvocation *invocation,
+ guint32 arg_tech,
+ guint32 arg_rate,
+ GVariant *smack_privilege,
+ gpointer user_data)
+{
+ TestPrbsData *data;
+ gboolean result;
+
+ INFO_MSG(">>> REQUEST from [%s]",
+ g_dbus_method_invocation_get_sender(invocation));
+
+ /* check privilege and update client context */
+ if (net_nfc_server_gdbus_check_privilege(invocation,
+ smack_privilege,
+ "nfc-manager",
+ "rw") == false) {
+ DEBUG_ERR_MSG("permission denied, and finished request");
+
+ return TRUE;
+ }
+
+ DEBUG_SERVER_MSG("prbs_test");
+
+ data = g_new0(TestPrbsData, 1);
+ if (data == NULL)
+ {
+ DEBUG_ERR_MSG("Memory allocation failed");
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.AllocationError",
+ "Can not allocate memory");
+
+ return FALSE;
+ }
+
+ data->test = g_object_ref(test);
+ data->invocation = g_object_ref(invocation);
+ data->tech = arg_tech;
+ data->rate = arg_rate;
+
+ result = net_nfc_server_controller_async_queue_push(
+ test_handle_prbs_test_thread_func,
+ data);
+ if (result == FALSE)
+ {
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.ThreadError",
+ "can not push to controller thread");
+
+ g_object_unref(data->invocation);
+ g_object_unref(data->test);
+
+ g_free(data);
+ }
+
+ return result;
+}
+
+static gboolean test_handle_get_firmware_version(NetNfcGDbusTest *test,
+ GDBusMethodInvocation *invocation,
+ GVariant *smack_privilege,
+ gpointer user_data)
+{
+ TestData *data;
+ gboolean result;
+
+ INFO_MSG(">>> REQUEST from [%s]",
+ g_dbus_method_invocation_get_sender(invocation));
+
+ /* check privilege and update client context */
+ if (net_nfc_server_gdbus_check_privilege(invocation,
+ smack_privilege,
+ "nfc-manager",
+ "rw") == false) {
+ DEBUG_ERR_MSG("permission denied, and finished request");
+
+ return FALSE;
+ }
+
+ data = g_new0(TestData, 1);
+ if (data == NULL)
+ {
+ DEBUG_ERR_MSG("Memory allocation failed");
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.AllocationError",
+ "Can not allocate memory");
+
+ return FALSE;
+ }
+
+ data->test = g_object_ref(test);
+ data->invocation = g_object_ref(invocation);
+
+ result = net_nfc_server_controller_async_queue_push(
+ test_handle_get_firmware_version_thread_func,
+ data);
+ if (result == FALSE)
+ {
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.ThreadError",
+ "can not push to controller thread");
+
+ g_object_unref(data->test);
+ g_object_unref(data->invocation);
+
+ g_free(data);
+ }
+
+ return result;
+}
+
+static gboolean test_handle_set_ee_data(NetNfcGDbusTest *test,
+ GDBusMethodInvocation *invocation,
+ guint32 mode,
+ guint32 reg_id,
+ GVariant *variant,
+ GVariant *smack_privilege,
+ gpointer user_data)
+{
+ TestSetEeData *data;
+ gboolean result;
+
+ INFO_MSG(">>> REQUEST from [%s]",
+ g_dbus_method_invocation_get_sender(invocation));
+
+ /* check privilege and update client context */
+ if (net_nfc_server_gdbus_check_privilege(invocation,
+ smack_privilege,
+ "nfc-manager",
+ "rw") == false) {
+ DEBUG_ERR_MSG("permission denied, and finished request");
+
+ return FALSE;
+ }
+
+ data = g_new0(TestSetEeData, 1);
+ if (data == NULL)
+ {
+ DEBUG_ERR_MSG("Memory allocation failed");
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.AllocationError",
+ "Can not allocate memory");
+
+ return FALSE;
+ }
+
+ data->test = g_object_ref(test);
+ data->invocation = g_object_ref(invocation);
+ data->mode = mode;
+ data->reg_id = reg_id;
+ net_nfc_util_gdbus_variant_to_data_s(variant, &data->data);
+
+ result = net_nfc_server_controller_async_queue_push(
+ test_handle_set_ee_data_thread_func, data);
+ if (result == FALSE)
+ {
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.ThreadError",
+ "can not push to controller thread");
+
+ net_nfc_util_free_data(&data->data);
+
+ g_object_unref(data->invocation);
+ g_object_unref(data->test);
+
+ g_free(data);
+ }
+
+ return result;
+}
+
+gboolean net_nfc_server_test_init(GDBusConnection *connection)
+{
+ GError *error = NULL;
+ gboolean result;
+
+ if (test_skeleton)
+ g_object_unref(test_skeleton);
+
+ test_skeleton = net_nfc_gdbus_test_skeleton_new();
+
+ g_signal_connect(test_skeleton,
+ "handle-sim-test",
+ G_CALLBACK(test_handle_sim_test),
+ NULL);
+
+ g_signal_connect(test_skeleton,
+ "handle-prbs-test",
+ G_CALLBACK(test_handle_prbs_test),
+ NULL);
+
+ g_signal_connect(test_skeleton,
+ "handle-get-firmware-version",
+ G_CALLBACK(test_handle_get_firmware_version),
+ NULL);
+
+ g_signal_connect(test_skeleton,
+ "handle-set-ee-data",
+ G_CALLBACK(test_handle_set_ee_data),
+ NULL);
+
+ result = g_dbus_interface_skeleton_export(
+ G_DBUS_INTERFACE_SKELETON(test_skeleton),
+ connection,
+ "/org/tizen/NetNfcService/Test",
+ &error);
+ if (result == FALSE)
+ {
+ DEBUG_ERR_MSG("Can not skeleton_export %s", error->message);
+ g_error_free(error);
+ g_object_unref(test_skeleton);
+
+ test_skeleton = NULL;
+ }
+
+ return result;
+}
+
+void net_nfc_server_test_deinit(void)
+{
+ if (test_skeleton)
+ {
+ g_object_unref(test_skeleton);
+ test_skeleton = NULL;
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_SERVER_TEST_H__
+#define __NET_NFC_SERVER_TEST_H__
+
+#include <gio/gio.h>
+
+gboolean net_nfc_server_test_init(GDBusConnection *connection);
+
+void net_nfc_server_test_deinit(void);
+
+#endif //__NET_NFC_SERVER_TEST_H__
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "net_nfc_typedef_internal.h"
+#include "net_nfc_debug_internal.h"
+#include "net_nfc_util_internal.h"
+#include "net_nfc_util_gdbus_internal.h"
+#include "net_nfc_server_controller.h"
+#include "net_nfc_gdbus.h"
+#include "net_nfc_server_common.h"
+#include "net_nfc_server_tag.h"
+#include "net_nfc_server_context.h"
+#include "net_nfc_server_transceive.h"
+
+
+static NetNfcGDbusTransceive *transceive_skeleton = NULL;
+
+static void transceive_thread_func(gpointer user_data);
+
+static void transceive_data_thread_func(gpointer user_data);
+
+static gboolean transceive_handle(NetNfcGDbusTransceive *transceive,
+ GDBusMethodInvocation *invocation,
+ guint handle,
+ guint dev_type,
+ GVariant *arg_data,
+ GVariant *smack_privilege,
+ gpointer user_data);
+
+static gboolean transceive_data_handle(NetNfcGDbusTransceive *transceive,
+ GDBusMethodInvocation *invocation,
+ guint handle,
+ guint dev_type,
+ GVariant *arg_data,
+ GVariant *smack_privilege,
+ gpointer user_data);
+
+
+typedef struct _TransceiveSendData TransceiveSendData;
+
+struct _TransceiveSendData
+{
+ NetNfcGDbusTransceive *transceive;
+ GDBusMethodInvocation *invocation;
+ guint transceive_handle;
+ net_nfc_transceive_info_s transceive_info;
+};
+
+static void transceive_data_thread_func(gpointer user_data)
+{
+ TransceiveSendData *transceive_data = (TransceiveSendData*)user_data;
+ net_nfc_target_handle_s *handle =
+ (net_nfc_target_handle_s *)transceive_data->transceive_handle;
+ net_nfc_error_e result;
+ data_s *data = NULL;
+ GVariant *resp_data = NULL;
+
+ /* use assert because it was checked in handle function */
+ g_assert(transceive_data != NULL);
+ g_assert(transceive_data->transceive != NULL);
+ g_assert(transceive_data->invocation != NULL);
+
+ if (net_nfc_server_target_connected(handle) == true)
+ {
+ DEBUG_SERVER_MSG("call transceive");
+
+ if (net_nfc_controller_transceive(handle,
+ &transceive_data->transceive_info,
+ &data,
+ &result) == true)
+ {
+ if (data != NULL)
+ {
+ DEBUG_SERVER_MSG("Transceive data received [%d]",
+ data->length);
+ }
+ }
+ }
+ else
+ {
+ result = NET_NFC_TARGET_IS_MOVED_AWAY;
+ }
+
+ DEBUG_SERVER_MSG("transceive result : %d", result);
+
+ resp_data = net_nfc_util_gdbus_data_to_variant(data);
+
+ net_nfc_gdbus_transceive_complete_transceive_data(
+ transceive_data->transceive,
+ transceive_data->invocation,
+ (gint)result,
+ resp_data);
+
+ if (data)
+ {
+ g_free(data->buffer);
+ g_free(data);
+ }
+
+ net_nfc_util_free_data(&transceive_data->transceive_info.trans_data);
+
+ g_object_unref(transceive_data->invocation);
+ g_object_unref(transceive_data->transceive);
+
+ g_free(transceive_data);
+}
+
+static gboolean transceive_data_handle(NetNfcGDbusTransceive *transceive,
+ GDBusMethodInvocation *invocation,
+ guint handle,
+ guint dev_type,
+ GVariant *arg_data,
+ GVariant *smack_privilege,
+ gpointer user_data)
+{
+ TransceiveSendData *data;
+ gboolean result;
+
+ INFO_MSG(">>> REQUEST from [%s]",
+ g_dbus_method_invocation_get_sender(invocation));
+
+ /* check privilege and update client context */
+ if (net_nfc_server_gdbus_check_privilege(invocation,
+ smack_privilege,
+ "nfc-manager",
+ "rw") == false) {
+ DEBUG_ERR_MSG("permission denied, and finished request");
+
+ return FALSE;
+ }
+
+ data = g_new0(TransceiveSendData, 1);
+ if (data == NULL)
+ {
+ DEBUG_ERR_MSG("Memory allocation failed");
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.AllocationError",
+ "Can not allocate memory");
+
+ return FALSE;
+ }
+
+ data->transceive = g_object_ref(transceive);
+ data->invocation = g_object_ref(invocation);
+ data->transceive_handle = handle;
+ data->transceive_info.dev_type = dev_type;
+ net_nfc_util_gdbus_variant_to_data_s(arg_data,
+ &data->transceive_info.trans_data);
+
+ result = net_nfc_server_controller_async_queue_push(
+ transceive_data_thread_func, data);
+ if (result == FALSE)
+ {
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.Transceive.ThreadError",
+ "can not push to controller thread");
+
+ net_nfc_util_free_data(&data->transceive_info.trans_data);
+
+ g_object_unref(data->transceive);
+ g_object_unref(data->invocation);
+
+ g_free(data);
+ }
+
+ return result;
+}
+
+static void transceive_thread_func(gpointer user_data)
+{
+ TransceiveSendData *transceive_data = (TransceiveSendData *)user_data;
+ net_nfc_target_handle_s *handle =
+ (net_nfc_target_handle_s *)transceive_data->transceive_handle;
+ net_nfc_error_e result = NET_NFC_OK;
+ data_s *data = NULL;
+
+ /* use assert because it was checked in handle function */
+ g_assert(transceive_data != NULL);
+ g_assert(transceive_data->transceive != NULL);
+ g_assert(transceive_data->invocation != NULL);
+
+ if (net_nfc_server_target_connected(handle) == true)
+ {
+ DEBUG_MSG("call transceive");
+
+ if (net_nfc_controller_transceive(handle,
+ &transceive_data->transceive_info,
+ &data,
+ &result) == true)
+ {
+ if (data != NULL)
+ {
+ DEBUG_SERVER_MSG(
+ "Transceive data received [%d]",
+ data->length);
+
+ /* free resource because it doesn't need */
+ g_free(data->buffer);
+ g_free(data);
+ }
+ }
+ }
+ else
+ {
+ DEBUG_SERVER_MSG("target is not connected");
+
+ result = NET_NFC_TARGET_IS_MOVED_AWAY;
+ }
+
+ DEBUG_SERVER_MSG("transceive result : %d", result);
+
+ net_nfc_gdbus_transceive_complete_transceive(
+ transceive_data->transceive,
+ transceive_data->invocation,
+ (gint)result);
+
+ net_nfc_util_free_data(&transceive_data->transceive_info.trans_data);
+
+ g_object_unref(transceive_data->invocation);
+ g_object_unref(transceive_data->transceive);
+
+ g_free(transceive_data);
+}
+
+static gboolean transceive_handle(NetNfcGDbusTransceive *transceive,
+ GDBusMethodInvocation *invocation,
+ guint handle,
+ guint dev_type,
+ GVariant *arg_data,
+ GVariant *smack_privilege,
+ gpointer user_data)
+{
+ TransceiveSendData *data;
+ gboolean result;
+
+ INFO_MSG(">>> REQUEST from [%s]",
+ g_dbus_method_invocation_get_sender(invocation));
+
+ /* check privilege and update client context */
+ if (net_nfc_server_gdbus_check_privilege(invocation,
+ smack_privilege,
+ "nfc-manager",
+ "rw") == false) {
+ DEBUG_ERR_MSG("permission denied, and finished request");
+
+ return FALSE;
+ }
+
+ data = g_new0(TransceiveSendData, 1);
+ if (data == NULL)
+ {
+ DEBUG_ERR_MSG("Memory allocation failed");
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.AllocationError",
+ "Can not allocate memory");
+
+ return FALSE;
+ }
+
+ data->transceive = g_object_ref(transceive);
+ data->invocation = g_object_ref(invocation);
+ data->transceive_handle = handle;
+ data->transceive_info.dev_type = dev_type;
+ net_nfc_util_gdbus_variant_to_data_s(arg_data,
+ &data->transceive_info.trans_data);
+
+ result = net_nfc_server_controller_async_queue_push(
+ transceive_thread_func, data);
+ if (result == FALSE)
+ {
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.Transceive.ThreadError",
+ "can not push to controller thread");
+
+ net_nfc_util_free_data(&data->transceive_info.trans_data);
+
+ g_object_unref(data->transceive);
+ g_object_unref(data->invocation);
+
+ g_free(data);
+ }
+
+ return result;
+}
+
+
+gboolean net_nfc_server_transceive_init(GDBusConnection *connection)
+{
+ GError *error = NULL;
+ gboolean result;
+
+ if (transceive_skeleton)
+ g_object_unref(transceive_skeleton);
+
+ transceive_skeleton = net_nfc_gdbus_transceive_skeleton_new();
+
+ g_signal_connect(transceive_skeleton,
+ "handle-transceive-data",
+ G_CALLBACK(transceive_data_handle),
+ NULL);
+
+ g_signal_connect(transceive_skeleton,
+ "handle-transceive",
+ G_CALLBACK(transceive_handle),
+ NULL);
+
+ result = g_dbus_interface_skeleton_export(
+ G_DBUS_INTERFACE_SKELETON(transceive_skeleton),
+ connection,
+ "/org/tizen/NetNfcService/Transceive",
+ &error);
+ if (result == FALSE)
+ {
+ g_error_free(error);
+ g_object_unref(transceive_skeleton);
+ transceive_skeleton = NULL;
+ }
+
+ return result;
+}
+
+void net_nfc_server_transceive_deinit(void)
+{
+ if (transceive_skeleton)
+ {
+ g_object_unref(transceive_skeleton);
+ transceive_skeleton = NULL;
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_SERVER_TRANSCEIVE_H__
+#define __NET_NFC_SERVER_TRANSCEIVE_H__
+
+#include <gio/gio.h>
+
+gboolean net_nfc_server_transceive_init(GDBusConnection *connection);
+
+void net_nfc_server_transceive_deinit(void);
+
+#endif //__NET_NFC_SERVER_TRANSCEIVE_H__
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#define _GNU_SOURCE
+#include <string.h>
+#include <dirent.h>
+#include <errno.h>
+#include <pwd.h>
+#include <grp.h>
+#include <sys/stat.h>
+#include <sys/time.h>
+#include <time.h>
+#include <pthread.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <curl/curl.h>
+#include <glib.h>
+#include <openssl/evp.h>
+#include <openssl/bio.h>
+#include <openssl/buffer.h>
+
+#include <vconf.h>
+#include <svi.h>
+#include <wav_player.h>
+#include <appsvc.h>
+#include <aul.h>
+#include <Ecore_X.h>
+
+#include "net_nfc_typedef.h"
+#include "net_nfc_typedef_internal.h"
+#include "net_nfc_debug_internal.h"
+#include "net_nfc_util_defines.h"
+#include "net_nfc_util_internal.h"
+#include "net_nfc_util_ndef_message.h"
+#include "net_nfc_util_ndef_record.h"
+#include "net_nfc_server_context.h"
+#include "net_nfc_server_se.h"
+#include "net_nfc_server_util.h"
+
+#define NET_NFC_MANAGER_SOUND_PATH_TASK_START "/usr/share/nfc-manager-daemon/sounds/Operation_sdk.wav"
+#define NET_NFC_MANAGER_SOUND_PATH_TASK_END "/usr/share/nfc-manager-daemon/sounds/Operation_sdk.wav"
+#define NET_NFC_MANAGER_SOUND_PATH_TASK_ERROR "/usr/share/nfc-manager-daemon/sounds/Operation_sdk.wav"
+
+#define OSP_K_COND "__OSP_COND_NAME__"
+#define OSP_K_COND_TYPE "nfc"
+#define OSP_K_LAUNCH_TYPE "__OSP_LAUNCH_TYPE__"
+
+static const char osp_launch_type_condition[] = "condition";
+
+static bool _net_nfc_app_util_change_file_owner_permission(FILE *file)
+{
+ char *buffer = NULL;
+ size_t buffer_len = 0;
+ struct passwd pwd = { 0, };
+ struct passwd *pw_inhouse = NULL;
+ struct group grp = { 0, };
+ struct group *gr_inhouse = NULL;
+
+ if (file == NULL)
+ return false;
+
+ /* change permission */
+ fchmod(fileno(file), 0777);
+
+ /* change owner */
+ /* get passwd id */
+ buffer_len = sysconf(_SC_GETPW_R_SIZE_MAX);
+ if (buffer_len == -1)
+ {
+ buffer_len = 16384;
+ }
+
+ _net_nfc_util_alloc_mem(buffer, buffer_len);
+ if (buffer == NULL)
+ return false;
+
+ getpwnam_r("inhouse", &pwd, buffer, buffer_len, &pw_inhouse);
+ _net_nfc_util_free_mem(buffer);
+
+ /* get group id */
+ buffer_len = sysconf(_SC_GETGR_R_SIZE_MAX);
+ if (buffer_len == -1)
+ {
+ buffer_len = 16384;
+ }
+
+ _net_nfc_util_alloc_mem(buffer, buffer_len);
+ if (buffer == NULL)
+ return false;
+
+ getgrnam_r("inhouse", &grp, buffer, buffer_len, &gr_inhouse);
+ _net_nfc_util_free_mem(buffer);
+
+ if ((pw_inhouse != NULL) && (gr_inhouse != NULL))
+ {
+ if (fchown(fileno(file), pw_inhouse->pw_uid, gr_inhouse->gr_gid) < 0)
+ {
+ DEBUG_ERR_MSG("failed to change owner");
+ }
+ }
+
+ return true;
+}
+
+static net_nfc_error_e net_nfc_app_util_store_ndef_message(data_s *data)
+{
+ net_nfc_error_e result = NET_NFC_UNKNOWN_ERROR;
+ char file_name[1024] = { 0, };
+ struct stat st;
+ FILE *fp = NULL;
+
+ if (data == NULL)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ /* check and make directory */
+ snprintf(file_name, sizeof(file_name), "%s/%s", NET_NFC_MANAGER_DATA_PATH,
+ NET_NFC_MANAGER_DATA_PATH_MESSAGE);
+
+ if (stat(file_name, &st) == -1)
+ {
+ int result;
+ char command[1024];
+
+ SECURE_LOGD("path doesn't exist, do mkdir : %s", file_name);
+
+ snprintf(command, sizeof(command), "mkdir -p -m 755 %s", file_name);
+
+ result = system(command);
+
+ if (stat(file_name, &st) == -1)
+ {
+ DEBUG_ERR_MSG("mkdir failed");
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+ }
+
+ /* create file */
+ snprintf(file_name, sizeof(file_name), "%s/%s/%s", NET_NFC_MANAGER_DATA_PATH,
+ NET_NFC_MANAGER_DATA_PATH_MESSAGE, NET_NFC_MANAGER_NDEF_FILE_NAME);
+ SECURE_LOGD("file path : %s", file_name);
+
+ unlink(file_name);
+
+ if ((fp = fopen(file_name, "w")) != NULL)
+ {
+ int length = 0;
+
+ if ((length = fwrite(data->buffer, 1, data->length, fp)) > 0)
+ {
+ DEBUG_SERVER_MSG("[%d] bytes is written", length);
+
+ _net_nfc_app_util_change_file_owner_permission(fp);
+
+ fflush(fp);
+ fsync(fileno(fp));
+
+ result = NET_NFC_OK;
+ }
+ else
+ {
+ DEBUG_ERR_MSG("write is failed = [%d]", data->length);
+ result = NET_NFC_UNKNOWN_ERROR;
+ }
+
+ fclose(fp);
+ }
+
+ return result;
+}
+
+static bool _net_nfc_app_util_get_operation_from_record(ndef_record_s *record, char *operation, size_t length)
+{
+ bool result = false;
+ char *op_text = NULL;
+
+ if (record == NULL || operation == NULL || length == 0)
+ {
+ return result;
+ }
+
+ switch (record->TNF)
+ {
+ case NET_NFC_RECORD_WELL_KNOWN_TYPE :
+ op_text = "http://tizen.org/appcontrol/operation/nfc/wellknown";
+ break;
+
+ case NET_NFC_RECORD_MIME_TYPE :
+ op_text = "http://tizen.org/appcontrol/operation/nfc/mime";
+ break;
+
+ case NET_NFC_RECORD_URI : /* Absolute URI */
+ op_text = "http://tizen.org/appcontrol/operation/nfc/uri";
+ break;
+
+ case NET_NFC_RECORD_EXTERNAL_RTD : /* external type */
+ op_text = "http://tizen.org/appcontrol/operation/nfc/external";
+ break;
+
+ case NET_NFC_RECORD_EMPTY : /* empty_tag */
+ op_text = "http://tizen.org/appcontrol/operation/nfc/empty";
+ break;
+
+ case NET_NFC_RECORD_UNKNOWN : /* unknown msg. discard it */
+ case NET_NFC_RECORD_UNCHAGNED : /* RFU msg. discard it */
+ default :
+ break;
+ }
+
+ if (op_text != NULL)
+ {
+ snprintf(operation, length, "%s", op_text);
+ result = TRUE;
+ }
+
+ return result;
+}
+
+static void _to_lower_utf_8(char *str)
+{
+ while (*str != 0)
+ {
+ if (*str >= 'A' && *str <= 'Z')
+ *str += ('a' - 'A');
+
+ str++;
+ }
+}
+
+static void _to_lower(int type, char *str)
+{
+ _to_lower_utf_8(str);
+}
+
+static bool _net_nfc_app_util_get_mime_from_record(ndef_record_s *record, char *mime, size_t length)
+{
+ bool result = false;
+
+ if (record == NULL || mime == NULL || length == 0)
+ {
+ return result;
+ }
+
+ switch (record->TNF)
+ {
+ case NET_NFC_RECORD_WELL_KNOWN_TYPE :
+ {
+ if (record->type_s.buffer == NULL || record->type_s.length == 0 ||
+ record->payload_s.buffer == NULL || record->payload_s.length == 0)
+ {
+ DEBUG_ERR_MSG("Broken NDEF Message [NET_NFC_RECORD_WELL_KNOWN_TYPE]");
+ break;
+ }
+
+ if (record->type_s.length == 1 && record->type_s.buffer[0] == 'U')
+ {
+ snprintf(mime, length, "U/0x%02x", record->payload_s.buffer[0]);
+ }
+ else
+ {
+ memcpy(mime, record->type_s.buffer, record->type_s.length);
+ mime[record->type_s.length] = '\0';
+
+ strncat(mime, "/*", 2);
+ mime[record->type_s.length + 2] = '\0';
+ }
+
+ //DEBUG_SERVER_MSG("mime [%s]", mime);
+
+ result = true;
+ }
+ break;
+
+ case NET_NFC_RECORD_MIME_TYPE :
+ {
+ char *token = NULL;
+ char *buffer = NULL;
+ int len = 0;
+
+ if (record->type_s.buffer == NULL || record->type_s.length == 0)
+ {
+ DEBUG_ERR_MSG("Broken NDEF Message [NET_NFC_RECORD_MIME_TYPE]");
+ break;
+ }
+
+ /* get mime type */
+ _net_nfc_util_alloc_mem(buffer, record->type_s.length + 1);
+ if (buffer == NULL)
+ {
+ DEBUG_ERR_MSG("_net_nfc_manager_util_alloc_mem return NULL");
+ break;
+ }
+ memcpy(buffer, record->type_s.buffer, record->type_s.length);
+
+ //DEBUG_SERVER_MSG("NET_NFC_RECORD_MIME_TYPE type [%s]", buffer);
+
+ token = strchr(buffer, ';');
+ if (token != NULL)
+ {
+ //DEBUG_SERVER_MSG("token = strchr(buffer, ';') != NULL, len [%d]", token - buffer);
+ len = MIN(token - buffer, length - 1);
+ }
+ else
+ {
+ len = MIN(strlen(buffer), length - 1);
+ }
+
+ //DEBUG_SERVER_MSG("len [%d]", len);
+
+ strncpy(mime, buffer, len);
+ mime[len] = '\0';
+
+ _to_lower(0, mime);
+
+ //DEBUG_SERVER_MSG("mime [%s]", mime);
+
+ _net_nfc_util_free_mem(buffer);
+
+ result = true;
+ }
+ break;
+
+ case NET_NFC_RECORD_URI : /* Absolute URI */
+ case NET_NFC_RECORD_EXTERNAL_RTD : /* external type */
+ case NET_NFC_RECORD_EMPTY : /* empty_tag */
+ result = true;
+ break;
+
+ case NET_NFC_RECORD_UNKNOWN : /* unknown msg. discard it */
+ case NET_NFC_RECORD_UNCHAGNED : /* RFU msg. discard it */
+ default :
+ break;
+ }
+
+ return result;
+}
+
+#ifdef USE_FULL_URI
+static bool _net_nfc_app_util_get_uri_from_record(ndef_record_s *record, char *data, size_t length)
+{
+ bool result = false;
+
+ if (record == NULL || data == NULL || length == 0)
+ {
+ return result;
+ }
+
+ switch (record->TNF)
+ {
+ case NET_NFC_RECORD_WELL_KNOWN_TYPE :
+ case NET_NFC_RECORD_URI : /* Absolute URI */
+ {
+ char *uri = NULL;
+
+ if (net_nfc_util_create_uri_string_from_uri_record(record, &uri) == NET_NFC_OK &&
+ uri != NULL)
+ {
+ //DEBUG_SERVER_MSG("uri record : %s", uri);
+ snprintf(data, length, "%s", uri);
+
+ _net_nfc_util_free_mem(uri);
+ }
+ result = true;
+ }
+ break;
+
+ case NET_NFC_RECORD_EXTERNAL_RTD : /* external type */
+ {
+ data_s *type = &record->type_s;
+
+ if (type->length > 0)
+ {
+#if 0
+ char *buffer = NULL;
+ int len = strlen(NET_NFC_UTIL_EXTERNAL_TYPE_SCHEME);
+
+ _net_nfc_util_alloc_mem(buffer, type->length + len + 1);
+ if (buffer != NULL)
+ {
+ memcpy(buffer, NET_NFC_UTIL_EXTERNAL_TYPE_SCHEME, len);
+ memcpy(buffer + len, type->buffer, type->length);
+
+ /* to lower case!! */
+ strlwr(buffer);
+
+ DEBUG_SERVER_MSG("uri record : %s", buffer);
+ snprintf(data, length, "%s", buffer);
+
+ _net_nfc_util_free_mem(buffer);
+ }
+#else
+ int len = MIN(type->length, length - 1);
+ memcpy(data, type->buffer, len);
+ data[len] = 0;
+
+ /* to lower case!! */
+ _to_lower(0, data);
+
+ //DEBUG_SERVER_MSG("uri record : %s", data);
+ result = true;
+#endif
+ }
+ }
+ break;
+
+ case NET_NFC_RECORD_MIME_TYPE :
+ case NET_NFC_RECORD_EMPTY : /* empy msg. discard it */
+ result = true;
+ break;
+
+ case NET_NFC_RECORD_UNKNOWN : /* unknown msg. discard it */
+ case NET_NFC_RECORD_UNCHAGNED : /* RFU msg. discard it */
+ default :
+ break;
+ }
+
+ return result;
+}
+#endif
+
+static bool _net_nfc_app_util_get_data_from_record(ndef_record_s *record, char *data, size_t length)
+{
+ bool result = false;
+
+ if (record == NULL || data == NULL || length == 0)
+ {
+ return result;
+ }
+
+ switch (record->TNF)
+ {
+ case NET_NFC_RECORD_WELL_KNOWN_TYPE :
+ {
+ if (record->type_s.buffer == NULL || record->type_s.length == 0
+ || record->payload_s.buffer == NULL || record->payload_s.length == 0)
+ {
+ DEBUG_ERR_MSG("Broken NDEF Message [NET_NFC_RECORD_WELL_KNOWN_TYPE]");
+ break;
+ }
+
+ if (record->type_s.length == 1 && record->type_s.buffer[0] == 'T')
+ {
+ uint8_t *buffer_temp = record->payload_s.buffer;
+ uint32_t buffer_length = record->payload_s.length;
+
+ int index = (buffer_temp[0] & 0x3F) + 1;
+ int text_length = buffer_length - index;
+
+ memcpy(data, &(buffer_temp[index]), MIN(text_length, length));
+ }
+
+ //DEBUG_SERVER_MSG("data [%s]", data);
+
+ result = true;
+ }
+ break;
+
+ case NET_NFC_RECORD_MIME_TYPE :
+ case NET_NFC_RECORD_URI : /* Absolute URI */
+ case NET_NFC_RECORD_EXTERNAL_RTD : /* external type */
+ case NET_NFC_RECORD_EMPTY : /* empy msg. discard it */
+ result = true;
+ break;
+
+ case NET_NFC_RECORD_UNKNOWN : /* unknown msg. discard it */
+ case NET_NFC_RECORD_UNCHAGNED : /* RFU msg. discard it */
+ default :
+ break;
+ }
+
+ return result;
+}
+
+net_nfc_error_e net_nfc_app_util_process_ndef(data_s *data)
+{
+ net_nfc_error_e result = NET_NFC_UNKNOWN_ERROR;
+ ndef_message_s *msg = NULL;
+ char operation[2048] = { 0, };
+ char mime[2048] = { 0, };
+ char text[2048] = { 0, };
+#ifdef USE_FULL_URI
+ char uri[2048] = { 0, };
+#endif
+ int ret = 0;
+
+ if (data == NULL || data->buffer == NULL || data->length == 0)
+ {
+ DEBUG_ERR_MSG("net_nfc_app_util_process_ndef NET_NFC_NULL_PARAMETER");
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ /* create file */
+ if ((result = net_nfc_app_util_store_ndef_message(data)) != NET_NFC_OK)
+ {
+ DEBUG_ERR_MSG("net_nfc_app_util_store_ndef_message failed [%d]", result);
+ return result;
+ }
+
+ /* check state of launch popup */
+ if(net_nfc_app_util_check_launch_state() == TRUE)
+ {
+ DEBUG_SERVER_MSG("skip launch popup!!!");
+ result = NET_NFC_OK;
+ return result;
+ }
+
+ if (net_nfc_util_create_ndef_message(&msg) != NET_NFC_OK)
+ {
+ DEBUG_ERR_MSG("memory alloc fail..");
+ return NET_NFC_ALLOC_FAIL;
+ }
+
+ /* parse ndef message and fill appsvc data */
+ if ((result = net_nfc_util_convert_rawdata_to_ndef_message(data, msg)) != NET_NFC_OK)
+ {
+ DEBUG_ERR_MSG("net_nfc_app_util_store_ndef_message failed [%d]", result);
+ goto ERROR;
+ }
+
+ if (_net_nfc_app_util_get_operation_from_record(msg->records, operation, sizeof(operation)) == FALSE)
+ {
+ DEBUG_ERR_MSG("_net_nfc_app_util_get_operation_from_record failed [%d]", result);
+ result = NET_NFC_UNKNOWN_ERROR;
+ goto ERROR;
+ }
+
+ if (_net_nfc_app_util_get_mime_from_record(msg->records, mime, sizeof(mime)) == FALSE)
+ {
+ DEBUG_ERR_MSG("_net_nfc_app_util_get_mime_from_record failed [%d]", result);
+ result = NET_NFC_UNKNOWN_ERROR;
+ goto ERROR;
+ }
+#ifdef USE_FULL_URI
+ if (_net_nfc_app_util_get_uri_from_record(msg->records, uri, sizeof(uri)) == FALSE)
+ {
+ DEBUG_ERR_MSG("_net_nfc_app_util_get_uri_from_record failed [%d]", result);
+ result = NET_NFC_UNKNOWN_ERROR;
+ goto ERROR;
+ }
+#endif
+ /* launch appsvc */
+ if (_net_nfc_app_util_get_data_from_record(msg->records, text, sizeof(text)) == FALSE)
+ {
+ DEBUG_ERR_MSG("_net_nfc_app_util_get_data_from_record failed [%d]", result);
+ result = NET_NFC_UNKNOWN_ERROR;
+ goto ERROR;
+ }
+
+ ret = net_nfc_app_util_appsvc_launch(operation, uri, mime, text);
+#if 0
+ if (ret == APPSVC_RET_ENOMATCH)
+ {
+ /* TODO : check again */
+ ret = net_nfc_app_util_appsvc_launch(operation, uri, mime, text);
+ }
+#endif
+
+ DEBUG_SERVER_MSG("net_nfc_app_util_appsvc_launch return %d", ret);
+
+ result = NET_NFC_OK;
+
+ERROR :
+ net_nfc_util_free_ndef_message(msg);
+
+ return result;
+}
+
+static bool net_nfc_app_util_is_dir(const char* path_name)
+{
+ struct stat statbuf = { 0 };
+
+ if (stat(path_name, &statbuf) == -1)
+ {
+ return false;
+ }
+
+ if (S_ISDIR(statbuf.st_mode) != 0)
+ {
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+}
+
+void net_nfc_app_util_clean_storage(char* src_path)
+{
+ struct dirent* ent = NULL;
+ DIR* dir = NULL;
+
+ char path[1024] = { 0 };
+
+ if ((dir = opendir(src_path)) == NULL)
+ {
+ return;
+ }
+
+ while ((ent = readdir(dir)) != NULL)
+ {
+ if (strncmp(ent->d_name, ".", 1) == 0 || strncmp(ent->d_name, "..", 2) == 0)
+ {
+ continue;
+ }
+ else
+ {
+ snprintf(path, 1024, "%s/%s", src_path, ent->d_name);
+
+ if (net_nfc_app_util_is_dir(path) != false)
+ {
+ net_nfc_app_util_clean_storage(path);
+ rmdir(path);
+ }
+ else
+ {
+ unlink(path);
+ }
+ }
+ }
+
+ closedir(dir);
+
+ rmdir(src_path);
+}
+
+void net_nfc_app_util_aul_launch_app(char* package_name, bundle* kb)
+{
+ int result = 0;
+ if((result = aul_launch_app(package_name, kb)) < 0)
+ {
+ switch(result)
+ {
+ case AUL_R_EINVAL:
+ DEBUG_SERVER_MSG("aul launch error : AUL_R_EINVAL");
+ break;
+ case AUL_R_ECOMM:
+ DEBUG_SERVER_MSG("aul launch error : AUL_R_ECOM");
+ break;
+ case AUL_R_ERROR:
+ DEBUG_SERVER_MSG("aul launch error : AUL_R_ERROR");
+ break;
+ default:
+ DEBUG_SERVER_MSG("aul launch error : unknown ERROR");
+ break;
+ }
+ }
+ else
+ {
+ DEBUG_SERVER_MSG("success to launch [%s]", package_name);
+ }
+}
+
+int net_nfc_app_util_appsvc_launch(const char *operation, const char *uri, const char *mime, const char *data)
+{
+ int result = -1;
+
+ bundle *bd = NULL;
+
+ bd = bundle_create();
+ if (bd == NULL)
+ return result;
+
+ if (operation != NULL && strlen(operation) > 0)
+ {
+ DEBUG_SERVER_MSG("operation : %s", operation);
+ appsvc_set_operation(bd, operation);
+ }
+
+ if (uri != NULL && strlen(uri) > 0)
+ {
+ DEBUG_SERVER_MSG("uri : %s", uri);
+ appsvc_set_uri(bd, uri);
+ }
+
+ if (mime != NULL && strlen(mime) > 0)
+ {
+ DEBUG_SERVER_MSG("mime : %s", mime);
+ appsvc_set_mime(bd, mime);
+ }
+
+ if (data != NULL && strlen(data) > 0)
+ {
+ DEBUG_SERVER_MSG("data : %s", data);
+ appsvc_add_data(bd, "data", data);
+ }
+
+ bundle_add(bd, OSP_K_COND, OSP_K_COND_TYPE);
+ bundle_add(bd, OSP_K_LAUNCH_TYPE, osp_launch_type_condition);
+
+ result = appsvc_run_service(bd, 0, NULL, NULL);
+
+ bundle_free(bd);
+
+ return result;
+}
+
+void _binary_to_string(uint8_t *buffer, uint32_t len, char *out_buf, uint32_t max_len)
+{
+ int current = 0;
+
+ if (buffer == NULL || len == 0 || out_buf == NULL || max_len == 0)
+ return;
+
+ while (len > 0 && current < max_len)
+ {
+ current += snprintf(out_buf + current, max_len - current, "%02X", *(buffer++));
+ len--;
+ }
+}
+
+void _string_to_binary(const char *input, uint8_t *output, uint32_t *length)
+{
+ int current = 0;
+ int temp;
+
+ if (input == NULL || *length == 0 || output == NULL)
+ return;
+
+ DEBUG_SERVER_MSG("_string_to_binary ");
+
+ /* strlen("nfc://secure/aid/") = 17 */
+
+ input += 17;
+
+ while (*input && (current < *length))
+ {
+ temp = (*input++) - '0';
+
+ if(temp > 9)
+ temp -= 7;
+
+ if(current % 2)
+ {
+ output[current / 2] += temp;
+ }
+ else
+ {
+ output[current / 2] = temp << 4;
+ }
+
+ current++;
+ }
+
+ *length = current / 2;
+}
+
+int net_nfc_app_util_launch_se_transaction_app(uint8_t *aid, uint32_t aid_len, uint8_t *param, uint32_t param_len)
+{
+ bundle *bd = NULL;
+
+ /* launch */
+ bd = bundle_create();
+
+ appsvc_set_operation(bd, "http://tizen.org/appcontrol/operation/nfc/transaction");
+
+ /* convert aid to aid string */
+ if (aid != NULL && aid_len > 0)
+ {
+ char temp_string[1024] = { 0, };
+ char aid_string[1024] = { 0, };
+
+ _binary_to_string(aid, aid_len, temp_string, sizeof(temp_string));
+ snprintf(aid_string, sizeof(aid_string), "nfc://secure/aid/%s", temp_string);
+ DEBUG_SERVER_MSG("aid_string : %s", aid_string);
+ appsvc_set_uri(bd, aid_string);
+ }
+
+ if (param != NULL && param_len > 0)
+ {
+ char param_string[1024] = { 0, };
+
+ _binary_to_string(param, param_len, param_string, sizeof(param_string));
+ DEBUG_SERVER_MSG("param_string : %s", param_string);
+ appsvc_add_data(bd, "data", param_string);
+ }
+
+ appsvc_run_service(bd, 0, NULL, NULL);
+ bundle_free(bd);
+
+ return 0;
+}
+
+int net_nfc_app_util_encode_base64(uint8_t *buffer, uint32_t buf_len, char *result, uint32_t max_result)
+{
+ int ret = -1;
+ BUF_MEM *bptr;
+ BIO *b64, *bmem;
+
+ if (buffer == NULL || buf_len == 0 || result == NULL || max_result == 0)
+ return ret;
+
+ /* base 64 */
+ b64 = BIO_new(BIO_f_base64());
+ BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL);
+ bmem = BIO_new(BIO_s_mem());
+ b64 = BIO_push(b64, bmem);
+
+ BIO_write(b64, buffer, buf_len);
+ BIO_flush(b64);
+ BIO_get_mem_ptr(b64, &bptr);
+
+ memset(result, 0, max_result);
+ memcpy(result, bptr->data, MIN(bptr->length, max_result - 1));
+
+ BIO_free_all(b64);
+
+ ret = 0;
+
+ return ret;
+}
+
+int net_nfc_app_util_decode_base64(const char *buffer, uint32_t buf_len, uint8_t *result, uint32_t *res_len)
+{
+ int ret = -1;
+ char *temp = NULL;
+
+ if (buffer == NULL || buf_len == 0 || result == NULL || res_len == NULL || *res_len == 0)
+ return ret;
+
+ _net_nfc_util_alloc_mem(temp, buf_len);
+ if (temp != NULL)
+ {
+ BIO *b64, *bmem;
+ uint32_t temp_len;
+
+ b64 = BIO_new(BIO_f_base64());
+ BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL);
+ bmem = BIO_new_mem_buf((void *)buffer, buf_len);
+ bmem = BIO_push(b64, bmem);
+
+ temp_len = BIO_read(bmem, temp, buf_len);
+
+ BIO_free_all(bmem);
+
+ memset(result, 0, *res_len);
+ memcpy(result, temp, MIN(temp_len, *res_len));
+
+ *res_len = MIN(temp_len, *res_len);
+
+ _net_nfc_util_free_mem(temp);
+
+ ret = 0;
+ }
+ else
+ {
+ DEBUG_ERR_MSG("alloc failed");
+ }
+
+ return ret;
+}
+
+static pid_t _net_nfc_app_util_get_focus_app_pid()
+{
+ Ecore_X_Window focus;
+ pid_t pid;
+
+ ecore_x_init(":0");
+
+ focus = ecore_x_window_focus_get();
+ if (ecore_x_netwm_pid_get(focus, &pid))
+ return pid;
+
+ return -1;
+}
+
+bool net_nfc_app_util_check_launch_state()
+{
+ pid_t focus_app_pid;
+ net_nfc_launch_popup_state_e popup_state;
+ bool result = false;
+
+ focus_app_pid = _net_nfc_app_util_get_focus_app_pid();
+
+ popup_state = net_nfc_server_gdbus_get_client_popup_state(focus_app_pid);
+
+ if(popup_state == NET_NFC_NO_LAUNCH_APP_SELECT)
+ result = true;
+
+ return result;
+}
+
+static void _play_sound_callback(int id, void *data)
+{
+ DEBUG_MSG("_play_sound_callback");
+
+ if (WAV_PLAYER_ERROR_NONE != wav_player_stop(id))
+ {
+ DEBUG_MSG("wav_player_stop failed");
+ }
+}
+
+void net_nfc_manager_util_play_sound(net_nfc_sound_type_e sound_type)
+{
+ int bSoundOn = 0;
+ int bVibrationOn = 0;
+
+ if (vconf_get_bool(VCONFKEY_SETAPPL_SOUND_STATUS_BOOL, &bSoundOn) != 0)
+ {
+ DEBUG_MSG("vconf_get_bool failed for Sound");
+ return;
+ }
+
+ if (vconf_get_bool(VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL, &bVibrationOn) != 0)
+ {
+ DEBUG_MSG("vconf_get_bool failed for Vibration");
+ return;
+ }
+
+ if ((sound_type > NET_NFC_TASK_ERROR) || (sound_type < NET_NFC_TASK_START))
+ {
+ DEBUG_MSG("Invalid Sound Type");
+ return;
+ }
+
+ if (bVibrationOn)
+ {
+ int svi_handle = -1;
+
+ DEBUG_MSG("Play Vibration");
+
+ if (SVI_SUCCESS == svi_init(&svi_handle))
+ {
+ if (SVI_SUCCESS == svi_play_vib(svi_handle, SVI_VIB_TOUCH_SIP))
+ {
+ DEBUG_MSG("svi_play_vib success");
+ }
+
+ svi_fini(svi_handle);
+ }
+ }
+
+ if (bSoundOn)
+ {
+ char *sound_path = NULL;
+
+ DEBUG_MSG("Play Sound");
+
+ switch (sound_type)
+ {
+ case NET_NFC_TASK_START :
+ sound_path = strdup(NET_NFC_MANAGER_SOUND_PATH_TASK_START);
+ break;
+ case NET_NFC_TASK_END :
+ sound_path = strdup(NET_NFC_MANAGER_SOUND_PATH_TASK_END);
+ break;
+ case NET_NFC_TASK_ERROR :
+ sound_path = strdup(NET_NFC_MANAGER_SOUND_PATH_TASK_ERROR);
+ break;
+ }
+
+ if (sound_path != NULL)
+ {
+ if (WAV_PLAYER_ERROR_NONE == wav_player_start(sound_path, SOUND_TYPE_MEDIA, _play_sound_callback, NULL, NULL))
+ {
+ DEBUG_MSG("wav_player_start success");
+ }
+
+ _net_nfc_util_free_mem(sound_path);
+ }
+ else
+ {
+ DEBUG_ERR_MSG("Invalid Sound Path");
+ }
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_SERVER_UTIL_H__
+#define __NET_NFC_SERVER_UTIL_H__
+
+#include <aul.h>
+#include "net_nfc_typedef_internal.h"
+
+#ifndef MESSAGE_STORAGE
+#define MESSAGE_STORAGE "/opt/share/service/nfc-manager"
+#endif
+
+typedef enum
+{
+ NET_NFC_TASK_START = 0x00,
+ NET_NFC_TASK_END,
+ NET_NFC_TASK_ERROR
+} net_nfc_sound_type_e;
+
+void net_nfc_manager_util_play_sound(net_nfc_sound_type_e sound_type);
+
+net_nfc_error_e net_nfc_app_util_process_ndef(data_s *data);
+void net_nfc_app_util_aul_launch_app(char* package_name, bundle* kb);
+void net_nfc_app_util_clean_storage(char* src_path);
+int net_nfc_app_util_appsvc_launch(const char *operation, const char *uri, const char *mime, const char *data);
+int net_nfc_app_util_launch_se_transaction_app(uint8_t *aid, uint32_t aid_len, uint8_t *param, uint32_t param_len);
+int net_nfc_app_util_encode_base64(uint8_t *buffer, uint32_t buf_len, char *result, uint32_t max_result);
+int net_nfc_app_util_decode_base64(const char *buffer, uint32_t buf_len, uint8_t *result, uint32_t *res_len);
+bool net_nfc_app_util_check_launch_state();
+
+#endif //__NET_NFC_SERVER_UTIL_H__
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <glib.h>
+#include <vconf.h>
+
+#include "net_nfc_typedef.h"
+
+#include "net_nfc_server_vconf.h"
+#include "net_nfc_server_common.h"
+#include "net_nfc_server_manager.h"
+
+#include "net_nfc_debug_internal.h"
+
+static gboolean powered_off_by_flightmode = FALSE;
+
+static void vconf_set_flight_mode(int boolval);
+
+static void net_nfc_server_vconf_pm_state_changed(keynode_t *key,
+ void *user_data);
+
+static void net_nfc_server_vconf_flight_mode_changed(keynode_t *key,
+ void *user_data);
+
+
+static void vconf_set_flight_mode(int boolval)
+{
+ gint result;
+
+ /* set predefined item */
+ result = vconf_set_bool(VCONFKEY_NFC_PREDEFINED_ITEM_STATE, boolval);
+ if (result != 0)
+ {
+ DEBUG_ERR_MSG("can not set to %d: %s",
+ boolval,
+ "VCONKEY_NFC_PREDEFINED_ITEM_STATE");
+ }
+}
+
+static void net_nfc_server_vconf_pm_state_changed(keynode_t *key,
+ void *user_data)
+{
+ gint state = 0;
+ gint pm_state = 0;
+ gint result;
+
+ result = vconf_get_bool(VCONFKEY_NFC_STATE, &state);
+ if (result != 0)
+ DEBUG_ERR_MSG("can not get %s", "VCONFKEY_NFC_STATE");
+
+ if (state == false)
+ {
+ DEBUG_MSG("NFC off");
+ return;
+ }
+
+ result = vconf_get_int(VCONFKEY_PM_STATE, &pm_state);
+ if (result != 0)
+ DEBUG_ERR_MSG("can not get %s", "VCONFKEY_PM_STATE");
+
+ DEBUG_SERVER_MSG("pm_state : %d", pm_state);
+
+ if (pm_state == VCONFKEY_PM_STATE_NORMAL ||
+ pm_state == VCONFKEY_PM_STATE_LCDOFF)
+ {
+ net_nfc_server_restart_polling_loop();
+ }
+}
+
+static void net_nfc_server_vconf_flight_mode_changed(keynode_t *key,
+ void *user_data)
+{
+ gint flight_mode = 0;
+ gint nfc_state = 0;
+
+ gint result = 0;
+
+ result = vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, &flight_mode);
+ if (result != 0)
+ {
+ DEBUG_ERR_MSG("Can not get %s",
+ "VCONFKEY_TELEPHONY_FLIGHT_MODE");
+ }
+
+ DEBUG_SERVER_MSG("flight mode %d", flight_mode);
+
+ result = vconf_get_bool(VCONFKEY_NFC_STATE, &nfc_state);
+ if (result != 0)
+ {
+ DEBUG_ERR_MSG("Can not get %s",
+ "VCONFKEY_NET_STATE");
+ }
+
+ DEBUG_SERVER_MSG("nfc_state %d", nfc_state);
+ DEBUG_SERVER_MSG("powerd_off_by_flightmode %d",
+ powered_off_by_flightmode);
+
+ if (flight_mode) /* turn on flight mode */
+ {
+ /* nfc is already disabled ignore it */
+ if (nfc_state == VCONFKEY_NFC_STATE_OFF)
+ return;
+
+ DEBUG_SERVER_MSG("Turning NFC off");
+ net_nfc_server_manager_set_active(FALSE);
+
+ powered_off_by_flightmode = TRUE;
+
+ vconf_set_flight_mode(0);
+ }
+ else /* turn off flight mode */
+ {
+ /* nfc is already enabled, ignre it */
+ if (nfc_state == VCONFKEY_NFC_STATE_ON)
+ return;
+
+ if (powered_off_by_flightmode == FALSE)
+ return;
+
+ DEBUG_SERVER_MSG("Turning NFC on");
+ net_nfc_server_manager_set_active(TRUE);
+
+ powered_off_by_flightmode = FALSE;
+
+ vconf_set_flight_mode(1);
+ }
+}
+
+void net_nfc_server_vconf_init(void)
+{
+ vconf_notify_key_changed(VCONFKEY_PM_STATE,
+ net_nfc_server_vconf_pm_state_changed,
+ NULL);
+
+ vconf_notify_key_changed(VCONFKEY_TELEPHONY_FLIGHT_MODE,
+ net_nfc_server_vconf_flight_mode_changed,
+ NULL);
+}
+
+void net_nfc_server_vconf_deinit(void)
+{
+ vconf_ignore_key_changed(VCONFKEY_PM_STATE,
+ net_nfc_server_vconf_pm_state_changed);
+
+ vconf_ignore_key_changed(VCONFKEY_TELEPHONY_FLIGHT_MODE,
+ net_nfc_server_vconf_flight_mode_changed);
+}
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_SERVER_VCONF_H__
+#define __NET_NFC_SERVER_VCONF_H__
+
+void net_nfc_server_vconf_init(void);
+
+void net_nfc_server_vconf_deinit(void);
+
+#endif //__NET_NFC_SERVER_VCONF_H__
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<manifest xmlns="http://tizen.org/ns/packages"
+ package="nfc-manager"
+ version="0.1.0"
+ install-location="internal-only"
+ type="rpm">
+ <label>NFC Manager</label>
+ <author email="email" href="www.samsung.com">name</author>
+ <description>NFC manager</description>
+ <ui-application appid="nfc-manager"
+ exec="/usr/bin/nfc-manager-daemon"
+ nodisplay="true"
+ multiple="false"
+ type="capp"
+ taskmanage="false"
+ mainapp="true">
+ <label>NFC Manager</label>
+ </ui-application>
+</manifest>
--- /dev/null
+[D-BUS Service]
+Name=org.tizen.NetNfcService
+Exec=/usr/bin/nfc-manager-daemon
+++ /dev/null
-nfc-manager (0.0.1-77) unstable; urgency=low
-
- * JSR257 NDEF absoluteURI issue resolved
- * Git: slp/pkgs/n/nfc-manager
- * Tag: nfc-manager_0.0.1-77
-
- -- Sechang Sohn <sc.sohn@samsung.com> Thu, 31 May 2012 10:18:24 +0900
-
-nfc-manager (0.0.1-76) unstable; urgency=low
-
- * Add the function checking nfc feature
- * Git: slp/pkgs/n/nfc-manager
- * Tag: nfc-manager_0.0.1-76
-
- -- Wonkyu Kwon <wonkyu.kwon@samsung.com> Wed, 30 May 2012 16:24:50 +0900
-
-nfc-manager (0.0.1-75) unstable; urgency=low
-
- * Modify the plugin check routine
- * Git: slp/pkgs/n/nfc-manager
- * Tag: nfc-manager_0.0.1-75
-
- -- Sungjae Lim <neueziel.lim@samsung.com> Thu, 24 May 2012 17:00:11 +0900
-
-nfc-manager (0.0.1-74) unstable; urgency=low
-
- * Add signature RTD library and ndef-tool
- * Git: slp/pkgs/n/nfc-manager
- * Tag: nfc-manager_0.0.1-74
-
- -- Wonkyu Kwon <wonkyu.kwon@samsung.com> Mon, 21 May 2012 15:32:08 +0900
-
-nfc-manager (0.0.1-73) unstable; urgency=low
-
- * Modify the Private vconf.
- * Git: slp/pkgs/n/nfc-manager
- * Tag: nfc-manager_0.0.1-73
-
- -- Sungjae Lim <neueziel.lim@samsung.com> Mon, 16 May 2012 11:00:11 +0900
-
-nfc-manager (0.0.1-72) unstable; urgency=low
-
- * Modify the absolute uri.
- * Git: slp/pkgs/n/nfc-manager
- * Tag: nfc-manager_0.0.1-72
-
- -- Sungjae Lim <neueziel.lim@samsung.com> Mon, 14 May 2012 17:00:11 +0900
-
-nfc-manager (0.0.1-71) unstable; urgency=low
-
- * Add the routine to initialize the vconf for nfc
- * Git: slp/pkgs/n/nfc-manager
- * Tag: nfc-manager_0.0.1-71
-
- -- Junyong Sim <junyong.sim@samsung.com> Mon, 07 May 2012 16:37:50 +0900
-
-nfc-manager (0.0.1-70) unstable; urgency=low
-
- * Remove unused file
- * Git: slp/pkgs/n/nfc-manager
- * Tag: nfc-manager_0.0.1-70
-
- -- Wonkyu Kwon <wonkyu.kwon@samsung.com> Fri, 04 May 2012 14:21:29 +0900
-
-nfc-manager (0.0.1-69) unstable; urgency=low
-
- * Add the pm's lock&unlock api.
- * Git: slp/pkgs/n/nfc-manager
- * Tag: nfc-manager_0.0.1-69
-
- -- Sungjae Lim <neueziel.lim@samsung.com> Thu, 03 May 2012 17:00:11 +0900
-
-nfc-manager (0.0.1-68) unstable; urgency=low
-
- * Remove the nfc-agent's daemon
- * Git: slp/pkgs/n/nfc-manager
- * Tag: nfc-manager_0.0.1-68
-
- -- Sungjae Lim <neueziel.lim@samsung.com> Thu, 26 Apr 2012 17:17:17 +0900
-
-nfc-manager (0.0.1-67) unstable; urgency=low
-
- * initialize vconf value : db/nfc/feature
- * Git: slp/pkgs/n/nfc-manager
- * Tag: nfc-manager_0.0.1-67
-
- -- Junyong Sim <junyong.sim@samsung.com> Tue, 24 Apr 2012 21:17:17 +0900
-
-nfc-manager (0.0.1-66) unstable; urgency=low
-
- * apply the access control in SE transaction.
- * Git: slp/pkgs/n/nfc-manager
- * Tag: nfc-manager_0.0.1-66
-
- -- Wonkyu Kwon <wonkyu.kwon@samsung.com> Fri, 20 Apr 2012 11:00:00 +0900
-
-nfc-manager (0.0.1-65) unstable; urgency=low
-
- * Check the state using nfc set state func
- * Git: slp/pkgs/n/nfc-manager
- * Tag: nfc-manager_0.0.1-65
-
- -- Sungjae Lim <neueziel.lim@samsung.com> Thu, 19 Apr 2012 13:54:15 +0900
-
-nfc-manager (0.0.1-64) unstable; urgency=low
-
- * Modify the spec & net_nfc_set_state's return value
- * Git: slp/pkgs/n/nfc-manager
- * Tag: nfc-manager_0.0.1-64
-
- -- Sungjae Lim <neueziel.lim@samsung.com> Thu, 05 Apr 2012 19:32:15 +0900
-
-nfc-manager (0.0.1-63) unstable; urgency=low
-
- * package upload
- * Git: slp/pkgs/n/nfc-manager
- * Tag: nfc-manager_0.0.1-63
-
- -- Sungjae Lim <neueziel.lim@samsung.com> Wed, 04 Apr 2012 16:58:15 +0900
-
-nfc-manager (0.0.1-62) unstable; urgency=low
-
- * Check the plugin's so file for Pulic Version
- * Git: slp/pkgs/n/nfc-manager
- * Tag: nfc-manager_0.0.1-62
-
- -- Sungjae Lim <neuezieil.lim@samsung.com> Wed, 04 Apr 2012 10:58:15 +0900
-
-nfc-manager (0.0.1-61) unstable; urgency=low
-
- * Add the routine to check tag stage
- * Git: slp/pkgs/n/nfc-manager
- * Tag: nfc-manager_0.0.1-61
-
- -- Junyong Sim <junyong.sim@samsung.com> Thu, 29 Mar 2012 14:38:15 +0900
-
-nfc-manager (0.0.1-60) unstable; urgency=low
-
- * Modify SE event
- * Git: slp/pkgs/n/nfc-manager
- * Tag: nfc-manager_0.0.1-60
-
- -- Sangsoo Lee <constant.lee@samsung.com> Fri, 16 Mar 2012 16:11:31 +0900
-
-nfc-manager (0.0.1-59) unstable; urgency=low
-
- * change appsvc operation
- * Git: slp/pkgs/n/nfc-manager
- * Tag: nfc-manager_0.0.1-59
-
- -- Wonkyu Kwon <wonkyu.kwon@samsung.com> Thu, 15 Mar 2012 15:30:00 +0900
-
-nfc-manager (0.0.1-58) unstable; urgency=low
-
- * bug fix about trans param
- * Git: slp/pkgs/n/nfc-manager
- * Tag: nfc-manager_0.0.1-58
-
- -- Sangsoo Lee <constant.lee@samsung.com> Thu, 15 Mar 2012 11:06:38 +0900
-
-nfc-manager (0.0.1-57) unstable; urgency=low
-
- * remove capi dependency
- * Git: slp/pkgs/n/nfc-manager
- * Tag: nfc-manager_0.0.1-57
-
- -- Junyong Sim <junyong.sim@samsung.com> Wed, 14 Mar 2012 19:54:13 +0900
-
-nfc-manager (0.0.1-56) unstable; urgency=low
-
- * Broadcasting enable
- * Git: slp/pkgs/n/nfc-manager
- * Tag: nfc-manager_0.0.1-56
-
- -- Sangsoo Lee <constant.lee@samsung.com> Mon, 12 Mar 2012 16:52:39 +0900
-
-nfc-manager (0.0.1-55) unstable; urgency=low
-
- * Tag connection check api change
- * Git: slp/pkgs/n/nfc-manager
- * Tag: nfc-manager_0.0.1-55
-
- -- Sangsoo Lee <constant.lee@samsung.com> Wed, 07 Mar 2012 17:21:51 +0900
-
-nfc-manager (0.0.1-54) unstable; urgency=low
-
- * add new client api
- * Git: slp/pkgs/n/nfc-manager
- * Tag: nfc-manager_0.0.1-54
-
- -- Sangsoo Lee <constant.lee@samsung.com> Tue, 06 Mar 2012 20:30:19 +0900
-
-nfc-manager (0.0.1-53) unstable; urgency=low
-
- * fix the crash issue of nfc manager in emulator
- * Git: slp/pkgs/n/nfc-manager
- * Tag: nfc-manager_0.0.1-53
-
- -- Junyong Sim <junyong.sim@samsung.com> Mon, 05 Mar 2012 10:02:00 +0900
-
-nfc-manager (0.0.1-52) unstable; urgency=low
-
- * Upload package
- * Git: slp/pkgs/n/nfc-manager
- * Tag: nfc-manager_0.0.1-52
-
- -- Wonkyu Kwon <wonkyu.kwon@samsung.com> Mon, 27 Feb 2012 17:00:00 +0900
-
-nfc-manager (0.0.1-51) unstable; urgency=low
-
- * Implement the check routin to distinguish the driver
- * Git: slp/pkgs/n/nfc-manager
- * Tag: nfc-manager_0.0.1-51
-
- -- Sechang Sohn <sc.sohn@samsung.com> Tue, 21 Feb 2012 13:06:37 +0900
-
-nfc-manager (0.0.1-50) unstable; urgency=low
-
- * Implement the check routin to distinguish the driver
- * Git: slp/pkgs/n/nfc-manager
- * Tag: nfc-manager_0.0.1-50
-
- -- Sungjae Lim <neuezieil.lim@samsung.com> Mon, 20 Feb 2012 10:36:28 +0900
-
-nfc-manager (0.0.1-49) unstable; urgency=low
-
- * Update changelog
- * Git: slp/pkgs/n/nfc-manager
- * Tag: nfc-manager_0.0.1-49
-
- -- Junyong Sim <junyong.sim@samsung.com> Mon, 06 Feb 2012 10:36:28 +0900
-
-nfc-manager (0.0.1-48) unstable; urgency=low
-
- * Implement the polling loop after wake-up.
- * Git: slp/pkgs/n/nfc-manager
- * Tag: nfc-manager_0.0.1-48
-
- -- Sungjae Lim <neueziel.lim@samsung.com> Fri, 03 Feb 2012 14:47:35 +0900
-
-nfc-manager (0.0.1-47) unstable; urgency=low
-
- * Modify the LTO value from 10 to 100.
- * Git: slp/pkgs/n/nfc-manager
- * Tag: nfc-manager_0.0.1-47
-
- -- Sungjae Lim <neueziel.lim@samsung.com> Wed, 01 Feb 2012 09:23:35 +0900
-
-nfc-manager (0.0.1-46) unstable; urgency=low
-
- * Fix build error when is using cxx compiler
- * Git: slp/pkgs/n/nfc-manager
- * Tag: nfc-manager_0.0.1-46
-
- -- Wonkyu Kwon <wonkyu.kwon@samsung.com> Thu, 26 Jan 2012 15:00:35 +0900
-
-nfc-manager (0.0.1-45) unstable; urgency=low
-
- * Change IPC request algorithm from client to server
- * Git: slp/pkgs/n/nfc-manager
- * Tag: nfc-manager_0.0.1-45
-
- -- Wonkyu Kwon <wonkyu.kwon@samsung.com> Thu, 29 Dec 2011 13:00:35 +0900
-
-nfc-manager (0.0.1-44) unstable; urgency=low
-
- * modify changelog
- * Git: slp/pkgs/n/nfc-manager
- * Tag: nfc-manager_0.0.1-44
-
- -- Junyong Sim <junyong.sim@samsung.com> Thu, 15 Dec 2011 18:58:35 +0900
-
-nfc-manager (0.0.1-43) unstable; urgency=low
-
- * Change ambiguous value name and option name
- * Git: 165.213.180.234:slp/pkgs/n/nfc-manager
- * Tag: nfc-manager_0.0.1-43
-
- -- Sangsoo Lee <constant.lee@samsung.com> Wed, 07 Dec 2011 12:45:19 +0900
-
-nfc-manager (0.0.1-42) unstable; urgency=low
-
- * Clean unused code
- * Git: 165.213.180.234:slp/pkgs/n/nfc-manager
- * Tag: nfc-manager_0.0.1-42
-
- -- Wonkyu kwon <wonkyu.kwon@samsung.com> Tue, 06 Dec 2011 17:40:00 +0900
-
-nfc-manager (0.0.1-41) unstable; urgency=low
-
- *Modify the code
- *Git: 165.213.180.234:slp/pkgs/n/nfc-manager
- *Tag: nfc-manager_0.0.1-41
-
- -- Sungjae Lim <neueziel.lim@samsung.com> Tue, 06 Dec 2011 12:40:45 +0900
-
-nfc-manager (0.0.1-40) unstable; urgency=low
-
- *Change AUTHORS.
- *Git: 165.213.180.234:slp/pkgs/n/nfc-manager
- *Tag: nfc-manager_0.0.1-40
-
- -- Junyong Sim <junyong.sim@samsung.com> Sat, 03 Dec 2011 13:05:45 +0900
-
-nfc-manager (0.0.1-39) unstable; urgency=low
-
- *Package Upload.
- *Git: 165.213.180.234:slp/pkgs/n/nfc-manager
- *Tag: nfc-manager_0.0.1-39
-
- -- sungjae.lim <neueziel.lim@samsung.com> Fri, 02 Dec 2011 19:57:07 +0900
-
-nfc-manager (0.0.1-38) unstable; urgency=low
-
- *Change the boilerplate.
- *Git: 165.213.180.234:slp/pkgs/n/nfc-manager
- *Tag: nfc-manager_0.0.1-38
-
- -- sungjae.lim <neueziel.lim@samsung.com> Fri, 02 Dec 2011 19:00:07 +0900
-
-nfc-manager (0.0.1-37) unstable; urgency=low
-
- *Change the function name for 3rd part.
- *Git: 165.213.180.234:slp/pkgs/n/nfc-manager
- *Tag: nfc-manager_0.0.1-37
-
- -- sungjae.lim <neueziel.lim@samsung.com> Fri, 02 Dec 2011 11:20:07 +0900
-
-nfc-manager (0.0.1-36) unstable; urgency=low
-
- *Bug fix.
- *Git: 165.213.180.234:slp/pkgs/n/nfc-manager
- *Tag: nfc-manager_0.0.1-36
-
- -- constant.lee <constant.lee@samsung.com> Thu, 01 Dec 2011 21:08:07 +0900
-
-nfc-manager (0.0.1-35) unstable; urgency=low
-
- *Change the boilerplate.
- *Git: 165.213.180.234:slp/pkgs/n/nfc-manager
- *Tag: nfc-manager_0.0.1-35
-
- -- Sungjae Lim <neueziel.lim@samsung.com> Thu, 01 Dec 2011 15:55:42 +0900
-
-nfc-manager (0.0.1-34) unstable; urgency=low
-
- * Package upload
- * Git: 165.213.180.234:slp/pkgs/n/nfc-manager
- * Tag: nfc-manager_0.0.1-34
-
- -- Wonkyu Kwon <wonkyu.kwon@samsung.com> Wed, 30 Nov 2011 18:00:00 +0900
-
-nfc-manager (0.0.1-33) unstable; urgency=low
-
- *some error value change
- *Git: 165.213.180.234:slp/pkgs/n/nfc-manager
- *Tag: nfc-manager_0.0.1-33
-
- -- Sangsoo Lee <constant.lee@samsung.com> Tue, 29 Nov 2011 14:45:40 +0900
-
-nfc-manager (0.0.1-32) unstable; urgency=low
-
- *NET_NFC_MESSSAGE_P2P_RECEIVE problem fix
- *Git: 165.213.180.234:slp/pkgs/n/nfc-manager
- *Tag: nfc-manager_0.0.1-32
-
- -- Sangsoo Lee <constant.lee@samsung.com> Tue, 29 Nov 2011 13:07:01 +0900
-
-nfc-manager (0.0.1-31) unstable; urgency=low
-
- *p2p popup problem fix.
- *Git: 165.213.180.234:slp/pkgs/n/nfc-manager
- *Tag: nfc-manager_0.0.1-31
-
- -- Sangsoo Lee <constant.lee@samsung.com> Fri, 25 Nov 2011 15:04:48 +0900
-
-nfc-manager (0.0.1-30) unstable; urgency=low
-
- *bug fix
- *Git: 165.213.180.234:slp/pkgs/n/nfc-manager
- *Tag : nfc-manager_0.0.1-30
-
- -- Sangsoo Lee <constant.lee@samsung.com> Fri, 18 Nov 2011 12:45:58 +0900
-
-nfc-manager (0.0.1-29) unstable; urgency=low
-
- *LLCP problem was fixed. and some message name change.
- *Git: 165.213.180.234:slp/pkgs/n/nfc-manager
- *Tag: nfc-manager_0.0.1-29
-
- -- Sangsoo Lee <constant.lee@samsung.com> Wed, 16 Nov 2011 22:55:18 +0900
-
-nfc-manager (0.0.1-28) unstable; urgency=low
-
- *NXP parser was seperated to net_nfc_util_ndef_parser.c
- *Git: 165.213.180.234:slp/pkgs/n/nfc-manager
- *Tag: nfc-manager_0.0.1-28
-
- -- Sangsoo Lee <constant.lee@samsung.com> Wed, 02 Nov 2011 18:30:57 +0900
-
-nfc-manager (0.0.1-27) unstable; urgency=low
-
- *Modify app launch condition
- *Git: 165.213.180.234:slp/pkgs/n/nfc-manager
- *Tag: nfc-manager_0.0.1-27
-
- -- Wonkyu Kwon <wonkyu.kwon@samsung.com> Wed, 02 Nov 2011 13:50:00 +0900
-
-nfc-manager (0.0.1-26) unstable; urgency=low
-
- *ndef memory problem fix
- *Git: 165.213.180.234:slp/pkgs/n/nfc-manager
- *Tag: nfc-manager_0.0.1-26
-
- -- Sangsoo Lee <constant.lee@samsung.com> Mon, 31 Oct 2011 17:54:56 +0900
-
-nfc-manager (0.0.1-25) unstable; urgency=low
-
- *LLCP flow change.
- *Git: 165.213.180.234:slp/pkgs/n/nfc-manager
- *Tag: nfc-manager_0.0.1-25
-
- -- Sangsoo Lee <constant.lee@samsung.com> Fri, 28 Oct 2011 14:57:26 +0900
-
-nfc-manager (0.0.1-24) unstable; urgency=low
-
- *Change the boilerplate.
- *Git: 165.213.180.234:slp/pkgs/n/nfc-manager
- *Tag: nfc-manager_0.0.1-24
-
- -- Sungjae Lim <neueziel.lim@samsung.com> Thu, 27 Oct 2011 14:55:42 +0900
-
-nfc-manager (0.0.1-23) unstable; urgency=low
-
- *Add the NPP for android NFC.
- *Git: 165.213.180.234:slp/pkgs/n/nfc-manager
- *Tag: nfc-manager_0.0.1-23
-
- -- Sungjae Lim <neueziel.lim@samsung.com> Wed, 26 Oct 2011 17:19:02 +0900
-
-nfc-manager (0.0.1-22) unstable; urgency=low
-
- *Modify the code for Prevent.
- *Git: 165.213.180.234:slp/pkgs/n/nfc-manager
- *Tag: nfc-manager_0.0.1-22
-
- -- Sungjae Lim <neueziel.lim@samsung.com> Mon, 24 Oct 2011 19:38:59 +0900
-
-nfc-manager (0.0.1-21ubuntu2) unstable; urgency=low
-
- *add server state.
- *Git: 165.213.180.234:slp/pkgs/n/nfc-manager
- *Tag: nfc-manager_0.0.1-21
-
- -- Sangsoo Lee <constant.lee@samsung.com> Wed, 12 Oct 2011 20:10:02 +0900
-
-nfc-manager (0.0.1-20ubuntu1) unstable; urgency=low
-
- *bug fix. when read ndef fail, data was free two times.
- *Git: 165.213.180.234:slp/pkgs/n/nfc-manager
- *Tag: nfc-manager_0.0.1-20
-
- -- Sangsoo Lee <constant.lee@samsung.com> Mon, 10 Oct 2011 18:51:42 +0900
-
-nfc-manager (0.0.1-19) unstable; urgency=low
-
- *Add message broadcasting. and implement net_nfc_get_server_state
- *Git: 165.213.180.234:slp/pkgs/n/nfc-manager
- *Tag: nfc-manager_0.0.1-19
-
- -- Sangsoo Lee <constant.lee@samsung.com> Thu, 06 Oct 2011 16:01:59 +0900
-
-nfc-manager (0.0.1-18) unstable; urgency=low
-
- *Add the prefix net to the NFC Manager FW
- *Git: 165.213.180.234:slp/pkgs/n/nfc-manager
- *Tag: nfc-manager_0.0.1-18
-
- -- Sungjae Lim <neueziel.lim@samsung.com> Thu, 22 Sep 2011 16:51:30 +0900
-
-nfc-manager (0.0.1-17) unstable; urgency=low
-
- *Add the prefix net to the common and client lib
- *Git: 165.213.180.234:slp/pkgs/n/nfc-manager
- *Tag: nfc-manager_0.0.1-17
-
- -- Sungjae Lim <neueziel.lim@samsung.com> Tue, 20 Sep 2011 10:48:30 +0900
-
-nfc-manager (0.0.1-16) unstable; urgency=low
-
- *Modify the manager for setting and exchanger
- *Git: 165.213.180.234:slp/pkgs/n/nfc-manager
- *Tag: nfc-manager_0.0.1-16
-
- -- Sungjae Lim <neueziel.lim@samsung.com> Wed, 7 Sep 2011 19:19:20 +0900
-
-nfc-manager (0.0.1-15) unstable; urgency=low
-
- * add NDEF parser
- * Git: 165.213.180.234:slp/pkgs/n/nfc-manager
- * Tag: nfc-manager_0.0.1-15
-
- -- Sangsoo Lee <constant.lee@samsung.com> Wed, 24 Aug 2011 15:27:30 +0900
-
-nfc-manager (0.0.1-14) unstable; urgency=low
-
- * change the traceive function parameter
- * Git: 165.213.180.234:slp/pkgs/n/nfc-manager
- * Tag: nfc-manager_0.0.1-14
-
- -- root <bumj.kim@samsung.com> Mon, 27 Jun 2011 20:15:09 +0900
-
-nfc-manager (0.0.1-13) unstable; urgency=low
-
- * updates package for CAPI
- * Git: 165.213.180.234:slp/pkgs/n/nfc-manager
- * Tag: nfc-manager_0.0.1-13
-
- -- root <bumj.kim@samsung.com> Fri, 24 Jun 2011 18:52:20 +0900
-
-nfc-manager (0.0.1-12) unstable; urgency=low
-
- * adding missing header file
- * Git: 165.213.180.234:slp/pkgs/n/nfc-manager
- * Tag: nfc-manager_0.0.1-12
-
- -- root <bumj.kim@samsung.com> Wed, 15 Jun 2011 10:04:58 +0900
-
-nfc-manager (0.0.1-11) unstable; urgency=low
-
- * Change llcp connection policy and sepcific API for tags
- * Git: 165.213.180.234:slp/pkgs/n/nfc-manager
- * Tag: nfc-manager_0.0.1-11
-
- -- root <bumj.kim@samsung.com> Wed, 15 Jun 2011 09:47:21 +0900
-
-nfc-manager (0.0.1-10) unstable; urgency=low
-
- * fix the compile error and add comments of exception
- * Git: 165.213.180.234:slp/pkgs/n/nfc-manager
- * Tag: nfc-manager_0.0.1-10
-
- -- root <bumj.kim@samsung.com> Wed, 18 May 2011 14:31:45 +0900
-
-nfc-manager (0.0.1-9) unstable; urgency=low
-
- * update NFC manager API and split the solution package and manger package
- * Git: 165.213.180.234:slp/pkgs/n/nfc-manager
- * Tag: nfc-manager_0.0.1-9
-
- -- root <bumj.kim@samsung.com> Wed, 18 May 2011 14:27:37 +0900
-
-nfc-manager (0.0.1-8) unstable; urgency=low
-
- * remove the dependency of bt-engine
- * Git: 165.213.180.234:slp/pkgs/n/nfc-manager
- * Tag: nfc-manager_0.0.1-8
-
- -- Bumjoon Kim <bumj.kim@samsung.com> Fri, 11 Mar 2011 09:52:48 +0900
-
-nfc-manager (0.0.1-7) unstable; urgency=low
-
- * fix the prevent issues extra
- * Git: 165.213.180.234:slp/pkgs/n/nfc-manager
- * Tag: nfc-manager_0.0.1-7
-
- -- Bumjoon Kim <bumj.kim@samsung.com> Thu, 17 Feb 2011 17:12:47 +0900
-
-nfc-manager (0.0.1-6) unstable; urgency=low
-
- * fix the prevent issues
- * Git: 165.213.180.234:slp/pkgs/n/nfc-manager
- * Tag: nfc-manager_0.0.1-6
-
- -- Bumjoon Kim <bumj.kim@samsung.com> Tue, 15 Feb 2011 21:12:22 +0900
-
-nfc-manager (0.0.1-5) unstable; urgency=low
-
- * enhance the stablity of nfc-manager
- * Git: 165.213.180.234:slp/pkgs/n/nfc-manager
- * Tag: nfc-manager_0.0.1-5
-
- -- Bumjoon Kim <bumj.kim@samsung.com> Tue, 01 Feb 2011 18:21:56 +0900
-
-nfc-manager (0.0.1-4) unstable; urgency=low
-
- * Vice President demo version
- * Git: 165.213.180.234:slp/pkgs/n/nfc-manager
- * Tag: nfc-manager_0.0.1-4
-
- -- Bumjoon Kim <bumj.kim@samsung.com> Thu, 27 Jan 2011 13:49:18 +0900
-
-nfc-manager (0.0.1-3) unstable; urgency=low
-
- * adding settup switch to enable disable nfc-manager
- * Git: 165.213.180.234:slp/pkgs/n/nfc-manager
- * Tag: nfc-manager_0.0.1-3
-
- -- Bumjoon Kim <bumj.kim@samsung.com> Mon, 24 Jan 2011 16:21:44 +0900
-
-nfc-manager (0.0.1-2) unstable; urgency=low
-
- * nfc-manager and stand alone mode is enabled
- * Git: 165.213.180.234:slp/pkgs/n/nfc-manager
- * Tag: nfc-manager_0.0.1-2
-
- -- Bumjoon Kim <bumj.kim@samsung.com> Tue, 04 Jan 2011 20:21:19 +0900
-
-nfc-manager (0.0.1-1) unstable; urgency=low
-
- * first source package for building
-
- -- hyogil.kim <hyogil.kim@samsung.com> Wed, 3 Nov 2010 13:43:34 +0900
-
+++ /dev/null
-Source: nfc-manager
-Section: libs
-Priority: extra
-Maintainer: Sangsoo Lee <constant.lee@samsung.com>, Sungjae Lim <sungjae.lim@samsung.com>, Sechang Sohn <sc.sohn@samsung.com>
-Build-Depends: debhelper (>= 5), libaul-1-dev, libglib2.0-dev, libvconf-dev, libsecurity-server-client-dev, libbluetooth-frwk-dev,libdbus-glib-1-dev, dlog-dev, libecore-dev, libslp-tapi-dev, libappsvc-dev, libcurl-dev, libheynoti-dev, libsvi-dev, libssl-dev, smartcard-service-dev, smartcard-service-common-dev, libslp-pm-dev
-Standards-Version: 0.0.1
-
-Package: libnfc-common-lib-0
-Section: libs
-Architecture: any
-Depends: ${shlibs:Depends}, ${misc:Depends}
-Description: NFC Common Library
-
-Package: libnfc-common-lib-dev
-Section: libs
-Architecture: any
-Depends: ${misc:Depends}, libnfc-common-lib-0 (= ${Source-Version})
-Description: NFC Common Library
-
-Package: libnfc-common-lib-dbg
-Section: debug
-Architecture: any
-Depends: ${misc:Depends}, libnfc-common-lib-0 (= ${Source-Version})
-Description: NFC Common Library (unstripped)
-
-Package: libnfc-manager-0
-Section: libs
-Architecture: any
-Depends: ${shlibs:Depends}, ${misc:Depends}, libnfc-common-lib-0 (= ${Source-Version})
-Description: NFC freamework
-
-Package: libnfc-manager-dev
-Section: libs
-Architecture: any
-Depends: ${misc:Depends}, libnfc-manager-0 (= ${Source-Version})
-Description: NFC freamework
-
-Package: libnfc-manager-dbg
-Section: debug
-Architecture: any
-Depends: ${misc:Depends}, libnfc-manager-0 (= ${Source-Version})
-Description: NFC-manager (unstripped)
+++ /dev/null
-@PREFIX@/lib/libnfc-common-lib.so.*
+++ /dev/null
-#!/bin/sh
-#Add boot sequence script
-if [ ${USER} == "root" ]
-then
-vconftool set -t bool memory/private/nfc-manager/popup_disabled 0 -u 5000
-else
-vconftool set -t bool memory/private/nfc-manager/popup_disabled 0
-fi
+++ /dev/null
-@PREFIX@/lib/pkgconfig/nfc-common-lib.pc
-@PREFIX@/include/nfc-common-lib/*
-@PREFIX@/lib/libnfc-common-lib.so
+++ /dev/null
-#!/bin/sh
-### BEGIN INIT INFO
-# Provides: nfc-agent
-# Required-Start:
-# Required-Stop:
-# Default-Start: 3 5
-# Default-Stop: 0
-# Short-Description: NFC agent
-# Description: NFC agent
-#
-#
-### END INIT INFO
-
-# Author: Wonkyu Kwon <wonkyu.kwon@samsung.com>
-
-# PATH should only include /usr/* if it runs after the mountnfs.sh script
-DAEMON=/usr/bin/nfc-manager-daemon
-DAEMON_ARGS="" # Arguments to run the daemon with
-
-# Exit if the package is not installed
-[ -x $DAEMON ] || exit 0
-
-$DAEMON $DAEMON_ARGS &
+++ /dev/null
-@PREFIX@/lib/libnfc.so.*
-@PREFIX@/bin/*
-/etc/init.d/*
-/etc/rc.d/*
-
+++ /dev/null
-#!/bin/sh
-#Add boot sequence script
-if [ ${USER} == "root" ]
-then
-vconftool set -t bool db/nfc/feature 0 -u 5000
-vconftool set -t bool db/nfc/enable 0 -u 5000
-vconftool set -t bool db/nfc/sbeam 0 -u 5000
-else
-vconftool set -t bool db/nfc/feature 0
-vconftool set -t bool db/nfc/enable 0
-vconftool set -t bool db/nfc/sbeam 0
-fi
+++ /dev/null
-@PREFIX@/lib/pkgconfig/nfc.pc
-@PREFIX@/include/nfc/*
-@PREFIX@/lib/libnfc.so
+++ /dev/null
-#!/usr/bin/make -f
-# -*- makefile -*-
-# Sample debian/rules that uses debhelper.
-# This file was originally written by Joey Hess and Craig Small.
-# As a special exception, when this file is copied by dh-make into a
-# dh-make output file, you may use that output file without restriction.
-# This special exception was added by Craig Small in version 0.37 of dh-make.
-
-# Uncomment this to turn on verbose mode.
-#export DH_VERBOSE=1
-
-CFLAGS ?= -Wall -g
-CXXFLAGS ?= -Wall -g
-LDFLAGS ?=
-PREFIX ?= /usr
-
-ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
- CFLAGS += -O0
- CXXFLAGS += -O0
-else
- CFLAGS += -O2
- CXXFLAGS += -O2
-endif
-
-LDFLAGS += -Wl,--rpath=$(PREFIX)/lib -Wl,--as-needed
-
-CMAKE_TMP_DIR = $(CURDIR)/cmake_tmp
-
-
-configure: configure-stamp
-configure-stamp:
- dh_testdir
- # Add here commands to configure the package.
- mkdir -p $(CMAKE_TMP_DIR);
- cd $(CMAKE_TMP_DIR); CFLAGS="$(CFLAGS)" CXXFLAGS="$(CXXFLAGS)" LDFLAGS="$(LDFLAGS)" cmake .. -DCMAKE_INSTALL_PREFIX=$(PREFIX)
-
- touch configure-stamp
-
-build: build-stamp
-
-build-stamp: configure-stamp
- dh_testdir
-
- # Add here commands to compile the package.
- cd $(CMAKE_TMP_DIR) && $(MAKE)
- #docbook-to-man debian/wavplayer.sgml > wavplayer.1
-
- for f in `find $(CURDIR)/debian/ -name "*.in"`; do \
- cat $$f > $${f%.in}; \
- sed -i -e "s#@PREFIX@#$(PREFIX)#g" $${f%.in}; \
- done
-
-
- touch $@
-
-clean:
- dh_testdir
- dh_testroot
- rm -f build-stamp configure-stamp
-
- # Add here commands to clean up after the build process.
- -cd $(CMAKE_TMP_DIR) && $(MAKE) clean
- rm -rf $(CMAKE_TMP_DIR)
-
- rm -rf CMakeCache.txt
- rm -rf CMakeFiles
- rm -rf cmake_install.cmake
- rm -rf Makefile
- rm -rf install_manifest.txt
- rm -rf *.so
-
- for f in `find $(CURDIR)/debian/ -name "*.in"`; do \
- rm -f $${f%.in}; \
- done
-
- dh_clean
-
-install: build
- dh_testdir
- dh_testroot
- dh_clean -k
- dh_installdirs
-
- mkdir -p $(CURDIR)/debian/tmp/etc/init.d
- cp -af $(CURDIR)/debian/libnfc-manager-0.init.in $(CURDIR)/debian/tmp/etc/init.d/libnfc-manager-0
-
- # Add here commands to install the package into debian/wavplayer.
- cd $(CMAKE_TMP_DIR) && $(MAKE) DESTDIR=$(CURDIR)/debian/tmp install
-
- mkdir -p $(CURDIR)/debian/tmp/etc/rc.d/rc3.d/
- mkdir -p $(CURDIR)/debian/tmp/etc/rc.d/rc5.d/
-
- ln -s /etc/init.d/libnfc-manager-0 $(CURDIR)/debian/tmp/etc/rc.d/rc3.d/S81libnfc-manager-0
- ln -s /etc/init.d/libnfc-manager-0 $(CURDIR)/debian/tmp/etc/rc.d/rc5.d/S81libnfc-manager-0
-
-# Build architecture-independent files here.
-binary-indep: build install
-# We have nothing to do by default.
-
-# Build architecture-dependent files here.
-binary-arch: build install
- dh_testdir
- dh_testroot
-# dh_installchangelogs
-# dh_installdocs
-# dh_installexamples
- dh_install --sourcedir=debian/tmp
-# dh_installmenu
-# dh_installdebconf
-# dh_installlogrotate
-# dh_installemacsen
-# dh_installpam
-# dh_installmime
-# dh_python
-# dh_installinit
-# dh_installcron
-# dh_installinfo
-# dh_installman
- dh_link
- dh_strip --dbg-package=libnfc-manager-dbg --dbg-package=libnfc-common-lib-dbg
- dh_compress
- dh_fixperms
-# dh_perl
- dh_makeshlibs
- dh_installdeb
- dh_shlibdeps
- dh_gencontrol
- dh_md5sums
- dh_builddeb
-
-binary: binary-indep binary-arch
-.PHONY: build clean binary-indep binary-arch binary install configure
# directories like "/usr/src/myproject". Separate the files or directories
# with spaces.
-#INPUT = ..
-INPUT = ../src/commonlib/include/net_nfc_typedef.h ../src/clientlib/include/net_nfc_target_info.h ../src/clientlib/include/net_nfc_llcp.h ../src/clientlib/include/net_nfc_exchanger.h ../src/clientlib/include/net_nfc_ndef_message.h ../src/clientlib/include/net_nfc_data.h ../src/clientlib/include/net_nfc_ndef_record.h ../src/clientlib/include/net_nfc_apdu.h ../src/clientlib/include/net_nfc_tag.h ../src/clientlib/include/net_nfc.h ../src/clientlib/include/net_nfc_ndef_message_handover.h ../src/clientlib/include/net_nfc_tag_felica.h ../src/clientlib/include/net_nfc_tag_jewel.h ../src/clientlib/include/net_nfc_tag_mifare.h
+INPUT = ../common/include/ ../client/include/
# This tag can be used to specify the character encoding of the source files that
+++ /dev/null
-#!/bin/sh
-### BEGIN INIT INFO
-# Provides: nfc-manager-daemon
-# Required-Start:
-# Required-Stop:
-# Default-Start: 3 5
-# Default-Stop: 0
-# Short-Description: NFC manager
-# Description: NFC manager
-#
-#
-### END INIT INFO
-
-# Author: Wonkyu Kwon <wonkyu.kwon@samsung.com>
-
-# PATH should only include /usr/* if it runs after the mountnfs.sh script
-DAEMON=/usr/bin/nfc-manager-daemon
-DAEMON_ARGS="--daemon" # Arguments to run the daemon with
-VCONFTOOL=/usr/bin/vconftool
-
-# Exit if the package is not installed
-[ -x $DAEMON ] || exit 0
-[ -x $VCONFTOOL ] || exit 0
-
-#if vconftool get db/nfc/enable | grep -q "db/nfc/enable, value = 1 (bool)"
-#then
- if ! ps -f --ppid 1 | grep -q nfc-manager-daemon
- then
- $DAEMON $DAEMON_ARGS &
- fi
-#fi
Summary: NFC framework manager
Version: 0.1.0
Release: 0
-Group: libs
+Group: Network & Connectivity/NFC
License: Flora Software License
Source0: %{name}-%{version}.tar.gz
-Source1: libnfc-manager-0.init.in
-Source2: nfc-manager.service
+Source1: %{name}.service
Source1001: %{name}.manifest
BuildRequires: cmake
BuildRequires: pkgconfig(aul)
%description
-NFC library Manager.
+Tizen NFC framework manager.
%prep
%package -n nfc-common-lib
Summary: NFC common library
-Group: Development/Libraries
+Group: Network & Connectivity/Development
%description -n nfc-common-lib
%package -n nfc-common-lib-devel
Summary: NFC common library (devel)
-Group: libs
+Group: Network & Connectivity/Development
Requires: nfc-common-lib = %{version}
%description -n nfc-common-lib-devel
-NFC common library (devel)
+NFC manager common library for internal development.
%package -n nfc-client-lib
Summary: NFC client library
-Group: Development/Libraries
+Group: Network & Connectivity/NFC
Requires: nfc-common-lib = %{version}
%description -n nfc-client-lib
-NFC Client library.
+NFC manager Client library for NFC client applications.
%package -n nfc-client-lib-devel
Summary: NFC client library (devel)
-Group: libs
+Group: Network & Connectivity/Development
Requires: nfc-client-lib = %{version}
%description -n nfc-client-lib-devel
-NFC client library (devel)
+NFC manager Client library for developing NFC client applications.
-#%package -n nfc-client-test
+
+#%%package -n nfc-client-test
#Summary: NFC client test
-#Group: Development/Libraries
-#Requires: %{name} = %{version}-%{release}
+#Group: Network & Connectivity/NFC
+#Requires: %%{name} = %%{version}
-#%description -n nfc-client-test
+#%%description -n nfc-client-test
#NFC client test (devel)
%build
-export LDFLAGS+="-Wl,--rpath=%{_prefix}/lib -Wl,--as-needed"
-LDFLAGS="$LDFLAGS" cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix}
+MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'`
+%cmake . -DMAJORVER=${MAJORVER} -DFULLVER=%{version}
%install
%make_install
-install -D -m 0755 %SOURCE1 %{buildroot}%{_sysconfdir}/init.d/libnfc-manager-0
mkdir -p %{buildroot}/opt/usr/share/nfc_debug
mkdir -p %{buildroot}%{_libdir}/systemd/system/multi-user.target.wants
-cp -af %{SOURCE2} %{buildroot}%{_libdir}/systemd/system/
+cp -af %{SOURCE1} %{buildroot}%{_libdir}/systemd/system/
ln -s ../%{name}.service %{buildroot}%{_libdir}/systemd/system/multi-user.target.wants/%{name}.service
%post
/sbin/ldconfig
-#ln -s /etc/init.d/libnfc-manager-0 /etc/rc.d/rc3.d/S81libnfc-manager-0 -f
-#ln -s /etc/init.d/libnfc-manager-0 /etc/rc.d/rc5.d/S81libnfc-manager-0 -f
-
systemctl daemon-reload
if [ $1 == 1 ]; then
systemctl restart %{name}.service
fi
+%post -n nfc-common-lib -p /sbin/ldconfig
%post -n nfc-client-lib
/sbin/ldconfig
%postun
/sbin/ldconfig
-#mkdir -p /etc/rc.d/rc3.d
-#mkdir -p /etc/rc.d/rc5.d
-#rm -f /etc/rc.d/rc3.d/S81libnfc-manager-0
-#rm -f /etc/rc.d/rc5.d/S81libnfc-manager-0
-
if [ $1 == 0 ]; then
systemctl stop %{name}.service
fi
systemctl daemon-reload
-
-%post -n nfc-common-lib -p /sbin/ldconfig
-
-
%postun -n nfc-common-lib -p /sbin/ldconfig
+%postun -n nfc-client-lib -p /sbin/ldconfig
+
%files
%manifest %{name}.manifest
%defattr(-,root,root,-)
%{_bindir}/nfc-manager-daemon
-#%{_bindir}/ndef-tool
+#%%{_bindir}/ndef-tool
%{_libdir}/systemd/system/%{name}.service
%{_libdir}/systemd/system/multi-user.target.wants/%{name}.service
-%{_sysconfdir}/init.d/libnfc-manager-0
%{_datadir}/dbus-1/services/org.tizen.NetNfcService.service
%{_datadir}/packages/%{name}.xml
%{_datadir}/nfc-manager-daemon/sounds/*
%files -n nfc-client-lib-devel
-%manifest %{name}.manifest
%defattr(-,root,root,-)
%{_libdir}/libnfc.so
%{_libdir}/pkgconfig/nfc.pc
%files -n nfc-common-lib
%manifest %{name}.manifest
%defattr(-,root,root,-)
-%{_libdir}/libnfc-common-lib.so.*
-%{_datadir}/nfc-manager-daemon/sounds/*
+%{_libdir}/libnfc-common.so.*
%license LICENSE.Flora
%files -n nfc-common-lib-devel
-%manifest %{name}.manifest
%defattr(-,root,root,-)
-%{_libdir}/libnfc-common-lib.so
-%{_libdir}/pkgconfig/nfc-common-lib.pc
-%{_includedir}/nfc-common-lib/*.h
+%{_libdir}/libnfc-common.so
+%{_libdir}/pkgconfig/nfc-common.pc
+%{_includedir}/nfc-common/*.h
-#%files -n nfc-client-test
-#%manifest nfc-client-test.manifest
-#%defattr(-,root,root,-)
-#%{_bindir}/nfc_client
-#%license LICENSE.Flora
+#%%files -n nfc-client-test
+#%%manifest nfc-client-test.manifest
+#%%defattr(-,root,root,-)
+#%%{_bindir}/nfc_client
+#%%license LICENSE.Flora
+++ /dev/null
-CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
-PROJECT(nfc-client-lib C)
-
-#SET(NFC_CLIENT_LIB "nfc-client-lib")
-SET(NFC_CLIENT_LIB "nfc")
-SET(VERSION_MAJOR 1)
-SET(VERSION ${VERSION_MAJOR}.0.0)
-
-include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
-include_directories(${CMAKE_SOURCE_DIR}/src/commonlib)
-include_directories(${CMAKE_SOURCE_DIR}/src/commonlib/include)
-include_directories(${CMAKE_SOURCE_DIR}/src/manager/include)
-
-AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} CLIENT_SRCS)
-
-IF("${CMAKE_BUILD_TYPE}" STREQUAL "")
- SET(CMAKE_BUILD_TYPE "Release")
-ENDIF("${CMAKE_BUILD_TYPE}" STREQUAL "")
-
-INCLUDE(FindPkgConfig)
-pkg_check_modules(clientlib_pkges REQUIRED security-server dlog ecore-x vconf)
-
-FOREACH(flag ${clientlib_pkges_CFLAGS})
- SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
-ENDFOREACH(flag)
-
-MESSAGE("CHECK MODULE in MANAGER ${clientlib_pkges_LDFLAGS}")
-
-# this for NFC flag
-
-SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -pipe -fomit-frame-pointer -Wall -Wno-trigraphs -Werror-implicit-function-declaration -fno-strict-aliasing -Wl,-zdefs -fvisibility=hidden")
-
-SET(ARM_CFLAGS "${ARM_CLAGS} -mapcs -mno-sched-prolog -mabi=aapcs-linux -Uarm -fno-common -fpic")
-
-SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror-implicit-function-declaration")
-
-SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
-SET(CMAKE_C_FLAGS_DEBUG "-O0 -g")
-
-FIND_PROGRAM(UNAME NAMES uname)
-EXEC_PROGRAM("${UNAME}" ARGS "-m" OUTPUT_VARIABLE "ARCH")
-IF("${ARCH}" MATCHES "^arm.*")
- ADD_DEFINITIONS("-DTARGET")
- MESSAGE("add -DTARGET")
- SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${ARM_CFLAGS}")
-ENDIF()
-
-ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"")
-
-SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed")
-
-ADD_LIBRARY(${NFC_CLIENT_LIB} SHARED ${CLIENT_SRCS})
-SET_TARGET_PROPERTIES(${NFC_CLIENT_LIB} PROPERTIES SOVERSION ${VERSION_MAJOR})
-SET_TARGET_PROPERTIES(${NFC_CLIENT_LIB} PROPERTIES VERSION ${VERSION})
-TARGET_LINK_LIBRARIES(${NFC_CLIENT_LIB} ${clientlib_pkges_LDFLAGS} nfc-common-lib)
-
-LINK_DIRECTORIES(${CMAKE_BUILD_DIR}/src/commonlib)
-
-
-SET(CLIENT_HEADER
- ${CMAKE_SOURCE_DIR}/src/commonlib/include/net_nfc_typedef.h
- include/net_nfc.h
- include/net_nfc_data.h
- include/net_nfc_target_info.h
- include/net_nfc_ndef_message.h
- include/net_nfc_ndef_record.h
- include/net_nfc_sign_record.h
- include/net_nfc_ndef_message_handover.h
- include/net_nfc_client_context.h
- include/net_nfc_client_manager.h
- include/net_nfc_client_system_handler.h
- include/net_nfc_client_transceive.h
- include/net_nfc_client_tag.h
- include/net_nfc_client_ndef.h
- include/net_nfc_client_llcp.h
- include/net_nfc_client_p2p.h
- include/net_nfc_client_snep.h
- include/net_nfc_client_exchanger.h
- include/net_nfc_client_handover.h
- include/net_nfc_client_se.h
- include/net_nfc_client_tag_felica.h
- include/net_nfc_client_tag_jewel.h
- include/net_nfc_tag_mifare.h
- include/net_nfc_client_test.h
-)
-
-CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/nfc.pc.in ${CMAKE_CURRENT_SOURCE_DIR}/nfc.pc)
-INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/nfc.pc DESTINATION lib/pkgconfig)
-
-INSTALL(TARGETS ${NFC_CLIENT_LIB} DESTINATION lib)
-
-FOREACH(hfile ${CLIENT_HEADER})
- INSTALL(FILES ${hfile} DESTINATION include/nfc)
-ENDFOREACH(hfile)
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __NET_NFC_H__
-#define __NET_NFC_H__
-
-#include "net_nfc_typedef.h"
-#include "net_nfc_data.h"
-#include "net_nfc_target_info.h"
-#include "net_nfc_ndef_message.h"
-#include "net_nfc_ndef_record.h"
-#include "net_nfc_sign_record.h"
-#include "net_nfc_ndef_message_handover.h"
-
-#include "net_nfc_client_context.h"
-#include "net_nfc_client_manager.h"
-#include "net_nfc_client_system_handler.h"
-#include "net_nfc_client_transceive.h"
-#include "net_nfc_client_tag.h"
-#include "net_nfc_client_ndef.h"
-#include "net_nfc_client_llcp.h"
-#include "net_nfc_client_p2p.h"
-#include "net_nfc_client_snep.h"
-#include "net_nfc_client_exchanger.h"
-#include "net_nfc_client_handover.h"
-#include "net_nfc_client_se.h"
-#include "net_nfc_client_tag_felica.h"
-#include "net_nfc_client_tag_jewel.h"
-#include "net_nfc_tag_mifare.h"
-#include "net_nfc_client_test.h"
-
-#endif //__NET_NFC_H__
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef __NET_NFC_CLIENT_H__
-#define __NET_NFC_CLIENT_H__
-
-#include <glib.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/* TODO : change to internal header */
-void net_nfc_client_gdbus_init(void);
-
-void net_nfc_client_gdbus_deinit(void);
-
-GVariant *net_nfc_client_gdbus_get_privilege();
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif //__NET_NFC_CLIENT_H__
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef __NET_NFC_CLIENT_CONTEXT_H__
-#define __NET_NFC_CLIENT_CONTEXT_H__
-
-#include "net_nfc_typedef.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define NET_NFC_SERVICE_EMPTY_TYPE \
- "http://tizen.org/appcontrol/operation/nfc/empty"
-#define NET_NFC_SERVICE_WELL_KNOWN_TYPE \
- "http://tizen.org/appcontrol/operation/nfc/wellknown"
-#define NET_NFC_SERVICE_EXTERNAL_TYPE \
- "http://tizen.org/appcontrol/operation/nfc/external"
-#define NET_NFC_SERVICE_MIME_TYPE \
- "http://tizen.org/appcontrol/operation/nfc/mime"
-#define NET_NFC_SERVICE_URI_TYPE \
- "http://tizen.org/appcontrol/operation/nfc/uri"
-
-
-net_nfc_error_e net_nfc_client_initialize();
-
-net_nfc_error_e net_nfc_client_deinitialize();
-
-net_nfc_error_e net_nfc_client_is_nfc_supported(int *state);
-
-net_nfc_error_e net_nfc_client_get_nfc_state(int *state);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif //__NET_NFC_CLIENT_CONTEXT_H__
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef __NET_NFC_CLIENT_EXCHANGER_H__
-#define __NET_NFC_CLIENT_EXCHANGER_H__
-
-
-#include "net_nfc_typedef.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**
-@addtogroup NET_NFC_MANAGER_EXCHANGE
-@{
-
-*/
-
-
-/**
- create net_nfc_exchagner raw type data handler with given values
-
- @param[out] ex_data exchangner handler
- @param[in] payload the data will be deliver (NDEF message)
-
- @return result of this function call
-
- @exception NET_NFC_ALLOC_FAIL memory allocation is failed
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illegal NULL pointer(s)
-*/
-net_nfc_error_e net_nfc_client_create_exchanger_data(
- net_nfc_exchanger_data_h *ex_data,
- data_h payload);
-
-
-/**
- this makes free exchagner data handler
-
- @param[in] ex_data exchagner handler
-
- @return result of this function call
-
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
-*/
-net_nfc_error_e net_nfc_client_free_exchanger_data (
- net_nfc_exchanger_data_h ex_data);
-
-
-net_nfc_error_e net_nfc_client_unset_exchanger_cb();
-
-
-net_nfc_error_e net_nfc_client_send_exchanger_data (
- net_nfc_exchanger_data_h ex_handle,
- net_nfc_target_handle_h target_handle,
- void* trans_param);
-
-/**
- request connection handover with discovered P2P device
-
- @param[in] target_handle target device handle
- @param[in] type specific alternative carrier type (if type is NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN, it will be selected available type of this target)
- @param[in] trans_param user data
-
- @return result of this function call
-
- @exception NET_NFC_ALLOC_FAIL memory allocation is failed
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
-*/
-net_nfc_error_e net_nfc_client_exchanger_request_connection_handover(
- net_nfc_target_handle_h target_handle,
- net_nfc_conn_handover_carrier_type_e type);
-
-/**
- get alternative carrier type from connection handover information handle.
-
- @param[in] info_handle connection handover information handle
- @param[out] type alternative carrier type
-
- @return return the result of this operation
-
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
-*/
-net_nfc_error_e net_nfc_client_exchanger_get_alternative_carrier_type(
- net_nfc_connection_handover_info_h info_handle,
- net_nfc_conn_handover_carrier_type_e *type);
-
-/**
- get alternative carrier dependant data from connection handover information handle.
- Bluetooth : target device address
- Wifi : target device ip address
-
- @param[in] info_handle connection handover information handle
- @param[out] data alternative carrier data
-
- @return return the result of this operation
-
- @exception NET_NFC_ALLOC_FAIL memory allocation is failed
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
-*/
-net_nfc_error_e net_nfc_client_exchanger_get_alternative_carrier_data(
- net_nfc_connection_handover_info_h info_handle,
- data_h *data);
-
-/**
- this makes free alternative carrier data handler
-
- @param[in] info_handle alternative carrier data handler
-
- @return result of this function call
-
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
-*/
-net_nfc_error_e net_nfc_client_exchanger_free_alternative_carrier_data(
- net_nfc_connection_handover_info_h info_handle);
-
-
-/**
-@}
-*/
-
-
-#ifdef __cplusplus
-}
-#endif
-
-
-#endif //__NET_NFC_CLIENT_EXCHANGER_H__
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef __NET_NFC_CLIENT_HANDOVER_H__
-#define __NET_NFC_CLIENT_HANDOVER_H__
-
-#include "net_nfc_typedef.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef void (*net_nfc_p2p_connection_handover_completed_cb)(
- net_nfc_error_e result,
- net_nfc_conn_handover_carrier_type_e carrier,
- data_h ac_data,
- void *user_data);
-
-
-net_nfc_error_e net_nfc_client_handover_free_alternative_carrier_data(
- net_nfc_connection_handover_info_h info_handle);
-
-
-net_nfc_error_e net_nfc_client_handover_get_alternative_carrier_type(
- net_nfc_connection_handover_info_h info_handle,
- net_nfc_conn_handover_carrier_type_e *type);
-
-
-net_nfc_error_e net_nfc_client_handover_get_alternative_carrier_data(
- net_nfc_connection_handover_info_h info_handle,
- data_h *data);
-
-
-net_nfc_error_e net_nfc_client_p2p_connection_handover(
- net_nfc_target_handle_h handle,
- net_nfc_conn_handover_carrier_type_e arg_type,
- net_nfc_p2p_connection_handover_completed_cb callback,
- void *cb_data);
-
-
-net_nfc_error_e net_nfc_client_p2p_connection_handover_sync(
- net_nfc_target_handle_h handle,
- net_nfc_conn_handover_carrier_type_e arg_type,
- net_nfc_conn_handover_carrier_type_e *out_carrier,
- data_h *out_ac_data);
-
-/* TODO : move to internal header */
-net_nfc_error_e net_nfc_client_handover_init(void);
-
-void net_nfc_client_handover_deinit(void);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif //__NET_NFC_CLIENT_HANDOVER_H__
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef __NET_NFC_CLIENT_LLCP_H__
-#define __NET_NFC_CLIENT_LLCP_H__
-
-#include "net_nfc_typedef.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef void (*net_nfc_client_llcp_config_completed) (net_nfc_error_e result,
- void *user_data);
-
-typedef void (*net_nfc_client_llcp_listen_completed) (net_nfc_error_e result,
- net_nfc_llcp_socket_t client_socket,
- void *user_data);
-
-typedef void (*net_nfc_client_llcp_connect_completed) (net_nfc_error_e result,
- net_nfc_llcp_socket_t client_socket,
- void *user_data);
-
-typedef void (*net_nfc_client_llcp_connect_sap_completed) (
- net_nfc_error_e result,
- net_nfc_llcp_socket_t client_socket,
- void *user_data);
-
-typedef void (*net_nfc_client_llcp_send_completed) (net_nfc_error_e result,
- net_nfc_llcp_socket_t client_socket,
- void *user_data);
-
-typedef void (*net_nfc_client_llcp_send_to_completed) (net_nfc_error_e result,
- net_nfc_llcp_socket_t client_socket,
- void *user_data);
-
-typedef void (*net_nfc_client_llcp_receive_completed) (net_nfc_error_e result,
- data_h data,
- void *user_data);
-
-typedef void (*net_nfc_client_llcp_receive_from_completed) (
- net_nfc_error_e result,
- sap_t sap,
- data_h data,
- void *user_data);
-
-typedef void (*net_nfc_client_llcp_close_completed) (net_nfc_error_e result,
- net_nfc_llcp_socket_t client_socket,
- void *user_data);
-
-typedef void (*net_nfc_client_llcp_disconnect_completed) (
- net_nfc_error_e result,
- net_nfc_llcp_socket_t client_socket,
- void *user_data);
-
-net_nfc_error_e net_nfc_client_llcp_config(net_nfc_llcp_config_info_h config,
- net_nfc_client_llcp_config_completed callback,
- void *user_data);
-
-net_nfc_error_e net_nfc_client_llcp_config_sync
- (net_nfc_llcp_config_info_h config);
-
-net_nfc_error_e net_nfc_client_llcp_get_config
- (net_nfc_llcp_config_info_h *config);
-
-net_nfc_error_e net_nfc_client_llcp_listen(net_nfc_llcp_socket_t socket,
- const char *service_name,
- sap_t sap,
- net_nfc_client_llcp_listen_completed callback,
- void *user_data);
-
-net_nfc_error_e net_nfc_client_llcp_listen_sync(net_nfc_llcp_socket_t socket,
- const char *service_name,
- sap_t sap,
- net_nfc_llcp_socket_t *out_socket);
-
-net_nfc_error_e net_nfc_client_llcp_connect(net_nfc_llcp_socket_t socket,
- const char *service_name,
- net_nfc_client_llcp_connect_completed callback,
- void *user_data);
-
-net_nfc_error_e net_nfc_client_llcp_connect_sync(net_nfc_llcp_socket_t socket,
- const char *service_name,
- net_nfc_llcp_socket_t *out_socket);
-
-net_nfc_error_e net_nfc_client_llcp_send(net_nfc_llcp_socket_t socket,
- data_h data,
- net_nfc_client_llcp_send_completed callback,
- void *user_data);
-
-net_nfc_error_e net_nfc_client_llcp_send_sync(net_nfc_llcp_socket_t socket,
- data_h data,
- net_nfc_llcp_socket_t *out_socket);
-
-net_nfc_error_e net_nfc_client_llcp_send_to(net_nfc_llcp_socket_t socket,
- sap_t sap,
- data_h data,
- net_nfc_client_llcp_send_to_completed callback,
- void *user_data);
-
-net_nfc_error_e net_nfc_client_llcp_send_to_sync(net_nfc_llcp_socket_t socket,
- sap_t sap,
- data_h data,
- net_nfc_llcp_socket_t *out_socket);
-
-net_nfc_error_e net_nfc_client_llcp_receive(net_nfc_llcp_socket_t socket,
- size_t request_length,
- net_nfc_client_llcp_receive_completed callback,
- void *user_data);
-
-net_nfc_error_e net_nfc_client_llcp_receive_sync(net_nfc_llcp_socket_t socket,
- size_t request_length,
- data_h *out_data);
-
-net_nfc_error_e net_nfc_client_llcp_receive_from(net_nfc_llcp_socket_t socket,
- size_t request_length,
- net_nfc_client_llcp_receive_from_completed callback,
- void *user_data);
-
-net_nfc_error_e net_nfc_client_llcp_receive_from_sync(net_nfc_llcp_socket_t socket,
- size_t request_length,
- sap_t *out_sap,
- data_h *out_data);
-
-net_nfc_error_e net_nfc_client_llcp_close(net_nfc_llcp_socket_t socket,
- net_nfc_client_llcp_close_completed callback,
- void *user_data);
-
-net_nfc_error_e net_nfc_client_llcp_close_sync(net_nfc_llcp_socket_t socket,
- net_nfc_llcp_socket_t *out_socket);
-
-net_nfc_error_e net_nfc_client_llcp_disconnect(net_nfc_llcp_socket_t socket,
- net_nfc_client_llcp_disconnect_completed callback,
- void *user_data);
-
-net_nfc_error_e net_nfc_client_llcp_disconnect_sync(
- net_nfc_llcp_socket_t socket,
- net_nfc_llcp_socket_t *out_socket);
-
-void net_nfc_client_llcp_create_socket(net_nfc_llcp_socket_t *socket,
- net_nfc_llcp_socket_option_h option);
-
-net_nfc_error_e net_nfc_client_llcp_get_local_config(
- net_nfc_llcp_config_info_h *config);
-
-net_nfc_error_e net_nfc_client_llcp_get_local_socket_option(
- net_nfc_llcp_socket_t socket,
- net_nfc_llcp_socket_option_h *option);
-
-net_nfc_error_e net_nfc_client_llcp_create_socket_option(
- net_nfc_llcp_socket_option_h *option,
- uint16_t miu,
- uint8_t rw,
- net_nfc_socket_type_e type);
-
-net_nfc_error_e net_nfc_client_llcp_socket_option_default(
- net_nfc_llcp_socket_option_h *option);
-
-net_nfc_error_e net_nfc_client_llcp_get_socket_option_miu(
- net_nfc_llcp_socket_option_h option,
- uint16_t *miu);
-
-net_nfc_error_e net_nfc_client_llcp_set_socket_option_miu(
- net_nfc_llcp_socket_option_h option,
- uint16_t miu);
-
-net_nfc_error_e net_nfc_client_llcp_get_socket_option_rw(
- net_nfc_llcp_socket_option_h option,
- uint8_t *rt);
-
-net_nfc_error_e net_nfc_client_llcp_set_socket_option_rw(
- net_nfc_llcp_socket_option_h option,
- uint8_t rt);
-
-net_nfc_error_e net_nfc_client_llcp_get_socket_option_type(
- net_nfc_llcp_socket_option_h option,
- net_nfc_socket_type_e *type);
-
-net_nfc_error_e net_nfc_client_llcp_set_socket_option_type(
- net_nfc_llcp_socket_option_h option,
- net_nfc_socket_type_e type);
-
-net_nfc_error_e net_nfc_client_llcp_free_socket_option(
- net_nfc_llcp_socket_option_h option);
-
-net_nfc_error_e net_nfc_client_llcp_create_config(
- net_nfc_llcp_config_info_h *config,
- uint16_t miu,
- uint16_t wks,
- uint8_t lto,
- uint8_t option);
-
-net_nfc_error_e net_nfc_client_llcp_create_config_default(
- net_nfc_llcp_config_info_h *config);
-
-net_nfc_error_e net_nfc_client_llcp_get_config_miu(
- net_nfc_llcp_config_info_h config,
- uint16_t *miu);
-
-net_nfc_error_e net_nfc_client_llcp_get_config_wks(
- net_nfc_llcp_config_info_h config,
- uint16_t *wks);
-
-net_nfc_error_e net_nfc_client_llcp_get_config_lto(
- net_nfc_llcp_config_info_h config,
- uint8_t *lto);
-
-net_nfc_error_e net_nfc_client_llcp_get_config_option(
- net_nfc_llcp_config_info_h config,
- uint8_t *option);
-
-net_nfc_error_e net_nfc_client_llcp_set_config_miu(
- net_nfc_llcp_config_info_h config,
- uint16_t miu);
-
-net_nfc_error_e net_nfc_client_llcp_set_config_wks(
- net_nfc_llcp_config_info_h config,
- uint16_t wks);
-
-net_nfc_error_e net_nfc_client_llcp_set_config_lto(
- net_nfc_llcp_config_info_h config,
- uint8_t lto);
-
-net_nfc_error_e net_nfc_client_llcp_set_config_option(
- net_nfc_llcp_config_info_h config,
- uint8_t option);
-
-net_nfc_error_e net_nfc_client_llcp_free_config(
- net_nfc_llcp_config_info_h config);
-
-net_nfc_error_e net_nfc_client_llcp_create_socket_option_default(
- net_nfc_llcp_socket_option_h *option);
-
-net_nfc_error_e net_nfc_client_llcp_connect_sap(net_nfc_llcp_socket_t socket,
- sap_t sap,
- net_nfc_client_llcp_connect_sap_completed callback,
- void *user_data);
-
-net_nfc_error_e net_nfc_client_llcp_connect_sap_sync(
- net_nfc_llcp_socket_t socket,
- sap_t sap,
- net_nfc_llcp_socket_t *out_socket);
-
-
-net_nfc_error_e net_nfc_client_llcp_init(void);
-
-void net_nfc_client_llcp_deinit(void);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif //__NET_NFC_CLIENT_LLCP_H__
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef __NET_NFC_CLIENT_MANAGER_H__
-#define __NET_NFC_CLIENT_MANAGER_H__
-
-#include "net_nfc_typedef.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef void (*net_nfc_client_manager_set_active_completed)(
- net_nfc_error_e result,
- void *user_data);
-
-typedef void (*net_nfc_client_manager_get_server_state_completed)(
- net_nfc_error_e result,
- unsigned int state,
- void *user_data);
-
-typedef void (*net_nfc_client_manager_activated)(bool state,
- void *user_data);
-
-void net_nfc_client_manager_set_activated(
- net_nfc_client_manager_activated callback,
- void *user_data);
-
-void net_nfc_client_manager_unset_activated(void);
-
-net_nfc_error_e net_nfc_client_manager_set_active(int state,
- net_nfc_client_manager_set_active_completed callback,
- void *user_data);
-
-net_nfc_error_e net_nfc_client_manager_set_active_sync(int state);
-
-net_nfc_error_e net_nfc_client_manager_get_server_state(
- net_nfc_client_manager_get_server_state_completed callback,
- void *user_data);
-
-net_nfc_error_e net_nfc_client_manager_get_server_state_sync(
- unsigned int *state);
-
-/* TODO : move to internal header */
-net_nfc_error_e net_nfc_client_manager_init(void);
-
-void net_nfc_client_manager_deinit(void);
-
-bool net_nfc_client_manager_is_activated();
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif //__NET_NFC_CLIENT_MANAGER_H__
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef __NET_NFC_CLIENT_NDEF_H__
-#define __NET_NFC_CLIENT_NDEF_H__
-
-#include "net_nfc_typedef.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef void (*net_nfc_client_ndef_read_completed) (net_nfc_error_e result,
- ndef_message_h message,
- void *user_data);
-
-typedef void (*net_nfc_client_ndef_write_completed) (net_nfc_error_e result,
- void *user_data);
-
-typedef void (*net_nfc_client_ndef_make_read_only_completed) (
- net_nfc_error_e result,
- void *user_data);
-
-typedef void (*net_nfc_client_ndef_format_completed) (net_nfc_error_e result,
- void *user_data);
-
-net_nfc_error_e net_nfc_client_ndef_read(net_nfc_target_handle_h handle,
- net_nfc_client_ndef_read_completed callback,
- void *user_data);
-
-net_nfc_error_e net_nfc_client_ndef_read_sync(net_nfc_target_handle_h handle,
- ndef_message_h *message);
-
-net_nfc_error_e net_nfc_client_ndef_write(net_nfc_target_handle_h handle,
- ndef_message_h message,
- net_nfc_client_ndef_write_completed callback,
- void *user_data);
-
-net_nfc_error_e net_nfc_client_ndef_write_sync(net_nfc_target_handle_h handle,
- ndef_message_h message);
-
-net_nfc_error_e net_nfc_client_ndef_make_read_only(
- net_nfc_target_handle_h handle,
- net_nfc_client_ndef_make_read_only_completed callback,
- void *user_data);
-
-net_nfc_error_e net_nfc_client_ndef_make_read_only_sync(
- net_nfc_target_handle_h handle);
-
-net_nfc_error_e net_nfc_client_ndef_format(net_nfc_target_handle_h handle,
- data_h key,
- net_nfc_client_ndef_format_completed callback,
- void *user_data);
-
-net_nfc_error_e net_nfc_client_ndef_format_sync(
- net_nfc_target_handle_h handle,
- data_h key);
-
-/* TODO : move to internal header */
-net_nfc_error_e net_nfc_client_ndef_init(void);
-
-void net_nfc_client_ndef_deinit(void);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif //__NET_NFC_CLIENT_NDEF_H__
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef __NET_NFC_CLIENT_P2P_H__
-#define __NET_NFC_CLIENT_P2P_H__
-
-#include "net_nfc_typedef.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/* p2p callbacks */
-
-typedef void (*net_nfc_client_p2p_send_completed)(net_nfc_error_e result,
- void *user_data);
-
-typedef void (*net_nfc_client_p2p_device_discovered)(net_nfc_target_handle_h handle_info,
- void *user_data);
-
-typedef void (*net_nfc_client_p2p_device_detached)(void *user_data);
-
-typedef void (*net_nfc_client_p2p_data_received)(
- data_h p2p_data,
- void *user_data);
-
-/* P2P client API's*/
-net_nfc_error_e net_nfc_client_p2p_send(net_nfc_exchanger_data_h exchg_data,
- net_nfc_target_handle_h handle,
- net_nfc_client_p2p_send_completed callback,
- void *cb_data);
-
-net_nfc_error_e net_nfc_client_p2p_send_sync(
- net_nfc_exchanger_data_h exchg_data,
- net_nfc_target_handle_h handle);
-
-
-/* P2P client API's - used for registering callbacks*/
-void net_nfc_client_p2p_set_data_received(
- net_nfc_client_p2p_data_received callback,
- void *user_data);
-
-void net_nfc_client_p2p_set_device_detached(
- net_nfc_client_p2p_device_detached callback,
- void *user_data);
-
-void net_nfc_client_p2p_set_device_discovered(
- net_nfc_client_p2p_device_discovered callback,
- void *user_data);
-
-/* P2P client API's - used for unregistering callbacks*/
-void net_nfc_client_p2p_unset_data_received(void);
-
-void net_nfc_client_p2p_unset_device_detached(void);
-
-void net_nfc_client_p2p_unset_device_discovered(void);
-
-/* TODO : move to internal header */
-/* Init/Deint function calls*/
-net_nfc_error_e net_nfc_client_p2p_init(void);
-
-void net_nfc_client_p2p_deinit(void);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif //__NET_NFC_CLIENT_P2P_H__
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef __NET_NFC_CLIENT_SE_H__
-#define __NET_NFC_CLIENT_SE_H__
-
-#include <glib.h>
-#include "net_nfc_typedef.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/*************Secure Element Callbacks*********/
-typedef void (*net_nfc_se_set_se_cb)(
- net_nfc_error_e result,
- void *user_data);
-
-typedef void (*net_nfc_se_open_se_cb)(
- net_nfc_error_e result,
- net_nfc_target_handle_h handle,
- void *user_data);
-
-typedef void (*net_nfc_se_close_se_cb)(
- net_nfc_error_e result,
- void *user_data);
-
-typedef void (*net_nfc_se_get_atr_cb)(
- net_nfc_error_e result,
- data_h data,
- void *user_data);
-
-typedef void (*net_nfc_se_send_apdu_cb)(
- net_nfc_error_e result,
- data_h data,
- void *user_data);
-
-typedef void (*net_nfc_client_se_event)(
- net_nfc_message_e event,
- void *user_data);
-
-typedef void (*net_nfc_client_se_transaction_event)(data_h aid,
- data_h param,
- void *user_data);
-
-typedef void (*net_nfc_client_se_ese_detected_event)(
- net_nfc_target_handle_h handle,
- int dev_type,
- data_h data,
- void *user_data);
-
-/************* Secure Element API's*************/
-
-net_nfc_error_e net_nfc_client_se_set_secure_element_type(
- net_nfc_se_type_e se_type,
- net_nfc_se_set_se_cb callback,
- void *user_data);
-
-
-net_nfc_error_e net_nfc_client_se_set_secure_element_type_sync(
- net_nfc_se_type_e se_type);
-
-
-net_nfc_error_e net_nfc_client_se_get_secure_element_type(
- void *user_data);
-
-
-net_nfc_error_e net_nfc_client_se_get_secure_element_type_sync(
- gint *se_type);
-
-
-net_nfc_error_e net_nfc_client_se_open_internal_secure_element(
- net_nfc_se_type_e se_type,
- net_nfc_se_open_se_cb callback,
- void *user_data);
-
-
-net_nfc_error_e net_nfc_client_se_open_internal_secure_element_sync(
- net_nfc_se_type_e se_type,
- net_nfc_target_handle_h *handle);
-
-
-net_nfc_error_e net_nfc_client_se_close_internal_secure_element(
- net_nfc_target_handle_h handle,
- net_nfc_se_close_se_cb callback,
- void *user_data);
-
-
-net_nfc_error_e net_nfc_client_se_close_internal_secure_element_sync(
- net_nfc_target_handle_h handle);
-
-
-net_nfc_error_e net_nfc_client_se_get_atr(
- net_nfc_target_handle_h handle,
- net_nfc_se_get_atr_cb callback,
- void *user_data);
-
-
-net_nfc_error_e net_nfc_client_se_get_atr_sync(
- net_nfc_target_handle_h handle,
- data_h *atr);
-
-
-net_nfc_error_e net_nfc_client_se_send_apdu(
- net_nfc_target_handle_h handle,
- data_h apdu_data,
- net_nfc_se_send_apdu_cb callback,
- void *user_data);
-
-
-net_nfc_error_e net_nfc_client_se_send_apdu_sync(
- net_nfc_target_handle_h handle,
- data_h apdu_data,
- data_h *response);
-
-
-/************* Secure Element CallBack Register/Deregister functions*************/
-
-void net_nfc_client_se_set_ese_detection_cb(
- net_nfc_client_se_ese_detected_event callback,
- void *user_data);
-
-void net_nfc_client_se_unset_ese_detection_cb(void);
-
-void net_nfc_client_se_set_transaction_event_cb(
- net_nfc_client_se_transaction_event callback,
- void *user_data);
-
-void net_nfc_client_se_unset_transaction_event_cb(void);
-
-void net_nfc_client_se_set_event_cb(net_nfc_client_se_event callback,
- void *user_data);
-
-void net_nfc_client_se_unset_event_cb(void);
-
-
-/* TODO : move to internal header */
-/************* Secure Element Init/Deint*************/
-
-net_nfc_error_e net_nfc_client_se_init(void);
-
-
-void net_nfc_client_se_deinit(void);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif //__NET_NFC_CLIENT_SE_H__
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef __NET_NFC_CLIENT_SNEP_H__
-#define __NET_NFC_CLIENT_SNEP_H__
-
-#include "net_nfc_typedef.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef void (*net_nfc_client_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);
-
-net_nfc_error_e net_nfc_client_snep_start_server(
- net_nfc_target_handle_h target,
- const char *san,
- sap_t sap,
- net_nfc_client_snep_event_cb callback,
- void *user_data);
-
-net_nfc_error_e net_nfc_client_snep_start_client(
- net_nfc_target_handle_h target,
- const char *san,
- sap_t sap,
- net_nfc_client_snep_event_cb callback,
- void *user_data);
-
-net_nfc_error_e net_nfc_client_snep_send_client_request(
- net_nfc_snep_handle_h handle,
- net_nfc_snep_type_t snep_type,
- ndef_message_h msg,
- net_nfc_client_snep_event_cb callback,
- void *user_data);
-
-net_nfc_error_e net_nfc_client_snep_send_client_request_sync(
- net_nfc_target_handle_h target,
- net_nfc_snep_type_t snep_type,
- ndef_message_h msg,
- net_nfc_snep_type_t *resp_type,
- ndef_message_h *response);
-
-net_nfc_error_e net_nfc_client_snep_stop_service(
- net_nfc_target_handle_h target,
- net_nfc_snep_handle_h service,
- net_nfc_client_snep_event_cb callback,
- void *user_data);
-
-net_nfc_error_e net_nfc_client_snep_stop_service_sync(
- net_nfc_target_handle_h target,
- net_nfc_snep_handle_h service);
-
-net_nfc_error_e net_nfc_client_snep_register_server(const char *san,
- sap_t sap,
- net_nfc_client_snep_event_cb callback,
- void *user_data);
-
-net_nfc_error_e net_nfc_client_snep_unregister_server(const char *san,
- sap_t sap);
-
-/* TODO : move to internal header */
-net_nfc_error_e net_nfc_client_snep_init(void);
-
-void net_nfc_client_snep_deinit(void);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif //__NET_NFC_CLIENT_SNEP_H__
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef __NET_NFC_CLIENT_SYSTEM_HANDLER_H__
-#define __NET_NFC_CLIENT_SYSTEM_HANDLER_H__
-
-#include "net_nfc_typedef.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef void (*net_nfc_client_popup_set_state_callback)(
- net_nfc_error_e result,
- void *user_data);
-
-net_nfc_error_e net_nfc_client_sys_handler_set_state(int state,
- net_nfc_client_popup_set_state_callback callback,
- void *user_data);
-
-net_nfc_error_e net_nfc_client_sys_handler_set_state_force(int state,
- net_nfc_client_popup_set_state_callback callback,
- void *user_data);
-
-net_nfc_error_e net_nfc_client_sys_handler_set_state_sync(int state);
-
-net_nfc_error_e net_nfc_client_sys_handler_set_state_force_sync(int state);
-
-net_nfc_error_e net_nfc_client_sys_handler_set_launch_popup_state(int enable);
-
-net_nfc_error_e net_nfc_client_sys_handler_set_launch_popup_state_force(
- int enable);
-
-net_nfc_error_e net_nfc_client_sys_handler_get_launch_popup_state(int *state);
-
-/* TODO : move to internal header */
-net_nfc_error_e net_nfc_client_sys_handler_init(void);
-
-void net_nfc_client_sys_handler_deinit(void);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif //__NET_NFC_CLIENT_SYSTEM_HANDLER_H__
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef __NET_NFC_CLIENT_TAG_H__
-#define __NET_NFC_CLIENT_TAG_H__
-
-#include "net_nfc_typedef.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef void (*net_nfc_client_tag_is_tag_connected_completed) (
- net_nfc_error_e result,
- net_nfc_target_type_e dev_type,
- void *user_data);
-
-typedef void (*net_nfc_client_tag_get_current_tag_info_completed) (
- net_nfc_error_e result,
- net_nfc_target_info_h info,
- void *user_data);
-
-typedef void (*net_nfc_client_tag_get_current_target_handle_completed) (
- net_nfc_error_e result,
- net_nfc_target_handle_h handle,
- void *user_data);
-
-typedef void (*net_nfc_client_tag_tag_discovered) (net_nfc_target_info_h info,
- void *user_data);
-
-typedef void (*net_nfc_client_tag_tag_detached) (void *user_data);
-
-
-net_nfc_error_e net_nfc_client_tag_is_tag_connected(
- net_nfc_client_tag_is_tag_connected_completed callback,
- void *user_data);
-
-net_nfc_error_e net_nfc_client_tag_is_tag_connected_sync(
- net_nfc_target_type_e *dev_type);
-
-net_nfc_error_e net_nfc_client_tag_get_current_tag_info(
- net_nfc_client_tag_get_current_tag_info_completed callback,
- void *user_data);
-
-net_nfc_error_e net_nfc_client_tag_get_current_tag_info_sync(
- net_nfc_target_info_h *info);
-
-net_nfc_error_e net_nfc_client_tag_get_current_target_handle(
- net_nfc_client_tag_get_current_target_handle_completed callback,
- void *user_data);
-
-net_nfc_error_e net_nfc_client_tag_get_current_target_handle_sync(
- net_nfc_target_handle_h *handle);
-
-void net_nfc_client_tag_set_tag_discovered(
- net_nfc_client_tag_tag_discovered callback,
- void *user_data);
-
-void net_nfc_client_tag_unset_tag_discovered(void);
-
-void net_nfc_client_tag_set_tag_detached(
- net_nfc_client_tag_tag_detached callback,
- void *user_data);
-
-void net_nfc_client_tag_unset_tag_detached(void);
-
-void net_nfc_client_tag_set_filter(net_nfc_event_filter_e filter);
-
-net_nfc_event_filter_e net_nfc_client_tag_get_filter(void);
-
-/* TODO : move to internal header */
-net_nfc_error_e net_nfc_client_tag_init(void);
-
-void net_nfc_client_tag_deinit(void);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif //__NET_NFC_CLIENT_TAG_H__
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef __NET_NFC_CLIENT_TAG_FELICA_H__
-#define __NET_NFC_CLIENT_TAG_FELICA_H__
-
-#include "net_nfc_typedef.h"
-#include "net_nfc_client_transceive.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**
-
- @addtogroup NET_NFC_MANAGER_TAG
- @{
-
- send poll request to felica tag.
- Use this command to acquire and identify a card. Acqusition of IDm and PMm is possible with this command.
- By specifying a request code , you can acquire system code or communication performance of the system.
- By specifying a time slot, you can designate the maximum number of time slots possible to return response.
-
- NET_NFC_FELICA_POLL_NO_REQUEST = 0x00
- NET_NFC_FELICA_POLL_SYSTEM_CODE_REQUEST = 0x01
- NET_NFC_FELICA_POLL_COMM_SPEED_REQUEST= 0x02
-
- time slot
-
- Time slot Max number of slots
- 0x00, 1
- 0x01, 2
- 0x03, 4
- 0x07, 8
- 0x0f, 16
-
- \par Sync (or) Async: Sync
- This is a Asynchronous API
-
- @param[in] handle target handle of detected tag
- @param[in] req_code request code with this command
- @param[in] time_slot time slot value
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter has illigal NULL pointer
- @exception NET_NFC_ALLOC_FAIL memory allocation is failed
- @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization
- @exception NET_NFC_BUSY Device is too busy to handle your request
- @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error
- @exception NET_NFC_RF_TIMEOUT Timeout is raised while communicate with tag
- @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command
- @exception NET_NFC_INVALID_HANDLE target handle is not valid
- @exception NET_NFC_TAG_READ_FAILED received chunked data is not valied (damaged data is recieved) or error ack is recieved
- @exception NET_NFC_NO_DATA_FOUND mendantory tag info (SYSTEM_CODE, etc) is not founded
-
-*/
-
-net_nfc_error_e net_nfc_client_felica_poll(net_nfc_target_handle_h handle,
- net_nfc_felica_poll_request_code_e req_code,
- uint8_t time_slote,
- nfc_transceive_data_callback callback,
- void *user_data);
-
-/**
- Use this command to check for the existence of Area / Service specified by Area Code / Service Code
- If the specified Area / Service exists, the card returns version information of the key known as "Key Version" (2 Bytes)
- If the specified Area / Service does not exist, the card returns 0xffff as it s Key Version
-
- \par Sync (or) Async: Sync
- This is a Asynchronous API
-
- @param[in] handle target handle of detected tag
- @param[in] number_of_area_service the number of specified Area / Service list
- @param[in] area_service_list specified Area / Service list
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter has illigal NULL pointer
- @exception NET_NFC_ALLOC_FAIL memory allocation is failed
- @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization
- @exception NET_NFC_BUSY Device is too busy to handle your request
- @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error
- @exception NET_NFC_RF_TIMEOUT Timeout is raised while communicate with tag
- @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command
- @exception NET_NFC_INVALID_HANDLE target handle is not valid
- @exception NET_NFC_TAG_READ_FAILED received chunked data is not valied (damaged data is recieved) or error ack is recieved
- @exception NET_NFC_NO_DATA_FOUND mendantory tag info (IDm, etc) is not founded
- @exception NET_NFC_OUT_OF_BOUND the length of IDm is not correct. number of services exceed max value
-
-*/
-
-net_nfc_error_e net_nfc_client_felica_request_service(
- net_nfc_target_handle_h handle,
- uint8_t number_of_area_service,
- uint16_t area_service_list[],
- uint8_t number_of_services,
- nfc_transceive_data_callback callback,
- void *user_data);
-
-/**
- Use this command to check whether a card exist
- the Current mode of the card is returned.
-
- Mode
-
- 0x00 Mode0
- 0x01 Mode1
- 0x02 Mode2
- 0x03 Mode3
-
- \par Sync (or) Async: Sync
- This is a Asynchronous API
-
- @param[in] handle target handle of detected tag
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter has illigal NULL pointer
- @exception NET_NFC_ALLOC_FAIL memory allocation is failed
- @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization
- @exception NET_NFC_BUSY Device is too busy to handle your request
- @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error
- @exception NET_NFC_RF_TIMEOUT Timeout is raised while communicate with tag
- @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command
- @exception NET_NFC_INVALID_HANDLE target handle is not valid
- @exception NET_NFC_TAG_READ_FAILED received chunked data is not valied (damaged data is recieved) or error ack is recieved
- @exception NET_NFC_NO_DATA_FOUND mendantory tag info (IDm, etc) is not founded
- @exception NET_NFC_OUT_OF_BOUND the length of IDm is not correct
-
-*/
-
-net_nfc_error_e net_nfc_client_felica_request_response(
- net_nfc_target_handle_h handle,
- nfc_transceive_data_callback callback,
- void *user_data);
-
-/**
- Use this command to read block data from a Service that requires no authentification
-
- \par Sync (or) Async: Sync
- This is a Asynchronous API
-
- @param[in] handle target handle of detected tag
- @param[in] number_of_service the number of service list to read
- @param[in] service_list specified Service list to read
- @param[in] number_of_blocks the number of blocks to read
- @param[in] block_list the blocks to read
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter has illigal NULL pointer
- @exception NET_NFC_ALLOC_FAIL memory allocation is failed
- @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization
- @exception NET_NFC_BUSY Device is too busy to handle your request
- @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error
- @exception NET_NFC_RF_TIMEOUT Timeout is raised while communicate with tag
- @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command
- @exception NET_NFC_INVALID_HANDLE target handle is not valid
- @exception NET_NFC_TAG_READ_FAILED received chunked data is not valied (damaged data is recieved) or error ack is recieved
- @exception NET_NFC_NO_DATA_FOUND mendantory tag info (IDm, etc) is not founded
- @exception NET_NFC_OUT_OF_BOUND the length of IDm is not correct
-
-*/
-
-net_nfc_error_e net_nfc_client_felica_read_without_encryption(
- net_nfc_target_handle_h handle,
- uint8_t number_of_services,
- uint16_t service_list[],
- uint8_t number_of_blocks,
- uint8_t block_list[],
- nfc_transceive_data_callback callback,
- void *user_data);
-
-/**
- Use this command to write block data to a Service that requires no authentification
-
- \par Sync (or) Async: Sync
- This is a Asynchronous API
-
- @param[in] handle target handle of detected tag
- @param[in] number_of_service the number of service list to write
- @param[in] service_list specified Service list to write
- @param[in] number_of_blocks the number of blocks to write
- @param[in] block_list the blocks to write
- @param[in] data the data to write
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter has illigal NULL pointer
- @exception NET_NFC_ALLOC_FAIL memory allocation is failed
- @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization
- @exception NET_NFC_BUSY Device is too busy to handle your request
- @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error
- @exception NET_NFC_RF_TIMEOUT Timeout is raised while communicate with tag
- @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command
- @exception NET_NFC_INVALID_HANDLE target handle is not valid
- @exception NET_NFC_TAG_READ_FAILED received chunked data is not valied (damaged data is recieved) or error ack is recieved
- @exception NET_NFC_NO_DATA_FOUND mendantory tag info (IDm, etc) is not founded
- @exception NET_NFC_OUT_OF_BOUND the length of IDm is not correct. number of services exceed max value, the data length to write is exceed the limitation. It should be less than number_of_blocks * 16 bytes
-
-*/
-
-net_nfc_error_e net_nfc_client_felica_write_without_encryption(
- net_nfc_target_handle_h handle,
- uint8_t number_of_services,
- uint16_t service_list[],
- uint8_t number_of_blocks,
- uint8_t block_list[],
- data_h data,
- nfc_transceive_data_callback callback,
- void *user_data);
-
-/**
- Use this command to acquire system code of the system located on a card
- If a card is divided into mutiple system, this command acquires system code of all the system existing in the card
-
- \par Sync (or) Async: Sync
- This is a Asynchronous API
-
- @param[in] handle target handle of detected tag
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter has illigal NULL pointer
- @exception NET_NFC_ALLOC_FAIL memory allocation is failed
- @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization
- @exception NET_NFC_BUSY Device is too busy to handle your request
- @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error
- @exception NET_NFC_RF_TIMEOUT Timeout is raised while communicate with tag
- @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command
- @exception NET_NFC_INVALID_HANDLE target handle is not valid
- @exception NET_NFC_TAG_READ_FAILED received chunked data is not valied (damaged data is recieved) or error ack is recieved
- @exception NET_NFC_NO_DATA_FOUND mendantory tag info (IDm, etc) is not founded
- @exception NET_NFC_OUT_OF_BOUND the length of IDm is not correct.
-
-*/
-
-net_nfc_error_e net_nfc_client_felica_request_system_code(
- net_nfc_target_handle_h handle,
- nfc_transceive_data_callback callback,
- void* trans_param);
-
-/**
-@}
-*/
-
-
-#ifdef __cplusplus
-}
-#endif
-
-
-#endif //__NET_NFC_CLIENT_TAG_FELICA_H__
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef __NET_NFC_CLIENT_TAG_INTERNAL_H__
-#define __NET_NFC_CLIENT_TAG_INTERNAL_H__
-
-#include <glib.h>
-
-#include "net_nfc_typedef_internal.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-gboolean net_nfc_client_tag_is_connected(void);
-
-net_nfc_target_info_s *net_nfc_client_tag_get_client_target_info(void);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif //__NET_NFC_CLIENT_TAG_INTERNAL_H__
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef __NET_NFC_CLIENT_TAG_JEWEL_H__
-#define __NET_NFC_CLIENT_TAG_JEWEL_H__
-
-#include "net_nfc_typedef.h"
-#include "net_nfc_client_transceive.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**
-
- @addtogroup NET_NFC_MANAGER_TAG
- @{
-
- read uid from jewel tag.
-
- \par Sync (or) Async: Sync
- This is a Asynchronous API
-
- @param[in] handle target handle of detected tag
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter has illigal NULL pointer
- @exception NET_NFC_ALLOC_FAIL memory allocation is failed
- @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization
- @exception NET_NFC_BUSY Device is too busy to handle your request
- @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error
- @exception NET_NFC_RF_TIMEOUT Timeout is raised while communicate with tag
- @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command
- @exception NET_NFC_INVALID_HANDLE target handle is not valid
- @exception NET_NFC_TAG_READ_FAILED received chunked data is not valied (damaged data is recieved) or error ack is recieved
- @exception NET_NFC_NO_DATA_FOUND mendantory tag info (UID, etc) is not founded
-
-*/
-
-net_nfc_error_e net_nfc_client_jewel_read_id(net_nfc_target_handle_h handle,
- nfc_transceive_data_callback callback,
- void *user_data);
-
-/**
- read one byte of specific address .
-
- \par Sync (or) Async: Sync
- This is a Asynchronous API
-
- @param[in] handle target handle of detected tag
- @param[in] block block number. (block 0 ~ block E)
- @param[in] byte byte number. Each block has 8 bytes. (byte 0 ~ byte 7)
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter has illigal NULL pointer
- @exception NET_NFC_ALLOC_FAIL memory allocation is failed
- @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization
- @exception NET_NFC_BUSY Device is too busy to handle your request
- @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error
- @exception NET_NFC_RF_TIMEOUT Timeout is raised while communicate with tag
- @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command
- @exception NET_NFC_INVALID_HANDLE target handle is not valid
- @exception NET_NFC_TAG_READ_FAILED received chunked data is not valied (damaged data is recieved) or error ack is recieved
- @exception NET_NFC_NO_DATA_FOUND mendantory tag info (UID, etc) is not founded
-
-*/
-
-net_nfc_error_e net_nfc_client_jewel_read_byte(net_nfc_target_handle_h handle,
- uint8_t block,
- uint8_t byte,
- nfc_transceive_data_callback callback,
- void *user_data);
-
-/**
- read all byte from tag .
-
- \par Sync (or) Async: Sync
- This is a Asynchronous API
-
- @param[in] handle target handle of detected tag
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter has illigal NULL pointer
- @exception NET_NFC_ALLOC_FAIL memory allocation is failed
- @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization
- @exception NET_NFC_BUSY Device is too busy to handle your request
- @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error
- @exception NET_NFC_RF_TIMEOUT Timeout is raised while communicate with tag
- @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command
- @exception NET_NFC_INVALID_HANDLE target handle is not valid
- @exception NET_NFC_TAG_READ_FAILED received chunked data is not valied (damaged data is recieved) or error ack is recieved
- @exception NET_NFC_NO_DATA_FOUND mendantory tag info (UID, etc) is not founded
-
-*/
-
-
-net_nfc_error_e net_nfc_client_jewel_read_all(net_nfc_target_handle_h handle,
- nfc_transceive_data_callback callback,
- void *user_data);
-
-
-/**
- operate erase and write cycle . If any of BLOCK-0 to BLOCK-D is locked then write with erase is barred form thoes blocks.
- Additionally 0, D, E blocks are automatically in the lock condition. so write with erase is always barred from thoes blocks.
-
- \par Sync (or) Async: Sync
- This is a Asynchronous API
-
- @param[in] handle target handle of detected tag
- @param[in] block block number. (block 0 ~ block E)
- @param[in] data the data to write
- @param[in] byte byte number. Each block has 8 bytes. (byte 0 ~ byte 7)
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter has illigal NULL pointer
- @exception NET_NFC_ALLOC_FAIL memory allocation is failed
- @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization
- @exception NET_NFC_BUSY Device is too busy to handle your request
- @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error
- @exception NET_NFC_RF_TIMEOUT Timeout is raised while communicate with tag
- @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command
- @exception NET_NFC_INVALID_HANDLE target handle is not valid
- @exception NET_NFC_TAG_WRITE_FAILED read only tag, or error ack is received from tag
- @exception NET_NFC_NO_DATA_FOUND mendantory tag info (UID, etc) is not founded
-
-*/
-
-net_nfc_error_e net_nfc_client_jewel_write_with_erase(
- net_nfc_target_handle_h handle,
- uint8_t block,
- uint8_t byte,
- uint8_t data,
- nfc_transceive_callback callback,
- void *user_data);
-
-
-/**
- operate no erase and write cycle .
-
- The WRITE-NE command is available for three main purposes
- - Lock . to set the ��lock bit�� for a block
- - OTP . to set One-Time-Programmable bits (bytes 2 . 7 of Block-E), where between one and eight OTP bits can be set with a singleWRITE-NE command
- - A fast-write in order to reduce overall time to write data to memory blocks for the first time given that the original condition of memory is zero
-
- \par Sync (or) Async: Sync
- This is a Asynchronous API
-
- @param[in] handle target handle of detected tag
- @param[in] block block number. (block 0 ~ block E)
- @param[in] data the data to write
- @param[in] byte byte number. Each block has 8 bytes. (byte 0 ~ byte 7)
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter has illigal NULL pointer
- @exception NET_NFC_ALLOC_FAIL memory allocation is failed
- @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization
- @exception NET_NFC_BUSY Device is too busy to handle your request
- @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error
- @exception NET_NFC_RF_TIMEOUT Timeout is raised while communicate with tag
- @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command
- @exception NET_NFC_INVALID_HANDLE target handle is not valid
- @exception NET_NFC_TAG_WRITE_FAILED read only tag, or error ack is received from tag
- @exception NET_NFC_NO_DATA_FOUND mendantory tag info (UID, etc) is not founded
-
-*/
-
-net_nfc_error_e net_nfc_client_jewel_write_with_no_erase(
- net_nfc_target_handle_h handle,
- uint8_t block,
- uint8_t byte,
- uint8_t data,
- nfc_transceive_callback callback,
- void *user_data);
-
-/**
-@}
-*/
-
-
-#ifdef __cplusplus
-}
-#endif
-
-
-#endif //__NET_NFC_CLIENT_TAG_JEWEL_H__
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef __NET_NFC_CLIENT_TEST_H__
-#define __NET_NFC_CLIENT_TEST_H__
-
-#include "net_nfc_typedef.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef void (*net_nfc_client_test_sim_test_completed) (net_nfc_error_e result,
- void *user_data);
-
-typedef void (*net_nfc_client_test_prbs_test_completed) (
- net_nfc_error_e result,
- void *user_data);
-
-typedef void (*net_nfc_client_test_get_firmware_version_completed) (
- net_nfc_error_e result,
- char *version,
- void *user_data);
-typedef void (*net_nfc_client_test_set_ee_data_completed) (
- net_nfc_error_e result,
- void *user_data);
-
-
-net_nfc_error_e net_nfc_client_test_sim_test(
- net_nfc_client_test_sim_test_completed callback,
- void *user_data);
-
-net_nfc_error_e net_nfc_client_test_sim_test_sync(void);
-
-net_nfc_error_e net_nfc_client_test_prbs_test(uint32_t tech,
- uint32_t rate,
- net_nfc_client_test_prbs_test_completed callback,
- void *user_data);
-
-net_nfc_error_e net_nfc_client_test_prbs_test_sync(uint32_t tech,
- uint32_t rate);
-
-net_nfc_error_e net_nfc_client_test_get_firmware_version(
- net_nfc_client_test_get_firmware_version_completed callback,
- void *user_data);
-
-net_nfc_error_e net_nfc_client_test_get_firmware_version_sync(char **version);
-
-net_nfc_error_e net_nfc_client_test_set_ee_data(int mode,
- int reg_id,
- data_h data,
- net_nfc_client_test_set_ee_data_completed callback,
- void *user_data);
-
-net_nfc_error_e net_nfc_client_test_set_ee_data_sync(int mode,
- int reg_id,
- data_h data);
-
-
-/* TODO : move to internal header */
-net_nfc_error_e net_nfc_client_test_init(void);
-
-void net_nfc_client_test_deinit(void);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif //__NET_NFC_CLIENT_TEST_H__
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef __NET_NFC_CLIENT_TRANSCEIVE_H__
-#define __NET_NFC_CLIENT_TRANSCEIVE_H__
-
-#include "net_nfc_typedef.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef void (* nfc_transceive_callback)(net_nfc_error_e result,
- void *user_data);
-
-typedef void (* nfc_transceive_data_callback)(net_nfc_error_e result,
- data_h data,
- void *user_data);
-
-net_nfc_error_e net_nfc_client_transceive(net_nfc_target_handle_h handle,
- data_h rawdata,
- nfc_transceive_callback callback,
- void *user_data);
-
-net_nfc_error_e net_nfc_client_transceive_data(net_nfc_target_handle_h handle,
- data_h rawdata,
- nfc_transceive_data_callback callback,
- void *user_data);
-
-net_nfc_error_e net_nfc_client_transceive_sync(net_nfc_target_handle_h handle,
- data_h rawdata);
-
-net_nfc_error_e net_nfc_client_transceive_data_sync(
- net_nfc_target_handle_h handle,
- data_h rawdata,
- data_h *response);
-
-/* TODO : move to internal header */
-net_nfc_error_e net_nfc_client_transceive_init(void);
-
-void net_nfc_client_transceive_deinit(void);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif //__NET_NFC_CLIENT_TRANSCEIVE_H__
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __NET_NFC_CLIENT_UTIL_INTERNAL_H__
-#define __NET_NFC_CLIENT_UTIL_INTERNAL_H__
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif //__NET_NFC_CLIENT_UTIL_INTERNAL_H__
\ No newline at end of file
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef __NET_NFC_DATA_H__
-#define __NET_NFC_DATA_H__
-
-#include <net_nfc_typedef.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-/**
-
- @addtogroup NET_NFC_MANAGER_INFO
- @{
- This document is for the APIs reference document
-
- NFC Manager defines are defined in <nfc-manager-def.h>
-
- @li @c #net_nfc_initialize Initialize the nfc device.
-
-*/
-
-/**
- create data handler only.
-
- @param[out] data data handler
-
- @return return the result of this operation
-
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- @exception NET_NFC_ALLOC_FAIL memory allocation is failed
- */
-
-net_nfc_error_e net_nfc_create_data_only (data_h* data);
-
-/**
- create data handler with initial values, bytes will be copied into the data handler.
-
- @param[out] data data handler
- @param[in] bytes binary data
- @param[in] length size of binary data;
-
- @return return the result of this operation
-
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- @exception NET_NFC_ALLOC_FAIL memory allocation is failed
- */
-net_nfc_error_e net_nfc_create_data (data_h* data, const uint8_t* bytes, const uint32_t length);
-
-/**
- get the byes and length from data handler. data handler assume bytes may have '0x0' value.
- that's why this function also provides the length.
-
- @param[in] data data handler
- @param[out] bytes binary pointer (it returns the direct pointer of handler's data) do not free this
- @param[out] length length of the binary data;
-
- @return return the result of this operation
-
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- */
-net_nfc_error_e net_nfc_get_data (const data_h data, uint8_t** bytes, uint32_t * length);
-
-/**
- replace the data handler with given bytes. binary data (bytes) will be copied to data hander.
- application should free or use local variable for given byte pointer.
-
- @param[in] data data handler
- @param[in] bytes binary data
- @param[in] length size of binary data
-
- @return return the result of this operation
-
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- */
-
-net_nfc_error_e net_nfc_set_data (const data_h data, const uint8_t* bytes, const uint32_t length);
-
-/**
- get length of data handler's bytes.
-
- @param[in] data data handler
-
- @return length of bytes length
-
- @exception 0 is returned if data is NULL
- */
-
-uint32_t net_nfc_get_data_length (const data_h data);
-
-/**
- get pointer of the handler's bytes (do not free this. it wll be freed when the application call "net_nfc_free_data" function
-
- @param[in] data data handler
-
- @return the pointer of bytes.
-
- @exception NULL is returned if data is NULL
- */
-
-uint8_t * net_nfc_get_data_buffer (const data_h data);
-
-/**
- free data handler. (it also free the copied bytes)
-
- @param[in] data data handler
-
- @return return the result of this operation
-
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- */
-
-net_nfc_error_e net_nfc_free_data (data_h data);
-
-
-
-/**
-@}
-*/
-#ifdef __cplusplus
-}
-#endif
-
-#endif //__NET_NFC_DATA_H__
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef __NET_NFC_NDEF_MESSAGE_H__
-#define __NET_NFC_NDEF_MESSAGE_H__
-
-#include "net_nfc_typedef.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-/**
-
- @addtogroup NET_NFC_MANAGER_NDEF
- @{
- This document is for the APIs reference document
-
- NFC Manager defines are defined in <nfc-manager-def.h>
-
- @li @c #net_nfc_initialize Initialize the nfc device.
-
-*/
-
-/**
- create ndef message handler. this function allocate the ndef message handler and initialize.
-
- \par Sync (or) Async: sync
- This is a Synchronous API
-
- @param[out] ndef_message instance of the ndef_message is retuened
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- @exception NET_NFC_ALLOC_FAIL memory allocation is failed
-
- @code
-
- net_nfc_error_e result = NET_NFC_OK;
- ndef_message_h msg = NULL;
- ndef_record_h record = NULL;
-
- result = net_nfc_create_ndef_message (&msg);
- if (result != NET_NFC_OK) return result;
-
- result = net_nfc_create_uri_type_record (&record , "http://www.samsung.com" ,NET_NFC_SCHEMA_FULL_URI);
- if (result != NET_NFC_OK) return result;
-
- result = net_nfc_append_record_to_ndef_message (msg ,record);
- if (result != NET_NFC_OK) return result;
-
- net_nfc_write_ndef(id, msg, &user_context);
-
- net_nfc_free_ndef_message (msg);
-
- @endcode
- */
-
-
-net_nfc_error_e net_nfc_create_ndef_message (ndef_message_h* ndef_message);
-
-/**
- this APIs is the getter of record counts
-
- \par Sync (or) Async: sync
- This is a Synchronous API
-
- @param[in] ndef_message output structure to get the record
- @param[out] count number of record count
-
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
-
- @code
-
- static void net_nfc_cb(net_nfc_message_e message, net_nfc_error_e result, void* data , void* userContext)
- {
- switch (message)
- {
- case NET_NFC_MESSAGE_READ_NDEF:
- {
- if(data != NULL)
- {
- int count = 0;
- ndef_message_h ndef = (ndef_message_h)(data);
- net_nfc_get_ndef_message_record_count (ndef, &count);
- printf ("record count = %d\n", count);
- }
- }
- break;
- }
- }
- @endcode
-*/
-net_nfc_error_e net_nfc_get_ndef_message_record_count (ndef_message_h ndef_message, int * count);
-
-/**
- This function converts the NDEF Message structure to serial bytes of ndef message.
-
- it gets copy of the rawdata bytes from ndef_message. ndef_message has no effect after free rawdata
- Application should free rawdata.
-
- \par Sync (or) Async: sync
- This is a Synchronous API
-
- @param[in] ndef_message output structure to get the record
- @param[out] rawdata this is the raw data that will be formed into the
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- @exception NET_NFC_ALLOC_FAIL memory allocation is failed
- @exception NET_NFC_NDEF_BUF_END_WITHOUT_ME Wrong formatted NDEF message
-
- @code
-
- net_nfc_error_e result = NET_NFC_OK;
- data_h rawdata;
- ndef_message_h msg = NULL;
- ndef_record_h record = NULL;
- int idx;
- uint8_t * buffer = NULL;
-
- result = net_nfc_create_ndef_message (&msg);
- if (result != NET_NFC_OK) return result;
-
- result = net_nfc_create_uri_type_record (&record , "http://www.samsung.com" ,NET_NFC_SCHEMA_FULL_URI);
- if (result != NET_NFC_OK) return result;
-
- result = net_nfc_append_record_to_ndef_message (msg ,record);
- if (result != NET_NFC_OK) return result;
-
- net_nfc_create_rawdata_from_ndef_message (msg, &rawdata);
-
- buffer = net_nfc_get_data_buffer (rawdata) ;
-
- for (idx = 0; idx < net_nfc_get_data_length (rawdata) ; idx++)
- {
- printf (" %02X", buffer[idx]);
- if (idx % 16 == 0) printf ("\n");
- }
-
- net_nfc_free_ndef_message (msg);
-
- @endcode
-
-
-*/
-
-net_nfc_error_e net_nfc_create_rawdata_from_ndef_message (ndef_message_h ndef_message, data_h* rawdata);
-
-/**
- This function return the structure of ndef_message from serial format of ndef message.
- You may say create ndef handler from raw serial bytes
- it cunsumes the bytes array until get the (ME==1). it retunrs error if the bytes array does not have ME flag.
- if the array has two NDEF Message serially (not recursive case - like smart poster). the first NDEF message
- will be converted to ndef_message handler, and other messages will be ignored.
-
- \par Sync (or) Async: sync
- This is a Synchronous API
-
- @param[out] ndef_message ndef message handler that will be returned
- @param[in] rawdata ndef message that formed in bytes array
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- @exception NET_NFC_ALLOC_FAIL memory allocation is failed
- @exception NET_NFC_NDEF_BUF_END_WITHOUT_ME Wrong formatted NDEF message
-
- @code
-
- static void net_nfc_cb(net_nfc_message_e message, net_nfc_error_e result, void* data , void* userContext)
- {
- switch (message)
- {
- case NET_NFC_MESSAGE_READ_NDEF:
- {
- if(data != NULL)
- {
- record_h record;
- ndef_message_h url;
- data_h ndef_type;
- data_h payload;
-
- ndef_message_h ndef = (ndef_message_h)(data);
- net_nfc_get_record_by_index (ndef, 0, &record);
- net_nfc_get_record_type (record, &ndef_type);
- if (strncmp (ndef_type.buffer, "Sp", ndef_type.length)){
- net_nfc_get_record_payload (record, &payload);
- net_nfc_create_ndef_message_from_rawdata (&url, payload);
- printf_ndef_massage (url);
- }
- }
- }
- break;
- }
- }
- @endcode
-
-*/
-
-
-net_nfc_error_e net_nfc_create_ndef_message_from_rawdata (ndef_message_h* ndef_message, data_h rawdata);
-
-/**
- it returns the total size of ndef message bytes. parse the structure data and count the bytes
- to know the length of bytes required to store the NDEF message.
-
- it calculates the length every time application calls this function. it does not cache inside.
- TODO: do we need to cache the value inside of ndef_message_h
-
- \par Sync (or) Async: sync
- This is a Synchronous API
-
- @param[in] ndef_message this is the raw data that will be formed into the
- @param[out] length number of bytes required to create ndef message serial format
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
-*/
-
-net_nfc_error_e net_nfc_get_ndef_message_byte_length(ndef_message_h ndef_message, uint32_t *length);
-/**
- Append a record to ndef message structure.
- This API help to create NDEF message and it control Record flags to follow the NDEF forum specification
-
- \par Sync (or) Async: sync
- This is a Synchronous API
-
- @param[in] ndef_message NDEF message structure
- @param[in] record a record will be added into the ndef message
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
-
- @code
-
- net_nfc_error_e result = NET_NFC_OK;
- data_h rawdata;
- ndef_message_h msg = NULL;
- ndef_record_h record = NULL;
- int idx;
- uint8_t * buffer = NULL;
-
- result = net_nfc_create_ndef_message (&msg);
- if (result != NET_NFC_OK) return result;
-
- result = net_nfc_create_uri_type_record (&record , "http://www.samsung.com" ,NET_NFC_SCHEMA_FULL_URI);
- if (result != NET_NFC_OK) return result;
-
- result = net_nfc_append_record_to_ndef_message (msg ,record);
- if (result != NET_NFC_OK) return result;
-
- net_nfc_create_rawdata_from_ndef_message (msg, &rawdata);
-
- buffer = net_nfc_get_data_buffer (rawdata) ;
-
- for (idx = 0; idx < net_nfc_get_data_length (rawdata) ; idx++)
- {
- printf (" %02X", buffer[idx]);
- if (idx % 16 == 0) printf ("\n");
- }
-
- net_nfc_free_ndef_message (msg);
-
- @endcode
-*/
-net_nfc_error_e net_nfc_append_record_to_ndef_message(ndef_message_h ndef_message, ndef_record_h record);
-
-/**
- remove the record that indicated by index number.
- and this deleted record will be freed.
-
- \par Sync (or) Async: sync
- This is a Synchronous API
-
- @param[in] ndef_message the message wil be freed
- @param[in] index index of record
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- @exception NET_NFC_OUT_OF_BOUND index is out of bound
- @exception NET_NFC_INVALID_FORMAT Wrong formatted ndef message
-
-*/
-
-net_nfc_error_e net_nfc_remove_record_by_index (ndef_message_h ndef_message, int index);
-
-/**
- get record by index. this function just return the pointer of record.
- if you change the record value it directly affected to NDEF message
-
- \par Sync (or) Async: sync
- This is a Synchronous API
-
- @param[in] ndef_message the message wil be freed
- @param[in] index index of record
- @param[in] record record pointer
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- @exception NET_NFC_OUT_OF_BOUND index is out of bound
-
-*/
-net_nfc_error_e net_nfc_get_record_by_index (ndef_message_h ndef_message, int index, ndef_record_h* record);
-
-/**
- Add a record by index. This API help to add record by index. MB or ME bits will automatically assained.
-
- \par Sync (or) Async: sync
- This is a Synchronous API
-
- @param[in] ndef_message the message wil be freed
- @param[in] index index of record
- @param[in] record record pointer
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- @exception NET_NFC_OUT_OF_BOUND index is out of bound
- @exception NET_NFC_INVALID_FORMAT Wrong formatted ndef message
- */
-
-net_nfc_error_e net_nfc_append_record_by_index (ndef_message_h ndef_message,int index, ndef_record_h record);
-
-
-/**
- search the specific type in the NDEF message. this function return the first record that holds the type.
- if the type has "urn:nfc:wkt:" or "urn:nfc:ext:", these prefix will be removed automatically.
-
- @param[in] ndef_message NDEF message handler
- @param[in] tnf TNF value
- @param[in] type Record type , include type length
- @param[out] record record handle
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- @exception NET_NFC_NO_DATA_FOUND search is failed
- @exception NET_NFC_INVALID_FORMAT Wrong formatted ndef message
-
- @code
-
- static void net_nfc_cb(net_nfc_message_e message, net_nfc_error_e result, void* data , void* userContext)
- {
- switch (message)
- {
- case NET_NFC_MESSAGE_READ_NDEF:
- {
- if(data != NULL)
- {
- date_h type;
- int count = 0;
- ndef_message_h ndef = (ndef_message_h)(data);
- ndef_record_h record;
- net_nfc_create_data (&type, "Sp", 2);
- net_nfc_search_record_by_type (ndef, NET_NFC_RECORD_WELL_KNOWN_TYPE, type, &record);
- }
- }
- break;
- }
- }
-
- @endcode
-
-*/
-net_nfc_error_e net_nfc_search_record_by_type (ndef_message_h ndef_message, net_nfc_record_tnf_e tnf, data_h type, ndef_record_h * record);
-
-
-/**
- this function helps to free the ndef_message_s type structure.
- it has multiple ndef_record_s with linked list form and each record has own pointer.
- this function free these memory in one shot!
- don't worry about the record handler. these handlers also freed.
-
- \par Sync (or) Async: sync
- This is a Synchronous API
-
- @param[in] ndef_message the message wil be freed
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
-
-*/
-
-net_nfc_error_e net_nfc_free_ndef_message(ndef_message_h ndef_message);
-
-
-/**
- retreive ndef message which is read by nfc-manager .
- after reading message, it will be removed from nfc-manager storage
-
- \par Sync (or) Async: sync
- This is a Synchronous API
-
- @param[in] ndef_message the message wil be retrieved
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- @exception NET_NFC_NO_NDEF_MESSAGE No ndef message is found
- @exception NET_NFC_INVALID_FORMAT Wrong formatted ndef message
- @exception NET_NFC_ALLOC_FAIL memory allocation is failed
-
-*/
-
-net_nfc_error_e net_nfc_retrieve_current_ndef_message (ndef_message_h* ndef_message);
-
-
-/**
-@}
-*/
-
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif //__NET_NFC_NDEF_MESSAGE_H__
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef __NET_NFC_NDEF_MESSAGE_HANDOVER_H__
-#define __NET_NFC_NDEF_MESSAGE_HANDOVER_H__
-
-#include "net_nfc_typedef.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**
- This function create wifi configure handler instance.
-
- @param[out] config instance handler
- @param[in] type Carrier types it would be wifi add hoc or wifi AP
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- @exception NET_NFC_OUT_OF_BOUND type value is not enum value
- @exception NET_NFC_ALLOC_FAIL allocation is failed
- */
-
-net_nfc_error_e net_nfc_create_carrier_config (net_nfc_carrier_config_h * config, net_nfc_conn_handover_carrier_type_e type);
-
-/**
- Add property key and value for configuration.
- the data will be copied to config handle, you should free used data array.
-
- @param[in] config instance handler
- @param[in] attribute attribue key for value.
- @param[in] size size of value
- @param[in] data value array (binary type)
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- @exception NET_NFC_ALLOC_FAIL allocation is failed
- */
-
-net_nfc_error_e net_nfc_add_carrier_config_property (net_nfc_carrier_config_h config, uint16_t attribute, uint16_t size, uint8_t * data);
-
-/**
- Remove the key and value from configuration, you can also remove the group withe CREDENTIAL key.
- The the attribute is exist then it will be removed and also freed automatically.
-
- @param[in] config instance handler
- @param[in] attribute attribue key for value.
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- @exception NET_NFC_NO_DATA_FOUND the given key is not found
- @exception NET_NFC_ALREADY_REGISTERED the given attribute is already registered
- */
-
-net_nfc_error_e net_nfc_remove_carrier_config_property (net_nfc_carrier_config_h config, uint16_t attribute);
-/**
- Get the property value by attribute.
-
- @param[in] config instance handler
- @param[in] attribute attribue key for value.
- @param[out] size size of value
- @param[out] data value array (binary type)
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- @exception NET_NFC_NO_DATA_FOUND The given key is not found
- */
-
-net_nfc_error_e net_nfc_get_carrier_config_property (net_nfc_carrier_config_h config, uint16_t attribute, uint16_t * size, uint8_t ** data);
-
-/**
- The group will be joined into the configure
-
- @param[in] config instance handler
- @param[in] group group handle
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- @exception NET_NFC_ALREADY_REGISTERED The given group is already registered
- */
-
-net_nfc_error_e net_nfc_append_carrier_config_group (net_nfc_carrier_config_h config, net_nfc_property_group_h group);
-
-/**
- Remove the group from configure handle
-
- @param[in] config instance handler
- @param[in] group group handle
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- @exception NET_NFC_NO_DATA_FOUND given handle pointer is not exist in the configure handle
- */
-
-net_nfc_error_e net_nfc_remove_carrier_config_group (net_nfc_carrier_config_h config, net_nfc_property_group_h group);
-
-/**
- Get the group from configure handle by index
-
- @param[in] config instance handler
- @param[in] index index number
- @param[out] group group handle
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- @exception NET_NFC_OUT_OF_BOUND the index number is not bound of the max count
- @exception NET_NFC_NO_DATA_FOUND this is should be happened if the configure handle is dammaged
- */
-
-net_nfc_error_e net_nfc_get_carrier_config_group (net_nfc_carrier_config_h config, int index, net_nfc_property_group_h * group);
-
-/**
- free the configure handle
-
- @param[in] config instance handler
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- */
-
-net_nfc_error_e net_nfc_free_carrier_config (net_nfc_carrier_config_h config);
-
-/**
- create the group handle
-
- @param[out] group instance group handler
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- @exception NET_NFC_ALLOC_FAIL allocation is failed
- */
-
-net_nfc_error_e net_nfc_create_carrier_config_group (net_nfc_property_group_h * group, uint16_t attribute);
-
-/**
- add property into the group
-
- @param[in] group instance group handler
- @param[in] attribute attribute of the property
- @param[in] size size of data (value)
- @param[in] data data of the property
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- @exception NET_NFC_ALLOC_FAIL allocation is failed
- @exception NET_NFC_ALREADY_REGISTERED the given key is already registered
- */
-
-net_nfc_error_e net_nfc_add_carrier_config_group_property (net_nfc_property_group_h group, uint16_t attribute, uint16_t size, uint8_t * data);
-
-/**
- get property from group handle
-
- @param[in] group instance group handler
- @param[in] attribute attribute of the property
- @param[out] size size of data (value)
- @param[out] data data of the property
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- @exception NET_NFC_NO_DATA_FOUND the attribute does not exist in the group
- */
-
-net_nfc_error_e net_nfc_get_carrier_config_group_property (net_nfc_property_group_h group, uint16_t attribute, uint16_t *size, uint8_t ** data);
-
-/**
- remove the property from the group
-
- @param[in] group instance group handler
- @param[in] attribute attribute of the property
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- @exception NET_NFC_NO_DATA_FOUND the attribute does not exist in the group
- */
-
-net_nfc_error_e net_nfc_remove_carrier_config_group_property (net_nfc_property_group_h group, uint16_t attribute);
-
-
-/**
- free the group
-
- @param[in] group instance group handler
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- */
-
-net_nfc_error_e net_nfc_free_carrier_group (net_nfc_property_group_h group);
-
-/**
- Create record handler with config.
-
- @param[out] record record handler
- @param[in] config the wifi configure handle
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- @exception NET_NFC_ALLOC_FAIL allocation is failed
- */
-
-net_nfc_error_e net_nfc_create_ndef_record_with_carrier_config (ndef_record_h * record, net_nfc_carrier_config_h config);
-
-
-/**
- create configure from the ndef record. the. the record must contained the configuration.
- config should be freed after using
-
- @param[in] record record handler
- @param[out] config the configure handle
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- @exception NET_NFC_ALLOC_FAIL allocation is failed
- @exception NET_NFC_INVALID_FORMAT if the record does not contained the valid format.
- */
-
-net_nfc_error_e net_nfc_create_carrier_config_from_config_record (net_nfc_carrier_config_h* config, ndef_record_h record);
-
-/**
- append record into the connection handover request for reponse message;
-
- @param[in] message ndef message handler
- @param[in] record record handler
- @param[in] power_status the power status of the current configuration
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- @exception NET_NFC_ALLOC_FAIL allocation is failed
- @exception NET_NFC_INVALID_FORMAT if the record does not contained the valid format.
- @exception NET_NFC_NO_DATA_FOUND the attribute does not exist in the group
- */
-net_nfc_error_e net_nfc_append_carrier_config_record (ndef_message_h message, ndef_record_h record, net_nfc_conn_handover_carrier_state_e power_status);
-
-/**
- append record into the connection handover request for reponse message;
-
- @param[in] message ndef message handler
- @param[in] record record handler
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- @exception NET_NFC_ALLOC_FAIL allocation is failed
- @exception NET_NFC_INVALID_FORMAT if the record does not contained the valid format.
- @exception NET_NFC_NO_DATA_FOUND Given record does not exist in the ndef message
- */
-
-net_nfc_error_e net_nfc_remove_carrier_config_record (ndef_message_h message, ndef_record_h record);
-
-/**
- get configure record from ndef message by index
-
- @param[in] message ndef message handler
- @param[in] index
- @param[out] record record handler
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- @exception NET_NFC_ALLOC_FAIL allocation is failed
- @exception NET_NFC_INVALID_FORMAT if the record does not contained the valid format.
- */
-
-net_nfc_error_e net_nfc_get_carrier_config_record (ndef_message_h message, int index, ndef_record_h * record);
-
-/**
- get randome number from the connection request message
-
- @param[in] message ndef message handler
- @param[out] randome_number randome number
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- @exception NET_NFC_INVALID_FORMAT if the record does not contained the valid format.
- */
-
-net_nfc_error_e net_nfc_get_handover_random_number(ndef_message_h message, unsigned short* random_number);
-
-/**
- get the count of the alternative (configuration) in the message
-
- @param[in] message ndef message handler
- @param[out] count number configuration in the message
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- @exception NET_NFC_INVALID_FORMAT if the record does not contained the valid format.
- */
-net_nfc_error_e net_nfc_get_alternative_carrier_record_count (ndef_message_h message, unsigned int * count);
-
-
-/**
- get power status of the given configruation
-
- @param[in] message ndef message handler
- @param[in] index index
- @param[out] power_state power state of the alternative
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- @exception NET_NFC_INVALID_FORMAT if the record does not contained the valid format.
- @exception NET_NFC_NO_DATA_FOUND there is no alternative record is found
- @exception NET_NFC_OUT_OF_BOUND index number is out of message count
- */
-
-net_nfc_error_e net_nfc_get_alternative_carrier_power_status (ndef_message_h message, int index, net_nfc_conn_handover_carrier_state_e * power_state);
-
-/**
- set power status of the given configruation
-
- @param[in] message ndef message handler
- @param[in] index index
- @param[in] power_state power state of the alternative
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- @exception NET_NFC_INVALID_FORMAT if the record does not contained the valid format.
- @exception NET_NFC_NO_DATA_FOUND there is no alternative record is found
- @exception NET_NFC_OUT_OF_BOUND index number is out of message count
- */
-net_nfc_error_e net_nfc_set_alternative_carrier_power_status (ndef_message_h message, int index, net_nfc_conn_handover_carrier_state_e power_status);
-
-/**
- this function will get carrier type.
-
- @param[in] carrier_info connection handover carrier info handler
- @param[in] carrier_type record type. it can be a NET_NFC_CONN_HANDOVER_CARRIER_BT or NET_NFC_CONN_HANDOVER_CARRIER_WIFI or NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN.
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- */
-
-net_nfc_error_e net_nfc_get_alternative_carrier_type (ndef_message_h message, int index, net_nfc_conn_handover_carrier_type_e * power_state);
-
-
-/**
- craete the connection handover request message
-
- @param[in] message connection handover carrier info handler
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- @exception NET_NFC_ALLOC_FAIL allocation is failed
- */
-
-net_nfc_error_e net_nfc_create_handover_request_message (ndef_message_h * message);
-
-/**
- craete the connection handover select message
-
- @param[in] message connection handover carrier info handler
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- @exception NET_NFC_ALLOC_FAIL allocation is failed
- */
-
-net_nfc_error_e net_nfc_create_handover_select_message (ndef_message_h * message);
-
-/**
- craete the connection handover error record message
-
- @param[out] record connection handover carrier info handler
- @param[in] reason error codes (reason)
- @param[in] data extra data for each error codes
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- @exception NET_NFC_ALLOC_FAIL allocation is failed
- */
-net_nfc_error_e net_nfc_create_handover_error_record (ndef_record_h * record, uint8_t reason, uint32_t data);
-
-
-#ifdef __cplusplus
-}
-#endif
-
-
-#endif //__NET_NFC_NDEF_MESSAGE_HANDOVER_H__
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef __NET_NFC_NDEF_RECORD_H__
-#define __NET_NFC_NDEF_RECORD_H__
-
-#include "net_nfc_typedef.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-/**
-
- @addtogroup NET_NFC_MANAGER_RECORD
- @{
- This document is for the APIs reference document
-
- NFC Manager defines are defined in <nfc-typedef.h>
-
-*/
-
-
-/**
- This define gives you Message Begin from the flag byte
-
- @param[in] flag flag that comes from "net_nfc_get_record_flags" function
- @return the mb flag
-
- @exception NONE
- */
-uint8_t net_nfc_get_record_mb (uint8_t flag);
-/**
- This define gives you Message end from the flag byte
-
- @param[in] flag flag that comes from "net_nfc_get_record_flags" function
- @return the me flag
-
- @exception NONE
- */
-uint8_t net_nfc_get_record_me (uint8_t flag);
-/**
- This define gives you Chun Flag that indicate that either the first record chunk or a middle record chunk of a chunked payload
-
- @param[in] flag flag that comes from "net_nfc_get_record_flags" function
- @return the chunk flag
-
- @exception NONE
- */
-uint8_t net_nfc_get_record_cf (uint8_t flag);
-/**
- This define gives you ID length present flag
-
- @param[in] flag flag that comes from "net_nfc_get_record_flags" function
- @return the il (id length flag) flag
-
- @exception NONE
-
-*/
-uint8_t net_nfc_get_record_il (uint8_t flag);
-/**
- This define gives you short record flag. This flag indicates that the payload length filed is a single octet
-
- @param[in] flag flag that comes from "net_nfc_get_record_flags" function
- @return the short record flag
-
- @exception NONE
- */
-uint8_t net_nfc_get_record_sr (uint8_t flag);
-
-
-
-/**
- creat a record with given parameter value. this function automatically set the NDEF record flags
-
- @param[out] record Record handler
- @param[in] tnf record type (TNF value) empty, well known, mime type, URI, external, or unchanged
- @param[in] typeName specify type name ex) Sp, U, or Hr ...
- @param[in] id record id
- @param[in] payload payload of this record
-
- @return return the result of the calling the function
-
- @exception NET_NFC_OUT_OF_BOUND tnf value is out of range
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- @exception NET_NFC_ALLOC_FAIL memory allocation is failed
-
- @code
- char uri[] = " yahoo.com";
- ndef_record_s uriRecord;
-
- data_h payload;
-
- net_nfc_create_data (&payload, uri, strlen (uri));
- uri[0] = 0x01;
-
- if((result = net_nfc_create_record( &uriRecord, NET_NFC_RECORD_WELL_KNOWN_TYPE, "U" , NULL, payload, )) != NET_NFC_OK)
- {
- printf("U record is failed [%d]\n", result);
- }
- @endcode
- */
-net_nfc_error_e net_nfc_create_record(ndef_record_h* record, net_nfc_record_tnf_e tnf, data_h typeName, data_h id, data_h payload );
-
-
-/**
- this function helps to create text type payload
- please, refer the NDEF forum specification "Text Record Type Definition"
- it creates byte array payload can be used in text type record
-
- this function does not encode the text. The paramter "text" will be asuumed as that it is already encoded with encode type.
- this function just helps to create text records.
-
- @param[out] record Record handler
- @param[in] text encoded text (this should be text not binary)
- @param[in] language_code_str language_code_str ex) en-US
- @param[in] encode text concoding type such as "utf8"
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- @exception NET_NFC_ALLOC_FAIL memory allocation is failed
-
-
- @code
- net_nfc_error_e result = NET_NFC_OK;
- ndef_message_h msg = NULL;
- ndef_record_h record = NULL;
-
- char* message = "Hello, NFC World";
-
- net_nfc_create_ndef_message (&msg);
- net_nfc_create_text_type_record (&record , message, "en-US", NET_NFC_ENCODE_UTF_8);
- net_nfc_append_record_to_ndef_message (msg ,record);
-
- @endcode
-
-*/
-net_nfc_error_e net_nfc_create_text_type_record(ndef_record_h* record, const char* text, const char* language_code_str, net_nfc_encode_type_e encode);
-
-/**
- this function helps to create URI type payload
- please refer the NFC forum specification "URI Record type Definition"
- it creates byte array payload.
-
- @param[out] record Record handler
- @param[in] uri string uri that will be stored in the payload
- @param[in] protocol_schema protocol schema that is specified in NFC Forum
-
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- @exception NET_NFC_ALLOC_FAIL memory allocation is failed
-
- @code
- net_nfc_error_e result = NET_NFC_OK;
- ndef_message_h msg = NULL;
- ndef_record_h record = NULL;
-
- net_nfc_create_ndef_message (&msg);
- net_nfc_create_uri_type_record (&record ,"http://www.samsung.com" ,NET_NFC_SCHEMA_FULL_URI);
- net_nfc_append_record_to_ndef_message (msg ,record);
- @endcode
- */
-
-net_nfc_error_e net_nfc_create_uri_type_record(ndef_record_h* record, const char * uri, net_nfc_schema_type_e protocol_schema);
-
-/**
- this function is getter of record payload.
- this function gives you the pointer of pyaload that is contained by record.
- Do not free the payload. it will be freed when the record is freed
-
- @param[in] record Record handler
- @param[out] payload data_h type payload pointer (it gives you the pointer of payload; not copied)
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
-
-*/
-net_nfc_error_e net_nfc_get_record_payload (ndef_record_h record, data_h * payload);
-
-/**
- this function is getter of record type.
- this function gives you the pointer of record type that is contained by record.
- Do not free the type. it will be freed when the record is freed
-
- @param[in] record Record handler
- @param[out] type dat_h type pointer (it gives you the pointer of type; not copied)
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
-
-*/
-net_nfc_error_e net_nfc_get_record_type (ndef_record_h record, data_h * type);
-
-/**
- this function is getter of record ID.
- this function gives you the pointer of ID that is contained by record.
- it may return NULL pointer if the ID is not exist
- Do not free the type. it will be freed when the record is freed.
-
- @param[in] record Record handler
- @param[out] id dat_h type ID pointer (it gives you the pointer of payload not copied)
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- */
-net_nfc_error_e net_nfc_get_record_id (ndef_record_h record, data_h * id);
-
-/**
- this function is getter of record TNF value.
-
- @param[in] record Record handler
- @param[out] tnf TNF value
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
-
-
-*/
-net_nfc_error_e net_nfc_get_record_tnf(ndef_record_h record, net_nfc_record_tnf_e * tnf);
-
-/**
- this function is getter of record flags.
- you can get the each flag value by using defines "RECORD_GET_XX"
-
- @param[in] record Record handler
- @param[out] flag flag value (it gives you the pointer of payload not copied)
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
-
- @code
-
- ndef_record_h record;
- uint8_t flag;
-
- net_nfc_get_record_by_index (msg, 0, &record);
- if (record != NULL){
- net_nfc_get_record_flags (record, &flag);
- printf ("MB:%d, ME:%d, CF:%d, IL:%d, SR:%d\n",
- net_nfc_get_record_mb(flag),
- net_nfc_get_record_me(flag),
- net_nfc_get_record_cf(flag),
- net_nfc_get_record_il(flag),
- net_nfc_get_record_sr(flag));
- }
-
- @endcode
-
-*/
-net_nfc_error_e net_nfc_get_record_flags (ndef_record_h record, uint8_t * flag);
-
-
-/**
- you can set record ID with this function
-
- @param[in] record Record handler
- @param[in] id Record ID
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
-
-*/
-net_nfc_error_e net_nfc_set_record_id (ndef_record_h record, data_h id);
-
-/**
- this function free the record handler. do not use this function after appending the ndef message
-
- @param[in] record Record handler
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
-
-*/
-net_nfc_error_e net_nfc_free_record (ndef_record_h record);
-
-
-/**
- this function get text from text record. it allocate buffer char and store the text string. you should free this string.
-
- @param[in] record Record handler
- @param[out] buffer text string
-
- @return return the result of the calling the function
-
- @exception NET_NFC_ALLOC_FAIL memory allocation is failed
- @exception NET_NFC_NDEF_RECORD_IS_NOT_EXPECTED_TYPE record is not text record
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
-
-*/
-
-net_nfc_error_e net_nfc_create_text_string_from_text_record(ndef_record_h record, char** buffer);
-
-/**
- this function get language code from text record. (ex: US-en)
-
- @param[in] record Record handler
- @param[out] lang_code_str lang code string value followed by IANA
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NDEF_RECORD_IS_NOT_EXPECTED_TYPE record is not text record
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
-
-*/
-
-net_nfc_error_e net_nfc_get_languange_code_string_from_text_record (ndef_record_h record, char** lang_code_str);
-
-
-/**
- this function get encoding type from text record (ex: UTF-8)
-
- @param[in] record Record handler
- @param[out] encoding encoding type
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NDEF_RECORD_IS_NOT_EXPECTED_TYPE record is not text record
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
-
-*/
-
-net_nfc_error_e net_nfc_get_encoding_type_from_text_record(ndef_record_h record, net_nfc_encode_type_e * encoding);
-
-
-/**
- this function get URI from uri record. you should free the uri string.
-
- @param[in] record Record handler
- @param[out] uri uri text string
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NDEF_RECORD_IS_NOT_EXPECTED_TYPE record is not uri record
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
-
-*/
-
-net_nfc_error_e net_nfc_create_uri_string_from_uri_record(ndef_record_h record, char ** uri);
-
-#ifdef __cplusplus
-}
-#endif
-
-
-#endif //__NET_NFC_NDEF_RECORD_H__
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef __NET_NFC_SIGN_RECORD_H__
-#define __NET_NFC_SIGN_RECORD_H__
-
-#include "net_nfc_typedef.h"
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
-
-/**
-
- @addtogroup NET_NFC_MANAGER_RECORD
- @{
- This document is for the APIs reference document
-
- NFC Manager defines are defined in <nfc-typedef.h>
-
-*/
-
-/**
- this function make the signature of some continuous records
- please refer the NFC forum specification "Signature Record type Definition"
-
- @param[in/out] msg NDEF message handler. After executing this function, a signature record will be added.
- @param[in] begin_index the index of beginning record that will be signed.
- @param[in] end_index the last index of record that will be signed.
- @param[in] cert_file PKCS #12 type certificate file (.p12). And the file should be encoded in DER type. (NOT PEM type)
- @param[in] passowrd the password of cert_file
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illegal NULL pointer(s)
- @exception NET_NFC_ALLOC_FAIL memory allocation is failed
-
- @code
- ndef_message_h msg = NULL;
-
- // create a ndef message and add some records
- // ...
-
- net_nfc_sign_records(msg, 0, 1, "/tmp/cert.p12", "abcdef");
- @endcode
-*/
-net_nfc_error_e net_nfc_sign_records(ndef_message_h msg, int begin_index, int end_index, char *cert_file, char *password);
-
-/**
- this function make the signature of whole records in NDEF message
-
- @param[in/out] msg NDEF message handler. After executing this function, a signature record will be added.
- @param[in] cert_file PKCS #12 type certificate file (.p12). And the file should be encoded in DER type. (NOT PEM type)
- @param[in] passowrd the password of cert_file
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illegal NULL pointer(s)
- @exception NET_NFC_ALLOC_FAIL memory allocation is failed
-
- @code
- ndef_message_h msg = NULL;
-
- // create a ndef message and add some records
- // ...
-
- net_nfc_sign_ndef_message(msg, "/tmp/cert.p12", "abcdef");
- @endcode
-*/
-net_nfc_error_e net_nfc_sign_ndef_message(ndef_message_h msg, char *cert_file, char *password);
-
-/**
- This function does verify signature of records
- record MUST be continuous.
-
- @param[in] begin_record the handle of beginning record that will be verified
- @param[in] sign_record the handle of signature record
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illegal NULL pointer(s)
- @exception NET_NFC_ALLOC_FAIL memory allocation is failed
-
- @code
- net_nfc_error_e error = NET_NFC_OK;
- ndef_message_h msg = NULL;
- ndef_record_h begin_record = NULL;
- ndef_record_h sign_record = NULL;
-
- // import NDEF message including the signature record.
- // ...
-
- net_nfc_get_record_by_index(msg, 0, &begin_record);
- net_nfc_get_record_by_index(msg, 2, &sign_record);
-
- error = net_nfc_verify_signature_records(begin_record, sign_record);
-
- return (error == NET_NFC_OK);
- @endcode
-*/
-net_nfc_error_e net_nfc_verify_signature_records(ndef_record_h begin_record, ndef_record_h sign_record);
-
-/**
- This function does verify signature in NDEF message
- If message has 2 or more signature record, it should do verify every signatures and return result.
- (Despite of failing only one signature record, this function will return error.)
-
- @param[in] msg NDEF message that will be verified.
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illegal NULL pointer(s)
- @exception NET_NFC_ALLOC_FAIL memory allocation is failed
-
- @code
- net_nfc_error_e error = NET_NFC_OK;
- ndef_message_h msg = NULL;
-
- // import NDEF message including the signature record.
- // ...
-
- error = net_nfc_verify_signature_ndef_message(msg);
-
- return (error == NET_NFC_OK);
- @endcode
-*/
-net_nfc_error_e net_nfc_verify_signature_ndef_message(ndef_message_h msg);
-
-#ifdef __cplusplus
-}
-#endif
-
-
-#endif //__NET_NFC_SIGN_RECORD_H__
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef __NET_NFC_TAG_MIFARE_H__
-#define __NET_NFC_TAG_MIFARE_H__
-
-#include "net_nfc_typedef.h"
-
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**
-
- @addtogroup NET_NFC_MANAGER_TAG
- @{
- Authenticate a sector with key A. I/O operation. e.g. read / write /
- increment / decrement will be available after successful authentication.
- This API is only available for MIFARE classic
-
- MIFARE CLASSIC MINI
- => 0 ~ 4 : 5 sector and 4 block with 16 bytes
-
- MIFARE CLASSIC 1K
- => 0 ~ 15 : 16 sector and 4 block with 16 bytes
-
- MIFARE CLASSIC 4K
- => 0 ~ 31 : 32 sector and 4 block with 16 bytes
- => 32 ~ 39 : 8 sector and 16 block with 16 bytes
-
- \par Sync (or) Async: Sync
- This is a Asynchronous API
-
- @param[in] handle target handle of detected tag
- @param[in] sector sector to authenticate with key A
- @param[in] auth_key 6 byte key to authenticate the sector
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter has illigal NULL pointer
- @exception NET_NFC_ALLOC_FAIL memory allocation is failed
- @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization
- @exception NET_NFC_BUSY Device is too busy to handle your request
- @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error
- @exception NET_NFC_RF_TIMEOUT Timeout raised while communicate with tag
- @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command
- @exception NET_NFC_INVALID_HANDLE target handle is not valid
- @exception NET_NFC_NO_DATA_FOUND mendantory tag info (UID, etc) is not founded
-
-*/
-
-net_nfc_error_e net_nfc_client_mifare_authenticate_with_keyA(
- net_nfc_target_handle_h handle,
- uint8_t sector,
- data_h auth_key,
- void *callback,
- void *user_data);
-
-/**
- Authenticate a sector with key B. I/O operation. e.g. read / write /
- increment / decrement will be available after successful authentication.
- This API is only available for MIFARE classic
-
- MIFARE CLASSIC MINI
- => 0 ~ 4 : 5 sector and 4 block with 16 bytes
-
- MIFARE CLASSIC 1K
- => 0 ~ 15 : 16 sector and 4 block with 16 bytes
-
- MIFARE CLASSIC 4K
- => 0 ~ 31 : 32 sector and 4 block with 16 bytes
- => 32 ~ 39 : 8 sector and 16 block with 16 bytes
-
- \par Sync (or) Async: Sync
- This is a Asynchronous API
-
- @param[in] handle target handle of detected tag
- @param[in] sector sector to authenticate with key B
- @param[in] auth_key 6 byte key to authenticate the sector
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter has illigal NULL pointer
- @exception NET_NFC_ALLOC_FAIL memory allocation is failed
- @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization
- @exception NET_NFC_BUSY Device is too busy to handle your request
- @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error
- @exception NET_NFC_RF_TIMEOUT Timeout raised while communicate with tag
- @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command
- @exception NET_NFC_INVALID_HANDLE target handle is not valid
- @exception NET_NFC_NO_DATA_FOUND mendantory tag info (UID, etc) is not founded
-
-*/
-
-
-net_nfc_error_e net_nfc_client_mifare_authenticate_with_keyB(
- net_nfc_target_handle_h handle,
- uint8_t sector,
- data_h auth_key,
- void *callback,
- void *user_data);
-
-/**
- read block or read page. If detected card is MIFARE classic, then It will
- read a block (16 byte). If detected card is Ultra light, then It will read
- 4 page (16 block)
-
- \par Sync (or) Async: Sync
- This is a Asynchronous API
-
- @param[in] handle target handle of detected tag
- @param[in] addr block or starting page number
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter has illigal NULL pointer
- @exception NET_NFC_ALLOC_FAIL memory allocation is failed
- @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization
- @exception NET_NFC_BUSY Device is too busy to handle your request
- @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error
- @exception NET_NFC_RF_TIMEOUT Timeout raised while communicate with tag
- @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command
- @exception NET_NFC_INVALID_HANDLE target handle is not valid
- @exception NET_NFC_TAG_READ_FAILED received chunked data is not valied (damaged data is recieved) or error ack is recieved
-*/
-
-net_nfc_error_e net_nfc_client_mifare_read(net_nfc_target_handle_h handle,
- uint8_t addr,
- void *callback,
- void *user_data);
-
-/**
- write block (16 byte) to addr. Only 4 bytes will be written when tag is
- ultra light
-
- \par Sync (or) Async: Sync
- This is a Asynchronous API
-
- @param[in] handle target handle of detected tag
- @param[in] addr block or starting page number
- @param[in] data data to write
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter has illigal NULL pointer
- @exception NET_NFC_ALLOC_FAIL memory allocation is failed
- @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization
- @exception NET_NFC_BUSY Device is too busy to handle your request
- @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error
- @exception NET_NFC_RF_TIMEOUT Timeout raised while communicate with tag
- @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command
- @exception NET_NFC_INVALID_HANDLE target handle is not valid
- @exception NET_NFC_TAG_WRITE_FAILED read only tag, or error ack is received from tag
-
-*/
-
-
-net_nfc_error_e net_nfc_client_mifare_write_block(
- net_nfc_target_handle_h handle,
- uint8_t addr,
- data_h data,
- void *callback,
- void *user_data);
-
-/**
- write page (4 byte) to addr. Only 4 bytes will be written when tag is
- MIFARE classic
-
- \par Sync (or) Async: Sync
- This is a Asynchronous API
-
- @param[in] handle target handle of detected tag
- @param[in] addr block or starting page number
- @param[in] data data to write
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter has illigal NULL pointer
- @exception NET_NFC_ALLOC_FAIL memory allocation is failed
- @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization
- @exception NET_NFC_BUSY Device is too busy to handle your request
- @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error
- @exception NET_NFC_RF_TIMEOUT Timeout raised while communicate with tag
- @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command
- @exception NET_NFC_INVALID_HANDLE target handle is not valid
- @exception NET_NFC_TAG_WRITE_FAILED read only tag, or error ack is received from tag
-
-*/
-
-net_nfc_error_e net_nfc_client_mifare_write_page(
- net_nfc_target_handle_h handle,
- uint8_t addr,
- data_h data,
- void *callback,
- void *user_data);
-
-
-/**
- Increase a value block, storing the result in the temporary block on the
- tag
- This API is only available for MIFARE classic
-
- \par Sync (or) Async: Sync
- This is a Asynchronous API
-
- @param[in] handle target handle of detected tag
- @param[in] addr block
- @param[in] value index of block to increase, starting from 0
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter has illigal NULL pointer
- @exception NET_NFC_ALLOC_FAIL memory allocation is failed
- @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization
- @exception NET_NFC_BUSY Device is too busy to handle your request
- @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error
- @exception NET_NFC_RF_TIMEOUT Timeout raised while communicate with tag
- @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command
- @exception NET_NFC_INVALID_HANDLE target handle is not valid
- @exception NET_NFC_TAG_WRITE_FAILED read only tag, or error ack is received from tag
-
-*/
-
-net_nfc_error_e net_nfc_client_mifare_increment(net_nfc_target_handle_h handle,
- uint8_t addr,
- int value,
- void *callback,
- void *user_data);
-
-/**
- Decrease a value block, storing the result in the temporary block on the tag
- This API is only available for MIFARE classic
-
- \par Sync (or) Async: Sync
- This is a Asynchronous API
-
- @param[in] handle target handle of detected tag
- @param[in] addr block
- @param[in] value index of block to decrease, starting from 0
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter has illigal NULL pointer
- @exception NET_NFC_ALLOC_FAIL memory allocation is failed
- @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization
- @exception NET_NFC_BUSY Device is too busy to handle your request
- @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error
- @exception NET_NFC_RF_TIMEOUT Timeout raised while communicate with tag
- @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command
- @exception NET_NFC_INVALID_HANDLE target handle is not valid
- @exception NET_NFC_TAG_WRITE_FAILED read only tag, or error ack is received from tag
-
-*/
-
-net_nfc_error_e net_nfc_client_mifare_decrement(net_nfc_target_handle_h handle,
- uint8_t addr,
- int value,
- void *callback,
- void *user_data);
-
-/**
- Copy from the temporary block to a value block.
- This API is only available for MIFARE classic
-
- \par Sync (or) Async: Sync
- This is a Asynchronous API
-
- @param[in] handle target handle of detected tag
- @param[in] addr block
- @param[in] value index of block to decrease, starting from 0
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter has illigal NULL pointer
- @exception NET_NFC_ALLOC_FAIL memory allocation is failed
- @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization
- @exception NET_NFC_BUSY Device is too busy to handle your request
- @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error
- @exception NET_NFC_RF_TIMEOUT Timeout raised while communicate with tag
- @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command
- @exception NET_NFC_INVALID_HANDLE target handle is not valid
- @exception NET_NFC_TAG_WRITE_FAILED read only tag, or error ack is received from tag
-
-*/
-
-net_nfc_error_e net_nfc_client_mifare_transfer(net_nfc_target_handle_h handle,
- uint8_t addr,
- void *callback,
- void *user_data);
-
-/**
- Copy from a value block to the temporary block.
- This API is only available for MIFARE classic
-
- \par Sync (or) Async: Sync
- This is a Asynchronous API
-
- @param[in] handle target handle of detected tag
- @param[in] addr block
- @param[in] value index of block to decrease, starting from 0
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter has illigal NULL pointer
- @exception NET_NFC_ALLOC_FAIL memory allocation is failed
- @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization
- @exception NET_NFC_BUSY Device is too busy to handle your request
- @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error
- @exception NET_NFC_RF_TIMEOUT Timeout raised while communicate with tag
- @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command
- @exception NET_NFC_INVALID_HANDLE target handle is not valid
- @exception NET_NFC_TAG_WRITE_FAILED read only tag, or error ack is received from tag
-
-*/
-
-net_nfc_error_e net_nfc_client_mifare_restore(net_nfc_target_handle_h handle,
- uint8_t addr,
- void *callback,
- void *user_data);
-
-/**
- create default factory key. The key is 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
-
- \par Sync (or) Async: Sync
- This is a Asynchronous API
-
- @param[in] key the handle to create key
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- @exception NET_NFC_ALLOC_FAIL memory allocation is failed
-
-*/
-
-net_nfc_error_e net_nfc_client_mifare_create_default_key(data_h* key);
-
-/**
- create mifare application directory key. The key is 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5
-
- \par Sync (or) Async: Sync
- This is a Asynchronous API
-
- @param[in] key the handle to create key
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- @exception NET_NFC_ALLOC_FAIL memory allocation is failed
-
-*/
-
-net_nfc_error_e net_nfc_client_mifare_create_application_directory_key(
- data_h* key);
-
-/**
- create nfc forum key. The key is 0xD3, 0xF7, 0xD3, 0xF7, 0xD3, 0xF7
-
- \par Sync (or) Async: Sync
- This is a Asynchronous API
-
- @param[in] key the handle to create key
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- @exception NET_NFC_ALLOC_FAIL memory allocation is failed
-
-*/
-
-net_nfc_error_e net_nfc_client_mifare_create_net_nfc_forum_key(data_h* key);
-
-/**
-@}
-*/
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif //__NET_NFC_TAG_MIFARE_H__
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef __NET_NFC_TARGET_INFO_H__
-#define __NET_NFC_TARGET_INFO_H__
-
-#include "net_nfc_typedef.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**
-
- @addtogroup NET_NFC_MANAGER_INFO
- @{
- This document is for the APIs reference document
-
- NFC Manager defines are defined in <nfc-typedef.h>
-
- These APIs help to get infomation of detected target. these target info handler holds
- - type of target
- - target ID
- - ndef message supporting
- - max data size (if this tag is ndef message tag)
- - actual data size (if this tag is ndef message tag)
- */
-
-/**
- type getter from targte info handler
-
- \par Sync (or) Async: Sync
- This is a Synchronous API
-
- @param[in] target_info target info handler
- @param[out] type tag type these type is one of the enum "net_nfc_target_type_e" defined
-
- @return return the result of calling this functions
-
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
-
-*/
-
-net_nfc_error_e net_nfc_get_tag_type (net_nfc_target_info_h target_info, net_nfc_target_type_e * type);
-
-/**
- type getter from targte info handler
-
- \par Sync (or) Async: Sync
- This is a Synchronous API
-
- @param[in] target_info target info handler
- @param[out] handle target handle that is generated by nfc-manager
-
- @return return the result of calling this functions
-
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
-
-*/
-
-net_nfc_error_e net_nfc_get_tag_handle(net_nfc_target_info_h target_info, net_nfc_target_handle_h * handle);
-
-/**
- this API returns the NDEF support boolean value.
- The TRUE value will be returned if the detected target is support NDEF, or return FALSE
-
- \par Sync (or) Async: Sync
- This is a Synchronous API
-
- @param[in] target_info target info handler
- @param[out] is_support boolean value of NDEF supporting
-
- @return return the result of calling this functions
-
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
-
-*/
-
-net_nfc_error_e net_nfc_get_tag_ndef_support (net_nfc_target_info_h target_info, bool * is_support);
-
-/**
- The max size getter from targte info handler. This max size indicates the maximum size of NDEF message that can be stored in this detected tag.
-
- \par Sync (or) Async: Sync
- This is a Synchronous API
-
- @param[in] target_info target info handler
- @param[out] max_size max size of NDEF message that can be stored in this detected tag.
-
- @return return the result of calling this functions
-
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
-
-*/
-
-net_nfc_error_e net_nfc_get_tag_max_data_size (net_nfc_target_info_h target_info, uint32_t * max_size);
-
-/**
- this function return the actual NDEF message size that stored in the tag
-
- \par Sync (or) Async: Sync
- This is a Synchronous API
-
- @param[in] target_info target info handler
- @param[out] actual_data the actual NDEF message size that stored in the tag
-
- @return return the result of calling this functions
-
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
-
-*/
-
-net_nfc_error_e net_nfc_get_tag_actual_data_size (net_nfc_target_info_h target_info, uint32_t * actual_data);
-
-
-/**
- this function return keys which will be used to get a tag information
-
- \par Sync (or) Async: Sync
- This is a Synchronous API. keys will be freed by user.
-
- @param[in] target_info target info handler
- @param[out] keys pointer of double array. it will be array of string.
- @param[out] number_of_keys length of array.
-
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- @exception NET_NFC_ALLOC_FAIL memory allocation is failed
- @exception NET_NFC_NO_DATA_FOUND No data is returned
-
- @code
- void user_cb(net_nfc_message_e message, net_nfc_error_e result, void* data, void* trans_param)
- {
-
- switch(message)
- {
- case NET_NFC_MESSAGE_TAG_DISCOVERED:
- {
- if(info != NULL)
- {
- net_nfc_target_info_h target_info = (net_nfc_target_info_h)data;
-
- char **keys;
- int keys_length;
-
- if(net_nfc_get_tag_info_keys(target_info, &keys, &keys_length) == true)
- {
- int index = 0;
- for(; index < keys_length; index++)
- {
- char* key = keys[index];
- }
- }
-
- free(keys);
- }
- }
- }
- }
- @endcode
-
- @return return the result of calling this functions
-
-*/
-
-net_nfc_error_e net_nfc_get_tag_info_keys(net_nfc_target_info_h target_info, char ***keys, int* number_of_keys);
-
-/**
- this function return value which is matched key
-
- \par Sync (or) Async: Sync
- This is a Synchronous API
-
- @param[in] target_info target info handler
- @param[in] key key to retrieve
- @param[out] value value which is matched with key
-
- @code
- void user_cb(net_nfc_message_e message, net_nfc_error_e result, void* data, void* trans_param)
- {
- switch(message)
- {
- case NET_NFC_MESSAGE_TAG_DISCOVERED:
- {
- if(info != NULL)
- {
- net_nfc_target_info_h target_info = (net_nfc_target_info_h)data;
-
- char** keys;
- int keys_length;
-
- if(net_nfc_get_tag_info_keys(target_info, &keys, &keys_length) == NET_NFC_OK)
- {
- int index = 0;
- for(; index < keys_length; index++)
- {
- char* key = keys[index];
- data_h value;
- net_nfc_get_tag_info_value(target_info, key, &value);
- net_nfc_free_data(value);
- }
- }
- }
- }
- }
- }
- @endcode
-
- @return return the result of calling this functions
-
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illegal NULL pointer(s)
- @exception NET_NFC_NO_DATA_FOUND No data is returned
- */
-
-net_nfc_error_e net_nfc_get_tag_info_value(net_nfc_target_info_h target_info, const char* key, data_h* value);
-
-/**
- Duplicate a handle of target information
-
- ** IMPORTANT : After using duplicated handle, you should release a handle returned from this function.
- ** You can release a handle by net_nfc_release_tag_info function.
-
- \par Sync (or) Async: Sync
- This is a Synchronous API
-
- @param[in] origin The original handle you want to duplicate
- @param[out] result The result of this function.
-
- @code
- void user_cb(net_nfc_message_e message, net_nfc_error_e result, void *data, void *trans_param)
- {
- switch(message)
- {
- case NET_NFC_MESSAGE_TAG_DISCOVERED:
- {
- net_nfc_target_info_h target_info = (net_nfc_target_info_h)data;
- net_nfc_target_info_h handle = NULL;
-
- net_nfc_duplicate_target_info(target_info, &handle);
-
- // do something...
-
- net_nfc_release_tag_info(handle);
- }
- break;
- }
- }
- @endcode
-
- @return return the result of calling this functions
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illegal NULL pointer(s)
-*/
-
-net_nfc_error_e net_nfc_duplicate_target_info(net_nfc_target_info_h origin, net_nfc_target_info_h *result);
-
-/**
- After using net_nfc_target_info_h handle, you should release its resource by this function.
-
- ** IMPORTANT : Never use this function in user callback you registered by net_nfc_set_response_callback function
- ** This function is for the result of net_nfc_duplicate_target_info or net_nfc_get_current_tag_info_sync
-
- \par Sync (or) Async: Sync
- This is a Synchronous API
-
- @param[in] target_info target info handle
-
- @code
- net_nfc_target_info_h handle;
-
- net_nfc_get_current_tag_info_sync(&handle);
-
- // do something...
-
- net_nfc_release_tag_info(handle);
- @endcode
-
- @return return the result of calling this functions
-
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illegal NULL pointer(s)
-*/
-
-net_nfc_error_e net_nfc_release_tag_info(net_nfc_target_info_h target_info);
-
-
-/**
-@}
-*/
-
-
-#ifdef __cplusplus
-}
-#endif
-
-
-#endif //__NET_NFC_TARGET_INFO_H__
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <glib.h>
-
-#ifdef SECURITY_SERVER
-#include "security-server.h"
-#endif
-
-#include "net_nfc_typedef.h"
-#include "net_nfc_util_gdbus_internal.h"
-#include "net_nfc_client_se.h"
-#include "net_nfc_client.h"
-#include "net_nfc_client_manager.h"
-#include "net_nfc_client_tag.h"
-#include "net_nfc_client_ndef.h"
-#include "net_nfc_client_transceive.h"
-#include "net_nfc_client_llcp.h"
-#include "net_nfc_client_snep.h"
-#include "net_nfc_client_p2p.h"
-#include "net_nfc_client_test.h"
-#include "net_nfc_client_system_handler.h"
-#include "net_nfc_client_handover.h"
-
-#ifndef NET_NFC_EXPORT_API
-#define NET_NFC_EXPORT_API __attribute__((visibility("default")))
-#endif
-
-#ifdef SECURITY_SERVER
-static uint8_t *cookie;
-static size_t cookie_len;
-
-static void _init_smack()
-{
- if (cookie == NULL) {
- cookie_len = security_server_get_cookie_size();
- if (cookie_len > 0) {
- cookie = g_new0(uint8_t, cookie_len);
- if (cookie != NULL) {
- if (security_server_request_cookie(
- (char *)cookie,
- cookie_len) < 0) {
- g_free(cookie);
- cookie = NULL;
- }
- }
- }
- }
-}
-
-static void _deinit_smack()
-{
- if (cookie != NULL) {
- g_free(cookie);
- cookie = NULL;
- }
-}
-#endif
-
-GVariant *net_nfc_client_gdbus_get_privilege()
-{
-#ifdef SECURITY_SERVER
- return net_nfc_util_gdbus_buffer_to_variant(cookie, cookie_len);
-#else
- return net_nfc_util_gdbus_buffer_to_variant(NULL, 0);
-#endif
-}
-
-void net_nfc_client_gdbus_init(void)
-{
-#ifdef SECURITY_SERVER
- _init_smack();
-#endif
- if (net_nfc_client_manager_init() != NET_NFC_OK)
- return;
- if (net_nfc_client_tag_init() != NET_NFC_OK)
- return;
- if (net_nfc_client_ndef_init() != NET_NFC_OK)
- return;
- if (net_nfc_client_transceive_init() != NET_NFC_OK)
- return;
- if (net_nfc_client_llcp_init() != NET_NFC_OK)
- return;
- if (net_nfc_client_snep_init() != NET_NFC_OK)
- return;
- if (net_nfc_client_p2p_init() != NET_NFC_OK)
- return;
- if (net_nfc_client_sys_handler_init() != NET_NFC_OK)
- return;
- if (net_nfc_client_se_init() != NET_NFC_OK)
- return;
- if (net_nfc_client_test_init() != NET_NFC_OK)
- return;
- if(net_nfc_client_handover_init() != NET_NFC_OK)
- return;
-}
-
-void net_nfc_client_gdbus_deinit(void)
-{
- net_nfc_client_handover_deinit();
- net_nfc_client_test_deinit();
- net_nfc_client_se_deinit();
- net_nfc_client_sys_handler_deinit();
- net_nfc_client_p2p_deinit();
- net_nfc_client_snep_deinit();
- net_nfc_client_llcp_deinit();
- net_nfc_client_transceive_deinit();
- net_nfc_client_ndef_deinit();
- net_nfc_client_tag_deinit();
- net_nfc_client_manager_deinit();
-#ifdef SECURITY_SERVER
- _deinit_smack();
-#endif
-}
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#include <vconf.h>
-
-#include "net_nfc_typedef.h"
-#include "net_nfc_client.h"
-
-#ifndef NET_NFC_EXPORT_API
-#define NET_NFC_EXPORT_API __attribute__((visibility("default")))
-#endif
-
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_initialize()
-{
- net_nfc_error_e result = NET_NFC_OK;
-
- net_nfc_client_gdbus_init();
-
- return result;
-}
-
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_deinitialize()
-{
- net_nfc_error_e result = NET_NFC_OK;
-
- net_nfc_client_gdbus_deinit();
-
- return result;
-}
-
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_is_nfc_supported(int *state)
-{
- net_nfc_error_e ret;
-
- if (state != NULL)
- {
- if (vconf_get_bool(VCONFKEY_NFC_FEATURE, state) == 0)
- {
- ret = NET_NFC_OK;
- }
- else
- {
- ret = NET_NFC_INVALID_STATE;
- }
- }
- else
- {
- ret = NET_NFC_NULL_PARAMETER;
- }
-
- return ret;
-}
-
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_get_nfc_state(int *state)
-{
- net_nfc_error_e ret;
-
- if (state != NULL)
- {
- if (vconf_get_bool(VCONFKEY_NFC_STATE, state) == 0)
- {
- ret = NET_NFC_OK;
- }
- else
- {
- ret = NET_NFC_INVALID_STATE;
- }
- }
- else
- {
- ret = NET_NFC_NULL_PARAMETER;
- }
-
- return ret;
-}
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <string.h>
-
-#include "net_nfc_data.h"
-#include "net_nfc_typedef_internal.h"
-#include "net_nfc_util_internal.h"
-
-#ifndef NET_NFC_EXPORT_API
-#define NET_NFC_EXPORT_API __attribute__((visibility("default")))
-#endif
-
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_create_data_only(data_h* data)
-{
- return net_nfc_create_data(data, NULL, 0);
-}
-
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_create_data(data_h* data, const uint8_t* bytes, const uint32_t length)
-{
- data_s *tmp_data = NULL;
-
- if (data == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
-
- _net_nfc_util_alloc_mem(tmp_data, sizeof(data_s));
- if (tmp_data == NULL)
- return NET_NFC_ALLOC_FAIL;
-
- if (length > 0)
- {
- _net_nfc_util_alloc_mem(tmp_data->buffer, length);
- if (tmp_data->buffer == NULL)
- {
- _net_nfc_util_free_mem(tmp_data);
- return NET_NFC_ALLOC_FAIL;
- }
-
- tmp_data->length = length;
-
- if (bytes != NULL)
- {
- memcpy(tmp_data->buffer, bytes, length);
- }
- }
-
- *data = (data_h)tmp_data;
-
- return NET_NFC_OK;
-}
-
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_data(const data_h data, uint8_t** bytes, uint32_t * length)
-{
- if (data == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
- data_s * tmp_data = (data_s *)data;
-
- *bytes = tmp_data->buffer;
- *length = tmp_data->length;
-
- return NET_NFC_OK;
-}
-
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_set_data(const data_h data, const uint8_t* bytes, const uint32_t length)
-{
- if (data == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
- data_s * tmp_data = (data_s *)data;
-
- if (tmp_data->buffer == bytes && tmp_data->length == length)
- {
- return NET_NFC_OK;
- }
-
- if (tmp_data->buffer != NULL)
- {
- _net_nfc_util_free_mem(tmp_data->buffer);
- }
-
- if (length <= 0)
- {
- tmp_data->buffer = NULL;
- tmp_data->length = 0;
- return NET_NFC_OK;
- }
-
- if (length > 0)
- {
- _net_nfc_util_alloc_mem((tmp_data)->buffer, length);
- }
-
- if (bytes != NULL)
- {
- memcpy(tmp_data->buffer, bytes, length);
- }
-
- tmp_data->length = length;
-
- return NET_NFC_OK;
-}
-
-NET_NFC_EXPORT_API uint32_t net_nfc_get_data_length(const data_h data)
-{
- if (data == NULL)
- {
- return 0;
- }
- data_s * tmp_data = (data_s *)data;
-
- return tmp_data->length;
-}
-
-NET_NFC_EXPORT_API uint8_t * net_nfc_get_data_buffer(const data_h data)
-{
- if (data == NULL)
- {
- return NULL;
- }
- data_s * tmp_data = (data_s *)data;
-
- return tmp_data->buffer;
-}
-
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_free_data(data_h data)
-{
- if (data == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
- data_s * tmp_data = (data_s *)data;
-
- if (tmp_data->buffer != NULL)
- {
- _net_nfc_util_free_mem(tmp_data->buffer);
- }
- _net_nfc_util_free_mem(tmp_data);
-
- return NET_NFC_OK;
-}
+++ /dev/null
-/*
-* Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-#include <pthread.h>
-
-#include "net_nfc_typedef_internal.h"
-#include "net_nfc_debug_internal.h"
-#include "net_nfc_util_internal.h"
-#include "net_nfc_data.h"
-#include "net_nfc_client_context.h"
-#include "net_nfc_client_p2p.h"
-#include "net_nfc_client_handover.h"
-#include "net_nfc_client_exchanger.h"
-
-static net_nfc_exchanger_cb gdbus_exch_cb = NULL;
-
-#ifndef NET_NFC_EXPORT_API
-#define NET_NFC_EXPORT_API __attribute__((visibility("default")))
-#endif
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_create_exchanger_data(
- net_nfc_exchanger_data_h *ex_data,
- data_h payload)
-{
- net_nfc_exchanger_data_s* tmp_ex_data = NULL;
-
- if (ex_data == NULL || payload == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
-
- _net_nfc_util_alloc_mem(
- tmp_ex_data,
- sizeof(net_nfc_exchanger_data_s));
-
- if (tmp_ex_data == NULL)
- {
- return NET_NFC_ALLOC_FAIL;
- }
-
- tmp_ex_data->type = NET_NFC_EXCHANGER_RAW;
-
- _net_nfc_util_alloc_mem(
- tmp_ex_data->binary_data.buffer,
- ((data_s *)payload)->length);
-
- if (tmp_ex_data->binary_data.buffer == NULL)
- {
- _net_nfc_util_free_mem(tmp_ex_data);
-
- return NET_NFC_ALLOC_FAIL;
- }
-
- memcpy(tmp_ex_data->binary_data.buffer,
- ((data_s *)payload)->buffer,
- ((data_s *)payload)->length);
-
- tmp_ex_data->binary_data.length = ((data_s *)payload)->length;
-
- *ex_data = (net_nfc_exchanger_data_h)tmp_ex_data;
-
- return NET_NFC_OK;
-}
-
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_free_exchanger_data(
- net_nfc_exchanger_data_h ex_data)
-{
- if (ex_data == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
-
- if (((net_nfc_exchanger_data_s *)ex_data)->binary_data.buffer != NULL)
- {
- _net_nfc_util_free_mem(
- ((net_nfc_exchanger_data_s *)ex_data)->binary_data.buffer);
- }
-
- _net_nfc_util_free_mem(ex_data);
-
- return NET_NFC_OK;
-}
-
-NET_NFC_EXPORT_API
-net_nfc_exchanger_cb net_nfc_client_get_exchanger_cb()
-{
- return gdbus_exch_cb;
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_unset_exchanger_cb()
-{
-
- if (gdbus_exch_cb == NULL)
- {
- return NET_NFC_NOT_REGISTERED;
- }
-
- gdbus_exch_cb = NULL;
-
- net_nfc_client_deinitialize();
-
- return NET_NFC_OK;
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_send_exchanger_data(
- net_nfc_exchanger_data_h ex_handle,
- net_nfc_target_handle_h target_handle,
- void* trans_param)
-{
- net_nfc_error_e ret;
- net_nfc_exchanger_data_s *ex_data = (net_nfc_exchanger_data_s *)ex_handle;
-
- DEBUG_CLIENT_MSG("send reqeust :: exchanger data = "
- "[%p] target_handle = [%p]", ex_handle, target_handle);
-
- /*Sync call is used because there is no callback provided*/
- ret = net_nfc_client_p2p_send_sync(ex_data,target_handle);
-
- return ret;
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_exchanger_request_connection_handover(
- net_nfc_target_handle_h target_handle,
- net_nfc_conn_handover_carrier_type_e type)
-{
- net_nfc_error_e ret = NET_NFC_UNKNOWN_ERROR;
- net_nfc_conn_handover_carrier_type_e carrier_type;
- data_h data = NULL;
-
- if (target_handle == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
-
- ret = net_nfc_client_p2p_connection_handover_sync(target_handle,
- type,
- &carrier_type,
- &data);
-
- return ret;
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_exchanger_get_alternative_carrier_type(
- net_nfc_connection_handover_info_h info_handle,
- net_nfc_conn_handover_carrier_type_e *type)
-{
- net_nfc_connection_handover_info_s *info = NULL;
-
- if (info_handle == NULL || type == NULL)
- return NET_NFC_NULL_PARAMETER;
-
- info = (net_nfc_connection_handover_info_s *)info_handle;
-
- *type = info->type;
-
- return NET_NFC_OK;
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_exchanger_get_alternative_carrier_data(
- net_nfc_connection_handover_info_h info_handle,
- data_h *data)
-{
- net_nfc_error_e result = NET_NFC_UNKNOWN_ERROR;
- net_nfc_connection_handover_info_s *info = NULL;
-
- if (info_handle == NULL || data == NULL)
- return NET_NFC_NULL_PARAMETER;
-
- info = (net_nfc_connection_handover_info_s *)info_handle;
-
- result = net_nfc_create_data(data, info->data.buffer, info->data.length);
-
- return result;
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_exchanger_free_alternative_carrier_data(
- net_nfc_connection_handover_info_h info_handle)
-{
- net_nfc_error_e result = NET_NFC_UNKNOWN_ERROR;
- net_nfc_connection_handover_info_s *info = NULL;
-
- if (info_handle == NULL)
- return NET_NFC_NULL_PARAMETER;
-
- info = (net_nfc_connection_handover_info_s *)info_handle;
-
- if (info->data.buffer != NULL)
- {
- _net_nfc_util_free_mem(info->data.buffer);
- }
-
- _net_nfc_util_free_mem(info);
-
- return result;
-}
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "net_nfc_typedef_internal.h"
-#include "net_nfc_debug_internal.h"
-#include "net_nfc_util_internal.h"
-#include "net_nfc_util_ndef_message.h"
-#include "net_nfc_util_gdbus_internal.h"
-#include "net_nfc_gdbus.h"
-#include "net_nfc_data.h"
-#include "net_nfc_client.h"
-#include "net_nfc_client_manager.h"
-#include "net_nfc_client_handover.h"
-
-#ifndef NET_NFC_EXPORT_API
-#define NET_NFC_EXPORT_API __attribute__((visibility("default")))
-#endif
-
-typedef struct _HandoverFuncData HandoverFuncData;
-
-struct _HandoverFuncData
-{
- gpointer handover_callback;
- gpointer handover_data;
-};
-
-static NetNfcGDbusHandover *handover_proxy = NULL;
-
-static void p2p_connection_handover(GObject *source_object,
- GAsyncResult *res,
- gpointer user_data);
-
-static void p2p_connection_handover(GObject *source_object,
- GAsyncResult *res,
- gpointer user_data)
-{
- HandoverFuncData *func_data;
- GVariant *data;
- GError *error = NULL;
- net_nfc_error_e result = NET_NFC_OK;
- net_nfc_exchanger_event_e event;
- net_nfc_conn_handover_carrier_type_e type;
- data_s arg_data;
-
- net_nfc_p2p_connection_handover_completed_cb callback;
-
- if(net_nfc_gdbus_handover_call_request_finish (handover_proxy,
- (gint32 *)&event,
- (gint32 *)&type,
- &data,
- res,
- &error) == FALSE)
- {
- result = NET_NFC_UNKNOWN_ERROR;
-
- DEBUG_ERR_MSG("Can not finish"
- " connection handover: %s", error->message);
- g_error_free(error);
- return;
- }
-
- func_data = user_data;
- if(func_data == NULL)
- {
- DEBUG_ERR_MSG("can not get HandoverFuncData");
- return;
- }
-
- if(func_data->handover_callback == NULL)
- {
- DEBUG_CLIENT_MSG("callback function is not avaiilable");
- g_free(func_data);
- return;
- }
-
- net_nfc_util_gdbus_variant_to_data_s(data, &arg_data);
-
- callback = (net_nfc_p2p_connection_handover_completed_cb)
- func_data->handover_callback;
-
- callback(result,
- type,
- &arg_data,
- func_data->handover_data);
-
- net_nfc_util_free_data(&arg_data);
-
- g_free(func_data);
-}
-
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_handover_free_alternative_carrier_data(
- net_nfc_connection_handover_info_h info_handle)
-{
- net_nfc_error_e result = NET_NFC_UNKNOWN_ERROR;
- net_nfc_connection_handover_info_s *info = NULL;
-
- if (info_handle == NULL)
- return NET_NFC_NULL_PARAMETER;
-
- info = (net_nfc_connection_handover_info_s *)info_handle;
-
- if (info->data.buffer != NULL)
- {
- _net_nfc_util_free_mem(info->data.buffer);
- }
-
- _net_nfc_util_free_mem(info);
-
- return result;
-}
-
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_handover_get_alternative_carrier_type(
- net_nfc_connection_handover_info_h info_handle,
- net_nfc_conn_handover_carrier_type_e *type)
-{
- net_nfc_connection_handover_info_s *info = NULL;
-
- if (info_handle == NULL || type == NULL)
- return NET_NFC_NULL_PARAMETER;
-
- info = (net_nfc_connection_handover_info_s *)info_handle;
-
- *type = info->type;
-
- return NET_NFC_OK;
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_handover_get_alternative_carrier_data(
- net_nfc_connection_handover_info_h info_handle,
- data_h *data)
-{
- net_nfc_error_e result = NET_NFC_UNKNOWN_ERROR;
- net_nfc_connection_handover_info_s *info = NULL;
-
- if (info_handle == NULL || data == NULL)
- return NET_NFC_NULL_PARAMETER;
-
- info = (net_nfc_connection_handover_info_s *)info_handle;
-
- result = net_nfc_create_data(data, info->data.buffer, info->data.length);
-
- return result;
-}
-
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_p2p_connection_handover(
- net_nfc_target_handle_h handle,
- net_nfc_conn_handover_carrier_type_e arg_type,
- net_nfc_p2p_connection_handover_completed_cb callback,
- void *cb_data)
-{
-
- HandoverFuncData *funcdata = NULL;
- net_nfc_target_handle_s *tag_handle = (net_nfc_target_handle_s *)handle;
-
- if(handover_proxy == NULL)
- {
- DEBUG_ERR_MSG("Can not get handover Proxy");
- return NET_NFC_UNKNOWN_ERROR;
- }
-
- /* prevent executing daemon when nfc is off */
- if (net_nfc_client_manager_is_activated() == false) {
- return NET_NFC_INVALID_STATE;
- }
-
- funcdata = g_new0(HandoverFuncData, 1);
- if (funcdata == NULL)
- return NET_NFC_UNKNOWN_ERROR;
-
- funcdata->handover_callback = (gpointer)callback;
- funcdata->handover_data = cb_data;
-
- net_nfc_gdbus_handover_call_request(handover_proxy,
- GPOINTER_TO_UINT(tag_handle),
- arg_type,
- net_nfc_client_gdbus_get_privilege(),
- NULL,
- p2p_connection_handover,
- funcdata);
-
- return NET_NFC_OK;
-}
-
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_p2p_connection_handover_sync(
- net_nfc_target_handle_h handle,
- net_nfc_conn_handover_carrier_type_e arg_type,
- net_nfc_conn_handover_carrier_type_e *out_carrier,
- data_h *out_ac_data)
-{
-
- net_nfc_target_handle_s *tag_handle = (net_nfc_target_handle_s *)handle;
- GError *error = NULL;
- GVariant *out_data;
- net_nfc_exchanger_event_e out_event;
- net_nfc_conn_handover_carrier_type_e out_type;
-
- if(handover_proxy == NULL)
- {
- DEBUG_ERR_MSG("Can not get handover Proxy");
- return NET_NFC_UNKNOWN_ERROR;
- }
-
- /* prevent executing daemon when nfc is off */
- if (net_nfc_client_manager_is_activated() == false) {
- return NET_NFC_INVALID_STATE;
- }
-
- if(net_nfc_gdbus_handover_call_request_sync(handover_proxy,
- GPOINTER_TO_UINT(tag_handle),
- arg_type,
- net_nfc_client_gdbus_get_privilege(),
- (gint32 *)&out_event,
- (gint32 *)&out_type,
- &out_data,
- NULL,
- &error) == FALSE)
- {
- DEBUG_ERR_MSG("handover (sync call) failed: %s",error->message);
- g_error_free(error);
- return NET_NFC_UNKNOWN_ERROR;
- }
-
- if (out_carrier)
- {
- *out_carrier = out_type;
- }
-
- if (out_ac_data)
- {
- *out_ac_data = net_nfc_util_gdbus_variant_to_data(out_data);
- }
-
- return NET_NFC_OK;
-}
-
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_handover_init(void)
-{
- GError *error = NULL;
-
- if (handover_proxy)
- {
- DEBUG_CLIENT_MSG("Already initialized");
- return NET_NFC_OK;
- }
-
- handover_proxy = net_nfc_gdbus_handover_proxy_new_for_bus_sync(
- G_BUS_TYPE_SYSTEM,
- G_DBUS_PROXY_FLAGS_NONE,
- "org.tizen.NetNfcService",
- "/org/tizen/NetNfcService/Handover",
- NULL,
- &error);
-
- if(handover_proxy == NULL)
- {
- DEBUG_ERR_MSG("Can not create proxy : %s", error->message);
- g_error_free(error);
- return NET_NFC_UNKNOWN_ERROR;
- }
-
- return NET_NFC_OK;
-}
-
-NET_NFC_EXPORT_API
-void net_nfc_client_handover_deinit(void)
-{
- if(handover_proxy)
- {
- g_object_unref(handover_proxy);
- handover_proxy = NULL;
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "net_nfc_typedef_internal.h"
-#include "net_nfc_debug_internal.h"
-#include "net_nfc_util_internal.h"
-#include "net_nfc_util_gdbus_internal.h"
-#include "net_nfc_gdbus.h"
-#include "net_nfc_client.h"
-#include "net_nfc_client_manager.h"
-#include "net_nfc_client_llcp.h"
-
-#ifndef NET_NFC_EXPORT_API
-#define NET_NFC_EXPORT_API __attribute__((visibility("default")))
-#endif
-
-typedef struct _LlcpFuncData LlcpFuncData;
-
-struct _LlcpFuncData
-{
- gpointer callback;
- gpointer user_data;
-};
-
-static NetNfcGDbusLlcp *llcp_proxy = NULL;
-static net_nfc_llcp_config_info_s llcp_config = { 128, 0, 0, 1 };
-static net_nfc_target_handle_s *llcp_handle = NULL;
-static GList *socket_data_list = NULL;
-static guint socket_handle = 0;
-
-
-void llcp_socket_data_append(net_nfc_llcp_internal_socket_s *socket_data);
-
-void llcp_socket_data_remove(net_nfc_llcp_internal_socket_s *socket_data);
-
-net_nfc_llcp_internal_socket_s *llcp_socket_data_find
- (net_nfc_llcp_socket_t socket);
-
-/* aysnc callback */
-static void llcp_call_config(GObject *source_object,
- GAsyncResult *res,
- gpointer user_data);
-
-static void llcp_call_listen(GObject *source_object,
- GAsyncResult *res,
- gpointer user_data);
-
-static void llcp_call_connect(GObject *source_object,
- GAsyncResult *res,
- gpointer user_data);
-
-static void llcp_call_connect_sap(GObject *source_object,
- GAsyncResult *res,
- gpointer user_data);
-
-static void llcp_call_send(GObject *source_object,
- GAsyncResult *res,
- gpointer user_data);
-
-static void llcp_call_send_to(GObject *source_object,
- GAsyncResult *res,
- gpointer user_data);
-
-static void llcp_call_receive(GObject *source_object,
- GAsyncResult *res,
- gpointer user_data);
-
-static void llcp_call_receive_from(GObject *source_object,
- GAsyncResult *res,
- gpointer user_data);
-
-static void llcp_call_close(GObject *source_object,
- GAsyncResult *res,
- gpointer user_data);
-
-static void llcp_call_disconnect(GObject *source_object,
- GAsyncResult *res,
- gpointer user_data);
-
-/* signal callback */
-static void llcp_error(NetNfcGDbusLlcp *object,
- guint arg_handle,
- guint client_socket,
- guint oal_socket,
- gint error,
- gpointer user_data);
-
-
-void llcp_socket_data_append(net_nfc_llcp_internal_socket_s *socket_data)
-{
- if (socket_data_list == NULL)
- return;
-
- if (socket_data)
- {
- socket_data_list = g_list_append(socket_data_list,
- socket_data);
- }
-}
-
-void llcp_socket_data_remove(net_nfc_llcp_internal_socket_s *socket_data)
-{
- if (socket_data_list == NULL)
- return;
-
- if (socket_data)
- {
- socket_data_list = g_list_remove(socket_data_list,
- socket_data);
-
- g_free(socket_data->service_name);
- g_free(socket_data);
- }
-}
-
-net_nfc_llcp_internal_socket_s *llcp_socket_data_find
- (net_nfc_llcp_socket_t socket)
-{
- GList *pos;
-
- if (socket_data_list == NULL)
- return NULL;
-
-
- for (pos = g_list_first(socket_data_list); pos ; pos = pos->data)
- {
- net_nfc_llcp_internal_socket_s *data;
-
- data = pos->data;
- if (data == NULL)
- continue;
-
- if (data->client_socket == socket)
- break;
- }
-
- if (pos == NULL)
- return NULL;
-
- return pos->data;
-}
-
-static void llcp_call_config(GObject *source_object,
- GAsyncResult *res,
- gpointer user_data)
-{
- LlcpFuncData *func_data;
-
- net_nfc_error_e result = NET_NFC_OK;
- GError *error = NULL;
-
- net_nfc_client_llcp_config_completed callback;
-
- if (net_nfc_gdbus_llcp_call_config_finish(
- NET_NFC_GDBUS_LLCP(source_object),
- res,
- &error) == FALSE)
- {
- result = NET_NFC_UNKNOWN_ERROR;
-
- DEBUG_ERR_MSG("Can not finish config: %s",
- error->message);
- g_error_free(error);
- }
-
- func_data = user_data;
- if (func_data == NULL)
- {
- DEBUG_ERR_MSG("can not get LlcpFuncData");
- return;
- }
-
- if (func_data->callback == NULL)
- {
- DEBUG_CLIENT_MSG("callback function is not available");
- g_free(func_data);
- return;
- }
-
- callback = (net_nfc_client_llcp_config_completed)func_data->callback;
- callback(result, func_data->user_data);
-}
-
-static void llcp_call_listen(GObject *source_object,
- GAsyncResult *res,
- gpointer user_data)
-{
- LlcpFuncData *func_data;
-
- net_nfc_error_e result = NET_NFC_OK;
- GError *error = NULL;
-
- guint32 out_client_socket;
- guint32 out_oal_socket;
-
- net_nfc_llcp_internal_socket_s *socket_data = NULL;
-
- net_nfc_client_llcp_listen_completed callback;
-
- if (net_nfc_gdbus_llcp_call_listen_finish(
- NET_NFC_GDBUS_LLCP(source_object),
- &out_client_socket,
- &out_oal_socket,
- res,
- &error) == FALSE)
- {
- result = NET_NFC_UNKNOWN_ERROR;
-
- DEBUG_ERR_MSG("Can not finish listen: %s",
- error->message);
- g_error_free(error);
- }
-
- socket_data = llcp_socket_data_find(out_client_socket);
- if (socket_data == NULL)
- {
- DEBUG_ERR_MSG("Wrong client socket is returned");
- return;
- }
-
- socket_data->oal_socket = out_oal_socket;
-
- func_data = user_data;
- if (func_data == NULL)
- {
- DEBUG_ERR_MSG("can not get LlcpFuncData");
- return;
- }
-
- if (func_data->callback == NULL)
- {
- DEBUG_CLIENT_MSG("callback function is not available");
- g_free(func_data);
- return;
- }
-
- callback = (net_nfc_client_llcp_listen_completed)func_data->callback;
- callback(result, out_client_socket, func_data->user_data);
-}
-
-static void llcp_call_connect(GObject *source_object,
- GAsyncResult *res,
- gpointer user_data)
-{
- LlcpFuncData *func_data;
-
- net_nfc_error_e result = NET_NFC_OK;
- GError *error = NULL;
-
- guint32 out_client_socket;
- guint32 out_oal_socket;
-
- net_nfc_llcp_internal_socket_s *socket_data = NULL;
-
- net_nfc_client_llcp_connect_completed callback;
-
- if (net_nfc_gdbus_llcp_call_connect_finish(
- NET_NFC_GDBUS_LLCP(source_object),
- &out_client_socket,
- &out_oal_socket,
- res,
- &error) == FALSE)
- {
- result = NET_NFC_UNKNOWN_ERROR;
-
- DEBUG_ERR_MSG("Can not finish connect: %s",
- error->message);
- g_error_free(error);
- }
-
- socket_data = llcp_socket_data_find(out_client_socket);
- if (socket_data == NULL)
- {
- DEBUG_ERR_MSG("Wrong client socket is returned");
- return;
- }
-
- socket_data->oal_socket = out_oal_socket;
-
- func_data = user_data;
- if (func_data == NULL)
- {
- DEBUG_ERR_MSG("can not get LlcpFuncData");
- return;
- }
-
- if (func_data->callback == NULL)
- {
- DEBUG_CLIENT_MSG("callback function is not available");
- g_free(func_data);
- return;
- }
-
- callback = (net_nfc_client_llcp_connect_completed)func_data->callback;
- callback(result, out_client_socket, func_data->user_data);
-}
-
-static void llcp_call_connect_sap(GObject *source_object,
- GAsyncResult *res,
- gpointer user_data)
-{
- LlcpFuncData *func_data;
-
- net_nfc_error_e result = NET_NFC_OK;
- GError *error = NULL;
-
- guint32 out_client_socket;
- guint32 out_oal_socket;
-
- net_nfc_llcp_internal_socket_s *socket_data = NULL;
-
- net_nfc_client_llcp_connect_sap_completed callback;
-
- if (net_nfc_gdbus_llcp_call_connect_sap_finish(
- NET_NFC_GDBUS_LLCP(source_object),
- &out_client_socket,
- &out_oal_socket,
- res,
- &error) == FALSE)
- {
- result = NET_NFC_UNKNOWN_ERROR;
-
- DEBUG_ERR_MSG("Can not finish connect sap: %s",
- error->message);
- g_error_free(error);
- }
-
- socket_data = llcp_socket_data_find(out_client_socket);
- if (socket_data == NULL)
- {
- DEBUG_ERR_MSG("Wrong client socket is returned");
- return;
- }
-
- socket_data->oal_socket = out_oal_socket;
-
- func_data = user_data;
- if (func_data == NULL)
- {
- DEBUG_ERR_MSG("can not get LlcpFuncData");
- return;
- }
-
- if (func_data->callback == NULL)
- {
- DEBUG_CLIENT_MSG("callback function is not available");
- g_free(func_data);
- return;
- }
-
- callback = (net_nfc_client_llcp_connect_sap_completed)
- func_data->callback;
- callback(result, out_client_socket, func_data->user_data);
-}
-
-
-static void llcp_call_send(GObject *source_object,
- GAsyncResult *res,
- gpointer user_data)
-{
- LlcpFuncData *func_data;
-
- guint32 out_client_socket;
-
- net_nfc_error_e result = NET_NFC_OK;
- GError *error = NULL;
-
- net_nfc_client_llcp_send_completed callback;
-
- if (net_nfc_gdbus_llcp_call_send_finish(
- NET_NFC_GDBUS_LLCP(source_object),
- &out_client_socket,
- res,
- &error) == FALSE)
- {
- result = NET_NFC_UNKNOWN_ERROR;
-
- DEBUG_ERR_MSG("Can not finish send: %s",
- error->message);
-
- g_error_free(error);
- }
-
- func_data = user_data;
- if (func_data == NULL)
- {
- DEBUG_ERR_MSG("can not get LlcpFuncData");
- return;
- }
-
- if (func_data->callback == NULL)
- {
- DEBUG_CLIENT_MSG("callback function is not available");
- g_free(func_data);
- return;
- }
-
- callback = (net_nfc_client_llcp_send_completed)func_data->callback;
- callback(result, out_client_socket, func_data->user_data);
-}
-
-static void llcp_call_send_to(GObject *source_object,
- GAsyncResult *res,
- gpointer user_data)
-{
- LlcpFuncData *func_data;
-
- guint32 out_client_socket;
-
- net_nfc_error_e result = NET_NFC_OK;
- GError *error = NULL;
-
- net_nfc_client_llcp_send_to_completed callback;
-
- if (net_nfc_gdbus_llcp_call_send_to_finish(
- NET_NFC_GDBUS_LLCP(source_object),
- &out_client_socket,
- res,
- &error) == FALSE)
- {
- result = NET_NFC_UNKNOWN_ERROR;
-
- DEBUG_ERR_MSG("Can not finish send to: %s",
- error->message);
-
- g_error_free(error);
- }
- func_data = user_data;
- if (func_data == NULL)
- {
- DEBUG_ERR_MSG("can not get LlcpFuncData");
- return;
- }
-
- if (func_data->callback == NULL)
- {
- DEBUG_CLIENT_MSG("callback function is not available");
- g_free(func_data);
- return;
- }
-
- callback = (net_nfc_client_llcp_send_to_completed)func_data->callback;
- callback(result, out_client_socket, func_data->user_data);
-}
-
-static void llcp_call_receive(GObject *source_object,
- GAsyncResult *res,
- gpointer user_data)
-{
- LlcpFuncData *func_data;
-
- GVariant *variant = NULL;
- data_s data;
-
- net_nfc_error_e result = NET_NFC_OK;
- GError *error = NULL;
-
- net_nfc_client_llcp_receive_completed callback;
-
- if (net_nfc_gdbus_llcp_call_receive_finish(
- NET_NFC_GDBUS_LLCP(source_object),
- &variant,
- res,
- &error) == FALSE)
- {
- result = NET_NFC_UNKNOWN_ERROR;
-
- DEBUG_ERR_MSG("Can not finish receive: %s",
- error->message);
-
- g_error_free(error);
- }
-
- func_data = user_data;
- if (func_data == NULL)
- {
- DEBUG_ERR_MSG("can not get LlcpFuncData");
- return;
- }
-
- if (func_data->callback == NULL)
- {
- DEBUG_CLIENT_MSG("callback function is not available");
- g_free(func_data);
- return;
- }
-
- net_nfc_util_gdbus_variant_to_data_s(variant, &data);
-
- callback = (net_nfc_client_llcp_receive_completed)func_data->callback;
- callback(result, &data, func_data->user_data);
-
- net_nfc_util_free_data(&data);
-
- g_free(func_data);
-}
-
-static void llcp_call_receive_from(GObject *source_object,
- GAsyncResult *res,
- gpointer user_data)
-{
- LlcpFuncData *func_data;
-
- GVariant *variant = NULL;
-
- sap_t sap;
- data_s data;
-
- net_nfc_error_e result = NET_NFC_OK;
- GError *error = NULL;
-
- net_nfc_client_llcp_receive_from_completed callback;
-
- if (net_nfc_gdbus_llcp_call_receive_from_finish(
- NET_NFC_GDBUS_LLCP(source_object),
- &sap,
- &variant,
- res,
- &error) == FALSE)
- {
- result = NET_NFC_UNKNOWN_ERROR;
-
- DEBUG_ERR_MSG("Can not finish receive from: %s",
- error->message);
-
- g_error_free(error);
- }
-
- func_data = user_data;
- if (func_data == NULL)
- {
- DEBUG_ERR_MSG("can not get LlcpFuncData");
- return;
- }
-
- if (func_data->callback == NULL)
- {
- DEBUG_CLIENT_MSG("callback function is not available");
- g_free(func_data);
- return;
- }
-
- net_nfc_util_gdbus_variant_to_data_s(variant, &data);
-
- callback = (net_nfc_client_llcp_receive_from_completed)
- func_data->callback;
- callback(result, sap, &data, func_data->user_data);
-
- net_nfc_util_free_data(&data);
-
- g_free(func_data);
-}
-
-static void llcp_call_close(GObject *source_object,
- GAsyncResult *res,
- gpointer user_data)
-{
- LlcpFuncData *func_data;
-
- net_nfc_error_e result = NET_NFC_OK;
- GError *error = NULL;
-
- guint32 out_client_socket;
-
- net_nfc_llcp_internal_socket_s *socket_data = NULL;
-
- net_nfc_client_llcp_close_completed callback;
-
- if (net_nfc_gdbus_llcp_call_close_finish(
- NET_NFC_GDBUS_LLCP(source_object),
- &out_client_socket,
- res,
- &error) == FALSE)
- {
- result = NET_NFC_UNKNOWN_ERROR;
-
- DEBUG_ERR_MSG("Can not finish close: %s",
- error->message);
- g_error_free(error);
- }
-
- socket_data = llcp_socket_data_find(out_client_socket);
- if (socket_data == NULL)
- {
- DEBUG_ERR_MSG("Wrong client socket is returned");
- return;
- }
-
- func_data = user_data;
- if (func_data == NULL)
- {
- DEBUG_ERR_MSG("can not get LlcpFuncData");
- return;
- }
-
- if (func_data->callback == NULL)
- {
- DEBUG_CLIENT_MSG("callback function is not available");
- g_free(func_data);
- return;
- }
-
- callback = (net_nfc_client_llcp_close_completed)func_data->callback;
- callback(result, out_client_socket, func_data->user_data);
-}
-
-static void llcp_call_disconnect(GObject *source_object,
- GAsyncResult *res,
- gpointer user_data)
-{
- LlcpFuncData *func_data;
-
- net_nfc_error_e result = NET_NFC_OK;
- GError *error = NULL;
-
- guint32 out_client_socket;
-
- net_nfc_llcp_internal_socket_s *socket_data = NULL;
-
- net_nfc_client_llcp_disconnect_completed callback;
-
- if (net_nfc_gdbus_llcp_call_disconnect_finish(
- NET_NFC_GDBUS_LLCP(source_object),
- &out_client_socket,
- res,
- &error) == FALSE)
- {
- result = NET_NFC_UNKNOWN_ERROR;
-
- DEBUG_ERR_MSG("Can not finish disconnect: %s",
- error->message);
- g_error_free(error);
- }
-
- socket_data = llcp_socket_data_find(out_client_socket);
- if (socket_data == NULL)
- {
- DEBUG_ERR_MSG("Wrong client socket is returned");
- return;
- }
-
- func_data = user_data;
- if (func_data == NULL)
- {
- DEBUG_ERR_MSG("can not get LlcpFuncData");
- return;
- }
-
- if (func_data->callback == NULL)
- {
- DEBUG_CLIENT_MSG("callback function is not available");
- g_free(func_data);
- return;
- }
-
- callback = (net_nfc_client_llcp_disconnect_completed)
- func_data->callback;
- callback(result, out_client_socket, func_data->user_data);
-}
-
-
-static void llcp_error(NetNfcGDbusLlcp *object,
- guint arg_handle,
- guint client_socket,
- guint oal_socket,
- gint error,
- gpointer user_data)
-{
- INFO_MSG(">>> SIGNAL arrived");
-}
-
-/* Public APIs */
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_llcp_config(net_nfc_llcp_config_info_h config,
- net_nfc_client_llcp_config_completed callback,
- void *user_data)
-{
- LlcpFuncData *func_data;
- GVariant *variant = NULL;
-
- if (llcp_proxy == NULL)
- {
- DEBUG_ERR_MSG("Can not get LlcpProxy");
- return NET_NFC_UNKNOWN_ERROR;
- }
-
- if (config == NULL)
- {
- DEBUG_ERR_MSG("Config is empty");
- return NET_NFC_UNKNOWN_ERROR;
- }
-
- /* prevent executing daemon when nfc is off */
- if (net_nfc_client_manager_is_activated() == false) {
- return NET_NFC_INVALID_STATE;
- }
-
- func_data = g_new0(LlcpFuncData, 1);
- func_data->callback = (gpointer)callback;
- func_data->user_data = user_data;
-
- memcpy(&llcp_config, config, sizeof(net_nfc_llcp_config_info_s));
-
- variant = g_variant_new("(qqyy)",
- config->miu,
- config->wks,
- config->lto,
- config->option);
-
- net_nfc_gdbus_llcp_call_config(llcp_proxy,
- variant,
- net_nfc_client_gdbus_get_privilege(),
- NULL,
- llcp_call_config,
- func_data);
-
- return NET_NFC_OK;
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_llcp_config_sync
- (net_nfc_llcp_config_info_h config)
-{
- GVariant *variant = NULL;
- GError *error = NULL;
-
- if (llcp_proxy == NULL)
- {
- DEBUG_ERR_MSG("Can not get LlcpProxy");
- return NET_NFC_UNKNOWN_ERROR;
- }
-
- /* prevent executing daemon when nfc is off */
- if (net_nfc_client_manager_is_activated() == false) {
- return NET_NFC_INVALID_STATE;
- }
-
- memcpy(&llcp_config, config, sizeof(net_nfc_llcp_config_info_s));
-
- variant = g_variant_new("(qqyy)",
- config->miu,
- config->wks,
- config->lto,
- config->option);
-
- if (net_nfc_gdbus_llcp_call_config_sync(llcp_proxy,
- variant,
- net_nfc_client_gdbus_get_privilege(),
- NULL,
- &error) == FALSE)
- {
- DEBUG_ERR_MSG("can not config: %s",
- error->message);
- g_error_free(error);
- return NET_NFC_UNKNOWN_ERROR;
- }
-
- return NET_NFC_OK;
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_llcp_get_config
- (net_nfc_llcp_config_info_h *config)
-{
- if (config == NULL)
- return NET_NFC_NULL_PARAMETER;
-
- *config = (net_nfc_llcp_config_info_h)&llcp_config;
-
- return NET_NFC_OK;
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_llcp_listen(net_nfc_llcp_socket_t socket,
- const char *service_name,
- sap_t sap,
- net_nfc_client_llcp_listen_completed callback,
- void *user_data)
-{
- LlcpFuncData *func_data;
- net_nfc_llcp_internal_socket_s *socket_data = NULL;
-
- if (llcp_proxy == NULL)
- {
- DEBUG_ERR_MSG("Can not get LlcpProxy");
- return NET_NFC_UNKNOWN_ERROR;
- }
-
- if (service_name == NULL)
- {
- DEBUG_ERR_MSG("service_name is empty");
- return NET_NFC_UNKNOWN_ERROR;
- }
-
- socket_data = llcp_socket_data_find(socket);
- if (socket_data == NULL)
- {
- DEBUG_ERR_MSG("can not get socket_data");
- return NET_NFC_LLCP_INVALID_SOCKET;
- }
-
- /* FIXME: temporary typecast to (uint8_t *) */
- socket_data->service_name = (uint8_t *)g_strdup(service_name);
- socket_data->sap = sap;
-
- /* prevent executing daemon when nfc is off */
- if (net_nfc_client_manager_is_activated() == false) {
- return NET_NFC_INVALID_STATE;
- }
-
- func_data = g_new0(LlcpFuncData, 1);
- func_data->callback = (gpointer)callback;
- func_data->user_data = user_data;
-
- net_nfc_gdbus_llcp_call_listen(llcp_proxy,
- GPOINTER_TO_UINT(llcp_handle),
- socket_data->client_socket,
- socket_data->oal_socket,
- socket_data->miu,
- socket_data->rw,
- socket_data->type,
- socket_data->sap,
- service_name,
- net_nfc_client_gdbus_get_privilege(),
- NULL,
- llcp_call_listen,
- func_data);
-
- return NET_NFC_OK;
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_llcp_listen_sync(net_nfc_llcp_socket_t socket,
- const char *service_name,
- sap_t sap,
- net_nfc_llcp_socket_t *out_socket)
-{
- GError *error = NULL;
- guint32 out_client_socket;
- guint32 out_oal_socket;
-
- net_nfc_llcp_internal_socket_s *socket_data = NULL;
- net_nfc_llcp_internal_socket_s *out_socket_data = NULL;
-
- if (llcp_proxy == NULL)
- {
- DEBUG_ERR_MSG("Can not get LlcpProxy");
- return NET_NFC_UNKNOWN_ERROR;
- }
-
- if (service_name == NULL)
- {
- DEBUG_ERR_MSG("service_name is empty");
- return NET_NFC_UNKNOWN_ERROR;
- }
-
- socket_data = llcp_socket_data_find(socket);
- if (socket_data == NULL)
- {
- DEBUG_ERR_MSG("can not get socket_data");
- return NET_NFC_LLCP_INVALID_SOCKET;
- }
-
- /* FIXME: temporary typecast to (uint8_t *) */
- socket_data->service_name = (uint8_t *)g_strdup(service_name);
- socket_data->sap = sap;
-
- /* prevent executing daemon when nfc is off */
- if (net_nfc_client_manager_is_activated() == false) {
- return NET_NFC_INVALID_STATE;
- }
-
- if (net_nfc_gdbus_llcp_call_listen_sync(llcp_proxy,
- GPOINTER_TO_UINT(llcp_handle),
- socket_data->client_socket,
- socket_data->oal_socket,
- socket_data->miu,
- socket_data->rw,
- socket_data->type,
- socket_data->sap,
- service_name,
- net_nfc_client_gdbus_get_privilege(),
- &out_client_socket,
- &out_oal_socket,
- NULL,
- &error) == FALSE)
- {
- DEBUG_ERR_MSG("can not listen: %s",
- error->message);
- g_error_free(error);
- return NET_NFC_UNKNOWN_ERROR;
- }
-
- out_socket_data = llcp_socket_data_find(out_client_socket);
- if (out_socket_data == NULL || out_socket_data != socket_data)
- {
- DEBUG_ERR_MSG("Wrong client socket is returned");
- return NET_NFC_UNKNOWN_ERROR;
- }
-
- out_socket_data->oal_socket = out_oal_socket;
-
- if (out_socket)
- *out_socket = out_client_socket;
-
- return NET_NFC_OK;
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_llcp_connect(net_nfc_llcp_socket_t socket,
- const char *service_name,
- net_nfc_client_llcp_connect_completed callback,
- void *user_data)
-{
- LlcpFuncData *func_data;
- net_nfc_llcp_internal_socket_s *socket_data = NULL;
-
- if (llcp_proxy == NULL)
- {
- DEBUG_ERR_MSG("Can not get LlcpProxy");
- return NET_NFC_UNKNOWN_ERROR;
- }
-
- if (service_name == NULL)
- {
- DEBUG_ERR_MSG("service_name is empty");
- return NET_NFC_UNKNOWN_ERROR;
- }
-
- socket_data = llcp_socket_data_find(socket);
- if (socket_data == NULL)
- {
- DEBUG_ERR_MSG("can not get socket_data");
- return NET_NFC_LLCP_INVALID_SOCKET;
- }
-
- /* prevent executing daemon when nfc is off */
- if (net_nfc_client_manager_is_activated() == false) {
- return NET_NFC_INVALID_STATE;
- }
-
- func_data = g_new0(LlcpFuncData, 1);
- func_data->callback = (gpointer)callback;
- func_data->user_data = user_data;
-
- net_nfc_gdbus_llcp_call_connect(llcp_proxy,
- GPOINTER_TO_UINT(llcp_handle),
- socket_data->client_socket,
- socket_data->oal_socket,
- socket_data->miu,
- socket_data->rw,
- socket_data->type,
- service_name,
- net_nfc_client_gdbus_get_privilege(),
- NULL,
- llcp_call_connect,
- func_data);
-
- return NET_NFC_OK;
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_llcp_connect_sync(net_nfc_llcp_socket_t socket,
- const char *service_name,
- net_nfc_llcp_socket_t *out_socket)
-{
- GError *error = NULL;
- guint32 out_client_socket;
- guint32 out_oal_socket;
-
- net_nfc_llcp_internal_socket_s *socket_data = NULL;
- net_nfc_llcp_internal_socket_s *out_socket_data = NULL;
-
- if (llcp_proxy == NULL)
- {
- DEBUG_ERR_MSG("Can not get LlcpProxy");
- return NET_NFC_UNKNOWN_ERROR;
- }
-
- if (service_name == NULL)
- {
- DEBUG_ERR_MSG("service_name is empty");
- return NET_NFC_UNKNOWN_ERROR;
- }
-
- socket_data = llcp_socket_data_find(socket);
- if (socket_data == NULL)
- {
- DEBUG_ERR_MSG("can not get socket_data");
- return NET_NFC_LLCP_INVALID_SOCKET;
- }
-
- /* prevent executing daemon when nfc is off */
- if (net_nfc_client_manager_is_activated() == false) {
- return NET_NFC_INVALID_STATE;
- }
-
- if (net_nfc_gdbus_llcp_call_connect_sync(llcp_proxy,
- GPOINTER_TO_UINT(llcp_handle),
- socket_data->client_socket,
- socket_data->oal_socket,
- socket_data->miu,
- socket_data->rw,
- socket_data->type,
- service_name,
- net_nfc_client_gdbus_get_privilege(),
- &out_client_socket,
- &out_oal_socket,
- NULL,
- &error) == FALSE)
- {
- DEBUG_ERR_MSG("can not connect: %s",
- error->message);
- g_error_free(error);
- return NET_NFC_UNKNOWN_ERROR;
- }
-
- out_socket_data = llcp_socket_data_find(out_client_socket);
- if (out_socket_data == NULL || out_socket_data != socket_data)
- {
- DEBUG_ERR_MSG("Wrong client socket is returned");
- return NET_NFC_UNKNOWN_ERROR;
- }
-
- out_socket_data->oal_socket = out_oal_socket;
-
- if (out_socket)
- *out_socket = out_client_socket;
-
- return NET_NFC_OK;
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_llcp_connect_sap(net_nfc_llcp_socket_t socket,
- sap_t sap,
- net_nfc_client_llcp_connect_sap_completed callback,
- void *user_data)
-{
- LlcpFuncData *func_data;
- net_nfc_llcp_internal_socket_s *socket_data = NULL;
-
- if (llcp_proxy == NULL)
- {
- DEBUG_ERR_MSG("Can not get LlcpProxy");
- return NET_NFC_UNKNOWN_ERROR;
- }
-
- socket_data = llcp_socket_data_find(socket);
- if (socket_data == NULL)
- {
- DEBUG_ERR_MSG("can not get socket_data");
- return NET_NFC_LLCP_INVALID_SOCKET;
- }
-
- /* prevent executing daemon when nfc is off */
- if (net_nfc_client_manager_is_activated() == false) {
- return NET_NFC_INVALID_STATE;
- }
-
- func_data = g_new0(LlcpFuncData, 1);
- func_data->callback = (gpointer)callback;
- func_data->user_data = user_data;
-
- net_nfc_gdbus_llcp_call_connect_sap(llcp_proxy,
- GPOINTER_TO_UINT(llcp_handle),
- socket_data->client_socket,
- socket_data->oal_socket,
- socket_data->miu,
- socket_data->rw,
- socket_data->type,
- sap,
- net_nfc_client_gdbus_get_privilege(),
- NULL,
- llcp_call_connect_sap,
- func_data);
-
- return NET_NFC_OK;
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_llcp_connect_sap_sync(
- net_nfc_llcp_socket_t socket,
- sap_t sap,
- net_nfc_llcp_socket_t *out_socket)
-{
- GError *error = NULL;
- guint32 out_client_socket;
- guint32 out_oal_socket;
-
- net_nfc_llcp_internal_socket_s *socket_data = NULL;
- net_nfc_llcp_internal_socket_s *out_socket_data = NULL;
-
- if (llcp_proxy == NULL)
- {
- DEBUG_ERR_MSG("Can not get LlcpProxy");
- return NET_NFC_UNKNOWN_ERROR;
- }
-
- socket_data = llcp_socket_data_find(socket);
- if (socket_data == NULL)
- {
- DEBUG_ERR_MSG("can not get socket_data");
- return NET_NFC_LLCP_INVALID_SOCKET;
- }
-
- /* prevent executing daemon when nfc is off */
- if (net_nfc_client_manager_is_activated() == false) {
- return NET_NFC_INVALID_STATE;
- }
-
- if (net_nfc_gdbus_llcp_call_connect_sap_sync(llcp_proxy,
- GPOINTER_TO_UINT(llcp_handle),
- socket_data->client_socket,
- socket_data->oal_socket,
- socket_data->miu,
- socket_data->rw,
- socket_data->type,
- sap,
- net_nfc_client_gdbus_get_privilege(),
- &out_client_socket,
- &out_oal_socket,
- NULL,
- &error) == FALSE)
- {
- DEBUG_ERR_MSG("can not connect: %s",
- error->message);
- g_error_free(error);
- return NET_NFC_UNKNOWN_ERROR;
- }
-
- out_socket_data = llcp_socket_data_find(out_client_socket);
- if (out_socket_data == NULL || out_socket_data != socket_data)
- {
- DEBUG_ERR_MSG("Wrong client socket is returned");
- return NET_NFC_UNKNOWN_ERROR;
- }
-
- out_socket_data->oal_socket = out_oal_socket;
-
- if (out_socket)
- *out_socket = out_client_socket;
-
- return NET_NFC_OK;
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_llcp_send(net_nfc_llcp_socket_t socket,
- data_h data,
- net_nfc_client_llcp_send_completed callback,
- void *user_data)
-{
- LlcpFuncData *func_data;
- GVariant *variant = NULL;
- net_nfc_llcp_internal_socket_s *socket_data = NULL;
-
- if (llcp_proxy == NULL)
- {
- DEBUG_ERR_MSG("Can not get LlcpProxy");
- return NET_NFC_UNKNOWN_ERROR;
- }
-
- /* prevent executing daemon when nfc is off */
- if (net_nfc_client_manager_is_activated() == false) {
- return NET_NFC_INVALID_STATE;
- }
-
- socket_data = llcp_socket_data_find(socket);
- if (socket_data == NULL)
- {
- DEBUG_ERR_MSG("can not get socket_data");
- return NET_NFC_LLCP_INVALID_SOCKET;
- }
-
- if (data == NULL)
- {
- DEBUG_ERR_MSG("data is empty");
- return NET_NFC_INVALID_PARAM;
- }
-
- variant = net_nfc_util_gdbus_data_to_variant(data);
- if (variant == NULL)
- {
- DEBUG_ERR_MSG("Can not convert to variant");
- return NET_NFC_INVALID_PARAM;
- }
-
-
- func_data = g_new0(LlcpFuncData, 1);
- func_data->callback = (gpointer)callback;
- func_data->user_data = user_data;
-
- net_nfc_gdbus_llcp_call_send(llcp_proxy,
- GPOINTER_TO_UINT(llcp_handle),
- socket_data->client_socket,
- socket_data->oal_socket,
- variant,
- net_nfc_client_gdbus_get_privilege(),
- NULL,
- llcp_call_send,
- func_data);
-
- return NET_NFC_OK;
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_llcp_send_sync(net_nfc_llcp_socket_t socket,
- data_h data,
- net_nfc_llcp_socket_t *out_socket)
-{
- GVariant *variant;
- GError *error = NULL;
- guint32 out_client_socket;
-
- net_nfc_llcp_internal_socket_s *socket_data;
- net_nfc_llcp_internal_socket_s *out_socket_data;
-
- if (llcp_proxy == NULL)
- {
- DEBUG_ERR_MSG("Can not get LlcpProxy");
- return NET_NFC_UNKNOWN_ERROR;
- }
-
- socket_data = llcp_socket_data_find(socket);
- if (socket_data == NULL)
- {
- DEBUG_ERR_MSG("can not get socket_data");
- return NET_NFC_LLCP_INVALID_SOCKET;
- }
-
- if (data == NULL)
- {
- DEBUG_ERR_MSG("data is empty");
- return NET_NFC_INVALID_PARAM;
- }
-
- /* prevent executing daemon when nfc is off */
- if (net_nfc_client_manager_is_activated() == false) {
- return NET_NFC_INVALID_STATE;
- }
-
- variant = net_nfc_util_gdbus_data_to_variant(data);
- if (variant == NULL)
- {
- DEBUG_ERR_MSG("Can not convert to variant");
- return NET_NFC_INVALID_PARAM;
- }
-
- if (net_nfc_gdbus_llcp_call_send_sync(llcp_proxy,
- GPOINTER_TO_UINT(llcp_handle),
- socket_data->client_socket,
- socket_data->oal_socket,
- variant,
- net_nfc_client_gdbus_get_privilege(),
- &out_client_socket,
- NULL,
- &error) == FALSE)
- {
- DEBUG_ERR_MSG("can not call send: %s",
- error->message);
- g_error_free(error);
- return NET_NFC_UNKNOWN_ERROR;
- }
-
- out_socket_data = llcp_socket_data_find(out_client_socket);
- if (out_socket_data == NULL)
- {
- DEBUG_ERR_MSG("can not find socket_data");
- return NET_NFC_UNKNOWN_ERROR;
- }
-
- if (out_socket)
- *out_socket = out_client_socket;
-
- return NET_NFC_OK;
-}
-
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_llcp_send_to(net_nfc_llcp_socket_t socket,
- sap_t sap,
- data_h data,
- net_nfc_client_llcp_send_to_completed callback,
- void *user_data)
-{
- LlcpFuncData *func_data;
- GVariant *variant = NULL;
- net_nfc_llcp_internal_socket_s *socket_data = NULL;
-
- if (llcp_proxy == NULL)
- {
- DEBUG_ERR_MSG("Can not get LlcpProxy");
- return NET_NFC_UNKNOWN_ERROR;
- }
-
- socket_data = llcp_socket_data_find(socket);
- if (socket_data == NULL)
- {
- DEBUG_ERR_MSG("can not get socket_data");
- return NET_NFC_LLCP_INVALID_SOCKET;
- }
-
- if (data == NULL)
- {
- DEBUG_ERR_MSG("data is empty");
- return NET_NFC_INVALID_PARAM;
- }
-
- variant = net_nfc_util_gdbus_data_to_variant(data);
- if (variant == NULL)
- {
- DEBUG_ERR_MSG("Can not convert to variant");
- return NET_NFC_INVALID_PARAM;
- }
-
- /* prevent executing daemon when nfc is off */
- if (net_nfc_client_manager_is_activated() == false) {
- return NET_NFC_INVALID_STATE;
- }
-
- func_data = g_new0(LlcpFuncData, 1);
- func_data->callback = (gpointer)callback;
- func_data->user_data = user_data;
-
- net_nfc_gdbus_llcp_call_send_to(llcp_proxy,
- GPOINTER_TO_UINT(llcp_handle),
- socket_data->client_socket,
- socket_data->oal_socket,
- sap,
- variant,
- net_nfc_client_gdbus_get_privilege(),
- NULL,
- llcp_call_send_to,
- func_data);
-
- return NET_NFC_OK;
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_llcp_send_to_sync(net_nfc_llcp_socket_t socket,
- sap_t sap,
- data_h data,
- net_nfc_llcp_socket_t *out_socket)
-{
- GVariant *variant;
- GError *error = NULL;
- guint32 out_client_socket;
-
- net_nfc_llcp_internal_socket_s *socket_data;
- net_nfc_llcp_internal_socket_s *out_socket_data;
-
- if (llcp_proxy == NULL)
- {
- DEBUG_ERR_MSG("Can not get LlcpProxy");
- return NET_NFC_UNKNOWN_ERROR;
- }
-
- socket_data = llcp_socket_data_find(socket);
- if (socket_data == NULL)
- {
- DEBUG_ERR_MSG("can not get socket_data");
- return NET_NFC_LLCP_INVALID_SOCKET;
- }
-
- if (data == NULL)
- {
- DEBUG_ERR_MSG("data is empty");
- return NET_NFC_INVALID_PARAM;
- }
-
- /* prevent executing daemon when nfc is off */
- if (net_nfc_client_manager_is_activated() == false) {
- return NET_NFC_INVALID_STATE;
- }
-
- variant = net_nfc_util_gdbus_data_to_variant(data);
- if (variant == NULL)
- {
- DEBUG_ERR_MSG("Can not convert to variant");
- return NET_NFC_INVALID_PARAM;
- }
-
- if (net_nfc_gdbus_llcp_call_send_to_sync(llcp_proxy,
- GPOINTER_TO_UINT(llcp_handle),
- socket_data->client_socket,
- socket_data->oal_socket,
- sap,
- variant,
- net_nfc_client_gdbus_get_privilege(),
- &out_client_socket,
- NULL,
- &error) == FALSE)
- {
- DEBUG_ERR_MSG("can not call send to: %s",
- error->message);
- g_error_free(error);
- return NET_NFC_UNKNOWN_ERROR;
- }
-
- out_socket_data = llcp_socket_data_find(out_client_socket);
- if (out_socket_data == NULL)
- {
- DEBUG_ERR_MSG("can not find socket_data");
- return NET_NFC_UNKNOWN_ERROR;
- }
-
- if (out_socket)
- *out_socket = out_client_socket;
-
- return NET_NFC_OK;
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_llcp_receive(net_nfc_llcp_socket_t socket,
- size_t request_length,
- net_nfc_client_llcp_receive_completed callback,
- void *user_data)
-{
- LlcpFuncData *func_data;
- net_nfc_llcp_internal_socket_s *socket_data = NULL;
-
- if (llcp_proxy == NULL)
- {
- DEBUG_ERR_MSG("Can not get LlcpProxy");
- return NET_NFC_UNKNOWN_ERROR;
- }
-
- socket_data = llcp_socket_data_find(socket);
- if (socket_data == NULL)
- {
- DEBUG_ERR_MSG("can not get socket_data");
- return NET_NFC_LLCP_INVALID_SOCKET;
- }
-
- /* prevent executing daemon when nfc is off */
- if (net_nfc_client_manager_is_activated() == false) {
- return NET_NFC_INVALID_STATE;
- }
-
- func_data = g_new0(LlcpFuncData, 1);
- func_data->callback = (gpointer)callback;
- func_data->user_data = user_data;
-
- net_nfc_gdbus_llcp_call_receive(llcp_proxy,
- GPOINTER_TO_UINT(llcp_handle),
- socket_data->client_socket,
- socket_data->oal_socket,
- request_length,
- net_nfc_client_gdbus_get_privilege(),
- NULL,
- llcp_call_receive,
- func_data);
-
- return NET_NFC_OK;
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_llcp_receive_sync(net_nfc_llcp_socket_t socket,
- size_t request_length,
- data_h *out_data)
-{
- GVariant *variant = NULL;
- GError *error = NULL;
- net_nfc_llcp_internal_socket_s *socket_data;
-
- if (llcp_proxy == NULL)
- {
- DEBUG_ERR_MSG("Can not get LlcpProxy");
- return NET_NFC_UNKNOWN_ERROR;
- }
-
- socket_data = llcp_socket_data_find(socket);
- if (socket_data == NULL)
- {
- DEBUG_ERR_MSG("can not get socket_data");
- return NET_NFC_LLCP_INVALID_SOCKET;
- }
-
- /* prevent executing daemon when nfc is off */
- if (net_nfc_client_manager_is_activated() == false) {
- return NET_NFC_INVALID_STATE;
- }
-
- if (net_nfc_gdbus_llcp_call_receive_sync(llcp_proxy,
- GPOINTER_TO_UINT(llcp_handle),
- socket_data->client_socket,
- socket_data->oal_socket,
- request_length,
- net_nfc_client_gdbus_get_privilege(),
- &variant,
- NULL,
- &error) == FALSE)
- {
- DEBUG_ERR_MSG("can not call receive: %s",
- error->message);
- g_error_free(error);
- return NET_NFC_UNKNOWN_ERROR;
- }
-
- if (out_data)
- {
- *out_data = net_nfc_util_gdbus_variant_to_data(variant);
- }
-
- return NET_NFC_OK;
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_llcp_receive_from(net_nfc_llcp_socket_t socket,
- size_t request_length,
- net_nfc_client_llcp_receive_from_completed callback,
- void *user_data)
-{
- LlcpFuncData *func_data;
- net_nfc_llcp_internal_socket_s *socket_data = NULL;
-
- if (llcp_proxy == NULL)
- {
- DEBUG_ERR_MSG("Can not get LlcpProxy");
- return NET_NFC_UNKNOWN_ERROR;
- }
-
- socket_data = llcp_socket_data_find(socket);
- if (socket_data == NULL)
- {
- DEBUG_ERR_MSG("can not get socket_data");
- return NET_NFC_LLCP_INVALID_SOCKET;
- }
-
- func_data = g_new0(LlcpFuncData, 1);
- func_data->callback = (gpointer)callback;
- func_data->user_data = user_data;
-
- net_nfc_gdbus_llcp_call_receive_from(llcp_proxy,
- GPOINTER_TO_UINT(llcp_handle),
- socket_data->client_socket,
- socket_data->oal_socket,
- request_length,
- net_nfc_client_gdbus_get_privilege(),
- NULL,
- llcp_call_receive_from,
- func_data);
-
- return NET_NFC_OK;
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_llcp_receive_from_sync
- (net_nfc_llcp_socket_t socket,
- size_t request_length,
- sap_t *out_sap,
- data_h *out_data)
-{
- GVariant *variant = NULL;
- GError *error = NULL;
- sap_t sap;
-
- net_nfc_llcp_internal_socket_s *socket_data;
-
- if (llcp_proxy == NULL)
- {
- DEBUG_ERR_MSG("Can not get LlcpProxy");
- return NET_NFC_UNKNOWN_ERROR;
- }
-
- socket_data = llcp_socket_data_find(socket);
- if (socket_data == NULL)
- {
- DEBUG_ERR_MSG("can not get socket_data");
- return NET_NFC_LLCP_INVALID_SOCKET;
- }
-
- /* prevent executing daemon when nfc is off */
- if (net_nfc_client_manager_is_activated() == false) {
- return NET_NFC_INVALID_STATE;
- }
-
- if (net_nfc_gdbus_llcp_call_receive_from_sync(llcp_proxy,
- GPOINTER_TO_UINT(llcp_handle),
- socket_data->client_socket,
- socket_data->oal_socket,
- request_length,
- net_nfc_client_gdbus_get_privilege(),
- &sap,
- &variant,
- NULL,
- &error) == FALSE)
- {
- DEBUG_ERR_MSG("can not call receive from: %s",
- error->message);
- g_error_free(error);
- return NET_NFC_UNKNOWN_ERROR;
- }
-
- if (*out_sap)
- *out_sap = sap;
-
- if (out_data)
- {
- *out_data = net_nfc_util_gdbus_variant_to_data(variant);
- }
-
- return NET_NFC_OK;
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_llcp_close(net_nfc_llcp_socket_t socket,
- net_nfc_client_llcp_close_completed callback,
- void *user_data)
-{
- LlcpFuncData *func_data;
- net_nfc_llcp_internal_socket_s *socket_data = NULL;
-
- if (llcp_proxy == NULL)
- {
- DEBUG_ERR_MSG("Can not get LlcpProxy");
- return NET_NFC_UNKNOWN_ERROR;
- }
-
- socket_data = llcp_socket_data_find(socket);
- if (socket_data == NULL)
- {
- DEBUG_ERR_MSG("can not get socket_data");
- return NET_NFC_LLCP_INVALID_SOCKET;
- }
-
- /* prevent executing daemon when nfc is off */
- if (net_nfc_client_manager_is_activated() == false) {
- return NET_NFC_INVALID_STATE;
- }
-
- func_data = g_new0(LlcpFuncData, 1);
- func_data->callback = (gpointer)callback;
- func_data->user_data = user_data;
-
- net_nfc_gdbus_llcp_call_close(llcp_proxy,
- GPOINTER_TO_UINT(llcp_handle),
- socket_data->client_socket,
- socket_data->oal_socket,
- net_nfc_client_gdbus_get_privilege(),
- NULL,
- llcp_call_close,
- func_data);
-
- return NET_NFC_OK;
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_llcp_close_sync(net_nfc_llcp_socket_t socket,
- net_nfc_llcp_socket_t *out_socket)
-{
- GError *error = NULL;
- guint32 out_client_socket;
-
- net_nfc_llcp_internal_socket_s *socket_data = NULL;
- net_nfc_llcp_internal_socket_s *out_socket_data = NULL;
-
- if (llcp_proxy == NULL)
- {
- DEBUG_ERR_MSG("Can not get LlcpProxy");
- return NET_NFC_UNKNOWN_ERROR;
- }
-
- socket_data = llcp_socket_data_find(socket);
- if (socket_data == NULL)
- {
- DEBUG_ERR_MSG("can not get socket_data");
- return NET_NFC_LLCP_INVALID_SOCKET;
- }
-
- /* prevent executing daemon when nfc is off */
- if (net_nfc_client_manager_is_activated() == false) {
- return NET_NFC_INVALID_STATE;
- }
-
- if (net_nfc_gdbus_llcp_call_close_sync(llcp_proxy,
- GPOINTER_TO_UINT(llcp_handle),
- socket_data->client_socket,
- socket_data->oal_socket,
- net_nfc_client_gdbus_get_privilege(),
- &out_client_socket,
- NULL,
- &error) == FALSE)
- {
- DEBUG_ERR_MSG("can not close: %s",
- error->message);
- g_error_free(error);
- return NET_NFC_UNKNOWN_ERROR;
- }
-
- out_socket_data = llcp_socket_data_find(out_client_socket);
- if (out_socket_data == NULL || out_socket_data != socket_data)
- {
- DEBUG_ERR_MSG("Wrong client socket is returned");
- return NET_NFC_UNKNOWN_ERROR;
- }
-
- if (out_socket)
- *out_socket = out_client_socket;
-
- return NET_NFC_OK;
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_llcp_disconnect(net_nfc_llcp_socket_t socket,
- net_nfc_client_llcp_disconnect_completed callback,
- void *user_data)
-{
- LlcpFuncData *func_data;
- net_nfc_llcp_internal_socket_s *socket_data = NULL;
-
- if (llcp_proxy == NULL)
- {
- DEBUG_ERR_MSG("Can not get LlcpProxy");
- return NET_NFC_UNKNOWN_ERROR;
- }
-
- socket_data = llcp_socket_data_find(socket);
- if (socket_data == NULL)
- {
- DEBUG_ERR_MSG("can not get socket_data");
- return NET_NFC_LLCP_INVALID_SOCKET;
- }
-
- /* prevent executing daemon when nfc is off */
- if (net_nfc_client_manager_is_activated() == false) {
- return NET_NFC_INVALID_STATE;
- }
-
- func_data = g_new0(LlcpFuncData, 1);
- func_data->callback = (gpointer)callback;
- func_data->user_data = user_data;
-
- net_nfc_gdbus_llcp_call_disconnect(llcp_proxy,
- GPOINTER_TO_UINT(llcp_handle),
- socket_data->client_socket,
- socket_data->oal_socket,
- net_nfc_client_gdbus_get_privilege(),
- NULL,
- llcp_call_disconnect,
- func_data);
-
- return NET_NFC_OK;
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_llcp_disconnect_sync(
- net_nfc_llcp_socket_t socket,
- net_nfc_llcp_socket_t *out_socket)
-{
- GError *error = NULL;
- guint32 out_client_socket;
-
- net_nfc_llcp_internal_socket_s *socket_data = NULL;
- net_nfc_llcp_internal_socket_s *out_socket_data = NULL;
-
- if (llcp_proxy == NULL)
- {
- DEBUG_ERR_MSG("Can not get LlcpProxy");
- return NET_NFC_UNKNOWN_ERROR;
- }
-
- socket_data = llcp_socket_data_find(socket);
- if (socket_data == NULL)
- {
- DEBUG_ERR_MSG("can not get socket_data");
- return NET_NFC_LLCP_INVALID_SOCKET;
- }
-
- /* prevent executing daemon when nfc is off */
- if (net_nfc_client_manager_is_activated() == false) {
- return NET_NFC_INVALID_STATE;
- }
-
- if (net_nfc_gdbus_llcp_call_disconnect_sync(llcp_proxy,
- GPOINTER_TO_UINT(llcp_handle),
- socket_data->client_socket,
- socket_data->oal_socket,
- net_nfc_client_gdbus_get_privilege(),
- &out_client_socket,
- NULL,
- &error) == FALSE)
- {
- DEBUG_ERR_MSG("can not disconnect: %s",
- error->message);
- g_error_free(error);
- return NET_NFC_UNKNOWN_ERROR;
- }
-
- out_socket_data = llcp_socket_data_find(out_client_socket);
- if (out_socket_data == NULL || out_socket_data != socket_data)
- {
- DEBUG_ERR_MSG("Wrong client socket is returned");
- return NET_NFC_UNKNOWN_ERROR;
- }
-
- if (out_socket)
- *out_socket = out_client_socket;
-
- return NET_NFC_OK;
-}
-
-NET_NFC_EXPORT_API
-void net_nfc_client_llcp_create_socket(net_nfc_llcp_socket_t *socket,
- net_nfc_llcp_socket_option_h option)
-{
- net_nfc_llcp_internal_socket_s *socket_data = NULL;
-
- socket_data = g_new0(net_nfc_llcp_internal_socket_s, 1);
-
- socket_data->client_socket = socket_handle++;
-
- if (option)
- {
- socket_data->miu = option->miu;
- socket_data->rw = option->rw;
- socket_data->type = option->type;
- }
- else
- {
- socket_data->miu = 128;
- socket_data->rw = 1;
- socket_data->type =
- NET_NFC_LLCP_SOCKET_TYPE_CONNECTIONORIENTED;
- }
-
- socket_data->device_id = llcp_handle;
- socket_data->close_requested = false;
-
-
- if (socket)
- *socket = socket_data->client_socket;
-}
-
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_llcp_get_local_config(
- net_nfc_llcp_config_info_h *config)
-{
- if (config == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
-
- *config = (net_nfc_llcp_config_info_h)&llcp_config;
-
- return NET_NFC_OK;
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_llcp_get_local_socket_option(
- net_nfc_llcp_socket_t socket,
- net_nfc_llcp_socket_option_h *info)
-{
- net_nfc_llcp_internal_socket_s *socket_data = NULL;
-
- DEBUG_CLIENT_MSG("function %s is called", __func__);
-
- socket_data = llcp_socket_data_find(socket);
- if (socket_data == NULL)
- return NET_NFC_LLCP_INVALID_SOCKET;
-
- *info = (net_nfc_llcp_socket_option_h)socket_data;
-
- return NET_NFC_OK;
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_llcp_create_socket_option(
- net_nfc_llcp_socket_option_h *option,
- uint16_t miu,
- uint8_t rw,
- net_nfc_socket_type_e type)
-{
- net_nfc_llcp_socket_option_s *struct_option = NULL;
-
- if (option == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
-
- if (miu < 128 || miu > 1152 ||
- rw < 1 || rw > 15 ||
- type < NET_NFC_LLCP_SOCKET_TYPE_CONNECTIONORIENTED ||
- type > NET_NFC_LLCP_SOCKET_TYPE_CONNECTIONLESS)
- {
- return NET_NFC_OUT_OF_BOUND;
- }
-
- _net_nfc_util_alloc_mem(struct_option, sizeof(net_nfc_llcp_socket_option_s));
- if (struct_option != NULL)
- {
- struct_option->miu = miu;
- struct_option->rw = rw;
- struct_option->type = type;
-
- *option = (net_nfc_llcp_socket_option_h)struct_option;
-
- return NET_NFC_OK;
- }
- else
- {
- return NET_NFC_ALLOC_FAIL;
- }
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_llcp_create_socket_option_default(
- net_nfc_llcp_socket_option_h *option)
-{
- return net_nfc_client_llcp_create_socket_option(
- option,
- 128,
- 1,
- NET_NFC_LLCP_SOCKET_TYPE_CONNECTIONORIENTED);
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_llcp_get_socket_option_miu(
- net_nfc_llcp_socket_option_h option,
- uint16_t *miu)
-{
- if (option == NULL || miu == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
- net_nfc_llcp_socket_option_s *struct_option = (net_nfc_llcp_socket_option_s *)option;
-
- *miu = struct_option->miu;
- return NET_NFC_OK;
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_llcp_set_socket_option_miu(
- net_nfc_llcp_socket_option_h option,
- uint16_t miu)
-{
- if (option == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
- net_nfc_llcp_socket_option_s *struct_option = (net_nfc_llcp_socket_option_s *)option;
-
- struct_option->miu = miu;
- return NET_NFC_OK;
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_llcp_get_socket_option_rw(
- net_nfc_llcp_socket_option_h option,
- uint8_t *rw)
-{
- if (option == NULL || rw == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
- net_nfc_llcp_socket_option_s *struct_option = (net_nfc_llcp_socket_option_s *)option;
-
- *rw = struct_option->rw;
- return NET_NFC_OK;
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_llcp_set_socket_option_rw(
- net_nfc_llcp_socket_option_h option,
- uint8_t rw)
-{
- if (option == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
- net_nfc_llcp_socket_option_s *struct_option = (net_nfc_llcp_socket_option_s *)option;
-
- struct_option->rw = rw;
- return NET_NFC_OK;
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_llcp_get_socket_option_type(
- net_nfc_llcp_socket_option_h option,
- net_nfc_socket_type_e * type)
-{
- if (option == NULL || type == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
- net_nfc_llcp_socket_option_s *struct_option = (net_nfc_llcp_socket_option_s *)option;
-
- *type = struct_option->type;
- return NET_NFC_OK;
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_llcp_set_socket_option_type(
- net_nfc_llcp_socket_option_h option,
- net_nfc_socket_type_e type)
-{
- if (option == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
- net_nfc_llcp_socket_option_s *struct_option = (net_nfc_llcp_socket_option_s *)option;
-
- struct_option->type = type;
- return NET_NFC_OK;
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_llcp_free_socket_option(
- net_nfc_llcp_socket_option_h option)
-{
- if (option == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
-
- _net_nfc_util_free_mem(option);
-
- return NET_NFC_OK;
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_llcp_create_config(
- net_nfc_llcp_config_info_h *config,
- uint16_t miu,
- uint16_t wks,
- uint8_t lto,
- uint8_t option)
-{
- if (config == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
-
- net_nfc_llcp_config_info_s **tmp_config =
- (net_nfc_llcp_config_info_s **)config;
-
- _net_nfc_util_alloc_mem(*tmp_config,
- sizeof(net_nfc_llcp_config_info_s));
-
- if (*tmp_config == NULL)
- return NET_NFC_ALLOC_FAIL;
-
- (*tmp_config)->miu = miu;
- (*tmp_config)->wks = wks;
- (*tmp_config)->lto = lto;
- (*tmp_config)->option = option;
-
- return NET_NFC_OK;
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_llcp_create_config_default(net_nfc_llcp_config_info_h *config)
-{
- return net_nfc_client_llcp_create_config(config, 128, 1, 10, 0);
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_llcp_get_config_miu(
- net_nfc_llcp_config_info_h config,
- uint16_t *miu)
-{
- if (config == NULL || miu == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
-
- net_nfc_llcp_config_info_s *tmp_config =
- (net_nfc_llcp_config_info_s *)config;
-
- *miu = tmp_config->miu;
-
- return NET_NFC_OK;
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_llcp_get_config_wks(
- net_nfc_llcp_config_info_h config,
- uint16_t *wks)
-{
- if (config == NULL || wks == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
-
- net_nfc_llcp_config_info_s *tmp_config =
- (net_nfc_llcp_config_info_s *)config;
-
- *wks = tmp_config->wks;
-
- return NET_NFC_OK;
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_llcp_get_config_lto(
- net_nfc_llcp_config_info_h config,
- uint8_t *lto)
-{
- if (config == NULL || lto == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
-
- net_nfc_llcp_config_info_s *tmp_config =
- (net_nfc_llcp_config_info_s *)config;
-
- *lto = tmp_config->lto;
-
- return NET_NFC_OK;
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_llcp_get_config_option(
- net_nfc_llcp_config_info_h config,
- uint8_t *option)
-{
- if (config == NULL || option == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
-
- net_nfc_llcp_config_info_s *tmp_config =
- (net_nfc_llcp_config_info_s *)config;
-
- *option = tmp_config->option;
-
- return NET_NFC_OK;
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_llcp_set_config_miu(
- net_nfc_llcp_config_info_h config,
- uint16_t miu)
-{
- if (config == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
-
- if (miu < 128 || miu > 1152)
- {
- return NET_NFC_OUT_OF_BOUND;
- }
-
- net_nfc_llcp_config_info_s * tmp_config =
- (net_nfc_llcp_config_info_s *)config;
-
- tmp_config->miu = miu;
-
- return NET_NFC_OK;
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_llcp_set_config_wks(
- net_nfc_llcp_config_info_h config,
- uint16_t wks)
-{
- if (config == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
-
- net_nfc_llcp_config_info_s *tmp_config =
- (net_nfc_llcp_config_info_s *)config;
-
- tmp_config->wks = wks;
-
- return NET_NFC_OK;
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_llcp_set_config_lto(
- net_nfc_llcp_config_info_h config,
- uint8_t lto)
-{
- if (config == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
-
- net_nfc_llcp_config_info_s *tmp_config =
- (net_nfc_llcp_config_info_s *)config;
-
- tmp_config->lto = lto;
-
- return NET_NFC_OK;
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_llcp_set_config_option(
- net_nfc_llcp_config_info_h config,
- uint8_t option)
-{
- if (config == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
-
- net_nfc_llcp_config_info_s * tmp_config =
- (net_nfc_llcp_config_info_s *)config;
-
- tmp_config->option = option;
-
- return NET_NFC_OK;
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_llcp_free_config(net_nfc_llcp_config_info_h config)
-{
- if (config == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
-
- _net_nfc_util_free_mem(config);
- return NET_NFC_OK;
-}
-
-net_nfc_error_e net_nfc_client_llcp_init(void)
-{
- GError *error = NULL;
-
- if (llcp_proxy)
- {
- DEBUG_CLIENT_MSG("Already initialized");
- return NET_NFC_OK;
- }
-
- llcp_proxy = net_nfc_gdbus_llcp_proxy_new_for_bus_sync(
- G_BUS_TYPE_SYSTEM,
- G_DBUS_PROXY_FLAGS_NONE,
- "org.tizen.NetNfcService",
- "/org/tizen/NetNfcService/Llcp",
- NULL,
- &error);
-
- if (llcp_proxy == NULL)
- {
- DEBUG_ERR_MSG("Can not create proxy : %s", error->message);
- g_error_free(error);
- return NET_NFC_UNKNOWN_ERROR;
- }
-
- g_signal_connect(llcp_proxy, "error",
- G_CALLBACK(llcp_error), NULL);
-
- return NET_NFC_OK;
-}
-
-void net_nfc_client_llcp_deinit(void)
-{
- if (llcp_proxy)
- {
- g_object_unref(llcp_proxy);
- llcp_proxy = NULL;
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "net_nfc_debug_internal.h"
-
-#include "net_nfc_gdbus.h"
-#include "net_nfc_client.h"
-#include "net_nfc_client_context.h"
-#include "net_nfc_client_manager.h"
-
-#ifndef NET_NFC_EXPORT_API
-#define NET_NFC_EXPORT_API __attribute__((visibility("default")))
-#endif
-
-typedef struct _ManagerFuncData ManagerFuncData;
-
-struct _ManagerFuncData
-{
- gpointer callback;
- gpointer user_data;
-};
-
-static NetNfcGDbusManager *manager_proxy = NULL;
-static gboolean activation_is_running = FALSE;
-
-static ManagerFuncData *activated_func_data = NULL;
-
-static int is_activated = -1;
-
-static void manager_call_set_active_callback(GObject *source_object,
- GAsyncResult *res,
- gpointer user_data);
-
-static void manager_call_get_server_state_callback(GObject *source_object,
- GAsyncResult *res,
- gpointer user_data);
-
-
-static void manager_activated(NetNfcGDbusManager *manager,
- gboolean activated,
- gpointer user_data);
-
-
-static void manager_call_set_active_callback(GObject *source_object,
- GAsyncResult *res,
- gpointer user_data)
-{
- ManagerFuncData *func_data;
-
- net_nfc_error_e result = NET_NFC_OK;
- GError *error = NULL;
-
- net_nfc_client_manager_set_active_completed callback;
- gpointer data;
-
- activation_is_running = FALSE;
-
- if (net_nfc_gdbus_manager_call_set_active_finish(
- NET_NFC_GDBUS_MANAGER(source_object),
- res,
- &error) == FALSE)
- {
- result = NET_NFC_UNKNOWN_ERROR;
-
- DEBUG_ERR_MSG("Can not finish call_set_active: %s",
- error->message);
- g_error_free(error);
- }
-
- func_data = user_data;
- if (func_data == NULL)
- return;
-
- if (func_data->callback == NULL)
- {
- g_free(func_data);
- return;
- }
-
-
- callback = (net_nfc_client_manager_set_active_completed)
- func_data->callback;
- data = func_data->user_data;
-
- callback(result, data);
-
- g_free(func_data);
-}
-
-static void manager_call_get_server_state_callback(GObject *source_object,
- GAsyncResult *res,
- gpointer user_data)
-{
- ManagerFuncData *func_data;
-
- net_nfc_error_e result = NET_NFC_OK;
- guint out_state;
- GError *error = NULL;
-
- net_nfc_client_manager_get_server_state_completed callback;
- gpointer data;
-
- if (net_nfc_gdbus_manager_call_get_server_state_finish(
- NET_NFC_GDBUS_MANAGER(source_object),
- &out_state,
- res,
- &error) == FALSE)
- {
-
- result = NET_NFC_UNKNOWN_ERROR;
-
- DEBUG_ERR_MSG("Can not finish get_server_state: %s",
- error->message);
- g_error_free(error);
- }
-
- func_data = user_data;
- if (func_data == NULL)
- return;
-
- if (func_data->callback == NULL)
- {
- g_free(func_data);
- return;
- }
-
- callback = (net_nfc_client_manager_get_server_state_completed)
- func_data->callback;
- data = func_data->user_data;
-
- callback(result, out_state, data);
-
- g_free(func_data);
-}
-
-
-static void manager_activated(NetNfcGDbusManager *manager,
- gboolean activated,
- gpointer user_data)
-{
- bool state = false;
-
- INFO_MSG(">>> SIGNAL arrived");
- DEBUG_CLIENT_MSG("activated %d", activated);
-
- /* update current state */
- is_activated = (int)activated;
-
- if (activated_func_data == NULL)
- return;
-
- if (activated == TRUE)
- state = true;
-
- if (activated_func_data->callback)
- {
- net_nfc_client_manager_activated callback;
- gpointer user_data;
-
- callback = (net_nfc_client_manager_activated)
- (activated_func_data->callback);
- user_data = activated_func_data->user_data;
-
- callback(state, user_data);
- }
-}
-
-NET_NFC_EXPORT_API
-void net_nfc_client_manager_set_activated(
- net_nfc_client_manager_activated callback,
- void *user_data)
-{
- if (activated_func_data == NULL)
- activated_func_data = g_new0(ManagerFuncData, 1);
-
- activated_func_data->callback = (gpointer)callback;
- activated_func_data->user_data = user_data;
-}
-
-NET_NFC_EXPORT_API
-void net_nfc_client_manager_unset_activated(void)
-{
- if (activated_func_data == NULL)
- {
- DEBUG_ERR_MSG("manager_func_data is not initialized");
- return;
- }
-
- g_free(activated_func_data);
- activated_func_data = NULL;
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_manager_set_active(int state,
- net_nfc_client_manager_set_active_completed callback,
- void *user_data)
-{
- gboolean active = FALSE;
- ManagerFuncData *func_data;
-
- if (manager_proxy == NULL)
- return NET_NFC_UNKNOWN_ERROR;
-
- /* allow this function even nfc is off */
-
- if (activation_is_running == TRUE)
- return NET_NFC_BUSY;
-
- activation_is_running = TRUE;
-
- func_data = g_new0(ManagerFuncData, 1);
- if (func_data == NULL)
- return NET_NFC_UNKNOWN_ERROR;
-
- func_data->callback = (gpointer)callback;
- func_data->user_data = user_data;
-
- if (state == true)
- active = TRUE;
-
- net_nfc_gdbus_manager_call_set_active(manager_proxy,
- active,
- net_nfc_client_gdbus_get_privilege(),
- NULL,
- manager_call_set_active_callback,
- func_data);
-
- return NET_NFC_OK;
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_manager_set_active_sync(int state)
-{
- GError *error = NULL;
-
- if (manager_proxy == NULL)
- return NET_NFC_UNKNOWN_ERROR;
-
- /* allow this function even nfc is off */
-
- if (net_nfc_gdbus_manager_call_set_active_sync(manager_proxy,
- (gboolean)state,
- net_nfc_client_gdbus_get_privilege(),
- NULL,
- &error) == FALSE)
- {
- DEBUG_CLIENT_MSG("can not call SetActive: %s",
- error->message);
- g_error_free(error);
- return NET_NFC_UNKNOWN_ERROR;
- }
-
- return NET_NFC_OK;
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_manager_get_server_state(
- net_nfc_client_manager_get_server_state_completed callback,
- void *user_data)
-{
- ManagerFuncData *func_data;
-
- if (manager_proxy == NULL)
- return NET_NFC_UNKNOWN_ERROR;
-
- /* prevent executing daemon when nfc is off */
- if (net_nfc_client_manager_is_activated() == false) {
- return NET_NFC_INVALID_STATE;
- }
-
- func_data = g_new0(ManagerFuncData, 1);
- if (func_data == NULL)
- return NET_NFC_UNKNOWN_ERROR;
-
- func_data->callback = (gpointer) callback;
- func_data->user_data = user_data;
-
- net_nfc_gdbus_manager_call_get_server_state(manager_proxy,
- net_nfc_client_gdbus_get_privilege(),
- NULL,
- manager_call_get_server_state_callback,
- func_data);
-
- return NET_NFC_OK;
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_manager_get_server_state_sync(
- unsigned int *state)
-{
- GError *error = NULL;
- guint out_state;
-
- if (manager_proxy == NULL)
- return NET_NFC_UNKNOWN_ERROR;
-
- /* prevent executing daemon when nfc is off */
- if (net_nfc_client_manager_is_activated() == false) {
- return NET_NFC_INVALID_STATE;
- }
-
- if (net_nfc_gdbus_manager_call_get_server_state_sync(manager_proxy,
- net_nfc_client_gdbus_get_privilege(),
- &out_state,
- NULL,
- &error) == FALSE)
- {
- DEBUG_CLIENT_MSG("can not call GetServerState: %s",
- error->message);
- g_error_free(error);
-
- return NET_NFC_UNKNOWN_ERROR;
- }
-
- *state = out_state;
- return NET_NFC_OK;
-
-}
-
-net_nfc_error_e net_nfc_client_manager_init(void)
-{
- GError *error = NULL;
-
- if (manager_proxy)
- {
- DEBUG_CLIENT_MSG("Already initialized");
- return NET_NFC_OK;
- }
-
- manager_proxy = net_nfc_gdbus_manager_proxy_new_for_bus_sync(
- G_BUS_TYPE_SYSTEM,
- G_DBUS_PROXY_FLAGS_NONE,
- "org.tizen.NetNfcService",
- "/org/tizen/NetNfcService/Manager",
- NULL,
- &error);
-
- if (manager_proxy == NULL)
- {
- DEBUG_ERR_MSG("Can not create proxy : %s", error->message);
- g_error_free(error);
- return NET_NFC_UNKNOWN_ERROR;
- }
-
- g_signal_connect(manager_proxy, "activated",
- G_CALLBACK(manager_activated), NULL);
-
- return NET_NFC_OK;
-}
-
-void net_nfc_client_manager_deinit(void)
-{
- if (manager_proxy)
- {
- g_object_unref(manager_proxy);
- manager_proxy = NULL;
- }
-
- if (activated_func_data)
- {
- g_free(activated_func_data);
- activated_func_data = NULL;
- }
-}
-
-/* internal function */
-bool net_nfc_client_manager_is_activated()
-{
- if (is_activated < 0) {
- net_nfc_client_get_nfc_state(&is_activated);
- }
-
- return is_activated;
-}
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "net_nfc_typedef_internal.h"
-#include "net_nfc_debug_internal.h"
-#include "net_nfc_util_internal.h"
-#include "net_nfc_util_ndef_message.h"
-#include "net_nfc_util_gdbus_internal.h"
-#include "net_nfc_gdbus.h"
-#include "net_nfc_data.h"
-#include "net_nfc_ndef_message.h"
-#include "net_nfc_client.h"
-#include "net_nfc_client_manager.h"
-#include "net_nfc_client_ndef.h"
-#include "net_nfc_client_tag_internal.h"
-
-#ifndef NET_NFC_EXPORT_API
-#define NET_NFC_EXPORT_API __attribute__((visibility("default")))
-#endif
-
-typedef struct _NdefFuncData NdefFuncData;
-
-struct _NdefFuncData
-{
- gpointer callback;
- gpointer user_data;
-};
-
-static NetNfcGDbusNdef *ndef_proxy = NULL;
-
-static ndef_message_h ndef_variant_to_message(GVariant *variant);
-
-static GVariant *ndef_message_to_variant(ndef_message_h message);
-
-static gboolean ndef_is_supported_tag(void);
-
-static void ndef_call_read(GObject *source_object,
- GAsyncResult *res,
- gpointer user_data);
-
-static void ndef_call_write(GObject *source_object,
- GAsyncResult *res,
- gpointer user_data);
-
-static void ndef_call_make_read_only(GObject *source_object,
- GAsyncResult *res,
- gpointer user_data);
-
-static void ndef_call_format(GObject *source_object,
- GAsyncResult *res,
- gpointer user_data);
-
-static ndef_message_h ndef_variant_to_message(GVariant *variant)
-{
- data_s data;
- ndef_message_h message = NULL;
-
- net_nfc_util_gdbus_variant_to_data_s(variant, &data);
-
- if (data.buffer && data.length > 0)
- {
- if (net_nfc_create_ndef_message_from_rawdata(&message, &data)
- != NET_NFC_OK)
- {
- DEBUG_ERR_MSG("memory alloc fail...");
- }
-
- net_nfc_util_free_data(&data);
- }
-
- return message;
-}
-
-static GVariant *ndef_message_to_variant(ndef_message_h message)
-{
- guint length;
- data_s data;
- GVariant *variant = NULL;
-
- length = net_nfc_util_get_ndef_message_length(
- (ndef_message_s *)message);
-
- if (length == 0)
- {
- DEBUG_ERR_MSG("message length is 0");
- return NULL;
- }
-
- data.length = length;
- data.buffer = g_new0(guint8, length);
-
- if(net_nfc_util_convert_ndef_message_to_rawdata(
- (ndef_message_s *)message,
- &data) != NET_NFC_OK)
- {
- DEBUG_ERR_MSG("can not convert ndef_message to rawdata");
- return NULL;
- }
-
- variant = net_nfc_util_gdbus_data_to_variant(&data);
-
- g_free(data.buffer);
-
- return variant;
-}
-
-static gboolean ndef_is_supported_tag(void)
-{
- net_nfc_target_info_s *target_info = NULL;
-
- target_info = net_nfc_client_tag_get_client_target_info();
-
- if (target_info == NULL)
- {
- DEBUG_ERR_MSG("target_info does not exist");
- return TRUE;
- }
-
- switch (target_info->devType)
- {
- case NET_NFC_ISO14443_A_PICC :
- case NET_NFC_MIFARE_MINI_PICC :
- case NET_NFC_MIFARE_1K_PICC :
- case NET_NFC_MIFARE_4K_PICC :
- case NET_NFC_MIFARE_ULTRA_PICC :
- case NET_NFC_JEWEL_PICC :
- return TRUE;
- break;
- default:
- DEBUG_CLIENT_MSG(
- "not supported tag for read only tag");
- return FALSE;
- }
-}
-
-static void ndef_call_read(GObject *source_object,
- GAsyncResult *res,
- gpointer user_data)
-{
- NdefFuncData *func_data;
-
- net_nfc_error_e out_result = NET_NFC_OK;
- GError *error = NULL;
-
- net_nfc_client_ndef_read_completed callback;
-
- GVariant *out_data = NULL;
- ndef_message_h message = NULL;
-
- if (net_nfc_gdbus_ndef_call_read_finish(
- NET_NFC_GDBUS_NDEF(source_object),
- (gint *)&out_result,
- &out_data,
- res,
- &error) == FALSE)
- {
- out_result = NET_NFC_UNKNOWN_ERROR;
-
- DEBUG_ERR_MSG("Can not finish read: %s", error->message);
- g_error_free(error);
- }
-
- func_data = (NdefFuncData *)user_data;
- if (func_data == NULL)
- {
- DEBUG_ERR_MSG("can not get NdefFuncData");
- return;
- }
-
- if (func_data->callback == NULL)
- {
- DEBUG_CLIENT_MSG("callback function is not avaiilable");
- g_free(func_data);
- return;
- }
-
- if (out_result == NET_NFC_OK)
- message = ndef_variant_to_message(out_data);
-
- callback = (net_nfc_client_ndef_read_completed)func_data->callback;
- callback(out_result, message, func_data->user_data);
-
- if (message)
- net_nfc_util_free_ndef_message(message);
-
- g_free(func_data);
-}
-
-static void ndef_call_write(GObject *source_object,
- GAsyncResult *res,
- gpointer user_data)
-{
- NdefFuncData *func_data;
-
- net_nfc_error_e out_result = NET_NFC_OK;
- GError *error = NULL;
-
- net_nfc_client_ndef_write_completed callback;
-
- if (net_nfc_gdbus_ndef_call_write_finish(
- NET_NFC_GDBUS_NDEF(source_object),
- (gint *)&out_result,
- res,
- &error) == FALSE)
- {
- out_result = NET_NFC_UNKNOWN_ERROR;
-
- DEBUG_ERR_MSG("Can not finish write: %s", error->message);
- g_error_free(error);
- }
-
- func_data = (NdefFuncData *)user_data;
- if (func_data == NULL)
- {
- DEBUG_ERR_MSG("can not get NdefFuncData");
- return;
- }
-
- if (func_data->callback == NULL)
- {
- DEBUG_CLIENT_MSG("callback function is not avaiilable");
- g_free(func_data);
- return;
- }
-
- callback = (net_nfc_client_ndef_write_completed)func_data->callback;
- callback(out_result, func_data->user_data);
-
- g_free(func_data);
-}
-
-static void ndef_call_make_read_only(GObject *source_object,
- GAsyncResult *res,
- gpointer user_data)
-{
- NdefFuncData *func_data;
-
- net_nfc_error_e out_result = NET_NFC_OK;
- GError *error = NULL;
-
- net_nfc_client_ndef_make_read_only_completed callback;
-
- if (net_nfc_gdbus_ndef_call_make_read_only_finish(
- NET_NFC_GDBUS_NDEF(source_object),
- (gint *)&out_result,
- res,
- &error) == FALSE)
- {
- out_result = NET_NFC_UNKNOWN_ERROR;
-
- DEBUG_ERR_MSG("Can not finish make read only: %s",
- error->message);
- g_error_free(error);
- }
-
- func_data = (NdefFuncData *)user_data;
- if (func_data == NULL)
- {
- DEBUG_ERR_MSG("can not get NdefFuncData");
- return;
- }
-
- if (func_data->callback == NULL)
- {
- DEBUG_CLIENT_MSG("callback function is not avaiilable");
- g_free(func_data);
- return;
- }
-
- callback = (net_nfc_client_ndef_make_read_only_completed)
- func_data->callback;
- callback(out_result, func_data->user_data);
-
- g_free(func_data);
-}
-
-static void ndef_call_format(GObject *source_object,
- GAsyncResult *res,
- gpointer user_data)
-{
- NdefFuncData *func_data;
-
- net_nfc_error_e out_result = NET_NFC_OK;
- GError *error = NULL;
-
- net_nfc_client_ndef_format_completed callback;
-
- if (net_nfc_gdbus_ndef_call_format_finish(
- NET_NFC_GDBUS_NDEF(source_object),
- (gint *)&out_result,
- res,
- &error) == FALSE)
- {
- out_result = NET_NFC_UNKNOWN_ERROR;
-
- DEBUG_ERR_MSG("Can not finish format: %s", error->message);
- g_error_free(error);
- }
-
- func_data = (NdefFuncData *)user_data;
- if (func_data == NULL)
- {
- DEBUG_ERR_MSG("can not get NdefFuncData");
- return;
- }
-
- if (func_data->callback == NULL)
- {
- DEBUG_CLIENT_MSG("callback function is not avaiilable");
- g_free(func_data);
- return;
- }
-
- callback = (net_nfc_client_ndef_format_completed) func_data->callback;
- callback(out_result, func_data->user_data);
-
- g_free(func_data);
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_ndef_read(net_nfc_target_handle_h handle,
- net_nfc_client_ndef_read_completed callback,
- void *user_data)
-{
- NdefFuncData *func_data;
-
- if (ndef_proxy == NULL)
- {
- DEBUG_ERR_MSG("Can not get NdefProxy");
- return NET_NFC_UNKNOWN_ERROR;
- }
-
- /* prevent executing daemon when nfc is off */
- if (net_nfc_client_manager_is_activated() == false) {
- return NET_NFC_INVALID_STATE;
- }
-
- DEBUG_CLIENT_MSG("send reqeust :: read ndef = [%p]", handle);
-
- if (handle == NULL)
- return NET_NFC_NULL_PARAMETER;
-
- if (net_nfc_client_tag_is_connected() == FALSE)
- return NET_NFC_OPERATION_FAIL;
-
- func_data = g_new0(NdefFuncData, 1);
-
- func_data->callback = (gpointer)callback;
- func_data->user_data = user_data;
-
- net_nfc_gdbus_ndef_call_read(ndef_proxy,
- GPOINTER_TO_UINT(handle),
- net_nfc_client_gdbus_get_privilege(),
- NULL,
- ndef_call_read,
- func_data);
-
- return NET_NFC_OK;
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_ndef_read_sync(net_nfc_target_handle_h handle,
- ndef_message_h *message)
-{
- GVariant *out_data = NULL;
- GError *error = NULL;
-
- net_nfc_error_e out_result = NET_NFC_OK;
-
- if (ndef_proxy == NULL)
- {
- DEBUG_ERR_MSG("Can not get NdefProxy");
- return NET_NFC_UNKNOWN_ERROR;
- }
-
- /* prevent executing daemon when nfc is off */
- if (net_nfc_client_manager_is_activated() == false) {
- return NET_NFC_INVALID_STATE;
- }
-
- DEBUG_CLIENT_MSG("send reqeust :: read ndef = [%p]", handle);
-
- if (handle == NULL)
- return NET_NFC_NULL_PARAMETER;
-
- if (net_nfc_client_tag_is_connected() == FALSE)
- return NET_NFC_OPERATION_FAIL;
-
- if (net_nfc_gdbus_ndef_call_read_sync(ndef_proxy,
- GPOINTER_TO_UINT(handle),
- net_nfc_client_gdbus_get_privilege(),
- (gint *)&out_result,
- &out_data,
- NULL,
- &error) == FALSE)
- {
- DEBUG_ERR_MSG("can not call read: %s",
- error->message);
- g_error_free(error);
- return NET_NFC_UNKNOWN_ERROR;
- }
-
- *message = ndef_variant_to_message(out_data);
-
- return out_result;
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_ndef_write(net_nfc_target_handle_h handle,
- ndef_message_h message,
- net_nfc_client_ndef_write_completed callback,
- void *user_data)
-{
- NdefFuncData *func_data;
-
- GVariant *arg_data = NULL;
-
- if (ndef_proxy == NULL)
- {
- DEBUG_ERR_MSG("Can not get NdefProxy");
- return NET_NFC_UNKNOWN_ERROR;
- }
-
- /* prevent executing daemon when nfc is off */
- if (net_nfc_client_manager_is_activated() == false) {
- return NET_NFC_INVALID_STATE;
- }
-
- if (handle == NULL)
- return NET_NFC_NULL_PARAMETER;
-
- if (message == NULL)
- return NET_NFC_NULL_PARAMETER;
-
- if (net_nfc_client_tag_is_connected() == FALSE)
- return NET_NFC_OPERATION_FAIL;
-
- func_data = g_new0(NdefFuncData, 1);
-
- func_data->callback = (gpointer)callback;
- func_data->user_data = user_data;
-
- arg_data = ndef_message_to_variant(message);
- if (arg_data == NULL)
- return NET_NFC_INVALID_PARAM;
-
- net_nfc_gdbus_ndef_call_write(ndef_proxy,
- GPOINTER_TO_UINT(handle),
- arg_data,
- net_nfc_client_gdbus_get_privilege(),
- NULL,
- ndef_call_write,
- func_data);
-
- return NET_NFC_OK;
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_ndef_write_sync(net_nfc_target_handle_h handle,
- ndef_message_h message)
-{
- GVariant *arg_data = NULL;
- GError *error = NULL;
-
- net_nfc_error_e out_result = NET_NFC_OK;
-
- if (ndef_proxy == NULL)
- {
- DEBUG_ERR_MSG("Can not get NdefProxy");
- return NET_NFC_UNKNOWN_ERROR;
- }
-
- /* prevent executing daemon when nfc is off */
- if (net_nfc_client_manager_is_activated() == false) {
- return NET_NFC_INVALID_STATE;
- }
-
- if (handle == NULL)
- return NET_NFC_NULL_PARAMETER;
-
- if (message == NULL)
- return NET_NFC_NULL_PARAMETER;
-
- if (net_nfc_client_tag_is_connected() == FALSE)
- return NET_NFC_OPERATION_FAIL;
-
- arg_data = ndef_message_to_variant(message);
- if (arg_data == NULL)
- return NET_NFC_INVALID_PARAM;
-
- if (net_nfc_gdbus_ndef_call_write_sync(ndef_proxy ,
- GPOINTER_TO_UINT(handle),
- arg_data,
- net_nfc_client_gdbus_get_privilege(),
- (gint *)&out_result,
- NULL,
- &error) == FALSE)
- {
- DEBUG_ERR_MSG("can not call write: %s",
- error->message);
- g_error_free(error);
- return NET_NFC_UNKNOWN_ERROR;
- }
-
- return out_result;
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_ndef_make_read_only(
- net_nfc_target_handle_h handle,
- net_nfc_client_ndef_make_read_only_completed callback,
- void *user_data)
-{
- NdefFuncData *func_data;
-
- if (ndef_proxy == NULL)
- {
- DEBUG_ERR_MSG("Can not get NdefProxy");
- return NET_NFC_UNKNOWN_ERROR;
- }
-
- /* prevent executing daemon when nfc is off */
- if (net_nfc_client_manager_is_activated() == false) {
- return NET_NFC_INVALID_STATE;
- }
-
- if (handle == NULL)
- return NET_NFC_NULL_PARAMETER;
-
- if (net_nfc_client_tag_is_connected() == FALSE)
- return NET_NFC_OPERATION_FAIL;
-
- if (ndef_is_supported_tag() == FALSE)
- return NET_NFC_NOT_SUPPORTED;
-
- func_data = g_new0(NdefFuncData, 1);
-
- func_data->callback = (gpointer)callback;
- func_data->user_data = user_data;
-
- net_nfc_gdbus_ndef_call_make_read_only(ndef_proxy,
- GPOINTER_TO_UINT(handle),
- net_nfc_client_gdbus_get_privilege(),
- NULL,
- ndef_call_make_read_only,
- func_data);
-
- return NET_NFC_OK;
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_ndef_make_read_only_sync(
- net_nfc_target_handle_h handle)
-{
- GError *error = NULL;
-
- net_nfc_error_e out_result = NET_NFC_OK;
-
- if (ndef_proxy == NULL)
- {
- DEBUG_ERR_MSG("Can not get NdefProxy");
- return NET_NFC_UNKNOWN_ERROR;
- }
-
- /* prevent executing daemon when nfc is off */
- if (net_nfc_client_manager_is_activated() == false) {
- return NET_NFC_INVALID_STATE;
- }
-
- if (handle == NULL)
- return NET_NFC_NULL_PARAMETER;
-
- if (net_nfc_client_tag_is_connected() == FALSE)
- return NET_NFC_OPERATION_FAIL;
-
- if (ndef_is_supported_tag() == FALSE)
- return NET_NFC_NOT_SUPPORTED;
-
- if (net_nfc_gdbus_ndef_call_make_read_only_sync(ndef_proxy,
- GPOINTER_TO_UINT(handle),
- net_nfc_client_gdbus_get_privilege(),
- (gint *)&out_result,
- NULL,
- &error) == FALSE)
- {
- DEBUG_ERR_MSG("can not make read only: %s",
- error->message);
- g_error_free(error);
- return NET_NFC_UNKNOWN_ERROR;
- }
-
- return out_result;
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_ndef_format(net_nfc_target_handle_h handle,
- data_h key,
- net_nfc_client_ndef_format_completed callback,
- void *user_data)
-{
- NdefFuncData *func_data;
- GVariant *arg_data = NULL;
-
-
- if (ndef_proxy == NULL)
- {
- DEBUG_ERR_MSG("Can not get NdefProxy");
- return NET_NFC_UNKNOWN_ERROR;
- }
-
- /* prevent executing daemon when nfc is off */
- if (net_nfc_client_manager_is_activated() == false) {
- return NET_NFC_INVALID_STATE;
- }
-
- if (handle == NULL)
- return NET_NFC_NULL_PARAMETER;
-
- if (key == NULL)
- arg_data = net_nfc_util_gdbus_buffer_to_variant(NULL, 0);
- else
- {
- data_s *key_s;
-
- key_s = (data_s *)key;
- arg_data = net_nfc_util_gdbus_data_to_variant(key_s);
- }
-
- if (arg_data == NULL)
- return NET_NFC_INVALID_PARAM;
-
- func_data = g_new0(NdefFuncData, 1);
-
- func_data->callback = (gpointer)callback;
- func_data->user_data = user_data;
-
- net_nfc_gdbus_ndef_call_format(ndef_proxy ,
- GPOINTER_TO_UINT(handle),
- arg_data,
- net_nfc_client_gdbus_get_privilege(),
- NULL,
- ndef_call_format,
- func_data);
-
- return NET_NFC_OK;
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_ndef_format_sync(
- net_nfc_target_handle_h handle,
- data_h key)
-{
- GVariant *arg_data = NULL;
- GError *error = NULL;
-
- net_nfc_error_e out_result = NET_NFC_OK;
-
- if (ndef_proxy == NULL)
- {
- DEBUG_ERR_MSG("Can not get NdefProxy");
- return NET_NFC_UNKNOWN_ERROR;
- }
-
- /* prevent executing daemon when nfc is off */
- if (net_nfc_client_manager_is_activated() == false) {
- return NET_NFC_INVALID_STATE;
- }
-
- if (handle == NULL)
- return NET_NFC_NULL_PARAMETER;
-
- if (key == NULL)
- arg_data = net_nfc_util_gdbus_buffer_to_variant(NULL, 0);
- else
- {
- data_s *key_s;
-
- key_s = (data_s *)key;
- arg_data = net_nfc_util_gdbus_data_to_variant(key_s);
- }
-
- if (arg_data == NULL)
- return NET_NFC_INVALID_PARAM;
-
- if (net_nfc_gdbus_ndef_call_format_sync(ndef_proxy ,
- GPOINTER_TO_UINT(handle),
- arg_data,
- net_nfc_client_gdbus_get_privilege(),
- (gint *)&out_result,
- NULL,
- &error) == FALSE)
- {
- DEBUG_ERR_MSG("can not call format: %s",
- error->message);
- g_error_free(error);
- return NET_NFC_UNKNOWN_ERROR;
- }
-
- return out_result;
-}
-
-net_nfc_error_e net_nfc_client_ndef_init(void)
-{
- GError *error = NULL;
-
- if (ndef_proxy)
- {
- DEBUG_CLIENT_MSG("Already initialized");
- return NET_NFC_OK;
- }
-
- ndef_proxy = net_nfc_gdbus_ndef_proxy_new_for_bus_sync(
- G_BUS_TYPE_SYSTEM,
- G_DBUS_PROXY_FLAGS_NONE,
- "org.tizen.NetNfcService",
- "/org/tizen/NetNfcService/Ndef",
- NULL,
- &error);
-
- if (ndef_proxy == NULL)
- {
- DEBUG_ERR_MSG("Can not create proxy : %s", error->message);
- g_error_free(error);
- return NET_NFC_UNKNOWN_ERROR;
- }
-
- return NET_NFC_OK;
-}
-
-void net_nfc_client_ndef_deinit(void)
-{
- if (ndef_proxy)
- {
- g_object_unref(ndef_proxy);
- ndef_proxy = NULL;
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
-
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "net_nfc_debug_internal.h"
-#include "net_nfc_util_internal.h"
-#include "net_nfc_util_ndef_message.h"
-#include "net_nfc_ndef_message.h"
-#include "net_nfc_data.h"
-
-
-
-#ifndef NET_NFC_MANAGER_DATA_PATH
-#define NET_NFC_MANAGER_DATA_PATH "/opt/data/nfc-manager-daemon"
-#endif
-
-#ifndef NET_NFC_MANAGER_DATA_PATH_MESSAGE
-#define NET_NFC_MANAGER_DATA_PATH_MESSAGE "message"
-#endif
-
-#ifndef NET_NFC_MANAGER_NDEF_FILE_NAME
-#define NET_NFC_MANAGER_NDEF_FILE_NAME "ndef-message.txt"
-#endif
-
-
-#ifndef NET_NFC_EXPORT_API
-#define NET_NFC_EXPORT_API __attribute__((visibility("default")))
-#endif
-
-
-/* public functions */
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_create_ndef_message(ndef_message_h *ndef_message)
-{
- return net_nfc_util_create_ndef_message((ndef_message_s **)ndef_message);
-}
-
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_create_rawdata_from_ndef_message(ndef_message_h ndef_message, data_h *rawdata)
-{
- uint32_t count;
- net_nfc_error_e result;
- data_h data;
-
- if (ndef_message == NULL || rawdata == NULL) {
- return NET_NFC_NULL_PARAMETER;
- }
-
- *rawdata = NULL;
-
- result = net_nfc_get_ndef_message_byte_length(ndef_message, &count);
- if (result != NET_NFC_OK) {
- return result;
- }
-
- result = net_nfc_create_data(&data ,NULL, count);
- if (result != NET_NFC_OK) {
- return result;
- }
-
- result = net_nfc_util_convert_ndef_message_to_rawdata(
- (ndef_message_s *)ndef_message, (data_s *)data);
- if (result == NET_NFC_OK) {
- *rawdata = data;
- } else {
- net_nfc_free_data(data);
- }
-
- return result;
-}
-
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_create_ndef_message_from_rawdata(ndef_message_h *ndef_message, data_h rawdata)
-{
- net_nfc_error_e result;
- ndef_message_h msg;
-
- if (ndef_message == NULL || rawdata == NULL) {
- return NET_NFC_NULL_PARAMETER;
- }
-
- *ndef_message = NULL;
-
- result = net_nfc_create_ndef_message(&msg);
- if (result != NET_NFC_OK) {
- return result;
- }
-
- result = net_nfc_util_convert_rawdata_to_ndef_message(
- (data_s *)rawdata, (ndef_message_s *)msg);
- if (result == NET_NFC_OK) {
- *ndef_message = msg;
- } else {
- net_nfc_free_ndef_message(msg);
- }
-
- return result;
-}
-
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_ndef_message_byte_length(ndef_message_h ndef_message, uint32_t *length)
-{
- net_nfc_error_e result;
-
- if (ndef_message == NULL || length == NULL){
- return NET_NFC_NULL_PARAMETER;
- }
-
- *length = net_nfc_util_get_ndef_message_length((ndef_message_s *)ndef_message);
- if (*length > 0) {
- result = NET_NFC_OK;
- } else {
- result = NET_NFC_INVALID_PARAM;
- }
-
- return result;
-}
-
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_append_record_to_ndef_message(ndef_message_h ndef_message, ndef_record_h record)
-{
- if (ndef_message == NULL || record == NULL){
- return NET_NFC_NULL_PARAMETER;
- }
-
- return net_nfc_util_append_record((ndef_message_s*)ndef_message, (ndef_record_s *)record);
-}
-
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_free_ndef_message(ndef_message_h ndef_message)
-{
- if (ndef_message == NULL) {
- return NET_NFC_NULL_PARAMETER;
- }
-
- return net_nfc_util_free_ndef_message((ndef_message_s *)ndef_message);
-}
-
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_ndef_message_record_count(ndef_message_h ndef_message, int *count)
-{
- if (ndef_message == NULL || count == NULL) {
- return NET_NFC_NULL_PARAMETER;
- }
-
- ndef_message_s *msg = (ndef_message_s *)ndef_message;
-
- *count = msg->recordCount;
-
- return NET_NFC_OK;
-}
-
-NET_NFC_EXPORT_API void net_nfc_ndef_print_message (ndef_message_h ndef_message )
-{
- net_nfc_util_print_ndef_message ((ndef_message_s *)(ndef_message) );
-}
-
-
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_search_record_by_type (ndef_message_h ndef_message, net_nfc_record_tnf_e tnf, data_h type, ndef_record_h* record)
-{
- return net_nfc_util_search_record_by_type ((ndef_message_s*)ndef_message, tnf, (data_s *)type, (ndef_record_s**)record);
-}
-
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_append_record_by_index (ndef_message_h ndef_message, int index, ndef_record_h record)
-{
- return net_nfc_util_append_record_by_index ((ndef_message_s *) ndef_message, index, (ndef_record_s *) record);
-}
-
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_record_by_index (ndef_message_h ndef_message, int index, ndef_record_h* record)
-{
- return net_nfc_util_get_record_by_index ((ndef_message_s*) ndef_message, index, (ndef_record_s**) record);
-}
-
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_remove_record_by_index (ndef_message_h ndef_message, int index)
-{
- return net_nfc_util_remove_record_by_index ((ndef_message_s*)ndef_message, index);
-}
-
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_retrieve_current_ndef_message(ndef_message_h* ndef_message)
-{
- net_nfc_error_e result = NET_NFC_UNKNOWN_ERROR;
- char file_path[1024] = { 0, };
- FILE *fp = NULL;
-
- if (ndef_message == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
-
- snprintf(file_path, sizeof(file_path), "%s/%s/%s", NET_NFC_MANAGER_DATA_PATH, NET_NFC_MANAGER_DATA_PATH_MESSAGE, NET_NFC_MANAGER_NDEF_FILE_NAME);
-
- if ((fp = fopen(file_path, "r")) != NULL)
- {
- long int size = 0;
-
- /* rewind to start of file */
- fseek(fp, 0, SEEK_END);
- size = ftell(fp);
- fseek(fp, 0, SEEK_SET);
-
- DEBUG_CLIENT_MSG("message length = [%ld]", size);
-
- if (size > 0)
- {
- uint8_t *buffer = NULL;
-
- _net_nfc_util_alloc_mem(buffer, size);
- if (buffer != NULL)
- {
- /* read fully */
- if ((size = fread(buffer, 1, size, fp)) > 0)
- {
- data_h data = NULL;
- if ((result = net_nfc_create_data(&data, buffer, size)) == NET_NFC_OK)
- {
- result = net_nfc_create_ndef_message_from_rawdata(ndef_message, data);
-
- net_nfc_free_data(data);
- }
- }
-
- _net_nfc_util_free_mem(buffer);
- }
- }
- else
- {
- result = NET_NFC_ALLOC_FAIL;
- }
-
- fclose(fp);
- }
- else
- {
- result = NET_NFC_NO_NDEF_MESSAGE;
- }
-
- return result;
-}
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
-
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-#include "net_nfc_ndef_message_handover.h"
-
-#include "net_nfc_typedef_internal.h"
-#include "net_nfc_debug_internal.h"
-#include "net_nfc_util_internal.h"
-#include "net_nfc_util_handover.h"
-
-#ifndef NET_NFC_EXPORT_API
-#define NET_NFC_EXPORT_API __attribute__((visibility("default")))
-#endif
-
-#include <glib.h>
-
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_create_carrier_config (net_nfc_carrier_config_h * config, net_nfc_conn_handover_carrier_type_e type)
-{
- return net_nfc_util_create_carrier_config ((net_nfc_carrier_config_s **) config, type);
-}
-
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_add_carrier_config_property (net_nfc_carrier_config_h config, uint16_t attribute, uint16_t size, uint8_t * data)
-{
- return net_nfc_util_add_carrier_config_property ((net_nfc_carrier_config_s *) config, attribute, size, data);
-}
-
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_remove_carrier_config_property (net_nfc_carrier_config_h config, uint16_t attribute)
-{
- return net_nfc_util_remove_carrier_config_property ((net_nfc_carrier_config_s *) config, attribute);
-}
-
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_carrier_config_property (net_nfc_carrier_config_h config, uint16_t attribute, uint16_t * size, uint8_t ** data)
-{
- return net_nfc_util_get_carrier_config_property ((net_nfc_carrier_config_s *) config, attribute, size, data);
-}
-
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_append_carrier_config_group (net_nfc_carrier_config_h config, net_nfc_property_group_h group)
-{
- return net_nfc_util_append_carrier_config_group ((net_nfc_carrier_config_s *) config, (net_nfc_carrier_property_s *) group);
-}
-
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_remove_carrier_config_group (net_nfc_carrier_config_h config, net_nfc_property_group_h group)
-{
- return net_nfc_util_remove_carrier_config_group ((net_nfc_carrier_config_s *) config, (net_nfc_carrier_property_s *) group);
-}
-
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_carrier_config_group (net_nfc_carrier_config_h config, int index, net_nfc_property_group_h * group)
-{
- return net_nfc_util_get_carrier_config_group ((net_nfc_carrier_config_s *) config, index, (net_nfc_carrier_property_s **) group);
-}
-
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_free_carrier_config (net_nfc_carrier_config_h config)
-{
- return net_nfc_util_free_carrier_config ((net_nfc_carrier_config_s *) config);
-}
-
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_create_carrier_config_group (net_nfc_property_group_h * group, uint16_t attribute)
-{
- return net_nfc_util_create_carrier_config_group ((net_nfc_carrier_property_s **) group, attribute);
-}
-
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_add_carrier_config_group_property (net_nfc_property_group_h group, uint16_t attribute, uint16_t size, uint8_t * data)
-{
- return net_nfc_util_add_carrier_config_group_property ((net_nfc_carrier_property_s*) group, attribute, size, data);
-}
-
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_carrier_config_group_property (net_nfc_property_group_h group, uint16_t attribute, uint16_t *size, uint8_t ** data)
-{
- return net_nfc_util_get_carrier_config_group_property ((net_nfc_carrier_property_s*) group, attribute, size, data);
-}
-
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_remove_carrier_config_group_property (net_nfc_property_group_h group, uint16_t attribute)
-{
- return net_nfc_util_remove_carrier_config_group_property ((net_nfc_carrier_property_s*) group, attribute);
-}
-
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_free_carrier_group (net_nfc_property_group_h group)
-{
- return net_nfc_util_free_carrier_group ((net_nfc_carrier_property_s*) group);
-}
-
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_create_ndef_record_with_carrier_config (ndef_record_h * record, net_nfc_carrier_config_h config)
-{
- return net_nfc_util_create_ndef_record_with_carrier_config ((ndef_record_s**) record, (net_nfc_carrier_config_s *) config);
-}
-
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_create_carrier_config_from_config_record (net_nfc_carrier_config_h * config, ndef_record_h record)
-{
- return net_nfc_util_create_carrier_config_from_config_record ((net_nfc_carrier_config_s **) config, (ndef_record_s *) record);
-
-}
-
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_append_carrier_config_record (ndef_message_h message, ndef_record_h record, net_nfc_conn_handover_carrier_state_e power_status)
-{
- return net_nfc_util_append_carrier_config_record ((ndef_message_s *) message, (ndef_record_s *) record, power_status);
-}
-
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_remove_carrier_config_record (ndef_message_h message, ndef_record_h record)
-{
- return net_nfc_util_remove_carrier_config_record ((ndef_message_s *) message, (ndef_record_s *) record);
-}
-
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_carrier_config_record (ndef_message_h message, int index, ndef_record_h * record)
-{
- return net_nfc_util_get_carrier_config_record ((ndef_message_s *) message, index, (ndef_record_s **) record);
-}
-
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_handover_random_number(ndef_message_h message, unsigned short* random_number)
-{
- return net_nfc_util_get_handover_random_number((ndef_message_s *) message, random_number);
-}
-
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_alternative_carrier_record_count (ndef_message_h message, unsigned int * count)
-{
- return net_nfc_util_get_alternative_carrier_record_count ((ndef_message_s *) message, count);
-}
-
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_alternative_carrier_power_status (ndef_message_h message, int index, net_nfc_conn_handover_carrier_state_e * power_state)
-{
- return net_nfc_util_get_alternative_carrier_power_status ((ndef_message_s *) message, index, power_state);
-}
-
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_set_alternative_carrier_power_status (ndef_message_h message, int index, net_nfc_conn_handover_carrier_state_e power_status)
-{
- return net_nfc_util_set_alternative_carrier_power_status ((ndef_message_s *) message, index, power_status);
-}
-
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_alternative_carrier_type (ndef_message_h message, int index, net_nfc_conn_handover_carrier_type_e * type)
-{
- return net_nfc_util_get_alternative_carrier_type ((ndef_message_s *) message, index, type);
-}
-
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_create_handover_request_message (ndef_message_h * message)
-{
- return net_nfc_util_create_handover_request_message ((ndef_message_s **) message);
-}
-
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_create_handover_select_message (ndef_message_h * message)
-{
- return net_nfc_util_create_handover_select_message((ndef_message_s **) message);
-}
-
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_create_handover_error_record (ndef_record_h * record, uint8_t reason, uint32_t data)
-{
- return net_nfc_util_create_handover_error_record ((ndef_record_s**) record, reason, data);
-}
-
-
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
-
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "net_nfc_ndef_record.h"
-#include "net_nfc_ndef_message.h"
-#include "net_nfc_data.h"
-#include "net_nfc_debug_internal.h"
-#include "net_nfc_util_internal.h"
-#include "net_nfc_util_ndef_record.h"
-
-#ifndef NET_NFC_EXPORT_API
-#define NET_NFC_EXPORT_API __attribute__((visibility("default")))
-#endif
-
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_create_record(ndef_record_h* record, net_nfc_record_tnf_e tnf, data_h typeName, data_h id, data_h payload)
-{
- return net_nfc_util_create_record(tnf, (data_s*)typeName, (data_s*)id, (data_s*)payload, (ndef_record_s**)record);
-}
-
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_create_text_type_record(ndef_record_h* record, const char* text, const char* language_code_str, net_nfc_encode_type_e encode)
-{
- return net_nfc_util_create_text_type_record(text, language_code_str, encode, (ndef_record_s**)record);
-}
-
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_create_uri_type_record(ndef_record_h* record, const char* uri, net_nfc_schema_type_e protocol_schema)
-{
- return net_nfc_util_create_uri_type_record(uri, protocol_schema, (ndef_record_s**)record);
-}
-
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_free_record(ndef_record_h record)
-{
- return net_nfc_util_free_record((ndef_record_s*)record);
-}
-
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_record_payload(ndef_record_h record, data_h * payload)
-{
- if (record == NULL || payload == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
- ndef_record_s * struct_record = (ndef_record_s *)record;
-
- *payload = (data_h)&(struct_record->payload_s);
-
- return NET_NFC_OK;
-}
-
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_record_type(ndef_record_h record, data_h * type)
-{
- if (record == NULL || type == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
- ndef_record_s * struct_record = (ndef_record_s *)record;
-
- *type = (data_h)&(struct_record->type_s);
-
- return NET_NFC_OK;
-
-}
-
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_record_id(ndef_record_h record, data_h * id)
-{
- if (record == NULL || id == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
- ndef_record_s * struct_record = (ndef_record_s *)record;
-
- *id = (data_h)&(struct_record->id_s);
-
- return NET_NFC_OK;
-
-}
-
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_record_tnf(ndef_record_h record, net_nfc_record_tnf_e * TNF)
-{
- if (record == NULL || TNF == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
- ndef_record_s * struct_record = (ndef_record_s *)record;
-
- *TNF = (net_nfc_record_tnf_e)struct_record->TNF;
-
- return NET_NFC_OK;
-}
-
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_set_record_id(ndef_record_h record, data_h id)
-{
-
- ndef_record_s * tmp_record = (ndef_record_s *)record;
- data_s * tmp_id = (data_s *)id;
-
- if (tmp_id == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
- return net_nfc_util_set_record_id(tmp_record, tmp_id->buffer, tmp_id->length);
-}
-
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_record_flags(ndef_record_h record, uint8_t * flag)
-{
- if (record == NULL || flag == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
-
- ndef_record_s * struct_record = (ndef_record_s *)record;
-
- *flag = struct_record->MB;
- *flag <<= 1;
- *flag += struct_record->ME;
- *flag <<= 1;
- *flag += struct_record->CF;
- *flag <<= 1;
- *flag += struct_record->SR;
- *flag <<= 1;
- *flag += struct_record->IL;
- *flag <<= 3;
- *flag += struct_record->TNF;
-
- return NET_NFC_OK;
-}
-
-NET_NFC_EXPORT_API uint8_t net_nfc_get_record_mb(uint8_t flag)
-{
- return ((flag >> 7) & 0x01);
-}
-
-NET_NFC_EXPORT_API uint8_t net_nfc_get_record_me(uint8_t flag)
-{
- return ((flag >> 6) & 0x01);
-}
-
-NET_NFC_EXPORT_API uint8_t net_nfc_get_record_cf(uint8_t flag)
-{
- return ((flag >> 5) & 0x01);
-}
-
-NET_NFC_EXPORT_API uint8_t net_nfc_get_record_sr(uint8_t flag)
-{
- return ((flag >> 4) & 0x01);
-}
-
-NET_NFC_EXPORT_API uint8_t net_nfc_get_record_il(uint8_t flag)
-{
- return ((flag >> 3) & 0x01);
-}
-
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_create_text_string_from_text_record(ndef_record_h record, char** buffer)
-{
- if (record == NULL || buffer == NULL)
- {
- return NET_NFC_ALLOC_FAIL;
- }
-
- data_h payload;
- data_h rec_type;
-
- if (net_nfc_get_record_type(record, &rec_type) == NET_NFC_OK)
- {
- if (strncmp((char *)net_nfc_get_data_buffer(rec_type), TEXT_RECORD_TYPE, 1) != 0)
- {
- DEBUG_CLIENT_MSG("record type is not matched");
- return NET_NFC_NDEF_RECORD_IS_NOT_EXPECTED_TYPE;
- }
- }
-
- if (net_nfc_get_record_payload(record, &payload) == NET_NFC_OK)
- {
- uint8_t* buffer_temp = net_nfc_get_data_buffer(payload);
- uint32_t buffer_length = net_nfc_get_data_length(payload);
-
- int controllbyte = buffer_temp[0];
- int lang_code_length = controllbyte & 0x3F;
- int index = lang_code_length + 1;
- int text_length = buffer_length - (lang_code_length + 1);
-
- if ((*buffer = (char *)calloc(1, text_length + 1)) != NULL)
- {
- memcpy(*buffer, &(buffer_temp[index]), text_length);
- DEBUG_CLIENT_MSG("text = [%s]", *buffer);
- }
- else
- {
- return NET_NFC_ALLOC_FAIL;
- }
- }
-
- return NET_NFC_OK;
-}
-
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_languange_code_string_from_text_record(ndef_record_h record, char** lang_code_str)
-{
- if (record == NULL || lang_code_str == NULL)
- {
- return NET_NFC_ALLOC_FAIL;
- }
-
- data_h payload;
- data_h rec_type;
-
- if (net_nfc_get_record_type(record, &rec_type) == NET_NFC_OK)
- {
- if (strncmp((char *)net_nfc_get_data_buffer(rec_type), TEXT_RECORD_TYPE, 1) != 0)
- {
- DEBUG_CLIENT_MSG("record type is not matched");
- return NET_NFC_NDEF_RECORD_IS_NOT_EXPECTED_TYPE;
- }
- }
-
- if (net_nfc_get_record_payload(record, &payload) == NET_NFC_OK)
- {
- uint8_t* buffer_temp = net_nfc_get_data_buffer(payload);
- char * buffer = NULL;
-
- int controllbyte = buffer_temp[0];
- int lang_code_length = controllbyte & 0x3F;
- int index = 1;
-
- if ((buffer = (char *)calloc(1, lang_code_length + 1)) != NULL)
- {
- memcpy(buffer, &(buffer_temp[index]), lang_code_length);
- DEBUG_CLIENT_MSG("language code = [%s]", buffer);
-
- *lang_code_str = buffer;
- }
- else
- {
- return NET_NFC_ALLOC_FAIL;
- }
- }
-
- return NET_NFC_OK;
-}
-
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_encoding_type_from_text_record(ndef_record_h record, net_nfc_encode_type_e * encoding)
-{
- if (record == NULL || encoding == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
-
- data_h payload;
- data_h rec_type;
-
- if (net_nfc_get_record_type(record, &rec_type) == NET_NFC_OK)
- {
- if (strncmp((char *)net_nfc_get_data_buffer(rec_type), TEXT_RECORD_TYPE, 1) != 0)
- {
- DEBUG_CLIENT_MSG("record type is not matched");
- return NET_NFC_NDEF_RECORD_IS_NOT_EXPECTED_TYPE;
- }
- }
-
- if (net_nfc_get_record_payload(record, &payload) == NET_NFC_OK)
- {
- uint8_t* buffer_temp = net_nfc_get_data_buffer(payload);
-
- int controllbyte = buffer_temp[0];
-
- if ((controllbyte & 0x80) == 0x80)
- {
- *encoding = NET_NFC_ENCODE_UTF_16;
- }
- else
- {
- *encoding = NET_NFC_ENCODE_UTF_8;
- }
- }
-
- return NET_NFC_OK;
-}
-
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_create_uri_string_from_uri_record(ndef_record_h record, char **uri)
-{
- return net_nfc_util_create_uri_string_from_uri_record((ndef_record_s *)record, uri);
-}
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "net_nfc_typedef_internal.h"
-#include "net_nfc_debug_internal.h"
-#include "net_nfc_util_internal.h"
-#include "net_nfc_util_ndef_message.h"
-#include "net_nfc_util_gdbus_internal.h"
-#include "net_nfc_gdbus.h"
-#include "net_nfc_client.h"
-#include "net_nfc_client_manager.h"
-#include "net_nfc_client_p2p.h"
-
-#ifndef NET_NFC_EXPORT_API
-#define NET_NFC_EXPORT_API __attribute__((visibility("default")))
-#endif
-
-typedef struct _P2pFuncData P2pFuncData;
-
-struct _P2pFuncData
-{
- gpointer p2p_send_callback;
- gpointer p2p_send_data;
-};
-
-
-typedef struct _P2p_SignalHandler P2pSignalHandler;
-
-struct _P2p_SignalHandler
-{
- net_nfc_client_p2p_device_discovered p2p_device_discovered_cb;
- net_nfc_client_p2p_device_detached p2p_device_detached_cb;
- net_nfc_client_p2p_data_received p2p_data_received_cb;
-
- gpointer p2p_device_discovered_data;
- gpointer p2p_device_detached_data;
- gpointer p2p_data_received_data;
-};
-
-static NetNfcGDbusP2p *p2p_proxy = NULL;
-static P2pSignalHandler *p2p_signal_handler = NULL;
-
-static void p2p_device_detached(GObject *source_object,
- gpointer user_data);
-
-static void p2p_device_discovered(GObject *source_object,
- guint arg_handle,
- gpointer user_data);
-
-static void p2p_device_data_received(GObject *source_object,
- GVariant *arg_data,
- gpointer user_data);
-
-static void p2p_call_send(GObject *source_object,
- GAsyncResult *res,
- gpointer user_data);
-
-static void p2p_device_detached(GObject *source_object,
- gpointer user_data)
-{
- INFO_MSG(">>> SIGNAL arrived");
-
- /*llcp client function to set/unset the current target id needs to be implemented*/
- /*net_nfc_client_llcp_current_target_id(NULL);*/
-
- if(p2p_signal_handler == NULL)
- return;
-
- if(p2p_signal_handler->p2p_device_detached_cb)
- {
- p2p_signal_handler->p2p_device_detached_cb(
- p2p_signal_handler->p2p_device_detached_data);
- }
-
- /*llcp client function to close all socket needs to be implemented*/
- /*net_nfc_client_llcp_close_all_socket();*/
-}
-
-static void p2p_device_discovered(GObject *source_object,
- guint arg_handle,
- gpointer user_data)
-{
- net_nfc_target_handle_s *handle_info = NULL;
-
- INFO_MSG(">>> SIGNAL arrived");
-
- handle_info = GUINT_TO_POINTER(arg_handle);
-
- if(p2p_signal_handler == NULL)
- return;
-
- if(p2p_signal_handler->p2p_device_discovered_cb)
- {
- p2p_signal_handler->p2p_device_discovered_cb(handle_info,
- p2p_signal_handler->p2p_device_discovered_data);
- }
-}
-
-static void p2p_device_data_received(GObject *source_object,
- GVariant *arg_data,
- gpointer user_data)
-{
- INFO_MSG(">>> SIGNAL arrived");
-
- if (p2p_signal_handler == NULL)
- return;
-
- if (p2p_signal_handler->p2p_data_received_cb)
- {
- data_s p2p_data;
-
- net_nfc_util_gdbus_variant_to_data_s(arg_data, &p2p_data);
-
- p2p_signal_handler->p2p_data_received_cb(&p2p_data,
- p2p_signal_handler->p2p_data_received_data);
-
- net_nfc_util_free_data(&p2p_data);
- }
-}
-
-static void p2p_call_send(GObject *source_object,
- GAsyncResult *res,
- gpointer user_data)
-{
- P2pFuncData *func_data;
-
- net_nfc_error_e out_result = NET_NFC_OK;
- GError *error = NULL;
-
- net_nfc_client_p2p_send_completed callback;
-
- if (net_nfc_gdbus_p2p_call_send_finish(
- NET_NFC_GDBUS_P2P(source_object),
- (gint *)&out_result,
- res,
- &error) == FALSE)
- {
- out_result = NET_NFC_UNKNOWN_ERROR;
-
- DEBUG_ERR_MSG("Can not finish p2p send: %s", error->message);
- g_error_free(error);
- }
-
- func_data = user_data;
- if (func_data == NULL)
- {
- DEBUG_ERR_MSG("can not get P2pFuncData");
- return;
- }
-
- if (func_data->p2p_send_callback == NULL)
- {
- DEBUG_CLIENT_MSG("callback function is not avaiilable");
- g_free(func_data);
- return;
- }
-
- callback = (net_nfc_client_p2p_send_completed)
- func_data->p2p_send_callback;
- callback(out_result, func_data->p2p_send_data);
-
- g_free(func_data);
-}
-
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_p2p_send(net_nfc_exchanger_data_h exchg_data,
- net_nfc_target_handle_h handle,
- net_nfc_client_p2p_send_completed callback,
- void *cb_data)
-{
-
- GVariant *arg_data = NULL;
- P2pFuncData *func_data = NULL;
- net_nfc_exchanger_data_s *exch_data;
-
- if(p2p_proxy == NULL)
- {
- DEBUG_ERR_MSG("Can not get P2pProxy");
- return NET_NFC_UNKNOWN_ERROR;
- }
-
- /* prevent executing daemon when nfc is off */
- if (net_nfc_client_manager_is_activated() == false) {
- return NET_NFC_INVALID_STATE;
- }
-
- func_data = g_new0(P2pFuncData, 1);
-
- func_data->p2p_send_callback = (gpointer)callback;
- func_data->p2p_send_data = cb_data;
-
- exch_data = (net_nfc_exchanger_data_s *)exchg_data;
-
- arg_data = net_nfc_util_gdbus_data_to_variant(&exch_data->binary_data);
-
- net_nfc_gdbus_p2p_call_send(p2p_proxy,
- exch_data->type,
- arg_data,
- GPOINTER_TO_UINT(handle),
- net_nfc_client_gdbus_get_privilege(),
- NULL,
- p2p_call_send,
- func_data);
-
- return NET_NFC_OK;
-}
-
-
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_p2p_send_sync(
- net_nfc_exchanger_data_h exchg_data,
- net_nfc_target_handle_h handle)
-{
- GVariant *arg_data = NULL;
- GError *error = NULL;
- net_nfc_exchanger_data_s *exch_data;
-
- net_nfc_error_e out_result = NET_NFC_OK;
-
- if (p2p_proxy == NULL)
- {
- DEBUG_ERR_MSG("Can not get P2pProxy");
-
- return NET_NFC_UNKNOWN_ERROR;
- }
-
- /* prevent executing daemon when nfc is off */
- if (net_nfc_client_manager_is_activated() == false) {
- return NET_NFC_INVALID_STATE;
- }
-
- exch_data = (net_nfc_exchanger_data_s *)exchg_data;
-
- arg_data = net_nfc_util_gdbus_data_to_variant(&exch_data->binary_data);
-
- if (net_nfc_gdbus_p2p_call_send_sync(p2p_proxy,
- exch_data->type,
- arg_data,
- GPOINTER_TO_UINT(handle),
- net_nfc_client_gdbus_get_privilege(),
- (gint *)&out_result,
- NULL,
- &error) == FALSE)
- {
- DEBUG_ERR_MSG("p2p send (sync call) failed: %s",
- error->message);
-
- g_error_free(error);
- return NET_NFC_UNKNOWN_ERROR;
- }
-
- return out_result;
-}
-
-
-NET_NFC_EXPORT_API
-void net_nfc_client_p2p_set_device_discovered(
- net_nfc_client_p2p_device_discovered callback,
- void *user_data)
-{
- if(p2p_signal_handler == NULL)
- {
- p2p_signal_handler = g_new0(P2pSignalHandler, 1);
- }
-
- p2p_signal_handler->p2p_device_discovered_cb = callback;
- p2p_signal_handler->p2p_device_discovered_data = user_data;
-}
-
-
-NET_NFC_EXPORT_API
-void net_nfc_client_p2p_set_device_detached(
- net_nfc_client_p2p_device_detached callback,
- void *user_data)
-{
- if(p2p_signal_handler == NULL)
- {
- p2p_signal_handler = g_new0(P2pSignalHandler, 1);
- }
-
- p2p_signal_handler->p2p_device_detached_cb = callback;
- p2p_signal_handler->p2p_device_detached_data = user_data;
-}
-
-
-NET_NFC_EXPORT_API
-void net_nfc_client_p2p_set_data_received(
- net_nfc_client_p2p_data_received callback,
- void *user_data)
-{
- if(p2p_signal_handler == NULL)
- {
- p2p_signal_handler = g_new0(P2pSignalHandler, 1);
- }
-
- p2p_signal_handler->p2p_data_received_cb = callback;
- p2p_signal_handler->p2p_data_received_data = user_data;
-}
-
-
-NET_NFC_EXPORT_API
-void net_nfc_client_p2p_unset_device_discovered(void)
-{
- if(p2p_signal_handler == NULL)
- {
- DEBUG_ERR_MSG("p2p_signal_handler is not initialized");
- return;
- }
-
- else
- {
- p2p_signal_handler->p2p_device_discovered_cb = NULL;
- p2p_signal_handler->p2p_device_discovered_data = NULL;
- g_free(p2p_signal_handler);
- p2p_signal_handler = NULL;
- }
-}
-
-
-NET_NFC_EXPORT_API
-void net_nfc_client_p2p_unset_device_detached(void)
-{
- if(p2p_signal_handler == NULL)
- {
- DEBUG_ERR_MSG("p2p_signal_handler is not initialized");
- return;
- }
-
- else
- {
- p2p_signal_handler->p2p_device_detached_cb = NULL;
- p2p_signal_handler->p2p_device_detached_data = NULL;
- }
-}
-
-
-NET_NFC_EXPORT_API
-void net_nfc_client_p2p_unset_data_received(void)
-{
- if(p2p_signal_handler == NULL)
- {
- DEBUG_ERR_MSG("p2p_signal_handler is not initialized");
- return;
- }
-
- else
- {
- p2p_signal_handler->p2p_data_received_cb = NULL;
- p2p_signal_handler->p2p_data_received_data = NULL;
- }
-}
-
-net_nfc_error_e net_nfc_client_p2p_init(void)
-{
- GError *error = NULL;
-
- if (p2p_proxy)
- {
- DEBUG_CLIENT_MSG("Already initialized");
-
- return NET_NFC_OK;
- }
-
- p2p_proxy = net_nfc_gdbus_p2p_proxy_new_for_bus_sync(
- G_BUS_TYPE_SYSTEM,
- G_DBUS_PROXY_FLAGS_NONE,
- "org.tizen.NetNfcService",
- "/org/tizen/NetNfcService/P2p",
- NULL,
- &error);
- if (p2p_proxy == NULL)
- {
- DEBUG_ERR_MSG("Can not create proxy : %s", error->message);
- g_error_free(error);
-
- return NET_NFC_UNKNOWN_ERROR;
- }
-
- g_signal_connect(p2p_proxy, "detached",
- G_CALLBACK(p2p_device_detached), NULL);
-
- g_signal_connect(p2p_proxy, "discovered",
- G_CALLBACK(p2p_device_discovered), NULL);
-
- g_signal_connect(p2p_proxy, "received",
- G_CALLBACK(p2p_device_data_received), NULL);
-
- return NET_NFC_OK;
-}
-
-void net_nfc_client_p2p_deinit(void)
-{
- if(p2p_proxy)
- {
- g_object_unref(p2p_proxy);
- p2p_proxy = NULL;
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "net_nfc_typedef_internal.h"
-#include "net_nfc_debug_internal.h"
-#include "net_nfc_util_internal.h"
-#include "net_nfc_util_ndef_message.h"
-#include "net_nfc_util_gdbus_internal.h"
-#include "net_nfc_gdbus.h"
-#include "net_nfc_client.h"
-#include "net_nfc_client_manager.h"
-#include "net_nfc_client_se.h"
-
-
-#ifndef NET_NFC_EXPORT_API
-#define NET_NFC_EXPORT_API __attribute__((visibility("default")))
-#endif
-
-typedef struct _SeFuncData SeFuncData;
-
-struct _SeFuncData
-{
- gpointer se_callback;
- gpointer se_data;
-};
-
-typedef struct _SeEventHandler SeEventHandler;
-
-struct _SeEventHandler
-{
- net_nfc_client_se_event se_event_cb;
- gpointer se_event_data;
-};
-
-typedef struct _SeTransEventHandler SeTransEventHandler;
-
-struct _SeTransEventHandler
-{
- net_nfc_client_se_transaction_event se_transaction_event_cb;
- gpointer se_transaction_event_data;
-};
-
-typedef struct _SeESEDetectedHandler SeESEDetectedHandler;
-
-struct _SeESEDetectedHandler
-{
- net_nfc_client_se_ese_detected_event se_ese_detected_cb;
- gpointer se_ese_detected_data;
-};
-
-
-static NetNfcGDbusSecureElement *se_proxy = NULL;
-
-static SeEventHandler se_eventhandler;
-static SeTransEventHandler se_transeventhandler;
-static SeESEDetectedHandler se_esedetecthandler;
-
-static void se_ese_detected(GObject *source_object,
- guint arg_handle,
- gint arg_se_type,
- GVariant *arg_data);
-
-static void se_type_changed(GObject *source_object,
- gint arg_se_type);
-
-static void set_secure_element(GObject *source_object,
- GAsyncResult *res,
- gpointer user_data);
-
-static void open_secure_element(GObject *source_object,
- GAsyncResult *res,
- gpointer user_data);
-
-static void close_secure_element(GObject *source_object,
- GAsyncResult *res,
- gpointer user_data);
-
-static void send_apdu_secure_element(GObject *source_object,
- GAsyncResult *res,
- gpointer user_data);
-
-static void get_atr_secure_element(GObject *source_object,
- GAsyncResult *res,
- gpointer user_data);
-
-
-static void se_ese_detected(GObject *source_object,
- guint arg_handle,
- gint arg_se_type,
- GVariant *arg_data)
-{
- INFO_MSG(">>> SIGNAL arrived");
-
- if (se_esedetecthandler.se_ese_detected_cb != NULL) {
- data_s buffer_data = { NULL, 0 };
- net_nfc_client_se_ese_detected_event callback =
- (net_nfc_client_se_ese_detected_event)se_esedetecthandler.se_ese_detected_cb;
-
- net_nfc_util_gdbus_variant_to_data_s(arg_data, &buffer_data);
-
- callback((net_nfc_target_handle_h)arg_handle,
- arg_se_type, &buffer_data,
- se_esedetecthandler.se_ese_detected_data);
-
- net_nfc_util_free_data(&buffer_data);
- }
-}
-
-
-static void se_type_changed(GObject *source_object,
- gint arg_se_type)
-{
- INFO_MSG(">>> SIGNAL arrived");
-
- if (se_eventhandler.se_event_cb != NULL)
- {
- net_nfc_client_se_event callback =
- (net_nfc_client_se_event)se_eventhandler.se_event_cb;
-
- callback((net_nfc_message_e)arg_se_type,
- se_eventhandler.se_event_data);
- }
-}
-
-
-static void se_transaction_event(GObject *source_object,
- gint arg_se_type,
- GVariant *arg_aid,
- GVariant *arg_param)
-{
- INFO_MSG(">>> SIGNAL arrived");
-
- if (se_transeventhandler.se_transaction_event_cb != NULL) {
- net_nfc_client_se_transaction_event callback =
- (net_nfc_client_se_transaction_event)se_transeventhandler.se_transaction_event_cb;
- data_s aid = { NULL, 0 };
- data_s param = { NULL, 0 };
-
- net_nfc_util_gdbus_variant_to_data_s(arg_aid, &aid);
- net_nfc_util_gdbus_variant_to_data_s(arg_param, ¶m);
-
- callback(&aid, ¶m,
- se_transeventhandler.se_transaction_event_data);
-
- net_nfc_util_free_data(¶m);
- net_nfc_util_free_data(&aid);
- }
-}
-
-
-static void set_secure_element(GObject *source_object,
- GAsyncResult *res,
- gpointer user_data)
-{
- SeFuncData *func_data = (SeFuncData *)user_data;
- net_nfc_error_e result;
- GError *error = NULL;
-
- g_assert(user_data != NULL);
-
- if (net_nfc_gdbus_secure_element_call_set_finish(se_proxy,
- &result,
- res,
- &error) == FALSE)
- {
- result = NET_NFC_IPC_FAIL;
-
- DEBUG_ERR_MSG("Could not set secure element: %s",
- error->message);
-
- g_error_free(error);
- }
-
- if (func_data->se_callback != NULL)
- {
- net_nfc_se_set_se_cb se_callback =
- (net_nfc_se_set_se_cb)func_data->se_callback;
-
- se_callback(result, func_data->se_data);
- }
-
- g_free(func_data);
-}
-
-
-static void open_secure_element(GObject *source_object,
- GAsyncResult *res,
- gpointer user_data)
-{
- SeFuncData *func_data = (SeFuncData *)user_data;
- net_nfc_error_e result;
- GError *error = NULL;
- guint out_handle;
-
- g_assert(user_data != NULL);
-
- if (net_nfc_gdbus_secure_element_call_open_secure_element_finish(
- se_proxy,
- &result,
- &out_handle,
- res,
- &error) == FALSE)
- {
- result = NET_NFC_IPC_FAIL;
-
- DEBUG_ERR_MSG("Could not open secure element: %s",
- error->message);
-
- g_error_free(error);
- }
-
- if (func_data->se_callback != NULL)
- {
- net_nfc_se_open_se_cb se_callback =
- (net_nfc_se_open_se_cb)func_data->se_callback;
-
- se_callback(result,
- (net_nfc_target_handle_h)out_handle,
- func_data->se_data);
- }
-
- g_free(func_data);
-}
-
-
-static void close_secure_element(GObject *source_object,
- GAsyncResult *res,
- gpointer user_data)
-{
- SeFuncData *func_data = (SeFuncData *)user_data;
- net_nfc_error_e result;
- GError *error = NULL;
-
- g_assert(user_data != NULL);
-
- if (net_nfc_gdbus_secure_element_call_close_secure_element_finish(
- se_proxy,
- &result,
- res,
- &error) == FALSE)
- {
- result = NET_NFC_IPC_FAIL;
-
- DEBUG_ERR_MSG("Could not close secure element: %s", error->message);
-
- g_error_free(error);
- }
-
- if (func_data->se_callback != NULL)
- {
- net_nfc_se_close_se_cb se_callback =
- (net_nfc_se_close_se_cb)func_data->se_callback;
-
- se_callback(result, func_data->se_data);
- }
-
- g_free(func_data);
-}
-
-
-static void send_apdu_secure_element(GObject *source_object,
- GAsyncResult *res,
- gpointer user_data)
-{
- SeFuncData *func_data = (SeFuncData *)user_data;
- net_nfc_error_e result;
- GVariant *out_response;
- GError *error = NULL;
-
- g_assert(user_data != NULL);
-
- if (net_nfc_gdbus_secure_element_call_send_apdu_finish(
- se_proxy,
- &result,
- &out_response,
- res,
- &error) == FALSE)
- {
- result = NET_NFC_IPC_FAIL;
-
- DEBUG_ERR_MSG("Could not send apdu: %s", error->message);
-
- g_error_free(error);
- }
-
- if (func_data->se_callback != NULL)
- {
- net_nfc_se_send_apdu_cb se_callback =
- (net_nfc_se_send_apdu_cb)func_data->se_callback;
- data_s data = { NULL, };
-
- net_nfc_util_gdbus_variant_to_data_s(out_response, &data);
-
- se_callback(result, &data, func_data->se_data);
-
- net_nfc_util_free_data(&data);
- }
-
- g_free(func_data);
-}
-
-
-static void get_atr_secure_element(GObject *source_object,
- GAsyncResult *res,
- gpointer user_data)
-{
- SeFuncData *func_data = (SeFuncData *)user_data;
- net_nfc_error_e result;
- GVariant *out_atr;
- GError *error = NULL;
-
- g_assert(user_data != NULL);
-
- if (net_nfc_gdbus_secure_element_call_get_atr_finish(
- se_proxy,
- &result,
- &out_atr,
- res,
- &error) == FALSE)
- {
- result = NET_NFC_IPC_FAIL;
-
- DEBUG_ERR_MSG("Could not get atr: %s", error->message);
-
- g_error_free(error);
- }
-
- if (func_data->se_callback != NULL)
- {
- net_nfc_se_get_atr_cb se_callback =
- (net_nfc_se_get_atr_cb)func_data->se_callback;
- data_s data = { NULL, };
-
- net_nfc_util_gdbus_variant_to_data_s(out_atr, &data);
-
- se_callback(result, &data, func_data->se_data);
-
- net_nfc_util_free_data(&data);
- }
-
- g_free(func_data);
-}
-
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_se_set_secure_element_type(
- net_nfc_se_type_e se_type,
- net_nfc_se_set_se_cb callback,
- void *user_data)
-{
- SeFuncData *func_data;
-
- if (se_proxy == NULL)
- {
- DEBUG_ERR_MSG("Can not get se_proxy");
-
- return NET_NFC_NOT_INITIALIZED;
- }
-
- /* prevent executing daemon when nfc is off */
- if (net_nfc_client_manager_is_activated() == false) {
- return NET_NFC_INVALID_STATE;
- }
-
- func_data = g_new0(SeFuncData, 1);
- if (func_data == NULL)
- return NET_NFC_ALLOC_FAIL;
-
- func_data->se_callback = (gpointer)callback;
- func_data->se_data = user_data;
-
- net_nfc_gdbus_secure_element_call_set(
- se_proxy,
- (gint)se_type,
- net_nfc_client_gdbus_get_privilege(),
- NULL,
- set_secure_element,
- func_data);
-
- return NET_NFC_OK;
-}
-
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_se_set_secure_element_type_sync(
- net_nfc_se_type_e se_type)
-{
- net_nfc_error_e result;
- GError *error = NULL;
-
- if (se_proxy == NULL)
- {
- DEBUG_ERR_MSG("Can not get se_proxy");
-
- return NET_NFC_NOT_INITIALIZED;
- }
-
- /* prevent executing daemon when nfc is off */
- if (net_nfc_client_manager_is_activated() == false) {
- return NET_NFC_INVALID_STATE;
- }
-
- if (net_nfc_gdbus_secure_element_call_set_sync(
- se_proxy,
- (gint)se_type,
- net_nfc_client_gdbus_get_privilege(),
- &result,
- NULL,
- &error) == FALSE)
- {
- DEBUG_ERR_MSG("Set secure element failed: %s", error->message);
-
- g_error_free(error);
-
- result = NET_NFC_IPC_FAIL;
- }
-
- return result;
-}
-
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_se_open_internal_secure_element(
- net_nfc_se_type_e se_type,
- net_nfc_se_open_se_cb callback,
- void *user_data)
-{
- SeFuncData *func_data;
-
- if (se_proxy == NULL)
- {
- DEBUG_ERR_MSG("Can not get se_proxy");
-
- return NET_NFC_NOT_INITIALIZED;
- }
-
- /* allow this function even nfc is off */
-
- func_data = g_new0(SeFuncData, 1);
- if (func_data == NULL)
- return NET_NFC_ALLOC_FAIL;
-
- func_data->se_callback = (gpointer)callback;
- func_data->se_data = user_data;
-
- net_nfc_gdbus_secure_element_call_open_secure_element(
- se_proxy,
- (gint)se_type,
- net_nfc_client_gdbus_get_privilege(),
- NULL,
- open_secure_element,
- user_data);
-
- return NET_NFC_OK;
-}
-
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_se_open_internal_secure_element_sync(
- net_nfc_se_type_e se_type,
- net_nfc_target_handle_h *handle)
-{
- net_nfc_error_e result;
- guint out_handle;
- GError *error = NULL;
-
- if (handle == NULL) {
- return NET_NFC_NULL_PARAMETER;
- }
-
- if (se_proxy == NULL)
- {
- DEBUG_ERR_MSG("Can not get se_proxy");
-
- return NET_NFC_NOT_INITIALIZED;
- }
-
- /* allow this function even nfc is off */
-
- if (net_nfc_gdbus_secure_element_call_open_secure_element_sync(
- se_proxy,
- se_type,
- net_nfc_client_gdbus_get_privilege(),
- &result,
- &out_handle,
- NULL,
- &error) == true) {
- *handle = GUINT_TO_POINTER(out_handle);
- } else {
- DEBUG_ERR_MSG("Open internal secure element failed: %s",
- error->message);
- g_error_free(error);
-
- result = NET_NFC_IPC_FAIL;
- }
-
- return result;
-}
-
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_se_close_internal_secure_element(
- net_nfc_target_handle_h handle,
- net_nfc_se_close_se_cb callback,
- void *user_data)
-{
- SeFuncData *func_data;
-
- if (se_proxy == NULL)
- {
- DEBUG_ERR_MSG("Can not get se_proxy");
-
- return NET_NFC_NOT_INITIALIZED;
- }
-
- /* allow this function even nfc is off */
-
- func_data = g_new0(SeFuncData, 1);
- if (func_data == NULL)
- return NET_NFC_ALLOC_FAIL;
-
- func_data->se_callback = (gpointer)callback;
- func_data->se_data = user_data;
-
- net_nfc_gdbus_secure_element_call_close_secure_element(
- se_proxy,
- GPOINTER_TO_UINT(handle),
- net_nfc_client_gdbus_get_privilege(),
- NULL,
- close_secure_element,
- user_data);
-
- return NET_NFC_OK;
-}
-
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_se_close_internal_secure_element_sync(
- net_nfc_target_handle_h handle)
-{
- net_nfc_error_e result;
- GError *error = NULL;
-
- if (se_proxy == NULL)
- {
- DEBUG_ERR_MSG("Can not get se_proxy");
-
- return NET_NFC_NOT_INITIALIZED;
- }
-
- /* allow this function even nfc is off */
-
- if (net_nfc_gdbus_secure_element_call_close_secure_element_sync(
- se_proxy,
- GPOINTER_TO_UINT(handle),
- net_nfc_client_gdbus_get_privilege(),
- &result,
- NULL,
- &error) == FALSE)
- {
- DEBUG_ERR_MSG("close internal secure element failed: %s",
- error->message);
- g_error_free(error);
-
- result = NET_NFC_IPC_FAIL;
- }
-
- return result;
-}
-
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_se_get_atr(
- net_nfc_target_handle_h handle,
- net_nfc_se_get_atr_cb callback,
- void *user_data)
-{
- SeFuncData *func_data;
-
- if (se_proxy == NULL)
- {
- DEBUG_ERR_MSG("Can not get se_proxy");
-
- return NET_NFC_NOT_INITIALIZED;
- }
-
- /* allow this function even nfc is off */
-
- func_data = g_new0(SeFuncData, 1);
- if (func_data == NULL)
- return NET_NFC_ALLOC_FAIL;
-
- func_data->se_callback = (gpointer)callback;
- func_data->se_data = user_data;
-
- net_nfc_gdbus_secure_element_call_get_atr(
- se_proxy,
- GPOINTER_TO_UINT(handle),
- net_nfc_client_gdbus_get_privilege(),
- NULL,
- get_atr_secure_element,
- func_data);
-
- return NET_NFC_OK;
-}
-
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_se_get_atr_sync(
- net_nfc_target_handle_h handle,
- data_h *atr)
-{
- net_nfc_error_e result;
- GVariant *out_atr;
- GError *error = NULL;
-
- if (atr == NULL) {
- return NET_NFC_NULL_PARAMETER;
- }
-
- *atr = NULL;
-
- if (se_proxy == NULL)
- {
- DEBUG_ERR_MSG("Can not get se_proxy");
-
- return NET_NFC_NOT_INITIALIZED;
- }
-
- /* allow this function even nfc is off */
-
- if (net_nfc_gdbus_secure_element_call_get_atr_sync(
- se_proxy,
- GPOINTER_TO_UINT(handle),
- net_nfc_client_gdbus_get_privilege(),
- &result,
- &out_atr,
- NULL,
- &error) == true) {
- *atr = net_nfc_util_gdbus_variant_to_data(out_atr);
- } else {
- DEBUG_ERR_MSG("Get attributes failed: %s", error->message);
- g_error_free(error);
-
- result = NET_NFC_IPC_FAIL;
- }
-
- return result;
-}
-
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_se_send_apdu(
- net_nfc_target_handle_h handle,
- data_h apdu_data,
- net_nfc_se_send_apdu_cb callback,
- void *user_data)
-{
- SeFuncData *func_data;
- GVariant *arg_data;
-
- if (se_proxy == NULL)
- {
- DEBUG_ERR_MSG("Can not get se_proxy");
-
- return NET_NFC_NOT_INITIALIZED;
- }
-
- /* allow this function even nfc is off */
-
- arg_data = net_nfc_util_gdbus_data_to_variant((data_s *)apdu_data);
- if (arg_data == NULL)
- return NET_NFC_INVALID_PARAM;
-
- func_data = g_new0(SeFuncData, 1);
- if (func_data == NULL) {
- g_variant_unref(arg_data);
-
- return NET_NFC_ALLOC_FAIL;
- }
-
- func_data->se_callback = (gpointer)callback;
- func_data->se_data = user_data;
-
- net_nfc_gdbus_secure_element_call_send_apdu(
- se_proxy,
- GPOINTER_TO_UINT(handle),
- arg_data,
- net_nfc_client_gdbus_get_privilege(),
- NULL,
- send_apdu_secure_element,
- func_data);
-
- return NET_NFC_OK;
-}
-
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_se_send_apdu_sync(
- net_nfc_target_handle_h handle,
- data_h apdu_data,
- data_h *response)
-{
- net_nfc_error_e result;
- GVariant *out_data;
- GVariant *arg_data;
- GError *error = NULL;
-
- if (response == NULL) {
- return NET_NFC_NULL_PARAMETER;
- }
-
- *response = NULL;
-
- if (se_proxy == NULL)
- {
- DEBUG_ERR_MSG("Can not get se_proxy");
-
- return NET_NFC_NOT_INITIALIZED;
- }
-
- /* allow this function even nfc is off */
-
- arg_data = net_nfc_util_gdbus_data_to_variant((data_s *)apdu_data);
- if (arg_data == NULL)
- return NET_NFC_INVALID_PARAM;
-
- if (net_nfc_gdbus_secure_element_call_send_apdu_sync(
- se_proxy,
- GPOINTER_TO_UINT(handle),
- arg_data,
- net_nfc_client_gdbus_get_privilege(),
- &result,
- &out_data,
- NULL,
- &error) == true) {
- *response = net_nfc_util_gdbus_variant_to_data(out_data);
- } else {
- DEBUG_ERR_MSG("Send APDU failed: %s",
- error->message);
- g_error_free(error);
-
- result = NET_NFC_IPC_FAIL;
- }
-
- return result;
-}
-
-
-NET_NFC_EXPORT_API
-void net_nfc_client_se_set_ese_detection_cb(
- net_nfc_client_se_ese_detected_event callback,
- void *user_data)
-{
- se_esedetecthandler.se_ese_detected_cb = callback;
- se_esedetecthandler.se_ese_detected_data = user_data;
-}
-
-
-NET_NFC_EXPORT_API
-void net_nfc_client_se_unset_ese_detection_cb(void)
-{
- net_nfc_client_se_set_ese_detection_cb(NULL, NULL);
-}
-
-
-NET_NFC_EXPORT_API
-void net_nfc_client_se_set_transaction_event_cb(
- net_nfc_client_se_transaction_event callback,
- void *user_data)
-{
- se_transeventhandler.se_transaction_event_cb = callback;
- se_transeventhandler.se_transaction_event_data = user_data;
-}
-
-
-NET_NFC_EXPORT_API
-void net_nfc_client_se_unset_transaction_event_cb(void)
-{
- net_nfc_client_se_set_transaction_event_cb(NULL, NULL);
-}
-
-
-NET_NFC_EXPORT_API
-void net_nfc_client_se_set_event_cb(net_nfc_client_se_event callback,
- void *user_data)
-{
- se_eventhandler.se_event_cb = callback;
- se_eventhandler.se_event_data = user_data;
-}
-
-
-NET_NFC_EXPORT_API
-void net_nfc_client_se_unset_event_cb(void)
-{
- net_nfc_client_se_set_event_cb(NULL, NULL);
-}
-
-
-net_nfc_error_e net_nfc_client_se_init(void)
-{
- GError *error = NULL;
-
- if (se_proxy)
- {
- DEBUG_CLIENT_MSG("Already initialized");
-
- return NET_NFC_OK;
- }
-
- se_proxy = net_nfc_gdbus_secure_element_proxy_new_for_bus_sync(
- G_BUS_TYPE_SYSTEM,
- G_DBUS_PROXY_FLAGS_NONE,
- "org.tizen.NetNfcService",
- "/org/tizen/NetNfcService/SecureElement",
- NULL,
- &error);
- if (se_proxy == NULL)
- {
- DEBUG_ERR_MSG("Can not create proxy : %s", error->message);
-
- g_error_free(error);
-
- return NET_NFC_UNKNOWN_ERROR;
- }
-
- g_signal_connect(se_proxy, "se-type-changed",
- G_CALLBACK(se_type_changed), NULL);
-
- g_signal_connect(se_proxy, "ese-detected",
- G_CALLBACK(se_ese_detected), NULL);
-
- g_signal_connect(se_proxy, "transaction-event",
- G_CALLBACK(se_transaction_event), NULL);
-
- return NET_NFC_OK;
-}
-
-
-void net_nfc_client_se_deinit(void)
-{
- if (se_proxy)
- {
- g_object_unref(se_proxy);
- se_proxy = NULL;
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
-
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-#include "net_nfc_util_sign_record.h"
-
-#ifndef NET_NFC_EXPORT_API
-#define NET_NFC_EXPORT_API __attribute__((visibility("default")))
-#endif
-
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_sign_records(ndef_message_h msg, int begin_index, int end_index, char *cert_file, char *password)
-{
- return net_nfc_util_sign_records((ndef_message_s *)msg, begin_index, end_index, cert_file, password);
-}
-
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_sign_ndef_message(ndef_message_h msg, char *cert_file, char *password)
-{
- return net_nfc_util_sign_ndef_message((ndef_message_s *)msg, cert_file, password);
-}
-
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_verify_signature_ndef_message(ndef_message_h msg)
-{
- return net_nfc_util_verify_signature_ndef_message((ndef_message_s *)msg);
-}
-
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_verify_signature_records(ndef_record_h begin_record, ndef_record_h sign_record)
-{
- return net_nfc_util_verify_signature_records((ndef_record_s *)begin_record, (ndef_record_s *)sign_record);
-}
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "net_nfc_typedef_internal.h"
-#include "net_nfc_debug_internal.h"
-#include "net_nfc_util_internal.h"
-#include "net_nfc_util_ndef_message.h"
-#include "net_nfc_util_gdbus_internal.h"
-#include "net_nfc_gdbus.h"
-#include "net_nfc_data.h"
-#include "net_nfc_ndef_message.h"
-#include "net_nfc_client.h"
-#include "net_nfc_client_manager.h"
-#include "net_nfc_client_snep.h"
-
-#ifndef NET_NFC_EXPORT_API
-#define NET_NFC_EXPORT_API __attribute__((visibility("default")))
-#endif
-
-static NetNfcGDbusSnep *snep_proxy = NULL;
-
-/*******************************************************************/
-
-static GVariant *snep_message_to_variant(ndef_message_h message);
-
-static ndef_message_h snep_variant_to_message(GVariant *variant);
-
-/*********************************************************************/
-
-static void snep_send_client_request(GObject *source_object,
- GAsyncResult *res,
- gpointer user_data);
-
-/*********************************************************************/
-
-static GVariant *snep_message_to_variant(ndef_message_h message)
-{
- data_h data = NULL;
- GVariant *variant = NULL;
-
- if (net_nfc_create_rawdata_from_ndef_message(message,
- &data) != NET_NFC_OK)
- {
- DEBUG_ERR_MSG("can not convert ndef_message to rawdata");
- return NULL;
- }
-
- variant = net_nfc_util_gdbus_data_to_variant((data_s *)data);
-
- net_nfc_free_data(data);
-
- return variant;
-}
-
-static ndef_message_h snep_variant_to_message(GVariant *variant)
-{
- data_s data = { NULL, };
- ndef_message_h message = NULL;
-
- net_nfc_util_gdbus_variant_to_data_s(variant, &data);
-
- if (data.buffer && data.length > 0)
- {
- if (net_nfc_create_ndef_message_from_rawdata(&message, &data)
- != NET_NFC_OK)
- {
- DEBUG_ERR_MSG("memory alloc fail...");
- }
-
- net_nfc_util_free_data(&data);
- }
-
- return message;
-}
-
-static void snep_send_client_request(GObject *source_object,
- GAsyncResult *res,
- gpointer user_data)
-{
- GVariant *parameter = (GVariant *)user_data;
- GError *error = NULL;
- net_nfc_error_e out_result;
- net_nfc_snep_type_t out_type;
- GVariant *out_data;
-
- if (net_nfc_gdbus_snep_call_client_request_finish(
- NET_NFC_GDBUS_SNEP(source_object),
- (gint *)&out_result,
- (guint *)&out_type,
- &out_data,
- res,
- &error) == FALSE)
- {
- DEBUG_ERR_MSG("Can not finish send client request %s",
- error->message);
- g_error_free(error);
-
- out_result = NET_NFC_UNKNOWN_ERROR;
- }
-
- if (parameter != NULL) {
- net_nfc_client_snep_event_cb callback;
- void *user_param;
- net_nfc_snep_handle_h handle;
- ndef_message_h message = NULL;
-
- g_variant_get(parameter, "(uuu)",
- (guint *)&callback,
- (guint *)&user_param,
- (guint *)&handle);
-
- if (callback != NULL) {
- message = snep_variant_to_message(out_data);
-
- callback(handle, out_type, out_result,
- message, user_param);
- }
-
- g_object_unref(parameter);
- }
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_snep_start_server(
- net_nfc_target_handle_h target,
- const char *san,
- sap_t sap,
- net_nfc_client_snep_event_cb callback,
- void *user_data)
-{
- net_nfc_error_e result = NET_NFC_OK;
- GError *error = NULL;
- GVariant *parameter;
-
- if (snep_proxy == NULL)
- {
- DEBUG_ERR_MSG("Can not get Snep Proxy");
-
- return NET_NFC_UNKNOWN_ERROR;
- }
-
- /* prevent executing daemon when nfc is off */
- if (net_nfc_client_manager_is_activated() == false) {
- return NET_NFC_INVALID_STATE;
- }
-
- parameter = g_variant_new("(uu)",
- GPOINTER_TO_UINT(callback),
- GPOINTER_TO_UINT(user_data));
-
- g_object_ref(parameter);
-
- if (net_nfc_gdbus_snep_call_server_start_sync(snep_proxy,
- GPOINTER_TO_UINT(target),
- sap,
- san,
- GPOINTER_TO_UINT(parameter),
- net_nfc_client_gdbus_get_privilege(),
- (gint *)&result,
- NULL,
- &error) == FALSE)
- {
- DEBUG_ERR_MSG("snep server(sync call) failed: %s",
- error->message);
- g_error_free(error);
- g_object_unref(parameter);
-
- result = NET_NFC_UNKNOWN_ERROR;
- }
-
- return result;
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_snep_start_client(
- net_nfc_target_handle_h target,
- const char *san,
- sap_t sap,
- net_nfc_client_snep_event_cb callback,
- void *user_data)
-{
- net_nfc_error_e result = NET_NFC_OK;
- GError *error = NULL;
- GVariant *parameter;
-
- if (snep_proxy == NULL)
- {
- DEBUG_ERR_MSG("Can not get Snep Proxy");
-
- return NET_NFC_UNKNOWN_ERROR;
- }
-
- /* prevent executing daemon when nfc is off */
- if (net_nfc_client_manager_is_activated() == false) {
- return NET_NFC_INVALID_STATE;
- }
-
- parameter = g_variant_new("(uu)",
- GPOINTER_TO_UINT(callback),
- GPOINTER_TO_UINT(user_data));
-
- g_object_ref(parameter);
-
- if (net_nfc_gdbus_snep_call_client_start_sync(snep_proxy,
- GPOINTER_TO_UINT(target),
- sap,
- san,
- GPOINTER_TO_UINT(parameter),
- net_nfc_client_gdbus_get_privilege(),
- (gint *)&result,
- NULL,
- &error) == FALSE)
- {
- DEBUG_ERR_MSG("snep client(sync call) failed: %s",
- error->message);
- g_error_free(error);
- g_object_unref(parameter);
-
- result = NET_NFC_UNKNOWN_ERROR;
- }
-
- return result;
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_snep_send_client_request(
- net_nfc_snep_handle_h target,
- net_nfc_snep_type_t snep_type,
- ndef_message_h msg,
- net_nfc_client_snep_event_cb callback,
- void *user_data)
-{
- GVariant *ndef_msg = NULL;
- GVariant *parameter;
-
- if (target == NULL || msg == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
-
- if (snep_proxy == NULL)
- {
- DEBUG_ERR_MSG("Can not get Snep Proxy");
-
- return NET_NFC_NOT_INITIALIZED;
- }
-
- /* prevent executing daemon when nfc is off */
- if (net_nfc_client_manager_is_activated() == false) {
- return NET_NFC_INVALID_STATE;
- }
-
- parameter = g_variant_new("(uuu)",
- GPOINTER_TO_UINT(callback),
- GPOINTER_TO_UINT(user_data),
- GPOINTER_TO_UINT(target));
-
- g_object_ref(parameter);
-
- ndef_msg = snep_message_to_variant(msg);
-
- net_nfc_gdbus_snep_call_client_request(snep_proxy,
- GPOINTER_TO_UINT(target),
- snep_type,
- ndef_msg,
- net_nfc_client_gdbus_get_privilege(),
- NULL,
- snep_send_client_request,
- parameter);
-
- return NET_NFC_OK;
-}
-#if 0
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_snep_send_client_request_sync(
- net_nfc_target_handle_h target,
- net_nfc_snep_type_t snep_type,
- ndef_message_h msg,
- net_nfc_snep_type_t *resp_type,
- ndef_message_h *response)
-{
- GVariant *resp_msg = NULL;
- GVariant *arg_msg = NULL;
- GError *error = NULL;
- net_nfc_error_e result;
- guint type;
-
- if (target == NULL || msg == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
-
- if (snep_proxy == NULL)
- {
- DEBUG_ERR_MSG("Can not get Snep Proxy");
-
- return NET_NFC_NOT_INITIALIZED;
- }
-
- arg_msg = snep_message_to_variant(msg);
-
- if (net_nfc_gdbus_snep_call_client_request_sync(snep_proxy,
- GPOINTER_TO_UINT(target),
- snep_type,
- arg_msg,
- net_nfc_client_gdbus_get_privilege(),
- &result,
- resp_type,
- &resp_msg,
- NULL,
- &error) == FALSE)
- {
- DEBUG_ERR_MSG(" send client request (sync call) failed: %s",
- error->message);
- g_error_free(error);
-
- return NET_NFC_IPC_FAIL;
- }
-
- *response = NULL;
-
- if (result == NET_NFC_OK)
- {
- data_s ndef_data = { NULL, };
-
- net_nfc_util_gdbus_variant_to_data_s(resp_msg, &ndef_data);
-
- if (ndef_data.buffer != NULL && ndef_data.length > 0)
- {
- result = net_nfc_create_ndef_message_from_rawdata(
- response,
- &ndef_data);
-
- net_nfc_util_free_data(&ndef_data);
- }
- }
-
- return result;
-}
-#endif
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_snep_stop_service_sync(
- net_nfc_target_handle_h target,
- net_nfc_snep_handle_h service)
-{
- net_nfc_error_e result = NET_NFC_OK;
- GError *error = NULL;
-
- if (target == NULL || service == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
-
- if (snep_proxy == NULL)
- {
- DEBUG_ERR_MSG("Can not get Snep Proxy");
-
- return NET_NFC_NOT_INITIALIZED;
- }
-
- /* prevent executing daemon when nfc is off */
- if (net_nfc_client_manager_is_activated() == false) {
- return NET_NFC_INVALID_STATE;
- }
-
- if (net_nfc_gdbus_snep_call_stop_snep_sync(
- snep_proxy,
- GPOINTER_TO_UINT(target),
- GPOINTER_TO_UINT(service),
- net_nfc_client_gdbus_get_privilege(),
- (gint *)&result,
- NULL,
- &error) == FALSE)
- {
- DEBUG_ERR_MSG("snep stop service(sync call) failed: %s",
- error->message);
- g_error_free(error);
-
- return NET_NFC_IPC_FAIL;
- }
-
- return result;
-}
-
-static void _snep_event_cb(NetNfcGDbusSnep *object,
- guint arg_handle,
- guint arg_event,
- gint arg_result,
- GVariant *arg_ndef_msg,
- guint arg_user_data)
-{
- GVariant *parameter = (GVariant *)GUINT_TO_POINTER(arg_user_data);
-
- INFO_MSG(">>> SIGNAL arrived");
-
- DEBUG_CLIENT_MSG("handle [%p], event [%d], result [%d], user_data [%p]",
- GUINT_TO_POINTER(arg_handle),
- arg_event,
- arg_result,
- parameter);
-
- if (parameter != NULL)
- {
- net_nfc_client_snep_event_cb callback;
- void *user_data;
-
- g_variant_get(parameter,
- "(uu)",
- &callback,
- &user_data);
-
- if (callback != NULL)
- {
- ndef_message_h message =
- snep_variant_to_message(arg_ndef_msg);
-
- callback(GUINT_TO_POINTER(arg_handle),
- arg_event,
- arg_result,
- message,
- user_data);
- }
-
- if (arg_event == NET_NFC_LLCP_UNREGISTERED) {
- g_variant_unref(parameter);
- }
- }
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_snep_register_server(const char *san,
- sap_t sap,
- net_nfc_client_snep_event_cb callback,
- void *user_data)
-{
- net_nfc_error_e result = NET_NFC_OK;
- GError *error = NULL;
- GVariant *parameter;
-
- if (snep_proxy == NULL)
- {
- DEBUG_ERR_MSG("Can not get Snep Proxy");
-
- return NET_NFC_UNKNOWN_ERROR;
- }
-
- /* prevent executing daemon when nfc is off */
- if (net_nfc_client_manager_is_activated() == false) {
- return NET_NFC_INVALID_STATE;
- }
-
- parameter = g_variant_new("(uu)",
- GPOINTER_TO_UINT(callback),
- GPOINTER_TO_UINT(user_data));
-
- if (net_nfc_gdbus_snep_call_server_register_sync(snep_proxy,
- sap,
- san,
- GPOINTER_TO_UINT(parameter),
- net_nfc_client_gdbus_get_privilege(),
- (gint *)&result,
- NULL,
- &error) == FALSE)
- {
- DEBUG_ERR_MSG("snep register server(sync call) failed: %s",
- error->message);
- g_error_free(error);
- g_variant_unref(parameter);
-
- result = NET_NFC_UNKNOWN_ERROR;
- }
-
- return result;
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_snep_unregister_server(const char *san,
- sap_t sap)
-{
- net_nfc_error_e result = NET_NFC_OK;
- GError *error = NULL;
-
- if (snep_proxy == NULL)
- {
- DEBUG_ERR_MSG("Can not get Snep Proxy");
-
- return NET_NFC_UNKNOWN_ERROR;
- }
-
- /* prevent executing daemon when nfc is off */
- if (net_nfc_client_manager_is_activated() == false) {
- return NET_NFC_INVALID_STATE;
- }
-
- if (net_nfc_gdbus_snep_call_server_unregister_sync(snep_proxy,
- sap,
- san,
- net_nfc_client_gdbus_get_privilege(),
- (gint *)&result,
- NULL,
- &error) == FALSE)
- {
- DEBUG_ERR_MSG("snep unregister server(sync call) failed: %s",
- error->message);
- g_error_free(error);
-
- result = NET_NFC_UNKNOWN_ERROR;
- }
-
- return result;
-}
-
-net_nfc_error_e net_nfc_client_snep_init(void)
-{
- GError *error = NULL;
-
- if (snep_proxy)
- {
- DEBUG_CLIENT_MSG("Already initialized");
-
- return NET_NFC_OK;
- }
-
- snep_proxy = net_nfc_gdbus_snep_proxy_new_for_bus_sync(
- G_BUS_TYPE_SYSTEM,
- G_DBUS_PROXY_FLAGS_NONE,
- "org.tizen.NetNfcService",
- "/org/tizen/NetNfcService/Snep",
- NULL,
- &error);
- if (snep_proxy == NULL)
- {
- DEBUG_ERR_MSG("Can not create proxy : %s", error->message);
- g_error_free(error);
-
- return NET_NFC_UNKNOWN_ERROR;
- }
-
- g_signal_connect(snep_proxy, "snep-event",
- G_CALLBACK(_snep_event_cb), NULL);
-
- return NET_NFC_OK;
-}
-
-void net_nfc_client_snep_deinit(void)
-{
- if (snep_proxy)
- {
- g_object_unref(snep_proxy);
- snep_proxy = NULL;
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "Ecore_X.h"
-
-#include "net_nfc_typedef_internal.h"
-#include "net_nfc_debug_internal.h"
-#include "net_nfc_util_ndef_message.h"
-#include "net_nfc_gdbus.h"
-#include "net_nfc_client.h"
-#include "net_nfc_client_manager.h"
-#include "net_nfc_client_system_handler.h"
-
-
-#ifndef NET_NFC_EXPORT_API
-#define NET_NFC_EXPORT_API __attribute__((visibility("default")))
-#endif
-
-typedef struct _PopupFuncData PopupFuncData;
-
-struct _PopupFuncData
-{
- gpointer callback;
- gpointer user_data;
-};
-
-static NetNfcGDbusPopup *popup_proxy = NULL;
-static int popup_state = 0;
-
-static void popup_set_active_callback(GObject *source_object,
- GAsyncResult *res,
- gpointer user_data);
-
-static void popup_set_active_callback(GObject *source_object,
- GAsyncResult *res,
- gpointer user_data)
-{
- PopupFuncData *func_data;
-
- net_nfc_error_e result = NET_NFC_OK;
- GError *error = NULL;
-
- net_nfc_client_popup_set_state_callback callback;
- gpointer data;
-
- if (net_nfc_gdbus_popup_call_set_finish(
- NET_NFC_GDBUS_POPUP(source_object),
- res,
- &error) == FALSE)
- {
-
- result = NET_NFC_UNKNOWN_ERROR;
-
- DEBUG_ERR_MSG("Can not finish popup_set_active: %s",
- error->message);
- g_error_free(error);
- }
-
- func_data = user_data;
- if (func_data == NULL)
- return;
-
- if (func_data->callback == NULL)
- {
- g_free(func_data);
- return;
- }
-
- callback = (net_nfc_client_popup_set_state_callback)
- func_data->callback;
- data = func_data->user_data;
-
- callback(result, data);
-
- g_free(func_data);
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_sys_handler_set_state(int state,
- net_nfc_client_popup_set_state_callback callback,
- void *user_data)
-{
- gboolean active = FALSE;
- PopupFuncData *func_data;
- net_nfc_launch_popup_check_e focus_state = CHECK_FOREGROUND;
-
- if (popup_proxy == NULL )
- return NET_NFC_NOT_INITIALIZED;
-
- /* prevent executing daemon when nfc is off */
- if (net_nfc_client_manager_is_activated() == false) {
- return NET_NFC_INVALID_STATE;
- }
-
- func_data = g_new0(PopupFuncData, 1);
- if (func_data == NULL )
- return NET_NFC_ALLOC_FAIL;
-
- func_data->callback = (gpointer)callback;
- func_data->user_data = user_data;
-
- if (state == true)
- active = TRUE;
-
- net_nfc_gdbus_popup_call_set(popup_proxy,
- active,
- focus_state,
- net_nfc_client_gdbus_get_privilege(),
- NULL,
- popup_set_active_callback,
- func_data);
-
- return NET_NFC_OK;
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_sys_handler_set_state_sync(int state)
-{
- GError *error = NULL;
- net_nfc_launch_popup_check_e focus_state = CHECK_FOREGROUND;
-
- if (popup_proxy == NULL)
- return NET_NFC_NOT_INITIALIZED;
-
- /* prevent executing daemon when nfc is off */
- if (net_nfc_client_manager_is_activated() == false) {
- return NET_NFC_INVALID_STATE;
- }
-
- if (net_nfc_gdbus_popup_call_set_sync(popup_proxy,
- (gboolean)state,
- focus_state,
- net_nfc_client_gdbus_get_privilege(),
- NULL,
- &error) == FALSE)
- {
- DEBUG_CLIENT_MSG("can not call SetActive: %s",
- error->message);
- g_error_free(error);
-
- return NET_NFC_IPC_FAIL;
- }
-
- return NET_NFC_OK;
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_sys_handler_set_state_force(int state,
- net_nfc_client_popup_set_state_callback callback,
- void *user_data)
-{
- gboolean active = FALSE;
- PopupFuncData *func_data;
- net_nfc_launch_popup_check_e focus_state = NO_CHECK_FOREGROUND;
-
- if (popup_proxy == NULL)
- return NET_NFC_NOT_INITIALIZED;
-
- /* prevent executing daemon when nfc is off */
- if (net_nfc_client_manager_is_activated() == false) {
- return NET_NFC_INVALID_STATE;
- }
-
- func_data = g_new0(PopupFuncData, 1);
- if (func_data == NULL)
- return NET_NFC_ALLOC_FAIL;
-
- func_data->callback = (gpointer)callback;
- func_data->user_data = user_data;
-
- if (state == true)
- active = TRUE;
-
- net_nfc_gdbus_popup_call_set(popup_proxy,
- active,
- focus_state,
- net_nfc_client_gdbus_get_privilege(),
- NULL,
- popup_set_active_callback,
- func_data);
-
- return NET_NFC_OK;
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_sys_handler_set_state_force_sync(int state)
-{
- GError *error = NULL;
- net_nfc_launch_popup_check_e focus_state = NO_CHECK_FOREGROUND;
-
- if (popup_proxy == NULL)
- return NET_NFC_NOT_INITIALIZED;
-
- /* prevent executing daemon when nfc is off */
- if (net_nfc_client_manager_is_activated() == false) {
- return NET_NFC_INVALID_STATE;
- }
-
- if (net_nfc_gdbus_popup_call_set_sync(popup_proxy,
- (gboolean)state,
- focus_state,
- net_nfc_client_gdbus_get_privilege(),
- NULL,
- &error) == FALSE)
- {
- DEBUG_CLIENT_MSG("can not call SetActive: %s",
- error->message);
- g_error_free(error);
-
- return NET_NFC_IPC_FAIL;
- }
-
- return NET_NFC_OK;
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_sys_handler_set_launch_popup_state(
- int enable)
-{
- net_nfc_error_e ret;
-
- popup_state = enable;
-
- if (enable)
- {
- ret = net_nfc_client_sys_handler_set_state_sync(
- NET_NFC_LAUNCH_APP_SELECT);
- }
- else
- {
- ret = net_nfc_client_sys_handler_set_state_sync(
- NET_NFC_NO_LAUNCH_APP_SELECT);
- }
-
- return ret;
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_sys_handler_set_launch_popup_state_force(
- int enable)
-{
- net_nfc_error_e ret;
-
- popup_state = enable;
-
- if (enable)
- {
- ret = net_nfc_client_sys_handler_set_state_force_sync(
- NET_NFC_LAUNCH_APP_SELECT);
- }
- else
- {
- ret = net_nfc_client_sys_handler_set_state_force_sync(
- NET_NFC_NO_LAUNCH_APP_SELECT);
- }
-
- return ret;
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_sys_handler_get_launch_popup_state(
- int *state)
-{
- if (state == NULL)
- return NET_NFC_NULL_PARAMETER;
-#if 1
- *state = popup_state;
-#else
- /* TODO : get state from server */
- GError *error = NULL;
-
- if (popup_proxy == NULL) {
- DEBUG_ERR_MSG("popup_proxy is null");
-
- return NET_NFC_NOT_INITIALIZED;
- }
-
- if (net_nfc_gdbus_popup_call_get_sync(popup_proxy,
- net_nfc_client_gdbus_get_privilege(),
- state,
- NULL,
- &error) == false) {
- DEBUG_CLIENT_MSG("net_nfc_gdbus_popup_call_get_sync failed: %s",
- error->message);
- g_error_free(error);
-
- return NET_NFC_IPC_FAIL;
- }
-#endif
- return NET_NFC_OK;
-}
-
-net_nfc_error_e net_nfc_client_sys_handler_init(void)
-{
- GError *error = NULL;
-
- if (popup_proxy)
- {
- DEBUG_CLIENT_MSG("Already initialized");
-
- return NET_NFC_OK;
- }
-
- popup_proxy = net_nfc_gdbus_popup_proxy_new_for_bus_sync(
- G_BUS_TYPE_SYSTEM,
- G_DBUS_PROXY_FLAGS_NONE,
- "org.tizen.NetNfcService",
- "/org/tizen/NetNfcService/Popup",
- NULL,
- &error);
- if (popup_proxy == NULL)
- {
- DEBUG_ERR_MSG("Can not create proxy : %s", error->message);
- g_error_free(error);
-
- return NET_NFC_OPERATION_FAIL;
- }
-
- return NET_NFC_OK;
-}
-
-void net_nfc_client_sys_handler_deinit(void)
-{
- if (popup_proxy)
- {
- g_object_unref(popup_proxy);
- popup_proxy = NULL;
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#include "net_nfc_typedef_internal.h"
-#include "net_nfc_debug_internal.h"
-#include "net_nfc_util_gdbus_internal.h"
-#include "net_nfc_gdbus.h"
-#include "net_nfc_data.h"
-#include "net_nfc_target_info.h"
-#include "net_nfc_client.h"
-#include "net_nfc_client_manager.h"
-#include "net_nfc_client_tag.h"
-#include "net_nfc_client_tag_internal.h"
-
-#ifndef NET_NFC_EXPORT_API
-#define NET_NFC_EXPORT_API __attribute__((visibility("default")))
-#endif
-
-typedef struct _TagFuncData TagFuncData;
-
-struct _TagFuncData
-{
- gpointer callback;
- gpointer user_data;
-};
-
-static NetNfcGDbusTag *tag_proxy = NULL;
-
-static TagFuncData *tag_discovered_func_data = NULL;
-static TagFuncData *tag_detached_func_data = NULL;
-
-static net_nfc_target_info_s *client_target_info = NULL;
-static net_nfc_event_filter_e client_filter = NET_NFC_ALL_ENABLE;
-
-static gboolean tag_check_filter(net_nfc_target_type_e type);
-
-static void tag_get_info_list(guint8 *buffer,
- gint number_of_keys,
- net_nfc_tag_info_s **list);
-
-static void tag_get_target_info(guint handle,
- guint dev_type,
- gboolean is_ndef_supported,
- guchar ndef_card_state,
- guint max_data_size,
- guint actual_data_size,
- guint number_of_keys,
- GVariant *target_info_values,
- GVariant *raw_data,
- net_nfc_target_info_s **info);
-
-
-/* async callback */
-static void tag_is_tag_connected(GObject *source_object,
- GAsyncResult *res,
- gpointer user_data);
-
-static void tag_get_current_tag_info(GObject *source_object,
- GAsyncResult *res,
- gpointer user_data);
-
-static void tag_get_current_target_handle(GObject *source_object,
- GAsyncResult *res,
- gpointer user_data);
-
-/* signal callback */
-static void tag_tag_discovered(NetNfcGDbusTag *object,
- guint arg_handle,
- gint arg_dev_type,
- gboolean arg_is_ndef_supported,
- guchar arg_ndef_card_state,
- guint arg_max_data_size,
- guint arg_actual_data_size,
- guint arg_number_of_keys,
- GVariant *arg_target_info_values,
- GVariant *arg_raw_data,
- gpointer user_data);
-
-static void tag_tag_detached(NetNfcGDbusTag *object,
- guint arg_handle,
- gint arg_dev_type,
- gpointer user_data);
-
-static gboolean tag_check_filter(net_nfc_target_type_e type)
-{
- net_nfc_event_filter_e converted = NET_NFC_ALL_ENABLE;
-
- DEBUG_CLIENT_MSG("client filter = %d", client_filter);
-
- if (type >= NET_NFC_ISO14443_A_PICC &&
- type <= NET_NFC_MIFARE_DESFIRE_PICC)
- {
- converted = NET_NFC_ISO14443A_ENABLE;
- }
- else if (type >= NET_NFC_ISO14443_B_PICC &&
- type <= NET_NFC_ISO14443_BPRIME_PICC)
- {
- converted = NET_NFC_ISO14443B_ENABLE;
- }
- else if (type == NET_NFC_FELICA_PICC)
- {
- converted = NET_NFC_FELICA_ENABLE;
- }
- else if (type == NET_NFC_JEWEL_PICC)
- {
- converted = NET_NFC_FELICA_ENABLE;
- }
- else if (type == NET_NFC_ISO15693_PICC)
- {
- converted = NET_NFC_ISO15693_ENABLE;
- }
-
- if ((converted & client_filter) == 0)
- return FALSE;
-
- return TRUE;
-}
-
-static void tag_get_info_list(guint8 *buffer,
- gint number_of_keys,
- net_nfc_tag_info_s **list)
-{
- net_nfc_tag_info_s *tmp_list = NULL;
- net_nfc_tag_info_s *current = NULL;
-
- gint i = 0;
- gint length;
-
- guint8 *pos = buffer;
-
- if (buffer == NULL)
- return;
-
- tmp_list = g_new0(net_nfc_tag_info_s, number_of_keys);
- current = tmp_list;
-
- while(i < number_of_keys)
- {
- gchar *str = NULL;
- data_h value = NULL;
-
- /* key */
- length = *pos; /* first values is length of key */
- pos++;
-
- str = g_new0(gchar, length + 1);
- memcpy(str, pos, length);
-
- DEBUG_CLIENT_MSG("key = [%s]", str);
-
- pos += length;
-
- current->key = str;
-
- /* value */
- length = *pos; /* first value is length of value */
- pos++;
-
- value = NULL;
- if (length > 0)
- {
- net_nfc_create_data(&value, pos, length);
- pos += length;
- }
-
- current->value = value;
-
- current++;
- i++;
- }
-
- *list = tmp_list;
-}
-
-static void tag_get_target_info(guint handle,
- guint dev_type,
- gboolean is_ndef_supported,
- guchar ndef_card_state,
- guint max_data_size,
- guint actual_data_size,
- guint number_of_keys,
- GVariant *target_info_values,
- GVariant *raw_data,
- net_nfc_target_info_s **info)
-{
- guint8 *buffer = NULL;
- net_nfc_target_info_s *info_data = NULL;
- net_nfc_tag_info_s *list = NULL;
-
- if (info == NULL)
- return;
-
- net_nfc_util_gdbus_variant_to_buffer(target_info_values,
- &buffer, NULL);
-
- tag_get_info_list(buffer, number_of_keys, &list);
-
- info_data = g_new0(net_nfc_target_info_s, 1);
-
- info_data->ndefCardState = ndef_card_state;
- info_data->actualDataSize = actual_data_size;
- info_data->maxDataSize = max_data_size;
- info_data->devType = dev_type;
- info_data->handle = GUINT_TO_POINTER(handle);
- info_data->is_ndef_supported = (uint8_t)is_ndef_supported;
- info_data->number_of_keys = number_of_keys;
- info_data->tag_info_list = list;
-
- net_nfc_util_gdbus_variant_to_data_s(raw_data,
- &info_data->raw_data);
-
- *info = info_data;
-}
-
-static void tag_is_tag_connected(GObject *source_object,
- GAsyncResult *res,
- gpointer user_data)
-{
- TagFuncData *func_data;
-
- net_nfc_error_e result = NET_NFC_OK;
- GError *error = NULL;
-
- gboolean out_is_connected = FALSE;
- net_nfc_target_type_e out_dev_type;
-
- net_nfc_client_tag_is_tag_connected_completed callback;
-
- if (net_nfc_gdbus_tag_call_is_tag_connected_finish(
- NET_NFC_GDBUS_TAG(source_object),
- &out_is_connected,
- (gint32 *)&out_dev_type,
- res,
- &error) == FALSE)
- {
- result = NET_NFC_UNKNOWN_ERROR;
-
- DEBUG_ERR_MSG("Can not finish is_tag_connected: %s",
- error->message);
- g_error_free(error);
-
- }
-
- func_data = user_data;
- if (func_data == NULL)
- return;
-
- if (func_data->callback == NULL)
- {
- g_free(func_data);
- return;
- }
-
- if (out_is_connected == FALSE)
- result = NET_NFC_NOT_CONNECTED;
-
- callback = (net_nfc_client_tag_is_tag_connected_completed)
- func_data->callback;
- callback(result, out_dev_type, func_data->user_data);
-
- g_free(func_data);
-}
-
-static void tag_get_current_tag_info(GObject *source_object,
- GAsyncResult *res,
- gpointer user_data)
-{
- TagFuncData *func_data;
-
- net_nfc_error_e result = NET_NFC_OK;
-
- net_nfc_target_type_e out_dev_type;
- gboolean out_is_connected = FALSE;
- gboolean out_is_ndef_supported = FALSE;
- guchar out_ndef_card_state;
- guint out_handle;
- guint out_max_data_size;
- guint out_actual_data_size;
- guint out_number_of_keys;
- GVariant *out_target_info_values = NULL;
- GVariant *out_raw_data = NULL;
-
- GError *error = NULL;
-
- net_nfc_client_tag_get_current_tag_info_completed callback;
-
- /*FIXME: currently SAVE_TARGET_INFO_IN_CC support only */
- net_nfc_target_info_s *info_s = NULL;
-
- if (net_nfc_gdbus_tag_call_get_current_tag_info_finish (
- NET_NFC_GDBUS_TAG(source_object),
- &out_is_connected,
- &out_handle,
- (gint *)&out_dev_type,
- &out_is_ndef_supported,
- &out_ndef_card_state,
- &out_max_data_size,
- &out_actual_data_size,
- &out_number_of_keys,
- &out_target_info_values,
- &out_raw_data,
- res,
- &error) == FALSE)
- {
- result = NET_NFC_UNKNOWN_ERROR;
-
- DEBUG_ERR_MSG("Can not finish get_current_tag_info: %s",
- error->message);
- g_error_free(error);
- }
-
- func_data = user_data;
- if(func_data == NULL)
- return;
-
- if (func_data->callback == NULL)
- {
- g_free(func_data);
- return;
- }
-
- if (out_is_connected == FALSE)
- result = NET_NFC_NOT_CONNECTED;
-
- callback = (net_nfc_client_tag_get_current_tag_info_completed)
- func_data->callback;
-
- if (result != NET_NFC_OK)
- {
- callback(result, NULL, func_data->user_data);
- g_free(func_data);
- return;
- }
-
- if (tag_check_filter(out_dev_type) == FALSE)
- DEBUG_CLIENT_MSG("The detected target is filtered out");
-
- net_nfc_release_tag_info((net_nfc_target_info_h)client_target_info);
- client_target_info = NULL;
-
- tag_get_target_info(out_handle,
- out_dev_type,
- out_is_ndef_supported,
- out_ndef_card_state,
- out_max_data_size,
- out_actual_data_size,
- out_number_of_keys,
- out_target_info_values,
- out_raw_data,
- &info_s);
-
- client_target_info = info_s;
-
- callback(result, info_s, func_data->user_data);
-
- g_free(func_data);
-}
-
-static void tag_get_current_target_handle(GObject *source_object,
- GAsyncResult *res,
- gpointer user_data)
-{
- TagFuncData *func_data;
-
- net_nfc_target_handle_h handle = NULL;
- net_nfc_target_type_e out_dev_type;
-
- gboolean out_is_connected = FALSE;
- guint out_handle = 0;
-
- net_nfc_error_e result = NET_NFC_OK;
- GError *error = NULL;
-
- net_nfc_client_tag_get_current_target_handle_completed callback;
-
- if (net_nfc_gdbus_tag_call_get_current_target_handle_finish(
- NET_NFC_GDBUS_TAG(source_object),
- &out_is_connected,
- &out_handle,
- (gint *)&out_dev_type,
- res,
- &error) == FALSE)
- {
- result = NET_NFC_UNKNOWN_ERROR;
-
- DEBUG_ERR_MSG("Can not finish get_current_target_handle: %s",
- error->message);
- g_error_free(error);
- }
-
- func_data = user_data;
- if (func_data == NULL)
- return;
-
- if (func_data->callback == NULL)
- {
- g_free(func_data);
- return;
- }
-
- callback = (net_nfc_client_tag_get_current_target_handle_completed)
- func_data->callback;
-
- if (out_is_connected == FALSE)
- result = NET_NFC_NOT_CONNECTED;
-
- if (out_handle)
- handle = GUINT_TO_POINTER(out_handle);
-
- callback(result, handle, func_data->user_data);
-
- g_free(func_data);
-}
-
-static void tag_tag_discovered(NetNfcGDbusTag *object,
- guint arg_handle,
- gint arg_dev_type,
- gboolean arg_is_ndef_supported,
- guchar arg_ndef_card_state,
- guint arg_max_data_size,
- guint arg_actual_data_size,
- guint arg_number_of_keys,
- GVariant *arg_target_info_values,
- GVariant *arg_raw_data,
- gpointer user_data)
-{
- /*FIXME: currently SAVE_TARGET_INFO_IN_CC support only */
- net_nfc_target_info_s *info_s = NULL;
-
- net_nfc_client_tag_tag_discovered callback;
-
- INFO_MSG(">>> SIGNAL arrived");
-
- if (tag_discovered_func_data == NULL)
- return;
-
- if (tag_discovered_func_data->callback == NULL)
- return;
-
- if (tag_check_filter(arg_dev_type) == FALSE)
- DEBUG_CLIENT_MSG("The detected target is filtered out");
-
- net_nfc_release_tag_info((net_nfc_target_info_h)client_target_info);
- client_target_info = NULL;
-
- tag_get_target_info(arg_handle,
- arg_dev_type,
- arg_is_ndef_supported,
- arg_ndef_card_state,
- arg_max_data_size,
- arg_actual_data_size,
- arg_number_of_keys,
- arg_target_info_values,
- arg_raw_data,
- &info_s);
-
- client_target_info = info_s;
-
- callback = (net_nfc_client_tag_tag_discovered)
- tag_discovered_func_data->callback;
-
- callback(info_s, tag_discovered_func_data->user_data);
-}
-
-static void tag_tag_detached(NetNfcGDbusTag *object,
- guint arg_handle,
- gint arg_dev_type,
- gpointer user_data)
-{
- net_nfc_client_tag_tag_detached callback;
-
- INFO_MSG(">>> SIGNAL arrived");
-
- if (tag_detached_func_data == NULL)
- return;
-
- if (tag_detached_func_data->callback == NULL)
- return;
-
- if (tag_check_filter(arg_dev_type) == FALSE)
- DEBUG_CLIENT_MSG("The detected target is filtered out");
-
- /*FIXME: currently SAVE_TARGET_INFO_IN_CC support only */
- net_nfc_release_tag_info((net_nfc_target_info_h)client_target_info);
- client_target_info = NULL;
-
- callback = (net_nfc_client_tag_tag_detached)
- tag_detached_func_data->callback;
-
- callback(tag_detached_func_data->user_data);
-}
-
-/* internal funcion */
-gboolean net_nfc_client_tag_is_connected(void)
-{
- if (client_target_info == NULL)
- return FALSE;
-
- if (client_target_info->handle == NULL)
- return FALSE;
-
- return TRUE;
-}
-
-net_nfc_target_info_s *net_nfc_client_tag_get_client_target_info(void)
-{
- return client_target_info;
-}
-
-/* public APIs */
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_tag_is_tag_connected(
- net_nfc_client_tag_is_tag_connected_completed callback,
- void *user_data)
-{
- TagFuncData *func_data;
-
- if (tag_proxy == NULL)
- return NET_NFC_UNKNOWN_ERROR;
-
- /* prevent executing daemon when nfc is off */
- if (net_nfc_client_manager_is_activated() == false) {
- return NET_NFC_INVALID_STATE;
- }
-
- func_data = g_new0(TagFuncData, 1);
- if (func_data == NULL)
- return NET_NFC_UNKNOWN_ERROR;
-
- func_data->callback = (gpointer)callback;
- func_data->user_data = user_data;
-
- net_nfc_gdbus_tag_call_is_tag_connected(tag_proxy,
- net_nfc_client_gdbus_get_privilege(),
- NULL,
- tag_is_tag_connected,
- func_data);
-
- return NET_NFC_OK;
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_tag_is_tag_connected_sync(
- net_nfc_target_type_e *dev_type)
-{
- net_nfc_target_type_e out_dev_type;
-
- gboolean out_is_connected = FALSE;
-
- GError *error = NULL;
-
- /* prevent executing daemon when nfc is off */
- if (net_nfc_client_manager_is_activated() == false) {
- return NET_NFC_INVALID_STATE;
- }
-
- if (net_nfc_gdbus_tag_call_is_tag_connected_sync(tag_proxy,
- net_nfc_client_gdbus_get_privilege(),
- &out_is_connected,
- (gint *)&out_dev_type,
- NULL,
- &error) == FALSE)
- {
- DEBUG_ERR_MSG("Can not get is_tag_connected result: %s",
- error->message);
- g_error_free(error);
- return NET_NFC_UNKNOWN_ERROR;
- }
-
- if (dev_type)
- *dev_type = out_dev_type;
-
- if (out_is_connected == FALSE)
- return NET_NFC_NOT_CONNECTED;
-
- return NET_NFC_OK;
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_tag_get_current_tag_info(
- net_nfc_client_tag_get_current_tag_info_completed callback,
- void *user_data)
-{
- TagFuncData *func_data;
-
- if (tag_proxy == NULL)
- return NET_NFC_UNKNOWN_ERROR;
-
- /* prevent executing daemon when nfc is off */
- if (net_nfc_client_manager_is_activated() == false) {
- return NET_NFC_INVALID_STATE;
- }
-
- func_data = g_new0(TagFuncData, 1);
- func_data->callback = (gpointer)callback;
- func_data->user_data = user_data;
-
-
- net_nfc_gdbus_tag_call_get_current_tag_info(tag_proxy,
- net_nfc_client_gdbus_get_privilege(),
- NULL,
- tag_get_current_tag_info,
- func_data);
-
- return NET_NFC_OK;
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_tag_get_current_tag_info_sync(
- net_nfc_target_info_h *info)
-{
- net_nfc_target_type_e out_dev_type;
- gboolean out_is_connected = FALSE;
- gboolean out_is_ndef_supported;
- guchar out_ndef_card_state;
- guint out_handle;
- guint out_max_data_size;
- guint out_actual_data_size;
- guint out_number_of_keys;
- GVariant *out_target_info_values;
- GVariant *out_raw_data;
-
- net_nfc_target_info_s *info_s = NULL;
-
- GError *error = NULL;
-
- if (tag_proxy == NULL)
- return NET_NFC_UNKNOWN_ERROR;
-
- /* prevent executing daemon when nfc is off */
- if (net_nfc_client_manager_is_activated() == false) {
- return NET_NFC_INVALID_STATE;
- }
-
- if (net_nfc_gdbus_tag_call_get_current_tag_info_sync(tag_proxy,
- net_nfc_client_gdbus_get_privilege(),
- &out_is_connected,
- &out_handle,
- (gint *)&out_dev_type,
- &out_is_ndef_supported,
- &out_ndef_card_state,
- &out_max_data_size,
- &out_actual_data_size,
- &out_number_of_keys,
- &out_target_info_values,
- &out_raw_data,
- NULL,
- &error) == FALSE)
- {
- DEBUG_ERR_MSG("Can no get current_tag_info result: %s",
- error->message);
-
- g_error_free(error);
- return NET_NFC_UNKNOWN_ERROR;
- }
-
- if (out_is_connected == FALSE)
- return NET_NFC_NOT_CONNECTED;
-
- /* TODO : do something */
- if (info == NULL)
- return NET_NFC_OK;
-
- if(tag_check_filter(out_dev_type) == FALSE)
- DEBUG_CLIENT_MSG("The detected target is filtered out");
-
- tag_get_target_info(out_handle,
- out_dev_type,
- out_is_ndef_supported,
- out_ndef_card_state,
- out_max_data_size,
- out_actual_data_size,
- out_number_of_keys,
- out_target_info_values,
- out_raw_data,
- &info_s);
-
- *info = info_s;
-
- return NET_NFC_OK;
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_tag_get_current_target_handle(
- net_nfc_client_tag_get_current_target_handle_completed callback,
- void *user_data)
-{
- TagFuncData *func_data;
-
- if (tag_proxy == NULL)
- return NET_NFC_UNKNOWN_ERROR;
-
- /* prevent executing daemon when nfc is off */
- if (net_nfc_client_manager_is_activated() == false) {
- return NET_NFC_INVALID_STATE;
- }
-
- func_data = g_new0(TagFuncData, 1);
- func_data->callback = (gpointer)callback;
- func_data->user_data = user_data;
-
- net_nfc_gdbus_tag_call_get_current_target_handle(tag_proxy,
- net_nfc_client_gdbus_get_privilege(),
- NULL,
- tag_get_current_target_handle,
- func_data);
-
- return NET_NFC_OK;
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_tag_get_current_target_handle_sync(
- net_nfc_target_handle_h *handle)
-{
- net_nfc_target_type_e out_dev_type;
- gboolean out_is_connected = FALSE;
- guint out_handle;
- GError *error = NULL;
-
- if (tag_proxy == NULL)
- return NET_NFC_UNKNOWN_ERROR;
-
- /* prevent executing daemon when nfc is off */
- if (net_nfc_client_manager_is_activated() == false) {
- return NET_NFC_INVALID_STATE;
- }
-
- if (net_nfc_gdbus_tag_call_get_current_target_handle_sync(tag_proxy,
- net_nfc_client_gdbus_get_privilege(),
- &out_is_connected,
- &out_handle,
- (gint *)&out_dev_type,
- NULL,
- &error) == FALSE)
- {
- DEBUG_ERR_MSG("Can no get current_target_handle result: %s",
- error->message);
-
- g_error_free(error);
- return NET_NFC_UNKNOWN_ERROR;
- }
-
- if (out_is_connected == FALSE)
- return NET_NFC_NOT_CONNECTED;
-
- if (handle)
- *handle = GUINT_TO_POINTER(out_handle);
-
- return NET_NFC_OK;
-}
-
-NET_NFC_EXPORT_API
-void net_nfc_client_tag_set_tag_discovered(
- net_nfc_client_tag_tag_discovered callback,
- void *user_data)
-{
- if (tag_discovered_func_data == NULL)
- tag_discovered_func_data = g_new0(TagFuncData, 1);
-
- tag_discovered_func_data->callback = (gpointer) callback;
- tag_discovered_func_data->user_data = user_data;
-}
-
-NET_NFC_EXPORT_API
-void net_nfc_client_tag_unset_tag_discovered(void)
-{
- if (tag_discovered_func_data)
- {
- g_free(tag_discovered_func_data);
- tag_discovered_func_data = NULL;
- }
-
-}
-
-NET_NFC_EXPORT_API
-void net_nfc_client_tag_set_tag_detached(
- net_nfc_client_tag_tag_detached callback,
- void *user_data)
-{
- if (tag_detached_func_data == NULL)
- tag_detached_func_data = g_new0(TagFuncData, 1);
-
- tag_detached_func_data->callback = (gpointer) callback;
- tag_detached_func_data->user_data = user_data;
-}
-
-NET_NFC_EXPORT_API
-void net_nfc_client_tag_unset_tag_detached(void)
-{
- if (tag_detached_func_data)
- {
- g_free(tag_detached_func_data);
- tag_detached_func_data = NULL;
- }
-}
-
-NET_NFC_EXPORT_API
-void net_nfc_client_tag_set_filter(net_nfc_event_filter_e filter)
-{
- client_filter = filter;
-}
-
-NET_NFC_EXPORT_API
-net_nfc_event_filter_e net_nfc_client_tag_get_filter(void)
-{
- return client_filter;
-}
-
-net_nfc_error_e net_nfc_client_tag_init(void)
-{
- GError *error = NULL;
-
- if (tag_proxy)
- {
- DEBUG_CLIENT_MSG("Alrady initialized");
- return NET_NFC_OK;
- }
-
- if (client_target_info)
- {
- net_nfc_release_tag_info(
- (net_nfc_target_info_h)client_target_info);
- client_target_info = NULL;
- }
-
- client_filter = NET_NFC_ALL_ENABLE;
-
- tag_proxy = net_nfc_gdbus_tag_proxy_new_for_bus_sync(
- G_BUS_TYPE_SYSTEM,
- G_DBUS_PROXY_FLAGS_NONE,
- "org.tizen.NetNfcService",
- "/org/tizen/NetNfcService/Tag",
- NULL,
- &error);
- if (tag_proxy == NULL)
- {
- DEBUG_ERR_MSG("Can not create proxy : %s", error->message);
- g_error_free(error);
-
- return NET_NFC_UNKNOWN_ERROR;
- }
-
- g_signal_connect(tag_proxy, "tag-discovered",
- G_CALLBACK(tag_tag_discovered), NULL);
-
- g_signal_connect(tag_proxy, "tag-detached",
- G_CALLBACK(tag_tag_detached), NULL);
-
- return NET_NFC_OK;
-}
-
-void net_nfc_client_tag_deinit(void)
-{
- if (tag_proxy)
- {
- g_object_unref(tag_proxy);
- tag_proxy = NULL;
- }
-
- if (tag_discovered_func_data)
- {
- g_free(tag_discovered_func_data);
- tag_discovered_func_data = NULL;
- }
-
- if (tag_detached_func_data)
- {
- g_free(tag_detached_func_data);
- tag_detached_func_data = NULL;
- }
-
- net_nfc_release_tag_info((net_nfc_target_info_h)client_target_info);
- client_target_info = NULL;
-
- client_filter = NET_NFC_ALL_ENABLE;
-}
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
-
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <glib.h>
-#include <string.h>
-
-#include "net_nfc_client_tag_felica.h"
-#include "net_nfc_client_tag_internal.h"
-
-#include "net_nfc_typedef_internal.h"
-#include "net_nfc_debug_internal.h"
-#include "net_nfc_util_internal.h"
-#include "net_nfc_target_info.h"
-
-#ifndef NET_NFC_EXPORT_API
-#define NET_NFC_EXPORT_API __attribute__((visibility("default")))
-#endif
-
-#define FELICA_CMD_POLL 0x00
-#define FELICA_CMD_REQ_SERVICE 0x02
-#define FELICA_CMD_REQ_RESPONSE 0x04
-#define FELICA_CMD_READ_WITHOUT_ENC 0x06
-#define FELICA_CMD_WRITE_WITHOUT_ENC 0x08
-#define FELICA_CMD_REQ_SYSTEM_CODE 0x0C
-#define FELICA_TAG_KEY "IDm"
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_felica_poll(net_nfc_target_handle_h handle,
- net_nfc_felica_poll_request_code_e req_code,
- uint8_t time_slote,
- nfc_transceive_data_callback callback,
- void *user_data)
-{
- net_nfc_target_info_s* target_info = NULL;
-
- data_s rawdata;
-
- uint8_t send_buffer[6] = { 0x00, };
-
- if (handle == NULL)
- return NET_NFC_NULL_PARAMETER;
-
- if(net_nfc_client_tag_is_connected() == FALSE)
- return NET_NFC_OPERATION_FAIL;
-
- target_info = net_nfc_client_tag_get_client_target_info();
- if (target_info == NULL)
- return NET_NFC_NO_DATA_FOUND;
-
- if (target_info->devType != NET_NFC_FELICA_PICC)
- {
- DEBUG_CLIENT_MSG("only felica tag is available");
- return NET_NFC_NOT_ALLOWED_OPERATION;
- }
-
- /* total size of requet command */
- send_buffer[0] = 0x06;
- send_buffer[1] = FELICA_CMD_POLL;
-
- /* use wild card for system code */
- send_buffer[2] = 0xff;
- send_buffer[3] = 0xff;
-
- send_buffer[4] = req_code;
- send_buffer[5] = time_slote;
-
- DEBUG_MSG_PRINT_BUFFER(send_buffer, 6);
-
- rawdata.buffer = send_buffer;
- rawdata.length = 6;
-
- return net_nfc_client_transceive_data(handle,
- (data_h)&rawdata,
- callback,
- user_data);
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_felica_request_service(
- net_nfc_target_handle_h handle,
- uint8_t number_of_area_service,
- uint16_t area_service_list[],
- uint8_t number_of_services,
- nfc_transceive_data_callback callback,
- void *user_data)
-{
- net_nfc_target_info_s* target_info = NULL;
-
- data_s rawdata;
-
- data_h IDm = NULL;
-
- uint32_t send_buffer_length;
- uint8_t* send_buffer = NULL;
- uint8_t* temp = NULL;
-
- int i;
-
- if (handle == NULL || area_service_list == NULL)
- return NET_NFC_NULL_PARAMETER;
-
- if(net_nfc_client_tag_is_connected() == FALSE)
- return NET_NFC_OPERATION_FAIL;
-
- target_info = net_nfc_client_tag_get_client_target_info();
- if (target_info == NULL)
- return NET_NFC_NO_DATA_FOUND;
-
- if (target_info->devType != NET_NFC_FELICA_PICC)
- {
- DEBUG_CLIENT_MSG("only Jewel tag is available");
- return NET_NFC_NOT_ALLOWED_OPERATION;
- }
-
- if (net_nfc_get_tag_info_value((net_nfc_target_info_h)target_info,
- FELICA_TAG_KEY,
- &IDm) != NET_NFC_OK)
- {
- return NET_NFC_NO_DATA_FOUND;
- }
-
- if (((data_s*)IDm)->length != 8)
- return NET_NFC_OUT_OF_BOUND;
-
- if (number_of_area_service > 32)
- return NET_NFC_OUT_OF_BOUND;
-
- /* size + cmd + UID + number of service service count + service list */
- send_buffer_length = 1 + 1 + 8 + 1 + (2 * number_of_services);
-
- _net_nfc_util_alloc_mem(send_buffer, send_buffer_length * sizeof(uint8_t));
- if (send_buffer == NULL)
- return NET_NFC_ALLOC_FAIL;
-
- temp = send_buffer;
-
- /* set cmd length */
- *send_buffer = send_buffer_length;
- send_buffer++;
-
- /* set cmd */
- *send_buffer = FELICA_CMD_REQ_SERVICE;
- send_buffer++;
-
- /* set IDm */
- memcpy(send_buffer, ((data_s*)IDm)->buffer, ((data_s*)IDm)->length);
- send_buffer = send_buffer + ((data_s*)IDm)->length;
-
- /* set the number of service codes */
- *send_buffer = number_of_area_service;
- send_buffer++;
-
- for (i = 0; i < number_of_services; i++)
- {
- memcpy(send_buffer, &area_service_list[i], sizeof(uint16_t));
- send_buffer = send_buffer + 2;
- }
-
- DEBUG_MSG_PRINT_BUFFER(temp, send_buffer_length);
-
- rawdata.buffer = send_buffer;
- rawdata.length = send_buffer_length;
-
- net_nfc_error_e result = NET_NFC_OK;
- result = net_nfc_client_transceive_data(handle,
- (data_h)&rawdata,
- callback,
- user_data);
-
- if (temp != NULL)
- _net_nfc_util_free_mem(temp);
-
- return result;
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_felica_request_response(
- net_nfc_target_handle_h handle,
- nfc_transceive_data_callback callback,
- void *user_data)
-{
- net_nfc_target_info_s* target_info = NULL;
-
- data_s rawdata;
-
- data_h IDm = NULL;
-
- uint8_t send_buffer[10] = { 0x00, };
-
- if (handle == NULL)
- return NET_NFC_NULL_PARAMETER;
-
- if(net_nfc_client_tag_is_connected() == FALSE)
- return NET_NFC_OPERATION_FAIL;
-
- target_info = net_nfc_client_tag_get_client_target_info();
- if (target_info == NULL)
- return NET_NFC_NO_DATA_FOUND;
-
- if (target_info->devType != NET_NFC_FELICA_PICC)
- {
- DEBUG_CLIENT_MSG("only Jewel tag is available");
- return NET_NFC_NOT_ALLOWED_OPERATION;
- }
-
- if (net_nfc_get_tag_info_value((net_nfc_target_info_h)target_info,
- FELICA_TAG_KEY,
- &IDm) != NET_NFC_OK)
- {
- return NET_NFC_NO_DATA_FOUND;
- }
-
- if (((data_s*)IDm)->length != 8)
- return NET_NFC_OUT_OF_BOUND;
-
- send_buffer[0] = 0xA;
- send_buffer[1] = FELICA_CMD_REQ_RESPONSE;
-
- memcpy(send_buffer + 2,
- ((data_s*)IDm)->buffer,
- ((data_s*)IDm)->length);
-
- DEBUG_MSG_PRINT_BUFFER(send_buffer, 10);
-
- rawdata.buffer = send_buffer;
- rawdata.length = 10;
-
- return net_nfc_client_transceive_data(handle,
- (data_h)&rawdata,
- callback,
- user_data);
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_felica_read_without_encryption(
- net_nfc_target_handle_h handle,
- uint8_t number_of_services,
- uint16_t service_list[],
- uint8_t number_of_blocks,
- uint8_t block_list[],
- nfc_transceive_data_callback callback,
- void *user_data)
-{
- net_nfc_target_info_s* target_info = NULL;
-
- data_s rawdata;
-
- data_h IDm = NULL;
-
- uint32_t send_buffer_length;
- uint8_t* send_buffer = NULL;
- uint8_t* temp = NULL;
-
- int i;
-
- if (handle == NULL || service_list == NULL || block_list == NULL)
- return NET_NFC_NULL_PARAMETER;
-
- if(net_nfc_client_tag_is_connected() == FALSE)
- return NET_NFC_OPERATION_FAIL;
-
- target_info = net_nfc_client_tag_get_client_target_info();
- if (target_info == NULL)
- return NET_NFC_NO_DATA_FOUND;
-
- if (target_info->devType != NET_NFC_FELICA_PICC)
- {
- DEBUG_CLIENT_MSG("only Jewel tag is available");
- return NET_NFC_NOT_ALLOWED_OPERATION;
- }
-
- if (net_nfc_get_tag_info_value((net_nfc_target_info_h)target_info,
- FELICA_TAG_KEY,
- &IDm) != NET_NFC_OK)
- {
- return NET_NFC_NO_DATA_FOUND;
- }
-
- if (((data_s*)IDm)->length != 8)
- return NET_NFC_OUT_OF_BOUND;
-
- if (number_of_services > 16)
- return NET_NFC_OUT_OF_BOUND;
-
- send_buffer_length = 1 + 1 + 8 + 1 + (2 * number_of_services)
- + 1 + number_of_blocks;
-
- _net_nfc_util_alloc_mem(send_buffer,
- send_buffer_length * sizeof(uint8_t));
- if (send_buffer == NULL)
- return NET_NFC_ALLOC_FAIL;
-
- temp = send_buffer;
-
- *send_buffer = send_buffer_length;
- send_buffer++;
-
- *send_buffer = FELICA_CMD_READ_WITHOUT_ENC;
- send_buffer++;
-
- memcpy(send_buffer, ((data_s*)IDm)->buffer, ((data_s*)IDm)->length);
- send_buffer = send_buffer + ((data_s*)IDm)->length;
-
- *send_buffer = number_of_services;
- send_buffer++;
-
- for (i = 0; i < number_of_services; i++)
- {
- memcpy(send_buffer, &service_list[i], sizeof(uint16_t));
- send_buffer = send_buffer + 2;
- }
-
- *send_buffer = number_of_blocks;
- send_buffer++;
-
- for (i = 0; i < number_of_blocks; i++)
- {
- memcpy(send_buffer, &block_list[i], sizeof(uint8_t));
- send_buffer++;
- }
-
- DEBUG_MSG_PRINT_BUFFER(temp, send_buffer_length);
-
- rawdata.buffer = temp;
- rawdata.length = send_buffer_length;
-
- net_nfc_error_e result = NET_NFC_OK;
- result = net_nfc_client_transceive_data(handle,
- (data_h)&rawdata,
- callback,
- user_data);
-
- if (temp != NULL)
- _net_nfc_util_free_mem(temp);
-
- return result;
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_felica_write_without_encryption(
- net_nfc_target_handle_h handle,
- uint8_t number_of_services,
- uint16_t service_list[],
- uint8_t number_of_blocks,
- uint8_t block_list[],
- data_h data,
- nfc_transceive_data_callback callback,
- void *user_data)
-{
- net_nfc_target_info_s* target_info = NULL;
-
- data_s rawdata;
-
- data_h IDm = NULL;
-
- uint32_t send_buffer_length;
- uint8_t* send_buffer = NULL;
- uint8_t* temp = NULL;
-
- int i;
-
- if (handle == NULL || service_list == NULL ||
- block_list == NULL || data == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
-
- if(net_nfc_client_tag_is_connected() == FALSE)
- return NET_NFC_OPERATION_FAIL;
- target_info = net_nfc_client_tag_get_client_target_info();
- if (target_info == NULL)
- return NET_NFC_NO_DATA_FOUND;
-
- if (target_info->devType != NET_NFC_FELICA_PICC)
- {
- DEBUG_CLIENT_MSG("only Jewel tag is available");
- return NET_NFC_NOT_ALLOWED_OPERATION;
- }
-
- if (net_nfc_get_tag_info_value((net_nfc_target_info_h)target_info,
- FELICA_TAG_KEY,
- &IDm) != NET_NFC_OK)
- {
- return NET_NFC_NO_DATA_FOUND;
- }
-
- if (((data_s*)IDm)->length != 8)
- return NET_NFC_OUT_OF_BOUND;
-
- if (number_of_services > 16)
- return NET_NFC_OUT_OF_BOUND;
-
- if (((data_s*)data)->length > 16 * number_of_blocks)
- return NET_NFC_OUT_OF_BOUND;
-
- send_buffer_length = 1 + 1 + 8 + 1 + (2 * number_of_services)
- + 1 + number_of_blocks
- +((data_s*)data)->length;
-
- _net_nfc_util_alloc_mem(send_buffer,
- send_buffer_length * sizeof(uint8_t));
- if (send_buffer == NULL)
- return NET_NFC_ALLOC_FAIL;
-
- temp = send_buffer;
-
- *send_buffer = send_buffer_length;
- send_buffer++;
-
- *send_buffer = FELICA_CMD_WRITE_WITHOUT_ENC;
- send_buffer++;
-
- memcpy(send_buffer, ((data_s*)IDm)->buffer, ((data_s*)IDm)->length);
- send_buffer = send_buffer + ((data_s*)IDm)->length;
-
- *send_buffer = number_of_services;
- send_buffer++;
-
- for (i = 0; i < number_of_services; i++)
- {
- memcpy(send_buffer, &service_list[i], sizeof(uint16_t));
- send_buffer = send_buffer + 2;
- }
-
- *send_buffer = number_of_blocks;
- send_buffer++;
-
- for (i = 0; i < number_of_blocks; i++)
- {
- memcpy(send_buffer, &block_list[i], sizeof(uint8_t));
- send_buffer++;
- }
-
- memcpy(send_buffer, ((data_s*)data)->buffer, ((data_s*)data)->length);
-
- DEBUG_MSG_PRINT_BUFFER(temp, send_buffer_length);
-
- rawdata.buffer = temp;
- rawdata.length = send_buffer_length;
-
- net_nfc_error_e result = NET_NFC_OK;
-
- result = net_nfc_client_transceive_data(handle,
- (data_h)&rawdata,
- callback,
- user_data);
-
- if (temp != NULL)
- _net_nfc_util_free_mem(temp);
-
- return result;
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_felica_request_system_code(
- net_nfc_target_handle_h handle,
- nfc_transceive_data_callback callback,
- void *user_data)
-{
- net_nfc_target_info_s* target_info = NULL;
-
- data_s rawdata;
-
- data_h IDm = NULL;
-
- uint8_t send_buffer[10] = { 0x00, };
-
- if (handle == NULL)
- return NET_NFC_NULL_PARAMETER;
-
- if(net_nfc_client_tag_is_connected() == FALSE)
- return NET_NFC_OPERATION_FAIL;
-
- target_info = net_nfc_client_tag_get_client_target_info();
- if (target_info == NULL)
- return NET_NFC_NO_DATA_FOUND;
-
- if (target_info->devType != NET_NFC_FELICA_PICC)
- {
- DEBUG_CLIENT_MSG("only Jewel tag is available");
- return NET_NFC_NOT_ALLOWED_OPERATION;
- }
-
- if (net_nfc_get_tag_info_value((net_nfc_target_info_h)target_info,
- FELICA_TAG_KEY,
- &IDm) != NET_NFC_OK)
- {
- return NET_NFC_NO_DATA_FOUND;
- }
-
- if (((data_s*)IDm)->length != 8)
- return NET_NFC_OUT_OF_BOUND;
-
-
- send_buffer[0] = 0xA;
- send_buffer[1] = FELICA_CMD_REQ_SYSTEM_CODE;
-
- memcpy(send_buffer + 2,
- ((data_s *)IDm)->buffer,
- ((data_s *)IDm)->length);
-
- DEBUG_MSG_PRINT_BUFFER(send_buffer, 10);
-
- rawdata.buffer = send_buffer;
- rawdata.length = 10;
-
- return net_nfc_client_transceive_data(handle,
- (data_h)&rawdata,
- callback,
- user_data);
-}
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <glib.h>
-#include <string.h>
-
-#include "net_nfc_client_tag_jewel.h"
-#include "net_nfc_client_tag_internal.h"
-
-#include "net_nfc_typedef_internal.h"
-#include "net_nfc_debug_internal.h"
-#include "net_nfc_util_internal.h"
-#include "net_nfc_target_info.h"
-
-
-#ifndef NET_NFC_EXPORT_API
-#define NET_NFC_EXPORT_API __attribute__((visibility("default")))
-#endif
-
-
-#define JEWEL_CMD_REQA 0x26
-#define JEWEL_CMD_WUPA 0x52
-#define JEWEL_CMD_RID 0x78
-#define JEWEL_CMD_RALL 0x00
-#define JEWEL_CMD_READ 0x01
-#define JEWEL_CMD_WRITE_E 0x53
-#define JEWEL_CMD_WRITE_NE 0x1A
-#define JEWEL_TAG_KEY "UID"
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_jewel_read_id(net_nfc_target_handle_h handle,
- nfc_transceive_data_callback callback,
- void *user_data)
-{
- net_nfc_target_info_s* target_info = NULL;
-
- data_s rawdata;
-
- uint8_t send_buffer[9] = {0x00, };
-
- if(handle == NULL)
- return NET_NFC_NULL_PARAMETER;
-
- if(net_nfc_client_tag_is_connected() == FALSE)
- return NET_NFC_OPERATION_FAIL;
-
- target_info = net_nfc_client_tag_get_client_target_info();
- if (target_info == NULL)
- return NET_NFC_NO_DATA_FOUND;
-
- if(target_info->devType != NET_NFC_JEWEL_PICC)
- {
- DEBUG_CLIENT_MSG("only Jewel tag is available");
- return NET_NFC_NOT_ALLOWED_OPERATION;
- }
-
- send_buffer[0] = JEWEL_CMD_RID;
-
- net_nfc_util_compute_CRC(CRC_B, send_buffer, 9);
-
- DEBUG_MSG_PRINT_BUFFER(send_buffer, 9);
-
- rawdata.buffer = send_buffer;
- rawdata.length = 9;
-
- return net_nfc_client_transceive_data(handle,
- (data_h)&rawdata,
- callback,
- user_data);
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_jewel_read_byte(net_nfc_target_handle_h handle,
- uint8_t block,
- uint8_t byte,
- nfc_transceive_data_callback callback,
- void *user_data)
-{
- net_nfc_target_info_s* target_info = NULL;
-
- data_s rawdata;
-
- data_h UID = NULL;
-
- uint8_t send_buffer[9] = {0x00, };
-
- if(handle == NULL)
- return NET_NFC_NULL_PARAMETER;
-
- if(block > 0xE || byte > 0x7 )
- return NET_NFC_OUT_OF_BOUND;
-
- if(net_nfc_client_tag_is_connected() == FALSE)
- return NET_NFC_OPERATION_FAIL;
-
- target_info = net_nfc_client_tag_get_client_target_info();
- if (target_info == NULL)
- return NET_NFC_NO_DATA_FOUND;
-
- if(target_info->devType != NET_NFC_JEWEL_PICC)
- {
- DEBUG_CLIENT_MSG("only Jewel tag is available");
- return NET_NFC_NOT_ALLOWED_OPERATION;
- }
-
- if(net_nfc_get_tag_info_value((net_nfc_target_info_h)target_info,
- JEWEL_TAG_KEY,
- &UID) != NET_NFC_OK)
- {
- return NET_NFC_NO_DATA_FOUND;
- }
-
-
- if(((data_s*)UID)->length != 4)
- return NET_NFC_OUT_OF_BOUND;
-
- /* command */
- send_buffer[0] = JEWEL_CMD_READ;
-
- /* addr */
- send_buffer[1] = (((block << 3) & 0x78) | (byte & 0x7));
-
- /* data */
- send_buffer[2] = 0x00;
-
- /* UID0 ~ 3 */
- memcpy(&(send_buffer[3]),
- ((data_s*)UID)->buffer,
- ((data_s*)UID)->length);
-
- net_nfc_util_compute_CRC(CRC_B, send_buffer, 9);
-
- DEBUG_MSG_PRINT_BUFFER(send_buffer, 9);
-
- rawdata.buffer = send_buffer;
- rawdata.length = 9;
-
- return net_nfc_client_transceive_data(handle,
- (data_h)&rawdata,
- callback,
- user_data);
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_jewel_read_all(net_nfc_target_handle_h handle,
- nfc_transceive_data_callback callback,
- void *user_data)
-{
- net_nfc_target_info_s* target_info = NULL;
-
- data_s rawdata;
-
- data_h UID = NULL;
-
- uint8_t send_buffer[9] = {0x00, };
-
- if(handle == NULL )
- return NET_NFC_NULL_PARAMETER;
-
- if(net_nfc_client_tag_is_connected() == FALSE)
- return NET_NFC_OPERATION_FAIL;
-
- target_info = net_nfc_client_tag_get_client_target_info();
- if (target_info == NULL)
- return NET_NFC_NO_DATA_FOUND;
-
- if(target_info->devType != NET_NFC_JEWEL_PICC)
- {
- DEBUG_CLIENT_MSG("only Jewel tag is available");
- return NET_NFC_NOT_ALLOWED_OPERATION;
- }
-
- if(net_nfc_get_tag_info_value((net_nfc_target_info_h)target_info,
- JEWEL_TAG_KEY,
- &UID) != NET_NFC_OK)
- {
- return NET_NFC_NO_DATA_FOUND;
- }
-
- if(((data_s*)UID)->length != 4)
- return NET_NFC_OUT_OF_BOUND;
-
- /* command */
- send_buffer[0] = JEWEL_CMD_RALL;
-
- /* addr */
- send_buffer[1] = 0x00;
-
- /* data */
- send_buffer[2] = 0x00;
-
- /* UID0 ~ 3 */
- memcpy(&(send_buffer[3]),
- ((data_s*)UID)->buffer,
- ((data_s*)UID)->length);
-
- net_nfc_util_compute_CRC(CRC_B, send_buffer, 9);
-
- DEBUG_MSG_PRINT_BUFFER(send_buffer, 9);
-
- rawdata.buffer = send_buffer;
- rawdata.length = 9;
-
- return net_nfc_client_transceive_data(handle,
- (data_h)&rawdata,
- callback,
- user_data);
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_jewel_write_with_erase(
- net_nfc_target_handle_h handle,
- uint8_t block,
- uint8_t byte,
- uint8_t data,
- nfc_transceive_callback callback,
- void *user_data)
-{
- net_nfc_target_info_s* target_info = NULL;
-
- data_s rawdata;
-
- data_h UID = NULL;
-
- uint8_t send_buffer[9] = {0x00, };
-
- if(handle == NULL)
- return NET_NFC_NULL_PARAMETER;
-
- if(block > 0xE || byte > 0x7 )
- return NET_NFC_OUT_OF_BOUND;
-
- if(net_nfc_client_tag_is_connected() == FALSE)
- return NET_NFC_OPERATION_FAIL;
-
-
- target_info = net_nfc_client_tag_get_client_target_info();
- if (target_info == NULL)
- return NET_NFC_NO_DATA_FOUND;
-
- if(net_nfc_get_tag_info_value((net_nfc_target_info_h)target_info,
- JEWEL_TAG_KEY,
- &UID) != NET_NFC_OK)
- {
- return NET_NFC_NO_DATA_FOUND;
- }
-
- if(((data_s*)UID)->length != 4)
- return NET_NFC_OUT_OF_BOUND;
-
- /* command */
- send_buffer[0] = JEWEL_CMD_WRITE_E;
-
- /* addr */
- send_buffer[1] = (((block << 3) & 0x78) | (byte & 0x7));
-
- /* data */
- send_buffer[2] = data;
-
- /* UID0 ~ 3 */
- memcpy(&(send_buffer[3]),
- ((data_s*)UID)->buffer,
- ((data_s*)UID)->length);
-
- net_nfc_util_compute_CRC(CRC_B, send_buffer, 9);
-
- DEBUG_MSG_PRINT_BUFFER(send_buffer, 9);
-
- rawdata.buffer = send_buffer;
- rawdata.length = 9;
-
- return net_nfc_client_transceive(handle,
- (data_h)&rawdata,
- callback,
- user_data);
-
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_jewel_write_with_no_erase(
- net_nfc_target_handle_h handle,
- uint8_t block,
- uint8_t byte,
- uint8_t data,
- nfc_transceive_callback callback,
- void *user_data)
-{
- net_nfc_target_info_s* target_info = NULL;
-
- data_s rawdata;
-
- data_h UID = NULL;
-
- uint8_t send_buffer[9] = {0x00, };
-
- if(handle == NULL)
- return NET_NFC_NULL_PARAMETER;
-
- if(block > 0xE || byte > 0x7 )
- return NET_NFC_OUT_OF_BOUND;
-
- if(net_nfc_client_tag_is_connected() == FALSE)
- return NET_NFC_OPERATION_FAIL;
-
- target_info = net_nfc_client_tag_get_client_target_info();
- if (target_info == NULL)
- return NET_NFC_NO_DATA_FOUND;
-
- if(target_info->devType != NET_NFC_JEWEL_PICC)
- {
- DEBUG_CLIENT_MSG("only Jewel tag is available");
- return NET_NFC_NOT_ALLOWED_OPERATION;
- }
-
- if(net_nfc_get_tag_info_value((net_nfc_target_info_h)target_info,
- JEWEL_TAG_KEY,
- &UID) != NET_NFC_OK)
- {
- return NET_NFC_NO_DATA_FOUND;
- }
-
- if(((data_s*)UID)->length != 4)
- return NET_NFC_OUT_OF_BOUND;
-
- /* command */
- send_buffer[0] = JEWEL_CMD_WRITE_NE;
-
- /* addr */
- send_buffer[1] = (((block << 3) & 0x78) | (byte & 0x7));
-
- /* data */
- send_buffer[2] = data;
-
- /* UID0 ~ 3 */
- memcpy(&(send_buffer[3]),
- ((data_s*)UID)->buffer,
- ((data_s*)UID)->length);
-
- net_nfc_util_compute_CRC(CRC_B, send_buffer, 9);
-
- DEBUG_MSG_PRINT_BUFFER(send_buffer, 9);
-
- rawdata.buffer = send_buffer;
- rawdata.length = 9;
-
- return net_nfc_client_transceive(handle,
- (data_h)&rawdata,
- callback,
- user_data);
-}
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
-
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#include <glib.h>
-#include <string.h>
-
-#include "net_nfc_client_transceive.h"
-#include "net_nfc_client_tag_internal.h"
-
-#include "net_nfc_tag_mifare.h"
-
-#include "net_nfc_data.h"
-#include "net_nfc_typedef_internal.h"
-#include "net_nfc_debug_internal.h"
-#include "net_nfc_target_info.h"
-#include "net_nfc_util_internal.h"
-
-#ifndef NET_NFC_EXPORT_API
-#define NET_NFC_EXPORT_API __attribute__((visibility("default")))
-#endif
-
-#define MIFARE_CMD_RAW 0x00U
-#define MIFARE_CMD_AUTH_A 0x60U /**< authenticate with key A */
-#define MIFARE_CMD_AUTH_B 0x61U /**< authenticate with key B */
-#define MIFARE_CMD_READ 0x30U /**< read 16 bytes */
-#define MIFARE_CMD_WRITE_BLOCK 0xA0U /**< write 16 bytes */
-#define MIFARE_CMD_WRITE_PAGE 0xA2U /**< write 4 bytes */
-#define MIFARE_CMD_INCREMENT 0xC1U /**< Increment. */
-#define MIFARE_CMD_DECREMENT 0xC0U /**< Decrement. */
-#define MIFARE_CMD_TRANSFER 0xB0U /**< Tranfer. */
-#define MIFARE_CMD_RESTORE 0xC2U /**< Restore. */
-#define MIFARE_TAG_KEY "UID"
-
-#define MIFARE_CMD_READ_SECTOR 0x38U /* read sector */
-#define MIFARE_CMD_WRITE_SECTOR 0xA8U /* write sector */
-
-static uint8_t default_key[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
-static uint8_t mad_key[6] = { 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5 };
-static uint8_t net_nfc_forum_key[6] = { 0xD3, 0xF7, 0xD3, 0xF7, 0xD3, 0xF7 };
-
-#define MIFARE_BLOCK_4 4
-#define MIFARE_BLOCK_16 16
-
-#define MIFARE_MINI_SECTORS 5
-#define MIFARE_1K_SECTORS 16
-#define MIFARE_4K_SECTORS 40
-
-#define MIFARE_BLOCK_SIZE 16 /* 1 block is 16 byte */
-#define MIFARE_PAGE_SIZE 4 /* 1 page is 4 byte */
-
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_mifare_authenticate_with_keyA(
- net_nfc_target_handle_h handle,
- uint8_t sector,
- data_h auth_key,
- void *callback,
- void *user_data)
-{
- net_nfc_target_info_s* target_info = NULL;
-
- data_s *key;
- data_s rawdata;
-
- data_h UID = NULL;
-
- uint8_t* send_buffer = NULL;
- uint8_t* temp = NULL;
-
- int send_buffer_length = 0;
-
- uint8_t sector_to_block = 0;
-
-
- if (handle == NULL || auth_key == NULL)
- return NET_NFC_NULL_PARAMETER;
-
- if (net_nfc_client_tag_is_connected() == FALSE)
- return NET_NFC_OPERATION_FAIL;
-
- key = (data_s *)auth_key;
-
- if (key->length != 6)
- return NET_NFC_OUT_OF_BOUND;
-
- target_info = net_nfc_client_tag_get_client_target_info();
-
- if (target_info)
- {
- if (target_info->devType < NET_NFC_MIFARE_MINI_PICC ||
- target_info->devType > NET_NFC_MIFARE_4K_PICC)
- {
- DEBUG_CLIENT_MSG("not a MIFARE Classic TAG");
- return NET_NFC_NOT_SUPPORTED;
- }
- }
-
- if (net_nfc_get_tag_info_value((net_nfc_target_info_h)target_info,
- MIFARE_TAG_KEY,
- &UID) != NET_NFC_OK)
- {
- return NET_NFC_NO_DATA_FOUND;
- }
-
- switch (target_info->devType)
- {
- case NET_NFC_MIFARE_MINI_PICC :
- {
- /* 0 ~ 4 : 5 sector and 4 block with 16 bytes */
- if (sector > MIFARE_MINI_SECTORS - 1)
- return NET_NFC_OUT_OF_BOUND;
-
- sector_to_block = sector * MIFARE_BLOCK_4 + 3;
- }
- break;
- case NET_NFC_MIFARE_1K_PICC :
- {
- /* 0 ~ 15 : 16 sector and 4 block with 16 bytes */
- if (sector > MIFARE_1K_SECTORS)
- return NET_NFC_OUT_OF_BOUND;
-
- sector_to_block = sector * MIFARE_BLOCK_4 + 3;
- }
- break;
- case NET_NFC_MIFARE_4K_PICC :
- {
- /* 0 ~ 31 : 32 sector and 4 block with 16 bytes
- * 32 ~ 39 : 8 sector and 16 block with 16 bytes
- */
- if (sector > MIFARE_4K_SECTORS)
- return NET_NFC_OUT_OF_BOUND;
-
- if (sector < 32)
- sector_to_block = sector * MIFARE_BLOCK_4 + 3;
- else
- {
- sector_to_block = (31 * MIFARE_BLOCK_4 + 3)
- + (sector - 32)
- * MIFARE_BLOCK_16 + 15;
- }
- }
- break;
- default :
- break;
- }
-
-
- /* cmd + addr + UID + AUTH_KEY + CRC_A */
- send_buffer_length = 1 + 1 + ((data_s*)UID)->length
- + key->length + 2;
-
- _net_nfc_util_alloc_mem(send_buffer,
- send_buffer_length * sizeof(uint8_t));
- if (send_buffer == NULL)
- {
- net_nfc_free_data(UID);
- return NET_NFC_ALLOC_FAIL;
- }
-
- temp = send_buffer;
-
- *temp = MIFARE_CMD_AUTH_A;
- temp++;
-
- *temp = sector_to_block;
- temp++;
-
- memcpy(temp, ((data_s*)UID)->buffer, ((data_s*)UID)->length);
- temp = temp + ((data_s*)UID)->length;
-
- memcpy(temp, key->buffer, key->length);
-
- net_nfc_util_compute_CRC(CRC_A, send_buffer, send_buffer_length);
-
-
- rawdata.buffer = send_buffer;
- rawdata.length = send_buffer_length;
-
- net_nfc_error_e result = net_nfc_client_transceive(handle,
- (data_h)&rawdata,
- callback,
- user_data);
-
- if (send_buffer != NULL)
- _net_nfc_util_free_mem(send_buffer);
-
- return result;
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_mifare_authenticate_with_keyB(
- net_nfc_target_handle_h handle,
- uint8_t sector,
- data_h auth_key,
- void *callback,
- void *user_data)
-{
- net_nfc_target_info_s* target_info = NULL;
-
- data_s *key;
- data_s rawdata;
-
- data_h UID = NULL;
-
- uint8_t* send_buffer = NULL;
- uint8_t* temp = NULL;
-
- int send_buffer_length = 0;
-
- uint8_t sector_to_block = 0;
-
-
- if (handle == NULL || auth_key == NULL)
- return NET_NFC_NULL_PARAMETER;
-
- if (net_nfc_client_tag_is_connected() == FALSE)
- return NET_NFC_OPERATION_FAIL;
-
- key = (data_s *)auth_key;
-
- if (key->length != 6)
- return NET_NFC_OUT_OF_BOUND;
-
- target_info = net_nfc_client_tag_get_client_target_info();
-
- if (target_info != NULL)
- {
- if (target_info->devType < NET_NFC_MIFARE_MINI_PICC ||
- target_info->devType > NET_NFC_MIFARE_4K_PICC)
- {
- DEBUG_CLIENT_MSG("not a MIFARE Classic TAG");
- return NET_NFC_NOT_SUPPORTED;
- }
- }
-
- if (net_nfc_get_tag_info_value((net_nfc_target_info_h)target_info,
- MIFARE_TAG_KEY,
- &UID) != NET_NFC_OK)
- {
- return NET_NFC_NO_DATA_FOUND;
- }
-
- switch (target_info->devType)
- {
- case NET_NFC_MIFARE_MINI_PICC :
- {
- /* 0 ~ 4 : 5 sector and 4 block with 16 bytes */
- if (sector > MIFARE_MINI_SECTORS)
- return NET_NFC_OUT_OF_BOUND;
-
- sector_to_block = sector * MIFARE_BLOCK_4 + 3;
- }
- break;
- case NET_NFC_MIFARE_1K_PICC :
- {
- /* 0 ~ 15 : 16 sector and 4 block with 16 bytes */
- if (sector > MIFARE_1K_SECTORS)
- return NET_NFC_OUT_OF_BOUND;
-
- sector_to_block = sector * MIFARE_BLOCK_4 + 3;
- }
- break;
- case NET_NFC_MIFARE_4K_PICC :
- {
- /* 0 ~ 31 : 32 sector and 4 block with 16 bytes
- * 32 ~ 39 : 8 sector and 16 block with 16 bytes
- */
- if (sector > MIFARE_4K_SECTORS)
- return NET_NFC_OUT_OF_BOUND;
-
- if (sector < 32)
- sector_to_block = sector * MIFARE_BLOCK_4 + 3;
- else
- {
- sector_to_block = (31 * MIFARE_BLOCK_4 + 3)
- + (sector - 32)
- * MIFARE_BLOCK_16 + 15;
- }
- }
- break;
- default :
- break;
- }
-
- send_buffer_length = 1 + 1 + ((data_s*)UID)->length
- + key->length + 2; /* cmd + addr + UID + AUTH_KEY + CRC_A */
-
- _net_nfc_util_alloc_mem(send_buffer, send_buffer_length
- * sizeof(uint8_t));
- if (send_buffer == NULL)
- {
- net_nfc_free_data(UID);
- return NET_NFC_ALLOC_FAIL;
- }
-
- temp = send_buffer;
-
- *temp = MIFARE_CMD_AUTH_B;
- temp++;
-
- *temp = sector_to_block;
- temp++;
-
- memcpy(temp, ((data_s*)UID)->buffer, ((data_s*)UID)->length);
- temp = temp + ((data_s*)UID)->length;
-
- memcpy(temp, key->buffer, key->length);
-
- net_nfc_util_compute_CRC(CRC_A, send_buffer, send_buffer_length);
-
- rawdata.buffer = send_buffer;
- rawdata.length = send_buffer_length;
-
- net_nfc_error_e result = net_nfc_client_transceive(handle,
- (data_h)&rawdata,
- callback,
- user_data);
-
- if (send_buffer != NULL)
- _net_nfc_util_free_mem(send_buffer);
-
- return result;
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_mifare_read(net_nfc_target_handle_h handle,
- uint8_t addr,
- void *callback,
- void *user_data)
-{
- net_nfc_target_info_s* target_info = NULL;
-
- data_s rawdata;
-
- uint8_t send_buffer[4] = { 0 };
-
-
- if (handle == NULL)
- return NET_NFC_NULL_PARAMETER;
-
- if (net_nfc_client_tag_is_connected() == FALSE)
- return NET_NFC_OPERATION_FAIL;
-
- target_info = net_nfc_client_tag_get_client_target_info();
-
- if (target_info != NULL)
- {
- if (target_info->devType < NET_NFC_MIFARE_MINI_PICC ||
- target_info->devType > NET_NFC_MIFARE_ULTRA_PICC)
- {
- DEBUG_CLIENT_MSG("not a MIFARE TAG = [%d]",
- target_info->devType);
- return NET_NFC_NOT_SUPPORTED;
- }
-
- if (target_info->devType == NET_NFC_MIFARE_ULTRA_PICC)
- {
- if (addr > 7)
- return NET_NFC_OUT_OF_BOUND;
- }
- }
-
-
- send_buffer[0] = MIFARE_CMD_READ;
- send_buffer[1] = addr;
-
- net_nfc_util_compute_CRC(CRC_A, send_buffer, 4);
-
- rawdata.buffer = send_buffer;
- rawdata.length = 4;
-
- return net_nfc_client_transceive_data(handle,
- (data_h)&rawdata,
- callback,
- user_data);
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_mifare_write_block(
- net_nfc_target_handle_h handle,
- uint8_t addr,
- data_h data,
- void *callback,
- void *user_data)
-{
- net_nfc_target_info_s* target_info = NULL;
-
- data_s rawdata;
-
- uint8_t* send_buffer = NULL;
-
- uint32_t send_buffer_length = 0;
-
-
- if (handle == NULL)
- return NET_NFC_NULL_PARAMETER;
-
- if (net_nfc_client_tag_is_connected() == FALSE)
- return NET_NFC_OPERATION_FAIL;
-
-
- target_info = net_nfc_client_tag_get_client_target_info();
-
- if (target_info == NULL)
- return NET_NFC_NOT_INITIALIZED;
-
- if (target_info->devType < NET_NFC_MIFARE_MINI_PICC ||
- target_info->devType > NET_NFC_MIFARE_ULTRA_PICC)
- {
- DEBUG_CLIENT_MSG("not a MIFARE TAG = [%d] \n",
- target_info->devType);
- return NET_NFC_NOT_SUPPORTED;
- }
-
- if (target_info->devType == NET_NFC_MIFARE_ULTRA_PICC)
- {
- if (addr > 7)
- return NET_NFC_OUT_OF_BOUND;
- }
-
- if (target_info->devType == NET_NFC_MIFARE_ULTRA_PICC)
- {
- if (((data_s *)data)->length > MIFARE_PAGE_SIZE)
- {
- uint8_t* temp = NULL;
-
- /* cmd + addr + page + CRC */
- send_buffer_length = 1 + 1 + MIFARE_PAGE_SIZE + 2;
-
- _net_nfc_util_alloc_mem(send_buffer,
- send_buffer_length * sizeof(uint8_t));
- if (send_buffer == NULL)
- return NET_NFC_ALLOC_FAIL;
-
- temp = send_buffer;
-
- *temp = MIFARE_CMD_WRITE_PAGE;
- temp++;
-
- *temp = addr;
- temp++;
-
- memcpy(temp,
- ((data_s*)data)->buffer,
- MIFARE_PAGE_SIZE);
-
- }
- else
- {
- uint8_t* temp = NULL;
-
- /* cmd + addr + page + CRC */
- send_buffer_length = 1 + 1 +
- ((data_s*)data)->length + 2;
-
- _net_nfc_util_alloc_mem(send_buffer,
- send_buffer_length * sizeof(uint8_t));
- if (send_buffer == NULL)
- return NET_NFC_ALLOC_FAIL;
-
- temp = send_buffer;
-
- *temp = MIFARE_CMD_WRITE_PAGE;
- temp++;
-
- *temp = addr;
- temp++;
-
- memcpy(temp,
- ((data_s*)data)->buffer,
- ((data_s*)data)->length);
- }
-
- }
- else
- {
-
- if (((data_s*)data)->length > MIFARE_BLOCK_SIZE)
- {
- uint8_t* temp = NULL;
-
- /* cmd + addr + page + CRC */
- send_buffer_length = 1 + 1 + MIFARE_BLOCK_SIZE + 2;
-
- _net_nfc_util_alloc_mem(send_buffer,
- send_buffer_length * sizeof(uint8_t));
- if (send_buffer == NULL)
- return NET_NFC_ALLOC_FAIL;
-
- temp = send_buffer;
-
- *temp = MIFARE_CMD_WRITE_BLOCK;
- temp++;
-
- *temp = addr;
- temp++;
-
- memcpy(temp,
- ((data_s*)data)->buffer,
- MIFARE_BLOCK_SIZE);
- }
- else
- {
- uint8_t* temp = NULL;
-
- /* cmd + addr + page + CRC */
- send_buffer_length = 1 + 1 + ((data_s*)data)->length
- + 2;
-
- _net_nfc_util_alloc_mem(send_buffer,
- send_buffer_length * sizeof(uint8_t));
- if (send_buffer == NULL)
- return NET_NFC_ALLOC_FAIL;
-
- temp = send_buffer;
-
- *temp = MIFARE_CMD_WRITE_BLOCK;
- temp++;
-
- *temp = addr;
- temp++;
-
- memcpy(temp,
- ((data_s*)data)->buffer,
- ((data_s*)data)->length);
- }
- }
-
- net_nfc_util_compute_CRC(CRC_A, send_buffer, send_buffer_length);
-
- rawdata.buffer = send_buffer;
- rawdata.length = send_buffer_length;
-
- net_nfc_error_e result = net_nfc_client_transceive(handle,
- (data_h)&rawdata,
- callback,
- user_data);
-
- if (send_buffer != NULL)
- _net_nfc_util_free_mem(send_buffer);
-
- return result;
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_mifare_write_page(
- net_nfc_target_handle_h handle,
- uint8_t addr,
- data_h data,
- void *callback,
- void *user_data)
-{
- net_nfc_target_info_s* target_info = NULL;
-
- uint8_t* send_buffer = NULL;
-
- uint32_t send_buffer_length = 0;
-
- if (handle == NULL)
- return NET_NFC_NULL_PARAMETER;
-
- if (net_nfc_client_tag_is_connected() == FALSE)
- return NET_NFC_OPERATION_FAIL;
-
- target_info = net_nfc_client_tag_get_client_target_info();
-
- if (target_info == NULL)
- return NET_NFC_NOT_INITIALIZED;
-
- if (target_info->devType < NET_NFC_MIFARE_MINI_PICC ||
- target_info->devType > NET_NFC_MIFARE_ULTRA_PICC)
- {
- DEBUG_CLIENT_MSG("not a MIFARE TAG = [%d] \n",
- target_info->devType);
- return NET_NFC_NOT_SUPPORTED;
- }
-
- if (target_info->devType == NET_NFC_MIFARE_ULTRA_PICC)
- {
- if (addr > 7)
- return NET_NFC_OUT_OF_BOUND;
- }
-
- if (target_info->devType == NET_NFC_MIFARE_ULTRA_PICC)
- {
- if (((data_s*)data)->length > MIFARE_PAGE_SIZE)
- {
- uint8_t* temp = NULL;
-
- /* cmd + addr + page + CRC */
- send_buffer_length = 1 + 1 + MIFARE_PAGE_SIZE + 2;
-
- _net_nfc_util_alloc_mem(send_buffer,
- send_buffer_length * sizeof(uint8_t));
- if (send_buffer == NULL)
- return NET_NFC_ALLOC_FAIL;
-
- temp = send_buffer;
-
- *temp = MIFARE_CMD_WRITE_PAGE;
- temp++;
-
- *temp = addr;
- temp++;
-
- memcpy(temp,
- ((data_s*)data)->buffer,
- MIFARE_PAGE_SIZE);
- }
- else
- {
- uint8_t* temp = NULL;
-
- /* cmd + addr + page + CRC */
- send_buffer_length = 1 + 1 + ((data_s*)data)->length
- + 2;
-
- _net_nfc_util_alloc_mem(send_buffer,
- send_buffer_length * sizeof(uint8_t));
- if (send_buffer == NULL)
- return NET_NFC_ALLOC_FAIL;
-
- temp = send_buffer;
-
- *temp = MIFARE_CMD_WRITE_PAGE;
- temp++;
-
- *temp = addr;
- temp++;
-
- memcpy(temp,
- ((data_s*)data)->buffer,
- ((data_s*)data)->length);
- }
-
- }
- else
- {
- if (((data_s*)data)->length > MIFARE_PAGE_SIZE)
- {
- uint8_t* temp = NULL;
-
- /* cmd + addr + page + CRC */
- send_buffer_length = 1 + 1 + MIFARE_PAGE_SIZE + 2;
-
- _net_nfc_util_alloc_mem(send_buffer,
- send_buffer_length * sizeof(uint8_t));
- if (send_buffer == NULL)
- return NET_NFC_ALLOC_FAIL;
-
- temp = send_buffer;
-
- *temp = MIFARE_CMD_WRITE_BLOCK;
- temp++;
-
- *temp = addr;
- temp++;
-
- memcpy(temp,
- ((data_s*)data)->buffer,
- MIFARE_PAGE_SIZE);
-
- }
- else
- {
- uint8_t* temp = NULL;
-
- /* cmd + addr + page + CRC */
- send_buffer_length = 1 + 1 + ((data_s*)data)->length
- + 2;
-
- _net_nfc_util_alloc_mem(send_buffer,
- send_buffer_length * sizeof(uint8_t));
- if (send_buffer == NULL)
- return NET_NFC_ALLOC_FAIL;
-
- temp = send_buffer;
-
- *temp = MIFARE_CMD_WRITE_BLOCK;
- temp++;
-
- *temp = addr;
- temp++;
-
- memcpy(temp,
- ((data_s*)data)->buffer,
- ((data_s*)data)->length);
- }
-
- }
-
- net_nfc_util_compute_CRC(CRC_A, send_buffer, send_buffer_length);
-
- data_s rawdata;
-
- rawdata.buffer = send_buffer;
- rawdata.length = send_buffer_length;
-
- net_nfc_error_e result = net_nfc_client_transceive(handle,
- (data_h)&rawdata,
- callback,
- user_data);
-
- if (send_buffer != NULL)
- _net_nfc_util_free_mem(send_buffer);
-
- return result;
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_mifare_increment(net_nfc_target_handle_h handle,
- uint8_t addr,
- int value,
- void *callback,
- void *user_data)
-{
- net_nfc_target_info_s* target_info = NULL;
-
- data_s rawdata;
-
- uint8_t send_buffer[8] = { 0 };
-
-
- if (handle == NULL)
- return NET_NFC_NULL_PARAMETER;
-
- if (net_nfc_client_tag_is_connected() == FALSE)
- return NET_NFC_OPERATION_FAIL;
-
- target_info = net_nfc_client_tag_get_client_target_info();
-
- if (target_info)
- {
- if (target_info->devType < NET_NFC_MIFARE_MINI_PICC ||
- target_info->devType > NET_NFC_MIFARE_4K_PICC)
- {
- DEBUG_CLIENT_MSG(
- "not a MIFARE Classic TAG = [%d]",
- target_info->devType);
- return NET_NFC_NOT_SUPPORTED;
- }
- }
-
-
- send_buffer[0] = MIFARE_CMD_INCREMENT;
- send_buffer[1] = addr;
-
- /* little endian.
- little value of byte array will be saved first in memory */
- send_buffer[5] = (value & 0xFF000000) >> 24;
- send_buffer[4] = (value & 0x00FF0000) >> 16;
- send_buffer[3] = (value & 0x0000FF00) >> 8;
- send_buffer[2] = (value & 0x000000FF);
-
- net_nfc_util_compute_CRC(CRC_A, send_buffer, 8);
-
- rawdata.buffer = send_buffer;
- rawdata.length = 8;
-
- return net_nfc_client_transceive(handle, (data_h)&rawdata, callback,
- user_data);
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_mifare_decrement(net_nfc_target_handle_h handle,
- uint8_t addr,
- int value,
- void *callback,
- void *user_data)
-{
- net_nfc_target_info_s* target_info = NULL;
-
- data_s rawdata;
-
- uint8_t send_buffer[8] = { 0 };
-
- if (handle == NULL)
- return NET_NFC_NULL_PARAMETER;
-
- if (net_nfc_client_tag_is_connected() == FALSE)
- return NET_NFC_OPERATION_FAIL;
-
- target_info = net_nfc_client_tag_get_client_target_info();
-
- if (target_info)
- {
-
- if (target_info->devType < NET_NFC_MIFARE_MINI_PICC ||
- target_info->devType > NET_NFC_MIFARE_4K_PICC)
- {
- DEBUG_CLIENT_MSG("not a MIFARE Classic TAG = [%d] \n",
- target_info->devType);
- return NET_NFC_NOT_SUPPORTED;
- }
- }
-
- send_buffer[0] = MIFARE_CMD_DECREMENT;
- send_buffer[1] = addr;
-
- /* little endian.
- little value of byte array will be saved first in memory */
- send_buffer[5] = (value & 0xFF000000) >> 24;
- send_buffer[4] = (value & 0x00FF0000) >> 16;
- send_buffer[3] = (value & 0x0000FF00) >> 8;
- send_buffer[2] = (value & 0x000000FF);
-
- net_nfc_util_compute_CRC(CRC_A, send_buffer, 8);
-
- DEBUG_MSG_PRINT_BUFFER(send_buffer, 8);
-
- rawdata.buffer = send_buffer;
- rawdata.length = 8;
-
- return net_nfc_client_transceive(handle, (data_h)&rawdata, callback,
- user_data);
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_mifare_transfer(net_nfc_target_handle_h handle,
- uint8_t addr,
- void *callback,
- void *user_data)
-{
- net_nfc_target_info_s* target_info = NULL;
-
- data_s rawdata;
-
- uint8_t send_buffer[4] = { 0 };
-
- if (handle == NULL)
- return NET_NFC_NULL_PARAMETER;
-
- if (net_nfc_client_tag_is_connected() == FALSE)
- return NET_NFC_OPERATION_FAIL;
-
- target_info = net_nfc_client_tag_get_client_target_info();
-
- if (target_info)
- {
- if (target_info->devType < NET_NFC_MIFARE_MINI_PICC ||
- target_info->devType > NET_NFC_MIFARE_4K_PICC)
- {
- DEBUG_CLIENT_MSG("not a MIFARE Classic TAG = [%d]",
- target_info->devType);
- return NET_NFC_NOT_SUPPORTED;
- }
- }
-
- send_buffer[0] = MIFARE_CMD_TRANSFER;
- send_buffer[1] = addr;
-
- net_nfc_util_compute_CRC(CRC_A, send_buffer, 4);
-
- rawdata.buffer = send_buffer;
- rawdata.length = 4;
-
- return net_nfc_client_transceive(handle, (data_h)&rawdata, callback,
- user_data);
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_mifare_restore(net_nfc_target_handle_h handle,
- uint8_t addr,
- void *callback,
- void *user_data)
-{
- net_nfc_target_info_s* target_info = NULL;
-
- data_s rawdata;
-
- uint8_t send_buffer[4] = { 0 };
-
- if (handle == NULL)
- return NET_NFC_NULL_PARAMETER;
-
- if (net_nfc_client_tag_is_connected() == FALSE)
- return NET_NFC_OPERATION_FAIL;
-
- target_info = net_nfc_client_tag_get_client_target_info();
-
- if (target_info)
- {
- if (target_info->devType < NET_NFC_MIFARE_MINI_PICC ||
- target_info->devType > NET_NFC_MIFARE_4K_PICC)
- {
- DEBUG_CLIENT_MSG("not a MIFARE Classic TAG = [%d]",
- target_info->devType);
- return NET_NFC_NOT_SUPPORTED;
- }
- }
-
- send_buffer[0] = MIFARE_CMD_RESTORE;
- send_buffer[1] = addr;
-
- net_nfc_util_compute_CRC(CRC_A, send_buffer, 4);
-
- rawdata.buffer = send_buffer;
- rawdata.length = 4;
-
- return net_nfc_client_transceive(handle, (data_h)&rawdata, callback,
- user_data);
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_mifare_create_default_key(data_h* key)
-{
- if (key == NULL)
- return NET_NFC_NULL_PARAMETER;
-
- return net_nfc_create_data(key, default_key, 6);
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_mifare_create_application_directory_key(
- data_h* key)
-{
- if (key == NULL)
- return NET_NFC_NULL_PARAMETER;
-
- return net_nfc_create_data(key, mad_key, 6);
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_mifare_create_net_nfc_forum_key(data_h* key)
-{
- if (key == NULL)
- return NET_NFC_NULL_PARAMETER;
-
- return net_nfc_create_data(key, net_nfc_forum_key, 6);
-}
-
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <stdbool.h>
-
-#include "net_nfc_typedef_internal.h"
-#include "net_nfc_debug_internal.h"
-#include "net_nfc_data.h"
-#include "net_nfc_target_info.h"
-#include "net_nfc_util_internal.h"
-
-#ifndef NET_NFC_EXPORT_API
-#define NET_NFC_EXPORT_API __attribute__((visibility("default")))
-#endif
-
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_tag_type(net_nfc_target_info_h target_info, net_nfc_target_type_e * type)
-{
- if (target_info == NULL || type == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
- net_nfc_target_info_s * tmp_target_info = (net_nfc_target_info_s*)target_info;
-
- *type = tmp_target_info->devType;
- return NET_NFC_OK;
-}
-
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_tag_handle(net_nfc_target_info_h target_info, net_nfc_target_handle_h * handle)
-{
- if (target_info == NULL || handle == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
- net_nfc_target_info_s * tmp_target_info = (net_nfc_target_info_s*)target_info;
-
- *handle = (net_nfc_target_handle_h)tmp_target_info->handle;
- return NET_NFC_OK;
-}
-
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_tag_ndef_support(net_nfc_target_info_h target_info, bool * is_support)
-{
- if (target_info == NULL || is_support == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
- net_nfc_target_info_s * tmp_target_info = (net_nfc_target_info_s*)target_info;
-
- *is_support = (bool)tmp_target_info->is_ndef_supported;
- return NET_NFC_OK;
-}
-
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_tag_max_data_size(net_nfc_target_info_h target_info, uint32_t * max_size)
-{
- if (target_info == NULL || max_size == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
- net_nfc_target_info_s * tmp_target_info = (net_nfc_target_info_s*)target_info;
-
- *max_size = tmp_target_info->maxDataSize;
- return NET_NFC_OK;
-}
-
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_tag_actual_data_size(net_nfc_target_info_h target_info, uint32_t * actual_data)
-{
- if (target_info == NULL || actual_data == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
- net_nfc_target_info_s * tmp_target_info = (net_nfc_target_info_s*)target_info;
-
- *actual_data = tmp_target_info->actualDataSize;
- return NET_NFC_OK;
-}
-
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_tag_info_keys(net_nfc_target_info_h target_info, char ***keys, int* number_of_keys)
-{
- if (keys == NULL || number_of_keys == NULL || target_info == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
-
- net_nfc_target_info_s* handle = (net_nfc_target_info_s*)target_info;
-
- if (handle->tag_info_list == NULL)
- {
- return NET_NFC_NO_DATA_FOUND;
- }
-
- if (handle->number_of_keys <= 0)
- {
- return NET_NFC_NO_DATA_FOUND;
- }
-
- int i = 0;
-
- if (handle->keylist != NULL)
- {
- *keys = handle->keylist;
- return NET_NFC_OK;
- }
-
- _net_nfc_util_alloc_mem(*keys, handle->number_of_keys * sizeof(char *));
- if (*keys == NULL)
- return NET_NFC_ALLOC_FAIL;
-
- net_nfc_tag_info_s* tag_info = handle->tag_info_list;
-
- for (; i < handle->number_of_keys; i++, tag_info++)
- {
- (*keys)[i] = tag_info->key;
- }
-
- *number_of_keys = handle->number_of_keys;
-
- DEBUG_CLIENT_MSG("number of keys = [%d]", handle->number_of_keys);
-
- handle->keylist = *keys;
-
- return NET_NFC_OK;
-}
-
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_tag_info_value(net_nfc_target_info_h target_info, const char* key, data_h* value)
-{
- if (target_info == NULL || key == NULL || value == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
-
- net_nfc_target_info_s* handle = (net_nfc_target_info_s*)target_info;
-
- if (handle->tag_info_list == NULL)
- {
- return NET_NFC_NO_DATA_FOUND;
- }
-
- int i = 0;
-
- net_nfc_tag_info_s* tag_info = handle->tag_info_list;
-
- for (; i < handle->number_of_keys; i++, tag_info++)
- {
- if (strcmp(key, tag_info->key) == 0)
- {
- if (tag_info->value == NULL)
- {
- return NET_NFC_NO_DATA_FOUND;
- }
- else
- {
- *value = tag_info->value;
- break;
- }
- }
- }
-
- if (i == handle->number_of_keys)
- return NET_NFC_NOT_SUPPORTED;
-
- return NET_NFC_OK;
-}
-
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_duplicate_target_info(net_nfc_target_info_h origin, net_nfc_target_info_h *result)
-{
- net_nfc_target_info_s *handle = (net_nfc_target_info_s *)origin;
- net_nfc_target_info_s *temp = NULL;
-
- if (handle == NULL || result == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
-
- _net_nfc_util_alloc_mem(temp, sizeof(net_nfc_target_info_s));
- if (temp == NULL)
- {
- return NET_NFC_ALLOC_FAIL;
- }
-
- temp->ndefCardState = handle->ndefCardState;
- temp->actualDataSize = handle->actualDataSize;
- temp->maxDataSize = handle->maxDataSize;
- temp->devType = handle->devType;
- temp->handle = handle->handle;
- temp->is_ndef_supported = handle->is_ndef_supported;
- temp->number_of_keys = handle->number_of_keys;
-
- if (temp->number_of_keys > 0)
- {
- int i;
-
- _net_nfc_util_alloc_mem(temp->tag_info_list, temp->number_of_keys * sizeof(net_nfc_tag_info_s));
- if (temp->tag_info_list == NULL)
- {
- _net_nfc_util_free_mem(temp);
- return NET_NFC_ALLOC_FAIL;
- }
-
- for (i = 0; i < handle->number_of_keys; i++)
- {
- if (handle->tag_info_list[i].key != NULL)
- _net_nfc_util_strdup(temp->tag_info_list[i].key, handle->tag_info_list[i].key);
-
- if (handle->tag_info_list[i].value != NULL)
- {
- data_s *data = (data_s *)handle->tag_info_list[i].value;
-
- net_nfc_create_data(&temp->tag_info_list[i].value, data->buffer, data->length);
- }
- }
- }
-
- if (handle->raw_data.length > 0)
- {
- net_nfc_util_alloc_data(&temp->raw_data, handle->raw_data.length);
- memcpy(temp->raw_data.buffer, handle->raw_data.buffer, temp->raw_data.length);
- }
-
- *result = (net_nfc_target_info_h)temp;
-
- return NET_NFC_OK;
-}
-
-static net_nfc_error_e net_nfc_util_release_tag_info(net_nfc_target_info_s *info)
-{
- net_nfc_error_e result = NET_NFC_OK;
- net_nfc_tag_info_s *list = NULL;
-
- if (info == NULL)
- return NET_NFC_NULL_PARAMETER;
-
- list = info->tag_info_list;
- if (list != NULL)
- {
- int i = 0;
- for (i = 0; i < info->number_of_keys; i++, list++)
- {
- if (list->key != NULL)
- _net_nfc_util_free_mem(list->key);
-
- if (list->value != NULL)
- net_nfc_free_data(list->value);
- }
-
- _net_nfc_util_free_mem(info->tag_info_list);
- }
-
- if (info->keylist != NULL)
- {
- _net_nfc_util_free_mem(info->keylist);
- }
-
- net_nfc_util_free_data(&info->raw_data);
-
- return result;
-}
-
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_release_tag_info(net_nfc_target_info_h target_info)
-{
- net_nfc_error_e result = NET_NFC_OK;
- net_nfc_target_info_s *info = (net_nfc_target_info_s *)target_info;
-
- if (info == NULL)
- return NET_NFC_NULL_PARAMETER;
-
- net_nfc_util_release_tag_info(info);
-
- _net_nfc_util_free_mem(info);
-
- return result;
-}
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "net_nfc_debug_internal.h"
-#include "net_nfc_util_gdbus_internal.h"
-#include "net_nfc_gdbus.h"
-#include "net_nfc_client.h"
-#include "net_nfc_client_manager.h"
-#include "net_nfc_client_test.h"
-
-#ifndef NET_NFC_EXPORT_API
-#define NET_NFC_EXPORT_API __attribute__((visibility("default")))
-#endif
-
-typedef struct _TestFuncData TestFuncData;
-
-struct _TestFuncData
-{
- gpointer callback;
- gpointer user_data;
-};
-
-static void test_call_sim_test_callback(GObject *source_object,
- GAsyncResult *res,
- gpointer user_data);
-
-static void test_call_prbs_test_callback(GObject *source_object,
- GAsyncResult *res,
- gpointer user_data);
-
-static void test_call_get_firmware_version_callback(GObject *source_object,
- GAsyncResult *res,
- gpointer user_data);
-
-static void test_call_set_ee_data_callback(GObject *source_object,
- GAsyncResult *res,
- gpointer user_data);
-
-static NetNfcGDbusTest *test_proxy = NULL;
-
-
-static void test_call_sim_test_callback(GObject *source_object,
- GAsyncResult *res,
- gpointer user_data)
-{
- TestFuncData *func_data;
-
- net_nfc_error_e out_result = NET_NFC_OK;
- GError *error = NULL;
-
- net_nfc_client_test_sim_test_completed callback;
- gpointer data;
-
- if (net_nfc_gdbus_test_call_sim_test_finish(
- NET_NFC_GDBUS_TEST(source_object),
- (gint *)&out_result,
- res,
- &error) == FALSE)
- {
-
- out_result = NET_NFC_UNKNOWN_ERROR;
-
- DEBUG_ERR_MSG("Can not finish sim_test: %s",
- error->message);
- g_error_free(error);
- }
-
- func_data = user_data;
- if (func_data == NULL)
- return;
-
- if (func_data->callback == NULL)
- {
- g_free(func_data);
- return;
- }
-
- callback = (net_nfc_client_test_sim_test_completed)func_data->callback;
- data = func_data->user_data;
-
- callback(out_result, data);
-
- g_free(func_data);
-}
-
-static void test_call_prbs_test_callback(GObject *source_object,
- GAsyncResult *res,
- gpointer user_data)
-{
- TestFuncData *func_data;
-
- net_nfc_error_e out_result = NET_NFC_OK;
- GError *error = NULL;
-
- net_nfc_client_test_prbs_test_completed callback;
- gpointer data;
-
- if (net_nfc_gdbus_test_call_prbs_test_finish(
- NET_NFC_GDBUS_TEST(source_object),
- (gint *)&out_result,
- res,
- &error) == FALSE)
- {
-
- out_result = NET_NFC_UNKNOWN_ERROR;
-
- DEBUG_ERR_MSG("Can not finish prbs test: %s",
- error->message);
- g_error_free(error);
- }
-
- func_data = user_data;
- if (func_data == NULL)
- return;
-
- if (func_data->callback == NULL)
- {
- g_free(func_data);
- return;
- }
-
- callback = (net_nfc_client_test_prbs_test_completed)
- func_data->callback;
- data = func_data->user_data;
-
- callback(out_result, data);
-
- g_free(func_data);
-}
-
-static void test_call_get_firmware_version_callback(GObject *source_object,
- GAsyncResult *res,
- gpointer user_data)
-{
- TestFuncData *func_data;
-
- net_nfc_error_e out_result = NET_NFC_OK;
- gchar *out_version = NULL;
- GError *error = NULL;
-
- net_nfc_client_test_get_firmware_version_completed callback;
- gpointer data;
-
- if (net_nfc_gdbus_test_call_get_firmware_version_finish(
- NET_NFC_GDBUS_TEST(source_object),
- (gint *)&out_result,
- &out_version,
- res,
- &error) == FALSE)
- {
-
- out_result = NET_NFC_UNKNOWN_ERROR;
-
- DEBUG_ERR_MSG("Can not finish get_firmware_version: %s",
- error->message);
- g_error_free(error);
- }
-
- func_data = user_data;
- if (func_data == NULL)
- return;
-
- if (func_data->callback == NULL)
- {
- g_free(out_version);
- g_free(func_data);
- return;
- }
-
- callback = (net_nfc_client_test_get_firmware_version_completed)
- func_data->callback;
- data = func_data->user_data;
-
- callback(out_result, out_version, data);
-
- g_free(out_version);
- g_free(func_data);
-}
-
-static void test_call_set_ee_data_callback(GObject *source_object,
- GAsyncResult *res,
- gpointer user_data)
-{
- TestFuncData *func_data;
-
- net_nfc_error_e out_result = NET_NFC_OK;
-
- GError *error = NULL;
-
- net_nfc_client_test_set_ee_data_completed callback;
-
- if (net_nfc_gdbus_test_call_set_ee_data_finish(
- NET_NFC_GDBUS_TEST(source_object),
- (gint *)&out_result,
- res,
- &error) == FALSE)
- {
- out_result = NET_NFC_UNKNOWN_ERROR;
-
- DEBUG_ERR_MSG("Can not finish set_ee_data: %s\n",
- error->message);
- g_error_free(error);
- }
-
- func_data = user_data;
-
- if (func_data->callback == NULL)
- {
- g_free(func_data);
- return;
- }
-
- callback = (net_nfc_client_test_set_ee_data_completed)
- func_data->callback;
-
- callback(out_result, func_data->user_data);
-
- g_free(func_data);
-}
-
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_test_sim_test(
- net_nfc_client_test_sim_test_completed callback,
- void *user_data)
-{
- TestFuncData *func_data;
-
- if (test_proxy == NULL)
- return NET_NFC_UNKNOWN_ERROR;
-
- /* prevent executing daemon when nfc is off */
- if (net_nfc_client_manager_is_activated() == false) {
- return NET_NFC_INVALID_STATE;
- }
-
- func_data = g_new0(TestFuncData, 1);
- if (func_data == NULL)
- return NET_NFC_UNKNOWN_ERROR;
-
- func_data->callback = (gpointer)callback;
- func_data->user_data = user_data;
-
- net_nfc_gdbus_test_call_sim_test(test_proxy,
- net_nfc_client_gdbus_get_privilege(),
- NULL,
- test_call_sim_test_callback,
- func_data);
-
- return NET_NFC_OK;
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_test_sim_test_sync(void)
-{
- GError *error = NULL;
- net_nfc_error_e out_result = NET_NFC_OK;
-
- if (test_proxy == NULL)
- return NET_NFC_UNKNOWN_ERROR;
-
- /* prevent executing daemon when nfc is off */
- if (net_nfc_client_manager_is_activated() == false) {
- return NET_NFC_INVALID_STATE;
- }
-
- if (net_nfc_gdbus_test_call_sim_test_sync(test_proxy,
- net_nfc_client_gdbus_get_privilege(),
- (gint *)&out_result,
- NULL,
- &error) == FALSE)
- {
- DEBUG_CLIENT_MSG("can not call SimTest: %s",
- error->message);
- g_error_free(error);
- return NET_NFC_UNKNOWN_ERROR;
- }
-
- return out_result;
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_test_prbs_test(uint32_t tech,
- uint32_t rate,
- net_nfc_client_test_prbs_test_completed callback,
- void *user_data)
-{
- TestFuncData *func_data;
-
- if (test_proxy == NULL)
- return NET_NFC_UNKNOWN_ERROR;
-
- /* prevent executing daemon when nfc is off */
- if (net_nfc_client_manager_is_activated() == false) {
- return NET_NFC_INVALID_STATE;
- }
-
- func_data = g_new0(TestFuncData, 1);
- if (func_data == NULL)
- return NET_NFC_UNKNOWN_ERROR;
-
- func_data->callback = (gpointer)callback;
- func_data->user_data = user_data;
-
- net_nfc_gdbus_test_call_prbs_test(test_proxy,
- tech,
- rate,
- net_nfc_client_gdbus_get_privilege(),
- NULL,
- test_call_prbs_test_callback,
- func_data);
-
- return NET_NFC_OK;
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_test_prbs_test_sync(uint32_t tech,
- uint32_t rate)
-{
- GError *error = NULL;
- net_nfc_error_e out_result = NET_NFC_OK;
-
- if (test_proxy == NULL)
- return NET_NFC_UNKNOWN_ERROR;
-
- /* prevent executing daemon when nfc is off */
- if (net_nfc_client_manager_is_activated() == false) {
- return NET_NFC_INVALID_STATE;
- }
-
- if (net_nfc_gdbus_test_call_prbs_test_sync(test_proxy,
- tech,
- rate,
- net_nfc_client_gdbus_get_privilege(),
- (gint *)&out_result,
- NULL,
- &error) == FALSE)
- {
- DEBUG_CLIENT_MSG("can not call PrbsTest: %s",
- error->message);
- g_error_free(error);
- return NET_NFC_UNKNOWN_ERROR;
- }
-
- return out_result;
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_test_get_firmware_version(
- net_nfc_client_test_get_firmware_version_completed callback,
- void *user_data)
-{
- TestFuncData *func_data;
-
- if (test_proxy == NULL)
- return NET_NFC_UNKNOWN_ERROR;
-
- /* prevent executing daemon when nfc is off */
- if (net_nfc_client_manager_is_activated() == false) {
- return NET_NFC_INVALID_STATE;
- }
-
- func_data = g_new0(TestFuncData, 1);
- if (func_data == NULL)
- return NET_NFC_UNKNOWN_ERROR;
-
- func_data->callback = (gpointer)callback;
- func_data->user_data = user_data;
-
- net_nfc_gdbus_test_call_get_firmware_version(test_proxy,
- net_nfc_client_gdbus_get_privilege(),
- NULL,
- test_call_get_firmware_version_callback,
- func_data);
-
- return NET_NFC_OK;
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_test_get_firmware_version_sync(char **version)
-{
- gchar *out_version = NULL;
- GError *error = NULL;
-
- net_nfc_error_e out_result = NET_NFC_OK;
-
- if (test_proxy == NULL)
- return NET_NFC_UNKNOWN_ERROR;
-
- /* prevent executing daemon when nfc is off */
- if (net_nfc_client_manager_is_activated() == false) {
- return NET_NFC_INVALID_STATE;
- }
-
- if (net_nfc_gdbus_test_call_get_firmware_version_sync(test_proxy,
- net_nfc_client_gdbus_get_privilege(),
- (gint *)out_result,
- &out_version,
- NULL,
- &error) == FALSE)
- {
- DEBUG_CLIENT_MSG("can not call PrbsTest: %s",
- error->message);
- g_error_free(error);
- return NET_NFC_UNKNOWN_ERROR;
- }
-
- if (version != NULL)
- *version = out_version;
-
- return out_result;
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_test_set_ee_data(int mode,
- int reg_id,
- data_h data,
- net_nfc_client_test_set_ee_data_completed callback,
- void *user_data)
-{
- TestFuncData *func_data;
- GVariant *variant = NULL;
-
- if (test_proxy == NULL)
- return NET_NFC_UNKNOWN_ERROR;
-
- /* prevent executing daemon when nfc is off */
- if (net_nfc_client_manager_is_activated() == false) {
- return NET_NFC_INVALID_STATE;
- }
-
- func_data = g_new0(TestFuncData, 1);
- func_data->callback = (gpointer)callback;
- func_data->user_data = user_data;
-
- variant = net_nfc_util_gdbus_data_to_variant((data_s *)data);
-
- net_nfc_gdbus_test_call_set_ee_data(test_proxy,
- mode,
- reg_id,
- variant,
- net_nfc_client_gdbus_get_privilege(),
- NULL,
- test_call_set_ee_data_callback,
- func_data);
-
- return NET_NFC_OK;
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_test_set_ee_data_sync(int mode,
- int reg_id,
- data_h data)
-{
- GVariant *variant = NULL;
- GError *error = NULL;
-
- net_nfc_error_e out_result = NET_NFC_OK;
-
- if (test_proxy == NULL)
- return NET_NFC_UNKNOWN_ERROR;
-
- /* prevent executing daemon when nfc is off */
- if (net_nfc_client_manager_is_activated() == false) {
- return NET_NFC_INVALID_STATE;
- }
-
- variant = net_nfc_util_gdbus_data_to_variant((data_s *)data);
-
- if (net_nfc_gdbus_test_call_set_ee_data_sync(test_proxy,
- mode,
- reg_id,
- variant,
- net_nfc_client_gdbus_get_privilege(),
- (gint *)&out_result,
- NULL,
- &error) == FALSE)
- {
- DEBUG_CLIENT_MSG("can not call SetEeTest: %s",
- error->message);
- g_error_free(error);
- return NET_NFC_UNKNOWN_ERROR;
- }
-
- return out_result;
-}
-
-net_nfc_error_e net_nfc_client_test_init(void)
-{
- GError *error = NULL;
-
- if (test_proxy)
- {
- DEBUG_CLIENT_MSG("Already initialized");
-
- return NET_NFC_OK;
- }
-
- test_proxy = net_nfc_gdbus_test_proxy_new_for_bus_sync(
- G_BUS_TYPE_SYSTEM,
- G_DBUS_PROXY_FLAGS_NONE,
- "org.tizen.NetNfcService",
- "/org/tizen/NetNfcService/Test",
- NULL,
- &error);
-
- if (test_proxy == NULL)
- {
- DEBUG_ERR_MSG("Can not create proxy : %s", error->message);
- g_error_free(error);
-
- return NET_NFC_UNKNOWN_ERROR;
- }
-
- return NET_NFC_OK;
-}
-
-void net_nfc_client_test_deinit(void)
-{
- if (test_proxy)
- {
- g_object_unref(test_proxy);
- test_proxy = NULL;
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <string.h>
-
-#include "net_nfc_typedef_internal.h"
-#include "net_nfc_debug_internal.h"
-#include "net_nfc_util_internal.h"
-#include "net_nfc_util_gdbus_internal.h"
-#include "net_nfc_gdbus.h"
-#include "net_nfc_client.h"
-#include "net_nfc_client_manager.h"
-#include "net_nfc_client_tag_internal.h"
-#include "net_nfc_client_transceive.h"
-
-#ifndef NET_NFC_EXPORT_API
-#define NET_NFC_EXPORT_API __attribute__((visibility("default")))
-#endif
-
-static NetNfcGDbusTransceive *transceive_proxy = NULL;
-
-static GVariant *transceive_data_to_transceive_variant(
- net_nfc_target_type_e dev_type,
- data_s *data);
-
-static void transceive_call(GObject *source_object,
- GAsyncResult *res,
- gpointer user_data);
-
-static void transceive_data_call(GObject *source_object,
- GAsyncResult *res,
- gpointer user_data);
-
-typedef struct _TransceiveFuncData TransceiveFuncData;
-
-struct _TransceiveFuncData
-{
- gpointer transceive_send_callback;
- gpointer transceive_send_data;
-};
-
-static GVariant *transceive_data_to_transceive_variant(
- net_nfc_target_type_e devType,
- data_s *data)
-{
- GVariant *variant = NULL;
- data_s transceive_info = {NULL,};
-
- if (data == NULL)
- {
- DEBUG_ERR_MSG("data is empty");
- return NULL;
- }
-
- switch (devType)
- {
- case NET_NFC_MIFARE_MINI_PICC :
- case NET_NFC_MIFARE_1K_PICC :
- case NET_NFC_MIFARE_4K_PICC :
- case NET_NFC_MIFARE_ULTRA_PICC :
- {
- if(net_nfc_util_alloc_data(&transceive_info,
- data->length + 2) == true)
- {
- memcpy(transceive_info.buffer,
- data->buffer,
- data->length);
-
- net_nfc_util_compute_CRC(CRC_A,
- transceive_info.buffer,
- transceive_info.length);
- }
- }
- break;
-
- case NET_NFC_JEWEL_PICC :
- {
- if (data->length > 9)
- {
- DEBUG_ERR_MSG("data length is larger than 9");
- return NULL;
- }
-
- if(net_nfc_util_alloc_data(&transceive_info, 9) == true)
- {
- memcpy(transceive_info.buffer,
- data->buffer,
- data->length);
- net_nfc_util_compute_CRC(CRC_B,
- transceive_info.buffer,
- transceive_info.length);
- }
-
- }
- break;
-
- default :
- {
- if(net_nfc_util_alloc_data(&transceive_info,
- data->length) == true)
- {
- memcpy(transceive_info.buffer,
- data->buffer,
- data->length);
- }
- }
- break;
- }
-
- variant = net_nfc_util_gdbus_data_to_variant(&transceive_info);
-
- net_nfc_util_free_data(&transceive_info);
-
- return variant;
-}
-
-static void transceive_data_call(GObject *source_object,
- GAsyncResult *res,
- gpointer user_data)
-{
- TransceiveFuncData *func_data;
-
- net_nfc_error_e out_result = NET_NFC_OK;
- GError *error = NULL;
-
- GVariant *out_data = NULL;
-
- data_s resp = {NULL,};
-
- if(net_nfc_gdbus_transceive_call_transceive_data_finish(
- NET_NFC_GDBUS_TRANSCEIVE(source_object),
- (gint *)&out_result,
- &out_data,
- res,
- &error) == FALSE)
- {
- out_result = NET_NFC_UNKNOWN_ERROR;
-
- DEBUG_ERR_MSG("Can not finish transceive: %s", error->message);
- g_error_free(error);
- }
-
- func_data = (TransceiveFuncData*) user_data;
- if(func_data == NULL)
- {
- DEBUG_ERR_MSG("can not get TransceiveFuncData");
- return;
- }
-
- if(func_data->transceive_send_callback == NULL)
- {
- DEBUG_CLIENT_MSG("callback function is not avaiilable");
- g_free(func_data);
- return;
- }
-
- net_nfc_util_gdbus_variant_to_data_s(out_data, &resp);
-
- ((nfc_transceive_data_callback)func_data->transceive_send_callback)(
- out_result,
- &resp,
- func_data->transceive_send_data);
-
- net_nfc_util_free_data(&resp);
-
- g_free(func_data);
-}
-
-static void transceive_call(GObject *source_object,
- GAsyncResult *res,
- gpointer user_data)
-{
- TransceiveFuncData *func_data;
-
- net_nfc_error_e out_result = NET_NFC_OK;
- GError *error = NULL;
-
- if(net_nfc_gdbus_transceive_call_transceive_finish(
- NET_NFC_GDBUS_TRANSCEIVE(source_object),
- (gint *)&out_result,
- res,
- &error) == FALSE)
- {
- out_result = NET_NFC_UNKNOWN_ERROR;
-
- DEBUG_ERR_MSG("Can not finish transceive: %s", error->message);
- g_error_free(error);
- }
-
- func_data = (TransceiveFuncData*) user_data;
- if(func_data == NULL)
- {
- DEBUG_ERR_MSG("can not get TransceiveFuncData");
- return;
- }
-
- if(func_data->transceive_send_callback == NULL)
- {
- DEBUG_CLIENT_MSG("callback function is not avaiilable");
- g_free(func_data);
- return;
- }
-
- ((nfc_transceive_callback)func_data->transceive_send_callback)(
- out_result,
- func_data->transceive_send_data);
-
- g_free(func_data);
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_transceive(net_nfc_target_handle_h handle,
- data_h rawdata,
- nfc_transceive_callback callback,
- void *user_data)
-{
- net_nfc_target_info_s *target_info = NULL;
- data_s *data = (data_s *)rawdata;
-
- GVariant *arg_data = NULL;
- TransceiveFuncData *funcdata = NULL;
-
- if (transceive_proxy == NULL)
- {
- DEBUG_ERR_MSG("Can not get TransceiveProxy");
- return NET_NFC_UNKNOWN_ERROR;
- }
-
- DEBUG_CLIENT_MSG("send reqeust :: transceive = [%p]", handle);
-
- if (handle == NULL || rawdata == NULL)
- return NET_NFC_NULL_PARAMETER;
-
- /* prevent executing daemon when nfc is off */
- if (net_nfc_client_manager_is_activated() == false) {
- return NET_NFC_INVALID_STATE;
- }
-
- if (net_nfc_client_tag_is_connected() == FALSE)
- return NET_NFC_OPERATION_FAIL;
-
- /* fill trans information struct */
- target_info = net_nfc_client_tag_get_client_target_info();
-
- if (target_info == NULL)
- return NET_NFC_OPERATION_FAIL;
-
- arg_data = transceive_data_to_transceive_variant(target_info->devType,
- data);
- if (arg_data == NULL)
- return NET_NFC_OPERATION_FAIL;
-
- funcdata = g_new0(TransceiveFuncData, 1);
-
- funcdata->transceive_send_callback = (gpointer)callback;
- funcdata->transceive_send_data = user_data;
-
- net_nfc_gdbus_transceive_call_transceive(transceive_proxy,
- GPOINTER_TO_UINT(handle),
- target_info->devType,
- arg_data,
- net_nfc_client_gdbus_get_privilege(),
- NULL,
- transceive_call,
- funcdata);
-
- return NET_NFC_OK;
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_transceive_data(net_nfc_target_handle_h handle,
- data_h rawdata,
- nfc_transceive_data_callback callback,
- void *user_data)
-{
- net_nfc_target_info_s *target_info = NULL;
- data_s *data = (data_s *)rawdata;
-
- GVariant *arg_data = NULL;
- TransceiveFuncData *funcdata = NULL;
-
- if (transceive_proxy == NULL)
- {
- DEBUG_ERR_MSG("Can not get TransceiveProxy");
- return NET_NFC_UNKNOWN_ERROR;
- }
-
- DEBUG_CLIENT_MSG("send reqeust :: transceive = [%p]", handle);
-
- if (handle == NULL || rawdata == NULL)
- return NET_NFC_NULL_PARAMETER;
-
- /* prevent executing daemon when nfc is off */
- if (net_nfc_client_manager_is_activated() == false) {
- return NET_NFC_INVALID_STATE;
- }
-
- if (net_nfc_client_tag_is_connected() == FALSE)
- return NET_NFC_OPERATION_FAIL;
-
- /* fill trans information struct */
- target_info = net_nfc_client_tag_get_client_target_info();
-
- if (target_info == NULL)
- return NET_NFC_OPERATION_FAIL;
-
- arg_data = transceive_data_to_transceive_variant(target_info->devType,
- data);
- if (arg_data == NULL)
- return NET_NFC_OPERATION_FAIL;
-
- funcdata = g_new0(TransceiveFuncData, 1);
-
- funcdata->transceive_send_callback = (gpointer)callback;
- funcdata->transceive_send_data = user_data;
-
- net_nfc_gdbus_transceive_call_transceive_data(transceive_proxy,
- GPOINTER_TO_UINT(handle),
- target_info->devType,
- arg_data,
- net_nfc_client_gdbus_get_privilege(),
- NULL,
- transceive_data_call,
- funcdata);
-
- return NET_NFC_OK;
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_transceive_sync(net_nfc_target_handle_h handle,
- data_h rawdata)
-{
- net_nfc_target_info_s *target_info = NULL;
- data_s *data = (data_s *)rawdata;
-
- GError *error = NULL;
- GVariant *arg_data = NULL;
-
- net_nfc_error_e out_result;
-
- if (transceive_proxy == NULL)
- {
- DEBUG_ERR_MSG("Can not get TransceiveProxy");
- return NET_NFC_UNKNOWN_ERROR;
- }
-
- DEBUG_CLIENT_MSG("send reqeust :: transceive = [%p]", handle);
-
- if (handle == NULL || rawdata == NULL)
- return NET_NFC_NULL_PARAMETER;
-
- /* prevent executing daemon when nfc is off */
- if (net_nfc_client_manager_is_activated() == false) {
- return NET_NFC_INVALID_STATE;
- }
-
- if (net_nfc_client_tag_is_connected() == FALSE)
- return NET_NFC_OPERATION_FAIL;
-
- /* fill trans information struct */
- target_info = net_nfc_client_tag_get_client_target_info();
-
- if (target_info == NULL)
- return NET_NFC_OPERATION_FAIL;
-
- arg_data = transceive_data_to_transceive_variant(target_info->devType,
- data);
- if (arg_data == NULL)
- return NET_NFC_OPERATION_FAIL;
-
- if(net_nfc_gdbus_transceive_call_transceive_sync(transceive_proxy,
- GPOINTER_TO_UINT(handle),
- target_info->devType,
- arg_data,
- net_nfc_client_gdbus_get_privilege(),
- (gint *)&out_result,
- NULL,
- &error) == FALSE)
- {
- DEBUG_ERR_MSG("Transceive (sync call) failed: %s",
- error->message);
-
- g_error_free(error);
- return NET_NFC_UNKNOWN_ERROR;
- }
-
- return out_result;
-}
-
-NET_NFC_EXPORT_API
-net_nfc_error_e net_nfc_client_transceive_data_sync(
- net_nfc_target_handle_h handle,
- data_h rawdata,
- data_h *response)
-{
- net_nfc_target_info_s *target_info = NULL;
- data_s *data = (data_s *)rawdata;
-
- GError *error = NULL;
- GVariant *arg_data = NULL;
- GVariant *out_data = NULL;
-
- net_nfc_error_e out_result = NET_NFC_OK;
-
- if (transceive_proxy == NULL)
- {
- DEBUG_ERR_MSG("Can not get TransceiveProxy");
- return NET_NFC_UNKNOWN_ERROR;
- }
-
- DEBUG_CLIENT_MSG("send reqeust :: transceive = [%p]", handle);
-
- if (handle == NULL || rawdata == NULL)
- return NET_NFC_NULL_PARAMETER;
-
- /* prevent executing daemon when nfc is off */
- if (net_nfc_client_manager_is_activated() == false) {
- return NET_NFC_INVALID_STATE;
- }
-
- if (net_nfc_client_tag_is_connected() == FALSE)
- return NET_NFC_OPERATION_FAIL;
-
- /* fill trans information struct */
- target_info = net_nfc_client_tag_get_client_target_info();
-
- if (target_info == NULL)
- return NET_NFC_OPERATION_FAIL;
-
- arg_data = transceive_data_to_transceive_variant(target_info->devType,
- data);
- if (arg_data == NULL)
- return NET_NFC_OPERATION_FAIL;
-
- if (net_nfc_gdbus_transceive_call_transceive_data_sync(
- transceive_proxy,
- GPOINTER_TO_UINT(handle),
- target_info->devType,
- arg_data,
- net_nfc_client_gdbus_get_privilege(),
- (gint *)&out_result,
- &out_data,
- NULL,
- &error) == FALSE)
- {
- DEBUG_ERR_MSG("Transceive (sync call) failed: %s",
- error->message);
- g_error_free(error);
- return NET_NFC_UNKNOWN_ERROR;
- }
-
- if (response && out_data != NULL)
- {
- *response = net_nfc_util_gdbus_variant_to_data(out_data);
- }
-
- return out_result;
-}
-
-
-net_nfc_error_e net_nfc_client_transceive_init(void)
-{
- GError *error = NULL;
-
- if (transceive_proxy)
- {
- DEBUG_CLIENT_MSG("Already initialized");
-
- return NET_NFC_OK;
- }
-
- transceive_proxy = net_nfc_gdbus_transceive_proxy_new_for_bus_sync(
- G_BUS_TYPE_SYSTEM,
- G_DBUS_PROXY_FLAGS_NONE,
- "org.tizen.NetNfcService",
- "/org/tizen/NetNfcService/Transceive",
- NULL,
- &error);
- if (transceive_proxy == NULL)
- {
- DEBUG_ERR_MSG("Can not create proxy : %s", error->message);
- g_error_free(error);
-
- return NET_NFC_UNKNOWN_ERROR;
- }
-
- return NET_NFC_OK;
-}
-
-void net_nfc_client_transceive_deinit(void)
-{
- if(transceive_proxy)
- {
- g_object_unref(transceive_proxy);
- transceive_proxy = NULL;
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <stdlib.h>
-#include <string.h>
-
-#include "net_nfc_client_util_internal.h"
-
+++ /dev/null
-prefix=/usr
-exec_prefix=${prefix}/bin
-libdir=@LIB_INSTALL_DIR@
-includedir=${prefix}/include
-
-Name: nfc
-Description: NFC
-Version: $version
-Requires:
-Libs: -lnfc
-Cflags: -I/usr/include/nfc
\ No newline at end of file
+++ /dev/null
-CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
-PROJECT(nfc-common-lib C)
-
-SET(NFC_COMMON_LIB "nfc-common-lib")
-SET(VERSION_MAJOR 1)
-SET(VERSION ${VERSION_MAJOR}.0.0)
-
-FIND_PROGRAM(GDBUS_CODEGEN NAMES gdbus-codegen)
-EXEC_PROGRAM(${GDBUS_CODEGEN} ARGS
- " \\
- --generate-c-code ${CMAKE_CURRENT_SOURCE_DIR}/net_nfc_gdbus \\
- --c-namespace NetNfcGDbus\\
- --interface-prefix org.tizen.NetNfcService. \\
- ${CMAKE_CURRENT_SOURCE_DIR}/net_nfc.xml \\
- ")
-
-include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
-
-AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} COMMON_LIB_SRCS)
-
-IF("${CMAKE_BUILD_TYPE}" STREQUAL "")
- SET(CMAKE_BUILD_TYPE "Release")
-ENDIF("${CMAKE_BUILD_TYPE}" STREQUAL "")
-
-INCLUDE(FindPkgConfig)
-pkg_check_modules(commonlib_pkges REQUIRED
- glib-2.0 gio-2.0 gio-unix-2.0 dlog bluetooth-api libssl)
-
-FOREACH(flag ${commonlib_pkges_CFLAGS})
- SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
-ENDFOREACH(flag)
-
-MESSAGE("CHECK MODULE in COMMON_LIB ${commonlib_pkges_LDFLAGS}")
-
-# this for NFC flag
-
-SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -pipe -fomit-frame-pointer -Wall -Wno-trigraphs -Werror-implicit-function-declaration -fno-strict-aliasing -Wl,-zdefs")
-
-SET(ARM_CFLAGS "${ARM_CLAGS} -mapcs -mno-sched-prolog -mabi=aapcs-linux -Uarm -fno-common -fpic")
-
-SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror-implicit-function-declaration")
-SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
-SET(CMAKE_C_FLAGS_DEBUG "-O0 -g")
-
-FIND_PROGRAM(UNAME NAMES uname)
-EXEC_PROGRAM("${UNAME}" ARGS "-m" OUTPUT_VARIABLE "ARCH")
-IF("${ARCH}" MATCHES "^arm.*")
- ADD_DEFINITIONS("-DTARGET")
- MESSAGE("add -DTARGET")
- SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${ARM_CFLAGS}")
-ENDIF()
-
-ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"")
-
-ADD_LIBRARY(${NFC_COMMON_LIB} SHARED ${COMMON_LIB_SRCS})
-SET_TARGET_PROPERTIES(${NFC_COMMON_LIB} PROPERTIES SOVERSION ${VERSION_MAJOR})
-SET_TARGET_PROPERTIES(${NFC_COMMON_LIB} PROPERTIES VERSION ${VERSION})
-
-TARGET_LINK_LIBRARIES(${NFC_COMMON_LIB} ${commonlib_pkges_LDFLAGS})
-
-SET(COMMON_LIB_HEADER
- include/net_nfc_typedef.h
- include/net_nfc_util_internal.h
- include/net_nfc_oem_controller.h
- include/net_nfc_typedef_internal.h
- include/net_nfc_util_ndef_message.h
- include/net_nfc_util_handover.h
- include/net_nfc_util_ndef_record.h
- include/net_nfc_util_sign_record.h
-)
-
-CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/${NFC_COMMON_LIB}.pc.in ${CMAKE_CURRENT_SOURCE_DIR}/${NFC_COMMON_LIB}.pc)
-INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${NFC_COMMON_LIB}.pc DESTINATION lib/pkgconfig)
-INSTALL(TARGETS ${NFC_COMMON_LIB} DESTINATION lib)
-
-FOREACH(hfile ${COMMON_LIB_HEADER})
- INSTALL(FILES ${hfile} DESTINATION include/nfc-common-lib)
-ENDFOREACH(hfile)
-
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef __NET_NFC_DEBUG_INTERNAL_H__
-#define __NET_NFC_DEBUG_INTERNAL_H__
-
-#include <stdio.h>
-#include <errno.h>
-#include <time.h>
-#include <sys/time.h>
-#include <libgen.h>
-#include <dlog.h>
-
-#define LOG_SERVER_TAG "NET_NFC_MANAGER"
-#define LOG_CLIENT_TAG "NET_NFC_CLIENT"
-
-#define LOG_COLOR_RED "\033[0;31m"
-#define LOG_COLOR_GREEN "\033[0;32m"
-#define LOG_COLOR_BROWN "\033[0;33m"
-#define LOG_COLOR_BLUE "\033[0;34m"
-#define LOG_COLOR_PURPLE "\033[0;35m"
-#define LOG_COLOR_CYAN "\033[0;36m"
-#define LOG_COLOR_LIGHTBLUE "\033[0;37m"
-#define LOG_COLOR_END "\033[0;m"
-
-/* nfc_log_to_file */
-extern FILE *nfc_log_file;
-#define NFC_DLOG_FILE "/opt/usr/share/nfc_debug/nfc_mgr_dlog.txt"
-
-/* tag */
-const char *net_nfc_get_log_tag();
-
-#define NFC_LOGD(format, arg...) SLOG(LOG_DEBUG, net_nfc_get_log_tag(), format, ##arg)
-#define NFC_LOGI(format, arg...) SLOG(LOG_INFO, net_nfc_get_log_tag(), format, ##arg)
-#define NFC_LOGW(format, arg...) SLOG(LOG_WARN, net_nfc_get_log_tag(), format, ##arg)
-#define NFC_LOGE(format, arg...) SLOG(LOG_ERROR, net_nfc_get_log_tag(), format, ##arg)
-
-#ifndef SECURE_LOGD
-#define SECURE_LOGD NFC_LOGD
-#endif
-
-#define DEBUG_MSG_PRINT_BUFFER(buffer, length) \
- do { \
- int i = 0, offset = 0; \
- char temp_buffer[4096] = { 0, }; \
- NFC_LOGD(LOG_COLOR_BLUE "BUFFER [%d] = {" LOG_COLOR_END, length); \
- for(; i < length && offset < sizeof(temp_buffer); i++) \
- { \
- offset += snprintf(temp_buffer + offset, sizeof(temp_buffer) - offset, " %02x", buffer[i]); \
- if (i % 16 == 15) \
- { \
- NFC_LOGD(LOG_COLOR_BLUE "\t%s" LOG_COLOR_END, temp_buffer); \
- offset = 0; \
- } \
- } \
- NFC_LOGD(LOG_COLOR_BLUE "\t%s" LOG_COLOR_END, temp_buffer); \
- NFC_LOGD(LOG_COLOR_BLUE "}" LOG_COLOR_END); \
- } while(0)
-
-#define DEBUG_MSG_PRINT_BUFFER_CHAR(buffer, length) \
- do { \
- int i = 0, offset = 0; \
- char temp_buffer[4096] = { 0, }; \
- NFC_LOGD(LOG_COLOR_BLUE "BUFFER [%d] = {" LOG_COLOR_END, length); \
- for(; i < length && offset < sizeof(temp_buffer); i++) \
- { \
- offset += snprintf(temp_buffer + offset, sizeof(temp_buffer) - offset, " %c", buffer[i]); \
- if (i % 16 == 15) \
- { \
- NFC_LOGD(LOG_COLOR_BLUE "\t%s" LOG_COLOR_END, temp_buffer); \
- offset = 0; \
- } \
- } \
- NFC_LOGD(LOG_COLOR_BLUE "\t%s" LOG_COLOR_END, temp_buffer); \
- NFC_LOGD(LOG_COLOR_BLUE "}" LOG_COLOR_END); \
- } while(0)
-
-#define DEBUG_MSG(format, args...) \
- do { \
- NFC_LOGD(format, ##args); \
- if (nfc_log_file) \
- { \
- char timeBuf[50]; \
- time_t rawtime; time (&rawtime); strftime(timeBuf, sizeof(timeBuf), "%m-%d %H:%M:%S", localtime(&rawtime)); \
- fprintf(nfc_log_file, "\n%s",timeBuf); \
- fprintf(nfc_log_file, "[D][%s:%d] "format"",__func__, __LINE__, ##args); \
- fflush(nfc_log_file);\
- }\
- } while(0)
-
-#define DEBUG_SERVER_MSG(format, args...) \
- do {\
- NFC_LOGD(LOG_COLOR_PURPLE format LOG_COLOR_END, ##args);\
- if (nfc_log_file) \
- { \
- char timeBuf[50]; \
- time_t rawtime; time (&rawtime); strftime(timeBuf, sizeof(timeBuf), "%m-%d %H:%M:%S", localtime(&rawtime)); \
- fprintf(nfc_log_file, "\n%s",timeBuf); \
- fprintf(nfc_log_file, "[S][%s:%d] "format"",__func__, __LINE__, ##args); \
- fflush(nfc_log_file);\
- } \
- } while(0)
-
-#define DEBUG_CLIENT_MSG(format, args...) \
- do {\
- NFC_LOGD(LOG_COLOR_CYAN format LOG_COLOR_END, ##args); \
- if (nfc_log_file) \
- { \
- char timeBuf[50]; \
- time_t rawtime; time (&rawtime); strftime(timeBuf, sizeof(timeBuf), "%m-%d %H:%M:%S", localtime(&rawtime)); \
- fprintf(nfc_log_file, "\n%s",timeBuf); \
- fprintf(nfc_log_file, "[C][%s:%d] "format"",__func__, __LINE__, ##args); \
- fflush(nfc_log_file);\
- }\
- } while(0)
-
-#define DEBUG_ERR_MSG(format, args...) \
- do {\
- NFC_LOGD(LOG_COLOR_RED format LOG_COLOR_END, ##args);\
- if (nfc_log_file) \
- { \
- char timeBuf[50]; \
- time_t rawtime; time (&rawtime); strftime(timeBuf, sizeof(timeBuf), "%m-%d %H:%M:%S", localtime(&rawtime)); \
- fprintf(nfc_log_file, "\n%s",timeBuf); \
- fprintf(nfc_log_file, "[E][%s:%d] "format"",__func__, __LINE__, ##args); \
- fflush(nfc_log_file);\
- } \
- } while(0)
-
-#define INFO_MSG(format, args...) \
- do {\
- NFC_LOGI(LOG_COLOR_GREEN format LOG_COLOR_END, ##args);\
- if (nfc_log_file) \
- { \
- char timeBuf[50]; \
- time_t rawtime; time (&rawtime); strftime(timeBuf, sizeof(timeBuf), "%m-%d %H:%M:%S", localtime(&rawtime)); \
- fprintf(nfc_log_file, "\n%s",timeBuf); \
- fprintf(nfc_log_file, "[I][%s:%d] "format"",__func__, __LINE__, ##args); \
- fflush(nfc_log_file);\
- } \
- } while(0)
-
-#define WARN_MSG(format, args...) \
- do {\
- NFC_LOGW(LOG_COLOR_BROWN format LOG_COLOR_END, ##args);\
- if (nfc_log_file) \
- { \
- char timeBuf[50]; \
- time_t rawtime; time (&rawtime); strftime(timeBuf, sizeof(timeBuf), "%m-%d %H:%M:%S", localtime(&rawtime)); \
- fprintf(nfc_log_file, "\n%s",timeBuf); \
- fprintf(nfc_log_file, "[W][%s:%d] "format"",__func__, __LINE__, ##args); \
- fflush(nfc_log_file);\
- } \
- } while(0)
-
-#define PROFILING(str) \
- do{ \
- struct timeval mytime;\
- char buf[128]; = {0};\
- memset(buf, 0x00, 128);\
- gettimeofday(&mytime, NULL);\
- char time_string[128] = {0,};\
- sprintf(time_string, "%d.%4d", mytime.tv_sec, mytime.tv_usec);\
- NFC_LOGD(str); \
- NFC_LOGD("\t time = [%s]", time_string);\
- } while(0)
-
-#endif //__NET_NFC_DEBUG_INTERNAL_H__
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef __NET_NFC_OEM_CONTROLLER_H__
-#define __NET_NFC_OEM_CONTROLLER_H__
-
-#include "net_nfc_typedef_internal.h"
-
-typedef bool (*net_nfc_oem_controller_init)(net_nfc_error_e *result);
-typedef bool (*net_nfc_oem_controller_deinit)(void);
-typedef bool (*net_nfc_oem_controller_register_listener)(target_detection_listener_cb target_detection_listener, se_transaction_listener_cb se_transaction_listener, llcp_event_listener_cb llcp_event_listener, net_nfc_error_e *result);
-typedef bool (*net_nfc_oem_controller_unregister_listener)(void);
-typedef bool (*net_nfc_oem_controller_support_nfc)(net_nfc_error_e *result);
-typedef bool (*net_nfc_oem_controller_get_firmware_version)(data_s **data, net_nfc_error_e *result);
-typedef bool (*net_nfc_oem_controller_check_firmware_version)(net_nfc_error_e *result);
-typedef bool (*net_nfc_oem_controller_update_firmware)(net_nfc_error_e *result);
-typedef bool (*net_nfc_oem_controller_get_stack_information)(net_nfc_stack_information_s *stack_info, net_nfc_error_e *result);
-typedef bool (*net_nfc_oem_controller_configure_discovery)(net_nfc_discovery_mode_e mode, net_nfc_event_filter_e config, net_nfc_error_e *result);
-typedef bool (*net_nfc_oem_controller_exception_handler)(void);
-
-/* tag api */
-typedef bool (*net_nfc_oem_controller_connect)(net_nfc_target_handle_s *handle, net_nfc_error_e *result);
-typedef bool (*net_nfc_oem_controller_disconnect)(net_nfc_target_handle_s *handle, net_nfc_error_e *result);
-typedef bool (*net_nfc_oem_controller_check_target_presence)(net_nfc_target_handle_s *handle, net_nfc_error_e *result);
-typedef bool (*net_nfc_oem_controller_check_ndef)(net_nfc_target_handle_s *handle, uint8_t *ndef_card_state, int *max_data_size, int *real_data_size, net_nfc_error_e *result);
-typedef bool (*net_nfc_oem_controller_read_ndef)(net_nfc_target_handle_s *handle, data_s **data, net_nfc_error_e *result);
-typedef bool (*net_nfc_oem_controller_write_ndef)(net_nfc_target_handle_s *handle, data_s *data, net_nfc_error_e *result);
-typedef bool (*net_nfc_oem_controller_make_read_only_ndef)(net_nfc_target_handle_s *handle, net_nfc_error_e *result);
-typedef bool (*net_nfc_oem_controller_format_ndef)(net_nfc_target_handle_s *handle, data_s *secure_key, net_nfc_error_e *result);
-typedef bool (*net_nfc_oem_controller_transceive)(net_nfc_target_handle_s *handle, net_nfc_transceive_info_s *info, data_s **data, net_nfc_error_e *result);
-typedef bool (*net_nfc_oem_controller_is_ready)(net_nfc_error_e *result);
-
-/* llcp api */
-typedef bool (*net_nfc_oem_controller_llcp_config)(net_nfc_llcp_config_info_s *config, net_nfc_error_e *result);
-typedef bool (*net_nfc_oem_controller_llcp_check_llcp)(net_nfc_target_handle_s *handle, net_nfc_error_e *result);
-typedef bool (*net_nfc_oem_controller_llcp_activate_llcp)(net_nfc_target_handle_s *handle, net_nfc_error_e *result);
-typedef bool (*net_nfc_oem_controller_llcp_create_socket)(net_nfc_llcp_socket_t *socket, net_nfc_socket_type_e socketType, uint16_t miu, uint8_t rw, net_nfc_error_e *result, void *user_param);
-typedef bool (*net_nfc_oem_controller_llcp_bind)(net_nfc_llcp_socket_t socket, uint8_t service_access_point, net_nfc_error_e *result);
-typedef bool (*net_nfc_oem_controller_llcp_listen)(net_nfc_target_handle_s *handle, uint8_t *service_access_name, net_nfc_llcp_socket_t socket, net_nfc_error_e *result, void *user_param);
-typedef bool (*net_nfc_oem_controller_llcp_accept)(net_nfc_llcp_socket_t socket, net_nfc_error_e *result, void *user_param);
-typedef bool (*net_nfc_oem_controller_llcp_connect_by_url)(net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, uint8_t *service_access_name, net_nfc_error_e *result, void *user_param);
-typedef bool (*net_nfc_oem_controller_llcp_connect)(net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, uint8_t service_access_point, net_nfc_error_e *result, void *user_param);
-typedef bool (*net_nfc_oem_controller_llcp_disconnect)(net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, net_nfc_error_e *result, void *user_param);
-typedef bool (*net_nfc_oem_controller_llcp_socket_close)(net_nfc_llcp_socket_t socket, net_nfc_error_e *result);
-typedef bool (*net_nfc_oem_controller_llcp_recv)(net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, data_s *data, net_nfc_error_e *result, void *user_param);
-typedef bool (*net_nfc_oem_controller_llcp_send)(net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, data_s *data, net_nfc_error_e *result, void *user_param);
-typedef bool (*net_nfc_oem_controller_llcp_recv_from)(net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, data_s *data, net_nfc_error_e *result, void *user_param);
-typedef bool (*net_nfc_oem_controller_llcp_send_to)(net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, data_s *data, uint8_t service_access_point, net_nfc_error_e *result, void *user_param);
-typedef bool (*net_nfc_oem_controller_llcp_reject)(net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, net_nfc_error_e *result);
-typedef bool (*net_nfc_oem_controller_llcp_get_remote_config)(net_nfc_target_handle_s *handle, net_nfc_llcp_config_info_s *config, net_nfc_error_e *result);
-typedef bool (*net_nfc_oem_controller_llcp_get_remote_socket_info)(net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, net_nfc_llcp_socket_option_s *option, net_nfc_error_e *result);
-
-/* secure element api */
-typedef bool (*net_nfc_oem_controller_get_secure_element_list)(net_nfc_secure_element_info_s *list, int* count, net_nfc_error_e *result);
-typedef bool (*net_nfc_oem_controller_set_secure_element_mode)(net_nfc_secure_element_type_e element_type, net_nfc_secure_element_mode_e mode, net_nfc_error_e *result);
-typedef bool (*net_nfc_oem_controller_secure_element_open)(net_nfc_secure_element_type_e element_type, net_nfc_target_handle_s **handle, net_nfc_error_e *result);
-typedef bool (*net_nfc_oem_controller_secure_element_get_atr)(net_nfc_target_handle_s *handle, data_s **atr, net_nfc_error_e *result);
-typedef bool (*net_nfc_oem_controller_secure_element_send_apdu)(net_nfc_target_handle_s *handle, data_s *command, data_s **response, net_nfc_error_e *result);
-typedef bool (*net_nfc_oem_controller_secure_element_close)(net_nfc_target_handle_s *handle, net_nfc_error_e *result);
-
-/* test api */
-typedef bool (*net_nfc_oem_controller_sim_test)(net_nfc_error_e *result);
-typedef bool (*net_nfc_oem_controller_prbs_test)(net_nfc_error_e *result , int tech , int rate);
-typedef bool (*net_nfc_oem_controller_test_mode_on)(net_nfc_error_e *result);
-typedef bool (*net_nfc_oem_controller_test_mode_off)(net_nfc_error_e *result);
-typedef bool (*net_nfc_oem_controller_eedata_register_set)(net_nfc_error_e *result , uint32_t mode , uint32_t reg_id , data_s *data);
-
-typedef struct _net_nfc_oem_interface_s
-{
- net_nfc_oem_controller_init init;
- net_nfc_oem_controller_deinit deinit;
- net_nfc_oem_controller_register_listener register_listener;
- net_nfc_oem_controller_unregister_listener unregister_listener;
- net_nfc_oem_controller_get_firmware_version get_firmware_version;
- net_nfc_oem_controller_check_firmware_version check_firmware_version;
- net_nfc_oem_controller_update_firmware update_firmeware;
- net_nfc_oem_controller_get_stack_information get_stack_information;
- net_nfc_oem_controller_configure_discovery configure_discovery;
- net_nfc_oem_controller_get_secure_element_list get_secure_element_list;
- net_nfc_oem_controller_set_secure_element_mode set_secure_element_mode;
- net_nfc_oem_controller_connect connect;
- net_nfc_oem_controller_connect disconnect;
- net_nfc_oem_controller_check_ndef check_ndef;
- net_nfc_oem_controller_check_target_presence check_presence;
- net_nfc_oem_controller_read_ndef read_ndef;
- net_nfc_oem_controller_write_ndef write_ndef;
- net_nfc_oem_controller_make_read_only_ndef make_read_only_ndef;
- net_nfc_oem_controller_transceive transceive;
- net_nfc_oem_controller_format_ndef format_ndef;
- net_nfc_oem_controller_exception_handler exception_handler;
- net_nfc_oem_controller_is_ready is_ready;
-
- net_nfc_oem_controller_llcp_config config_llcp;
- net_nfc_oem_controller_llcp_check_llcp check_llcp_status;
- net_nfc_oem_controller_llcp_activate_llcp activate_llcp;
- net_nfc_oem_controller_llcp_create_socket create_llcp_socket;
- net_nfc_oem_controller_llcp_bind bind_llcp_socket;
- net_nfc_oem_controller_llcp_listen listen_llcp_socket;
- net_nfc_oem_controller_llcp_accept accept_llcp_socket;
- net_nfc_oem_controller_llcp_connect_by_url connect_llcp_by_url;
- net_nfc_oem_controller_llcp_connect connect_llcp;
- net_nfc_oem_controller_llcp_disconnect disconnect_llcp;
- net_nfc_oem_controller_llcp_socket_close close_llcp_socket;
- net_nfc_oem_controller_llcp_recv recv_llcp;
- net_nfc_oem_controller_llcp_send send_llcp;
- net_nfc_oem_controller_llcp_recv_from recv_from_llcp;
- net_nfc_oem_controller_llcp_send_to send_to_llcp;
- net_nfc_oem_controller_llcp_reject reject_llcp;
- net_nfc_oem_controller_llcp_get_remote_config get_remote_config;
- net_nfc_oem_controller_llcp_get_remote_socket_info get_remote_socket_info;
-
- net_nfc_oem_controller_sim_test sim_test;
- net_nfc_oem_controller_prbs_test prbs_test;
- net_nfc_oem_controller_test_mode_on test_mode_on;
- net_nfc_oem_controller_test_mode_off test_mode_off;
-
- net_nfc_oem_controller_support_nfc support_nfc;
- net_nfc_oem_controller_eedata_register_set eedata_register_set;
-
- net_nfc_oem_controller_secure_element_open secure_element_open;
- net_nfc_oem_controller_secure_element_get_atr secure_element_get_atr;
- net_nfc_oem_controller_secure_element_send_apdu secure_element_send_apdu;
- net_nfc_oem_controller_secure_element_close secure_element_close;
-} net_nfc_oem_interface_s;
-
-#endif //__NET_NFC_OEM_CONTROLLER_H__
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef __NET_NFC_TYPEDEF_H__
-#define __NET_NFC_TYPEDEF_H__
-
-/**
- NFC Manager
- NFC Manager controls the nfc device with high level APIs such as SmartPoster and Connection handover.
- It also support the JSR257 push handling.
- This file describe the structure and defines of the NFC manager
-
- @version 0.1
-
- */
-
-/**
- @defgroup NET_NFC_MANAGER The description of NFC Manager
- @defgroup NET_NFC_TYPEDEF Defines and structures
- @defgroup NET_NFC_MANAGER_API NFC Manager
- @defgroup NET_NFC_MANAGER_INFO Tag Information and data APIs
- @defgroup NET_NFC_MANAGER_TAG Tag Read/Write APIs
- @defgroup NET_NFC_MANAGER_NDEF NDEF Message APIs
- @defgroup NET_NFC_MANAGER_RECORD NDEF Record APIs
- @defgroup NET_NFC_MANAGER_LLCP NFC LLCP APIs
- @defgroup NET_NFC_MANAGER_APDU Internal APDU APIs
- @defgroup NET_NFC_MANAGER_EXCHANGE App Exchanger APIs
-
-
- @addtogroup NET_NFC_MANAGER
- @{
- <P> "NFC Manager" is the framework that provide NFC APIs,
- and it also provide high level services such as Smart Poster, Connection Handover,
- and JSR257 push registry. </P>
-
- NFC Manager APIs are defined in <net_nfc.h>, <net_nfc_typedef.h>
-
- <P>
- Memory management rules <br>
- depends on the the verb of each function it describe memory management roles
-
- 1. set: copy the parameters and used inside of nfc-manager, you should free the parameter you have used
- 2. append: it is similar to "set" but, it does not make copy, you SHOULD NOT free the parameter after use it belongs to nfc-manager and it will be freed later
- (example "net_nfc_append_record_to_ndef_message") the appended record will be free the at the ndef message free time.
- 3. get, search : it gives original pointer to you, DO NOT free the pointer get from nfc-manager API
- 4. remove: automatically free inside of the this function do not free again.
- 5. create: it allocate handle, therefore, you should consider free after using (for example "net_nfc_create_rawdata_from_ndef_message(ndef_message_h ndef_message, data_h *rawdata)"
- this function allocate the data_h, you should free data with the function net_nfc_free_data())
- </p>
-
- @}
- */
-
-/**
- @addtogroup NET_NFC_TYPEDEF
- @{
- This documents provide the NFC defines
-
- */
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stddef.h>
-#include <stdint.h>
-#include <stdbool.h>
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
-/**
- net_nfc_error_e is enum type that returned from each functions
- it mostly contains the error codes and it may contains status codes.
- */
-typedef enum
-{
-/*000*/NET_NFC_OK = 0, /**< Status is OK */
-/*999*/NET_NFC_UNKNOWN_ERROR = -999, /**< Unknown error */
-/*998*/NET_NFC_ALLOC_FAIL, /**< Memory allocation is failed */
-/*997*/NET_NFC_THREAD_CREATE_FAIL, /**< Thread creation is failed */
-/*996*/NET_NFC_INVALID_STATE, /**< State of NFC-Manager or nfc-stack is not normal */
-/*995*/NET_NFC_IPC_FAIL, /**< Communication with ipc is failed. (from client to server)*/
-/*994*/NET_NFC_OUT_OF_BOUND, /**< Index is out of bound */
-/*993*/NET_NFC_NULL_PARAMETER, /**< Unexpected NULL parameter is received */
-/*992*/NET_NFC_BUFFER_TOO_SMALL, /**< Requested buffer is too small to store data, this error should be received */
-/*991*/NET_NFC_ALREADY_INITIALIZED, /**< You tried to initialized again without de-init */
-/*990*/NET_NFC_COMMUNICATE_WITH_CONTROLLER_FAILED, /**< Communication with Controller Chipset is failed this is Fatal Error */
-/*989*/NET_NFC_RF_TIMEOUT, /**< Timeout is raised while communicate with a tag */
-/*988*/NET_NFC_RF_ERROR, /**< Unexpected package is received from target, you may receive this error comes by the low level RF communication fault*/
-/*987*/NET_NFC_NOT_INITIALIZED, /**< Application tries to request without initialization */
-/*986*/NET_NFC_NOT_SUPPORTED, /**< Request information or command is not supported in current connected target */
-/*985*/NET_NFC_ALREADY_REGISTERED, /**< Requested SAP number is already used by other socket or data is already appended or registered */
-/*984*/NET_NFC_NOT_ALLOWED_OPERATION, /**< Requested Operation is not allowed in the situation in critical time (such as write data on target)*/
-/*983*/NET_NFC_BUSY, /**< Previous operation is not finished. don't worry to get this message, most of request will be executed in the serial queue */
-/*982*/NET_NFC_INVALID_HANDLE, /**< Requested Device in not valid device */
-/*981*/NET_NFC_TAG_READ_FAILED, /**< Tag reading is failed because of unexpected chunk data is received or error ack is received */
-/*980*/NET_NFC_TAG_WRITE_FAILED, /**< When you try to write on read only tag or error ack is received */
-/*979*/NET_NFC_NO_NDEF_SUPPORT, /**< Tag is not supported NDEF format for tag is not formatted for NDEF */
-/*978*/NET_NFC_NO_NDEF_MESSAGE, /**< No data is received after NDEF reading */
-/*977*/NET_NFC_INVALID_FORMAT, /**< Received data is not readable or it has illegal values or format */
-/*976*/NET_NFC_INSUFFICIENT_STORAGE, /**< The connected tag does not have enough information */
-/*975*/NET_NFC_OPERATION_FAIL, /**< The remote target returned error while doing a operation*/
-/*974*/NET_NFC_NOT_CONNECTED, /**< remote is not connected correctly. This can be happened when the RF does not have enough strength */
-/*973*/NET_NFC_NO_DATA_FOUND, /**< Requested data is not found in the list or properties */
-/*972*/NET_NFC_SECURITY_FAIL, /**< Authentication is failed while communication with nfc-manager server */
-/*971*/NET_NFC_TARGET_IS_MOVED_AWAY, /**< Target is lost while doing a operation */
-/*970*/NET_NFC_TAG_IS_ALREADY_FORMATTED, /** Target is already formatted */
-/*969*/NET_NFC_NOT_REGISTERED, /**< removal is requested but requested data is not registered */
-/*968*/NET_NFC_INVALID_PARAM, /**< removal is requested but requested data is not registered */
-/*499*/NET_NFC_NDEF_TYPE_LENGTH_IS_NOT_OK = -499, /**< Illegal ndef record type length */
-/*498*/NET_NFC_NDEF_PAYLOAD_LENGTH_IS_NOT_OK, /**< Illegal ndef record payload length */
-/*497*/NET_NFC_NDEF_ID_LENGTH_IS_NOT_OK, /**< Illegal ndef record id length */
-/*496*/NET_NFC_NDEF_RECORD_IS_NOT_EXPECTED_TYPE, /**< Parameter record is not expected record. for example, try to URI from text record */
-/*495*/NET_NFC_NDEF_BUF_END_WITHOUT_ME, /**< NDEF messages is terminated without ME flag */
-/*494*/NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC, /**< Current device does not support NFC feature or this manager does not found plugin library */
-
-/*399*/NET_NFC_LLCP_INVALID_SOCKET = -399, /**< socket is not valid socket */
-/*398*/NET_NFC_LLCP_SOCKET_DISCONNECTED, /**< socket is disconnected */
-/*397*/NET_NFC_LLCP_SOCKET_FRAME_REJECTED, /**< send data is rejected from remote side */
-
-/*299*/NET_NFC_P2P_SEND_FAIL = -299, /**< P2P data send fail */
-} net_nfc_error_e;
-
-/**
- Enum value of the record type ( TNF value )
- */
-typedef enum
-{
- NET_NFC_RECORD_EMPTY = 0x0,
- NET_NFC_RECORD_WELL_KNOWN_TYPE,
- NET_NFC_RECORD_MIME_TYPE, // Media type
- NET_NFC_RECORD_URI,
- NET_NFC_RECORD_EXTERNAL_RTD,
- NET_NFC_RECORD_UNKNOWN,
- NET_NFC_RECORD_UNCHAGNED,
-} net_nfc_record_tnf_e;
-
-/**
- net_nfc_message_e is identify the events comes from nfc-manager.
- most of the events response event that you requested operations.
- and some of the events are generated by nfc-manager. (example, NET_NFC_MESSAGE_TAG_DISCOVERED, NET_NFC_MESSAGE_TAG_DETACHED,
- NET_NFC_MESSAGE_LLCP_DISCOVERED and NET_NFC_MESSAGE_LLCP_DETACHED)
-
- All of the events are delivered by the the callback function that registered with "net_nfc_set_response_callback"
- */
-
-typedef enum
-{
- NET_NFC_MESSAGE_TRANSCEIVE = 0, /**< Type: Response Event, <br> This events is received after calling the "net_nfc_tranceive"
- <br> if the operation is success, the data parameter should cast into data_h or it return NULL*/
- NET_NFC_MESSAGE_READ_NDEF, /**< Type: Response Event, <br> This events is received after calling the "net_nfc_read_tag"
- <br> if the operation is success, the data parameter should cast into ndef_message_h or it return NULL */
- NET_NFC_MESSAGE_WRITE_NDEF, /**< Type: Response Event, <br> This events is received after calling the "net_nfc_write_ndef"
- <br> data pointer always returns NULL */
- NET_NFC_MESSAGE_MAKE_READ_ONLY_NDEF, /**< Type: Response Event, <br> This events is received after calling the "net_nfc_make_read_only_ndef"
- <br> data pointer always returns NULL */
- NET_NFC_MESSAGE_IS_TAG_CONNECTED, /**< Type: Response Event, <br> This events is received after calling the "net_nfc_is_tag_conneced"
- <br> data pointer always returns NULL */
- NET_NFC_MESSAGE_GET_CURRENT_TAG_INFO, /**< Type: Response Event, <br> This events is received after calling the "net_nfc_get_current_tag_infof"
- <br> if the operation is success, the data parameter should cast into net_nfc_target_info_h or it return NULL */
- NET_NFC_MESSAGE_GET_CURRENT_TARGET_HANDLE, /**< Type: Response Event, <br> This events is received after calling the "net_nfc_get_current_target_handle"
- <br> if the operation is success, the data parameter should cast into net_nfc_target_handle_h or it return NULL */
- NET_NFC_MESSAGE_TAG_DISCOVERED, /**< Type: Notify Event, <br> When a tag or SE is detected, you got this event.
- <br> The data contains the target info , need to cast to net_nfc_target_info_h*/
- NET_NFC_MESSAGE_NOTIFY, /**< This Notify Event <br> when the unexpected error has occurred, this event is delivered. data pointer always returns NULL */
- NET_NFC_MESSAGE_TAG_DETACHED, /**< Type: Notify Event, <br> When a tag or SE is disappeared, you got this event.
- <br> The data contains the target info , need to cast to net_nfc_target_info_h but it does not have detail target info
- <br> please, do not use "net_nfc_get_tag_info_keys" when you got this event*/
-/*10*/ NET_NFC_MESSAGE_FORMAT_NDEF, /**< Type: Response Event <br> After complete "net_nfc_format_ndef", this event is delivered */
- NET_NFC_MESSAGE_LLCP_DISCOVERED,/**< Type: Notify Event <br> When LLCP is discovered and remote device is support llcp, you receive this event
- <br> data pointer contains the remote llcp configuration info. Cast to net_nfc_llcp_config_info_h*/
- NET_NFC_MESSAGE_P2P_DETACHED, /**< Type: Notify Event <br> When LLCP is de-activated by removing the device, you receive this event*/
- NET_NFC_MESSAGE_LLCP_CONFIG, /**< Type: Response Event. <br> The operation of "net_nfc_set_llcp_local_configure" is completed */
-
- NET_NFC_MESSAGE_P2P_DISCOVERED, /**< Type: Notify Event <br> The remove device is detected and ready for transferring data to remote side */
- NET_NFC_MESSAGE_P2P_SEND, /**< Type: Response Event, <br> This events is received after calling the "net_nfc_send_exchanger_data" */
- NET_NFC_MESSAGE_P2P_RECEIVE, /**< Type: Notify Event, <br> When llcp server socket receive some data, this event is delivered. */
-
- NET_NFC_MESSAGE_SE_START_TRANSACTION, /**< Type: Notify Event, indicates external reader start transaction*/
- NET_NFC_MESSAGE_SE_END_TRANSACTION, /**< Type: Notify Event, indicates external reader end transaction*/
- NET_NFC_MESSAGE_SE_TYPE_TRANSACTION, /**< Type: Notify Event, Indicates external reader trying to access secure element */
-/*20*/ NET_NFC_MESSAGE_SE_CONNECTIVITY, /**< Type: Notify Event, This event notifies the terminal host that it shall send a connectivity event from UICC */
- NET_NFC_MESSAGE_SE_FIELD_ON, /**< Type: Notify Event, indicates external reader field is on*/
- NET_NFC_MESSAGE_SE_FIELD_OFF, /**< Type: Notify Event, indicates external reader field is off*/
- NET_NFC_MESSAGE_SE_TYPE_CHANGED, /**< Type: Notify Event, indicates secure element type is changed*/
-
- NET_NFC_MESSAGE_CONNECTION_HANDOVER, /**< Type: Response Event. <br> The result of connection handover. If it has been completed successfully, this event will include the information of alternative carrier. */
-
- NET_NFC_MESSAGE_SET_SE,
- NET_NFC_MESSAGE_GET_SE,
- NET_NFC_MESSAGE_OPEN_INTERNAL_SE,
- NET_NFC_MESSAGE_CLOSE_INTERNAL_SE,
- NET_NFC_MESSAGE_SEND_APDU_SE,
-/*30*/ NET_NFC_MESSAGE_GET_ATR_SE,
- NET_NFC_GET_SERVER_STATE,
-
- NET_NFC_MESSAGE_SIM_TEST,
-
- NET_NFC_MESSAGE_INIT,
- NET_NFC_MESSAGE_DEINIT,
-
- NET_NFC_MESSAGE_PRBS_TEST,
-
- NET_NFC_MESSAGE_GET_FIRMWARE_VERSION,
-
- NET_NFC_MESSAGE_SET_EEDATA,
-
- NET_NFC_MESSAGE_SNEP_START_SERVER,
- NET_NFC_MESSAGE_SNEP_START_CLIENT,
-/*40*/ NET_NFC_MESSAGE_SNEP_REQUEST,
- NET_NFC_MESSAGE_SNEP_STOP_SERVICE,
- NET_NFC_MESSAGE_SNEP_REGISTER_SERVER,
- NET_NFC_MESSAGE_SNEP_UNREGISTER_SERVER,
-
- NET_NFC_MESSAGE_CONNECT,
- NET_NFC_MESSAGE_DISCONNECT,
- NET_NFC_MESSAGE_SET_CARD_EMULATION,
-} net_nfc_message_e;
-
-typedef enum
-{
- NET_NFC_UNKNOWN_TARGET = 0x00U,
-
- /* Specific PICC Devices */
-
- NET_NFC_GENERIC_PICC,
- NET_NFC_ISO14443_A_PICC,
- NET_NFC_ISO14443_4A_PICC,
- NET_NFC_ISO14443_3A_PICC,
- NET_NFC_MIFARE_MINI_PICC,
- NET_NFC_MIFARE_1K_PICC,
- NET_NFC_MIFARE_4K_PICC,
- NET_NFC_MIFARE_ULTRA_PICC,
- NET_NFC_MIFARE_DESFIRE_PICC,
- NET_NFC_ISO14443_B_PICC,
- NET_NFC_ISO14443_4B_PICC,
- NET_NFC_ISO14443_BPRIME_PICC,
- NET_NFC_FELICA_PICC,
- NET_NFC_JEWEL_PICC,
- NET_NFC_ISO15693_PICC,
-
- /* NFC-IP1 Device Types */
- NET_NFC_NFCIP1_TARGET,
- NET_NFC_NFCIP1_INITIATOR,
-
-} net_nfc_target_type_e;
-
-/**
- Card states for nfc tag
- */
-typedef enum
-{
- NET_NFC_NDEF_CARD_INVALID = 0x00, /**< The card is not NFC forum specified tag. The ndef format will be needed. */
- NET_NFC_NDEF_CARD_INITIALISED, /**< The card is NFC forum specified tag, but It has no actual data. So, the ndef write will be needed. */
- NET_NFC_NDEF_CARD_READ_WRITE, /**< The card is NFC forum specified tag. The ndef read and write will be allowed. */
- NET_NFC_NDEF_CARD_READ_ONLY /**< The card is NFC forum specified tag, but only the ndef read will be allowed. */
-} net_nfc_ndef_card_state_e;
-
-/**
- Encoding type for string message
- */
-typedef enum
-{
- NET_NFC_ENCODE_UTF_8 = 0x00,
- NET_NFC_ENCODE_UTF_16,
-} net_nfc_encode_type_e;
-
-/**
- URI scheme type defined in the NFC forum "URI Record Type Definition"
- */
-typedef enum
-{
- NET_NFC_SCHEMA_FULL_URI = 0x00, /**< protocol is specify by payload */
- NET_NFC_SCHEMA_HTTP_WWW, /**< http://www. */
- NET_NFC_SCHEMA_HTTPS_WWW, /**< https://www. */
- NET_NFC_SCHEMA_HTTP, /**< http:// */
- NET_NFC_SCHEMA_HTTPS, /**< https:// */
- NET_NFC_SCHEMA_TEL, /**< tel: */
- NET_NFC_SCHEMA_MAILTO, /**< mailto: */
- NET_NFC_SCHEMA_FTP_ANONYMOUS, /**< ftp://anonymouse:anonymouse@ */
- NET_NFC_SCHEMA_FTP_FTP, /**< ftp://ftp. */
- NET_NFC_SCHEMA_FTPS, /**< ftps:// */
- NET_NFC_SCHEMA_SFTP, /**< sftp:// */
- NET_NFC_SCHEMA_SMB, /**< smb:// */
- NET_NFC_SCHEMA_NFS, /**< nfs:// */
- NET_NFC_SCHEMA_FTP, /**< ftp:// */
- NET_NFC_SCHEMA_DAV, /**< dav:// */
- NET_NFC_SCHEMA_NEWS, /**< news:// */
- NET_NFC_SCHEMA_TELNET, /**< telnet:// */
- NET_NFC_SCHEMA_IMAP, /**< imap: */
- NET_NFC_SCHEMA_RTSP, /**< rtsp:// */
- NET_NFC_SCHEMA_URN, /**< urn: */
- NET_NFC_SCHEMA_POP, /**< pop: */
- NET_NFC_SCHEMA_SIP, /**< sip: */
- NET_NFC_SCHEMA_SIPS, /**< sips: */
- NET_NFC_SCHEMA_TFTP, /**< tftp: */
- NET_NFC_SCHEMA_BTSPP, /**< btspp:// */
- NET_NFC_SCHEMA_BTL2CAP, /**< btl2cap:// */
- NET_NFC_SCHEMA_BTGOEP, /**< btgoep:// */
- NET_NFC_SCHEMA_TCPOBEX, /**< tcpobex:// */
- NET_NFC_SCHEMA_IRDAOBEX, /**< irdaobex:// */
- NET_NFC_SCHEMA_FILE, /**< file:// */
- NET_NFC_SCHEMA_URN_EPC_ID, /**< urn:epc:id: */
- NET_NFC_SCHEMA_URN_EPC_TAG, /**< urn:epc:tag: */
- NET_NFC_SCHEMA_URN_EPC_PAT, /**< urn:epc:pat: */
- NET_NFC_SCHEMA_URN_EPC_RAW, /**< urn:epc:raw: */
- NET_NFC_SCHEMA_URN_EPC, /**< urn:epc: */
- NET_NFC_SCHEMA_URN_NFC, /**< urn:epc:nfc: */
- NET_NFC_SCHEMA_MAX /**< -- indicating max-- */
-} net_nfc_schema_type_e;
-
-// this is for target detect event filter
-
-typedef enum
-{
- NET_NFC_ALL_DISABLE = 0x0000,
- NET_NFC_ISO14443A_ENABLE = 0x0001,
- NET_NFC_ISO14443B_ENABLE = 0x0002,
- NET_NFC_ISO15693_ENABLE = 0x0004,
- NET_NFC_FELICA_ENABLE = 0x0008,
- NET_NFC_JEWEL_ENABLE = 0x0010,
- NET_NFC_IP_ENABLE = 0x0020,
- NET_NFC_ALL_ENABLE = ~0,
-
-} net_nfc_event_filter_e;
-
-/*
- **************************************
- LLCP defines
- **************************************
- */
-/**
- These events are delivered to the each socket callback. These events are separated events that comes from "net_nfc_set_response_callback" callback
- */
-typedef enum
-{
- /* start number should be larger than "net_nfc_message_e"
- because to make seperate with net_nfc_message_e event it may conflict in
- the dispatcher and ipc part */
- NET_NFC_MESSAGE_LLCP_LISTEN = 1000, /**< Type: Response Event <br> this event indicates "net_nfc_listen_llcp" requested is completed*/
- NET_NFC_MESSAGE_LLCP_ACCEPTED, /**< Type: Notify Event. <br> Remote socket is accepted to listening socket
- <br> data pointer contains the remote socket info (Cast to net_nfc_llcp_socket_option_h)*/
- NET_NFC_MESSAGE_LLCP_CONNECT, /**< Type: Response Event. <br> "net_nfc_connect_llcp_with" request is completed and your socket is connected to remote site with url*/
- NET_NFC_MESSAGE_LLCP_CONNECT_SAP, /**< Type: Response Event.<br> "net_nfc_connect_llcp_with_sap" request is completed and your socket is connected to remote site with sap number*/
- NET_NFC_MESSAGE_LLCP_SEND, /**< Type: Response Event,<br> "net_nfc_send_llcp" operation is completed (connection mode)*/
- NET_NFC_MESSAGE_LLCP_SEND_TO, /**< Type: Response Event,<br> "net_nfc_send_llcp_to"operation is completed (connectionless mode)*/
- NET_NFC_MESSAGE_LLCP_RECEIVE, /**< Type: Response Event,<br> "net_nfc_receive_llcp" operation is completed (connection mode)
- <br> data pointer contains received data (Cast to data_h)*/
- NET_NFC_MESSAGE_LLCP_RECEIVE_FROM, /**< Type: Response Event,<br> "net_nfc_receive_llcp_from" operation is completed (connectionless mode)*/
- NET_NFC_MESSAGE_LLCP_DISCONNECT, /**< Type: Response Event,<br> "net_nfc_disconnect_llcp" request is completed */
- NET_NFC_MESSAGE_LLCP_ERROR, /**< Type: Notify Event,<br> when the socket is disconnected, you may receive this event */
- NET_NFC_MESSAGE_LLCP_CONNECT_REQ, /**< Type: Notify Event,<br> when the peer requests connect, you may receive this event */
- NET_NFC_MESSAGE_LLCP_ACCEPT, /**< Type: Response Event <br> this event indicates "net_nfc_accept_llcp" requested is completed*/
- NET_NFC_MESSAGE_LLCP_REJECT, /**< Type: Response Event <br> this event indicates "net_nfc_reject_llcp" requested is completed*/
- NET_NFC_MESSAGE_LLCP_REJECTED, /**< Type: Notify Event,<br> when the socket is rejected, you may receive this event */
- NET_NFC_MESSAGE_LLCP_CLOSE, /**< Type: Response Event,<br> "net_nfc_close_llcp_socket" request is completed */
-
-} net_nfc_llcp_message_e;
-
-typedef enum
-{
- NET_NFC_LLCP_SOCKET_TYPE_CONNECTIONORIENTED,
- NET_NFC_LLCP_SOCKET_TYPE_CONNECTIONLESS,
-} net_nfc_socket_type_e;
-
-typedef enum
-{
- NET_NFC_SNEP = 0x00,
- NET_NFC_NPP,
-} llcp_app_protocol_e;
-
-typedef struct _data_s *data_h;
-
-typedef struct _ndef_record_s *ndef_record_h;
-
-typedef struct _ndef_message_s *ndef_message_h;
-
-typedef struct _net_nfc_target_info_s *net_nfc_target_info_h;
-
-typedef uint32_t net_nfc_traceive_cmd;
-
-typedef struct _net_nfc_llcp_config_info_s *net_nfc_llcp_config_info_h;
-
-typedef struct _net_nfc_llcp_socket_option_s *net_nfc_llcp_socket_option_h;
-
-typedef struct _net_nfc_target_handle_s *net_nfc_target_handle_h;
-
-typedef struct _net_nfc_connection_handover_info_s *net_nfc_connection_handover_info_h;
-
-typedef uint8_t sap_t;
-
-typedef uint32_t net_nfc_llcp_socket_t;
-
-typedef void *net_nfc_snep_handle_h;
-
-// LLCP Callback
-typedef void (*net_nfc_llcp_socket_cb)(net_nfc_llcp_message_e message, net_nfc_error_e result, void *data, void *user_data, void *trans_data);
-
-// Main Callback
-typedef void (*net_nfc_response_cb)(net_nfc_message_e message, net_nfc_error_e result, void *data, void *user_param, void *trans_data);
-
-typedef void (*net_nfc_internal_se_response_cb)(net_nfc_message_e message, net_nfc_error_e result, void *data, void *user_param, void *trans_data);
-
-typedef void (* net_nfc_set_activation_completed_cb)(net_nfc_error_e error, void *user_data);
-
-// for data exchanger
-
-typedef enum
-{
- NET_NFC_EXCHANGER_DATA_REQUESTED = 0x00,
- NET_NFC_EXCHANGER_TRANSFER_COMPLETED,
- NET_NFC_EXCHANGER_TRANSFER_FAILED,
-} net_nfc_exchanger_event_e;
-
-typedef enum
-{
- NET_NFC_EXCHANGER_RAW,
-} net_nfc_exchanger_data_type_e;
-
-typedef struct _net_nfc_exchanger_data_s *net_nfc_exchanger_data_h;
-
-typedef net_nfc_exchanger_data_h (*net_nfc_exchanger_cb)(net_nfc_exchanger_event_e event, void *user_param);
-
-typedef enum
-{
- NET_NFC_CONN_HANDOVER_CARRIER_BT = 0x00,
- NET_NFC_CONN_HANDOVER_CARRIER_WIFI_BSS, /* infrastructure */
- NET_NFC_CONN_HANDOVER_CARRIER_WIFI_IBSS, /* add hoc */
- NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN,
-} net_nfc_conn_handover_carrier_type_e;
-
-typedef enum
-{
- NET_NFC_CONN_HANDOVER_CARRIER_INACTIVATE = 0x00,
- NET_NFC_CONN_HANDOVER_CARRIER_ACTIVATE,
- NET_NFC_CONN_HANDOVER_CARRIER_ACTIVATING,
- NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN_STATUS,
-} net_nfc_conn_handover_carrier_state_e;
-
-typedef struct _net_nfc_conn_handover_carrier_info_s *net_nfc_conn_handover_carrier_info_h;
-typedef struct _net_nfc_conn_handover_info_s *net_nfc_conn_handover_info_h;
-
-#define MIFARE_KEY_DEFAULT {(uint8_t)0xFF,(uint8_t)0xFF,(uint8_t)0xFF,(uint8_t)0xFF,(uint8_t)0xFF,(uint8_t)0xFF}
-#define MIFARE_KEY_APPLICATION_DIRECTORY {(uint8_t)0xA0,(uint8_t)0xA1,(uint8_t)0xA2,(uint8_t)0xA3,(uint8_t)0xA4,(uint8_t)0xA5}
-#define MIFARE_KEY_NET_NFC_FORUM {(uint8_t)0xD3,(uint8_t)0xF7,(uint8_t)0xD3,(uint8_t)0xF7,(uint8_t)0xD3,(uint8_t)0xF7}
-#define MIFARE_KEY_LENGTH 6
-
-typedef enum
-{
- NET_NFC_FELICA_POLL_NO_REQUEST = 0x00,
- NET_NFC_FELICA_POLL_SYSTEM_CODE_REQUEST,
- NET_NFC_FELICA_POLL_COMM_SPEED_REQUEST,
- NET_NFC_FELICA_POLL_MAX = 0xFF,
-} net_nfc_felica_poll_request_code_e;
-
-/**
- WIFI configuration key enums for connection handover.
- */
-
-typedef enum
-{
- NET_NFC_WIFI_ATTRIBUTE_VERSION = 0x104A,
- NET_NFC_WIFI_ATTRIBUTE_CREDENTIAL = 0x100E,
- NET_NFC_WIFI_ATTRIBUTE_NET_INDEX = 0x1026,
- NET_NFC_WIFI_ATTRIBUTE_SSID = 0x1045,
- NET_NFC_WIFI_ATTRIBUTE_AUTH_TYPE = 0x1003, /*< WPA2PSK 0x0020 */
- NET_NFC_WIFI_ATTRIBUTE_ENC_TYPE = 0x100F, /*< AES 0x0008 */
- NET_NFC_WIFI_ATTRIBUTE_NET_KEY = 0x1027,
- NET_NFC_WIFI_ATTRIBUTE_MAC_ADDR = 0x1020,
- NET_NFC_WIFI_ATTRIBUTE_CHANNEL = 0x1001, /* Channel number - based on IEEE */
- NET_NFC_WIFI_ATTRIBUTE_VEN_EXT = 0x1049,
- NET_NFC_WIFI_ATTRIBUTE_VERSION2 = 0x00,
-} net_nfc_carrier_wifi_attribute_e;
-
-typedef enum
-{
- NET_NFC_BT_ATTRIBUTE_UUID16_PART = 0x02, /* More 16-bit UUIDs available */
- NET_NFC_BT_ATTRIBUTE_UUID16 = 0x03, /* Complete list of 16-bit UUIDs */
- NET_NFC_BT_ATTRIBUTE_UUID32_PART = 0x04, /* More 32-bit UUIDs available */
- NET_NFC_BT_ATTRIBUTE_UUID32 = 0x05, /* Complete list of 32-bit UUIDs */
- NET_NFC_BT_ATTRIBUTE_UUID128_PART = 0x06, /* More 128-bit UUIDs available */
- NET_NFC_BT_ATTRIBUTE_UUID128 = 0x07, /* Complete list of 128-bit UUIDs */
- NET_NFC_BT_ATTRIBUTE_NAME_PART = 0x08, /* Shortened local name */
- NET_NFC_BT_ATTRIBUTE_NAME = 0x09, /* Complete local name */
- NET_NFC_BT_ATTRIBUTE_TXPOWER = 0x0a, /* TX Power level */
- NET_NFC_BT_ATTRIBUTE_OOB_COD = 0x0d, /* SSP OOB Class of Device */
- NET_NFC_BT_ATTRIBUTE_OOB_HASH_C = 0x0e, /* SSP OOB Hash C */
- NET_NFC_BT_ATTRIBUTE_OOB_HASH_R = 0x0f, /* SSP OOB Randomizer R */
- NET_NFC_BT_ATTRIBUTE_ID = 0x10, /* Device ID */
- NET_NFC_BT_ATTRIBUTE_MANUFACTURER = 0xFF, /* Manufacturer Specific Data */
- NET_NFC_BT_ATTRIBUTE_ADDRESS = 0xF0, /* Bluetooth device Address */
-} net_nfc_handover_bt_attribute_e;
-
-typedef struct _net_nfc_carrier_config_s *net_nfc_carrier_config_h;
-typedef struct _net_nfc_carrier_property_s *net_nfc_property_group_h;
-
-typedef enum
-{
- NET_NFC_SE_TYPE_NONE = 0x00,/**< Invalid */
- NET_NFC_SE_TYPE_ESE = 0x01,/**< SmartMX */
- NET_NFC_SE_TYPE_UICC = 0x02,/**< UICC */
- NET_NFC_SE_TYPE_SDCARD = 0x03, /* SDCard type is not currently supported */
-} net_nfc_se_type_e;
-
-typedef enum
-{
- NET_NFC_SIGN_TYPE_NO_SIGN = 0,
- NET_NFC_SIGN_TYPE_PKCS_1,
- NET_NFC_SIGN_TYPE_PKCS_1_V_1_5,
- NET_NFC_SIGN_TYPE_DSA,
- NET_NFC_SIGN_TYPE_ECDSA,
- NET_NFC_MAX_SIGN_TYPE,
-} net_nfc_sign_type_t;
-
-typedef enum
-{
- NET_NFC_CERT_FORMAT_X_509 = 0,
- NET_NFC_CERT_FORMAT_X9_86,
- NET_NFC_MAX_CERT_FORMAT,
-} net_nfc_cert_format_t;
-
-typedef enum
-{
- NET_NFC_SNEP_GET = 1,
- NET_NFC_SNEP_PUT = 2,
-} net_nfc_snep_type_t;
-
-typedef enum
-{
- NET_NFC_LLCP_REGISTERED = -1,
- NET_NFC_LLCP_UNREGISTERED = -2,
- NET_NFC_LLCP_START = -3,
- NET_NFC_LLCP_STOP = -4,
-}
-net_nfc_llcp_state_t;
-
-typedef enum
-{
- NET_NFC_CARD_EMELATION_ENABLE = 0,
- NET_NFC_CARD_EMULATION_DISABLE,
-}
-net_nfc_card_emulation_mode_t;
-
-#ifdef __cplusplus
-}
-#endif
-
-/**
- @}
- */
-
-#endif //__NET_NFC_TYPEDEF_H__
+++ /dev/null
-/*
- * Copyright (C) 2010 NXP Semiconductors
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef __NET_NFC_TYPEDEF_INTERNAL_H__
-#define __NET_NFC_TYPEDEF_INTERNAL_H__
-
-#include "net_nfc_typedef.h"
-
-typedef enum
-{
- NET_NFC_POLL_START = 0x01,
- NET_NFC_POLL_STOP,
-} net_nfc_detect_mode_e;
-
-/**
- This structure is just data, to express bytes array
- */
-typedef struct _data_s
-{
- uint8_t *buffer;
- uint32_t length;
-} data_s;
-
-typedef struct _net_nfc_data_t
-{
- uint32_t length;
- uint8_t buffer[0];
-} net_nfc_data_s;
-
-typedef enum _net_nfc_connection_type_e
-{
- NET_NFC_TAG_CONNECTION = 0x00,
- NET_NFC_P2P_CONNECTION_TARGET,
- NET_NFC_P2P_CONNECTION_INITIATOR,
- NET_NFC_SE_CONNECTION
-} net_nfc_connection_type_e;
-
-typedef struct _net_nfc_target_handle_s
-{
- uint32_t connection_id;
- net_nfc_connection_type_e connection_type;
- net_nfc_target_type_e target_type;
- /*++npp++*/
- llcp_app_protocol_e app_type;
- /*--npp--*/
-} net_nfc_target_handle_s;
-
-typedef struct _net_nfc_current_target_info_s
-{
- net_nfc_target_handle_s *handle;
- uint32_t devType;
- int number_of_keys;
- net_nfc_data_s target_info_values;
-}net_nfc_current_target_info_s;
-
-typedef struct _net_nfc_llcp_config_info_s
-{
- uint16_t miu; /** The remote Maximum Information Unit (NOTE: this is MIU, not MIUX !)*/
- uint16_t wks; /** The remote Well-Known Services*/
- uint8_t lto; /** The remote Link TimeOut (in 1/100s)*/
- uint8_t option; /** The remote options*/
-} net_nfc_llcp_config_info_s;
-
-typedef struct _net_nfc_llcp_socket_option_s
-{
- uint16_t miu; /** The remote Maximum Information Unit */
- uint8_t rw; /** The Receive Window size (4 bits)*/
- net_nfc_socket_type_e type;
-} net_nfc_llcp_socket_option_s;
-
-typedef struct _net_nfc_llcp_internal_socket_s
-{
- uint16_t miu; /** The remote Maximum Information Unit */
- uint8_t rw; /** The Receive Window size (4 bits)*/
- net_nfc_socket_type_e type;
- net_nfc_llcp_socket_t oal_socket;
- net_nfc_llcp_socket_t client_socket;
- sap_t sap;
- uint8_t *service_name;
- net_nfc_target_handle_s *device_id;
- net_nfc_llcp_socket_cb cb;
- bool close_requested;
- void *register_param; /* void param that has been registered in callback register time */
-} net_nfc_llcp_internal_socket_s;
-
-/**
- ndef_record_s structure has the NDEF record data. it is only a record not a message
- */
-typedef struct _record_s
-{
- uint8_t MB :1;
- uint8_t ME :1;
- uint8_t CF :1;
- uint8_t SR :1;
- uint8_t IL :1;
- uint8_t TNF :3;
- data_s type_s;
- data_s id_s;
- data_s payload_s;
- struct _record_s *next;
-} ndef_record_s;
-
-/**
- NDEF message it has record counts and records (linked listed form)
- */
-typedef struct _ndef_message_s
-{
- uint32_t recordCount;
- ndef_record_s *records; // linked list
-} ndef_message_s;
-
-/**
- Enum value to stop or start the discovery mode
- */
-
-#define NET_NFC_MAX_UID_LENGTH 0x0AU /**< Maximum UID length expected */
-#define NET_NFC_MAX_ATR_LENGTH 0x30U /**< Maximum ATR_RES (General Bytes) */
-#define NET_NFC_ATQA_LENGTH 0x02U /**< ATQA length */
-#define NET_NFC_ATQB_LENGTH 0x0BU /**< ATQB length */
-
-#define NET_NFC_PUPI_LENGTH 0x04U /**< PUPI length */
-#define NET_NFC_APP_DATA_B_LENGTH 0x04U /**< Application Data length for Type B */
-#define NET_NFC_PROT_INFO_B_LENGTH 0x03U /**< Protocol info length for Type B */
-
-#define NET_NFC_MAX_ATR_LENGTH 0x30U /**< Maximum ATR_RES (General Bytes) */
-#define NET_NFC_MAX_UID_LENGTH 0x0AU /**< Maximum UID length expected */
-#define NET_NFC_FEL_ID_LEN 0x08U /**< Felica current ID Length */
-#define NET_NFC_FEL_PM_LEN 0x08U /**< Felica current PM Length */
-#define NET_NFC_FEL_SYS_CODE_LEN 0x02U /**< Felica System Code Length */
-
-#define NET_NFC_15693_UID_LENGTH 0x08U /**< Length of the Inventory bytes for */
-
-typedef struct _net_nfc_sIso14443AInfo_t
-{
- uint8_t Uid[NET_NFC_MAX_UID_LENGTH]; /**< UID information of the TYPE A Tag Discovered */
- uint8_t UidLength; /**< UID information length, shall not be greater than NET_NFC_MAX_UID_LENGTH i.e., 10 */
- uint8_t AppData[NET_NFC_MAX_ATR_LENGTH]; /**< Application data information of the tag discovered (= Historical bytes for type A) */
- uint8_t AppDataLength; /**< Application data length */
- uint8_t Sak; /**< SAK informationof the TYPE A Tag Discovered */
- uint8_t AtqA[NET_NFC_ATQA_LENGTH]; /**< ATQA informationof the TYPE A Tag Discovered */
- uint8_t MaxDataRate; /**< Maximum data rate supported by the TYPE A Tag Discovered */
- uint8_t Fwi_Sfgt; /**< Frame waiting time and start up frame guard time as defined in ISO/IEC 14443-4[7] for type A */
-} net_nfc_sIso14443AInfo_t;
-
-/** \ingroup grp_hal_nfci
- *
- * \brief Remote Device Reader B RF Gate Information Container
- *
- * The <em> Reader B structure </em> includes the available information
- * related to the discovered ISO14443B remote device. This information
- * is updated for every device discovery.
- * \note None.
- *
- */
-typedef struct _net_nfc_sIso14443BInfo_t
-{
- union net_nfc_uAtqBInfo
- {
- struct net_nfc_sAtqBInfo
- {
- uint8_t Pupi[NET_NFC_PUPI_LENGTH]; /**< PUPI information of the TYPE B Tag Discovered */
- uint8_t AppData[NET_NFC_APP_DATA_B_LENGTH]; /**< Application Data of the TYPE B Tag Discovered */
- uint8_t ProtInfo[NET_NFC_PROT_INFO_B_LENGTH]; /**< Protocol Information of the TYPE B Tag Discovered */
- } AtqResInfo;
- uint8_t AtqRes[NET_NFC_ATQB_LENGTH]; /**< ATQB Response Information of TYPE B Tag Discovered */
- } AtqB;
-
- uint8_t HiLayerResp[NET_NFC_MAX_ATR_LENGTH]; /**< Higher Layer Response information in answer to ATRRIB Command for Type B */
- uint8_t HiLayerRespLength; /**< Higher Layer Response length */
- uint8_t Afi; /**< Application Family Identifier of TYPE B Tag Discovered */
- uint8_t MaxDataRate; /**< Maximum data rate supported by the TYPE B Tag Discovered */
-} net_nfc_sIso14443BInfo_t;
-
-/** \ingroup grp_hal_nfci
- *
- * \brief Remote Device Reader B prime RF Gate Information Container
- *
- */
-typedef struct _net_nfc_sIso14443BPrimeInfo_t
-{
- void *BPrimeCtxt;
-} net_nfc_sIso14443BPrimeInfo_t;
-
-/** \ingroup grp_hal_nfci
- *
- * \brief Remote Device Jewel Reader RF Gate Information Container
- *
- * The <em> Jewel Reader structure </em> includes the available information
- * related to the discovered Jewel remote device. This information
- * is updated for every device discovery.
- * \note None.
- *
- */
-typedef struct _net_nfc_sJewelInfo_t
-{
- uint8_t Uid[NET_NFC_MAX_UID_LENGTH]; /**< UID information of the TYPE A Tag Discovered */
- uint8_t UidLength; /**< UID information length, shall not be greater than NET_NFC_MAX_UID_LENGTH i.e., 10 */
- uint8_t HeaderRom0; /**< Header Rom byte zero */
- uint8_t HeaderRom1; /**< Header Rom byte one */
-
-} net_nfc_sJewelInfo_t;
-
-/** \ingroup grp_hal_nfci
- *
- * \brief Remote Device Felica Reader RF Gate Information Container
- *
- * The <em> Felica Reader structure </em> includes the available information
- * related to the discovered Felica remote device. This information
- * is updated for every device discovery.
- * \note None.
- *
- */
-typedef struct _net_nfc_sFelicaInfo_t
-{
- uint8_t IDm[(NET_NFC_FEL_ID_LEN + 2)]; /**< Current ID of Felica tag */
- uint8_t IDmLength; /**< IDm length, shall not be greater than NET_NFC_FEL_ID_LEN i.e., 8 */
- uint8_t PMm[NET_NFC_FEL_PM_LEN]; /**< Current PM of Felica tag */
- uint8_t SystemCode[NET_NFC_FEL_SYS_CODE_LEN]; /**< System code of Felica tag */
-} net_nfc_sFelicaInfo_t;
-
-/** \ingroup grp_hal_nfci
- *
- * \brief Remote Device Reader 15693 RF Gate Information Container
- *
- * The <em> Reader A structure </em> includes the available information
- * related to the discovered ISO15693 remote device. This information
- * is updated for every device discovery.
- * \note None.
- *
- */
-
-typedef struct _net_nfc_sIso15693Info_t
-{
- uint8_t Uid[NET_NFC_15693_UID_LENGTH]; /**< UID information of the 15693 Tag Discovered */
- uint8_t UidLength; /**< UID information length, shall not be greater than NET_NFC_15693_UID_LENGTH i.e., 8 */
- uint8_t Dsfid; /**< DSF information of the 15693 Tag Discovered */
- uint8_t Flags; /**< Information about the Flags in the 15693 Tag Discovered */
- uint8_t Afi; /**< Application Family Identifier of 15693 Tag Discovered */
-} net_nfc_sIso15693Info_t;
-
-/** \ingroup grp_hal_nfci
- *
- * \brief NFC Data Rate Supported between the Reader and the Target
- *
- * The <em> \ref Halnet_nfc_eDataRate enum </em> lists all the Data Rate
- * values to be used to determine the rate at which the data is transmitted
- * to the target.
- *
- * \note None.
- */
-
-/** \ingroup grp_hal_nfci
- *
- * \brief NFCIP1 Data rates
- *
- */
-typedef enum net_nfc_eDataRate_t
-{
- net_nfc_eDataRate_106 = 0x00U,
- net_nfc_eDataRate_212,
- net_nfc_eDataRate_424,
- net_nfc_eDataRate_RFU
-} net_nfc_eDataRate_t;
-
-/** \ingroup grp_hal_nfci
- *
- * \brief NFCIP1 Gate Information Container
- *
- * The <em> NFCIP1 structure </em> includes the available information
- * related to the discovered NFCIP1 remote device. This information
- * is updated for every device discovery.
- * \note None.
- *
- */
-typedef struct _net_nfc_sNfcIPInfo_t
-{
- /* Contains the random NFCID3I conveyed with the ATR_REQ.
- always 10 bytes length
- or contains the random NFCID3T conveyed with the ATR_RES.
- always 10 bytes length */
- uint8_t NFCID[NET_NFC_MAX_UID_LENGTH];
- uint8_t NFCID_Length;
- /* ATR_RES = General bytes length, Max length = 48 bytes */
- uint8_t ATRInfo[NET_NFC_MAX_ATR_LENGTH];
- uint8_t ATRInfo_Length;
- /**< SAK information of the tag discovered */
- uint8_t SelRes;
- /**< ATQA information of the tag discovered */
- uint8_t SenseRes[NET_NFC_ATQA_LENGTH];
- /**< Is Detection Mode of the NFCIP Target Active */
- uint8_t nfcip_Active;
- /**< Maximum frame length supported by the NFCIP device */
- uint16_t MaxFrameLength;
- /**< Data rate supported by the NFCIP device */
- net_nfc_eDataRate_t nfcip_Datarate;
-
-} net_nfc_sNfcIPInfo_t;
-
-typedef union net_nfc_remoteDevInfo_t
-{
- net_nfc_sIso14443AInfo_t Iso14443A_Info;
- net_nfc_sIso14443BInfo_t Iso14443B_Info;
- net_nfc_sIso14443BPrimeInfo_t Iso14443BPrime_Info;
- net_nfc_sNfcIPInfo_t NfcIP_Info;
- net_nfc_sFelicaInfo_t Felica_Info;
- net_nfc_sJewelInfo_t Jewel_Info;
- net_nfc_sIso15693Info_t Iso15693_Info;
-} net_nfc_remoteDevInfo_t;
-
-typedef struct _net_nfc_tag_info_s
-{
- char *key;
- data_h value;
-} net_nfc_tag_info_s;
-
-typedef struct _net_nfc_target_info_s
-{
- net_nfc_target_handle_s *handle;
- net_nfc_target_type_e devType;
- uint8_t is_ndef_supported;
- uint8_t ndefCardState;
- uint32_t maxDataSize;
- uint32_t actualDataSize;
- int number_of_keys;
- net_nfc_tag_info_s *tag_info_list;
- char **keylist;
- data_s raw_data;
-} net_nfc_target_info_s;
-
-typedef struct _net_nfc_se_event_info_s
-{
- data_s aid;
- data_s param;
-} net_nfc_se_event_info_s;
-
-typedef struct _net_nfc_transceive_info_s
-{
- uint32_t dev_type;
- data_s trans_data;
-} net_nfc_transceive_info_s;
-
-typedef struct _net_nfc_connection_handover_info_s
-{
- net_nfc_conn_handover_carrier_type_e type;
- data_s data;
-}
-net_nfc_connection_handover_info_s;
-
-typedef enum _client_state_e
-{
- NET_NFC_CLIENT_INACTIVE_STATE = 0x00,
- NET_NFC_CLIENT_ACTIVE_STATE,
-} client_state_e;
-
-typedef enum _net_nfc_launch_popup_check_e
-{
- CHECK_FOREGROUND = 0x00,
- NO_CHECK_FOREGROUND,
-} net_nfc_launch_popup_check_e;
-
-typedef enum _net_nfc_launch_popup_state_e
-{
- NET_NFC_LAUNCH_APP_SELECT = 0x00,
- NET_NFC_NO_LAUNCH_APP_SELECT,
-} net_nfc_launch_popup_state_e;
-
-/* server state */
-#define NET_NFC_SERVER_IDLE 0
-#define NET_NFC_SERVER_DISCOVERY (1 << 1)
-#define NET_NFC_TAG_CONNECTED (1 << 2)
-#define NET_NFC_SE_CONNECTED (1 << 3)
-#define NET_NFC_SNEP_CLIENT_CONNECTED (1 << 4)
-#define NET_NFC_NPP_CLIENT_CONNECTED (1 << 5)
-#define NET_NFC_SNEP_SERVER_CONNECTED (1 << 6)
-#define NET_NFC_NPP_SERVER_CONNECTED (1 << 7)
-
-// these are messages for request
-#define NET_NFC_REQUEST_MSG_HEADER \
- /* DON'T MODIFY THIS CODE - BEGIN */ \
- uint32_t length; \
- uint32_t request_type; \
- uint32_t client_fd; \
- uint32_t flags; \
- uint32_t user_param; \
- /* DON'T MODIFY THIS CODE - END */
-
-typedef struct _net_nfc_request_msg_t
-{
- NET_NFC_REQUEST_MSG_HEADER
-} net_nfc_request_msg_t;
-
-typedef struct _net_nfc_request_target_detected_t
-{
- NET_NFC_REQUEST_MSG_HEADER
-
- net_nfc_target_handle_s *handle;
- uint32_t devType;
- int number_of_keys;
- net_nfc_data_s target_info_values;
-} net_nfc_request_target_detected_t;
-
-typedef struct _net_nfc_request_se_event_t
-{
- NET_NFC_REQUEST_MSG_HEADER
-
- data_s aid;
- data_s param;
-} net_nfc_request_se_event_t;
-
-typedef struct _net_nfc_request_llcp_msg_t
-{
- NET_NFC_REQUEST_MSG_HEADER
-
- uint32_t result;
- net_nfc_llcp_socket_t llcp_socket;
-} net_nfc_request_llcp_msg_t;
-
-typedef struct _net_nfc_request_listen_socket_t
-{
- NET_NFC_REQUEST_MSG_HEADER
-
- uint32_t result;
- net_nfc_target_handle_s *handle;
- net_nfc_llcp_socket_t client_socket;
- uint16_t miu; /** The remote Maximum Information Unit */
- uint8_t rw; /** The Receive Window size (4 bits)*/
- net_nfc_socket_type_e type;
- net_nfc_llcp_socket_t oal_socket;
- sap_t sap;
- void *trans_param;
- net_nfc_data_s service_name;
-} net_nfc_request_listen_socket_t;
-
-typedef struct _net_nfc_request_receive_socket_t
-{
- NET_NFC_REQUEST_MSG_HEADER
-
- uint32_t result;
- net_nfc_target_handle_s *handle;
- net_nfc_llcp_socket_t client_socket;
- net_nfc_llcp_socket_t oal_socket;
- size_t req_length;
- void *trans_param;
- net_nfc_data_s data;
-} net_nfc_request_receive_socket_t;
-
-typedef struct _net_nfc_request_receive_from_socket_t
-{
- NET_NFC_REQUEST_MSG_HEADER
-
- uint32_t result;
- net_nfc_target_handle_s *handle;
- net_nfc_llcp_socket_t client_socket;
- net_nfc_llcp_socket_t oal_socket;
- size_t req_length;
- sap_t sap;
- void *trans_param;
- net_nfc_data_s data;
-} net_nfc_request_receive_from_socket_t;
-
-// data exchanger
-typedef struct _net_nfc_exchanger_data_s
-{
- net_nfc_exchanger_data_type_e type;
- data_s binary_data; /* this can be binary data */
-} net_nfc_exchanger_data_s;
-
-// these are messages for response
-
-typedef void (*target_detection_listener_cb)(void *data, void *user_param);
-typedef void (*se_transaction_listener_cb)(void *data, void *user_param);
-typedef void (*llcp_event_listener_cb)(void *data, void *user_param);
-
-typedef enum _llcp_event_e
-{
- LLCP_EVENT_SOCKET_ACCEPTED = 0x1,
- LLCP_EVENT_SOCKET_ERROR,
- LLCP_EVENT_DEACTIVATED,
-} llcp_event_e;
-
-typedef struct _net_nfc_stack_information_s
-{
- uint32_t net_nfc_supported_tagetType;
- uint32_t net_nfc_fw_version;
-} net_nfc_stack_information_s;
-
-typedef enum _net_nfc_discovery_mode_e
-{
- NET_NFC_DISCOVERY_MODE_CONFIG = 0x00U,
- NET_NFC_DISCOVERY_MODE_START,
- NET_NFC_DISCOVERY_MODE_STOP,
- NET_NFC_DISCOVERY_MODE_RESUME,
-} net_nfc_discovery_mode_e;
-
-typedef enum _net_nfc_secure_element_type_e
-{
- SECURE_ELEMENT_TYPE_INVALID = 0x00, /**< Indicates SE type is Invalid */
- SECURE_ELEMENT_TYPE_ESE = 0x01, /**< Indicates SE type is SmartMX */
- SECURE_ELEMENT_TYPE_UICC = 0x02, /**<Indicates SE type is UICC */
- SECURE_ELEMENT_TYPE_UNKNOWN = 0x03 /**< Indicates SE type is Unknown */
-} net_nfc_secure_element_type_e;
-
-typedef enum _net_nfc_secure_element_state_e
-{
- SECURE_ELEMENT_ACTIVE_STATE = 0x00, /**< state of the SE is active */
- SECURE_ELEMENT_INACTIVE_STATE = 0x01 /**< state of the SE is In active*/
-
-} net_nfc_secure_element_state_e;
-
-typedef struct _secure_element_info_s
-{
- net_nfc_target_handle_s *handle;
- net_nfc_secure_element_type_e secure_element_type;
- net_nfc_secure_element_state_e secure_element_state;
-
-} net_nfc_secure_element_info_s;
-
-typedef enum _net_nfc_secure_element_mode_e
-{
- SECURE_ELEMENT_WIRED_MODE = 0x00, /**< Enables Wired Mode communication.This mode shall be applied to */
- SECURE_ELEMENT_VIRTUAL_MODE, /**< Enables Virtual Mode communication.This can be applied to UICC as well as SmartMX*/
- SECURE_ELEMENT_OFF_MODE /**< Inactivate SE.This means,put SE in in-active state */
-} net_nfc_secure_element_mode_e;
-
-typedef enum _net_nfc_message_service_e
-{
- NET_NFC_MESSAGE_SERVICE_RESET = 2000,
- NET_NFC_MESSAGE_SERVICE_INIT,
- NET_NFC_MESSAGE_SERVICE_ACTIVATE,
- NET_NFC_MESSAGE_SERVICE_DEACTIVATE,
- NET_NFC_MESSAGE_SERVICE_DEINIT,
- NET_NFC_MESSAGE_SERVICE_STANDALONE_TARGET_DETECTED,
- NET_NFC_MESSAGE_SERVICE_SE,
- NET_NFC_MESSAGE_SERVICE_TERMINATION,
- NET_NFC_MESSAGE_SERVICE_SLAVE_TARGET_DETECTED,
- NET_NFC_MESSAGE_SERVICE_SLAVE_ESE_DETECTED,
- NET_NFC_MESSAGE_SERVICE_RESTART_POLLING_LOOP,
- NET_NFC_MESSAGE_SERVICE_LLCP_LISTEN,
- NET_NFC_MESSAGE_SERVICE_LLCP_INCOMING,
- NET_NFC_MESSAGE_SERVICE_LLCP_ACCEPT,
- NET_NFC_MESSAGE_SERVICE_LLCP_REJECT,
- NET_NFC_MESSAGE_SERVICE_LLCP_SEND,
- NET_NFC_MESSAGE_SERVICE_LLCP_SEND_TO,
- NET_NFC_MESSAGE_SERVICE_LLCP_RECEIVE,
- NET_NFC_MESSAGE_SERVICE_LLCP_RECEIVE_FROM,
- NET_NFC_MESSAGE_SERVICE_LLCP_CONNECT,
- NET_NFC_MESSAGE_SERVICE_LLCP_CONNECT_SAP,
- NET_NFC_MESSAGE_SERVICE_LLCP_DISCONNECT,
- NET_NFC_MESSAGE_SERVICE_LLCP_DEACTIVATED,
- NET_NFC_MESSAGE_SERVICE_LLCP_SOCKET_ERROR,
- NET_NFC_MESSAGE_SERVICE_LLCP_SOCKET_ACCEPTED_ERROR,
- NET_NFC_MESSAGE_SERVICE_CHANGE_CLIENT_STATE,
- NET_NFC_MESSAGE_SERVICE_WATCH_DOG,
- NET_NFC_MESSAGE_SERVICE_CLEANER,
- NET_NFC_MESSAGE_SERVICE_SET_LAUNCH_STATE,
-} net_nfc_message_service_e;
-
-typedef enum _net_nfc_se_command_e
-{
- NET_NFC_SE_CMD_UICC_ON = 0,
- NET_NFC_SE_CMD_ESE_ON,
- NET_NFC_SE_CMD_ALL_OFF,
- NET_NFC_SE_CMD_ALL_ON,
-} net_nfc_se_command_e;
-
-/* connection handover info */
-
-typedef enum
-{
- NET_NFC_CONN_HANDOVER_ERR_REASON_RESERVED = 0x00,
- NET_NFC_CONN_HANDOVER_ERR_REASON_TEMP_MEM_CONSTRAINT,
- NET_NFC_CONN_HANDOVER_ERR_REASON_PERM_MEM_CONSTRAINT,
- NET_NFC_CONN_HANDOVER_ERR_REASON_CARRIER_SPECIFIC_CONSTRAINT,
-} net_nfc_conn_handover_error_reason_e;
-
-/* WIFI Info */
-typedef struct _net_nfc_carrier_property_s
-{
- bool is_group;
- uint16_t attribute;
- uint16_t length;
- void *data;
-} net_nfc_carrier_property_s;
-
-typedef struct _net_nfc_carrier_config_s
-{
- net_nfc_conn_handover_carrier_type_e type;
- int length;
- struct _GList *data;
-} net_nfc_carrier_config_s;
-
-typedef struct _net_nfc_sub_field_s
-{
- uint16_t length;
- uint8_t value[0];
-}
-__attribute__((packed)) net_nfc_sub_field_s;
-
-typedef struct _net_nfc_signature_record_s
-{
- uint8_t version;
- uint8_t sign_type : 7;
- uint8_t uri_present : 1;
- net_nfc_sub_field_s signature;
-}
-__attribute__((packed)) net_nfc_signature_record_s;
-
-typedef struct _net_nfc_certificate_chain_s
-{
- uint8_t num_of_certs : 4;
- uint8_t cert_format : 3;
- uint8_t uri_present : 1;
- uint8_t cert_store[0];
-}
-__attribute__((packed)) net_nfc_certificate_chain_s;
-
-#define SMART_POSTER_RECORD_TYPE "Sp"
-#define URI_RECORD_TYPE "U"
-#define TEXT_RECORD_TYPE "T"
-#define GC_RECORD_TYPE "Gc"
-#define SIGNATURE_RECORD_TYPE "Sig"
-#define CH_REQ_RECORD_TYPE "Hr"
-#define CH_SEL_RECORD_TYPE "Hs"
-#define CH_CAR_RECORD_TYPE "Hc"
-#define COLLISION_DETECT_RECORD_TYPE "cr"
-#define ALTERNATIVE_RECORD_TYPE "ac"
-#define ERROR_RECORD_TYPE "err"
-
-#define URI_SCHEM_FILE "file://"
-
-typedef void (*net_nfc_service_llcp_cb)(net_nfc_llcp_socket_t socket,
- net_nfc_error_e result, data_s *data, void *extra, void *user_param);
-
-typedef struct _net_nfc_llcp_param_t
-{
- net_nfc_llcp_socket_t socket;
- net_nfc_service_llcp_cb cb;
- data_s data;
- void *user_param;
-}
-net_nfc_llcp_param_t;
-
-#endif //__NET_NFC_TYPEDEF_INTERNAL_H__
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef __NET_NFC_UTIL_DEFINES_H__
-#define __NET_NFC_UTIL_DEFINES_H__
-
-#define NET_NFC_UTIL_MSG_TYPE_REQUEST 0
-#define NET_NFC_UTIL_MSG_TYPE_RESPONSE 1
-
-#define CONN_HANDOVER_BT_CARRIER_MIME_NAME "application/vnd.bluetooth.ep.oob"
-#define CONN_HANDOVER_WIFI_BSS_CARRIER_MIME_NAME "application/vnd.wfa.wsc"
-#define CONN_HANDOVER_WIFI_IBSS_CARRIER_MIME_NAME "application/vnd.wfa.wsc;mode=ibss"
-
-#define BLUETOOTH_ADDRESS_LENGTH 6
-#define HIDDEN_BT_ADDR_FILE "/opt/etc/.bd_addr"
-
-#endif //__NET_NFC_UTIL_DEFINES_H__
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef __NET_NFC_UTIL_GDBUS_INTERNAL_H__
-#define __NET_NFC_UTIL_GDBUS_INTERNAL_H__
-
-#include <glib.h>
-
-#include "net_nfc_typedef_internal.h"
-
-void net_nfc_util_gdbus_variant_to_buffer(GVariant *variant, uint8_t **buffer,
- size_t *length);
-
-data_s *net_nfc_util_gdbus_variant_to_data(GVariant *variant);
-
-void net_nfc_util_gdbus_variant_to_data_s(GVariant *variant, data_s *data);
-
-GVariant *net_nfc_util_gdbus_buffer_to_variant(const uint8_t *buffer,
- size_t length);
-
-GVariant *net_nfc_util_gdbus_data_to_variant(const data_s *data);
-
-#endif //__NET_NFC_UTIL_GDBUS_INTERNAL_H__
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef __NET_NFC_UTIL_HANDOVER_H__
-#define __NET_NFC_UTIL_HANDOVER_H__
-
-#include "net_nfc_typedef_internal.h"
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
-#define CH_MAJOR_VER 1
-#define CH_MINOR_VER 2
-#define CH_VERSION ((CH_MAJOR_VER << 4) | CH_MINOR_VER)
-
-#define CH_SAN "urn:nfc:sn:handover"
-#define CH_SAP 0x11 /* connection handover service access point */
-
-net_nfc_error_e net_nfc_util_create_carrier_config(net_nfc_carrier_config_s **config, net_nfc_conn_handover_carrier_type_e type);
-
-net_nfc_error_e net_nfc_util_add_carrier_config_property(net_nfc_carrier_config_s *config, uint16_t attribute, uint16_t size, uint8_t *data);
-
-net_nfc_error_e net_nfc_util_remove_carrier_config_property(net_nfc_carrier_config_s *config, uint16_t attribute);
-
-net_nfc_error_e net_nfc_util_get_carrier_config_property(net_nfc_carrier_config_s *config, uint16_t attribute, uint16_t *size, uint8_t **data);
-
-net_nfc_error_e net_nfc_util_append_carrier_config_group(net_nfc_carrier_config_s *config, net_nfc_carrier_property_s *group);
-
-net_nfc_error_e net_nfc_util_remove_carrier_config_group(net_nfc_carrier_config_s *config, net_nfc_carrier_property_s *group);
-
-net_nfc_error_e net_nfc_util_get_carrier_config_group(net_nfc_carrier_config_s *config, int index, net_nfc_carrier_property_s **group);
-
-net_nfc_error_e net_nfc_util_free_carrier_config(net_nfc_carrier_config_s *config);
-
-net_nfc_error_e net_nfc_util_create_carrier_config_group(net_nfc_carrier_property_s **group, uint16_t attribute);
-
-net_nfc_error_e net_nfc_util_add_carrier_config_group_property(net_nfc_carrier_property_s *group, uint16_t attribute, uint16_t size, uint8_t *data);
-
-net_nfc_error_e net_nfc_util_get_carrier_config_group_property(net_nfc_carrier_property_s *group, uint16_t attribute, uint16_t *size, uint8_t **data);
-
-net_nfc_error_e net_nfc_util_remove_carrier_config_group_property(net_nfc_carrier_property_s *group, uint16_t attribute);
-
-net_nfc_error_e net_nfc_util_free_carrier_group(net_nfc_carrier_property_s *group);
-
-net_nfc_error_e net_nfc_util_create_ndef_record_with_carrier_config(ndef_record_s **record, net_nfc_carrier_config_s *config);
-
-net_nfc_error_e net_nfc_util_create_carrier_config_from_config_record(net_nfc_carrier_config_s **config, ndef_record_s *record);
-
-net_nfc_error_e net_nfc_util_append_carrier_config_record(ndef_message_s *message, ndef_record_s *record, net_nfc_conn_handover_carrier_state_e power_status);
-
-net_nfc_error_e net_nfc_util_remove_carrier_config_record(ndef_message_s *message, ndef_record_s *record);
-
-net_nfc_error_e net_nfc_util_get_carrier_config_record(ndef_message_s *message, int index, ndef_record_s **record);
-
-net_nfc_error_e net_nfc_util_get_handover_random_number(ndef_message_s *message, unsigned short *random_number);
-
-net_nfc_error_e net_nfc_util_get_alternative_carrier_record_count(ndef_message_s *message, unsigned int *count);
-
-net_nfc_error_e net_nfc_util_get_alternative_carrier_power_status(ndef_message_s *message, int index, net_nfc_conn_handover_carrier_state_e *power_state);
-
-net_nfc_error_e net_nfc_util_set_alternative_carrier_power_status(ndef_message_s *message, int index, net_nfc_conn_handover_carrier_state_e power_status);
-
-net_nfc_error_e net_nfc_util_get_alternative_carrier_type_from_record(ndef_record_s *record, net_nfc_conn_handover_carrier_type_e *type);
-
-/**
- this function will get carrier type.
-
- @param[in] carrier_info connection handover carrier info handler
- @param[in] carrier_type record type. it can be a NET_NFC_CONN_HANDOVER_CARRIER_BT or NET_NFC_CONN_HANDOVER_CARRIER_WIFI or NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN.
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illegal NULL pointer(s)
- */
-net_nfc_error_e net_nfc_util_get_alternative_carrier_type(ndef_message_s *message, int index, net_nfc_conn_handover_carrier_type_e *power_state);
-
-net_nfc_error_e net_nfc_util_create_handover_request_message(ndef_message_s **message);
-
-net_nfc_error_e net_nfc_util_create_handover_select_message(ndef_message_s **message);
-
-net_nfc_error_e net_nfc_util_create_handover_error_record(ndef_record_s **record, uint8_t reason, uint32_t data);
-
-net_nfc_error_e net_nfc_util_get_selector_power_status(ndef_message_s *message, net_nfc_conn_handover_carrier_state_e *power_state);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif //__NET_NFC_UTIL_HANDOVER_H__
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef __NET_NFC_UTIL_INTERNAL_H__
-#define __NET_NFC_UTIL_INTERNAL_H__
-
-#include <stdio.h>
-#include <libgen.h>
-#include <netinet/in.h>
-
-#include "net_nfc_typedef_internal.h"
-
-#define NET_NFC_REVERSE_ORDER_6_BYTES(__array) \
- do \
- { \
- uint16_t __x = htons(*(uint16_t *)(__array + 4)); \
- *(uint32_t *)(__array + 2) = htonl(*(uint32_t *)(__array)); \
- *(uint16_t *)(__array) = __x; \
- } while (0)
-
-#define NET_NFC_REVERSE_ORDER_16_BYTES(array) \
- do \
- { \
- uint32_t __x1 = htonl(*(uint32_t *)(array + 12)); \
- uint32_t __x2 = htonl(*(uint32_t *)(array + 8)); \
- *(uint32_t *)(array + 8) = htonl(*(uint32_t *)(array + 4)); \
- *(uint32_t *)(array + 12) = htonl(*(uint32_t *)(array)); \
- *(uint32_t *)(array) = __x1; \
- *(uint32_t *)(array + 4) = __x2; \
- } while (0)
-
-typedef enum
-{
- CRC_A = 0x00,
- CRC_B,
-} CRC_type_e;
-
-void net_nfc_manager_init_log();
-void net_nfc_manager_fini_log();
-
-/* Memory utils */
-/* allocation memory */
-void __net_nfc_util_alloc_mem(void **mem, int size, char *filename, unsigned int line);
-#define _net_nfc_util_alloc_mem(mem,size) __net_nfc_util_alloc_mem((void **)&mem,size, basename(__FILE__), __LINE__)
-
-/* allocation memory */
-void __net_nfc_util_strdup(char **output, const char *origin, char *filename, unsigned int line);
-#define _net_nfc_util_strdup(output, origin) __net_nfc_util_strdup(&output, origin, basename(__FILE__), __LINE__)
-
-/* free memory, after free given memory it set NULL. Before proceed free, this function also check NULL */
-void __net_nfc_util_free_mem(void **mem, char *filename, unsigned int line);
-#define _net_nfc_util_free_mem(mem) __net_nfc_util_free_mem((void **)&mem, basename(__FILE__), __LINE__)
-
-bool net_nfc_util_alloc_data(data_s *data, uint32_t length);
-bool net_nfc_util_duplicate_data(data_s *dest, net_nfc_data_s *src);
-void net_nfc_util_free_data(data_s *data);
-
-net_nfc_conn_handover_carrier_state_e net_nfc_util_get_cps(net_nfc_conn_handover_carrier_type_e carrier_type);
-
-uint8_t *net_nfc_util_get_local_bt_address();
-void net_nfc_util_enable_bluetooth(void);
-
-bool net_nfc_util_strip_string(char *buffer, int buffer_length);
-
-void net_nfc_util_compute_CRC(CRC_type_e CRC_type, uint8_t *buffer, uint32_t length);
-
-const char *net_nfc_util_get_schema_string(int index);
-
-#endif //__NET_NFC_UTIL_INTERNAL_H__
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef __NET_NFC_UTIL_IPC_H__
-#define __NET_NFC_UTIL_IPC_H__
-
-#define NET_NFC_SERVER_ADDRESS "127.0.0.1"
-#define NET_NFC_SERVER_PORT 3000
-#define NET_NFC_SERVER_DOMAIN "/tmp/nfc-manager-server-domain"
-
-#define NET_NFC_MAX_MESSAGE_LENGTH (1024 * 512)
-
-#define NET_NFC_FLAGS_SYNC_CALL (1 << 0)
-#define NET_NFC_FLAGS_NO_RESPONSE (1 << 1)
-
-#define NET_NFC_IS_FLAGS_SET(__var, __flag) (((__var) & (__flag)) == (__flag))
-#define NET_NFC_SET_FLAGS(__var, __flag) (__var) |= (__flag)
-#define NET_NFC_UNSET_FLAGS(__var, __flag) (__var) &= ~(__flag)
-
-#define NET_NFC_FLAGS_SET_SYNC_CALL(__var) NET_NFC_SET_FLAGS(__var, NET_NFC_FLAGS_SYNC_CALL)
-#define NET_NFC_FLAGS_UNSET_SYNC_CALL(__var) NET_NFC_UNSET_FLAGS(__var, NET_NFC_FLAGS_SYNC_CALL)
-#define NET_NFC_FLAGS_IS_SYNC_CALL(__var) NET_NFC_IS_FLAGS_SET(__var, NET_NFC_FLAGS_SYNC_CALL)
-
-#define NET_NFC_FLAGS_SET_NO_RESPONSE(__var) NET_NFC_SET_FLAGS(__var, NET_NFC_FLAGS_NO_RESPONSE)
-#define NET_NFC_FLAGS_UNSET_NO_RESPONSE(__var) NET_NFC_UNSET_FLAGS(__var, NET_NFC_FLAGS_NO_RESPONSE)
-#define NET_NFC_FLAGS_IS_NO_RESPONSE(__var) NET_NFC_IS_FLAGS_SET(__var, NET_NFC_FLAGS_NO_RESPONSE)
-
-int net_nfc_util_get_va_list_length(va_list list);
-int net_nfc_util_fill_va_list(uint8_t *buffer, int length, va_list list);
-void net_nfc_util_set_non_block_socket(int socket);
-
-#endif //__NET_NFC_UTIL_IPC_H__
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef __NET_NFC_UTIL_NDEF_MESSAGE_H__
-#define __NET_NFC_UTIL_NDEF_MESSAGE_H__
-
-#include "net_nfc_typedef_internal.h"
-
-/**
- * \brief These are the flags specifying the content, structure or purpose of a NDEF Record.
- * \name NDEF Record Header Flags
- *
- * Flags of the first record byte, as defined by the NDEF specification.
- *
- */
-/*@{*/
-#define NET_NFC_NDEF_RECORD_MASK_MB 0x80 /**< This marks the begin of a NDEF Message. */
-#define NET_NFC_NDEF_RECORD_MASK_ME 0x40 /**< Set if the record is at the Message End. */
-#define NET_NFC_NDEF_RECORD_MASK_CF 0x20 /**< Chunk Flag: The record is a record chunk only. */
-#define NET_NFC_NDEF_RECORD_MASK_SR 0x10 /**< Short Record: Payload Length is encoded in ONE byte only. */
-#define NET_NFC_NDEF_RECORD_MASK_IL 0x08 /**< The ID Length Field is present. */
-#define NET_NFC_NDEF_RECORD_MASK_TNF 0x07 /**< Type Name Format. */
-/*@}*/
-
-/* Internal:
- * NDEF Record #defines for constant value
- */
-
-#define NET_NFC_NDEF_TNF_EMPTY 0x00 /**< Empty Record, no type, ID or payload present. */
-#define NET_NFC_NDEF_TNF_NFCWELLKNOWN 0x01 /**< NFC well-known type (RTD). */
-#define NET_NFC_NDEF_TNF_MEDIATYPE 0x02 /**< Media Type. */
-#define NET_NFC_NDEF_TNF_ABSURI 0x03 /**< Absolute URI. */
-#define NET_NFC_NDEF_TNF_NFCEXT 0x04 /**< Nfc External Type (following the RTD format). */
-#define NET_NFC_NDEF_TNF_UNKNOWN 0x05 /**< Unknown type; Contains no Type information. */
-#define NET_NFC_NDEF_TNF_UNCHANGED 0x06 /**< Unchanged: Used for Chunked Records. */
-#define NET_NFC_NDEF_TNF_RESERVED 0x07 /**< RFU, must not be used. */
-
-/*
- convert rawdata into ndef message structure
- */
-net_nfc_error_e net_nfc_util_convert_rawdata_to_ndef_message(data_s *rawdata, ndef_message_s *ndef);
-
-/*
- this util function converts into rawdata from ndef message structure
- */
-net_nfc_error_e net_nfc_util_convert_ndef_message_to_rawdata(ndef_message_s *ndef, data_s *rawdata);
-
-/*
- get total bytes of ndef message in serial form
- */
-uint32_t net_nfc_util_get_ndef_message_length(ndef_message_s *message);
-
-/*
- free ndef message. this function also free any defined buffer insdie structures
- */
-net_nfc_error_e net_nfc_util_free_ndef_message(ndef_message_s *msg);
-
-/*
- append record into ndef message
- */
-net_nfc_error_e net_nfc_util_append_record(ndef_message_s *msg, ndef_record_s *record);
-
-/*
- print out ndef structure value with printf function. this is for just debug purpose
- */
-void net_nfc_util_print_ndef_message(ndef_message_s *msg);
-
-net_nfc_error_e net_nfc_util_create_ndef_message(ndef_message_s **ndef_message);
-
-net_nfc_error_e net_nfc_util_search_record_by_type(ndef_message_s *ndef_message, net_nfc_record_tnf_e tnf, data_s *type, ndef_record_s **record);
-
-net_nfc_error_e net_nfc_util_append_record_by_index(ndef_message_s *ndef_message, int index, ndef_record_s *record);
-
-net_nfc_error_e net_nfc_util_get_record_by_index(ndef_message_s *ndef_message, int index, ndef_record_s **record);
-
-net_nfc_error_e net_nfc_util_remove_record_by_index(ndef_message_s *ndef_message, int index);
-
-net_nfc_error_e net_nfc_util_search_record_by_id(ndef_message_s *ndef_message, data_s *id, ndef_record_s **record);
-
-#endif //__NET_NFC_UTIL_NDEF_MESSAGE_H__
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef __NET_NFC_UTIL_NDEF_RECORD_H__
-#define __NET_NFC_UTIL_NDEF_RECORD_H__
-
-#include "net_nfc_typedef_internal.h"
-
-/*
- create record structure with basic info
- */
-net_nfc_error_e net_nfc_util_create_record(net_nfc_record_tnf_e recordType, data_s *typeName, data_s *id, data_s *payload, ndef_record_s **record);
-
-/*
- create text type record
- */
-net_nfc_error_e net_nfc_util_create_text_type_record(const char *text, const char *lang_code_str, net_nfc_encode_type_e encode, ndef_record_s **record);
-
-/*
- this utility function help to create uri type record
- */
-net_nfc_error_e net_nfc_util_create_uri_type_record(const char *uri, net_nfc_schema_type_e protocol_schema, ndef_record_s **record);
-
-/*
- free ndef record. it free all the buffered data
- */
-net_nfc_error_e net_nfc_util_free_record(ndef_record_s *record);
-
-/*
- convert schema enum value to character string.
- */
-net_nfc_error_e net_nfc_util_set_record_id(ndef_record_s *record, uint8_t *data, int length);
-
-/*
- get total bytes of ndef record in serial form
- */
-uint32_t net_nfc_util_get_record_length(ndef_record_s *record);
-
-/*
- create uri string from record
- */
-net_nfc_error_e net_nfc_util_create_uri_string_from_uri_record(ndef_record_s *record, char **uri);
-
-#endif //__NET_NFC_UTIL_NDEF_RECORD_H__
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef __NET_NFC_UTIL_OPENSSL_INTERNAL_H__
-#define __NET_NFC_UTIL_OPENSSL_INTERNAL_H__
-
-#include <openssl/x509.h>
-
-enum
-{
- OPENSSL_FORMAT_UNDEF,
- OPENSSL_FORMAT_ASN1,
- OPENSSL_FORMAT_TEXT,
- OPENSSL_FORMAT_PEM,
- OPENSSL_FORMAT_NETSCAPE,
- OPENSSL_FORMAT_PKCS12,
- OPENSSL_FORMAT_SMIME,
- OPENSSL_FORMAT_ENGINE,
- OPENSSL_FORMAT_IISSGC,
- OPENSSL_FORMAT_PEMRSA,
- OPENSSL_FORMAT_ASN1RSA,
- OPENSSL_FORMAT_MSBLOB,
- OPENSSL_FORMAT_PVK,
-};
-
-typedef struct _net_nfc_openssl_verify_context_s
-{
- X509 *signer_cert;
- X509_STORE *store;
- X509_STORE_CTX *store_ctx;
-}
-net_nfc_openssl_verify_context_s;
-
-typedef net_nfc_openssl_verify_context_s *net_nfc_openssl_verify_context_h;
-
-net_nfc_openssl_verify_context_h net_nfc_util_openssl_init_verify_certificate(void);
-bool net_nfc_util_openssl_add_certificate_of_signer(net_nfc_openssl_verify_context_h context, uint8_t *buffer, uint32_t length);
-bool net_nfc_util_openssl_add_certificate_of_ca(net_nfc_openssl_verify_context_h context, uint8_t *buffer, uint32_t length);
-int net_nfc_util_openssl_verify_certificate(net_nfc_openssl_verify_context_h context);
-void net_nfc_util_openssl_release_verify_certificate(net_nfc_openssl_verify_context_h context);
-
-int net_nfc_util_openssl_sign_buffer(uint32_t type, uint8_t *buffer, uint32_t length, char *key_file, char *password, uint8_t *sign, uint32_t *sign_len);
-int net_nfc_util_openssl_verify_signature(uint32_t type, uint8_t *buffer, uint32_t length, uint8_t *cert, uint32_t cert_len, uint8_t *sign, uint32_t sign_len);
-int net_nfc_util_get_cert_list_from_file(char *file_name, char *password, uint8_t **buffer, uint32_t *length, uint32_t *cert_count);
-
-
-bool net_nfc_util_openssl_encode_base64(const uint8_t *buffer, const uint32_t buf_len, char *result, uint32_t max_len, bool new_line_char);
-bool net_nfc_util_openssl_decode_base64(const char *buffer, uint8_t *result, uint32_t *out_len, bool new_line_char);
-bool net_nfc_util_openssl_digest(const char *algorithm, const uint8_t *buffer, const uint32_t buf_len, uint8_t *result, uint32_t *out_len);
-
-#endif //__NET_NFC_UTIL_OPENSSL_INTERNAL_H__
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef __NET_NFC_UTIL_SIGN_RECORD_H__
-#define __NET_NFC_UTIL_SIGN_RECORD_H__
-
-#include "net_nfc_typedef_internal.h"
-
-/*
- * sign ndef record and ndef message
- */
-net_nfc_error_e net_nfc_util_sign_records(ndef_message_s *msg, int begin_index, int end_index, char *cert_file, char *password);
-net_nfc_error_e net_nfc_util_sign_ndef_message(ndef_message_s *msg, char *cert_file, char *password);
-
-/*
- * check validity of ndef record and ndef message
- */
-net_nfc_error_e net_nfc_util_verify_signature_ndef_message(ndef_message_s *msg);
-net_nfc_error_e net_nfc_util_verify_signature_records(ndef_record_s *begin_record, ndef_record_s *sign_record);
-
-
-#endif //__NET_NFC_UTIL_SIGN_RECORD_H__
-
+++ /dev/null
-<!--
- org.tizen.NfcService
-
--->
-
-<node>
- <interface name="org.tizen.NetNfcService.Manager">
- <!--
- SetActive
- -->
- <method name="SetActive">
- <arg type="b" name="is_active" direction="in" />
- <arg type="a(y)" name="privilege" direction="in" />
- </method>
-
- <!--
- GetServerState
- -->
- <method name="GetServerState">
- <arg type="a(y)" name="privilege" direction="in" />
- <arg type="u" name="state" direction="out" />
- </method>
-
-
- <!--
- Activated
- -->
- <signal name="Activated">
- <arg type="b" name="active" />
- </signal>
- </interface>
-
- <interface name="org.tizen.NetNfcService.Tag">
- <!--
- IsConnected
- -->
- <method name="IsTagConnected">
- <arg type="a(y)" name="privilege" direction="in" />
- <arg type="b" name="is_connected" direction="out" />
- <arg type="i" name="dev_type" direction="out" />
- </method>
-
- <!--
- GetInfo
- -->
- <method name="GetCurrentTagInfo">
- <arg type="a(y)" name="privilege" direction="in" />
- <arg type="b" name="is_connected" direction="out" />
- <arg type="u" name="handle" direction="out" />
- <arg type="i" name="dev_type" direction="out" />
- <arg type="b" name="is_ndef_supported" direction="out" />
- <arg type="y" name="ndef_card_state" direction="out" />
- <arg type="u" name="max_data_size" direction="out" />
- <arg type="u" name="actual_data_size" direction="out" />
- <arg type="u" name="number_of_keys" direction="out" />
- <arg type="a(y)" name="target_info_values" direction="out" />
- <arg type="a(y)" name="raw_data" direction="out" />
- </method>
-
- <!--
- GetTagetHandle
- -->
- <method name="GetCurrentTargetHandle">
- <arg type="a(y)" name="privilege" direction="in" />
- <arg type="b" name="is_connected" direction="out" />
- <arg type="u" name="handle" direction="out" />
- <arg type="i" name="dev_type" direction="out" />
- </method>
-
- <!--
- TagDiscovered
- -->
- <signal name="TagDiscovered">
- <arg type="u" name="handle" />
- <arg type="i" name="dev_type" />
- <arg type="b" name="is_ndef_supported" />
- <arg type="y" name="ndef_card_state" />
- <arg type="u" name="max_data_size" />
- <arg type="u" name="actual_data_size" />
- <arg type="u" name="number_of_keys" />
- <arg type="a(y)" name="target_info_values" />
- <arg type="a(y)" name="raw_data" />
- </signal>
-
- <!--
- TagDetached
- -->
- <signal name="TagDetached">
- <arg type="u" name="handle" />
- <arg type="i" name="dev_type" />
- </signal>
- </interface>
-
- <interface name="org.tizen.NetNfcService.Ndef">
- <!--
- Read
- -->
- <method name="Read">
- <arg type="u" name="handle" direction="in" />
- <arg type="a(y)" name="privilege" direction="in" />
- <arg type="i" name="result" direction="out" />
- <arg type="a(y)" name="data" direction="out" />
- </method>
-
- <!--
- Write
- -->
- <method name="Write">
- <arg type="u" name="handle" direction="in" />
- <arg type="a(y)" name="data" direction="in" />
- <arg type="a(y)" name="privilege" direction="in" />
- <arg type="i" name="result" direction="out" />
- </method>
-
- <!--
- MakeReadOnly
- -->
- <method name="MakeReadOnly">
- <arg type="u" name="handle" direction="in" />
- <arg type="a(y)" name="privilege" direction="in" />
- <arg type="i" name="result" direction="out" />
- </method>
-
- <!--
- Format
- -->
- <method name="Format">
- <arg type="u" name="handle" direction="in" />
- <arg type="a(y)" name="key" direction="in" />
- <arg type="a(y)" name="privilege" direction="in" />
- <arg type="i" name="result" direction="out" />
- </method>
- </interface>
-
- <interface name="org.tizen.NetNfcService.Llcp">
- <!--
- Config
- -->
- <method name="Config">
- <arg type="(qqyy)" name="config" direction="in" />
- <arg type="a(y)" name="privilege" direction="in" />
- </method>
- <!--
- Listen
- -->
- <method name="Listen">
- <arg type="u" name="handle" direction="in" />
- <arg type="u" name="client_socket" direction="in" />
- <arg type="u" name="oal_socket" direction="in" />
- <arg type="q" name="miu" direction="in" />
- <arg type="y" name="rw" direction="in" />
- <arg type="i" name="type" direction="in" />
- <arg type="y" name="sap" direction="in" />
- <arg type="s" name="service_name" direction="in" />
- <arg type="a(y)" name="privilege" direction="in" />
- <arg type="u" name="client_socket" direction="out" />
- <arg type="u" name="oal_socket" direction="out" />
- </method>
-
- <!--
- Connect
- -->
- <method name="Connect">
- <arg type="u" name="handle" direction="in" />
- <arg type="u" name="client_socket" direction="in" />
- <arg type="u" name="oal_socket" direction="in" />
- <arg type="q" name="miu" direction="in" />
- <arg type="y" name="rw" direction="in" />
- <arg type="i" name="type" direction="in" />
- <arg type="s" name="service_name" direction="in" />
- <arg type="a(y)" name="privilege" direction="in" />
- <arg type="u" name="client_socket" direction="out" />
- <arg type="u" name="oal_socket" direction="out" />
- </method>
-
- <!--
- ConnectSap
- -->
- <method name="ConnectSap">
- <arg type="u" name="handle" direction="in" />
- <arg type="u" name="client_socket" direction="in" />
- <arg type="u" name="oal_socket" direction="in" />
- <arg type="q" name="miu" direction="in" />
- <arg type="y" name="rw" direction="in" />
- <arg type="i" name="type" direction="in" />
- <arg type="y" name="sap" direction="in" />
- <arg type="a(y)" name="privilege" direction="in" />
- <arg type="u" name="client_socket" direction="out" />
- <arg type="u" name="oal_socket" direction="out" />
- </method>
-
- <!--
- Send
- -->
- <method name="Send">
- <arg type="u" name="handle" direction="in" />
- <arg type="u" name="client_socket" direction="in" />
- <arg type="u" name="oal_socket" direction="in" />
- <arg type="a(y)" name="data" direction="in" />
- <arg type="a(y)" name="privilege" direction="in" />
- <arg type="u" name="client_socket" direction="out" />
- </method>
-
- <!--
- SendTo
- -->
- <method name="SendTo">
- <arg type="u" name="handle" direction="in" />
- <arg type="u" name="client_socket" direction="in" />
- <arg type="u" name="oal_socket" direction="in" />
- <arg type="y" name="sap" direction="in" />
- <arg type="a(y)" name="data" direction="in" />
- <arg type="a(y)" name="privilege" direction="in" />
- <arg type="u" name="client_socket" direction="out" />
- </method>
-
- <!--
- Receive
- -->
- <method name="Receive">
- <arg type="u" name="handle" direction="in" />
- <arg type="u" name="client_socket" direction="in" />
- <arg type="u" name="oal_socket" direction="in" />
- <arg type="u" name="request_length" direction="in" />
- <arg type="a(y)" name="privilege" direction="in" />
- <arg type="a(y)" name="data" direction="out" />
- </method>
-
- <!--
- ReceiveFrom
- -->
- <method name="ReceiveFrom">
- <arg type="u" name="handle" direction="in" />
- <arg type="u" name="client_socket" direction="in" />
- <arg type="u" name="oal_socket" direction="in" />
- <arg type="u" name="request_length" direction="in" />
- <arg type="a(y)" name="privilege" direction="in" />
- <arg type="y" name="sap" direction="out" />
- <arg type="a(y)" name="data" direction="out" />
- </method>
-
- <!--
- Close
- -->
- <method name="Close">
- <arg type="u" name="handle" direction="in" />
- <arg type="u" name="client_socket" direction="in" />
- <arg type="u" name="oal_socket" direction="in" />
- <arg type="a(y)" name="privilege" direction="in" />
- <arg type="u" name="client_socket" direction="out" />
- </method>
-
- <!--
- Disconnect
- -->
- <method name="Disconnect">
- <arg type="u" name="handle" direction="in" />
- <arg type="u" name="client_socket" direction="in" />
- <arg type="u" name="oal_socket" direction="in" />
- <arg type="a(y)" name="privilege" direction="in" />
- <arg type="u" name="client_socket" direction="out" />
- </method>
-
- <!--
- Error
- -->
- <signal name="Error">
- <arg type="u" name="handle" />
- <arg type="u" name="client_socket" />
- <arg type="u" name="oal_socket" />
- <arg type="i" name="error" />
- </signal>
- </interface>
-
- <interface name="org.tizen.NetNfcService.P2p">
- <!--
- Send
- -->
- <method name="Send">
- <arg type="i" name="type" direction="in" />
- <arg type="a(y)" name="data" direction="in" />
- <arg type="u" name="handle" direction="in" />
- <arg type="a(y)" name="privilege" direction="in" />
- <arg type="i" name="result" direction="out" />
- </method>
-
- <!--
- Detached
- -->
- <signal name="Detached" />
-
- <!--
- Discovered
- -->
- <signal name="Discovered">
- <arg type="u" name="handle" />
- </signal>
-
- <!--
- Receive
- -->
- <signal name="Received">
- <arg type="a(y)" name="data" />
- </signal>
-
- </interface>
- <interface name="org.tizen.NetNfcService.Popup">
- <!--
- Set
- -->
- <method name="Set">
- <arg type="b" name="state" direction="in" />
- <arg type="i" name="focus_state" direction="in" />
- <arg type="a(y)" name="privilege" direction="in" />
- </method>
-
- <!--
- Get
- -->
- <method name="Get">
- <arg type="a(y)" name="privilege" direction="in" />
- <arg type="b" name="state" direction="out" />
- </method>
- </interface>
-
- <interface name="org.tizen.NetNfcService.SecureElement">
- <!--
- Set
- -->
- <method name="Set">
- <arg type="i" name="type" direction="in" />
- <arg type="a(y)" name="privilege" direction="in" />
- <arg type="i" name="result" direction="out" />
- </method>
-
- <!--
- OpenSecureElement
- -->
- <method name="OpenSecureElement">
- <arg type="i" name="type" direction="in" />
- <arg type="a(y)" name="privilege" direction="in" />
- <arg type="i" name="result" direction="out" />
- <arg type="u" name="handle" direction="out" />
- </method>
-
- <!--
- CloseSecureElement
- -->
- <method name="CloseSecureElement">
- <arg type="u" name="handle" direction="in" />
- <arg type="a(y)" name="privilege" direction="in" />
- <arg type="i" name="result" direction="out" />
- </method>
-
- <!--
- GetAtr
- -->
- <method name="GetAtr">
- <arg type="u" name="handle" direction="in" />
- <arg type="a(y)" name="privilege" direction="in" />
- <arg type="i" name="result" direction="out" />
- <arg type="a(y)" name="atr" direction="out" />
- </method>
-
- <!--
- SendAPDU
- -->
- <method name="SendAPDU">
- <arg type="u" name="handle" direction="in" />
- <arg type="a(y)" name="data" direction="in" />
- <arg type="a(y)" name="privilege" direction="in" />
- <arg type="i" name="result" direction="out" />
- <arg type="a(y)" name="response" direction="out" />
- </method>
-
- <!--
- EseDetected
- -->
- <signal name="EseDetected">
- <arg type="u" name="handle" />
- <arg type="i" name="se_type" />
- <arg type="a(y)" name="data" />
- </signal>
-
- <!--
- SeTypeChanged
- -->
- <signal name="SeTypeChanged">
- <arg type="i" name="se_type" />
- </signal>
-
- <!--
- TransactionEvent
- -->
- <signal name="TransactionEvent">
- <arg type="i" name="se_type" />
- <arg type="a(y)" name="aid" />
- <arg type="a(y)" name="param" />
- </signal>
- </interface>
-
- <interface name="org.tizen.NetNfcService.Transceive">
- <!--
- TransceiveData
- -->
- <method name="TransceiveData">
- <arg type="u" name="handle" direction="in" />
- <arg type="u" name="dev_type" direction="in" />
- <arg type="a(y)" name="data" direction="in" />
- <arg type="a(y)" name="privilege" direction="in" />
- <arg type="i" name="result" direction="out" />
- <arg type="a(y)" name="resp_data" direction="out" />
- </method>
- <!--
- Transceive
- -->
- <method name="Transceive">
- <arg type="u" name="handle" direction="in" />
- <arg type="u" name="dev_type" direction="in" />
- <arg type="a(y)" name="data" direction="in" />
- <arg type="a(y)" name="privilege" direction="in" />
- <arg type="i" name="result" direction="out" />
- </method>
- </interface>
-
- <interface name="org.tizen.NetNfcService.Handover">
- <!--
- Request
- -->
- <method name="Request">
- <arg type="u" name="handle" direction="in" />
- <arg type="i" name="type" direction="in" />
- <arg type="a(y)" name="privilege" direction="in" />
- <arg type="i" name="event" direction="out" />
- <arg type="i" name="carrier_type" direction="out" />
- <arg type="a(y)" name="handover_data" direction="out" />
- </method>
- </interface>
-
- <interface name="org.tizen.NetNfcService.Test">
- <!--
- SimTest
- -->
- <method name="SimTest">
- <arg type="a(y)" name="privilege" direction="in" />
- <arg type="i" name="result" direction="out" />
- </method>
-
- <!--
- PrbsTest
- -->
- <method name="PrbsTest">
- <arg type="u" name="tech" direction="in" />
- <arg type="u" name="rate" direction="in" />
- <arg type="a(y)" name="privilege" direction="in" />
- <arg type="i" name="result" direction="out" />
- </method>
-
- <!--
- GetFirmwareVersion
- -->
- <method name="GetFirmwareVersion">
- <arg type="a(y)" name="privilege" direction="in" />
- <arg type="i" name="result" direction="out" />
- <arg type="s" name="version" direction="out" />
- </method>
-
- <method name="SetEeData">
- <arg type="u" name="mode" direction="in" />
- <arg type="u" name="reg_id" direction="in" />
- <arg type="a(y)" name="data" direction="in" />
- <arg type="a(y)" name="privilege" direction="in" />
- <arg type="i" name="result" direction="out" />
- </method>
- </interface>
-
- <interface name="org.tizen.NetNfcService.Snep">
- <!--
- Register Server
- -->
- <method name="ServerRegister">
- <arg type="u" name="sap" direction="in" />
- <arg type="s" name="san" direction="in" />
- <arg type="u" name="user_data" direction="in" />
- <arg type="a(y)" name="privilege" direction="in" />
- <arg type="i" name="result" direction="out" />
- </method>
-
- <!--
- Unregister Server
- -->
- <method name="ServerUnregister">
- <arg type="u" name="sap" direction="in" />
- <arg type="s" name="san" direction="in" />
- <arg type="a(y)" name="privilege" direction="in" />
- <arg type="i" name="result" direction="out" />
- </method>
-
- <!--
- Start Server
- -->
- <method name="ServerStart">
- <arg type="u" name="handle" direction="in" />
- <arg type="u" name="sap" direction="in" />
- <arg type="s" name="san" direction="in" />
- <arg type="u" name="user_data" direction="in" />
- <arg type="a(y)" name="privilege" direction="in" />
- <arg type="i" name="result" direction="out" />
- </method>
-
- <!--
- Start Client
- -->
- <method name="ClientStart">
- <arg type="u" name="handle" direction="in" />
- <arg type="u" name="sap" direction="in" />
- <arg type="s" name="san" direction="in" />
- <arg type="u" name="user_data" direction="in" />
- <arg type="a(y)" name="privilege" direction="in" />
- <arg type="i" name="result" direction="out" />
- </method>
-
- <!--
- ClientRequest
- -->
- <method name="ClientRequest">
- <arg type="u" name="snep_handle" direction="in" />
- <arg type="u" name="type" direction="in" />
- <arg type="a(y)" name="ndef_msg" direction="in" />
- <arg type="a(y)" name="privilege" direction="in" />
- <arg type="i" name="result" direction="out" />
- <arg type="u" name="type" direction="out" />
- <arg type="a(y)" name="data" direction="out" />
- </method>
-
- <!--
- StopService
- -->
- <method name="StopSnep">
- <arg type="u" name="handle" direction="in" />
- <arg type="u" name="snep_handle" direction="in" />
- <arg type="a(y)" name="privilege" direction="in" />
- <arg type="i" name="result" direction="out" />
- </method>
-
- <!--
- SnepEvent
- -->
- <signal name="SnepEvent">
- <arg type="u" name="handle" />
- <arg type="u" name="event" />
- <arg type="i" name="result" />
- <arg type="a(y)" name="ndef_msg" />
- <arg type="u" name="user_data" />
- </signal>
- </interface>
-
-</node>
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
-
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-// libc header
-#include <stdlib.h>
-#include <string.h>
-#include <pthread.h>
-#include <fcntl.h>
-
-// platform header
-#include <bluetooth-api.h>
-#include <vconf.h>
-
-// nfc-manager header
-#include "net_nfc_util_internal.h"
-#include "net_nfc_debug_internal.h"
-#include "net_nfc_oem_controller.h"
-#include "net_nfc_util_defines.h"
-
-#ifndef NET_NFC_EXPORT_API
-#define NET_NFC_EXPORT_API __attribute__((visibility("default")))
-#endif
-
-static const char *schema[] =
-{
- "",
- "http://www.",
- "https://www.",
- "http://",
- "https://",
- "tel:",
- "mailto:",
- "ftp://anonymous:anonymous@",
- "ftp://ftp.",
- "ftps://",
- "sftp://",
- "smb://",
- "nfs://",
- "ftp://",
- "dav://",
- "news:",
- "telnet://",
- "imap:",
- "rtsp://",
- "urn:",
- "pop:",
- "sip:",
- "sips:",
- "tftp:",
- "btspp://",
- "btl2cap://",
- "btgoep://",
- "tcpobex://",
- "irdaobex://",
- "file://",
- "urn:epc:id:",
- "urn:epc:tag:",
- "urn:epc:pat:",
- "urn:epc:raw:",
- "urn:epc:",
- "urn:epc:nfc:",
-};
-
-// defines for bluetooth api
-#define USE_BLUETOOTH_API
-static uint8_t *bt_addr = NULL;
-
-/* for log tag */
-#define NET_NFC_MANAGER_NAME "nfc-manager-daemon"
-static const char *log_tag = LOG_CLIENT_TAG;
-extern char *__progname;
-FILE *nfc_log_file;
-
-const char *net_nfc_get_log_tag()
-{
- return log_tag;
-}
-
-void __attribute__ ((constructor)) lib_init()
-{
- if (__progname != NULL && strncmp(__progname, NET_NFC_MANAGER_NAME, strlen(NET_NFC_MANAGER_NAME)) == 0)
- {
- log_tag = LOG_SERVER_TAG;
- }
-}
-
-void __attribute__ ((destructor)) lib_fini()
-{
-}
-
-void net_nfc_manager_init_log()
-{
- nfc_log_file = fopen(NFC_DLOG_FILE, "a+");
- if (nfc_log_file != NULL)
- {
- char timeBuf[50];
- time_t rawtime;
-
- time (&rawtime);
- strftime(timeBuf, sizeof(timeBuf), "%m-%d %H:%M:%S", localtime(&rawtime));
- fprintf(nfc_log_file, "\n%s",timeBuf);
- fprintf(nfc_log_file, "========== log begin, pid [%d] =========", getpid());
- fflush(nfc_log_file);
- }
- else
- {
- fprintf(stderr, "\n\nfopen error\n\n");
- }
-}
-
-void net_nfc_manager_fini_log()
-{
- if (nfc_log_file != NULL)
- {
- char timeBuf[50];
- time_t rawtime;
-
- time (&rawtime);
- strftime(timeBuf, sizeof(timeBuf), "%m-%d %H:%M:%S", localtime(&rawtime));
- fprintf(nfc_log_file, "\n%s",timeBuf);
- fprintf(nfc_log_file, "=========== log end, pid [%d] ==========", getpid());
- fflush(nfc_log_file);
- fclose(nfc_log_file);
- nfc_log_file = NULL;
- }
-}
-
-NET_NFC_EXPORT_API void __net_nfc_util_free_mem(void **mem, char *filename, unsigned int line)
-{
- if (mem == NULL)
- {
- SECURE_LOGD("FILE: %s, LINE:%d, Invalid parameter in mem free util, mem is NULL", filename, line);
- return;
- }
-
- if (*mem == NULL)
- {
- SECURE_LOGD("FILE: %s, LINE:%d, Invalid Parameter in mem free util, *mem is NULL", filename, line);
- return;
- }
-
- g_free(*mem);
- *mem = NULL;
-}
-
-NET_NFC_EXPORT_API void __net_nfc_util_alloc_mem(void **mem, int size, char *filename, unsigned int line)
-{
- if (mem == NULL || size <= 0)
- {
- SECURE_LOGD("FILE: %s, LINE:%d, Invalid parameter in mem alloc util, mem [%p], size [%d]", filename, line, mem, size);
- return;
- }
-
- if (*mem != NULL)
- {
- SECURE_LOGD("FILE: %s, LINE:%d, WARNING: Pointer is not NULL, mem [%p]", filename, line, *mem);
- }
-
- *mem = g_malloc0(size);
-
- if (*mem == NULL)
- {
- SECURE_LOGD("FILE: %s, LINE:%d, Allocation is failed, size [%d]", filename, line, size);
- }
-}
-
-NET_NFC_EXPORT_API void __net_nfc_util_strdup(char **output, const char *origin, char *filename, unsigned int line)
-{
- if (output == NULL || origin == NULL)
- {
- SECURE_LOGD("FILE: %s, LINE:%d, Invalid parameter in strdup, output [%p], origin [%p]", filename, line, output, origin);
- return;
- }
-
- if (*output != NULL)
- {
- SECURE_LOGD("FILE: %s, LINE:%d, WARNING: Pointer is not NULL, mem [%p]", filename, line, *output);
- }
-
- *output = g_strdup(origin);
-
- if (*output == NULL)
- {
- SECURE_LOGD("FILE: %s, LINE:%d, strdup failed", filename, line);
- }
-}
-
-NET_NFC_EXPORT_API bool net_nfc_util_alloc_data(data_s *data, uint32_t length)
-{
- if (data == NULL || length == 0)
- return false;
-
- _net_nfc_util_alloc_mem(data->buffer, length);
- if (data->buffer == NULL)
- return false;
-
- data->length = length;
-
- return true;
-}
-
-NET_NFC_EXPORT_API bool net_nfc_util_duplicate_data(data_s *dest, net_nfc_data_s *src)
-{
- if (dest == NULL || src == NULL || src->length == 0)
- return false;
-
- if (net_nfc_util_alloc_data(dest, src->length) == false)
- return false;
-
- memcpy(dest->buffer, src->buffer, dest->length);
-
- return true;
-}
-
-NET_NFC_EXPORT_API void net_nfc_util_free_data(data_s *data)
-{
- if (data == NULL || data->buffer == NULL)
- return;
-
- _net_nfc_util_free_mem(data->buffer);
- data->length = 0;
-}
-
-net_nfc_conn_handover_carrier_state_e net_nfc_util_get_cps(net_nfc_conn_handover_carrier_type_e carrier_type)
-{
- net_nfc_conn_handover_carrier_state_e cps = NET_NFC_CONN_HANDOVER_CARRIER_INACTIVATE;
-
- if (carrier_type == NET_NFC_CONN_HANDOVER_CARRIER_BT)
- {
- int ret = bluetooth_check_adapter();
-
- switch (ret)
- {
- case BLUETOOTH_ADAPTER_ENABLED :
- cps = NET_NFC_CONN_HANDOVER_CARRIER_ACTIVATE;
- break;
-
- case BLUETOOTH_ADAPTER_CHANGING_ENABLE :
- cps = NET_NFC_CONN_HANDOVER_CARRIER_ACTIVATING;
- break;
-
- case BLUETOOTH_ADAPTER_DISABLED :
- case BLUETOOTH_ADAPTER_CHANGING_DISABLE :
- case BLUETOOTH_ERROR_NO_RESOURCES :
- default :
- cps = NET_NFC_CONN_HANDOVER_CARRIER_INACTIVATE;
- break;
- }
- }
- else if (carrier_type == NET_NFC_CONN_HANDOVER_CARRIER_WIFI_BSS)
- {
- int wifi_state = 0;
-
- vconf_get_int(VCONFKEY_WIFI_STATE, &wifi_state);
-
- switch (wifi_state)
- {
- case VCONFKEY_WIFI_UNCONNECTED :
- case VCONFKEY_WIFI_CONNECTED :
- case VCONFKEY_WIFI_TRANSFER :
- cps = NET_NFC_CONN_HANDOVER_CARRIER_ACTIVATE;
- break;
-
- case VCONFKEY_WIFI_OFF :
- default :
- cps = NET_NFC_CONN_HANDOVER_CARRIER_INACTIVATE;
- break;
- }
- }
-
- return cps;
-}
-
-uint8_t *net_nfc_util_get_local_bt_address()
-{
- if (bt_addr != NULL)
- {
- return bt_addr;
- }
-
- _net_nfc_util_alloc_mem(bt_addr, BLUETOOTH_ADDRESS_LENGTH);
- if (bt_addr != NULL)
- {
- if (net_nfc_util_get_cps(NET_NFC_CONN_HANDOVER_CARRIER_BT) != NET_NFC_CONN_HANDOVER_CARRIER_ACTIVATE)
- {
- // bt power is off. so get bt address from configuration file.
- FILE *fp = NULL;
-
- if ((fp = fopen(HIDDEN_BT_ADDR_FILE, "r")) != NULL)
- {
- unsigned char temp[BLUETOOTH_ADDRESS_LENGTH * 2] = { 0, };
-
- int ch;
- int count = 0;
- int i = 0;
-
- while ((ch = fgetc(fp)) != EOF && count < BLUETOOTH_ADDRESS_LENGTH * 2)
- {
- if (((ch >= '0') && (ch <= '9')))
- {
- temp[count++] = ch - '0';
- }
- else if (((ch >= 'a') && (ch <= 'z')))
- {
- temp[count++] = ch - 'a' + 10;
- }
- else if (((ch >= 'A') && (ch <= 'Z')))
- {
- temp[count++] = ch - 'A' + 10;
- }
- }
-
- for (; i < BLUETOOTH_ADDRESS_LENGTH; i++)
- {
- bt_addr[i] = temp[i * 2] << 4 | temp[i * 2 + 1];
- }
-
- fclose(fp);
- }
- }
- else
- {
- bluetooth_device_address_t local_address;
-
- memset(&local_address, 0x00, sizeof(bluetooth_device_address_t));
-
- bluetooth_get_local_address(&local_address);
-
- memcpy(bt_addr, &local_address.addr, BLUETOOTH_ADDRESS_LENGTH);
- }
- }
-
- return bt_addr;
-}
-
-void net_nfc_util_enable_bluetooth(void)
-{
- bluetooth_enable_adapter();
-}
-
-bool net_nfc_util_strip_string(char *buffer, int buffer_length)
-{
- bool result = false;
- char *temp = NULL;
- int i = 0;
-
- _net_nfc_util_alloc_mem(temp, buffer_length);
- if (temp == NULL)
- {
- return result;
- }
-
- for (; i < buffer_length; i++)
- {
- if (buffer[i] != ' ' && buffer[i] != '\t')
- break;
- }
-
- if (i < buffer_length)
- {
- memcpy(temp, &buffer[i], buffer_length - i);
- memset(buffer, 0x00, buffer_length);
-
- memcpy(buffer, temp, buffer_length - i);
-
- result = true;
- }
- else
- {
- result = false;
- }
-
- _net_nfc_util_free_mem(temp);
-
- return true;
-}
-
-static uint16_t _net_nfc_util_update_CRC(uint8_t ch, uint16_t *lpwCrc)
-{
- ch = (ch ^ (uint8_t)((*lpwCrc) & 0x00FF));
- ch = (ch ^ (ch << 4));
- *lpwCrc = (*lpwCrc >> 8) ^ ((uint16_t)ch << 8) ^ ((uint16_t)ch << 3) ^ ((uint16_t)ch >> 4);
- return (*lpwCrc);
-}
-
-void net_nfc_util_compute_CRC(CRC_type_e CRC_type, uint8_t *buffer, uint32_t length)
-{
- uint8_t chBlock = 0;
- int msg_length = length - 2;
- uint8_t *temp = buffer;
-
- // default is CRC_B
- uint16_t wCrc = 0xFFFF; /* ISO/IEC 13239 (formerly ISO/IEC 3309) */
-
- switch (CRC_type)
- {
- case CRC_A :
- wCrc = 0x6363;
- break;
-
- case CRC_B :
- wCrc = 0xFFFF;
- break;
- }
-
- do
- {
- chBlock = *buffer++;
- _net_nfc_util_update_CRC(chBlock, &wCrc);
- }
- while (--msg_length > 0);
-
- if (CRC_type == CRC_B)
- {
- wCrc = ~wCrc; /* ISO/IEC 13239 (formerly ISO/IEC 3309) */
- }
-
- temp[length - 2] = (uint8_t)(wCrc & 0xFF);
- temp[length - 1] = (uint8_t)((wCrc >> 8) & 0xFF);
-}
-
-const char *net_nfc_util_get_schema_string(int index)
-{
- if (index == 0 || index >= NET_NFC_SCHEMA_MAX)
- return NULL;
- else
- return schema[index];
-}
-
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
-
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-// libc header
-
-// platform header
-
-// nfc-manager header
-#include "net_nfc_debug_internal.h"
-#include "net_nfc_util_internal.h"
-#include "net_nfc_util_gdbus_internal.h"
-
-void net_nfc_util_gdbus_variant_to_buffer(GVariant *variant, uint8_t **buffer,
- size_t *length)
-{
- GVariantIter *iter;
- guint8 *buf = NULL;
- guint size = 0;
-
- if (variant == NULL)
- return;
-
- g_variant_get(variant, "a(y)", &iter);
-
- size = g_variant_iter_n_children(iter);
- buf = g_new0(guint8, size);
- if (buf != NULL)
- {
- guint8 element;
- guint i;
-
- i = 0;
- while (g_variant_iter_loop(iter, "(y)", &element))
- {
- *(buf + i) = element;
- i++;
- }
-
- g_variant_iter_free(iter);
-
- if (length)
- *length = size;
-
- if (buffer)
- *buffer = buf;
- else
- g_free(buf);
- }
-}
-
-data_s *net_nfc_util_gdbus_variant_to_data(GVariant *variant)
-{
- GVariantIter *iter;
- guint8 *buf = NULL;
- guint size = 0;
- data_s *result = NULL;
-
- if (variant == NULL)
- return result;
-
- g_variant_get(variant, "a(y)", &iter);
-
- size = g_variant_iter_n_children(iter);
- buf = g_new0(guint8, size);
- if (buf != NULL)
- {
- guint i;
- guint8 element;
-
- i = 0;
- while (g_variant_iter_loop(iter, "(y)", &element))
- {
- *(buf + i) = element;
- i++;
- }
-
- g_variant_iter_free(iter);
-
- result = g_new0(data_s, 1);
- if (result != NULL)
- {
- result->buffer = buf;
- result->length = size;
- }
- else
- {
- g_free(buf);
- }
- }
-
- return result;
-}
-
-void net_nfc_util_gdbus_variant_to_data_s(GVariant *variant, data_s *data)
-{
- GVariantIter *iter;
-
- guint8 element;
- guint8 *buf = NULL;
-
- guint size = 0;
-
- if (data == NULL)
- return;
-
- data->buffer = NULL;
- data->length = 0;
-
- if (variant == NULL)
- {
- return;
- }
-
- g_variant_get(variant, "a(y)", &iter);
-
- size = g_variant_iter_n_children(iter);
- buf = g_new0(guint8, size);
- if (buf != NULL)
- {
- guint i = 0;
-
- while (g_variant_iter_loop(iter, "(y)", &element))
- {
- *(buf + i) = element;
- i++;
- }
-
- g_variant_iter_free(iter);
-
- data->length = size;
- data->buffer = buf;
- }
-}
-
-GVariant *net_nfc_util_gdbus_buffer_to_variant(const uint8_t *buffer,
- size_t length)
-{
- GVariantBuilder builder;
-
- g_variant_builder_init(&builder, G_VARIANT_TYPE("a(y)"));
-
- if (buffer && length > 0)
- {
- int i;
-
- for(i = 0; i < length; i++)
- g_variant_builder_add(&builder, "(y)", *(buffer + i));
- }
-
- return g_variant_builder_end(&builder);
-}
-
-GVariant *net_nfc_util_gdbus_data_to_variant(const data_s *data)
-{
- if (data != NULL)
- {
- return net_nfc_util_gdbus_buffer_to_variant(data->buffer,
- data->length);
- }
- else
- {
- return net_nfc_util_gdbus_buffer_to_variant(NULL, 0);
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
-
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-#include <glib.h>
-
-#include "net_nfc_typedef_internal.h"
-#include "net_nfc_debug_internal.h"
-#include "net_nfc_util_defines.h"
-#include "net_nfc_util_internal.h"
-#include "net_nfc_util_ndef_record.h"
-#include "net_nfc_util_ndef_message.h"
-#include "net_nfc_util_handover.h"
-
-typedef struct _search_index
-{
- int target;
- int current;
- void *found;
-} search_index;
-
-static int __property_equal_to(gconstpointer key1, gconstpointer key2)
-{
- net_nfc_carrier_property_s *arg1 = (net_nfc_carrier_property_s *)key1;
- net_nfc_carrier_property_s *arg2 = (net_nfc_carrier_property_s *)key2;
-
- if (arg1->attribute < arg2->attribute)
- {
- return -1;
- }
- else if (arg1->attribute > arg2->attribute)
- {
- return 1;
- }
- else
- {
- return 0;
- }
-}
-
-static net_nfc_carrier_property_s *__find_property_by_attrubute(GList *list, uint16_t attribute)
-{
- GList *found = NULL;
- net_nfc_carrier_property_s temp;
-
- temp.attribute = attribute;
- found = g_list_find_custom(list, &temp, __property_equal_to);
-
- if (found == NULL)
- {
- return NULL;
- }
-
- return (net_nfc_carrier_property_s *)found->data;
-}
-
-static void __find_nth_group(gpointer data, gpointer user_data)
-{
- net_nfc_carrier_property_s *info = (net_nfc_carrier_property_s *)data;
- search_index *nth = (search_index *)user_data;
-
- if (info == NULL || user_data == NULL)
- return;
-
- if (info->is_group)
- {
- if (nth->current == nth->target)
- {
- nth->found = data;
- }
- nth->current++;
- }
-}
-
-static void __free_all_data(gpointer data, gpointer user_data)
-{
- net_nfc_carrier_property_s *info = (net_nfc_carrier_property_s *)data;
-
- if (info == NULL)
- return;
-
- if (info->is_group)
- {
- DEBUG_MSG("FREE: group is found");
- net_nfc_util_free_carrier_group((net_nfc_carrier_property_s *)info);
- }
- else
- {
- DEBUG_MSG("FREE: element is found ATTRIB:0x%X length:%d", info->attribute, info->length);
- _net_nfc_util_free_mem(info->data);
- _net_nfc_util_free_mem(info);
- }
-}
-
-static net_nfc_error_e __net_nfc_util_create_connection_handover_collsion_resolution_record(ndef_record_s **record)
-{
- uint32_t state = 0;
- data_s typeName = { 0 };
- data_s payload = { 0 };
- uint8_t rand_buffer[2] = { 0, 0 };
- uint16_t random_num;
-
- if (record == NULL)
- return NET_NFC_NULL_PARAMETER;
-
- state = (uint32_t)time(NULL);
- random_num = (unsigned short)rand_r(&state);
-
- typeName.buffer = (uint8_t *)COLLISION_DETECT_RECORD_TYPE;
- typeName.length = strlen(COLLISION_DETECT_RECORD_TYPE);
-
- rand_buffer[0] = (random_num & 0xff00) >> 8; // MSB
- rand_buffer[1] = (random_num & 0x00ff); // LSB
-
- payload.buffer = rand_buffer;
- payload.length = 2;
-
- DEBUG_MSG("rand number = [0x%x] [0x%x] => [0x%x]", payload.buffer[0], payload.buffer[1], random_num);
-
- return net_nfc_util_create_record(NET_NFC_RECORD_WELL_KNOWN_TYPE, &typeName, NULL, &payload, record);
-}
-
-static int __net_nfc_get_size_of_attribute(int attribute)
-{
- switch (attribute)
- {
- case NET_NFC_BT_ATTRIBUTE_UUID16_PART :
- case NET_NFC_BT_ATTRIBUTE_UUID16 :
- case NET_NFC_BT_ATTRIBUTE_UUID32_PART :
- case NET_NFC_BT_ATTRIBUTE_UUID32 :
- case NET_NFC_BT_ATTRIBUTE_UUID128_PART :
- case NET_NFC_BT_ATTRIBUTE_UUID128 :
- case NET_NFC_BT_ATTRIBUTE_NAME_PART :
- case NET_NFC_BT_ATTRIBUTE_NAME :
- case NET_NFC_BT_ATTRIBUTE_TXPOWER :
- case NET_NFC_BT_ATTRIBUTE_OOB_COD :
- case NET_NFC_BT_ATTRIBUTE_OOB_HASH_C :
- case NET_NFC_BT_ATTRIBUTE_OOB_HASH_R :
- case NET_NFC_BT_ATTRIBUTE_ID :
- case NET_NFC_BT_ATTRIBUTE_MANUFACTURER :
- case NET_NFC_BT_ATTRIBUTE_ADDRESS :
- // case NET_NFC_WIFI_ATTRIBUTE_VERSION2:
- return 1;
-
- default :
- return 2;
- }
-}
-
-net_nfc_error_e net_nfc_util_create_carrier_config(net_nfc_carrier_config_s **config, net_nfc_conn_handover_carrier_type_e type)
-{
- if (config == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
-
- if (type < 0 || type >= NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN)
- {
- return NET_NFC_OUT_OF_BOUND;
- }
-
- _net_nfc_util_alloc_mem(*config, sizeof(net_nfc_carrier_config_s));
- if (*config == NULL)
- {
- return NET_NFC_ALLOC_FAIL;
- }
-
- (*config)->type = type;
- (*config)->length = 0;
-
- return NET_NFC_OK;
-}
-
-net_nfc_error_e net_nfc_util_add_carrier_config_property(net_nfc_carrier_config_s *config, uint16_t attribute, uint16_t size, uint8_t * data)
-{
- net_nfc_carrier_property_s *elem = NULL;
-
- DEBUG_MSG("ADD property: [ATTRIB:0x%X, SIZE:%d]", attribute, size);
-
- if (config == NULL || data == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
-
- if (__find_property_by_attrubute(config->data, attribute) != NULL)
- {
- return NET_NFC_ALREADY_REGISTERED;
- }
-
- _net_nfc_util_alloc_mem(elem, sizeof (net_nfc_carrier_property_s));
- if (elem == NULL)
- {
- return NET_NFC_ALLOC_FAIL;
- }
- elem->attribute = attribute;
- elem->length = size;
- elem->is_group = false;
-
- _net_nfc_util_alloc_mem(elem->data, size);
- if (elem->data == NULL)
- {
- _net_nfc_util_free_mem(elem);
- return NET_NFC_ALLOC_FAIL;
- }
- memcpy(elem->data, data, size);
-
- config->data = g_list_append(config->data, elem);
- config->length += size + 2 * __net_nfc_get_size_of_attribute(attribute);
-
- DEBUG_MSG("ADD completed total length %d", config->length);
-
- return NET_NFC_OK;
-}
-
-net_nfc_error_e net_nfc_util_remove_carrier_config_property(net_nfc_carrier_config_s *config, uint16_t attribute)
-{
- net_nfc_carrier_property_s *elem = NULL;
-
- if (config == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
-
- elem = __find_property_by_attrubute(config->data, attribute);
- if (elem == NULL)
- {
- return NET_NFC_NO_DATA_FOUND;
- }
-
- config->data = g_list_remove(config->data, elem);
- config->length -= (elem->length + 2 * __net_nfc_get_size_of_attribute(attribute));
-
- if (elem->is_group)
- {
- net_nfc_util_free_carrier_group((net_nfc_carrier_property_s *)elem);
- }
- else
- {
- _net_nfc_util_free_mem(elem->data);
- _net_nfc_util_free_mem(elem);
- }
-
- return NET_NFC_OK;
-}
-
-net_nfc_error_e net_nfc_util_get_carrier_config_property(net_nfc_carrier_config_s *config, uint16_t attribute, uint16_t * size, uint8_t ** data)
-{
- net_nfc_carrier_property_s *elem = NULL;
-
- if (config == NULL || size == NULL || data == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
-
- elem = __find_property_by_attrubute(config->data, attribute);
- if (elem == NULL)
- {
- *size = 0;
- *data = NULL;
- return NET_NFC_NO_DATA_FOUND;
- }
-
- *size = elem->length;
- if (elem->is_group)
- {
- *data = NULL;
- }
- else
- {
- *data = elem->data;
- }
-
- return NET_NFC_OK;
-}
-
-net_nfc_error_e net_nfc_util_append_carrier_config_group(net_nfc_carrier_config_s *config, net_nfc_carrier_property_s *group)
-{
- if (config == NULL || group == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
- if (g_list_find(config->data, group) != NULL)
- {
- return NET_NFC_ALREADY_REGISTERED;
- }
-
- config->data = g_list_append(config->data, group);
- config->length += group->length;
-
- return NET_NFC_OK;
-}
-
-net_nfc_error_e net_nfc_util_remove_carrier_config_group(net_nfc_carrier_config_s *config, net_nfc_carrier_property_s *group)
-{
- if (config == NULL || group == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
-
- if (g_list_find(config->data, group) != NULL)
- {
- return NET_NFC_NO_DATA_FOUND;
- }
-
- config->length -= group->length;
- config->data = g_list_remove(config->data, group);
-
- net_nfc_util_free_carrier_group((net_nfc_carrier_property_s *)group);
-
- return NET_NFC_OK;
-}
-
-net_nfc_error_e net_nfc_util_get_carrier_config_group(net_nfc_carrier_config_s *config, int index, net_nfc_carrier_property_s **group)
-{
- search_index result;
-
- if (config == NULL || group == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
-
- if (index < 0)
- {
- return NET_NFC_OUT_OF_BOUND;
- }
-
- result.current = 0;
- result.target = index;
- result.found = NULL;
-
- g_list_foreach(config->data, __find_nth_group, &result);
-
- if (result.found == NULL)
- {
- return NET_NFC_NO_DATA_FOUND;
- }
- *group = (net_nfc_carrier_property_s *)result.found;
-
- return NET_NFC_OK;
-}
-
-net_nfc_error_e net_nfc_util_free_carrier_config(net_nfc_carrier_config_s *config)
-{
- if (config == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
-
- g_list_foreach(config->data, __free_all_data, NULL);
- g_list_free(config->data);
-
- _net_nfc_util_free_mem(config);
-
- return NET_NFC_OK;
-}
-
-net_nfc_error_e net_nfc_util_create_carrier_config_group(net_nfc_carrier_property_s **group, uint16_t attribute)
-{
- if (group == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
-
- _net_nfc_util_alloc_mem(*group, sizeof(net_nfc_carrier_property_s));
- if (*group == NULL)
- {
- return NET_NFC_ALLOC_FAIL;
- }
-
- (*group)->attribute = attribute;
- (*group)->is_group = true;
-
- return NET_NFC_OK;
-}
-
-net_nfc_error_e net_nfc_util_add_carrier_config_group_property(net_nfc_carrier_property_s *group, uint16_t attribute, uint16_t size, uint8_t *data)
-{
- net_nfc_carrier_property_s *elem = NULL;
-
- DEBUG_MSG("ADD group property: [ATTRIB:0x%X, SIZE:%d]", attribute, size);
-
- if (group == NULL || data == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
-
- if (__find_property_by_attrubute((GList *)group->data, attribute) != NULL)
- {
- return NET_NFC_ALREADY_REGISTERED;
- }
-
- _net_nfc_util_alloc_mem(elem, sizeof (net_nfc_carrier_property_s));
- if (elem == NULL)
- {
- return NET_NFC_ALLOC_FAIL;
- }
- elem->attribute = attribute;
- elem->length = size;
- elem->is_group = false;
-
- _net_nfc_util_alloc_mem(elem->data, size);
- if (elem->data == NULL)
- {
- _net_nfc_util_free_mem(elem);
- return NET_NFC_ALLOC_FAIL;
- }
- memcpy(elem->data, data, size);
- group->length += size + 2 * __net_nfc_get_size_of_attribute(attribute);
- group->data = g_list_append((GList *)(group->data), elem);
-
- DEBUG_MSG("ADD group completed total length %d", group->length);
-
- return NET_NFC_OK;
-}
-
-net_nfc_error_e net_nfc_util_get_carrier_config_group_property(net_nfc_carrier_property_s *group, uint16_t attribute, uint16_t *size, uint8_t ** data)
-{
- net_nfc_carrier_property_s *elem = NULL;
-
- if (group == NULL || size == NULL || data == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
-
- elem = __find_property_by_attrubute((GList*)(group->data), attribute);
- if (elem == NULL)
- {
- *size = 0;
- *data = NULL;
- return NET_NFC_NO_DATA_FOUND;
- }
-
- *size = elem->length;
- *data = elem->data;
-
- return NET_NFC_OK;
-}
-
-net_nfc_error_e net_nfc_util_remove_carrier_config_group_property(net_nfc_carrier_property_s *group, uint16_t attribute)
-{
- net_nfc_carrier_property_s *elem = NULL;
-
- if (group == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
-
- elem = __find_property_by_attrubute((GList*)(group->data), attribute);
- if (elem == NULL)
- {
- return NET_NFC_NO_DATA_FOUND;
- }
- group->length -= elem->length;
- group->data = g_list_remove((GList*)(group->data), elem);
-
- _net_nfc_util_free_mem(elem->data);
- _net_nfc_util_free_mem(elem);
-
- return NET_NFC_OK;
-
-}
-
-net_nfc_error_e net_nfc_util_free_carrier_group(net_nfc_carrier_property_s *group)
-{
- if (group == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
- g_list_foreach((GList*)(group->data), __free_all_data, NULL);
- g_list_free((GList*)(group->data));
-
- _net_nfc_util_free_mem(group);
-
- return NET_NFC_OK;
-}
-
-static void __make_serial_wifi(gpointer data, gpointer user_data)
-{
- net_nfc_carrier_property_s *info = (net_nfc_carrier_property_s *)data;
- data_s *payload = (data_s *)user_data;
- uint8_t *current;
- int inc = 0;
-
- if (info == NULL || user_data == NULL)
- return;
-
- current = payload->buffer + payload->length;
- inc = __net_nfc_get_size_of_attribute(info->attribute);
-
- if (info->is_group)
- {
- DEBUG_MSG("[WIFI]Found Group make recursive");
- *(uint16_t *)current = info->attribute;
- *(uint16_t *)(current + inc) = info->length;
- payload->length += (inc + inc);
- g_list_foreach((GList *)info->data, __make_serial_wifi, payload);
- }
- else
- {
- DEBUG_MSG("[WIFI]Element is found attrib:0x%X length:%d current:%d", info->attribute, info->length, payload->length);
- *(uint16_t *)current = info->attribute;
- *(uint16_t *)(current + inc) = info->length;
- memcpy(current + inc + inc, info->data, info->length);
- payload->length += (inc + inc + info->length);
- }
-}
-
-static void __make_serial_bt(gpointer data, gpointer user_data)
-{
- net_nfc_carrier_property_s *info = (net_nfc_carrier_property_s *)data;
- data_s *payload = (data_s *)user_data;
- uint8_t *current;
- int inc = 0;
-
- if (info == NULL || user_data == NULL)
- return;
-
- current = payload->buffer + payload->length; /* payload->length is zero */
-
- if (info->is_group)
- {
- DEBUG_MSG("[BT]Found Group. call recursive");
- g_list_foreach((GList *)info->data, __make_serial_bt, payload);
- }
- else
- {
- if (info->attribute != NET_NFC_BT_ATTRIBUTE_ADDRESS)
- {
- DEBUG_MSG("[BT]Element is found attrib:0x%X length:%d current:%d", info->attribute, info->length, payload->length);
- inc = __net_nfc_get_size_of_attribute(info->attribute);
- *current = info->length + 1;
- *(current + inc) = info->attribute;
- memcpy(current + inc + inc, info->data, info->length);
- payload->length += (inc + inc + info->length);
- }
- else
- {
- DEBUG_MSG("[BT]BT address is found length:%d", info->length);
- memcpy(current, info->data, info->length);
- payload->length += (info->length);
- }
- }
-}
-
-net_nfc_error_e net_nfc_util_create_ndef_record_with_carrier_config(ndef_record_s **record, net_nfc_carrier_config_s *config)
-{
- data_s payload = { NULL, 0 };
- data_s record_type = { NULL, 0 };
-
- if (record == NULL || config == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
-
- _net_nfc_util_alloc_mem(payload.buffer, config->length);
- if (payload.buffer == NULL)
- {
- return NET_NFC_ALLOC_FAIL;
- }
- payload.length = 0; /* this should be zero because this will be used as current position of data written */
-
- if (config->type == NET_NFC_CONN_HANDOVER_CARRIER_WIFI_BSS)
- {
- record_type.buffer = (uint8_t *)CONN_HANDOVER_WIFI_BSS_CARRIER_MIME_NAME;
- record_type.length = strlen(CONN_HANDOVER_WIFI_BSS_CARRIER_MIME_NAME);
- g_list_foreach(config->data, __make_serial_wifi, &payload);
- }
- else if (config->type == NET_NFC_CONN_HANDOVER_CARRIER_WIFI_IBSS)
- {
- record_type.buffer = (uint8_t *)CONN_HANDOVER_WIFI_IBSS_CARRIER_MIME_NAME;
- record_type.length = strlen(CONN_HANDOVER_WIFI_IBSS_CARRIER_MIME_NAME);
- g_list_foreach(config->data, __make_serial_wifi, &payload);
- }
- else if (config->type == NET_NFC_CONN_HANDOVER_CARRIER_BT)
- {
- record_type.buffer = (uint8_t *)CONN_HANDOVER_BT_CARRIER_MIME_NAME;
- record_type.length = strlen(CONN_HANDOVER_BT_CARRIER_MIME_NAME);
- payload.buffer += 2; /* OOB total length */
- g_list_foreach(config->data, __make_serial_bt, &payload);
- payload.buffer -= 2; /* return to original */
- payload.length += 2;
- payload.buffer[0] = payload.length & 0xFF;
- payload.buffer[1] = (payload.length >> 8) & 0xFF;
- }
- else
- {
- return NET_NFC_NOT_SUPPORTED;
- }
-
- DEBUG_MSG("payload length = %d", payload.length);
-
- return net_nfc_util_create_record(NET_NFC_RECORD_MIME_TYPE, &record_type, NULL, &payload, record);
-}
-
-static net_nfc_error_e __net_nfc_get_list_from_serial_for_wifi(GList **list, uint8_t *data, uint32_t length)
-{
- uint8_t *current = data;
- uint8_t *last = current + length;
-
- while (current < last)
- {
- net_nfc_carrier_property_s *elem = NULL;
- _net_nfc_util_alloc_mem(elem, sizeof(net_nfc_carrier_property_s));
- if (elem == NULL)
- {
- return NET_NFC_ALLOC_FAIL;
- }
- elem->attribute = current[0]<<8|current[1];
- elem->length = current[2]<<8|current[3];
-
- if (elem->attribute == NET_NFC_WIFI_ATTRIBUTE_CREDENTIAL)
- {
- __net_nfc_get_list_from_serial_for_wifi(list, (current + 4), elem->length);
- elem->is_group = true;
- }
- else
- {
- _net_nfc_util_alloc_mem(elem->data, elem->length);
- if (elem->data == NULL)
- {
- _net_nfc_util_free_mem(elem);
- return NET_NFC_ALLOC_FAIL;
- }
- memcpy(elem->data, (current + 4), elem->length);
- elem->is_group = false;
- }
- *list = g_list_append(*list, elem);
- current += (4 + elem->length);
- }
-
- return NET_NFC_OK;
-}
-
-net_nfc_error_e __net_nfc_get_list_from_serial_for_bt(GList **list, uint8_t *data, uint32_t length)
-{
- net_nfc_carrier_property_s *elem = NULL;
- uint8_t *current = data;
- uint8_t *last = NULL;
-
- current += 2; /* remove oob data length two bytes length*/
- length -= 2;
-
- _net_nfc_util_alloc_mem(elem, sizeof(net_nfc_carrier_property_s));
- if (elem == NULL)
- {
- return NET_NFC_ALLOC_FAIL;
- }
- elem->attribute = (uint16_t)NET_NFC_BT_ATTRIBUTE_ADDRESS;
- elem->length = 6; /* BT address length is always 6 */
-
- _net_nfc_util_alloc_mem(elem->data, elem->length);
- if (elem->data == NULL)
- {
- _net_nfc_util_free_mem(elem);
- return NET_NFC_ALLOC_FAIL;
- }
- memcpy(elem->data, current, elem->length);
- elem->is_group = false;
-
- current += 6; /* BT address length is always 6 */
- length -= 6; /* substracted by 6 (Address length)*/
- *list = g_list_append(*list, elem);
-
- last = current + length;
-
- while (current < last)
- {
- _net_nfc_util_alloc_mem(elem, sizeof(net_nfc_carrier_property_s));
- if (elem == NULL)
- {
- return NET_NFC_ALLOC_FAIL;
- }
- elem->length = *((uint8_t *)current) - 1;
- elem->attribute = *((uint8_t *)(++current));
-
- _net_nfc_util_alloc_mem(elem->data, elem->length);
- if (elem->data == NULL)
- {
- _net_nfc_util_free_mem(elem);
- return NET_NFC_ALLOC_FAIL;
- }
- memcpy(elem->data, (++current), elem->length);
- elem->is_group = false;
-
- current += elem->length;
- *list = g_list_append(*list, elem);
- }
-
- return NET_NFC_OK;
-}
-
-net_nfc_error_e net_nfc_util_create_carrier_config_from_config_record(net_nfc_carrier_config_s **config, ndef_record_s *record)
-{
- net_nfc_error_e result = NET_NFC_OK;
- net_nfc_conn_handover_carrier_type_e type;
-
- if (record == NULL || config == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
-
- if (strncmp((char *)record->type_s.buffer, CONN_HANDOVER_WIFI_BSS_CARRIER_MIME_NAME, record->type_s.length) == 0)
- {
- type = NET_NFC_CONN_HANDOVER_CARRIER_WIFI_BSS;
- }
- else if (strncmp((char *)record->type_s.buffer, CONN_HANDOVER_WIFI_IBSS_CARRIER_MIME_NAME, record->type_s.length) == 0)
- {
- type = NET_NFC_CONN_HANDOVER_CARRIER_WIFI_IBSS;
- }
- else if (strncmp((char *)record->type_s.buffer, CONN_HANDOVER_BT_CARRIER_MIME_NAME, record->type_s.length) == 0)
- {
- type = NET_NFC_CONN_HANDOVER_CARRIER_BT;
- }
- else
- {
- DEBUG_MSG("Record type is not config type");
- return NET_NFC_INVALID_FORMAT;
- }
-
- result = net_nfc_util_create_carrier_config(config, type);
- if (*config == NULL)
- {
- return NET_NFC_ALLOC_FAIL;
- }
-
- switch ((*config)->type)
- {
- case NET_NFC_CONN_HANDOVER_CARRIER_WIFI_BSS :
- case NET_NFC_CONN_HANDOVER_CARRIER_WIFI_IBSS :
- result = __net_nfc_get_list_from_serial_for_wifi((GList **)&((*config)->data), record->payload_s.buffer, record->payload_s.length);
- break;
- case NET_NFC_CONN_HANDOVER_CARRIER_BT :
- result = __net_nfc_get_list_from_serial_for_bt((GList **)&((*config)->data), record->payload_s.buffer, record->payload_s.length);
- break;
- case NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN :
- result = NET_NFC_NOT_SUPPORTED;
- break;
- }
-
- if (result != NET_NFC_OK)
- {
- net_nfc_util_free_carrier_config((net_nfc_carrier_config_s *)*config);
- }
-
- return result;
-}
-
-net_nfc_error_e net_nfc_util_create_handover_request_message(ndef_message_s **message)
-{
- ndef_message_s *inner_message = NULL;
- net_nfc_error_e error;
- ndef_record_s *record = NULL;
- data_s type = { NULL, 0 };
- data_s payload = { NULL, 0 };
- int size = 0;
-
- if (message == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
-
- error = net_nfc_util_create_ndef_message(message);
- if (error != NET_NFC_OK)
- {
- return error;
- }
-
- error = net_nfc_util_create_ndef_message(&inner_message);
- if (error != NET_NFC_OK)
- {
- net_nfc_util_free_ndef_message(*message);
- *message = NULL;
-
- return error;
- }
-
- __net_nfc_util_create_connection_handover_collsion_resolution_record(&record);
- net_nfc_util_append_record(inner_message, record);
-
- size = net_nfc_util_get_ndef_message_length(inner_message) + 1;
- _net_nfc_util_alloc_mem(payload.buffer, size);
- if (payload.buffer == NULL)
- {
- net_nfc_util_free_ndef_message(inner_message);
- net_nfc_util_free_ndef_message(*message);
- *message = NULL;
-
- return NET_NFC_ALLOC_FAIL;
- }
- payload.length = size;
-
- uint8_t version = CH_VERSION;
-
- (payload.buffer)[0] = version;
- (payload.buffer)++;
- (payload.length)--;
-
- error = net_nfc_util_convert_ndef_message_to_rawdata(inner_message, &payload);
- if (error != NET_NFC_OK)
- {
- _net_nfc_util_free_mem(payload.buffer);
- net_nfc_util_free_ndef_message(inner_message);
- net_nfc_util_free_ndef_message(*message);
- *message = NULL;
-
- return error;
- }
-
- net_nfc_util_free_ndef_message(inner_message);
- (payload.buffer)--;
- (payload.length)++;
-
- type.buffer = (uint8_t *)CH_REQ_RECORD_TYPE;
- type.length = strlen(CH_REQ_RECORD_TYPE);
-
- net_nfc_util_create_record(NET_NFC_RECORD_WELL_KNOWN_TYPE, &type, NULL, &payload, &record);
- net_nfc_util_append_record(*message, record);
-
- _net_nfc_util_free_mem(payload.buffer);
-
- return NET_NFC_OK;
-}
-
-net_nfc_error_e net_nfc_util_create_handover_select_message(ndef_message_s **message)
-{
- net_nfc_error_e error = NET_NFC_OK;
- ndef_record_s *record = NULL;
- data_s type = { NULL, 0 };
- data_s payload = { NULL, 0 };
-
- if (message == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
-
- error = net_nfc_util_create_ndef_message(message);
- if (error != NET_NFC_OK)
- {
- return error;
- }
-
- _net_nfc_util_alloc_mem(payload.buffer, 1);
- if (payload.buffer == NULL)
- {
- net_nfc_util_free_ndef_message(*message);
- return NET_NFC_ALLOC_FAIL;
- }
- payload.length = (uint32_t)1;
-
- (payload.buffer)[0] = CH_VERSION;
-
- type.buffer = (uint8_t*)CH_SEL_RECORD_TYPE;
- type.length = strlen(CH_SEL_RECORD_TYPE);
-
- net_nfc_util_create_record(NET_NFC_RECORD_WELL_KNOWN_TYPE, &type, NULL, &payload, &record);
- net_nfc_util_append_record(*message, record);
-
- _net_nfc_util_free_mem(payload.buffer);
-
- return NET_NFC_OK;
-}
-
-net_nfc_error_e net_nfc_util_create_handover_error_record(ndef_record_s **record, uint8_t reason, uint32_t data)
-{
- data_s type;
- data_s payload;
- int size = 1;
-
- switch (reason)
- {
- case 0x01 :
- size += 1;
- break;
- case 0x02 :
- size += 4;
- break;
- case 0x03 :
- size += 1;
- break;
- }
-
- _net_nfc_util_alloc_mem(payload.buffer, size);
- if (payload.buffer == NULL)
- {
- return NET_NFC_ALLOC_FAIL;
- }
- payload.length = size;
-
- type.buffer = (uint8_t *)ERROR_RECORD_TYPE;
- type.length = strlen(ERROR_RECORD_TYPE);
-
- net_nfc_util_create_record(NET_NFC_RECORD_WELL_KNOWN_TYPE, &type, NULL, &payload, (ndef_record_s **)record);
-
- _net_nfc_util_free_mem(payload.buffer);
-
- return NET_NFC_OK;
-}
-
-/*
- inner_msg should be freed after using
- */
-
-static net_nfc_error_e __net_nfc_get_inner_message(ndef_message_s *message, ndef_message_s *inner_msg)
-{
- net_nfc_error_e error;
- ndef_record_s *inner_record = NULL;
-
- if (message == NULL || inner_msg == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
-
- inner_record = message->records;
- if (inner_record == NULL)
- {
- // This message is not connection handover message
- return NET_NFC_INVALID_FORMAT;
- }
-
- if (strncmp((char*)(inner_record->type_s.buffer), CH_REQ_RECORD_TYPE, (size_t)(inner_record->type_s.length)) != 0
- && strncmp((char*)(inner_record->type_s.buffer), CH_SEL_RECORD_TYPE, (size_t)(inner_record->type_s.length)) != 0)
- {
- // This message is not connection handover message
- return NET_NFC_INVALID_FORMAT;
- }
-
- if (inner_record->payload_s.length > 1)
- {
- /* There is Alternative Carrier Record or Collision Res. Rec. */
- (inner_record->payload_s.buffer)++; /* version */
- (inner_record->payload_s.length)--;
- error = net_nfc_util_convert_rawdata_to_ndef_message(&(inner_record->payload_s), inner_msg);
- (inner_record->payload_s.buffer)--;
- (inner_record->payload_s.length)++;
- }
- else
- {
- error = NET_NFC_NO_DATA_FOUND;
- }
-
- return error;
-}
-
-static net_nfc_error_e __net_nfc_replace_inner_message(ndef_message_s *message, ndef_message_s *inner_msg)
-{
- net_nfc_error_e error;
- ndef_record_s *inner_record = NULL;
-
- if (message == NULL || inner_msg == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
-
- inner_record = message->records;
- if (inner_record == NULL)
- {
- // This message is not connection handover message
- DEBUG_ERR_MSG("inner_record == NULL");
- return NET_NFC_INVALID_FORMAT;
- }
-
- if (strncmp((char *)(inner_record->type_s.buffer), CH_REQ_RECORD_TYPE, (size_t)(inner_record->type_s.length)) != 0
- && strncmp((char *)(inner_record->type_s.buffer), CH_SEL_RECORD_TYPE, (size_t)(inner_record->type_s.length)) != 0)
- {
- // This message is not connection handover message
- DEBUG_ERR_MSG("unknown type [%s]", inner_record->type_s.buffer);
- return NET_NFC_INVALID_FORMAT;
- }
-
- if (inner_record->payload_s.length >= 1)
- {
- /* There is Alternative Carrier Record or Collision Res. Rec. */
- data_s tdata = { NULL, 0 };
- int inner_length;
-
- inner_length = net_nfc_util_get_ndef_message_length(inner_msg);
-
- _net_nfc_util_alloc_mem(tdata.buffer, inner_length + 1);
- if (tdata.buffer == NULL)
- {
- return NET_NFC_ALLOC_FAIL;
- }
-
- (tdata.buffer)++;
- tdata.length = inner_length;
- error = net_nfc_util_convert_ndef_message_to_rawdata(inner_msg, &tdata);
- if (error == NET_NFC_OK)
- {
- (tdata.buffer)--;
- (tdata.length)++;
- (tdata.buffer)[0] = (inner_record->payload_s.buffer)[0];
- _net_nfc_util_free_mem(inner_record->payload_s.buffer);
- inner_record->payload_s.buffer = tdata.buffer;
- inner_record->payload_s.length = tdata.length;
- }
- else
- {
- DEBUG_ERR_MSG("net_nfc_util_convert_ndef_message_to_rawdata failed [%d]", error);
- _net_nfc_util_free_mem(tdata.buffer);
- }
- }
- else
- {
- DEBUG_ERR_MSG("inner_record->payload_s.length(%d) < 1 ", inner_record->payload_s.length);
- error = NET_NFC_INVALID_FORMAT;
- }
-
- return error;
-}
-
-net_nfc_error_e net_nfc_util_append_carrier_config_record(ndef_message_s *message, ndef_record_s *record, net_nfc_conn_handover_carrier_state_e power_status)
-{
- ndef_message_s *inner_msg = NULL;
- ndef_record_s *carrier_rec = NULL;
- data_s payload = { NULL, 0 };
- data_s type = { NULL, 0 };
- int config_ref_count = 0;
- net_nfc_error_e error;
- uint8_t buffer[256] = { 0, };
-#if 0
- int i;
-#endif
- int offset;
- uint8_t id;
-
- if (message == NULL || record == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
-
- if ((error = net_nfc_util_create_ndef_message(&inner_msg)) != NET_NFC_OK)
- {
- DEBUG_ERR_MSG("net_nfc_util_create_ndef_message failed [%d]", error);
-
- return error;
- }
-
- if ((error = __net_nfc_get_inner_message(message, inner_msg)) == NET_NFC_OK)
- {
- int idx = 1;
- ndef_record_s *last_rec = inner_msg->records;
-
- for (; idx < inner_msg->recordCount; idx++)
- {
- last_rec = last_rec->next;
- }
-
- if (strncmp((char *)last_rec->type_s.buffer, COLLISION_DETECT_RECORD_TYPE, (size_t)last_rec->type_s.length) == 0)
- {
- config_ref_count = 0;
- }
- else if (strncmp((char *)last_rec->type_s.buffer, ALTERNATIVE_RECORD_TYPE, (size_t)last_rec->type_s.length) == 0)
- {
- memcpy(buffer, last_rec->payload_s.buffer, last_rec->payload_s.length);
- config_ref_count = last_rec->payload_s.buffer[1];
- }
- }
- else
- {
- /* selector record type can include empty inner message. so that case, we will continue */
- if (message->records != NULL &&
- memcmp((char *)message->records->type_s.buffer, CH_SEL_RECORD_TYPE, (size_t)message->records->type_s.length) != 0)
- {
- DEBUG_ERR_MSG("ERROR [%d]", error);
-
- net_nfc_util_free_ndef_message(inner_msg);
-
- return error;
- }
- }
-
- type.buffer = (uint8_t *)ALTERNATIVE_RECORD_TYPE;
- type.length = strlen(ALTERNATIVE_RECORD_TYPE);
-
- config_ref_count++;
- offset = 0;
-// id = '0' + config_ref_count;
- id = 'b';
-
- /* carrier flag */
- buffer[offset++] = (uint8_t)(power_status & 0x3); /* first byte, power status */
-
- /* carrier data ref. len */
- buffer[offset++] = config_ref_count;
-
- /* carrier data ref. */
- offset += (config_ref_count - 1);
- buffer[offset++] = id;
-
- /* FIXME */
- /* aux data ref. len */
- buffer[offset++] = 0;
-#if 0 /* FIXME */
- /* carrier data ref. */
- for (i = 0; i < 0; i++)
- {
- buffer[offset++] = 0;
- }
-#endif
- payload.buffer = buffer;
- payload.length = offset;
-
- error = net_nfc_util_create_record(NET_NFC_RECORD_WELL_KNOWN_TYPE, &type, NULL, &payload, &carrier_rec);
- if (error != NET_NFC_OK)
- {
- DEBUG_ERR_MSG("net_nfc_util_create_record failed [%d]", error);
-
- net_nfc_util_free_ndef_message(inner_msg);
-
- return error;
- }
-
- error = net_nfc_util_append_record(inner_msg, carrier_rec);
- if (error != NET_NFC_OK)
- {
- DEBUG_ERR_MSG("net_nfc_util_create_record failed [%d]", error);
-
- net_nfc_util_free_record(carrier_rec);
- net_nfc_util_free_ndef_message(inner_msg);
-
- return error;
- }
-
- error = __net_nfc_replace_inner_message(message, inner_msg);
- net_nfc_util_free_ndef_message(inner_msg);
- if (error != NET_NFC_OK)
- {
- DEBUG_ERR_MSG("__net_nfc_replace_inner_message failed [%d]", error);
-
- return error;
- }
-
- /* set record id to record that will be appended to ndef message */
- error = net_nfc_util_set_record_id((ndef_record_s *)record, &id, sizeof(id));
- if (error != NET_NFC_OK)
- {
- DEBUG_ERR_MSG("net_nfc_util_set_record_id failed [%d]", error);
-
- return error;
- }
-
- error = net_nfc_util_append_record(message, (ndef_record_s *)record);
- if (error != NET_NFC_OK)
- {
- DEBUG_ERR_MSG("net_nfc_util_append_record failed [%d]", error);
-
- return error;
- }
-
- return NET_NFC_OK;
-}
-
-net_nfc_error_e net_nfc_util_remove_carrier_config_record(ndef_message_s *message, ndef_record_s *record)
-{
- ndef_message_s *inner_msg = NULL;
- int idx = 0;
- int saved_idx = 0;
- net_nfc_error_e error;
- ndef_record_s *current = NULL;
- ndef_record_s *record_priv = (ndef_record_s *)record;
-
- if (message == NULL || record == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
-
- current = message->records;
-
- for (idx = 0; idx < message->recordCount; idx++)
- {
- if (current == record)
- {
- break;
- }
- current = current->next;
- }
-
- if (current == NULL || idx == message->recordCount)
- {
- DEBUG_MSG("The reference is not found in config records");
-
- return NET_NFC_NO_DATA_FOUND;
- }
- saved_idx = idx;
-
- if ((error = net_nfc_util_create_ndef_message(&inner_msg)) != NET_NFC_OK)
- {
- DEBUG_MSG("net_nfc_util_create_ndef_message failed [%d]", error);
-
- return error;
- }
-
- if ((error = __net_nfc_get_inner_message(message, inner_msg)) == NET_NFC_OK)
- {
- current = inner_msg->records;
-
- for (idx = 0; idx < inner_msg->recordCount; idx++, current = current->next)
- {
- if (strncmp((char *)current->type_s.buffer, ALTERNATIVE_RECORD_TYPE, (size_t)current->type_s.length) == 0)
- {
- if ((uint32_t)(current->payload_s.buffer[1]) == record_priv->id_s.length &&
- strncmp((char *)(current->payload_s.buffer + 2), (char*)(record_priv->id_s.buffer), (size_t)current->payload_s.buffer[1]) == 0)
- {
- // comparing the instance
- break;
- }
- }
- }
-
- if (current == NULL || idx == message->recordCount)
- {
- DEBUG_MSG("The reference is not found in inner message");
-
- error = NET_NFC_NO_DATA_FOUND;
- }
- else
- {
- net_nfc_util_remove_record_by_index(inner_msg, idx);
- __net_nfc_replace_inner_message(message, inner_msg);
-
- // remove the record only if the inner record is found.
- net_nfc_util_remove_record_by_index(message, saved_idx);
- }
- }
-
- net_nfc_util_free_ndef_message(inner_msg);
-
- return error;
-}
-
-net_nfc_error_e net_nfc_util_get_carrier_config_record(ndef_message_s *message, int index, ndef_record_s** record)
-{
- ndef_message_s *inner_msg = NULL;
- data_s id;
- net_nfc_error_e error;
- ndef_record_s *current = NULL;
- int idx = 0;
- int current_idx = 0;
-
- if (message == NULL || record == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
-
- if ((error = net_nfc_util_create_ndef_message(&inner_msg)) != NET_NFC_OK)
- {
- DEBUG_MSG("net_nfc_util_create_ndef_message failed [%d]", error);
-
- return error;
- }
-
- if ((error = __net_nfc_get_inner_message(message, inner_msg)) == NET_NFC_OK)
- {
- current = inner_msg->records;
- for (idx = 0; idx < inner_msg->recordCount; idx++)
- {
- if (strncmp((char*)current->type_s.buffer, ALTERNATIVE_RECORD_TYPE, (size_t)current->type_s.length) == 0)
- {
- if (current_idx == index)
- break;
- current_idx++;
- }
- current = current->next;
- }
-
- if (current == NULL || idx == message->recordCount)
- {
- DEBUG_MSG("The reference is not found in inner message");
-
- error = NET_NFC_NO_DATA_FOUND;
- }
- else
- {
- id.buffer = (current->payload_s.buffer) + 2;
- id.length = current->payload_s.buffer[1];
-
- error = net_nfc_util_search_record_by_id(message, &id, record);
- }
- }
-
- net_nfc_util_free_ndef_message(inner_msg);
-
- return error;
-}
-
-net_nfc_error_e net_nfc_util_get_handover_random_number(ndef_message_s *message, unsigned short *random_number)
-{
- net_nfc_error_e error;
- ndef_message_s *inner_msg = NULL;
- ndef_record_s *cr_record = NULL;
-
- if (message == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
-
- if ((error = net_nfc_util_create_ndef_message(&inner_msg)) != NET_NFC_OK)
- {
- DEBUG_MSG("net_nfc_util_create_ndef_message failed [%d]", error);
-
- return error;
- }
-
- if ((error = __net_nfc_get_inner_message(message, inner_msg)) == NET_NFC_OK)
- {
- cr_record = inner_msg->records;
- if (strncmp((char*)cr_record->type_s.buffer, COLLISION_DETECT_RECORD_TYPE, (size_t)cr_record->type_s.length) != 0
- || cr_record->payload_s.length < 2)
- {
- DEBUG_MSG("There is no Collision resolution record");
-
- error = NET_NFC_INVALID_FORMAT;
- }
- else
- {
- *random_number = ((unsigned short)cr_record->payload_s.buffer[0] << 8) | (unsigned short)(cr_record->payload_s.buffer[1]);
- }
- }
-
- net_nfc_util_free_ndef_message(inner_msg);
-
- return error;
-}
-
-net_nfc_error_e net_nfc_util_get_alternative_carrier_record_count(ndef_message_s *message, unsigned int *count)
-{
- net_nfc_error_e error;
- ndef_message_s *inner_msg = NULL;
- ndef_record_s *current = NULL;
- int idx;
-
- if (message == NULL || count == 0)
- {
- return NET_NFC_NULL_PARAMETER;
- }
-
- if ((error = net_nfc_util_create_ndef_message(&inner_msg)) != NET_NFC_OK)
- {
- DEBUG_MSG("net_nfc_util_create_ndef_message failed [%d]", error);
-
- return error;
- }
-
- *count = 0;
-
- if ((error = __net_nfc_get_inner_message(message, inner_msg)) == NET_NFC_OK)
- {
- current = inner_msg->records;
- for (idx = 0; idx < inner_msg->recordCount; idx++)
- {
- if (strncmp((char *)current->type_s.buffer, ALTERNATIVE_RECORD_TYPE, (size_t)current->type_s.length) == 0)
- {
- (*count)++;
- }
- current = current->next;
- }
- }
-
- net_nfc_util_free_ndef_message(inner_msg);
-
- return error;
-}
-
-net_nfc_error_e net_nfc_util_get_alternative_carrier_power_status(ndef_message_s *message, int index, net_nfc_conn_handover_carrier_state_e *power_state)
-{
- net_nfc_error_e error;
- ndef_message_s *inner_msg = NULL;
- ndef_record_s *current = NULL;
- int idx;
- int idx_count = 0;
-
- if (message == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
-
- if (index < 0)
- {
- return NET_NFC_OUT_OF_BOUND;
- }
-
- if ((error = net_nfc_util_create_ndef_message(&inner_msg)) != NET_NFC_OK)
- {
- DEBUG_MSG("net_nfc_util_create_ndef_message failed [%d]", error);
-
- return error;
- }
-
- if ((error = __net_nfc_get_inner_message(message, inner_msg)) == NET_NFC_OK)
- {
- error = NET_NFC_OUT_OF_BOUND;
- current = inner_msg->records;
- for (idx = 0; idx < inner_msg->recordCount; idx++)
- {
- if (strncmp((char *)current->type_s.buffer, ALTERNATIVE_RECORD_TYPE, (size_t)current->type_s.length) == 0)
- {
- if (idx_count == index)
- {
- *power_state = current->payload_s.buffer[0] & 0x3;
- error = NET_NFC_OK;
- break;
- }
- idx_count++;
- }
- current = current->next;
- }
- }
-
- net_nfc_util_free_ndef_message(inner_msg);
-
- return error;
-}
-
-net_nfc_error_e net_nfc_util_set_alternative_carrier_power_status(ndef_message_s *message, int index, net_nfc_conn_handover_carrier_state_e power_status)
-{
- net_nfc_error_e error;
- ndef_message_s *inner_msg = NULL;
-
- if (message == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
- if (index < 0)
- {
- return NET_NFC_OUT_OF_BOUND;
- }
-
- if ((error = net_nfc_util_create_ndef_message(&inner_msg)) != NET_NFC_OK)
- {
- DEBUG_MSG("net_nfc_util_create_ndef_message failed [%d]", error);
-
- return error;
- }
-
- if ((error = __net_nfc_get_inner_message(message, inner_msg)) == NET_NFC_OK)
- {
- int idx;
- int idx_count = 0;
- ndef_record_s *current = inner_msg->records;
-
- error = NET_NFC_OUT_OF_BOUND;
- for (idx = 0; idx < inner_msg->recordCount; idx++, current = current->next)
- {
- if (strncmp((char *)current->type_s.buffer, ALTERNATIVE_RECORD_TYPE, (size_t)current->type_s.length) == 0)
- {
- if (idx_count == index)
- {
- current->payload_s.buffer[0] = (power_status & 0x3) | (current->payload_s.buffer[0] & 0xFC);
-
- __net_nfc_replace_inner_message(message, inner_msg);
- error = NET_NFC_OK;
- break;
- }
- idx_count++;
- }
- }
- }
-
- net_nfc_util_free_ndef_message(inner_msg);
-
- return error;
-}
-
-net_nfc_error_e net_nfc_util_get_alternative_carrier_type_from_record(ndef_record_s *record, net_nfc_conn_handover_carrier_type_e *type)
-{
- if (strncmp((char *)record->type_s.buffer, CONN_HANDOVER_BT_CARRIER_MIME_NAME, (size_t)record->type_s.length) == 0)
- {
- *type = NET_NFC_CONN_HANDOVER_CARRIER_BT;
- }
- else if (strncmp((char *)record->type_s.buffer, CONN_HANDOVER_WIFI_BSS_CARRIER_MIME_NAME, (size_t)record->type_s.length) == 0)
- {
- *type = NET_NFC_CONN_HANDOVER_CARRIER_WIFI_BSS;
- }
- else if (strncmp((char *)record->type_s.buffer, CONN_HANDOVER_WIFI_IBSS_CARRIER_MIME_NAME, (size_t)record->type_s.length) == 0)
- {
- *type = NET_NFC_CONN_HANDOVER_CARRIER_WIFI_IBSS;
- }
- else
- {
- *type = NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN;
- }
-
- return NET_NFC_OK;
-}
-
-net_nfc_error_e net_nfc_util_get_alternative_carrier_type(ndef_message_s *message, int index, net_nfc_conn_handover_carrier_type_e *type)
-{
- ndef_record_s *record = NULL;
- net_nfc_error_e error;
-
- error = net_nfc_util_get_carrier_config_record(message, index, (ndef_record_s **)&record);
- if (error != NET_NFC_OK)
- {
- return error;
- }
-
- return net_nfc_util_get_alternative_carrier_type_from_record(record, type);
-}
-
-net_nfc_error_e net_nfc_util_get_selector_power_status(ndef_message_s *message, net_nfc_conn_handover_carrier_state_e *power_state)
-{
- net_nfc_error_e error;
- ndef_message_s *inner_msg = NULL;
- ndef_record_s *current = NULL;
- int idx;
- net_nfc_conn_handover_carrier_state_e selector_state = NET_NFC_CONN_HANDOVER_CARRIER_INACTIVATE;
-
- if (message == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
-
- if ((error = net_nfc_util_create_ndef_message(&inner_msg)) == NET_NFC_OK)
- {
- if ((error = __net_nfc_get_inner_message(message, inner_msg)) == NET_NFC_OK)
- {
- if (inner_msg->recordCount > 1)
- {
- current = inner_msg->records;
- for (idx = 0; idx < inner_msg->recordCount; idx++)
- {
- if (strncmp((char *)current->type_s.buffer, ALTERNATIVE_RECORD_TYPE, (size_t)current->type_s.length) == 0)
- {
- if (((current->payload_s.buffer[0] & 0x3) == NET_NFC_CONN_HANDOVER_CARRIER_ACTIVATE) || ((current->payload_s.buffer[0] & 0x3) == NET_NFC_CONN_HANDOVER_CARRIER_ACTIVATING))
- {
- selector_state = NET_NFC_CONN_HANDOVER_CARRIER_ACTIVATE;
- break;
- }
- }
- current = current->next;
- }
- }
- else
- {
- /* always activate when ac is only one */
- selector_state = NET_NFC_CONN_HANDOVER_CARRIER_ACTIVATE;
- }
-
- *power_state = selector_state;
- }
- else
- {
- DEBUG_ERR_MSG("_net_nfc_util_create_ndef_message failed [%d]", error);
- }
-
- net_nfc_util_free_ndef_message(inner_msg);
- }
- else
- {
- DEBUG_ERR_MSG("_net_nfc_util_create_ndef_message failed [%d]", error);
- error = NET_NFC_ALLOC_FAIL;
- }
-
- return error;
-}
-
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <stddef.h>
-#include <stdint.h>
-#include <stdbool.h>
-#include <stdarg.h>
-#include <string.h>
-#include <fcntl.h>
-
-#include "net_nfc_debug_internal.h"
-
-int net_nfc_util_get_va_list_length(va_list list)
-{
- int length = 0;
-
- while (va_arg(list, void *) != 0)
- {
- length += (sizeof(int) + va_arg(list, int));
- }
-
- return length;
-}
-
-int net_nfc_util_fill_va_list(uint8_t *buffer, int length, va_list list)
-{
- uint8_t *data = NULL;
- int len = 0;
- int current = 0;
-
- while (current < length && (data = va_arg(list, void *)) != NULL)
- {
- if ((len = va_arg(list, int)) > 0)
- {
- memcpy(buffer + current, &len, sizeof(len));
- current += sizeof(len);
-
- memcpy(buffer + current, data, len);
- current += len;
- }
- }
-
- return current;
-}
-
-void net_nfc_util_set_non_block_socket(int socket)
-{
- DEBUG_SERVER_MSG("set non block socket");
-
- int flags = fcntl(socket, F_GETFL);
- flags |= O_NONBLOCK;
-
- if (fcntl(socket, F_SETFL, flags) < 0)
- {
- DEBUG_ERR_MSG("fcntl, executing nonblock error");
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
-
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-#include "net_nfc_debug_internal.h"
-#include "net_nfc_util_defines.h"
-#include "net_nfc_util_internal.h"
-#include "net_nfc_util_ndef_message.h"
-#include "net_nfc_util_ndef_record.h"
-
-static net_nfc_error_e __net_nfc_repair_record_flags(ndef_message_s *ndef_message);
-
-net_nfc_error_e net_nfc_util_convert_rawdata_to_ndef_message(data_s *rawdata, ndef_message_s *ndef)
-{
- ndef_record_s *newRec = NULL;
- ndef_record_s *prevRec = NULL;
- uint8_t *current = NULL;
- uint8_t *last = NULL;
- uint8_t ndef_header = 0;
- net_nfc_error_e result = NET_NFC_OK;
-
- if (rawdata == NULL || ndef == NULL)
- return NET_NFC_NULL_PARAMETER;
-
- current = rawdata->buffer;
- last = current + rawdata->length;
-
- if(rawdata->length < 3)
- return NET_NFC_INVALID_FORMAT;
-
- for(ndef->recordCount = 0; current < last; ndef->recordCount++)
- {
- ndef_header = *current++;
-
- if(ndef->recordCount == 0)
- {
- /* first record has MB field */
- if((ndef_header & NET_NFC_NDEF_RECORD_MASK_MB) == 0)
- return NET_NFC_INVALID_FORMAT;
-
- /* first record should not be a chunked record */
- if((ndef_header & NET_NFC_NDEF_RECORD_MASK_TNF) == NET_NFC_NDEF_TNF_UNCHANGED)
- return NET_NFC_INVALID_FORMAT;
- }
-
- _net_nfc_util_alloc_mem(newRec, sizeof(ndef_record_s));
- if (newRec == NULL)
- {
- result = NET_NFC_ALLOC_FAIL;
- goto error;
- }
-
- /* ndef header set */
- if (ndef_header & NET_NFC_NDEF_RECORD_MASK_MB)
- {
- newRec->MB = 1;
- }
- if (ndef_header & NET_NFC_NDEF_RECORD_MASK_ME)
- {
- newRec->ME = 1;
- }
- if (ndef_header & NET_NFC_NDEF_RECORD_MASK_CF)
- {
- newRec->CF = 1;
- }
- if (ndef_header & NET_NFC_NDEF_RECORD_MASK_SR)
- {
- newRec->SR = 1;
- }
- if (ndef_header & NET_NFC_NDEF_RECORD_MASK_IL)
- {
- newRec->IL = 1;
- }
-
- newRec->TNF = ndef_header & NET_NFC_NDEF_RECORD_MASK_TNF;
-
- newRec->type_s.length = *current++;
-
- /* SR = 1 -> payload is 1 byte, SR = 0 -> payload is 4 bytes */
- if(ndef_header & NET_NFC_NDEF_RECORD_MASK_SR)
- {
- newRec->payload_s.length = *current++;
- }
- else
- {
- newRec->payload_s.length = (uint32_t)((*current) << 24);
- current++;
-
- newRec->payload_s.length += (uint32_t)((*current) << 16);
- current++;
-
- newRec->payload_s.length += (uint32_t)((*current) << 8);
- current++;
-
- newRec->payload_s.length += (uint32_t)((*current));
- current++;
- }
-
- /* ID length check */
- if(ndef_header & NET_NFC_NDEF_RECORD_MASK_IL)
- {
- newRec->id_s.length = *current++;
- }
- else
- {
- newRec->id_s.length = 0;
- }
-
- /* to do : chunked record */
-
-
- /* empty record check */
- if((ndef_header & NET_NFC_NDEF_RECORD_MASK_TNF) == NET_NFC_NDEF_TNF_EMPTY)
- {
- if(newRec->type_s.length != 0 || newRec->id_s.length != 0 || newRec->payload_s.length != 0)
- {
- result = NET_NFC_INVALID_FORMAT;
- goto error;
- }
- }
-
- if((ndef_header & NET_NFC_NDEF_RECORD_MASK_TNF) == NET_NFC_NDEF_TNF_UNKNOWN)
- {
- if(newRec->type_s.length != 0)
- {
- result = NET_NFC_INVALID_FORMAT;
- goto error;
- }
- }
-
- /* put Type buffer */
- if(newRec->type_s.length > 0)
- {
- _net_nfc_util_alloc_mem(newRec->type_s.buffer, newRec->type_s.length);
- if (newRec->type_s.buffer == NULL)
- {
- result = NET_NFC_ALLOC_FAIL;
- goto error;
- }
-
- memcpy(newRec->type_s.buffer, current, newRec->type_s.length);
- current += newRec->type_s.length;
- }
- else
- {
- newRec->type_s.buffer = NULL;
- }
-
- /* put ID buffer */
- if(newRec->id_s.length > 0)
- {
- _net_nfc_util_alloc_mem(newRec->id_s.buffer, newRec->id_s.length);
- if (newRec->id_s.buffer == NULL)
- {
- result = NET_NFC_ALLOC_FAIL;
- goto error;
- }
-
- memcpy(newRec->id_s.buffer, current, newRec->id_s.length);
- current += newRec->id_s.length;
- }
- else
- {
- newRec->id_s.buffer = NULL;
- }
-
- /* put Payload buffer */
- if(newRec->payload_s.length > 0)
- {
- _net_nfc_util_alloc_mem(newRec->payload_s.buffer, newRec->payload_s.length);
- if (newRec->payload_s.buffer == NULL)
- {
- result = NET_NFC_ALLOC_FAIL;
- goto error;
- }
-
- memcpy(newRec->payload_s.buffer, current, newRec->payload_s.length);
- current += newRec->payload_s.length;
- }
- else
- {
- newRec->payload_s.buffer = NULL;
- }
-
- if (ndef->recordCount == 0)
- ndef->records = newRec;
- else
- prevRec->next = newRec;
-
- prevRec = newRec;
- newRec = NULL;
-
- if(ndef_header & NET_NFC_NDEF_RECORD_MASK_ME)
- {
- break;
- }
- }
-
- ndef->recordCount++;
-
- if((current != last) || ((ndef_header & NET_NFC_NDEF_RECORD_MASK_ME) == 0))
- {
- result = NET_NFC_INVALID_FORMAT;
- goto error;
- }
-
- return NET_NFC_OK;
-
-error:
-
- DEBUG_ERR_MSG("parser error");
-
- if (newRec)
- {
- _net_nfc_util_free_mem(newRec->type_s.buffer);
- _net_nfc_util_free_mem(newRec->id_s.buffer);
- _net_nfc_util_free_mem(newRec->payload_s.buffer);
- _net_nfc_util_free_mem(newRec);
- }
-
- prevRec = ndef->records;
-
- while(prevRec)
- {
- ndef_record_s *tmpRec = NULL;
-
- _net_nfc_util_free_mem(prevRec->type_s.buffer);
- _net_nfc_util_free_mem(prevRec->id_s.buffer);
- _net_nfc_util_free_mem(prevRec->payload_s.buffer);
-
- tmpRec = prevRec->next;
- _net_nfc_util_free_mem(prevRec);
- prevRec = tmpRec;
- }
-
- ndef->records = NULL;
-
- return result;
-}
-
-net_nfc_error_e net_nfc_util_convert_ndef_message_to_rawdata(ndef_message_s *ndef, data_s *rawdata)
-{
- ndef_record_s *record = NULL;
- uint8_t *current = NULL;
- uint8_t ndef_header;
-
- if (rawdata == NULL || ndef == NULL)
- return NET_NFC_NULL_PARAMETER;
-
- record = ndef->records;
- current = rawdata->buffer;
-
- while(record)
- {
- ndef_header = 0x00;
-
- if(record->MB)
- ndef_header |= NET_NFC_NDEF_RECORD_MASK_MB;
- if(record->ME)
- ndef_header |= NET_NFC_NDEF_RECORD_MASK_ME;
- if(record->CF)
- ndef_header |= NET_NFC_NDEF_RECORD_MASK_CF;
- if(record->SR)
- ndef_header |= NET_NFC_NDEF_RECORD_MASK_SR;
- if(record->IL)
- ndef_header |= NET_NFC_NDEF_RECORD_MASK_IL;
-
- ndef_header |= record->TNF;
-
- *current++ = ndef_header;
-
- /* check empty record */
- if(record->TNF == NET_NFC_NDEF_TNF_EMPTY)
- {
- /* set type length to zero */
- *current++ = 0x00;
-
- /* set payload length to zero */
- *current++ = 0x00;
-
- /* set ID length to zero */
- if(record->IL)
- {
- *current++ = 0x00;
- }
-
- record = record->next;
-
- continue;
- }
-
- /* set type length */
- if(record->TNF == NET_NFC_NDEF_TNF_UNKNOWN || record->TNF == NET_NFC_NDEF_TNF_UNCHANGED)
- {
- *current++ = 0x00;
- }
- else
- {
- *current++ = record->type_s.length;
- }
-
- /* set payload length */
- if(record->SR)
- {
- *current++ = (uint8_t)(record->payload_s.length & 0x000000FF);
- }
- else
- {
- *current++ = (uint8_t)((record->payload_s.length & 0xFF000000) >> 24);
- *current++ = (uint8_t)((record->payload_s.length & 0x00FF0000) >> 16);
- *current++ = (uint8_t)((record->payload_s.length & 0x0000FF00) >> 8);
- *current++ = (uint8_t)(record->payload_s.length & 0x000000FF) ;
- }
-
- /* set ID length */
- if(record->IL)
- {
- *current++ = record->id_s.length;
- }
-
- /* set type buffer */
- if((record->TNF != NET_NFC_NDEF_TNF_UNKNOWN) && (record->TNF != NET_NFC_NDEF_TNF_UNCHANGED))
- {
- memcpy(current, record->type_s.buffer, record->type_s.length);
- current += record->type_s.length;
- }
-
- /* set ID buffer */
- memcpy(current, record->id_s.buffer, record->id_s.length);
- current += record->id_s.length;
-
- /* set payload buffer */
- memcpy(current, record->payload_s.buffer, record->payload_s.length);
- current += record->payload_s.length;
-
- record = record->next;
- }
-
- return NET_NFC_OK;
-}
-
-net_nfc_error_e net_nfc_util_append_record(ndef_message_s *msg, ndef_record_s *record)
-{
- if (msg == NULL || record == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
-
- if (msg->recordCount == 0)
- {
- // set short message and append
- record->MB = 1;
- record->ME = 1;
- record->next = NULL;
-
- msg->records = record;
-
- msg->recordCount++;
-
- DEBUG_MSG("record is added to NDEF message :: count [%d]", msg->recordCount);
- }
- else
- {
- ndef_record_s *current = NULL;
- ndef_record_s *prev = NULL;
-
- // set flag :: this record is FIRST
- current = msg->records;
-
- if (current != NULL)
- {
- // first node
- current->MB = 1;
- current->ME = 0;
-
- prev = current;
-
- // second node
- current = current->next;
-
- while (current != NULL)
- {
- current->MB = 0;
- current->ME = 0;
- prev = current;
- current = current->next;
- }
-
- // set flag :: this record is END
- record->MB = 0;
- record->ME = 1;
-
- prev->next = record;
- msg->recordCount++;
- }
-
- }
-
- return NET_NFC_OK;
-}
-
-uint32_t net_nfc_util_get_ndef_message_length(ndef_message_s *message)
-{
- ndef_record_s *current;
- int total = 0;
-
- if (message == NULL)
- return 0;
-
- current = message->records;
-
- while (current != NULL)
- {
- total += net_nfc_util_get_record_length(current);
- current = current->next;
- }
-
- return total;
-}
-
-void net_nfc_util_print_ndef_message(ndef_message_s *msg)
-{
- int idx = 0, idx2 = 0;
- ndef_record_s *current = NULL;
- char buffer[1024];
-
- if (msg == NULL)
- {
- return;
- }
-
- // 123456789012345678901234567890123456789012345678901234567890
- DEBUG_MSG("========== NDEF Message ====================================\n");
- DEBUG_MSG("Total NDEF Records count: %d\n", msg->recordCount);
- current = msg->records;
- for (idx = 0; idx < msg->recordCount; idx++)
- {
- if (current == NULL)
- {
- DEBUG_ERR_MSG("Message Record is NULL!! unexpected error");
- DEBUG_MSG("============================================================\n");
- return;
- }
- DEBUG_MSG("---------- Record -----------------------------------------\n");
- DEBUG_MSG("MB:%d ME:%d CF:%d SR:%d IL:%d TNF:0x%02X\n",
- current->MB, current->ME, current->CF, current->SR, current->IL, current->TNF);
- DEBUG_MSG("TypeLength:%d PayloadLength:%d IDLength:%d\n",
- current->type_s.length, current->payload_s.length, current->id_s.length);
- if (current->type_s.buffer != NULL)
- {
- memcpy(buffer, current->type_s.buffer, current->type_s.length);
- buffer[current->type_s.length] = '\0';
- DEBUG_MSG("Type: %s\n", buffer);
- }
- if (current->id_s.buffer != NULL)
- {
- memcpy(buffer, current->id_s.buffer, current->id_s.length);
- buffer[current->id_s.length] = '\0';
- SECURE_LOGD("ID: %s\n", buffer);
- }
- if (current->payload_s.buffer != NULL)
- {
- DEBUG_MSG("Payload: ");
- for (idx2 = 0; idx2 < current->payload_s.length; idx2++)
- {
- if (idx2 % 16 == 0)
- DEBUG_MSG("\n\t");
- DEBUG_MSG("%02X ", current->payload_s.buffer[idx2]);
- }
- DEBUG_MSG("\n");
- }
- current = current->next;
- }
- // 123456789012345678901234567890123456789012345678901234567890
- DEBUG_MSG("============================================================\n");
-
-}
-
-net_nfc_error_e net_nfc_util_free_ndef_message(ndef_message_s *msg)
-{
- int idx = 0;
- ndef_record_s *prev, *current;
-
- if (msg == NULL)
- return NET_NFC_NULL_PARAMETER;
-
- current = msg->records;
-
- for (idx = 0; idx < msg->recordCount; idx++)
- {
- if (current == NULL)
- break;
-
- prev = current;
- current = current->next;
-
- net_nfc_util_free_record(prev);
- }
-
- _net_nfc_util_free_mem(msg);
-
- return NET_NFC_OK;
-}
-
-net_nfc_error_e net_nfc_util_create_ndef_message(ndef_message_s **ndef_message)
-{
- if (ndef_message == NULL) {
- return NET_NFC_NULL_PARAMETER;
- }
-
- _net_nfc_util_alloc_mem(*ndef_message, sizeof(ndef_message_s));
- if (*ndef_message == NULL) {
- return NET_NFC_ALLOC_FAIL;
- }
-
- return NET_NFC_OK;
-}
-
-net_nfc_error_e net_nfc_util_remove_record_by_index(ndef_message_s *ndef_message, int index)
-{
- int current_idx = 0;
- ndef_record_s *prev;
- ndef_record_s *next;
- ndef_record_s *current;
-
- if (ndef_message == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
-
- if (index < 0 || index >= ndef_message->recordCount)
- {
- return NET_NFC_OUT_OF_BOUND;
- }
-
- if (index == 0)
- {
- current = ndef_message->records;
- next = ndef_message->records->next;
- ndef_message->records = next;
- }
- else
- {
- prev = ndef_message->records;
- for (; current_idx < index - 1; current_idx++)
- {
- prev = prev->next;
- if (prev == NULL)
- {
- return NET_NFC_INVALID_FORMAT;
- }
- }
- current = prev->next;
- if (current == NULL)
- {
- return NET_NFC_INVALID_FORMAT;
- }
- next = current->next;
- prev->next = next;
- }
-
- net_nfc_util_free_record(current);
- (ndef_message->recordCount)--;
-
- return __net_nfc_repair_record_flags(ndef_message);
-}
-
-net_nfc_error_e net_nfc_util_get_record_by_index(ndef_message_s *ndef_message, int index, ndef_record_s **record)
-{
- ndef_record_s *current;
- int idx = 0;
-
- if (ndef_message == NULL || record == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
-
- if (index < 0 || index >= ndef_message->recordCount)
- {
- return NET_NFC_OUT_OF_BOUND;
- }
-
- current = ndef_message->records;
-
- for (; current != NULL && idx < index; idx++)
- {
- current = current->next;
- }
-
- *record = current;
-
- return NET_NFC_OK;
-}
-
-net_nfc_error_e net_nfc_util_append_record_by_index(ndef_message_s *ndef_message, int index, ndef_record_s *record)
-{
- int idx = 0;
- ndef_record_s *prev;
- ndef_record_s *next;
-
- if (ndef_message == NULL || record == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
-
- if (index < 0 || index > ndef_message->recordCount)
- {
- return NET_NFC_OUT_OF_BOUND;
- }
-
- prev = ndef_message->records;
-
- if (index == 0)
- {
- ndef_message->records = record;
- record->next = prev;
- }
- else
- {
- for (; idx < index - 1; idx++)
- {
- prev = prev->next;
- if (prev == NULL)
- {
- return NET_NFC_INVALID_FORMAT;
- }
- }
- next = prev->next;
- prev->next = record;
- record->next = next;
- }
- (ndef_message->recordCount)++;
-
- return __net_nfc_repair_record_flags(ndef_message);
-}
-
-net_nfc_error_e net_nfc_util_search_record_by_type(ndef_message_s *ndef_message, net_nfc_record_tnf_e tnf, data_s *type, ndef_record_s **record)
-{
- int idx = 0;
- ndef_record_s *tmp_record;
- uint32_t type_length;
- uint8_t *buf;
-
- if (ndef_message == NULL || type == NULL || record == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
-
- type_length = type->length;
- buf = type->buffer;
-
- /* remove prefix of nfc specific urn */
- if (type_length > 12)
- {
- if (memcmp(buf, "urn:nfc:ext:", 12) == 0 ||
- memcmp(buf, "urn:nfc:wkt:", 12) == 0)
- {
- buf += 12;
- type_length -= 12;
- }
- }
-
- tmp_record = ndef_message->records;
-
- for (; idx < ndef_message->recordCount; idx++)
- {
- if (tmp_record == NULL)
- {
- *record = NULL;
-
- return NET_NFC_INVALID_FORMAT;
- }
-
- if (tmp_record->TNF == tnf &&
- type_length == tmp_record->type_s.length &&
- memcmp(buf, tmp_record->type_s.buffer, type_length) == 0)
- {
- *record = tmp_record;
-
- return NET_NFC_OK;
- }
-
- tmp_record = tmp_record->next;
- }
-
- return NET_NFC_NO_DATA_FOUND;
-}
-
-net_nfc_error_e net_nfc_util_search_record_by_id(ndef_message_s *ndef_message, data_s *id, ndef_record_s **record)
-{
- int idx = 0;
- ndef_record_s *record_in_msg;
- uint32_t id_length;
- uint8_t *buf;
-
- if (ndef_message == NULL || id == NULL || record == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
-
- id_length = id->length;
- buf = id->buffer;
-
- record_in_msg = ndef_message->records;
-
- for (; idx < ndef_message->recordCount; idx++)
- {
- if (record_in_msg == NULL)
- {
- *record = NULL;
-
- return NET_NFC_INVALID_FORMAT;
- }
- if (id_length == record_in_msg->id_s.length &&
- memcmp(buf, record_in_msg->id_s.buffer, id_length) == 0)
- {
- *record = record_in_msg;
-
- return NET_NFC_OK;
- }
-
- record_in_msg = record_in_msg->next;
- }
-
- return NET_NFC_NO_DATA_FOUND;
-}
-
-static net_nfc_error_e __net_nfc_repair_record_flags(ndef_message_s *ndef_message)
-{
- int idx = 0;
- ndef_record_s *record;
-
- if (ndef_message == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
-
- record = ndef_message->records;
-
- if (ndef_message->recordCount == 1)
- {
- if (record == NULL)
- {
- return NET_NFC_INVALID_FORMAT;
- }
-
- record->MB = 1;
- record->ME = 1;
-
- return NET_NFC_OK;
- }
-
- for (idx = 0; idx < ndef_message->recordCount; idx++)
- {
- if (record == NULL)
- {
- return NET_NFC_INVALID_FORMAT;
- }
-
- if (idx == 0)
- {
- record->MB = 1;
- record->ME = 0;
- }
- else if (idx == ndef_message->recordCount - 1)
- {
- record->MB = 0;
- record->ME = 1;
- }
- else
- {
- record->MB = 0;
- record->ME = 0;
- }
- record = record->next;
- }
-
- return NET_NFC_OK;
-}
-
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
-
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "net_nfc_debug_internal.h"
-#include "net_nfc_util_defines.h"
-#include "net_nfc_util_internal.h"
-#include "net_nfc_util_ndef_message.h"
-#include "net_nfc_util_ndef_record.h"
-
-net_nfc_error_e net_nfc_util_free_record(ndef_record_s *record)
-{
- if (record == NULL)
- return NET_NFC_NULL_PARAMETER;
-
- if (record->type_s.buffer != NULL)
- _net_nfc_util_free_mem(record->type_s.buffer);
- if (record->id_s.buffer != NULL)
- _net_nfc_util_free_mem(record->id_s.buffer);
- if (record->payload_s.buffer != NULL)
- _net_nfc_util_free_mem(record->payload_s.buffer);
-
- _net_nfc_util_free_mem(record);
-
- return NET_NFC_OK;
-}
-
-net_nfc_error_e net_nfc_util_create_record(net_nfc_record_tnf_e recordType, data_s *typeName, data_s *id, data_s *payload, ndef_record_s **record)
-{
- ndef_record_s *record_temp = NULL;
-
- if (typeName == NULL || payload == NULL || record == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
-
- if (recordType < NET_NFC_RECORD_EMPTY || recordType > NET_NFC_RECORD_UNCHAGNED)
- {
- return NET_NFC_OUT_OF_BOUND;
- }
-
- /* empty_tag */
- if (recordType == NET_NFC_RECORD_EMPTY)
- {
- if ((typeName->buffer != NULL) || (payload->buffer != NULL) || (id->buffer != NULL) || (typeName->length != 0) || (payload->length != 0) || (id->length != 0))
- return NET_NFC_NULL_PARAMETER;
- }
-
- _net_nfc_util_alloc_mem(record_temp, sizeof(ndef_record_s));
- if (record_temp == NULL)
- {
- return NET_NFC_ALLOC_FAIL;
- }
-
- // set type name and length and TNF field
- record_temp->TNF = recordType;
- record_temp->type_s.length = typeName->length;
-
- if(record_temp->type_s.length > 0)
- {
- _net_nfc_util_alloc_mem(record_temp->type_s.buffer, record_temp->type_s.length);
- if (record_temp->type_s.buffer == NULL)
- {
- _net_nfc_util_free_mem(record_temp);
-
- return NET_NFC_ALLOC_FAIL;
- }
-
- memcpy(record_temp->type_s.buffer, typeName->buffer, record_temp->type_s.length);
- }
- else
- {
- record_temp->type_s.buffer = NULL;
- record_temp->type_s.length = 0;
- }
-
- // set payload
- record_temp->payload_s.length = payload->length;
- if(payload->length >0)
- {
- _net_nfc_util_alloc_mem(record_temp->payload_s.buffer, record_temp->payload_s.length);
- if (record_temp->payload_s.buffer == NULL)
- {
- _net_nfc_util_free_mem(record_temp->type_s.buffer);
- _net_nfc_util_free_mem(record_temp);
-
- return NET_NFC_ALLOC_FAIL;
- }
-
- memcpy(record_temp->payload_s.buffer, payload->buffer, record_temp->payload_s.length);
- }
- else
- {
- record_temp->payload_s.buffer = NULL;
- record_temp->payload_s.length = 0;
- }
-
- if (payload->length < 256)
- {
- record_temp->SR = 1;
- }
- else
- {
- record_temp->SR = 0;
- }
-
- // set id and id length and IL field
- if (id != NULL && id->buffer != NULL && id->length > 0)
- {
- record_temp->id_s.length = id->length;
- _net_nfc_util_alloc_mem(record_temp->id_s.buffer, record_temp->id_s.length);
- if (record_temp->id_s.buffer == NULL)
- {
- _net_nfc_util_free_mem(record_temp->payload_s.buffer);
- _net_nfc_util_free_mem(record_temp->type_s.buffer);
- _net_nfc_util_free_mem(record_temp);
-
- return NET_NFC_ALLOC_FAIL;
- }
-
- memcpy(record_temp->id_s.buffer, id->buffer, record_temp->id_s.length);
- record_temp->IL = 1;
- }
- else
- {
- record_temp->IL = 0;
- record_temp->id_s.buffer = NULL;
- record_temp->id_s.length = 0;
- }
-
- // this is default value
- record_temp->MB = 1;
- record_temp->ME = 1;
-
- record_temp->next = NULL;
-
- *record = record_temp;
-
- return NET_NFC_OK;
-}
-
-net_nfc_error_e net_nfc_util_create_uri_type_record(const char *uri, net_nfc_schema_type_e protocol_schema, ndef_record_s **record)
-{
- net_nfc_error_e error;
- data_s type_data;
- data_s payload_data = { NULL, 0 };
-
- if (uri == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
-
- payload_data.length = strlen((char *)uri) + 1;
- if (payload_data.length == 1)
- {
- return NET_NFC_INVALID_PARAM;
- }
-
- _net_nfc_util_alloc_mem(payload_data.buffer, payload_data.length);
- if (payload_data.buffer == NULL)
- {
- return NET_NFC_ALLOC_FAIL;
- }
-
- payload_data.buffer[0] = protocol_schema; /* first byte of payload is protocol scheme */
- memcpy(payload_data.buffer + 1, uri, payload_data.length - 1);
-
- type_data.length = 1;
- type_data.buffer = (uint8_t *)URI_RECORD_TYPE;
-
- error = net_nfc_util_create_record(NET_NFC_RECORD_WELL_KNOWN_TYPE, &type_data, NULL, &payload_data, record);
-
- _net_nfc_util_free_mem(payload_data.buffer);
-
- return error;
-}
-
-net_nfc_error_e net_nfc_util_create_text_type_record(const char *text, const char *lang_code_str, net_nfc_encode_type_e encode, ndef_record_s **record)
-{
- data_s type_data;
- data_s payload_data;
- int controll_byte;
- int offset = 0;
-
- if (text == NULL || lang_code_str == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
-
- if ((encode < NET_NFC_ENCODE_UTF_8 || encode > NET_NFC_ENCODE_UTF_16))
- {
- return NET_NFC_OUT_OF_BOUND;
- }
-
- payload_data.length = strlen((char *)text) + strlen(lang_code_str) + 1;
-
- _net_nfc_util_alloc_mem(payload_data.buffer, payload_data.length);
- if (payload_data.buffer == NULL)
- {
- return NET_NFC_ALLOC_FAIL;
- }
-
- controll_byte = strlen(lang_code_str) & 0x3F;
- if (encode == NET_NFC_ENCODE_UTF_16)
- {
- controll_byte = controll_byte | 0x80;
- }
-
- payload_data.buffer[0] = controll_byte;
-
- offset = 1;
- memcpy(payload_data.buffer + offset, lang_code_str, strlen(lang_code_str));
-
- offset = offset + strlen(lang_code_str);
- memcpy(payload_data.buffer + offset, (char *)text, strlen((char *)text));
-
- type_data.length = 1;
- type_data.buffer = (uint8_t *)TEXT_RECORD_TYPE;
-
- net_nfc_util_create_record(NET_NFC_RECORD_WELL_KNOWN_TYPE, &type_data, NULL, &payload_data, record);
-
- _net_nfc_util_free_mem(payload_data.buffer);
-
- return NET_NFC_OK;
-}
-
-net_nfc_error_e net_nfc_util_set_record_id(ndef_record_s *record, uint8_t *data, int length)
-{
- if (record == NULL || data == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
-
- if (length < 1)
- {
- return NET_NFC_OUT_OF_BOUND;
- }
-
- if (record->id_s.buffer != NULL && record->id_s.length > 0)
- {
- _net_nfc_util_free_mem(record->id_s.buffer);
- }
-
- _net_nfc_util_alloc_mem(record->id_s.buffer, length);
- if (record->id_s.buffer == NULL)
- {
- return NET_NFC_ALLOC_FAIL;
- }
- memcpy(record->id_s.buffer, data, length);
- record->id_s.length = length;
- record->IL = 1;
-
- return NET_NFC_OK;
-}
-
-uint32_t net_nfc_util_get_record_length(ndef_record_s *Record)
-{
- uint32_t RecordLength = 1;
-
- if (Record == NULL)
- return 0;
-
- /* Type length is present only for following TNF
- NET_NFC_TNF_NFCWELLKNOWN
- NET_NFC_TNF_MEDIATYPE
- SLP_FRINET_NFC_NDEFRECORD_TNF_ABSURI
- SLP_FRINET_NFC_NDEFRECORD_TNF_NFCEXT
- */
-
- /* ++ is for the Type Length Byte */
- RecordLength++;
- if (Record->TNF != NET_NFC_NDEF_TNF_EMPTY &&
- Record->TNF != NET_NFC_NDEF_TNF_UNKNOWN &&
- Record->TNF != NET_NFC_NDEF_TNF_UNCHANGED)
- {
- RecordLength += Record->type_s.length;
- }
-
- /* to check if payloadlength is 8bit or 32bit*/
- if (Record->SR != 0)
- {
- /* ++ is for the Payload Length Byte */
- RecordLength++;/* for short record*/
- }
- else
- {
- /* + NET_NFC_NDEF_NORMAL_RECORD_BYTE is for the Payload Length Byte */
- RecordLength += 4;
- }
-
- /* for non empty record */
- if (Record->TNF != NET_NFC_NDEF_TNF_EMPTY)
- {
- RecordLength += Record->payload_s.length;
- }
-
- /* ID and IDlength are present only if IL flag is set*/
- if (Record->IL != 0)
- {
- RecordLength += Record->id_s.length;
- /* ++ is for the ID Length Byte */
- RecordLength++;
- }
-
- return RecordLength;
-}
-
-net_nfc_error_e net_nfc_util_create_uri_string_from_uri_record(ndef_record_s *record, char **uri)
-{
- net_nfc_error_e result = NET_NFC_OK;
-
- if (record == NULL || uri == NULL)
- {
- return NET_NFC_INVALID_PARAM;
- }
-
- *uri = NULL;
-
- if (record->TNF == NET_NFC_RECORD_WELL_KNOWN_TYPE &&
- (record->type_s.length == 1 && record->type_s.buffer[0] == 'U'))
- {
- data_s *payload = &record->payload_s;
-
- if (payload->length > 0)
- {
- int length = 0;
- const char *scheme = NULL;
-
- /* buffer length include a schema byte.
- * so it does not need to allocate one more byte for string. */
- if ((scheme = net_nfc_util_get_schema_string(payload->buffer[0])) != NULL)
- {
- length = strlen(scheme);
- }
-
- *uri = (char *)calloc(1, length + payload->length);
- if (*uri != NULL)
- {
- if (length > 0)
- memcpy(*uri, scheme, length);
- memcpy(*uri + length, payload->buffer + 1, payload->length - 1);
- }
- else
- {
- result = NET_NFC_ALLOC_FAIL;
- }
- }
- else
- {
- DEBUG_ERR_MSG("invalid payload in record");
- }
- }
- else if (record->TNF == NET_NFC_RECORD_URI)
- {
- data_s *type = &record->type_s;
-
- if (type->length > 0)
- {
- *uri = (char *)calloc(1, type->length + 1);
-
- if (*uri != NULL)
- {
- memcpy(*uri, type->buffer, type->length);
- }
- else
- {
- result = NET_NFC_ALLOC_FAIL;
- }
- }
- }
- else
- {
- DEBUG_ERR_MSG("no uri record");
- result = NET_NFC_NDEF_RECORD_IS_NOT_EXPECTED_TYPE;
- }
-
- return result;
-}
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
-
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-#include <openssl/evp.h>
-#include <openssl/engine.h>
-#include <openssl/pkcs12.h>
-#include <openssl/pem.h>
-
-#include "net_nfc_typedef_internal.h"
-#include "net_nfc_debug_internal.h"
-#include "net_nfc_util_internal.h"
-#include "net_nfc_util_openssl_internal.h"
-
-//static X509 *_load_certificate_from_file(const char *file)
-//{
-// X509 *x509 = NULL;
-// BIO *cert = NULL;
-//
-// cert = BIO_new(BIO_s_file());
-// if (cert != NULL)
-// {
-// if (BIO_read_filename(cert, file) > 0)
-// {
-// x509 = PEM_read_bio_X509_AUX(cert, NULL, NULL, NULL);
-// }
-//
-// BIO_free(cert);
-// }
-//
-// return x509;
-//}
-
-static X509 *_load_certificate_from_mem(int format, uint8_t *buffer, uint32_t length, char *password)
-{
- X509 *x509 = NULL;
- BIO *mem = NULL;
-
- mem = BIO_new_mem_buf(buffer, length);
- if (mem != NULL)
- {
- switch (format)
- {
- case 0 :
- x509 = d2i_X509_bio(mem, NULL);
- break;
-
- case 1 :
- x509 = PEM_read_bio_X509(mem, NULL, NULL, NULL);
- break;
-
- case 2 :
- {
- PKCS12 *p12 = d2i_PKCS12_bio(mem, NULL);
- PKCS12_parse(p12, password, NULL, &x509, NULL);
- PKCS12_free(p12);
- }
- break;
- }
-
- BIO_free(mem);
- }
- else
- {
- DEBUG_ERR_MSG("X509_LOOKUP_load_file failed");
- }
-
- return x509;
-}
-
-//int net_nfc_util_openssl_verify_certificate(const char* certfile, const char* CAfile)
-//{
-// int ret = 0;
-// X509_STORE *cert_ctx = NULL;
-// X509_LOOKUP *lookup = NULL;
-//
-// cert_ctx = X509_STORE_new();
-// if (cert_ctx != NULL)
-// {
-// OpenSSL_add_all_algorithms();
-//
-// lookup = X509_STORE_add_lookup(cert_ctx, X509_LOOKUP_file());
-// if (lookup != NULL)
-// {
-// if (X509_LOOKUP_load_file(lookup, CAfile, X509_FILETYPE_PEM) == true)
-// {
-// lookup = X509_STORE_add_lookup(cert_ctx, X509_LOOKUP_hash_dir());
-// if (lookup != NULL)
-// {
-// X509_LOOKUP_add_dir(lookup, NULL, X509_FILETYPE_DEFAULT);
-//
-// ret = _verify_certificate_file(cert_ctx, certfile);
-// }
-// else
-// {
-// DEBUG_ERR_MSG("X509_STORE_add_lookup failed");
-// }
-// }
-// else
-// {
-// DEBUG_ERR_MSG("X509_LOOKUP_load_file failed");
-// }
-// }
-// else
-// {
-// DEBUG_ERR_MSG("X509_STORE_add_lookup failed");
-// }
-//
-// X509_STORE_free(cert_ctx);
-// }
-// else
-// {
-// DEBUG_ERR_MSG("X509_STORE_new failed");
-// }
-//
-// return ret;
-//}
-
-net_nfc_openssl_verify_context_s *net_nfc_util_openssl_init_verify_certificate(void)
-{
- net_nfc_openssl_verify_context_s *result = NULL;
-
- _net_nfc_util_alloc_mem(result, sizeof(net_nfc_openssl_verify_context_s));
- if (result != NULL)
- {
- result->store = X509_STORE_new();
- if (result->store != NULL)
- {
- OpenSSL_add_all_algorithms();
- }
- else
- {
- DEBUG_ERR_MSG("X509_STORE_new failed");
- }
- }
- else
- {
- DEBUG_ERR_MSG("alloc failed [%d]", sizeof(net_nfc_openssl_verify_context_s));
- }
-
- return result;
-}
-
-void net_nfc_util_openssl_release_verify_certificate(net_nfc_openssl_verify_context_s *context)
-{
- if (context != NULL)
- {
- if (context->signer_cert != NULL)
- X509_free(context->signer_cert);
-
- if (context->store != NULL)
- X509_STORE_free(context->store);
-
- _net_nfc_util_free_mem(context);
- }
-}
-
-bool net_nfc_util_openssl_add_certificate_of_signer(net_nfc_openssl_verify_context_s *context, uint8_t *buffer, uint32_t length)
-{
- bool result = false;
-
- if (context->signer_cert != NULL)
- {
- X509_free(context->signer_cert);
- context->signer_cert = NULL;
- }
-
- context->signer_cert = _load_certificate_from_mem(1, buffer, length, NULL);
- if (context->signer_cert != NULL)
- result = true;
-
- return result;
-}
-
-bool net_nfc_util_openssl_add_certificate_of_ca(net_nfc_openssl_verify_context_s *context, uint8_t *buffer, uint32_t length)
-{
- bool result = false;
- X509 *x509 = NULL;
-
- x509 = _load_certificate_from_mem(1, buffer, length, NULL);
- if (x509 != NULL)
- {
- if (X509_STORE_add_cert(context->store, x509))
- {
- result = true;
- }
- }
-
- return result;
-}
-
-int net_nfc_util_openssl_verify_certificate(net_nfc_openssl_verify_context_s *context)
-{
- int result = 0;
- X509_STORE_CTX *store_ctx = NULL;
-
- store_ctx = X509_STORE_CTX_new();
- if (store_ctx != NULL)
- {
- X509_STORE_set_flags(context->store, 0);
- if (X509_STORE_CTX_init(store_ctx, context->store, context->signer_cert, 0) == true)
- {
- result = X509_verify_cert(store_ctx);
- }
- else
- {
- DEBUG_ERR_MSG("X509_STORE_CTX_init failed");
- }
-
- X509_STORE_CTX_free(store_ctx);
- }
- else
- {
- DEBUG_ERR_MSG("X509_STORE_CTX_new failed");
- }
-
- return result;
-}
-
-int _password_callback(char *buf, int bufsiz, int verify, void *data)
-{
- int res = 0;
- const char *password = (char *)data;
-
- if (password)
- {
- res = strlen(password);
- if (res > bufsiz)
- res = bufsiz;
- memcpy(buf, password, res);
- return res;
- }
-
- return res;
-}
-
-static int _load_pkcs12(BIO *in, const char *password, EVP_PKEY **pkey, X509 **cert, STACK_OF(X509) **ca)
-{
- int ret = 0;
- PKCS12 *p12 = NULL;
-
- if ((p12 = d2i_PKCS12_bio(in, NULL)) != NULL)
- {
- if (PKCS12_verify_mac(p12, password, strlen(password)) == true)
- {
- ret = PKCS12_parse(p12, password, pkey, cert, ca);
- }
- else
- {
- DEBUG_ERR_MSG("Mac verify error (wrong password?) in PKCS12 file");
- }
-
- PKCS12_free(p12);
- }
- else
- {
- DEBUG_ERR_MSG("Error loading PKCS12 file");
- }
-
- return ret;
-}
-
-EVP_PKEY *_load_key(const char *file, int format, const char *pass, ENGINE *e)
-{
- BIO *key = NULL;
- EVP_PKEY *pkey = NULL;
-
- if (file == NULL)
- {
- DEBUG_ERR_MSG("no keyfile specified\n");
- return pkey;
- }
-
- if (format == OPENSSL_FORMAT_ENGINE)
- {
- if (e != NULL)
- {
- pkey = ENGINE_load_private_key(e, file, NULL/*ui_method*/, (void *)pass);
- if (!pkey)
- {
- DEBUG_ERR_MSG("cannot load key from engine");
- }
- }
- else
- {
- DEBUG_ERR_MSG("no engine specified");
- }
- }
- else
- {
- if ((key = BIO_new(BIO_s_file())) != NULL)
- {
- if (BIO_read_filename(key,file) > 0)
- {
- switch (format)
- {
- case OPENSSL_FORMAT_ASN1 :
- pkey = d2i_PrivateKey_bio(key, NULL);
- break;
-
- case OPENSSL_FORMAT_PEM :
- pkey = PEM_read_bio_PrivateKey(key, NULL, (pem_password_cb *)_password_callback, (void *)pass);
- break;
-
- case OPENSSL_FORMAT_PKCS12 :
- if (_load_pkcs12(key, pass, &pkey, NULL, NULL) == false)
- {
- DEBUG_ERR_MSG("_load_pkcs12 failed");
- }
- break;
-
- case OPENSSL_FORMAT_MSBLOB :
- pkey = b2i_PrivateKey_bio(key);
- break;
-
- case OPENSSL_FORMAT_PVK :
- pkey = b2i_PVK_bio(key, (pem_password_cb *)_password_callback, (void *)pass);
- break;
-
- default :
- DEBUG_ERR_MSG("bad input format specified for key file");
- break;
- }
- }
- else
- {
- DEBUG_ERR_MSG("Error opening %s", file);
- }
-
- BIO_free(key);
- }
- else
- {
- DEBUG_ERR_MSG("BIO_new failed");
- }
- }
-
- return pkey;
-}
-
-EVP_PKEY *_load_pubkey(const char *file, int format, const char *pass, ENGINE *e, const char *key_descrip)
-{
- BIO *key = NULL;
- EVP_PKEY *pkey = NULL;
-
- if (file == NULL)
- {
- DEBUG_ERR_MSG("no keyfile specified");
- return pkey;
- }
-
- if (format == OPENSSL_FORMAT_ENGINE)
- {
- if (e != NULL)
- {
- pkey = ENGINE_load_public_key(e, file, NULL/*ui_method*/, (void *)pass);
- }
- else
- {
- DEBUG_ERR_MSG("no engine specified");
- }
- }
- else
- {
- if ((key = BIO_new(BIO_s_file())) != NULL)
- {
- if (BIO_read_filename(key,file) <= 0)
- {
- switch (format)
- {
- case OPENSSL_FORMAT_ASN1 :
- pkey = d2i_PUBKEY_bio(key, NULL);
- break;
-
- case OPENSSL_FORMAT_ASN1RSA :
- {
- RSA *rsa;
- rsa = d2i_RSAPublicKey_bio(key, NULL);
- if (rsa)
- {
- pkey = EVP_PKEY_new();
- if (pkey)
- EVP_PKEY_set1_RSA(pkey, rsa);
- RSA_free(rsa);
- }
- else
- pkey = NULL;
- }
- break;
-
- case OPENSSL_FORMAT_PEMRSA :
- {
- RSA *rsa;
- rsa = PEM_read_bio_RSAPublicKey(key, NULL, (pem_password_cb *)_password_callback, (void *)pass);
- if (rsa)
- {
- pkey = EVP_PKEY_new();
- if (pkey)
- EVP_PKEY_set1_RSA(pkey, rsa);
- RSA_free(rsa);
- }
- else
- pkey = NULL;
- }
- break;
-
- case OPENSSL_FORMAT_PEM :
- pkey = PEM_read_bio_PUBKEY(key, NULL, (pem_password_cb *)_password_callback, (void *)pass);
- break;
-
- case OPENSSL_FORMAT_MSBLOB :
- pkey = b2i_PublicKey_bio(key);
- break;
-
- default :
- DEBUG_ERR_MSG("bad input format specified for key file");
- break;
- }
- }
- else
- {
- DEBUG_ERR_MSG("Error opening %s %s", key_descrip, file);
- }
-
- BIO_free(key);
- }
- else
- {
- DEBUG_ERR_MSG("BIO_new failed");
- }
- }
-
- return pkey;
-}
-
-int net_nfc_util_openssl_sign_buffer(uint32_t type, uint8_t *buffer, uint32_t length, char *key_file, char *password, uint8_t *sign, uint32_t *sign_len)
-{
- int result = 0;
- const EVP_MD *md = NULL;
- ENGINE *engine;
- EVP_PKEY *pkey;
-
- OpenSSL_add_all_algorithms();
-
- /* md context */
- EVP_MD_CTX ctx = { 0, };
- EVP_PKEY_CTX *pctx = NULL;
-
- switch (type)
- {
- case 0 :
- result = 0;
- return result;
-
- /* RSASSA-PSS, RSASSA-PKCS1-v1_5 */
- case 1 :
- case 2 :
- /* md */
- md = EVP_get_digestbyname("sha1");
-
- /* engine */
- engine = ENGINE_get_default_RSA();
- break;
-
- /* DSA */
- case 3 :
- /* md */
- //md = EVP_get_digestbyname("sha1");
- /* engine */
- engine = ENGINE_get_default_DSA();
- break;
-
- /* ECDSA */
- case 4 :
- /* md */
- md = EVP_get_digestbyname("sha1");
-
- /* engine */
- engine = ENGINE_get_default_ECDSA();
- break;
-
- default :
- result = -1;
- return result;
- }
-
- /* pkey */
- pkey = _load_key(key_file, OPENSSL_FORMAT_PKCS12, password, NULL);
-
- EVP_DigestSignInit(&ctx, &pctx, md, engine, pkey);
- EVP_DigestSignUpdate(&ctx, buffer, length);
- EVP_DigestSignFinal(&ctx, sign, sign_len);
-
- return result;
-}
-
-int net_nfc_util_openssl_verify_signature(uint32_t type, uint8_t *buffer, uint32_t length, uint8_t *cert, uint32_t cert_len, uint8_t *sign, uint32_t sign_len)
-{
- int result = 0;
- const EVP_MD *md = NULL;
- ENGINE *engine;
- EVP_PKEY *pkey;
-
- OpenSSL_add_all_algorithms();
-
- /* md context */
- EVP_MD_CTX ctx = { 0, };
- EVP_PKEY_CTX *pctx = NULL;
-
- switch (type)
- {
- case 0 :
- result = 0;
- return result;
-
- /* RSASSA-PSS, RSASSA-PKCS1-v1_5 */
- case 1 :
- case 2 :
- /* md */
- md = EVP_get_digestbyname("sha1");
-
- /* engine */
- engine = ENGINE_get_default_RSA();
- break;
-
- /* DSA */
- case 3 :
- /* md */
- //md = EVP_get_digestbyname("sha1");
- /* engine */
- engine = ENGINE_get_default_DSA();
- break;
-
- /* ECDSA */
- case 4 :
- /* md */
- md = EVP_get_digestbyname("sha1");
-
- /* engine */
- engine = ENGINE_get_default_ECDSA();
- break;
-
- default :
- result = -1;
- return result;
- }
-
- /* pkey */
- X509 *x509 = _load_certificate_from_mem(0, cert, cert_len, NULL);
- pkey = X509_PUBKEY_get(X509_get_X509_PUBKEY(x509));
- X509_free(x509);
-
- EVP_DigestVerifyInit(&ctx, &pctx, md, engine, pkey);
- EVP_DigestVerifyUpdate(&ctx, buffer, length);
- result = EVP_DigestVerifyFinal(&ctx, sign, sign_len);
-
- DEBUG_MSG("EVP_DigestVerifyFinal returns %d", result);
-
- return result;
-}
-
-#if 0
-int net_nfc_util_get_cert_list_from_file(char *file_name, char *password, uint8_t **buffer, uint32_t *length, uint32_t *cert_count)
-{
- int result = 0;
- BIO *bio = NULL;
-
- bio = BIO_new(BIO_s_file());
- if (bio != NULL)
- {
- if (BIO_read_filename(bio, file_name) > 0)
- {
- STACK_OF(X509_INFO) *xis = NULL;
-
- if ((xis = PEM_X509_INFO_read_bio(bio, NULL, (pem_password_cb *)_password_callback, password)) != NULL)
- {
- X509_INFO *xi;
- int i;
- uint32_t temp_len = 0;
- uint8_t *temp_buf = NULL;
- uint32_t offset = 0;
- uint32_t count = 0;
-
- for (i = 0; i < sk_X509_INFO_num(xis); i++)
- {
- xi = sk_X509_INFO_value(xis, i);
- if (xi->x509)
- {
- int32_t ret = 0;
-
- if ((ret = i2d_X509(xi->x509, NULL)) > 0)
- {
- temp_len += (ret + 2);
- }
- }
- }
-
- DEBUG_MSG("count = %d, length = %d", sk_X509_INFO_num(xis), temp_len);
- *length = temp_len;
- _net_nfc_util_alloc_mem(*buffer, temp_len);
-
- for (i = 0; i < sk_X509_INFO_num(xis); i++)
- {
- xi = sk_X509_INFO_value(xis, i);
- if (xi->x509)
- {
- temp_buf = NULL;
-
- if ((temp_len = i2d_X509(xi->x509, &temp_buf)) > 0)
- {
- *(uint16_t *)(*buffer + offset) = temp_len;
- offset += sizeof(uint16_t);
-
- memcpy(*buffer + offset, temp_buf, temp_len);
- offset += temp_len;
-
- count++;
- }
- }
- }
-
- *cert_count = count;
-
- sk_X509_INFO_pop_free(xis, X509_INFO_free);
- }
- else
- {
- DEBUG_ERR_MSG("PEM_X509_INFO_read_bio failed");
- }
- }
-
- BIO_free(bio);
- }
-
- return result;
-}
-#endif
-
-/* TODO : DER?? PEM?? */
-int net_nfc_util_get_cert_list_from_file(char *file_name, char *password, uint8_t **buffer, uint32_t *length, uint32_t *cert_count)
-{
- int result = 0;
- BIO *bio = NULL;
-
- bio = BIO_new(BIO_s_file());
- if (bio != NULL)
- {
- if (BIO_read_filename(bio, file_name) > 0)
- {
- EVP_PKEY *pkey = NULL;
- X509 *x509 = NULL;
- STACK_OF(X509) *ca = NULL;
-
- if (_load_pkcs12(bio, password, &pkey, &x509, &ca) != 0)
- {
- X509 *temp_x509;
- int i;
- uint32_t temp_len = 0;
- uint8_t *temp_buf = NULL;
- uint32_t offset = 0;
- uint32_t count = 0;
- int32_t ret = 0;
-
- if ((ret = i2d_X509(x509, NULL)) > 0)
- {
- temp_len += (ret + 2);
- }
-
- for (i = 0; i < sk_X509_num(ca); i++)
- {
- temp_x509 = sk_X509_value(ca, i);
- if (temp_x509)
- {
- if ((ret = i2d_X509(temp_x509, NULL)) > 0)
- {
- temp_len += (ret + 2);
- }
- }
- }
-
- DEBUG_MSG("count = %d, length = %d", sk_X509_num(ca) + 1, temp_len);
- *length = temp_len;
- _net_nfc_util_alloc_mem(*buffer, temp_len);
-
- if ((temp_len = i2d_X509(x509, &temp_buf)) > 0)
- {
- *(uint16_t *)(*buffer + offset) = temp_len;
- offset += sizeof(uint16_t);
-
- memcpy(*buffer + offset, temp_buf, temp_len);
- offset += temp_len;
-
- count++;
- }
-
- for (i = 0; i < sk_X509_num(ca); i++)
- {
- temp_x509 = sk_X509_value(ca, i);
- if (temp_x509)
- {
- temp_buf = NULL;
-
- if ((temp_len = i2d_X509(temp_x509, &temp_buf)) > 0)
- {
- *(uint16_t *)(*buffer + offset) = temp_len;
- offset += sizeof(uint16_t);
-
- memcpy(*buffer + offset, temp_buf, temp_len);
- offset += temp_len;
-
- count++;
- }
- }
- }
-
- *cert_count = count;
-
- sk_X509_pop_free(ca, X509_free);
- }
- else
- {
- DEBUG_ERR_MSG("PEM_X509_INFO_read_bio failed");
- }
- }
-
- BIO_free(bio);
- }
-
- return result;
-}
-
-bool net_nfc_util_openssl_encode_base64(const uint8_t *buffer, const uint32_t buf_len, char *result, uint32_t max_len, bool new_line_char)
-{
- bool ret = false;
- BUF_MEM *bptr;
- BIO *b64, *bmem;
-
- if (buffer == NULL || buf_len == 0)
- {
- return ret;
- }
-
- b64 = BIO_new(BIO_f_base64());
- bmem = BIO_new(BIO_s_mem());
-
- if (new_line_char == false)
- BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL);
-
- b64 = BIO_push(b64, bmem);
-
- BIO_write(b64, buffer, buf_len);
- BIO_flush(b64);
- BIO_get_mem_ptr(b64, &bptr);
-
- if (max_len >= bptr->length)
- {
- memcpy(result, bptr->data, bptr->length);
- result[bptr->length] = 0;
- ret = true;
- }
- else
- {
- DEBUG_ERR_MSG("not enough result buffer");
- }
-
- BIO_free_all(b64);
-
- return ret;
-}
-
-bool net_nfc_util_openssl_decode_base64(const char *buffer, uint8_t *result, uint32_t *out_len, bool new_line_char)
-{
- bool ret = false;
- unsigned int length = 0;
- char *temp;
-
- if (buffer == NULL || (length = strlen(buffer)) == 0)
- {
- return ret;
- }
-
- _net_nfc_util_alloc_mem(temp, length);
- if (temp != NULL)
- {
- BIO *b64, *bmem;
-
- b64 = BIO_new(BIO_f_base64());
- bmem = BIO_new_mem_buf((void *)buffer, length);
- if (new_line_char == false)
- BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL);
- bmem = BIO_push(b64, bmem);
-
- length = BIO_read(bmem, temp, length);
-
- BIO_free_all(bmem);
-
- if (*out_len > length)
- {
- *out_len = length;
- memcpy(result, temp, *out_len);
- ret = true;
- }
- else
- {
- DEBUG_ERR_MSG("not enough result buffer");
- }
-
- _net_nfc_util_free_mem(temp);
- }
- else
- {
- DEBUG_ERR_MSG("alloc failed");
- }
-
- return ret;
-}
-
-bool net_nfc_util_openssl_digest(const char *algorithm, const uint8_t *buffer, const uint32_t buf_len, uint8_t *result, uint32_t *out_len)
-{
- const EVP_MD *md;
- unsigned char *temp;
- bool ret = false;
-
- if (algorithm == NULL || buffer == NULL || buf_len == 0)
- {
- return ret;
- }
-
- OpenSSL_add_all_digests();
-
- if ((md = EVP_get_digestbyname(algorithm)) != NULL)
- {
- _net_nfc_util_alloc_mem(temp, EVP_MAX_MD_SIZE);
- if (temp != NULL)
- {
- EVP_MD_CTX mdCtx;
- unsigned int resultLen = 0;
-
- memset(temp, 0, EVP_MAX_MD_SIZE);
-
- EVP_DigestInit(&mdCtx, md);
- if (EVP_DigestUpdate(&mdCtx, buffer, buf_len) != 0)
- {
- DEBUG_ERR_MSG("EVP_DigestUpdate failed");
- }
- EVP_DigestFinal(&mdCtx, temp, &resultLen);
-
- if (*out_len >= resultLen)
- {
- *out_len = resultLen;
- memcpy(result, temp, *out_len);
- ret = true;
- }
- else
- {
- DEBUG_ERR_MSG("not enough result buffer");
- }
-
- _net_nfc_util_free_mem(temp);
- }
- else
- {
- DEBUG_ERR_MSG("alloc failed");
- }
- }
- else
- {
- DEBUG_ERR_MSG("EVP_get_digestbyname(\"%s\") returns NULL", algorithm);
- }
-
- return ret;
-}
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-#include <sys/param.h>
-
-#include "net_nfc_debug_internal.h"
-#include "net_nfc_util_defines.h"
-#include "net_nfc_util_internal.h"
-#include "net_nfc_util_ndef_message.h"
-#include "net_nfc_util_ndef_record.h"
-#include "net_nfc_util_openssl_internal.h"
-#include "net_nfc_util_sign_record.h"
-
-#define IS_SIGN_RECORD(__x) \
- (((__x)->TNF == NET_NFC_RECORD_WELL_KNOWN_TYPE) && \
- ((__x)->type_s.length == 3) && \
- (memcmp((__x)->type_s.buffer, "Sig", 3) == 0))
-
-#define IS_EMPTY_RECORD(__x) \
- ((__x->TNF == NET_NFC_RECORD_EMPTY))
-
-#define __FILL_SUB_FIELD(__dst, __buf, __len) \
- (__dst)->length = (__len); \
- memcpy((__dst)->value, (__buf), (__dst)->length);
-
-#define __NEXT_SUB_FIELD(__dst) ((__dst)->value + (__dst)->length)
-
-bool _get_records_data_buffer(ndef_record_s *begin_record, ndef_record_s *end_record, uint8_t **buffer, uint32_t *length)
-{
- bool result = false;
- uint32_t len = 0;
- ndef_record_s *current_record = NULL;
-
- if (begin_record == NULL || begin_record == end_record)
- return result;
-
- /* count total buffer length */
- current_record = begin_record;
- len = 0;
-
- while (current_record != NULL && current_record != end_record)
- {
- /* type length */
- if (current_record->type_s.buffer != NULL && current_record->type_s.length > 0)
- len += current_record->type_s.length;
-
- /* ID length */
- if (current_record->id_s.buffer != NULL && current_record->id_s.length > 0)
- len += current_record->id_s.length;
-
- /* payload length */
- if (current_record->payload_s.buffer != NULL && current_record->payload_s.length > 0)
- len += current_record->payload_s.length;
-
- current_record = current_record->next;
- }
-
- if (len > 0)
- {
- uint8_t *buf = NULL;
-
- _net_nfc_util_alloc_mem(buf, len);
- if (buf != NULL)
- {
- uint32_t offset = 0;
-
- current_record = begin_record;
-
- while (offset < len && current_record != NULL && current_record != end_record)
- {
- /* type length */
- if (current_record->type_s.buffer != NULL && current_record->type_s.length > 0)
- {
- memcpy(buf + offset, current_record->type_s.buffer, MIN(current_record->type_s.length, len - offset));
- offset += MIN(current_record->type_s.length, len - offset);
- }
-
- /* ID length */
- if (current_record->id_s.buffer != NULL && current_record->id_s.length > 0)
- {
- memcpy(buf + offset, current_record->id_s.buffer, MIN(current_record->id_s.length, len - offset));
- offset += MIN(current_record->id_s.length, len - offset);
- }
-
- /* payload length */
- if (current_record->payload_s.buffer != NULL && current_record->payload_s.length > 0)
- {
- memcpy(buf + offset, current_record->payload_s.buffer, MIN(current_record->payload_s.length, len - offset));
- offset += MIN(current_record->payload_s.length, len - offset);
- }
-
- current_record = current_record->next;
- }
-
- *buffer = buf;
- *length = offset;
-
- result = true;
- }
- }
-
- return result;
-}
-
-net_nfc_error_e net_nfc_util_verify_signature_records(ndef_record_s *begin_record, ndef_record_s *sign_record)
-{
- net_nfc_error_e result = NET_NFC_UNKNOWN_ERROR;
- uint8_t *buffer = NULL;
- uint32_t length = 0;
-
- if (begin_record == NULL || sign_record == NULL || begin_record == sign_record)
- return NET_NFC_INVALID_PARAM;
-
- /* get signed data */
- if (_get_records_data_buffer(begin_record, sign_record, &buffer, &length) == true)
- {
- uint8_t *signature = NULL;
- uint32_t sign_len = 0;
- net_nfc_signature_record_s *sign_info = NULL;
- net_nfc_certificate_chain_s *chain_info = NULL;
-
- /* parse signature info */
- sign_info = (net_nfc_signature_record_s *)sign_record->payload_s.buffer;
-
- DEBUG_MSG("record version : %d", sign_info->version);
- DEBUG_MSG("signature URI present? : %s", sign_info->uri_present ? "true" : "false");
- DEBUG_MSG("signature type : %d", sign_info->sign_type);
- DEBUG_MSG("signature length : %d", sign_info->signature.length);
-
- if (sign_info->uri_present == true)
- {
- /* TODO */
- /* receive the signature data directed by uri */
- DEBUG_ERR_MSG("NOT IMPLEMENTED (sign_info->uri_present == true)");
- _net_nfc_util_free_mem(buffer);
- return result;
- }
- else
- {
- signature = sign_info->signature.value;
- sign_len = sign_info->signature.length;
- }
-
- /* parse certificate chain info */
- chain_info = (net_nfc_certificate_chain_s *)__NEXT_SUB_FIELD(&(sign_info->signature));
-
- SECURE_LOGD("certificate URI present? : %s", chain_info->uri_present ? "true" : "false");
- DEBUG_MSG("certificate format : %d", chain_info->cert_format);
- DEBUG_MSG("number of certificates : %d", chain_info->num_of_certs);
-
- if (chain_info->num_of_certs > 0)
- {
- net_nfc_sub_field_s *data_info = NULL;
-
- data_info = (net_nfc_sub_field_s *)chain_info->cert_store;
- DEBUG_MSG("certficate length : %d", data_info->length);
-
- // DEBUG_MSG_PRINT_BUFFER(data_info->value, data_info->length);
-
- /* the first certificate is signer's one
- * verify signature of content */
- if (net_nfc_util_openssl_verify_signature(sign_info->sign_type, buffer, length, data_info->value, data_info->length, sign_info->signature.value, sign_info->signature.length) == true)
- {
- if (chain_info->num_of_certs > 1)
- {
- int32_t i = 0;
- net_nfc_openssl_verify_context_h context = NULL;
-
- /* initialize context of verifying certificate */
- context = net_nfc_util_openssl_init_verify_certificate();
-
- /* add signer's certificate */
- net_nfc_util_openssl_add_certificate_of_signer(context, data_info->value, data_info->length);
-
- /* verify certificate using certificate chain */
- for (i = 1, data_info = (net_nfc_sub_field_s *)__NEXT_SUB_FIELD(data_info);
- i < chain_info->num_of_certs;
- i++, data_info = (net_nfc_sub_field_s *)__NEXT_SUB_FIELD(data_info))
- {
- DEBUG_MSG("certficate length : %d", data_info->length);
-// DEBUG_MSG_PRINT_BUFFER(data_info->value, data_info->length);
-
- net_nfc_util_openssl_add_certificate_of_ca(context, data_info->value, data_info->length);
- }
-
- /* if the CA_Uri is present, continue adding certificate from uri */
- if (chain_info->uri_present == true)
- {
- /* TODO : Need to implement */
- DEBUG_ERR_MSG("NOT IMPLEMENTED (found_root == false && chain_info->uri_present == true)");
- net_nfc_util_openssl_release_verify_certificate(context);
- _net_nfc_util_free_mem(buffer);
- return result;
-
-// DEBUG_MSG("certficate length : %d", data_info->length);
-// DEBUG_MSG_PRINT_BUFFER(data_info->value, data_info->length);
- }
-
- /* verify buffer with cert chain and signature bytes */
- if (net_nfc_util_openssl_verify_certificate(context) == true)
- result = NET_NFC_OK;
-
- net_nfc_util_openssl_release_verify_certificate(context);
- }
- else
- {
- /* TODO : test certificate??? */
- result = NET_NFC_OK;
- }
-
- DEBUG_MSG("verifying signature %d", result);
- }
- else
- {
- DEBUG_ERR_MSG("verifying signature failed");
- }
- }
- else
- {
- DEBUG_ERR_MSG("certificate not found");
- }
-
- _net_nfc_util_free_mem(buffer);
- }
- else
- {
- if(buffer != NULL)
- {
- _net_nfc_util_free_mem(buffer);
- }
- DEBUG_ERR_MSG("_get_records_data_buffer failed");
- }
-
- return result;
-}
-
-net_nfc_error_e net_nfc_util_verify_signature_ndef_message(ndef_message_s *msg)
-{
- net_nfc_error_e result = NET_NFC_UNKNOWN_ERROR;
- ndef_record_s *begin_record = NULL;
- ndef_record_s *current_record = NULL;
-
- begin_record = msg->records;
- current_record = msg->records;
-
- while (current_record != NULL)
- {
- if (begin_record == NULL)
- {
- begin_record = current_record;
- }
-
- if (IS_EMPTY_RECORD(current_record))
- {
- begin_record = NULL;
- }
- else if (IS_SIGN_RECORD(current_record))
- {
- result = net_nfc_util_verify_signature_records(begin_record, current_record);
-
- begin_record = NULL;
- }
-
- current_record = current_record->next;
- }
-
- return result;
-}
-
-/*
- * sign method
- */
-net_nfc_error_e net_nfc_util_sign_records(ndef_message_s *msg, int begin_index, int end_index, char *cert_file, char *password)
-{
- net_nfc_error_e result = NET_NFC_UNKNOWN_ERROR;
- ndef_record_s *begin_record = NULL, *end_record = NULL, *record = NULL;
- data_s payload = { NULL, 0 };
- uint8_t *data_buffer = NULL;
- uint32_t data_len = 0;
- uint8_t signature[1024] = { 0, };
- uint32_t sign_len = sizeof(signature);
- uint8_t *cert_buffer = NULL;
- uint32_t cert_len = 0;
- uint32_t cert_count = 0;
-
- net_nfc_util_get_record_by_index(msg, begin_index, &begin_record);
- net_nfc_util_get_record_by_index(msg, end_index, &end_record);
-
- DEBUG_MSG("total record count : %d, begin_index : %d, end_index : %d", msg->recordCount, begin_index, end_index);
-
- /* get target data */
- _get_records_data_buffer(begin_record, end_record->next, &data_buffer, &data_len);
-
- DEBUG_MSG_PRINT_BUFFER(data_buffer, data_len);
-
- net_nfc_util_openssl_sign_buffer(NET_NFC_SIGN_TYPE_PKCS_1, data_buffer, data_len, cert_file, password, signature, &sign_len);
-
- /* get cert chain */
- net_nfc_util_get_cert_list_from_file(cert_file, password, &cert_buffer, &cert_len, &cert_count);
-
- /* create payload */
- payload.length = sizeof(net_nfc_signature_record_s) + sign_len + sizeof(net_nfc_certificate_chain_s) + cert_len;
-
- _net_nfc_util_alloc_mem(payload.buffer, payload.length);
-
- net_nfc_signature_record_s *sign_record = (net_nfc_signature_record_s *)payload.buffer;
- sign_record->version = 1;
- sign_record->uri_present = 0;
- sign_record->sign_type = NET_NFC_SIGN_TYPE_PKCS_1;
-
- if (sign_record->uri_present)
- {
- /* TODO */
- }
- else
- {
- __FILL_SUB_FIELD(&(sign_record->signature), signature, sign_len);
- }
-
- net_nfc_certificate_chain_s *chain = (net_nfc_certificate_chain_s *)__NEXT_SUB_FIELD(&(sign_record->signature));
- if (cert_count < 16)
- {
- chain->uri_present = 0;
- }
- else
- {
- chain->uri_present = 1;
- }
-
- chain->cert_format = NET_NFC_CERT_FORMAT_X_509;
- chain->num_of_certs = cert_count;
- memcpy(chain->cert_store, cert_buffer, cert_len);
-
- if (chain->uri_present)
- {
- /* TODO */
- DEBUG_ERR_MSG("num_of_certs is greater than 15 [%d]", cert_count);
- }
-
- /* create record */
- data_s type = { (uint8_t *)"Sig", 3 };
-
- net_nfc_util_create_record(NET_NFC_RECORD_WELL_KNOWN_TYPE, &type, NULL, &payload, &record);
-
- /* get last record index */
- net_nfc_util_append_record_by_index(msg, end_index + 1, record);
-
- _net_nfc_util_free_mem(payload.buffer);
- _net_nfc_util_free_mem(cert_buffer);
- _net_nfc_util_free_mem(data_buffer);
-
- return result;
-}
-
-net_nfc_error_e net_nfc_util_sign_ndef_message(ndef_message_s *msg, char *cert_file, char *password)
-{
- net_nfc_error_e result = NET_NFC_UNKNOWN_ERROR;
-
- if (msg->recordCount > 0)
- {
- net_nfc_util_sign_records(msg, 0, msg->recordCount - 1, cert_file, password);
-
- result = NET_NFC_OK;
- }
-
- return result;
-}
+++ /dev/null
-# Package Information for pkg-config
-
-prefix=/usr
-exec_prefix=/usr/bin
-libdir=/usr/lib
-includedir=/usr/include/nfc-common-lib
-
-Name: nfc-common-lib
-Description: NFC Common Library
-Version: 1.0
-Requires:
-Libs: -L/usr/lib -lnfc-common-lib
-Cflags: -I/usr/include/nfc-common-lib
+++ /dev/null
-CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
-#PROJECT(nfc C)
-PROJECT(nfc-manager-daemon C)
-
-SET(NFC_MANAGER_DAEMON "nfc-manager-daemon")
-
-include_directories(${CMAKE_SOURCE_DIR}/src/commonlib/)
-include_directories(${CMAKE_SOURCE_DIR}/src/commonlib/include)
-include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
-
-AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/ MANAGER_SRCS)
-
-IF("${CMAKE_BUILD_TYPE}" STREQUAL "")
- SET(CMAKE_BUILD_TYPE "Release")
-ENDIF("${CMAKE_BUILD_TYPE}" STREQUAL "")
-
-INCLUDE(FindPkgConfig)
-pkg_check_modules(manager_pkges REQUIRED aul glib-2.0 gio-unix-2.0 security-server vconf dlog tapi appsvc libcurl bluetooth-api libssl svi capi-media-wav-player pkgmgr pkgmgr-info capi-network-wifi ecore-x pmapi)
-FOREACH(flag ${manager_pkges_CFLAGS})
- SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
-ENDFOREACH(flag)
-
-MESSAGE("CHECK MODULE in MANAGER ${manager_pkges_LDFLAGS}")
-
-# this for NFC flag
-
-SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -pipe -fomit-frame-pointer -Wall -Wno-trigraphs -Werror-implicit-function-declaration -fno-strict-aliasing -Wl,-zdefs -fvisibility=hidden")
-
-SET(ARM_CFLAGS "${ARM_CLAGS} -mapcs -mno-sched-prolog -mabi=aapcs-linux -Uarm -fno-common -fpic")
-
-SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror-implicit-function-declaration")
-
-SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
-SET(CMAKE_C_FLAGS_DEBUG "-O0 -g")
-
-FIND_PROGRAM(UNAME NAMES uname)
-EXEC_PROGRAM("${UNAME}" ARGS "-m" OUTPUT_VARIABLE "ARCH")
-IF("${ARCH}" MATCHES "^arm.*")
- ADD_DEFINITIONS("-DTARGET")
- MESSAGE("add -DTARGET")
- SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${ARM_CFLAGS}")
-ENDIF()
-
-ADD_DEFINITIONS("-DPREFIX=\"${PREFIX}\"")
-ADD_DEFINITIONS("-DNFC_MANAGER_MODULEDIR=\"${MODULEDIR}\"")
-
-ADD_DEFINITIONS("-DUSE_FULL_URI")
-#ADD_DEFINITIONS("-DESE_ALWAYS_ON")
-
-SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie")
-
-ADD_EXECUTABLE(${NFC_MANAGER_DAEMON} ${MANAGER_SRCS})
-
-TARGET_LINK_LIBRARIES(${NFC_MANAGER_DAEMON} ${manager_pkges_LDFLAGS} pthread dl rt nfc-common-lib nfc)
-LINK_DIRECTORIES(${CMAKE_BUILD_DIR}/src/commonlib ${CMAKE_BUILD_DIR}/src/clientlib)
-INSTALL(TARGETS ${NFC_MANAGER_DAEMON} DESTINATION bin)
-
-INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/org.tizen.NetNfcService.service DESTINATION share/dbus-1/services)
-INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/nfc-manager.xml DESTINATION share/packages)
-INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/sounds DESTINATION share/nfc-manager-daemon)
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef __NET_NFC_APP_UTIL_INTERNAL_H__
-#define __NET_NFC_APP_UTIL_INTERNAL_H__
-
-#include <aul.h>
-#include "net_nfc_typedef_internal.h"
-
-#ifndef MESSAGE_STORAGE
-#define MESSAGE_STORAGE "/opt/share/service/nfc-manager"
-#endif
-
-net_nfc_error_e net_nfc_app_util_store_ndef_message(data_s *data);
-net_nfc_error_e net_nfc_app_util_process_ndef(data_s *data);
-void net_nfc_app_util_aul_launch_app(char* package_name, bundle* kb);
-void net_nfc_app_util_clean_storage(char* src_path);
-bool net_nfc_app_util_is_dir(const char* path_name);
-int net_nfc_app_util_appsvc_launch(const char *operation, const char *uri, const char *mime, const char *data);
-int net_nfc_app_util_launch_se_transaction_app(uint8_t *aid, uint32_t aid_len, uint8_t *param, uint32_t param_len);
-int net_nfc_app_util_encode_base64(uint8_t *buffer, uint32_t buf_len, char *result, uint32_t max_result);
-int net_nfc_app_util_decode_base64(const char *buffer, uint32_t buf_len, uint8_t *result, uint32_t *res_len);
-bool net_nfc_app_util_check_launch_state();
-
-#endif //__NET_NFC_APP_UTIL_INTERNAL_H__
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef __NET_NFC_CONTROLLER_INTERNAL_H__
-#define __NET_NFC_CONTROLLER_INTERNAL_H__
-
-#include "net_nfc_typedef_internal.h"
-
-typedef struct _socket_info_t
-{
- net_nfc_llcp_socket_t socket;
- net_nfc_service_llcp_cb err_cb;
- net_nfc_service_llcp_cb work_cb;
- void *err_param;
- void *work_param;
-}
-socket_info_t;
-
-/* common api */
-void *net_nfc_controller_onload(void);
-bool net_nfc_controller_unload(void *handle);
-bool net_nfc_controller_init(net_nfc_error_e *result);
-bool net_nfc_controller_deinit(void);
-bool net_nfc_controller_register_listener(target_detection_listener_cb target_detection_listener, se_transaction_listener_cb se_transaction_listener, llcp_event_listener_cb llcp_event_listener, net_nfc_error_e* result);
-bool net_nfc_controller_unregister_listener(void);
-bool net_nfc_controller_support_nfc(net_nfc_error_e *result);
-bool net_nfc_controller_get_firmware_version(data_s **data, net_nfc_error_e *result);
-bool net_nfc_controller_check_firmware_version(net_nfc_error_e *result);
-bool net_nfc_controller_update_firmware(net_nfc_error_e *result);
-bool net_nfc_controller_get_stack_information(net_nfc_stack_information_s *stack_info, net_nfc_error_e *result);
-bool net_nfc_controller_configure_discovery (net_nfc_discovery_mode_e mode, net_nfc_event_filter_e config, net_nfc_error_e *result);
-bool net_nfc_controller_check_target_presence(net_nfc_target_handle_s *handle, net_nfc_error_e *result);
-bool net_nfc_controller_connect(net_nfc_target_handle_s *handle, net_nfc_error_e *result);
-bool net_nfc_controller_disconnect(net_nfc_target_handle_s *handle, net_nfc_error_e *result);
-bool net_nfc_controller_check_ndef(net_nfc_target_handle_s *handle, uint8_t *ndef_card_state, int *max_data_size, int *real_data_size, net_nfc_error_e *result);
-bool net_nfc_controller_read_ndef(net_nfc_target_handle_s *handle, data_s **data, net_nfc_error_e *result);
-bool net_nfc_controller_write_ndef(net_nfc_target_handle_s *handle, data_s *data, net_nfc_error_e *result);
-bool net_nfc_controller_make_read_only_ndef(net_nfc_target_handle_s *handle, net_nfc_error_e *result);
-bool net_nfc_controller_format_ndef(net_nfc_target_handle_s *handle, data_s *secure_key, net_nfc_error_e *result);
-bool net_nfc_controller_transceive (net_nfc_target_handle_s *handle, net_nfc_transceive_info_s *info, data_s **data, net_nfc_error_e *result);
-bool net_nfc_controller_exception_handler(void);
-bool net_nfc_controller_is_ready(net_nfc_error_e *result);
-
-/* llcp api */
-bool net_nfc_controller_llcp_config(net_nfc_llcp_config_info_s *config, net_nfc_error_e *result);
-bool net_nfc_controller_llcp_check_llcp(net_nfc_target_handle_s *handle, net_nfc_error_e *result);
-bool net_nfc_controller_llcp_activate_llcp(net_nfc_target_handle_s *handle, net_nfc_error_e *result);
-bool net_nfc_controller_llcp_create_socket(net_nfc_llcp_socket_t *socket, net_nfc_socket_type_e socketType, uint16_t miu, uint8_t rw, net_nfc_error_e *result, net_nfc_service_llcp_cb cb, void *user_param);
-bool net_nfc_controller_llcp_bind(net_nfc_llcp_socket_t socket, uint8_t service_access_point, net_nfc_error_e *result);
-bool net_nfc_controller_llcp_listen(net_nfc_target_handle_s* handle, uint8_t *service_access_name, net_nfc_llcp_socket_t socket, net_nfc_error_e *result, net_nfc_service_llcp_cb cb, void *user_param);
-bool net_nfc_controller_llcp_accept(net_nfc_llcp_socket_t socket, net_nfc_error_e *result, net_nfc_service_llcp_cb cb, void *user_param);
-bool net_nfc_controller_llcp_connect_by_url(net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, uint8_t *service_access_name, net_nfc_error_e *result, net_nfc_service_llcp_cb cb, void *user_param);
-bool net_nfc_controller_llcp_connect(net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, uint8_t service_access_point, net_nfc_error_e *result, net_nfc_service_llcp_cb cb, void *user_param);
-bool net_nfc_controller_llcp_disconnect(net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, net_nfc_error_e *result, net_nfc_service_llcp_cb cb, void *user_param);
-bool net_nfc_controller_llcp_socket_close(net_nfc_llcp_socket_t socket, net_nfc_error_e *result);
-bool net_nfc_controller_llcp_recv(net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, uint32_t max_len, net_nfc_error_e *result, net_nfc_service_llcp_cb cb, void *user_param);
-bool net_nfc_controller_llcp_send(net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, data_s *data, net_nfc_error_e *result, net_nfc_service_llcp_cb cb, void *user_param);
-bool net_nfc_controller_llcp_recv_from(net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, uint32_t max_len, net_nfc_error_e *result, net_nfc_service_llcp_cb cb, void *user_param);
-bool net_nfc_controller_llcp_send_to(net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, data_s *data, uint8_t service_access_point, net_nfc_error_e *result, net_nfc_service_llcp_cb cb, void *user_param);
-bool net_nfc_controller_llcp_reject(net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, net_nfc_error_e *result);
-bool net_nfc_controller_llcp_get_remote_config (net_nfc_target_handle_s *handle, net_nfc_llcp_config_info_s *config, net_nfc_error_e *result);
-bool net_nfc_controller_llcp_get_remote_socket_info (net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, net_nfc_llcp_socket_option_s *option, net_nfc_error_e *result);
-
-void net_nfc_controller_llcp_socket_error_cb(net_nfc_llcp_socket_t socket,
- net_nfc_error_e result, void *data, void *user_param);
-void net_nfc_controller_llcp_incoming_cb(net_nfc_llcp_socket_t socket,
- net_nfc_error_e result, void *data, void *user_param);
-void net_nfc_controller_llcp_connected_cb(net_nfc_llcp_socket_t socket,
- net_nfc_error_e result, void *data, void *user_param);
-void net_nfc_controller_llcp_disconnected_cb(net_nfc_llcp_socket_t socket,
- net_nfc_error_e result, void *data, void *user_param);
-void net_nfc_controller_llcp_received_cb(net_nfc_llcp_socket_t socket,
- net_nfc_error_e result, void *data, void *user_param);
-void net_nfc_controller_llcp_sent_cb(net_nfc_llcp_socket_t socket,
- net_nfc_error_e result, void *data, void *user_param);
-
-/* secure element api */
-bool net_nfc_controller_secure_element_open(net_nfc_secure_element_type_e element_type, net_nfc_target_handle_s **handle, net_nfc_error_e *result);
-bool net_nfc_controller_secure_element_get_atr(net_nfc_target_handle_s *handle, data_s **atr, net_nfc_error_e *result);
-bool net_nfc_controller_secure_element_send_apdu(net_nfc_target_handle_s *handle, data_s *command, data_s **response, net_nfc_error_e *result);
-bool net_nfc_controller_secure_element_close(net_nfc_target_handle_s *handle, net_nfc_error_e *result);
-bool net_nfc_controller_get_secure_element_list(net_nfc_secure_element_info_s* list, int* count, net_nfc_error_e* result);
-bool net_nfc_controller_set_secure_element_mode(net_nfc_secure_element_type_e element_type, net_nfc_secure_element_mode_e mode, net_nfc_error_e* result);
-
-/* test api */
-bool net_nfc_controller_sim_test(net_nfc_error_e *result);
-bool net_nfc_controller_prbs_test(net_nfc_error_e *result , uint32_t tech , uint32_t rate);
-bool net_nfc_controller_test_mode_on(net_nfc_error_e *result);
-bool net_nfc_controller_test_mode_off(net_nfc_error_e *result);
-bool net_nfc_test_sim(void);
-bool net_nfc_controller_eedata_register_set(net_nfc_error_e *result , uint32_t mode , uint32_t reg_id , data_s *data);
-
-socket_info_t *_get_socket_info(net_nfc_llcp_socket_t socket);
-socket_info_t *_add_socket_info(net_nfc_llcp_socket_t socket);
-
-#endif //__NET_NFC_CONTROLLER_INTERNAL_H__
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef __NET_NFC_MANAGER_H__
-#define __NET_NFC_MANAGER_H__
-
-void net_nfc_manager_quit();
-
-#endif //__NET_NFC_MANAGER_H__
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef __NET_NFC_MANAGER_UTIL_INTERNAL_H__
-#define __NET_NFC_MANAGER_UTIL_INTERNAL_H__
-
-#define NET_NFC_MANAGER_DATA_PATH "/opt/data/nfc-manager-daemon"
-#define NET_NFC_MANAGER_DATA_PATH_MESSAGE "message"
-#define NET_NFC_MANAGER_DATA_PATH_CONFIG "config"
-#define NET_NFC_MANAGER_NDEF_FILE_NAME "ndef-message.txt"
-#define NET_NFC_MANAGER_LLCP_CONFIG_FILE_NAME "nfc-manager-config.txt"
-
-#define NET_NFC_MANAGER_SOUND_PATH_TASK_START "/usr/share/nfc-manager-daemon/sounds/Operation_sdk.wav"
-#define NET_NFC_MANAGER_SOUND_PATH_TASK_END "/usr/share/nfc-manager-daemon/sounds/Operation_sdk.wav"
-#define NET_NFC_MANAGER_SOUND_PATH_TASK_ERROR "/usr/share/nfc-manager-daemon/sounds/Operation_sdk.wav"
-
-#define BUFFER_LENGTH_MAX 1024
-
-#define READ_BUFFER_LENGTH_MAX BUFFER_LENGTH_MAX
-#define WRITE_BUFFER_LENGTH_MAX BUFFER_LENGTH_MAX
-#define NET_NFC_MAX_LLCP_SOCKET_BUFFER BUFFER_LENGTH_MAX
-
-typedef enum
-{
- NET_NFC_TASK_START = 0x00,
- NET_NFC_TASK_END,
- NET_NFC_TASK_ERROR
-} net_nfc_sound_type_e;
-
-void net_nfc_manager_util_play_sound(net_nfc_sound_type_e sound_type);
-
-#endif //__NET_NFC_MANAGER_UTIL_INTERNAL_H__
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef __NET_NFC_SERVER_H__
-#define __NET_NFC_SERVER_H__
-
-void net_nfc_server_gdbus_init(void);
-
-void net_nfc_server_gdbus_deinit(void);
-
-pid_t net_nfc_server_gdbus_get_pid(const char *name);
-
-#endif //__NET_NFC_SERVER_H__
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef __NET_NFC_SERVER_COMMON_H__
-#define __NET_NFC_SERVER_COMMON_H__
-
-#include <glib.h>
-
-#include "net_nfc_typedef.h"
-
-typedef void (*net_nfc_server_controller_func)(gpointer user_data);
-
-gboolean net_nfc_server_controller_thread_init(void);
-
-void net_nfc_server_controller_thread_deinit(void);
-
-void net_nfc_server_controller_init(void);
-#ifndef ESE_ALWAYS_ON
-void net_nfc_server_controller_deinit(void);
-#endif
-gboolean net_nfc_server_controller_async_queue_push(
- net_nfc_server_controller_func func,
- gpointer user_data);
-
-void net_nfc_server_restart_polling_loop(void);
-
-void net_nfc_server_set_state(guint32 state);
-
-void net_nfc_server_unset_state(guint32 state);
-
-guint32 net_nfc_server_get_state(void);
-
-#endif //__NET_NFC_SERVER_COMMON_H__
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef __NET_NFC_SERVER_CONTEXT_INTERNAL_H__
-#define __NET_NFC_SERVER_CONTEXT_INTERNAL_H__
-
-#include <unistd.h>
-#include <glib.h>
-#include <gio/gio.h>
-
-#include "net_nfc_typedef_internal.h"
-
-typedef struct _net_nfc_client_context_info_t
-{
- /* Permanent property */
- char *id;
- pid_t pid;
- pid_t pgid;
-
- /* changed by client state */
- int ref_se;
- client_state_e state;
- net_nfc_launch_popup_state_e launch_popup_state;
- net_nfc_launch_popup_state_e launch_popup_state_no_check;
-
-} net_nfc_client_context_info_t;
-
-typedef void (*net_nfc_server_gdbus_for_each_client_cb)(
- net_nfc_client_context_info_t *client, void *user_param);
-
-void net_nfc_server_gdbus_init_client_context();
-
-void net_nfc_server_gdbus_deinit_client_context();
-
-bool net_nfc_server_gdbus_check_privilege(GDBusMethodInvocation *invocation,
- GVariant *privilege,
- const char *object,
- const char *right);
-
-void net_nfc_server_gdbus_add_client_context(const char *id,
- client_state_e state);
-
-void net_nfc_server_gdbus_cleanup_client_context(const char *id);
-
-net_nfc_client_context_info_t *net_nfc_server_gdbus_get_client_context(
- const char *id);
-
-size_t net_nfc_server_gdbus_get_client_count();
-
-void net_nfc_server_gdbus_for_each_client_context(
- net_nfc_server_gdbus_for_each_client_cb cb,
- void *user_param);
-
-bool net_nfc_server_gdbus_check_client_is_running(const char *id);
-
-client_state_e net_nfc_server_gdbus_get_client_state(
- const char *id);
-
-void net_nfc_server_gdbus_set_client_state(const char *id,
- client_state_e state);
-
-void net_nfc_server_gdbus_set_launch_state(const char *id,
- net_nfc_launch_popup_state_e popup_state,
- net_nfc_launch_popup_check_e check_foreground);
-
-net_nfc_launch_popup_state_e net_nfc_server_gdbus_get_launch_state(
- const char *id);
-
-net_nfc_launch_popup_state_e net_nfc_server_gdbus_get_client_popup_state(
- pid_t pid);
-
-void net_nfc_server_gdbus_increase_se_count(const char *id);
-void net_nfc_server_gdbus_decrease_se_count(const char *id);
-
-bool net_nfc_server_gdbus_is_server_busy();
-
-#endif //__NET_NFC_SERVER_CONTEXT_INTERNAL_H__
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef __NET_NFC_SERVER_HANDOVER_H__
-#define __NET_NFC_SERVER_HANDOVER_H__
-
-#include <gio/gio.h>
-#include "net_nfc_gdbus.h"
-#include "net_nfc_typedef_internal.h"
-
-
-typedef struct _HandoverRequestData HandoverRequestData;
-
-struct _HandoverRequestData
-{
- NetNfcGDbusHandover *handoverobj;
- GDBusMethodInvocation *invocation;
- guint32 handle;
- gint32 type;
- data_s *data;
-};
-
-gboolean net_nfc_server_handover_init(GDBusConnection *connection);
-
-void net_nfc_server_handover_deinit(void);
-
-
-#endif //__NET_NFC_SERVER_HANDOVER_H__
+++ /dev/null
-/*
- * Copyright (c) 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-#ifndef __NET_NFC_SERVER_HANDOVER_BSS_H__
-#define __NET_NFC_SERVER_HANDOVER_BSS_H__
-#include <gio/gio.h>
-#include <wifi.h>
-#include "net_nfc_debug_internal.h"
-#include "net_nfc_util_internal.h"
-#include "net_nfc_util_ndef_message.h"
-#include "net_nfc_util_ndef_record.h"
-#include "net_nfc_util_handover.h"
-#include "net_nfc_server_handover_internal.h"
-#include "net_nfc_server_llcp.h"
-
-typedef struct _net_nfc_handover_bss_process_context_t
-{
- int step;
- net_nfc_error_e result;
- net_nfc_server_handover_process_carrier_record_cb cb;
- ndef_record_s *carrier;
- data_s data;
- void *user_param;
- wifi_ap_h ap_handle;
- net_nfc_carrier_config_s *config;
-}
-net_nfc_handover_bss_process_context_t;
-
-net_nfc_error_e net_nfc_server_handover_bss_process_carrier_record(
- ndef_record_s *record,
- net_nfc_server_handover_process_carrier_record_cb cb,
- void *user_param);
-#endif //__NET_NFC_SERVER_HANDOVER_BSS_H__
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef __NET_NFC_SERVER_HANDOVER_INTERNAL_H__
-#define __NET_NFC_SERVER_HANDOVER_INTERNAL_H__
-
-#include "net_nfc_typedef_internal.h"
-
-typedef void (*net_nfc_server_handover_get_carrier_record_cb)(
- net_nfc_error_e result,
- net_nfc_conn_handover_carrier_state_e cps,
- ndef_record_s *carrier,
- uint32_t aux_data_count,
- ndef_record_s *aux_data,
- void *user_param);
-
-typedef void (*net_nfc_server_handover_process_carrier_record_cb)(
- net_nfc_error_e result,
- net_nfc_conn_handover_carrier_type_e type,
- data_s *data,
- void *user_param);
-
-
-/* alternative carrier functions */
-net_nfc_error_e net_nfc_server_handover_bt_get_carrier_record(
- net_nfc_server_handover_get_carrier_record_cb cb, void *user_param);
-
-net_nfc_error_e net_nfc_server_handover_bt_process_carrier_record(
- ndef_record_s *record, net_nfc_server_handover_process_carrier_record_cb cb,
- void *user_param);
-
-net_nfc_error_e net_nfc_server_handover_bt_post_process(
- data_s *data, net_nfc_server_handover_process_carrier_record_cb cb,
- void *user_param);
-
-
-
-/* handover server/client functions */
-net_nfc_error_e net_nfc_server_handover_default_server_start(
- net_nfc_target_handle_s *handle);
-
-net_nfc_error_e net_nfc_server_handover_default_client_start(
- net_nfc_target_handle_s *handle,
- void *user_data);
-
-#endif //__NET_NFC_SERVER_HANDOVER_INTERNAL_H__
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef __NET_NFC_SERVER_LLCP_H__
-#define __NET_NFC_SERVER_LLCP_H__
-
-#include <gio/gio.h>
-
-#include "net_nfc_typedef_internal.h"
-
-/* define */
-/* Service Name should be followed naming rule. */
-// service access name
-#define SDP_SAN "urn:nfc:sn:sdp"
-#define IP_SAN "urn:nfc:sn:ip"
-#define OBEX_SAN "urn:nfc:sn:obex"
-
-#define SDP_SAP 1 /* service discovery protocol service access point */
-#define IP_SAP 2 /* Internet protocol service access point */
-#define OBEX_SAP 3 /* object exchange service access point */
-
-#define GET_MAJOR_VER(__x) (((__x) >> 4) & 0x0F)
-#define GET_MINOR_VER(__x) ((__x) & 0x0F)
-
-/* default llcp configurations */
-#define NET_NFC_LLCP_MIU 128
-#define NET_NFC_LLCP_WKS 1
-#define NET_NFC_LLCP_LTO 10
-#define NET_NFC_LLCP_OPT 0
-
-typedef enum
-{
- NET_NFC_LLCP_IDLE = 0,
- NET_NFC_LLCP_STEP_01 = 0xFFFF,
- NET_NFC_LLCP_STEP_02,
- NET_NFC_LLCP_STEP_03,
- NET_NFC_LLCP_STEP_04,
- NET_NFC_LLCP_STEP_05,
- NET_NFC_LLCP_STEP_06,
- NET_NFC_LLCP_STEP_07,
- NET_NFC_LLCP_STEP_08,
- NET_NFC_LLCP_STEP_09,
- NET_NFC_LLCP_STEP_10,
- NET_NFC_LLCP_STEP_11,
- NET_NFC_LLCP_STEP_12,
- NET_NFC_LLCP_STEP_13,
- NET_NFC_LLCP_STEP_14,
- NET_NFC_LLCP_STEP_15,
- NET_NFC_LLCP_STEP_16,
- NET_NFC_LLCP_STEP_17,
- NET_NFC_LLCP_STEP_18,
- NET_NFC_LLCP_STEP_19,
- NET_NFC_LLCP_STEP_20,
- NET_NFC_LLCP_STEP_RETURN,
- NET_NFC_STATE_SOCKET_ERROR,
- NET_NFC_STATE_ERROR,
-} net_nfc_state_e;
-
-typedef void (*net_nfc_server_llcp_callback) (net_nfc_error_e result,
- net_nfc_target_handle_s *handle,
- net_nfc_llcp_socket_t socket,
- data_s *data,
- gpointer user_data);
-
-typedef void (*net_nfc_server_llcp_activate_cb)(
- int event,
- net_nfc_target_handle_s *handle,
- uint32_t sap,
- const char *san,
- void *user_param);
-
-gboolean net_nfc_server_llcp_init(GDBusConnection *connection);
-
-void net_nfc_server_llcp_deinit(void);
-
-/* server side */
-void net_nfc_server_llcp_deactivated(net_nfc_request_msg_t *req_msg);
-
-void net_nfc_server_llcp_listen(net_nfc_request_msg_t *req_msg);
-
-void net_nfc_server_llcp_socket_error(net_nfc_request_msg_t *req_msg);
-
-void net_nfc_server_llcp_socket_accepted_error(net_nfc_request_msg_t *req_msg);
-
-void net_nfc_server_llcp_send(net_nfc_request_msg_t *req_msg);
-
-void net_nfc_server_llcp_receive(net_nfc_request_msg_t *req_msg);
-
-void net_nfc_server_llcp_receive_from(net_nfc_request_msg_t *req_msg);
-
-void net_nfc_server_llcp_connect(net_nfc_request_msg_t *req_msg);
-
-void net_nfc_server_llcp_disconnect(net_nfc_request_msg_t *req_msg);
-
-net_nfc_error_e net_nfc_server_llcp_set_config(
- net_nfc_llcp_config_info_s *config);
-
-guint16 net_nfc_server_llcp_get_miu(void);
-
-guint16 net_nfc_server_llcp_get_wks(void);
-
-guint8 net_nfc_server_llcp_get_lto(void);
-
-guint8 net_nfc_server_llcp_get_option(void);
-
-void net_nfc_server_llcp_target_detected(void *info);
-
-net_nfc_error_e net_nfc_server_llcp_simple_server(
- net_nfc_target_handle_s *handle,
- const char *san,
- sap_t sap,
- net_nfc_server_llcp_callback callback,
- net_nfc_server_llcp_callback error_callback,
- gpointer user_data);
-
-net_nfc_error_e net_nfc_server_llcp_simple_client(
- net_nfc_target_handle_s *handle,
- const char *san,
- sap_t sap,
- net_nfc_server_llcp_callback callback,
- net_nfc_server_llcp_callback error_callback,
- gpointer user_data);
-
-net_nfc_error_e net_nfc_server_llcp_simple_accept(
- net_nfc_target_handle_s *handle,
- net_nfc_llcp_socket_t socket,
- net_nfc_server_llcp_callback error_callback,
- gpointer user_data);
-
-net_nfc_error_e net_nfc_server_llcp_simple_send(
- net_nfc_target_handle_s *handle,
- net_nfc_llcp_socket_t socket,
- data_s *data,
- net_nfc_server_llcp_callback callback,
- gpointer user_data);
-
-net_nfc_error_e net_nfc_server_llcp_simple_receive(
- net_nfc_target_handle_s *handle,
- net_nfc_llcp_socket_t socket,
- net_nfc_server_llcp_callback callback,
- gpointer user_data);
-
-net_nfc_error_e net_nfc_server_llcp_register_service(const char *id,
- sap_t sap, const char *san, net_nfc_server_llcp_activate_cb cb,
- void *user_param);
-
-net_nfc_error_e net_nfc_server_llcp_unregister_service(const char *id,
- sap_t sap, const char *san);
-
-net_nfc_error_e net_nfc_server_llcp_unregister_services(const char *id);
-
-net_nfc_error_e net_nfc_server_llcp_unregister_all();
-
-net_nfc_error_e net_nfc_server_llcp_start_registered_services(
- net_nfc_target_handle_s *handle);
-
-#endif //__NET_NFC_SERVER_LLCP_H__
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef __NET_NFC_SERVER_MANAGER_H__
-#define __NET_NFC_SERVER_MANAGER_H__
-
-#include <gio/gio.h>
-
-gboolean net_nfc_server_manager_init(GDBusConnection *connection);
-
-void net_nfc_server_manager_deinit(void);
-
-void net_nfc_server_manager_set_active(gboolean is_active);
-
-bool net_nfc_server_manager_get_active();
-
-#endif //__NET_NFC_SERVER_MANAGER_H__
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef __NET_NFC_SERVER_NDEF_H__
-#define __NET_NFC_SERVER_NDEF_H__
-
-#include <gio/gio.h>
-
-gboolean net_nfc_server_ndef_init(GDBusConnection *connection);
-
-void net_nfc_server_ndef_deinit(void);
-
-#endif //__NET_NFC_SERVER_NDEF_H__
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef __NET_NFC_SERVER_P2P_H__
-#define __NET_NFC_SERVER_P2P_H__
-
-#include <gio/gio.h>
-
-#include "net_nfc_typedef_internal.h"
-
-gboolean net_nfc_server_p2p_init(GDBusConnection *connection);
-
-void net_nfc_server_p2p_deinit(void);
-
-/* server side */
-void net_nfc_server_p2p_detached(void);
-
-void net_nfc_server_p2p_discovered(net_nfc_target_handle_h handle);
-
-void net_nfc_server_p2p_received(data_h user_data);
-
-void net_nfc_server_p2p_data_sent(net_nfc_error_e result, gpointer user_data);
-
-#endif //__NET_NFC_SERVER_P2P_H__
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef __NET_NFC_SERVER_PROCESS_HANDOVER_H__
-#define __NET_NFC_SERVER_PROCESS_HANDOVER_H__
-
-#include "net_nfc_typedef_internal.h"
-
-net_nfc_error_e net_nfc_server_handover_default_server_start(
- net_nfc_target_handle_s *handle);
-
-net_nfc_error_e net_nfc_server_handover_default_client_start(
- net_nfc_target_handle_s *handle,
- void *user_data);
-
-net_nfc_error_e net_nfc_server_handover_default_server_register();
-
-net_nfc_error_e net_nfc_server_handover_default_server_unregister();
-
-net_nfc_error_e _net_nfc_server_handover_create_selector_from_rawdata(
- ndef_message_s **selector,
- data_s *data);
-
-net_nfc_error_e
-_net_nfc_server_handover_get_carrier_record_by_priority_order(
- ndef_message_s *request,
- ndef_record_s **record);
-
-net_nfc_error_e _net_nfc_server_handover_process_carrier_record(
- ndef_record_s *carrier,
- void *cb,
- void *user_param);
-
-#endif //__NET_NFC_SERVER_PROCESS_HANDOVER_H__
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef __NET_NFC_SERVER_PROCESS_NPP_H__
-#define __NET_NFC_SERVER_PROCESS_NPP_H__
-
-#include <glib.h>
-
-#include "net_nfc_typedef.h"
-#include "net_nfc_typedef_internal.h"
-
-typedef void (*net_nfc_server_npp_callback) (net_nfc_error_e result,
- data_s *data,
- gpointer user_data);
-
-net_nfc_error_e net_nfc_server_npp_server(net_nfc_target_handle_s *handle,
- char *san,
- sap_t sap,
- net_nfc_server_npp_callback callback,
- gpointer user_data);
-
-net_nfc_error_e net_nfc_server_npp_client(net_nfc_target_handle_s *handle,
- char *san,
- sap_t sap,
- data_s *data,
- net_nfc_server_npp_callback callback,
- gpointer user_data);
-
-net_nfc_error_e net_nfc_server_npp_default_server_start(
- net_nfc_target_handle_s *handle);
-
-net_nfc_error_e net_nfc_server_npp_default_client_start(
- net_nfc_target_handle_s *handle,
- data_s *data,
- int client,
- gpointer user_data);
-
-net_nfc_error_e net_nfc_server_npp_default_server_register();
-
-net_nfc_error_e net_nfc_server_npp_default_server_unregister();
-
-#endif //__NET_NFC_SERVER_PROCESS_NPP_H__
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef __NET_NFC_SERVER_PROCESS_SNEP_H__
-#define __NET_NFC_SERVER_PROCESS_SNEP_H__
-
-#include "net_nfc_gdbus.h"
-#include "net_nfc_typedef_internal.h"
-
-#define SNEP_SAN "urn:nfc:sn:snep"
-#define SNEP_SAP 4
-
-typedef enum
-{
- SNEP_REQ_CONTINUE = 0x00,
- SNEP_REQ_GET = 0x01,
- SNEP_REQ_PUT = 0x02,
- SNEP_REQ_REJECT = 0x7F,
- SNEP_RESP_CONT = 0x80,
- SNEP_RESP_SUCCESS = 0x81,
- SNEP_RESP_NOT_FOUND = 0xC0,
- SNEP_RESP_EXCESS_DATA = 0xC1,
- SNEP_RESP_BAD_REQ = 0xC2,
- SNEP_RESP_NOT_IMPLEMENT = 0xE0,
- SNEP_RESP_UNSUPPORTED_VER = 0xE1,
- SNEP_RESP_REJECT = 0xFF,
-} snep_command_field_e;
-
-typedef bool (*net_nfc_server_snep_listen_cb)(net_nfc_snep_handle_h handle,
- uint32_t type,
- uint32_t max_len,
- data_s *data,
- void *user_param);
-
-typedef net_nfc_error_e (*net_nfc_server_snep_cb)(net_nfc_snep_handle_h handle,
- net_nfc_error_e result,
- uint32_t type,
- data_s *data,
- void *user_param);
-
-net_nfc_error_e net_nfc_server_snep_server(
- net_nfc_target_handle_s *handle,
- const char *san,
- sap_t sap,
- net_nfc_server_snep_cb cb,
- void *user_param);
-
-net_nfc_error_e net_nfc_server_snep_client(
- net_nfc_target_handle_s *handle,
- const char *san,
- sap_t sap,
- net_nfc_server_snep_cb cb,
- void *user_param);
-
-net_nfc_error_e net_nfc_server_snep_server_send_get_response(
- net_nfc_snep_handle_h snep_handle,
- data_s *data);
-
-net_nfc_error_e net_nfc_server_snep_client_request(
- net_nfc_snep_handle_h snep,
- uint8_t type,
- data_s *data,
- net_nfc_server_snep_cb cb,
- void *user_param);
-
-net_nfc_error_e net_nfc_server_snep_default_server_start(
- net_nfc_target_handle_s *handle);
-
-net_nfc_error_e net_nfc_server_snep_default_client_start(
- net_nfc_target_handle_s *handle,
- int type,
- data_s *data,
- int client,
- void *user_param);
-
-net_nfc_error_e
-net_nfc_server_snep_default_server_register_get_response_cb(
- net_nfc_server_snep_listen_cb cb,
- void *user_param);
-
-net_nfc_error_e
-net_nfc_server_snep_default_server_unregister_get_response_cb(
- net_nfc_server_snep_listen_cb cb);
-
-net_nfc_error_e
-net_nfc_server_snep_default_server_send_get_response(
- net_nfc_snep_handle_h snep_handle,
- data_s *data);
-
-net_nfc_error_e net_nfc_server_snep_default_server_register();
-
-net_nfc_error_e net_nfc_server_snep_default_server_unregister();
-
-net_nfc_error_e net_nfc_server_snep_parse_get_request(data_s *request,
- size_t *max_len, data_s *message);
-
-#endif //__NET_NFC_SERVER_PROCESS_SNEP_H__
\ No newline at end of file
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef __NET_NFC_SERVER_SE_H__
-#define __NET_NFC_SERVER_SE_H__
-
-#include <gio/gio.h>
-
-#include "net_nfc_typedef_internal.h"
-
-
-/***************************************************************/
-
-uint8_t net_nfc_server_se_get_se_type();
-
-uint8_t net_nfc_server_se_get_se_mode();
-
-net_nfc_error_e net_nfc_server_se_change_se(uint8_t type);
-
-/***************************************************************/
-
-gboolean net_nfc_server_se_init(GDBusConnection *connection);
-
-void net_nfc_server_se_deinit(void);
-
-void net_nfc_server_se_detected(void *info);
-
-void net_nfc_server_se_transaction_received(void *info);
-
-#endif //__NET_NFC_SERVER_SE_H__
\ No newline at end of file
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef __NET_NFC_SERVER_SNEP_H__
-#define __NET_NFC_SERVER_SNEP_H__
-
-#include "net_nfc_gdbus.h"
-#include "net_nfc_typedef_internal.h"
-
-gboolean net_nfc_server_snep_init(GDBusConnection *connection);
-
-void net_nfc_server_snep_deinit(void);
-
-#endif //__NET_NFC_SERVER_SNEP_H__
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef __NET_NFC_SERVER_SYSTEM_HANDLER_H__
-#define __NET_NFC_SERVER_SYSTEM_HANDLER_H__
-
-#include <gio/gio.h>
-
-gboolean net_nfc_server_system_handler_init(GDBusConnection *connection);
-
-void net_nfc_server_system_handler_deinit(void);
-
-#endif //__NET_NFC_SERVER_SYSTEM_HANDLER_H__
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef __NET_NFC_SERVER_TAG_H__
-#define __NET_NFC_SERVER_TAG_H__
-
-#include <gio/gio.h>
-
-#include "net_nfc_typedef_internal.h"
-
-gboolean net_nfc_server_tag_init(GDBusConnection *connection);
-
-void net_nfc_server_tag_deinit(void);
-
-void net_nfc_server_set_target_info(void *info);
-
-net_nfc_current_target_info_s *net_nfc_server_get_target_info(void);
-
-gboolean net_nfc_server_target_connected(net_nfc_target_handle_s *handle);
-
-void net_nfc_server_free_target_info(void);
-
-void net_nfc_server_tag_target_detected(void *info);
-
-#endif //__NET_NFC_SERVER_TAG_H__
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef __NET_NFC_SERVER_TEST_H__
-#define __NET_NFC_SERVER_TEST_H__
-
-#include <gio/gio.h>
-
-gboolean net_nfc_server_test_init(GDBusConnection *connection);
-
-void net_nfc_server_test_deinit(void);
-
-#endif //__NET_NFC_SERVER_TEST_H__
\ No newline at end of file
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef __NET_NFC_SERVER_TRANSCEIVE_H__
-#define __NET_NFC_SERVER_TRANSCEIVE_H__
-
-#include <gio/gio.h>
-
-gboolean net_nfc_server_transceive_init(GDBusConnection *connection);
-
-void net_nfc_server_transceive_deinit(void);
-
-#endif //__NET_NFC_SERVER_TRANSCEIVE_H__
\ No newline at end of file
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef __NET_NFC_SERVER_VCONF_H__
-#define __NET_NFC_SERVER_VCONF_H__
-
-void net_nfc_server_vconf_init(void);
-
-void net_nfc_server_vconf_deinit(void);
-
-#endif //__NET_NFC_SERVER_VCONF_H__
\ No newline at end of file
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
-
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-#include <dirent.h>
-#include <pwd.h>
-#include <grp.h>
-#include <sys/stat.h>
-#include <time.h>
-#include <sys/time.h>
-#include <pthread.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <curl/curl.h>
-#include <glib.h>
-#include <openssl/evp.h>
-#include <openssl/bio.h>
-#include <openssl/buffer.h>
-
-#include "appsvc.h"
-#include "aul.h"
-#include "vconf.h"
-#include "Ecore_X.h"
-
-#include "net_nfc_typedef.h"
-#include "net_nfc_typedef_internal.h"
-#include "net_nfc_debug_internal.h"
-#include "net_nfc_util_defines.h"
-#include "net_nfc_util_internal.h"
-#include "net_nfc_util_ndef_message.h"
-#include "net_nfc_util_ndef_record.h"
-#include "net_nfc_manager_util_internal.h"
-#include "net_nfc_app_util_internal.h"
-#include "net_nfc_server_context_internal.h"
-#include "net_nfc_server_se.h"
-//#include "syspopup_caller.h"
-
-#define OSP_K_COND "__OSP_COND_NAME__"
-#define OSP_K_COND_TYPE "nfc"
-#define OSP_K_LAUNCH_TYPE "__OSP_LAUNCH_TYPE__"
-
-static bool _net_nfc_app_util_get_operation_from_record(ndef_record_s *record, char *operation, size_t length);
-static bool _net_nfc_app_util_get_mime_from_record(ndef_record_s *record, char *mime, size_t length);
-#ifdef USE_FULL_URI
-static bool _net_nfc_app_util_get_uri_from_record(ndef_record_s *record, char *uri, size_t length);
-#endif
-static bool _net_nfc_app_util_get_data_from_record(ndef_record_s *record, char *data, size_t length);
-
-static const char osp_launch_type_condition[] = "condition";
-
-net_nfc_error_e net_nfc_app_util_process_ndef(data_s *data)
-{
- net_nfc_error_e result = NET_NFC_UNKNOWN_ERROR;
- ndef_message_s *msg = NULL;
- char operation[2048] = { 0, };
- char mime[2048] = { 0, };
- char text[2048] = { 0, };
-#ifdef USE_FULL_URI
- char uri[2048] = { 0, };
-#endif
- int ret = 0;
-
- if (data == NULL || data->buffer == NULL || data->length == 0)
- {
- DEBUG_ERR_MSG("net_nfc_app_util_process_ndef NET_NFC_NULL_PARAMETER");
- return NET_NFC_NULL_PARAMETER;
- }
-
- /* create file */
- if ((result = net_nfc_app_util_store_ndef_message(data)) != NET_NFC_OK)
- {
- DEBUG_ERR_MSG("net_nfc_app_util_store_ndef_message failed [%d]", result);
- return result;
- }
-
- /* check state of launch popup */
- if(net_nfc_app_util_check_launch_state() == TRUE)
- {
- DEBUG_SERVER_MSG("skip launch popup!!!");
- result = NET_NFC_OK;
- return result;
- }
-
- if (net_nfc_util_create_ndef_message(&msg) != NET_NFC_OK)
- {
- DEBUG_ERR_MSG("memory alloc fail..");
- return NET_NFC_ALLOC_FAIL;
- }
-
- /* parse ndef message and fill appsvc data */
- if ((result = net_nfc_util_convert_rawdata_to_ndef_message(data, msg)) != NET_NFC_OK)
- {
- DEBUG_ERR_MSG("net_nfc_app_util_store_ndef_message failed [%d]", result);
- goto ERROR;
- }
-
- if (_net_nfc_app_util_get_operation_from_record(msg->records, operation, sizeof(operation)) == FALSE)
- {
- DEBUG_ERR_MSG("_net_nfc_app_util_get_operation_from_record failed [%d]", result);
- result = NET_NFC_UNKNOWN_ERROR;
- goto ERROR;
- }
-
- if (_net_nfc_app_util_get_mime_from_record(msg->records, mime, sizeof(mime)) == FALSE)
- {
- DEBUG_ERR_MSG("_net_nfc_app_util_get_mime_from_record failed [%d]", result);
- result = NET_NFC_UNKNOWN_ERROR;
- goto ERROR;
- }
-#ifdef USE_FULL_URI
- if (_net_nfc_app_util_get_uri_from_record(msg->records, uri, sizeof(uri)) == FALSE)
- {
- DEBUG_ERR_MSG("_net_nfc_app_util_get_uri_from_record failed [%d]", result);
- result = NET_NFC_UNKNOWN_ERROR;
- goto ERROR;
- }
-#endif
- /* launch appsvc */
- if (_net_nfc_app_util_get_data_from_record(msg->records, text, sizeof(text)) == FALSE)
- {
- DEBUG_ERR_MSG("_net_nfc_app_util_get_data_from_record failed [%d]", result);
- result = NET_NFC_UNKNOWN_ERROR;
- goto ERROR;
- }
-
- ret = net_nfc_app_util_appsvc_launch(operation, uri, mime, text);
-#if 0
- if (ret == APPSVC_RET_ENOMATCH)
- {
- /* TODO : check again */
- ret = net_nfc_app_util_appsvc_launch(operation, uri, mime, text);
- }
-#endif
-
- DEBUG_SERVER_MSG("net_nfc_app_util_appsvc_launch return %d", ret);
-
- result = NET_NFC_OK;
-
-ERROR :
- net_nfc_util_free_ndef_message(msg);
-
- return result;
-}
-
-bool _net_nfc_app_util_change_file_owner_permission(FILE *file)
-{
- char *buffer = NULL;
- size_t buffer_len = 0;
- struct passwd pwd = { 0, };
- struct passwd *pw_inhouse = NULL;
- struct group grp = { 0, };
- struct group *gr_inhouse = NULL;
-
- if (file == NULL)
- return false;
-
- /* change permission */
- fchmod(fileno(file), 0777);
-
- /* change owner */
- /* get passwd id */
- buffer_len = sysconf(_SC_GETPW_R_SIZE_MAX);
- if (buffer_len == -1)
- {
- buffer_len = 16384;
- }
-
- _net_nfc_util_alloc_mem(buffer, buffer_len);
- if (buffer == NULL)
- return false;
-
- getpwnam_r("inhouse", &pwd, buffer, buffer_len, &pw_inhouse);
- _net_nfc_util_free_mem(buffer);
-
- /* get group id */
- buffer_len = sysconf(_SC_GETGR_R_SIZE_MAX);
- if (buffer_len == -1)
- {
- buffer_len = 16384;
- }
-
- _net_nfc_util_alloc_mem(buffer, buffer_len);
- if (buffer == NULL)
- return false;
-
- getgrnam_r("inhouse", &grp, buffer, buffer_len, &gr_inhouse);
- _net_nfc_util_free_mem(buffer);
-
- if ((pw_inhouse != NULL) && (gr_inhouse != NULL))
- {
- if (fchown(fileno(file), pw_inhouse->pw_uid, gr_inhouse->gr_gid) < 0)
- {
- DEBUG_ERR_MSG("failed to change owner");
- }
- }
-
- return true;
-}
-
-net_nfc_error_e net_nfc_app_util_store_ndef_message(data_s *data)
-{
- net_nfc_error_e result = NET_NFC_UNKNOWN_ERROR;
- char file_name[1024] = { 0, };
- struct stat st;
- FILE *fp = NULL;
-
- if (data == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
-
- /* check and make directory */
- snprintf(file_name, sizeof(file_name), "%s/%s", NET_NFC_MANAGER_DATA_PATH,
- NET_NFC_MANAGER_DATA_PATH_MESSAGE);
-
- if (stat(file_name, &st) == -1)
- {
- int result;
- char command[1024];
-
- SECURE_LOGD("path doesn't exist, do mkdir : %s", file_name);
-
- snprintf(command, sizeof(command), "mkdir -p -m 755 %s", file_name);
-
- result = system(command);
-
- if (stat(file_name, &st) == -1)
- {
- DEBUG_ERR_MSG("mkdir failed");
- return NET_NFC_UNKNOWN_ERROR;
- }
- }
-
- /* create file */
- snprintf(file_name, sizeof(file_name), "%s/%s/%s", NET_NFC_MANAGER_DATA_PATH,
- NET_NFC_MANAGER_DATA_PATH_MESSAGE, NET_NFC_MANAGER_NDEF_FILE_NAME);
- SECURE_LOGD("file path : %s", file_name);
-
- unlink(file_name);
-
- if ((fp = fopen(file_name, "w")) != NULL)
- {
- int length = 0;
-
- if ((length = fwrite(data->buffer, 1, data->length, fp)) > 0)
- {
- DEBUG_SERVER_MSG("[%d] bytes is written", length);
-
- _net_nfc_app_util_change_file_owner_permission(fp);
-
- fflush(fp);
- fsync(fileno(fp));
-
- result = NET_NFC_OK;
- }
- else
- {
- DEBUG_ERR_MSG("write is failed = [%d]", data->length);
- result = NET_NFC_UNKNOWN_ERROR;
- }
-
- fclose(fp);
- }
-
- return result;
-}
-
-bool net_nfc_app_util_is_dir(const char* path_name)
-{
- struct stat statbuf = { 0 };
-
- if (stat(path_name, &statbuf) == -1)
- {
- return false;
- }
-
- if (S_ISDIR(statbuf.st_mode) != 0)
- {
- return true;
- }
- else
- {
- return false;
- }
-}
-
-void net_nfc_app_util_clean_storage(char* src_path)
-{
- struct dirent* ent = NULL;
- DIR* dir = NULL;
-
- char path[1024] = { 0 };
-
- if ((dir = opendir(src_path)) == NULL)
- {
- return;
- }
-
- while ((ent = readdir(dir)) != NULL)
- {
- if (strncmp(ent->d_name, ".", 1) == 0 || strncmp(ent->d_name, "..", 2) == 0)
- {
- continue;
- }
- else
- {
- snprintf(path, 1024, "%s/%s", src_path, ent->d_name);
-
- if (net_nfc_app_util_is_dir(path) != false)
- {
- net_nfc_app_util_clean_storage(path);
- rmdir(path);
- }
- else
- {
- unlink(path);
- }
- }
- }
-
- closedir(dir);
-
- rmdir(src_path);
-}
-
-static void _to_lower_utf_8(char *str)
-{
- while (*str != 0)
- {
- if (*str >= 'A' && *str <= 'Z')
- *str += ('a' - 'A');
-
- str++;
- }
-}
-
-static void _to_lower(int type, char *str)
-{
- _to_lower_utf_8(str);
-}
-
-static bool _net_nfc_app_util_get_operation_from_record(ndef_record_s *record, char *operation, size_t length)
-{
- bool result = false;
- char *op_text = NULL;
-
- if (record == NULL || operation == NULL || length == 0)
- {
- return result;
- }
-
- switch (record->TNF)
- {
- case NET_NFC_RECORD_WELL_KNOWN_TYPE :
- op_text = "http://tizen.org/appcontrol/operation/nfc/wellknown";
- break;
-
- case NET_NFC_RECORD_MIME_TYPE :
- op_text = "http://tizen.org/appcontrol/operation/nfc/mime";
- break;
-
- case NET_NFC_RECORD_URI : /* Absolute URI */
- op_text = "http://tizen.org/appcontrol/operation/nfc/uri";
- break;
-
- case NET_NFC_RECORD_EXTERNAL_RTD : /* external type */
- op_text = "http://tizen.org/appcontrol/operation/nfc/external";
- break;
-
- case NET_NFC_RECORD_EMPTY : /* empty_tag */
- op_text = "http://tizen.org/appcontrol/operation/nfc/empty";
- break;
-
- case NET_NFC_RECORD_UNKNOWN : /* unknown msg. discard it */
- case NET_NFC_RECORD_UNCHAGNED : /* RFU msg. discard it */
- default :
- break;
- }
-
- if (op_text != NULL)
- {
- snprintf(operation, length, "%s", op_text);
- result = TRUE;
- }
-
- return result;
-}
-
-static bool _net_nfc_app_util_get_mime_from_record(ndef_record_s *record, char *mime, size_t length)
-{
- bool result = false;
-
- if (record == NULL || mime == NULL || length == 0)
- {
- return result;
- }
-
- switch (record->TNF)
- {
- case NET_NFC_RECORD_WELL_KNOWN_TYPE :
- {
- if (record->type_s.buffer == NULL || record->type_s.length == 0 ||
- record->payload_s.buffer == NULL || record->payload_s.length == 0)
- {
- DEBUG_ERR_MSG("Broken NDEF Message [NET_NFC_RECORD_WELL_KNOWN_TYPE]");
- break;
- }
-
- if (record->type_s.length == 1 && record->type_s.buffer[0] == 'U')
- {
- snprintf(mime, length, "U/0x%02x", record->payload_s.buffer[0]);
- }
- else
- {
- memcpy(mime, record->type_s.buffer, record->type_s.length);
- mime[record->type_s.length] = '\0';
-
- strncat(mime, "/*", 2);
- mime[record->type_s.length + 2] = '\0';
- }
-
- //DEBUG_SERVER_MSG("mime [%s]", mime);
-
- result = true;
- }
- break;
-
- case NET_NFC_RECORD_MIME_TYPE :
- {
- char *token = NULL;
- char *buffer = NULL;
- int len = 0;
-
- if (record->type_s.buffer == NULL || record->type_s.length == 0)
- {
- DEBUG_ERR_MSG("Broken NDEF Message [NET_NFC_RECORD_MIME_TYPE]");
- break;
- }
-
- /* get mime type */
- _net_nfc_util_alloc_mem(buffer, record->type_s.length + 1);
- if (buffer == NULL)
- {
- DEBUG_ERR_MSG("_net_nfc_manager_util_alloc_mem return NULL");
- break;
- }
- memcpy(buffer, record->type_s.buffer, record->type_s.length);
-
- //DEBUG_SERVER_MSG("NET_NFC_RECORD_MIME_TYPE type [%s]", buffer);
-
- token = strchr(buffer, ';');
- if (token != NULL)
- {
- //DEBUG_SERVER_MSG("token = strchr(buffer, ';') != NULL, len [%d]", token - buffer);
- len = MIN(token - buffer, length - 1);
- }
- else
- {
- len = MIN(strlen(buffer), length - 1);
- }
-
- //DEBUG_SERVER_MSG("len [%d]", len);
-
- strncpy(mime, buffer, len);
- mime[len] = '\0';
-
- _to_lower(0, mime);
-
- //DEBUG_SERVER_MSG("mime [%s]", mime);
-
- _net_nfc_util_free_mem(buffer);
-
- result = true;
- }
- break;
-
- case NET_NFC_RECORD_URI : /* Absolute URI */
- case NET_NFC_RECORD_EXTERNAL_RTD : /* external type */
- case NET_NFC_RECORD_EMPTY : /* empty_tag */
- result = true;
- break;
-
- case NET_NFC_RECORD_UNKNOWN : /* unknown msg. discard it */
- case NET_NFC_RECORD_UNCHAGNED : /* RFU msg. discard it */
- default :
- break;
- }
-
- return result;
-}
-
-#ifdef USE_FULL_URI
-static bool _net_nfc_app_util_get_uri_from_record(ndef_record_s *record, char *data, size_t length)
-{
- bool result = false;
-
- if (record == NULL || data == NULL || length == 0)
- {
- return result;
- }
-
- switch (record->TNF)
- {
- case NET_NFC_RECORD_WELL_KNOWN_TYPE :
- case NET_NFC_RECORD_URI : /* Absolute URI */
- {
- char *uri = NULL;
-
- if (net_nfc_util_create_uri_string_from_uri_record(record, &uri) == NET_NFC_OK &&
- uri != NULL)
- {
- //DEBUG_SERVER_MSG("uri record : %s", uri);
- snprintf(data, length, "%s", uri);
-
- _net_nfc_util_free_mem(uri);
- }
- result = true;
- }
- break;
-
- case NET_NFC_RECORD_EXTERNAL_RTD : /* external type */
- {
- data_s *type = &record->type_s;
-
- if (type->length > 0)
- {
-#if 0
- char *buffer = NULL;
- int len = strlen(NET_NFC_UTIL_EXTERNAL_TYPE_SCHEME);
-
- _net_nfc_util_alloc_mem(buffer, type->length + len + 1);
- if (buffer != NULL)
- {
- memcpy(buffer, NET_NFC_UTIL_EXTERNAL_TYPE_SCHEME, len);
- memcpy(buffer + len, type->buffer, type->length);
-
- /* to lower case!! */
- strlwr(buffer);
-
- DEBUG_SERVER_MSG("uri record : %s", buffer);
- snprintf(data, length, "%s", buffer);
-
- _net_nfc_util_free_mem(buffer);
- }
-#else
- int len = MIN(type->length, length - 1);
- memcpy(data, type->buffer, len);
- data[len] = 0;
-
- /* to lower case!! */
- _to_lower(0, data);
-
- //DEBUG_SERVER_MSG("uri record : %s", data);
- result = true;
-#endif
- }
- }
- break;
-
- case NET_NFC_RECORD_MIME_TYPE :
- case NET_NFC_RECORD_EMPTY : /* empy msg. discard it */
- result = true;
- break;
-
- case NET_NFC_RECORD_UNKNOWN : /* unknown msg. discard it */
- case NET_NFC_RECORD_UNCHAGNED : /* RFU msg. discard it */
- default :
- break;
- }
-
- return result;
-}
-#endif
-
-static bool _net_nfc_app_util_get_data_from_record(ndef_record_s *record, char *data, size_t length)
-{
- bool result = false;
-
- if (record == NULL || data == NULL || length == 0)
- {
- return result;
- }
-
- switch (record->TNF)
- {
- case NET_NFC_RECORD_WELL_KNOWN_TYPE :
- {
- if (record->type_s.buffer == NULL || record->type_s.length == 0
- || record->payload_s.buffer == NULL || record->payload_s.length == 0)
- {
- DEBUG_ERR_MSG("Broken NDEF Message [NET_NFC_RECORD_WELL_KNOWN_TYPE]");
- break;
- }
-
- if (record->type_s.length == 1 && record->type_s.buffer[0] == 'T')
- {
- uint8_t *buffer_temp = record->payload_s.buffer;
- uint32_t buffer_length = record->payload_s.length;
-
- int index = (buffer_temp[0] & 0x3F) + 1;
- int text_length = buffer_length - index;
-
- memcpy(data, &(buffer_temp[index]), MIN(text_length, length));
- }
-
- //DEBUG_SERVER_MSG("data [%s]", data);
-
- result = true;
- }
- break;
-
- case NET_NFC_RECORD_MIME_TYPE :
- case NET_NFC_RECORD_URI : /* Absolute URI */
- case NET_NFC_RECORD_EXTERNAL_RTD : /* external type */
- case NET_NFC_RECORD_EMPTY : /* empy msg. discard it */
- result = true;
- break;
-
- case NET_NFC_RECORD_UNKNOWN : /* unknown msg. discard it */
- case NET_NFC_RECORD_UNCHAGNED : /* RFU msg. discard it */
- default :
- break;
- }
-
- return result;
-}
-
-void net_nfc_app_util_aul_launch_app(char* package_name, bundle* kb)
-{
- int result = 0;
- if((result = aul_launch_app(package_name, kb)) < 0)
- {
- switch(result)
- {
- case AUL_R_EINVAL:
- DEBUG_SERVER_MSG("aul launch error : AUL_R_EINVAL");
- break;
- case AUL_R_ECOMM:
- DEBUG_SERVER_MSG("aul launch error : AUL_R_ECOM");
- break;
- case AUL_R_ERROR:
- DEBUG_SERVER_MSG("aul launch error : AUL_R_ERROR");
- break;
- default:
- DEBUG_SERVER_MSG("aul launch error : unknown ERROR");
- break;
- }
- }
- else
- {
- DEBUG_SERVER_MSG("success to launch [%s]", package_name);
- }
-}
-
-int net_nfc_app_util_appsvc_launch(const char *operation, const char *uri, const char *mime, const char *data)
-{
- int result = -1;
-
- bundle *bd = NULL;
-
- bd = bundle_create();
- if (bd == NULL)
- return result;
-
- if (operation != NULL && strlen(operation) > 0)
- {
- DEBUG_SERVER_MSG("operation : %s", operation);
- appsvc_set_operation(bd, operation);
- }
-
- if (uri != NULL && strlen(uri) > 0)
- {
- DEBUG_SERVER_MSG("uri : %s", uri);
- appsvc_set_uri(bd, uri);
- }
-
- if (mime != NULL && strlen(mime) > 0)
- {
- DEBUG_SERVER_MSG("mime : %s", mime);
- appsvc_set_mime(bd, mime);
- }
-
- if (data != NULL && strlen(data) > 0)
- {
- DEBUG_SERVER_MSG("data : %s", data);
- appsvc_add_data(bd, "data", data);
- }
-
- bundle_add(bd, OSP_K_COND, OSP_K_COND_TYPE);
- bundle_add(bd, OSP_K_LAUNCH_TYPE, osp_launch_type_condition);
-
- result = appsvc_run_service(bd, 0, NULL, NULL);
-
- bundle_free(bd);
-
- return result;
-}
-
-void _binary_to_string(uint8_t *buffer, uint32_t len, char *out_buf, uint32_t max_len)
-{
- int current = 0;
-
- if (buffer == NULL || len == 0 || out_buf == NULL || max_len == 0)
- return;
-
- while (len > 0 && current < max_len)
- {
- current += snprintf(out_buf + current, max_len - current, "%02X", *(buffer++));
- len--;
- }
-}
-
-void _string_to_binary(const char *input, uint8_t *output, uint32_t *length)
-{
- int current = 0;
- int temp;
-
- if (input == NULL || *length == 0 || output == NULL)
- return;
-
- DEBUG_SERVER_MSG("_string_to_binary ");
-
- /* strlen("nfc://secure/aid/") = 17 */
-
- input += 17;
-
- while (*input && (current < *length))
- {
- temp = (*input++) - '0';
-
- if(temp > 9)
- temp -= 7;
-
- if(current % 2)
- {
- output[current / 2] += temp;
- }
- else
- {
- output[current / 2] = temp << 4;
- }
-
- current++;
- }
-
- *length = current / 2;
-}
-
-int net_nfc_app_util_launch_se_transaction_app(uint8_t *aid, uint32_t aid_len, uint8_t *param, uint32_t param_len)
-{
- bundle *bd = NULL;
-
- /* launch */
- bd = bundle_create();
-
- appsvc_set_operation(bd, "http://tizen.org/appcontrol/operation/nfc/transaction");
-
- /* convert aid to aid string */
- if (aid != NULL && aid_len > 0)
- {
- char temp_string[1024] = { 0, };
- char aid_string[1024] = { 0, };
-
- _binary_to_string(aid, aid_len, temp_string, sizeof(temp_string));
- snprintf(aid_string, sizeof(aid_string), "nfc://secure/aid/%s", temp_string);
- DEBUG_SERVER_MSG("aid_string : %s", aid_string);
- appsvc_set_uri(bd, aid_string);
- }
-
- if (param != NULL && param_len > 0)
- {
- char param_string[1024] = { 0, };
-
- _binary_to_string(param, param_len, param_string, sizeof(param_string));
- DEBUG_SERVER_MSG("param_string : %s", param_string);
- appsvc_add_data(bd, "data", param_string);
- }
-
- appsvc_run_service(bd, 0, NULL, NULL);
- bundle_free(bd);
-
- return 0;
-}
-
-int net_nfc_app_util_encode_base64(uint8_t *buffer, uint32_t buf_len, char *result, uint32_t max_result)
-{
- int ret = -1;
- BUF_MEM *bptr;
- BIO *b64, *bmem;
-
- if (buffer == NULL || buf_len == 0 || result == NULL || max_result == 0)
- return ret;
-
- /* base 64 */
- b64 = BIO_new(BIO_f_base64());
- BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL);
- bmem = BIO_new(BIO_s_mem());
- b64 = BIO_push(b64, bmem);
-
- BIO_write(b64, buffer, buf_len);
- BIO_flush(b64);
- BIO_get_mem_ptr(b64, &bptr);
-
- memset(result, 0, max_result);
- memcpy(result, bptr->data, MIN(bptr->length, max_result - 1));
-
- BIO_free_all(b64);
-
- ret = 0;
-
- return ret;
-}
-
-int net_nfc_app_util_decode_base64(const char *buffer, uint32_t buf_len, uint8_t *result, uint32_t *res_len)
-{
- int ret = -1;
- char *temp = NULL;
-
- if (buffer == NULL || buf_len == 0 || result == NULL || res_len == NULL || *res_len == 0)
- return ret;
-
- _net_nfc_util_alloc_mem(temp, buf_len);
- if (temp != NULL)
- {
- BIO *b64, *bmem;
- uint32_t temp_len;
-
- b64 = BIO_new(BIO_f_base64());
- BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL);
- bmem = BIO_new_mem_buf((void *)buffer, buf_len);
- bmem = BIO_push(b64, bmem);
-
- temp_len = BIO_read(bmem, temp, buf_len);
-
- BIO_free_all(bmem);
-
- memset(result, 0, *res_len);
- memcpy(result, temp, MIN(temp_len, *res_len));
-
- *res_len = MIN(temp_len, *res_len);
-
- _net_nfc_util_free_mem(temp);
-
- ret = 0;
- }
- else
- {
- DEBUG_ERR_MSG("alloc failed");
- }
-
- return ret;
-}
-
-static pid_t _net_nfc_app_util_get_focus_app_pid()
-{
- Ecore_X_Window focus;
- pid_t pid;
-
- ecore_x_init(":0");
-
- focus = ecore_x_window_focus_get();
- if (ecore_x_netwm_pid_get(focus, &pid))
- return pid;
-
- return -1;
-}
-
-bool net_nfc_app_util_check_launch_state()
-{
- pid_t focus_app_pid;
- net_nfc_launch_popup_state_e popup_state;
- bool result = false;
-
- focus_app_pid = _net_nfc_app_util_get_focus_app_pid();
-
- popup_state = net_nfc_server_gdbus_get_client_popup_state(focus_app_pid);
-
- if(popup_state == NET_NFC_NO_LAUNCH_APP_SELECT)
- result = true;
-
- return result;
-}
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#include <linux/limits.h>
-#include <stdio.h>
-#include <dlfcn.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <dirent.h>
-#include <string.h>
-#include <errno.h>
-
-#include <pmapi.h>/*for pm lock*/
-
-#include "net_nfc_oem_controller.h"
-#include "net_nfc_controller_internal.h"
-#include "net_nfc_util_internal.h"
-#include "net_nfc_debug_internal.h"
-#include "net_nfc_server_tag.h"
-
-#define NET_NFC_OEM_LIBRARY_PATH "/usr/lib/libnfc-plugin.so"
-#define NET_NFC_DEFAULT_PLUGIN "libnfc-plugin.so"
-
-
-static net_nfc_oem_interface_s g_interface;
-
-static void *net_nfc_controller_load_file(const char *dir_path,
- const char *filename)
-{
- void *handle = NULL;
- char path[PATH_MAX] = { '\0' };
- struct stat st;
-
- net_nfc_error_e result;
-
- bool (*onload)(net_nfc_oem_interface_s *interfaces);
-
- snprintf(path, PATH_MAX, "%s/%s", dir_path, filename);
- DEBUG_SERVER_MSG("path : %s", path);
-
- if (stat(path, &st) == -1) {
- DEBUG_ERR_MSG("stat failed : file not found");
- goto ERROR;
- }
-
- if (S_ISREG(st.st_mode) == 0) {
- DEBUG_ERR_MSG("S_ISREG(st.st_mode) == 0");
- goto ERROR;
- }
-
- handle = dlopen(path, RTLD_LAZY);
- if (handle == NULL) {
- char buffer[1024];
- DEBUG_ERR_MSG("dlopen failed, [%d] : %s",
- errno, strerror_r(errno, buffer, sizeof(buffer)));
- goto ERROR;
- }
-
- onload = dlsym(handle, "onload");
- if (onload == NULL) {
- char buffer[1024];
- DEBUG_ERR_MSG("dlsym failed, [%d] : %s",
- errno, strerror_r(errno, buffer, sizeof(buffer)));
- goto ERROR;
- }
-
- memset(&g_interface, 0, sizeof(g_interface));
- if (onload(&g_interface) == false) {
- DEBUG_ERR_MSG("onload failed");
- goto ERROR;
- }
-
- if (net_nfc_controller_support_nfc(&result) == false) {
- DEBUG_ERR_MSG("net_nfc_controller_support_nfc failed, [%d]",
- result);
- goto ERROR;
- }
-
- return handle;
-
-ERROR :
- if (handle != NULL) {
- dlclose(handle);
- }
-
- return NULL;
-}
-
-void *net_nfc_controller_onload()
-{
- DIR *dirp;
- struct dirent *dir;
-
- void *handle = NULL;
-
- dirp = opendir(NFC_MANAGER_MODULEDIR);
- if (dirp == NULL)
- {
- DEBUG_ERR_MSG("Can not open directory %s",
- NFC_MANAGER_MODULEDIR);
- return NULL;
- }
-
- while ((dir = readdir(dirp)))
- {
- if ((strcmp(dir->d_name, ".") == 0) ||
- (strcmp(dir->d_name, "..") == 0))
- {
- continue;
- }
-
- /* check ".so" suffix */
- if (strcmp(dir->d_name + (strlen(dir->d_name) - strlen(".so")),
- ".so") != 0)
- continue;
-
- /* check default plugin later */
- if (strcmp(dir->d_name, NET_NFC_DEFAULT_PLUGIN) == 0)
- continue;
-
- handle = net_nfc_controller_load_file(NFC_MANAGER_MODULEDIR,
- dir->d_name);
- if (handle)
- {
- SECURE_LOGD("Successfully loaded : %s",
- dir->d_name);
- closedir(dirp);
- return handle;
- }
- }
-
- closedir(dirp);
-
- /* load default plugin */
- handle = net_nfc_controller_load_file(NFC_MANAGER_MODULEDIR,
- NET_NFC_DEFAULT_PLUGIN);
-
- if (handle)
- {
- DEBUG_SERVER_MSG("loaded default plugin : %s",
- NET_NFC_DEFAULT_PLUGIN);
- return handle;
- }
- else
- {
- DEBUG_ERR_MSG("can not load default plugin : %s",
- NET_NFC_DEFAULT_PLUGIN);
- return NULL;
- }
-}
-
-bool net_nfc_controller_unload(void *handle)
-{
- memset(&g_interface, 0x00, sizeof(net_nfc_oem_interface_s));
-
- if (handle != NULL)
- {
- dlclose(handle);
- handle = NULL;
- }
- return true;
-}
-
-bool net_nfc_controller_init(net_nfc_error_e *result)
-{
- if (g_interface.init != NULL)
- {
- return g_interface.init(result);
- }
- else
- {
- *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;
- DEBUG_SERVER_MSG("interface is null");
- return false;
- }
-}
-
-bool net_nfc_controller_deinit(void)
-{
- if (g_interface.deinit != NULL)
- {
- return g_interface.deinit();
- }
- else
- {
- DEBUG_SERVER_MSG("interface is null");
- return false;
- }
-}
-
-bool net_nfc_controller_register_listener(target_detection_listener_cb target_detection_listener,
- se_transaction_listener_cb se_transaction_listener, llcp_event_listener_cb llcp_event_listener, net_nfc_error_e *result)
-{
- if (g_interface.register_listener != NULL)
- {
- return g_interface.register_listener(target_detection_listener, se_transaction_listener, llcp_event_listener, result);
- }
- else
- {
- *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;
- DEBUG_SERVER_MSG("interface is null");
- return false;
- }
-}
-
-bool net_nfc_controller_unregister_listener()
-{
- if (g_interface.unregister_listener != NULL)
- {
- return g_interface.unregister_listener();
- }
- else
- {
- DEBUG_SERVER_MSG("interface is null");
- return false;
- }
-}
-
-bool net_nfc_controller_get_firmware_version(data_s **data, net_nfc_error_e *result)
-{
- if (g_interface.get_firmware_version != NULL)
- {
- return g_interface.get_firmware_version(data, result);
- }
- else
- {
- *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;
- DEBUG_SERVER_MSG("interface is null");
- return false;
- }
-}
-
-bool net_nfc_controller_check_firmware_version(net_nfc_error_e *result)
-{
- if (g_interface.check_firmware_version != NULL)
- {
- return g_interface.check_firmware_version(result);
- }
- else
- {
- *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;
- DEBUG_SERVER_MSG("interface is null");
- return false;
- }
-}
-
-bool net_nfc_controller_update_firmware(net_nfc_error_e *result)
-{
- if (g_interface.update_firmeware != NULL)
- {
- return g_interface.update_firmeware(result);
- }
- else
- {
- *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;
- DEBUG_SERVER_MSG("interface is null");
- return false;
- }
-}
-
-bool net_nfc_controller_get_stack_information(net_nfc_stack_information_s *stack_info, net_nfc_error_e *result)
-{
- if (g_interface.get_stack_information != NULL)
- {
- return g_interface.get_stack_information(stack_info, result);
- }
- else
- {
- *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;
- DEBUG_SERVER_MSG("interface is null");
- return false;
- }
-}
-
-bool net_nfc_controller_configure_discovery(net_nfc_discovery_mode_e mode, net_nfc_event_filter_e config, net_nfc_error_e *result)
-{
- if (g_interface.configure_discovery != NULL)
- {
- return g_interface.configure_discovery(mode, config, result);
- }
- else
- {
- *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;
- DEBUG_SERVER_MSG("interface is null");
- return false;
- }
-}
-
-bool net_nfc_controller_get_secure_element_list(net_nfc_secure_element_info_s *list, int *count, net_nfc_error_e *result)
-{
- if (g_interface.get_secure_element_list != NULL)
- {
- return g_interface.get_secure_element_list(list, count, result);
- }
- else
- {
- *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;
- DEBUG_SERVER_MSG("interface is null");
- return false;
- }
-}
-
-bool net_nfc_controller_set_secure_element_mode(net_nfc_secure_element_type_e element_type, net_nfc_secure_element_mode_e mode, net_nfc_error_e *result)
-{
- if (g_interface.set_secure_element_mode != NULL)
- {
- return g_interface.set_secure_element_mode(element_type, mode, result);
- }
- else
- {
- *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;
- DEBUG_SERVER_MSG("interface is null");
- return false;
- }
-}
-
-bool net_nfc_controller_secure_element_open(net_nfc_secure_element_type_e element_type, net_nfc_target_handle_s **handle, net_nfc_error_e *result)
-{
- int ret_val = 0;
-
- ret_val = pm_lock_state(LCD_NORMAL, GOTO_STATE_NOW, 0);
-
- if (g_interface.secure_element_open != NULL)
- {
- return g_interface.secure_element_open(element_type, handle, result);
- }
- else
- {
- *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;
- DEBUG_SERVER_MSG("interface is null");
- return false;
- }
-}
-
-bool net_nfc_controller_secure_element_get_atr(net_nfc_target_handle_s *handle, data_s **atr, net_nfc_error_e *result)
-{
- if (g_interface.secure_element_get_atr != NULL)
- {
- return g_interface.secure_element_get_atr(handle, atr, result);
- }
- else
- {
- *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;
- DEBUG_SERVER_MSG("interface is null");
- return false;
- }
-}
-
-bool net_nfc_controller_secure_element_send_apdu(net_nfc_target_handle_s *handle, data_s *command, data_s **response, net_nfc_error_e *result)
-{
- if (g_interface.secure_element_send_apdu != NULL)
- {
- return g_interface.secure_element_send_apdu(handle, command, response, result);
- }
- else
- {
- *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;
- DEBUG_SERVER_MSG("interface is null");
- return false;
- }
-}
-
-bool net_nfc_controller_secure_element_close(net_nfc_target_handle_s *handle, net_nfc_error_e *result)
-{
- int ret_val = 0;
-
- ret_val = pm_unlock_state(LCD_NORMAL, PM_RESET_TIMER);
-
- if (g_interface.secure_element_close != NULL)
- {
- return g_interface.secure_element_close(handle, result);
- }
- else
- {
- *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;
- DEBUG_SERVER_MSG("interface is null");
- return false;
- }
-}
-
-bool net_nfc_controller_check_target_presence(net_nfc_target_handle_s *handle, net_nfc_error_e *result)
-{
- if (g_interface.check_presence != NULL)
- {
- return g_interface.check_presence(handle, result);
- }
- else
- {
- *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;
- DEBUG_SERVER_MSG("interface is null");
- return false;
- }
-}
-
-bool net_nfc_controller_connect(net_nfc_target_handle_s *handle, net_nfc_error_e *result)
-{
- int ret_val = 0;
-
- ret_val = pm_lock_state(LCD_NORMAL, GOTO_STATE_NOW, 0);
-
- DEBUG_SERVER_MSG("net_nfc_controller_connect pm_lock_state [%d]!!", ret_val);
-
- if (g_interface.connect != NULL)
- {
- return g_interface.connect(handle, result);
- }
- else
- {
- *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;
- DEBUG_SERVER_MSG("interface is null");
- return false;
- }
-}
-
-bool net_nfc_controller_disconnect(net_nfc_target_handle_s *handle, net_nfc_error_e *result)
-{
- int ret_val = 0;
-
- ret_val = pm_unlock_state(LCD_NORMAL, PM_RESET_TIMER);
-
- DEBUG_ERR_MSG("net_nfc_controller_disconnect pm_lock_state [%d]!!", ret_val);
-
- if (g_interface.disconnect != NULL)
- {
- net_nfc_server_free_target_info();
-
- return g_interface.disconnect(handle, result);
- }
- else
- {
- *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;
- DEBUG_SERVER_MSG("interface is null");
- return false;
- }
-}
-
-bool net_nfc_controller_check_ndef(net_nfc_target_handle_s *handle, uint8_t *ndef_card_state, int *max_data_size, int *real_data_size, net_nfc_error_e *result)
-{
- if (g_interface.check_ndef != NULL)
- {
- return g_interface.check_ndef(handle, ndef_card_state, max_data_size, real_data_size, result);
- }
- else
- {
- *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;
- DEBUG_SERVER_MSG("interface is null");
- return false;
- }
-}
-
-bool net_nfc_controller_read_ndef(net_nfc_target_handle_s *handle, data_s **data, net_nfc_error_e *result)
-{
- if (g_interface.read_ndef != NULL)
- {
- return g_interface.read_ndef(handle, data, result);
- }
- else
- {
- *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;
- DEBUG_SERVER_MSG("interface is null");
- return false;
- }
-}
-
-bool net_nfc_controller_write_ndef(net_nfc_target_handle_s *handle, data_s *data, net_nfc_error_e *result)
-{
- if (g_interface.write_ndef != NULL)
- {
- return g_interface.write_ndef(handle, data, result);
- }
- else
- {
- *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;
- DEBUG_SERVER_MSG("interface is null");
- return false;
- }
-}
-
-bool net_nfc_controller_make_read_only_ndef(net_nfc_target_handle_s *handle, net_nfc_error_e *result)
-{
- if (g_interface.make_read_only_ndef != NULL)
- {
- return g_interface.make_read_only_ndef(handle, result);
- }
- else
- {
- *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;
- DEBUG_SERVER_MSG("interface is null");
- return false;
- }
-}
-
-bool net_nfc_controller_format_ndef(net_nfc_target_handle_s *handle, data_s *secure_key, net_nfc_error_e *result)
-{
- if (g_interface.format_ndef != NULL)
- {
- return g_interface.format_ndef(handle, secure_key, result);
- }
- else
- {
- *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;
- DEBUG_SERVER_MSG("interface is null");
- return false;
- }
-}
-
-bool net_nfc_controller_transceive(net_nfc_target_handle_s *handle, net_nfc_transceive_info_s *info, data_s **data, net_nfc_error_e *result)
-{
- if (g_interface.transceive != NULL)
- {
- return g_interface.transceive(handle, info, data, result);
- }
- else
- {
- *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;
- DEBUG_SERVER_MSG("interface is null");
- return false;
- }
-}
-
-bool net_nfc_controller_exception_handler()
-{
- if (g_interface.exception_handler != NULL)
- {
- return g_interface.exception_handler();
- }
- else
- {
- DEBUG_SERVER_MSG("interface is null");
- return false;
- }
-}
-
-bool net_nfc_controller_is_ready(net_nfc_error_e *result)
-{
- if (g_interface.is_ready != NULL)
- {
- return g_interface.is_ready(result);
- }
- else
- {
- *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;
- DEBUG_SERVER_MSG("interface is null");
- return false;
- }
-}
-
-bool net_nfc_controller_llcp_config(net_nfc_llcp_config_info_s *config, net_nfc_error_e *result)
-{
- if (g_interface.config_llcp != NULL)
- {
- return g_interface.config_llcp(config, result);
- }
- else
- {
- *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;
- DEBUG_SERVER_MSG("interface is null");
- return false;
- }
-}
-bool net_nfc_controller_llcp_check_llcp(net_nfc_target_handle_s *handle, net_nfc_error_e *result)
-{
- if (g_interface.check_llcp_status != NULL)
- {
- return g_interface.check_llcp_status(handle, result);
- }
- else
- {
- *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;
- DEBUG_SERVER_MSG("interface is null");
- return false;
- }
-}
-bool net_nfc_controller_llcp_activate_llcp(net_nfc_target_handle_s *handle, net_nfc_error_e *result)
-{
- if (g_interface.activate_llcp != NULL)
- {
- return g_interface.activate_llcp(handle, result);
- }
- else
- {
- *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;
- DEBUG_SERVER_MSG("interface is null");
- return false;
- }
-}
-
-static GSList *llcp_sockets;
-
-static gint _compare_socket_info(gconstpointer a, gconstpointer b)
-{
- int result;
- socket_info_t *info = (socket_info_t *)a;
-
- if (info->socket == (net_nfc_llcp_socket_t)b)
- result = 0;
- else
- result = -1;
-
- return result;
-}
-
-socket_info_t *_get_socket_info(net_nfc_llcp_socket_t socket)
-{
- socket_info_t *result;
- GSList *item;
-
- item = g_slist_find_custom(llcp_sockets, GUINT_TO_POINTER(socket),
- _compare_socket_info);
- if (item != NULL) {
- result = (socket_info_t *)item->data;
- } else {
- result = NULL;
- }
-
- return result;
-}
-
-socket_info_t *_add_socket_info(net_nfc_llcp_socket_t socket)
-{
- socket_info_t *result;
-
- _net_nfc_util_alloc_mem(result, sizeof(*result));
- if (result != NULL) {
- result->socket = socket;
-
- llcp_sockets = g_slist_append(llcp_sockets, result);
- }
-
- return result;
-}
-
-static void _remove_socket_info(net_nfc_llcp_socket_t socket)
-{
- GSList *item;
-
- item = g_slist_find_custom(llcp_sockets, GUINT_TO_POINTER(socket),
- _compare_socket_info);
- if (item != NULL) {
- llcp_sockets = g_slist_remove_link(llcp_sockets, item);
- free(item->data);
- }
-}
-
-static void _destroy_function(gpointer data)
-{
- free(data);
-}
-
-static void _clear_socket_info()
-{
- g_slist_free_full(llcp_sockets, _destroy_function);
- llcp_sockets = NULL;
-}
-
-void net_nfc_controller_llcp_socket_error_cb(net_nfc_llcp_socket_t socket,
- net_nfc_error_e result, void *data, void *user_param)
-{
- socket_info_t *info;
-
- info = _get_socket_info(socket);
- if (info != NULL) {
- if (info->err_cb != NULL) {
- info->err_cb(socket, result, NULL, NULL, info->err_param);
- }
-
- _remove_socket_info(socket);
- }
-}
-
-bool net_nfc_controller_llcp_create_socket(net_nfc_llcp_socket_t *socket, net_nfc_socket_type_e socketType, uint16_t miu, uint8_t rw, net_nfc_error_e *result, net_nfc_service_llcp_cb cb, void *user_param)
-{
- if (g_interface.create_llcp_socket != NULL)
- {
- bool ret;
- socket_info_t *info;
-
- info = _add_socket_info(-1);
- if (info == NULL) {
- DEBUG_ERR_MSG("_net_nfc_util_alloc_mem failed");
- *result = NET_NFC_ALLOC_FAIL;
- return false;
- }
-
- ret = g_interface.create_llcp_socket(socket, socketType, miu, rw, result, NULL);
- if (ret == true) {
- info->socket = *socket;
- info->err_cb = cb;
- info->err_param = user_param;
- } else {
- _remove_socket_info(-1);
- }
-
- return ret;
- }
- else
- {
- *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;
- DEBUG_SERVER_MSG("interface is null");
- return false;
- }
-}
-
-bool net_nfc_controller_llcp_bind(net_nfc_llcp_socket_t socket, uint8_t service_access_point, net_nfc_error_e *result)
-{
- if (g_interface.bind_llcp_socket != NULL)
- {
- return g_interface.bind_llcp_socket(socket, service_access_point, result);
- }
- else
- {
- *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;
- DEBUG_SERVER_MSG("interface is null");
- return false;
- }
-}
-
-void net_nfc_controller_llcp_incoming_cb(net_nfc_llcp_socket_t socket,
- net_nfc_error_e result, void *data, void *user_param)
-{
- socket_info_t *info = (socket_info_t *)user_param;
-
- info = _get_socket_info(info->socket);
- if (info != NULL) {
- if (_add_socket_info(socket) != NULL) {
- if (info->work_cb != NULL) {
- info->work_cb(socket, result, NULL, NULL,
- info->work_param);
- }
- } else {
- DEBUG_ERR_MSG("_net_nfc_util_alloc_mem failed");
- }
- }
-}
-
-bool net_nfc_controller_llcp_listen(net_nfc_target_handle_s* handle, uint8_t *service_access_name, net_nfc_llcp_socket_t socket, net_nfc_error_e *result, net_nfc_service_llcp_cb cb, void *user_param)
-{
- if (g_interface.listen_llcp_socket != NULL)
- {
- socket_info_t *info;
-
- info = _get_socket_info(socket);
- if (info == NULL) {
- DEBUG_ERR_MSG("_get_socket_info failed");
- *result = NET_NFC_INVALID_HANDLE;
- return false;
- }
-
- info->work_cb = cb;
- info->work_param = user_param;
-
- return g_interface.listen_llcp_socket(handle, service_access_name, socket, result, info);
- }
- else
- {
- *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;
- DEBUG_SERVER_MSG("interface is null");
- return false;
- }
-}
-
-bool net_nfc_controller_llcp_accept(net_nfc_llcp_socket_t socket, net_nfc_error_e *result, net_nfc_service_llcp_cb cb, void *user_param)
-{
- if (g_interface.accept_llcp_socket != NULL)
- {
- socket_info_t *info;
-
- info = _get_socket_info(socket);
- if (info == NULL) {
- DEBUG_ERR_MSG("_get_socket_info failed");
- *result = NET_NFC_INVALID_HANDLE;
- return false;
- }
-
- info->err_cb = cb;
- info->err_param = user_param;
-
- return g_interface.accept_llcp_socket(socket, result, NULL);
- }
- else
- {
- *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;
- DEBUG_SERVER_MSG("interface is null");
- return false;
- }
-}
-
-bool net_nfc_controller_llcp_reject(net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, net_nfc_error_e *result)
-{
- if (g_interface.reject_llcp != NULL)
- {
- bool ret;
-
- ret = g_interface.reject_llcp(handle, socket, result);
- if (ret == true) {
- _remove_socket_info(socket);
- }
-
- return ret;
- }
- else
- {
- *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;
- DEBUG_SERVER_MSG("interface is null");
- return false;
- }
-}
-
-void net_nfc_controller_llcp_connected_cb(net_nfc_llcp_socket_t socket,
- net_nfc_error_e result, void *data, void *user_param)
-{
- net_nfc_llcp_param_t *param = (net_nfc_llcp_param_t *)user_param;
-
- if (param == NULL)
- return;
-
- if (param->cb != NULL) {
- param->cb(param->socket, result, NULL, NULL, param->user_param);
- }
-
- _net_nfc_util_free_mem(param);
-}
-
-bool net_nfc_controller_llcp_connect_by_url(net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, uint8_t *service_access_name, net_nfc_error_e *result, net_nfc_service_llcp_cb cb, void *user_param)
-{
- int ret_val = 0;
-
- ret_val = pm_lock_state(LCD_NORMAL, GOTO_STATE_NOW, 0);
-
- DEBUG_SERVER_MSG("net_nfc_controller_llcp_connect_by_url pm_lock_state [%d]!!", ret_val);
-
- if (g_interface.connect_llcp_by_url != NULL)
- {
- net_nfc_llcp_param_t *param = NULL;
-
- _net_nfc_util_alloc_mem(param, sizeof(*param));
- if (param == NULL) {
- DEBUG_ERR_MSG("_net_nfc_util_alloc_mem failed");
- *result = NET_NFC_ALLOC_FAIL;
- return false;
- }
-
- param->socket = socket;
- param->cb = cb;
- param->user_param = user_param;
-
- return g_interface.connect_llcp_by_url(handle, socket, service_access_name, result, param);
- }
- else
- {
- *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;
- DEBUG_SERVER_MSG("interface is null");
- return false;
- }
-}
-
-bool net_nfc_controller_llcp_connect(net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, uint8_t service_access_point, net_nfc_error_e *result, net_nfc_service_llcp_cb cb, void *user_param)
-{
- int ret_val = 0;
-
- ret_val = pm_lock_state(LCD_NORMAL, GOTO_STATE_NOW, 0);
-
- DEBUG_SERVER_MSG("net_nfc_controller_llcp_connect pm_lock_state [%d]!!", ret_val);
-
- if (g_interface.connect_llcp != NULL)
- {
- net_nfc_llcp_param_t *param = NULL;
-
- _net_nfc_util_alloc_mem(param, sizeof(*param));
- if (param == NULL) {
- DEBUG_ERR_MSG("_net_nfc_util_alloc_mem failed");
- *result = NET_NFC_ALLOC_FAIL;
- return false;
- }
-
- param->socket = socket;
- param->cb = cb;
- param->user_param = user_param;
-
- return g_interface.connect_llcp(handle, socket, service_access_point, result, param);
- }
- else
- {
- *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;
- DEBUG_SERVER_MSG("interface is null");
- return false;
- }
-}
-
-void net_nfc_controller_llcp_disconnected_cb(net_nfc_llcp_socket_t socket,
- net_nfc_error_e result, void *data, void *user_param)
-{
- net_nfc_llcp_param_t *param = (net_nfc_llcp_param_t *)user_param;
-
- if (param == NULL)
- return;
-
- if (param->cb != NULL) {
- param->cb(param->socket, result, NULL, NULL, param->user_param);
- }
-
- _net_nfc_util_free_mem(param);
-}
-
-bool net_nfc_controller_llcp_disconnect(net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, net_nfc_error_e *result, net_nfc_service_llcp_cb cb, void *user_param)
-{
- int ret_val = 0;
-
- ret_val = pm_unlock_state(LCD_NORMAL, PM_RESET_TIMER);
-
- DEBUG_SERVER_MSG("net_nfc_controller_llcp_disconnect pm_unlock_state [%d]!!", ret_val);
-
- if (g_interface.disconnect_llcp != NULL)
- {
- net_nfc_llcp_param_t *param = NULL;
-
- _net_nfc_util_alloc_mem(param, sizeof(*param));
- if (param == NULL) {
- DEBUG_ERR_MSG("_net_nfc_util_alloc_mem failed");
- *result = NET_NFC_ALLOC_FAIL;
- return false;
- }
-
- param->socket = socket;
- param->cb = cb;
- param->user_param = user_param;
-
- return g_interface.disconnect_llcp(handle, socket, result, param);
- }
- else
- {
- *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;
- DEBUG_SERVER_MSG("interface is null");
- return false;
- }
-}
-
-bool net_nfc_controller_llcp_socket_close(net_nfc_llcp_socket_t socket, net_nfc_error_e *result)
-{
- if (g_interface.close_llcp_socket != NULL)
- {
- return g_interface.close_llcp_socket(socket, result);
- }
- else
- {
- *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;
- DEBUG_SERVER_MSG("interface is null");
- return false;
- }
-}
-
-void net_nfc_controller_llcp_received_cb(net_nfc_llcp_socket_t socket,
- net_nfc_error_e result, void *data, void *user_param)
-{
- net_nfc_llcp_param_t *param = (net_nfc_llcp_param_t *)user_param;
-
- if (param == NULL)
- return;
-
- if (param->cb != NULL) {
- param->cb(param->socket, result, ¶m->data, data, param->user_param);
- }
-
- if (param->data.buffer != NULL) {
- _net_nfc_util_free_mem(param->data.buffer);
- }
- _net_nfc_util_free_mem(param);
-}
-
-bool net_nfc_controller_llcp_recv(net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, uint32_t max_len, net_nfc_error_e *result, net_nfc_service_llcp_cb cb, void *user_param)
-{
- if (g_interface.recv_llcp != NULL)
- {
- net_nfc_llcp_param_t *param = NULL;
-
- _net_nfc_util_alloc_mem(param, sizeof(*param));
- if (param == NULL) {
- DEBUG_ERR_MSG("_net_nfc_util_alloc_mem failed");
- *result = NET_NFC_ALLOC_FAIL;
- return false;
- }
-
- param->socket = socket;
- param->cb = cb;
- if (max_len > 0) {
- _net_nfc_util_alloc_mem(param->data.buffer, max_len);
- if (param->data.buffer == NULL) {
- DEBUG_ERR_MSG("_net_nfc_util_alloc_mem failed");
- _net_nfc_util_free_mem(param);
- *result = NET_NFC_ALLOC_FAIL;
- return false;
- }
- param->data.length = max_len;
- }
- param->user_param = user_param;
-
- return g_interface.recv_llcp(handle, socket, ¶m->data, result, param);
- }
- else
- {
- *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;
- DEBUG_SERVER_MSG("interface is null");
- return false;
- }
-}
-
-void net_nfc_controller_llcp_sent_cb(net_nfc_llcp_socket_t socket,
- net_nfc_error_e result, void *data, void *user_param)
-{
- net_nfc_llcp_param_t *param = (net_nfc_llcp_param_t *)user_param;
-
- if (param == NULL)
- return;
-
- if (param->cb != NULL) {
- param->cb(param->socket, result, NULL, NULL, param->user_param);
- }
-
- _net_nfc_util_free_mem(param);
-}
-
-bool net_nfc_controller_llcp_send(net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, data_s *data, net_nfc_error_e *result, net_nfc_service_llcp_cb cb, void *user_param)
-{
- if (g_interface.send_llcp != NULL)
- {
- net_nfc_llcp_param_t *param = NULL;
-
- _net_nfc_util_alloc_mem(param, sizeof(*param));
- if (param == NULL) {
- DEBUG_ERR_MSG("_net_nfc_util_alloc_mem failed");
- *result = NET_NFC_ALLOC_FAIL;
- return false;
- }
-
- param->socket = socket;
- param->cb = cb;
- param->user_param = user_param;
-
- return g_interface.send_llcp(handle, socket, data, result, param);
- }
- else
- {
- *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;
- DEBUG_SERVER_MSG("interface is null");
- return false;
- }
-}
-bool net_nfc_controller_llcp_recv_from(net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, uint32_t max_len, net_nfc_error_e *result, net_nfc_service_llcp_cb cb, void *user_param)
-{
- if (g_interface.recv_from_llcp != NULL)
- {
- net_nfc_llcp_param_t *param = NULL;
-
- _net_nfc_util_alloc_mem(param, sizeof(*param));
- if (param == NULL) {
- DEBUG_ERR_MSG("_net_nfc_util_alloc_mem failed");
- *result = NET_NFC_ALLOC_FAIL;
- return false;
- }
-
- param->socket = socket;
- param->cb = cb;
- if (max_len > 0) {
- _net_nfc_util_alloc_mem(param->data.buffer, max_len);
- if (param->data.buffer == NULL) {
- DEBUG_ERR_MSG("_net_nfc_util_alloc_mem failed");
- _net_nfc_util_free_mem(param);
- *result = NET_NFC_ALLOC_FAIL;
- return false;
- }
- param->data.length = max_len;
- }
- param->user_param = user_param;
-
- return g_interface.recv_from_llcp(handle, socket, ¶m->data, result, param);
- }
- else
- {
- *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;
- DEBUG_SERVER_MSG("interface is null");
- return false;
- }
-}
-bool net_nfc_controller_llcp_send_to(net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, data_s *data, uint8_t service_access_point, net_nfc_error_e *result, net_nfc_service_llcp_cb cb, void *user_param)
-{
- if (g_interface.send_to_llcp != NULL)
- {
- net_nfc_llcp_param_t *param = NULL;
-
- _net_nfc_util_alloc_mem(param, sizeof(*param));
- if (param == NULL) {
- DEBUG_ERR_MSG("_net_nfc_util_alloc_mem failed");
- *result = NET_NFC_ALLOC_FAIL;
- return false;
- }
-
- param->socket = socket;
- param->cb = cb;
- param->user_param = user_param;
-
- return g_interface.send_to_llcp(handle, socket, data, service_access_point, result, param);
- }
- else
- {
- *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;
- DEBUG_SERVER_MSG("interface is null");
- return false;
- }
-}
-
-bool net_nfc_controller_llcp_get_remote_config(net_nfc_target_handle_s *handle, net_nfc_llcp_config_info_s *config, net_nfc_error_e *result)
-{
- if (g_interface.get_remote_config != NULL)
- {
- return g_interface.get_remote_config(handle, config, result);
- }
- else
- {
- *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;
- DEBUG_SERVER_MSG("interface is null");
- return false;
- }
-}
-bool net_nfc_controller_llcp_get_remote_socket_info(net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, net_nfc_llcp_socket_option_s *option, net_nfc_error_e *result)
-{
- if (g_interface.get_remote_socket_info != NULL)
- {
- return g_interface.get_remote_socket_info(handle, socket, option, result);
- }
- else
- {
- *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;
- DEBUG_SERVER_MSG("interface is null");
- return false;
- }
-
-}
-
-bool net_nfc_controller_sim_test(net_nfc_error_e *result)
-{
- if (g_interface.sim_test != NULL)
- {
- return g_interface.sim_test(result);
- }
- else
- {
- *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;
- DEBUG_SERVER_MSG("interface is null");
- return false;
- }
-}
-
-bool net_nfc_controller_prbs_test(net_nfc_error_e *result, uint32_t tech, uint32_t rate)
-{
- if (g_interface.prbs_test != NULL)
- {
- return g_interface.prbs_test(result, tech, rate);
- }
- else
- {
- *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;
- DEBUG_SERVER_MSG("interface is null");
- return false;
- }
-}
-
-bool net_nfc_controller_test_mode_on(net_nfc_error_e *result)
-{
- if (g_interface.test_mode_on != NULL)
- {
- return g_interface.test_mode_on(result);
- }
- else
- {
- *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;
- DEBUG_SERVER_MSG("interface is null");
- return false;
- }
-}
-
-bool net_nfc_controller_test_mode_off(net_nfc_error_e *result)
-{
- if (g_interface.test_mode_off != NULL)
- {
- return g_interface.test_mode_off(result);
- }
- else
- {
- *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;
- DEBUG_SERVER_MSG("interface is null");
- return false;
- }
-}
-
-bool net_nfc_controller_support_nfc(net_nfc_error_e *result)
-{
- if (g_interface.support_nfc != NULL)
- {
- return g_interface.support_nfc(result);
- }
- else
- {
- *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;
- DEBUG_SERVER_MSG("interface is null");
- return false;
- }
-}
-
-bool net_nfc_controller_eedata_register_set(net_nfc_error_e *result, uint32_t mode, uint32_t reg_id, data_s *data)
-{
- if (g_interface.eedata_register_set != NULL)
- {
- return g_interface.eedata_register_set(result, mode, reg_id, data);
- }
- else
- {
- *result = NET_NFC_DEVICE_DOES_NOT_SUPPORT_NFC;
- DEBUG_SERVER_MSG("interface is null");
- return false;
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <stdio.h>
-#include <unistd.h>
-#include <glib.h>
-#include <pthread.h>
-#include <dbus/dbus-glib.h>
-#include <dbus/dbus-glib-bindings.h>
-#include <gio/gio.h>
-#include <sys/utsname.h>
-
-#include <vconf.h>
-
-#include "net_nfc_server_common.h"
-#include "net_nfc_server_vconf.h"
-#include "net_nfc_server_manager.h"
-#include "net_nfc_server_se.h"
-#include "net_nfc_server_tag.h"
-#include "net_nfc_debug_internal.h"
-#include "net_nfc_typedef_internal.h"
-#include "net_nfc_app_util_internal.h"
-#include "net_nfc_controller_internal.h"
-#include "net_nfc_util_internal.h"
-#include "net_nfc_util_defines.h"
-#include "net_nfc_manager.h"
-#include "net_nfc_server.h"
-
-static gboolean use_daemon = FALSE;
-
-GOptionEntry option_entries[] = {
- { "daemon", 'd', 0, G_OPTION_ARG_NONE, &use_daemon,
- "Use Daemon mode", NULL },
- { NULL }
-};
-
-static GMainLoop *loop = NULL;
-
-void net_nfc_manager_quit()
-{
- DEBUG_MSG("net_nfc_manager_quit kill the nfc-manager daemon!!");
- if (loop != NULL) {
- g_main_loop_quit(loop);
- }
-}
-
-static void on_bus_acquired(GDBusConnection *connection,
- const gchar *path,
- gpointer user_data)
-{
- gint state;
-
- DEBUG_MSG("bus path : %s", path);
-
- net_nfc_server_gdbus_init();
-
- net_nfc_server_controller_init();
-
- if (vconf_get_bool(VCONFKEY_NFC_STATE, &state) != 0)
- {
- DEBUG_MSG("VCONFKEY_NFC_STATE is not exist");
- net_nfc_manager_quit();
-
- return;
- }
-
- net_nfc_server_vconf_init();
-
- if (state == 1)
- net_nfc_server_manager_set_active(TRUE);
-#ifndef ESE_ALWAYS_ON
- else if (use_daemon == TRUE)
- net_nfc_server_controller_deinit();
-#endif
-}
-
-static void on_name_acquired(GDBusConnection *connection,
- const gchar *name,
- gpointer user_data)
-{
- DEBUG_SERVER_MSG("name : %s", name);
-}
-
-static void on_name_lost(GDBusConnection *connnection,
- const gchar *name,
- gpointer user_data)
-{
- DEBUG_SERVER_MSG("name : %s", name);
-
- net_nfc_manager_quit();
-}
-
-
-int main(int argc, char *argv[])
-{
-
- void *handle = NULL;
- guint id = 0;
- gboolean use_daemon = FALSE;
-
- GOptionContext *option_context;
- GError *error = NULL;
-
- if (!g_thread_supported())
- {
- g_thread_init(NULL);
- }
-
- g_type_init();
-
- option_context = g_option_context_new("Nfc manager");
- g_option_context_add_main_entries(option_context,
- option_entries,
- NULL);
-
- if (g_option_context_parse(option_context,
- &argc,
- &argv,
- &error) == FALSE)
- {
- DEBUG_ERR_MSG("can not parse option: %s",
- error->message);
- g_error_free(error);
-
- g_option_context_free(option_context);
- return 0;
- }
-
- DEBUG_SERVER_MSG("start nfc manager");
- DEBUG_SERVER_MSG("use_daemon : %d", use_daemon);
-
- net_nfc_manager_init_log();
-
- net_nfc_app_util_clean_storage(MESSAGE_STORAGE);
-
- handle = net_nfc_controller_onload();
- if (handle == NULL)
- {
- DEBUG_ERR_MSG("load plugin library is failed");
-
- if (vconf_set_bool(VCONFKEY_NFC_FEATURE,
- VCONFKEY_NFC_FEATURE_OFF) != 0)
- {
- DEBUG_ERR_MSG("VCONFKEY_NFC_FEATURE set to %d failed",
- VCONFKEY_NFC_FEATURE_OFF);
- }
-
- if (vconf_set_bool(VCONFKEY_NFC_STATE, 0) != 0)
- {
- DEBUG_ERR_MSG("VCONFKEY_NFC_STATE set to %d failed",
- 0);
- }
-
- goto EXIT;
- }
-
- if (vconf_set_bool(VCONFKEY_NFC_FEATURE, VCONFKEY_NFC_FEATURE_ON) != 0)
- {
- DEBUG_ERR_MSG("VCONFKEY_NFC_FEATURE set to %d failed",
- VCONFKEY_NFC_FEATURE_ON);
- }
-
- id = g_bus_own_name(G_BUS_TYPE_SYSTEM,
- "org.tizen.NetNfcService",
- G_BUS_NAME_OWNER_FLAGS_NONE,
- on_bus_acquired,
- on_name_acquired,
- on_name_lost,
- NULL,
- NULL);
-
- loop = g_main_loop_new(NULL, FALSE);
- g_main_loop_run(loop);
-
-EXIT :
- net_nfc_server_vconf_deinit();
- net_nfc_server_controller_deinit();
- net_nfc_server_gdbus_deinit();
-
- if (id)
- {
- g_bus_unown_name(id);
- }
-
- net_nfc_controller_unload(handle);
-
- net_nfc_manager_fini_log();
-
- g_option_context_free(option_context);
-
- return 0;
-}
\ No newline at end of file
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <stdlib.h>
-#include <string.h>
-
-#include "vconf.h"
-#include "svi.h"
-#include "wav_player.h"
-
-#include "net_nfc_debug_internal.h"
-#include "net_nfc_util_internal.h"
-#include "net_nfc_manager_util_internal.h"
-
-static void _play_sound_callback(int id, void *data)
-{
- DEBUG_MSG("_play_sound_callback");
-
- if (WAV_PLAYER_ERROR_NONE != wav_player_stop(id))
- {
- DEBUG_MSG("wav_player_stop failed");
- }
-}
-
-void net_nfc_manager_util_play_sound(net_nfc_sound_type_e sound_type)
-{
- int bSoundOn = 0;
- int bVibrationOn = 0;
-
- if (vconf_get_bool(VCONFKEY_SETAPPL_SOUND_STATUS_BOOL, &bSoundOn) != 0)
- {
- DEBUG_MSG("vconf_get_bool failed for Sound");
- return;
- }
-
- if (vconf_get_bool(VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL, &bVibrationOn) != 0)
- {
- DEBUG_MSG("vconf_get_bool failed for Vibration");
- return;
- }
-
- if ((sound_type > NET_NFC_TASK_ERROR) || (sound_type < NET_NFC_TASK_START))
- {
- DEBUG_MSG("Invalid Sound Type");
- return;
- }
-
- if (bVibrationOn)
- {
- int svi_handle = -1;
-
- DEBUG_MSG("Play Vibration");
-
- if (SVI_SUCCESS == svi_init(&svi_handle))
- {
- if (SVI_SUCCESS == svi_play_vib(svi_handle, SVI_VIB_TOUCH_SIP))
- {
- DEBUG_MSG("svi_play_vib success");
- }
-
- svi_fini(svi_handle);
- }
- }
-
- if (bSoundOn)
- {
- char *sound_path = NULL;
-
- DEBUG_MSG("Play Sound");
-
- switch (sound_type)
- {
- case NET_NFC_TASK_START :
- sound_path = strdup(NET_NFC_MANAGER_SOUND_PATH_TASK_START);
- break;
- case NET_NFC_TASK_END :
- sound_path = strdup(NET_NFC_MANAGER_SOUND_PATH_TASK_END);
- break;
- case NET_NFC_TASK_ERROR :
- sound_path = strdup(NET_NFC_MANAGER_SOUND_PATH_TASK_ERROR);
- break;
- }
-
- if (sound_path != NULL)
- {
- if (WAV_PLAYER_ERROR_NONE == wav_player_start(sound_path, SOUND_TYPE_MEDIA, _play_sound_callback, NULL, NULL))
- {
- DEBUG_MSG("wav_player_start success");
- }
-
- _net_nfc_util_free_mem(sound_path);
- }
- else
- {
- DEBUG_ERR_MSG("Invalid Sound Path");
- }
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <gio/gio.h>
-
-#include "net_nfc_debug_internal.h"
-#include "net_nfc_gdbus.h"
-#include "net_nfc_server_common.h"
-#include "net_nfc_server.h"
-#include "net_nfc_server_manager.h"
-#include "net_nfc_server_tag.h"
-#include "net_nfc_server_ndef.h"
-#include "net_nfc_server_llcp.h"
-#include "net_nfc_server_p2p.h"
-#include "net_nfc_server_transceive.h"
-#include "net_nfc_server_test.h"
-#include "net_nfc_server_handover.h"
-#include "net_nfc_server_se.h"
-#include "net_nfc_server_snep.h"
-#include "net_nfc_server_system_handler.h"
-#include "net_nfc_server_context_internal.h"
-
-static GDBusConnection *connection = NULL;
-static guint subscribe_id;
-
-pid_t net_nfc_server_gdbus_get_pid(const char *name)
-{
- guint pid = 0;
- GError *error = NULL;
- GVariant *_ret;
-
- _ret = g_dbus_connection_call_sync(connection,
- "org.freedesktop.DBus",
- "/org/freedesktop/DBus",
- "org.freedesktop.DBus",
- "GetConnectionUnixProcessID",
- g_variant_new("(s)", name),
- NULL,
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- &error);
- if (_ret != NULL) {
- g_variant_get(_ret, "(u)", &pid);
- g_variant_unref(_ret);
- }
-
- return pid;
-}
-
-static void _name_owner_changed(GDBusProxy *proxy,
- const gchar *name, const gchar *old_owner,
- const gchar *new_owner, void *user_data)
-{
- if (name == NULL || old_owner == NULL || new_owner == NULL) {
- DEBUG_ERR_MSG("invalid parameter");
-
- return;
- }
-
- if (strlen(new_owner) == 0) {
- if (net_nfc_server_gdbus_check_client_is_running(old_owner)) {
- /* unregister service */
- net_nfc_server_llcp_unregister_services(old_owner);
-
- /* remove client context */
- net_nfc_server_gdbus_cleanup_client_context(old_owner);
- }
- }
-}
-
-static void _on_name_owner_changed(GDBusConnection *connection,
- const gchar *sender_name, const gchar *object_path,
- const gchar *interface_name, const gchar *signal_name,
- GVariant *parameters, gpointer user_data)
-{
- gchar *name;
- gchar *old_owner;
- gchar *new_owner;
-
- g_variant_get(parameters,
- "(sss)",
- &name,
- &old_owner,
- &new_owner);
-
- _name_owner_changed((GDBusProxy *)connection,
- name, old_owner, new_owner, user_data);
-}
-
-static void _subscribe_name_owner_changed_event()
-{
- if (connection == NULL)
- return;
-
- /* subscribe signal */
- subscribe_id = g_dbus_connection_signal_subscribe(connection,
- "org.freedesktop.DBus", /* bus name */
- "org.freedesktop.DBus", /* interface */
- "NameOwnerChanged", /* member */
- "/org/freedesktop/DBus", /* path */
- NULL, /* arg0 */
- G_DBUS_SIGNAL_FLAGS_NONE,
- _on_name_owner_changed,
- NULL, NULL);
-}
-
-static void _unsubscribe_name_owner_changed_event()
-{
- if (connection == NULL)
- return;
-
- /* subscribe signal */
- if (subscribe_id > 0) {
- g_dbus_connection_signal_unsubscribe(connection, subscribe_id);
- }
-}
-
-void net_nfc_server_gdbus_init(void)
-{
- GError *error = NULL;
-
- if (connection)
- g_object_unref(connection);
-
- connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
- if (connection == NULL)
- {
- DEBUG_ERR_MSG("Can not get connection %s", error->message);
- g_error_free (error);
- return;
- }
-
- net_nfc_server_gdbus_init_client_context();
-
- if (net_nfc_server_manager_init(connection) == FALSE)
- {
- DEBUG_ERR_MSG("Can not init manager");
- return;
- }
-
- if (net_nfc_server_tag_init(connection) == FALSE)
- {
- DEBUG_ERR_MSG("Can not init tag");
- return;
- }
-
- if (net_nfc_server_ndef_init(connection) == FALSE)
- {
- DEBUG_ERR_MSG("Can not init ndef");
- return;
- }
-
- if (net_nfc_server_llcp_init(connection) == FALSE)
- {
- DEBUG_ERR_MSG("Can not init llcp");
- return;
- }
-
- if (net_nfc_server_p2p_init(connection) == FALSE)
- {
- DEBUG_ERR_MSG("Can not init tag");
- return;
- }
-
- if (net_nfc_server_transceive_init(connection) == FALSE)
- {
- DEBUG_ERR_MSG("Can not initialize transceive");
- return;
- }
-
- if (net_nfc_server_test_init(connection) == FALSE)
- {
- DEBUG_ERR_MSG("Can not init Test");
- return;
- }
-
- if (net_nfc_server_handover_init(connection) == FALSE)
- {
- DEBUG_ERR_MSG("Can not initialize transceive");
- return;
- }
-
- if (net_nfc_server_se_init(connection) == FALSE)
- {
- DEBUG_ERR_MSG("Can not init Test");
- return;
- }
-
- if (net_nfc_server_snep_init(connection) == FALSE)
- {
- DEBUG_ERR_MSG("Can not init controller thread");
- return;
- }
-
- if (net_nfc_server_system_handler_init(connection) == FALSE)
- {
- DEBUG_ERR_MSG("Can not init controller thread");
- return;
- }
-
- if (net_nfc_server_controller_thread_init() == FALSE)
- {
- DEBUG_ERR_MSG("Can not init controller thread");
- return;
- }
-
- _subscribe_name_owner_changed_event();
-}
-
-void net_nfc_server_gdbus_deinit(void)
-{
- _unsubscribe_name_owner_changed_event();
-
- net_nfc_server_manager_deinit();
- net_nfc_server_tag_deinit();
- net_nfc_server_ndef_deinit();
- net_nfc_server_llcp_deinit();
- net_nfc_server_transceive_deinit();
- net_nfc_server_test_deinit();
- net_nfc_server_handover_deinit();
- net_nfc_server_se_deinit();
- net_nfc_server_snep_deinit();
- net_nfc_server_system_handler_deinit();
-
- net_nfc_server_gdbus_deinit_client_context();
-
- net_nfc_server_controller_thread_deinit();
-
- if (connection)
- {
- g_object_unref(connection);
- connection = NULL;
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <vconf.h>
-
-#include "net_nfc_debug_internal.h"
-#include "net_nfc_util_internal.h"
-#include "net_nfc_manager.h"
-#include "net_nfc_manager_util_internal.h"
-#include "net_nfc_controller_internal.h"
-#include "net_nfc_server_common.h"
-#include "net_nfc_server_tag.h"
-#include "net_nfc_server_llcp.h"
-#include "net_nfc_server_se.h"
-
-
-typedef struct _ControllerFuncData ControllerFuncData;
-
-struct _ControllerFuncData
-{
- net_nfc_server_controller_func func;
- gpointer data;
-};
-
-static gpointer controller_thread_func(gpointer user_data);
-
-static void controller_async_queue_free_func(gpointer user_data);
-
-static void controller_thread_deinit_thread_func(gpointer user_data);
-
-static void controller_target_detected_cb(void *info,
- void *user_context);
-
-static void controller_se_transaction_cb(void *info,
- void *user_context);
-
-static void controller_llcp_event_cb(void *info,
- void *user_context);
-
-static void controller_init_thread_func(gpointer user_data);
-
-#ifndef ESE_ALWAYS_ON
-static void controller_deinit_thread_func(gpointer user_data);
-#endif
-
-static void restart_polling_loop_thread_func(gpointer user_data);
-
-static GAsyncQueue *controller_async_queue = NULL;
-
-static GThread *controller_thread = NULL;
-
-static gboolean controller_is_running = FALSE;
-
-static guint32 server_state = NET_NFC_SERVER_IDLE;
-
-
-static gpointer controller_thread_func(gpointer user_data)
-{
- if (controller_async_queue == NULL)
- {
- g_thread_exit(NULL);
- return NULL;
- }
-
- controller_is_running = TRUE;
- while(controller_is_running)
- {
- ControllerFuncData *func_data;
-
- func_data = g_async_queue_pop(controller_async_queue);
- if (func_data->func)
- func_data->func(func_data->data);
-
- g_free(func_data);
- }
-
- g_thread_exit(NULL);
- return NULL;
-}
-
-static void controller_async_queue_free_func(gpointer user_data)
-{
- g_free(user_data);
-}
-
-static void controller_thread_deinit_thread_func(gpointer user_data)
-{
- controller_is_running = FALSE;
-}
-
-/* FIXME: it works as broadcast only now */
-static void controller_target_detected_cb(void *info,
- void *user_context)
-{
- net_nfc_request_target_detected_t *req =
- (net_nfc_request_target_detected_t *)info;
-
- g_assert(info != NULL);
-
- if (req->request_type == NET_NFC_MESSAGE_SERVICE_RESTART_POLLING_LOOP)
- {
- net_nfc_server_restart_polling_loop();
- }
- else
- {
- net_nfc_server_set_target_info(info);
-
- if (req->devType != NET_NFC_UNKNOWN_TARGET) {
- if (req->devType == NET_NFC_NFCIP1_TARGET ||
- req->devType == NET_NFC_NFCIP1_INITIATOR) {
- /* llcp target detected */
- net_nfc_server_llcp_target_detected(info);
- } else {
- /* tag target detected */
- net_nfc_server_tag_target_detected(info);
- }
- }
-
- /* If target detected, sound should be played. */
- net_nfc_manager_util_play_sound(NET_NFC_TASK_START);
- }
-
- /* FIXME : should be removed when plugins would be fixed*/
- _net_nfc_util_free_mem(info);
-}
-
-/* FIXME : net_nfc_dispatcher_queue_push() need to be removed */
-static void controller_se_transaction_cb(void *info,
- void *user_context)
-{
- net_nfc_request_se_event_t *req = (net_nfc_request_se_event_t *)info;
-
- g_assert(info != NULL);
-
- req->user_param = (uint32_t)user_context;
-
- switch(req->request_type)
- {
- case NET_NFC_MESSAGE_SERVICE_SLAVE_ESE_DETECTED :
- net_nfc_server_se_detected(req);
- break;
-
- case NET_NFC_MESSAGE_SE_START_TRANSACTION :
- net_nfc_server_se_transaction_received(req);
- break;
-
- default :
- break;
- }
-}
-
-/* FIXME : net_nfc_dispatcher_queue_push() need to be removed */
-static void controller_llcp_event_cb(void *info,
- void *user_context)
-{
- net_nfc_request_llcp_msg_t *req_llcp_msg;
- net_nfc_request_msg_t *req_msg;
-
- if (info == NULL)
- {
- DEBUG_ERR_MSG("can not get llcp_event info");
- return;
- }
-
- req_llcp_msg = (net_nfc_request_llcp_msg_t *)info;
- req_llcp_msg->user_param = (uint32_t) user_context;
-
- req_msg = (net_nfc_request_msg_t *)req_llcp_msg;
-
- switch (req_msg->request_type)
- {
- case NET_NFC_MESSAGE_SERVICE_LLCP_DEACTIVATED:
- net_nfc_server_llcp_deactivated(req_msg);
- break;
- case NET_NFC_MESSAGE_SERVICE_LLCP_LISTEN:
- net_nfc_server_llcp_listen(req_msg);
- break;
- case NET_NFC_MESSAGE_SERVICE_LLCP_SOCKET_ERROR:
- case NET_NFC_MESSAGE_SERVICE_LLCP_SOCKET_ACCEPTED_ERROR:
- net_nfc_server_llcp_socket_error(req_msg);
- break;
- case NET_NFC_MESSAGE_SERVICE_LLCP_SEND:
- case NET_NFC_MESSAGE_SERVICE_LLCP_SEND_TO:
- net_nfc_server_llcp_send(req_msg);
- break;
- case NET_NFC_MESSAGE_SERVICE_LLCP_RECEIVE:
- net_nfc_server_llcp_receive(req_msg);
- break;
- case NET_NFC_MESSAGE_SERVICE_LLCP_RECEIVE_FROM:
- net_nfc_server_llcp_receive_from(req_msg);
- break;
- case NET_NFC_MESSAGE_SERVICE_LLCP_CONNECT:
- case NET_NFC_MESSAGE_SERVICE_LLCP_CONNECT_SAP:
- net_nfc_server_llcp_connect(req_msg);
- break;
- case NET_NFC_MESSAGE_SERVICE_LLCP_DISCONNECT:
- net_nfc_server_llcp_disconnect(req_msg);
- break;
- case NET_NFC_MESSAGE_SERVICE_LLCP_ACCEPT: /* currently not used */
- break;
- default:
- break;
- }
-}
-
-static void controller_init_thread_func(gpointer user_data)
-{
- net_nfc_error_e result;
-
- if (net_nfc_controller_init(&result) == false)
- {
- DEBUG_ERR_MSG("%s failed [%d]",
- "net_nfc_controller_init",
- result);
-
- net_nfc_manager_quit();
- return;
- }
-
- DEBUG_SERVER_MSG("%s success [%d]",
- "net_nfc_controller_init",
- result);
-
- if (net_nfc_controller_register_listener(controller_target_detected_cb,
- controller_se_transaction_cb,
- controller_llcp_event_cb,
- &result) == false)
- {
- DEBUG_ERR_MSG("%s failed [%d]",
- "net_nfc_contorller_register_listener",
- result);
- }
- else
- {
- DEBUG_SERVER_MSG("%s success !!",
- "net_nfc_contorller_register_listener");
- }
-
- if (net_nfc_server_llcp_set_config(NULL) == NET_NFC_OK)
- DEBUG_SERVER_MSG("llcp is enabled !!");
- else
- DEBUG_ERR_MSG("net_nfc_server_llcp_set config failed");
-}
-
-#ifndef ESE_ALWAYS_ON
-static void controller_deinit_thread_func(gpointer user_data)
-{
- net_nfc_error_e result;
-
- net_nfc_controller_configure_discovery(NET_NFC_DISCOVERY_MODE_CONFIG,
- NET_NFC_ALL_DISABLE,
- &result);
-
- net_nfc_server_free_target_info();
-
- if (net_nfc_controller_deinit() == false)
- {
- DEBUG_ERR_MSG("%s is failed %d",
- "net_nfc_controller_deinit",
- result);
- return;
- }
-
- DEBUG_SERVER_MSG("%s success [%d]",
- "net_nfc_controller_deinit",
- result);
-
- net_nfc_manager_quit();
-}
-#endif
-
-static void restart_polling_loop_thread_func(gpointer user_data)
-{
-
- gint state = 0;
- gint pm_state = 0;
-
- net_nfc_error_e result;
-
- if (vconf_get_bool(VCONFKEY_NFC_STATE, &state) != 0)
- DEBUG_ERR_MSG("%s does not exist", "VCONFKEY_NFC_STATE");
- if (state == 0)
- return;
-
- if (vconf_get_int(VCONFKEY_PM_STATE, &pm_state) != 0)
- DEBUG_ERR_MSG("%s does not exist", "VCONFKEY_PM_STATE");
-
-
- DEBUG_SERVER_MSG("net_nfc_service_restart_polling, state = [%d]",
- pm_state);
-
-
- if (pm_state == VCONFKEY_PM_STATE_NORMAL)
- {
- if (net_nfc_controller_configure_discovery(
- NET_NFC_DISCOVERY_MODE_CONFIG,
- NET_NFC_ALL_ENABLE,
- &result) == true)
- {
- DEBUG_SERVER_MSG("polling enable");
- }
-
- return;
- }
-
- if (pm_state == VCONFKEY_PM_STATE_LCDOFF)
- {
- if (net_nfc_controller_configure_discovery(
- NET_NFC_DISCOVERY_MODE_CONFIG,
- NET_NFC_ALL_DISABLE,
- &result) == true)
- {
- DEBUG_SERVER_MSG("polling disabled");
- }
-
- return;
- }
-}
-
-gboolean net_nfc_server_controller_thread_init(void)
-{
- GError *error = NULL;
-
- controller_async_queue = g_async_queue_new_full(
- controller_async_queue_free_func);
-
- controller_thread = g_thread_try_new("controller_thread",
- controller_thread_func,
- NULL,
- &error);
-
- if (controller_thread == NULL)
- {
- DEBUG_ERR_MSG("can not create controller thread: %s",
- error->message);
- g_error_free(error);
- return FALSE;
- }
-
- return TRUE;
-}
-
-void net_nfc_server_controller_thread_deinit(void)
-{
- if(net_nfc_server_controller_async_queue_push(
- controller_thread_deinit_thread_func,
- NULL)==FALSE)
- {
- DEBUG_ERR_MSG("Failed to push onto the queue");
- }
-
- g_thread_join(controller_thread);
- controller_thread = NULL;
-
- g_async_queue_unref(controller_async_queue);
- controller_async_queue = NULL;
-}
-
-void net_nfc_server_controller_init(void)
-{
- if(net_nfc_server_controller_async_queue_push(
- controller_init_thread_func,
- NULL)==FALSE)
- {
- DEBUG_ERR_MSG("Failed to push onto the queue");
- }
-}
-
-#ifndef ESE_ALWAYS_ON
-void net_nfc_server_controller_deinit(void)
-{
- net_nfc_server_controller_async_queue_push(
- controller_deinit_thread_func,
- NULL);
-}
-#endif
-
-gboolean net_nfc_server_controller_async_queue_push(
- net_nfc_server_controller_func func,
- gpointer user_data)
-{
- ControllerFuncData *func_data;
-
- if(controller_async_queue == NULL)
- {
- DEBUG_ERR_MSG("controller_async_queue is not initialized");
- return FALSE;
- }
-
- func_data = g_new0(ControllerFuncData, 1);
- func_data->func = func;
- func_data->data = user_data;
-
- g_async_queue_push(controller_async_queue, func_data);
-
- return TRUE;
-}
-
-void net_nfc_server_restart_polling_loop(void)
-{
- if(net_nfc_server_controller_async_queue_push(
- restart_polling_loop_thread_func,
- NULL) == FALSE)
- {
- DEBUG_ERR_MSG("Failed to push onto the queue");
- }
-}
-
-void net_nfc_server_set_state(guint32 state)
-{
- if (state == NET_NFC_SERVER_IDLE)
- server_state &= NET_NFC_SERVER_IDLE;
- else
- server_state |= state;
-}
-
-void net_nfc_server_unset_state(guint32 state)
-{
- server_state &= ~state;
-}
-
-guint32 net_nfc_server_get_state(void)
-{
- return server_state;
-}
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <unistd.h>
-#include <glib.h>
-
-#include "vconf.h"
-#ifdef SECURITY_SERVER
-#include "security-server.h"
-#endif
-
-#include "net_nfc_manager.h"
-#include "net_nfc_debug_internal.h"
-#include "net_nfc_util_internal.h"
-#include "net_nfc_util_defines.h"
-#include "net_nfc_util_gdbus_internal.h"
-#include "net_nfc_server.h"
-#include "net_nfc_server_context_internal.h"
-
-
-static GHashTable *client_contexts;
-static pthread_mutex_t context_lock = PTHREAD_MUTEX_INITIALIZER;
-
-static void _cleanup_client_context(gpointer data)
-{
- net_nfc_client_context_info_t *info = data;
-
- if (info != NULL)
- {
- g_free(info->id);
- g_free(info);
- }
-}
-
-void net_nfc_server_gdbus_init_client_context()
-{
- pthread_mutex_lock(&context_lock);
-
- if (client_contexts == NULL)
- client_contexts = g_hash_table_new(g_str_hash, g_str_equal);
-
- pthread_mutex_unlock(&context_lock);
-}
-
-void net_nfc_server_gdbus_deinit_client_context()
-{
- pthread_mutex_lock(&context_lock);
-
- if (client_contexts != NULL) {
- g_hash_table_destroy(client_contexts);
- client_contexts = NULL;
- }
-
- pthread_mutex_unlock(&context_lock);
-}
-
-/* TODO */
-bool net_nfc_server_gdbus_check_privilege(GDBusMethodInvocation *invocation,
- GVariant *privilege,
- const char *object,
- const char *right)
-{
-#ifdef SECURITY_SERVER
- data_s priv = { NULL, 0 };
- int result;
-
- if (privilege == NULL || object == NULL || right == NULL) {
- return false;
- }
-
- net_nfc_util_gdbus_variant_to_data_s(privilege, &priv);
-
- result = security_server_check_privilege_by_cookie((char *)priv.buffer,
- object, right);
-
- net_nfc_util_free_data(&priv);
-
- if (result < 0) {
- DEBUG_ERR_MSG("permission denied : \"%s\", \"%s\"", object, right);
- g_dbus_method_invocation_return_dbus_error(invocation,
- "org.tizen.NetNfcService.Privilege",
- "Permission denied");
-
- return false;
- }
-#endif
- const char *id = g_dbus_method_invocation_get_sender(invocation);
-
- net_nfc_server_gdbus_add_client_context(id,
- NET_NFC_CLIENT_ACTIVE_STATE);
-
- return true;
-}
-
-size_t net_nfc_server_gdbus_get_client_count_no_lock()
-{
- return g_hash_table_size(client_contexts);
-}
-
-size_t net_nfc_server_gdbus_get_client_count()
-{
- size_t result;
-
- pthread_mutex_lock(&context_lock);
-
- result = net_nfc_server_gdbus_get_client_count_no_lock();
-
- pthread_mutex_unlock(&context_lock);
-
- return result;
-}
-
-net_nfc_client_context_info_t *net_nfc_server_gdbus_get_client_context_no_lock(
- const char *id)
-{
- net_nfc_client_context_info_t *result;
-
- result = g_hash_table_lookup(client_contexts, id);
-
- return result;
-}
-
-net_nfc_client_context_info_t *net_nfc_server_gdbus_get_client_context(
- const char *id)
-{
- net_nfc_client_context_info_t *result;
-
- pthread_mutex_lock(&context_lock);
-
- result = net_nfc_server_gdbus_get_client_context_no_lock(id);
-
- pthread_mutex_unlock(&context_lock);
-
- return result;
-}
-
-void net_nfc_server_gdbus_add_client_context(const char *id,
- client_state_e state)
-{
- pthread_mutex_lock(&context_lock);
-
- if (net_nfc_server_gdbus_get_client_context_no_lock(id) == NULL)
- {
- net_nfc_client_context_info_t *info = NULL;
-
- info = g_new0(net_nfc_client_context_info_t, 1);
- if (info != NULL)
- {
- pid_t pid;
-
- pid = net_nfc_server_gdbus_get_pid(id);
- DEBUG_SERVER_MSG("added client id : [%s], pid [%d]", id, pid);
-
- info->id = g_strdup(id);
- info->pid = pid;
- info->pgid = getpgid(pid);
- info->state = state;
- info->launch_popup_state = NET_NFC_LAUNCH_APP_SELECT;
- info->launch_popup_state_no_check = NET_NFC_LAUNCH_APP_SELECT;
-
- g_hash_table_insert(client_contexts,
- (gpointer)info->id,
- (gpointer)info);
-
- DEBUG_SERVER_MSG("current client count = [%d]",
- net_nfc_server_gdbus_get_client_count_no_lock());
- }
- else
- {
- DEBUG_ERR_MSG("alloc failed");
- }
- }
-
- pthread_mutex_unlock(&context_lock);
-}
-
-void net_nfc_server_gdbus_cleanup_client_context(const char *id)
-{
- net_nfc_client_context_info_t *info;
-
- pthread_mutex_lock(&context_lock);
-
- info = net_nfc_server_gdbus_get_client_context_no_lock(id);
- if (info != NULL)
- {
- DEBUG_SERVER_MSG("clean up client context, [%s, %d]", info->id,
- info->pid);
-
- g_hash_table_remove(client_contexts, id);
-
- _cleanup_client_context(info);
-
- DEBUG_SERVER_MSG("current client count = [%d]",
- net_nfc_server_gdbus_get_client_count_no_lock());
-
-// /* TODO : exit when no client */
-// if (net_nfc_server_gdbus_get_client_count_no_lock() == 0)
-// {
-// /* terminate service */
-// net_nfc_manager_quit();
-// }
- }
-
- pthread_mutex_unlock(&context_lock);
-}
-
-void net_nfc_server_gdbus_for_each_client_context(
- net_nfc_server_gdbus_for_each_client_cb cb,
- void *user_param)
-{
- GHashTableIter iter;
- char *id;
- net_nfc_client_context_info_t *info;
-
- if (cb == NULL)
- return;
-
- pthread_mutex_lock(&context_lock);
-
- g_hash_table_iter_init(&iter, client_contexts);
- while (g_hash_table_iter_next(&iter, (gpointer *)&id,
- (gpointer *)&info) == true) {
- cb(info, user_param);
- }
-
- pthread_mutex_unlock(&context_lock);
-}
-
-bool net_nfc_server_gdbus_check_client_is_running(const char *id)
-{
- return (net_nfc_server_gdbus_get_client_context(id) != NULL);
-}
-
-client_state_e net_nfc_server_gdbus_get_client_state(const char *id)
-{
- net_nfc_client_context_info_t *info;
- client_state_e state = NET_NFC_CLIENT_INACTIVE_STATE;
-
- pthread_mutex_lock(&context_lock);
-
- info = net_nfc_server_gdbus_get_client_context_no_lock(id);
- if (info != NULL) {
- state = info->state;
- }
-
- pthread_mutex_unlock(&context_lock);
-
- return state;
-}
-
-void net_nfc_server_gdbus_set_client_state(const char *id, client_state_e state)
-{
- net_nfc_client_context_info_t *info;
-
- pthread_mutex_lock(&context_lock);
-
- info = net_nfc_server_gdbus_get_client_context_no_lock(id);
- if (info != NULL) {
- info->state = state;
- }
-
- pthread_mutex_unlock(&context_lock);
-}
-
-void net_nfc_server_gdbus_set_launch_state(const char *id,
- net_nfc_launch_popup_state_e popup_state,
- net_nfc_launch_popup_check_e check_foreground)
-{
- net_nfc_client_context_info_t *info;
-
- pthread_mutex_lock(&context_lock);
-
- info = net_nfc_server_gdbus_get_client_context_no_lock(id);
- if (info != NULL) {
- if (check_foreground == CHECK_FOREGROUND) {
- info->launch_popup_state = popup_state;
- } else {
- info->launch_popup_state_no_check = popup_state;
- }
- }
-
- pthread_mutex_unlock(&context_lock);
-}
-
-net_nfc_launch_popup_state_e net_nfc_server_gdbus_get_launch_state(
- const char *id)
-{
- net_nfc_client_context_info_t *info;
- net_nfc_launch_popup_state_e result = NET_NFC_LAUNCH_APP_SELECT;
-
- pthread_mutex_lock(&context_lock);
-
- info = net_nfc_server_gdbus_get_client_context_no_lock(id);
- if (info != NULL) {
- if (info->launch_popup_state_no_check ==
- NET_NFC_NO_LAUNCH_APP_SELECT) {
- result = NET_NFC_NO_LAUNCH_APP_SELECT;
- } else {
- result = info->launch_popup_state;
- }
- }
-
- pthread_mutex_unlock(&context_lock);
-
- return result;
-}
-
-net_nfc_launch_popup_state_e net_nfc_server_gdbus_get_client_popup_state(
- pid_t pid)
-{
- GHashTableIter iter;
- char *id;
- net_nfc_launch_popup_state_e state = NET_NFC_LAUNCH_APP_SELECT;
- net_nfc_client_context_info_t *info = NULL, *temp;
-
- pthread_mutex_lock(&context_lock);
-
- g_hash_table_iter_init(&iter, client_contexts);
- while (g_hash_table_iter_next(&iter, (gpointer *)&id,
- (gpointer *)&temp) == true) {
- if (temp->launch_popup_state_no_check ==
- NET_NFC_NO_LAUNCH_APP_SELECT) {
- state = NET_NFC_NO_LAUNCH_APP_SELECT;
- break;
- }
-
- if (temp->pgid == pid) {
- info = temp;
- break;
- }
- }
-
- if (info != NULL) {
- state = info->launch_popup_state;
- }
-
- pthread_mutex_unlock(&context_lock);
-
- return state;
-}
-
-void net_nfc_server_gdbus_increase_se_count(const char *id)
-{
- net_nfc_client_context_info_t *info;
-
- pthread_mutex_lock(&context_lock);
-
- info = net_nfc_server_gdbus_get_client_context_no_lock(id);
- if (info != NULL) {
- info->ref_se++;
- }
-
- pthread_mutex_unlock(&context_lock);
-}
-
-void net_nfc_server_gdbus_decrease_se_count(const char *id)
-{
- net_nfc_client_context_info_t *info;
-
- pthread_mutex_lock(&context_lock);
-
- info = net_nfc_server_gdbus_get_client_context_no_lock(id);
- if (info != NULL) {
- info->ref_se--;
- }
-
- pthread_mutex_unlock(&context_lock);
-}
-
-bool net_nfc_server_gdbus_is_server_busy()
-{
- bool result = false;
-
- pthread_mutex_lock(&context_lock);
-
- if (g_hash_table_size(client_contexts) > 0) {
- GHashTableIter iter;
- char *id;
- net_nfc_client_context_info_t *info;
-
- g_hash_table_iter_init(&iter, client_contexts);
- while (g_hash_table_iter_next(&iter, (gpointer *)&id,
- (gpointer *)&info) == true) {
- if (info->ref_se > 0) {
- result = true;
- break;
- }
- }
- }
-
- pthread_mutex_unlock(&context_lock);
-
- return result;
-}
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-#include "net_nfc_server_common.h"
-#include "net_nfc_server_process_handover.h"
-#include "net_nfc_server_handover.h"
-#include "net_nfc_debug_internal.h"
-#include "net_nfc_controller_internal.h"
-#include "net_nfc_util_gdbus_internal.h"
-#include "net_nfc_server_context_internal.h"
-
-static NetNfcGDbusHandover *handover_skeleton = NULL;
-
-static void handover_request_thread_func(gpointer user_data);
-
-static gboolean handover_handle_request(NetNfcGDbusHandover *hdover,
- GDBusMethodInvocation *invocation,
- guint32 arg_handle,
- gint32 arg_type,
- GVariant *smack_privilege,
- gpointer user_data);
-
-static void handover_request_thread_func(gpointer user_data)
-{
- HandoverRequestData *handover_data;
- net_nfc_target_handle_s *handle;
- net_nfc_error_e error = NET_NFC_OK;
-
- handover_data = (HandoverRequestData *)user_data;
-
- if (handover_data == NULL)
- {
- DEBUG_ERR_MSG("cannot send Handover data");
-
- return;
- }
-
- if (handover_data->handoverobj == NULL)
- {
- DEBUG_ERR_MSG("can not get Handover object");
-
- if (handover_data->invocation)
- {
- g_dbus_method_invocation_return_dbus_error(
- handover_data->invocation,
- "org.tizen.NetNfcService.Handover.DataError",
- "Handover invocation is NULL");
-
- g_object_unref(handover_data->invocation);
- }
-
- g_free(handover_data);
-
- return;
- }
-
- handle = GUINT_TO_POINTER(handover_data->handle);
-
- if ((error = net_nfc_server_handover_default_client_start(
- handle,
- (void *)handover_data)) != NET_NFC_OK)
- {
- if (handover_data->invocation)
- {
- g_dbus_method_invocation_return_dbus_error(
- handover_data->invocation,
- "org.tizen.NetNfcService.Handover.SendError",
- "handover operation unsuccessfull");
-
- g_object_unref(handover_data->invocation);
- }
-
- g_object_unref(handover_data->handoverobj);
- g_free(handover_data);
- }
-}
-
-static gboolean handover_handle_request(NetNfcGDbusHandover *hdover,
- GDBusMethodInvocation *invocation,
- guint32 arg_handle,
- gint32 arg_type,
- GVariant *smack_privilege,
- gpointer user_data)
-{
- HandoverRequestData *data;
-
- INFO_MSG(">>> REQUEST from [%s]",
- g_dbus_method_invocation_get_sender(invocation));
-
- /* check privilege and update client context */
- if (net_nfc_server_gdbus_check_privilege(invocation,
- smack_privilege,
- "nfc-manager::p2p",
- "rw") == false) {
- DEBUG_ERR_MSG("permission denied, and finished request");
-
- return TRUE;
- }
-
- data = g_new0(HandoverRequestData,1);
- if(data == NULL)
- {
- DEBUG_ERR_MSG("Memory allocation failed");
- g_dbus_method_invocation_return_dbus_error(invocation,
- "org.tizen.NetNfcService.AllocationError",
- "Can not allocate memory");
- return FALSE;
- }
-
- data->handoverobj = g_object_ref(hdover);
- data->handle = arg_handle;
- data->type = arg_type;
- data->invocation = g_object_ref(invocation);
-
- if (net_nfc_server_controller_async_queue_push(
- handover_request_thread_func, data) == FALSE)
- {
- g_dbus_method_invocation_return_dbus_error(invocation,
- "org.tizen.NetNfcService.Handover.ThreadError",
- "can not push to controller thread");
-
- g_object_unref(data->handoverobj);
- g_object_unref(data->invocation);
- g_free(data);
-
- return FALSE;
- }
-
- return TRUE;
-}
-
-gboolean net_nfc_server_handover_init(GDBusConnection *connection)
-{
- GError *error = NULL;
-
- if (handover_skeleton)
- g_object_unref(handover_skeleton);
-
- handover_skeleton = net_nfc_gdbus_handover_skeleton_new();
-
- g_signal_connect(handover_skeleton,
- "handle-request",
- G_CALLBACK(handover_handle_request),
- NULL);
-
- if (g_dbus_interface_skeleton_export(
- G_DBUS_INTERFACE_SKELETON(handover_skeleton),
- connection,
- "/org/tizen/NetNfcService/Handover",
- &error) == FALSE)
- {
- g_error_free(error);
- g_object_unref(handover_skeleton);
- handover_skeleton = NULL;
-
- return FALSE;
- }
-
- return TRUE;
-}
-
-void net_nfc_server_handover_deinit(void)
-{
- if (handover_skeleton)
- {
- g_object_unref(handover_skeleton);
- handover_skeleton = NULL;
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "net_nfc_util_handover.h"
-#include "net_nfc_server_handover_bss.h"
-
-static int _net_nfc_handover_bss_process_carrier_record(
- net_nfc_handover_bss_process_context_t *context);
-
-int _net_nfc_handover_bss_convert_security_type(int value)
-{
- int retval = 0;
- switch (value)
- {
- case 0x0001: /* Open */
- retval = WIFI_SECURITY_TYPE_NONE;
- break;
- case 0x0002: /* WPA - Personal */
- retval = WIFI_SECURITY_TYPE_WPA_PSK;
- break;
- case 0x0004: /* WPA - Shared */
- retval = WIFI_SECURITY_TYPE_WEP;
- break;
- case 0x0008: /* WPA - Enterprise */
- case 0x0010: /* WPA2 - Enterprise */
- retval = WIFI_SECURITY_TYPE_EAP;
- break;
- case 0x0020: /* WPA2 - Personal */
- retval = WIFI_SECURITY_TYPE_WPA_PSK;
- break;
- default:
- DEBUG_ERR_MSG("Invalid security Type");
- retval = 0;
- }
- return retval;
-}
-
-int _net_nfc_handover_bss_convert_encryption_type (int enc_type)
-{
- int retval = 0;
- switch (enc_type)
- {
- case 0x0001: /* None */
- retval = WIFI_ENCRYPTION_TYPE_NONE;
- break;
- case 0x0002: /* WEP */
- retval = WIFI_ENCRYPTION_TYPE_WEP;
- break;
- case 0x0004: /* TKIP */
- retval = WIFI_ENCRYPTION_TYPE_TKIP;
- break;
- case 0x0008: /* AES */
- retval = WIFI_ENCRYPTION_TYPE_AES;
- break;
- case 0x000C: /* TKIP + AES */
- retval = WIFI_ENCRYPTION_TYPE_TKIP_AES_MIXED;
- break;
- default:
- DEBUG_ERR_MSG("Invalid Encryption type");
- retval = 0;
- }
- return retval;
-}
-
-wifi_ap_h
-_net_nfc_handover_bss_create_ap(net_nfc_carrier_config_s *config)
-{
- wifi_ap_h ap_handle = NULL;
- data_s temp = { NULL, 0 };
- int err = WIFI_ERROR_NONE;
-
- // Sets SSID
- err = net_nfc_util_get_carrier_config_property(config,
- NET_NFC_WIFI_ATTRIBUTE_SSID,(uint16_t *)&temp.length, &temp.buffer);
- DEBUG_SERVER_MSG("SSID = [%s] err %d",temp.buffer, err);
- err = wifi_ap_create((char*)temp.buffer, &ap_handle);
- if(err != WIFI_ERROR_NONE)
- {
- DEBUG_ERR_MSG("Failed to create AP information %d",err);
- goto error;
- }
-
- // Sets Authentication Type
- net_nfc_util_get_carrier_config_property(config,
- NET_NFC_WIFI_ATTRIBUTE_AUTH_TYPE,(uint16_t *)&temp.length, &temp.buffer);
- if(temp.length == 2)
- {
- uint16_t securitytype = temp.buffer[0] <<8 | temp.buffer[1];
- DEBUG_MSG("wifi_ap_set_security_type %x", securitytype);
- err = wifi_ap_set_security_type(ap_handle,
- _net_nfc_handover_bss_convert_security_type(securitytype));
- if(err != WIFI_ERROR_NONE)
- {
- DEBUG_ERR_MSG("set security type failed");
- goto error;
- }
- }
- else
- {
- DEBUG_ERR_MSG("Invalid authentication length");
- goto error;
- }
- net_nfc_util_get_carrier_config_property(config,
- NET_NFC_WIFI_ATTRIBUTE_NET_KEY,(uint16_t *)&temp.length, &temp.buffer);
-
- // Sets Network Key
- err = wifi_ap_set_passphrase(ap_handle,(char*)temp.buffer);
- if(err != WIFI_ERROR_NONE)
- {
- DEBUG_ERR_MSG("Failed to set passphrase");
- goto error;
- }
- // Sets encryption Type
- net_nfc_util_get_carrier_config_property(config,
- NET_NFC_WIFI_ATTRIBUTE_ENC_TYPE,(uint16_t *)&temp.length, &temp.buffer);
- if(temp.length == 2)
- {
- uint16_t enc_type = temp.buffer[0] <<8 | temp.buffer[1];
- DEBUG_MSG("wifi_ap_set_encryption_type %x", enc_type);
- err = wifi_ap_set_encryption_type(ap_handle,
- _net_nfc_handover_bss_convert_encryption_type(enc_type));
- }
- else
- {
- DEBUG_ERR_MSG("Invalid Encryption length");
- goto error;
- }
- return ap_handle;
-error:
- if(ap_handle != NULL)
- {
- wifi_ap_destroy(ap_handle);
- }
- return NULL;
-}
-
-void
-_net_nfc_handover_bss_on_wifi_activated(wifi_error_e errorCode, void* user_data)
-{
- net_nfc_handover_bss_process_context_t *context = user_data;
- if(context == NULL)
- {
- DEBUG_ERR_MSG("Invalid context");
- context->result = NET_NFC_OPERATION_FAIL;
- }
- if (errorCode == WIFI_ERROR_NONE)
- {
- DEBUG_ERR_MSG("WIFI activated succesfully");
- context->result = NET_NFC_OK;
- }
- else
- {
- DEBUG_ERR_MSG("Failed to activate WIFI");
- context->result = NET_NFC_OPERATION_FAIL;
- }
-}
-
-bool
-_net_nfc_handover_bss_wifi_for_each_access_point_found(
- wifi_ap_h ap_handle, void *user_data)
-{
- data_s temp_ssid = { NULL, 0 };
- int err = WIFI_ERROR_NONE;
- char* essid = NULL;
- net_nfc_handover_bss_process_context_t *context = user_data;
-
- if(context == NULL)
- {
- DEBUG_ERR_MSG("Invalid context");
- context->result = NET_NFC_OPERATION_FAIL;
- context->step = NET_NFC_LLCP_STEP_RETURN;
- g_idle_add(
- (GSourceFunc)_net_nfc_handover_bss_process_carrier_record,
- (gpointer)context);
- return false;
- }
-
- wifi_ap_clone(&context->ap_handle, ap_handle);
- err = net_nfc_util_get_carrier_config_property(context->config,
- NET_NFC_WIFI_ATTRIBUTE_SSID,(uint16_t *)&temp_ssid.length,
- &temp_ssid.buffer);
-
- if(err != WIFI_ERROR_NONE)
- {
- DEBUG_ERR_MSG("Wifi get carrier config failed");
- context->result = NET_NFC_OPERATION_FAIL;
- context->step = NET_NFC_LLCP_STEP_RETURN;
- g_idle_add(
- (GSourceFunc)_net_nfc_handover_bss_process_carrier_record,
- (gpointer)context);
- return false;
- }
-
- wifi_ap_get_essid(ap_handle, &essid);
- DEBUG_MSG("Scan Result Ap essid [%s]",essid);
- if(memcmp(temp_ssid.buffer, essid,temp_ssid.length) == 0)
- {
- return false;
- }
- else
- {
- wifi_ap_destroy(context->ap_handle);
- context->ap_handle = NULL;
- }
- return true;
-}
-
-void
-_net_nfc_handover_bss_on_wifi_bgscan_completed(wifi_error_e errorCode,
- void* user_data)
-{
- int err = WIFI_ERROR_NONE;
- net_nfc_handover_bss_process_context_t *context = user_data;
-
- if(context == NULL)
- {
- DEBUG_ERR_MSG("Invalid context");
- context->result = NET_NFC_OPERATION_FAIL;
- context->step = NET_NFC_LLCP_STEP_RETURN;
- g_idle_add(
- (GSourceFunc)_net_nfc_handover_bss_process_carrier_record,
- (gpointer)context);
- return false;
- }
-
- if(errorCode != WIFI_ERROR_NONE)
- {
- DEBUG_ERR_MSG("Wifi scan failed");
- context->result = NET_NFC_OPERATION_FAIL;
- context->step = NET_NFC_LLCP_STEP_RETURN;
- g_idle_add(
- (GSourceFunc)_net_nfc_handover_bss_process_carrier_record,
- (gpointer)context);
- }
- else
- {
- net_nfc_util_create_carrier_config_from_config_record(
- &context->config, context->carrier);
- context->ap_handle = NULL;
- err = wifi_foreach_found_aps(
- _net_nfc_handover_bss_wifi_for_each_access_point_found,
- context);
- if(err != WIFI_ERROR_NONE)
- {
- DEBUG_ERR_MSG("wifi_foreach_found_aps failed Err[%x]",err);
- context->result = NET_NFC_OPERATION_FAIL;
- context->step = NET_NFC_LLCP_STEP_RETURN;
- g_idle_add(
- (GSourceFunc)_net_nfc_handover_bss_process_carrier_record,
- (gpointer)context);
- }
- if(context->ap_handle == NULL)
- {
- wifi_encryption_type_e enc_type;
- wifi_security_type_e sec_type;
- DEBUG_MSG("It's Hidden AP");
- context->ap_handle = _net_nfc_handover_bss_create_ap(
- context->config);
- wifi_ap_get_encryption_type(context->ap_handle, &enc_type);
- DEBUG_MSG("Encryption type %x",enc_type);
- wifi_ap_get_security_type(context->ap_handle, &sec_type);
- DEBUG_MSG("Authentication type %x", sec_type);
- }
- else
- {
- data_s temp = { NULL, 0 };
- wifi_encryption_type_e enc_type = WIFI_ENCRYPTION_TYPE_NONE;
- wifi_security_type_e sec_type = WIFI_SECURITY_TYPE_NONE;
- //set passkey
- net_nfc_util_get_carrier_config_property(context->config,
- NET_NFC_WIFI_ATTRIBUTE_NET_KEY,(uint16_t *)&temp.length,
- &temp.buffer);
-
- DEBUG_ERR_MSG("Network Key %s",temp.buffer);
- // Sets Network Key
- err = wifi_ap_set_passphrase(context->ap_handle,
- (char*)temp.buffer);
-
- wifi_ap_get_encryption_type(context->ap_handle, &enc_type);
- DEBUG_MSG("Encryption type %x",enc_type);
- wifi_ap_get_security_type(context->ap_handle, &sec_type);
- DEBUG_MSG("Authentication type %x", sec_type);
- }
- context->step = NET_NFC_LLCP_STEP_03;
- g_idle_add(
- (GSourceFunc)_net_nfc_handover_bss_process_carrier_record,
- (gpointer)context);
-
- }
-}
-
-void
-_net_nfc_handover_bss_on_wifi_scan_completed(wifi_error_e errorCode,
- void* user_data)
-{
- int err = WIFI_ERROR_NONE;
- net_nfc_handover_bss_process_context_t *context = user_data;
-
- if(context == NULL)
- {
- DEBUG_ERR_MSG("Invalid context");
- context->result = NET_NFC_OPERATION_FAIL;
- context->step = NET_NFC_LLCP_STEP_RETURN;
- g_idle_add(
- (GSourceFunc)_net_nfc_handover_bss_process_carrier_record,
- (gpointer)context);
- return false;
- }
-
- if(errorCode != WIFI_ERROR_NONE)
- {
- DEBUG_ERR_MSG("Wifi scan failed");
- context->result = NET_NFC_OPERATION_FAIL;
- context->step = NET_NFC_LLCP_STEP_RETURN;
- g_idle_add(
- (GSourceFunc)_net_nfc_handover_bss_process_carrier_record,
- (gpointer)context);
- }
- else
- {
- net_nfc_util_create_carrier_config_from_config_record(
- &context->config, context->carrier);
- context->ap_handle = NULL;
- err = wifi_foreach_found_aps(
- _net_nfc_handover_bss_wifi_for_each_access_point_found,
- context);
- if(err != WIFI_ERROR_NONE)
- {
- DEBUG_ERR_MSG("wifi_foreach_found_aps failed Err[%x]",err);
- context->result = NET_NFC_OPERATION_FAIL;
- context->step = NET_NFC_LLCP_STEP_RETURN;
- g_idle_add(
- (GSourceFunc)_net_nfc_handover_bss_process_carrier_record,
- (gpointer)context);
-
- }
- if(context->ap_handle == NULL)
- {
- wifi_encryption_type_e enc_type;
- wifi_security_type_e sec_type;
- DEBUG_MSG("It's Hidden AP");
- context->ap_handle = _net_nfc_handover_bss_create_ap(
- context->config);
- wifi_ap_get_encryption_type(context->ap_handle, &enc_type);
- DEBUG_MSG("Encryption type %x",enc_type);
- wifi_ap_get_security_type(context->ap_handle, &sec_type);
- DEBUG_MSG("Authentication type %x", sec_type);
- }
- else
- {
- data_s temp = { NULL, 0 };
- wifi_encryption_type_e enc_type = WIFI_ENCRYPTION_TYPE_NONE;
- wifi_security_type_e sec_type = WIFI_SECURITY_TYPE_NONE;
- //set passkey
- net_nfc_util_get_carrier_config_property(context->config,
- NET_NFC_WIFI_ATTRIBUTE_NET_KEY,(uint16_t *)&temp.length,
- &temp.buffer);
-
- DEBUG_ERR_MSG("Network Key %s",temp.buffer);
- // Sets Network Key
- err = wifi_ap_set_passphrase(context->ap_handle,(char*)temp.buffer);
-
- wifi_ap_get_encryption_type(context->ap_handle, &enc_type);
- DEBUG_MSG("Encryption type %x",enc_type);
- wifi_ap_get_security_type(context->ap_handle, &sec_type);
- DEBUG_MSG("Authentication type %x", sec_type);
- }
- context->step = NET_NFC_LLCP_STEP_03;
- g_idle_add(
- (GSourceFunc)_net_nfc_handover_bss_process_carrier_record,
- (gpointer)context);
-
- }
-
-}
-
-void
-_net_nfc_handover_bss_on_wifi_connected(wifi_error_e errorCode, void* user_data)
-{
- net_nfc_handover_bss_process_context_t *context = user_data;
-
- if(context == NULL)
- {
- DEBUG_ERR_MSG("Invalid context");
- context->result = NET_NFC_OPERATION_FAIL;
- context->step = NET_NFC_LLCP_STEP_RETURN;
- g_idle_add(
- (GSourceFunc)_net_nfc_handover_bss_process_carrier_record,
- (gpointer)context);
- return false;
- }
-
- if(errorCode == WIFI_ERROR_NONE)
- {
- DEBUG_ERR_MSG("WIFI Connected succesfully");
- context->result = NET_NFC_OK;
- }
- else
- {
- DEBUG_ERR_MSG("Failed to connect WIFI");
- context->result = NET_NFC_OPERATION_FAIL;
- }
- context->step = NET_NFC_LLCP_STEP_RETURN;
- g_idle_add(
- (GSourceFunc)_net_nfc_handover_bss_process_carrier_record,
- (gpointer)context);
-}
-
-static int _net_nfc_handover_bss_process_carrier_record(
- net_nfc_handover_bss_process_context_t *context)
-{
- LOGD("[%s:%d] START", __func__, __LINE__);
-
- if(context == NULL)
- {
- DEBUG_ERR_MSG("Invalid context");
- DEBUG_ERR_MSG("Handover Failed");
- return -1;
- }
-
- if (context->result != NET_NFC_OK && context->result != NET_NFC_BUSY)
- {
- DEBUG_ERR_MSG("context->result is error"
- " [%d]", context->result);
- context->step = NET_NFC_LLCP_STEP_RETURN;
- }
-
- switch (context->step)
- {
- case NET_NFC_LLCP_STEP_01 :
- {
- int err = WIFI_ERROR_NONE;
- DEBUG_MSG("STEP [1]");
- err = wifi_initialize();
- /* WIFI returns WIFI_ERROR_INVALID_OPERATION in case already
- * initialized*/
- if (err == WIFI_ERROR_NONE || err == WIFI_ERROR_INVALID_OPERATION)
- {
- bool val = false;
-
- err = wifi_is_activated(&val);
- /* next step */
-
- if (val == false)
- {
- context->result = NET_NFC_OK;
- wifi_set_background_scan_cb(
- _net_nfc_handover_bss_on_wifi_bgscan_completed, context);
- wifi_activate(
- _net_nfc_handover_bss_on_wifi_activated, context);
- }
- else
- {
- /* do next step */
- DEBUG_MSG("Wifi is enabled already, go next step");
- context->result = NET_NFC_OK;
- context->step = NET_NFC_LLCP_STEP_02;
- g_idle_add((GSourceFunc)
- _net_nfc_handover_bss_process_carrier_record,
- (gpointer)context);
- }
- }
- else
- {
- DEBUG_ERR_MSG("Wifi init failed");
- context->result = NET_NFC_OPERATION_FAIL;
- context->step = NET_NFC_LLCP_STEP_RETURN;
- g_idle_add(
- (GSourceFunc)_net_nfc_handover_bss_process_carrier_record,
- (gpointer)context);
- }
- }
- break;
-
- case NET_NFC_LLCP_STEP_02 :
- {
-
- int err = WIFI_ERROR_NONE;
- DEBUG_MSG("STEP [2]");
- err = wifi_scan(_net_nfc_handover_bss_on_wifi_scan_completed,
- context);
- if(err != WIFI_ERROR_NONE)
- {
- DEBUG_ERR_MSG("Wifi scan failed");
- context->result = NET_NFC_OPERATION_FAIL;
- context->step = NET_NFC_LLCP_STEP_RETURN;
- g_idle_add(
- (GSourceFunc)_net_nfc_handover_bss_process_carrier_record,
- (gpointer)context);
- }
- }
-
- break;
- case NET_NFC_LLCP_STEP_03 :
- {
- DEBUG_MSG("Connect with WIFI");
- int err = wifi_connect(context->ap_handle,
- _net_nfc_handover_bss_on_wifi_connected, context);
- DEBUG_MSG("Connect with WIFI err [%x]",err);
- if(err != WIFI_ERROR_NONE)
- {
- DEBUG_ERR_MSG("Wifi Connect failed");
- context->result = NET_NFC_OPERATION_FAIL;
- context->step = NET_NFC_LLCP_STEP_RETURN;
- g_idle_add(
- (GSourceFunc)_net_nfc_handover_bss_process_carrier_record,
- (gpointer)context);
- }
- }
- break;
- case NET_NFC_LLCP_STEP_RETURN :
- {
- DEBUG_MSG("STEP return");
- if(context->result == NET_NFC_OK)
- {
- DEBUG_MSG("Handover completed succesfully");
- }
- else
- {
- DEBUG_ERR_MSG("Handover Failed");
- }
- wifi_deinitialize();
- }
- break;
-
- default :
- break;
- }
-
- LOGD("[%s:%d] END", __func__, __LINE__);
-
- return 0;
-}
-
-net_nfc_error_e net_nfc_server_handover_bss_process_carrier_record(
- ndef_record_s *record,
- net_nfc_server_handover_process_carrier_record_cb cb,
- void *user_param)
-{
- net_nfc_error_e result = NET_NFC_OK;
- net_nfc_handover_bss_process_context_t *context = NULL;
-
- _net_nfc_util_alloc_mem(context, sizeof(*context));
- if (context != NULL)
- {
- context->cb = cb;
- context->user_param = user_param;
- context->step = NET_NFC_LLCP_STEP_01;
- net_nfc_util_create_record(record->TNF, &record->type_s,
- &record->id_s, &record->payload_s, &context->carrier);
-
- g_idle_add(
- (GSourceFunc)_net_nfc_handover_bss_process_carrier_record,
- (gpointer)context);
- }
- else
- {
- result = NET_NFC_ALLOC_FAIL;
- }
-
- return result;
-}
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "bluetooth-api.h"
-#include "net_nfc_debug_internal.h"
-#include "net_nfc_util_internal.h"
-#include "net_nfc_util_ndef_message.h"
-#include "net_nfc_util_ndef_record.h"
-#include "net_nfc_util_handover.h"
-#include "net_nfc_server_handover_internal.h"
-#include "net_nfc_server_llcp.h"
-
-
-typedef struct _net_nfc_handover_bt_get_context_t
-{
- int step;
- net_nfc_error_e result;
- net_nfc_conn_handover_carrier_state_e cps;
- net_nfc_server_handover_get_carrier_record_cb cb;
- ndef_record_s *carrier;
- uint32_t aux_data_count;
- ndef_record_s *aux_data;
- void *user_param;
-}
-net_nfc_handover_bt_get_context_t;
-
-typedef struct _net_nfc_handover_bt_process_context_t
-{
- int step;
- net_nfc_error_e result;
- net_nfc_server_handover_process_carrier_record_cb cb;
- ndef_record_s *carrier;
- data_s data;
- bluetooth_device_address_t addr;
- void *user_param;
-}
-net_nfc_handover_bt_process_context_t;
-
-
-static int _net_nfc_handover_bt_get_carrier_record(
- net_nfc_handover_bt_get_context_t *context);
-static int _net_nfc_handover_bt_process_carrier_record(
- net_nfc_handover_bt_process_context_t *context);
-
-
-static net_nfc_error_e _net_nfc_handover_bt_get_oob_data(
- net_nfc_carrier_config_s *config,
- bt_oob_data_t *oob)
-{
- net_nfc_error_e result = NET_NFC_UNKNOWN_ERROR;
- data_s hash = { NULL, 0 };
- data_s randomizer = { NULL, 0 };
-
- LOGD("[%s:%d] START", __func__, __LINE__);
-
- if (config == NULL || oob == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
-
- memset(oob, 0, sizeof(bt_oob_data_t));
-
- if ((result = net_nfc_util_get_carrier_config_property(
- config,
- NET_NFC_BT_ATTRIBUTE_OOB_HASH_C,
- (uint16_t *)&hash.length,
- &hash.buffer)) == NET_NFC_OK)
- {
- if (hash.length == 16)
- {
- DEBUG_MSG("hash.length == 16");
-
- NET_NFC_REVERSE_ORDER_16_BYTES(hash.buffer);
-
- oob->hash_len = MIN(sizeof(oob->hash), hash.length);
- memcpy(oob->hash, hash.buffer, oob->hash_len);
- }
- else
- {
- DEBUG_ERR_MSG("hash.length error : [%d] bytes", hash.length);
- }
- }
-
- if ((result = net_nfc_util_get_carrier_config_property(
- config,
- NET_NFC_BT_ATTRIBUTE_OOB_HASH_R,
- (uint16_t *)&randomizer.length,
- &randomizer.buffer)) == NET_NFC_OK)
- {
- if (randomizer.length == 16)
- {
- DEBUG_MSG("randomizer.length == 16");
-
- NET_NFC_REVERSE_ORDER_16_BYTES(randomizer.buffer);
-
- oob->randomizer_len = MIN(sizeof(oob->randomizer), randomizer.length);
- memcpy(oob->randomizer, randomizer.buffer, oob->randomizer_len);
- }
- else
- {
- DEBUG_ERR_MSG("randomizer.length error :"
- " [%d] bytes", randomizer.length);
- }
- }
-
- LOGD("[%s:%d] END", __func__, __LINE__);
-
- return result;
-}
-
-static void _net_nfc_handover_bt_get_carrier_config_cb(
- int event,
- bluetooth_event_param_t *param,
- void *user_data)
-{
- net_nfc_handover_bt_get_context_t *context =
- (net_nfc_handover_bt_get_context_t *)user_data;
-
- LOGD("[%s] START", __func__);
-
- if (context == NULL)
- {
- DEBUG_SERVER_MSG("user_data is null");
- LOGD("[%s] END", __func__);
- return;
- }
-
- switch (event)
- {
- case BLUETOOTH_EVENT_ENABLED :
- DEBUG_SERVER_MSG("BLUETOOTH_EVENT_ENABLED");
- if (context->step == NET_NFC_LLCP_STEP_02)
- {
- _net_nfc_handover_bt_get_carrier_record(context);
- }
- else
- {
- DEBUG_SERVER_MSG("step is incorrect");
- }
- break;
-
- case BLUETOOTH_EVENT_DISABLED :
- DEBUG_SERVER_MSG("BLUETOOTH_EVENT_DISABLED");
- break;
-
- default :
- DEBUG_SERVER_MSG("unhandled bt event [%d],"
- "[0x%04x]", event, param->result);
- break;
- }
-
- LOGD("[%s] END", __func__);
-}
-
-static net_nfc_error_e _net_nfc_handover_bt_create_config_record(
- ndef_record_s **record)
-{
- bluetooth_device_address_t bt_addr = { { 0, } };
- net_nfc_carrier_config_s *config = NULL;
- net_nfc_error_e result;
-
- /* append config to ndef message */
- if ((result = bluetooth_get_local_address(&bt_addr))
- == BLUETOOTH_ERROR_NONE)
- {
- if ((result = net_nfc_util_create_carrier_config(
- &config,
- NET_NFC_CONN_HANDOVER_CARRIER_BT)) == NET_NFC_OK)
- {
- bt_oob_data_t oob = { { 0 }, };
-
- NET_NFC_REVERSE_ORDER_6_BYTES(bt_addr.addr);
-
- if ((result = net_nfc_util_add_carrier_config_property(
- config,
- NET_NFC_BT_ATTRIBUTE_ADDRESS,
- sizeof(bt_addr.addr), bt_addr.addr)) != NET_NFC_OK)
- {
- DEBUG_ERR_MSG("net_nfc_util_add_carrier"
- "_config_property failed"
- "[%d]", result);
- }
-
- /* get oob data */
- if (bluetooth_oob_read_local_data(&oob) == BLUETOOTH_ERROR_NONE)
- {
- if (oob.hash_len == 16 && oob.randomizer_len == 16)
- {
- DEBUG_SERVER_MSG("oob.hash_len "
- "[%d]", oob.hash_len);
- DEBUG_SERVER_MSG("oob.randomizer_len"
- " [%d]", oob.randomizer_len);
-
- NET_NFC_REVERSE_ORDER_16_BYTES(oob.hash);
-
- if ((result =
- net_nfc_util_add_carrier_config_property(
- config,
- NET_NFC_BT_ATTRIBUTE_OOB_HASH_C,
- oob.hash_len, oob.hash)) != NET_NFC_OK)
- {
- DEBUG_ERR_MSG("net_nfc_util_add_carrier"
- "_config_property failed"
- " [%d]",result);
- }
-
- NET_NFC_REVERSE_ORDER_16_BYTES(oob.randomizer);
-
- if ((result = net_nfc_util_add_carrier_config_property(
- config,
- NET_NFC_BT_ATTRIBUTE_OOB_HASH_R,
- oob.randomizer_len,
- oob.randomizer)) != NET_NFC_OK)
- {
- DEBUG_ERR_MSG("net_nfc_util_add_carrier"
- "_config_property failed"
- " [%d]",result);
- }
- }
- else
- {
- DEBUG_ERR_MSG("abnormal oob data, skip... [%d]", result);
- }
- }
-
- if ((result = net_nfc_util_create_ndef_record_with_carrier_config(
- record,
- config)) != NET_NFC_OK)
- {
- DEBUG_ERR_MSG("net_nfc_util_create_ndef_record"
- "_with_carrier_config failed"
- "[%d]",result);
- }
-
- net_nfc_util_free_carrier_config(config);
- }
- else
- {
- DEBUG_ERR_MSG("net_nfc_util_create_carrier_config failed "
- "[%d]", result);
- }
- }
- else
- {
- DEBUG_ERR_MSG("bluetooth_get_local_address failed"
- " [%d]", result);
- result = NET_NFC_OPERATION_FAIL;
- }
-
- return result;
-}
-
-static int _net_nfc_handover_bt_get_carrier_record(
- net_nfc_handover_bt_get_context_t *context)
-{
- LOGD("[%s:%d] START", __func__, __LINE__);
-
- if (context->result != NET_NFC_OK && context->result != NET_NFC_BUSY)
- {
- DEBUG_ERR_MSG("context->result is error"
- " [%d]", context->result);
-
- context->step = NET_NFC_LLCP_STEP_RETURN;
- }
-
- switch (context->step)
- {
- case NET_NFC_LLCP_STEP_01 :
- DEBUG_MSG("STEP [1]");
-
- if (bluetooth_register_callback(
- _net_nfc_handover_bt_get_carrier_config_cb,
- context) >= BLUETOOTH_ERROR_NONE)
- {
- context->step = NET_NFC_LLCP_STEP_02;
- context->result = NET_NFC_OK;
-
- if (bluetooth_check_adapter() != BLUETOOTH_ADAPTER_ENABLED)
- {
- bluetooth_enable_adapter();
- }
- else
- {
- DEBUG_MSG("bluetooth is enabled already");
-
- /* do next step */
- g_idle_add((GSourceFunc)
- _net_nfc_handover_bt_get_carrier_record,
- (gpointer)context);
- }
- }
- else
- {
- DEBUG_ERR_MSG("bluetooth_register_callback failed");
-
- context->step = NET_NFC_LLCP_STEP_RETURN;
- context->result = NET_NFC_OPERATION_FAIL;
-
- g_idle_add((GSourceFunc)
- _net_nfc_handover_bt_get_carrier_record,
- (gpointer)context);
- }
- break;
-
- case NET_NFC_LLCP_STEP_02 :
- DEBUG_MSG("STEP [2]");
-
- context->step = NET_NFC_LLCP_STEP_RETURN;
-
- /* append config to ndef message */
- if ((context->result =
- _net_nfc_handover_bt_create_config_record(
- &context->carrier)) != NET_NFC_OK)
- {
- DEBUG_ERR_MSG("_ch_create_bt_config_record failed"
- "[%d]", context->result);
- }
-
- /* complete and return to upper step */
- g_idle_add((GSourceFunc)
- _net_nfc_handover_bt_get_carrier_record,
- (gpointer)context);
- break;
-
- case NET_NFC_LLCP_STEP_RETURN :
- DEBUG_MSG("STEP return");
-
- /* unregister current callback */
- bluetooth_unregister_callback();
-
- /* complete and return to upper step */
- context->cb(context->result,
- context->cps,
- context->carrier,
- context->aux_data_count,
- context->aux_data,
- context->user_param);
- break;
-
- default :
- break;
- }
-
- LOGD("[%s:%d] END", __func__, __LINE__);
-
- return 0;
-}
-
-net_nfc_error_e net_nfc_server_handover_bt_get_carrier_record(
- net_nfc_server_handover_get_carrier_record_cb cb,
- void *user_param)
-{
- net_nfc_error_e result = NET_NFC_OK;
- net_nfc_handover_bt_get_context_t *context = NULL;
-
- _net_nfc_util_alloc_mem(context, sizeof(*context));
- if (context != NULL)
- {
- context->cb = cb;
- context->user_param = user_param;
- context->step = NET_NFC_LLCP_STEP_01;
- /* TODO : check cps of bt */
- context->cps = NET_NFC_CONN_HANDOVER_CARRIER_ACTIVATE;
-
- g_idle_add((GSourceFunc)_net_nfc_handover_bt_get_carrier_record,
- (gpointer)context);
- }
- else
- {
- result = NET_NFC_ALLOC_FAIL;
- }
-
- return result;
-}
-
-static bool _net_nfc_handover_bt_check_bond_device(
- bluetooth_device_address_t *address)
-{
- bool result = false;
- int ret;
- GPtrArray *devinfo = NULL;
-
- LOGD("[%s] START", __func__);
-
- /* allocate the g_pointer_array */
- devinfo = g_ptr_array_new();
-
- ret = bluetooth_get_bonded_device_list(&devinfo);
- if (ret == BLUETOOTH_ERROR_NONE)
- {
- int i;
- bluetooth_device_info_t *ptr;
-
- DEBUG_SERVER_MSG("g pointer array count :"
- " [%d]", devinfo->len);
-
- for (i = 0; i < devinfo->len; i++)
- {
- ptr = g_ptr_array_index(devinfo, i);
- if (ptr != NULL)
- {
- SECURE_LOGD("Name [%s]", ptr->device_name.name);
- DEBUG_SERVER_MSG("Major Class [%d]",
- ptr->device_class.major_class);
- DEBUG_SERVER_MSG("Minor Class [%d]",
- ptr->device_class.minor_class);
- DEBUG_SERVER_MSG("Service Class [%d]",
- ptr->device_class.service_class);
- DEBUG_SERVER_MSG("%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X",
- ptr->device_address.addr[0],
- ptr->device_address.addr[1],
- ptr->device_address.addr[2],
- ptr->device_address.addr[3],
- ptr->device_address.addr[4],
- ptr->device_address.addr[5]);
-
- /* compare selector address */
- if (memcmp(&(ptr->device_address),
- address,
- sizeof(ptr->device_address)) == 0)
- {
- DEBUG_SERVER_MSG("Found!!!");
- result = true;
- break;
- }
- }
- }
- }
- else
- {
- DEBUG_ERR_MSG("bluetooth_get_bonded_device_list failed with"
- " [%d]", ret);
- }
-
- /* free g_pointer_array */
- g_ptr_array_free(devinfo, TRUE);
-
- LOGD("[%s] END", __func__);
-
- return result;
-}
-
-static void _net_nfc_handover_bt_process_carrier_record_cb(
- int event,
- bluetooth_event_param_t *param,
- void *user_data)
-{
- net_nfc_handover_bt_process_context_t *context =
- (net_nfc_handover_bt_process_context_t *)user_data;
-
- LOGD("[%s] START", __func__);
-
- if (context == NULL)
- {
- DEBUG_SERVER_MSG("user_data is null");
- LOGD("[%s] END", __func__);
- return;
- }
-
- switch (event)
- {
- case BLUETOOTH_EVENT_ENABLED :
- DEBUG_SERVER_MSG("BLUETOOTH_EVENT_ENABLED");
- if (context->step == NET_NFC_LLCP_STEP_02)
- {
- _net_nfc_handover_bt_process_carrier_record(context);
- }
- else
- {
- DEBUG_SERVER_MSG("step is incorrect");
- }
- break;
-
- case BLUETOOTH_EVENT_DISABLED :
- DEBUG_SERVER_MSG("BLUETOOTH_EVENT_DISABLED");
- break;
-
- case BLUETOOTH_EVENT_BONDING_FINISHED :
- DEBUG_SERVER_MSG("BLUETOOTH_EVENT_BONDING_FINISHED, result "
- "[0x%04x]", param->result);
- if (context->step == NET_NFC_LLCP_STEP_03)
- {
- if (param->result < BLUETOOTH_ERROR_NONE)
- {
- DEBUG_ERR_MSG("bond failed");
- context->result = NET_NFC_OPERATION_FAIL;
- }
-
- _net_nfc_handover_bt_process_carrier_record(context);
- }
- else
- {
- DEBUG_SERVER_MSG("step is incorrect");
- }
- break;
-
- default :
- DEBUG_SERVER_MSG("unhandled bt event [%d],"
- "[0x%04x]", event, param->result);
- break;
- }
-
- LOGD("[%s] END", __func__);
-}
-
-static int _net_nfc_handover_bt_process_carrier_record(
- net_nfc_handover_bt_process_context_t *context)
-{
- LOGD("[%s:%d] START", __func__, __LINE__);
-
- if (context->result != NET_NFC_OK && context->result != NET_NFC_BUSY)
- {
- DEBUG_ERR_MSG("context->result is error"
- " [%d]", context->result);
- context->step = NET_NFC_LLCP_STEP_RETURN;
- }
-
- switch (context->step)
- {
- case NET_NFC_LLCP_STEP_01 :
- DEBUG_MSG("STEP [1]");
-
- if (bluetooth_register_callback(
- _net_nfc_handover_bt_process_carrier_record_cb,
- context) >= BLUETOOTH_ERROR_NONE)
- {
- /* next step */
- context->step = NET_NFC_LLCP_STEP_02;
-
- if (bluetooth_check_adapter() != BLUETOOTH_ADAPTER_ENABLED)
- {
- context->result = NET_NFC_OK;
- bluetooth_enable_adapter();
- }
- else
- {
- /* do next step */
- DEBUG_MSG("BT is enabled already, go next step");
- context->result = NET_NFC_OK;
-
- g_idle_add((GSourceFunc)
- _net_nfc_handover_bt_process_carrier_record,
- (gpointer)context);
- }
- }
- else
- {
- DEBUG_ERR_MSG("bluetooth_register_callback failed");
- context->result = NET_NFC_OPERATION_FAIL;
-
- g_idle_add(
- (GSourceFunc)_net_nfc_handover_bt_process_carrier_record,
- (gpointer)context);
- }
- break;
-
- case NET_NFC_LLCP_STEP_02 :
- {
- net_nfc_carrier_config_s *config;
- data_s temp = { NULL, 0 };
-
- DEBUG_MSG("STEP [2]");
-
- net_nfc_util_create_carrier_config_from_config_record(
- &config,
- context->carrier);
-
- net_nfc_util_get_carrier_config_property(config,
- NET_NFC_BT_ATTRIBUTE_ADDRESS,
- (uint16_t *)&temp.length, &temp.buffer);
-
- if (temp.length == 6)
- {
- NET_NFC_REVERSE_ORDER_6_BYTES(temp.buffer);
-
- memcpy(context->addr.addr,
- temp.buffer,
- MIN(sizeof(context->addr.addr),
- temp.length));
-
- if (_net_nfc_handover_bt_check_bond_device
- (&context->addr) == true)
- {
- DEBUG_SERVER_MSG("already paired with"
- " [%02x:%02x:%02x:%02x:%02x:%02x]",
- context->addr.addr[0],
- context->addr.addr[1],
- context->addr.addr[2],
- context->addr.addr[3],
- context->addr.addr[4],
- context->addr.addr[5]);
-
- /* return */
- context->step = NET_NFC_LLCP_STEP_RETURN;
- context->result = NET_NFC_OK;
- }
- else
- {
- bt_oob_data_t oob = { { 0 } , };
-
- if (_net_nfc_handover_bt_get_oob_data(
- config,
- &oob) == NET_NFC_OK)
- {
- /* set oob data */
- bluetooth_oob_add_remote_data(
- &context->addr,
- &oob);
- }
-
- /* pair and send reponse */
- context->result = NET_NFC_OK;
- context->step = NET_NFC_LLCP_STEP_RETURN;
- }
- }
- else
- {
- DEBUG_ERR_MSG("bluetooth address is invalid."
- " [%d] bytes", temp.length);
-
- context->step = NET_NFC_LLCP_STEP_RETURN;
- context->result = NET_NFC_OPERATION_FAIL;
- }
-
- net_nfc_util_free_carrier_config(config);
-
- g_idle_add(
- (GSourceFunc)_net_nfc_handover_bt_process_carrier_record,
- (gpointer)context);
- }
- break;
-
- case NET_NFC_LLCP_STEP_RETURN :
- {
- DEBUG_MSG("STEP return");
- data_s data = { context->addr.addr,
- sizeof(context->addr.addr) };
-
- /* unregister bluetooth callback */
- bluetooth_unregister_callback();
-
- context->cb(context->result,
- NET_NFC_CONN_HANDOVER_CARRIER_BT,
- &data,
- context->user_param);
- }
- break;
-
- default :
- break;
- }
-
- LOGD("[%s:%d] END", __func__, __LINE__);
-
- return 0;
-}
-
-net_nfc_error_e net_nfc_server_handover_bt_process_carrier_record(
- ndef_record_s *record,
- net_nfc_server_handover_process_carrier_record_cb cb,
- void *user_param)
-{
- net_nfc_error_e result = NET_NFC_OK;
- net_nfc_handover_bt_process_context_t *context = NULL;
-
- _net_nfc_util_alloc_mem(context, sizeof(*context));
- if (context != NULL)
- {
- context->cb = cb;
- context->user_param = user_param;
- context->step = NET_NFC_LLCP_STEP_01;
- net_nfc_util_create_record(record->TNF, &record->type_s,
- &record->id_s, &record->payload_s, &context->carrier);
-
- g_idle_add(
- (GSourceFunc)_net_nfc_handover_bt_process_carrier_record,
- (gpointer)context);
- }
- else
- {
- result = NET_NFC_ALLOC_FAIL;
- }
-
- return result;
-}
-
-static void _net_nfc_handover_bt_post_process_cb(int event,
- bluetooth_event_param_t *param, void *user_data)
-{
- net_nfc_handover_bt_process_context_t *context =
- (net_nfc_handover_bt_process_context_t *)user_data;
-
- LOGD("[%s] START", __func__);
-
- if (context == NULL)
- {
- DEBUG_SERVER_MSG("user_data is null");
- LOGD("[%s] END", __func__);
- return;
- }
-
- switch (event)
- {
- case BLUETOOTH_EVENT_ENABLED :
- DEBUG_SERVER_MSG("BLUETOOTH_EVENT_ENABLED");
- break;
-
- case BLUETOOTH_EVENT_DISABLED :
- DEBUG_SERVER_MSG("BLUETOOTH_EVENT_DISABLED");
- break;
-
- case BLUETOOTH_EVENT_BONDING_FINISHED :
- DEBUG_SERVER_MSG("BLUETOOTH_EVENT_BONDING_FINISHED,"
- " result [0x%04x]",param->result);
-
- if (param->result < BLUETOOTH_ERROR_NONE)
- {
- DEBUG_ERR_MSG("bond failed");
- context->result = NET_NFC_OPERATION_FAIL;
- }
- else
- {
- context->result = NET_NFC_OK;
- }
-
- context->cb(context->result,
- NET_NFC_CONN_HANDOVER_CARRIER_BT,
- NULL,
- context->user_param);
- break;
-
- default :
- DEBUG_SERVER_MSG("unhandled bt event"
- " [%d], [0x%04x]", event, param->result);
- break;
- }
-
- LOGD("[%s] END", __func__);
-}
-
-net_nfc_error_e net_nfc_server_handover_bt_post_process(
- data_s *data,
- net_nfc_server_handover_process_carrier_record_cb cb,
- void *user_param)
-{
- net_nfc_error_e result = NET_NFC_OK;
- net_nfc_handover_bt_process_context_t *context = NULL;
-
- _net_nfc_util_alloc_mem(context, sizeof(*context));
- if (context != NULL)
- {
- bluetooth_device_address_t bt_addr;
-
- context->cb = cb;
- context->user_param = user_param;
-
- memcpy(&bt_addr.addr, data->buffer, sizeof(bt_addr.addr));
-
- if (bluetooth_register_callback(
- _net_nfc_handover_bt_post_process_cb,
- context) >= BLUETOOTH_ERROR_NONE)
- {
- bluetooth_bond_device(&bt_addr);
- }
- else
- {
- _net_nfc_util_free_mem(context);
- result = NET_NFC_OPERATION_FAIL;
- }
- }
- else
- {
- result = NET_NFC_ALLOC_FAIL;
- }
-
- return result;
-}
-
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#include <pmapi.h>/*for pm lock*/
-
-#include "net_nfc_gdbus.h"
-#include "net_nfc_server_common.h"
-#include "net_nfc_server_p2p.h"
-#include "net_nfc_server_llcp.h"
-
-#include "net_nfc_server_process_snep.h"
-#include "net_nfc_server_process_npp.h"
-#include "net_nfc_server_process_handover.h"
-#include "net_nfc_server_tag.h"
-
-#include "net_nfc_debug_internal.h"
-#include "net_nfc_controller_internal.h"
-#include "net_nfc_util_gdbus_internal.h"
-#include "net_nfc_server_context_internal.h"
-
-/* default llcp configurations */
-#define NET_NFC_LLCP_MIU 128
-#define NET_NFC_LLCP_WKS 1
-#define NET_NFC_LLCP_LTO 10
-#define NET_NFC_LLCP_OPT 0
-
-static NetNfcGDbusLlcp *llcp_skeleton = NULL;
-
-static net_nfc_llcp_config_info_s llcp_config =
-{
- NET_NFC_LLCP_MIU,
- NET_NFC_LLCP_WKS,
- NET_NFC_LLCP_LTO,
- NET_NFC_LLCP_OPT,
-};
-
-typedef struct _LlcpData LlcpData;
-
-struct _LlcpData
-{
- NetNfcGDbusLlcp *llcp;
- GDBusMethodInvocation *invocation;
-};
-
-typedef struct _LlcpConfigData LlcpConfigData;
-
-struct _LlcpConfigData
-{
- NetNfcGDbusLlcp *llcp;
- GDBusMethodInvocation *invocation;
-
- guint16 miu;
- guint16 wks;
- guint8 lto;
- guint8 option;
-};
-
-typedef struct _LlcpListenData LlcpListenData;
-
-struct _LlcpListenData
-{
- NetNfcGDbusLlcp *llcp;
- GDBusMethodInvocation *invocation;
-
- guint32 handle;
- guint32 client_socket;
- guint32 oal_socket;
- guint16 miu;
- guint8 rw;
- guint type;
- guint sap;
- gchar *service_name;
-};
-
-typedef struct _LlcpConnectData LlcpConnectData;
-
-struct _LlcpConnectData
-{
- NetNfcGDbusLlcp *llcp;
- GDBusMethodInvocation *invocation;
-
- guint32 handle;
- guint32 client_socket;
- guint32 oal_socket;
- guint16 miu;
- guint8 rw;
- guint type;
- gchar *service_name;
-};
-
-typedef struct _LlcpConnectSapData LlcpConnectSapData;
-
-struct _LlcpConnectSapData
-{
- NetNfcGDbusLlcp *llcp;
- GDBusMethodInvocation *invocation;
-
- guint32 handle;
- guint32 client_socket;
- guint32 oal_socket;
- guint16 miu;
- guint8 rw;
- guint type;
- guint sap;
-};
-
-typedef struct _LlcpSendData LlcpSendData;
-
-struct _LlcpSendData
-{
- NetNfcGDbusLlcp *llcp;
- GDBusMethodInvocation *invocation;
-
- guint32 handle;
- guint32 client_socket;
- guint32 oal_socket;
-
- data_s *data;
-};
-
-typedef struct _LlcpSendToData LlcpSendToData;
-
-struct _LlcpSendToData
-{
- NetNfcGDbusLlcp *llcp;
- GDBusMethodInvocation *invocation;
-
- guint32 handle;
- guint32 client_socket;
- guint32 oal_socket;
- guint8 sap;
-
- data_s *data;
-};
-
-typedef struct _LlcpReceiveData LlcpReceiveData;
-
-struct _LlcpReceiveData
-{
- NetNfcGDbusLlcp *llcp;
- GDBusMethodInvocation *invocation;
-
- guint32 handle;
- guint32 client_socket;
- guint32 oal_socket;
- guint32 req_length;
-};
-
-typedef struct _LlcpCloseData LlcpCloseData;
-
-struct _LlcpCloseData
-{
- NetNfcGDbusLlcp *llcp;
- GDBusMethodInvocation *invocation;
-
- guint32 handle;
- guint32 client_socket;
- guint32 oal_socket;
-};
-
-typedef struct _LlcpDisconnectData LlcpDisconnectData;
-
-struct _LlcpDisconnectData
-{
- NetNfcGDbusLlcp *llcp;
- GDBusMethodInvocation *invocation;
-
- guint32 handle;
- guint32 client_socket;
- guint32 oal_socket;
-};
-
-/* server_side */
-typedef struct _ServerLlcpData ServerLlcpData;
-
-struct _ServerLlcpData
-{
- NetNfcGDbusLlcp *llcp;
- net_nfc_request_msg_t *req_msg;
-};
-
-typedef struct _LlcpSimpleData LlcpSimpleData;
-
-struct _LlcpSimpleData
-{
- net_nfc_target_handle_s *handle;
- net_nfc_llcp_socket_t socket;
- guint32 miu;
- net_nfc_server_llcp_callback callback;
- net_nfc_server_llcp_callback error_callback;
- gpointer user_data;
-};
-
-
-static void llcp_add_async_queue(net_nfc_request_msg_t *req_msg,
- net_nfc_server_controller_func func);
-
-static void llcp_socket_error_cb(net_nfc_llcp_socket_t socket,
- net_nfc_error_e result,
- data_s *data,
- void *extra,
- void *user_param);
-
-static void llcp_listen_cb(net_nfc_llcp_socket_t socket,
- net_nfc_error_e result,
- data_s *data,
- void *extra,
- void *user_param);
-
-static void llcp_connect_by_url_cb(net_nfc_llcp_socket_t socket,
- net_nfc_error_e result,
- data_s *data,
- void *extra,
- void *user_param);
-
-static void llcp_connect_cb(net_nfc_llcp_socket_t socket,
- net_nfc_error_e result,
- data_s *data,
- void *extra,
- void *user_param);
-
-static void llcp_send_cb(net_nfc_llcp_socket_t socket,
- net_nfc_error_e result,
- data_s *data,
- void *extra,
- void *user_param);
-
-static void llcp_receive_cb(net_nfc_llcp_socket_t socket,
- net_nfc_error_e result,
- data_s *data,
- void *extra,
- void *user_param);
-
-static void llcp_receive_from_cb(net_nfc_llcp_socket_t socket,
- net_nfc_error_e result,
- data_s *data,
- void *extra,
- void *user_param);
-
-static void llcp_disconnect_cb(net_nfc_llcp_socket_t socket,
- net_nfc_error_e result,
- data_s *data,
- void *extra,
- void *user_param);
-
-/* client method */
-static void llcp_handle_config_thread_func(gpointer user_data);
-
-static void llcp_handle_listen_thread_func(gpointer user_data);
-
-static void llcp_handle_connect_thread_func(gpointer user_data);
-
-static void llcp_handle_connect_sap_thread_func(gpointer user_data);
-
-static void llcp_handle_send_thread_func(gpointer user_data);
-
-static void llcp_handle_send_to_thread_func(gpointer user_data);
-
-static void llcp_handle_receive_thread_func(gpointer user_data);
-
-static void llcp_handle_receive_from_thread_func(gpointer user_data);
-
-static void llcp_handle_close_thread_func(gpointer user_data);
-
-static void llcp_handle_disconnect_thread_func(gpointer user_data);
-
-/* methods */
-static gboolean llcp_handle_config(NetNfcGDbusLlcp *llcp,
- GDBusMethodInvocation *invocation,
- GVariant *arg_config,
- GVariant *smack_privilege,
- gpointer user_data);
-
-static gboolean llcp_handle_listen(NetNfcGDbusLlcp *llcp,
- GDBusMethodInvocation *invocation,
- guint32 arg_handle,
- guint32 arg_client_socket,
- guint32 arg_oal_socket,
- guint16 arg_miu,
- guint8 arg_rw,
- gint32 arg_type,
- guint8 arg_sap,
- const gchar *arg_service_name,
- GVariant *smack_privilege,
- gpointer user_data);
-
-static gboolean llcp_handle_connect(NetNfcGDbusLlcp *llcp,
- GDBusMethodInvocation *invocation,
- guint32 arg_handle,
- guint32 arg_client_socket,
- guint32 arg_oal_socket,
- guint16 arg_miu,
- guint8 arg_rw,
- gint32 arg_type,
- const gchar *arg_service_name,
- GVariant *smack_privilege,
- gpointer user_data);
-
-static gboolean llcp_handle_connect_sap(NetNfcGDbusLlcp *llcp,
- GDBusMethodInvocation *invocation,
- guint32 arg_handle,
- guint32 arg_client_socket,
- guint32 arg_oal_socket,
- guint16 arg_miu,
- guint8 arg_rw,
- gint32 arg_type,
- guint8 arg_sap,
- GVariant *smack_privilege,
- gpointer user_data);
-
-static gboolean llcp_handle_send(NetNfcGDbusLlcp *llcp,
- GDBusMethodInvocation *invocation,
- guint32 arg_handle,
- guint32 arg_client_socket,
- guint32 arg_oal_socket,
- GVariant *arg_data,
- GVariant *smack_privilege,
- gpointer user_data);
-
-static gboolean llcp_handle_send_to(NetNfcGDbusLlcp *llcp,
- GDBusMethodInvocation *invocation,
- guint32 arg_handle,
- guint32 arg_client_socket,
- guint32 arg_oal_socket,
- guint8 arg_sap,
- GVariant *arg_data,
- GVariant *smack_privilege,
- gpointer user_data);
-
-static gboolean llcp_handle_receive(NetNfcGDbusLlcp *llcp,
- GDBusMethodInvocation *invocation,
- guint32 arg_handle,
- guint32 arg_client_socket,
- guint32 arg_oal_socket,
- guint32 arg_req_length,
- GVariant *smack_privilege,
- gpointer user_data);
-
-static gboolean llcp_handle_receive_from(NetNfcGDbusLlcp *llcp,
- GDBusMethodInvocation *invocation,
- guint32 arg_handle,
- guint32 arg_client_socket,
- guint32 arg_oal_socket,
- guint32 arg_req_length,
- GVariant *smack_privilege,
- gpointer user_data);
-
-static gboolean llcp_handle_close(NetNfcGDbusLlcp *llcp,
- GDBusMethodInvocation *invocation,
- guint32 arg_handle,
- guint32 arg_client_socket,
- guint32 arg_oal_socket,
- GVariant *smack_privilege,
- gpointer user_data);
-
-static gboolean llcp_handle_disconnect(NetNfcGDbusLlcp *llcp,
- GDBusMethodInvocation *invocation,
- guint32 arg_handle,
- guint32 arg_client_socket,
- guint32 arg_oal_socket,
- GVariant *smack_privilege,
- gpointer user_data);
-
-
-/* server side */
-static void llcp_deactivated_thread_func(gpointer user_data);
-
-static void llcp_listen_thread_func(gpointer user_data);
-
-static void llcp_socket_error_thread_func(gpointer user_data);
-
-static void llcp_send_thread_func(gpointer user_data);
-
-static void llcp_receive_thread_func(gpointer user_data);
-
-static void llcp_receive_from_thread_func(gpointer user_data);
-
-static void llcp_connect_thread_func(gpointer user_data);
-
-static void llcp_disconnect_thread_func(gpointer user_data);
-
-/* simple */
-static void llcp_simple_socket_error_cb(net_nfc_llcp_socket_t socket,
- net_nfc_error_e result,
- data_s *data,
- void *extra,
- void *user_param);
-
-static void llcp_simple_listen_cb(net_nfc_llcp_socket_t socket,
- net_nfc_error_e result,
- data_s *data,
- void *extra,
- void *user_param);
-
-static void llcp_simple_connect_cb(net_nfc_llcp_socket_t socket,
- net_nfc_error_e result,
- data_s *data,
- void *extra,
- void *user_param);
-
-static void llcp_simple_server_error_cb(net_nfc_llcp_socket_t socket,
- net_nfc_error_e result,
- data_s *data,
- void *extra,
- void *user_param);
-
-static void llcp_simple_send_cb(net_nfc_llcp_socket_t socket,
- net_nfc_error_e result,
- data_s *data,
- void *extra,
- void *user_param);
-
-static void llcp_simple_receive_cb(net_nfc_llcp_socket_t socket,
- net_nfc_error_e result,
- data_s *data,
- void *extra,
- void *user_param);
-
-
-static void llcp_add_async_queue(net_nfc_request_msg_t *req_msg,
- net_nfc_server_controller_func func)
-{
- ServerLlcpData *data = NULL;
-
- if (llcp_skeleton == NULL)
- {
- DEBUG_ERR_MSG("%s is not initialized",
- "net_nfc_server_llcp");
- return;
- }
-
- if (req_msg == NULL)
- {
- DEBUG_ERR_MSG("req msg is null");
- }
-
- data = g_new0(ServerLlcpData, 1);
- if(data == NULL)
- {
- DEBUG_ERR_MSG("Memory allocation failed");
- return;
- }
- data->llcp = g_object_ref(llcp_skeleton);
- data->req_msg = req_msg;
-
- if (net_nfc_server_controller_async_queue_push(func, data) == FALSE)
- {
- DEBUG_ERR_MSG("can not push to controller thread");
-
- if (data)
- {
- g_object_unref(data->llcp);
- g_free(data->req_msg);
- g_free(data);
- }
- }
-}
-
-static void llcp_socket_error_cb(net_nfc_llcp_socket_t socket,
- net_nfc_error_e result,
- data_s *data,
- void *extra,
- void *user_param)
-{
- LlcpData *llcp_data;
-
- llcp_data = (LlcpData *)user_param;
-
- if (llcp_data->invocation)
- {
- g_dbus_method_invocation_return_dbus_error(
- llcp_data->invocation,
- "org.tizen.NetNfcService.SocketError",
- "socket error");
-
- g_object_unref(llcp_data->invocation);
- }
-
- if (llcp_data->llcp)
- g_object_unref(llcp_data->llcp);
-
- g_free(llcp_data);
-}
-
-static void llcp_listen_cb(net_nfc_llcp_socket_t socket,
- net_nfc_error_e result,
- data_s *data,
- void *extra,
- void *user_param)
-{
- LlcpListenData *llcp_data;
-
- llcp_data = (LlcpListenData *)user_param;
-
- if (llcp_data == NULL)
- return;
-
- if (llcp_data->llcp)
- {
-
- if (llcp_data->invocation)
- {
- net_nfc_gdbus_llcp_complete_listen(llcp_data->llcp,
- llcp_data->invocation,
- llcp_data->client_socket,
- socket);
- g_object_unref(llcp_data->invocation);
- }
-
- g_object_unref(llcp_data->llcp);
- }
-
- g_free(llcp_data->service_name);
- g_free(llcp_data);
-}
-
-static void llcp_connect_by_url_cb(net_nfc_llcp_socket_t socket,
- net_nfc_error_e result,
- data_s *data,
- void *extra,
- void *user_param)
-{
- LlcpConnectData *llcp_data;
-
- llcp_data = (LlcpConnectData *)user_param;
-
- if (llcp_data == NULL)
- return;
-
- if (llcp_data->llcp)
- {
-
- if (llcp_data->invocation)
- {
- net_nfc_gdbus_llcp_complete_connect(llcp_data->llcp,
- llcp_data->invocation,
- llcp_data->client_socket,
- socket);
- g_object_unref(llcp_data->invocation);
- }
-
- g_object_unref(llcp_data->llcp);
- }
-
- g_free(llcp_data->service_name);
- g_free(llcp_data);
-}
-
-static void llcp_connect_cb(net_nfc_llcp_socket_t socket,
- net_nfc_error_e result,
- data_s *data,
- void *extra,
- void *user_param)
-{
- LlcpConnectSapData *llcp_data;
-
- llcp_data = (LlcpConnectSapData *)user_param;
-
- if (llcp_data == NULL)
- return;
-
- if (llcp_data->llcp)
- {
-
- if (llcp_data->invocation)
- {
- net_nfc_gdbus_llcp_complete_connect_sap(
- llcp_data->llcp,
- llcp_data->invocation,
- llcp_data->client_socket,
- socket);
- g_object_unref(llcp_data->invocation);
- }
-
- g_object_unref(llcp_data->llcp);
- }
-
- g_free(llcp_data);
-}
-
-static void llcp_send_cb(net_nfc_llcp_socket_t socket,
- net_nfc_error_e result,
- data_s *data,
- void *extra,
- void *user_param)
-{
- LlcpData *llcp_data;
-
- llcp_data = (LlcpData *)user_param;
-
- if (llcp_data == NULL)
- return;
-
- if (llcp_data->llcp)
- {
-
- if (llcp_data->invocation)
- {
- net_nfc_gdbus_llcp_complete_send(
- llcp_data->llcp,
- llcp_data->invocation,
- socket);
- g_object_unref(llcp_data->invocation);
- }
-
- g_object_unref(llcp_data->llcp);
- }
-
- g_free(llcp_data);
-}
-
-static void llcp_receive_cb(net_nfc_llcp_socket_t socket,
- net_nfc_error_e result,
- data_s *data,
- void *extra,
- void *user_param)
-{
- LlcpData *llcp_data;
-
- llcp_data = (LlcpData *)user_param;
-
- if (llcp_data == NULL)
- return;
-
- if (llcp_data->llcp)
- {
- if (llcp_data->invocation)
- {
- GVariant *variant;
-
- variant = net_nfc_util_gdbus_data_to_variant(data);
- net_nfc_gdbus_llcp_complete_receive(
- llcp_data->llcp,
- llcp_data->invocation,
- variant);
-
- g_object_unref(llcp_data->invocation);
- }
-
- g_object_unref(llcp_data->llcp);
- }
-
- g_free(llcp_data);
-}
-
-static void llcp_receive_from_cb(net_nfc_llcp_socket_t socket,
- net_nfc_error_e result,
- data_s *data,
- void *extra,
- void *user_param)
-{
- LlcpData *llcp_data;
-
- llcp_data = (LlcpData *)user_param;
-
- if (llcp_data == NULL)
- return;
-
- if (llcp_data->llcp)
- {
-
- if (llcp_data->invocation)
- {
- GVariant *variant;
-
- variant = net_nfc_util_gdbus_data_to_variant(data);
- net_nfc_gdbus_llcp_complete_receive_from(
- llcp_data->llcp,
- llcp_data->invocation,
- (guint8) (int)extra,
- variant);
-
- g_object_unref(llcp_data->invocation);
- }
-
- g_object_unref(llcp_data->llcp);
- }
-
- g_free(llcp_data);
-}
-
-
-static void llcp_disconnect_cb(net_nfc_llcp_socket_t socket,
- net_nfc_error_e result,
- data_s *data,
- void *extra,
- void *user_param)
-{
- LlcpData *llcp_data;
-
- llcp_data = (LlcpData *)user_param;
-
- if (llcp_data == NULL)
- return;
-
- if (llcp_data->llcp)
- {
-
- if (llcp_data->invocation)
- {
- net_nfc_gdbus_llcp_complete_disconnect(
- llcp_data->llcp,
- llcp_data->invocation,
- socket);
-
- g_object_unref(llcp_data->invocation);
- }
-
- g_object_unref(llcp_data->llcp);
- }
-
- g_free(llcp_data);
-}
-
-
-static void llcp_handle_config_thread_func(gpointer user_data)
-{
- LlcpConfigData *data;
-
- net_nfc_llcp_config_info_s config;
-
- data = (LlcpConfigData *)user_data;
-
- if (data == NULL)
- {
- DEBUG_ERR_MSG("can not get LlcpConfigData");
- return;
- }
-
- if (data->llcp == NULL)
- {
- DEBUG_ERR_MSG("can not get llcp");
- if (data->invocation)
- {
- g_dbus_method_invocation_return_dbus_error(
- data->invocation,
- "org.tizen.NetNfcService.ConfigError",
- "can not get llcp");
-
- g_object_unref(data->invocation);
- }
- g_free(data);
-
- return;
- }
-
- config.miu = data->miu;
- config.wks = data->wks;
- config.lto = data->lto;
- config.option = data->option;
-
- if (net_nfc_server_llcp_set_config(&config) != NET_NFC_OK)
- {
- if (data->invocation)
- {
- g_dbus_method_invocation_return_dbus_error(
- data->invocation,
- "org.tizen.NetNfcService.ConfigError",
- "can not get llcp");
-
- g_object_unref(data->invocation);
- }
-
- g_object_unref(data->llcp);
- g_free(data);
- return;
- }
-
- if (data->invocation)
- {
- net_nfc_gdbus_llcp_complete_config(data->llcp,
- data->invocation);
-
- g_object_unref(data->invocation);
- }
-
- g_object_unref(data->llcp);
- g_free(data);
-
- return;
-}
-
-static void llcp_handle_listen_thread_func(gpointer user_data)
-{
- LlcpListenData *data;
- LlcpData *error_data;
-
- net_nfc_llcp_socket_t socket = -1;
- net_nfc_error_e result = NET_NFC_OK;
-
- data = (LlcpListenData *)user_data;
-
- if (data == NULL)
- {
- DEBUG_ERR_MSG("can not get LlcpListenData");
- return;
- }
-
- if (data->llcp == NULL)
- {
- DEBUG_ERR_MSG("can not get llcp");
- if (data->invocation)
- {
- g_dbus_method_invocation_return_dbus_error(
- data->invocation,
- "org.tizen.NetNfcService.ListenError",
- "can not get llcp");
-
- g_object_unref(data->invocation);
- }
-
- g_free(data->service_name);
- g_free(data);
-
- return;
- }
-
- error_data = g_new0(LlcpData, 1);
- if(error_data == NULL)
- {
- DEBUG_ERR_MSG("Memory allocation failed");
- g_dbus_method_invocation_return_dbus_error(data->invocation,
- "org.tizen.NetNfcService.AllocationError",
- "Can not allocate memory");
- return;
- }
- error_data->llcp = g_object_ref(data->llcp);
- error_data->invocation = g_object_ref(data->invocation);
-
- if (net_nfc_controller_llcp_create_socket(&socket,
- data->type,
- data->miu,
- data->rw,
- &result,
- llcp_socket_error_cb,
- error_data) == false)
- {
- DEBUG_ERR_MSG("%s fiailed [%d]",
- "net_nfc_controller_llcp_create_socket" ,result);
-
- if (data->invocation)
- {
- g_dbus_method_invocation_return_dbus_error(
- data->invocation,
- "org.tizen.NetNfcService.ListenError",
- "can not create socket");
-
- g_object_unref(data->invocation);
- }
-
- g_object_unref(data->llcp);
-
- g_free(data->service_name);
- g_free(data);
-
- g_free(error_data);
-
- return;
- }
-
- if (net_nfc_controller_llcp_bind(socket,
- data->sap,
- &result) == false)
- {
- DEBUG_ERR_MSG("%s fiailed [%d]",
- "net_nfc_controller_llcp_create_socket" ,result);
-
- if (data->invocation)
- {
- g_dbus_method_invocation_return_dbus_error(
- data->invocation,
- "org.tizen.NetNfcService.ListenError",
- "can not bind socket");
-
- g_object_unref(data->invocation);
- }
-
- g_object_unref(data->llcp);
-
- g_free(data->service_name);
- g_free(data);
-
- g_free(error_data);
-
- if (socket != -1)
- net_nfc_controller_llcp_socket_close(socket, &result);
-
- return;
- }
-
- DEBUG_SERVER_MSG("OAL socket in Listen : %d\n", socket);
-
- if (net_nfc_controller_llcp_listen(GUINT_TO_POINTER(data->handle),
- (uint8_t *)data->service_name,
- socket,
- &result,
- llcp_listen_cb,
- data) == false)
- {
- DEBUG_ERR_MSG("%s failed [%d]",
- "net_nfc_controller_llcp_listen",
- result);
-
- if (data->invocation)
- {
- g_dbus_method_invocation_return_dbus_error(
- data->invocation,
- "org.tizen.NetNfcService.ListenError",
- "can not listen socket");
-
- g_object_unref(data->invocation);
- }
-
- g_object_unref(data->llcp);
-
- g_free(data->service_name);
- g_free(data);
-
- g_free(error_data);
-
- if (socket != -1)
- net_nfc_controller_llcp_socket_close(socket, &result);
- }
-}
-
-static void llcp_handle_connect_thread_func(gpointer user_data)
-{
- LlcpConnectData *data;
- LlcpData *error_data;
-
- net_nfc_llcp_socket_t socket = -1;
- net_nfc_error_e result = NET_NFC_OK;
-
- data = (LlcpConnectData *)user_data;
-
- if (data == NULL)
- {
- DEBUG_ERR_MSG("can not get LlcpListenData");
- return;
- }
-
- if (data->llcp == NULL)
- {
- DEBUG_ERR_MSG("can not get llcp");
- if (data->invocation)
- {
- g_dbus_method_invocation_return_dbus_error(
- data->invocation,
- "org.tizen.NetNfcService.ConnectError",
- "can not get llcp");
-
- g_object_unref(data->invocation);
- }
-
- g_free(data->service_name);
- g_free(data);
-
- return;
- }
-
- error_data = g_new0(LlcpData, 1);
- if(error_data == NULL)
- {
- DEBUG_ERR_MSG("Memory allocation failed");
- g_dbus_method_invocation_return_dbus_error(data->invocation,
- "org.tizen.NetNfcService.AllocationError",
- "Can not allocate memory");
- return;
- }
- error_data->llcp = g_object_ref(data->llcp);
- error_data->invocation = g_object_ref(data->invocation);
-
- if (net_nfc_controller_llcp_create_socket(&socket,
- data->type,
- data->miu,
- data->rw,
- &result,
- llcp_socket_error_cb,
- error_data) == false)
- {
- DEBUG_ERR_MSG("%s fiailed [%d]",
- "net_nfc_controller_llcp_create_socket" ,result);
-
- if (data->invocation)
- {
- g_dbus_method_invocation_return_dbus_error(
- data->invocation,
- "org.tizen.NetNfcService.ConnectError",
- "can not create socket");
-
- g_object_unref(data->invocation);
- }
-
- g_object_unref(data->llcp);
-
- g_free(data->service_name);
- g_free(data);
-
- g_free(error_data);
-
- return;
- }
-
- DEBUG_SERVER_MSG("OAL socket in Listen :%d", socket);
-
- if (net_nfc_controller_llcp_connect_by_url(
- GUINT_TO_POINTER(data->handle),
- socket,
- (uint8_t *)data->service_name,
- &result,
- llcp_connect_by_url_cb,
- data) == false)
- {
- DEBUG_ERR_MSG("%s failed, [%d]",
- "net_nfc_controller_llcp_connect_by_url",
- result);
-
- if (data->invocation)
- {
- g_dbus_method_invocation_return_dbus_error(
- data->invocation,
- "org.tizen.NetNfcService.ConnectError",
- "can not listen socket");
-
- g_object_unref(data->invocation);
- }
-
- g_object_unref(data->llcp);
-
- g_free(data->service_name);
- g_free(data);
-
- g_free(error_data);
-
- if (socket != -1)
- net_nfc_controller_llcp_socket_close(socket, &result);
- }
-}
-
-static void llcp_handle_connect_sap_thread_func(gpointer user_data)
-{
- LlcpConnectSapData *data;
- LlcpData *error_data;
-
- net_nfc_llcp_socket_t socket = -1;
- net_nfc_error_e result = NET_NFC_OK;
-
- data = (LlcpConnectSapData *)user_data;
-
- if (data == NULL)
- {
- DEBUG_ERR_MSG("can not get LlcpConnectSapData");
- return;
- }
-
- if (data->llcp == NULL)
- {
- DEBUG_ERR_MSG("can not get llcp");
- if (data->invocation)
- {
- g_dbus_method_invocation_return_dbus_error(
- data->invocation,
- "org.tizen.NetNfcService.ConnectSapError",
- "can not get llcp");
-
- g_object_unref(data->invocation);
- }
-
- g_free(data);
-
- return;
- }
-
- error_data = g_new0(LlcpData, 1);
- if(error_data == NULL)
- {
- DEBUG_ERR_MSG("Memory allocation failed");
- g_dbus_method_invocation_return_dbus_error(data->invocation,
- "org.tizen.NetNfcService.AllocationError",
- "Can not allocate memory");
- return;
- }
- error_data->llcp = g_object_ref(data->llcp);
- error_data->invocation = g_object_ref(data->invocation);
-
- if (net_nfc_controller_llcp_create_socket(&socket,
- data->type,
- data->miu,
- data->rw,
- &result,
- llcp_socket_error_cb,
- error_data) == false)
- {
- DEBUG_ERR_MSG("%s fiailed [%d]",
- "net_nfc_controller_llcp_create_socket" ,result);
-
- if (data->invocation)
- {
- g_dbus_method_invocation_return_dbus_error(
- data->invocation,
- "org.tizen.NetNfcService.ConnectSapError",
- "can not create socket");
-
- g_object_unref(data->invocation);
- }
-
- g_object_unref(data->llcp);
-
- g_free(data);
-
- g_free(error_data);
-
- return;
- }
-
- DEBUG_SERVER_MSG("OAL socket in Listen :%d", socket);
-
- if (net_nfc_controller_llcp_connect(GUINT_TO_POINTER(data->handle),
- socket,
- data->sap,
- &result,
- llcp_connect_cb,
- data) == false)
- {
- DEBUG_ERR_MSG("%s failed, [%d]",
- "net_nfc_controller_llcp_connect",
- result);
-
- if (data->invocation)
- {
- g_dbus_method_invocation_return_dbus_error(
- data->invocation,
- "org.tizen.NetNfcService.ConnectSapError",
- "can not connect socket");
-
- g_object_unref(data->invocation);
- }
-
- g_object_unref(data->llcp);
-
- g_free(data);
-
- g_free(error_data);
-
- if (socket != -1)
- net_nfc_controller_llcp_socket_close(socket, &result);
-
- }
-}
-
-static void llcp_handle_send_thread_func(gpointer user_data)
-{
- LlcpSendData *data;
- LlcpData *llcp_data;
-
- net_nfc_error_e result = NET_NFC_OK;
-
- data = (LlcpSendData *)user_data;
-
- if (data == NULL)
- {
- DEBUG_ERR_MSG("can not get LlcpSendData");
- return;
- }
-
- if (data->llcp == NULL)
- {
- DEBUG_ERR_MSG("can not get llcp");
- if (data->invocation)
- {
- g_dbus_method_invocation_return_dbus_error(
- data->invocation,
- "org.tizen.NetNfcService.SendError",
- "can not get llcp");
-
- g_object_unref(data->invocation);
- }
-
- if (data->data)
- {
- g_free(data->data->buffer);
- g_free(data->data);
- }
-
- g_free(data);
-
- return;
- }
-
- llcp_data = g_new0(LlcpData, 1);
- if(llcp_data == NULL)
- {
- DEBUG_ERR_MSG("Memory allocation failed");
- g_dbus_method_invocation_return_dbus_error(data->invocation,
- "org.tizen.NetNfcService.AllocationError",
- "Can not allocate memory");
- return;
- }
- llcp_data->llcp = g_object_ref(data->llcp);
- llcp_data->invocation = g_object_ref(data->invocation);
-
- if (net_nfc_controller_llcp_send(GUINT_TO_POINTER(data->handle),
- data->oal_socket,
- data->data,
- &result,
- llcp_send_cb,
- llcp_data) == false)
- {
- DEBUG_ERR_MSG("%s failed, [%d]",
- "net_nfc_controller_llcp_send",
- result);
-
- if (data->invocation)
- {
- g_dbus_method_invocation_return_dbus_error(
- data->invocation,
- "org.tizen.NetNfcService.SendError",
- "can not send socket");
-
- g_object_unref(data->invocation);
- }
-
- g_object_unref(data->llcp);
-
- if (data->data)
- {
- g_free(data->data->buffer);
- g_free(data->data);
- }
-
- g_free(data);
-
- g_free(llcp_data);
-
- return;
- }
-
- g_object_unref(data->llcp);
- g_object_unref(data->invocation);
-
- if (data->data)
- {
- g_free(data->data->buffer);
- g_free(data->data);
- }
-
- g_free(data);
-
- g_free(llcp_data);
-}
-
-static void llcp_handle_send_to_thread_func(gpointer user_data)
-{
- LlcpSendToData *data;
- LlcpData *llcp_data;
-
- net_nfc_error_e result = NET_NFC_OK;
-
- data = (LlcpSendToData *)user_data;
-
- if (data == NULL)
- {
- DEBUG_ERR_MSG("can not get LlcpSendToData");
- return;
- }
-
- if (data->llcp == NULL)
- {
- DEBUG_ERR_MSG("can not get llcp");
- if (data->invocation)
- {
- g_dbus_method_invocation_return_dbus_error(
- data->invocation,
- "org.tizen.NetNfcService.SendToError",
- "can not get llcp");
-
- g_object_unref(data->invocation);
- }
-
- if (data->data)
- {
- g_free(data->data->buffer);
- g_free(data->data);
- }
-
- g_free(data);
-
- return;
- }
-
- llcp_data = g_new0(LlcpData, 1);
- if(llcp_data == NULL)
- {
- DEBUG_ERR_MSG("Memory allocation failed");
- g_dbus_method_invocation_return_dbus_error(data->invocation,
- "org.tizen.NetNfcService.AllocationError",
- "Can not allocate memory");
- return;
- }
- llcp_data->llcp = g_object_ref(data->llcp);
- llcp_data->invocation = g_object_ref(data->invocation);
-
- if (net_nfc_controller_llcp_send_to(GUINT_TO_POINTER(data->handle),
- data->oal_socket,
- data->data,
- data->sap,
- &result,
- llcp_send_cb,
- llcp_data) == false)
- {
- DEBUG_ERR_MSG("%s failed, [%d]",
- "net_nfc_controller_llcp_send_to",
- result);
-
- if (data->invocation)
- {
- g_dbus_method_invocation_return_dbus_error(
- data->invocation,
- "org.tizen.NetNfcService.SendToError",
- "can not send socket");
-
- g_object_unref(data->invocation);
- }
-
- g_object_unref(data->llcp);
-
- if (data->data)
- {
- g_free(data->data->buffer);
- g_free(data->data);
- }
-
- g_free(data);
-
- g_free(llcp_data);
-
- return;
- }
-
- g_object_unref(data->llcp);
- g_object_unref(data->invocation);
-
- if (data->data)
- {
- g_free(data->data->buffer);
- g_free(data->data);
- }
-
- g_free(data);
-
- g_free(llcp_data);
-}
-
-static void llcp_handle_receive_thread_func(gpointer user_data)
-{
- LlcpReceiveData *data;
- LlcpData *llcp_data;
-
- net_nfc_error_e result = NET_NFC_OK;
-
- data = (LlcpReceiveData *)user_data;
-
- if (data == NULL)
- {
- DEBUG_ERR_MSG("can not get LlcpReceiveData");
- return;
- }
-
- if (data->llcp == NULL)
- {
- DEBUG_ERR_MSG("can not get llcp");
- if (data->invocation)
- {
- g_dbus_method_invocation_return_dbus_error(
- data->invocation,
- "org.tizen.NetNfcService.ReceiveError",
- "can not get llcp");
-
- g_object_unref(data->invocation);
- }
-
- g_free(data);
-
- return;
- }
-
- llcp_data = g_new0(LlcpData, 1);
- if(llcp_data == NULL)
- {
- DEBUG_ERR_MSG("Memory allocation failed");
- g_dbus_method_invocation_return_dbus_error(data->invocation,
- "org.tizen.NetNfcService.AllocationError",
- "Can not allocate memory");
- return;
- }
- llcp_data->llcp = g_object_ref(data->llcp);
- llcp_data->invocation = g_object_ref(data->invocation);
-
- if (net_nfc_controller_llcp_recv(GUINT_TO_POINTER(data->handle),
- data->oal_socket,
- data->req_length,
- &result,
- llcp_receive_cb,
- llcp_data) == false)
- {
- DEBUG_ERR_MSG("%s failed, [%d]",
- "net_nfc_controller_llcp_receive",
- result);
-
- if (data->invocation)
- {
- g_dbus_method_invocation_return_dbus_error(
- data->invocation,
- "org.tizen.NetNfcService.ReceiveError",
- "can not receive");
-
- g_object_unref(data->invocation);
- }
-
- g_object_unref(data->llcp);
- g_free(data);
-
- g_free(llcp_data);
-
- return;
- }
-
- g_object_unref(data->llcp);
- g_object_unref(data->invocation);
-
- g_free(data);
-
- g_free(llcp_data);
-}
-
-static void llcp_handle_receive_from_thread_func(gpointer user_data)
-{
- LlcpReceiveData *data;
- LlcpData *llcp_data;
-
- net_nfc_error_e result = NET_NFC_OK;
-
- data = (LlcpReceiveData *)user_data;
-
- if (data == NULL)
- {
- DEBUG_ERR_MSG("can not get LlcpReceiveData");
- return;
- }
-
- if (data->llcp == NULL)
- {
- DEBUG_ERR_MSG("can not get llcp");
- if (data->invocation)
- {
- g_dbus_method_invocation_return_dbus_error(
- data->invocation,
- "org.tizen.NetNfcService.ReceiveFromError",
- "can not get llcp");
-
- g_object_unref(data->invocation);
- }
-
- g_free(data);
-
- return;
- }
-
- llcp_data = g_new0(LlcpData, 1);
- if(llcp_data == NULL)
- {
- DEBUG_ERR_MSG("Memory allocation failed");
- g_dbus_method_invocation_return_dbus_error(data->invocation,
- "org.tizen.NetNfcService.AllocationError",
- "Can not allocate memory");
- return;
- }
- llcp_data->llcp = g_object_ref(data->llcp);
- llcp_data->invocation = g_object_ref(data->invocation);
-
- if (net_nfc_controller_llcp_recv_from(GUINT_TO_POINTER(data->handle),
- data->oal_socket,
- data->req_length,
- &result,
- llcp_receive_from_cb,
- llcp_data) == false)
- {
- DEBUG_ERR_MSG("%s failed, [%d]",
- "net_nfc_controller_llcp_receive",
- result);
-
- if (data->invocation)
- {
- g_dbus_method_invocation_return_dbus_error(
- data->invocation,
- "org.tizen.NetNfcService.ReceiveFromError",
- "can not receive");
-
- g_object_unref(data->invocation);
- }
-
- g_object_unref(data->llcp);
- g_free(data);
-
- g_free(llcp_data);
-
- return;
- }
-
- g_object_unref(data->llcp);
- g_object_unref(data->invocation);
-
- g_free(data);
-
- g_free(llcp_data);
-}
-
-static void llcp_handle_close_thread_func(gpointer user_data)
-{
- LlcpCloseData *data;
-
- net_nfc_error_e result = NET_NFC_OK;
-
- data = (LlcpCloseData *)user_data;
-
- if (data == NULL)
- {
- DEBUG_ERR_MSG("can not get LlcpCloseData");
- return;
- }
-
- if (data->llcp == NULL)
- {
- DEBUG_ERR_MSG("can not get llcp");
- if (data->invocation)
- {
- g_dbus_method_invocation_return_dbus_error(
- data->invocation,
- "org.tizen.NetNfcService.CloseError",
- "can not get llcp");
-
- g_object_unref(data->invocation);
- }
-
- g_free(data);
-
- return;
- }
-
- net_nfc_controller_llcp_socket_close(data->oal_socket,
- &result);
-
- net_nfc_gdbus_llcp_complete_close(data->llcp,
- data->invocation,
- data->client_socket);
-}
-
-static void llcp_handle_disconnect_thread_func(gpointer user_data)
-{
- LlcpDisconnectData *data;
- LlcpData *llcp_data;
- int ret_val = 0;
-
- net_nfc_error_e result = NET_NFC_OK;
-
- data = (LlcpDisconnectData *)user_data;
-
- if (data == NULL)
- {
- DEBUG_ERR_MSG("can not get LlcpDisconnectData");
- return;
- }
-
- if (data->llcp == NULL)
- {
- DEBUG_ERR_MSG("can not get llcp");
- if (data->invocation)
- {
- g_dbus_method_invocation_return_dbus_error(
- data->invocation,
- "org.tizen.NetNfcService.DisconnectError",
- "can not get llcp");
-
- g_object_unref(data->invocation);
- }
-
- g_free(data);
-
- return;
- }
-
- if(GUINT_TO_POINTER(data->handle) == 0)
- {
- net_nfc_server_free_target_info();
- ret_val = pm_unlock_state(LCD_NORMAL, PM_RESET_TIMER);
- DEBUG_SERVER_MSG("net_nfc_controller_disconnect pm_unlock_state"
- "[%d]!!", ret_val);
- }
-
- llcp_data = g_new0(LlcpData, 1);
- if(llcp_data == NULL)
- {
- DEBUG_ERR_MSG("Memory allocation failed");
- return;
- }
- llcp_data->llcp = g_object_ref(data->llcp);
- llcp_data->invocation = g_object_ref(data->invocation);
-
- if (net_nfc_controller_llcp_disconnect(GUINT_TO_POINTER(data->handle),
- data->oal_socket,
- &result,
- llcp_disconnect_cb,
- llcp_data) == false)
- {
- DEBUG_ERR_MSG("%s failed, [%d]",
- "net_nfc_controller_llcp_receive",
- result);
-
- if (data->invocation)
- {
- g_dbus_method_invocation_return_dbus_error(
- data->invocation,
- "org.tizen.NetNfcService.DisconnectError",
- "can not disconnect socket");
-
- g_object_unref(data->invocation);
- }
-
- g_object_unref(data->llcp);
- g_free(data);
-
- g_free(llcp_data);
-
- return;
- }
-
- g_object_unref(data->llcp);
- g_object_unref(data->invocation);
-
- g_free(data);
-
- g_free(llcp_data);
-}
-
-
-static gboolean llcp_handle_config(NetNfcGDbusLlcp *llcp,
- GDBusMethodInvocation *invocation,
- GVariant *arg_config,
- GVariant *smack_privilege,
- gpointer user_data)
-{
- LlcpConfigData *data;
-
- INFO_MSG(">>> REQUEST from [%s]",
- g_dbus_method_invocation_get_sender(invocation));
-
- /* check privilege and update client context */
- if (net_nfc_server_gdbus_check_privilege(invocation,
- smack_privilege,
- "nfc-manager::p2p",
- "w") == false) {
- DEBUG_ERR_MSG("permission denied, and finished request");
-
- return TRUE;
- }
-
- data = g_new0(LlcpConfigData, 1);
- if(data == NULL)
- {
- DEBUG_ERR_MSG("Memory allocation failed");
- g_dbus_method_invocation_return_dbus_error(invocation,
- "org.tizen.NetNfcService.AllocationError",
- "Can not allocate memory");
- return FALSE;
- }
- data->llcp = g_object_ref(llcp);
- data->invocation = g_object_ref(invocation);
-
- g_variant_get(arg_config,
- "(qqyy)",
- &data->miu,
- &data->wks,
- &data->lto,
- &data->option);
-
- if (net_nfc_server_controller_async_queue_push(
- llcp_handle_config_thread_func,
- data) == FALSE)
- {
- g_dbus_method_invocation_return_dbus_error(invocation,
- "org.tizen.NetNfcService.ThreadError",
- "can not push to controller thread");
- g_object_unref(data->llcp);
- g_object_unref(data->invocation);
-
- g_free(data);
-
- return FALSE;
- }
-
- return TRUE;
-}
-
-static gboolean llcp_handle_listen(NetNfcGDbusLlcp *llcp,
- GDBusMethodInvocation *invocation,
- guint32 arg_handle,
- guint32 arg_client_socket,
- guint32 arg_oal_socket,
- guint16 arg_miu,
- guint8 arg_rw,
- gint32 arg_type,
- guint8 arg_sap,
- const gchar *arg_service_name,
- GVariant *smack_privilege,
- gpointer user_data)
-{
- LlcpListenData *data;
-
- INFO_MSG(">>> REQUEST from [%s]",
- g_dbus_method_invocation_get_sender(invocation));
-
- /* check privilege and update client context */
- if (net_nfc_server_gdbus_check_privilege(invocation,
- smack_privilege,
- "nfc-manager::p2p",
- "rw") == false) {
- DEBUG_ERR_MSG("permission denied, and finished request");
-
- return TRUE;
- }
-
- data = g_new0(LlcpListenData, 1);
- if(data == NULL)
- {
- DEBUG_ERR_MSG("Memory allocation failed");
- g_dbus_method_invocation_return_dbus_error(invocation,
- "org.tizen.NetNfcService.AllocationError",
- "Can not allocate memory");
- return FALSE;
- }
- data->llcp = g_object_ref(llcp);
- data->invocation = g_object_ref(invocation);
- data->handle = arg_handle;
- data->client_socket = arg_client_socket;
- data->oal_socket = arg_oal_socket;
- data->miu = arg_miu;
- data->rw = arg_rw;
- data->type = arg_type;
- data->sap = arg_sap;
- data->service_name = g_strdup(arg_service_name);
-
- if (net_nfc_server_controller_async_queue_push(
- llcp_handle_listen_thread_func,
- data) == FALSE)
- {
- g_dbus_method_invocation_return_dbus_error(invocation,
- "org.tizen.NetNfcService.ThreadError",
- "can not push to controller thread");
-
- g_object_unref(data->llcp);
- g_object_unref(data->invocation);
-
- g_free(data->service_name);
- g_free(data);
-
- return FALSE;
- }
-
- return TRUE;
-}
-
-static gboolean llcp_handle_connect(NetNfcGDbusLlcp *llcp,
- GDBusMethodInvocation *invocation,
- guint32 arg_handle,
- guint32 arg_client_socket,
- guint32 arg_oal_socket,
- guint16 arg_miu,
- guint8 arg_rw,
- gint32 arg_type,
- const gchar *arg_service_name,
- GVariant *smack_privilege,
- gpointer user_data)
-{
- LlcpConnectData *data;
-
- INFO_MSG(">>> REQUEST from [%s]",
- g_dbus_method_invocation_get_sender(invocation));
-
- /* check privilege and update client context */
- if (net_nfc_server_gdbus_check_privilege(invocation,
- smack_privilege,
- "nfc-manager::p2p",
- "rw") == false) {
- DEBUG_ERR_MSG("permission denied, and finished request");
-
- return TRUE;
- }
-
- data = g_new0(LlcpConnectData, 1);
- if(data == NULL)
- {
- DEBUG_ERR_MSG("Memory allocation failed");
- g_dbus_method_invocation_return_dbus_error(invocation,
- "org.tizen.NetNfcService.AllocationError",
- "Can not allocate memory");
- return FALSE;
- }
- data->llcp = g_object_ref(llcp);
- data->invocation = g_object_ref(invocation);
- data->handle = arg_handle;
- data->client_socket = arg_client_socket;
- data->oal_socket = arg_oal_socket;
- data->miu = arg_miu;
- data->rw = arg_rw;
- data->type = arg_type;
- data->service_name = g_strdup(arg_service_name);
-
- if (net_nfc_server_controller_async_queue_push(
- llcp_handle_connect_thread_func,
- data) == FALSE)
- {
- g_dbus_method_invocation_return_dbus_error(invocation,
- "org.tizen.NetNfcService.ThreadError",
- "can not push to controller thread");
-
- g_object_unref(data->llcp);
- g_object_unref(data->invocation);
-
- g_free(data->service_name);
- g_free(data);
-
- return FALSE;
- }
-
- return TRUE;
-}
-
-static gboolean llcp_handle_connect_sap(NetNfcGDbusLlcp *llcp,
- GDBusMethodInvocation *invocation,
- guint32 arg_handle,
- guint32 arg_client_socket,
- guint32 arg_oal_socket,
- guint16 arg_miu,
- guint8 arg_rw,
- gint32 arg_type,
- guint8 arg_sap,
- GVariant *smack_privilege,
- gpointer user_data)
-{
- LlcpConnectSapData *data;
-
- INFO_MSG(">>> REQUEST from [%s]",
- g_dbus_method_invocation_get_sender(invocation));
-
- /* check privilege and update client context */
- if (net_nfc_server_gdbus_check_privilege(invocation,
- smack_privilege,
- "nfc-manager::p2p",
- "rw") == false) {
- DEBUG_ERR_MSG("permission denied, and finished request");
-
- return TRUE;
- }
-
- data = g_new0(LlcpConnectSapData, 1);
- if(data == NULL)
- {
- DEBUG_ERR_MSG("Memory allocation failed");
- g_dbus_method_invocation_return_dbus_error(invocation,
- "org.tizen.NetNfcService.AllocationError",
- "Can not allocate memory");
- return FALSE;
- }
- data->llcp = g_object_ref(llcp);
- data->invocation = g_object_ref(invocation);
- data->handle = arg_handle;
- data->client_socket = arg_client_socket;
- data->oal_socket = arg_oal_socket;
- data->miu = arg_miu;
- data->rw = arg_rw;
- data->type = arg_type;
- data->sap = arg_sap;
-
- if(net_nfc_server_controller_async_queue_push(
- llcp_handle_connect_sap_thread_func,
- data) == FALSE)
- {
- g_dbus_method_invocation_return_dbus_error(invocation,
- "org.tizen.NetNfcService.ThreadError",
- "can not push to controller thread");
-
- g_object_unref(data->llcp);
- g_object_unref(data->invocation);
-
- g_free(data);
-
- return FALSE;
- }
-
- return TRUE;
-}
-
-static gboolean llcp_handle_send(NetNfcGDbusLlcp *llcp,
- GDBusMethodInvocation *invocation,
- guint32 arg_handle,
- guint32 arg_client_socket,
- guint32 arg_oal_socket,
- GVariant *arg_data,
- GVariant *smack_privilege,
- gpointer user_data)
-{
- LlcpSendData *data;
-
- INFO_MSG(">>> REQUEST from [%s]",
- g_dbus_method_invocation_get_sender(invocation));
-
- /* check privilege and update client context */
- if (net_nfc_server_gdbus_check_privilege(invocation,
- smack_privilege,
- "nfc-manager::p2p",
- "w") == false) {
- DEBUG_ERR_MSG("permission denied, and finished request");
-
- return TRUE;
- }
-
- data = g_new0(LlcpSendData, 1);
- if(data == NULL)
- {
- DEBUG_ERR_MSG("Memory allocation failed");
- g_dbus_method_invocation_return_dbus_error(invocation,
- "org.tizen.NetNfcService.AllocationError",
- "Can not allocate memory");
- return FALSE;
- }
- data->llcp = g_object_ref(llcp);
- data->invocation = g_object_ref(invocation);
- data->handle = arg_handle;
- data->client_socket = arg_client_socket;
- data->oal_socket = arg_oal_socket;
-
- data->data = net_nfc_util_gdbus_variant_to_data(arg_data);
-
- if (net_nfc_server_controller_async_queue_push(
- llcp_handle_send_thread_func,
- data) == FALSE)
- {
- g_dbus_method_invocation_return_dbus_error(invocation,
- "org.tizen.NetNfcService.ThreadError",
- "can not push to controller thread");
-
- g_object_unref(data->llcp);
- g_object_unref(data->invocation);
-
- if (data->data != NULL)
- {
- g_free(data->data->buffer);
- g_free(data->data);
- }
-
- g_free(data);
-
- return FALSE;
- }
-
- return TRUE;
-}
-
-static gboolean llcp_handle_send_to(NetNfcGDbusLlcp *llcp,
- GDBusMethodInvocation *invocation,
- guint32 arg_handle,
- guint32 arg_client_socket,
- guint32 arg_oal_socket,
- guint8 arg_sap,
- GVariant *arg_data,
- GVariant *smack_privilege,
- gpointer user_data)
-{
- LlcpSendToData *data;
-
- INFO_MSG(">>> REQUEST from [%s]",
- g_dbus_method_invocation_get_sender(invocation));
-
- /* check privilege and update client context */
- if (net_nfc_server_gdbus_check_privilege(invocation,
- smack_privilege,
- "nfc-manager::p2p",
- "rw") == false) {
- DEBUG_ERR_MSG("permission denied, and finished request");
-
- return TRUE;
- }
-
- data = g_new0(LlcpSendToData, 1);
- if(data == NULL)
- {
- DEBUG_ERR_MSG("Memory allocation failed");
- g_dbus_method_invocation_return_dbus_error(invocation,
- "org.tizen.NetNfcService.AllocationError",
- "Can not allocate memory");
- return FALSE;
- }
- data->llcp = g_object_ref(llcp);
- data->invocation = g_object_ref(invocation);
- data->handle = arg_handle;
- data->client_socket = arg_client_socket;
- data->oal_socket = arg_oal_socket;
- data->sap = arg_sap;
-
- data->data = net_nfc_util_gdbus_variant_to_data(arg_data);
-
- if(net_nfc_server_controller_async_queue_push(
- llcp_handle_send_to_thread_func,
- data) == FALSE)
- {
- g_dbus_method_invocation_return_dbus_error(invocation,
- "org.tizen.NetNfcService.ThreadError",
- "can not push to controller thread");
-
- g_object_unref(data->llcp);
- g_object_unref(data->invocation);
-
- if (data->data != NULL)
- {
- g_free(data->data->buffer);
- g_free(data->data);
- }
-
- g_free(data);
-
- return FALSE;
- }
-
- return TRUE;
-}
-
-static gboolean llcp_handle_receive(NetNfcGDbusLlcp *llcp,
- GDBusMethodInvocation *invocation,
- guint32 arg_handle,
- guint32 arg_client_socket,
- guint32 arg_oal_socket,
- guint32 arg_req_length,
- GVariant *smack_privilege,
- gpointer user_data)
-{
- LlcpReceiveData *data;
-
- INFO_MSG(">>> REQUEST from [%s]",
- g_dbus_method_invocation_get_sender(invocation));
-
- /* check privilege and update client context */
- if (net_nfc_server_gdbus_check_privilege(invocation,
- smack_privilege,
- "nfc-manager::p2p",
- "w") == false) {
- DEBUG_ERR_MSG("permission denied, and finished request");
-
- return TRUE;
- }
-
- data = g_new0(LlcpReceiveData, 1);
- if(data == NULL)
- {
- DEBUG_ERR_MSG("Memory allocation failed");
- g_dbus_method_invocation_return_dbus_error(invocation,
- "org.tizen.NetNfcService.AllocationError",
- "Can not allocate memory");
- return FALSE;
- }
- data->llcp = g_object_ref(llcp);
- data->invocation = g_object_ref(invocation);
- data->handle = arg_handle;
- data->client_socket = arg_client_socket;
- data->oal_socket = arg_oal_socket;
- data->req_length = arg_req_length;
-
- if(net_nfc_server_controller_async_queue_push(
- llcp_handle_receive_thread_func,
- data) == FALSE)
- {
- g_dbus_method_invocation_return_dbus_error(invocation,
- "org.tizen.NetNfcService.ThreadError",
- "can not push to controller thread");
-
- g_object_unref(data->llcp);
- g_object_unref(data->invocation);
-
- g_free(data);
-
- return FALSE;
- }
-
- return TRUE;
-}
-
-static gboolean llcp_handle_receive_from(NetNfcGDbusLlcp *llcp,
- GDBusMethodInvocation *invocation,
- guint32 arg_handle,
- guint32 arg_client_socket,
- guint32 arg_oal_socket,
- guint32 arg_req_length,
- GVariant *smack_privilege,
- gpointer user_data)
-{
- LlcpReceiveData *data;
-
- INFO_MSG(">>> REQUEST from [%s]",
- g_dbus_method_invocation_get_sender(invocation));
-
- /* check privilege and update client context */
- if (net_nfc_server_gdbus_check_privilege(invocation,
- smack_privilege,
- "nfc-manager::p2p",
- "w") == false) {
- DEBUG_ERR_MSG("permission denied, and finished request");
-
- return TRUE;
- }
-
- data = g_new0(LlcpReceiveData, 1);
- if(data == NULL)
- {
- DEBUG_ERR_MSG("Memory allocation failed");
- g_dbus_method_invocation_return_dbus_error(invocation,
- "org.tizen.NetNfcService.AllocationError",
- "Can not allocate memory");
- return FALSE;
- }
- data->llcp = g_object_ref(llcp);
- data->invocation = g_object_ref(invocation);
- data->handle = arg_handle;
- data->client_socket = arg_client_socket;
- data->oal_socket = arg_oal_socket;
- data->req_length = arg_req_length;
-
- if(net_nfc_server_controller_async_queue_push(
- llcp_handle_receive_from_thread_func,
- data) == FALSE)
- {
- g_dbus_method_invocation_return_dbus_error(invocation,
- "org.tizen.NetNfcService.ThreadError",
- "can not push to controller thread");
-
- g_object_unref(data->llcp);
- g_object_unref(data->invocation);
-
- g_free(data);
-
- return FALSE;
- }
-
- return TRUE;
-}
-
-static gboolean llcp_handle_close(NetNfcGDbusLlcp *llcp,
- GDBusMethodInvocation *invocation,
- guint32 arg_handle,
- guint32 arg_client_socket,
- guint32 arg_oal_socket,
- GVariant *smack_privilege,
- gpointer user_data)
-{
- LlcpCloseData *data;
-
- INFO_MSG(">>> REQUEST from [%s]",
- g_dbus_method_invocation_get_sender(invocation));
-
- /* check privilege and update client context */
- if (net_nfc_server_gdbus_check_privilege(invocation,
- smack_privilege,
- "nfc-manager::p2p",
- "w") == false) {
- DEBUG_ERR_MSG("permission denied, and finished request");
-
- return TRUE;
- }
-
- data = g_new0(LlcpCloseData, 1);
- if(data == NULL)
- {
- DEBUG_ERR_MSG("Memory allocation failed");
- g_dbus_method_invocation_return_dbus_error(invocation,
- "org.tizen.NetNfcService.AllocationError",
- "Can not allocate memory");
- return FALSE;
- }
- data->llcp = g_object_ref(llcp);
- data->invocation = g_object_ref(invocation);
- data->handle = arg_handle;
- data->client_socket = arg_client_socket;
- data->oal_socket = arg_oal_socket;
-
- if (net_nfc_server_controller_async_queue_push(
- llcp_handle_close_thread_func,
- data) == FALSE)
- {
- g_dbus_method_invocation_return_dbus_error(invocation,
- "org.tizen.NetNfcService.ThreadError",
- "can not push to controller thread");
-
- g_object_unref(data->llcp);
- g_object_unref(data->invocation);
-
- g_free(data);
-
- return FALSE;
- }
-
- return TRUE;
-}
-
-static gboolean llcp_handle_disconnect(NetNfcGDbusLlcp *llcp,
- GDBusMethodInvocation *invocation,
- guint32 arg_handle,
- guint32 arg_client_socket,
- guint32 arg_oal_socket,
- GVariant *smack_privilege,
- gpointer user_data)
-{
- LlcpDisconnectData *data;
-
- INFO_MSG(">>> REQUEST from [%s]",
- g_dbus_method_invocation_get_sender(invocation));
-
- /* check privilege and update client context */
- if (net_nfc_server_gdbus_check_privilege(invocation,
- smack_privilege,
- "nfc-manager::p2p",
- "w") == false) {
- DEBUG_ERR_MSG("permission denied, and finished request");
-
- return TRUE;
- }
-
- data = g_new0(LlcpDisconnectData, 1);
- if(data == NULL)
- {
- DEBUG_ERR_MSG("Memory allocation failed");
- g_dbus_method_invocation_return_dbus_error(invocation,
- "org.tizen.NetNfcService.AllocationError",
- "Can not allocate memory");
- return FALSE;
- }
- data->llcp = g_object_ref(llcp);
- data->invocation = g_object_ref(invocation);
- data->handle = arg_handle;
- data->client_socket = arg_client_socket;
- data->oal_socket = arg_oal_socket;
-
- if (net_nfc_server_controller_async_queue_push(
- llcp_handle_disconnect_thread_func,
- data) == FALSE)
- {
- g_dbus_method_invocation_return_dbus_error(invocation,
- "org.tizen.NetNfcService.ThreadError",
- "can not push to controller thread");
-
- g_object_unref(data->llcp);
- g_object_unref(data->invocation);
-
- g_free(data);
-
- return FALSE;
- }
-
- return TRUE;
-}
-
-
-static void llcp_deactivated_thread_func(gpointer user_data)
-{
- ServerLlcpData *data;
-
- net_nfc_request_llcp_msg_t *req_llcp_msg;
- net_nfc_target_handle_s *handle;
-
- data = (ServerLlcpData *)user_data;
-
- if (data == NULL)
- {
- DEBUG_ERR_MSG("can not get ServerLlcpData");
-
- return;
- }
-
- if (data->llcp == NULL)
- {
- DEBUG_ERR_MSG("can not get llcp");
-
- g_free(data->req_msg);
- g_free(data);
-
- return;
- }
-
- if (data->req_msg == NULL)
- {
- DEBUG_ERR_MSG("can not get request msg");
-
- g_object_unref(data->llcp);
- g_free(data);
-
- return;
- }
-
- req_llcp_msg = (net_nfc_request_llcp_msg_t *)data->req_msg;
-
- handle = (net_nfc_target_handle_s *)req_llcp_msg->user_param;
- if (handle == NULL)
- {
- DEBUG_SERVER_MSG(
- "the target ID = [0x%p] was not connected before."
- "current device may be a TARGET", handle);
- }
- else
- {
- net_nfc_error_e result = NET_NFC_OK;
-
- if (net_nfc_controller_disconnect(handle, &result) == false)
- {
- if (result != NET_NFC_NOT_CONNECTED)
- {
- net_nfc_controller_exception_handler();
- }
- else
- {
- DEBUG_SERVER_MSG("target was not connected.");
- }
- }
-
- net_nfc_server_set_state(NET_NFC_SERVER_IDLE);
- }
-
- /* send p2p detatch */
- net_nfc_server_p2p_detached();
-
- g_object_unref(data->llcp);
-
- g_free(data->req_msg);
- g_free(data);
-}
-
-static void llcp_listen_thread_func(gpointer user_data)
-{
- ServerLlcpData *data;
-
- socket_info_t *info = NULL;
- net_nfc_request_listen_socket_t *listen_socket;
-
- data = (ServerLlcpData *)user_data;
-
- if (data == NULL)
- {
- DEBUG_ERR_MSG("can not get ServerLlcpData");
- return;
- }
-
- if (data->llcp == NULL)
- {
- DEBUG_ERR_MSG("can not get llcp");
-
- g_free(data->req_msg);
- g_free(data);
-
- return;
- }
-
- if (data->req_msg == NULL)
- {
- DEBUG_ERR_MSG("can not get request msg");
-
- g_object_unref(data->llcp);
- g_free(data);
-
- return;
- }
-
- listen_socket = (net_nfc_request_listen_socket_t *)data->req_msg;
-
- info = (socket_info_t *)listen_socket->user_param;
- info = _get_socket_info(info->socket);
-
- if (info != NULL)
- {
- if (_add_socket_info(listen_socket->client_socket) != NULL)
- {
- if (info->work_cb != NULL)
- {
- info->work_cb(listen_socket->client_socket,
- listen_socket->result, NULL, NULL,info->work_param);
- }
- }
- else
- {
- DEBUG_ERR_MSG("_net_nfc_util_alloc_mem failed");
- }
- }
-
- g_object_unref(data->llcp);
-
- g_free(data->req_msg);
- g_free(data);
-}
-
-static void llcp_socket_error_thread_func(gpointer user_data)
-{
- ServerLlcpData *data;
-
- net_nfc_request_llcp_msg_t *req_llcp_msg;
- net_nfc_llcp_param_t *param;
-
- data = (ServerLlcpData *)user_data;
-
- if (data == NULL)
- {
- DEBUG_ERR_MSG("can not get ServerLlcpData");
- return;
- }
-
- if (data->llcp == NULL)
- {
- DEBUG_ERR_MSG("can not get llcp");
-
- g_free(data->req_msg);
- g_free(data);
-
- return;
- }
-
- if (data->req_msg == NULL)
- {
- DEBUG_ERR_MSG("can not get request msg");
-
- g_object_unref(data->llcp);
- g_free(data);
-
- return;
- }
-
- req_llcp_msg = (net_nfc_request_llcp_msg_t *)data->req_msg;
- param = (net_nfc_llcp_param_t *)req_llcp_msg->user_param;
-
- if (param)
- {
- if (param->cb)
- {
- param->cb(req_llcp_msg->llcp_socket,
- req_llcp_msg->result,
- NULL,
- NULL,
- param->user_param);
- }
-
- g_free(param);
- }
-
- g_object_unref(data->llcp);
-
- g_free(data->req_msg);
- g_free(data);
-}
-
-static void llcp_send_thread_func(gpointer user_data)
-{
- ServerLlcpData *data;
-
- net_nfc_request_llcp_msg_t *req_llcp_msg;
- net_nfc_llcp_param_t *param;
-
- data = (ServerLlcpData *)user_data;
-
- if (data == NULL)
- {
- DEBUG_ERR_MSG("can not get ServerLlcpData");
-
- return;
- }
-
- if (data->llcp == NULL)
- {
- DEBUG_ERR_MSG("can not get llcp");
-
- g_free(data->req_msg);
- g_free(data);
-
- return;
- }
-
- if (data->req_msg == NULL)
- {
- DEBUG_ERR_MSG("can not get request msg");
-
- g_object_unref(data->llcp);
- g_free(data);
-
- return;
- }
-
- req_llcp_msg = (net_nfc_request_llcp_msg_t *)data->req_msg;
- param = (net_nfc_llcp_param_t *)req_llcp_msg->user_param;
-
- if (param)
- {
- if (param->cb)
- {
- param->cb(param->socket,
- req_llcp_msg->result,
- NULL,
- NULL,
- param->user_param);
- }
-
- g_free(param);
- }
-
- g_object_unref(data->llcp);
-
- g_free(data->req_msg);
- g_free(data);
-}
-
-static void llcp_receive_thread_func(gpointer user_data)
-{
- ServerLlcpData *data;
-
- net_nfc_request_receive_socket_t *req_receive_socket;
- net_nfc_llcp_param_t *param;
-
- data = (ServerLlcpData *)user_data;
-
- if (data == NULL)
- {
- DEBUG_ERR_MSG("can not get ServerLlcpData");
-
- return;
- }
-
- if (data->llcp == NULL)
- {
- DEBUG_ERR_MSG("can not get llcp");
-
- g_free(data->req_msg);
- g_free(data);
-
- return;
- }
-
- if (data->req_msg == NULL)
- {
- DEBUG_ERR_MSG("can not get request msg");
-
- g_object_unref(data->llcp);
- g_free(data);
-
- return;
- }
-
- req_receive_socket = (net_nfc_request_receive_socket_t *)data->req_msg;
- param = (net_nfc_llcp_param_t *)req_receive_socket->user_param;
-
- if (param)
- {
- if (param->cb)
- {
- param->cb(param->socket,
- req_receive_socket->result,
- ¶m->data,
- NULL,
- param->user_param);
- }
-
- if (param->data.buffer)
- g_free(param->data.buffer);
-
- g_free(param);
- }
-
- g_object_unref(data->llcp);
-
- g_free(data->req_msg);
- g_free(data);
-}
-
-static void llcp_receive_from_thread_func(gpointer user_data)
-{
- ServerLlcpData *data;
-
- net_nfc_request_receive_from_socket_t *req_receive_from_socket;
- net_nfc_llcp_param_t *param;
-
- data = (ServerLlcpData *)user_data;
-
- if (data == NULL)
- {
- DEBUG_ERR_MSG("can not get ServerLlcpData");
-
- return;
- }
-
- if (data->llcp == NULL)
- {
- DEBUG_ERR_MSG("can not get llcp");
-
- g_free(data->req_msg);
- g_free(data);
-
- return;
- }
-
- if (data->req_msg == NULL)
- {
- DEBUG_ERR_MSG("can not get request msg");
-
- g_object_unref(data->llcp);
- g_free(data);
-
- return;
- }
-
- req_receive_from_socket = (net_nfc_request_receive_from_socket_t *)
- data->req_msg;
- param = (net_nfc_llcp_param_t *)req_receive_from_socket->user_param;
-
- if (param)
- {
- if (param->cb)
- {
- param->cb(param->socket,
- req_receive_from_socket->result,
- ¶m->data,
- (void *)(int)req_receive_from_socket->sap,
- param->user_param);
- }
-
- if (param->data.buffer)
- g_free(param->data.buffer);
-
- g_free(param);
- }
-
- g_object_unref(data->llcp);
-
- g_free(data->req_msg);
- g_free(data);
-}
-
-static void llcp_connect_thread_func(gpointer user_data)
-{
- ServerLlcpData *data;
-
- net_nfc_request_llcp_msg_t *req_llcp_msg;
- net_nfc_llcp_param_t *param;
-
- data = (ServerLlcpData *)user_data;
-
- if (data == NULL)
- {
- DEBUG_ERR_MSG("can not get ServerLlcpData");
-
- return;
- }
-
- if (data->llcp == NULL)
- {
- DEBUG_ERR_MSG("can not get llcp");
-
- g_free(data->req_msg);
- g_free(data);
-
- return;
- }
-
- if (data->req_msg == NULL)
- {
- DEBUG_ERR_MSG("can not get request msg");
-
- g_object_unref(data->llcp);
- g_free(data);
-
- return;
- }
-
- req_llcp_msg = (net_nfc_request_llcp_msg_t *)data->req_msg;
- param = (net_nfc_llcp_param_t *)req_llcp_msg->user_param;
-
- if (param)
- {
- if (param->cb)
- {
- param->cb(param->socket,
- req_llcp_msg->result,
- NULL,
- NULL,
- param->user_param);
- }
-
- g_free(param);
- }
-
- g_object_unref(data->llcp);
-
- g_free(data->req_msg);
- g_free(data);
-}
-
-static void llcp_disconnect_thread_func(gpointer user_data)
-{
- ServerLlcpData *data;
-
- net_nfc_request_llcp_msg_t *req_llcp_msg;
- net_nfc_llcp_param_t *param;
-
- data = (ServerLlcpData *)user_data;
-
- if (data == NULL)
- {
- DEBUG_ERR_MSG("can not get ServerLlcpData");
-
- return;
- }
-
- if (data->llcp == NULL)
- {
- DEBUG_ERR_MSG("can not get llcp");
-
- g_free(data->req_msg);
- g_free(data);
-
- return;
- }
-
- if (data->req_msg == NULL)
- {
- DEBUG_ERR_MSG("can not get request msg");
-
- g_object_unref(data->llcp);
- g_free(data);
-
- return;
- }
-
- req_llcp_msg = (net_nfc_request_llcp_msg_t *)data->req_msg;
- param = (net_nfc_llcp_param_t *)req_llcp_msg->user_param;
-
- if (param)
- {
- if (param->cb)
- {
- param->cb(param->socket,
- req_llcp_msg->result,
- NULL,
- NULL,
- param->user_param);
- }
-
- g_free(param);
- }
-
- g_object_unref(data->llcp);
-
- g_free(data->req_msg);
- g_free(data);
-}
-
-static void llcp_simple_socket_error_cb(net_nfc_llcp_socket_t socket,
- net_nfc_error_e result,
- data_s *data,
- void *extra,
- void *user_param)
-{
- LlcpSimpleData *simple_data;
-
- simple_data = (LlcpSimpleData *)user_param;
-
- if (simple_data->error_callback)
- {
- simple_data->error_callback(result,
- simple_data->handle,
- socket,
- data,
- simple_data->user_data);
- }
-
- g_free(simple_data);
-}
-
-static void llcp_simple_listen_cb(net_nfc_llcp_socket_t socket,
- net_nfc_error_e result,
- data_s *data,
- void *extra,
- void *user_param)
-{
- LlcpSimpleData *simple_data;
-
- simple_data = (LlcpSimpleData *)user_param;
-
- if (result != NET_NFC_OK) {
- DEBUG_ERR_MSG("listen socket failed, [%d]", result);
- }
-
- if (simple_data->callback)
- {
- simple_data->callback(result,
- simple_data->handle,
- socket,
- data,
- simple_data->user_data);
- }
-
- g_free(simple_data);
-}
-
-static void llcp_simple_connect_cb(net_nfc_llcp_socket_t socket,
- net_nfc_error_e result,
- data_s *data,
- void *extra,
- void *user_param)
-{
- LlcpSimpleData *simple_data;
-
- simple_data = (LlcpSimpleData *)user_param;
-
- if (result != NET_NFC_OK) {
- DEBUG_ERR_MSG("connect socket failed, [%d]", result);
- }
-
- if (simple_data->callback)
- {
- simple_data->callback(result,
- simple_data->handle,
- socket,
- data,
- simple_data->user_data);
- }
-
- g_free(simple_data);
-}
-
-static void llcp_simple_server_error_cb(net_nfc_llcp_socket_t socket,
- net_nfc_error_e result,
- data_s *data,
- void *extra,
- void *user_param)
-{
- LlcpSimpleData *simple_data;
-
- simple_data = (LlcpSimpleData *)user_param;
-
- if (simple_data->error_callback)
- {
- simple_data->error_callback(result,
- simple_data->handle,
- socket,
- data,
- simple_data->user_data);
- }
-
- g_free(simple_data);
-}
-
-static void llcp_simple_send_cb(net_nfc_llcp_socket_t socket,
- net_nfc_error_e result,
- data_s *data,
- void *extra,
- void *user_param)
-{
- LlcpSimpleData *simple_data;
-
- simple_data = (LlcpSimpleData *)user_param;
-
- if (simple_data->callback)
- {
- simple_data->callback(result,
- simple_data->handle,
- socket,
- data,
- simple_data->user_data);
- }
-
- g_free(simple_data);
-}
-
-static void llcp_simple_receive_cb(net_nfc_llcp_socket_t socket,
- net_nfc_error_e result,
- data_s *data,
- void *extra,
- void *user_param)
-{
- LlcpSimpleData *simple_data;
-
- simple_data = (LlcpSimpleData *)user_param;
-
- if (simple_data->callback)
- {
- simple_data->callback(result,
- simple_data->handle,
- socket,
- data,
- simple_data->user_data);
- }
-
- g_free(simple_data);
-}
-
-/* Public Function */
-gboolean net_nfc_server_llcp_init(GDBusConnection *connection)
-{
- GError *error = NULL;
-
- if (llcp_skeleton)
- g_object_unref(llcp_skeleton);
-
- llcp_skeleton = net_nfc_gdbus_llcp_skeleton_new();
-
- g_signal_connect(llcp_skeleton,
- "handle-config",
- G_CALLBACK(llcp_handle_config),
- NULL);
-
- g_signal_connect(llcp_skeleton,
- "handle-listen",
- G_CALLBACK(llcp_handle_listen),
- NULL);
-
- g_signal_connect(llcp_skeleton,
- "handle-connect",
- G_CALLBACK(llcp_handle_connect),
- NULL);
-
- g_signal_connect(llcp_skeleton,
- "handle-connect-sap",
- G_CALLBACK(llcp_handle_connect_sap),
- NULL);
-
- g_signal_connect(llcp_skeleton,
- "handle-send",
- G_CALLBACK(llcp_handle_send),
- NULL);
-
- g_signal_connect(llcp_skeleton,
- "handle-send-to",
- G_CALLBACK(llcp_handle_send_to),
- NULL);
-
- g_signal_connect(llcp_skeleton,
- "handle-receive",
- G_CALLBACK(llcp_handle_receive),
- NULL);
-
- g_signal_connect(llcp_skeleton,
- "handle-receive-from",
- G_CALLBACK(llcp_handle_receive_from),
- NULL);
-
- g_signal_connect(llcp_skeleton,
- "handle-close",
- G_CALLBACK(llcp_handle_close),
- NULL);
-
- g_signal_connect(llcp_skeleton,
- "handle-disconnect",
- G_CALLBACK(llcp_handle_disconnect),
- NULL);
-
- if(g_dbus_interface_skeleton_export(
- G_DBUS_INTERFACE_SKELETON(llcp_skeleton),
- connection,
- "/org/tizen/NetNfcService/Llcp",
- &error) == FALSE)
- {
- g_error_free(error);
- g_object_unref(llcp_skeleton);
- llcp_skeleton = NULL;
-
- return FALSE;
- }
-
- return TRUE;
-}
-
-void net_nfc_server_llcp_deinit(void)
-{
- if (llcp_skeleton)
- {
- g_object_unref(llcp_skeleton);
- llcp_skeleton = NULL;
- }
-}
-
-void net_nfc_server_llcp_deactivated(net_nfc_request_msg_t *req_msg)
-{
- llcp_add_async_queue(req_msg, llcp_deactivated_thread_func);
-}
-
-void net_nfc_server_llcp_listen(net_nfc_request_msg_t *req_msg)
-{
- llcp_add_async_queue(req_msg, llcp_listen_thread_func);
-}
-
-void net_nfc_server_llcp_socket_error(net_nfc_request_msg_t *req_msg)
-{
- llcp_add_async_queue(req_msg, llcp_socket_error_thread_func);
-}
-
-void net_nfc_server_llcp_send(net_nfc_request_msg_t *req_msg)
-{
- llcp_add_async_queue(req_msg, llcp_send_thread_func);
-}
-
-void net_nfc_server_llcp_receive(net_nfc_request_msg_t *req_msg)
-{
- llcp_add_async_queue(req_msg, llcp_receive_thread_func);
-}
-
-void net_nfc_server_llcp_receive_from(net_nfc_request_msg_t *req_msg)
-{
- llcp_add_async_queue(req_msg, llcp_receive_from_thread_func);
-}
-
-void net_nfc_server_llcp_connect(net_nfc_request_msg_t *req_msg)
-{
- llcp_add_async_queue(req_msg, llcp_connect_thread_func);
-}
-
-void net_nfc_server_llcp_disconnect(net_nfc_request_msg_t *req_msg)
-{
- llcp_add_async_queue(req_msg, llcp_disconnect_thread_func);
-}
-
-net_nfc_error_e net_nfc_server_llcp_set_config(
- net_nfc_llcp_config_info_s *config)
-{
- net_nfc_error_e result;
-
- if (config == NULL)
- {
- net_nfc_controller_llcp_config(&llcp_config, &result);
- return result;
- }
-
- net_nfc_controller_llcp_config(config, &result);
- memcpy(&llcp_config, config, sizeof(llcp_config));
-
- return result;
-}
-
-guint16 net_nfc_server_llcp_get_miu(void)
-{
- return llcp_config.miu;
-}
-
-guint16 net_nfc_server_llcp_get_wks(void)
-{
- return llcp_config.wks;
-}
-
-guint8 net_nfc_server_llcp_get_lto(void)
-{
- return llcp_config.lto;
-}
-
-guint8 net_nfc_server_llcp_get_option(void)
-{
- return llcp_config.option;
-}
-
-net_nfc_error_e net_nfc_server_llcp_simple_server(
- net_nfc_target_handle_s *handle,
- const char *san,
- sap_t sap,
- net_nfc_server_llcp_callback callback,
- net_nfc_server_llcp_callback error_callback,
- gpointer user_data)
-{
- net_nfc_error_e result = NET_NFC_OK;
-
- net_nfc_llcp_socket_t socket = -1;
- net_nfc_llcp_config_info_s config;
-
- LlcpSimpleData *simple_data = NULL;
-
- if (handle == NULL)
- return NET_NFC_NULL_PARAMETER;
-
- if (san == NULL)
- return NET_NFC_NULL_PARAMETER;
-
- if (net_nfc_controller_llcp_get_remote_config(handle,
- &config,
- &result) == false)
- {
- DEBUG_ERR_MSG("%s failed [%d]",
- "net_nfc_controller_llcp_get_remote_config",
- result);
- return result;
- }
-
- simple_data = g_new0(LlcpSimpleData, 1);
- if(simple_data == NULL)
- {
- DEBUG_ERR_MSG("Memory allocation failed");
-
- return NET_NFC_ALLOC_FAIL;
- }
- simple_data->handle = handle;
- simple_data->callback = callback;
- simple_data->error_callback = error_callback;
- simple_data->user_data = user_data;
-
- simple_data->miu = MIN(config.miu, net_nfc_server_llcp_get_miu());
-
- if (net_nfc_controller_llcp_create_socket(&socket,
- NET_NFC_LLCP_SOCKET_TYPE_CONNECTIONORIENTED,
- simple_data->miu,
- 1,
- &result,
- llcp_simple_socket_error_cb,
- simple_data) == false)
- {
- DEBUG_ERR_MSG("%s failed [%d]",
- "net_nfc_controller_llcp_create_socket",
- result);
-
- g_free(simple_data);
- return result;
- }
-
- simple_data->socket = socket;
-
- if (net_nfc_controller_llcp_bind(socket,
- sap,
- &result) == false)
- {
- DEBUG_ERR_MSG("%s failed [%d]",
- "nte_nfc_controller_llcp_bind",
- result);
-
- if (simple_data->socket != 1)
- net_nfc_controller_llcp_socket_close(socket, &result);
-
- g_free(simple_data);
-
- return result;
- }
-
- if (net_nfc_controller_llcp_listen(handle,
- (uint8_t *)san,
- socket,
- &result,
- llcp_simple_listen_cb,
- simple_data) == false)
- {
- DEBUG_ERR_MSG("%s failed [%d]",
- "net_nfc_controller_llcp_listen",
- result);
-
- if (simple_data->socket != 1)
- {
- net_nfc_controller_llcp_socket_close(
- simple_data->socket,
- &result);
- }
-
- g_free(simple_data);
-
- return result;
-
- }
-
- DEBUG_SERVER_MSG("result [%d]", result);
-
- if (result == NET_NFC_BUSY)
- result = NET_NFC_OK;
-
- return result;
-}
-
-net_nfc_error_e net_nfc_server_llcp_simple_client(
- net_nfc_target_handle_s *handle,
- const char *san,
- sap_t sap,
- net_nfc_server_llcp_callback callback,
- net_nfc_server_llcp_callback error_callback,
- gpointer user_data)
-{
- net_nfc_error_e result = NET_NFC_OK;
-
- net_nfc_llcp_socket_t socket = -1;
- net_nfc_llcp_config_info_s config;
-
- LlcpSimpleData *simple_data = NULL;
-
- if (handle == NULL)
- return NET_NFC_NULL_PARAMETER;
-
- if (net_nfc_controller_llcp_get_remote_config(handle,
- &config,
- &result) == false)
- {
- DEBUG_ERR_MSG("%s failed [%d]",
- "net_nfc_controller_llcp_get_remote_config",
- result);
- return result;
- }
-
- simple_data = g_new0(LlcpSimpleData, 1);
-
- simple_data->handle = handle;
- simple_data->callback = callback;
- simple_data->error_callback = error_callback;
- simple_data->user_data = user_data;
-
- simple_data->miu = MIN(config.miu, net_nfc_server_llcp_get_miu());
-
- if (net_nfc_controller_llcp_create_socket(&socket,
- NET_NFC_LLCP_SOCKET_TYPE_CONNECTIONORIENTED,
- simple_data->miu,
- 1,
- &result,
- llcp_simple_socket_error_cb,
- simple_data) == false)
- {
- DEBUG_ERR_MSG("%s failed [%d]",
- "net_nfc_controller_llcp_create_socket",
- result);
-
- g_free(simple_data);
- return result;
- }
-
- simple_data->socket = socket;
-
- if (san == NULL)
- {
- if (net_nfc_controller_llcp_connect(handle,
- simple_data->socket,
- sap,
- &result,
- llcp_simple_connect_cb,
- simple_data) == false)
- {
- DEBUG_ERR_MSG("%s failed [%d]",
- "net_nfc_controller_llcp_connect",
- result);
-
- if (simple_data->socket != -1)
- {
- net_nfc_controller_llcp_socket_close(
- simple_data->socket,
- &result);
- }
-
- g_free(simple_data);
-
- return result;
- }
-
- }
- else
- {
- if (net_nfc_controller_llcp_connect_by_url(handle,
- simple_data->socket,
- (uint8_t *)san,
- &result,
- llcp_simple_connect_cb,
- simple_data) == false)
- {
- DEBUG_ERR_MSG("%s failed [%d]",
- "net_nfc_controller_llcp_connect_by_url",
- result);
-
- if (simple_data->socket != -1)
- {
- net_nfc_controller_llcp_socket_close(
- simple_data->socket,
- &result);
- }
-
- g_free(simple_data);
-
- return result;
- }
- }
-
- DEBUG_SERVER_MSG("result [%d]", result);
-
- if (result == NET_NFC_BUSY)
- result = NET_NFC_OK;
-
- return result;
-}
-
-net_nfc_error_e net_nfc_server_llcp_simple_accept(
- net_nfc_target_handle_s *handle,
- net_nfc_llcp_socket_t socket,
- net_nfc_server_llcp_callback error_callback,
- gpointer user_data)
-{
- net_nfc_error_e result = NET_NFC_OK;
-
- LlcpSimpleData *simple_data;
-
- simple_data = g_new0(LlcpSimpleData, 1);
- if(simple_data == NULL)
- {
- DEBUG_ERR_MSG("Memory allocation failed");
-
- return NET_NFC_ALLOC_FAIL;
- }
- simple_data->handle = handle;
- simple_data->socket = socket;
- simple_data->error_callback = error_callback;
- simple_data->user_data = user_data;
-
- if (net_nfc_controller_llcp_accept(socket,
- &result,
- llcp_simple_server_error_cb,
- simple_data) == false)
- {
- DEBUG_ERR_MSG("%s failed [%d]",
- "net_nfc_controller_llcp_accept",
- result);
- }
-
- if (result == NET_NFC_BUSY)
- result = NET_NFC_OK;
-
- return result;
-}
-
-net_nfc_error_e net_nfc_server_llcp_simple_send(
- net_nfc_target_handle_s *handle,
- net_nfc_llcp_socket_t socket,
- data_s *data,
- net_nfc_server_llcp_callback callback,
- gpointer user_data)
-{
- net_nfc_error_e result = NET_NFC_OK;
-
- LlcpSimpleData *simple_data;
-
- simple_data = g_new0(LlcpSimpleData, 1);
- if(simple_data == NULL)
- {
- DEBUG_ERR_MSG("Memory allocation failed");
-
- return NET_NFC_ALLOC_FAIL;
- }
- simple_data->handle = handle;
- simple_data->socket = socket;
- simple_data->callback = callback;
- simple_data->user_data = user_data;
-
- if (net_nfc_controller_llcp_send(handle,
- socket,
- data,
- &result,
- llcp_simple_send_cb,
- simple_data) == false)
- {
- DEBUG_ERR_MSG("%s failed [%d]",
- "net_nfc_controller_llcp_send",
- result);
- }
-
- if (result == NET_NFC_BUSY)
- result = NET_NFC_OK;
-
- return result;
-}
-
-net_nfc_error_e net_nfc_server_llcp_simple_receive(
- net_nfc_target_handle_s *handle,
- net_nfc_llcp_socket_t socket,
- net_nfc_server_llcp_callback callback,
- gpointer user_data)
-{
- net_nfc_error_e result = NET_NFC_OK;
-
- LlcpSimpleData *simple_data;
-
- simple_data = g_new0(LlcpSimpleData, 1);
- if(simple_data == NULL)
- {
- DEBUG_ERR_MSG("Memory allocation failed");
-
- return NET_NFC_ALLOC_FAIL;
- }
- simple_data->handle = handle;
- simple_data->socket = socket;
- simple_data->callback = callback;
- simple_data->user_data = user_data;
-
- if (net_nfc_controller_llcp_recv(handle,
- socket,
- net_nfc_server_llcp_get_miu(),
- &result,
- llcp_simple_receive_cb,
- simple_data) == false)
- {
- DEBUG_ERR_MSG("%s failed [%d]",
- "net_nfc_controller_llcp_send",
- result);
- }
-
- if (result == NET_NFC_BUSY)
- result = NET_NFC_OK;
-
- return result;
-}
-
-typedef struct _service_t
-{
- uint32_t sap;
- char *san;
- char *id;
- net_nfc_server_llcp_activate_cb cb;
- void *user_data;
-}
-service_t;
-
-static GHashTable *service_table;
-
-static void _llcp_init()
-{
- if (service_table == NULL)
- service_table = g_hash_table_new(NULL, NULL);
-}
-
-inline static service_t *_llcp_find_service(uint32_t sap)
-{
- return (service_t *)g_hash_table_lookup(service_table,
- (gconstpointer)sap);
-}
-
-static net_nfc_error_e _llcp_add_service(const char *id, uint32_t sap,
- const char *san, net_nfc_server_llcp_activate_cb cb, void *user_data)
-{
- service_t *service = NULL;
- net_nfc_error_e result;
-
- if (cb == NULL) {
- DEBUG_ERR_MSG("callback is mandatory");
-
- return NET_NFC_NULL_PARAMETER;
- }
-
- _llcp_init();
-
- if (_llcp_find_service(sap) == NULL) {
- DEBUG_SERVER_MSG("new service, sap [%d]", sap);
-
- service = g_new0(service_t, 1);
- if (service != NULL) {
- service->sap = sap;
- if (san != NULL && strlen(san) > 0) {
- service->san = g_strdup(san);
- }
- if (id != NULL && strlen(id) > 0) {
- service->id = g_strdup(id);
- }
- service->cb = cb;
- service->user_data = user_data;
-
- g_hash_table_insert(service_table, (gpointer)sap,
- (gpointer)service);
-
- result = NET_NFC_OK;
- } else {
- DEBUG_ERR_MSG("alloc failed");
-
- result = NET_NFC_ALLOC_FAIL;
- }
- } else {
- DEBUG_ERR_MSG("already registered");
-
- result = NET_NFC_ALREADY_REGISTERED;
- }
-
- return result;
-}
-
-static void _llcp_remove_service(uint32_t sap)
-{
- service_t *service = NULL;
-
- service = _llcp_find_service(sap);
- if (service != NULL) {
- g_free(service->san);
- g_free(service->id);
- g_free(service);
-
- g_hash_table_remove(service_table, (gconstpointer)sap);
- }
-}
-
-static void _llcp_remove_services(const char *id)
-{
- GHashTableIter iter;
- gpointer key;
- service_t *service;
-
- if (service_table == NULL)
- return;
-
- g_hash_table_iter_init (&iter, service_table);
-
- while (g_hash_table_iter_next (&iter, &key, (gpointer)&service)) {
- if (id == NULL || strcmp(service->id, id) == 0) {
- g_free(service->san);
- g_free(service->id);
- g_free(service);
-
- g_hash_table_iter_remove(&iter);
- }
- }
-}
-
-static void _llcp_start_services_cb(gpointer key, gpointer value,
- gpointer user_data)
-{
- service_t *service = (service_t *)value;
-
- /* TODO : start service */
- if (service != NULL && service->cb != NULL) {
- service->cb(NET_NFC_LLCP_START,
- (net_nfc_target_handle_s *)user_data,
- service->sap,
- service->san, service->user_data);
- }
-}
-
-static void _llcp_start_services(net_nfc_target_handle_s *handle)
-{
- g_hash_table_foreach(service_table, _llcp_start_services_cb, handle);
-}
-
-net_nfc_error_e net_nfc_server_llcp_register_service(const char *id,
- sap_t sap, const char *san, net_nfc_server_llcp_activate_cb cb,
- void *user_param)
-{
- return _llcp_add_service(id, sap, san, cb, user_param);
-}
-
-net_nfc_error_e net_nfc_server_llcp_unregister_service(const char *id,
- sap_t sap, const char *san)
-{
- net_nfc_error_e result;
- service_t *service;
-
- service = _llcp_find_service(sap);
- if (service != NULL) {
- /* invoke callback */
- service->cb(NET_NFC_LLCP_UNREGISTERED, NULL, service->sap,
- service->san, service->user_data);
-
- _llcp_remove_service(sap);
-
- result = NET_NFC_OK;
- } else {
- DEBUG_ERR_MSG("service is not registered");
-
- result = NET_NFC_NOT_REGISTERED;
- }
-
- return result;
-}
-
-net_nfc_error_e net_nfc_server_llcp_unregister_services(const char *id)
-{
- _llcp_remove_services(id);
-
- return NET_NFC_OK;
-}
-
-net_nfc_error_e net_nfc_server_llcp_unregister_all()
-{
- GHashTableIter iter;
- gpointer key;
- service_t *service;
-
- if (service_table == NULL)
- return NET_NFC_OK;
-
- g_hash_table_iter_init(&iter, service_table);
-
- while (g_hash_table_iter_next(&iter, &key, (gpointer)&service)) {
- service->cb(NET_NFC_LLCP_UNREGISTERED, NULL, service->sap,
- service->san, service->user_data);
-
- g_free(service->san);
- g_free(service->id);
- g_free(service);
-
- g_hash_table_iter_remove(&iter);
- }
-
- return NET_NFC_OK;
-}
-
-net_nfc_error_e net_nfc_server_llcp_start_registered_services(
- net_nfc_target_handle_s *handle)
-{
- _llcp_start_services(handle);
-
- return NET_NFC_OK;
-}
-
-static void net_nfc_server_llcp_process(gpointer user_data)
-{
- net_nfc_current_target_info_s *target;
-#if 0
- net_nfc_error_e result;
-#endif
- net_nfc_target_handle_s *handle;
- net_nfc_target_type_e dev_type;
-
- target = net_nfc_server_get_target_info();
-
- g_assert(target != NULL); /* raise exception!!! what;s wrong?? */
-
- handle = target->handle;
- dev_type = target->devType;
-
- DEBUG_SERVER_MSG("connection type = [%d]", handle->connection_type);
-#if 0
- if (dev_type == NET_NFC_NFCIP1_TARGET)
- {
- DEBUG_SERVER_MSG("LLCP : target, try to connect");
-
- if (net_nfc_controller_connect(handle, &result) == false)
- {
- DEBUG_SERVER_MSG("%s is failed, [%d]",
- "net_nfc_controller_connect",
- result);
-
- if (net_nfc_controller_configure_discovery(
- NET_NFC_DISCOVERY_MODE_RESUME,
- NET_NFC_ALL_ENABLE,
- &result) == false)
- {
- DEBUG_ERR_MSG("%s is failed [%d]",
- "net_nfc_controller_configure_discovery",
- result);
-
- net_nfc_controller_exception_handler();
- }
-
- return;
- }
- }
-
- DEBUG_SERVER_MSG("check LLCP");
-
- if (net_nfc_controller_llcp_check_llcp(handle, &result) == false)
- {
- DEBUG_ERR_MSG("%s is failed [%d]",
- "net_nfc_controller_llcp_check_llcp",
- result);
-
- return;
- }
-
- DEBUG_SERVER_MSG("activate LLCP");
-
- if (net_nfc_controller_llcp_activate_llcp(handle, &result) == false)
- {
- DEBUG_ERR_MSG("%s is failed [%d]",
- "net_nfc_controller_llcp_activate_llcp",
- result);
-
- return;
- }
-#endif
- net_nfc_server_llcp_start_registered_services(handle);
-
- net_nfc_server_p2p_discovered(handle);
-}
-
-void net_nfc_server_llcp_target_detected(void *info)
-{
- if (net_nfc_server_controller_async_queue_push(
- net_nfc_server_llcp_process, NULL) == FALSE)
- {
- DEBUG_ERR_MSG("can not push to controller thread");
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <vconf.h>
-
-#include "net_nfc_typedef.h"
-
-#include "net_nfc_gdbus.h"
-#include "net_nfc_server_common.h"
-#include "net_nfc_server_manager.h"
-#include "net_nfc_server_tag.h"
-
-#include "net_nfc_typedef_internal.h"
-#include "net_nfc_debug_internal.h"
-#include "net_nfc_controller_internal.h"
-#include "net_nfc_manager.h"
-#include "net_nfc_server_se.h"
-#include "net_nfc_server_llcp.h"
-#include "net_nfc_server_process_snep.h"
-#include "net_nfc_server_process_npp.h"
-#include "net_nfc_server_process_handover.h"
-#include "net_nfc_server_context_internal.h"
-
-typedef struct _ManagerData ManagerData;
-
-struct _ManagerData
-{
- NetNfcGDbusManager *manager;
- GDBusMethodInvocation *invocation;
-};
-
-typedef struct _ManagerActivationData ManagerActivationData;
-
-struct _ManagerActivationData
-{
- NetNfcGDbusManager *manager;
- GDBusMethodInvocation *invocation;
- gboolean is_active;
-};
-
-typedef struct _ManagerPrbsData ManagerPrbsData;
-
-struct _ManagerPrbsData
-{
- NetNfcGDbusManager *manager;
- GDBusMethodInvocation *invocation;
- guint32 tech;
- guint32 rate;
-};
-
-typedef struct _ServerManagerActivationData ServerManagerActivationData;
-
-struct _ServerManagerActivationData
-{
- NetNfcGDbusManager *manager;
- gboolean is_active;
-};
-
-
-static NetNfcGDbusManager *manager_skeleton = NULL;
-
-static gboolean manager_active(void);
-
-static gboolean manager_deactive(void);
-
-static void manager_handle_active_thread_func(gpointer user_data);
-
-static gboolean manager_handle_set_active(NetNfcGDbusManager *manager,
- GDBusMethodInvocation *invocation,
- gboolean arg_is_active,
- GVariant *smack_privilege,
- gpointer user_data);
-
-static gboolean manager_handle_get_server_state(NetNfcGDbusManager *manager,
- GDBusMethodInvocation *invocation,
- GVariant *smack_privilege,
- gpointer user_data);
-
-
-static void manager_active_thread_func(gpointer user_data);
-
-
-/* reimplementation of net_nfc_service_init()*/
-static gboolean manager_active(void)
-{
- net_nfc_error_e result;
-
- if (net_nfc_controller_is_ready(&result) == false)
- {
- DEBUG_ERR_MSG("%s failed [%d]",
- "net_nfc_cotroller_is_ready", result);
- return FALSE;
- }
-
- result = net_nfc_server_se_change_se(SECURE_ELEMENT_TYPE_UICC);
-
- /* register default snep server */
- net_nfc_server_snep_default_server_register();
-
- /* register default npp server */
- net_nfc_server_npp_default_server_register();
-
- /* register default handover server */
- net_nfc_server_handover_default_server_register();
-
- if (net_nfc_controller_configure_discovery(
- NET_NFC_DISCOVERY_MODE_START,
- NET_NFC_ALL_ENABLE,
- &result) == false)
- {
- DEBUG_ERR_MSG("%s is failed %d",
- "net_nfc_controller_configure_discovery",
- result);
- return FALSE;
- }
-
- /* vconf on */
- if (vconf_set_bool(VCONFKEY_NFC_STATE, TRUE) != 0)
- {
- DEBUG_ERR_MSG("%s is failed", "vconf_set_bool");
- return FALSE;
- }
-
- return TRUE;
-}
-
-/* reimplementation of net_nfc_service_deinit()*/
-static gboolean manager_deactive(void)
-{
- net_nfc_error_e result;
-
- if (net_nfc_controller_is_ready(&result) == false)
- {
- DEBUG_ERR_MSG("%s failed [%d]",
- "net_nfc_cotroller_is_ready", result);
- return FALSE;
- }
-
- /* unregister all services */
- net_nfc_server_llcp_unregister_all();
-
- result = net_nfc_server_se_change_se(SECURE_ELEMENT_TYPE_INVALID);
-
- if (net_nfc_controller_configure_discovery(
- NET_NFC_DISCOVERY_MODE_STOP,
- NET_NFC_ALL_DISABLE,
- &result) == false)
- {
- DEBUG_ERR_MSG("%s is failed %d",
- "net_nfc_controller_configure_discovery",
- result);
- return FALSE;
- }
-
- /* vconf off */
- if (vconf_set_bool(VCONFKEY_NFC_STATE, FALSE) != 0)
- {
- DEBUG_ERR_MSG("%s is failed", "vconf_set_bool");
- return FALSE;
- }
-
- return TRUE;
-}
-
-static void manager_handle_active_thread_func(gpointer user_data)
-{
- gboolean ret;
-
- ManagerActivationData *data;
-
- data = (ManagerActivationData *)user_data;
-
- if (data == NULL)
- {
- DEBUG_ERR_MSG("can not get ManagerActivationData");
- return;
- }
-
- if (data->is_active)
- ret = manager_active();
- else
- ret = manager_deactive();
-
- if (data->manager == NULL)
- {
- DEBUG_ERR_MSG("can not get manager");
-
- if(data->invocation)
- {
- g_dbus_method_invocation_return_dbus_error(
- data->invocation,
- "org.tizen.NetNfcService.SetActiveError",
- "Can not get manager");
-
- g_object_unref(data->invocation);
- }
-
- g_free(data);
- return;
- }
-
- if (ret == FALSE)
- {
- if (data->invocation)
- {
- g_dbus_method_invocation_return_dbus_error(
- data->invocation,
- "org.tizen.NetNfcService.SetActiveError",
- "Can not set activation");
-
- g_object_unref(data->invocation);
- }
-
- g_object_unref(data->manager);
- g_free(data);
-
- return;
- }
-
- net_nfc_gdbus_manager_emit_activated(data->manager,
- data->is_active);
-
- if (data->invocation)
- {
- net_nfc_gdbus_manager_complete_set_active(data->manager,
- data->invocation);
-
- g_object_unref(data->invocation);
- }
-
- g_object_unref(data->manager);
- g_free(data);
-
- /* shutdown process if it doesn't need */
- if (data->is_active == false &&
- net_nfc_server_gdbus_is_server_busy() == false) {
-
- net_nfc_manager_quit();
- }
-}
-
-
-static gboolean manager_handle_set_active(NetNfcGDbusManager *manager,
- GDBusMethodInvocation *invocation,
- gboolean arg_is_active,
- GVariant *smack_privilege,
- gpointer user_data)
-{
- ManagerActivationData *data;
-
- INFO_MSG(">>> REQUEST from [%s]",
- g_dbus_method_invocation_get_sender(invocation));
-
- /* check privilege and update client context */
- if (net_nfc_server_gdbus_check_privilege(invocation,
- smack_privilege,
- "nfc-manager::admin",
- "rw") == false) {
- DEBUG_ERR_MSG("permission denied, and finished request");
-
- return TRUE;
- }
-
- DEBUG_SERVER_MSG("is_active %d", arg_is_active);
-
- data = g_new0(ManagerActivationData, 1);
- if(data == NULL)
- {
- DEBUG_ERR_MSG("Memory allocation failed");
- g_dbus_method_invocation_return_dbus_error(invocation,
- "org.tizen.NetNfcService.AllocationError",
- "Can not allocate memory");
- return FALSE;
- }
-
- data->manager = g_object_ref(manager);
- data->invocation = g_object_ref(invocation);
- data->is_active = arg_is_active;
-
- if (net_nfc_server_controller_async_queue_push(
- manager_handle_active_thread_func,
- data) == FALSE)
- {
- g_dbus_method_invocation_return_dbus_error(invocation,
- "org.tizen.NetNfcService.ThreadError",
- "can not push to controller thread");
- if (data)
- {
- g_object_unref(data->manager);
- g_object_unref(data->invocation);
-
- g_free(data);
- }
- return FALSE;
- }
-
- if (arg_is_active)
- net_nfc_server_restart_polling_loop();
-
- return TRUE;
-}
-
-static gboolean manager_handle_get_server_state(NetNfcGDbusManager *manager,
- GDBusMethodInvocation *invocation,
- GVariant *smack_privilege,
- gpointer user_data)
-{
- guint32 state;
-
- INFO_MSG(">>> REQUEST from [%s]",
- g_dbus_method_invocation_get_sender(invocation));
-
- /* check privilege and update client context */
- if (net_nfc_server_gdbus_check_privilege(invocation,
- smack_privilege,
- "nfc-manager::admin",
- "r") == false) {
- DEBUG_ERR_MSG("permission denied, and finished request");
-
- return TRUE;
- }
-
- state = net_nfc_server_get_state();
-
- net_nfc_gdbus_manager_complete_get_server_state(manager,
- invocation,
- state);
- return TRUE;
-}
-
-/* server side */
-static void manager_active_thread_func(gpointer user_data)
-{
- ServerManagerActivationData *data;
-
- gboolean ret = FALSE;
-
- data = (ServerManagerActivationData *)user_data;
-
- if (data == NULL)
- {
- DEBUG_ERR_MSG("can not get ServerManagerActivationData");
- return;
- }
-
- if (data->is_active)
- ret = manager_active();
- else
- ret = manager_deactive();
-
- if (ret == FALSE)
- {
- DEBUG_ERR_MSG("can not set activation");
- g_free(data);
- return;
- }
-
- net_nfc_gdbus_manager_emit_activated(data->manager,
- data->is_active);
-
- g_free(data);
-}
-
-gboolean net_nfc_server_manager_init(GDBusConnection *connection)
-{
- GError *error = NULL;
-
- if (manager_skeleton)
- g_object_unref(manager_skeleton);
-
- manager_skeleton = net_nfc_gdbus_manager_skeleton_new();
-
- g_signal_connect(manager_skeleton,
- "handle-set-active",
- G_CALLBACK(manager_handle_set_active),
- NULL);
-
- g_signal_connect(manager_skeleton,
- "handle-get-server-state",
- G_CALLBACK(manager_handle_get_server_state),
- NULL);
-
- if (g_dbus_interface_skeleton_export(
- G_DBUS_INTERFACE_SKELETON(manager_skeleton),
- connection,
- "/org/tizen/NetNfcService/Manager",
- &error) == FALSE)
- {
- DEBUG_ERR_MSG("Can not skeleton_export %s", error->message);
-
- g_error_free(error);
- g_object_unref(manager_skeleton);
-
- manager_skeleton = NULL;
-
- return FALSE;
- }
-
- return TRUE;
-}
-
-void net_nfc_server_manager_deinit(void)
-{
- if (manager_skeleton)
- {
- g_object_unref(manager_skeleton);
- manager_skeleton = NULL;
- }
-}
-
-void net_nfc_server_manager_set_active(gboolean is_active)
-{
- ServerManagerActivationData *data;
-
- if (manager_skeleton == NULL)
- {
- DEBUG_ERR_MSG("%s is not initialized",
- "net_nfc_server_manager");
- return;
- }
-
- DEBUG_SERVER_MSG("is_active %d", is_active);
-
- data = g_new0(ServerManagerActivationData, 1);
-
- if(data == NULL)
- {
- DEBUG_ERR_MSG("Memory allocation failed");
- return;
- }
-
- data->manager = g_object_ref(manager_skeleton);
- data->is_active = is_active;
-
- if (net_nfc_server_controller_async_queue_push(
- manager_active_thread_func,
- data) == FALSE)
- {
- DEBUG_ERR_MSG("can not push to controller thread");
-
- if (data)
- {
- g_object_unref(data->manager);
-
- g_free(data);
- }
- }
-
- if (is_active)
- net_nfc_server_restart_polling_loop();
-
- return;
-}
-
-bool net_nfc_server_manager_get_active()
-{
- int value;
-
- if (vconf_get_bool(VCONFKEY_NFC_STATE, &value) < 0)
- return false;
-
- return (!!value);
-}
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "net_nfc_typedef_internal.h"
-#include "net_nfc_debug_internal.h"
-#include "net_nfc_util_internal.h"
-#include "net_nfc_util_gdbus_internal.h"
-#include "net_nfc_controller_internal.h"
-#include "net_nfc_gdbus.h"
-
-#include "net_nfc_server_common.h"
-#include "net_nfc_server_context_internal.h"
-#include "net_nfc_server_tag.h"
-#include "net_nfc_server_ndef.h"
-
-typedef struct _ReadData ReadData;
-
-struct _ReadData
-{
- NetNfcGDbusNdef *ndef;
- GDBusMethodInvocation *invocation;
- guint32 handle;
-};
-
-typedef struct _WriteData WriteData;
-
-struct _WriteData
-{
- NetNfcGDbusNdef *ndef;
- GDBusMethodInvocation *invocation;
- guint32 handle;
- data_s data;
-};
-
-typedef struct _MakeReadOnlyData MakeReadOnlyData;
-
-struct _MakeReadOnlyData
-{
- NetNfcGDbusNdef *ndef;
- GDBusMethodInvocation *invocation;
- guint32 handle;
-};
-
-typedef struct _FormatData FormatData;
-
-struct _FormatData
-{
- NetNfcGDbusNdef *ndef;
- GDBusMethodInvocation *invocation;
- guint32 handle;
- data_s key;
-};
-
-
-static NetNfcGDbusNdef *ndef_skeleton = NULL;
-
-static void ndef_read_thread_func(gpointer user_data);
-
-static void ndef_write_thread_func(gpointer user_data);
-
-static void ndef_make_read_only_thread_func(gpointer user_data);
-
-static void ndef_format_thread_func(gpointer user_data);
-
-/* methods */
-static gboolean ndef_handle_read(NetNfcGDbusNdef *ndef,
- GDBusMethodInvocation *invocation,
- guint32 arg_handle,
- GVariant *smack_privilege,
- gpointer user_data);
-
-static gboolean ndef_handle_write(NetNfcGDbusNdef *ndef,
- GDBusMethodInvocation *invocation,
- guint32 arg_handle,
- GVariant *arg_data,
- GVariant *smack_privilege,
- gpointer user_data);
-
-static gboolean ndef_handle_make_read_only(NetNfcGDbusNdef *ndef,
- GDBusMethodInvocation *invocation,
- guint32 arg_handle,
- GVariant *smack_privilege,
- gpointer user_data);
-
-static gboolean ndef_handle_format(NetNfcGDbusNdef *ndef,
- GDBusMethodInvocation *invocation,
- guint32 arg_handle,
- GVariant *arg_key,
- GVariant *smack_privilege,
- gpointer user_data);
-
-
-static void ndef_read_thread_func(gpointer user_data)
-{
- ReadData *data = user_data;
-
- net_nfc_target_handle_s *handle;
- net_nfc_error_e result;
- data_s *read_data = NULL;
- GVariant *data_variant;
-
- g_assert(data != NULL);
- g_assert(data->ndef != NULL);
- g_assert(data->invocation != NULL);
-
- handle = GUINT_TO_POINTER(data->handle);
-
- if (net_nfc_server_target_connected(handle) == true) {
- net_nfc_controller_read_ndef(handle, &read_data, &result);
- } else {
- result = NET_NFC_TARGET_IS_MOVED_AWAY;
- }
-
- data_variant = net_nfc_util_gdbus_data_to_variant(read_data);
-
- net_nfc_gdbus_ndef_complete_read(data->ndef,
- data->invocation,
- (gint)result,
- data_variant);
-
- if (read_data) {
- net_nfc_util_free_data(read_data);
- g_free(read_data);
- }
-
- g_object_unref(data->invocation);
- g_object_unref(data->ndef);
-
- g_free(data);
-}
-
-static void ndef_write_thread_func(gpointer user_data)
-{
- WriteData *data = user_data;
-
- net_nfc_target_handle_s *handle;
- net_nfc_error_e result;
-
- g_assert(data != NULL);
- g_assert(data->ndef != NULL);
- g_assert(data->invocation != NULL);
-
- handle = GUINT_TO_POINTER(data->handle);
-
- if (net_nfc_server_target_connected(handle) == true) {
- net_nfc_controller_write_ndef(handle, &data->data, &result);
- } else {
- result = NET_NFC_TARGET_IS_MOVED_AWAY;
- }
-
- net_nfc_gdbus_ndef_complete_write(data->ndef,
- data->invocation,
- (gint)result);
-
- net_nfc_util_free_data(&data->data);
-
- g_object_unref(data->invocation);
- g_object_unref(data->ndef);
-
- g_free(data);
-}
-
-static void ndef_make_read_only_thread_func(gpointer user_data)
-{
- MakeReadOnlyData *data = user_data;
-
- net_nfc_target_handle_s *handle;
- net_nfc_error_e result;
-
- g_assert(data != NULL);
- g_assert(data->ndef != NULL);
- g_assert(data->invocation != NULL);
-
- handle = GUINT_TO_POINTER(data->handle);
-
- if (net_nfc_server_target_connected(handle) == true) {
- net_nfc_controller_make_read_only_ndef(handle, &result);
- } else {
- result = NET_NFC_TARGET_IS_MOVED_AWAY;
- }
-
- net_nfc_gdbus_ndef_complete_make_read_only(data->ndef,
- data->invocation,
- (gint)result);
-
- g_object_unref(data->invocation);
- g_object_unref(data->ndef);
-
- g_free(data);
-}
-
-static void ndef_format_thread_func(gpointer user_data)
-{
- FormatData *data = user_data;
-
- net_nfc_target_handle_s *handle;
- net_nfc_error_e result;
-
- g_assert(data != NULL);
- g_assert(data->ndef != NULL);
- g_assert(data->invocation != NULL);
-
- handle = GUINT_TO_POINTER(data->handle);
-
- if (net_nfc_server_target_connected(handle) == true) {
- net_nfc_controller_format_ndef(handle, &data->key, &result);
- } else {
- result = NET_NFC_TARGET_IS_MOVED_AWAY;
- }
-
- net_nfc_gdbus_ndef_complete_format(data->ndef,
- data->invocation,
- (gint)result);
-
- net_nfc_util_free_data(&data->key);
-
- g_object_unref(data->invocation);
- g_object_unref(data->ndef);
-
- g_free(data);
-}
-
-static gboolean ndef_handle_read(NetNfcGDbusNdef *ndef,
- GDBusMethodInvocation *invocation,
- guint32 arg_handle,
- GVariant *smack_privilege,
- gpointer user_data)
-{
- ReadData *data;
- gboolean result;
-
- INFO_MSG(">>> REQUEST from [%s]",
- g_dbus_method_invocation_get_sender(invocation));
-
- /* check privilege and update client context */
- if (net_nfc_server_gdbus_check_privilege(invocation,
- smack_privilege,
- "nfc-manager::tag",
- "r") == false) {
- DEBUG_ERR_MSG("permission denied, and finished request");
-
- return FALSE;
- }
-
- data = g_new0(ReadData, 1);
- if (data == NULL)
- {
- DEBUG_ERR_MSG("Memory allocation failed");
- g_dbus_method_invocation_return_dbus_error(invocation,
- "org.tizen.NetNfcService.AllocationError",
- "Can not allocate memory");
-
- return FALSE;
- }
-
- data->ndef = g_object_ref(ndef);
- data->invocation = g_object_ref(invocation);
- data->handle = arg_handle;
-
- result = net_nfc_server_controller_async_queue_push(
- ndef_read_thread_func,
- data);
- if (result == FALSE)
- {
- g_dbus_method_invocation_return_dbus_error(invocation,
- "org.tizen.NetNfcService.Ndef.ThreadError",
- "can not push to controller thread");
-
- g_object_unref(data->invocation);
- g_object_unref(data->ndef);
-
- g_free(data);
- }
-
- return result;
-}
-
-static gboolean ndef_handle_write(NetNfcGDbusNdef *ndef,
- GDBusMethodInvocation *invocation,
- guint32 arg_handle,
- GVariant *arg_data,
- GVariant *smack_privilege,
- gpointer user_data)
-{
- WriteData *data;
- gboolean result;
-
- INFO_MSG(">>> REQUEST from [%s]",
- g_dbus_method_invocation_get_sender(invocation));
-
- /* check privilege and update client context */
- if (net_nfc_server_gdbus_check_privilege(invocation,
- smack_privilege,
- "nfc-manager::tag",
- "w") == false) {
- DEBUG_ERR_MSG("permission denied, and finished request");
-
- return FALSE;
- }
-
- data = g_new0(WriteData, 1);
- if (data == NULL)
- {
- DEBUG_ERR_MSG("Memory allocation failed");
- g_dbus_method_invocation_return_dbus_error(invocation,
- "org.tizen.NetNfcService.AllocationError",
- "Can not allocate memory");
-
- return FALSE;
- }
-
- data->ndef = g_object_ref(ndef);
- data->invocation = g_object_ref(invocation);
- data->handle = arg_handle;
-
- net_nfc_util_gdbus_variant_to_data_s(arg_data, &data->data);
-
- result = net_nfc_server_controller_async_queue_push(
- ndef_write_thread_func,
- data);
- if (result == FALSE)
- {
- g_dbus_method_invocation_return_dbus_error(invocation,
- "org.tizen.NetNfcService.Ndef.ThreadError",
- "can not push to controller thread");
-
- net_nfc_util_free_data(&data->data);
-
- g_object_unref(data->invocation);
- g_object_unref(data->ndef);
-
- g_free(data);
- }
-
- return result;
-}
-
-static gboolean ndef_handle_make_read_only(NetNfcGDbusNdef *ndef,
- GDBusMethodInvocation *invocation,
- guint32 arg_handle,
- GVariant *smack_privilege,
- gpointer user_data)
-{
- MakeReadOnlyData *data;
- gboolean result;
-
- INFO_MSG(">>> REQUEST from [%s]",
- g_dbus_method_invocation_get_sender(invocation));
-
- /* check privilege and update client context */
- if (net_nfc_server_gdbus_check_privilege(invocation,
- smack_privilege,
- "nfc-manager::tag",
- "w") == false) {
- DEBUG_ERR_MSG("permission denied, and finished request");
-
- return FALSE;
- }
-
- data = g_new0(MakeReadOnlyData, 1);
- if (data == NULL)
- {
- DEBUG_ERR_MSG("Memory allocation failed");
- g_dbus_method_invocation_return_dbus_error(invocation,
- "org.tizen.NetNfcService.AllocationError",
- "Can not allocate memory");
-
- return FALSE;
- }
-
- data->ndef = g_object_ref(ndef);
- data->invocation = g_object_ref(invocation);
- data->handle = arg_handle;
-
- result = net_nfc_server_controller_async_queue_push(
- ndef_make_read_only_thread_func,
- data);
- if (result == FALSE)
- {
- g_dbus_method_invocation_return_dbus_error(invocation,
- "org.tizen.NetNfcService.Ndef.ThreadError",
- "can not push to controller thread");
-
- g_object_unref(data->invocation);
- g_object_unref(data->ndef);
-
- g_free(data);
- }
-
- return result;
-}
-
-static gboolean ndef_handle_format(NetNfcGDbusNdef *ndef,
- GDBusMethodInvocation *invocation,
- guint32 arg_handle,
- GVariant *arg_key,
- GVariant *smack_privilege,
- gpointer user_data)
-{
- FormatData *data;
- gboolean result;
-
- INFO_MSG(">>> REQUEST from [%s]",
- g_dbus_method_invocation_get_sender(invocation));
-
- /* check privilege and update client context */
- if (net_nfc_server_gdbus_check_privilege(invocation,
- smack_privilege,
- "nfc-manager::tag",
- "w") == false) {
- DEBUG_ERR_MSG("permission denied, and finished request");
-
- return FALSE;
- }
-
- data = g_new0(FormatData, 1);
- if (data == NULL)
- {
- DEBUG_ERR_MSG("Memory allocation failed");
- g_dbus_method_invocation_return_dbus_error(invocation,
- "org.tizen.NetNfcService.AllocationError",
- "Can not allocate memory");
-
- return FALSE;
- }
-
- data->ndef = g_object_ref(ndef);
- data->invocation = g_object_ref(invocation);
- data->handle = arg_handle;
- net_nfc_util_gdbus_variant_to_data_s(arg_key, &data->key);
-
- result = net_nfc_server_controller_async_queue_push(
- ndef_format_thread_func,
- data);
- if (result == FALSE)
- {
- g_dbus_method_invocation_return_dbus_error(invocation,
- "org.tizen.NetNfcService.Ndef.ThreadError",
- "can not push to controller thread");
-
- net_nfc_util_free_data(&data->key);
-
- g_object_unref(data->invocation);
- g_object_unref(data->ndef);
-
- g_free(data);
- }
-
- return result;
-}
-
-gboolean net_nfc_server_ndef_init(GDBusConnection *connection)
-{
- gboolean result;
- GError *error = NULL;
-
- if (ndef_skeleton)
- net_nfc_server_ndef_deinit();
-
- ndef_skeleton = net_nfc_gdbus_ndef_skeleton_new();
-
- g_signal_connect(ndef_skeleton,
- "handle-read",
- G_CALLBACK(ndef_handle_read),
- NULL);
-
- g_signal_connect(ndef_skeleton,
- "handle-write",
- G_CALLBACK(ndef_handle_write),
- NULL);
-
- g_signal_connect(ndef_skeleton,
- "handle-make-read-only",
- G_CALLBACK(ndef_handle_make_read_only),
- NULL);
-
- g_signal_connect(ndef_skeleton,
- "handle-format",
- G_CALLBACK(ndef_handle_format),
- NULL);
-
- result = g_dbus_interface_skeleton_export(
- G_DBUS_INTERFACE_SKELETON(ndef_skeleton),
- connection,
- "/org/tizen/NetNfcService/Ndef",
- &error);
- if (result == FALSE)
- {
- g_error_free(error);
-
- net_nfc_server_ndef_deinit();
- }
-
- return TRUE;
-}
-
-void net_nfc_server_ndef_deinit(void)
-{
- if (ndef_skeleton)
- {
- g_object_unref(ndef_skeleton);
- ndef_skeleton = NULL;
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "net_nfc_debug_internal.h"
-#include "net_nfc_util_internal.h"
-#include "net_nfc_util_gdbus_internal.h"
-#include "net_nfc_controller_internal.h"
-#include "net_nfc_gdbus.h"
-#include "net_nfc_server_common.h"
-#include "net_nfc_server_context_internal.h"
-#include "net_nfc_server_process_snep.h"
-#include "net_nfc_server_p2p.h"
-
-
-typedef struct _P2pSendData P2pSendData;
-
-struct _P2pSendData
-{
- NetNfcGDbusP2p *p2p;
- GDBusMethodInvocation *invocation;
- gint32 type;
- guint32 p2p_handle;
- data_s data;
-};
-
-static void p2p_send_data_thread_func(gpointer user_data);
-
-static gboolean p2p_handle_send(NetNfcGDbusP2p *p2p,
- GDBusMethodInvocation *invocation,
- gint32 arg_type,
- GVariant *arg_data,
- guint32 handle,
- GVariant *smack_privilege,
- gpointer user_data);
-
-static NetNfcGDbusP2p *p2p_skeleton = NULL;
-
-static void p2p_send_data_thread_func(gpointer user_data)
-{
- P2pSendData *p2p_data = (P2pSendData *)user_data;
- net_nfc_error_e result;
- net_nfc_target_handle_s *handle;
-
- g_assert(p2p_data != NULL);
- g_assert(p2p_data->p2p != NULL);
- g_assert(p2p_data->invocation != NULL);
-
- handle = GUINT_TO_POINTER(p2p_data->p2p_handle);
-
- result = net_nfc_server_snep_default_client_start(
- GUINT_TO_POINTER(p2p_data->p2p_handle),
- SNEP_REQ_PUT,
- &p2p_data->data,
- -1,
- p2p_data);
- if (result != NET_NFC_OK)
- {
- net_nfc_gdbus_p2p_complete_send(p2p_data->p2p,
- p2p_data->invocation,
- (gint)result);
-
- net_nfc_util_free_data(&p2p_data->data);
-
- g_object_unref(p2p_data->invocation);
- g_object_unref(p2p_data->p2p);
-
- g_free(p2p_data);
- }
-}
-
-static gboolean p2p_handle_send(NetNfcGDbusP2p *p2p,
- GDBusMethodInvocation *invocation,
- gint32 arg_type,
- GVariant *arg_data,
- guint32 handle,
- GVariant *smack_privilege,
- gpointer user_data)
-{
- gboolean result;
- P2pSendData *data;
-
- INFO_MSG(">>> REQUEST from [%s]",
- g_dbus_method_invocation_get_sender(invocation));
-
- /* check privilege and update client context */
- if (net_nfc_server_gdbus_check_privilege(invocation,
- smack_privilege,
- "nfc-manager::p2p",
- "w") == false) {
- DEBUG_ERR_MSG("permission denied, and finished request");
-
- return FALSE;
- }
-
- data = g_new0(P2pSendData, 1);
- if(data == NULL)
- {
- DEBUG_ERR_MSG("Memory allocation failed");
- g_dbus_method_invocation_return_dbus_error(invocation,
- "org.tizen.NetNfcService.AllocationError",
- "Can not allocate memory");
-
- return FALSE;
- }
-
- data->p2p = g_object_ref(p2p);
- data->invocation = g_object_ref(invocation);
- data->type = arg_type;
- data->p2p_handle = handle;
- net_nfc_util_gdbus_variant_to_data_s(arg_data, &data->data);
-
- result = net_nfc_server_controller_async_queue_push(
- p2p_send_data_thread_func, data);
- if (result == FALSE)
- {
- g_dbus_method_invocation_return_dbus_error(invocation,
- "org.tizen.NetNfcService.P2p.ThreadError",
- "can not push to controller thread");
-
- net_nfc_util_free_data(&data->data);
-
- g_object_unref(data->invocation);
- g_object_unref(data->p2p);
-
- g_free(data);
- }
-
- return result;
-}
-
-
-gboolean net_nfc_server_p2p_init(GDBusConnection *connection)
-{
- gboolean result;
- GError *error = NULL;
-
- if (p2p_skeleton)
- net_nfc_server_p2p_deinit();
-
- p2p_skeleton = net_nfc_gdbus_p2p_skeleton_new();
-
- g_signal_connect(p2p_skeleton,
- "handle-send",
- G_CALLBACK(p2p_handle_send),
- NULL);
-
- result = g_dbus_interface_skeleton_export(
- G_DBUS_INTERFACE_SKELETON(p2p_skeleton),
- connection,
- "/org/tizen/NetNfcService/P2p",
- &error);
- if (result == FALSE)
- {
- g_error_free(error);
-
- net_nfc_server_p2p_deinit();
- }
-
- return result;
-}
-
-void net_nfc_server_p2p_deinit(void)
-{
- if (p2p_skeleton)
- {
- g_object_unref(p2p_skeleton);
- p2p_skeleton = NULL;
- }
-}
-
-void net_nfc_server_p2p_detached(void)
-{
- if (p2p_skeleton == NULL)
- {
- DEBUG_ERR_MSG("p2p_skeleton is not initialized");
-
- return;
- }
-
- DEBUG_ERR_MSG("p2p detached signal");
-
- net_nfc_gdbus_p2p_emit_detached(p2p_skeleton);
-}
-
-void net_nfc_server_p2p_discovered(net_nfc_target_handle_h handle)
-{
- if (p2p_skeleton == NULL)
- {
- DEBUG_ERR_MSG("p2p_skeleton is not initialized");
-
- return;
- }
-
- DEBUG_ERR_MSG("Emitting p2p discovered signal");
-
- net_nfc_gdbus_p2p_emit_discovered(p2p_skeleton,
- GPOINTER_TO_UINT(handle));
-}
-
-void net_nfc_server_p2p_received(data_h user_data)
-{
- GVariant *arg_data;
-
- if (p2p_skeleton == NULL)
- {
- DEBUG_ERR_MSG("p2p_skeleton is not initialized");
-
- return;
- }
-
- arg_data = net_nfc_util_gdbus_data_to_variant((data_s *)user_data);
-
- net_nfc_gdbus_p2p_emit_received(p2p_skeleton, arg_data);
-}
-
-void net_nfc_server_p2p_data_sent(net_nfc_error_e result,
- gpointer user_data)
-{
- P2pSendData *data = (P2pSendData *)user_data;
-
- g_assert(data != NULL);
- g_assert(data->p2p != NULL);
- g_assert(data->invocation != NULL);
-
- net_nfc_gdbus_p2p_complete_send(data->p2p,
- data->invocation,
- (gint)result);
-
- net_nfc_util_free_data(&data->data);
-
- g_object_unref(data->invocation);
- g_object_unref(data->p2p);
-
- g_free(data);
-}
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "bluetooth-api.h"
-#include "net_nfc_server_handover.h"
-#include "net_nfc_debug_internal.h"
-#include "net_nfc_util_internal.h"
-#include "net_nfc_util_ndef_message.h"
-#include "net_nfc_util_ndef_record.h"
-#include "net_nfc_util_handover.h"
-#include "net_nfc_manager_util_internal.h"
-#include "net_nfc_controller_internal.h"
-#include "net_nfc_server_llcp.h"
-#include "net_nfc_server_handover_internal.h"
-#include "net_nfc_server_process_snep.h"
-#include "net_nfc_util_gdbus_internal.h"
-#include "net_nfc_server_handover_bss.h"
-
-typedef void (*_net_nfc_server_handover_create_carrier_msg_cb)(
- net_nfc_error_e result,
- ndef_message_s *selector,
- void *user_param);
-
-typedef struct _net_nfc_handover_context_t
-{
- net_nfc_target_handle_s *handle;
- net_nfc_error_e result;
- net_nfc_llcp_socket_t socket;
- uint32_t state;
- net_nfc_conn_handover_carrier_type_e type;
- data_s data;
- ndef_record_s *record;
- void *user_param;
-}
-net_nfc_handover_context_t;
-
-#define NET_NFC_CH_CONTEXT net_nfc_target_handle_s *handle;\
- net_nfc_llcp_socket_t socket;\
- net_nfc_error_e result;\
- int step;\
- net_nfc_conn_handover_carrier_type_e type;\
- void *user_param;
-
-typedef struct _net_nfc_server_handover_create_config_context_t
-{
- NET_NFC_CH_CONTEXT;
-
- _net_nfc_server_handover_create_carrier_msg_cb cb;
- net_nfc_conn_handover_carrier_type_e current_type;
- ndef_message_s *ndef_message;
- ndef_message_s *requester; /* for low power selector */
-
- ndef_record_s *record;
-}
-net_nfc_server_handover_create_config_context_t;
-
-typedef struct _net_nfc_server_handover_process_config_context_t
-{
- NET_NFC_CH_CONTEXT;
-
- net_nfc_server_handover_process_carrier_record_cb cb;
-}
-net_nfc_server_handover_process_config_context_t;
-
-
-
-static void _net_nfc_server_handover_send_response(void *user_param,
- data_h ac_data,
- net_nfc_error_e result);
-
-static void _net_nfc_server_handover_client_process(
- net_nfc_handover_context_t *context);
-
-static void _net_nfc_server_handover_client_error_cb(
- net_nfc_error_e result,
- net_nfc_target_handle_s *handle,
- net_nfc_llcp_socket_t socket,
- data_s *data,
- void *user_param);
-
-static void _net_nfc_server_handover_client_connected_cb(
- net_nfc_error_e result,
- net_nfc_target_handle_s *handle,
- net_nfc_llcp_socket_t socket,
- data_s *data,
- void *user_param);
-
-static void _net_nfc_server_handover_get_response_process(
- net_nfc_handover_context_t *context);
-
-static int _net_nfc_server_handover_append_wifi_carrier_config(
- net_nfc_server_handover_create_config_context_t *context);
-
-static net_nfc_error_e
-_net_nfc_server_handover_create_requester_from_rawdata(
- ndef_message_s **requestor,
- data_s *data);
-
-static net_nfc_error_e
-_net_nfc_server_handover_create_requester_carrier_configs(
- net_nfc_conn_handover_carrier_type_e type,
- void *cb,
- void *user_param);
-
-static bool _net_nfc_server_handover_check_hr_record_validation(
- ndef_message_s *message);
-
-static bool _net_nfc_server_handover_check_hs_record_validation(
- ndef_message_s *message);
-
-static net_nfc_error_e
-_net_nfc_server_handover_create_selector_carrier_configs(
- net_nfc_conn_handover_carrier_type_e type,
- void *cb,
- void *user_param);
-
-static int _net_nfc_server_handover_iterate_create_carrier_configs(
- net_nfc_server_handover_create_config_context_t *context);
-
-static int _net_nfc_server_handover_iterate_carrier_configs_to_next(
- net_nfc_server_handover_create_config_context_t *context);
-
-static int _net_nfc_server_handover_iterate_carrier_configs_step(
- net_nfc_server_handover_create_config_context_t *context);
-
-static void _net_nfc_server_handover_server_process(
- net_nfc_handover_context_t *context);
-
-static net_nfc_error_e
-_net_nfc_server_handover_create_low_power_selector_message(
- ndef_message_s *request_msg,
- ndef_message_s *select_msg);
-
-////////////////////////////////////////////////////////////////////////////
-
-static void _net_nfc_server_handover_send_response(
- void *user_param,
- data_h ac_data,
- net_nfc_error_e result)
-{
- HandoverRequestData *handover_data = NULL;
- guint32 resp_event;
- guint32 resp_type;
- GVariant* data = NULL;
-
- handover_data = (HandoverRequestData*)user_param;
-
- data = net_nfc_util_gdbus_data_to_variant(ac_data);
-
- resp_type = NET_NFC_MESSAGE_CONNECTION_HANDOVER;
-
- if (result == NET_NFC_OK)
- resp_event = NET_NFC_EXCHANGER_TRANSFER_COMPLETED;
- else
- resp_event = NET_NFC_EXCHANGER_TRANSFER_FAILED;
-
- if (handover_data->invocation)
- {
- net_nfc_gdbus_handover_complete_request(
- handover_data->handoverobj,
- handover_data->invocation,
- resp_event,
- resp_type,
- data);
-
- g_object_unref(handover_data->invocation);
- }
-
- if (handover_data->data)
- {
- g_free(handover_data->data->buffer);
- g_free(handover_data->data);
- }
-
- g_object_unref(handover_data->handoverobj);
- g_free(handover_data);
-
-}
-
-static net_nfc_error_e _net_nfc_server_handover_convert_ndef_message_to_data(
- ndef_message_s *msg,
- data_s *data)
-{
- net_nfc_error_e result;
- uint32_t length;
-
- if (msg == NULL || data == NULL)
- {
- return NET_NFC_INVALID_PARAM;
- }
-
- length = net_nfc_util_get_ndef_message_length(msg);
- if (length > 0)
- {
- net_nfc_util_alloc_data(data, length);
- result = net_nfc_util_convert_ndef_message_to_rawdata(msg, data);
- }
- else
- {
- result = NET_NFC_INVALID_PARAM;
- }
-
- return result;
-}
-
-static void _net_nfc_server_handover_bt_get_carrier_record_cb(
- net_nfc_error_e result,
- net_nfc_conn_handover_carrier_state_e cps,
- ndef_record_s *carrier,
- uint32_t aux_data_count,
- ndef_record_s *aux_data,
- void *user_param)
-{
- net_nfc_server_handover_create_config_context_t *context =
- (net_nfc_server_handover_create_config_context_t *)user_param;
-
- /* append record to ndef message */
- if (result == NET_NFC_OK)
- {
- ndef_record_s *record;
-
- /* FIXME : copy record and append */
- net_nfc_util_create_record(carrier->TNF,
- &carrier->type_s,
- &carrier->id_s,
- &carrier->payload_s,
- &record);
-
- if ((result = net_nfc_util_append_carrier_config_record(
- context->ndef_message,
- record,
- cps)) == NET_NFC_OK)
- {
- DEBUG_SERVER_MSG("net_nfc_util_append_carrier"
- "_config_record success");
- }
- else
- {
- DEBUG_ERR_MSG("net_nfc_util_append_carrier"
- "_config_record failed [%d]",
- result);
- net_nfc_util_free_record(record);
- }
-
- g_idle_add(
- (GSourceFunc)_net_nfc_server_handover_iterate_carrier_configs_to_next,
- (gpointer)context);
- }
-
- /* don't free context */
-}
-
-static void _net_nfc_server_handover_bt_process_carrier_record_cb(
- net_nfc_error_e result,
- net_nfc_conn_handover_carrier_type_e type,
- data_s *data,
- void *user_param)
-{
- net_nfc_server_handover_process_config_context_t *context =
- (net_nfc_server_handover_process_config_context_t *)user_param;
-
- if (result == NET_NFC_OK)
- {
- if (context->cb != NULL)
- {
- context->cb(result, type, data, context->user_param);
- }
- }
- else
- {
- DEBUG_ERR_MSG("_handover_bt_process_carrier_record failed [%d]",
- result);
- }
-
- _net_nfc_util_free_mem(context);
-}
-
-
-net_nfc_error_e
-_net_nfc_server_handover_get_carrier_record_by_priority_order(
- ndef_message_s *request,
- ndef_record_s **record)
-{
- net_nfc_error_e result;
- unsigned int carrier_count = 0;
-
- LOGD("[%s] START", __func__);
-
- if (request == NULL || record == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
-
- *record = NULL;
-
- if ((result = net_nfc_util_get_alternative_carrier_record_count(
- request,
- &carrier_count)) == NET_NFC_OK)
- {
- int idx, priority;
- net_nfc_conn_handover_carrier_type_e carrier_type =
- NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN;
-
- for (priority = NET_NFC_CONN_HANDOVER_CARRIER_BT;*record == NULL
- && priority < NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN;priority++)
- {
- /* check each carrier record and create matched record */
- for (idx = 0; idx < carrier_count; idx++)
- {
- if ((net_nfc_util_get_alternative_carrier_type(
- request,
- idx,
- &carrier_type)== NET_NFC_OK)
- && (carrier_type == priority))
- {
- DEBUG_SERVER_MSG("selected carrier type"
- " = [%d]", carrier_type);
- net_nfc_util_get_carrier_config_record(
- request,
- idx,
- record);
- result = NET_NFC_OK;
- break;
- }
- }
- }
- }
- else
- {
- DEBUG_ERR_MSG("net_nfc_util_get_alternative_carrier"
- "_record_count failed");
- }
-
- LOGD("[%s] END", __func__);
-
- return result;
-}
-
-static net_nfc_error_e _net_nfc_server_handover_create_requester_from_rawdata(
- ndef_message_s **requestor,
- data_s *data)
-{
- net_nfc_error_e result;
-
- if (requestor == NULL)
- return NET_NFC_NULL_PARAMETER;
-
- *requestor = NULL;
-
- result = net_nfc_util_create_ndef_message(requestor);
- if (result == NET_NFC_OK)
- {
- result = net_nfc_util_convert_rawdata_to_ndef_message(data,
- *requestor);
-
- if (result == NET_NFC_OK)
- {
- if (_net_nfc_server_handover_check_hr_record_validation(
- *requestor) == true)
- {
- result = NET_NFC_OK;
- }
- else
- {
- DEBUG_ERR_MSG("record is not valid or"
- " is not available");
- net_nfc_util_free_ndef_message(*requestor);
- result = NET_NFC_INVALID_PARAM;
- }
- }
- else
- {
- DEBUG_ERR_MSG("_net_nfc_ndef_rawdata_to_ndef"
- "failed [%d]",result);
- }
- } else {
- DEBUG_ERR_MSG("net_nfc_util_create_ndef_message failed [%d]",
- result);
- }
-
- return result;
-}
-
-net_nfc_error_e _net_nfc_server_handover_create_selector_from_rawdata(
- ndef_message_s **selector,
- data_s *data)
-{
- net_nfc_error_e result;
-
- if (selector == NULL)
- return NET_NFC_NULL_PARAMETER;
-
- *selector = NULL;
-
- if ((result = net_nfc_util_create_ndef_message(selector))
- == NET_NFC_OK)
- {
- if ((result = net_nfc_util_convert_rawdata_to_ndef_message(data,
- *selector)) == NET_NFC_OK)
- {
-
- /* if record is not Hs record, then */
- if (_net_nfc_server_handover_check_hs_record_validation(
- *selector) == true)
- {
- result = NET_NFC_OK;
- }
- else
- {
- DEBUG_ERR_MSG("record is not valid or is "
- "not available");
- net_nfc_util_free_ndef_message(*selector);
- result = NET_NFC_INVALID_PARAM;
- }
- }
- else
- {
- DEBUG_ERR_MSG("_net_nfc_ndef_rawdata_to_ndef"
- " failed [%d]",result);
- }
- }
- else
- {
- DEBUG_ERR_MSG("_net_nfc_util_create_ndef_message"
- " failed [%d]",result);
- }
-
- return result;
-}
-
-static bool _net_nfc_server_handover_check_hr_record_validation(
- ndef_message_s *message)
-{
- unsigned int count;
- ndef_record_s *rec;
-
- LOGD("[%s] START", __func__);
-
- if (message == NULL)
- return false;
-
- rec = (ndef_record_s *)message->records;
-
- if (memcmp(rec->type_s.buffer, CH_REQ_RECORD_TYPE,
- rec->type_s.length) != 0)
- {
- DEBUG_ERR_MSG("This is not connection handover"
- " request message");
- goto ERROR;
- }
-
- if (rec->payload_s.buffer[0] != CH_VERSION)
- {
- DEBUG_ERR_MSG("connection handover version is not matched");
- goto ERROR;
- }
-
- if (net_nfc_util_get_alternative_carrier_record_count(message, &count)
- != NET_NFC_OK || count == 0)
- {
- DEBUG_ERR_MSG("there is no carrier reference");
- goto ERROR;
- }
-
- LOGD("[%s] END", __func__);
-
- return true;
-
-ERROR :
- LOGD("[%s] END", __func__);
-
- return false;
-}
-
-static bool _net_nfc_server_handover_check_hs_record_validation(
- ndef_message_s *message)
-{
- unsigned int count;
- ndef_record_s *rec;
-
- LOGD("[%s] START", __func__);
-
- if (message == NULL)
- return false;
-
- rec = (ndef_record_s *)message->records;
-
- if (memcmp(rec->type_s.buffer, CH_SEL_RECORD_TYPE,
- rec->type_s.length) != 0)
- {
- DEBUG_ERR_MSG("This is not connection handover"
- " request message");
- goto ERROR;
- }
-
- if (net_nfc_util_get_alternative_carrier_record_count(
- message,&count)!= NET_NFC_OK || count == 0)
- {
- DEBUG_ERR_MSG("there is no carrrier reference");
- goto ERROR;
- }
-
- /* check version */
- if (rec->payload_s.buffer[0] != CH_VERSION)
- {
- DEBUG_ERR_MSG("connection handover version"
- " is not matched");
- goto ERROR;
- }
-
- LOGD("[%s] END", __func__);
-
- return true;
-
-ERROR :
- LOGD("[%s] END", __func__);
-
- return false;
-}
-
-static int _net_nfc_server_handover_iterate_carrier_configs_step(
- net_nfc_server_handover_create_config_context_t *context)
-{
- LOGD("[%s:%d] START", __func__, __LINE__);
-
- if (context == NULL)
- {
- return 0;
- }
-
- if (context->cb != NULL)
- {
- context->cb(NET_NFC_OK, context->ndef_message,
- context->user_param);
- }
-
- if (context->ndef_message != NULL)
- {
- net_nfc_util_free_ndef_message(context->ndef_message);
- }
-
- _net_nfc_util_free_mem(context);
-
- LOGD("[%s:%d] END", __func__, __LINE__);
-
- return 0;
-}
-
-static int _net_nfc_server_handover_append_wifi_carrier_config(
- net_nfc_server_handover_create_config_context_t *context)
-{
- LOGD("[%s:%d] START", __func__, __LINE__);
-
- switch (context->step)
- {
- case NET_NFC_LLCP_STEP_01 :
- DEBUG_MSG("STEP [1]");
-
- context->step = NET_NFC_LLCP_STEP_02;
- break;
-
- case NET_NFC_LLCP_STEP_02 :
- DEBUG_MSG("STEP [2]");
-
- context->step = NET_NFC_LLCP_STEP_03;
- break;
-
- case NET_NFC_LLCP_STEP_03 :
- DEBUG_MSG("STEP [3]");
-
- context->step = NET_NFC_LLCP_STEP_RETURN;
- break;
-
- case NET_NFC_LLCP_STEP_RETURN :
- DEBUG_MSG("STEP return");
-
- /* complete and return to upper step */
- g_idle_add(
- (GSourceFunc)_net_nfc_server_handover_iterate_carrier_configs_to_next,
- (gpointer)context);
- break;
-
- default :
- break;
- }
-
- LOGD("[%s:%d] END", __func__, __LINE__);
-
- return 0;
-}
-
-static int _net_nfc_server_handover_iterate_carrier_configs_to_next(
- net_nfc_server_handover_create_config_context_t *context)
-{
- if (context->result == NET_NFC_OK || context->result == NET_NFC_BUSY)
- {
- if (context->type == NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN)
- {
- if (context->current_type <
- NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN)
- {
- context->current_type++;
- }
- }
- else
- {
- context->current_type =
- NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN;
- }
-
- g_idle_add(
- (GSourceFunc)_net_nfc_server_handover_iterate_create_carrier_configs,
- (gpointer)context);
- }
- else
- {
- DEBUG_ERR_MSG("context->result is error [%d]", context->result);
-
- g_idle_add(
- (GSourceFunc)_net_nfc_server_handover_iterate_carrier_configs_step,
- (gpointer)context);
- }
-
- return 0;
-}
-
-static int _net_nfc_server_handover_iterate_create_carrier_configs(
- net_nfc_server_handover_create_config_context_t *context)
-{
- LOGD("[%s:%d] START", __func__, __LINE__);
-
- switch (context->current_type)
- {
- case NET_NFC_CONN_HANDOVER_CARRIER_BT :
- DEBUG_MSG("[NET_NFC_CONN_HANDOVER_CARRIER_BT]");
- net_nfc_server_handover_bt_get_carrier_record(
- _net_nfc_server_handover_bt_get_carrier_record_cb,
- context);
- break;
-
-// case NET_NFC_CONN_HANDOVER_CARRIER_WIFI_BSS :
-// DEBUG_MSG("[NET_NFC_CONN_HANDOVER_CARRIER_WIFI_BSS]");
-// g_idle_add(
-// (GSourceFunc)net_nfc_service_llcp_handover_append_wifi_carrier_config,
-// context);
-// break;
-
-// case NET_NFC_CONN_HANDOVER_CARRIER_WIFI_IBSS :
-// DEBUG_MSG("[NET_NFC_CONN_HANDOVER_CARRIER_WIFI_BSS]");
-// g_idle_add(
-// (GSourceFunc)_net_nfc_server_handover_append_wifi_carrier_config,
-// context);
-// break;
-
- case NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN :
- DEBUG_MSG("[NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN]");
- g_idle_add(
- (GSourceFunc)_net_nfc_server_handover_iterate_carrier_configs_step,
- (gpointer)context);
- break;
-
- default :
- DEBUG_MSG("[unknown : %d]", context->current_type);
- g_idle_add(
- (GSourceFunc)_net_nfc_server_handover_iterate_carrier_configs_step,
- (gpointer)context);
- break;
- }
-
- LOGD("[%s:%d] END", __func__, __LINE__);
-
- return 0;
-}
-
-static net_nfc_error_e
-_net_nfc_server_handover_create_requester_carrier_configs(
- net_nfc_conn_handover_carrier_type_e type,
- void *cb,
- void *user_param)
-{
- net_nfc_error_e result = NET_NFC_OK;
- net_nfc_server_handover_create_config_context_t *context = NULL;
-
- LOGD("[%s:%d] START", __func__, __LINE__);
-
- _net_nfc_util_alloc_mem(context, sizeof(*context));
- if (context != NULL)
- {
- context->type = type;
- if (type == NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN)
- {
- context->current_type =
- NET_NFC_CONN_HANDOVER_CARRIER_BT;
- }
- else
- context->current_type = context->type;
-
- context->cb = cb;
- context->user_param = user_param;
- net_nfc_util_create_handover_request_message(
- &context->ndef_message);
-
- /* append carrier record */
- g_idle_add(
- (GSourceFunc)_net_nfc_server_handover_iterate_create_carrier_configs,
- (gpointer)context);
- }
- else
- {
- DEBUG_ERR_MSG("alloc failed");
- result = NET_NFC_ALLOC_FAIL;
- }
-
- LOGD("[%s:%d] END", __func__, __LINE__);
-
- return result;
-}
-
-static net_nfc_error_e
-_net_nfc_server_handover_create_selector_carrier_configs(
- net_nfc_conn_handover_carrier_type_e type,
- void *cb,
- void *user_param)
-{
- net_nfc_error_e result = NET_NFC_OK;
- net_nfc_server_handover_create_config_context_t *context = NULL;
-
- LOGD("[%s:%d] START", __func__, __LINE__);
-
- _net_nfc_util_alloc_mem(context, sizeof(*context));
- if (context != NULL)
- {
- context->type = type;
- if (type == NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN)
- {
- context->current_type =
- NET_NFC_CONN_HANDOVER_CARRIER_BT;
- }
- else
- context->current_type = context->type;
- context->cb = cb;
- context->user_param = user_param;
- net_nfc_util_create_handover_select_message(
- &context->ndef_message);
-
- /* append carrier record */
- g_idle_add(
- (GSourceFunc)_net_nfc_server_handover_iterate_create_carrier_configs,
- (gpointer)context);
- }
- else
- {
- DEBUG_ERR_MSG("alloc failed");
- result = NET_NFC_ALLOC_FAIL;
- }
-
- LOGD("[%s:%d] END", __func__, __LINE__);
-
- return result;
-}
-
-static net_nfc_error_e
-_net_nfc_server_handover_create_low_power_selector_message(
- ndef_message_s *request_msg,
- ndef_message_s *select_msg)
-{
- net_nfc_error_e result = NET_NFC_UNKNOWN_ERROR;
- unsigned int carrier_count = 0;
-
- LOGD("[%s] START", __func__);
-
- if (request_msg == NULL || select_msg == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
-
- if ((result = net_nfc_util_get_alternative_carrier_record_count(
- request_msg,
- &carrier_count)) == NET_NFC_OK)
- {
- int idx;
- ndef_record_s *carrier_record = NULL;
- net_nfc_conn_handover_carrier_type_e carrier_type =
- NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN;
-
- /* check each carrier record and create matched record */
- for (idx = 0; idx < carrier_count; idx++)
- {
- if ((net_nfc_util_get_alternative_carrier_type(
- request_msg,idx,&carrier_type) != NET_NFC_OK) ||
- (carrier_type == NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN))
- {
- DEBUG_ERR_MSG("net_nfc_util_get_alternative"
- "_carrier_type failed or unknown");
- continue;
- }
-
- DEBUG_SERVER_MSG("carrier type = [%d]", carrier_type);
-
- /* add temporary config record */
- {
- net_nfc_carrier_config_s *config = NULL;
-
- if ((result = net_nfc_util_create_carrier_config(
- &config,carrier_type)) == NET_NFC_OK)
- {
- if ((result =
- net_nfc_util_create_ndef_record_with_carrier_config(
- &carrier_record,config)) == NET_NFC_OK)
- {
- DEBUG_SERVER_MSG("net_nfc_util_create_ndef_record_"
- "with_carrier_config success");
- }
- else
- {
- DEBUG_ERR_MSG("create_ndef_record_with_carrier_config "
- "failed [%d]", result);
- net_nfc_util_free_carrier_config(config);
- continue;
- }
-
- net_nfc_util_free_carrier_config(config);
- }
- else
- {
- DEBUG_ERR_MSG("net_nfc_util_get_local_bt_address return NULL");
- continue;
- }
- }
-
- /* append carrier configure record to selector message */
- if ((result = net_nfc_util_append_carrier_config_record(
- select_msg,
- carrier_record,
- NET_NFC_CONN_HANDOVER_CARRIER_INACTIVATE)) == NET_NFC_OK)
- {
- DEBUG_SERVER_MSG("net_nfc_util_append_carrier_config_record success");
- }
- else
- {
- DEBUG_ERR_MSG("net_nfc_util_append_carrier_config_record"
- " failed [%d]", result);
-
- net_nfc_util_free_record(carrier_record);
- }
- }
-
- result = NET_NFC_OK;
- }
- else
- {
- DEBUG_ERR_MSG("net_nfc_util_get_alternative_carrier_record_count failed");
- }
-
- LOGD("[%s] END", __func__);
-
- return result;
-}
-
-net_nfc_error_e _net_nfc_server_handover_process_carrier_record(
- ndef_record_s *carrier,
- void *cb,
- void *user_param)
-{
- net_nfc_error_e result = NET_NFC_OK;
- net_nfc_server_handover_process_config_context_t *context = NULL;
-
- LOGD("[%s:%d] START", __func__, __LINE__);
-
- _net_nfc_util_alloc_mem(context, sizeof(*context));
- if (context != NULL)
- {
- net_nfc_conn_handover_carrier_type_e type;
-
- net_nfc_util_get_alternative_carrier_type_from_record(
- carrier,
- &type);
-
- context->type = type;
- context->user_param = user_param;
- context->cb = cb;
- context->step = NET_NFC_LLCP_STEP_01;
-
- /* process carrier record */
- switch (type)
- {
- case NET_NFC_CONN_HANDOVER_CARRIER_BT :
- DEBUG_MSG("[NET_NFC_CONN_HANDOVER_CARRIER_BT]");
- net_nfc_server_handover_bt_process_carrier_record(
- carrier,
- _net_nfc_server_handover_bt_process_carrier_record_cb,
- context);
- break;
-
- case NET_NFC_CONN_HANDOVER_CARRIER_WIFI_BSS :
- DEBUG_MSG("[NET_NFC_CONN_HANDOVER_CARRIER_WIFI_BSS]");
- net_nfc_server_handover_bss_process_carrier_record(
- carrier,
- NULL,
- NULL);
- _net_nfc_util_free_mem(context);
- break;
-
- case NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN :
- DEBUG_MSG("[NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN]");
- _net_nfc_util_free_mem(context);
- break;
-
- default :
- DEBUG_MSG("[unknown]");
- _net_nfc_util_free_mem(context);
- break;
- }
- }
- else
- {
- DEBUG_ERR_MSG("alloc failed");
- result = NET_NFC_ALLOC_FAIL;
- }
-
- LOGD("[%s:%d] END", __func__, __LINE__);
-
- return result;
-}
-
-#if 0
-static net_nfc_error_e _net_nfc_server_handover_snep_client_cb(
- net_nfc_snep_handle_h handle,
- net_nfc_error_e result,
- uint32_t type,
- data_s *data,
- void *user_param)
-{
- _net_nfc_server_handover_client_context_t *context =
- (_net_nfc_server_handover_client_context_t *)user_param;
-
- DEBUG_SERVER_MSG("type [%d], result [%d], data [%p], user_param [%p]",
- type, result, data, user_param);
-
- switch (type) {
- case SNEP_RESP_SUCCESS :
- {
- ndef_message_s *selector;
-
- result = _net_nfc_server_handover_create_selector_from_rawdata(
- &selector,
- data);
- if (result == NET_NFC_OK) {
- if (false /* is low power ??? */) {
- result =
- _net_nfc_server_handover_process_selector_msg(
- selector,
- user_param);
- } else {
- result =
- _net_nfc_server_handover_process_selector_msg(
- selector,
- user_param);
- }
-
- if (result != NET_NFC_OK) {
- DEBUG_ERR_MSG("_net_nfc_server_handover_process"
- "_selector_msg failed [%d]",result);
- if (context->cb != NULL) {
- context->cb(result,
- context->type,
- NULL,
- context->user_param);
- }
- _net_nfc_util_free_mem(context);
- }
-
- net_nfc_util_free_ndef_message(selector);
- } else {
- DEBUG_ERR_MSG("_net_nfc_server_handover_create"
- "_selector_from_rawdata failed [%d]",result);
- if (context->cb != NULL) {
- context->cb(result,
- context->type,
- NULL,
- context->user_param);
- }
- _net_nfc_util_free_mem(context);
- }
- }
- break;
-
- case SNEP_RESP_BAD_REQ :
- case SNEP_RESP_EXCESS_DATA :
- case SNEP_RESP_NOT_FOUND :
- case SNEP_RESP_NOT_IMPLEMENT :
- case SNEP_RESP_REJECT :
- case SNEP_RESP_UNSUPPORTED_VER :
- default :
- {
- DEBUG_ERR_MSG("error response [0x%02x]", type);
- if (context->cb != NULL) {
- context->cb(result, context->type, NULL,
- context->user_param);
- }
- _net_nfc_util_free_mem(context);
- }
- break;
- }
-
- return result;
-}
-
-
-static void _net_nfc_server_handover_create_requester_carrier_configs_cb(
- net_nfc_error_e result,
- ndef_message_s *msg,
- void *user_param)
-{
- _net_nfc_server_handover_client_context_t *context =
- (_net_nfc_server_handover_client_context_t *)user_param;
- data_s data;
-
- if (context == NULL)
- {
- return;
- }
-
- if (msg != NULL) {
- /* convert ndef message */
- if ((result = _net_nfc_server_handover_convert_ndef_message_to_data(msg,
- &data)) == NET_NFC_OK) {
- net_nfc_service_snep_client(context->handle,
- SNEP_SAN,
- 0,
- SNEP_REQ_GET,
- &data,
- _net_nfc_server_handover_snep_client_cb,
- context);
-
- net_nfc_util_free_data(&data);
- }
- else
- {
- DEBUG_ERR_MSG("_net_nfc_server_handover_convert"
- "_ndef_message_to_datafailed [%d]",result);
- if (context->cb != NULL)
- {
- context->cb(result,
- context->type,
- NULL,
- context->user_param);
- }
- _net_nfc_util_free_mem(context);
- }
- }
- else
- {
- DEBUG_ERR_MSG("null param, [%d]", result);
- if (context->cb != NULL)
- {
- context->cb(result,
- context->type,
- NULL,
- context->user_param);
- }
- _net_nfc_util_free_mem(context);
- }
-}
-#endif
-
-
-#if 0
-
-static void _net_nfc_server_handover_server_create_carrier_configs_cb(
- net_nfc_error_e result,
- ndef_message_s *selector,
- void *user_param)
-{
- _net_nfc_server_handover_create_config_context_t *context =
- (_net_nfc_server_handover_create_config_context_t *)user_param;
- data_s data;
-
- if (context == NULL)
- {
- return;
- }
-
- if (result == NET_NFC_OK)
- {
- result = _net_nfc_server_handover_convert_ndef_message_to_data(
- selector,
- &data);
-
- if (result == NET_NFC_OK)
- {
- /* process message */
- _net_nfc_server_handover_process_carrier_record(
- context->record,
- NULL,
- NULL);
-
- result = net_nfc_service_snep_server_send_get_response(
- context->user_param,
- &data);
- if (result != NET_NFC_OK)
- {
- DEBUG_ERR_MSG("net_nfc_service_snep_server"
- "_send_get_response failed [%d]",result);
- }
- net_nfc_util_free_data(&data);
- }
- else
- {
- DEBUG_ERR_MSG("_net_nfc_server_handover_convert_ndef_message_to_data"
- "failed [%d]",result);
- }
- }
- else
- {
- DEBUG_ERR_MSG("_net_nfc_server_handover_create_selector_msg"
- "failed [%d]",result);
- }
-
- _net_nfc_util_free_mem(context);
-}
-
-static net_nfc_error_e _net_nfc_server_handover_create_selector_msg(
- net_nfc_snep_handle_h handle,
- ndef_message_s *request,
- void *user_param)
-{
- net_nfc_error_e result;
- uint32_t count;
-
- net_nfc_manager_util_play_sound(NET_NFC_TASK_END);
-
- /* get requester message */
- if ((result = net_nfc_util_get_alternative_carrier_record_count(
- request,
- &count)) == NET_NFC_OK)
- {
- if (1/* power state */ || count == 1)
- {
- ndef_record_s *record = NULL;
-
- /* fill alternative carrier information */
- if ((result =
- _net_nfc_server_handover_get_carrier_record_by_priority_order(
- request,
- &record)) == NET_NFC_OK)
- {
- net_nfc_conn_handover_carrier_type_e type =
- NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN;
-
- if ((result = net_nfc_util_get_alternative_carrier_type_from_record(
- record,
- &type)) == NET_NFC_OK)
- {
- _net_nfc_server_handover_create_config_context_t *context = NULL;
-
- _net_nfc_util_alloc_mem(context, sizeof(*context));
-
- context->user_param = handle;
-
- net_nfc_util_create_record(record->TNF,
- &record->type_s, &record->id_s,
- &record->payload_s,
- &context->record);
-
- if ((result = _net_nfc_server_handover_create_selector_carrier_configs(
- type,
- _net_nfc_server_handover_server_create_carrier_configs_cb,
- context)) != NET_NFC_OK)
- {
- DEBUG_ERR_MSG("_create_selector_carrier_configs "
- "failed [%d]", result);
- }
- }
- else
- {
- DEBUG_ERR_MSG("get_alternative_carrier_type_from_record "
- "failed [%d]", result);
- }
- }
- else
- {
- DEBUG_ERR_MSG("r_get_carrier_record_by_priority_order"
- " failed [%d]", result);
- }
- }
- else /* low power && count > 1 */
- {
- ndef_message_s selector;
-
- if ((result = _net_nfc_server_handover_create_low_power_selector_message(
- request,
- &selector)) == NET_NFC_OK)
- {
- _net_nfc_server_handover_server_create_carrier_configs_cb(
- NET_NFC_OK,
- &selector,
- user_param);
-
- net_nfc_util_free_ndef_message(&selector);
- }
- else
- {
- DEBUG_ERR_MSG("_create_low_power_selector_message"
- "failed [%d]", result);
- }
- }
- }
- else
- {
- DEBUG_ERR_MSG("net_nfc_util_get_alternative_carrier_record_count"
- "failed [%d]", result);
- }
-
- return result;
-}
-
-
-static net_nfc_error_e _net_nfc_server_handover_create_server_cb(
- net_nfc_snep_handle_h handle,
- net_nfc_error_e result,
- uint32_t type,
- data_s *data,
- void *user_param)
-{
- DEBUG_SERVER_MSG("type [0x%02x], result [%d], data [%p], user_param [%p]",
- type, result, data, user_param);
-
- if (result != NET_NFC_OK || data == NULL || data->buffer == NULL)
- {
- /* restart */
- return NET_NFC_NULL_PARAMETER;
- }
-
- switch (type)
- {
- case SNEP_REQ_GET :
- {
- ndef_message_s *request;
-
- /* TODO : send select response to requester */
- result =
- _net_nfc_server_handover_create_requester_from_rawdata(
- &request,
- data);
- if (result == NET_NFC_OK) {
- if (1/* TODO : check version */)
- {
- _net_nfc_server_handover_create_selector_msg(
- handle,
- request,
- user_param);
- }
- else
- {
- DEBUG_ERR_MSG("not supported version [0x%x]",
- result);
-
- result = NET_NFC_NOT_SUPPORTED;
- }
-
- net_nfc_util_free_ndef_message(request);
- }
- else
- {
- DEBUG_ERR_MSG("_net_nfc_server_handover_create"
- "_requester_from_rawdata failed [%d]",result);
- }
- }
- break;
-
- case SNEP_REQ_PUT :
- DEBUG_ERR_MSG("PUT request doesn't supported");
- result = NET_NFC_NOT_SUPPORTED;
- break;
-
- default :
- DEBUG_ERR_MSG("error [%d]", result);
- break;
- }
-
- return result;
-}
-#else
-
-
-
-static net_nfc_error_e _net_nfc_server_handover_select_carrier_record(
- ndef_message_s *request,
- net_nfc_conn_handover_carrier_type_e *type,
- ndef_record_s **record)
-{
- net_nfc_error_e result;
- uint32_t count;
-
- *record = NULL;
- *type = NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN;
-
- /* get requester message */
- if ((result = net_nfc_util_get_alternative_carrier_record_count(request,
- &count)) == NET_NFC_OK)
- {
- if (1/* power state */ || count == 1)
- {
- ndef_record_s *temp;
-
- /* fill alternative carrier information */
- if ((result =
- _net_nfc_server_handover_get_carrier_record_by_priority_order(
- request,
- &temp)) == NET_NFC_OK)
- {
- if ((result =
- net_nfc_util_get_alternative_carrier_type_from_record(
- temp,
- type)) == NET_NFC_OK)
- {
- net_nfc_util_create_record(temp->TNF,
- &temp->type_s, &temp->id_s,
- &temp->payload_s,
- record);
- }
- else
- {
- DEBUG_ERR_MSG("net_nfc_util_get_alternative"
- "_carrier_type_from_record failed [%d]", result);
- }
- }
- else
- {
- DEBUG_ERR_MSG("_handover_get_carrier_record"
- "_by_priority_order failed [%d]", result);
- }
- }
- else /* low power && count > 1 */
- {
- result = NET_NFC_INVALID_STATE;
- }
- }
- else
- {
- DEBUG_ERR_MSG("net_nfc_util_get_alternative_carrier_record_count "
- "failed [%d]", result);
- }
-
- return result;
-}
-
-#endif
-
-static void _net_nfc_server_handover_create_carrier_configs_2_cb(
- net_nfc_error_e result,
- ndef_message_s *selector,
- void *user_param)
-{
- net_nfc_handover_context_t *context =
- (net_nfc_handover_context_t *)user_param;
-
- DEBUG_SERVER_MSG("_net_nfc_server_handover_server_create_carrier_config_cb"
- "result [%d]",result);
-
- if (context == NULL)
- {
- return;
- }
-
- context->result = result;
-
- if (result == NET_NFC_OK) {
- result = _net_nfc_server_handover_convert_ndef_message_to_data(
- selector,
- &context->data);
-
- DEBUG_SERVER_MSG("selector message created, length [%d]",
- context->data.length);
-
- context->state = NET_NFC_LLCP_STEP_03;
- }
- else
- {
- DEBUG_ERR_MSG("_net_nfc_server_handover_create_selector_msg failed [%d]",
- result);
- context->state = NET_NFC_MESSAGE_LLCP_ERROR;
- }
-
- _net_nfc_server_handover_get_response_process(context);
-}
-
-static void _net_nfc_server_handover_process_carrier_record_2_cb(
- net_nfc_error_e result,
- net_nfc_conn_handover_carrier_type_e type,
- data_s *data,
- void *user_param)
-{
- net_nfc_handover_context_t *context =
- (net_nfc_handover_context_t *)user_param;
-
- DEBUG_SERVER_MSG("_net_nfc_server_handover_server_process_carrier_record_cb"
- "result [%d]",result);
-
- context->result = result;
- if (result == NET_NFC_OK)
- {
- context->state = NET_NFC_LLCP_STEP_04;
- }
- else
- {
- context->state = NET_NFC_MESSAGE_LLCP_ERROR;
- }
-
- context->data.length = data->length;
- _net_nfc_util_alloc_mem(context->data.buffer, context->data.length);
- memcpy(context->data.buffer, data->buffer, context->data.length);
-
-
- _net_nfc_server_handover_server_process(context);
-}
-
-static void _net_nfc_server_handover_get_response_process(
- net_nfc_handover_context_t *context)
-{
- net_nfc_error_e result;
-
- if (context == NULL)
- {
- return;
- }
-
- switch (context->state)
- {
- case NET_NFC_LLCP_STEP_02 :
- DEBUG_SERVER_MSG("NET_NFC_LLCP_STEP_02");
-
- result = _net_nfc_server_handover_create_selector_carrier_configs(
- context->type,
- _net_nfc_server_handover_create_carrier_configs_2_cb,
- context);
-
- if (result != NET_NFC_OK)
- {
- DEBUG_ERR_MSG("_net_nfc_server_handover_create_"
- "selector_carrier_config failed [%d]",result);
- }
- break;
-
- case NET_NFC_LLCP_STEP_03 :
- DEBUG_SERVER_MSG("NET_NFC_LLCP_STEP_03");
-
- result = _net_nfc_server_handover_process_carrier_record(
- context->record,
- _net_nfc_server_handover_process_carrier_record_2_cb,
- context);
-
- if (result != NET_NFC_OK)
- {
- DEBUG_ERR_MSG("_net_nfc_server_handover_process_carrier_record"
- "failed [%d]",result);
- }
- break;
-
- case NET_NFC_LLCP_STEP_04 :
- DEBUG_SERVER_MSG("NET_NFC_LLCP_STEP_04");
-
- /* response select message */
- result = net_nfc_server_snep_server_send_get_response(
- (net_nfc_snep_handle_h)context->handle,
- &context->data);
- break;
-
- case NET_NFC_STATE_ERROR :
- DEBUG_SERVER_MSG("NET_NFC_STATE_ERROR");
- break;
-
- default :
- DEBUG_ERR_MSG("NET_NFC_LLCP_STEP_??");
- /* TODO */
- break;
- }
-}
-
-static bool _net_nfc_server_handover_get_response_cb(
- net_nfc_snep_handle_h handle,
- uint32_t type,
- uint32_t max_len,
- data_s *data,
- void *user_param)
-{
- net_nfc_error_e result;
- ndef_message_s *request;
-
- DEBUG_SERVER_MSG("type [%d], data [%p], user_param [%p]",
- type, data, user_param);
-
- if (data == NULL || data->buffer == NULL)
- {
- /* restart */
- return false;
- }
-
- /* TODO : send select response to requester */
- result = _net_nfc_server_handover_create_requester_from_rawdata(
- &request,
- data);
-
- if (result == NET_NFC_OK)
- {
- net_nfc_conn_handover_carrier_type_e type;
- ndef_record_s *record;
-
- if (_net_nfc_server_handover_select_carrier_record(
- request,
- &type,
- &record) == NET_NFC_OK)
- {
- net_nfc_handover_context_t *context = NULL;
-
- _net_nfc_util_alloc_mem(context, sizeof(*context));
-
- if (context != NULL)
- {
- context->handle = (void *)handle;
- context->type = type;
- context->user_param = user_param;
- context->state = NET_NFC_LLCP_STEP_02;
-
- net_nfc_util_create_record(record->TNF,
- &record->type_s,
- &record->id_s,
- &record->payload_s,
- &context->record);
-
- _net_nfc_server_handover_get_response_process(context);
- }
- else
- {
- DEBUG_ERR_MSG("_net_nfc_util_alloc_mem failed");
- result = NET_NFC_ALLOC_FAIL;
- }
- }
- else
- {
- /* low power */
- }
-
- net_nfc_util_free_ndef_message(request);
- }
- else
- {
- DEBUG_SERVER_MSG("it is not handover requester message, [%d]",
- result);
- }
-
- return (result == NET_NFC_OK);
-}
-
-////////////////////////////////////////////////////////////////////////////////
-static void _net_nfc_server_handover_server_process_carrier_record_cb(
- net_nfc_error_e result,
- net_nfc_conn_handover_carrier_type_e type,
- data_s *data,
- void *user_param)
-{
- net_nfc_handover_context_t *context =
- (net_nfc_handover_context_t *)user_param;
-
- DEBUG_SERVER_MSG("_net_nfc_server_handover_server_process"
- "_carrier_record_cb result [%d]",result);
-
- context->result = result;
- if (result == NET_NFC_OK)
- {
- context->state = NET_NFC_LLCP_STEP_04;
- }
- else
- {
- context->state = NET_NFC_MESSAGE_LLCP_ERROR;
- }
-
- _net_nfc_server_handover_server_process(context);
-}
-
-static void _net_nfc_server_handover_server_create_carrier_config_cb(
- net_nfc_error_e result,
- ndef_message_s *selector,
- void *user_param)
-{
- net_nfc_handover_context_t *context =
- (net_nfc_handover_context_t *)user_param;
-
- DEBUG_SERVER_MSG("_net_nfc_server_handover_server_create"
- "_carrier_config_cb,result [%d]",result);
-
- if (context == NULL)
- {
- return;
- }
-
- context->result = result;
-
- if (result == NET_NFC_OK)
- {
- result = _net_nfc_server_handover_convert_ndef_message_to_data(
- selector,
- &context->data);
- DEBUG_SERVER_MSG("selector message created, length [%d]",
- context->data.length);
- context->state = NET_NFC_LLCP_STEP_03;
- }
- else
- {
- DEBUG_ERR_MSG("_net_nfc_server_handover_create_selector_msg"
- " failed [%d]", result);
- context->state = NET_NFC_MESSAGE_LLCP_ERROR;
- }
-
- _net_nfc_server_handover_server_process(context);
-}
-
-static void _net_nfc_server_handover_server_recv_cb(
- net_nfc_error_e result,
- net_nfc_target_handle_s *handle,
- net_nfc_llcp_socket_t socket,
- data_s *data,
- void *user_param)
-{
- net_nfc_handover_context_t *context =
- (net_nfc_handover_context_t *)user_param;
- ndef_message_s *request;
-
- DEBUG_SERVER_MSG("_net_nfc_server_handover_server_recv_cb,"
- " socket [%x], result [%d]", socket, result);
-
- context->result = result;
-
- if (result == NET_NFC_OK)
- {
- result = _net_nfc_server_handover_create_requester_from_rawdata(
- &request,
- data);
-
- if (result == NET_NFC_OK)
- {
- ndef_record_s *record;
-
- if (_net_nfc_server_handover_select_carrier_record(
- request,
- &context->type,
- &record) == NET_NFC_OK)
- {
- net_nfc_util_create_record(record->TNF,
- &record->type_s, &record->id_s,
- &record->payload_s,
- &context->record);
-
- context->state = NET_NFC_LLCP_STEP_02;
- }
- else
- {
- /* low power */
- context->state = NET_NFC_LLCP_STEP_06;
- }
-
- net_nfc_util_free_ndef_message(request);
- }
- else
- {
- DEBUG_ERR_MSG("_net_nfc_server_handover_create"
- "_requester_from_rawdata failed [%d]",result);
- context->state = NET_NFC_MESSAGE_LLCP_ERROR;
- }
- }
- else
- {
- DEBUG_ERR_MSG("net_nfc_server_llcp_simple_receive failed [%d]",
- result);
- context->state = NET_NFC_MESSAGE_LLCP_ERROR;
- }
-
- _net_nfc_server_handover_server_process(context);
-}
-
-static void _net_nfc_server_handover_server_send_cb(net_nfc_error_e result,
- net_nfc_target_handle_s *handle,
- net_nfc_llcp_socket_t socket,
- data_s *data,
- void *user_param)
-{
- net_nfc_handover_context_t *context =
- (net_nfc_handover_context_t *)user_param;
-
- DEBUG_SERVER_MSG("_net_nfc_server_handover_server_send_cb"
- " socket [%x], result [%d]", socket, result);
-
- context->result = result;
-
- if (result == NET_NFC_OK)
- {
- context->state = NET_NFC_LLCP_STEP_01;
- net_nfc_util_free_data(&context->data);
- net_nfc_util_free_record(context->record);
- context->record = NULL;
- }
- else
- {
- DEBUG_ERR_MSG("net_nfc_server_llcp_simple_send failed [%d]",
- result);
- context->state = NET_NFC_MESSAGE_LLCP_ERROR;
- }
-
- _net_nfc_server_handover_server_process(context);
-}
-
-static void _net_nfc_server_handover_server_process(
- net_nfc_handover_context_t *context)
-{
- if (context == NULL)
- {
- return;
- }
-
- switch (context->state)
- {
- case NET_NFC_LLCP_STEP_01 :
- DEBUG_SERVER_MSG("NET_NFC_LLCP_STEP_01");
-
- /* receive request message */
- net_nfc_server_llcp_simple_receive(context->handle,
- context->socket,
- _net_nfc_server_handover_server_recv_cb,
- context);
- break;
-
- case NET_NFC_LLCP_STEP_02 :
- DEBUG_SERVER_MSG("NET_NFC_LLCP_STEP_02");
-
- context->result = _net_nfc_server_handover_create_selector_carrier_configs(
- context->type,
- _net_nfc_server_handover_server_create_carrier_config_cb,
- context);
-
- if (context->result != NET_NFC_OK)
- {
- DEBUG_ERR_MSG("_net_nfc_server_handover_create_selector"
- "_carrier_configs failed [%d]", context->result);
- }
- break;
-
- case NET_NFC_LLCP_STEP_03 :
- DEBUG_SERVER_MSG("NET_NFC_LLCP_STEP_03");
-
- context->result = _net_nfc_server_handover_process_carrier_record(
- context->record,
- _net_nfc_server_handover_server_process_carrier_record_cb,
- context);
- if (context->result != NET_NFC_OK)
- {
- DEBUG_ERR_MSG("_net_nfc_server_handover_process_carrier_"
- "record failed [%d]",context->result);
- }
- break;
-
- case NET_NFC_LLCP_STEP_04 :
- DEBUG_SERVER_MSG("NET_NFC_LLCP_STEP_04");
-
- /* send select message */
- net_nfc_server_llcp_simple_send(
- context->handle,
- context->socket,
- &context->data,
- _net_nfc_server_handover_server_send_cb,
- context);
- break;
-
- case NET_NFC_STATE_ERROR :
- DEBUG_SERVER_MSG("NET_NFC_STATE_ERROR");
-
- /* error, invoke callback */
- DEBUG_ERR_MSG("handover_server failed, [%d]",
- context->result);
-
- /* restart?? */
- break;
-
- default :
- DEBUG_ERR_MSG("NET_NFC_LLCP_STEP_??");
- /* TODO */
- break;
- }
-}
-
-static void _net_nfc_server_handover_server_error_cb(
- net_nfc_error_e result,
- net_nfc_target_handle_s *handle,
- net_nfc_llcp_socket_t socket,
- data_s *data,
- void *user_param)
-{
- net_nfc_handover_context_t *context =
- (net_nfc_handover_context_t *)user_param;
-
- DEBUG_ERR_MSG("result [%d], socket [%x], user_param [%p]",
- result, socket, user_param);
-
- if (context == NULL)
- {
- return;
- }
-
- net_nfc_controller_llcp_socket_close(socket, &result);
-
- net_nfc_util_free_record(context->record);
- net_nfc_util_free_data(&context->data);
- _net_nfc_util_free_mem(user_param);
-}
-
-static void _net_nfc_server_handover_server_incomming_cb(
- net_nfc_error_e result,
- net_nfc_target_handle_s *handle,
- net_nfc_llcp_socket_t socket,
- data_s *data,
- void *user_param)
-{
- DEBUG_SERVER_MSG("result [%d], socket [%x], user_param [%p]",
- result, socket, user_param);
-
- net_nfc_handover_context_t *accept_context = NULL;
-
- _net_nfc_util_alloc_mem(accept_context, sizeof(*accept_context));
- if (accept_context == NULL)
- {
- DEBUG_ERR_MSG("_net_nfc_util_alloc_mem failed");
-
- result = NET_NFC_ALLOC_FAIL;
- goto ERROR;
- }
-
- accept_context->handle = handle;
- accept_context->socket = socket;
- accept_context->state = NET_NFC_LLCP_STEP_01;
-
- result = net_nfc_server_llcp_simple_accept(
- handle,
- socket,
- _net_nfc_server_handover_server_error_cb,
- accept_context);
-
- if (result != NET_NFC_OK)
- {
- DEBUG_ERR_MSG("net_nfc_server_llcp_simple_accept failed, [%d]",
- result);
-
- goto ERROR;
- }
-
- _net_nfc_server_handover_server_process(accept_context);
-
- return;
-
-ERROR :
- if (accept_context != NULL)
- {
- _net_nfc_util_free_mem(accept_context);
- }
-
- net_nfc_controller_llcp_socket_close(socket, &result);
-
- /* TODO : restart ?? */
-}
-
-net_nfc_error_e net_nfc_server_handover_default_server_start(
- net_nfc_target_handle_s *handle)
-{
- net_nfc_error_e result;
-
- /* start default handover server using snep */
- result =
- net_nfc_server_snep_default_server_register_get_response_cb(
- _net_nfc_server_handover_get_response_cb,
- NULL);
-
- /* start default handover server */
- result = net_nfc_server_llcp_simple_server(
- handle,
- CH_SAN,
- CH_SAP,
- _net_nfc_server_handover_server_incomming_cb,
- _net_nfc_server_handover_server_error_cb,
- NULL);
-
- if (result == NET_NFC_OK)
- {
- DEBUG_SERVER_MSG("start handover server, san [%s], sap [%d]",
- CH_SAN,CH_SAP);
- }
- else
- {
- DEBUG_ERR_MSG("net_nfc_server_llcp_simple_server failed, [%d]",
- result);
- }
-
- return result;
-}
-
-static void _handover_default_activate_cb(int event,
- net_nfc_target_handle_s *handle,
- uint32_t sap, const char *san, void *user_param)
-{
- net_nfc_error_e result;
-
- DEBUG_SERVER_MSG("event [%d], handle [%p], sap [%d], san [%s]",
- event, handle, sap, san);
-
- if (event == NET_NFC_LLCP_START) {
- /* start default handover server using snep */
- result = net_nfc_server_snep_default_server_register_get_response_cb(
- _net_nfc_server_handover_get_response_cb, NULL);
-
- /* start default handover server */
- result = net_nfc_server_llcp_simple_server(handle,
- CH_SAN, CH_SAP,
- _net_nfc_server_handover_server_incomming_cb,
- _net_nfc_server_handover_server_error_cb, NULL);
-
- if (result == NET_NFC_OK) {
- DEBUG_SERVER_MSG("start handover server, san [%s], sap [%d]",
- CH_SAN, CH_SAP);
- } else {
- DEBUG_ERR_MSG("net_nfc_service_llcp_server failed, [%d]",
- result);
- }
- } else if (event == NET_NFC_LLCP_UNREGISTERED) {
- /* unregister server, do nothing */
- }
-}
-
-net_nfc_error_e net_nfc_server_handover_default_server_register()
-{
- char id[20];
-
- /* TODO : make id, */
- snprintf(id, sizeof(id), "%d", getpid());
-
- /* start default snep server */
- return net_nfc_server_llcp_register_service(id,
- CH_SAP,
- CH_SAN,
- _handover_default_activate_cb,
- NULL);
-}
-
-net_nfc_error_e net_nfc_server_handover_default_server_unregister()
-{
- char id[20];
-
- /* TODO : make id, */
- snprintf(id, sizeof(id), "%d", getpid());
-
- /* start default snep server */
- return net_nfc_server_llcp_unregister_service(id,
- CH_SAP,
- CH_SAN);
-}
-
-////////////////////////////////////////////////////////////////////////////////
-
-static void _net_nfc_server_handover_client_post_process_cb(
- net_nfc_error_e result,
- net_nfc_conn_handover_carrier_type_e type,
- data_s *data,
- void *user_param)
-{
- net_nfc_handover_context_t *context =
- (net_nfc_handover_context_t *)user_param;
-
- if (context == NULL)
- {
- return;
- }
-
- context->state = NET_NFC_LLCP_STEP_RETURN;
-
- _net_nfc_server_handover_client_process(context);
-}
-
-static void _net_nfc_server_handover_client_process_carrier_record_cb(
- net_nfc_error_e result,
- net_nfc_conn_handover_carrier_type_e type,
- data_s *data,
- void *user_param)
-{
- net_nfc_handover_context_t *context =
- (net_nfc_handover_context_t *)user_param;
-
- DEBUG_SERVER_MSG("_net_nfc_server_handover_server_process"
- "_carrier_record_cb,result [%d]",result);
-
- context->result = result;
-
- net_nfc_util_free_data(&context->data);
-
- if (result == NET_NFC_OK)
- {
- net_nfc_util_alloc_data(&context->data, data->length);
- memcpy(context->data.buffer, data->buffer, data->length);
-
- context->state = NET_NFC_LLCP_STEP_05;
- }
- else
- {
- context->state = NET_NFC_MESSAGE_LLCP_ERROR;
- }
-
- _net_nfc_server_handover_client_process(context);
-}
-
-static void _net_nfc_server_handover_client_recv_cb(
- net_nfc_error_e result,
- net_nfc_target_handle_s *handle,
- net_nfc_llcp_socket_t socket,
- data_s *data,
- void *user_param)
-{
- net_nfc_handover_context_t *context =
- (net_nfc_handover_context_t *)user_param;
-
- if (context == NULL)
- {
- return;
- }
-
- context->result = result;
-
- if (result == NET_NFC_OK)
- {
- ndef_message_s *selector;
- ndef_record_s *record;
-
- result = _net_nfc_server_handover_create_selector_from_rawdata(
- &selector,
- data);
-
- if (result == NET_NFC_OK)
- {
- result =
- _net_nfc_server_handover_get_carrier_record_by_priority_order(
- selector,
- &record);
-
- if (result == NET_NFC_OK)
- {
- net_nfc_util_create_record(
- record->TNF,
- &record->type_s, &record->id_s,
- &record->payload_s,
- &context->record);
-
- context->state = NET_NFC_LLCP_STEP_04;
- }
- else
- {
- DEBUG_ERR_MSG("_get_carrier_record_by_priority_order"
- " failed, [%d]",result);
- context->state = NET_NFC_STATE_ERROR;
- }
- }
- else
- {
- DEBUG_ERR_MSG("_net_nfc_server_handover_create"
- "_selector_from_rawdata failed, [%d]",result);
- context->state = NET_NFC_STATE_ERROR;
- }
- }
- else
- {
- DEBUG_ERR_MSG("net_nfc_server_llcp_simple_receive failed, [%d]",
- result);
- context->state = NET_NFC_STATE_ERROR;
- }
-
- _net_nfc_server_handover_client_process(context);
-}
-
-static void _net_nfc_server_handover_client_send_cb(
- net_nfc_error_e result,
- net_nfc_target_handle_s *handle,
- net_nfc_llcp_socket_t socket,
- data_s *data,
- void *user_param)
-{
- net_nfc_handover_context_t *context =
- (net_nfc_handover_context_t *)user_param;
-
- if (context == NULL)
- {
- return;
- }
-
- context->result = result;
-
- net_nfc_util_free_data(&context->data);
-
- if (result == NET_NFC_OK)
- {
- context->state = NET_NFC_LLCP_STEP_03;
- }
- else
- {
- DEBUG_ERR_MSG("net_nfc_server_llcp_simple_client failed, [%d]",
- result);
- context->state = NET_NFC_STATE_ERROR;
- }
-
- _net_nfc_server_handover_client_process(context);
-}
-
-static void _net_nfc_server_handover_client_create_carrier_configs_cb(
- net_nfc_error_e result,
- ndef_message_s *msg,
- void *user_param)
-{
- net_nfc_handover_context_t *context =
- (net_nfc_handover_context_t *)user_param;
-
- if (context == NULL) {
- return;
- }
-
- context->result = result;
-
- if (msg != NULL)
- {
- if ((result =
- _net_nfc_server_handover_convert_ndef_message_to_data(
- msg,
- &context->data)) == NET_NFC_OK)
- {
- context->state = NET_NFC_LLCP_STEP_02;
- }
- else
- {
- DEBUG_ERR_MSG("_net_nfc_server_handover_convert_ndef_"
- "message_to_data failed [%d]",result);
- context->state = NET_NFC_STATE_ERROR;
- context->result = result;
- }
- }
- else
- {
- DEBUG_ERR_MSG("null param, [%d]", result);
- context->state = NET_NFC_STATE_ERROR;
- context->result = result;
- }
-
- _net_nfc_server_handover_client_process(context);
-}
-
-
-////////////////////////////////////////////////////////////////////////////////
-static void _net_nfc_server_handover_client_process(
- net_nfc_handover_context_t *context)
-{
- net_nfc_error_e result;
-
- if (context == NULL)
- {
- return;
- }
-
- switch (context->state)
- {
- case NET_NFC_LLCP_STEP_01 :
- DEBUG_SERVER_MSG("NET_NFC_LLCP_STEP_01");
-
- if ((result = _net_nfc_server_handover_create_requester_carrier_configs(
- context->type,
- _net_nfc_server_handover_client_create_carrier_configs_cb,
- context)) != NET_NFC_OK)
- {
- DEBUG_ERR_MSG("_net_nfc_server_handover_create_requester"
- "_carrier_configs failed [%d]",result);
- }
- break;
-
- case NET_NFC_LLCP_STEP_02 :
- DEBUG_SERVER_MSG("NET_NFC_LLCP_STEP_02");
-
- /* send request */
- net_nfc_server_llcp_simple_send(
- context->handle,
- context->socket,
- &context->data,
- _net_nfc_server_handover_client_send_cb,
- context);
- break;
-
- case NET_NFC_LLCP_STEP_03 :
- DEBUG_SERVER_MSG("NET_NFC_LLCP_STEP_03");
-
- /* receive response */
- net_nfc_server_llcp_simple_receive(context->handle,
- context->socket,
- _net_nfc_server_handover_client_recv_cb,
- context);
- break;
-
- case NET_NFC_LLCP_STEP_04 :
- DEBUG_SERVER_MSG("NET_NFC_LLCP_STEP_04");
-
- result = _net_nfc_server_handover_process_carrier_record(
- context->record,
- _net_nfc_server_handover_client_process_carrier_record_cb,
- context);
-
- if (result != NET_NFC_OK)
- {
- DEBUG_ERR_MSG("_net_nfc_server_handover_process_carrier_record"
- "failed [%d]",result);
- }
- break;
-
- case NET_NFC_LLCP_STEP_05 :
- DEBUG_SERVER_MSG("NET_NFC_LLCP_STEP_05");
-
- /* start post process */
- if (context->type == NET_NFC_CONN_HANDOVER_CARRIER_BT)
- {
- net_nfc_server_handover_bt_post_process(
- &context->data,
- _net_nfc_server_handover_client_post_process_cb,
- context);
- }
- else
- {
- DEBUG_ERR_MSG("not supported...");
- }
- break;
-
- case NET_NFC_LLCP_STEP_RETURN :
- DEBUG_SERVER_MSG("NET_NFC_LLCP_STEP_RETURN");
-
- /* complete and invoke callback */
- _net_nfc_server_handover_send_response(
- context->user_param,
- &context->data,
- context->result);
-
- net_nfc_util_free_data(&context->data);
- net_nfc_util_free_record(context->record);
- _net_nfc_util_free_mem(context);
- break;
-
- case NET_NFC_STATE_ERROR :
- default :
- DEBUG_ERR_MSG("NET_NFC_STATE_ERROR");
-
- _net_nfc_server_handover_send_response(
- context->user_param,
- NULL,
- context->result);
- break;
- }
-}
-
-
-
-static void _net_nfc_server_handover_client_connected_cb(
- net_nfc_error_e result,
- net_nfc_target_handle_s *handle,
- net_nfc_llcp_socket_t socket,
- data_s *data,
- void *user_param)
-{
- DEBUG_SERVER_MSG("result [%d], socket [%x], user_param [%p]",
- result, socket, user_param);
-
- if (result == NET_NFC_OK)
- {
- net_nfc_handover_context_t *context = NULL;
- _net_nfc_util_alloc_mem(context, sizeof(*context));
-
- if (context != NULL)
- {
- context->handle = handle;
- context->socket = socket;
- context->state = NET_NFC_LLCP_STEP_01;
- context->user_param = user_param;
- _net_nfc_server_handover_client_process(context);
- }
- else
- {
- DEBUG_ERR_MSG("_net_nfc_util_alloc_mem failed");
- result = NET_NFC_ALLOC_FAIL;
- }
- }
- else
- {
- DEBUG_ERR_MSG("net_nfc_server_llcp_simple_client"
- " failed, [%d]", result);
- }
-}
-
-static void _net_nfc_server_handover_client_error_cb(
- net_nfc_error_e result,
- net_nfc_target_handle_s *handle,
- net_nfc_llcp_socket_t socket,
- data_s *data,
- void *user_param)
-{
-
- DEBUG_ERR_MSG("result [%d], socket [%x], user_param [%p]",
- result, socket, user_param);
-
- if (false)
- {
- _net_nfc_server_handover_send_response(user_param, NULL, result);
- }
-
- net_nfc_controller_llcp_socket_close(socket, &result);
-}
-
-
-net_nfc_error_e net_nfc_server_handover_default_client_start(
- net_nfc_target_handle_s *handle,
- void *user_data)
-{
- net_nfc_error_e result;
-
- result = net_nfc_server_llcp_simple_client(
- handle,
- CH_SAN,
- CH_SAP,
- _net_nfc_server_handover_client_connected_cb,
- _net_nfc_server_handover_client_error_cb,
- user_data);
-
- if (result != NET_NFC_OK)
- {
- DEBUG_ERR_MSG("net_nfc_server_llcp_simple_client"
- " failed, [%d]",result);
- }
-
- return result;
-}
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#include <arpa/inet.h>
-
-#include "net_nfc_server_p2p.h"
-#include "net_nfc_server_llcp.h"
-
-#include "net_nfc_server_process_npp.h"
-
-#include "net_nfc_controller_internal.h"
-#include "net_nfc_app_util_internal.h"
-#include "net_nfc_debug_internal.h"
-
-typedef struct _net_nfc_npp_entity_t
-{
- uint8_t op;
- uint32_t length;
- uint8_t data[0];
-}
-__attribute__ ((packed)) net_nfc_npp_entity_t;
-
-typedef struct _net_nfc_npp_msg_t
-{
- uint8_t version;
- uint32_t entity_count;
- net_nfc_npp_entity_t entity[0];
-}
-__attribute__ ((packed)) net_nfc_npp_msg_t;
-
-typedef struct _NppData NppData;
-
-struct _NppData
-{
- net_nfc_target_handle_s *handle;
- net_nfc_llcp_socket_t socket;
- uint32_t type;
- data_s data;
- net_nfc_server_npp_callback callback;
- gpointer user_data;
-};
-
-typedef struct _NppClientStartData NppClientStartData;
-
-struct _NppClientStartData
-{
- net_nfc_target_handle_s *handle;
- int client;
- gpointer user_data;
-};
-
-#define NPP_SAN "com.android.npp"
-#define NPP_SAP 0x10
-
-#define NPP_HEADER_LEN (sizeof(net_nfc_npp_msg_t))
-#define NPP_ENTITY_HEADER_LEN (sizeof(net_nfc_npp_entity_t))
-
-#define NPP_MAJOR_VER 0
-#define NPP_MINOR_VER 1
-#define NPP_VERSION ((NPP_MAJOR_VER << 4) | NPP_MINOR_VER)
-
-#define NPP_NDEF_ENTRY 0x00000001
-#define NPP_ACTION_CODE 0x01
-
-static net_nfc_error_e npp_create_message(data_s *data,
- data_s *message);
-
-/* server */
-static void npp_server_receive_cb(net_nfc_error_e result,
- net_nfc_target_handle_s *handle,
- net_nfc_llcp_socket_t socket,
- data_s *data,
- gpointer user_data);
-
-static void npp_server_process(NppData *npp_data);
-
-static void npp_listen_cb(net_nfc_error_e result,
- net_nfc_target_handle_s *handle,
- net_nfc_llcp_socket_t socket,
- data_s *data,
- gpointer user_data);
-
-/* client */
-static void npp_client_disconnected_cb(net_nfc_llcp_socket_t socket,
- net_nfc_error_e result,
- data_s *data,
- void *extra,
- void *user_param);
-
-static void npp_client_send_cb(net_nfc_error_e result,
- net_nfc_target_handle_s *handle,
- net_nfc_llcp_socket_t socket,
- data_s *data,
- gpointer user_data);
-
-static void npp_client_process(NppData *npp_data);
-
-static void npp_connected_cb(net_nfc_error_e result,
- net_nfc_target_handle_s *handle,
- net_nfc_llcp_socket_t socket,
- data_s *data,
- gpointer user_data);
-
-static void npp_socket_error_cb(net_nfc_error_e result,
- net_nfc_target_handle_s *handle,
- net_nfc_llcp_socket_t socket,
- data_s *data,
- gpointer user_data);
-
-static void npp_default_server_cb(net_nfc_error_e result,
- data_s *data,
- gpointer user_data);
-
-static void npp_default_client_cb(net_nfc_error_e result,
- data_s *data,
- gpointer user_data);
-
-static net_nfc_error_e npp_create_message(data_s *data,
- data_s *message)
-{
- uint32_t length = NPP_HEADER_LEN;
- net_nfc_npp_msg_t *msg;
-
- if (data != NULL)
- length += NPP_ENTITY_HEADER_LEN + data->length;
-
- message->buffer = g_new0(uint8_t, length);
- message->length = length;
-
- msg = (net_nfc_npp_msg_t *)message->buffer;
- msg->version = NPP_VERSION;
-
- if (data != NULL)
- {
- net_nfc_npp_entity_t *entity;
-
- DEBUG_SERVER_MSG("data->length [%d]", data->length);
-
- msg->entity_count = htonl(1);
-
- entity = msg->entity;
-
- entity->op = NPP_ACTION_CODE;
- entity->length = htonl(data->length);
- /* copy ndef information to response msg */
- memcpy(entity->data, data->buffer, data->length);
- }
- else
- {
- msg->entity_count = 0;
- }
-
- return NET_NFC_OK;
-}
-
-static void npp_server_receive_cb(net_nfc_error_e result,
- net_nfc_target_handle_s *handle,
- net_nfc_llcp_socket_t socket,
- data_s *data,
- gpointer user_data)
-{
- NppData *npp_data;
-
- net_nfc_npp_msg_t *message;
- net_nfc_npp_entity_t *entity;
-
- data_s ndef_msg = { NULL, 0 };
-
- uint32_t length;
- uint32_t entity_count;
- uint32_t i;
-
- npp_data = (NppData *)user_data;
-
- if (npp_data == NULL)
- return;
-
- if (result != NET_NFC_OK)
- {
- DEBUG_ERR_MSG("error [%d]", result);
-
- if(npp_data->callback)
- npp_data->callback(result, NULL, npp_data->user_data);
-
- g_free(npp_data);
- return;
- }
-
- if (data == NULL)
- {
- DEBUG_ERR_MSG("data is NULL");
-
- if(npp_data->callback)
- {
- npp_data->callback(NET_NFC_INVALID_PARAM,
- NULL,
- npp_data->user_data);
- }
-
- g_free(npp_data);
- return;
- }
-
- if (data->buffer == NULL || data->length == 0)
- {
- DEBUG_ERR_MSG("Wrong data");
-
- if(npp_data->callback)
- {
- npp_data->callback(NET_NFC_INVALID_PARAM,
- NULL,
- npp_data->user_data);
- }
-
- g_free(npp_data);
- return;
- }
-
- message = (net_nfc_npp_msg_t *)data->buffer;
-
- if (data->length < NPP_HEADER_LEN)
- {
- DEBUG_ERR_MSG("too short data, length [%d]",
- data->length);
- /* FIXME!!! what should I do. */
- if(npp_data->callback)
- {
- npp_data->callback(NET_NFC_INVALID_PARAM,
- NULL,
- npp_data->user_data);
- }
-
- g_free(npp_data);
- return;
- }
-
- if (GET_MAJOR_VER(message->version) > NPP_MAJOR_VER ||
- GET_MINOR_VER(message->version > NPP_MINOR_VER))
- {
- DEBUG_ERR_MSG("not supported version, version [0x%02x]",
- message->version);
-
- if(npp_data->callback)
- {
- npp_data->callback(NET_NFC_NOT_SUPPORTED,
- NULL,
- npp_data->user_data);
- }
-
- g_free(npp_data);
- return;
- }
-
- entity_count = htonl(message->entity_count);
-
- if (entity_count > NPP_NDEF_ENTRY)
- {
- DEBUG_ERR_MSG("too many entities, [%d]",
- message->entity_count);
-
- if(npp_data->callback)
- {
- npp_data->callback(NET_NFC_INVALID_PARAM,
- NULL,
- npp_data->user_data);
- }
-
- g_free(npp_data);
- return;
- }
-
- for (i = 0; i < entity_count; i++)
- {
- entity = (message->entity + i);
-
- if (entity->op != NPP_ACTION_CODE) {
- DEBUG_ERR_MSG("not supported action code, [0x%02x]",
- entity->op);
-
- if(npp_data->callback)
- {
- npp_data->callback(NET_NFC_INVALID_PARAM,
- NULL,
- npp_data->user_data);
- }
-
- g_free(npp_data);
- return;
- }
-
- length = htonl(entity->length);
-
- DEBUG_SERVER_MSG("action code [0x%02x], length [%d]",
- entity->op, length);
-
- if (length > 0)
- {
- /* buffer create */
- ndef_msg.buffer = g_new0(uint8_t, length);
- ndef_msg.length = length;
-
- memcpy(ndef_msg.buffer, entity->data, length);
- }
- }
-
- if (npp_data->callback)
- npp_data->callback(result, &ndef_msg, npp_data->user_data);
-
- g_free(ndef_msg.buffer);
- g_free(npp_data);
-}
-
-
-static void npp_server_process(NppData *npp_data)
-{
- net_nfc_error_e result;
- if (npp_data == NULL)
- return;
-
- /* receive request */
- result = net_nfc_server_llcp_simple_receive(npp_data->handle,
- npp_data->socket,
- npp_server_receive_cb,
- npp_data);
- if (result != NET_NFC_OK)
- {
- if (npp_data->callback)
- npp_data->callback(result, NULL, npp_data->user_data);
-
- g_free(npp_data);
- }
-}
-
-static void npp_listen_cb(net_nfc_error_e result,
- net_nfc_target_handle_s *handle,
- net_nfc_llcp_socket_t socket,
- data_s *data,
- gpointer user_data)
-{
- NppData *npp_data;
- NppData *accept_data;
-
- npp_data = (NppData *)user_data;
- if (npp_data == NULL)
- return;
-
- DEBUG_SERVER_MSG("npp_listen_cb, incoming socket [%#x], result [%d]",
- socket, result);
-
- if (result != NET_NFC_OK)
- {
- DEBUG_ERR_MSG("listen failed [%d]", result);
-
- if (npp_data->callback)
- npp_data->callback(result, NULL, npp_data->user_data);
-
- g_free(npp_data);
- return;
- }
-
- /* start npp server */
- accept_data = g_new0(NppData, 1);
-
- accept_data->handle = npp_data->handle;
- accept_data->socket = socket;
- accept_data->callback = npp_data->callback;
- accept_data->user_data = npp_data->user_data;
-
- result = net_nfc_server_llcp_simple_accept(handle,
- socket,
- npp_socket_error_cb,
- accept_data);
- if (result != NET_NFC_OK)
- {
- DEBUG_ERR_MSG("%s failed",
- "net_nfc_server_llcp_simple_accept");
-
- if (npp_data->callback)
- npp_data->callback(result, NULL, npp_data->user_data);
-
- g_free(npp_data);
- g_free(accept_data);
-
- return;
- }
-
- DEBUG_SERVER_MSG("socket [%x] accepted.. waiting for request message",
- socket);
-
- npp_server_process(accept_data);
- g_free(npp_data);
-}
-
-/* client */
-static void npp_client_disconnected_cb(net_nfc_llcp_socket_t socket,
- net_nfc_error_e result,
- data_s *data,
- void *extra,
- void *user_param)
-{
- DEBUG_SERVER_MSG("disconnected! [%d]", result);
-}
-
-static void npp_client_send_cb(net_nfc_error_e result,
- net_nfc_target_handle_s *handle,
- net_nfc_llcp_socket_t socket,
- data_s *data,
- gpointer user_data)
-{
- NppData *npp_data;
-
- npp_data = (NppData *)user_data;
- if (npp_data == NULL)
- return;
-
- DEBUG_SERVER_MSG("send complete... [%d]", result);
-
- if (npp_data->callback)
- {
- npp_data->callback(result, NULL, npp_data->user_data);
- }
-
- net_nfc_controller_llcp_disconnect(npp_data->handle,
- npp_data->socket,
- &result,
- npp_client_disconnected_cb,
- NULL);
-
- g_free(npp_data->data.buffer);
- g_free(npp_data);
-
-}
-
-static void npp_client_process(NppData *npp_data)
-{
- net_nfc_error_e result;
- data_s data;
-
- if (npp_data == NULL)
- return;
-
- result = npp_create_message(&npp_data->data, &data);
- if (result != NET_NFC_OK)
- {
- DEBUG_ERR_MSG("%s failed [%d]", "npp_create_message", result);
-
- if (npp_data->callback)
- npp_data->callback(result, NULL, npp_data->user_data);
-
- g_free(npp_data->data.buffer);
- g_free(npp_data);
-
- return;
- }
-
- /* send request */
- result = net_nfc_server_llcp_simple_send(npp_data->handle,
- npp_data->socket,
- &data,
- npp_client_send_cb,
- npp_data);
- if (result != NET_NFC_OK)
- {
- DEBUG_ERR_MSG("%s failed [%d]",
- "net_nfc_server_llcp_simple_send",
- result);
-
- if (npp_data->callback)
- npp_data->callback(result, NULL, npp_data->user_data);
-
- g_free(npp_data->data.buffer);
- g_free(npp_data);
-
- }
-
- g_free(data.buffer);
-}
-
-static void npp_connected_cb(net_nfc_error_e result,
- net_nfc_target_handle_s *handle,
- net_nfc_llcp_socket_t socket,
- data_s *data,
- gpointer user_data)
-{
- NppData *npp_data;
-
- npp_data = (NppData *)user_data;
- if (npp_data == NULL)
- return;
-
- if (result != NET_NFC_OK)
- {
- DEBUG_ERR_MSG("connect socket failed, [%d]", result);
-
- if (npp_data->callback)
- npp_data->callback(result, NULL, npp_data->user_data);
-
- g_free(npp_data->data.buffer);
- g_free(npp_data);
-
- return;
- }
-
- /*start npp client */
- DEBUG_SERVER_MSG("socket [%x] connected, send request message.",
- socket);
- npp_data->socket = socket;
-
- npp_client_process(npp_data);
- return;
-}
-
-static void npp_socket_error_cb(net_nfc_error_e result,
- net_nfc_target_handle_s *handle,
- net_nfc_llcp_socket_t socket,
- data_s *data,
- gpointer user_data)
-{
- NppData *npp_data;
-
- DEBUG_SERVER_MSG("socket [%x], result [%d]", socket, result);
-
- npp_data = (NppData *)user_data;
- if (npp_data == NULL)
- return;
-
- if (npp_data->callback)
- npp_data->callback(result, NULL, npp_data->user_data);
-
- g_free(npp_data->data.buffer);
- g_free(npp_data);
-}
-
-static void npp_default_server_cb(net_nfc_error_e result,
- data_s *data,
- gpointer user_data)
-{
- DEBUG_SERVER_MSG("result [%d], data [%p], user_data [%p]",
- result, data, user_data);
-
- if (data == NULL)
- {
- DEBUG_ERR_MSG("npp server receive failed, [%d]", result);
- return;
- }
-
- if (data->buffer == NULL)
- {
- DEBUG_ERR_MSG("npp server receive failed, [%d]", result);
- return;
- }
-
- net_nfc_server_p2p_received(data);
- net_nfc_app_util_process_ndef(data);
-}
-
-static void npp_default_client_cb(net_nfc_error_e result,
- data_s *data,
- gpointer user_data)
-{
- NppClientStartData *npp_client_data;
-
- DEBUG_SERVER_MSG("result [%d], data [%p], user_data [%p]",
- result, data, user_data);
-
- if (user_data == NULL)
- return;
-
- npp_client_data = (NppClientStartData *)user_data;
-
- net_nfc_server_p2p_data_sent(result, npp_client_data->user_data);
-
- g_free(npp_client_data);
-}
-
-/* public apis */
-net_nfc_error_e net_nfc_server_npp_server(net_nfc_target_handle_s *handle,
- char *san,
- sap_t sap,
- net_nfc_server_npp_callback callback,
- gpointer user_data)
-{
- net_nfc_error_e result = NET_NFC_OK;
-
- NppData *npp_data = NULL;
-
- if (handle == NULL)
- {
- DEBUG_ERR_MSG("handle is NULL");
- return FALSE;
- }
-
- if (san == NULL)
- {
- DEBUG_ERR_MSG("san is NULL");
- return FALSE;
- }
-
- npp_data = g_new0(NppData, 1);
-
- npp_data->handle = handle;
- npp_data->callback = callback;
- npp_data->user_data = user_data;
-
- result = net_nfc_server_llcp_simple_server(handle,
- san,
- sap,
- npp_listen_cb,
- npp_socket_error_cb,
- npp_data);
- if (result != NET_NFC_OK)
- {
- DEBUG_ERR_MSG("%s failed",
- "net_nfc_server_llcp_simple_server");
-
- if (npp_data->callback)
- npp_data->callback(result, NULL, npp_data->user_data);
-
- g_free(npp_data);
-
- return FALSE;
- }
-
- DEBUG_SERVER_MSG("start npp server, san [%s], sap [%d]", san, sap);
-
- return result;
-}
-
-net_nfc_error_e net_nfc_server_npp_client(net_nfc_target_handle_s *handle,
- char *san,
- sap_t sap,
- data_s *data,
- net_nfc_server_npp_callback callback,
- gpointer user_data)
-{
- net_nfc_error_e result = NET_NFC_OK;;
- net_nfc_llcp_config_info_s config;
-
- NppData *npp_data;
-
- if (handle == NULL)
- {
- DEBUG_ERR_MSG("handle is NULL");
- return NET_NFC_NULL_PARAMETER;
- }
-
- if(net_nfc_controller_llcp_get_remote_config(handle,
- &config,
- &result) == false)
- {
- DEBUG_ERR_MSG("%s failed [%d]",
- "net_nfc_controller_llcp_get_remote_config",
- result);
-
- return result;
- }
-
- if (config.miu <
- data->length + NPP_HEADER_LEN + NPP_ENTITY_HEADER_LEN)
- {
- DEBUG_ERR_MSG("too large message, max [%d], request [%d]",
- config.miu - (NPP_HEADER_LEN + NPP_ENTITY_HEADER_LEN),
- data->length);
-
- return NET_NFC_INSUFFICIENT_STORAGE;
- }
-
- npp_data = g_new0(NppData, 1);
-
- npp_data->handle = handle;
- npp_data->callback = callback;
- npp_data->user_data = user_data;
-
- npp_data->data.buffer = g_new0(uint8_t, data->length);
- npp_data->data.length = data->length;
-
- result = net_nfc_server_llcp_simple_client(handle,
- san,
- sap,
- npp_connected_cb,
- npp_socket_error_cb,
- npp_data);
- if (result != NET_NFC_OK)
- {
- DEBUG_ERR_MSG("%s failed",
- "net_nfc_server_llcp_simple_client");
-
- if (npp_data->callback)
- {
- npp_data->callback(NET_NFC_UNKNOWN_ERROR,
- NULL,
- npp_data->user_data);
- }
-
- g_free(npp_data->data.buffer);
- g_free(npp_data);
-
- return result;
- }
-
- if (san != NULL)
- {
- DEBUG_SERVER_MSG("start npp client, san [%s], result [%d]",
- san, result);
- }
- else
- {
- DEBUG_SERVER_MSG("start npp client, sap [%d], result [%d]",
- sap, result);
- }
-
- return result;
-}
-
-net_nfc_error_e net_nfc_server_npp_default_server_start(
- net_nfc_target_handle_s *handle)
-{
- /* start default npp server */
- return net_nfc_server_npp_server(handle,
- NPP_SAN,
- NPP_SAP,
- npp_default_server_cb,
- (gpointer)1234);
-}
-
-static void _npp_default_activate_cb(int event,
- net_nfc_target_handle_s *handle,
- uint32_t sap, const char *san, void *user_param)
-{
- net_nfc_error_e result;
-
- DEBUG_SERVER_MSG("event [%d], handle [%p], sap [%d], san [%s]",
- event, handle, sap, san);
-
- if (event == NET_NFC_LLCP_START) {
- /* start default npp server */
- result = net_nfc_server_npp_server(handle, (char *)san, sap,
- npp_default_server_cb, user_param);
- if (result != NET_NFC_OK) {
- DEBUG_ERR_MSG("net_nfc_server_npp_server failed, [%d]",
- result);
- }
- } else if (event == NET_NFC_LLCP_UNREGISTERED) {
- /* unregister server, do nothing */
- }
-}
-
-net_nfc_error_e net_nfc_server_npp_default_server_register()
-{
- char id[20];
-
- /* TODO : make id, */
- snprintf(id, sizeof(id), "%d", getpid());
-
- /* start default npp server */
- return net_nfc_server_llcp_register_service(id,
- NPP_SAP,
- NPP_SAN,
- _npp_default_activate_cb,
- NULL);
-}
-
-net_nfc_error_e net_nfc_server_npp_default_server_unregister()
-{
- char id[20];
-
- /* TODO : make id, */
- snprintf(id, sizeof(id), "%d", getpid());
-
- /* start default npp server */
- return net_nfc_server_llcp_unregister_service(id,
- NPP_SAP,
- NPP_SAN);
-}
-
-net_nfc_error_e net_nfc_server_npp_default_client_start(
- net_nfc_target_handle_s *handle,
- data_s *data,
- int client,
- gpointer user_data)
-{
- NppClientStartData *npp_client_data;
-
- net_nfc_error_e result = NET_NFC_OK;
-
- if (handle == NULL)
- {
- DEBUG_ERR_MSG("handle is NULL");
- return NET_NFC_NULL_PARAMETER;
- }
-
- if (data == NULL)
- {
- DEBUG_ERR_MSG("data is NULL");
- return NET_NFC_NULL_PARAMETER;
- }
-
- if (data->buffer == NULL)
- {
- DEBUG_ERR_MSG("data->buffer is NULL");
- return NET_NFC_NULL_PARAMETER;
- }
-
- npp_client_data = g_new0(NppClientStartData, 1);
-
- npp_client_data->handle = handle;
- npp_client_data->client = client;
- npp_client_data->user_data = user_data;
-
- result = net_nfc_server_npp_client(handle,
- NPP_SAN,
- NPP_SAP,
- data,
- npp_default_client_cb,
- npp_client_data);
-
- if (result != NET_NFC_OK)
- {
- DEBUG_ERR_MSG("net_nfc_server_client failed");
- g_free(npp_client_data);
- }
-
- return result;
-}
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <glib.h>
-#include "net_nfc_server_p2p.h"
-#include "net_nfc_debug_internal.h"
-#include "net_nfc_util_defines.h"
-#include "net_nfc_util_internal.h"
-#include "net_nfc_server_llcp.h"
-#include "net_nfc_controller_internal.h"
-#include "net_nfc_server_snep.h"
-#include "net_nfc_server_process_snep.h"
-#include "net_nfc_app_util_internal.h"
-#include "net_nfc_util_gdbus_internal.h"
-
-
-typedef struct _net_nfc_server_snep_msg_t
-{
- uint8_t version;
- uint8_t op;
- uint32_t length;
- uint8_t data[0];
-}
-__attribute__ ((packed)) net_nfc_server_snep_msg_t;
-
-typedef struct _net_nfc_server_snep_get_msg_t
-{
- uint32_t length;
- uint8_t data[0];
-}
-__attribute__ ((packed)) net_nfc_server_snep_get_msg_t;
-
-typedef struct _net_nfc_server_cb_data_t
-{
- net_nfc_server_snep_listen_cb cb;
- void *user_param;
-}
-net_nfc_server_cb_data_t;
-
-typedef struct _net_nfc_server_snep_context_t
-{
- net_nfc_target_handle_s *handle;
- net_nfc_error_e result;
- net_nfc_llcp_socket_t socket;
- uint32_t state;
- uint32_t type;
- data_s data;
- net_nfc_server_snep_cb cb;
- void *user_param;
- GQueue queue;
-}
-net_nfc_server_snep_context_t;
-
-typedef struct _net_nfc_server_snep_job_t
-{
- net_nfc_server_snep_context_t *context;
- net_nfc_target_handle_s *handle;
- net_nfc_error_e result;
- net_nfc_llcp_socket_t socket;
- uint32_t state;
- uint32_t type;
- data_s data;
- net_nfc_server_snep_cb cb;
- void *user_param;
-}
-net_nfc_server_snep_job_t;
-
-
-typedef struct __net_nfc_server_snep_server_context_t
-{
- net_nfc_target_handle_s *handle;
- int client;
- void *user_param;
-}
-_net_nfc_server_snep_server_context_t;
-
-typedef struct __net_nfc_server_snep_service_context_t
-{
- net_nfc_target_handle_s *handle;
- int client;
- uint32_t type;
- data_s data;
- void *user_param;
-}
-_net_nfc_server_snep_service_context_t;
-
-typedef void (*_net_nfc_server_snep_operation_cb)(
- net_nfc_error_e result,
- uint32_t type,
- data_s *data,
- void *user_param);
-
-typedef struct _net_nfc_server_snep_op_context_t
-{
- net_nfc_target_handle_s *handle;
- net_nfc_error_e result;
- int socket;
- uint32_t state;
- uint32_t type;
- uint32_t current;
- uint16_t miu;
- data_s data;
- uint32_t offset;
- _net_nfc_server_snep_operation_cb cb;
- void *user_param;
-}
-
-net_nfc_server_snep_op_context_t;
-
-#define SNEP_MAJOR_VER 1
-#define SNEP_MINOR_VER 0
-#define SNEP_VERSION ((SNEP_MAJOR_VER << 4) | SNEP_MINOR_VER)
-
-#define SNEP_HEADER_LEN (sizeof(net_nfc_server_snep_msg_t))
-#define SNEP_MAX_LEN (SNEP_HEADER_LEN + 1024 * 10)
-
-#define SNEP_REQUEST (0)
-#define SNEP_RESPONSE (0x80)
-
-#define SNEP_PAIR_OP(__x) ((__x) ^ SNEP_RESPONSE)
-#define SNEP_MAKE_PAIR_OP(__x, __y) ((SNEP_PAIR_OP(__x) & SNEP_RESPONSE) | (__y))
-
-#define IS_SNEP_REQ(__x) (((__x) & SNEP_RESPONSE) == SNEP_REQUEST)
-#define IS_SNEP_RES(__x) (((__x) & SNEP_RESPONSE) == SNEP_RESPONSE)
-
-static GList *list_listen_cb = NULL;
-
-static void _net_nfc_server_snep_recv(
- net_nfc_server_snep_op_context_t *context);
-
-static void _net_nfc_server_snep_send(
- net_nfc_server_snep_op_context_t *context);
-
-static net_nfc_error_e net_nfc_server_snep_recv(
- net_nfc_target_handle_s *handle,
- net_nfc_llcp_socket_t socket,
- _net_nfc_server_snep_operation_cb cb,
- void *user_param);
-
-static net_nfc_error_e net_nfc_server_snep_send(
- net_nfc_target_handle_s *handle,
- net_nfc_llcp_socket_t socket,
- uint32_t type,
- data_s *data,
- _net_nfc_server_snep_operation_cb cb,
- void *user_param);
-
-
-static void _net_nfc_server_snep_client_process(
- net_nfc_server_snep_job_t *job);
-
-static void _net_nfc_server_snep_server_process(
- net_nfc_server_snep_context_t *context);
-
-/**********************************************************************/
-static bool _net_nfc_server_snep_add_get_response_cb(
- net_nfc_server_snep_listen_cb cb,
- void *user_param)
-{
- net_nfc_server_cb_data_t *data = NULL;
- bool result = false;
-
- _net_nfc_util_alloc_mem(data, sizeof(*data));
- if (data != NULL)
- {
- data->cb = cb;
- data->user_param = user_param;
-
- list_listen_cb = g_list_append(list_listen_cb, data);
- if (list_listen_cb != NULL)
- {
- result = true;
- }
- else
- {
- DEBUG_ERR_MSG("g_list_append failed");
- }
- }
- else
- {
- DEBUG_ERR_MSG("_net_nfc_util_alloc_mem failed");
- }
-
- return result;
-}
-
-static gint _net_nfc_server_snep_compare_func_cb(
- gconstpointer a,
- gconstpointer b)
-{
- net_nfc_server_cb_data_t *data = (net_nfc_server_cb_data_t *)a;
-
- if (data->cb == (void *)b)
- return 0;
- else
- return 1;
-}
-
-static void _net_nfc_server_snep_del_get_response_cb(
- net_nfc_server_snep_listen_cb cb)
-{
- GList *list;
-
- list = g_list_find_custom(list_listen_cb,
- cb,
- _net_nfc_server_snep_compare_func_cb);
-
- if (list != NULL)
- list_listen_cb = g_list_delete_link(list_listen_cb, list);
-}
-
-static bool _net_nfc_server_snep_process_get_response_cb(
- net_nfc_target_handle_s *handle,
- data_s *data,
- uint32_t max_len)
-{
- GList *list = list_listen_cb;
-
- while (list != NULL && list->data != NULL)
- {
- net_nfc_server_cb_data_t *cb_data =
- (net_nfc_server_cb_data_t *)list->data;
-
- if (cb_data->cb != NULL)
- {
- DEBUG_SERVER_MSG("invoke callback [%p]", cb_data->cb);
- if (cb_data->cb(handle,
- SNEP_REQ_GET,
- max_len,
- data,
- cb_data->user_param) == true)
- return true;
- }
- }
-
- return false;
-}
-
-static net_nfc_server_snep_op_context_t *
-_net_nfc_server_snep_create_send_context(uint32_t type,
- net_nfc_target_handle_s *handle,
- net_nfc_llcp_socket_t socket,
- data_s *data,
- void *cb,
- void *user_param)
-{
- net_nfc_server_snep_op_context_t *context = NULL;
- uint32_t data_len = 0;
- net_nfc_server_snep_msg_t *msg;
- net_nfc_llcp_config_info_s config;
- net_nfc_error_e result;
-
- if (net_nfc_controller_llcp_get_remote_config(handle,
- &config, &result) == false)
- {
- DEBUG_ERR_MSG("net_nfc_controller_llcp_get_remote_config failed, [%d]",
- result);
-
- return NULL;
- }
-
- _net_nfc_util_alloc_mem(context, sizeof(*context));
- if (context == NULL)
- {
- return NULL;
- }
-
- if (type == SNEP_REQ_GET)
- {
- data_len = sizeof(net_nfc_server_snep_msg_t);
- }
-
- if (data != NULL)
- {
- data_len += data->length;
- }
-
- net_nfc_util_alloc_data(&context->data, SNEP_HEADER_LEN + data_len);
- if (context->data.buffer == NULL)
- {
- _net_nfc_util_free_mem(context);
- return NULL;
- }
-
- msg = (net_nfc_server_snep_msg_t *)context->data.buffer;
-
- msg->version = SNEP_VERSION;
- msg->op = type;
-
- if (data_len > 0)
- {
- uint8_t *buffer;
-
- msg->length = htonl(data_len);
-
- if (type == SNEP_REQ_GET)
- {
- net_nfc_server_snep_msg_t *get_msg =
- (net_nfc_server_snep_msg_t *)msg->data;
-
- get_msg->length = htonl(SNEP_MAX_LEN);
- buffer = get_msg->data;
- }
- else
- {
- buffer = msg->data;
- }
-
- if (data != NULL && data->buffer != NULL)
- {
- DEBUG_SERVER_MSG("data->length [%d]", data->length);
-
- /* copy ndef information to response msg */
- memcpy(buffer, data->buffer, data->length);
- }
- }
-
- context->handle = handle;
- context->type = type;
- context->state = NET_NFC_LLCP_STEP_01;
- context->socket = socket;
- context->cb = cb;
- context->user_param = user_param;
- context->miu = MIN(config.miu, net_nfc_server_llcp_get_miu());
-
- return context;
-}
-
-static net_nfc_server_snep_op_context_t *
-_net_nfc_server_snep_create_recv_context(
- net_nfc_target_handle_s *handle,
- net_nfc_llcp_socket_t socket,
- void *cb,
- void *user_param)
-{
- net_nfc_server_snep_op_context_t *context = NULL;
- net_nfc_llcp_config_info_s config;
- net_nfc_error_e result;
-
- if (net_nfc_controller_llcp_get_remote_config(handle,
- &config,
- &result) == false)
- {
- DEBUG_ERR_MSG("net_nfc_controller_llcp_get_remote_config failed, [%d]",
- result);
- return NULL;
- }
-
- _net_nfc_util_alloc_mem(context, sizeof(*context));
-
- if (context == NULL)
- return NULL;
-
- context->handle = handle;
- context->state = NET_NFC_LLCP_STEP_01;
- context->socket = socket;
- context->cb = cb;
- context->user_param = user_param;
- context->miu = MIN(config.miu, net_nfc_server_llcp_get_miu());
-
- return context;
-}
-
-static void _net_nfc_server_snep_destory_context(
- net_nfc_server_snep_op_context_t *context)
-{
- if (context != NULL)
- {
- if (context->data.buffer != NULL)
- net_nfc_util_free_data(&context->data);
-
- _net_nfc_util_free_mem(context);
- }
-}
-
-static void _net_nfc_server_recv_fragment_cb(
- net_nfc_llcp_socket_t socket,
- net_nfc_error_e result,
- data_s *data,
- void *extra,
- void *user_param)
-{
- net_nfc_server_snep_op_context_t *context =
- (net_nfc_server_snep_op_context_t *)user_param;
- uint8_t *buffer;
- uint32_t length;
-
- DEBUG_SERVER_MSG("_net_nfc_server_recv_fragment_cb,"
- " socket [%x], result [%d]",socket, result);
-
- if (context == NULL)
- return;
-
- context->result = result;
-
- if (result != NET_NFC_OK)
- {
- DEBUG_ERR_MSG("error [%d]", result);
- context->state = NET_NFC_STATE_ERROR;
- goto END;
- }
-
- if (data == NULL || data->buffer == NULL || data->length == 0)
- {
- DEBUG_ERR_MSG("invalid response");
- context->state = NET_NFC_STATE_ERROR;
- goto END;
- }
-
- if (context->state == NET_NFC_LLCP_STEP_01)
- {
- net_nfc_server_snep_msg_t *msg =
- (net_nfc_server_snep_msg_t *)data->buffer;
-
- if (data->length < SNEP_HEADER_LEN)
- {
- DEBUG_ERR_MSG("too short data, length [%d]",
- data->length);
- /* FIXME!!! what should I do. */
- context->type = SNEP_RESP_BAD_REQ;
- context->state = NET_NFC_STATE_ERROR;
- context->result = NET_NFC_BUFFER_TOO_SMALL;
- goto END;
- }
-
- length = htonl(msg->length);
-
- if (length > SNEP_MAX_LEN)
- {
- DEBUG_ERR_MSG("too long snep message, length [%d]",
- length);
- if (IS_SNEP_REQ(msg->op))
- {
- context->type = SNEP_RESP_EXCESS_DATA;
- }
- else
- {
- context->type = SNEP_REQ_REJECT;
- }
- context->state = NET_NFC_LLCP_STEP_04;
- context->result = NET_NFC_INSUFFICIENT_STORAGE;
- goto END;
- }
-
- if (IS_SNEP_REQ(msg->op) &&
- GET_MAJOR_VER(msg->version) > SNEP_MAJOR_VER)
- {
- DEBUG_ERR_MSG("not supported version, version [0x%02x]",
- msg->version);
- context->type = SNEP_RESP_UNSUPPORTED_VER;
- context->state = NET_NFC_LLCP_STEP_04;
- context->result = NET_NFC_NOT_SUPPORTED;
- goto END;
- }
-
- if (length > 0)
- {
- /* buffer create */
- net_nfc_util_alloc_data(&context->data, length);
- if (context->data.buffer == NULL)
- {
- DEBUG_ERR_MSG("net_nfc_util_alloc_data failed");
- if (IS_SNEP_REQ(msg->op))
- {
- context->type = SNEP_RESP_REJECT;
- }
- else
- {
- context->type = SNEP_REQ_REJECT;
- }
- context->state = NET_NFC_LLCP_STEP_04;
- context->result = NET_NFC_ALLOC_FAIL;
- goto END;
- }
- }
-
- DEBUG_SERVER_MSG("incoming message, type [0x%02x], length [%d]",
- msg->op, length);
-
- context->type = msg->op;
- buffer = msg->data;
- length = data->length - SNEP_HEADER_LEN;
- context->state = NET_NFC_LLCP_STEP_02;
- }
- else
- {
- buffer = data->buffer;
- length = data->length;
- context->state = NET_NFC_LLCP_STEP_03;
- }
-
- if (context->data.length > 0)
- {
- /* copy data */
- memcpy(context->data.buffer + context->offset,
- buffer, length);
- context->offset += length;
-
- DEBUG_SERVER_MSG("receive progress... [%d|%d]",
- context->offset, context->data.length);
-
- if (context->offset >= context->data.length)
- context->state = NET_NFC_LLCP_STEP_RETURN;
-
- }
- else
- {
- DEBUG_SERVER_MSG("receive complete... [no ndef message]");
- context->state = NET_NFC_LLCP_STEP_RETURN;
- }
-
-END :
- _net_nfc_server_snep_recv(context);
-}
-
-
-static void _net_nfc_server_recv_fragment(
- net_nfc_server_snep_op_context_t *context)
-{
- net_nfc_error_e result;
-
- DEBUG_SERVER_MSG("socket [%x] waiting data.....", context->socket);
-
- if (net_nfc_controller_llcp_recv(
- context->handle,
- context->socket,
- context->miu,
- &result,
- _net_nfc_server_recv_fragment_cb,
- context) == false)
- {
- DEBUG_ERR_MSG("net_nfc_controller_llcp_recv failed, [%d]", result);
- context->state = NET_NFC_STATE_ERROR;
- context->result = result;
- _net_nfc_server_snep_recv(context);
- }
-}
-
-
-void _net_nfc_server_snep_recv_send_cb(
- net_nfc_error_e result,
- uint32_t type,
- data_s *data,
- void *user_param)
-{
- net_nfc_server_snep_op_context_t *context =
- (net_nfc_server_snep_op_context_t *)user_param;
-
- DEBUG_SERVER_MSG("_net_nfc_server_snep_recv_send_cb, result [%d]", result);
-
- if (context == NULL)/* TODO */
- return;
-
- if (result == NET_NFC_OK)
- context->state = NET_NFC_LLCP_STEP_03;
- else
- {
- DEBUG_ERR_MSG("net_nfc_server_snep_send failed, [0x%x][%d]",
- type, result);
- context->state = NET_NFC_STATE_ERROR;
- context->result = result;
- }
-
- _net_nfc_server_snep_recv(context);
-}
-
-void _net_nfc_server_snep_recv_send_reject_cb(
- net_nfc_error_e result,
- uint32_t type,
- data_s *data,
- void *user_param)
-{
- net_nfc_server_snep_op_context_t *context =
- (net_nfc_server_snep_op_context_t *)user_param;
-
- DEBUG_SERVER_MSG("_net_nfc_server_snep_recv_send_reject_cb,"
- " result [%d]", result);
-
- if (context == NULL)/* TODO */
- return;
-
- context->state = NET_NFC_LLCP_STEP_RETURN;
-
- if (result != NET_NFC_OK)
- {
- DEBUG_ERR_MSG("net_nfc_server_snep_send failed, [0x%x][%d]",
- type, result);
- }
-
- _net_nfc_server_snep_recv(context);
-}
-
-static void _net_nfc_server_snep_recv(
- net_nfc_server_snep_op_context_t *context)
-{
- if (context == NULL)
- return;
-
- switch (context->state)
- {
- case NET_NFC_LLCP_STEP_01 :
- case NET_NFC_LLCP_STEP_03 :
- DEBUG_SERVER_MSG("NET_NFC_LLCP_STEP_%02d",
- context->state - NET_NFC_LLCP_STEP_01 + 1);
-
- /* receive fragment */
- _net_nfc_server_recv_fragment(context);
- break;
-
- case NET_NFC_LLCP_STEP_02 :
- {
- uint8_t op = context->type;
-
- DEBUG_SERVER_MSG("NET_NFC_LLCP_STEP_02");
-
- /* make correct request/response code */
- op = SNEP_MAKE_PAIR_OP(op, SNEP_REQ_CONTINUE);
-
- /* send response */
- net_nfc_server_snep_send(
- context->handle,
- context->socket,
- op,
- NULL,
- _net_nfc_server_snep_recv_send_cb, context);
- }
- break;
-
- case NET_NFC_LLCP_STEP_04 :
- {
- DEBUG_SERVER_MSG("NET_NFC_LLCP_STEP_04");
-
- /* send response */
- net_nfc_server_snep_send(
- context->handle,
- context->socket,
- context->type, NULL,
- _net_nfc_server_snep_recv_send_reject_cb, context);
- }
- break;
-
- case NET_NFC_LLCP_STEP_RETURN :
- {
- DEBUG_SERVER_MSG("NET_NFC_LLCP_STEP_RETURN");
-
- /* complete and invoke callback */
- context->cb(
- context->result,
- context->type,
- &context->data,
- context->user_param);
-
- _net_nfc_server_snep_destory_context(context);
- }
- break;
-
- case NET_NFC_STATE_ERROR :
- default :
- DEBUG_ERR_MSG("NET_NFC_STATE_ERROR");
-
- /* error, invoke callback */
- DEBUG_ERR_MSG("net_nfc_server_snep_recv failed, [%d]",
- context->result);
-
- context->cb(
- context->result,
- context->type,
- NULL,
- context->user_param);
-
- _net_nfc_server_snep_destory_context(context);
-
- break;
- }
-}
-
-static net_nfc_error_e
-net_nfc_server_snep_recv(
- net_nfc_target_handle_s *handle,
- net_nfc_llcp_socket_t socket,
- _net_nfc_server_snep_operation_cb cb,
- void *user_param)
-{
- net_nfc_server_snep_op_context_t *context;
- net_nfc_error_e result = NET_NFC_OK;
-
- /* create context */
- context = _net_nfc_server_snep_create_recv_context(
- handle,
- socket,
- cb,
- user_param);
-
- if (context != NULL)/* send response */
- _net_nfc_server_snep_recv(context);
- else
- result = NET_NFC_ALLOC_FAIL;
-
- return result;
-}
-
-static void _net_nfc_server_send_fragment_cb(
- net_nfc_llcp_socket_t socket,
- net_nfc_error_e result,
- data_s *data,
- void *extra,
- void *user_param)
-{
- net_nfc_server_snep_op_context_t *context =
- (net_nfc_server_snep_op_context_t *)user_param;
-
- DEBUG_SERVER_MSG("_net_nfc_server_send_fragment_cb,"
- " socket [%x], result [%d]",socket, result);
-
- if (context == NULL)
- return;
-
- context->result = result;
-
- if (result == NET_NFC_OK)
- {
- DEBUG_SERVER_MSG("send progress... [%d|%d]",
- context->offset, context->data.length);
- if (context->offset < context->data.length)
- {
- if (context->state == NET_NFC_LLCP_STEP_01)
- {
- /* first fragment */
- context->state = NET_NFC_LLCP_STEP_02;
- }
- else
- {
- context->state = NET_NFC_LLCP_STEP_03;
- }
- }
- else
- {
- context->state = NET_NFC_LLCP_STEP_RETURN;
- }
- }
- else
- {
- DEBUG_ERR_MSG("net_nfc_controller_llcp_send failed, [%d]",
- result);
- context->state = NET_NFC_STATE_ERROR;
- }
- _net_nfc_server_snep_send(context);
-}
-
-static void _net_nfc_server_send_fragment(
- net_nfc_server_snep_op_context_t *context)
-{
- data_s req_msg;
- uint32_t remain_len;
- net_nfc_error_e result;
-
- if (context == NULL)
- return;
-
- /* calc remain buffer length */
- remain_len = context->data.length - context->offset;
-
- req_msg.length = (remain_len < context->miu) ? remain_len : context->miu;
- req_msg.buffer = context->data.buffer + context->offset;
-
- DEBUG_SERVER_MSG("try to send data, socket [%x], offset [%d],"
- " current [%d], remain [%d]",context->socket, context->offset,
- req_msg.length, remain_len - req_msg.length);
-
- context->offset += req_msg.length;
-
- if (net_nfc_controller_llcp_send(context->handle,
- context->socket,
- &req_msg,
- &result,
- _net_nfc_server_send_fragment_cb,
- context) == false)
- {
- DEBUG_ERR_MSG("net_nfc_controller_llcp_send failed, [%d]",
- result);
- context->state = NET_NFC_STATE_ERROR;
- context->result = result;
- _net_nfc_server_snep_send(context);
- }
-}
-
-void _net_nfc_server_snep_send_recv_cb(
- net_nfc_error_e result,
- uint32_t type,
- data_s *data,
- void *user_param)
-{
- net_nfc_server_snep_op_context_t *context =
- (net_nfc_server_snep_op_context_t *)user_param;
-
- DEBUG_SERVER_MSG("_net_nfc_server_snep_send_recv_cb,"
- " result [%d]", result);
-
- if (context == NULL)/* TODO */
- return;
-
- DEBUG_SERVER_MSG("received message, type [%d]", type);
-
- context->result = result;
- context->type = type;
-
- switch (type)
- {
- case SNEP_REQ_CONTINUE :
- case SNEP_RESP_CONT :
- context->state = NET_NFC_LLCP_STEP_03;
- break;
-
- case SNEP_REQ_REJECT :
- case SNEP_RESP_REJECT :
- context->state = NET_NFC_STATE_ERROR;
- context->result = NET_NFC_LLCP_SOCKET_FRAME_REJECTED;
- break;
-
- case SNEP_RESP_NOT_FOUND :
- context->state = NET_NFC_STATE_ERROR;
- context->result = NET_NFC_NO_DATA_FOUND;
- break;
-
- case SNEP_RESP_EXCESS_DATA :
- context->state = NET_NFC_STATE_ERROR;
- context->result = NET_NFC_INSUFFICIENT_STORAGE;
- break;
-
- case SNEP_RESP_BAD_REQ :
- context->state = NET_NFC_STATE_ERROR;
- context->result = NET_NFC_INVALID_FORMAT;
- break;
-
- case SNEP_RESP_NOT_IMPLEMENT :
- case SNEP_RESP_UNSUPPORTED_VER :
- context->state = NET_NFC_STATE_ERROR;
- context->result = NET_NFC_NOT_ALLOWED_OPERATION;
- break;
-
- default :
- context->state = NET_NFC_STATE_ERROR;
- context->result = NET_NFC_OPERATION_FAIL;
- break;
- }
-
- _net_nfc_server_snep_send(context);
-}
-
-static void _net_nfc_server_snep_send(
- net_nfc_server_snep_op_context_t *context)
-{
- if (context == NULL)
- {
- return;
- }
-
- switch (context->state)
- {
- case NET_NFC_LLCP_STEP_01 :
- case NET_NFC_LLCP_STEP_03 :
- DEBUG_SERVER_MSG("NET_NFC_LLCP_STEP_%02d",
- context->state - NET_NFC_LLCP_STEP_01 + 1);
-
- /* send fragment */
- _net_nfc_server_send_fragment(context);
- break;
-
- case NET_NFC_LLCP_STEP_02 :
- DEBUG_SERVER_MSG("NET_NFC_LLCP_STEP_02");
-
- /* receive response */
- net_nfc_server_snep_recv(
- context->handle,
- context->socket,
- _net_nfc_server_snep_send_recv_cb,
- context);
- break;
-
- case NET_NFC_LLCP_STEP_RETURN :
- DEBUG_SERVER_MSG("NET_NFC_LLCP_STEP_RETURN");
-
- /* complete and invoke callback */
- context->cb(
- context->result,
- context->type,
- NULL,
- context->user_param);
-
- _net_nfc_server_snep_destory_context(context);
- break;
-
- case NET_NFC_STATE_ERROR :
- DEBUG_ERR_MSG("NET_NFC_STATE_ERROR");
-
- /* error, invoke callback */
- DEBUG_ERR_MSG("net_nfc_server_snep_send failed, [%d]",
- context->result);
-
- context->cb(
- context->result,
- context->type,
- NULL,
- context->user_param);
-
- _net_nfc_server_snep_destory_context(context);
- break;
-
- default :
- DEBUG_ERR_MSG("NET_NFC_LLCP_STEP_??");
-
- context->cb(NET_NFC_OPERATION_FAIL,
- context->type,
- NULL,
- context->user_param);
-
- _net_nfc_server_snep_destory_context(context);
- break;
- }
-}
-
-net_nfc_error_e net_nfc_server_snep_send(
- net_nfc_target_handle_s *handle,
- net_nfc_llcp_socket_t socket,
- uint32_t type,
- data_s *data,
- _net_nfc_server_snep_operation_cb cb,
- void *user_param)
-{
- net_nfc_server_snep_op_context_t *context;
- net_nfc_error_e result = NET_NFC_OK;
-
- /* create context */
- context = _net_nfc_server_snep_create_send_context(
- type,
- handle,
- socket,
- data,
- cb,
- user_param);
-
- if (context != NULL)
- {
- /* send response */
- _net_nfc_server_snep_send(context);
- }
- else
- {
- result = NET_NFC_ALLOC_FAIL;
- }
-
- return result;
-}
-
-static void _net_nfc_server_snep_server_recv_cb(
- net_nfc_error_e result,
- uint32_t type,
- data_s *data,
- void *user_param)
-{
- net_nfc_server_snep_context_t *context =
- (net_nfc_server_snep_context_t *)user_param;
-
- DEBUG_SERVER_MSG("_net_nfc_server_snep_server_recv_cb"
- "result [%d]", result);
-
- if (context == NULL)
- {
- /* TODO */
- return;
- }
-
- context->result = result;
- context->type = type;
-
- if (result == NET_NFC_OK && data != NULL && data->buffer != NULL)
- {
- DEBUG_SERVER_MSG("received message, type [%d], length [%d]",
- type, data->length);
-
- net_nfc_util_alloc_data(&context->data, data->length);
- if (context->data.buffer != NULL)
- {
- memcpy(context->data.buffer,
- data->buffer, data->length);
-
- switch (type)
- {
- case SNEP_REQ_GET :
- context->state = NET_NFC_LLCP_STEP_02;
- break;
-
- case SNEP_REQ_PUT :
- context->state = NET_NFC_LLCP_STEP_04;
- break;
-
- default :
- DEBUG_ERR_MSG("invalid request, [%d]", type);
- context->state = NET_NFC_STATE_ERROR;
- context->result = NET_NFC_NOT_ALLOWED_OPERATION;
- break;
- }
- }
- else
- {
- DEBUG_ERR_MSG("net_nfc_util_alloc_data failed");
- /* TODO */
- context->state = NET_NFC_STATE_ERROR;
- context->result = NET_NFC_ALLOC_FAIL;
- }
- }
- else
- {
- DEBUG_ERR_MSG("net_nfc_server_snep_recv failed, [%d]", result);
- context->type = type;
- context->state = NET_NFC_STATE_ERROR;
- }
-
- _net_nfc_server_snep_server_process(context);
-}
-
-
-static void _net_nfc_server_snep_server_send_cb(net_nfc_error_e result,
- uint32_t type,
- data_s *data,
- void *user_param)
-{
- net_nfc_server_snep_context_t *context =
- (net_nfc_server_snep_context_t *)user_param;
-
- DEBUG_SERVER_MSG("_net_nfc_server_snep_server_send_cb"
- ", result [%d]", result);
-
- if (context == NULL)/* TODO */
- return;
-
- context->result = result;
-
- if (result == NET_NFC_OK)
- {
- DEBUG_SERVER_MSG("server process success. and restart....");
-
- /* restart */
- net_nfc_util_free_data(&context->data);
- context->state = NET_NFC_LLCP_STEP_01;
- }
- else
- {
- DEBUG_ERR_MSG("net_nfc_server_snep_send failed, [%d]", result);
- context->state = NET_NFC_STATE_ERROR;
- }
-
- _net_nfc_server_snep_server_process(context);
-}
-
-
-static void _net_nfc_server_snep_server_process(
- net_nfc_server_snep_context_t *context)
-{
- if (context == NULL)
- return;
-
- switch (context->state)
- {
- case NET_NFC_LLCP_STEP_01 :
- DEBUG_SERVER_MSG("NET_NFC_LLCP_STEP_01");
-
- /* receive request */
- net_nfc_server_snep_recv(
- context->handle,
- context->socket,
- _net_nfc_server_snep_server_recv_cb,
- context);
- break;
-
- case NET_NFC_LLCP_STEP_02 :
- DEBUG_SERVER_MSG("NET_NFC_LLCP_STEP_02");
-
- context->state = NET_NFC_LLCP_STEP_03;
-
- if (context->cb == NULL ||
- context->cb((net_nfc_snep_handle_h)context,
- context->result,
- context->type,
- &context->data,
- context->user_param) != NET_NFC_OK)
- {
- /* there is no response for GET request */
- DEBUG_ERR_MSG("there is no response for GET request");
-
- /* receive request */
- net_nfc_server_snep_send(context->handle,
- context->socket,
- SNEP_RESP_NOT_FOUND,
- NULL,
- _net_nfc_server_snep_server_send_cb,
- context);
- }
- break;
-
- case NET_NFC_LLCP_STEP_03 :
- DEBUG_SERVER_MSG("NET_NFC_LLCP_STEP_03");
-
- /* receive request */
- net_nfc_server_snep_send(context->handle,
- context->socket,
- SNEP_RESP_SUCCESS,
- &context->data,
- _net_nfc_server_snep_server_send_cb,
- context);
- break;
-
- case NET_NFC_LLCP_STEP_04 :
- DEBUG_SERVER_MSG("NET_NFC_LLCP_STEP_04");
-
- if (context->cb != NULL)
- {
- /* complete and invoke callback */
- context->cb(
- (net_nfc_snep_handle_h)context,
- NET_NFC_OK,
- context->type,
- &context->data,
- context->user_param);
- }
-
- /* receive request */
- net_nfc_server_snep_send(context->handle,
- context->socket,
- SNEP_RESP_SUCCESS,
- NULL,
- _net_nfc_server_snep_server_send_cb,
- context);
- break;
-
- case NET_NFC_LLCP_STEP_10 : /* server error, and need to send error code to client */
- {
- /* FIXME : */
- }
- break;
-
- case NET_NFC_STATE_ERROR :
- DEBUG_SERVER_MSG("NET_NFC_STATE_ERROR");
-
- /* error, invoke callback */
- DEBUG_ERR_MSG("_snep_server_recv failed, [%d]",
- context->result);
-
- if (context->cb != NULL)
- {
- context->cb((net_nfc_snep_handle_h)context,
- context->result,
- context->type,
- NULL,
- context->user_param);
- }
-
- /* restart?? */
- break;
-
- default :
- DEBUG_ERR_MSG("NET_NFC_LLCP_STEP_??");
- /* TODO */
- break;
- }
-}
-
-
-static void _net_nfc_server_snep_clear_queue(
- gpointer data,
- gpointer user_data)
-{
- net_nfc_server_snep_job_t *job = (net_nfc_server_snep_job_t *)data;
-
- if (job != NULL)
- {
- if (job->cb != NULL)
- {
- job->cb((net_nfc_snep_handle_h)job->context,
- NET_NFC_OPERATION_FAIL, job->type,
- NULL, job->user_param);
- }
-
- if (job->data.buffer != NULL)
- {
- net_nfc_util_free_data(&job->data);
- }
-
- _net_nfc_util_free_mem(job);
- }
-}
-
-
-static void _net_nfc_server_snep_incomming_socket_error_cb(
- net_nfc_error_e result,
- net_nfc_target_handle_s *handle,
- net_nfc_llcp_socket_t socket,
- data_s *data,
- void *user_param)
-{
- net_nfc_server_snep_context_t *context =
- (net_nfc_server_snep_context_t *)user_param;
-
- DEBUG_SERVER_MSG("_net_nfc_server_snep_incomming_socket_error_cb,"
- " socket [%x], result [%d]",socket, result);
-
- if (context == NULL)
- {
- return;
- }
-
- if (context->data.buffer != NULL)
- {
- net_nfc_util_free_data(&context->data);
- }
-
- g_queue_foreach(&context->queue,
- _net_nfc_server_snep_clear_queue,
- NULL);
-
- _net_nfc_util_free_mem(context);
-}
-
-
-static void _net_nfc_server_snep_socket_error_cb(
- net_nfc_error_e result,
- net_nfc_target_handle_s *handle,
- net_nfc_llcp_socket_t socket,
- data_s *data,
- void *user_param)
-{
- net_nfc_server_snep_context_t *context =
- (net_nfc_server_snep_context_t *)user_param;
-
- DEBUG_SERVER_MSG("_net_nfc_server_snep_socket_error_cb"
- " socket [%x], result [%d]",socket, result);
-
- if (context == NULL)
- {
- return;
- }
-
- if (context->cb != NULL)
- {
- context->cb((net_nfc_snep_handle_h)context,
- result,
- NET_NFC_LLCP_STOP,
- NULL,
- context->user_param);
- }
-
- /*net_nfc_controller_llcp_socket_close(socket, &result);*/
-
- if (context->data.buffer != NULL)
- {
- net_nfc_util_free_data(&context->data);
- }
-
- g_queue_foreach(&context->queue,
- _net_nfc_server_snep_clear_queue,
- NULL);
-
- _net_nfc_util_free_mem(context);
-}
-
-
-static void _net_nfc_server_snep_incoming_cb(
- net_nfc_error_e result,
- net_nfc_target_handle_s *handle,
- net_nfc_llcp_socket_t socket,
- data_s *data,
- void *user_param)
-{
- net_nfc_server_snep_context_t *context =
- (net_nfc_server_snep_context_t *)user_param;
- net_nfc_server_snep_context_t *accept_context = NULL;
-
- if (context == NULL)
- {
- return;
- }
-
- DEBUG_SERVER_MSG("_net_nfc_server_snep_incoming_cb,"
- " incoming socket [%x], result [%d]",socket, result);
-
- if (result != NET_NFC_OK)
- {
- DEBUG_ERR_MSG("listen socket failed, [%d]", result);
-
- goto ERROR;
- }
-
- /* start snep server */
- _net_nfc_util_alloc_mem(accept_context, sizeof(*accept_context));
-
- if (accept_context == NULL)
- {
- DEBUG_ERR_MSG("_net_nfc_util_alloc_mem failed");
- result = NET_NFC_ALLOC_FAIL;
-
- goto ERROR;
- }
-
- accept_context->handle = context->handle;
- accept_context->socket = socket;
- accept_context->cb = context->cb;
- accept_context->user_param = context->user_param;
- accept_context->state = NET_NFC_LLCP_STEP_01;
-
- result = net_nfc_server_llcp_simple_accept(handle,
- socket,
- _net_nfc_server_snep_incomming_socket_error_cb,
- accept_context);
-
- if (result != NET_NFC_OK)
- {
- DEBUG_ERR_MSG("net_nfc_server_llcp_simple_accept failed, [%d]",
- result);
- goto ERROR;
- }
-
- DEBUG_SERVER_MSG("socket [%x] accepted.. waiting for request message",
- socket);
-
- _net_nfc_server_snep_server_process(accept_context);
-
- return;
-
-ERROR :
- if (accept_context != NULL)
- {
- _net_nfc_util_free_mem(accept_context);
- }
-
- if (context->cb != NULL)
- {
- context->cb((net_nfc_snep_handle_h)context,
- result,
- context->type,
- NULL,
- context->user_param);
- }
-}
-
-net_nfc_error_e net_nfc_server_snep_server(
- net_nfc_target_handle_s *handle,
- const char *san,
- sap_t sap,
- net_nfc_server_snep_cb cb,
- void *user_param)
-{
- net_nfc_error_e result;
- net_nfc_server_snep_context_t *context = NULL;
-
- if (handle == NULL || san == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
-
- _net_nfc_util_alloc_mem(context, sizeof(*context));
-
- if (context == NULL)
- {
- DEBUG_ERR_MSG("_create_snep_context failed");
- result = NET_NFC_ALLOC_FAIL;
- goto ERROR;
- }
- context->handle = handle;
- context->cb = cb;
- context->user_param = user_param;
- context->state = NET_NFC_LLCP_STEP_01;
-
- result = net_nfc_server_llcp_simple_server(handle,
- san,
- sap,
- _net_nfc_server_snep_incoming_cb,
- _net_nfc_server_snep_socket_error_cb,
- context);
-
- if (result != NET_NFC_OK)
- {
- DEBUG_ERR_MSG("net_nfc_server_llcp_simple_server failed, [%d]",
- result);
- goto ERROR;
- }
-
- DEBUG_SERVER_MSG("start snep server, san [%s], sap [%d]",
- san, sap);
- return result;
-
-ERROR :
- if (context != NULL)
- _net_nfc_util_free_mem(context);
-
- return result;
-}
-
-net_nfc_error_e net_nfc_server_snep_server_send_get_response(
- net_nfc_snep_handle_h snep_handle,
- data_s *data)
-{
- net_nfc_server_snep_context_t *context =
- (net_nfc_server_snep_context_t *)snep_handle;
- net_nfc_error_e result = NET_NFC_OK;
-
- if (context == NULL/* && check valid handle */)
- {
- DEBUG_ERR_MSG("invalid handle");
- return NET_NFC_INVALID_PARAM;
- }
-
- DEBUG_SERVER_MSG("send get response, socket [%x]", context->socket);
-
- /* check correct status */
- if (context->type == SNEP_REQ_GET)
- {
- if (context->data.buffer != NULL)
- net_nfc_util_free_data(&context->data);
-
- if (data != NULL)
- {
- context->type = SNEP_RESP_SUCCESS;
-
- if (net_nfc_util_alloc_data(&context->data, data->length) == true)
- {
- memcpy(context->data.buffer, data->buffer,
- data->length);
- }
- else
- {
- DEBUG_ERR_MSG("net_nfc_util_alloc_data failed");
- result = NET_NFC_ALLOC_FAIL;
- }
- }
- else
- {
- /* not found */
- context->type = SNEP_RESP_NOT_FOUND;
- }
-
- _net_nfc_server_snep_server_process(context);
- }
- else
- {
- DEBUG_ERR_MSG("incorrect handle state");
- result = NET_NFC_INVALID_STATE;
- }
-
- return result;
-}
-
-static void _net_nfc_server_snep_client_send_cb(
- net_nfc_error_e result,
- uint32_t type,
- data_s *data,
- void *user_param)
-{
- net_nfc_server_snep_job_t*job =
- (net_nfc_server_snep_job_t *)user_param;
-
- if (job == NULL)
- {
- /* TODO */
- return;
- }
-
- job->type = type;
- job->result = result;
-
- if (result == NET_NFC_OK)
- {
- job->state = NET_NFC_LLCP_STEP_02;
-
- net_nfc_util_free_data(&job->data);
- }
- else
- {
- DEBUG_ERR_MSG("net_nfc_server_snep_send failed, [%d]", result);
- job->state = NET_NFC_STATE_ERROR;
- }
-
- _net_nfc_server_snep_client_process(job);
-}
-
-static void _net_nfc_server_snep_client_recv_cb(
- net_nfc_error_e result,
- uint32_t type,
- data_s *data,
- void *user_param)
-{
- net_nfc_server_snep_job_t *job =
- (net_nfc_server_snep_job_t *)user_param;
-
- if (job == NULL)
- {
- /* TODO */
- return;
- }
-
- job->type = type;
- job->result = result;
-
- if (result == NET_NFC_OK)
- {
- if (type == SNEP_RESP_SUCCESS)
- {
- job->state = NET_NFC_LLCP_STEP_RETURN;
- if (data != NULL && data->buffer != NULL)
- {
- net_nfc_util_alloc_data(&job->data, data->length);
- if (job->data.buffer != NULL)
- {
- memcpy(job->data.buffer, data->buffer,
- data->length);
- }
- else
- {
- DEBUG_ERR_MSG("net_nfc_util_alloc_data failed");
- job->state = NET_NFC_STATE_ERROR;
- job->result = NET_NFC_ALLOC_FAIL;
- }
- }
- }
- else
- {
- /* TODO */
- DEBUG_ERR_MSG("invalid request, [0x%x]", type);
- job->state = NET_NFC_STATE_ERROR;
- job->result = NET_NFC_NOT_ALLOWED_OPERATION;
- }
- }
- else
- {
-
- DEBUG_ERR_MSG("net_nfc_server_snep_recv failed, [%d]", result);
- job->state = NET_NFC_STATE_ERROR;
- }
-
- _net_nfc_server_snep_client_process(job);
-}
-
-
-static void _net_nfc_server_snep_client_do_job(net_nfc_server_snep_context_t *context)
-{
- if (context->state == NET_NFC_LLCP_IDLE &&
- g_queue_is_empty(&context->queue) == false) {
- net_nfc_server_snep_job_t *job;
-
- job = g_queue_pop_head(&context->queue);
- if (job != NULL) {
- context->state = NET_NFC_LLCP_STEP_01;
- job->state = NET_NFC_LLCP_STEP_01;
- _net_nfc_server_snep_client_process(job);
- }
- }
-}
-
-static void _net_nfc_server_snep_client_process(
- net_nfc_server_snep_job_t *job)
-{
- bool finish = false;
-
- if (job == NULL)
- {
- return;
- }
-
- switch (job->state)
- {
- case NET_NFC_LLCP_STEP_01 :
- DEBUG_SERVER_MSG("NET_NFC_LLCP_STEP_01");
-
- /* send request */
- net_nfc_server_snep_send(job->handle,
- job->socket,
- job->type,
- &job->data,
- _net_nfc_server_snep_client_send_cb,
- job);
- break;
-
- case NET_NFC_LLCP_STEP_02 :
- DEBUG_SERVER_MSG("NET_NFC_LLCP_STEP_02");
-
- /* receive response */
- net_nfc_server_snep_recv(job->handle,
- job->socket,
- _net_nfc_server_snep_client_recv_cb,
- job);
- break;
-
- case NET_NFC_LLCP_STEP_RETURN :
- DEBUG_SERVER_MSG("NET_NFC_LLCP_STEP_RETURN");
-
- /* complete and invoke callback */
- if (job->cb != NULL)
- {
- job->cb((net_nfc_snep_handle_h)job->context,
- NET_NFC_OK,
- job->type,
- &job->data,
- job->user_param);
- }
-
- /* finish job */
- finish = true;
- break;
-
- case NET_NFC_STATE_ERROR :
- default :
- DEBUG_ERR_MSG("NET_NFC_STATE_ERROR");
-
- /* error, invoke callback */
- DEBUG_ERR_MSG("_snep_server_send failed, [%d]",
- job->result);
- if (job->cb != NULL)
- {
- job->cb((net_nfc_snep_handle_h)job->context,
- job->result,
- job->type,
- &job->data,
- job->user_param);
- }
-
- /* finish job */
- finish = true;
- break;
- }
-
- if (finish == true)
- {
- net_nfc_server_snep_context_t *context = job->context;
-
- if (job->data.buffer != NULL)
- {
- net_nfc_util_free_data(&job->data);
- }
-
- _net_nfc_util_free_mem(job);
-
- context->state = NET_NFC_LLCP_IDLE;
-
- _net_nfc_server_snep_client_do_job(context);
- }
-}
-
-static void _net_nfc_server_snep_connected_cb(
- net_nfc_error_e result,
- net_nfc_target_handle_s *handle,
- net_nfc_llcp_socket_t socket,
- data_s *data,
- void *user_param)
-{
- net_nfc_server_snep_context_t *context =
- (net_nfc_server_snep_context_t *)user_param;
-
- if (context == NULL)
- {
- return;
- }
-
- context->socket = socket;
-
- if (result == NET_NFC_OK)
- {
- /* start snep client */
- DEBUG_SERVER_MSG("socket [%x] connected. send message",
- socket);
- }
- else
- {
- DEBUG_ERR_MSG("connect socket failed, [%d]", result);
- }
-
- if (context->cb != NULL)
- {
- context->cb((net_nfc_snep_handle_h)context,
- result,
- NET_NFC_LLCP_START,
- NULL,
- context->user_param);
- }
-}
-
-net_nfc_error_e net_nfc_server_snep_client(
- net_nfc_target_handle_s *handle,
- const char *san,
- sap_t sap,
- net_nfc_server_snep_cb cb,
- void *user_param)
-{
- net_nfc_error_e result;
- net_nfc_server_snep_context_t *context = NULL;
-
- if (handle == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
-
- _net_nfc_util_alloc_mem(context, sizeof(*context));
- if (context == NULL)
- {
- DEBUG_ERR_MSG("_net_nfc_util_alloc_mem failed");
- result = NET_NFC_ALLOC_FAIL;
-
- goto ERROR;
- }
- context->handle = handle;
- context->cb = cb;
- context->user_param = user_param;
-
- result = net_nfc_server_llcp_simple_client(handle,
- san,
- sap,
- _net_nfc_server_snep_connected_cb,
- _net_nfc_server_snep_socket_error_cb,
- context);
-
- if (result != NET_NFC_OK)
- {
- DEBUG_ERR_MSG("net_nfc_server_llcp_simple_client failed, [%d]",
- result);
-
- goto ERROR;
- }
- if (san != NULL)
- DEBUG_SERVER_MSG("start snep client, san [%s]",
- san);
- else
- DEBUG_SERVER_MSG("start snep client, sap [%d]",
- sap);
-
- return result;
-
-ERROR :
- if (context != NULL)
- {
- if (context->data.buffer != NULL)
- {
- net_nfc_util_free_data(&context->data);
- }
- _net_nfc_util_free_mem(context);
- }
-
- return result;
-}
-
-
-net_nfc_error_e net_nfc_server_snep_client_request(
- net_nfc_snep_handle_h snep,
- uint8_t type,
- data_s *data,
- net_nfc_server_snep_cb cb,
- void *user_param)
-{
- net_nfc_server_snep_context_t *context = (net_nfc_server_snep_context_t *)snep;
- net_nfc_error_e result = NET_NFC_OK;
- net_nfc_server_snep_job_t *job;
-
- if (context == NULL || data == NULL || data->buffer == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
-
- /* check type */
- _net_nfc_util_alloc_mem(job, sizeof(*job));
- if (job != NULL)
- {
- net_nfc_util_alloc_data(&job->data, data->length);
- if (job->data.buffer != NULL)
- {
- memcpy(job->data.buffer, data->buffer, data->length);
- }
- job->type = type;
- job->cb = cb;
- job->user_param = user_param;
-
- job->context = context;
- job->handle = context->handle;
- job->socket = context->socket;
-
- g_queue_push_tail(&context->queue, job);
- }
- else
- {
- return NET_NFC_ALLOC_FAIL;
- }
-
- INFO_MSG("enqueued jobs [%d]", g_queue_get_length(&context->queue));
-
- /* if client is idle, starts sending request */
- if (context->state == NET_NFC_LLCP_IDLE)
- {
- _net_nfc_server_snep_client_do_job(context);
- } else {
- INFO_MSG("client is working. this job will be enqueued");
- }
-
- return result;
-}
-
-static net_nfc_error_e _net_nfc_server_default_server_cb_(
- net_nfc_snep_handle_h handle,
- net_nfc_error_e result,
- uint32_t type,
- data_s *data,
- void *user_param)
-{
- DEBUG_SERVER_MSG("type [%d], result [%d], data [%p], user_param [%p]",
- type, result, data, user_param);
-
- if (result != NET_NFC_OK || data == NULL || data->buffer == NULL)
- {
- /* restart */
- return NET_NFC_NULL_PARAMETER;
- }
-
- switch (type)
- {
- case SNEP_REQ_GET:
- {
- net_nfc_server_snep_get_msg_t *msg =
- (net_nfc_server_snep_get_msg_t *)data->buffer;
-
-
- uint32_t max_len = htonl(msg->length);
- data_s get_msg = { msg->data,data->length - sizeof(msg->length)};
-
- DEBUG_SERVER_MSG("GET : acceptable max_len [%d], message [%d]",
- max_len, data->length - sizeof(msg->length));
-
-
- if (_net_nfc_server_snep_process_get_response_cb(handle, &get_msg, max_len))
- {
- result = NET_NFC_OK;
- }
- else
- {
- result = NET_NFC_NOT_SUPPORTED;
- }
- }
- break;
-
- case SNEP_REQ_PUT :
- {
- net_nfc_server_p2p_received(data);
- net_nfc_app_util_process_ndef(data);;
-
- result = NET_NFC_OK;
- }
- break;
-
- default :
- DEBUG_ERR_MSG("error [%d]", result);
- break;
- }
-
- return result;
-}
-
-
-static net_nfc_error_e _net_nfc_server_default_client_cb_(
- net_nfc_snep_handle_h handle,
- net_nfc_error_e result,
- uint32_t type,
- data_s *data,
- void *user_param)
-{
- _net_nfc_server_snep_service_context_t *context =
- (_net_nfc_server_snep_service_context_t*)user_param;
-
- DEBUG_SERVER_MSG("type [%d], result [%d], data [%p]",
- type, result, data);
-
- if (user_param == NULL)
- return NET_NFC_NULL_PARAMETER;;
-
- switch (type)
- {
- case SNEP_RESP_SUCCESS :
- case SNEP_RESP_BAD_REQ :
- case SNEP_RESP_EXCESS_DATA :
- case SNEP_RESP_NOT_FOUND :
- case SNEP_RESP_NOT_IMPLEMENT :
- case SNEP_RESP_REJECT :
- case SNEP_RESP_UNSUPPORTED_VER :
- context = (_net_nfc_server_snep_service_context_t *)user_param;
-
- net_nfc_server_p2p_data_sent(result,
- context->user_param);
-
- _net_nfc_util_free_mem(context);
- break;
-
- default :
- DEBUG_ERR_MSG("error [%d]", result);
- break;
- }
-
- return result;
-}
-
-
-static net_nfc_error_e _net_nfc_server_default_client_connected_cb_(
- net_nfc_snep_handle_h handle,
- net_nfc_error_e result,
- uint32_t type,
- data_s *data,
- void *user_param)
-{
- _net_nfc_server_snep_service_context_t *context =
- (_net_nfc_server_snep_service_context_t *)user_param;
-
- DEBUG_SERVER_MSG("type [%d], result [%d], data [%p], user_param [%p]",
- type, result, data, user_param);
-
- if (context == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
-
- if (result == NET_NFC_OK)
- {
- net_nfc_server_snep_client_request(handle,
- context->type,
- &context->data,
- _net_nfc_server_default_client_cb_,
- context);
- }
- else
- {
- if (context->data.buffer != NULL)
- {
- net_nfc_util_free_data(&context->data);
- }
- _net_nfc_util_free_mem(context);
- }
-
- return result;
-}
-
-
-net_nfc_error_e net_nfc_server_snep_default_server_start(
- net_nfc_target_handle_s *handle)
-{
- /* start default snep server, register your callback */
- return net_nfc_server_snep_server(handle,
- SNEP_SAN,
- SNEP_SAP,
- _net_nfc_server_default_server_cb_,
- (void *)1234);
-}
-
-
-net_nfc_error_e net_nfc_server_snep_default_client_start(
- net_nfc_target_handle_s *handle,
- int type,
- data_s *data,
- int client,
- void *user_param)
-{
- _net_nfc_server_snep_service_context_t *context = NULL;
-
- _net_nfc_util_alloc_mem(context, sizeof(*context));
- if (context != NULL)
- {
- context->handle = handle;
- context->client = client;
- context->user_param = user_param;
- context->type = type;
- net_nfc_util_alloc_data(&context->data, data->length);
- if (context->data.buffer != NULL)
- {
- memcpy(context->data.buffer, data->buffer,
- data->length);
- context->data.length = data->length;
- }
- /* start default snep client, register your callback */
- return net_nfc_server_snep_client(handle,
- SNEP_SAN,
- SNEP_SAP,
- _net_nfc_server_default_client_connected_cb_,
- context);
- }
- else
- {
- return NET_NFC_ALLOC_FAIL;
- }
-}
-
-net_nfc_error_e
-net_nfc_server_snep_default_server_register_get_response_cb(
- net_nfc_server_snep_listen_cb cb,
- void *user_param)
-{
- net_nfc_error_e result;
-
- if (_net_nfc_server_snep_add_get_response_cb(cb, user_param) == true)
- {
- result = NET_NFC_OK;
- }
- else
- {
- result = NET_NFC_ALREADY_REGISTERED;
- }
-
- return result;
-}
-
-net_nfc_error_e
-net_nfc_server_snep_default_server_unregister_get_response_cb(
- net_nfc_server_snep_listen_cb cb)
-{
- _net_nfc_server_snep_del_get_response_cb(cb);
-
- return NET_NFC_OK;
-}
-
-net_nfc_error_e net_nfc_server_snep_default_server_send_get_response(
- net_nfc_snep_handle_h snep_handle, data_s *data)
-{
- net_nfc_server_snep_context_t *context =
- (net_nfc_server_snep_context_t *)snep_handle;
- net_nfc_error_e result = NET_NFC_OK;
-
- if (context == NULL/* && check valid handle */)
- {
- DEBUG_ERR_MSG("invalid handle");
- return NET_NFC_INVALID_PARAM;
- }
-
- /* check correct status */
- if (context->type == SNEP_REQ_GET &&
- context->state == NET_NFC_LLCP_STEP_03)
- {
- net_nfc_server_snep_server_send_get_response(snep_handle, data);
- }
- else
- {
- DEBUG_ERR_MSG("incorrect handle state");
- result = NET_NFC_INVALID_STATE;
- }
-
- return result;
-}
-
-static void _snep_default_activate_cb(int event,
- net_nfc_target_handle_s *handle,
- uint32_t sap, const char *san, void *user_param)
-{
- net_nfc_error_e result;
-
- DEBUG_SERVER_MSG("event [%d], handle [%p], sap [%d], san [%s]",
- event, handle, sap, san);
-
- if (event == NET_NFC_LLCP_START) {
- /* start snep server */
- result = net_nfc_server_snep_server(handle, (char *)san, sap,
- _net_nfc_server_default_server_cb_, user_param);
- if (result != NET_NFC_OK) {
- DEBUG_ERR_MSG("net_nfc_service_snep_server failed, [%d]",
- result);
- }
- } else if (event == NET_NFC_LLCP_UNREGISTERED) {
- /* unregister server, do nothing */
- }
-}
-
-net_nfc_error_e net_nfc_server_snep_default_server_register()
-{
- char id[20];
-
- /* TODO : make id, */
- snprintf(id, sizeof(id), "%d", getpid());
-
- /* start default snep server */
- return net_nfc_server_llcp_register_service(id,
- SNEP_SAP,
- SNEP_SAN,
- _snep_default_activate_cb,
- NULL);
-}
-
-net_nfc_error_e net_nfc_server_snep_default_server_unregister()
-{
- char id[20];
-
- /* TODO : make id, */
- snprintf(id, sizeof(id), "%d", getpid());
-
- /* start default snep server */
- return net_nfc_server_llcp_unregister_service(id,
- SNEP_SAP,
- SNEP_SAN);
-}
-
-net_nfc_error_e net_nfc_server_snep_parse_get_request(data_s *request,
- size_t *max_len, data_s *message)
-{
- net_nfc_server_snep_msg_t *msg = NULL;
-
- if (request == NULL || request->buffer == NULL ||
- request->length == 0 || max_len == NULL || message == NULL) {
- return NET_NFC_NULL_PARAMETER;
- }
-
- msg = (net_nfc_server_snep_msg_t *)request->buffer;
-
- *max_len = htonl(msg->length);
-
- message->buffer = msg->data;
- message->length = request->length - sizeof(msg->length);
-
- DEBUG_SERVER_MSG("GET : acceptable max_len [%d], message [%d]",
- *max_len, request->length - sizeof(msg->length));
-
- return NET_NFC_OK;
-}
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#include <vconf.h>
-#include <tapi_common.h>
-#include <ITapiSim.h>
-
-#include "net_nfc_typedef_internal.h"
-#include "net_nfc_debug_internal.h"
-#include "net_nfc_util_internal.h"
-#include "net_nfc_util_gdbus_internal.h"
-#include "net_nfc_controller_internal.h"
-#include "net_nfc_gdbus.h"
-#include "net_nfc_manager.h"
-#include "net_nfc_server_common.h"
-#include "net_nfc_server_context_internal.h"
-#include "net_nfc_server_manager.h"
-#include "net_nfc_server_se.h"
-#include "net_nfc_app_util_internal.h"
-
-
-typedef struct _nfc_se_setting_t
-{
- bool busy;
- uint8_t type;
- uint8_t mode;
-}
-net_nfc_server_se_setting_t;
-
-
-static NetNfcGDbusSecureElement *se_skeleton = NULL;
-#if 0
-static uint8_t gdbus_se_prev_type = SECURE_ELEMENT_TYPE_INVALID;
-static uint8_t gdbus_se_prev_mode = SECURE_ELEMENT_OFF_MODE;
-#endif
-static net_nfc_server_se_setting_t gdbus_se_setting;
-
-/* TODO : make a list for handles */
-static TapiHandle *gdbus_uicc_handle;
-static net_nfc_target_handle_s *gdbus_ese_handle;
-
-/* server_side */
-typedef struct _ServerSeData ServerSeData;
-
-struct _ServerSeData
-{
- data_s aid;
- data_s param;
- guint event;
-};
-
-typedef struct _SeDataSeType SeDataSeType;
-
-struct _SeDataSeType
-{
- NetNfcGDbusSecureElement *object;
- GDBusMethodInvocation *invocation;
- gint se_type;
-};
-
-
-typedef struct _SeDataHandle SeDataHandle;
-
-struct _SeDataHandle
-{
- NetNfcGDbusSecureElement *object;
- GDBusMethodInvocation *invocation;
- net_nfc_target_handle_s* handle;
-};
-
-typedef struct _SeDataApdu SeDataApdu;
-
-struct _SeDataApdu
-{
- NetNfcGDbusSecureElement *object;
- GDBusMethodInvocation *invocation;
- net_nfc_target_handle_s* handle;
- GVariant *data;
-};
-
-static void se_close_secure_element_thread_func(gpointer user_data);
-
-static void se_get_atr_thread_func(gpointer user_data);
-
-static void se_open_secure_element_thread_func(gpointer user_data);
-
-static void se_send_apdu_thread_func(gpointer user_data);
-
-static void se_set_data_thread_func(gpointer user_data);
-
-static gboolean se_handle_close_secure_element(
- NetNfcGDbusSecureElement *object,
- GDBusMethodInvocation *invocation,
- guint arg_handle,
- GVariant *smack_privilege);
-
-static gboolean se_handle_get_atr(
- NetNfcGDbusSecureElement *object,
- GDBusMethodInvocation *invocation,
- guint arg_handle,
- GVariant *smack_privilege);
-
-
-static gboolean se_handle_open_secure_element(
- NetNfcGDbusSecureElement *object,
- GDBusMethodInvocation *invocation,
- gint arg_type,
- GVariant *smack_privilege);
-
-
-static gboolean se_handle_send_apdu(
- NetNfcGDbusSecureElement *object,
- GDBusMethodInvocation *invocation,
- guint arg_handle,
- GVariant* apdudata,
- GVariant *smack_privilege);
-
-static gboolean se_handle_set(
- NetNfcGDbusSecureElement *object,
- GDBusMethodInvocation *invocation,
- gint arg_type,
- GVariant *smack_privilege);
-
-
-uint8_t net_nfc_server_se_get_se_type()
-{
- return gdbus_se_setting.type;
-}
-
-uint8_t net_nfc_server_se_get_se_mode()
-{
- return gdbus_se_setting.mode;
-}
-
-static void net_nfc_server_se_set_se_type(uint8_t type)
-{
- gdbus_se_setting.type = type;
-}
-
-static void net_nfc_server_se_set_se_mode(uint8_t mode)
-{
- gdbus_se_setting.mode = mode;
-}
-
-
-/* eSE functions */
-static bool net_nfc_server_se_is_ese_handle(net_nfc_target_handle_s *handle)
-{
- return (gdbus_ese_handle != NULL &&
- gdbus_ese_handle == handle);
-}
-
-static void net_nfc_server_se_set_current_ese_handle(
- net_nfc_target_handle_s *handle)
-{
- gdbus_ese_handle = handle;
-}
-
-static net_nfc_target_handle_s *net_nfc_server_se_open_ese()
-{
- if (gdbus_ese_handle == NULL) {
- net_nfc_error_e result;
- net_nfc_target_handle_s *handle;
-
- if (net_nfc_controller_secure_element_open(
- SECURE_ELEMENT_TYPE_ESE,
- &handle, &result) == true)
- {
- net_nfc_server_se_set_current_ese_handle(handle);
-
- DEBUG_SERVER_MSG("handle [%p]", handle);
- }
- else
- {
- DEBUG_ERR_MSG("net_nfc_controller_secure_element_open failed [%d]",
- result);
- }
- }
-
- return gdbus_ese_handle;
-}
-
-static net_nfc_error_e net_nfc_server_se_close_ese()
-{
- net_nfc_error_e result = NET_NFC_OK;
-
- if (gdbus_ese_handle != NULL &&
- net_nfc_server_gdbus_is_server_busy() == false) {
- if (net_nfc_controller_secure_element_close(
- gdbus_ese_handle,
- &result) == false)
- {
- net_nfc_controller_exception_handler();
- }
- net_nfc_server_se_set_current_ese_handle(NULL);
- }
-
- return result;
-}
-
-
-/* UICC functions */
-static TelSimCardStatus_t _se_uicc_check_state(TapiHandle *handle)
-{
- TelSimCardStatus_t state = TAPI_SIM_STATUS_UNKNOWN;
- int b_card_changed = 0;
- int error;
-
- error = tel_get_sim_init_info(handle,
- &state,
- &b_card_changed);
- if (error != 0)
- {
- DEBUG_ERR_MSG("error = [%d]", error);
- }
-
- DEBUG_SERVER_MSG("current sim init state = [%d]", state);
-
- return state;
-}
-
-static void _se_uicc_status_noti_cb(TapiHandle *handle,
- const char *noti_id,
- void *data,
- void *user_data)
-{
- TelSimCardStatus_t *status = (TelSimCardStatus_t *)data;
-
- DEBUG_SERVER_MSG("_se_uicc_status_noti_cb");
-
- switch (*status) {
- case TAPI_SIM_STATUS_SIM_INIT_COMPLETED :
- if (gdbus_se_setting.busy == true)
- {
- net_nfc_error_e result;
-
- DEBUG_SERVER_MSG("TAPI_SIM_STATUS_SIM_INIT_COMPLETED");
-
- gdbus_se_setting.busy = false;
-
- net_nfc_controller_set_secure_element_mode(
- SECURE_ELEMENT_TYPE_UICC,
- SECURE_ELEMENT_VIRTUAL_MODE, &result);
- if (result == NET_NFC_OK) {
- DEBUG_SERVER_MSG(
- "changed to SECURE_ELEMENT_TYPE_UICC");
- net_nfc_server_se_set_se_type(
- SECURE_ELEMENT_TYPE_UICC);
- net_nfc_server_se_set_se_mode(
- SECURE_ELEMENT_VIRTUAL_MODE);
- if (vconf_set_int(VCONFKEY_NFC_SE_TYPE,
- VCONFKEY_NFC_SE_TYPE_UICC) != 0) {
- DEBUG_ERR_MSG("vconf_set_int failed");
- }
- } else {
- DEBUG_ERR_MSG(
- "SECURE_ELEMENT_TYPE_UICC, SECURE_ELEMENT_VIRTUAL_MODE failed [%d]",
- result);
- }
- }
- break;
-
- case TAPI_SIM_STATUS_CARD_REMOVED :
- DEBUG_SERVER_MSG("TAPI_SIM_STATUS_CARD_REMOVED");
- /* do something */
- break;
-
- default:
- break;
- }
-}
-
-static void _se_uicc_init(void)
-{
- char **cpList;
-
- cpList = tel_get_cp_name_list();
- if (cpList != NULL) {
- gdbus_uicc_handle = tel_init(cpList[0]);
- if (gdbus_uicc_handle != NULL) {
- tel_register_noti_event(gdbus_uicc_handle,
- TAPI_NOTI_SIM_STATUS,
- _se_uicc_status_noti_cb,
- NULL);
-
- } else {
- DEBUG_ERR_MSG("tel_init() failed");
- }
- } else {
- DEBUG_ERR_MSG("tel_get_cp_name_list() failed");
- }
-}
-
-static void _se_uicc_deinit()
-{
- tel_deregister_noti_event(gdbus_uicc_handle,
- TAPI_NOTI_SIM_STATUS);
-
- tel_deinit(gdbus_uicc_handle);
-
- gdbus_uicc_handle = NULL;
-}
-
-
-static net_nfc_target_handle_s *_se_uicc_open(void)
-{
- net_nfc_target_handle_s *result = NULL;
-
- if (gdbus_uicc_handle != NULL) {
- TelSimCardStatus_t status;
-
- status = _se_uicc_check_state(gdbus_uicc_handle);
- if (status == TAPI_SIM_STATUS_SIM_INIT_COMPLETED) {
- result = (net_nfc_target_handle_s *)gdbus_uicc_handle;
- }
- }
-
- return result;
-}
-
-static bool _se_is_uicc_handle(net_nfc_target_handle_s *handle)
-{
- return (gdbus_uicc_handle != NULL &&
- (TapiHandle *)handle == gdbus_uicc_handle);
-}
-
-static void _se_uicc_close(net_nfc_target_handle_s *handle)
-{
-}
-
-/* SE Functions */
-net_nfc_error_e net_nfc_server_se_change_se(uint8_t type)
-{
- net_nfc_error_e result = NET_NFC_OK;
-
- switch (type) {
- case SECURE_ELEMENT_TYPE_UICC :
- if (gdbus_se_setting.busy == false) {
- TelSimCardStatus_t state;
-
- /*turn off ESE*/
- net_nfc_controller_set_secure_element_mode(
- SECURE_ELEMENT_TYPE_ESE,
- SECURE_ELEMENT_OFF_MODE,
- &result);
-
- state = _se_uicc_check_state(gdbus_uicc_handle);
- if (state == TAPI_SIM_STATUS_SIM_INIT_COMPLETED ||
- state == TAPI_SIM_STATUS_CARD_NOT_PRESENT ||
- state == TAPI_SIM_STATUS_CARD_REMOVED) {
- /*turn on UICC*/
- net_nfc_controller_set_secure_element_mode(
- SECURE_ELEMENT_TYPE_UICC,
- SECURE_ELEMENT_VIRTUAL_MODE, &result);
- if (result == NET_NFC_OK) {
- DEBUG_SERVER_MSG(
- "changed to SECURE_ELEMENT_TYPE_UICC");
-
- net_nfc_server_se_set_se_type(
- SECURE_ELEMENT_TYPE_UICC);
- net_nfc_server_se_set_se_mode(
- SECURE_ELEMENT_VIRTUAL_MODE);
-
- if (vconf_set_int(
- VCONFKEY_NFC_SE_TYPE,
- VCONFKEY_NFC_SE_TYPE_UICC) != 0)
- {
- DEBUG_ERR_MSG("vconf_set_int failed");
- }
- } else {
- DEBUG_ERR_MSG("SECURE_ELEMENT_TYPE_UICC, SECURE_ELEMENT_VIRTUAL_MODE failed [%d]",
- result);
- }
- } else {
- DEBUG_SERVER_MSG("UICC is not ready. waiting UICC event");
-
- gdbus_se_setting.busy = true;
- }
- } else {
- DEBUG_SERVER_MSG("Previous request is processing.");
-
- result = NET_NFC_BUSY;
- }
- break;
-
- case SECURE_ELEMENT_TYPE_ESE :
- /*turn off UICC*/
- net_nfc_controller_set_secure_element_mode(
- SECURE_ELEMENT_TYPE_UICC,
- SECURE_ELEMENT_OFF_MODE,
- &result);
-
- /*turn on ESE*/
- net_nfc_controller_set_secure_element_mode(
- SECURE_ELEMENT_TYPE_ESE,
- SECURE_ELEMENT_VIRTUAL_MODE,
- &result);
-
- if (result == NET_NFC_OK) {
- DEBUG_SERVER_MSG("changed to SECURE_ELEMENT_TYPE_ESE");
-
- net_nfc_server_se_set_se_type(SECURE_ELEMENT_TYPE_ESE);
- net_nfc_server_se_set_se_mode(SECURE_ELEMENT_VIRTUAL_MODE);
-
- if (vconf_set_int(VCONFKEY_NFC_SE_TYPE,
- VCONFKEY_NFC_SE_TYPE_ESE) != 0) {
- DEBUG_ERR_MSG("vconf_set_int failed");
- }
- } else {
- DEBUG_ERR_MSG("SECURE_ELEMENT_TYPE_ESE, SECURE_ELEMENT_VIRTUAL_MODE failed [%d]", result);
- }
- break;
-
- default:
- {
- net_nfc_error_e result_ese, result_uicc;
-
- net_nfc_server_se_set_se_type(
- SECURE_ELEMENT_TYPE_INVALID);
- net_nfc_server_se_set_se_mode(SECURE_ELEMENT_OFF_MODE);
-
- /*turn off ESE*/
- net_nfc_controller_set_secure_element_mode(
- SECURE_ELEMENT_TYPE_ESE,
- SECURE_ELEMENT_OFF_MODE,
- &result_ese);
-
- /*turn off UICC*/
- net_nfc_controller_set_secure_element_mode(
- SECURE_ELEMENT_TYPE_UICC,
- SECURE_ELEMENT_OFF_MODE,
- &result_uicc);
-
- if (result_ese != NET_NFC_INVALID_HANDLE
- && result_uicc != NET_NFC_INVALID_HANDLE) {
- DEBUG_SERVER_MSG("SE off all");
- if (vconf_set_int(VCONFKEY_NFC_SE_TYPE,
- VCONFKEY_NFC_SE_TYPE_NONE) != 0) {
- DEBUG_ERR_MSG("vconf_set_int failed");
- }
-
- result = NET_NFC_OK;
- }
- else
- {
- DEBUG_ERR_MSG("ALL OFF failed, ese [%d], uicc [%d]",result_ese, result_uicc);
-
- result = NET_NFC_INVALID_HANDLE;
- }
- }
- break;
- }
-
- return result;
-}
-
-static void se_close_secure_element_thread_func(gpointer user_data)
-{
- SeDataHandle *detail = (SeDataHandle *)user_data;
- net_nfc_error_e result;
-
- g_assert(detail != NULL);
- g_assert(detail->object != NULL);
- g_assert(detail->invocation != NULL);
-
- if (_se_is_uicc_handle(detail->handle) == true)
- {
- _se_uicc_close(detail->handle);
-
- result = NET_NFC_OK;
- }
- else if (net_nfc_server_se_is_ese_handle(detail->handle) == true)
- {
- /* decrease client reference count */
- net_nfc_server_gdbus_decrease_se_count(
- g_dbus_method_invocation_get_sender(
- detail->invocation));
-
- result = net_nfc_server_se_close_ese();
- }
- else
- {
- result = NET_NFC_INVALID_HANDLE;
- }
-#if 0
- if ((gdbus_se_prev_type != net_nfc_server_se_get_se_type()) ||
- (gdbus_se_prev_mode != net_nfc_server_se_get_se_mode()))
- {
- /*return back se mode*/
- net_nfc_controller_set_secure_element_mode(gdbus_se_prev_type,
- gdbus_se_prev_mode, &result);
-
- net_nfc_server_se_set_se_type(gdbus_se_prev_type);
- net_nfc_server_se_set_se_mode(gdbus_se_prev_mode);
- }
-#endif
- net_nfc_gdbus_secure_element_complete_close_secure_element(
- detail->object, detail->invocation, result);
-
- g_object_unref(detail->invocation);
- g_object_unref(detail->object);
-
- g_free(detail);
-
- /* shutdown process if it doesn't need */
- if (net_nfc_server_manager_get_active() == false &&
- net_nfc_server_gdbus_is_server_busy() == false) {
- net_nfc_manager_quit();
- }
-}
-
-static gboolean se_handle_close_secure_element(
- NetNfcGDbusSecureElement *object,
- GDBusMethodInvocation *invocation,
- guint arg_handle,
- GVariant *smack_privilege)
-{
- SeDataHandle *data;
- gboolean result;
-
- INFO_MSG(">>> REQUEST from [%s]",
- g_dbus_method_invocation_get_sender(invocation));
-
- /* check privilege and update client context */
- if (net_nfc_server_gdbus_check_privilege(invocation,
- smack_privilege,
- "nfc-manager",
- "rw") == false) {
- DEBUG_ERR_MSG("permission denied, and finished request");
-
- return FALSE;
- }
-
- data = g_new0(SeDataHandle, 1);
- if (data == NULL)
- {
- DEBUG_ERR_MSG("Memory allocation failed");
- g_dbus_method_invocation_return_dbus_error(invocation,
- "org.tizen.NetNfcService.AllocationError",
- "Can not allocate memory");
-
- return FALSE;
- }
-
- data->object = g_object_ref(object);
- data->invocation = g_object_ref(invocation);
- data->handle = (net_nfc_target_handle_s *)arg_handle;
-
- result = net_nfc_server_controller_async_queue_push(
- se_close_secure_element_thread_func, data);
- if (result == FALSE)
- {
- g_dbus_method_invocation_return_dbus_error(invocation,
- "org.tizen.NetNfcService.Se.ThreadError",
- "can not push to controller thread");
-
- g_object_unref(data->object);
- g_object_unref(data->invocation);
-
- g_free(data);
- }
-
- return result;
-}
-
-static void se_get_atr_thread_func(gpointer user_data)
-{
- SeDataHandle *detail = (SeDataHandle *)user_data;
- data_s *atr = NULL;
- GVariant *data;
- net_nfc_error_e result;
-
- g_assert(detail != NULL);
- g_assert(detail->object != NULL);
- g_assert(detail->invocation != NULL);
-
- if (_se_is_uicc_handle(detail->handle) == true)
- {
- result = NET_NFC_NOT_SUPPORTED;
- }
- else if (net_nfc_server_se_is_ese_handle(detail->handle) == true)
- {
- net_nfc_controller_secure_element_get_atr(detail->handle, &atr,
- &result);
- }
- else
- {
- DEBUG_ERR_MSG("invalid se handle");
-
- result = NET_NFC_INVALID_HANDLE;
- }
-
- data = net_nfc_util_gdbus_data_to_variant(atr);
-
- net_nfc_gdbus_secure_element_complete_get_atr(
- detail->object,
- detail->invocation,
- result,
- data);
-
- if (atr != NULL) {
- net_nfc_util_free_data(atr);
- g_free(atr);
- }
-
- g_object_unref(detail->invocation);
- g_object_unref(detail->object);
-
- g_free(detail);
-}
-
-static gboolean se_handle_get_atr(
- NetNfcGDbusSecureElement *object,
- GDBusMethodInvocation *invocation,
- guint arg_handle,
- GVariant *smack_privilege)
-{
- SeDataHandle *data;
- gboolean result;
-
- INFO_MSG(">>> REQUEST from [%s]",
- g_dbus_method_invocation_get_sender(invocation));
-
- /* check privilege and update client context */
- if (net_nfc_server_gdbus_check_privilege(invocation,
- smack_privilege,
- "nfc-manager",
- "r") == false) {
- DEBUG_ERR_MSG("permission denied, and finished request");
-
- return FALSE;
- }
-
- data = g_new0(SeDataHandle, 1);
- if (data == NULL)
- {
- DEBUG_ERR_MSG("Memory allocation failed");
- g_dbus_method_invocation_return_dbus_error(invocation,
- "org.tizen.NetNfcService.AllocationError",
- "Can not allocate memory");
-
- return FALSE;
- }
-
- data->object = g_object_ref(object);
- data->invocation = g_object_ref(invocation);
- data->handle = (net_nfc_target_handle_s *)arg_handle;
-
- result = net_nfc_server_controller_async_queue_push(
- se_get_atr_thread_func, data);
- if (result == FALSE)
- {
- g_dbus_method_invocation_return_dbus_error(invocation,
- "org.tizen.NetNfcService.Se.ThreadError",
- "can not push to controller thread");
-
- g_object_unref(data->object);
- g_object_unref(data->invocation);
-
- g_free(data);
- }
-
- return result;
-}
-
-static void se_open_secure_element_thread_func(gpointer user_data)
-{
- SeDataSeType *detail = (SeDataSeType *)user_data;
- net_nfc_target_handle_s *handle = NULL;
- net_nfc_error_e result = NET_NFC_OK;
-
- g_assert(detail != NULL);
- g_assert(detail->object != NULL);
- g_assert(detail->invocation != NULL);
-
-#if 0 /* opening SE doesn't affect card emulation */
- gdbus_se_prev_type = net_nfc_server_se_get_se_type();
- gdbus_se_prev_mode = net_nfc_server_se_get_se_mode();
-#endif
-
- if (detail->se_type == SECURE_ELEMENT_TYPE_UICC)
- {
-#if 0 /* opening SE doesn't affect card emulation */
- /*off ESE*/
- net_nfc_controller_set_secure_element_mode(
- SECURE_ELEMENT_TYPE_ESE,
- SECURE_ELEMENT_OFF_MODE, &result);
-
- /*Off UICC. UICC SHOULD not be detected by external reader when
- being communicated in internal process*/
- net_nfc_controller_set_secure_element_mode(SECURE_ELEMENT_TYPE_UICC,
- SECURE_ELEMENT_OFF_MODE, &result);
-
- net_nfc_server_se_set_se_type(SECURE_ELEMENT_TYPE_UICC);
- net_nfc_server_se_set_se_mode(SECURE_ELEMENT_OFF_MODE);
-#endif
- handle = (net_nfc_target_handle_s *)_se_uicc_open();
- if (handle != NULL)
- {
- result = NET_NFC_OK;
- }
- else
- {
- result = NET_NFC_INVALID_STATE;
- handle = NULL;
- }
- }
- else if (detail->se_type == SECURE_ELEMENT_TYPE_ESE)
- {
-#if 0 /* opening SE doesn't affect card emulation */
- /*off UICC*/
- net_nfc_controller_set_secure_element_mode(
- SECURE_ELEMENT_TYPE_UICC,
- SECURE_ELEMENT_OFF_MODE, &result);
-#endif
- handle = net_nfc_server_se_open_ese();
- if (handle != NULL)
- {
- result = NET_NFC_OK;
-#if 0 /* opening SE doesn't affect card emulation */
- net_nfc_server_se_set_se_type(SECURE_ELEMENT_TYPE_ESE);
- net_nfc_server_se_set_se_mode(SECURE_ELEMENT_WIRED_MODE);
-
- net_nfc_server_se_set_current_ese_handle(handle);
-#endif
- DEBUG_SERVER_MSG("handle [%p]", handle);
-
- /* increase client reference count */
- net_nfc_server_gdbus_increase_se_count(
- g_dbus_method_invocation_get_sender(
- detail->invocation));
- }
- else
- {
- result = NET_NFC_INVALID_STATE;
- handle = NULL;
- }
- }
- else
- {
- result = NET_NFC_INVALID_PARAM;
- handle = NULL;
- }
-
- net_nfc_gdbus_secure_element_complete_open_secure_element(
- detail->object,
- detail->invocation,
- result,
- (guint)handle);
-
- g_object_unref(detail->invocation);
- g_object_unref(detail->object);
-
- g_free(detail);
-}
-
-static gboolean se_handle_open_secure_element(
- NetNfcGDbusSecureElement *object,
- GDBusMethodInvocation *invocation,
- gint arg_type,
- GVariant *smack_privilege)
-{
- SeDataSeType *data;
- gboolean result;
-
- INFO_MSG(">>> REQUEST from [%s]",
- g_dbus_method_invocation_get_sender(invocation));
-
- /* check privilege and update client context */
- if (net_nfc_server_gdbus_check_privilege(invocation,
- smack_privilege,
- "nfc-manager",
- "rw") == false) {
- DEBUG_ERR_MSG("permission denied, and finished request");
-
- return FALSE;
- }
-
- data = g_new0(SeDataSeType, 1);
- if (data == NULL)
- {
- DEBUG_ERR_MSG("Memory allocation failed");
- g_dbus_method_invocation_return_dbus_error(invocation,
- "org.tizen.NetNfcService.AllocationError",
- "Can not allocate memory");
-
- return FALSE;
- }
-
- data->object = g_object_ref(object);
- data->invocation = g_object_ref(invocation);
- data->se_type= arg_type;
-
- result = net_nfc_server_controller_async_queue_push(
- se_open_secure_element_thread_func, data);
- if (result == FALSE)
- {
- g_dbus_method_invocation_return_dbus_error(invocation,
- "org.tizen.NetNfcService.Se.ThreadError",
- "can not push to controller thread");
-
- g_object_unref(data->object);
- g_object_unref(data->invocation);
-
- g_free(data);
- }
-
- return result;
-}
-
-static void se_send_apdu_thread_func(gpointer user_data)
-{
- SeDataApdu *detail = (SeDataApdu *)user_data;
- data_s apdu_data = { NULL, 0 };
- data_s *response = NULL;
- net_nfc_error_e result;
- GVariant *rspdata = NULL;
- bool ret;
-
- g_assert(detail != NULL);
- g_assert(detail->object != NULL);
- g_assert(detail->invocation != NULL);
-
- net_nfc_util_gdbus_variant_to_data_s(detail->data, &apdu_data);
-
- if (_se_is_uicc_handle(detail->handle) == true)
- {
- result = NET_NFC_NOT_SUPPORTED;
- }
- else if (net_nfc_server_se_is_ese_handle(detail->handle) == true)
- {
- ret = net_nfc_controller_secure_element_send_apdu(
- detail->handle, &apdu_data, &response, &result);
- }
- else
- {
- result = NET_NFC_INVALID_HANDLE;
- }
-
- rspdata = net_nfc_util_gdbus_data_to_variant(response);
-
- net_nfc_gdbus_secure_element_complete_send_apdu(
- detail->object,
- detail->invocation,
- result,
- rspdata);
-
- if (response != NULL)
- {
- net_nfc_util_free_data(response);
- g_free(response);
- }
-
- net_nfc_util_free_data(&apdu_data);
-
- g_variant_unref(detail->data);
-
- g_object_unref(detail->invocation);
- g_object_unref(detail->object);
-
- g_free(detail);
-}
-
-static gboolean se_handle_send_apdu(
- NetNfcGDbusSecureElement *object,
- GDBusMethodInvocation *invocation,
- guint arg_handle,
- GVariant *apdudata,
- GVariant *smack_privilege)
-{
- SeDataApdu *data;
- gboolean result;
-
- INFO_MSG(">>> REQUEST from [%s]",
- g_dbus_method_invocation_get_sender(invocation));
-
- /* check privilege and update client context */
- if (net_nfc_server_gdbus_check_privilege(invocation,
- smack_privilege,
- "nfc-manager",
- "rw") == false) {
- DEBUG_ERR_MSG("permission denied, and finished request");
-
- return FALSE;
- }
-
- data = g_new0(SeDataApdu, 1);
- if (data == NULL)
- {
- DEBUG_ERR_MSG("Memory allocation failed");
- g_dbus_method_invocation_return_dbus_error(invocation,
- "org.tizen.NetNfcService.AllocationError",
- "Can not allocate memory");
-
- return FALSE;
- }
-
- data->object = g_object_ref(object);
- data->invocation = g_object_ref(invocation);
- data->handle = (net_nfc_target_handle_s *)arg_handle;
- data->data = g_variant_ref(apdudata);
-
- result = net_nfc_server_controller_async_queue_push(
- se_send_apdu_thread_func, data);
- if (result == FALSE)
- {
- g_dbus_method_invocation_return_dbus_error(invocation,
- "org.tizen.NetNfcService.Se.ThreadError",
- "can not push to controller thread");
-
- g_variant_unref(data->data);
-
- g_object_unref(data->object);
- g_object_unref(data->invocation);
-
- g_free(data);
- }
-
- return result;
-}
-
-static void se_set_data_thread_func(gpointer user_data)
-{
- SeDataSeType *data = (SeDataSeType *)user_data;
- gboolean isTypeChanged = FALSE;
- net_nfc_error_e result = NET_NFC_OK;
-
- g_assert(data != NULL);
- g_assert(data->object != NULL);
- g_assert(data->invocation != NULL);
-
- if (data->se_type != net_nfc_server_se_get_se_type())
- {
- result = net_nfc_server_se_change_se(data->se_type);
- isTypeChanged = TRUE;
- }
-
- net_nfc_gdbus_secure_element_complete_set(data->object,
- data->invocation, result);
-
- if (isTypeChanged)
- net_nfc_gdbus_secure_element_emit_se_type_changed(data->object,
- data->se_type);
-
- g_object_unref(data->invocation);
- g_object_unref(data->object);
-
- g_free(data);
-}
-
-static gboolean se_handle_set(
- NetNfcGDbusSecureElement *object,
- GDBusMethodInvocation *invocation,
- gint arg_type,
- GVariant *smack_privilege)
-{
- SeDataSeType *data;
- gboolean result;
-
- INFO_MSG(">>> REQUEST from [%s]",
- g_dbus_method_invocation_get_sender(invocation));
-
- /* check privilege and update client context */
- if (net_nfc_server_gdbus_check_privilege(invocation,
- smack_privilege,
- "nfc-manager",
- "w") == false) {
- DEBUG_ERR_MSG("permission denied, and finished request");
-
- return FALSE;
- }
-
- data = g_new0(SeDataSeType, 1);
- if (data == NULL)
- {
- DEBUG_ERR_MSG("Memory allocation failed");
- g_dbus_method_invocation_return_dbus_error(invocation,
- "org.tizen.NetNfcService.AllocationError",
- "Can not allocate memory");
-
- return FALSE;
- }
-
- data->object = g_object_ref(object);
- data->invocation = g_object_ref(invocation);
- data->se_type = arg_type;
-
- result = net_nfc_server_controller_async_queue_push(
- se_set_data_thread_func, data);
- if (result == FALSE)
- {
- g_dbus_method_invocation_return_dbus_error(invocation,
- "org.tizen.NetNfcService.Se.ThreadError",
- "can not push to controller thread");
-
- g_object_unref(data->object);
- g_object_unref(data->invocation);
-
- g_free(data);
- }
-
- return result;
-}
-
-gboolean net_nfc_server_se_init(GDBusConnection *connection)
-{
- GError *error = NULL;
- gboolean result;
-
- if (se_skeleton)
- g_object_unref(se_skeleton);
-
- /* initialize UICC */
- _se_uicc_init();
-
- se_skeleton = net_nfc_gdbus_secure_element_skeleton_new();
-
- g_signal_connect(se_skeleton,
- "handle-set",
- G_CALLBACK(se_handle_set),
- NULL);
- g_signal_connect(se_skeleton,
- "handle-open-secure-element",
- G_CALLBACK(se_handle_open_secure_element),
- NULL);
-
- g_signal_connect(se_skeleton,
- "handle-close-secure-element",
- G_CALLBACK(se_handle_close_secure_element),
- NULL);
-
- g_signal_connect(se_skeleton,
- "handle-get-atr",
- G_CALLBACK(se_handle_get_atr),
- NULL);
-
- g_signal_connect(se_skeleton,
- "handle-send-apdu",
- G_CALLBACK(se_handle_send_apdu),
- NULL);
-
- result = g_dbus_interface_skeleton_export(
- G_DBUS_INTERFACE_SKELETON(se_skeleton),
- connection,
- "/org/tizen/NetNfcService/SecureElement",
- &error);
- if (result == FALSE)
- {
- DEBUG_ERR_MSG("can not skeleton_export %s", error->message);
-
- g_error_free(error);
-
- net_nfc_server_se_deinit();
- }
-
- return result;
-}
-
-void net_nfc_server_se_deinit(void)
-{
- if (se_skeleton)
- {
- g_object_unref(se_skeleton);
- se_skeleton = NULL;
-
- /* de-initialize UICC */
- _se_uicc_deinit();
- }
-}
-
-static void se_detected_thread_func(gpointer user_data)
-{
- net_nfc_target_handle_s *handle;
- uint32_t devType;
- GVariant *data;
- net_nfc_error_e result;
-
- g_assert(user_data != NULL);
-
- if (se_skeleton == NULL)
- {
- DEBUG_ERR_MSG("se skeleton is not initialized");
-
- g_variant_unref((GVariant *)user_data);
-
- return;
- }
-
- g_variant_get((GVariant *)user_data,
- "uu@a(y)",
- (guint *)&handle,
- &devType,
- &data);
-
- net_nfc_server_se_set_current_ese_handle(handle);
-
- DEBUG_SERVER_MSG("trying to connect to ESE = [0x%p]", handle);
-
- if (!net_nfc_controller_connect(handle, &result))
- {
- DEBUG_SERVER_MSG("connect failed = [%d]", result);
- }
-
- net_nfc_gdbus_secure_element_emit_ese_detected(
- se_skeleton,
- GPOINTER_TO_UINT(handle),
- devType,
- data);
-
- g_variant_unref((GVariant *)user_data);
-}
-
-static void se_transcation_thread_func(gpointer user_data)
-{
- ServerSeData *detail = (ServerSeData *)user_data;
-
- g_assert(user_data != NULL);
-
- if (detail->event == NET_NFC_MESSAGE_SE_START_TRANSACTION)
- {
- DEBUG_SERVER_MSG("launch se app");
-
- net_nfc_app_util_launch_se_transaction_app(
- detail->aid.buffer,
- detail->aid.length,
- detail->param.buffer,
- detail->param.length);
-
- DEBUG_SERVER_MSG("launch se app end");
- }
-
- net_nfc_util_free_data(&detail->param);
- net_nfc_util_free_data(&detail->aid);
-
- g_free(detail);
-}
-
-void net_nfc_server_se_detected(void *info)
-{
- net_nfc_request_target_detected_t *se_target =
- (net_nfc_request_target_detected_t *)info;
- GVariant *parameter;
- GVariant *data;
-
- data = net_nfc_util_gdbus_buffer_to_variant(
- se_target->target_info_values.buffer,
- se_target->target_info_values.length);
-
- parameter = g_variant_new("uu@a(y)",
- GPOINTER_TO_UINT(se_target->handle),
- se_target->devType,
- data);
- if (parameter != NULL) {
- if (net_nfc_server_controller_async_queue_push(
- se_detected_thread_func,
- parameter) == FALSE) {
- DEBUG_ERR_MSG("can not push to controller thread");
-
- g_variant_unref(parameter);
- }
- } else {
- DEBUG_ERR_MSG("g_variant_new failed");
- }
-
- /* FIXME : should be removed when plugins would be fixed*/
- _net_nfc_util_free_mem(info);
-}
-
-void net_nfc_server_se_transaction_received(void *info)
-{
- net_nfc_request_se_event_t *se_event =
- (net_nfc_request_se_event_t *)info;
- ServerSeData *detail;
-
- detail = g_new0(ServerSeData, 1);
- if (detail != NULL) {
- detail->event = se_event->request_type;
-
- if (se_event->aid.buffer != NULL && se_event->aid.length > 0) {
- if (net_nfc_util_alloc_data(&detail->aid,
- se_event->aid.length) == true) {
- memcpy(detail->aid.buffer, se_event->aid.buffer,
- se_event->aid.length);
- }
- }
-
- if (se_event->param.buffer != NULL &&
- se_event->param.length > 0) {
- if (net_nfc_util_alloc_data(&detail->param,
- se_event->param.length) == true) {
- memcpy(detail->param.buffer,
- se_event->param.buffer,
- se_event->param.length);
- }
- }
-
- if (net_nfc_server_controller_async_queue_push(
- se_transcation_thread_func, detail) == FALSE) {
- DEBUG_ERR_MSG("can not push to controller thread");
-
- net_nfc_util_free_data(&detail->param);
- net_nfc_util_free_data(&detail->aid);
-
- g_free(detail);
- }
- } else {
- DEBUG_ERR_MSG("g_new0 failed");
- }
-
- /* FIXME : should be removed when plugins would be fixed*/
- net_nfc_util_free_data(&se_event->param);
- net_nfc_util_free_data(&se_event->aid);
-
- _net_nfc_util_free_mem(info);
-}
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <glib.h>
-
-#include "net_nfc_debug_internal.h"
-#include "net_nfc_util_defines.h"
-#include "net_nfc_util_internal.h"
-#include "net_nfc_controller_internal.h"
-#include "net_nfc_server_common.h"
-#include "net_nfc_server_llcp.h"
-#include "net_nfc_server_snep.h"
-#include "net_nfc_server_process_snep.h"
-#include "net_nfc_util_gdbus_internal.h"
-#include "net_nfc_server_context_internal.h"
-
-/* declaration */
-static gboolean _handle_start_server(
- NetNfcGDbusSnep *object,
- GDBusMethodInvocation *invocation,
- guint arg_handle,
- guint arg_sap,
- const gchar *arg_san,
- guint arg_user_data,
- GVariant *arg_privilege);
-
-static gboolean _handle_start_client(
- NetNfcGDbusSnep *object,
- GDBusMethodInvocation *invocation,
- guint arg_handle,
- guint arg_sap,
- const gchar *arg_san,
- guint arg_user_data,
- GVariant *arg_privilege);
-
-static gboolean _handle_client_send_request(
- NetNfcGDbusSnep *object,
- GDBusMethodInvocation *invocation,
- guint arg_snep_handle,
- guint arg_type,
- GVariant *arg_ndef_msg,
- GVariant *arg_privilege);
-
-static gboolean _handle_stop_snep(
- NetNfcGDbusSnep *object,
- GDBusMethodInvocation *invocation,
- guint arg_handle,
- guint arg_snep_handle,
- GVariant *arg_privilege);
-
-static void snep_server_start_thread_func(gpointer user_data);
-
-static void snep_client_start_thread_func(gpointer user_data);
-
-static void snep_client_send_request_thread_func(gpointer user_data);
-
-static void snep_stop_service_thread_func(gpointer user_data);
-
-/* definition */
-static NetNfcGDbusSnep *snep_skeleton = NULL;
-
-static void _emit_snep_event_signal(GVariant *parameter,
- net_nfc_snep_handle_h handle,
- net_nfc_error_e result,
- uint32_t type,
- data_s *data)
-{
- GDBusConnection *connection;
- char *client_id;
- void *user_data;
- GVariant *arg_data;
- GError *error = NULL;
-
- g_variant_get(parameter, "(usu)",
- (guint *)&connection,
- &client_id,
- (guint *)&user_data);
-
- arg_data = net_nfc_util_gdbus_data_to_variant(data);
-
- if (g_dbus_connection_emit_signal(
- connection,
- client_id,
- "/org/tizen/NetNfcService/Snep",
- "org.tizen.NetNfcService.Snep",
- "SnepEvent",
- g_variant_new("(uui@a(y)u)",
- GPOINTER_TO_UINT(handle),
- type,
- (gint)result,
- arg_data,
- GPOINTER_TO_UINT(user_data)),
- &error) == false) {
- if (error != NULL && error->message != NULL) {
- DEBUG_ERR_MSG("g_dbus_connection_emit_signal failed : %s", error->message);
- } else {
- DEBUG_ERR_MSG("g_dbus_connection_emit_signal failed");
- }
- }
-
- g_free(client_id);
-}
-
-static net_nfc_error_e _snep_server_cb(net_nfc_snep_handle_h handle,
- net_nfc_error_e result,
- uint32_t type,
- data_s *data,
- void *user_param)
-{
- GVariant *parameter = (GVariant *)user_param;
-
- data_s *temp = data;
-
- DEBUG_SERVER_MSG("type [%d], result [%d], data [%p], user_param [%p]",
- type, result, data, user_param);
-
- switch (type)
- {
- case SNEP_REQ_GET :
- {
- uint32_t max_len = 0;
-
- net_nfc_server_snep_parse_get_request(data, &max_len,
- temp);
- }
- break;
-
- case SNEP_REQ_PUT :
- break;
-
- default :
- DEBUG_ERR_MSG("error [%d]", result);
- break;
- }
-
- if (result < NET_NFC_OK) {
- type = NET_NFC_LLCP_STOP;
- }
-
- _emit_snep_event_signal(parameter, handle,
- result, type, data);
-
- if (type == NET_NFC_LLCP_STOP) {
- g_object_unref(parameter);
- }
-
- return result;
-}
-
-static void snep_server_start_thread_func(gpointer user_data)
-{
- NetNfcGDbusSnep *object;
- GDBusMethodInvocation *invocation;
- net_nfc_target_handle_s *arg_handle;
- guint arg_sap;
- gchar *arg_san;
- void *arg_user_data;
- net_nfc_error_e result;
-
- GVariant *parameter;
- GDBusConnection *connection;
-
- if (user_data == NULL)
- {
- DEBUG_ERR_MSG("cannot get SNEP client data");
-
- return;
- }
-
- g_variant_get((GVariant *)user_data,
- "(uuuusu)",
- (guint *)&object,
- (guint *)&invocation,
- (guint *)&arg_handle,
- &arg_sap,
- &arg_san,
- (guint *)&arg_user_data);
-
- g_assert(object != NULL);
- g_assert(invocation != NULL);
-
- connection = g_dbus_method_invocation_get_connection(invocation);
-
- parameter = g_variant_new("(usu)",
- GPOINTER_TO_UINT(g_object_ref(connection)),
- g_dbus_method_invocation_get_sender(invocation),
- GPOINTER_TO_UINT(arg_user_data));
- if (parameter != NULL) {
- result = net_nfc_server_snep_server(arg_handle,
- arg_san,
- arg_sap,
- _snep_server_cb,
- parameter);
- if (result != NET_NFC_OK) {
- DEBUG_ERR_MSG("net_nfc_server_snep_server failed, [%d]",
- result);
- g_object_unref(connection);
-
- g_variant_unref(parameter);
- }
- } else {
- DEBUG_ERR_MSG("g_variant_new failed");
-
- g_object_unref(connection);
-
- result = NET_NFC_ALLOC_FAIL;
- }
-
- net_nfc_gdbus_snep_complete_server_start(object, invocation, result);
-
- g_free(arg_san);
-
- g_variant_unref(user_data);
-}
-
-static gboolean _handle_start_server(
- NetNfcGDbusSnep *object,
- GDBusMethodInvocation *invocation,
- guint arg_handle,
- guint arg_sap,
- const gchar *arg_san,
- guint arg_user_data,
- GVariant *arg_privilege)
-{
- GVariant *parameter;
- gboolean result;
-
- INFO_MSG(">>> REQUEST from [%s]",
- g_dbus_method_invocation_get_sender(invocation));
-
- /* check privilege and update client context */
- if (net_nfc_server_gdbus_check_privilege(invocation,
- arg_privilege,
- "nfc-manager::p2p",
- "rw") == false) {
- DEBUG_ERR_MSG("permission denied, and finished request");
-
- return FALSE;
- }
-
- parameter = g_variant_new("(uuuusu)",
- GPOINTER_TO_UINT(g_object_ref(object)),
- GPOINTER_TO_UINT(g_object_ref(invocation)),
- arg_handle,
- arg_sap,
- arg_san,
- arg_user_data);
-
- if (parameter != NULL)
- {
- if ((result = net_nfc_server_controller_async_queue_push(
- snep_server_start_thread_func, parameter)) == FALSE)
- {
- DEBUG_ERR_MSG("net_nfc_server_controller_async_queue_push failed");
-
- g_dbus_method_invocation_return_dbus_error(invocation,
- "org.tizen.NetNfcService.Snep.ThreadError",
- "can not push to controller thread");
-
- g_object_unref(invocation);
- g_object_unref(object);
-
- g_variant_unref(parameter);
- }
- }
- else
- {
- DEBUG_ERR_MSG("g_variant_new failed");
-
- g_dbus_method_invocation_return_dbus_error(invocation,
- "org.tizen.NetNfcService.Snep.MemoryError",
- "Out of memory");
-
- result = FALSE;
- }
-
- return result;
-}
-
-static net_nfc_error_e _snep_start_client_cb(
- net_nfc_snep_handle_h handle,
- net_nfc_error_e result,
- uint32_t type,
- data_s *data,
- void *user_param)
-{
- GVariant *parameter = (GVariant *)user_param;
-
- DEBUG_SERVER_MSG("type [%d], result [%d], data [%p], user_param [%p]",
- type, result, data, user_param);
-
- _emit_snep_event_signal(parameter, handle, result, type, data);
-
- if (type == NET_NFC_LLCP_STOP) {
- g_variant_unref(parameter);
- }
-
- return result;
-}
-
-static void snep_client_start_thread_func(gpointer user_data)
-{
- NetNfcGDbusSnep *object;
- GDBusMethodInvocation *invocation;
- net_nfc_target_handle_s *arg_handle;
- guint arg_sap;
- gchar *arg_san;
- void *arg_user_data;
- net_nfc_error_e result;
-
- GVariant *parameter;
- GDBusConnection *connection;
-
- if (user_data == NULL)
- {
- DEBUG_ERR_MSG("cannot get SNEP client data");
-
- return;
- }
-
- g_variant_get((GVariant *)user_data,
- "(uuuusu)",
- (guint *)&object,
- (guint *)&invocation,
- (guint *)&arg_handle,
- &arg_sap,
- &arg_san,
- (guint *)&arg_user_data);
-
- g_assert(object != NULL);
- g_assert(invocation != NULL);
-
- connection = g_dbus_method_invocation_get_connection(invocation);
-
- parameter = g_variant_new("(usu)",
- GPOINTER_TO_UINT(g_object_ref(connection)),
- g_dbus_method_invocation_get_sender(invocation),
- GPOINTER_TO_UINT(arg_user_data));
- if (parameter != NULL) {
- result = net_nfc_server_snep_client(arg_handle,
- arg_san,
- arg_sap,
- _snep_start_client_cb,
- parameter);
- if (result != NET_NFC_OK) {
- DEBUG_ERR_MSG("net_nfc_server_snep_client failed, [%d]",
- result);
- g_object_unref(connection);
-
- g_variant_unref(parameter);
- }
- } else {
- DEBUG_ERR_MSG("g_variant_new failed");
-
- g_object_unref(connection);
-
- result = NET_NFC_ALLOC_FAIL;
- }
-
- net_nfc_gdbus_snep_complete_client_start(object, invocation, result);
-
- g_free(arg_san);
-
- g_variant_unref(user_data);
-}
-
-static gboolean _handle_start_client(
- NetNfcGDbusSnep *object,
- GDBusMethodInvocation *invocation,
- guint arg_handle,
- guint arg_sap,
- const gchar *arg_san,
- guint arg_user_data,
- GVariant *arg_privilege)
-{
- GVariant *parameter;
- gboolean result;
-
- INFO_MSG(">>> REQUEST from [%s]",
- g_dbus_method_invocation_get_sender(invocation));
-
- /* check privilege and update client context */
- if (net_nfc_server_gdbus_check_privilege(invocation,
- arg_privilege,
- "nfc-manager::p2p",
- "rw") == false) {
- DEBUG_ERR_MSG("permission denied, and finished request");
-
- return FALSE;
- }
-
- parameter = g_variant_new("(uuuusu)",
- GPOINTER_TO_UINT(g_object_ref(object)),
- GPOINTER_TO_UINT(g_object_ref(invocation)),
- arg_handle,
- arg_sap,
- arg_san,
- arg_user_data);
-
- if (parameter != NULL)
- {
- if ((result = net_nfc_server_controller_async_queue_push(
- snep_client_start_thread_func, parameter)) == FALSE)
- {
- DEBUG_ERR_MSG("net_nfc_server_controller_async_queue_push failed");
-
- g_dbus_method_invocation_return_dbus_error(invocation,
- "org.tizen.NetNfcService.Snep.ThreadError",
- "can not push to controller thread");
-
- g_object_unref(invocation);
- g_object_unref(object);
-
- g_object_unref(g_variant_unref);
- }
- }
- else
- {
- DEBUG_ERR_MSG("g_variant_new failed");
-
- g_dbus_method_invocation_return_dbus_error(invocation,
- "org.tizen.NetNfcService.Snep.MemoryError",
- "Out of memory");
-
- result = FALSE;
- }
-
- return result;
-}
-
-static net_nfc_error_e _snep_client_request_cb(
- net_nfc_snep_handle_h handle,
- net_nfc_error_e result,
- net_nfc_snep_type_t type,
- data_s *data,
- void *user_param)
-{
- GVariant *parameter = (GVariant *)user_param;
-
- DEBUG_SERVER_MSG("type [%d], result [%d], data [%p], user_param [%p]",
- type, result, data, user_param);
-
- if (parameter != NULL) {
- NetNfcGDbusSnep *object;
- GDBusMethodInvocation *invocation;
- net_nfc_snep_handle_h arg_snep_handle;
- net_nfc_snep_type_t arg_type;
- GVariant *arg_ndef_msg;
- GVariant *arg_data = NULL;
-
- g_variant_get(parameter,
- "(uuuu@a(y))",
- (guint *)&object,
- (guint *)&invocation,
- (guint *)&arg_snep_handle,
- (guint *)&arg_type,
- &arg_ndef_msg);
-
- if (data != NULL && data->buffer != NULL && data->length > 0) {
- arg_data = net_nfc_util_gdbus_data_to_variant(data);
- } else {
- arg_data = net_nfc_util_gdbus_buffer_to_variant(NULL, 0);
- }
-
- net_nfc_gdbus_snep_complete_client_request(object,
- invocation,
- result,
- type,
- arg_data);
-
- g_variant_unref(arg_ndef_msg);
-
- g_object_unref(invocation);
- g_object_unref(object);
-
- g_variant_unref(parameter);
-
- result = NET_NFC_OK;
- } else {
- result = NET_NFC_NULL_PARAMETER;
- }
-
- return result;
-}
-
-static void snep_client_send_request_thread_func(gpointer user_data)
-{
- NetNfcGDbusSnep *object;
- GDBusMethodInvocation *invocation;
- net_nfc_snep_handle_h arg_snep_handle;
- net_nfc_snep_type_t arg_type;
- GVariant *arg_ndef_msg;
- data_s data = { NULL, };
- net_nfc_error_e result;
-
- if (user_data == NULL)
- {
- DEBUG_ERR_MSG("cannot get SNEP client data");
-
- return;
- }
-
- g_variant_get((GVariant *)user_data,
- "(uuuu@a(y))",
- (guint *)&object,
- (guint *)&invocation,
- (guint *)&arg_snep_handle,
- (guint *)&arg_type,
- &arg_ndef_msg);
-
- g_assert(object != NULL);
- g_assert(invocation != NULL);
-
- net_nfc_util_gdbus_variant_to_data_s(arg_ndef_msg, &data);
-
- result = net_nfc_server_snep_client_request(arg_snep_handle,
- arg_type,
- &data,
- _snep_client_request_cb,
- user_data);
- if (result != NET_NFC_OK)
- {
- GVariant *resp;
-
- DEBUG_ERR_MSG("net_nfc_server_snep_client_request "
- "failed, [%d]",result);
-
- resp = net_nfc_util_gdbus_buffer_to_variant(NULL, 0);
-
- net_nfc_gdbus_snep_complete_client_request(object,
- invocation, result, NET_NFC_LLCP_STOP, resp);
-
- g_object_unref(invocation);
- g_object_unref(object);
-
- g_variant_unref(user_data);
- }
-
- net_nfc_util_free_data(&data);
-
- g_variant_unref(arg_ndef_msg);
-}
-
-static gboolean _handle_client_send_request(
- NetNfcGDbusSnep *object,
- GDBusMethodInvocation *invocation,
- guint arg_snep_handle,
- guint arg_type,
- GVariant *arg_ndef_msg,
- GVariant *arg_privilege)
-{
- GVariant *parameter;
- gboolean result;
-
- INFO_MSG(">>> REQUEST from [%s]",
- g_dbus_method_invocation_get_sender(invocation));
-
- /* check privilege and update client context */
- if (net_nfc_server_gdbus_check_privilege(invocation,
- arg_privilege,
- "nfc-manager::p2p",
- "rw") == false) {
- DEBUG_ERR_MSG("permission denied, and finished request");
-
- return FALSE;
- }
-
- parameter = g_variant_new("(uuuu@a(y))",
- GPOINTER_TO_UINT(g_object_ref(object)),
- GPOINTER_TO_UINT(g_object_ref(invocation)),
- arg_snep_handle,
- arg_type,
- arg_ndef_msg);
-
- if (parameter != NULL)
- {
- if ((result = net_nfc_server_controller_async_queue_push(
- snep_client_send_request_thread_func, parameter)) == FALSE)
- {
- DEBUG_ERR_MSG("net_nfc_server_controller_async_queue_push failed");
-
- g_dbus_method_invocation_return_dbus_error(invocation,
- "org.tizen.NetNfcService.Snep.ThreadError",
- "can not push to controller thread");
-
- g_object_unref(invocation);
- g_object_unref(object);
-
- g_variant_unref(parameter);
- }
- }
- else
- {
- DEBUG_ERR_MSG("g_variant_new failed");
-
- g_dbus_method_invocation_return_dbus_error(invocation,
- "org.tizen.NetNfcService.Snep.MemoryError",
- "Out of memory");
-
- result = FALSE;
- }
-
- return result;
-}
-
-static void snep_stop_service_thread_func(gpointer user_data)
-{
- NetNfcGDbusSnep *object;
- GDBusMethodInvocation *invocation;
- net_nfc_target_handle_s *handle;
- net_nfc_snep_handle_h snep_handle;
-
- if (user_data == NULL)
- {
- DEBUG_ERR_MSG("cannot get SNEP client data");
-
- return;
- }
-
- g_variant_get((GVariant *)user_data,
- "(uuuu)",
- (guint *)&object,
- (guint *)&invocation,
- (guint *)&handle,
- (guint *)&snep_handle);
-
- g_assert(object != NULL);
- g_assert(invocation != NULL);
-
- /* TODO :
- g_dbus_method_invocation_return_dbus_error(
- invocation,
- "org.tizen.NetNfcService.Snep.DataError",
- "Cannot stop SNEP service");
- */
-
- net_nfc_gdbus_snep_complete_stop_snep(object,
- invocation,
- NET_NFC_OK);
-
- g_object_unref(invocation);
- g_object_unref(object);
-
- g_variant_unref(user_data);
-}
-
-static gboolean _handle_stop_snep(
- NetNfcGDbusSnep *object,
- GDBusMethodInvocation *invocation,
- guint arg_handle,
- guint arg_snep_handle,
- GVariant *arg_privilege)
-{
- GVariant *parameter;
- gboolean result;
-
- INFO_MSG(">>> REQUEST from [%s]",
- g_dbus_method_invocation_get_sender(invocation));
-
- /* check privilege and update client context */
- if (net_nfc_server_gdbus_check_privilege(invocation,
- arg_privilege,
- "nfc-manager::p2p",
- "rw") == false) {
- DEBUG_ERR_MSG("permission denied, and finished request");
-
- return FALSE;
- }
-
- parameter = g_variant_new("(uuuu)",
- GPOINTER_TO_UINT(g_object_ref(object)),
- GPOINTER_TO_UINT(g_object_ref(invocation)),
- arg_handle,
- arg_snep_handle);
-
- if (parameter != NULL)
- {
- if ((result = net_nfc_server_controller_async_queue_push(
- snep_stop_service_thread_func, parameter)) == FALSE)
- {
- DEBUG_ERR_MSG("net_nfc_server_controller_async_queue_push failed");
-
- g_dbus_method_invocation_return_dbus_error(invocation,
- "org.tizen.NetNfcService.Snep.ThreadError",
- "can not push to controller thread");
-
- g_object_unref(invocation);
- g_object_unref(object);
-
- g_variant_unref(parameter);
- }
- }
- else
- {
- DEBUG_ERR_MSG("g_variant_new failed");
-
- g_dbus_method_invocation_return_dbus_error(invocation,
- "org.tizen.NetNfcService.Snep.MemoryError",
- "Out of memory");
-
- result = FALSE;
- }
-
- return result;
-}
-
-static void _snep_activate_cb(int event, net_nfc_target_handle_s *handle,
- uint32_t sap, const char *san, void *user_param)
-{
- GVariant *parameter = (GVariant *)user_param;
- net_nfc_error_e result = NET_NFC_OK;
-
- DEBUG_SERVER_MSG("event [%d], handle [%p], sap [%d], san [%s]",
- event, handle, sap, san);
-
- if (event == NET_NFC_LLCP_START) {
- GDBusConnection *connection;
- GVariant *param = NULL;
- char *client_id;
- void *user_data;
-
- /* start server */
- g_variant_get(parameter, "(usu)",
- (guint *)&connection,
- &client_id,
- (guint *)&user_data);
-
- param = g_variant_new("(usu)",
- GPOINTER_TO_UINT(g_object_ref(connection)),
- client_id,
- GPOINTER_TO_UINT(user_data));
-
- g_free(client_id);
-
- result = net_nfc_server_snep_server(handle, (char *)san, sap,
- _snep_server_cb, param);
- if (result == NET_NFC_OK) {
- _emit_snep_event_signal(parameter, handle,
- result, event, NULL);
- } else {
- DEBUG_ERR_MSG("net_nfc_server_snep_server failed, [%d]",
- result);
-
- g_variant_unref(param);
- }
- } else {
- _emit_snep_event_signal(parameter, handle,
- result, NET_NFC_LLCP_UNREGISTERED, NULL);
-
- /* unregister server */
- g_variant_unref(parameter);
- }
-}
-
-static void snep_register_server_thread_func(gpointer user_data)
-{
- NetNfcGDbusSnep *object;
- GDBusMethodInvocation *invocation;
- guint arg_sap;
- gchar *arg_san;
- guint arg_user_data;
-
- net_nfc_error_e result;
- GVariant *parameter = NULL;
- GDBusConnection *connection;
-
- g_assert(user_data != NULL);
-
- g_variant_get((GVariant *)user_data,
- "(uuusu)",
- (guint *)&object,
- (guint *)&invocation,
- &arg_sap,
- &arg_san,
- &arg_user_data);
-
- g_assert(object != NULL);
- g_assert(invocation != NULL);
-
- connection = g_dbus_method_invocation_get_connection(invocation);
-
- parameter = g_variant_new("(usu)",
- GPOINTER_TO_UINT(g_object_ref(connection)),
- g_dbus_method_invocation_get_sender(invocation),
- arg_user_data);
- if (parameter != NULL) {
- /* register default snep server */
- result = net_nfc_server_llcp_register_service(
- g_dbus_method_invocation_get_sender(invocation),
- arg_sap,
- arg_san,
- _snep_activate_cb,
- parameter);
- if (result != NET_NFC_OK) {
- DEBUG_ERR_MSG("net_nfc_service_llcp_register_service failed, [%d]", result);
- g_object_unref(connection);
- g_variant_unref(parameter);
- }
- } else {
- result = NET_NFC_ALLOC_FAIL;
- g_object_unref(connection);
- }
-
- net_nfc_gdbus_snep_complete_server_register(object,
- invocation,
- result);
-
- g_free(arg_san);
-
- g_object_unref(invocation);
- g_object_unref(object);
-
- g_variant_unref(user_data);
-}
-
-static gboolean _handle_register_server(
- NetNfcGDbusSnep *object,
- GDBusMethodInvocation *invocation,
- guint arg_sap,
- const gchar *arg_san,
- guint arg_user_data,
- GVariant *arg_privilege)
-{
- GVariant *parameter;
- gboolean result;
-
- INFO_MSG(">>> REQUEST from [%s]",
- g_dbus_method_invocation_get_sender(invocation));
-
- /* check privilege and update client context */
- if (net_nfc_server_gdbus_check_privilege(invocation,
- arg_privilege,
- "nfc-manager::p2p",
- "rw") == false) {
- DEBUG_ERR_MSG("permission denied, and finished request");
-
- return FALSE;
- }
-
- parameter = g_variant_new("(uuusu)",
- GPOINTER_TO_UINT(g_object_ref(object)),
- GPOINTER_TO_UINT(g_object_ref(invocation)),
- arg_sap,
- arg_san,
- arg_user_data);
-
- if (parameter != NULL)
- {
- if ((result = net_nfc_server_controller_async_queue_push(
- snep_register_server_thread_func, parameter)) == FALSE)
- {
- DEBUG_ERR_MSG("net_nfc_server_controller_async_queue_push failed");
-
- g_dbus_method_invocation_return_dbus_error(invocation,
- "org.tizen.NetNfcService.Snep.ThreadError",
- "can not push to controller thread");
-
- g_object_unref(invocation);
- g_object_unref(object);
-
- g_variant_unref(parameter);
- }
- }
- else
- {
- DEBUG_ERR_MSG("g_variant_new failed");
-
- g_dbus_method_invocation_return_dbus_error(invocation,
- "org.tizen.NetNfcService.Snep.MemoryError",
- "Out of memory");
-
- result = FALSE;
- }
-
- return result;
-}
-
-static void snep_unregister_server_thread_func(gpointer user_data)
-{
- NetNfcGDbusSnep *object;
- GDBusMethodInvocation *invocation;
- guint arg_sap;
- gchar *arg_san;
-
- net_nfc_error_e result;
-
- g_assert(user_data != NULL);
-
- g_variant_get((GVariant *)user_data,
- "(uuus)",
- (guint *)&object,
- (guint *)&invocation,
- &arg_sap,
- &arg_san);
-
- g_assert(object != NULL);
- g_assert(invocation != NULL);
-
- result = net_nfc_server_llcp_unregister_service(
- g_dbus_method_invocation_get_sender(invocation),
- arg_sap,
- arg_san);
-
- net_nfc_gdbus_snep_complete_server_unregister(object,
- invocation,
- result);
-
- g_free(arg_san);
-
- g_object_unref(invocation);
- g_object_unref(object);
-
- g_variant_unref(user_data);
-}
-
-static gboolean _handle_unregister_server(
- NetNfcGDbusSnep *object,
- GDBusMethodInvocation *invocation,
- guint arg_sap,
- const gchar *arg_san,
- GVariant *arg_privilege)
-{
- GVariant *parameter;
- gboolean result;
-
- INFO_MSG(">>> REQUEST from [%s]",
- g_dbus_method_invocation_get_sender(invocation));
-
- /* check privilege and update client context */
- if (net_nfc_server_gdbus_check_privilege(invocation,
- arg_privilege,
- "nfc-manager::p2p",
- "rw") == false) {
- DEBUG_ERR_MSG("permission denied, and finished request");
-
- return FALSE;
- }
-
- parameter = g_variant_new("(uuus)",
- GPOINTER_TO_UINT(g_object_ref(object)),
- GPOINTER_TO_UINT(g_object_ref(invocation)),
- arg_sap,
- arg_san);
-
- if (parameter != NULL)
- {
- if ((result = net_nfc_server_controller_async_queue_push(
- snep_unregister_server_thread_func, parameter)) == FALSE)
- {
- DEBUG_ERR_MSG("net_nfc_server_controller_async_queue_push failed");
-
- g_dbus_method_invocation_return_dbus_error(invocation,
- "org.tizen.NetNfcService.Snep.ThreadError",
- "can not push to controller thread");
-
- g_object_unref(invocation);
- g_object_unref(object);
-
- g_variant_unref(parameter);
- }
- }
- else
- {
- DEBUG_ERR_MSG("g_variant_new failed");
-
- g_dbus_method_invocation_return_dbus_error(invocation,
- "org.tizen.NetNfcService.Snep.MemoryError",
- "Out of memory");
-
- result = FALSE;
- }
-
- return result;
-}
-
-gboolean net_nfc_server_snep_init(GDBusConnection *connection)
-{
- GError *error = NULL;
- gboolean result;
-
- if (snep_skeleton)
- g_object_unref(snep_skeleton);
-
- snep_skeleton = net_nfc_gdbus_snep_skeleton_new();
-
- g_signal_connect(snep_skeleton,
- "handle-server-register",
- G_CALLBACK(_handle_register_server),
- NULL);
-
- g_signal_connect(snep_skeleton,
- "handle-server-unregister",
- G_CALLBACK(_handle_unregister_server),
- NULL);
-
- g_signal_connect(snep_skeleton,
- "handle-server-start",
- G_CALLBACK(_handle_start_server),
- NULL);
-
- g_signal_connect(snep_skeleton,
- "handle-client-start",
- G_CALLBACK(_handle_start_client),
- NULL);
-
- g_signal_connect(snep_skeleton,
- "handle-client-request",
- G_CALLBACK(_handle_client_send_request),
- NULL);
-
- g_signal_connect(snep_skeleton,
- "handle-stop-snep",
- G_CALLBACK(_handle_stop_snep),
- NULL);
-
- result = g_dbus_interface_skeleton_export(
- G_DBUS_INTERFACE_SKELETON(snep_skeleton),
- connection,
- "/org/tizen/NetNfcService/Snep",
- &error);
- if (result == FALSE)
- {
- g_error_free(error);
-
- net_nfc_server_snep_deinit();
- }
-
- return result;
-}
-
-void net_nfc_server_snep_deinit(void)
-{
- if (snep_skeleton)
- {
- g_object_unref(snep_skeleton);
- snep_skeleton = NULL;
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#include "net_nfc_gdbus.h"
-#include "net_nfc_debug_internal.h"
-#include "net_nfc_server_common.h"
-#include "net_nfc_server_context_internal.h"
-#include "net_nfc_server_system_handler.h"
-
-
-static NetNfcGDbusPopup *popup_skeleton = NULL;
-
-static gboolean popup_handle_set(NetNfcGDbusPopup *popup_manager,
- GDBusMethodInvocation *invocation,
- gboolean state,
- gint focus_state,
- GVariant *smack_privilege,
- gpointer user_data);
-
-static gboolean popup_handle_get(NetNfcGDbusPopup *popup_manager,
- GDBusMethodInvocation *invocation,
- GVariant *smack_privilege,
- gpointer user_data);
-
-static gboolean popup_handle_set(NetNfcGDbusPopup *popup_manager,
- GDBusMethodInvocation *invocation,
- gboolean state,
- gint focus_state,
- GVariant *smack_privilege,
- gpointer user_data)
-{
- INFO_MSG(">>> REQUEST from [%s]",
- g_dbus_method_invocation_get_sender(invocation));
-
- /* check privilege and update client context */
- if (net_nfc_server_gdbus_check_privilege(invocation,
- smack_privilege,
- "nfc-manager",
- "w") == false) {
- DEBUG_ERR_MSG("permission denied, and finished request");
-
- return FALSE;
- }
-
- net_nfc_server_gdbus_set_launch_state(
- g_dbus_method_invocation_get_sender(invocation),
- state, focus_state);
-
- net_nfc_gdbus_popup_complete_set(popup_manager, invocation);
-
- return TRUE;
-}
-
-static gboolean popup_handle_get(NetNfcGDbusPopup *popup_manager,
- GDBusMethodInvocation *invocation,
- GVariant *smack_privilege,
- gpointer user_data)
-{
- gboolean state;
-
- INFO_MSG(">>> REQUEST from [%s]",
- g_dbus_method_invocation_get_sender(invocation));
-
- /* check privilege and update client context */
- if (net_nfc_server_gdbus_check_privilege(invocation,
- smack_privilege,
- "nfc-manager",
- "r") == false) {
- DEBUG_ERR_MSG("permission denied, and finished request");
-
- return FALSE;
- }
-
- state = net_nfc_server_gdbus_get_launch_state(
- g_dbus_method_invocation_get_sender(invocation));
-
- net_nfc_gdbus_popup_complete_get(popup_manager, invocation, state);
-
- return TRUE;
-}
-
-gboolean net_nfc_server_system_handler_init(GDBusConnection *connection)
-{
- GError *error = NULL;
- gboolean result;
-
- if (popup_skeleton)
- g_object_unref(popup_skeleton);
-
- popup_skeleton = net_nfc_gdbus_popup_skeleton_new();
- if (popup_skeleton == NULL)
- {
- DEBUG_ERR_MSG("Failed to allocate popup skeleton");
-
- return FALSE;
- }
-
- g_signal_connect(popup_skeleton,
- "handle-set",
- G_CALLBACK(popup_handle_set),
- NULL);
-
- g_signal_connect(popup_skeleton,
- "handle-get",
- G_CALLBACK(popup_handle_get),
- NULL);
-
- result = g_dbus_interface_skeleton_export(
- G_DBUS_INTERFACE_SKELETON(popup_skeleton),
- connection,
- "/org/tizen/NetNfcService/Popup",
- &error);
- if (result == FALSE)
- {
- DEBUG_ERR_MSG("Can not skeleton_export %s", error->message);
-
- g_error_free(error);
- g_object_unref(popup_skeleton);
- popup_skeleton = NULL;
- }
-
- return result;
-}
-
-void net_nfc_server_system_handler_deinit(void)
-{
- if(popup_skeleton)
- {
- g_object_unref(popup_skeleton);
- popup_skeleton = NULL;
- }
-
-}
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "net_nfc_debug_internal.h"
-#include "net_nfc_util_internal.h"
-#include "net_nfc_util_gdbus_internal.h"
-#include "net_nfc_controller_internal.h"
-#include "net_nfc_app_util_internal.h"
-#include "net_nfc_gdbus.h"
-#include "net_nfc_server_common.h"
-#include "net_nfc_server_context_internal.h"
-#include "net_nfc_server_tag.h"
-#include "net_nfc_server_p2p.h"
-#include "net_nfc_server_process_handover.h"
-#include "net_nfc_util_ndef_record.h"
-
-typedef struct _CurrentTagInfoData CurrentTagInfoData;
-
-struct _CurrentTagInfoData
-{
- NetNfcGDbusTag *tag;
- GDBusMethodInvocation *invocation;
-};
-
-typedef struct _WatchDogData WatchDogData;
-
-struct _WatchDogData
-{
- net_nfc_target_type_e dev_type;
- net_nfc_target_handle_s *handle;
-};
-
-
-static gboolean tag_is_isp_dep_ndef_formatable(net_nfc_target_handle_s *handle,
- int dev_type);
-
-static gboolean tag_read_ndef_message(net_nfc_target_handle_s *handle,
- int dev_type,
- data_s **read_ndef);
-
-static void tag_watchdog_thread_func(gpointer user_data);
-
-static void tag_get_current_tag_info_thread_func(gpointer user_data);
-
-static void tag_slave_target_detected_thread_func(gpointer user_data);
-
-
-/* methods */
-static gboolean tag_handle_is_tag_connected(NetNfcGDbusTag *tag,
- GDBusMethodInvocation *invocation,
- GVariant *smack_privilege,
- gpointer user_data);
-
-static gboolean tag_handle_get_current_tag_info(NetNfcGDbusTag *tag,
- GDBusMethodInvocation *invocation,
- GVariant *smack_privilege,
- gpointer user_data);
-
-static gboolean tag_handle_get_current_target_handle(NetNfcGDbusTag *tag,
- GDBusMethodInvocation *invocation,
- GVariant *smack_privilege,
- gpointer user_data);
-
-static NetNfcGDbusTag *tag_skeleton = NULL;
-
-static net_nfc_current_target_info_s *current_target_info = NULL;
-
-static gboolean tag_is_isp_dep_ndef_formatable(net_nfc_target_handle_s *handle,
- int dev_type)
-{
- uint8_t cmd[] = { 0x90, 0x60, 0x00, 0x00, 0x00 };
-
- net_nfc_transceive_info_s info;
- data_s *response = NULL;
- net_nfc_error_e error = NET_NFC_OK;
- gboolean result = false;
-
- info.dev_type = dev_type;
- info.trans_data.buffer = cmd;
- info.trans_data.length = sizeof(cmd);
-
- if (net_nfc_controller_transceive(handle,
- &info,
- &response,
- &error) == false)
- {
- DEBUG_ERR_MSG("net_nfc_controller_transceive is failed");
-
- return result;
- }
-
- if (response != NULL)
- {
- if (response->length == 9 &&
- response->buffer[7] == (uint8_t)0x91 &&
- response->buffer[8] == (uint8_t)0xAF)
- {
- result = TRUE;
- }
-
- net_nfc_util_free_data(response);
- g_free(response);
- }
- else
- {
- DEBUG_ERR_MSG("response is NULL");
- }
-
- return result;
-}
-
-static gboolean tag_read_ndef_message(net_nfc_target_handle_s *handle,
- int dev_type,
- data_s **read_ndef)
-{
- net_nfc_error_e result = NET_NFC_OK;
- data_s *temp = NULL;
-
- if (handle == NULL)
- return FALSE;
-
- if (read_ndef == NULL)
- return FALSE;
-
- *read_ndef = NULL;
-
- if (dev_type == NET_NFC_MIFARE_DESFIRE_PICC)
- {
- if (tag_is_isp_dep_ndef_formatable(handle, dev_type) == FALSE)
- {
- DEBUG_ERR_MSG(
- "DESFIRE : ISO-DEP ndef not formatable");
- return FALSE;
- }
-
- DEBUG_SERVER_MSG("DESFIRE : ISO-DEP ndef formatable");
-
- if (net_nfc_controller_connect(handle, &result) == false)
- {
- DEBUG_ERR_MSG("%s failed, & retry polling!!",
- "net_nfc_controller_connect");
-
- if (net_nfc_controller_configure_discovery(
- NET_NFC_DISCOVERY_MODE_RESUME,
- NET_NFC_ALL_ENABLE,
- &result) == false)
- {
- net_nfc_controller_exception_handler();
- }
- return FALSE;
- }
- }
-
- if (net_nfc_controller_read_ndef(handle, &temp, &result) == false)
- {
- DEBUG_ERR_MSG("%s failed",
- "net_nfc_controller_read_ndef");
- return FALSE;
- }
-
- DEBUG_SERVER_MSG("%s success",
- "net_nfc_controller_read_ndef");
-
- if (dev_type == NET_NFC_MIFARE_DESFIRE_PICC)
- {
- if (net_nfc_controller_connect(handle, &result) == false)
- {
- DEBUG_ERR_MSG("%s failed, & retry polling!!",
- "net_nfc_controller_connect");
-
- if (net_nfc_controller_configure_discovery(
- NET_NFC_DISCOVERY_MODE_RESUME,
- NET_NFC_ALL_ENABLE,
- &result) == false)
- {
- net_nfc_controller_exception_handler();
- }
-
- if (temp)
- {
- g_free(temp->buffer);
- g_free(temp);
- }
-
- return FALSE;
- }
- }
-
- *read_ndef = temp;
-
- return TRUE;
-}
-
-static void tag_watchdog_thread_func(gpointer user_data)
-{
- WatchDogData *watch_dog = (WatchDogData *)user_data;
- net_nfc_target_handle_s *handle;
- net_nfc_error_e result = NET_NFC_OK;
- bool is_present_target = false;
-
- if (watch_dog == NULL)
- {
- DEBUG_ERR_MSG("can not get WatchDogData");
- return;
- }
-
- if (watch_dog->handle == NULL)
- {
- DEBUG_ERR_MSG("can not get WatchDogData->handle");
- return;
- }
-
-
- /* IMPORTANT, TEMPORARY : switching context to another thread
- for give CPU time */
- g_usleep(10000);
-
- handle = watch_dog->handle;
- if (handle->connection_type == NET_NFC_P2P_CONNECTION_TARGET ||
- handle->connection_type == NET_NFC_TAG_CONNECTION)
- {
- is_present_target = net_nfc_controller_check_target_presence(
- handle, &result);
- }
-
- if (is_present_target == true)
- {
- if(net_nfc_server_controller_async_queue_push(
- tag_watchdog_thread_func,
- watch_dog) == FALSE)
- {
- DEBUG_ERR_MSG("can not create watch dog");
- g_free(watch_dog);
- }
- return;
- }
-
- if (result != NET_NFC_NOT_INITIALIZED &&
- result != NET_NFC_INVALID_HANDLE)
- {
- if(net_nfc_controller_disconnect(handle, &result) == false)
- {
- DEBUG_SERVER_MSG("try to disconnect result = [%d]",
- result);
- net_nfc_controller_exception_handler();
- }
- }
-
- net_nfc_server_set_state(NET_NFC_SERVER_IDLE);
-
- net_nfc_gdbus_tag_emit_tag_detached(tag_skeleton,
- GPOINTER_TO_UINT(handle),
- watch_dog->dev_type);
-
- g_free(watch_dog);
-}
-
-static void tag_get_current_tag_info_thread_func(gpointer user_data)
-{
- CurrentTagInfoData *info_data =
- (CurrentTagInfoData *)user_data;
-
- /* FIXME : net_nfc_current_target_info_s should be removed */
- net_nfc_current_target_info_s *target_info;
- net_nfc_error_e result;
- net_nfc_target_handle_s *handle = NULL;
- net_nfc_target_type_e dev_type = NET_NFC_UNKNOWN_TARGET;
- gboolean is_ndef_supported = FALSE;
- guint8 ndef_card_state = 0;
- guint32 max_data_size = 0;
- guint32 actual_data_size = 0;
- gint number_of_keys = 0;
- data_s target_info_values = { NULL, 0 };
- data_s *raw_data = NULL;
-
- g_assert(info_data != NULL);
- g_assert(info_data->tag != NULL);
- g_assert(info_data->invocation != NULL);
-
- target_info = net_nfc_server_get_target_info();
- if (target_info != NULL &&
- target_info->devType != NET_NFC_NFCIP1_TARGET &&
- target_info->devType != NET_NFC_NFCIP1_INITIATOR)
- {
- handle = target_info->handle;
- number_of_keys = target_info->number_of_keys;
-
- target_info_values.buffer = target_info->target_info_values.buffer;
- target_info_values.length = target_info->target_info_values.length;
-
- dev_type = target_info->devType ;
-
- if (net_nfc_controller_check_ndef(target_info->handle,
- &ndef_card_state,
- (int *)&max_data_size,
- (int *)&actual_data_size,
- &result) == true)
- {
- is_ndef_supported = TRUE;
- }
-
- if (is_ndef_supported)
- {
- if (net_nfc_controller_read_ndef(target_info->handle,
- &raw_data, &result) == true)
- {
- DEBUG_SERVER_MSG("%s is success",
- "net_nfc_controller_read_ndef");
- }
- }
- }
-
- net_nfc_gdbus_tag_complete_get_current_tag_info(info_data->tag,
- info_data->invocation,
- (dev_type != NET_NFC_UNKNOWN_TARGET),
- GPOINTER_TO_UINT(handle),
- dev_type,
- is_ndef_supported,
- ndef_card_state,
- max_data_size,
- actual_data_size,
- number_of_keys,
- net_nfc_util_gdbus_data_to_variant(&target_info_values),
- net_nfc_util_gdbus_data_to_variant(raw_data));
-
- if (raw_data != NULL) {
- net_nfc_util_free_data(raw_data);
- g_free(raw_data);
- }
-
- g_object_unref(info_data->invocation);
- g_object_unref(info_data->tag);
-
- g_free(info_data);
-}
-
-static void tag_slave_target_detected_thread_func(gpointer user_data)
-{
- net_nfc_current_target_info_s *target;
- net_nfc_error_e result = NET_NFC_OK;
-
- guint32 max_data_size = 0;
- guint32 actual_data_size = 0;
- guint8 ndef_card_state = 0;
- gboolean is_ndef_supported = FALSE;
-
- GVariant *target_info_values = NULL;
- GVariant *raw_data = NULL;
-
- WatchDogData *watch_dog = NULL;
- bool isHandoverMessage = false;
-
- target = net_nfc_server_get_target_info();
-
- g_assert(target != NULL); /* raise exception!!! what;s wrong?? */
-
- if (tag_skeleton == NULL)
- {
- DEBUG_ERR_MSG("tag skeleton is not initialized");
-
- return;
- }
-
- if (net_nfc_controller_connect(target->handle, &result) == false)
- {
- DEBUG_ERR_MSG("connect failed & Retry Polling!!");
-
- if (net_nfc_controller_configure_discovery(
- NET_NFC_DISCOVERY_MODE_RESUME,
- NET_NFC_ALL_ENABLE,
- &result) == false)
- {
- net_nfc_controller_exception_handler();
- }
-
- return;
- }
-
- net_nfc_server_set_state(NET_NFC_TAG_CONNECTED);
-
- DEBUG_SERVER_MSG("tag is connected");
-
- target_info_values = net_nfc_util_gdbus_buffer_to_variant(
- target->target_info_values.buffer,
- target->target_info_values.length);
-
- if (net_nfc_controller_check_ndef(target->handle,
- &ndef_card_state,
- (int *)&max_data_size,
- (int *)&actual_data_size,
- &result) == true)
- {
- is_ndef_supported = TRUE;
- }
-
- if (is_ndef_supported)
- {
- data_s *recv_data = NULL;
-
- DEBUG_SERVER_MSG("support NDEF");
-
- if (tag_read_ndef_message(target->handle,
- target->devType,
- &recv_data) == TRUE)
- {
- ndef_message_s *selector;
- ndef_record_s *record;
- ndef_record_s *recordasperpriority;
- result = _net_nfc_server_handover_create_selector_from_rawdata(
- &selector,
- recv_data);
-
- if (result == NET_NFC_OK)
- {
- result =
- _net_nfc_server_handover_get_carrier_record_by_priority_order(
- selector,
- &record);
- isHandoverMessage = true;
- if (result == NET_NFC_OK)
- {
- net_nfc_util_create_record(
- record->TNF,
- &record->type_s, &record->id_s,
- &record->payload_s,
- &recordasperpriority);
-
- _net_nfc_server_handover_process_carrier_record(recordasperpriority, NULL, NULL);
- }
- else
- {
- DEBUG_ERR_MSG("_get_carrier_record_by_priority_order"
- " failed, [%d]",result);
- }
- }
- else
- {
- net_nfc_app_util_process_ndef(recv_data);
- raw_data = net_nfc_util_gdbus_data_to_variant(recv_data);
- }
- }
- else
- {
- DEBUG_ERR_MSG("net_nfc_controller_read_ndef failed");
- raw_data = net_nfc_util_gdbus_buffer_to_variant(NULL, 0);
- }
- }
- else
- {
- /* raw-data of empty ndef msseages */
- uint8_t empty[] = { 0xd0, 0x00, 0x00 };
- data_s empty_data = { empty, sizeof(empty) };
-
- DEBUG_SERVER_MSG("not support NDEF");
-
- net_nfc_app_util_process_ndef(&empty_data);
- raw_data = net_nfc_util_gdbus_data_to_variant(&empty_data);
- }
-
- if(isHandoverMessage == false)
- {
- /* send TagDiscoverd signal */
- net_nfc_gdbus_tag_emit_tag_discovered(tag_skeleton,
- GPOINTER_TO_UINT(target->handle),
- target->devType,
- is_ndef_supported,
- ndef_card_state,
- max_data_size,
- actual_data_size,
- target->number_of_keys,
- target_info_values,
- raw_data);
- }
-
- /* turn on watch dog */
- DEBUG_SERVER_MSG("turn on watch dog");
-
- watch_dog = g_new0(WatchDogData, 1);
- if(watch_dog == NULL)
- {
- DEBUG_ERR_MSG("Memory allocation failed");
- return;
- }
-
- watch_dog->dev_type = target->devType;
- watch_dog->handle = target->handle;
-
- if (net_nfc_server_controller_async_queue_push(
- tag_watchdog_thread_func,
- watch_dog) == FALSE)
- {
- DEBUG_ERR_MSG("can not create watch dog");
- g_free(watch_dog);
- return;
- }
-}
-
-
-static gboolean tag_handle_is_tag_connected(NetNfcGDbusTag *tag,
- GDBusMethodInvocation *invocation,
- GVariant *smack_privilege,
- gpointer user_data)
-{
- /* FIXME : net_nfc_current_target_info_s should be removed */
- net_nfc_current_target_info_s *target_info;
- net_nfc_target_type_e dev_type = NET_NFC_UNKNOWN_TARGET;
- gboolean is_connected = FALSE;
-
- INFO_MSG(">>> REQUEST from [%s]",
- g_dbus_method_invocation_get_sender(invocation));
-
- /* check privilege and update client context */
- if (net_nfc_server_gdbus_check_privilege(invocation,
- smack_privilege,
- "nfc-manager::tag",
- "r") == false) {
- DEBUG_ERR_MSG("permission denied, and finished request");
-
- return FALSE;
- }
-
- target_info = net_nfc_server_get_target_info();
- if (target_info != NULL)
- {
- dev_type = target_info->devType;
- is_connected = TRUE;
- }
-
- net_nfc_gdbus_tag_complete_is_tag_connected(tag,
- invocation,
- is_connected,
- (gint32)dev_type);
-
- return TRUE;
-}
-
-static gboolean tag_handle_get_current_tag_info(NetNfcGDbusTag *tag,
- GDBusMethodInvocation *invocation,
- GVariant *smack_privilege,
- gpointer user_data)
-{
- CurrentTagInfoData *info_data;
- gboolean result;
-
- INFO_MSG(">>> REQUEST from [%s]",
- g_dbus_method_invocation_get_sender(invocation));
-
- /* check privilege and update client context */
- if (net_nfc_server_gdbus_check_privilege(invocation,
- smack_privilege,
- "nfc-manager::tag",
- "r") == false) {
- DEBUG_ERR_MSG("permission denied, and finished request");
-
- return FALSE;
- }
-
- info_data = g_new0(CurrentTagInfoData, 1);
- if (info_data == NULL)
- {
- DEBUG_ERR_MSG("Memory allocation failed");
- g_dbus_method_invocation_return_dbus_error(invocation,
- "org.tizen.NetNfcService.AllocationError",
- "Can not allocate memory");
-
- return FALSE;
- }
-
- info_data->tag = g_object_ref(tag);
- info_data->invocation = g_object_ref(invocation);
-
- result = net_nfc_server_controller_async_queue_push(
- tag_get_current_tag_info_thread_func,
- info_data);
- if (result == FALSE)
- {
- g_dbus_method_invocation_return_dbus_error(invocation,
- "org.tizen.NetNfcService.ThreadError",
- "can not push to controller thread");
-
- g_object_unref(info_data->invocation);
- g_object_unref(info_data->tag);
-
- g_free(info_data);
- }
-
- return result;
-}
-
-static gboolean tag_handle_get_current_target_handle(NetNfcGDbusTag *tag,
- GDBusMethodInvocation *invocation,
- GVariant *smack_privilege,
- gpointer user_data)
-{
- /* FIXME : net_nfc_current_target_info_s should be removed */
- net_nfc_current_target_info_s *target_info;
- net_nfc_target_handle_s *handle = NULL;
- uint32_t devType = NET_NFC_UNKNOWN_TARGET;
-
- INFO_MSG(">>> REQUEST from [%s]",
- g_dbus_method_invocation_get_sender(invocation));
-
- /* check privilege and update client context */
- if (net_nfc_server_gdbus_check_privilege(invocation,
- smack_privilege,
- "nfc-manager::tag",
- "r") == false) {
- DEBUG_ERR_MSG("permission denied, and finished request");
-
- return FALSE;
- }
-
- target_info = net_nfc_server_get_target_info();
- if (target_info != NULL)
- {
- handle = target_info->handle;
- devType = target_info->devType;
- }
-
- net_nfc_gdbus_tag_complete_get_current_target_handle(tag,
- invocation,
- (handle != NULL),
- GPOINTER_TO_UINT(handle),
- devType);
-
- return TRUE;
-}
-
-
-gboolean net_nfc_server_tag_init(GDBusConnection *connection)
-{
- GError *error = NULL;
- gboolean result;
-
- if (tag_skeleton)
- net_nfc_server_tag_deinit();
-
- tag_skeleton = net_nfc_gdbus_tag_skeleton_new();
-
- g_signal_connect(tag_skeleton,
- "handle-is-tag-connected",
- G_CALLBACK(tag_handle_is_tag_connected),
- NULL);
-
- g_signal_connect(tag_skeleton,
- "handle-get-current-tag-info",
- G_CALLBACK(tag_handle_get_current_tag_info),
- NULL);
-
- g_signal_connect(tag_skeleton,
- "handle-get-current-target-handle",
- G_CALLBACK(tag_handle_get_current_target_handle),
- NULL);
-
- result = g_dbus_interface_skeleton_export(
- G_DBUS_INTERFACE_SKELETON(tag_skeleton),
- connection,
- "/org/tizen/NetNfcService/Tag",
- &error);
- if (result == FALSE)
- {
- DEBUG_ERR_MSG("can not skeleton_export %s", error->message);
-
- g_error_free(error);
-
- net_nfc_server_tag_deinit();
- }
-
- return result;
-}
-
-void net_nfc_server_tag_deinit(void)
-{
- if (tag_skeleton)
- {
- g_object_unref(tag_skeleton);
- tag_skeleton = NULL;
- }
-}
-
-void net_nfc_server_set_target_info(void *info)
-{
- net_nfc_request_target_detected_t *target;
-
- if (current_target_info)
- g_free(current_target_info);
-
- target = (net_nfc_request_target_detected_t *)info;
-
- current_target_info = g_malloc0(
- sizeof(net_nfc_current_target_info_s) +
- target->target_info_values.length);
-
- current_target_info->handle = target->handle;
- current_target_info->devType = target->devType;
-
- if (current_target_info->devType != NET_NFC_NFCIP1_INITIATOR &&
- current_target_info->devType != NET_NFC_NFCIP1_TARGET)
- {
- current_target_info->number_of_keys = target->number_of_keys;
- current_target_info->target_info_values.length =
- target->target_info_values.length;
-
- memcpy(¤t_target_info->target_info_values,
- &target->target_info_values,
- current_target_info->target_info_values.length);
- }
-}
-
-net_nfc_current_target_info_s *net_nfc_server_get_target_info(void)
-{
- return current_target_info;
-}
-
-gboolean net_nfc_server_target_connected(net_nfc_target_handle_s *handle)
-{
- if (current_target_info == NULL)
- return FALSE;
-
- if (current_target_info->handle != handle)
- return FALSE;
-
- return TRUE;
-}
-
-void net_nfc_server_free_target_info(void)
-{
- g_free(current_target_info);
- current_target_info = NULL;
-}
-
-void net_nfc_server_tag_target_detected(void *info)
-{
- if (net_nfc_server_controller_async_queue_push(
- tag_slave_target_detected_thread_func,
- NULL) == FALSE)
- {
- DEBUG_ERR_MSG("can not push to controller thread");
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "net_nfc_typedef_internal.h"
-#include "net_nfc_debug_internal.h"
-#include "net_nfc_util_internal.h"
-#include "net_nfc_util_gdbus_internal.h"
-#include "net_nfc_controller_internal.h"
-#include "net_nfc_gdbus.h"
-#include "net_nfc_server_common.h"
-#include "net_nfc_server_context_internal.h"
-#include "net_nfc_server_test.h"
-
-typedef struct _TestData TestData;
-
-struct _TestData
-{
- NetNfcGDbusTest *test;
- GDBusMethodInvocation *invocation;
-};
-
-typedef struct _TestPrbsData TestPrbsData;
-
-struct _TestPrbsData
-{
- NetNfcGDbusTest *test;
- GDBusMethodInvocation *invocation;
- guint32 tech;
- guint32 rate;
-};
-
-typedef struct _TestSetEeData TestSetEeData;
-
-struct _TestSetEeData
-{
- NetNfcGDbusTest *test;
- GDBusMethodInvocation *invocation;
-
- guint32 mode;
- guint32 reg_id;
- data_s data;
-};
-
-static void test_handle_sim_test_thread_func(gpointer user_data);
-
-static void test_handle_prbs_test_thread_func(gpointer user_data);
-
-static void test_handle_get_firmware_version_thread_func(gpointer user_data);
-
-static void test_handle_set_ee_data_thread_func(gpointer user_data);
-
-
-static gboolean test_handle_sim_test(NetNfcGDbusTest *test,
- GDBusMethodInvocation *invocation,
- GVariant *smack_privilege,
- gpointer user_data);
-
-static gboolean test_handle_prbs_test(NetNfcGDbusTest *test,
- GDBusMethodInvocation *invocation,
- guint32 arg_tech,
- guint32 arg_rate,
- GVariant *smack_privilege,
- gpointer user_data);
-
-static gboolean test_handle_get_firmware_version(NetNfcGDbusTest *test,
- GDBusMethodInvocation *invocation,
- GVariant *smack_privilege,
- gpointer user_data);
-
-static gboolean test_handle_set_ee_data(NetNfcGDbusTest *test,
- GDBusMethodInvocation *invocation,
- guint32 mode,
- guint32 reg_id,
- GVariant *variant,
- GVariant *smack_privilege,
- gpointer user_data);
-
-
-static NetNfcGDbusTest *test_skeleton = NULL;
-
-static void test_handle_sim_test_thread_func(gpointer user_data)
-{
- TestData *data = (TestData *)user_data;
- net_nfc_error_e result = NET_NFC_OK;
-
- g_assert(data != NULL);
- g_assert(data->test != NULL);
- g_assert(data->invocation != NULL);
-
- net_nfc_controller_sim_test(&result);
-
- net_nfc_gdbus_test_complete_sim_test(data->test,
- data->invocation,
- (gint)result);
-
- g_object_unref(data->invocation);
- g_object_unref(data->test);
-
- g_free(data);
-}
-
-static void test_handle_prbs_test_thread_func(gpointer user_data)
-{
- TestPrbsData *data = (TestPrbsData *)user_data;
- net_nfc_error_e result = NET_NFC_OK;
-
- g_assert(data != NULL);
- g_assert(data->test != NULL);
- g_assert(data->invocation != NULL);
-
- net_nfc_controller_prbs_test(&result, data->tech, data->rate);
-
- net_nfc_gdbus_test_complete_prbs_test(data->test,
- data->invocation,
- (gint)result);
-
- g_object_unref(data->invocation);
- g_object_unref(data->test);
-
- g_free(data);
-}
-
-static void test_handle_get_firmware_version_thread_func(gpointer user_data)
-{
- TestData *data = (TestData *)user_data;
- data_s *tmp_data = NULL;
- net_nfc_error_e result = NET_NFC_OK;
- gchar *version = NULL;
-
- g_assert(data != NULL);
- g_assert(data->test != NULL);
- g_assert(data->invocation != NULL);
-
- net_nfc_controller_get_firmware_version(&tmp_data, &result);
-
- if (tmp_data)
- {
- version = g_new0(gchar, tmp_data->length +1);
- memcpy((void *)version, tmp_data->buffer, tmp_data->length);
-
- g_free(tmp_data->buffer);
- g_free(tmp_data);
- }
- else
- {
- version = g_strdup("");
- }
-
- net_nfc_gdbus_test_complete_get_firmware_version(data->test,
- data->invocation,
- (gint)result,
- version);
-
- g_free(version);
-
- g_object_unref(data->invocation);
- g_object_unref(data->test);
-
- g_free(data);
-}
-
-static void test_handle_set_ee_data_thread_func(gpointer user_data)
-{
- TestSetEeData *data = (TestSetEeData *)user_data;
- net_nfc_error_e result = NET_NFC_OK;
-
- g_assert(data != NULL);
- g_assert(data->test != NULL);
- g_assert(data->invocation != NULL);
-
- net_nfc_controller_eedata_register_set(&result,
- data->mode,
- data->reg_id,
- &data->data);
-
- net_nfc_gdbus_test_complete_set_ee_data(data->test,
- data->invocation,
- (gint)result);
-
- net_nfc_util_free_data(&data->data);
-
- g_object_unref(data->invocation);
- g_object_unref(data->test);
-
- g_free(data);
-}
-
-static gboolean test_handle_sim_test(NetNfcGDbusTest *test,
- GDBusMethodInvocation *invocation,
- GVariant *smack_privilege,
- gpointer user_data)
-{
- TestData *data;
- gboolean result;
-
- INFO_MSG(">>> REQUEST from [%s]",
- g_dbus_method_invocation_get_sender(invocation));
-
- /* check privilege and update client context */
- if (net_nfc_server_gdbus_check_privilege(invocation,
- smack_privilege,
- "nfc-manager",
- "rw") == false) {
- DEBUG_ERR_MSG("permission denied, and finished request");
-
- return FALSE;
- }
-
- DEBUG_SERVER_MSG("sim_test");
-
- data = g_new0(TestData, 1);
- if (data == NULL)
- {
- DEBUG_ERR_MSG("Memory allocation failed");
- g_dbus_method_invocation_return_dbus_error(invocation,
- "org.tizen.NetNfcService.AllocationError",
- "Can not allocate memory");
-
- return FALSE;
- }
-
- data->test = g_object_ref(test);
- data->invocation = g_object_ref(invocation);
-
- result = net_nfc_server_controller_async_queue_push(
- test_handle_sim_test_thread_func,
- data);
- if (result == FALSE)
- {
- g_dbus_method_invocation_return_dbus_error(invocation,
- "org.tizen.NetNfcService.ThreadError",
- "can not push to controller thread");
-
- g_object_unref(data->invocation);
- g_object_unref(data->test);
-
- g_free(data);
- }
-
- return result;
-}
-
-static gboolean test_handle_prbs_test(NetNfcGDbusTest *test,
- GDBusMethodInvocation *invocation,
- guint32 arg_tech,
- guint32 arg_rate,
- GVariant *smack_privilege,
- gpointer user_data)
-{
- TestPrbsData *data;
- gboolean result;
-
- INFO_MSG(">>> REQUEST from [%s]",
- g_dbus_method_invocation_get_sender(invocation));
-
- /* check privilege and update client context */
- if (net_nfc_server_gdbus_check_privilege(invocation,
- smack_privilege,
- "nfc-manager",
- "rw") == false) {
- DEBUG_ERR_MSG("permission denied, and finished request");
-
- return TRUE;
- }
-
- DEBUG_SERVER_MSG("prbs_test");
-
- data = g_new0(TestPrbsData, 1);
- if (data == NULL)
- {
- DEBUG_ERR_MSG("Memory allocation failed");
- g_dbus_method_invocation_return_dbus_error(invocation,
- "org.tizen.NetNfcService.AllocationError",
- "Can not allocate memory");
-
- return FALSE;
- }
-
- data->test = g_object_ref(test);
- data->invocation = g_object_ref(invocation);
- data->tech = arg_tech;
- data->rate = arg_rate;
-
- result = net_nfc_server_controller_async_queue_push(
- test_handle_prbs_test_thread_func,
- data);
- if (result == FALSE)
- {
- g_dbus_method_invocation_return_dbus_error(invocation,
- "org.tizen.NetNfcService.ThreadError",
- "can not push to controller thread");
-
- g_object_unref(data->invocation);
- g_object_unref(data->test);
-
- g_free(data);
- }
-
- return result;
-}
-
-static gboolean test_handle_get_firmware_version(NetNfcGDbusTest *test,
- GDBusMethodInvocation *invocation,
- GVariant *smack_privilege,
- gpointer user_data)
-{
- TestData *data;
- gboolean result;
-
- INFO_MSG(">>> REQUEST from [%s]",
- g_dbus_method_invocation_get_sender(invocation));
-
- /* check privilege and update client context */
- if (net_nfc_server_gdbus_check_privilege(invocation,
- smack_privilege,
- "nfc-manager",
- "rw") == false) {
- DEBUG_ERR_MSG("permission denied, and finished request");
-
- return FALSE;
- }
-
- data = g_new0(TestData, 1);
- if (data == NULL)
- {
- DEBUG_ERR_MSG("Memory allocation failed");
- g_dbus_method_invocation_return_dbus_error(invocation,
- "org.tizen.NetNfcService.AllocationError",
- "Can not allocate memory");
-
- return FALSE;
- }
-
- data->test = g_object_ref(test);
- data->invocation = g_object_ref(invocation);
-
- result = net_nfc_server_controller_async_queue_push(
- test_handle_get_firmware_version_thread_func,
- data);
- if (result == FALSE)
- {
- g_dbus_method_invocation_return_dbus_error(invocation,
- "org.tizen.NetNfcService.ThreadError",
- "can not push to controller thread");
-
- g_object_unref(data->test);
- g_object_unref(data->invocation);
-
- g_free(data);
- }
-
- return result;
-}
-
-static gboolean test_handle_set_ee_data(NetNfcGDbusTest *test,
- GDBusMethodInvocation *invocation,
- guint32 mode,
- guint32 reg_id,
- GVariant *variant,
- GVariant *smack_privilege,
- gpointer user_data)
-{
- TestSetEeData *data;
- gboolean result;
-
- INFO_MSG(">>> REQUEST from [%s]",
- g_dbus_method_invocation_get_sender(invocation));
-
- /* check privilege and update client context */
- if (net_nfc_server_gdbus_check_privilege(invocation,
- smack_privilege,
- "nfc-manager",
- "rw") == false) {
- DEBUG_ERR_MSG("permission denied, and finished request");
-
- return FALSE;
- }
-
- data = g_new0(TestSetEeData, 1);
- if (data == NULL)
- {
- DEBUG_ERR_MSG("Memory allocation failed");
- g_dbus_method_invocation_return_dbus_error(invocation,
- "org.tizen.NetNfcService.AllocationError",
- "Can not allocate memory");
-
- return FALSE;
- }
-
- data->test = g_object_ref(test);
- data->invocation = g_object_ref(invocation);
- data->mode = mode;
- data->reg_id = reg_id;
- net_nfc_util_gdbus_variant_to_data_s(variant, &data->data);
-
- result = net_nfc_server_controller_async_queue_push(
- test_handle_set_ee_data_thread_func, data);
- if (result == FALSE)
- {
- g_dbus_method_invocation_return_dbus_error(invocation,
- "org.tizen.NetNfcService.ThreadError",
- "can not push to controller thread");
-
- net_nfc_util_free_data(&data->data);
-
- g_object_unref(data->invocation);
- g_object_unref(data->test);
-
- g_free(data);
- }
-
- return result;
-}
-
-gboolean net_nfc_server_test_init(GDBusConnection *connection)
-{
- GError *error = NULL;
- gboolean result;
-
- if (test_skeleton)
- g_object_unref(test_skeleton);
-
- test_skeleton = net_nfc_gdbus_test_skeleton_new();
-
- g_signal_connect(test_skeleton,
- "handle-sim-test",
- G_CALLBACK(test_handle_sim_test),
- NULL);
-
- g_signal_connect(test_skeleton,
- "handle-prbs-test",
- G_CALLBACK(test_handle_prbs_test),
- NULL);
-
- g_signal_connect(test_skeleton,
- "handle-get-firmware-version",
- G_CALLBACK(test_handle_get_firmware_version),
- NULL);
-
- g_signal_connect(test_skeleton,
- "handle-set-ee-data",
- G_CALLBACK(test_handle_set_ee_data),
- NULL);
-
- result = g_dbus_interface_skeleton_export(
- G_DBUS_INTERFACE_SKELETON(test_skeleton),
- connection,
- "/org/tizen/NetNfcService/Test",
- &error);
- if (result == FALSE)
- {
- DEBUG_ERR_MSG("Can not skeleton_export %s", error->message);
- g_error_free(error);
- g_object_unref(test_skeleton);
-
- test_skeleton = NULL;
- }
-
- return result;
-}
-
-void net_nfc_server_test_deinit(void)
-{
- if (test_skeleton)
- {
- g_object_unref(test_skeleton);
- test_skeleton = NULL;
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "net_nfc_typedef_internal.h"
-#include "net_nfc_debug_internal.h"
-#include "net_nfc_util_internal.h"
-#include "net_nfc_util_gdbus_internal.h"
-#include "net_nfc_controller_internal.h"
-#include "net_nfc_gdbus.h"
-#include "net_nfc_server_common.h"
-#include "net_nfc_server_tag.h"
-#include "net_nfc_server_context_internal.h"
-#include "net_nfc_server_transceive.h"
-
-
-static NetNfcGDbusTransceive *transceive_skeleton = NULL;
-
-static void transceive_thread_func(gpointer user_data);
-
-static void transceive_data_thread_func(gpointer user_data);
-
-static gboolean transceive_handle(NetNfcGDbusTransceive *transceive,
- GDBusMethodInvocation *invocation,
- guint handle,
- guint dev_type,
- GVariant *arg_data,
- GVariant *smack_privilege,
- gpointer user_data);
-
-static gboolean transceive_data_handle(NetNfcGDbusTransceive *transceive,
- GDBusMethodInvocation *invocation,
- guint handle,
- guint dev_type,
- GVariant *arg_data,
- GVariant *smack_privilege,
- gpointer user_data);
-
-
-typedef struct _TransceiveSendData TransceiveSendData;
-
-struct _TransceiveSendData
-{
- NetNfcGDbusTransceive *transceive;
- GDBusMethodInvocation *invocation;
- guint transceive_handle;
- net_nfc_transceive_info_s transceive_info;
-};
-
-static void transceive_data_thread_func(gpointer user_data)
-{
- TransceiveSendData *transceive_data = (TransceiveSendData*)user_data;
- net_nfc_target_handle_s *handle =
- (net_nfc_target_handle_s *)transceive_data->transceive_handle;
- net_nfc_error_e result;
- data_s *data = NULL;
- GVariant *resp_data = NULL;
-
- /* use assert because it was checked in handle function */
- g_assert(transceive_data != NULL);
- g_assert(transceive_data->transceive != NULL);
- g_assert(transceive_data->invocation != NULL);
-
- if (net_nfc_server_target_connected(handle) == true)
- {
- DEBUG_SERVER_MSG("call transceive");
-
- if (net_nfc_controller_transceive(handle,
- &transceive_data->transceive_info,
- &data,
- &result) == true)
- {
- if (data != NULL)
- {
- DEBUG_SERVER_MSG("Transceive data received [%d]",
- data->length);
- }
- }
- }
- else
- {
- result = NET_NFC_TARGET_IS_MOVED_AWAY;
- }
-
- DEBUG_SERVER_MSG("transceive result : %d", result);
-
- resp_data = net_nfc_util_gdbus_data_to_variant(data);
-
- net_nfc_gdbus_transceive_complete_transceive_data(
- transceive_data->transceive,
- transceive_data->invocation,
- (gint)result,
- resp_data);
-
- if (data)
- {
- g_free(data->buffer);
- g_free(data);
- }
-
- net_nfc_util_free_data(&transceive_data->transceive_info.trans_data);
-
- g_object_unref(transceive_data->invocation);
- g_object_unref(transceive_data->transceive);
-
- g_free(transceive_data);
-}
-
-static gboolean transceive_data_handle(NetNfcGDbusTransceive *transceive,
- GDBusMethodInvocation *invocation,
- guint handle,
- guint dev_type,
- GVariant *arg_data,
- GVariant *smack_privilege,
- gpointer user_data)
-{
- TransceiveSendData *data;
- gboolean result;
-
- INFO_MSG(">>> REQUEST from [%s]",
- g_dbus_method_invocation_get_sender(invocation));
-
- /* check privilege and update client context */
- if (net_nfc_server_gdbus_check_privilege(invocation,
- smack_privilege,
- "nfc-manager",
- "rw") == false) {
- DEBUG_ERR_MSG("permission denied, and finished request");
-
- return FALSE;
- }
-
- data = g_new0(TransceiveSendData, 1);
- if (data == NULL)
- {
- DEBUG_ERR_MSG("Memory allocation failed");
- g_dbus_method_invocation_return_dbus_error(invocation,
- "org.tizen.NetNfcService.AllocationError",
- "Can not allocate memory");
-
- return FALSE;
- }
-
- data->transceive = g_object_ref(transceive);
- data->invocation = g_object_ref(invocation);
- data->transceive_handle = handle;
- data->transceive_info.dev_type = dev_type;
- net_nfc_util_gdbus_variant_to_data_s(arg_data,
- &data->transceive_info.trans_data);
-
- result = net_nfc_server_controller_async_queue_push(
- transceive_data_thread_func, data);
- if (result == FALSE)
- {
- g_dbus_method_invocation_return_dbus_error(invocation,
- "org.tizen.NetNfcService.Transceive.ThreadError",
- "can not push to controller thread");
-
- net_nfc_util_free_data(&data->transceive_info.trans_data);
-
- g_object_unref(data->transceive);
- g_object_unref(data->invocation);
-
- g_free(data);
- }
-
- return result;
-}
-
-static void transceive_thread_func(gpointer user_data)
-{
- TransceiveSendData *transceive_data = (TransceiveSendData *)user_data;
- net_nfc_target_handle_s *handle =
- (net_nfc_target_handle_s *)transceive_data->transceive_handle;
- net_nfc_error_e result = NET_NFC_OK;
- data_s *data = NULL;
-
- /* use assert because it was checked in handle function */
- g_assert(transceive_data != NULL);
- g_assert(transceive_data->transceive != NULL);
- g_assert(transceive_data->invocation != NULL);
-
- if (net_nfc_server_target_connected(handle) == true)
- {
- DEBUG_MSG("call transceive");
-
- if (net_nfc_controller_transceive(handle,
- &transceive_data->transceive_info,
- &data,
- &result) == true)
- {
- if (data != NULL)
- {
- DEBUG_SERVER_MSG(
- "Transceive data received [%d]",
- data->length);
-
- /* free resource because it doesn't need */
- g_free(data->buffer);
- g_free(data);
- }
- }
- }
- else
- {
- DEBUG_SERVER_MSG("target is not connected");
-
- result = NET_NFC_TARGET_IS_MOVED_AWAY;
- }
-
- DEBUG_SERVER_MSG("transceive result : %d", result);
-
- net_nfc_gdbus_transceive_complete_transceive(
- transceive_data->transceive,
- transceive_data->invocation,
- (gint)result);
-
- net_nfc_util_free_data(&transceive_data->transceive_info.trans_data);
-
- g_object_unref(transceive_data->invocation);
- g_object_unref(transceive_data->transceive);
-
- g_free(transceive_data);
-}
-
-static gboolean transceive_handle(NetNfcGDbusTransceive *transceive,
- GDBusMethodInvocation *invocation,
- guint handle,
- guint dev_type,
- GVariant *arg_data,
- GVariant *smack_privilege,
- gpointer user_data)
-{
- TransceiveSendData *data;
- gboolean result;
-
- INFO_MSG(">>> REQUEST from [%s]",
- g_dbus_method_invocation_get_sender(invocation));
-
- /* check privilege and update client context */
- if (net_nfc_server_gdbus_check_privilege(invocation,
- smack_privilege,
- "nfc-manager",
- "rw") == false) {
- DEBUG_ERR_MSG("permission denied, and finished request");
-
- return FALSE;
- }
-
- data = g_new0(TransceiveSendData, 1);
- if (data == NULL)
- {
- DEBUG_ERR_MSG("Memory allocation failed");
- g_dbus_method_invocation_return_dbus_error(invocation,
- "org.tizen.NetNfcService.AllocationError",
- "Can not allocate memory");
-
- return FALSE;
- }
-
- data->transceive = g_object_ref(transceive);
- data->invocation = g_object_ref(invocation);
- data->transceive_handle = handle;
- data->transceive_info.dev_type = dev_type;
- net_nfc_util_gdbus_variant_to_data_s(arg_data,
- &data->transceive_info.trans_data);
-
- result = net_nfc_server_controller_async_queue_push(
- transceive_thread_func, data);
- if (result == FALSE)
- {
- g_dbus_method_invocation_return_dbus_error(invocation,
- "org.tizen.NetNfcService.Transceive.ThreadError",
- "can not push to controller thread");
-
- net_nfc_util_free_data(&data->transceive_info.trans_data);
-
- g_object_unref(data->transceive);
- g_object_unref(data->invocation);
-
- g_free(data);
- }
-
- return result;
-}
-
-
-gboolean net_nfc_server_transceive_init(GDBusConnection *connection)
-{
- GError *error = NULL;
- gboolean result;
-
- if (transceive_skeleton)
- g_object_unref(transceive_skeleton);
-
- transceive_skeleton = net_nfc_gdbus_transceive_skeleton_new();
-
- g_signal_connect(transceive_skeleton,
- "handle-transceive-data",
- G_CALLBACK(transceive_data_handle),
- NULL);
-
- g_signal_connect(transceive_skeleton,
- "handle-transceive",
- G_CALLBACK(transceive_handle),
- NULL);
-
- result = g_dbus_interface_skeleton_export(
- G_DBUS_INTERFACE_SKELETON(transceive_skeleton),
- connection,
- "/org/tizen/NetNfcService/Transceive",
- &error);
- if (result == FALSE)
- {
- g_error_free(error);
- g_object_unref(transceive_skeleton);
- transceive_skeleton = NULL;
- }
-
- return result;
-}
-
-void net_nfc_server_transceive_deinit(void)
-{
- if (transceive_skeleton)
- {
- g_object_unref(transceive_skeleton);
- transceive_skeleton = NULL;
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <glib.h>
-#include <vconf.h>
-
-#include "net_nfc_typedef.h"
-
-#include "net_nfc_server_vconf.h"
-#include "net_nfc_server_common.h"
-#include "net_nfc_server_manager.h"
-
-#include "net_nfc_debug_internal.h"
-
-static gboolean powered_off_by_flightmode = FALSE;
-
-static void vconf_set_flight_mode(int boolval);
-
-static void net_nfc_server_vconf_pm_state_changed(keynode_t *key,
- void *user_data);
-
-static void net_nfc_server_vconf_flight_mode_changed(keynode_t *key,
- void *user_data);
-
-
-static void vconf_set_flight_mode(int boolval)
-{
- gint result;
-
- /* set predefined item */
- result = vconf_set_bool(VCONFKEY_NFC_PREDEFINED_ITEM_STATE, boolval);
- if (result != 0)
- {
- DEBUG_ERR_MSG("can not set to %d: %s",
- boolval,
- "VCONKEY_NFC_PREDEFINED_ITEM_STATE");
- }
-}
-
-static void net_nfc_server_vconf_pm_state_changed(keynode_t *key,
- void *user_data)
-{
- gint state = 0;
- gint pm_state = 0;
- gint result;
-
- result = vconf_get_bool(VCONFKEY_NFC_STATE, &state);
- if (result != 0)
- DEBUG_ERR_MSG("can not get %s", "VCONFKEY_NFC_STATE");
-
- if (state == false)
- {
- DEBUG_MSG("NFC off");
- return;
- }
-
- result = vconf_get_int(VCONFKEY_PM_STATE, &pm_state);
- if (result != 0)
- DEBUG_ERR_MSG("can not get %s", "VCONFKEY_PM_STATE");
-
- DEBUG_SERVER_MSG("pm_state : %d", pm_state);
-
- if (pm_state == VCONFKEY_PM_STATE_NORMAL ||
- pm_state == VCONFKEY_PM_STATE_LCDOFF)
- {
- net_nfc_server_restart_polling_loop();
- }
-}
-
-static void net_nfc_server_vconf_flight_mode_changed(keynode_t *key,
- void *user_data)
-{
- gint flight_mode = 0;
- gint nfc_state = 0;
-
- gint result = 0;
-
- result = vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, &flight_mode);
- if (result != 0)
- {
- DEBUG_ERR_MSG("Can not get %s",
- "VCONFKEY_TELEPHONY_FLIGHT_MODE");
- }
-
- DEBUG_SERVER_MSG("flight mode %d", flight_mode);
-
- result = vconf_get_bool(VCONFKEY_NFC_STATE, &nfc_state);
- if (result != 0)
- {
- DEBUG_ERR_MSG("Can not get %s",
- "VCONFKEY_NET_STATE");
- }
-
- DEBUG_SERVER_MSG("nfc_state %d", nfc_state);
- DEBUG_SERVER_MSG("powerd_off_by_flightmode %d",
- powered_off_by_flightmode);
-
- if (flight_mode) /* turn on flight mode */
- {
- /* nfc is already disabled ignore it */
- if (nfc_state == VCONFKEY_NFC_STATE_OFF)
- return;
-
- DEBUG_SERVER_MSG("Turning NFC off");
- net_nfc_server_manager_set_active(FALSE);
-
- powered_off_by_flightmode = TRUE;
-
- vconf_set_flight_mode(0);
- }
- else /* turn off flight mode */
- {
- /* nfc is already enabled, ignre it */
- if (nfc_state == VCONFKEY_NFC_STATE_ON)
- return;
-
- if (powered_off_by_flightmode == FALSE)
- return;
-
- DEBUG_SERVER_MSG("Turning NFC on");
- net_nfc_server_manager_set_active(TRUE);
-
- powered_off_by_flightmode = FALSE;
-
- vconf_set_flight_mode(1);
- }
-}
-
-void net_nfc_server_vconf_init(void)
-{
- vconf_notify_key_changed(VCONFKEY_PM_STATE,
- net_nfc_server_vconf_pm_state_changed,
- NULL);
-
- vconf_notify_key_changed(VCONFKEY_TELEPHONY_FLIGHT_MODE,
- net_nfc_server_vconf_flight_mode_changed,
- NULL);
-}
-
-void net_nfc_server_vconf_deinit(void)
-{
- vconf_ignore_key_changed(VCONFKEY_PM_STATE,
- net_nfc_server_vconf_pm_state_changed);
-
- vconf_ignore_key_changed(VCONFKEY_TELEPHONY_FLIGHT_MODE,
- net_nfc_server_vconf_flight_mode_changed);
-}
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<manifest xmlns="http://tizen.org/ns/packages"
- package="nfc-manager"
- version="0.1.0"
- install-location="internal-only"
- type="rpm">
- <label>NFC Manager</label>
- <author email="email" href="www.samsung.com">name</author>
- <description>NFC manager</description>
- <ui-application appid="nfc-manager"
- exec="/usr/bin/nfc-manager-daemon"
- nodisplay="true"
- multiple="false"
- type="capp"
- taskmanage="false"
- mainapp="true">
- <label>NFC Manager</label>
- </ui-application>
-</manifest>
+++ /dev/null
-[D-BUS Service]
-Name=org.tizen.NetNfcService
-Exec=/usr/bin/nfc-manager-daemon
+++ /dev/null
-LOCAL_PATH=.
-
-#phLibNfc
-
-export PKG_CONFIG_PATH=/usr/lib/pkgconfig/
-
-#sources
-
-SRCS = $(LOCAL_PATH)/bt_paring.c
-
-#includes
-
-USER_HEADER =`pkg-config --cflags nfc bluetooth-api`
-
-LOCAL_CFLAGS = $(USER_HEADER)
-
-CC = arm-linux-gnueabi-gcc
-
-TARGET = bt_paring
-
-
-CFLAGS = $(LOCAL_CFLAGS) -g
-LDFLAGS = -lpthread `pkg-config --libs nfc bluetooth-api`
-
-
-SRC = $(SRCS)
-OBJS = $(SRC:.c=.o)
-RM = rm
-
-
-.SUFFIXES: .c .o
-
-.c.o:
- $(CC) -c $(CFLAGS) -o $*.o $<
-
-all: $(TARGET)
-
-$(TARGET): $(OBJS)
- $(CC) -o $@ $(OBJS) $(LDFLAGS) -g
-
-run: all
- $(TARGET)
-
-clean:
- $(RM) -f $(OBJS) $(TARGET)
-
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
-
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#include <bluetooth-api.h>
-#include <glib.h>
-
-#include <net_nfc.h>
-
-#include <pthread.h>
-
-void bt_event_callback(int event, bluetooth_event_param_t* param, void *user_data);
-void bt_test_bond_device(bluetooth_device_address_t* bt_address);
-GMainLoop* main_loop = NULL;
-
-void initialize()
-{
- if(!g_thread_supported())
- {
- g_thread_init(NULL);
- }
-
- dbus_g_thread_init();
- g_type_init();
-}
-
-
-int main()
-{
- initialize();
-
- //bluetooth_enable_adapter();
-
- //main_loop = g_main_loop_new(NULL, FALSE);
- //g_main_loop_run(main_loop);
-
-#if 1
-
- ndef_message_h ndef_message = NULL;
- net_nfc_conn_handover_info_h conn_handover_info = NULL;
-
-
- if(net_nfc_retrieve_current_ndef_message(&ndef_message) == NET_NFC_OK)
- {
- printf("retrieve ndef message from nfc storage \n");
-
- int count = 0;
-
- net_nfc_get_ndef_message_record_count(ndef_message, &count);
-
- int i = 0;
- while(i < count){
-
- ndef_record_h record = NULL;
- net_nfc_get_record_by_index(ndef_message, i++, &record);
-
- if(record != NULL){
-
- net_nfc_record_tnf_e TNF = NET_NFC_RECORD_EMPTY;
- data_h record_type = NULL;
-
- if((net_nfc_get_record_tnf(record, &TNF) == NET_NFC_OK) && (net_nfc_get_record_type(record, &record_type) == NET_NFC_OK ) ){
-
- uint8_t* buffer = net_nfc_get_data_buffer(record_type);
- int buffer_length = net_nfc_get_data_length(record_type);
-
- // record is WTK and Hs
- if((TNF == NET_NFC_RECORD_WELL_KNOWN_TYPE) && (buffer != NULL) && (buffer_length > 1) && (buffer[0] == 'H') && (buffer[1] == 's')){
- printf("record is found \n");
- net_nfc_parse_connection_handover_ndef_message(ndef_message, &conn_handover_info);
-
- if(conn_handover_info != NULL){
- uint8_t carrier_count = 0;
- net_nfc_get_connection_handover_alternative_carrier_count(conn_handover_info, &carrier_count);
-
- int j = 0;
- while(j < carrier_count){
-
- net_nfc_conn_handover_carrier_info_h carrier_info = NULL;
- net_nfc_get_connection_handover_carrier_handle_by_index(conn_handover_info, j++, &carrier_info);
-
- if(carrier_info != NULL){
- data_h configuration = NULL;
- net_nfc_get_carrier_configuration(carrier_info, &configuration);
-
- if(configuration != NULL)
- {
- uint8_t* buffer = net_nfc_get_data_buffer(configuration);
- if(buffer != NULL)
- {
- printf("bt addr [%X][%X][%X][%X][%X][%X] \n", buffer[2], buffer[3], buffer[4], buffer[5], buffer[6], buffer[7]);
- bluetooth_device_address_t bt_address = {{buffer[2], buffer[3], buffer[4], buffer[5], buffer[6], buffer[7]}};
- bt_test_bond_device(&bt_address);
- }
- else
- printf("buffer is NULL");
- }
- }
-
- }
- }
- }
- }
- }
- }
-
- }
-
-#endif
- return 0;
-}
-
-void bt_test_bond_device(bluetooth_device_address_t* bt_address)
-{
- int ret_val;
-
- ret_val = bluetooth_register_callback(bt_event_callback, NULL);
-
- if (ret_val >= BLUETOOTH_ERROR_NONE)
- {
- printf("bluetooth_register_callback returned Success");
- }
- else
- {
- printf("bluetooth_register_callback returned failiure [0x%04x]", ret_val);
- return ;
- }
-
- ret_val = bluetooth_check_adapter();
-
- if (ret_val < BLUETOOTH_ERROR_NONE)
- {
- printf("bluetooth_check_adapter returned failiure [0x%04x]", ret_val);
- }
- else
- {
- printf("BT state [0x%04x]", ret_val);
- }
-
- int error = 0;
-
- if((error = bluetooth_bond_device(bt_address)) < 0)
- {
- printf("Api failed: %d", error);
- }
- else
- {
- main_loop = g_main_loop_new(NULL, FALSE);
- g_main_loop_run(main_loop);
- }
-
-}
-
-void bt_event_callback(int event, bluetooth_event_param_t* param, void *user_data)
-{
- switch(event)
- {
- case BLUETOOTH_EVENT_ENABLED:
- printf("BLUETOOTH_EVENT_ENABLED:\n");
- break;
- case BLUETOOTH_EVENT_DISABLED:
- printf("BLUETOOTH_EVENT_DISABLED:\n");
- break;
- case BLUETOOTH_EVENT_LOCAL_NAME_CHANGED:
- printf("BLUETOOTH_EVENT_LOCAL_NAME_CHANGED:\n");
- break;
- case BLUETOOTH_EVENT_DISCOVERY_STARTED:
- printf("BLUETOOTH_EVENT_DISCOVERY_STARTED:\n");
- break;
- case BLUETOOTH_EVENT_REMOTE_DEVICE_FOUND:
- printf("BLUETOOTH_EVENT_REMOTE_DEVICE_FOUND:\n");
- break;
- case BLUETOOTH_EVENT_REMOTE_DEVICE_NAME_UPDATED:
- printf("BLUETOOTH_EVENT_REMOTE_DEVICE_NAME_UPDATED:\n");
- break;
- case BLUETOOTH_EVENT_DISCOVERY_FINISHED:
- printf("BLUETOOTH_EVENT_DISCOVERY_FINISHED:\n");
- break;
- case BLUETOOTH_EVENT_BONDING_FINISHED:
- printf("BLUETOOTH_EVENT_BONDING_FINISHED:\n");
-
- if (param->result >= BLUETOOTH_ERROR_NONE)
- {
- bluetooth_device_info_t *device_info = NULL;
- device_info = (bluetooth_device_info_t *)param->param_data;
- printf("dev [%s] [%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X] mjr[%#x] min[%#x] srv[%#x] \n", device_info->device_name.name, \
- device_info->device_address.addr[0], device_info->device_address.addr[1], device_info->device_address.addr[2], \
- device_info->device_address.addr[3], device_info->device_address.addr[4], device_info->device_address.addr[5], \
- device_info->device_class.major_class, device_info->device_class.minor_class, device_info->device_class.service_class);
- }
-
- g_main_loop_quit (main_loop);
-
- break;
- default:
- printf("BLUETOOTH_EVENT = [%d]:\n", event);
- break;
- }
-}
+++ /dev/null
-CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
-PROJECT(ndef-tool C)
-
-SET(NDEF_TOOL "ndef-tool")
-
-include_directories(${CMAKE_SOURCE_DIR}/src/commonlib)
-include_directories(${CMAKE_SOURCE_DIR}/src/commonlib/include)
-include_directories(${CMAKE_SOURCE_DIR}/src/clientlib/include)
-include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
-
-AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/ TOOL_SRC)
-
-IF("${CMAKE_BUILD_TYPE}" STREQUAL "")
- SET(CMAKE_BUILD_TYPE "Release")
-ENDIF("${CMAKE_BUILD_TYPE}" STREQUAL "")
-
-INCLUDE(FindPkgConfig)
-pkg_check_modules(tool_pkgs REQUIRED glib-2.0 gobject-2.0)
-
-FOREACH(flag ${tool_pkgs_CFLAGS})
- SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
-ENDFOREACH(flag)
-
-# this for NFC flag
-
-SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -pipe -fomit-frame-pointer -Wall -Wno-trigraphs -Werror-implicit-function-declaration -fno-strict-aliasing -Wl,-zdefs -fvisibility=hidden")
-
-SET(ARM_CFLAGS "${ARM_CLAGS} -mapcs -mno-sched-prolog -mabi=aapcs-linux -Uarm -fno-common -fpic")
-
-SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
-SET(CMAKE_C_FLAGS_DEBUG "-O0 -g")
-
-FIND_PROGRAM(UNAME NAMES uname)
-EXEC_PROGRAM("${UNAME}" ARGS "-m" OUTPUT_VARIABLE "ARCH")
-IF("${ARCH}" MATCHES "^arm.*")
- ADD_DEFINITIONS("-DTARGET")
- MESSAGE("add -DTARGET")
- SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${ARM_CFLAGS}")
-ENDIF()
-
-ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"")
-
-SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie")
-
-ADD_EXECUTABLE(${NDEF_TOOL} ${TOOL_SRC})
-
-TARGET_LINK_LIBRARIES(${NDEF_TOOL} ${tool_pkgs_LDFLAGS} pthread dl rt nfc-common-lib nfc)
-LINK_DIRECTORIES(${CMAKE_BUILD_DIR}/src/commonlib ${CMAKE_BUILD_DIR}/src/clientlib)
-
-INSTALL(TARGETS ${NDEF_TOOL} DESTINATION bin)
-
-
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
-
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-#include <stddef.h>
-#include <stdint.h>
-#include <stdbool.h>
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-
-#include "net_nfc.h"
-#include "net_nfc_sign_record.h"
-#include "ndef-tool.h"
-
-typedef struct _net_nfc_sub_field_s
-{
- uint16_t length;
- uint8_t value[0];
-}
-__attribute__((packed)) net_nfc_sub_field_s;
-
-typedef struct _net_nfc_signature_record_s
-{
- uint8_t version;
- uint8_t sign_type : 7;
- uint8_t uri_present : 1;
- net_nfc_sub_field_s signature;
-}
-__attribute__((packed)) net_nfc_signature_record_s;
-
-typedef struct _net_nfc_certificate_chain_s
-{
- uint8_t num_of_certs : 4;
- uint8_t cert_format : 3;
- uint8_t uri_present : 1;
- uint8_t cert_store[0];
-}
-__attribute__((packed)) net_nfc_certificate_chain_s;
-
-void _display_ndef_message(ndef_message_h msg);
-
-static void _display_buffer(char *title, uint8_t *buffer, uint32_t length)
-{
- int32_t i;
-
- if (length > 0)
- {
- fprintf(stdout, " %s[%d] = {", title, length);
-
- for (i = 0; i < length; i++)
- {
- if ((i % 16) == 0)
- fprintf(stdout, "\n");
-
- if ((i % 8) == 0)
- fprintf(stdout, " ");
-
- fprintf(stdout, "%02X ", buffer[i]);
- }
-
- fprintf(stdout, "\n };\n");
- }
- else
- {
- fprintf(stdout, " %s[%d] = Empty", title, length);
- }
-}
-
-static void _display_id(ndef_record_h record)
-{
- data_h data = NULL;
-
- net_nfc_get_record_id(record, &data);
- if (net_nfc_get_data_length(data) > 0)
- {
- char temp_buffer[1024] = { 0, };
-
- memcpy(temp_buffer, (void *)net_nfc_get_data_buffer(data), net_nfc_get_data_length(data));
- fprintf(stdout, " ID string : %s\n", temp_buffer);
- }
-}
-
-static void _display_signature(ndef_record_h record)
-{
- data_h data = NULL;
-
- _display_id(record);
-
- net_nfc_get_record_payload(record, &data);
- if (net_nfc_get_data_length(data) > 0)
- {
- int32_t i;
- char temp_buffer[1024];
- net_nfc_signature_record_s *sign = (net_nfc_signature_record_s *)net_nfc_get_data_buffer(data);
-
- fprintf(stdout, " Version : %d\n", sign->version);
- fprintf(stdout, " Signature URI present : %s\n", sign->uri_present ? "present" : "not present");
-
- switch (sign->sign_type)
- {
- case NET_NFC_SIGN_TYPE_NO_SIGN :
- fprintf(stdout, " Signing method : Not signed (%d)\n", sign->sign_type);
- break;
-
- case NET_NFC_SIGN_TYPE_PKCS_1 :
- fprintf(stdout, " Signing method : RSASSA-PSS with SHA1 (%d)\n", sign->sign_type);
- break;
-
- case NET_NFC_SIGN_TYPE_PKCS_1_V_1_5 :
- fprintf(stdout, " Signing method : PKCS #1 v1.5 with SHA1 (%d)\n", sign->sign_type);
- break;
-
- case NET_NFC_SIGN_TYPE_DSA :
- fprintf(stdout, " Signing method : DSA (%d)\n", sign->sign_type);
- break;
-
- case NET_NFC_SIGN_TYPE_ECDSA :
- fprintf(stdout, " Signing method : ECDSA (%d)\n", sign->sign_type);
- break;
-
- default :
- fprintf(stdout, " Signing method : Unknown (%d)\n", sign->sign_type);
- break;
- }
-
- if (sign->uri_present)
- {
- memset(temp_buffer, 0, sizeof(temp_buffer));
- memcpy(temp_buffer, sign->signature.value, sign->signature.length);
- fprintf(stdout, " URI : %s\n", temp_buffer);
- }
- else
- {
- _display_buffer("Signature", sign->signature.value, sign->signature.length);
- }
-
- net_nfc_certificate_chain_s *chain = (net_nfc_certificate_chain_s *)(sign->signature.value + sign->signature.length);
- fprintf(stdout, " Cert. URI : %s\n", chain->uri_present ? "present" : "not present");
-
- switch (chain->cert_format)
- {
- case NET_NFC_CERT_FORMAT_X_509 :
- fprintf(stdout, " Cert. format : X.509 (%d)\n", chain->cert_format);
- break;
-
- case NET_NFC_CERT_FORMAT_X9_86 :
- fprintf(stdout, " Cert. format : X9.86 (%d)\n", chain->cert_format);
- break;
-
- default :
- fprintf(stdout, " Cert. format : Unknown (%d)\n", chain->cert_format);
- break;
- }
-
- fprintf(stdout, " Cert. count : %d\n", chain->num_of_certs);
-
- net_nfc_sub_field_s *field = NULL;
-
- for (i = 0, field = (net_nfc_sub_field_s *)chain->cert_store; i < chain->num_of_certs; i++, field = (net_nfc_sub_field_s *)(field->value + field->length))
- {
- memset(temp_buffer, 0, sizeof(temp_buffer));
- snprintf(temp_buffer, sizeof(temp_buffer), "Certificate %d", i);
- _display_buffer(temp_buffer, field->value, field->length);
- }
-
- if (chain->uri_present)
- {
- memset(temp_buffer, 0, sizeof(temp_buffer));
- memcpy(temp_buffer, field->value, field->length);
- fprintf(stdout, " URI : %s\n", temp_buffer);
- }
- }
-}
-
-static void _display_smart_poster(ndef_record_h record)
-{
- data_h data = NULL;
-
- _display_id(record);
-
- net_nfc_get_record_payload(record, &data);
- if (net_nfc_get_data_length(data) > 0)
- {
- char temp_buffer[1024] = { 0, };
-
- memcpy(temp_buffer, (void *)net_nfc_get_data_buffer(data), net_nfc_get_data_length(data));
- fprintf(stdout, " Type string : %s (Signature)\n", temp_buffer);
- }
-}
-
-static void _display_text(ndef_record_h record)
-{
- data_h data = NULL;
- net_nfc_encode_type_e encoding = 0;
-
- _display_id(record);
-
- net_nfc_get_encoding_type_from_text_record(record, &encoding);
- switch (encoding)
- {
- case NET_NFC_ENCODE_UTF_8 :
- fprintf(stdout, " Encoding : UTF-8\n");
- break;
-
- case NET_NFC_ENCODE_UTF_16 :
- fprintf(stdout, " Encoding : UTF-16\n");
- break;
- }
-
- net_nfc_get_record_payload(record, &data);
- if (net_nfc_get_data_length(data) > 0)
- {
- uint8_t *buffer = net_nfc_get_data_buffer(data);
- uint32_t length = net_nfc_get_data_length(data);
- char temp_buffer[1024] = { 0, };
- int code_length = buffer[0] & 0x3F;
-
- memcpy(temp_buffer, buffer + 1, code_length);
- fprintf(stdout, " Language code[%d] : %s\n", code_length, temp_buffer);
-
- memset(temp_buffer, 0, sizeof(temp_buffer));
-
- memcpy(temp_buffer, buffer + code_length + 1, length - code_length - 1);
- fprintf(stdout, " Text[%d] : %s\n", length - code_length - 1, temp_buffer);
- }
-}
-
-static void _display_uri(ndef_record_h record)
-{
- data_h data = NULL;
-
- _display_id(record);
-
- net_nfc_get_record_payload(record, &data);
- if (net_nfc_get_data_length(data) > 0)
- {
- uint8_t *buffer = net_nfc_get_data_buffer(data);
- uint32_t length = net_nfc_get_data_length(data);
- char temp_buffer[1024] = { 0, };
- char *uri = NULL;
-
- fprintf(stdout, " URI scheme : 0x%02X\n", buffer[0]);
-
- memcpy(temp_buffer, buffer + 1, length - 1);
- fprintf(stdout, " Raw URI payload[%d] : %s\n", length - 1, temp_buffer);
-
- net_nfc_create_uri_string_from_uri_record(record, &uri);
- if (uri != NULL)
- {
- fprintf(stdout, " Resolved URI[%d] : %s\n", strlen(uri), uri);
- free(uri);
- }
- }
-}
-
-static void _display_hs(ndef_record_h record)
-{
- data_h data = NULL;
-
- _display_id(record);
-
- net_nfc_get_record_payload(record, &data);
- if (net_nfc_get_data_length(data) > 0)
- {
- uint8_t *buffer = net_nfc_get_data_buffer(data);
- uint32_t length = net_nfc_get_data_length(data);
-
- fprintf(stdout, " Version : %d.%d\n", ((*buffer) >> 4) & 0x0F,
- (*buffer) & 0x0F);
- fprintf(stdout, " -- Containing NDEF message -- \n");
-
- ndef_message_h msg;
- data_h temp;
-
- net_nfc_create_data(&temp, buffer + 1, length - 1);
- net_nfc_create_ndef_message_from_rawdata(&msg, temp);
-
- _display_ndef_message(msg);
-
- net_nfc_free_ndef_message(msg);
- net_nfc_free_data(temp);
- }
-}
-
-static void _display_hr(ndef_record_h record)
-{
- data_h data = NULL;
-
- _display_id(record);
-
- net_nfc_get_record_payload(record, &data);
- if (net_nfc_get_data_length(data) > 0)
- {
- uint8_t *buffer = net_nfc_get_data_buffer(data);
- uint32_t length = net_nfc_get_data_length(data);
-
- fprintf(stdout, " Version : %d.%d\n", ((*buffer) >> 4) & 0x0F,
- (*buffer) & 0x0F);
- fprintf(stdout, " -- Containing NDEF message -- \n");
-
- ndef_message_h msg;
- data_h temp;
-
- net_nfc_create_data(&temp, buffer + 1, length - 1);
- net_nfc_create_ndef_message_from_rawdata(&msg, temp);
-
- _display_ndef_message(msg);
-
- net_nfc_free_ndef_message(msg);
- net_nfc_free_data(temp);
- }
-}
-
-static void _display_ac(ndef_record_h record)
-{
- data_h data = NULL;
-
- _display_id(record);
-
- net_nfc_get_record_payload(record, &data);
- if (net_nfc_get_data_length(data) > 0)
- {
- uint8_t *buffer = net_nfc_get_data_buffer(data);
- int i, len;
- const char *flag = "unknown";
-
- switch (*buffer)
- {
- case 0 :
- flag = "inactive";
- break;
-
- case 1 :
- flag = "active";
- break;
-
- case 2 :
- flag = "activating";
- break;
-
- default :
- break;
- }
-
- fprintf(stdout, " Carrier Flags : 0x%x (%s)\n", *buffer++, flag);
- len = *buffer++;
- fprintf(stdout, " Carrier Data Ref. len : %d byte(s)\n", len);
-
- for (i = 0; i < len; i++)
- {
- fprintf(stdout, " Carrier Data Ref. [%d] : %c\n", i, *buffer++);
- }
-
- len = *buffer++;
- fprintf(stdout, " Aux. Data Ref. len : %d byte(s)\n", len);
-
- for (i = 0; i < len; i++)
- {
- fprintf(stdout, " Aux. Data Ref. [%d] : %c\n", i, *buffer++);
- }
- }
-}
-
-static void _display_hc(ndef_record_h record)
-{
- data_h data = NULL;
-
- _display_id(record);
-
- net_nfc_get_record_payload(record, &data);
- if (net_nfc_get_data_length(data) > 0)
- {
- uint8_t *buffer = net_nfc_get_data_buffer(data);
- int i, len;
- const char *flag = "unknown";
- uint8_t ctf = (*buffer) & 0x07;
-
- switch (ctf)
- {
- case 1 :
- flag = "Well-known type";
- break;
-
- case 2 :
- flag = "MIME type";
- break;
-
- case 3 :
- flag = "Absolute URI";
- break;
-
- case 4 :
- flag = "External";
- break;
-
- default :
- break;
- }
-
- fprintf(stdout, " Carrier type format : 0x%02x (%s)\n", ctf, flag);
- buffer++;
-
- len = *buffer++;
- fprintf(stdout, " Carrier type length : %d byte(s)\n", len);
-
- for (i = 0; i < len; i++)
- {
- fprintf(stdout, " Carrier type [%d] : 0x%02x\n", i, *buffer++);
- }
-
- len = net_nfc_get_data_length(data) - len - 2;
-
- for (i = 0; i < len; i++)
- {
- fprintf(stdout, " Carrier data [%d] : 0x%02x\n", i, *buffer++);
- }
- }
-}
-
-static void _display_cr(ndef_record_h record)
-{
- data_h data = NULL;
-
- _display_id(record);
-
- net_nfc_get_record_payload(record, &data);
- if (net_nfc_get_data_length(data) > 0)
- {
- uint8_t *buffer = net_nfc_get_data_buffer(data);
-
- fprintf(stdout, " Random number : %02X %02X\n", buffer[0], buffer[1]);
- }
-}
-
-static void _display_err(ndef_record_h record)
-{
- data_h data = NULL;
-
- _display_id(record);
-
- net_nfc_get_record_payload(record, &data);
- if (net_nfc_get_data_length(data) > 0)
- {
- uint8_t *buffer = net_nfc_get_data_buffer(data);
- const char *reason = "unknown";
-
- switch (buffer[0])
- {
- case 1 :
- reason = "temporary memory constraint";
- break;
-
- case 2 :
- reason = "permanent memory constraint";
- break;
-
- case 3 :
- reason = "carrier-specific constraint";
- break;
-
- default :
- break;
- }
-
- fprintf(stdout, " Error reason : %s\n", reason);
- fprintf(stdout, " Error data : %d ms\n", buffer[1]);
- }
-}
-
-static void _display_well_known(ndef_record_h record)
-{
- data_h data = NULL;
-
- net_nfc_get_record_type(record, &data);
- if (net_nfc_get_data_length(data) > 0)
- {
- uint8_t *buffer = net_nfc_get_data_buffer(data);
- uint32_t length = net_nfc_get_data_length(data);
- char temp_buffer[1024] = { 0, };
-
- memcpy(temp_buffer, buffer, length);
-
- if (strncmp(temp_buffer, "Sig", 3) == 0)
- {
- fprintf(stdout, " Type string[%d] : %s (Signature)\n", length, temp_buffer);
- _display_signature(record);
- }
- else if (strncmp(temp_buffer, "Sp", 2) == 0)
- {
- fprintf(stdout, " Type string[%d] : %s (Smart poster)\n", length, temp_buffer);
- _display_smart_poster(record);
- }
- else if (strncmp(temp_buffer, "Gc", 2) == 0)
- {
- fprintf(stdout, " Type string[%d] : %s (Generic control)\n", length, temp_buffer);
- }
- else if (strncmp(temp_buffer, "U", 1) == 0)
- {
- fprintf(stdout, " Type string[%d] : %s (URI)\n", length, temp_buffer);
- _display_uri(record);
- }
- else if (strncmp(temp_buffer, "T", 1) == 0)
- {
- fprintf(stdout, " Type string[%d] : %s (Text)\n", length, temp_buffer);
- _display_text(record);
- }
- else if (strncmp(temp_buffer, "Hc", 2) == 0)
- {
- fprintf(stdout, " Type string[%d] : %s (Handover carrier)\n", length, temp_buffer);
- _display_hc(record);
- }
- else if (strncmp(temp_buffer, "Hr", 2) == 0)
- {
- fprintf(stdout, " Type string[%d] : %s (Handover request)\n", length, temp_buffer);
- _display_hr(record);
- }
- else if (strncmp(temp_buffer, "Hs", 2) == 0)
- {
- fprintf(stdout, " Type string[%d] : %s (Handover select)\n", length, temp_buffer);
- _display_hs(record);
- }
- else if (strncmp(temp_buffer, "ac", 2) == 0)
- {
- fprintf(stdout, " Type string[%d] : %s (alternative carrier)\n", length, temp_buffer);
- _display_ac(record);
- }
- else if (strncmp(temp_buffer, "cr", 2) == 0)
- {
- fprintf(stdout, " Type string[%d] : %s (Collision Resolution)\n", length, temp_buffer);
- _display_cr(record);
- }
- else if (strncmp(temp_buffer, "err", 3) == 0)
- {
- fprintf(stdout, " Type string[%d] : %s (Error record)\n", length, temp_buffer);
- _display_err(record);
- }
- else
- {
- fprintf(stdout, " Type string[%d] : %s (Unknown)\n", length, temp_buffer);
- }
- }
-}
-
-static void _display_general_record(ndef_record_h record)
-{
- data_h data = NULL;
-
- net_nfc_get_record_type(record, &data);
- if (net_nfc_get_data_length(data) > 0)
- {
- uint8_t *buffer = net_nfc_get_data_buffer(data);
- uint32_t length = net_nfc_get_data_length(data);
- char temp_buffer[1024] = { 0, };
-
- memcpy(temp_buffer, buffer, length);
-
- fprintf(stdout, " Type string[%d] : %s\n", length, temp_buffer);
- }
-
- _display_id(record);
-
- net_nfc_get_record_payload(record, &data);
- if (net_nfc_get_data_length(data) > 0)
- {
- uint32_t length = net_nfc_get_data_length(data);
- uint8_t temp_buffer[512] = { 0, };
-
- if (length > sizeof(temp_buffer))
- {
- memcpy(temp_buffer, net_nfc_get_data_buffer(data), sizeof(temp_buffer));
-
- fprintf(stdout, " Real payload length : %d\n", length);
- _display_buffer("Abb. payload", temp_buffer, sizeof(temp_buffer));
- }
- else
- {
- _display_buffer("Payload", net_nfc_get_data_buffer(data), length);
- }
- }
-}
-
-static void _display_absolute_uri(ndef_record_h record)
-{
- data_h data = NULL;
-
- _display_id(record);
-
- net_nfc_get_record_type(record, &data);
- if (net_nfc_get_data_length(data) > 0)
- {
- uint8_t *buffer = net_nfc_get_data_buffer(data);
- uint32_t length = net_nfc_get_data_length(data);
- char temp_buffer[2048] = { 0, };
-
- memcpy(temp_buffer, buffer, length);
-
- fprintf(stdout, " URI[%d] : %s\n", length, temp_buffer);
- }
-#if 0
- nfc_ndef_record_get_payload(record, &buffer, &length);
- if (length > 0)
- {
- char temp_buffer[512] = { 0, };
-
- if (length > sizeof(temp_buffer))
- {
- memcpy(temp_buffer, buffer, sizeof(temp_buffer));
-
- fprintf(stdout, " Real payload length : %d\n", length);
- _display_buffer("Abb. payload", temp_buffer, sizeof(temp_buffer));
- }
- else
- {
- _display_buffer("Payload", temp_buffer, length);
- }
- }
-#endif
-}
-
-static void _display_tnf(ndef_record_h record)
-{
- net_nfc_record_tnf_e tnf = NET_NFC_RECORD_UNKNOWN;
-
- net_nfc_get_record_tnf(record, &tnf);
-
- switch (tnf)
- {
- case NET_NFC_RECORD_EMPTY :
- fprintf(stdout, " TNF : Empty (%d)\n", tnf);
- break;
-
- case NET_NFC_RECORD_WELL_KNOWN_TYPE :
- fprintf(stdout, " TNF : Well-known (%d)\n", tnf);
- _display_well_known(record);
- break;
-
- case NET_NFC_RECORD_MIME_TYPE :
- fprintf(stdout, " TNF : MIME (%d)\n", tnf);
- _display_general_record(record);
- break;
-
- case NET_NFC_RECORD_URI :
- fprintf(stdout, " TNF : Absolute URI (%d)\n", tnf);
- _display_absolute_uri(record);
- break;
-
- case NET_NFC_RECORD_EXTERNAL_RTD :
- fprintf(stdout, " TNF : External (%d)\n", tnf);
- _display_general_record(record);
- break;
-
- case NET_NFC_RECORD_UNKNOWN :
- fprintf(stdout, " TNF : Unknown (%d)\n", tnf);
- _display_general_record(record);
- break;
-
- case NET_NFC_RECORD_UNCHAGNED :
- fprintf(stdout, " TNF : Unchanged (%d)\n", tnf);
- _display_general_record(record);
- break;
-
- default :
- fprintf(stdout, " Invalid TNF\n");
- break;
- }
-}
-
-static void _display_record_length(ndef_record_h record)
-{
- int length = 2; /* header : 1 byte, type length : 1 byte */
-
- net_nfc_record_tnf_e tnf = NET_NFC_RECORD_UNKNOWN;
-
- net_nfc_get_record_tnf(record, &tnf);
- if (tnf != NET_NFC_RECORD_EMPTY &&
- tnf != NET_NFC_RECORD_UNKNOWN &&
- tnf != NET_NFC_RECORD_UNCHAGNED)
- {
- data_h data;
-
- net_nfc_get_record_type(record, &data);
- length += net_nfc_get_data_length(data);
- }
-
- uint8_t header;
-
- net_nfc_get_record_flags(record, &header);
- /* to check if payloadlength is 8bit or 32bit*/
- if (net_nfc_get_record_sr(header) == 1)
- {
- /* ++ is for the Payload Length Byte */
- length++;/* for short record*/
- }
- else
- {
- /* + NET_NFC_NDEF_NORMAL_RECORD_BYTE is for the Payload Length Byte */
- length += 4;/* for normal record*/
- }
-
- /* for non empty record */
- if (tnf != NET_NFC_RECORD_EMPTY)
- {
- data_h data;
-
- net_nfc_get_record_payload(record, &data);
- length += net_nfc_get_data_length(data);
- }
-
- /* ID and IDlength are present only if IL flag is set*/
- if (net_nfc_get_record_il(header) == 1)
- {
- data_h data;
-
- /* ++ is for the ID Length Byte */
- length++;
-
- net_nfc_get_record_id(record, &data);
- length += net_nfc_get_data_length(data);
- }
-
- fprintf(stdout, " Length : %d\n", length);
-}
-
-static void _display_record(ndef_record_h record, int index)
-{
- uint8_t header;
-
- fprintf(stdout, "------------------ NDEF record %02d ------------------\n", index);
-
- _display_record_length(record);
-
- net_nfc_get_record_flags(record, &header);
-
- fprintf(stdout, " MB[%d], ME[%d], CF[%d], SR[%d], IL[%d]\n", net_nfc_get_record_mb(header), net_nfc_get_record_me(header),
- net_nfc_get_record_cf(header), net_nfc_get_record_sr(header), net_nfc_get_record_il(header));
-
- _display_tnf(record);
-
- fprintf(stdout, "----------------------------------------------------\n");
-}
-
-void _display_ndef_message(ndef_message_h msg)
-{
- uint32_t length;
- int count = 0;
- int32_t i = 0;
- ndef_record_h record = NULL;
-
- net_nfc_get_ndef_message_byte_length(msg, &length);
-
- fprintf(stdout, "================ NDEF message begin ================\n");
- fprintf(stdout, "Length : %d\n", length);
-
- net_nfc_get_ndef_message_record_count(msg, &count);
-
- for (i = 0; i < count; i++)
- {
- net_nfc_get_record_by_index(msg, i, &record);
-
- _display_record(record, i);
- }
-
- fprintf(stdout, "================= NDEF message end =================\n");
-}
-
-
-void ndef_tool_display_ndef_message_from_file(const char *file_name)
-{
- int length = 0;
- ndef_message_h msg = NULL;
-
- if ((length = ndef_tool_read_ndef_message_from_file(file_name, &msg)) > 0)
- {
- fprintf(stdout, "\n");
-
- _display_ndef_message(msg);
-
- fprintf(stdout, "\n");
-
- net_nfc_free_ndef_message(msg);
- }
- else
- {
- fprintf(stdout, "No file exists : %s\n\n", file_name);
- }
-}
-
-void _display_target_type(net_nfc_target_type_e type)
-{
- char *text = NULL;
-
- switch (type)
- {
- case NET_NFC_GENERIC_PICC :
- text = "Generic";
- break;
-
- case NET_NFC_ISO14443_A_PICC :
- text = "ISO 14443 A";
- break;
-
- case NET_NFC_ISO14443_4A_PICC :
- text = "ISO 14443 4A";
- break;
-
- case NET_NFC_ISO14443_3A_PICC :
- text = "ISO 14443 3A";
- break;
-
- case NET_NFC_MIFARE_MINI_PICC :
- text = "Mifare Mini";
- break;
-
- case NET_NFC_MIFARE_1K_PICC :
- text = "Mifare 1k";
- break;
-
- case NET_NFC_MIFARE_4K_PICC :
- text = "Mifare 4k";
- break;
-
- case NET_NFC_MIFARE_ULTRA_PICC :
- text = "Mifare Ultralight";
- break;
-
- case NET_NFC_MIFARE_DESFIRE_PICC :
- text = "Mifare Desfire";
- break;
-
- case NET_NFC_ISO14443_B_PICC :
- text = "ISO 14443 B";
- break;
-
- case NET_NFC_ISO14443_4B_PICC :
- text = "ISO 14443 4B";
- break;
-
- case NET_NFC_ISO14443_BPRIME_PICC :
- text = "ISO 14443 B Prime";
- break;
-
- case NET_NFC_FELICA_PICC :
- text = "Felica";
- break;
-
- case NET_NFC_JEWEL_PICC :
- text = "Jewel";
- break;
-
- case NET_NFC_ISO15693_PICC :
- text = "ISO 15693";
- break;
-
- case NET_NFC_NFCIP1_TARGET :
- text = "P2P Target (NFCIP1)";
- break;
-
- case NET_NFC_NFCIP1_INITIATOR :
- text = "P2P Initiator (NFCIP1)";
- break;
-
- default :
- text = "Unknown";
- break;
- }
-
- fprintf(stdout, "Target Type : %s (%d)\n", text, type);
-}
-
-void _display_tag_info(net_nfc_target_info_h target)
-{
- int count, i;
- char **keys;
- data_h data;
-
- fprintf(stdout, "Target information\n");
- net_nfc_get_tag_info_keys(target, &keys, &count);
- for (i = 0; i < count; i++)
- {
- if (keys[i] != NULL)
- {
- if (net_nfc_get_tag_info_value(target, keys[i], &data) == 0)
- {
- _display_buffer(keys[i], net_nfc_get_data_buffer(data), net_nfc_get_data_length(data));
- }
- }
- }
-}
-
-void ndef_tool_display_discovered_tag(net_nfc_target_info_h target)
-{
- net_nfc_target_type_e type;
- bool is_ndef;
- uint32_t size;
-
- if (target == NULL)
- {
- return;
- }
-
- fprintf(stdout, "\n************* Tag discovered *************\n");
-
- net_nfc_get_tag_type(target, &type);
- _display_target_type(type);
-
- net_nfc_get_tag_ndef_support(target, &is_ndef);
- fprintf(stdout, "Including NDEF? : %s\n", is_ndef ? "Yes" : "No");
-
- net_nfc_get_tag_max_data_size(target, &size);
- fprintf(stdout, "Maximum size : %d\n", size);
-
- net_nfc_get_tag_actual_data_size(target, &size);
- fprintf(stdout, "Actual size : %d\n", size);
-
- _display_tag_info(target);
-
- fprintf(stdout, "******************************************\n");
-}
-
-void ndef_tool_display_discovered_target(net_nfc_target_handle_h handle)
-{
- if (handle == NULL)
- {
- return;
- }
-
- fprintf(stdout, "\n************* Target discovered *************\n");
- fprintf(stdout, "Target Type : P2P Target (NFCIP1) (%d)\n", NET_NFC_NFCIP1_TARGET);
- fprintf(stdout, "*********************************************\n");
-}
-
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
-
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-#include <stddef.h>
-#include <stdint.h>
-#include <stdbool.h>
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-
-#include "net_nfc.h"
-#include "net_nfc_sign_record.h"
-#include "ndef-tool.h"
-
-bool ndef_tool_sign_message_from_file(const char *file_name, int begin_index, int end_index, char *cert_file, char *password)
-{
- bool result = false;
- ndef_message_h msg = NULL;
- int32_t count = 0;
-
- if (ndef_tool_read_ndef_message_from_file(file_name, &msg) > 0)
- {
- net_nfc_get_ndef_message_record_count(msg, &count);
-
- if (count > end_index)
- {
- fprintf(stdout, "count : %d\n", count);
-
- net_nfc_sign_records(msg, begin_index, end_index, cert_file, password);
-
- ndef_tool_write_ndef_message_to_file(file_name, msg);
-
- result = true;
- }
-
- net_nfc_free_ndef_message(msg);
- }
-
- return result;
-}
-
-bool ndef_tool_verify_message_from_file(const char *file_name)
-{
- bool result = false;
- ndef_message_h msg = NULL;
-
- if (ndef_tool_read_ndef_message_from_file(file_name, &msg) > 0)
- {
- result = (net_nfc_verify_signature_ndef_message(msg) == 0);
-
- net_nfc_free_ndef_message(msg);
- }
-
- return result;
-}
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
-
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-#include <stddef.h>
-#include <stdint.h>
-#include <stdbool.h>
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <glib.h>
-
-#include "net_nfc.h"
-#include "net_nfc_exchanger.h"
-#include "ndef-tool.h"
-
-typedef struct _response_context_t
-{
- int type;
- void *user_param;
-} response_context_t;
-
-static GMainLoop *main_loop = NULL;
-static response_context_t response_context = { 0, };
-
-static void _tag_read_completed_cb(ndef_message_h msg, void *user_data)
-{
- response_context_t *context = (response_context_t *)user_data;
-
- fprintf(stdout, "read complete!!!\n");
- if (msg != NULL)
- {
- ndef_tool_write_ndef_message_to_file((char *)context->user_param, msg);
-
- ndef_tool_display_ndef_message_from_file((char *)context->user_param);
- }
-
- g_main_loop_quit(main_loop);
-}
-
-static void _tag_read_cb(net_nfc_target_handle_h handle, void *user_data)
-{
- fprintf(stdout, "\nreading...\n\n");
-
- net_nfc_read_tag(handle, user_data);
-}
-
-static void _tag_write_completed_cb(net_nfc_error_e result, void *user_data)
-{
- if (result == NET_NFC_OK)
- fprintf(stdout, "write success!!!\n\n");
- else
- fprintf(stdout, "write failed.\n\n");
-
- g_main_loop_quit(main_loop);
-}
-
-static void _tag_write_cb(net_nfc_target_handle_h handle, void *user_data)
-{
- response_context_t *context = (response_context_t *)user_data;
-
- fprintf(stdout, "\nwriting...\n\n");
-
- net_nfc_write_ndef(handle, (ndef_message_h)context->user_param, user_data);
-}
-
-static void _p2p_receive_completed_cb(data_h data, void *user_data)
-{
- response_context_t *context = (response_context_t *)user_data;
-
- fprintf(stdout, "\np2p receive complete!!!\n\n");
- if (data != NULL)
- {
- ndef_message_h msg;
-
- net_nfc_create_ndef_message_from_rawdata(&msg, data);
-
- ndef_tool_write_ndef_message_to_file((char *)context->user_param, msg);
-
- net_nfc_free_ndef_message(msg);
-
- ndef_tool_display_ndef_message_from_file((char *)context->user_param);
- }
-
- g_main_loop_quit(main_loop);
-}
-
-static void _p2p_send_completed_cb(net_nfc_error_e result, void *user_data)
-{
- if (result == NET_NFC_OK)
- fprintf(stdout, "send success!!!\n\n");
- else
- fprintf(stdout, "send failed.\n\n");
-
- g_main_loop_quit(main_loop);
-}
-
-static void _p2p_send_cb(net_nfc_target_handle_h handle, void *user_data)
-{
- response_context_t *context = (response_context_t *)user_data;
-
- fprintf(stdout, "\nsending...\n\n");
-
- net_nfc_exchanger_data_h data_handle;
- data_h rawdata;
-
- net_nfc_create_rawdata_from_ndef_message((ndef_message_h)context->user_param, &rawdata);
- net_nfc_create_exchanger_data(&data_handle, rawdata);
- net_nfc_free_data(rawdata);
-
- net_nfc_send_exchanger_data(data_handle, handle, user_data);
- net_nfc_free_exchanger_data(data_handle);
-}
-
-static void _handover_completed_cb(net_nfc_error_e result,
- data_h data, void *user_data)
-{
-// response_context_t *context = (response_context_t *)user_data;
-// data_h rawdata;
-
- if (result == NET_NFC_OK)
- fprintf(stdout, "handover success!!!\n\n");
- else
- fprintf(stdout, "handover failed.\n\n");
-
-// net_nfc_create_rawdata_from_ndef_message((ndef_message_h)context->user_param, &rawdata);
-//
-// net_nfc_ex
- g_main_loop_quit(main_loop);
-}
-
-static void _open_se_cb(net_nfc_error_e result, net_nfc_target_handle_h handle,
- void *user_data)
-{
- response_context_t *context = (response_context_t *)user_data;
-
- if (result == NET_NFC_OK)
- {
- data_h data = NULL;
-
- fprintf(stdout, "net_nfc_open_internal_secure_element success!!!\n\n");
-
- net_nfc_create_data(&data, (uint8_t *)context->user_param,
- context->type);
- if (data != NULL) {
- net_nfc_send_apdu(handle, data, handle);
- net_nfc_free_data(data);
- }
- }
- else
- {
- fprintf(stdout, "net_nfc_open_internal_secure_element failed.\n\n");
- g_main_loop_quit(main_loop);
- }
-}
-
-static void _send_apdu_se_cb(net_nfc_error_e result, net_nfc_target_handle_h handle, void *user_data)
-{
-// response_context_t *context = (response_context_t *)user_data;
-// data_h rawdata;
-
- if (result == NET_NFC_OK)
- {
- fprintf(stdout, "net_nfc_send_apdu success!!!\n\n");
- net_nfc_close_internal_secure_element(handle, user_data);
- }
- else
- {
- fprintf(stdout, "net_nfc_send_apdu failed.\n\n");
- g_main_loop_quit(main_loop);
- }
-}
-
-static void _close_se_cb(net_nfc_error_e result, void *user_data)
-{
- if (result == NET_NFC_OK)
- fprintf(stdout, "net_nfc_close_internal_secure_element success!!!\n\n");
- else
- fprintf(stdout, "net_nfc_close_internal_secure_element failed.\n\n");
-
- g_main_loop_quit(main_loop);
-}
-
-static void _handover_cb(net_nfc_target_handle_h handle, void *user_data)
-{
- fprintf(stdout, "\ntry to handover...\n\n");
-
- net_nfc_exchanger_request_connection_handover(handle,
- NET_NFC_CONN_HANDOVER_CARRIER_BT);
-}
-
-void _nfc_response_cb(net_nfc_message_e message, net_nfc_error_e result,
- void *data, void *user_param, void *trans_data)
-{
- response_context_t *context = (response_context_t *)user_param;
-
- switch (message)
- {
- case NET_NFC_MESSAGE_TAG_DISCOVERED :
- {
- net_nfc_target_handle_h handle = NULL;
- bool is_ndef = false;
-
- net_nfc_get_tag_handle((net_nfc_target_info_h)data, &handle);
- net_nfc_get_tag_ndef_support((net_nfc_target_info_h)data, &is_ndef);
-
- ndef_tool_display_discovered_tag(data);
-
- if (is_ndef == true)
- {
- if (context->type == 0) /* read */
- {
- _tag_read_cb(handle, user_param);
- }
- else
- {
- _tag_write_cb(handle, user_param);
- }
- }
- else
- {
- fprintf(stdout, "No NDEF tag.. read failed.\n\n");
- g_main_loop_quit(main_loop);
- }
- }
- break;
-
- case NET_NFC_MESSAGE_READ_NDEF :
- _tag_read_completed_cb((ndef_message_h)data, user_param);
- break;
-
- case NET_NFC_MESSAGE_WRITE_NDEF :
- _tag_write_completed_cb(result, user_param);
- break;
-
- case NET_NFC_MESSAGE_P2P_DISCOVERED :
-
- ndef_tool_display_discovered_target(data);
-
- if (context->type == 1) /* receive */
- {
- _p2p_send_cb((net_nfc_target_handle_h)data, user_param);
- }
- else if (context->type == 2) /* handover */
- {
- _handover_cb((net_nfc_target_handle_h)data, user_param);
- }
- break;
-
- case NET_NFC_MESSAGE_P2P_SEND :
- _p2p_send_completed_cb(result, user_param);
- break;
-
- case NET_NFC_MESSAGE_P2P_RECEIVE :
- _p2p_receive_completed_cb(data, user_param);
- break;
-
- case NET_NFC_MESSAGE_CONNECTION_HANDOVER :
- _handover_completed_cb(result, data, user_param);
- break;
-
- case NET_NFC_MESSAGE_OPEN_INTERNAL_SE :
- _open_se_cb(result, data, user_param);
- break;
-
- case NET_NFC_MESSAGE_SEND_APDU_SE :
- _send_apdu_se_cb(result, trans_data, user_param);
- break;
-
- case NET_NFC_MESSAGE_CLOSE_INTERNAL_SE :
- _close_se_cb(result, user_param);
- break;
-
- default :
- break;
- }
-}
-
-static void _initialize_tag_context(response_context_t *context)
-{
- int ret = 0;
-
- if (!g_thread_supported())
- {
- g_thread_init(NULL);
- }
-
- ret = net_nfc_initialize();
- if (ret == NET_NFC_OK)
- {
- net_nfc_set_response_callback(_nfc_response_cb, (void *)context);
- }
-}
-
-static void _run_tag_action()
-{
- main_loop = g_main_new(TRUE);
- g_main_loop_run(main_loop);
-}
-
-static void _release_tag_context(void)
-{
- net_nfc_unset_response_callback();
-
- net_nfc_deinitialize();
-}
-
-int ndef_tool_read_ndef_from_tag(const char *file)
-{
- int result = 0;
-
- response_context.type = 0;
- response_context.user_param = (void *)file;
-
- _initialize_tag_context(&response_context);
-
- fprintf(stdout, "Contact a tag to device.....\n");
-
- _run_tag_action();
-
- _release_tag_context();
-
- return result;
-}
-
-int ndef_tool_receive_ndef_via_p2p(const char *file)
-{
- int result = 0;
-
- response_context.type = 0;
- response_context.user_param = (void *)file;
-
- _initialize_tag_context(&response_context);
-
- fprintf(stdout, "Contact a target to device.....\n");
-
- _run_tag_action();
-
- _release_tag_context();
-
- return result;
-}
-
-int ndef_tool_write_ndef_to_tag(const char *file)
-{
- int result = 0;
- ndef_message_h msg = NULL;
-
- if (ndef_tool_read_ndef_message_from_file(file, &msg) > 0)
- {
- response_context.type = 1;
- response_context.user_param = (void *)msg;
-
- _initialize_tag_context(&response_context);
-
- fprintf(stdout, "Contact a tag to device.....\n");
-
- _run_tag_action();
-
- net_nfc_free_ndef_message(msg);
-
- _release_tag_context();
- }
-
- return result;
-}
-
-int ndef_tool_send_ndef_via_p2p(const char *file)
-{
- int result = 0;
- ndef_message_h msg = NULL;
-
- if (ndef_tool_read_ndef_message_from_file(file, &msg) > 0)
- {
- response_context.type = 1;
- response_context.user_param = (void *)msg;
-
- _initialize_tag_context(&response_context);
-
- fprintf(stdout, "Contact a target to device.....\n");
-
- _run_tag_action();
-
- net_nfc_free_ndef_message(msg);
-
- _release_tag_context();
- }
-
- return result;
-}
-
-static int _make_file_to_ndef_message(ndef_message_h *msg, const char *file_name)
-{
- int result = 0;
- FILE *file = NULL;
-
- file = fopen(file_name, "rb");
- if (file != NULL)
- {
- long int file_size = 0;
- size_t read = 0;
-
- fseek(file, 0, SEEK_END);
- file_size = ftell(file);
- fseek(file, 0, SEEK_SET);
-
- if (file_size > 0)
- {
- data_h data;
-
- net_nfc_create_data(&data, NULL, file_size);
- if (data != NULL)
- {
- ndef_record_h record;
- data_h type;
-
- read = fread((void *)net_nfc_get_data_buffer(data), 1, file_size, file);
-
- net_nfc_create_ndef_message(msg);
-
- net_nfc_create_data(&type, (uint8_t *)"image/jpeg", 10);
-
- net_nfc_create_record(&record, NET_NFC_RECORD_MIME_TYPE, type, NULL, data);
-
- net_nfc_append_record_to_ndef_message(*msg, record);
-
- net_nfc_free_data(type);
- net_nfc_free_data(data);
-
- result = file_size;
- }
- }
-
- fclose(file);
- }
-
- return result;
-}
-
-int ndef_tool_connection_handover(const char *file)
-{
- int result = 0;
- ndef_message_h msg = NULL;
-
- if (_make_file_to_ndef_message(&msg, file) > 0)
- {
- response_context.type = 2;
- response_context.user_param = (void *)msg;
-
- _initialize_tag_context(&response_context);
-
- fprintf(stdout, "Contact a target to device.....\n");
-
- _run_tag_action();
-
- net_nfc_free_ndef_message(msg);
-
- _release_tag_context();
- }
-
- return result;
-}
-
-static unsigned char char_to_num[] =
-{
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1,
- -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-};
-
-int _convert_string_to_hex(const char *str, unsigned char *buffer, size_t length)
-{
- size_t i, j, len = strlen(str);
-
- for (i = 0, j = 0; i < len; j++)
- {
- buffer[j] = (char_to_num[(unsigned char)str[i++]] << 4);
- if (i < len)
- {
- buffer[j] |= char_to_num[(unsigned char)str[i++]];
- }
- }
-
- return (int)j;
-}
-
-int ndef_tool_send_apdu(const char *apdu)
-{
- int result = 0;
- unsigned char *buffer;
- unsigned int length = (strlen(apdu) >> 1) + 1;
-
- buffer = calloc(1, length);
- if (buffer != NULL)
- {
- length = _convert_string_to_hex(apdu, buffer, length);
- if (length > 0)
- {
- response_context.type = length;
- response_context.user_param = (void *)buffer;
-
- _initialize_tag_context(&response_context);
-
- fprintf(stdout, "try to open eSE.....\n");
-
- net_nfc_open_internal_secure_element(NET_NFC_SE_TYPE_ESE, buffer);
-
- _run_tag_action();
-
-
- _release_tag_context();
- }
-
- free(buffer);
- }
-
- return result;
-}
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
-
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-#include <stddef.h>
-#include <stdint.h>
-#include <stdbool.h>
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <glib.h>
-
-#include "net_nfc.h"
-#include "ndef-tool.h"
-
-static GMainLoop *main_loop = NULL;
-
-void _activation_complete_cb(net_nfc_message_e message, net_nfc_error_e result,
- void *data, void *user_param, void *trans_data)
-{
- switch (message)
- {
- case NET_NFC_MESSAGE_INIT :
- if (result == NET_NFC_OK)
- fprintf(stdout, "power on success\n\n");
- else
- fprintf(stdout, "failed to power on (%d)\n\n", result);
-
- net_nfc_unset_response_callback();
- net_nfc_deinitialize();
- g_main_loop_quit(main_loop);
- break;
-
- case NET_NFC_MESSAGE_DEINIT :
- if (result == NET_NFC_OK)
- fprintf(stdout, "power off success\n\n");
- else
- fprintf(stdout, "failed to power off (%d)\n\n", result);
-
- net_nfc_unset_response_callback();
- net_nfc_deinitialize();
- g_main_loop_quit(main_loop);
- break;
-
- default :
- break;
- }
-}
-
-int ndef_tool_read_ndef_message_from_file(const char *file_name, ndef_message_h *msg)
-{
- int result = -1;
- FILE *file = NULL;
-
- file = fopen(file_name, "rb");
- if (file != NULL)
- {
- long int file_size = 0;
- size_t read = 0;
-
- fseek(file, 0, SEEK_END);
- file_size = ftell(file);
- fseek(file, 0, SEEK_SET);
-
- if (file_size > 0)
- {
- data_h data;
-
- net_nfc_create_data(&data, NULL, file_size);
- if (data != NULL)
- {
- read = fread((void *)net_nfc_get_data_buffer(data), 1, file_size, file);
-
- net_nfc_create_ndef_message_from_rawdata(msg, data);
-
- net_nfc_free_data(data);
-
- result = file_size;
- }
- }
-
- fclose(file);
- }
-
- return result;
-}
-
-int ndef_tool_write_ndef_message_to_file(const char *file_name, ndef_message_h msg)
-{
- int result = -1;
- FILE *file = NULL;
- data_h data = NULL;
-
- net_nfc_create_rawdata_from_ndef_message(msg, &data);
- if (data != NULL)
- {
- file = fopen(file_name, "wb");
- if (file != NULL)
- {
- fwrite((void *)net_nfc_get_data_buffer(data), 1, net_nfc_get_data_length(data), file);
- fflush(file);
- fclose(file);
-
- result = 0;
- }
-
- net_nfc_free_data(data);
- }
-
- return result;
-}
-
-static void print_usage(char *file_name)
-{
- fprintf(stdout, "Usage : %s OPERATION [OPTION]... FILE\n", file_name);
- fprintf(stdout, "\n");
- fprintf(stdout, " Operation\n");
- fprintf(stdout, " -a, --append-record Append a record to file\n");
- fprintf(stdout, " Options\n");
- fprintf(stdout, " -t, --tnf tnf Input TNF value\n");
- fprintf(stdout, " (WKT : Well-known, EXT : External, \n");
- fprintf(stdout, " MIME : MIME-type, URI : Absolute-URI)\n");
- fprintf(stdout, " -T, --type-data data Input Type-field data\n");
- fprintf(stdout, " -I, --id-data data Input ID-field data\n");
- fprintf(stdout, " -P, --payload-data data Input Payload-field data. You can input hexa-style data using '%%' prefix\n");
- fprintf(stdout, " ex) (0x20)abc : %%20abc\n");
- fprintf(stdout, " it is possible to input '%%' by using '%%%%'\n");
- fprintf(stdout, " ex) 120%%20 : 120%%%%20\n");
- fprintf(stdout, " --payload-file file Input Payload-field data from binary file\n");
- fprintf(stdout, " -E, --encoding data Input encoding method of Well-known Text type record\n");
- fprintf(stdout, "\n");
- fprintf(stdout, " -r, --remove-record Remove a specific record from file\n");
- fprintf(stdout, " Options\n");
- fprintf(stdout, " -i, --index value Input a record index\n");
- fprintf(stdout, "\n");
- fprintf(stdout, " -d, --display Display all records in file\n");
- fprintf(stdout, " -s, --sign-records Sign some continuous records in file\n");
- fprintf(stdout, " Options\n");
- fprintf(stdout, " -b, --begin-index value Input a beginning record index\n");
- fprintf(stdout, " -e, --end-index value Input a last record index\n");
- fprintf(stdout, " -c, --cert-file file Input a PKCS #12 certificate file (DER file, not PEM file)\n");
- fprintf(stdout, " -p, --password pass Input a password of PKCS #12 certificate file\n");
- fprintf(stdout, "\n");
- fprintf(stdout, " -v, --verify-signed-records Verify signature in file\n");
- fprintf(stdout, " --read-tag Read a ndef from tag and store to file\n");
- fprintf(stdout, " --write-tag Write a ndef file to tag\n");
- fprintf(stdout, " --receive-ndef Receive a ndef from target device and store to file\n");
- fprintf(stdout, " --send-ndef Send a ndef file to target device\n");
- fprintf(stdout, " --handover Try to handover another carrier\n");
- fprintf(stdout, "\n");
- fprintf(stdout, " -h, --help Show this help messages\n");
- fprintf(stdout, "\n");
-}
-
-static net_nfc_record_tnf_e _parse_tnf_string(const char *tnf)
-{
- net_nfc_record_tnf_e result = -1;
-
- if (tnf == NULL)
- return result;
-
- if (strncasecmp(tnf, "EMT", 3) == 0)
- {
- result = NET_NFC_RECORD_EMPTY;
- }
- else if (strncasecmp(tnf, "WKT", 3) == 0)
- {
- result = NET_NFC_RECORD_WELL_KNOWN_TYPE;
- }
- else if (strncasecmp(tnf, "MIME", 4) == 0)
- {
- result = NET_NFC_RECORD_MIME_TYPE;
- }
- else if (strncasecmp(tnf, "URI", 3) == 0)
- {
- result = NET_NFC_RECORD_URI;
- }
- else if (strncasecmp(tnf, "EXT", 3) == 0)
- {
- result = NET_NFC_RECORD_EXTERNAL_RTD;
- }
- else if (strncasecmp(tnf, "UNK", 3) == 0)
- {
- result = NET_NFC_RECORD_UNKNOWN;
- }
- else if (strncasecmp(tnf, "UNC", 3) == 0)
- {
- result = NET_NFC_RECORD_UNCHAGNED;
- }
-
- return result;
-}
-
-static int _append_record_to_file(const char *file_name, ndef_record_h record)
-{
- int result = -1;
- ndef_message_h msg = NULL;
-
- if (ndef_tool_read_ndef_message_from_file(file_name, &msg) <= 0)
- {
- net_nfc_create_ndef_message(&msg);
- }
-
- net_nfc_append_record_to_ndef_message(msg, record);
-
- ndef_tool_write_ndef_message_to_file(file_name, msg);
-
- net_nfc_free_ndef_message(msg);
-
- result = 0;
-
- return result;
-}
-
-ndef_record_h _create_record(net_nfc_record_tnf_e tnf, data_h type, data_h id , data_h payload, char *encoding)
-{
- ndef_record_h result = NULL;
-
- switch (tnf)
- {
- case NET_NFC_RECORD_WELL_KNOWN_TYPE :
- if (net_nfc_get_data_length(type) == 1 && memcmp((void *)net_nfc_get_data_buffer(type), "T", 1) == 0)
- {
- if (encoding == NULL)
- {
- fprintf(stdout, "encoding type is not present.\n");
- return result;
- }
-
- char *temp_str = calloc(1, net_nfc_get_data_length(payload) + 1);
- memcpy(temp_str, (void *)net_nfc_get_data_buffer(payload), net_nfc_get_data_length(payload));
-
- net_nfc_create_text_type_record(&result, temp_str, encoding, NET_NFC_ENCODE_UTF_8);
- free(temp_str);
-
- if (id != NULL)
- {
- net_nfc_set_record_id(result, id);
- }
- }
- else if (net_nfc_get_data_length(type) == 1 && memcmp((void *)net_nfc_get_data_buffer(type), "U", 1) == 0)
- {
- char *temp_str = calloc(1, net_nfc_get_data_length(payload) + 1);
- memcpy(temp_str, (void *)net_nfc_get_data_buffer(payload), net_nfc_get_data_length(payload));
-
- net_nfc_create_uri_type_record(&result, temp_str, 0);
- free(temp_str);
-
- if (id != NULL)
- {
- net_nfc_set_record_id(result, id);
- }
- }
- else
- {
- net_nfc_create_record(&result, tnf, type, id, payload);
- }
- break;
-
- default :
- net_nfc_create_record(&result, tnf, type, id, payload);
- break;
- }
-
- return result;
-}
-
-bool _remove_record_from_file(const char *file_name, int index)
-{
- bool result = false;
- ndef_message_h msg = NULL;
-
- if (ndef_tool_read_ndef_message_from_file(file_name, &msg) > 0)
- {
- net_nfc_remove_record_by_index(msg, index);
-
- ndef_tool_write_ndef_message_to_file(file_name, msg);
-
- net_nfc_free_ndef_message(msg);
-
- result = true;
- }
-
- return result;
-}
-
-#define __IS_SHORT_OPTION(__dst) ((strlen(__dst) == 2) && ((__dst)[0] == '-'))
-#define __IS_LONG_OPTION(__dst) ((strlen(__dst) > 2) && ((__dst)[0] == '-') && ((__dst)[1] == '-'))
-#define __IS_OPTION(__dst) (__IS_SHORT_OPTION(__dst) || __IS_LONG_OPTION(__dst))
-
-#define __COMPARE_OPTION(__dst, __s, __l) \
- ((__IS_SHORT_OPTION(__dst) && ((__dst)[1] == (__s))) || \
- (__IS_LONG_OPTION(__dst) && (strcmp((__dst) + 2, (__l)) == 0)))
-
-#define __DO_NEXT_ARG \
- if (++i >= argc || __IS_OPTION(argv[i]) == true) \
- { \
- operation = OPERATION_ERROR; \
- break; \
- }
-
-int main(int argc, char *argv[])
-{
- int remove_index = -1;
- int begin_index = -1;
- int end_index = -1;
- int operation = OPERATION_ERROR;
- net_nfc_record_tnf_e tnf = -1;
- data_h type = NULL;
- data_h id = NULL;
- data_h payload = NULL;
- char *file_name = NULL;
- char *cert_file = NULL;
- char *password = NULL;
- char *encoding = NULL;
- ndef_record_h record = NULL;
-
- int i = 1;
- int len = 0;
-
- for (i = 1; i < argc; i++)
- {
- if (__COMPARE_OPTION(argv[i], 'a', "append-record"))
- {
- operation = OPERATION_APPEND;
- }
- else if (__COMPARE_OPTION(argv[i], 's', "sign-records"))
- {
- operation = OPERATION_SIGN;
- }
- else if (__COMPARE_OPTION(argv[i], 'd', "display-record"))
- {
- operation = OPERATION_DISPLAY;
- }
- else if (__COMPARE_OPTION(argv[i], 'v', "verify-signed-records"))
- {
- operation = OPERATION_VERIFY;
- }
- else if (__COMPARE_OPTION(argv[i], 'r', "remove-record"))
- {
- operation = OPERATION_REMOVE;
- }
- else if (__COMPARE_OPTION(argv[i], 0, "read-tag"))
- {
- operation = OPERATION_READ_TAG;
- }
- else if (__COMPARE_OPTION(argv[i], 0, "write-tag"))
- {
- operation = OPERATION_WRITE_TAG;
- }
- else if (__COMPARE_OPTION(argv[i], 0, "receive-ndef"))
- {
- operation = OPERATION_RECEIVE_NDEF;
- }
- else if (__COMPARE_OPTION(argv[i], 0, "send-ndef"))
- {
- operation = OPERATION_SEND_NDEF;
- }
- else if (__COMPARE_OPTION(argv[i], 0, "handover"))
- {
- operation = OPERATION_HANDOVER;
- }
- else if (__COMPARE_OPTION(argv[i], 0, "off")) /* hidden operation */
- {
- operation = OPERATION_OFF;
- }
- else if (__COMPARE_OPTION(argv[i], 0, "on")) /* hidden operation */
- {
- operation = OPERATION_ON;
- }
- else if (__COMPARE_OPTION(argv[i], 0, "send-apdu")) /* hidden operation */
- {
- operation = OPERATION_SEND_APDU;
- }
- else if (__COMPARE_OPTION(argv[i], 0, "set-se")) /* hidden operation */
- {
- operation = OPERATION_SET_SE;
- }
- else if (__COMPARE_OPTION(argv[i], 'i', "record-index"))
- {
- __DO_NEXT_ARG;
- remove_index = atoi(argv[i]);
- }
- else if (__COMPARE_OPTION(argv[i], 'c', "cert-file"))
- {
- __DO_NEXT_ARG;
- cert_file = strdup(argv[i]);
- }
- else if (__COMPARE_OPTION(argv[i], 'p', "password"))
- {
- __DO_NEXT_ARG;
- password = strdup(argv[i]);
- }
- else if (__COMPARE_OPTION(argv[i], 'b', "begin-index"))
- {
- __DO_NEXT_ARG;
- begin_index = atoi(argv[i]);
- }
- else if (__COMPARE_OPTION(argv[i], 'e', "end-index"))
- {
- __DO_NEXT_ARG;
- end_index = atoi(argv[i]);
- }
- else if (__COMPARE_OPTION(argv[i], 't', "tnf"))
- {
- __DO_NEXT_ARG;
- tnf = _parse_tnf_string(argv[i]);
- }
- else if (__COMPARE_OPTION(argv[i], 'T', "type-data"))
- {
- __DO_NEXT_ARG;
- len = strlen(argv[i]);
- if (len > 0)
- {
- net_nfc_create_data(&type, (const uint8_t *)argv[i], len);
- }
- }
- else if (__COMPARE_OPTION(argv[i], 'I', "id-data"))
- {
- __DO_NEXT_ARG;
- len = strlen(argv[i]);
- if (len > 0)
- {
- net_nfc_create_data(&id, (const uint8_t *)argv[i], len);
- }
- }
- else if (__COMPARE_OPTION(argv[i], 'P', "payload-data"))
- {
- __DO_NEXT_ARG;
- len = strlen(argv[i]);
- if (len > 0)
- {
- uint8_t *buffer = NULL;
-
- buffer = calloc(1, len);
- if (buffer != NULL)
- {
- int j, current = 0;
-
- for (j = 0; j < len; j++)
- {
- if (argv[i][j] == '%')
- {
- if (j + 2 < len)
- {
- if (argv[i][j + 1] != '%')
- {
- char temp[3] = { 0, };
-
- temp[0] = argv[i][j + 1];
- temp[1] = argv[i][j + 2];
-
- buffer[current++] = (uint8_t)strtol(temp, NULL, 16);
- j += 2;
- }
- else
- {
- buffer[current++] = '%';
- j++;
- }
- }
- else if (j + 1 < len)
- {
- if (argv[i][j + 1] == '%')
- {
- buffer[current++] = '%';
- j++;
- }
- else
- {
- buffer[current++] = argv[i][j];
- }
- }
- else
- {
- /* invalid param. error? */
- }
- }
- else
- {
- buffer[current++] = argv[i][j];
- }
- }
-
- net_nfc_create_data(&payload, buffer, current);
-
- free(buffer);
- }
- }
- }
- else if (__COMPARE_OPTION(argv[i], 0, "payload-file"))
- {
- __DO_NEXT_ARG;
- len = strlen(argv[i]);
- if (len > 0)
- {
- FILE *file = NULL;
-
- file = fopen(argv[i], "rb");
- if (file != NULL)
- {
- long int file_size = 0;
- size_t read = 0;
-
- fseek(file, 0, SEEK_END);
- file_size = ftell(file);
- fseek(file, 0, SEEK_SET);
-
- if (file_size > 0)
- {
- uint8_t *buffer = NULL;
-
- buffer = calloc(1, file_size);
- if (buffer != NULL)
- {
- read = fread(buffer, 1, file_size, file);
-
- net_nfc_create_data(&payload, buffer, read);
-
- free(buffer);
- }
- }
-
- fclose(file);
- }
- }
- }
- else if (__COMPARE_OPTION(argv[i], 'E', "encoding"))
- {
- __DO_NEXT_ARG;
- encoding = strdup(argv[i]);
- }
- else if (__COMPARE_OPTION(argv[i], 'h', "help"))
- {
- operation = OPERATION_ERROR;
- break;
- }
- else
- {
- if (file_name == NULL)
- {
- file_name = strdup(argv[i]);
- }
- else
- {
- operation = OPERATION_ERROR;
- break;
- }
- }
- }
-
- if (operation != OPERATION_ON && operation != OPERATION_OFF && file_name == NULL)
- operation = OPERATION_ERROR;
-
- switch (operation)
- {
- case OPERATION_DISPLAY :
- ndef_tool_display_ndef_message_from_file(file_name);
- break;
-
- case OPERATION_APPEND :
- if (tnf >= 0 && type != NULL)
- {
- record = _create_record(tnf, type, id, payload, encoding);
-
- if (record != NULL)
- {
- _append_record_to_file(file_name, record);
-
- ndef_tool_display_ndef_message_from_file(file_name);
- }
- else
- {
- print_usage(argv[0]);
- }
- }
- else
- {
- print_usage(argv[0]);
- }
- break;
-
- case OPERATION_REMOVE :
- _remove_record_from_file(file_name, remove_index);
- ndef_tool_display_ndef_message_from_file(file_name);
- break;
-
- case OPERATION_SIGN :
- if (begin_index < 0 || end_index < 0 || begin_index > end_index || cert_file == NULL || password == NULL)
- {
- print_usage(argv[0]);
- }
- else
- {
- fprintf(stdout, "file : %s\ncert file : %s\npassword : %s\nbegin index : %d\nend index : %d\n", file_name, cert_file, password, begin_index, end_index);
- ndef_tool_sign_message_from_file(file_name, begin_index, end_index, cert_file, password);
- ndef_tool_display_ndef_message_from_file(file_name);
- }
- break;
-
- case OPERATION_VERIFY :
- fprintf(stdout, "verify %s\n", ndef_tool_verify_message_from_file(file_name) ? "success" : "failed");
- break;
-
- case OPERATION_READ_TAG :
- ndef_tool_read_ndef_from_tag(file_name);
- break;
-
- case OPERATION_WRITE_TAG :
- ndef_tool_write_ndef_to_tag(file_name);
- break;
-
- case OPERATION_RECEIVE_NDEF :
- ndef_tool_receive_ndef_via_p2p(file_name);
- break;
-
- case OPERATION_SEND_NDEF :
- ndef_tool_send_ndef_via_p2p(file_name);
- break;
-
- case OPERATION_HANDOVER :
- ndef_tool_connection_handover(file_name);
- break;
-
- case OPERATION_ON :
- {
- int state = 0;
-
- net_nfc_get_state(&state);
-
- if (state == 0)
- {
- fprintf(stdout, "Power on....\n\n");
-
- if(!g_thread_supported())
- {
- g_thread_init(NULL);
- }
-
- main_loop = g_main_new(true);
-
- net_nfc_initialize();
- net_nfc_set_response_callback(_activation_complete_cb, NULL);
- net_nfc_set_state(true, NULL);
-
- g_main_loop_run(main_loop);
- }
- else
- {
- fprintf(stdout, "Already power is on.\n\n");
- }
- }
- break;
-
- case OPERATION_OFF :
- {
- int state = 0;
-
- net_nfc_get_state(&state);
-
- if (state == 1)
- {
- fprintf(stdout, "Power off....\n\n");
-
- if(!g_thread_supported())
- {
- g_thread_init(NULL);
- }
-
- main_loop = g_main_new(true);
-
- net_nfc_initialize();
- net_nfc_set_response_callback(_activation_complete_cb, NULL);
- net_nfc_set_state(false, NULL);
-
- g_main_loop_run(main_loop);
- }
- else
- {
- fprintf(stdout, "Already power is off.\n\n");
- }
- }
- break;
-
- case OPERATION_SEND_APDU :
- ndef_tool_send_apdu(file_name);
- break;
-
- case OPERATION_SET_SE :
- net_nfc_initialize();
-
- if (strcmp(file_name, "SIM1") == 0) {
- net_nfc_set_secure_element_type(NET_NFC_SE_TYPE_UICC, NULL);
- } else if (strcmp(file_name, "eSE") == 0) {
- net_nfc_set_secure_element_type(NET_NFC_SE_TYPE_ESE, NULL);
- } else {
- fprintf(stdout, "Unknown SE name.\n\n");
- }
- break;
-
- case OPERATION_ERROR :
- default :
- print_usage(argv[0]);
- break;
- }
-
- return 0;
-}
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
-
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef __NDEF_TOOL_H__
-#define __NDEF_TOOL_H__
-
-#include "net_nfc_typedef.h"
-
-enum
-{
- OPERATION_ERROR,
- OPERATION_DISPLAY,
- OPERATION_APPEND,
- OPERATION_REMOVE,
- OPERATION_SIGN,
- OPERATION_VERIFY,
- OPERATION_READ_TAG,
- OPERATION_WRITE_TAG,
- OPERATION_RECEIVE_NDEF,
- OPERATION_SEND_NDEF,
- OPERATION_HANDOVER,
- OPERATION_SEND_APDU,
- OPERATION_ON, /* hidden operation */
- OPERATION_OFF, /* hidden operation */
- OPERATION_SET_SE, /* hidden operation */
-};
-
-int ndef_tool_read_ndef_message_from_file(const char *file_name, ndef_message_h *msg);
-int ndef_tool_write_ndef_message_to_file(const char *file_name, ndef_message_h msg);
-
-void ndef_tool_display_ndef_message_from_file(const char *file_name);
-void ndef_tool_display_discovered_tag(net_nfc_target_info_h target);
-void ndef_tool_display_discovered_target(net_nfc_target_handle_h handle);
-
-bool ndef_tool_sign_message_from_file(const char *file_name, int begin_index, int end_index, char *cert_file, char *password);
-bool ndef_tool_verify_message_from_file(const char *file_name);
-
-int ndef_tool_read_ndef_from_tag(const char *file);
-int ndef_tool_write_ndef_to_tag(const char *file);
-int ndef_tool_receive_ndef_via_p2p(const char *file);
-int ndef_tool_send_ndef_via_p2p(const char *file);
-int ndef_tool_connection_handover(const char *file);
-int ndef_tool_send_apdu(const char *apdu);
-
-
-#endif //__NDEF_TOOL_H__
+++ /dev/null
-CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
-PROJECT(nfc_client C)
-
-SET(NFC_CLIENT "nfc_client")
-
-include_directories(${CMAKE_SOURCE_DIR}/src/commonlib/include)
-include_directories(${CMAKE_SOURCE_DIR}/src/clientlib/include)
-include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
-
-AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/ TOOL_SRC)
-
-IF("${CMAKE_BUILD_TYPE}" STREQUAL "")
- SET(CMAKE_BUILD_TYPE "Release")
-ENDIF("${CMAKE_BUILD_TYPE}" STREQUAL "")
-
-INCLUDE(FindPkgConfig)
-pkg_check_modules(tool_pkgs REQUIRED glib-2.0 gobject-2.0)
-
-FOREACH(flag ${tool_pkgs_CFLAGS})
- SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
-ENDFOREACH(flag)
-
-# this for NFC flag
-
-SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -pipe -fomit-frame-pointer -Wall -Wno-trigraphs -Werror-implicit-function-declaration -fno-strict-aliasing -Wl,-zdefs -fvisibility=hidden")
-
-SET(ARM_CFLAGS "${ARM_CLAGS} -mapcs -mno-sched-prolog -mabi=aapcs-linux -Uarm -fno-common -fpie")
-
-SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
-SET(CMAKE_C_FLAGS_DEBUG "-O0 -g")
-
-FIND_PROGRAM(UNAME NAMES uname)
-EXEC_PROGRAM("${UNAME}" ARGS "-m" OUTPUT_VARIABLE "ARCH")
-IF("${ARCH}" MATCHES "^arm.*")
- ADD_DEFINITIONS("-DTARGET")
- MESSAGE("add -DTARGET")
- SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${ARM_CFLAGS}")
-ENDIF()
-
-ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"")
-
-SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie")
-
-ADD_EXECUTABLE(${NFC_CLIENT} ${TOOL_SRC})
-
-TARGET_LINK_LIBRARIES(${NFC_CLIENT} ${tool_pkgs_LDFLAGS} pthread dl rt nfc-common-lib nfc)
-LINK_DIRECTORIES(${CMAKE_BUILD_DIR}/src/commonlib ${CMAKE_BUILD_DIR}/src/clientlib)
-
-INSTALL(TARGETS ${NFC_CLIENT} DESTINATION bin)
-
-
+++ /dev/null
-LOCAL_PATH=.
-
-#phLibNfc
-
-export PKG_CONFIG_PATH=/usr/lib/pkgconfig/
-
-#sources
-
-SRCS = $(LOCAL_PATH)/main.c
-
-#includes
-
-USER_HEADER =`pkg-config --cflags nfc glib-2.0 gobject-2.0`
-
-LOCAL_CFLAGS = $(USER_HEADER)
-
-CC = arm-linux-gnueabi-gcc
-
-TARGET = nfc-test
-
-
-CFLAGS = $(LOCAL_CFLAGS) -g
-LDFLAGS = -lpthread `pkg-config --libs nfc glib-2.0 gobject-2.0`
-
-
-SRC = $(SRCS)
-OBJS = $(SRC:.c=.o)
-RM = rm
-
-
-.SUFFIXES: .c .o
-
-.c.o:
- $(CC) -c $(CFLAGS) -o $*.o $<
-
-all: $(TARGET)
-
-$(TARGET): $(OBJS)
- $(CC) -o $@ $(OBJS) $(LDFLAGS)
-
-run: all
- $(TARGET)
-
-clean:
- $(RM) -f $(OBJS) $(TARGET)
-
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
-
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <net_nfc.h>
-#include <unistd.h>
-#include <pthread.h>
-#include "nfc_api_test.h"
-
-#include <glib.h>
-
-/* Function definition list*/
-int nfcTestClientInit(uint8_t testNumber,void* arg_ptr2);
-int nfcTestNdefParser(uint8_t testNumber,void* arg_ptr2);
-int nfcTestWriteMode(uint8_t testNumber,void* arg_ptr2);
-int nfcTestReaderMode(uint8_t testNumber,void* arg_ptr2);
-int nfcTestTransceive(uint8_t testNumber,void* arg_ptr2);
-int nfcTestAPIBasicTest1(uint8_t testNumber,void* arg_ptr2);
-int nfcTestAPIBasicTest2(uint8_t testNumber,void* arg_ptr2);
-int nfcTestAPIBasicTest3(uint8_t testNumber,void* arg_ptr2);
-int nfcTestReadWriteMode(uint8_t testNumber,void* arg_ptr2);
-int nfcTestAPIMultipleRequest(uint8_t testNumber,void* arg_ptr2);
-int nfcTestLLCP(uint8_t testNumber,void* arg_ptr2);
-int nfcTestStressLLCP(uint8_t testNumber,void* arg_ptr2);
-int nfcTestExchanger(uint8_t testNumber,void* arg_ptr2);
-int nfcConnHandover(uint8_t testNumber,void* arg_ptr2);
-int nfcTestAPIException (uint8_t testNumber,void* arg_ptr);
-int nfcTestAPIException_tagAPI (uint8_t testNumber,void* arg_ptr);
-int nfcTestAPIException_targetInfo (uint8_t testNumber,void* arg_ptr);
-int nfcConnHandoverMessageTest (uint8_t testNumber,void* arg_ptr);
-int nfcTestFormatNdef(uint8_t testNumber,void* arg_ptr2);
-int nfcTestInternalSe(uint8_t testNumber,void* arg_ptr2);
-int nfcTestSnep(uint8_t testNumber,void* arg_ptr);
-
-
-void print_test_result (char * str, net_nfc_test_result_e result);
-
-#define NET_NFC_TAG_DISCOVERED 1
-#define NET_NFC_TAG_CONNECT (1 << 1)
-#define NET_NFC_TAG_CHECK_NDEF (1 << 2)
-#define NET_NFC_TAG_NDEF_READ (1 << 3)
-#define NET_NFC_TAG_NDEF_WRITE (1 << 4)
-#define NET_NFC_TAG_NDEF_READ_BIG (1 << 5)
-#define NET_NFC_TAG_NDEF_WRITE_BIG (1 << 6)
-#define NET_NFC_TAG_DISCONNECT (1 << 7)
-#define NET_NFC_MAX_TAG_TYPE 20
-
-static nfcTestType nfcTestMatrix[] =
-{
-// {"API STRESS_WRITE_READ TEST", nfcTestReadWriteMode, NET_NFC_TEST_NOT_YET}, // OK
-// {"Remove tag while writing", nfcTestWriteMode, NET_NFC_TEST_NOT_YET}, //OK
-// {"Remove tag while reading", nfcTestAPIBasicTest2, NET_NFC_TEST_NOT_YET}, // OK
- //{"API BASIC TEST3", nfcTestAPIBasicTest3, NET_NFC_TEST_NOT_YET},
-// {"API MUTIPLE REQUEST", nfcTestAPIMultipleRequest, NET_NFC_TEST_NOT_YET}, // OK
-// {"API BASIC TEST1", nfcTestAPIBasicTest1, NET_NFC_TEST_NOT_YET}, // OK
-// {"Check NDEF message", nfcTestNdefParser, NET_NFC_TEST_NOT_YET}, // OK
-// {"write mode", nfcTestWriteMode, NET_NFC_TEST_NOT_YET},
-// {"reader mode", nfcTestReaderMode, NET_NFC_TEST_NOT_YET},
-// {"format ndef", nfcTestFormatNdef, NET_NFC_TEST_NOT_YET},
-// {"internal_se_test", nfcTestInternalSe, NET_NFC_TEST_NOT_YET},
-// {"exchange mode", nfcTestExchanger, NET_NFC_TEST_NOT_YET},
-// {"Transceive Test", nfcTestTransceive, NET_NFC_TEST_NOT_YET},
-// {"LLCP Test", nfcTestLLCP, NET_NFC_TEST_NOT_YET},
-// {"connection handover msg test", nfcConnHandover, NET_NFC_TEST_NOT_YET},
-// {"API Exception Test", nfcTestAPIException, NET_NFC_TEST_NOT_YET},
-// {"API Exception Test2", nfcTestAPIException_tagAPI, NET_NFC_TEST_NOT_YET},
-/// {"API Exception Test3", nfcTestAPIException_targetInfo, NET_NFC_TEST_NOT_YET},
-// {"LLCP Test", nfcTestLLCP, NET_NFC_TEST_NOT_YET},
-// {"LLCP Test", nfcTestStressLLCP, NET_NFC_TEST_NOT_YET},
-// {"Handover Message", nfcConnHandoverMessageTest , NET_NFC_TEST_NOT_YET},
- {"snep test", nfcTestSnep, NET_NFC_TEST_NOT_YET},
- {NULL, NULL, NET_NFC_TEST_NOT_YET},
-};
-
-//static uint32_t testDevType = 0;
-//static uint32_t testCardMaxNdefLength = 0;
-//static uint8_t tagTestResult[NET_NFC_MAX_TAG_TYPE];
-
-static int read_count = 0;
-static int write_count = 0;
-static int detect_count = 0;
-
-static net_nfc_target_handle_h tag_handle = NULL;
-static int test_count = 0;
-
-
-
-/* Below smart poster data can has problem or parser has some problem.
- Need to check */
-uint8_t nfcTestSpHex[]= {0xD1,0x02,0x37,0x53,0x70,0x91,0x01,0x18,0x54,0x04,
- 0x74,0x65,0x73,0x74,0x53,0x6D,0x61,0x72,0x74,0x70,
- 0x6F,0x73,0x74,0x65,0x72,0x20,0x45,0x78,0x61,0x6D,
- 0x70,0x6C,0x65,0x11,0x03,0x01,0x61,0x63,0x74,0x00,
- 0x51,0x01,0x10,0x55,0x00,0x77,0x77,0x77,0x2E,0x73,
- 0x61,0x6D,0x73,0x75,0x6E,0x67,0x2E,0x63,0x6F,0x6D};
-
-/*
-uint8_t nfcTestSp[]={0xD1,0x02,0x24,0x53,0x70,0x91,0x01,0x14,0x54
- ,0x00,0x53,0x6D,0x61,0x72,0x74,0x70,0x6F,0x73
- ,0x74,0x65,0x72,0x20,0x45,0x78,0x61,0x6D,0x70
- ,0x6C,0x65,0x11,0x03,0x01,0x61,0x63,0x74,0x00
- ,0x51,0x01,0x01,0x55,0x00};
-*/
-
-// test Text "Samsung Linux Platform NFC TEST"
-uint8_t nfcTestTextHex[]= {0xD1,0x01,0x20,0x54,0x00,0x53,0x61,0x6D,0x73,0x75
- ,0x6E,0x67,0x20,0x4C,0x69,0x6E,0x75,0x78,0x20,0x50
- ,0x6C,0x61,0x74,0x66,0x6F,0x72,0x6D,0x20,0x4E,0x46
- ,0x43,0x20,0x54,0x45,0x53,0x54};
-
-
-// test URI "http://www.samsunglinuxplatform.nfctest.com"
-uint8_t nfcTestUriHex[]={0xD1,0x01,0x2C,0x55,0x00,0x68,0x74,0x74,0x70,0x3A
- ,0x2F,0x2F,0x77,0x77,0x77,0x2E,0x73,0x61,0x6D,0x73
- ,0x75,0x6E,0x67,0x6C,0x69,0x6E,0x75,0x78,0x70,0x6C
- ,0x61,0x74,0x66,0x6F,0x72,0x6D,0x2E,0x6E,0x66,0x63
- ,0x74,0x65,0x73,0x74,0x2E,0x63,0x6F,0x6D};
-
-uint8_t nfcTestText[] = "payload http://www.samsunglinuxplatform.nfctest.com";
-uint8_t nfcTestUri[] = {0xD1,0x01,0x13,0x55,0x1,0x73,0x61,0x6D,0x73,0x75,0x6E,0x67,0x6D,0x6F,0x62,0x69,0x6C,0x65,0x2E,0x63,0x6F,0x6D,0x2F};
-
-
-
-static pthread_cond_t pcond = PTHREAD_COND_INITIALIZER;
-static pthread_mutex_t plock = PTHREAD_MUTEX_INITIALIZER;
-
-static gboolean test_process_func(gpointer data)
-{
- uint8_t i;
- int count = 0;
-
- while (nfcTestMatrix[count].testName != NULL){
- count ++;
- }
-
- for(i=0; i<count; i++)
- {
- PRINT_INFO("%d. %s START\n", i, nfcTestMatrix[i].testName);
-
- if(nfcTestMatrix[i].testFn !=NULL){
- nfcTestMatrix[i].testResult = nfcTestMatrix[i].testFn(i, NULL);
- //print_test_result (nfcTestMatrix[i].testName, nfcTestMatrix[i].testResult);
- }
- }
-
- return false;
-}
-
-int main()
-{
-
- GMainLoop* loop = NULL;
- loop = g_main_new(TRUE);
-
- g_timeout_add_seconds(1, test_process_func, NULL); // 1secs
- g_main_loop_run(loop);
-
- return 0;
-}
-
-void print_test_result (char * str, net_nfc_test_result_e result)
-{
- if (result == NET_NFC_TEST_OK){
- PRINT_RESULT_SUCCESS("TEST [%s] is PASSED",str);
- }
- else if (result == NET_NFC_TEST_FAIL){
- PRINT_RESULT_FAIL("TEST [%s] is FAILED",str);
- }
- else {
- PRINT_INFO("TEST is being tested\n");
- }
-}
-
-
-/*=================================================================================*/
-
-static net_nfc_test_result_e test_case_result;
-
-static void net_nfc_test_read_write_cb(net_nfc_message_e message, net_nfc_error_e result, void* data, void* user_param, void * trans_data );
-static void net_nfc_test_static_handover_cb(net_nfc_message_e message, net_nfc_error_e result, void* data, void* user_param, void * trans_data);
-
-static void net_nfc_test_client_cb(net_nfc_message_e message, net_nfc_error_e result, void* data, void* user_param, void * trans_data )
-{
- // do nothing
-}
-
-int nfcTestClientInit(uint8_t testNumber,void* arg_ptr2)
-{
- net_nfc_error_e result;
- result = net_nfc_initialize();
- CHECK_RESULT(result);
-
-
- result = net_nfc_set_response_callback (net_nfc_test_client_cb, NULL);
- CHECK_RESULT(result);
-
- result = net_nfc_unset_response_callback ();
- CHECK_RESULT(result);
-
- result = net_nfc_deinitialize ();
- CHECK_RESULT(result);
-
- return NET_NFC_TEST_OK;
-}
-
-
-net_nfc_exchanger_data_h net_nfc_exchanger_callback(net_nfc_exchanger_event_e event, void * user_param)
-{
- PRINT_INFO(" event = [%d] \n", event);
- test_case_result = NET_NFC_TEST_OK;
-
- switch(event)
- {
- case NET_NFC_EXCHANGER_DATA_REQUESTED:
- {
- PRINT_INFO("exchange is requested");
- net_nfc_exchanger_data_h ex_data = NULL;
- net_nfc_error_e error = NET_NFC_OK;
- data_h payload = NULL;
-
-/*
- uint8_t buffer[1024] = {0};
-
- int i = 0;
- for(; i< 1024; i++){
- buffer[i] = 'a';
- }
-
- net_nfc_create_data(&payload, buffer, 1024);
-*/
-
- if((error = net_nfc_create_exchanger_data(&ex_data, payload/*(uint8_t *)"http://www.samsung.com"*/)) == NET_NFC_OK)
- //if((error = net_nfc_create_exchanger_url_type_data(&ex_data, NET_NFC_SCHEMA_FULL_URI, (uint8_t *)"file://test.txt")) == NET_NFC_OK)
- //if((error = net_nfc_create_exchanger_raw_type_data(&ex_data, "text/plain", payload)) == NET_NFC_OK)
- {
- return ex_data;
- }
- else
- {
- PRINT_INFO("create exchanger data is failed = [%d]", error);
- //pthread_cond_signal (&pcond);
- return NULL;
- }
- }
- case NET_NFC_EXCHANGER_TRANSFER_FAILED:
- case NET_NFC_EXCHANGER_TRANSFER_COMPLETED:
- default:
- {
- //pthread_cond_signal (&pcond);
-
- if(event == NET_NFC_EXCHANGER_TRANSFER_COMPLETED)
- {
- PRINT_INFO("transfer exchanger msg is completed");
- }
- else
- {
- PRINT_INFO("transfer exchanger msg is failed");
- }
-
- return NULL;
- }
- }
-
-}
-
-/*=================================================================================*/
-static void net_nfc_test_reader_cb(net_nfc_message_e message, net_nfc_error_e result, void* data, void* user_param, void * trans_data)
-{
- //int user_context;
-
- PRINT_INFO("user_param = [%p] trans_param = [%p]", user_param, trans_data);
-
- switch(message)
- {
- case NET_NFC_MESSAGE_TAG_DISCOVERED:{
- net_nfc_target_type_e type;
- net_nfc_target_handle_h id;
- bool is_ndef;
- net_nfc_target_info_h target_info = (net_nfc_target_info_h)data;
-
- net_nfc_get_tag_type (target_info, &type);
- net_nfc_get_tag_handle(target_info, &id);
- net_nfc_get_tag_ndef_support (target_info, &is_ndef);
- PRINT_INFO("target type: %d\n", type);
- PRINT_INFO("target id: %p\n", id);
- PRINT_INFO("Is NDEF supoort: %d\n", is_ndef);
-
- if (is_ndef){
- uint32_t actual_size;
- uint32_t max_size;
- net_nfc_get_tag_actual_data_size (target_info, &actual_size);
- net_nfc_get_tag_max_data_size (target_info ,&max_size);
- PRINT_INFO("\tmax data [%d]\tactual data [%d]\n", max_size,actual_size );
- net_nfc_read_tag (id, (void *)2);
- }
- else{
- PRINT_INSTRUCT("Please use NDEF formated tag!!");
- test_case_result = NET_NFC_TEST_FAIL;
- }
- break;
- }
- case NET_NFC_MESSAGE_READ_NDEF:{
- if(data != NULL){
- ndef_message_h ndef = (ndef_message_h)(data);
- data_h rawdata;
- net_nfc_create_rawdata_from_ndef_message (ndef ,&rawdata);
- PRINT_INFO("read ndef message is ok, length is [%d]", net_nfc_get_data_length(rawdata));
- net_nfc_free_data(rawdata);
- //_//net_nfc_ndef_print_message (ndef);
- /*
-
- if (memcmp(net_nfc_get_data_buffer (rawdata),nfcTestSpHex, net_nfc_get_data_length (rawdata)) == 0){
- test_case_result = NET_NFC_TEST_OK;
- }
- */
- }
- pthread_mutex_lock (&plock);
- pthread_cond_signal (&pcond);
- pthread_mutex_unlock (&plock);
- break;
- }
- default:
- break;
- }
-}
-
-
-static void net_nfc_test_format_cb(net_nfc_message_e message, net_nfc_error_e result, void* data, void* user_param, void * trans_data)
-{
- //int user_context;
-
- PRINT_INFO("user_param = [%p] trans_param = [%p]", user_param, trans_data);
-
- switch(message)
- {
- case NET_NFC_MESSAGE_TAG_DISCOVERED:{
-
- PRINT_INFO("NET_NFC_MESSAGE_TAG_DISCOVERED");
-
- net_nfc_target_type_e type;
- net_nfc_target_handle_h id;
- bool is_ndef;
- net_nfc_target_info_h target_info = (net_nfc_target_info_h)data;
-
- net_nfc_get_tag_type (target_info, &type);
- net_nfc_get_tag_handle(target_info, &id);
- net_nfc_get_tag_ndef_support (target_info, &is_ndef);
- PRINT_INFO("target type: %d\n", type);
- PRINT_INFO("target id: %p\n", id);
- PRINT_INFO("Is NDEF supoort: %d\n", is_ndef);
-
- data_h ndef_key = NULL;
- net_nfc_mifare_create_net_nfc_forum_key(&ndef_key);
- net_nfc_format_ndef(id, ndef_key, NULL);
- net_nfc_free_data(ndef_key);
-
- }
- break;
-
- case NET_NFC_MESSAGE_FORMAT_NDEF:{
- PRINT_INFO("NET_NFC_MESSAGE_FORMAT_NDEF");
- PRINT_INFO("result = [%d]", result);
- }
- break;
- case NET_NFC_MESSAGE_TAG_DETACHED:
- {
- PRINT_INFO("NET_NFC_MESSAGE_TAG_DETACHED");
- }
- break;
- default:
- break;
- }
-}
-
-static void net_nfc_test_se_cb(net_nfc_message_e message, net_nfc_error_e result, void* data, void* user_param, void * trans_data)
-{
- switch(message)
- {
- case NET_NFC_MESSAGE_GET_SE :
- {
- PRINT_INFO("NET_NFC_MESSAGE_GET_SE result = [%d] se type = [%d]", result, *((uint8_t *)data));
- //net_nfc_set_secure_element_type(NET_NFC_SE_TYPE_ESE, NULL);
- net_nfc_set_secure_element_type(NET_NFC_SE_TYPE_UICC, NULL);
- }
- break;
- case NET_NFC_MESSAGE_SET_SE :
- {
- PRINT_INFO("NET_NFC_MESSAGE_SET_SE result = [%d] se type = [%d]", result, *((uint8_t *)data));
- net_nfc_open_internal_secure_element(NET_NFC_SE_TYPE_ESE, NULL);
- //net_nfc_open_internal_secure_element(NET_NFC_SE_TYPE_UICC, NULL);
- }
- break;
- case NET_NFC_MESSAGE_OPEN_INTERNAL_SE :
- {
- PRINT_INFO("NET_NFC_MESSAGE_OPEN_INTERNAL_SE result = [%p] and handle = [%p]", result, data);
- data_h apdu = NULL;
- uint8_t apdu_cmd[4] = {0x00, 0xA4, 0x00, 0x0C} ; // CLA 0-> use default channel and no secure message. 0xA4 -> select instruction
- net_nfc_create_data(&apdu, apdu_cmd, 4);
- net_nfc_send_apdu((net_nfc_target_handle_h)(data), apdu, data);
- net_nfc_free_data(apdu);
-
- }
- break;
- case NET_NFC_MESSAGE_SEND_APDU_SE:
- {
- PRINT_INFO("NET_NFC_MESSAGE_SEND_APDU_SE result = [%d]", result);
-
- if(data != NULL)
- {
- uint8_t * r_buffer = net_nfc_get_data_buffer (data);
- uint32_t r_buffer_length = net_nfc_get_data_length (data);
-
- PRINT_INFO ("Received data [size:%d] \n", net_nfc_get_data_length (data));
-
- int idx = 0;
- for (idx = 0; idx < r_buffer_length; idx++){
- printf (" %02X", r_buffer[idx]);
- }printf ("\n");
- }
-
- net_nfc_close_internal_secure_element((net_nfc_target_handle_h)trans_data, NULL);
- }
- break;
- case NET_NFC_MESSAGE_CLOSE_INTERNAL_SE :
- {
-
- PRINT_INFO("NET_NFC_MESSAGE_CLOSE_INTERNAL_SE result = [%d]", result);
- }
- break;
- default:
- break;
- }
-
- PRINT_INFO("user_param = [%p] trans_param = [%p]", user_param, trans_data);
-}
-
-/*=================================================================================*/
-static void net_nfc_test_static_handover_cb(net_nfc_message_e message, net_nfc_error_e result, void* data, void* user_param, void * trans_data)
-{
- //int user_context;
- switch(message)
- {
- case NET_NFC_MESSAGE_TAG_DISCOVERED:{
- net_nfc_target_type_e type;
- net_nfc_target_handle_h id;
- bool is_ndef;
- net_nfc_target_info_h target_info = (net_nfc_target_info_h)data;
- net_nfc_carrier_config_h config;
- ndef_record_h record;
-
- net_nfc_get_tag_type (target_info, &type);
- net_nfc_get_tag_handle(target_info, &id);
- net_nfc_get_tag_ndef_support (target_info, &is_ndef);
- PRINT_INFO("target type: %d\n", type);
- PRINT_INFO("target id: %p\n", id);
- PRINT_INFO("Is NDEF supoort: %d\n", is_ndef);
-
- if (is_ndef){
-
- ndef_message_h ndef = NULL;
- data_h bt_config = NULL;
- net_nfc_create_data_only(&bt_config);
-
- // 2byte :: OOB length, 6byte :: bt addr
- uint8_t temp[8] = {0x00, 0x08, 0x00, 0x02, 0x78, 0xDD, 0xC4, 0x8A};
- net_nfc_create_carrier_config (&config,NET_NFC_CONN_HANDOVER_CARRIER_BT );
- net_nfc_add_carrier_config_property (config ,NET_NFC_BT_ATTRIBUTE_ADDRESS ,8 ,temp);
- net_nfc_create_ndef_record_with_carrier_config (&record, config);
- net_nfc_create_handover_select_message (&ndef);
- net_nfc_append_carrier_config_record (ndef,record,NET_NFC_CONN_HANDOVER_CARRIER_ACTIVATE);
- net_nfc_write_ndef(id, ndef, NULL);
- net_nfc_free_record(record);
- net_nfc_free_data(bt_config);
- net_nfc_free_carrier_config(config);
-
- }
- else{
- PRINT_INSTRUCT("Please use NDEF formated tag!!");
- test_case_result = NET_NFC_TEST_FAIL;
- }
- break;
- }
- case NET_NFC_MESSAGE_WRITE_NDEF:{
-
- if(result == NET_NFC_OK){
- PRINT_INFO("write ndef message is ok");
- test_case_result = NET_NFC_TEST_OK;
- }
-
- pthread_mutex_lock (&plock);
- pthread_cond_signal (&pcond);
- pthread_mutex_unlock (&plock);
- break;
- }
- default:
- break;
- }
-}
-
-int nfcConnHandover(uint8_t testNumber,void* arg_ptr2)
-{
- //int user_context = 0;
- net_nfc_error_e result;
-#if 1
- test_case_result = NET_NFC_TEST_FAIL;
-
- result = net_nfc_initialize();
-
- net_nfc_state_activate();
-
- CHECK_RESULT(result);
- result = net_nfc_set_response_callback (net_nfc_test_static_handover_cb, NULL);
- CHECK_RESULT(result);
-
- PRINT_INSTRUCT("Please close a tag to device!!");
-
- //pthread_cond_wait (&pcond,&plock );
- /*
- PRINT_INFO("operation is end");
-
- result = net_nfc_unset_response_callback ();
-
- CHECK_RESULT(result);
- result = net_nfc_deinitialize ();
- CHECK_RESULT(result);
- */
-#else
-
-/*
- ndef_message_h ndef = NULL;
-
- if(net_nfc_retrieve_current_ndef_message(&ndef) == NET_NFC_OK){
- PRINT_INFO("retrieve is ok");
- }
- else{
- PRINT_INFO("retrieve is failed");
- return NET_NFC_TEST_FAIL;
- }
-*/
- ndef_message_h ndef = NULL;
- data_h bt_config = NULL;
- net_nfc_create_data_only(&bt_config);
-
- // 2byte :: OOB length, 6byte :: bt addr
- uint8_t temp[8] = {0x00, 0x08, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05};
-
- net_nfc_set_data(bt_config, temp, 8);
- net_nfc_create_static_connection_handover_select_message(&ndef, bt_config, NULL);
-
- net_nfc_conn_handover_info_h handover_info = NULL;
-
- if(net_nfc_parse_connection_handover_ndef_message(ndef, &handover_info) == NET_NFC_OK){
- PRINT_INFO("parsing is ok");
-
- uint8_t version = 0;
-
- if((result = net_nfc_get_connection_handover_version(handover_info, &version)) == NET_NFC_OK){
- PRINT_INFO("version = [%d]", version);
- }
- else{
- PRINT_INFO("get version is failed = [%d]", result);
- }
-
-
- unsigned short random_number = 0;
- if((result = net_nfc_get_connection_handover_random_number(handover_info, &random_number)) == NET_NFC_OK)
- {
- PRINT_INFO("random_number = [%d]", random_number);
- }
- else
- {
- PRINT_INFO("get random_number is failed = [%d]", result);
- }
-
- data_h record_type = NULL;
- net_nfc_get_connection_handover_record_type(handover_info, &record_type);
- PRINT_INFO("record type = [%c] [%c]", (net_nfc_get_data_buffer(record_type))[0], (net_nfc_get_data_buffer(record_type))[1]);
-
- uint8_t carrier_count = 0;
- net_nfc_get_connection_handover_alternative_carrier_count(handover_info, &carrier_count);
-
- int i = 0;
- for(; i < carrier_count; i++)
- {
- net_nfc_conn_handover_carrier_info_h carrier_info = NULL;
- net_nfc_get_connection_handover_carrier_handle_by_index(handover_info, i, &carrier_info);
-
- if(carrier_info != NULL){
- net_nfc_conn_handover_carrier_type_e carrier_type = 0;
- net_nfc_get_carrier_type(carrier_info, &carrier_type);
-
- if(carrier_type == NET_NFC_CONN_HANDOVER_CARRIER_BT)
- {
- PRINT_INFO("carrier is BT");
- }
- else if(carrier_type == NET_NFC_CONN_HANDOVER_CARRIER_WIFI)
- {
- PRINT_INFO("carrier is WIFI");
- }
- else
- {
- PRINT_INFO("carrier is unknown");
- }
-
- data_h id = NULL;
- net_nfc_get_carrier_id(carrier_info, &id);
-
- PRINT_INFO("id = [0x%x]", (net_nfc_get_data_buffer(id))[0]);
-
- net_nfc_conn_handover_carrier_state_e carrier_state = 0;
- net_nfc_get_carrier_power_state(carrier_info, &carrier_state);
-
- PRINT_INFO("cps is = [0x%x]", carrier_state);
-
- data_h config = NULL;
- if((result = net_nfc_get_carrier_configuration(carrier_info, &config)) == NET_NFC_OK)
- {
- PRINT_INFO("good to get config");
- }
- else
- {
- PRINT_INFO("failed to get config = [%d]", result);
- }
-
- uint8_t* buffer = NULL;
- if((buffer = net_nfc_get_data_buffer(config)) != NULL)
- {
- unsigned short size = ( buffer[0] << 8 ) |buffer[1];
- PRINT_INFO("size is = [%d]", size);
-
- if(size == 8)
- {
- PRINT_INFO("carrier addr is [0x%x]", buffer[2]);
- PRINT_INFO("carrier addr is [0x%x]", buffer[3]);
- PRINT_INFO("carrier addr is [0x%x]", buffer[4]);
- PRINT_INFO("carrier addr is [0x%x]", buffer[5]);
- PRINT_INFO("carrier addr is [0x%x]", buffer[6]);
- PRINT_INFO("carrier addr is [0x%x]", buffer[7]);
- }
- else
- {
- PRINT_INFO("more data -_-;; ");
- }
- }
- else
- {
- PRINT_INFO("failed to buffer");
- }
- }
-
- }
- }
- else{
-
- PRINT_INFO("parsing is failed");
-
- return NET_NFC_TEST_FAIL;
- }
-
-
- if(handover_info != NULL){
- if((net_nfc_free_connection_handover_info(handover_info)) == NET_NFC_OK){
- PRINT_INFO("free is good");
- }
- else{
- PRINT_INFO("free is failed");
- }
- }
-#endif
-
- return test_case_result;
-}
-
-int nfcTestFormatNdef(uint8_t testNumber,void* arg_ptr2)
-{
- PRINT_INFO("%s is start", __func__);
-
- //int user_context = 0;
- net_nfc_error_e result;
- test_case_result = NET_NFC_TEST_FAIL;
-
- result = net_nfc_initialize();
-
- net_nfc_state_activate();
-
- CHECK_RESULT(result);
- result = net_nfc_set_response_callback (net_nfc_test_format_cb, (void *)1);
- CHECK_RESULT(result);
-
- PRINT_INSTRUCT("Please close a tag to device!!");
-
- //pthread_cond_wait (&pcond,&plock );
-
-/*
- PRINT_INFO("operation is end");
-
- result = net_nfc_unset_response_callback ();
-
- CHECK_RESULT(result);
- result = net_nfc_deinitialize ();
- CHECK_RESULT(result);
-
-*/
-
- return test_case_result;
-}
-
-int nfcTestInternalSe(uint8_t testNumber,void* arg_ptr2)
-{
- PRINT_INFO("%s is start", __func__);
-
- int user_context = 0;
- net_nfc_error_e result;
- test_case_result = NET_NFC_TEST_FAIL;
-
- result = net_nfc_initialize();
-
- net_nfc_state_activate();
-
- CHECK_RESULT(result);
- result = net_nfc_set_response_callback (net_nfc_test_se_cb, (void *)1);
- CHECK_RESULT(result);
-
- net_nfc_get_secure_element_type(NULL);
-
- PRINT_INSTRUCT("Please close a tag to device!!");
-
- return test_case_result;
-}
-
-
-
-int nfcTestReaderMode(uint8_t testNumber,void* arg_ptr2)
-{
- PRINT_INFO("%s is start", __func__);
-
- //int user_context = 0;
- net_nfc_error_e result;
- test_case_result = NET_NFC_TEST_FAIL;
-
- result = net_nfc_initialize();
-
- net_nfc_state_activate();
-
- CHECK_RESULT(result);
- result = net_nfc_set_response_callback (net_nfc_test_reader_cb, (void *)1);
- CHECK_RESULT(result);
-
- PRINT_INSTRUCT("Please close a tag to device!!");
-
- //pthread_cond_wait (&pcond,&plock );
-
-/*
- PRINT_INFO("operation is end");
-
- result = net_nfc_unset_response_callback ();
-
- CHECK_RESULT(result);
- result = net_nfc_deinitialize ();
- CHECK_RESULT(result);
-
-*/
-
- return test_case_result;
-}
-
-
-/*=================================================================================*/
-
-static void net_nfc_test_write_cb(net_nfc_message_e message, net_nfc_error_e result, void* data, void* user_param, void * trans_data)
-{
- int user_context;
-
- switch(message)
- {
- case NET_NFC_MESSAGE_TAG_DISCOVERED:{
- net_nfc_target_type_e type;
- net_nfc_target_handle_h handle;
- bool is_ndef;
- net_nfc_target_info_h target_info = (net_nfc_target_info_h)data;
-
- net_nfc_get_tag_type (target_info, &type);
- net_nfc_get_tag_handle (target_info, &handle);
- net_nfc_get_tag_ndef_support (target_info, &is_ndef);
- PRINT_INFO("target type: %d\n", type);
- PRINT_INFO("target id: %p\n", handle);
- PRINT_INFO("Is NDEF supoort: %d\n", is_ndef);
-
- tag_handle = handle;
-
- if (is_ndef){
-
- net_nfc_error_e error = NET_NFC_OK;
- ndef_message_h msg = NULL;
- ndef_record_h record = NULL;
-
- if( (error = net_nfc_create_uri_type_record(&record, "http://www.naver.com", NET_NFC_SCHEMA_FULL_URI)) == NET_NFC_OK)
- {
- if( (error = net_nfc_create_ndef_message(&msg)) == NET_NFC_OK)
- {
- if( (error = net_nfc_append_record_to_ndef_message(msg, record)) == NET_NFC_OK)
- {
- ////net_nfc_ndef_print_message(msg);
- net_nfc_write_ndef(tag_handle, msg, &user_context);
- net_nfc_free_ndef_message(msg);
- }
- else
- {
- PRINT_INFO("failed to append ndef message = [%d]", error);
- net_nfc_free_record(record);
- net_nfc_free_ndef_message(msg);
-
- pthread_mutex_lock (&plock);
- pthread_cond_signal (&pcond);
- pthread_mutex_unlock (&plock);
- }
- }
- else
- {
- PRINT_INFO("failed to create ndef msg");
- net_nfc_free_record(record);
-
- pthread_mutex_lock (&plock);
- pthread_cond_signal (&pcond);
- pthread_mutex_unlock (&plock);
- }
- }
- else
- {
- PRINT_INFO("failed to create text type record");
-
- pthread_mutex_lock (&plock);
- pthread_cond_signal (&pcond);
- pthread_mutex_unlock (&plock);
- }
- }
- else{
- PRINT_INSTRUCT("Please use NDEF formated tag!!");
- break;
- }
-
- break;
- }
- case NET_NFC_MESSAGE_TAG_DETACHED:
- {
- if (write_count++ >= 20) {
- test_case_result = NET_NFC_TEST_OK;
- pthread_mutex_lock (&plock);
- pthread_cond_signal (&pcond);
- pthread_mutex_unlock (&plock);
- }
- else {
- PRINT_INSTRUCT("Please close a tag to device again!!");
- }
- }
- break;
-
- case NET_NFC_MESSAGE_WRITE_NDEF:
- {
- /*if (result == NET_NFC_OK) {
- test_case_result = NET_NFC_TEST_OK;
- }
- else {
- PRINT_INFO("received error: %d\n", result);
- test_case_result = NET_NFC_TEST_FAIL;
- }
- */
-
- /* pthread_mutex_lock (&plock);
- pthread_cond_signal (&pcond);
- pthread_mutex_unlock (&plock);
- */
-
- if(write_count++ == 20)
- {
-
- PRINT_INSTRUCT("completed, please remove tag");
- }
-
- {
-
- net_nfc_error_e error = NET_NFC_OK;
- ndef_message_h msg = NULL;
- ndef_record_h record = NULL;
-
- if( (error = net_nfc_create_text_type_record(&record, "This is real NFC", "en-US", NET_NFC_ENCODE_UTF_8)) == NET_NFC_OK)
- {
- if( (error = net_nfc_create_ndef_message(&msg)) == NET_NFC_OK)
- {
- if( (error = net_nfc_append_record_to_ndef_message(msg, record)) == NET_NFC_OK)
- {
- ////net_nfc_ndef_print_message(msg);
- net_nfc_write_ndef(tag_handle, msg, &user_context);
- net_nfc_free_ndef_message(msg);
- }
- else
- {
- PRINT_INFO("failed to append ndef message = [%d]", error);
- net_nfc_free_record(record);
- net_nfc_free_ndef_message(msg);
- test_case_result = NET_NFC_TEST_FAIL;
-
- pthread_mutex_lock (&plock);
- pthread_cond_signal (&pcond);
- pthread_mutex_unlock (&plock);
- }
- }
- else
- {
- PRINT_INFO("failed to create ndef msg");
- net_nfc_free_record(record);
- test_case_result = NET_NFC_TEST_FAIL;
-
- pthread_mutex_lock (&plock);
- pthread_cond_signal (&pcond);
- pthread_mutex_unlock (&plock);
- }
- }
- else
- {
- PRINT_INFO("failed to create text type record");
- test_case_result = NET_NFC_TEST_FAIL;
-
- pthread_mutex_lock (&plock);
- pthread_cond_signal (&pcond);
- pthread_mutex_unlock (&plock);
-
- }
- }
-
- break;
- }
- default:
- break;
- }
-}
-
-
-int nfcTestWriteMode(uint8_t testNumber,void* arg_ptr2)
-{
- //int user_context = 0;
- net_nfc_error_e result;
- test_case_result = NET_NFC_TEST_FAIL;
-
- result = net_nfc_initialize();
- CHECK_RESULT(result);
-
- net_nfc_state_activate();
-
- result = net_nfc_set_response_callback (net_nfc_test_write_cb, NULL);
- CHECK_RESULT(result);
-
- write_count = 0;
- PRINT_INSTRUCT("TEST: remove tag while write");
- PRINT_INSTRUCT("Please close a tag to device!!");
-
- //pthread_cond_wait (&pcond,&plock );
-
-/*
- result = net_nfc_unset_response_callback ();
- CHECK_RESULT(result);
- result = net_nfc_deinitialize ();
- CHECK_RESULT(result);
-*/
- return test_case_result;
-
-}
-
-
-int nfcTestReadWriteMode(uint8_t testNumber,void* arg_ptr2)
-{
- //int user_context = 0;
- net_nfc_error_e result;
- test_case_result = NET_NFC_TEST_FAIL;
-
- read_count = 0;
- write_count = 0;
-
- result = net_nfc_initialize();
- CHECK_RESULT(result);
-
- net_nfc_state_activate();
-
- result = net_nfc_set_response_callback (net_nfc_test_read_write_cb, NULL);
- CHECK_RESULT(result);
-
- PRINT_INSTRUCT("Testing (50 each) read and write test");
- PRINT_INSTRUCT("Please close a tag to device!!");
-
- //pthread_cond_wait (&pcond,&plock );
-/*
- result = net_nfc_unset_response_callback ();
- CHECK_RESULT(result);
- result = net_nfc_deinitialize ();
- CHECK_RESULT(result);
-*/
-
-
- return test_case_result;
-
-}
-
-/*=================================================================================*/
-
-static void net_nfc_test_transceive_cb(net_nfc_message_e message, net_nfc_error_e result, void* data, void* user_param, void * trans_data)
-{
- //int user_context;
-
- printf ("callback is called with message %d\n", message);
- switch(message)
- {
- case NET_NFC_MESSAGE_TAG_DISCOVERED:{
- net_nfc_target_type_e type;
- net_nfc_target_handle_h id;
- bool is_ndef;
- net_nfc_target_info_h target_info = (net_nfc_target_info_h)data;
- net_nfc_error_e result = NET_NFC_OK;
-
- net_nfc_get_tag_type (target_info, &type);
- net_nfc_get_tag_handle (target_info, &id);
- net_nfc_get_tag_ndef_support (target_info, &is_ndef);
- PRINT_INFO("target type: %d\n", type);
- PRINT_INFO("target id: %p\n", id);
- PRINT_INFO("Is NDEF supoort: %d\n", is_ndef);
-
- tag_handle = id;
-
- if(type == NET_NFC_MIFARE_ULTRA_PICC){
-
- if((result = net_nfc_mifare_read(tag_handle, 0, NULL)) != NET_NFC_OK){
- PRINT_INFO("failed to read = [%d]", result);
- }
- }
-
- else if(type >= NET_NFC_MIFARE_MINI_PICC && type <= NET_NFC_MIFARE_4K_PICC){
-
- data_h mad_key = NULL;
- data_h net_nfc_forum_key = NULL;
- data_h default_key = NULL;
-
- net_nfc_mifare_create_application_directory_key(&mad_key);
- net_nfc_mifare_create_net_nfc_forum_key(&net_nfc_forum_key);
- net_nfc_mifare_create_default_key(&default_key);
-
- int sector = 1;
-
- data_h key = NULL;
- test_count = 4;
-
- if(sector == 0){
- key = mad_key;
- }
- else{
- key = default_key;
-// key = net_nfc_forum_key;
- }
-
-// if(net_nfc_mifare_authenticate_with_keyB(id, sector, key, NULL) != NET_NFC_OK){
- if(net_nfc_mifare_authenticate_with_keyA(id, sector, default_key, NULL) != NET_NFC_OK){
- PRINT_INFO("failed to authenticate sector");
-
- }
- else{
-
- int nBlocks = 0;
-
-// if(type == NET_NFC_MIFARE_4K_PICC && sector > 31){
-//
-// nBlocks = 16;
-// }
-// else{
-// nBlocks = 4;
-// }
-
- nBlocks = 4;
-
-
-/*
- int j = 0;
-
- for(; j < nBlocks; j++){
- if((result = net_nfc_mifare_read(tag_handle, sector * 4 + j, NULL)) != NET_NFC_OK){
- PRINT_INFO("failed to read = [%d]", result);
- }else{
- PRINT_INFO("block [%d] is read", sector * 4 + j);
- }
- }
-*/
-/*
- data_h write_block = NULL;
- uint8_t buffer[16] = {0x00,};
- uint8_t* temp = buffer;
-
- int value = 1000;
- int value_comp = 1 + ~value;
- uint8_t addr = 5;
- uint8_t addr_comp = 1 + ~addr;
-
-
- // read block 5 and write block 5 and read again
- if((result = net_nfc_mifare_read(tag_handle, addr, NULL)) != NET_NFC_OK){
- PRINT_INFO("failed to read = [%d]", result);
- }else{
- PRINT_INFO("block 5 is read");
- }
-
- // read block 5 and write block 5 and read again
-
- memcpy(temp, &value, sizeof(int));
- temp = temp + sizeof(int);
-
- memcpy(temp, &value_comp, sizeof(int));
- temp = temp + sizeof(int);
-
- memcpy(temp, &value, sizeof(int));
- temp = temp + sizeof(int);
-
- *temp = addr;
- temp = temp + 1;
-
- *temp = addr_comp;
- temp = temp + 1;
-
- *temp = addr;
- temp = temp + 1;
-
- *temp = addr_comp;
-
- net_nfc_create_data(&write_block, buffer, 16);
-
- if((result = net_nfc_mifare_write_block(tag_handle, addr, write_block,NULL)) != NET_NFC_OK){
- PRINT_INFO("failed to write = [%d]", result);
- }else{
- PRINT_INFO("block 5 is written");
- }
-
- if((result = net_nfc_mifare_read(tag_handle, addr, NULL)) != NET_NFC_OK){
- PRINT_INFO("failed to read = [%d]", result);
- }else{
- PRINT_INFO("block 5 is read");
- }
-*/
-
- // read block 6 and decrease 6 and read again
-
-/*
- if((result = net_nfc_mifare_read(tag_handle, 7, NULL)) != NET_NFC_OK){
- PRINT_INFO("failed to read = [%d]", result);
- }else{
- PRINT_INFO("read sector trailor of sector 1. it will be a block 7 th");
- }
-*/
-
-/*
- data_h write_block = NULL;
- uint8_t buffer[16] = {0x00, 0x00, 0x03, 0xE8, 0xFF, 0xFF, 0xFC, 0x18, 0x00, 0x00, 0x03, 0xE8, 0x05, 0xFB, 0x05, 0xFB};
-
- net_nfc_create_data(&write_block, buffer, 16);
-
- if((result = net_nfc_mifare_write_block(tag_handle, 5, write_block, NULL)) != NET_NFC_OK){
- PRINT_INFO("failed to write = [%d]", result);
- }else{
- PRINT_INFO("block 5 is written");
- }
-
-
- if((result = net_nfc_mifare_read(tag_handle, 5, NULL)) != NET_NFC_OK){
- PRINT_INFO("failed to read = [%d]", result);
- }else{
- PRINT_INFO("block 5 is read");
- }
-*/
-
-
- if((result = net_nfc_mifare_read(tag_handle, 5, NULL)) != NET_NFC_OK){
- PRINT_INFO("failed to read = [%d]", result);
- }
-
-
- int decrease_amount = 10; // 10 won
-
- if((result = net_nfc_mifare_decrement(tag_handle, 5, decrease_amount, NULL)) != NET_NFC_OK){
- PRINT_INFO("failed to decrease = [%d]", result);
- }else{
- PRINT_INFO("block 5 is decreased");
- }
-
- if((result = net_nfc_mifare_transfer(tag_handle, 5, NULL)) != NET_NFC_OK){
- PRINT_INFO("failed to transfer = [%d]", result);
- }else{
- PRINT_INFO("internal register is transfered to block 5");
- }
-
-/*
- if((result = net_nfc_mifare_read(tag_handle, 5, NULL)) != NET_NFC_OK){
- PRINT_INFO("failed to read = [%d]", result);
- }
-*/
-
-
- }
- net_nfc_free_data(key);
- net_nfc_free_data(default_key);
- net_nfc_free_data(mad_key);
- net_nfc_free_data(net_nfc_forum_key);
-
- }
- else if(type == NET_NFC_JEWEL_PICC){
-
- if(net_nfc_jewel_read_id(id, NULL) != NET_NFC_OK){
- PRINT_INFO("failed to read ID");
- }
-
- test_count = 0;
-
- }else if(type == NET_NFC_FELICA_PICC){
-
- test_count = 4;
- net_nfc_error_e result = NET_NFC_OK;
-
-/*
- if((result = net_nfc_felica_poll(id, NET_NFC_FELICA_POLL_COMM_SPEED_REQUEST, 0x0, NULL)) != NET_NFC_OK){
- PRINT_INFO("can not execute cmd felica poll");
- }
- else{
- PRINT_INFO("send poll req cmd is success");
- }
-
- if((result = net_nfc_felica_request_system_code(id, NULL)) != NET_NFC_OK){
- PRINT_INFO("can not execute cmd felica request system code");
- }
- else{
- PRINT_INFO("send request system req cmd is success");
- }
-
- if((result = net_nfc_felica_request_response(id, NULL)) != NET_NFC_OK){
- PRINT_INFO("can not execute cmd felica request response");
- }
- else{
- PRINT_INFO("send request response cmd is success");
- }
-
- uint16_t service_code = 0xffff;
- if((result = net_nfc_felica_request_service(id, 1, &service_code, 1, NULL)) != NET_NFC_OK){
- PRINT_INFO("can not execute cmd felica request response");
- }
- else{
- PRINT_INFO("send request response cmd is success");
- }
-*/
-
- uint16_t service_code = 0xffff;
- uint8_t blocks = 0x2;
-
- if((result = net_nfc_felica_read_without_encryption(id, 1, &service_code, 1, &blocks, NULL)) != NET_NFC_OK){
- PRINT_INFO("can not execute cmd felica request response");
- }
- else{
- PRINT_INFO("send request response cmd is success");
- }
- }
-
- break;
- }
- case NET_NFC_MESSAGE_TRANSCEIVE:{
- if (result == NET_NFC_OK) {
-
- if(test_count == 0){
- int idx;
- data_h r_data = (data_h) data;
-
- uint8_t * r_buffer = net_nfc_get_data_buffer (r_data);
- uint32_t r_buffer_length = net_nfc_get_data_length (r_data);
-
- PRINT_INFO ("read uid is ok. format is = > [HeadRom0][HeadRom1][UID0][UID1][UID2][UID3]");
- PRINT_INFO ("Received data [size:%d] \n", net_nfc_get_data_length (r_data));
-
- for (idx = 0; idx < r_buffer_length; idx++){
- printf (" %02X", r_buffer[idx]);
- }printf ("\n");
-
- PRINT_INFO("READ ALL DATA");
- if((result = net_nfc_jewel_read_all(tag_handle, NULL)) != NET_NFC_OK){
- PRINT_INFO("failed to read all jewel tag = [%d]", result);
- }
-
- test_count = 1;
- }
- else if(test_count == 1){
- int idx;
- data_h r_data = (data_h) data;
-
- uint8_t * r_buffer = net_nfc_get_data_buffer (r_data);
- uint32_t r_buffer_length = net_nfc_get_data_length (r_data);
-
- PRINT_INFO ("Received data [size:%d] \n", net_nfc_get_data_length (r_data));
-
- for (idx = 0; idx < r_buffer_length; idx++){
- printf (" %02X", r_buffer[idx]);
- }printf ("\n");
-
- test_case_result = NET_NFC_TEST_OK;
-
- // read UID0
-
- PRINT_INFO("READ one byte. addr is the first byte of block 0");
- if((result = net_nfc_jewel_read_byte(tag_handle, 0, 0, NULL)) != NET_NFC_OK){
- PRINT_INFO("failed to read all jewel tag = [%d]", result);
- }
-
- test_count = 2;
-
- }
- else if(test_count == 2){
- int idx;
- data_h r_data = (data_h) data;
-
- uint8_t * r_buffer = net_nfc_get_data_buffer (r_data);
- uint32_t r_buffer_length = net_nfc_get_data_length (r_data);
-
- PRINT_INFO ("Received data [size:%d] \n", net_nfc_get_data_length (r_data));
-
- for (idx = 0; idx < r_buffer_length; idx++){
- printf (" %02X", r_buffer[idx]);
- }printf ("\n");
-
- test_case_result = NET_NFC_TEST_OK;
-
- // read UID0
- PRINT_INFO("erase and write data 0xff . addr is the first byte of block 1");
- if((result = net_nfc_jewel_write_with_erase(tag_handle, 1, 0, 0xff, NULL)) != NET_NFC_OK){
- PRINT_INFO("failed to read all jewel tag = [%d]", result);
- }
-
- test_count = 3;
- }
- else if(test_count == 3){
- int idx;
- data_h r_data = (data_h) data;
-
- uint8_t * r_buffer = net_nfc_get_data_buffer (r_data);
- uint32_t r_buffer_length = net_nfc_get_data_length (r_data);
-
- PRINT_INFO ("Received data [size:%d] \n", net_nfc_get_data_length (r_data));
-
- for (idx = 0; idx < r_buffer_length; idx++){
- printf (" %02X", r_buffer[idx]);
- }printf ("\n");
-
- test_case_result = NET_NFC_TEST_OK;
-
- // read UID0
- PRINT_INFO("read one byte . addr is the first byte of block 1");
- if((result = net_nfc_jewel_read_byte(tag_handle, 1, 0, NULL)) != NET_NFC_OK){
- PRINT_INFO("failed to read all jewel tag = [%d]", result);
- }
-
- test_count = 4;
- }
- else if(test_count == 4){
-
- int idx;
- data_h r_data = (data_h) data;
-
- uint8_t * r_buffer = net_nfc_get_data_buffer (r_data);
- uint32_t r_buffer_length = net_nfc_get_data_length (r_data);
-
- PRINT_INFO ("Received data [size:%d] \n", net_nfc_get_data_length (r_data));
-
- for (idx = 0; idx < r_buffer_length; idx++){
- printf (" %02X", r_buffer[idx]);
- }printf ("\n");
- }
- else if(test_count == 5){
- PRINT_INFO("auth key A is success = [%d]", result);
- test_case_result = NET_NFC_TEST_OK;
- //net_nfc_error_e result = NET_NFC_OK;
- /*
- if((result = net_nfc_mifare_read(tag_handle, 0, NULL)) != NET_NFC_OK){
-
- PRINT_INFO("failed to read = [%d]", result);
- }else{
- PRINT_INFO("calling read is ok");
- }
-
- test_count = 4;
- */
- }
- }
- else {
-
- PRINT_INFO("trancecive is failed with %d\n", result);
- test_case_result = NET_NFC_TEST_FAIL;
-
- //pthread_mutex_lock (&plock);
- //pthread_cond_signal (&pcond);
- //pthread_mutex_unlock (&plock);
- }
- }
-
- default:
- break;
- }
-}
-
-
-#define NUM_OF_THREAD 10
-#define REQUEST_PER_THREAD 5
-
-static int number_of_read_completed = 0;
-
-static void* net_nfc_read_ndef_test(void* handle)
-{
- net_nfc_target_handle_h target_handle = (net_nfc_target_handle_h)handle;
- int count = 0;
-
- for (count = 0; count < REQUEST_PER_THREAD ; count ++)
- {
- if(net_nfc_read_tag(target_handle, NULL) == NET_NFC_OK)
- {
- PRINT_INFO("send request is success");
- }
- else
- {
- PRINT_INFO("send request is failed");
- }
- }
-
- return (void *)NULL;
-}
-static void net_nfc_test_multiple_request_cb(net_nfc_message_e message, net_nfc_error_e result, void* data, void* user_param, void * trans_data)
-{
- //int user_context;
-
- printf ("callback is called with message %d\n", message);
-
- switch(message)
- {
- case NET_NFC_MESSAGE_TAG_DISCOVERED:
- {
- net_nfc_target_type_e type;
- net_nfc_target_handle_h handle;
- bool is_ndef;
- net_nfc_target_info_h target_info = (net_nfc_target_info_h)data;
-
- net_nfc_get_tag_type (target_info, &type);
- net_nfc_get_tag_handle (target_info, &handle);
- net_nfc_get_tag_ndef_support (target_info, &is_ndef);
- PRINT_INFO("target type: %d\n", type);
- PRINT_INFO("target handle: %p\n", handle);
- PRINT_INFO("Is NDEF supoort: %d\n", is_ndef);
-
- test_case_result = NET_NFC_TEST_OK;
- number_of_read_completed = 0;
-
- pthread_t read_thread[NUM_OF_THREAD];
- pthread_attr_t attr;
- pthread_attr_init(&attr);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
-
- int i =0;
- for(; i < NUM_OF_THREAD; i++)
- {
- pthread_create(&read_thread[i], &attr, net_nfc_read_ndef_test, handle);
- }
-
- }
- break;
-
- case NET_NFC_MESSAGE_READ_NDEF:
- {
- PRINT_INFO("NET_NFC_MESSAGE_READ_NDEF result = [%d]\n", result);
-
- if(data != NULL)
- {
- PRINT_INFO("read ndef msg");
- number_of_read_completed ++;
-
- //ndef_message_h ndef = (ndef_message_h)(data);
-
- ////net_nfc_ndef_print_message(ndef);
-
- if (number_of_read_completed == NUM_OF_THREAD * REQUEST_PER_THREAD)
- {
- test_case_result = NET_NFC_TEST_OK;
- PRINT_INSTRUCT("Test is completed. please remove the tag !!");
- }
- }
- }
- break;
-
- case NET_NFC_MESSAGE_TAG_DETACHED:
- {
- PRINT_INFO("NET_NFC_MESSAGE_TAG_DETACHED \n");
-
- pthread_mutex_lock (&plock);
- pthread_cond_signal (&pcond);
- pthread_mutex_unlock (&plock);
- }
- break;
-
- case NET_NFC_MESSAGE_NOTIFY:
- {
- PRINT_INFO("NET_NFC_MESSAGE_NOTIFY \n");
- }
- break;
-
- default:
- break;
- }
-}
-
-#define NUM_OF_DETECT_TRY 10
-
-static void net_nfc_test_detected_cb(net_nfc_message_e message, net_nfc_error_e result, void* data, void* user_param, void * trans_data)
-{
- //int user_context;
-
- printf ("callback is called with message %d\n", message);
-
- switch(message)
- {
- case NET_NFC_MESSAGE_TAG_DISCOVERED:
- {
- net_nfc_target_type_e type;
- net_nfc_target_handle_h id;
- bool is_ndef;
- net_nfc_target_info_h target_info = (net_nfc_target_info_h)data;
-
- net_nfc_get_tag_type (target_info, &type);
- net_nfc_get_tag_handle (target_info, &id);
- net_nfc_get_tag_ndef_support (target_info, &is_ndef);
-
- PRINT_INFO("target type: %d\n", type);
- PRINT_INFO("target handle: %p\n", id);
- PRINT_INFO("Is NDEF supoort: %d\n", is_ndef);
-
- char** keys = NULL;
- int nok = 0; // number of keys
- net_nfc_error_e error = NET_NFC_OK;
-
- if((error = net_nfc_get_tag_info_keys(target_info, &keys, &nok)) == NET_NFC_OK)
- {
- int i = 0;
- for(; i < nok; i++)
- {
- PRINT_INFO("key [%s]", keys[i]);
-
- data_h value = NULL;
- if((error = net_nfc_get_tag_info_value(target_info, keys[i], &value)) == NET_NFC_OK)
- {
- int index = 0;
- uint32_t data_length = net_nfc_get_data_length(value);
- uint8_t* data_buffer = net_nfc_get_data_buffer(value);
-
- PRINT_INFO("\n key [%s] >> ", keys[i]);
- if(data_length > 1)
- {
- for(; index < data_length; index++)
- {
- printf(" [0x%x] ", data_buffer[index]);
- }
- }
- else
- {
- printf(" [0x%x] ", *data_buffer);
- }
-
-
- PRINT_INFO("<< \n");
- }
- else
- {
- PRINT_INFO("get value is failed = [0x%x]", error);
- }
- }
- }
- else
- {
- PRINT_INFO("failed to get keys = [%d]", error);
- }
-
- free(keys);
-
-
- detect_count++;
-
- PRINT_INFO("TAG is detected = [%d]", detect_count);
- PRINT_INSTRUCT("please remove the tag !! Test left [%d] times", NUM_OF_DETECT_TRY - detect_count);
-
- }
- break;
-
- case NET_NFC_MESSAGE_TAG_DETACHED:
- {
- PRINT_INSTRUCT("please close the tag again!!");
-
- //pthread_mutex_lock (&plock);
- //pthread_cond_signal (&pcond);
- //pthread_mutex_unlock (&plock);
-
- if(detect_count >= NUM_OF_DETECT_TRY)
- {
- test_case_result = NET_NFC_TEST_OK;
- pthread_mutex_lock (&plock);
- pthread_cond_signal (&pcond);
- pthread_mutex_unlock (&plock);
- }
- }
- break;
-
- case NET_NFC_MESSAGE_NOTIFY:
- {
- PRINT_INFO("NET_NFC_MESSAGE_NOTIFY \n");
- }
- break;
-
- default:
- break;
- }
-}
-
-
-static void* net_nfc_read_stress_ndef_test(void* handle)
-{
- net_nfc_target_handle_h target_handle = (net_nfc_target_handle_h)handle;
- int count = 0;
-
- for (count = 0; count < 200 ; count ++)
- {
- if(net_nfc_read_tag(target_handle, NULL) == NET_NFC_OK)
- {
- }
- else
- {
- PRINT_INFO("send request is failed");
- }
- }
-
- PRINT_INFO("send request is completed");
-
- return (void *)NULL;
-}
-
-static void net_nfc_test_read_cb(net_nfc_message_e message, net_nfc_error_e result, void* data, void* user_param, void * trans_data)
-{
- //int user_context;
-
- switch(message)
- {
- case NET_NFC_MESSAGE_TAG_DISCOVERED:
- {
- net_nfc_target_type_e type;
- net_nfc_target_handle_h handle;
- bool is_ndef;
- net_nfc_target_info_h target_info = (net_nfc_target_info_h)data;
-
- net_nfc_get_tag_type (target_info, &type);
- net_nfc_get_tag_handle (target_info, &handle);
- net_nfc_get_tag_ndef_support (target_info, &is_ndef);
- PRINT_INFO("target type: %d\n", type);
- PRINT_INFO("target handle: %p\n", handle);
- PRINT_INFO("Is NDEF supoort: %d\n", is_ndef);
-
- if(is_ndef)
- {
- pthread_t read_thread;
- pthread_attr_t attr;
- pthread_attr_init(&attr);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
-
- pthread_create(&read_thread, &attr, net_nfc_read_stress_ndef_test, handle);
- }
- else
- {
- PRINT_INFO("non ndef tag.");
-
- test_case_result = NET_NFC_TEST_FAIL;
-
- pthread_mutex_lock (&plock);
- pthread_cond_signal (&pcond);
- pthread_mutex_unlock (&plock);
- }
-
- }
- break;
-
- case NET_NFC_MESSAGE_READ_NDEF:
- {
- if(data != NULL){
-
- //ndef_message_h ndef = (ndef_message_h)(data);
-
- ////net_nfc_ndef_print_message(ndef);
-
- test_case_result = NET_NFC_TEST_OK;
-
- read_count++;
- }
-
- if(read_count == 20)
- {
- PRINT_INSTRUCT("please remove the tag !!");
- }
-
- break;
- }
- break;
-
- case NET_NFC_MESSAGE_TAG_DETACHED:
- {
- PRINT_INFO("NET_NFC_MESSAGE_TAG_DETACHED \n");
-
- if (read_count >= 20 && read_count < 200){
- test_case_result = NET_NFC_TEST_OK;
- pthread_mutex_lock (&plock);
- pthread_cond_signal (&pcond);
- pthread_mutex_unlock (&plock);
- }
- else {
- PRINT_INSTRUCT("please close the tag again !!");
- }
-
-
- }
- break;
-
- case NET_NFC_MESSAGE_NOTIFY:
- {
- PRINT_INFO("NET_NFC_MESSAGE_NOTIFY \n");
- }
- break;
-
- default:
- break;
- }
-}
-
-
-static void net_nfc_test_read_write_cb(net_nfc_message_e message, net_nfc_error_e result, void* data, void* user_param, void * trans_data)
-{
- int user_context;
-
- printf ("callback is called with message %d\n", message);
-
- switch(message)
- {
- case NET_NFC_MESSAGE_TAG_DISCOVERED:
- {
- net_nfc_target_type_e type;
- net_nfc_target_handle_h handle;
- bool is_ndef;
- net_nfc_target_info_h target_info = (net_nfc_target_info_h)data;
-
- net_nfc_get_tag_type (target_info, &type);
- net_nfc_get_tag_handle (target_info, &handle);
- net_nfc_get_tag_ndef_support (target_info, &is_ndef);
- PRINT_INFO("target type: %d\n", type);
- PRINT_INFO("target handle: %p\n", handle);
- PRINT_INFO("Is NDEF supoort: %d\n", is_ndef);
-
- if(is_ndef)
- {
- tag_handle = handle;
- if(net_nfc_read_tag(handle, user_param) == NET_NFC_OK)
- {
- PRINT_INFO("try to read ndef");
- }
- }
- else
- {
- PRINT_INFO("non ndef tag.");
-
- test_case_result = NET_NFC_TEST_FAIL;
-
- pthread_mutex_lock (&plock);
- pthread_cond_signal (&pcond);
- pthread_mutex_unlock (&plock);
- }
-
- }
- break;
-
- case NET_NFC_MESSAGE_READ_NDEF:
- {
- if (write_count >= 50){
- PRINT_INSTRUCT("Test is finished. Please remove the tag from device!!");
- test_case_result = NET_NFC_TEST_OK;
- break;
- }
- if(data != NULL){
-
- //ndef_message_h ndef = (ndef_message_h)(data);
-
- ////net_nfc_ndef_print_message(ndef);
-
- test_case_result = NET_NFC_TEST_OK;
-
- net_nfc_error_e error = NET_NFC_OK;
- ndef_message_h msg = NULL;
- ndef_record_h record = NULL;
-
- if( (error = net_nfc_create_text_type_record(&record, "This is real NFC", "en-US", NET_NFC_ENCODE_UTF_8)) == NET_NFC_OK)
- {
- if( (error = net_nfc_create_ndef_message(&msg)) == NET_NFC_OK)
- {
- if( (error = net_nfc_append_record_to_ndef_message(msg, record)) == NET_NFC_OK)
- {
- ////net_nfc_ndef_print_message(msg);
-
- if(net_nfc_write_ndef(tag_handle, msg, &user_context) == NET_NFC_OK)
- {
- PRINT_INFO("write count = [%d] \n", write_count++);
- PRINT_INFO("write ndef msg");
- }
- net_nfc_free_ndef_message(msg);
- }
- else
- {
- PRINT_INFO("failed to append ndef message = [%d]", error);
- net_nfc_free_record(record);
- net_nfc_free_ndef_message(msg);
-
- pthread_mutex_lock (&plock);
- pthread_cond_signal (&pcond);
- pthread_mutex_unlock (&plock);
- }
- }
- else
- {
- PRINT_INFO("failed to create ndef msg");
- net_nfc_free_record(record);
-
- pthread_mutex_lock (&plock);
- pthread_cond_signal (&pcond);
- pthread_mutex_unlock (&plock);
- }
- }
- else
- {
- PRINT_INFO("failed to create text type record");
-
- pthread_mutex_lock (&plock);
- pthread_cond_signal (&pcond);
- pthread_mutex_unlock (&plock);
-
- }
-
- }
- else
- {
- test_case_result = NET_NFC_TEST_FAIL;
-
- pthread_mutex_lock (&plock);
- pthread_cond_signal (&pcond);
- pthread_mutex_unlock (&plock);
-
- break;
- }
-
- //net_nfc_read_ndef(tag_handle, user_param);
-
- break;
- }
- break;
-
- case NET_NFC_MESSAGE_WRITE_NDEF:
- {
- if (result == NET_NFC_OK) {
-
- test_case_result = NET_NFC_TEST_OK;
-
- if(net_nfc_read_tag(tag_handle, user_param) == NET_NFC_OK)
- {
- PRINT_INFO("read count = [%d] \n", read_count++);
- PRINT_INFO("try to read ndef");
- }
- }
- else {
- PRINT_INFO("received error: %d\n", result);
- test_case_result = NET_NFC_TEST_FAIL;
-
- pthread_mutex_lock (&plock);
- pthread_cond_signal (&pcond);
- pthread_mutex_unlock (&plock);
- }
- }
- break;
-
- case NET_NFC_MESSAGE_TAG_DETACHED:
- {
- PRINT_INFO("NET_NFC_MESSAGE_TAG_DETACHED \n");
-
- pthread_mutex_lock (&plock);
- pthread_cond_signal (&pcond);
- pthread_mutex_unlock (&plock);
- }
- break;
-
- case NET_NFC_MESSAGE_NOTIFY:
- {
- PRINT_INFO("NET_NFC_MESSAGE_NOTIFY \n");
- }
- break;
-
- default:
- break;
- }
-}
-
-
-int nfcTestAPIMultipleRequest(uint8_t testNumber,void* arg_ptr2)
-{
- //int user_context = 0;
- net_nfc_error_e result;
- test_case_result = NET_NFC_TEST_FAIL;
-
- result = net_nfc_initialize();
- CHECK_RESULT(result);
-
- net_nfc_state_activate();
-
- result = net_nfc_set_response_callback (net_nfc_test_multiple_request_cb, NULL);
- CHECK_RESULT(result);
-
- PRINT_INSTRUCT("Please close a tag to device for a while!!");
-
- //pthread_cond_wait (&pcond,&plock );
-/*
- result = net_nfc_unset_response_callback ();
- CHECK_RESULT(result);
-
- result = net_nfc_deinitialize ();
- CHECK_RESULT(result);
-*/
- return test_case_result;
-}
-
-
-int nfcTestAPIBasicTest1(uint8_t testNumber,void* arg_ptr2)
-{
- //int user_context = 0;
- net_nfc_error_e result;
- test_case_result = NET_NFC_TEST_FAIL;
-
- //int length = 0;
-
-/*
- char** keys = NULL;
-
- int i = 0;
-
- for(i; i < NET_NFC_NFCIP1_INITIATOR; i++)
- {
- if(net_nfc_get_tag_info_keys(i, &keys, &length) == NET_NFC_OK)
- {
- int index = 0;
-
- PRINT_INFO("############################\n") ;
- for(; index < length; index++)
- {
- PRINT_INFO("supported key = [%s] \n", keys[index]);
- }
- PRINT_INFO("############################\n") ;
-
- test_case_result = NET_NFC_TEST_OK;
- }
- }
-*/
-
- result = net_nfc_initialize();
- CHECK_RESULT(result);
-
- net_nfc_state_activate();
-
- result = net_nfc_set_response_callback (net_nfc_test_detected_cb, NULL);
-
-// net_nfc_set_tag_filter(NET_NFC_ALL_DISABLE);
-// net_nfc_set_tag_filter(NET_NFC_ISO14443A_ENABLE);
-// net_nfc_set_tag_filter(NET_NFC_ISO14443B_ENABLE);
-// net_nfc_set_tag_filter(NET_NFC_ISO15693_ENABLE );
-// net_nfc_set_tag_filter(NET_NFC_FELICA_ENABLE );
-// net_nfc_set_tag_filter(NET_NFC_JEWEL_ENABLE );
-// net_nfc_set_tag_filter(NET_NFC_ALL_ENABLE );
-
-
- CHECK_RESULT(result);
-
- //PRINT_INSTRUCT("Please close a tag to device!!");
-
- //pthread_cond_wait (&pcond,&plock );
-
-/*
- result = net_nfc_unset_response_callback ();
- CHECK_RESULT(result);
-
- result = net_nfc_deinitialize ();
-
- sleep(1000);
-
- CHECK_RESULT(result);
-*/
-
- return test_case_result;
-}
-
-int nfcTestAPIBasicTest2(uint8_t testNumber,void* arg_ptr2)
-{
- //int user_context = 0;
- net_nfc_error_e result;
- test_case_result = NET_NFC_TEST_FAIL;
-
- result = net_nfc_initialize();
- CHECK_RESULT(result);
-
- net_nfc_state_activate();
-
- read_count = 0;
-
- result = net_nfc_set_response_callback (net_nfc_test_read_cb, NULL);
- CHECK_RESULT(result);
-
- PRINT_INSTRUCT("remove tag while reading operation !!");
- PRINT_INSTRUCT("Please close a tag to device!!");
-
-/*
- pthread_cond_wait (&pcond,&plock );
-
- result = net_nfc_unset_response_callback ();
- CHECK_RESULT(result);
-
- result = net_nfc_deinitialize ();
- CHECK_RESULT(result);
-*/
- return test_case_result;
-}
-
-int nfcTestAPIBasicTest3(uint8_t testNumber,void* arg_ptr2)
-{
- //int user_context = 0;
- //net_nfc_error_e result;
- test_case_result = NET_NFC_TEST_FAIL;
-
- ndef_message_h ndef_message = NULL;
-
- if(net_nfc_retrieve_current_ndef_message(&ndef_message) == NET_NFC_OK)
- {
- int count = 0;
- if(net_nfc_get_ndef_message_record_count(ndef_message, &count) == NET_NFC_OK)
- {
- int i = 0;
- for(; i < count; i++)
- {
- ndef_record_h record = NULL;
- if(net_nfc_get_record_by_index(ndef_message, i, &record) == NET_NFC_OK)
- {
- net_nfc_record_tnf_e tnf;
- if(net_nfc_get_record_tnf(record, &tnf) == NET_NFC_OK)
- {
- switch(tnf)
- {
- case NET_NFC_RECORD_WELL_KNOWN_TYPE:
- {
- data_h type = NULL;
- data_h payload = NULL;
-
- if(net_nfc_get_record_type(record, &type) == NET_NFC_OK && net_nfc_get_record_payload(record, &payload) == NET_NFC_OK)
- {
- if(strcmp((char*)net_nfc_get_data_buffer(type), "Sp") == 0)
- {
-
- }
- else if(strcmp((char*)net_nfc_get_data_buffer(type), "T") == 0)
- {
-
- net_nfc_encode_type_e utf;
- //uint32_t utf_length = 0;
- //uint32_t lang_length = 0;
- char* text = NULL;
- //uint32_t text_length = 0;
- char* language_code_str = NULL;
-
- if(net_nfc_get_encoding_type_from_text_record(record, &utf) == NET_NFC_OK)
- {
- PRINT_INFO("utf = [%d]", utf);
- }
- else
- {
- PRINT_INFO("failed to get utf");
- }
-
- if(net_nfc_get_languange_code_string_from_text_record(record, &language_code_str) == NET_NFC_OK)
- {
- PRINT_INFO("language_code = [%s]", language_code_str);
- }
- else
- {
- PRINT_INFO("failed to get language code");
- }
-
- if(net_nfc_create_text_string_from_text_record(record, &text) == NET_NFC_OK)
- {
- PRINT_INFO("text = [%s]", text);
- }
- else
- {
- PRINT_INFO("failed to get text");
- }
-
- if(text != NULL)
- free(text);
- if(language_code_str != NULL)
- free(language_code_str);
-/*
- uint8_t* utf = NULL;
- uint8_t* language_code = NULL;
- uint8_t* text = NULL;
- int index = 0;
-
- uint8_t* buffer = net_nfc_get_data_buffer(payload);
- uint32_t buffer_length = net_nfc_get_data_length(payload);
-
- PRINT_INFO("\n from file >>>");
-
- for(; index < buffer_length; index++)
- {
- printf(" [%d] ", buffer[index]);
- }
-
- PRINT_INFO("\n from file <<<");
-
- index = 0;
-
- int controllbyte = buffer[0];
-
- if((controllbyte & 0x80)== 1)
- {
- PRINT_INFO("UTF-16");
- utf = (uint8_t*)"UTF-16";
- }
- else
- {
- PRINT_INFO("UTF-8");
- utf = (uint8_t*)"UTF-8";
- }
-
- int lang_code_length = controllbyte & 0x3F;
-
- index = 1;
-
- language_code = (uint8_t *)malloc(lang_code_length + 1);
-
- memset(language_code, 0x00, lang_code_length + 1);
- memcpy(language_code, &(buffer[index]), lang_code_length);
-
- PRINT_INFO("lang_code = [%s]", language_code);
-
- index = lang_code_length + 1;
-
- int text_length = buffer_length - (lang_code_length + 1); // payload length - (lang code length + control byte)
-
- PRINT_INFO("buffer length = [%d]", buffer_length);
- PRINT_INFO("lang_code_length = [%d]", lang_code_length);
- PRINT_INFO("text_length = [%d]", text_length);
-
- text = (uint8_t *)malloc(text_length + 1);
-
- memset(text, 0x00, text_length + 1);
- memcpy(text, &(buffer[index]), text_length);
-
- PRINT_INFO("encoding type = [%s]", utf);
- PRINT_INFO("lang_code = [%s]", language_code);
- PRINT_INFO("text = [%s]", text);
- test_case_result = NET_NFC_TEST_OK;
-*/
- }
- else if(strcmp((char*)net_nfc_get_data_buffer(type), "U") == 0)
- {
-
- }
- else
- {
-
- }
- }
-
- }
- break;
-
- default:
- PRINT_INFO("unknow type");
- break;
- }
- }
- }
- }
- }
- }
-
- net_nfc_free_ndef_message(ndef_message);
- //CHECK_RESULT(result);
-
- return test_case_result;
-}
-
-int nfcTestTransceive(uint8_t testNumber,void* arg_ptr2)
-{
- //int user_context = 0;
- net_nfc_error_e result;
- test_case_result = NET_NFC_TEST_FAIL;
-
- result = net_nfc_initialize();
- CHECK_RESULT(result);
-
- net_nfc_state_activate();
-
- result = net_nfc_set_response_callback (net_nfc_test_transceive_cb, NULL);
- CHECK_RESULT(result);
-
- PRINT_INSTRUCT("Please close a tag to device!!");
-
- //pthread_cond_wait (&pcond,&plock );
- /*
- result = net_nfc_unset_response_callback ();
- CHECK_RESULT(result);
- result = net_nfc_deinitialize ();
- CHECK_RESULT(result);
- */
-
- return test_case_result;
-}
-
-/*=================================================================================*/
-
-
-int nfcTestNdefParser(uint8_t testNumber,void* arg_ptr2)
-{
- net_nfc_error_e result;
-
- ndef_message_h uriMsg = NULL;
- ndef_message_h spMsg = NULL;
- ndef_record_h uriRecord = NULL;
- ndef_record_h spRecord = NULL;
- data_h type_data = NULL;
- data_h raw_data = NULL;
- char smart_poster_type[] = "Sp";
- ndef_record_h record = NULL;
- test_case_result = NET_NFC_TEST_OK;
-
- result = net_nfc_create_ndef_message (&uriMsg);
- CHECK_RESULT(result);
-
- result = net_nfc_create_uri_type_record (&record ,"http://www.naver.com", NET_NFC_SCHEMA_FULL_URI);
- CHECK_RESULT(result);
-
- result = net_nfc_append_record_to_ndef_message (uriMsg, record);
- CHECK_RESULT(result);
-
- uriRecord = record;
-
- result = net_nfc_create_text_type_record (&record ,"This is the URI Test" ,"en-US" ,NET_NFC_ENCODE_UTF_8);
- CHECK_RESULT(result);
-
- result = net_nfc_append_record_to_ndef_message (uriMsg, record);
- CHECK_RESULT(result);
-
- result = net_nfc_create_text_type_record (&record ,"Hello World" ,"en-US" ,NET_NFC_ENCODE_UTF_8);
- CHECK_RESULT(result);
-
- result = net_nfc_append_record_by_index (uriMsg,0 ,record);
- CHECK_RESULT(result);
-
- result = net_nfc_create_text_type_record (&record ,"TEST1" ,"en-US" ,NET_NFC_ENCODE_UTF_8);
- CHECK_RESULT(result);
-
- result = net_nfc_append_record_by_index (uriMsg,1 ,record);
- CHECK_RESULT(result);
-
- result = net_nfc_create_text_type_record (&record ,"TEST2" ,"en-US" ,NET_NFC_ENCODE_UTF_8);
- CHECK_RESULT(result);
-
- result = net_nfc_append_record_by_index (uriMsg,2 ,record);
- CHECK_RESULT(result);
-
- result = net_nfc_create_text_type_record (&record ,"TEST3" ,"en-US" ,NET_NFC_ENCODE_UTF_8);
- CHECK_RESULT(result);
-
- int position;
- result = net_nfc_get_ndef_message_record_count (uriMsg,&position);
- CHECK_RESULT(result);
-
- result = net_nfc_append_record_by_index (uriMsg, position ,record);
- CHECK_RESULT(result);
-
- //_//net_nfc_ndef_print_message (uriMsg);
-
- result = net_nfc_create_data (&type_data ,(uint8_t*)"U", 1);
- CHECK_RESULT(result);
-
- result = net_nfc_search_record_by_type (uriMsg ,NET_NFC_RECORD_WELL_KNOWN_TYPE ,type_data ,&record);
- CHECK_RESULT(result);
- if (record != uriRecord){
- PRINT_RESULT_FAIL("Record search result does not matched");
- return NET_NFC_TEST_FAIL;
- }
-
- result = net_nfc_remove_record_by_index (uriMsg ,1);
- CHECK_RESULT(result);
-
- result = net_nfc_remove_record_by_index (uriMsg ,0);
- CHECK_RESULT(result);
-
- result = net_nfc_get_ndef_message_record_count (uriMsg,&position);
- CHECK_RESULT(result);
-
- result = net_nfc_remove_record_by_index (uriMsg, position - 1);
- CHECK_RESULT(result);
-
- result = net_nfc_remove_record_by_index (uriMsg ,2);
- CHECK_RESULT(result);
-
- //_//net_nfc_ndef_print_message (uriMsg);
-
- result = net_nfc_create_rawdata_from_ndef_message (uriMsg, &raw_data);
- CHECK_RESULT(result);
-
- result = net_nfc_create_data (&type_data, (uint8_t*)smart_poster_type, strlen (smart_poster_type));
- if (result != NET_NFC_OK) {
- net_nfc_free_data(raw_data);
- net_nfc_free_data(type_data);
- net_nfc_free_ndef_message(uriMsg);
- }
- CHECK_RESULT(result);
-
- result = net_nfc_create_record (&spRecord, NET_NFC_RECORD_WELL_KNOWN_TYPE,type_data , NULL, raw_data);
- if (result != NET_NFC_OK) {
- net_nfc_free_data(raw_data);
- net_nfc_free_data(type_data);
- net_nfc_free_ndef_message(uriMsg);
- }
- CHECK_RESULT(result);
-
- result = net_nfc_create_ndef_message (&spMsg);
- CHECK_RESULT(result);
-
- result = net_nfc_append_record_to_ndef_message (spMsg, spRecord);
- CHECK_RESULT(result);
-
- net_nfc_free_data (type_data);
- net_nfc_free_data (raw_data);
- net_nfc_free_ndef_message(uriMsg);
-
- return test_case_result;
-}
-
-/*=================================================================================*/
-
-net_nfc_llcp_socket_t server_socket;
-net_nfc_llcp_socket_t accepted_socket;
-net_nfc_llcp_socket_t client_socket;
-
-static void net_nfc_client_socket_cb (net_nfc_llcp_message_e message, net_nfc_error_e result, void * data, void * user_data, void * trans_data)
-{
- PRINT_INFO ("\nCLIENT callback is called MESSAGE[%d]", message);
- //int x;
- switch (message)
- {
- case NET_NFC_MESSAGE_LLCP_LISTEN:
- break;
- case NET_NFC_MESSAGE_LLCP_ACCEPTED:
- break;
- case NET_NFC_MESSAGE_LLCP_CONNECT:
- {
- PRINT_INFO ("LLCP connect is completed with error code %d", result);
- data_h data;
- char * str = "Client message: Hello, server!";
- net_nfc_create_data (&data, (uint8_t*)str ,strlen (str) + 1);
- net_nfc_send_llcp (client_socket, data, NULL);
- net_nfc_free_data(data);
- }
- break;
- case NET_NFC_MESSAGE_LLCP_CONNECT_SAP:
- break;
- case NET_NFC_MESSAGE_LLCP_SEND:
- {
- PRINT_INFO ("LLCP send is completed with error code %d", result);
- net_nfc_receive_llcp (client_socket, 512 ,NULL);
- }
- break;
-
- case NET_NFC_MESSAGE_LLCP_RECEIVE:
- PRINT_INFO ("LLCP receive is completed with error code %d", result);
- data_h received_data = (data_h) data;
- PRINT_INFO ("Server --> Client : %s" , net_nfc_get_data_buffer (received_data));
-
- net_nfc_disconnect_llcp (client_socket ,NULL);
- break;
- case NET_NFC_MESSAGE_LLCP_DISCONNECT:
- {
- PRINT_INFO ("LLCP disconnect is completed with error code %d", result);
- net_nfc_close_llcp_socket (client_socket, NULL);
- }
- break;
- case NET_NFC_MESSAGE_LLCP_ERROR:
- PRINT_INFO ("LLCP socket error is completed with error code %d", result);
- net_nfc_close_llcp_socket (client_socket, NULL);
- break;
- default:
- break;
- }
-
-}
-
-
-static void net_nfc_server_socket_cb (net_nfc_llcp_message_e message, net_nfc_error_e result, void * data, void * user_data, void * trans_data)
-{
- PRINT_INFO ("\nSERVER callback is called MESSAGE[%d]", message);
- switch (message)
- {
- case NET_NFC_MESSAGE_LLCP_LISTEN:
- {
- PRINT_INFO ("LLCP Listen is completed with error code %d", result);
- }
- break;
-
- case NET_NFC_MESSAGE_LLCP_ACCEPTED:
- {
- PRINT_INFO ("LLCP accept is completed with error code %d", result);
- accepted_socket = *(net_nfc_llcp_socket_t *)(data);
- net_nfc_set_llcp_socket_callback (accepted_socket, net_nfc_server_socket_cb, NULL);
- net_nfc_receive_llcp (accepted_socket, 512 ,NULL);
- }
- break;
- case NET_NFC_MESSAGE_LLCP_CONNECT:
- break;
- case NET_NFC_MESSAGE_LLCP_CONNECT_SAP:
- break;
- case NET_NFC_MESSAGE_LLCP_SEND:
- {
- PRINT_INFO ("LLCP send is completed with error code %d", result);
- net_nfc_disconnect_llcp (accepted_socket ,NULL);
- }
- break;
-
- case NET_NFC_MESSAGE_LLCP_RECEIVE:
- {
- PRINT_INFO ("LLCP receive is completed with error code %d", result);
- data_h received_data = (data_h) data;
- PRINT_INFO ("Server <-- Client : %s" , net_nfc_get_data_buffer (received_data));
-
- data_h data;
- char * str = "Server message: Welcome NFC llcp world!";
- net_nfc_create_data (&data, (uint8_t*)str ,strlen (str) + 1);
- net_nfc_send_llcp (accepted_socket, data, NULL);
- net_nfc_free_data(data);
- }
- break;
-
- case NET_NFC_MESSAGE_LLCP_DISCONNECT:
- {
- PRINT_INFO ("LLCP disconnect is completed with error code %d", result);
- net_nfc_close_llcp_socket (accepted_socket, NULL);
- }
- break;
- case NET_NFC_MESSAGE_LLCP_ERROR:
- {
- PRINT_INFO ("LLCP socket error is received with code %d", result);
- net_nfc_close_llcp_socket (accepted_socket, NULL);
- net_nfc_close_llcp_socket (server_socket, NULL);
- }
- break;
- default:
- break;
- }
-}
-
-net_nfc_target_handle_h snep_handle;
-net_nfc_exchanger_data_h snep_ex_data = NULL;
-int temp_count;
-
-static void net_nfc_test_snep_cb(net_nfc_message_e message, net_nfc_error_e result, void* data, void* user_param, void * trans_data)
-{
- PRINT_INFO ("client message received [%d]", message);
-
- switch (message) {
-#if 0
- case NET_NFC_MESSAGE_P2P_DISCOVERED:
- {
- snep_handle = (net_nfc_target_handle_h) data;
- //= (net_nfc_target_handle_h) target_info->handle;
- /* Fill the data to send. */
-
- if(NET_NFC_OK == net_nfc_create_exchanger_data(&snep_ex_data, nfcTestUri))
- {
- if(net_nfc_send_exchanger_data(snep_ex_data, snep_handle) == NET_NFC_OK)
- {
- PRINT_INFO ("exchanger data send success");
- }
- else
- {
- PRINT_INFO ("exchanger data send fail");
- }
- }
- else
- {
- PRINT_INFO ("create exchanger data fail");
- }
-
- }
- break;
-#endif
- case NET_NFC_MESSAGE_P2P_SEND:
- {
- PRINT_INFO ("NET_NFC_MESSAGE_P2P_SEND result [%d]", result);
-
- }
- break;
-
- case NET_NFC_MESSAGE_P2P_DETACHED:
- {
- PRINT_INFO ("Target disconnected.");
- temp_count = 0;
- }
- break;
-
- case NET_NFC_MESSAGE_P2P_RECEIVE:
- {
-// int i;
-// data_h received_data = (data_h)data;
-
-// PRINT_INFO ("NET_NFC_MESSAGE_P2P_RECEIVE [%s]", net_nfc_get_data_buffer(received_data));
-// PRINT_INFO (" length [%d]", net_nfc_get_data_length(received_data));
- }
- break;
-
- default:
- break;
- }
-}
-
-static void net_nfc_test_llcp_cb(net_nfc_message_e message, net_nfc_error_e result, void* data, void* user_param, void * trans_data)
-{
- // do nothing
- switch (message) {
- case NET_NFC_MESSAGE_LLCP_DISCOVERED:
- {
- net_nfc_llcp_config_info_h config = (net_nfc_llcp_config_info_h) data;
- uint8_t lto, option;
- uint16_t wks, miu;
- net_nfc_get_llcp_configure_lto (config , <o);
- net_nfc_get_llcp_configure_wks (config , &wks);
- net_nfc_get_llcp_configure_miu (config , &miu);
- net_nfc_get_llcp_configure_option (config , &option);
-
- PRINT_INFO ("Remote Device llcp info:\n \tlto: %d, \twks: %d, \tmiu: %d, \toption: %d", lto, wks, miu, option);
-
- net_nfc_create_llcp_socket (&server_socket, NULL);
- net_nfc_set_llcp_socket_callback (server_socket, net_nfc_server_socket_cb, NULL);
- net_nfc_listen_llcp (server_socket, "urn:nfc:xsn:samsung.com:testllcp" ,16 ,NULL);
-
- net_nfc_create_llcp_socket (&client_socket, NULL);
- net_nfc_set_llcp_socket_callback (client_socket, net_nfc_client_socket_cb, NULL);
- net_nfc_connect_llcp (client_socket,"urn:nfc:xsn:samsung.com:testllcp",NULL);
- }
- break;
-
- case NET_NFC_MESSAGE_LLCP_CONFIG:
- {
- PRINT_INFO ("LLCP llcp local config is completed with error code %d", result);
- }
- break;
-
- case NET_NFC_MESSAGE_P2P_DETACHED:
- {
- PRINT_INFO ("LLCP NET_NFC_MESSAGE_P2P_DETACHED %d", result);
- }
- break;
-
- default:
- break;
- }
-}
-
-int nfcTestSnep(uint8_t testNumber,void* arg_ptr)
-{
- net_nfc_error_e result;
-
- result = net_nfc_initialize();
- CHECK_RESULT(result);
- net_nfc_state_activate ();
- result = net_nfc_set_response_callback (net_nfc_test_snep_cb, NULL);
-
- PRINT_INSTRUCT("START SNEP test !!");
- return NET_NFC_TEST_OK;
-}
-
-int nfcTestLLCP(uint8_t testNumber,void* arg_ptr2)
-{
- net_nfc_error_e result;
- net_nfc_llcp_config_info_h config;
- result = net_nfc_initialize();
- CHECK_RESULT(result);
- net_nfc_state_activate ();
- result = net_nfc_set_response_callback (net_nfc_test_llcp_cb, NULL);
- CHECK_RESULT(result);
- result = net_nfc_create_llcp_configure_default (&config);
- CHECK_RESULT(result);
- result = net_nfc_set_llcp_local_configure (config ,NULL);
-
- PRINT_INSTRUCT("Please start P2P communicate!!");
-
-/*
- pthread_cond_wait (&pcond,&plock );
-
- result = net_nfc_unset_response_callback ();
- CHECK_RESULT(result);
- result = net_nfc_deinitialize ();
- CHECK_RESULT(result);
-*/
- net_nfc_free_llcp_configure(config);
- return NET_NFC_TEST_OK;
-}
-
-/*=================================================================================*/
-
-/* LLCP Stress Test */
-
-net_nfc_llcp_socket_t server_socket;
-net_nfc_llcp_socket_t client_socket;
-
-static void net_nfc_client_stress_socket_cb (net_nfc_llcp_message_e message, net_nfc_error_e result, void * data, void * user_data, void * trans_data)
-{
- PRINT_INFO ("\nCLIENT callback is called MESSAGE[%d]", message);
- //int x;
- switch (message)
- {
- case NET_NFC_MESSAGE_LLCP_LISTEN:
- break;
- case NET_NFC_MESSAGE_LLCP_ACCEPTED:
- break;
- case NET_NFC_MESSAGE_LLCP_CONNECT:
- {
- PRINT_INFO ("LLCP connect is completed with error code %d", result);
- data_h data;
- char * str = "Client message: Hello, server!";
- net_nfc_create_data (&data, (uint8_t*)str ,strlen (str) + 1);
- net_nfc_send_llcp (client_socket, data, NULL);
- net_nfc_free_data(data);
- }
- break;
- case NET_NFC_MESSAGE_LLCP_CONNECT_SAP:
- break;
- case NET_NFC_MESSAGE_LLCP_SEND:
- {
- PRINT_INFO ("LLCP send is completed with error code %d", result);
- net_nfc_receive_llcp (client_socket, 512 ,NULL);
- }
- break;
-
- case NET_NFC_MESSAGE_LLCP_RECEIVE:
- PRINT_INFO ("LLCP receive is completed with error code %d", result);
- data_h received_data = (data_h) data;
- PRINT_INFO ("Server --> Client : %s" , net_nfc_get_data_buffer (received_data));
-
- net_nfc_disconnect_llcp (client_socket ,NULL);
- break;
- case NET_NFC_MESSAGE_LLCP_DISCONNECT:
- {
- PRINT_INFO ("LLCP disconnect is completed with error code %d", result);
- net_nfc_close_llcp_socket (client_socket, NULL);
- }
- break;
- case NET_NFC_MESSAGE_LLCP_ERROR:
- PRINT_INFO ("LLCP socket error is completed with error code %d", result);
- net_nfc_close_llcp_socket (client_socket, NULL);
- break;
- default:
- break;
- }
-
-}
-
-
-static void net_nfc_server_stress_socket_cb (net_nfc_llcp_message_e message, net_nfc_error_e result, void * data, void * user_data, void * trans_data)
-{
- PRINT_INFO ("\nSERVER callback is called MESSAGE[%d]", message);
- switch (message)
- {
- case NET_NFC_MESSAGE_LLCP_LISTEN:
- {
- PRINT_INFO ("LLCP Listen is completed with error code %d", result);
- }
- break;
-
- case NET_NFC_MESSAGE_LLCP_ACCEPTED:
- {
- PRINT_INFO ("LLCP accept is completed with error code %d", result);
- net_nfc_receive_llcp (server_socket, 512 ,NULL);
- }
- break;
- case NET_NFC_MESSAGE_LLCP_CONNECT:
- break;
- case NET_NFC_MESSAGE_LLCP_CONNECT_SAP:
- break;
- case NET_NFC_MESSAGE_LLCP_SEND:
- {
- PRINT_INFO ("LLCP send is completed with error code %d", result);
- net_nfc_disconnect_llcp (server_socket ,NULL);
- }
- break;
-
- case NET_NFC_MESSAGE_LLCP_RECEIVE:
- {
- PRINT_INFO ("LLCP receive is completed with error code %d", result);
- data_h received_data = (data_h) data;
- PRINT_INFO ("Server <-- Client : %s" , net_nfc_get_data_buffer (received_data));
-
- data_h data;
- char * str = "Server message: Welcome NFC llcp world!";
- net_nfc_create_data (&data, (uint8_t*)str ,strlen (str) + 1);
- net_nfc_send_llcp (server_socket, data, NULL);
- net_nfc_free_data(data);
- }
- break;
-
- case NET_NFC_MESSAGE_LLCP_DISCONNECT:
- {
- PRINT_INFO ("LLCP disconnect is completed with error code %d", result);
- net_nfc_close_llcp_socket (server_socket, NULL);
- }
- break;
-
- case NET_NFC_MESSAGE_LLCP_ERROR:
- {
- PRINT_INFO ("LLCP socket error is received with code %d", result);
- net_nfc_close_llcp_socket (server_socket, NULL);
- }
- break;
- default:
- break;
- }
-}
-
-static void net_nfc_test_llcp_stress_cb(net_nfc_message_e message, net_nfc_error_e result, void* data, void* user_param, void * trans_data)
-{
- // do nothing
- switch (message) {
- case NET_NFC_MESSAGE_LLCP_DISCOVERED:
- {
- net_nfc_llcp_config_info_h config = (net_nfc_llcp_config_info_h) data;
- uint8_t lto, option;
- uint16_t wks, miu;
- net_nfc_get_llcp_configure_lto (config , <o);
- net_nfc_get_llcp_configure_wks (config , &wks);
- net_nfc_get_llcp_configure_miu (config , &miu);
- net_nfc_get_llcp_configure_option (config , &option);
-
- PRINT_INFO ("Remote Device llcp info:\n \tlto: %d, \twks: %d, \tmiu: %d, \toption: %d", lto, wks, miu, option);
-
- net_nfc_create_llcp_socket (&server_socket, NULL);
- net_nfc_set_llcp_socket_callback (server_socket, net_nfc_server_stress_socket_cb, NULL);
- net_nfc_listen_llcp (server_socket, "urn:nfc:xsn:samsung.com:testllcp" ,16 ,NULL);
-
- net_nfc_create_llcp_socket (&client_socket, NULL);
- net_nfc_set_llcp_socket_callback (client_socket, net_nfc_client_stress_socket_cb, NULL);
- net_nfc_connect_llcp (client_socket,"urn:nfc:xsn:samsung.com:testllcp",NULL);
- }
- break;
-
- case NET_NFC_MESSAGE_LLCP_CONFIG:
- {
- PRINT_INFO ("LLCP llcp local config is completed with error code %d", result);
- }
- break;
-
- case NET_NFC_MESSAGE_P2P_DETACHED:
- {
- PRINT_INFO ("LLCP NET_NFC_MESSAGE_P2P_DETACHED %d", result);
- }
- break;
-
- default:
- break;
- }
-}
-
-int nfcTestStressLLCP(uint8_t testNumber,void* arg_ptr2)
-{
- net_nfc_error_e result;
- net_nfc_llcp_config_info_h config;
- result = net_nfc_initialize();
- CHECK_RESULT(result);
- net_nfc_state_activate ();
- result = net_nfc_set_response_callback (net_nfc_test_llcp_stress_cb, NULL);
- CHECK_RESULT(result);
- result = net_nfc_create_llcp_configure_default (&config);
- CHECK_RESULT(result);
- result = net_nfc_set_llcp_local_configure (config ,NULL);
-
- PRINT_INSTRUCT("Please start P2P communicate!!");
-/*
- pthread_cond_wait (&pcond,&plock );
-
- result = net_nfc_unset_response_callback ();
- CHECK_RESULT(result);
- result = net_nfc_deinitialize ();
- CHECK_RESULT(result);
-*/
- net_nfc_free_llcp_configure(config);
- return NET_NFC_TEST_OK;
-}
-
-/*=================================================================================*/
-
-
-static void net_nfc_test_API_exception_cb1(net_nfc_message_e message, net_nfc_error_e result, void* data, void* user_param, void * trans_data)
-{
- PRINT_INFO ("Message is received 1 %d", result);
- test_case_result = NET_NFC_TEST_FAIL;
- pthread_mutex_lock (&plock);
- pthread_cond_signal (&pcond);
- pthread_mutex_unlock (&plock);
-}
-
-static void net_nfc_test_API_exception_cb2(net_nfc_message_e message, net_nfc_error_e result, void* data, void* user_param, void * trans_data)
-{
- PRINT_INFO ("Message is received 2 %d", result);
- test_case_result = NET_NFC_TEST_FAIL;
- pthread_mutex_lock (&plock);
- pthread_cond_signal (&pcond);
- pthread_mutex_unlock (&plock);
-}
-
-static void net_nfc_test_API_exception_cb3(net_nfc_message_e message, net_nfc_error_e result, void* data, void* user_param, void * trans_data)
-{
- PRINT_INFO ("Message is received 3 %d", result);
- test_case_result = NET_NFC_TEST_OK;
- pthread_mutex_lock (&plock);
- pthread_cond_signal (&pcond);
- pthread_mutex_unlock (&plock);
-}
-
-
-
-
-int nfcTestAPIException (uint8_t testNumber,void* arg_ptr)
-{
- //net_nfc_error_e result;
- test_case_result = NET_NFC_TEST_FAIL;
-
- CHECK_ASSULT(net_nfc_initialize() == NET_NFC_OK);
- CHECK_ASSULT(net_nfc_initialize() == NET_NFC_ALREADY_INITIALIZED);
- CHECK_ASSULT(net_nfc_deinitialize () == NET_NFC_OK);
-
- int count_try = 0;
- for (count_try = 0; count_try < 20; count_try ++)
- {
- CHECK_ASSULT(net_nfc_initialize() == NET_NFC_OK);
- CHECK_ASSULT(net_nfc_deinitialize () == NET_NFC_OK);
- }
-
- CHECK_ASSULT(net_nfc_deinitialize () == NET_NFC_NOT_INITIALIZED);
- CHECK_ASSULT(net_nfc_deinitialize () == NET_NFC_NOT_INITIALIZED);
-
-
- CHECK_ASSULT(net_nfc_initialize() == NET_NFC_OK);
-
- CHECK_ASSULT (NET_NFC_OK == net_nfc_set_response_callback (net_nfc_test_API_exception_cb1, NULL));
- CHECK_ASSULT (NET_NFC_OK == net_nfc_set_response_callback (net_nfc_test_API_exception_cb2, NULL));
- CHECK_ASSULT (NET_NFC_OK == net_nfc_set_response_callback (net_nfc_test_API_exception_cb3, NULL));
- net_nfc_state_activate ();
-
- PRINT_INSTRUCT("Please close a tag to device!!");
-
- pthread_cond_wait (&pcond,&plock );
- if (!test_case_result) return test_case_result;
-
- PRINT_INSTRUCT("Please remove the tag from device!!");
- pthread_cond_wait (&pcond,&plock );
-
- CHECK_ASSULT (NET_NFC_OK == net_nfc_set_response_callback (net_nfc_test_API_exception_cb2, NULL));
- CHECK_ASSULT (NET_NFC_OK != net_nfc_set_response_callback (NULL, NULL));
-
- CHECK_ASSULT (NET_NFC_OK == net_nfc_set_response_callback (net_nfc_test_API_exception_cb2, NULL));
- CHECK_ASSULT (NET_NFC_OK == net_nfc_unset_response_callback ());
-
- PRINT_INSTRUCT("Please close a tag to device!! in 10 sec");
-
- int idx = 0;
- for (idx = 10 ;idx > 0 ; idx --)
- {
- PRINT_INSTRUCT("count down [%d]", idx);
- sleep (1);
- }
- if (!test_case_result) return test_case_result;
-
- PRINT_INSTRUCT("Please remove the tag from device!!");
- sleep (2);
-
- CHECK_ASSULT (NET_NFC_OK == net_nfc_set_response_callback (net_nfc_test_API_exception_cb3, NULL));
- net_nfc_state_activate ();
- net_nfc_state_activate ();
- net_nfc_state_activate ();
-
- PRINT_INSTRUCT("Please close a tag to device!!");
-
- pthread_cond_wait (&pcond,&plock );
- if (!test_case_result) return test_case_result;
- PRINT_INSTRUCT("Please remove the tag from device!!");
- pthread_cond_wait (&pcond,&plock );
-
- net_nfc_state_deactivate ();
- PRINT_INSTRUCT("Please close a tag to device!! in 10 sec");
-
- for (idx = 10 ;idx > 0 ; idx --)
- {
- PRINT_INSTRUCT("count down [%d]", idx);
- sleep (1);
- }
- if (!test_case_result) return test_case_result;
- PRINT_INSTRUCT("Please remove the tag from device!!");
- sleep (2);
-
- net_nfc_state_activate ();
- CHECK_ASSULT(net_nfc_deinitialize () == NET_NFC_OK);
-
- PRINT_INSTRUCT("Please close a tag to device!! in 10 sec");
-
-
- for (idx = 10 ;idx > 0 ; idx --)
- {
- PRINT_INSTRUCT("count down [%d]", idx);
- sleep (1);
- }
- if (!test_case_result) return test_case_result;
-
- PRINT_INSTRUCT("Please remove the tag from device!!");
- sleep (2);
-
- CHECK_ASSULT(net_nfc_initialize() == NET_NFC_OK);
- CHECK_ASSULT (NET_NFC_OK == net_nfc_set_response_callback (net_nfc_test_API_exception_cb3, NULL));
- net_nfc_state_activate ();
-
- PRINT_INSTRUCT("Please close a tag to device!!");
-
- pthread_cond_wait (&pcond,&plock );
- if (!test_case_result) return test_case_result;
-
- return NET_NFC_TEST_OK;
-}
-
-/*=================================================================================*/
-
-
-static void net_nfc_test_API_exception_tagAPI(net_nfc_message_e message, net_nfc_error_e result, void* data, void* user_param, void * trans_data)
-{
- PRINT_INFO ("Message is received 3 %d", result);
- test_case_result = NET_NFC_TEST_OK;
-
- switch(message)
- {
- case NET_NFC_MESSAGE_TAG_DISCOVERED:
- {
- switch (*(int*) user_param)
- {
- case 0: // transceive
- {
- net_nfc_target_type_e type;
- net_nfc_target_handle_h id;
- bool is_ndef;
- net_nfc_target_info_h target_info = (net_nfc_target_info_h)data;
- //net_nfc_error_e e_ret ;
-
- net_nfc_get_tag_type (target_info, &type);
- net_nfc_get_tag_handle (target_info, &id);
- net_nfc_get_tag_ndef_support (target_info, &is_ndef);
- PRINT_INFO("target type: %d\n", type);
- PRINT_INFO("target id: %p\n", id);
- PRINT_INFO("Is NDEF supoort: %d\n", is_ndef);
-
- net_nfc_deinitialize (); // Before calling transceive
-
- }
- break;
- case 1:
- {
- net_nfc_target_info_h target_info = (net_nfc_target_info_h)data;
- net_nfc_target_handle_h id;
- net_nfc_get_tag_handle (target_info, &id);
- net_nfc_deinitialize();
- if (NET_NFC_OK == net_nfc_read_tag (id ,NULL)){
- test_case_result = NET_NFC_TEST_FAIL;
- }
- }
- break;
- case 2:
- {
- net_nfc_target_info_h target_info = (net_nfc_target_info_h)data;
- net_nfc_target_handle_h id;
- ndef_message_h message = NULL;
- ndef_record_h record = NULL;
-
- net_nfc_get_tag_handle (target_info, &id);
- net_nfc_deinitialize();
-
- net_nfc_create_ndef_message (&message);
- net_nfc_create_text_type_record (&record, "abc" ,"en-US" ,NET_NFC_ENCODE_UTF_8);
- net_nfc_append_record_to_ndef_message (message ,record);
- if (NET_NFC_OK == net_nfc_write_ndef (id ,message ,NULL)){
- test_case_result = NET_NFC_TEST_FAIL;
- }
- net_nfc_free_ndef_message(message);
-
- }
- break;
- case 3:
- {
- net_nfc_target_info_h target_info = (net_nfc_target_info_h)data;
- net_nfc_target_handle_h id;
- data_h key;
- char data [] = {0xff,0xff,0xff,0xff,0xff,0xff};
- net_nfc_create_data (&key, (uint8_t*)data, 6);
- net_nfc_get_tag_handle (target_info, &id);
- net_nfc_deinitialize();
- if (NET_NFC_OK == net_nfc_format_ndef(id, key, NULL)){
- test_case_result = NET_NFC_TEST_FAIL;
- }
- net_nfc_free_data(key);
- }
- break;
- default:
- break;
- }
-
- pthread_mutex_lock (&plock);
- pthread_cond_signal (&pcond);
- pthread_mutex_unlock (&plock);
- }
- break;
- default:
- break;
- }
-}
-
-
-int nfcTestAPIException_tagAPI (uint8_t testNumber,void* arg_ptr)
-{
- int test_case = 0;
-
- /* Call API before initailize */
-
- data_h key;
- net_nfc_error_e result;
- uint8_t data [] = {0xff,0xff,0xff,0xff,0xff,0xff};
- net_nfc_create_data (&key, data, 6);
- result = net_nfc_format_ndef((net_nfc_target_handle_h) 0x302023, key, NULL);
- if(NET_NFC_OK == result){
- net_nfc_free_data(key);
- }
- CHECK_ASSULT (NET_NFC_OK != result);
- result = net_nfc_format_ndef(NULL, key, NULL);
- if((NET_NFC_NULL_PARAMETER != result)||(NET_NFC_OK == net_nfc_format_ndef((net_nfc_target_handle_h) 0x302023, NULL, NULL))||(NET_NFC_OK == net_nfc_read_tag ((net_nfc_target_handle_h) 0x302023 ,NULL))||(NET_NFC_NULL_PARAMETER != net_nfc_read_tag (NULL ,NULL))){
- net_nfc_free_data(key);
- }
- CHECK_ASSULT (NET_NFC_NULL_PARAMETER == result);
- CHECK_ASSULT (NET_NFC_OK != net_nfc_format_ndef((net_nfc_target_handle_h) 0x302023, NULL, NULL));
-
- CHECK_ASSULT (NET_NFC_OK != net_nfc_read_tag ((net_nfc_target_handle_h) 0x302023 ,NULL));
- CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_read_tag (NULL ,NULL));
- net_nfc_free_data(key);
-
- ndef_message_h message = NULL;
- ndef_record_h record = NULL;
- net_nfc_create_ndef_message (&message);
- net_nfc_create_text_type_record (&record, "abc" ,"en-US" ,NET_NFC_ENCODE_UTF_8);
- net_nfc_append_record_to_ndef_message (message ,record);
- result = net_nfc_write_ndef ((net_nfc_target_handle_h)0x302023 ,message,NULL);
- if(NET_NFC_OK == result){
- net_nfc_free_ndef_message (message);
- }
- CHECK_ASSULT (NET_NFC_OK != result);
- result = net_nfc_write_ndef (NULL ,message,NULL);
- if((NET_NFC_NULL_PARAMETER != result)||(NET_NFC_NULL_PARAMETER != net_nfc_write_ndef ((net_nfc_target_handle_h)0x302023 ,NULL,NULL))){
- net_nfc_free_ndef_message (message);
- }
- CHECK_ASSULT (NET_NFC_NULL_PARAMETER == result);
- CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_write_ndef ((net_nfc_target_handle_h)0x302023 ,NULL,NULL));
- net_nfc_free_ndef_message (message);
-
-
- for (test_case = 0 ; test_case < 4; test_case++){
- CHECK_ASSULT(net_nfc_initialize() == NET_NFC_OK);
- net_nfc_state_activate ();
- PRINT_INSTRUCT("Please close a tag to device!!");
- CHECK_ASSULT (NET_NFC_OK == net_nfc_set_response_callback (net_nfc_test_API_exception_tagAPI, &test_case));
- pthread_cond_wait (&pcond,&plock );
- if (test_case_result == NET_NFC_TEST_FAIL) return test_case_result;
- PRINT_INSTRUCT("Please remoe the tag from device!!");
- sleep(2);
- }
-
- CHECK_ASSULT(net_nfc_deinitialize () != NET_NFC_OK);
-
- return NET_NFC_TEST_OK;
-}
-/*=================================================================================*/
-
-
-static void net_nfc_test_API_exception_targetInfo(net_nfc_message_e message, net_nfc_error_e result, void* data, void* user_param, void * trans_data)
-{
- PRINT_INFO ("Message is received 3 %d", result);
- test_case_result = NET_NFC_TEST_OK;
-
- char **keys;
- int length;
- data_h value;
-
- switch(message)
- {
- case NET_NFC_MESSAGE_TAG_DISCOVERED:
- {
-
- if (NET_NFC_OK != net_nfc_get_tag_info_keys((net_nfc_target_info_h)data, &keys, &length)){
- test_case_result = NET_NFC_TEST_FAIL;
- return;
- }
-
- if (NET_NFC_OK == net_nfc_get_tag_info_value ((net_nfc_target_info_h)data, "abc", &value)){
- test_case_result = NET_NFC_TEST_FAIL;
- return;
- }
- PRINT_INSTRUCT("Please remove the tag from device!!");
-
- }
- break;
- case NET_NFC_MESSAGE_TAG_DETACHED:
-
- if (NET_NFC_OK == net_nfc_get_tag_info_keys((net_nfc_target_info_h)data, &keys, &length)){
- test_case_result = NET_NFC_TEST_FAIL;
- return;
- }
-
- pthread_mutex_lock (&plock);
- pthread_cond_signal (&pcond);
- pthread_mutex_unlock (&plock);
-
-
- break;
- default:
- break;
- }
-}
-
-int nfcTestAPIException_targetInfo (uint8_t testNumber,void* arg_ptr)
-{
- net_nfc_target_type_e target_type;
- net_nfc_target_handle_h target_id;
- bool is_support;
- unsigned int size;
- CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_get_tag_type ((net_nfc_target_info_h)0x302023, NULL));
- CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_get_tag_type (NULL, &target_type));
-
- CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_get_tag_handle((net_nfc_target_info_h)0x302023, NULL));
- CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_get_tag_handle(NULL, &target_id));
-
- CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_get_tag_ndef_support ((net_nfc_target_info_h)0x302023, NULL));
- CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_get_tag_ndef_support (NULL, &is_support));
-
- CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_get_tag_max_data_size ((net_nfc_target_info_h)0x302023, NULL));
- CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_get_tag_max_data_size (NULL, &size));
-
- CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_get_tag_actual_data_size ((net_nfc_target_info_h)0x302023, NULL));
- CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_get_tag_actual_data_size (NULL, &size));
-
- char **keys;
- int length;
- CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_get_tag_info_keys((net_nfc_target_info_h)0x302023, NULL, &length));
- CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_get_tag_info_keys((net_nfc_target_info_h)0x302023, &keys, NULL));
- CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_get_tag_info_keys(NULL, &keys, &length));
-
- const char* key = "hello";
- data_h value;
-
- CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_get_tag_info_value((net_nfc_target_info_h)0x302023, key , NULL));
- CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_get_tag_info_value((net_nfc_target_info_h)0x302023, NULL, &value));
- CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_get_tag_info_value(NULL, key, &value));
-
- CHECK_ASSULT(net_nfc_initialize() == NET_NFC_OK);
- net_nfc_state_activate ();
- CHECK_ASSULT (NET_NFC_OK == net_nfc_set_response_callback (net_nfc_test_API_exception_targetInfo, NULL));
- PRINT_INSTRUCT("Please close a tag to device!!");
-
- pthread_cond_wait (&pcond,&plock );
-
- CHECK_ASSULT(net_nfc_deinitialize() == NET_NFC_OK);
- return NET_NFC_TEST_OK;
-}
-
-/*=================================================================================*/
-
-
-int nfcConnHandoverMessageTest (uint8_t testNumber,void* arg_ptr)
-{
- net_nfc_carrier_config_h carrier;
- net_nfc_property_group_h group;
- ndef_record_h carrier_record;
- ndef_message_h message;
- uint8_t buffer[256] = {0,};
- uint8_t * pdata;
- unsigned int length = 0;
- net_nfc_error_e result;
- char SSID[] = "HomeWLAN";
- char dev_name[] = "DeviceName";
- uint8_t btdev_addr[] = {0x01, 0x07, 0x80, 0x80, 0xBF, 0xA1};
-
- result = net_nfc_create_carrier_config (&carrier ,NET_NFC_CONN_HANDOVER_CARRIER_WIFI_BSS);
- CHECK_RESULT(result);
-
- buffer[0] = 0x10;
- result = net_nfc_add_carrier_config_property (carrier, NET_NFC_WIFI_ATTRIBUTE_VERSION, 1, buffer);
- CHECK_RESULT(result);
- result = net_nfc_create_carrier_config_group (&group, NET_NFC_WIFI_ATTRIBUTE_CREDENTIAL);
- CHECK_RESULT(result);
-
- buffer[0] = 0x1;
- result = net_nfc_add_carrier_config_group_property (group, NET_NFC_WIFI_ATTRIBUTE_NET_INDEX, 1, buffer);
- CHECK_RESULT(result);
-
- length = sprintf ((char*)buffer, "%s", SSID);
- result = net_nfc_add_carrier_config_group_property (group, NET_NFC_WIFI_ATTRIBUTE_SSID, length, buffer);
- CHECK_RESULT(result);
-
- *((uint16_t*) buffer ) = 0x20;
- result = net_nfc_add_carrier_config_group_property (group, NET_NFC_WIFI_ATTRIBUTE_AUTH_TYPE, 2, buffer);
- CHECK_RESULT(result);
-
- *((uint16_t*) buffer ) = 0x0008;
- result = net_nfc_add_carrier_config_group_property (group, NET_NFC_WIFI_ATTRIBUTE_ENC_TYPE, 2, buffer);
- CHECK_RESULT(result);
-
- length = sprintf ((char*)buffer, "MyPreSharedKey");
- result = net_nfc_add_carrier_config_group_property (group, NET_NFC_WIFI_ATTRIBUTE_NET_KEY, length, buffer);
- CHECK_RESULT(result);
-
- buffer[0] = 0x00;
- buffer[1] = 0x07;
- buffer[2] = 0xE9;
- buffer[3] = 0x4C;
- buffer[4] = 0xA8;
- buffer[5] = 0x1C;
- result = net_nfc_add_carrier_config_group_property (group, NET_NFC_WIFI_ATTRIBUTE_MAC_ADDR, 6, buffer);
- CHECK_RESULT(result);
-
-
- *((uint16_t*) buffer ) = 0x0001;
- result = net_nfc_add_carrier_config_group_property (group, NET_NFC_WIFI_ATTRIBUTE_CHANNEL, 2, buffer);
- if (result != NET_NFC_OK) {
- net_nfc_free_carrier_group(group);
- }
- CHECK_RESULT(result);
-
- buffer[0] = 0x00;
- buffer[1] = 0x37;
- buffer[2] = 0x2A;
- result = net_nfc_add_carrier_config_group_property (group, NET_NFC_WIFI_ATTRIBUTE_VEN_EXT, 3, buffer);
- if (result != NET_NFC_OK) {
- net_nfc_free_carrier_group(group);
- }
- CHECK_RESULT(result);
-
- result = net_nfc_append_carrier_config_group (carrier, group);
- CHECK_RESULT(result);
-
- buffer[0] = 0x20;
- result = net_nfc_add_carrier_config_property (carrier, NET_NFC_WIFI_ATTRIBUTE_VERSION2, 1, buffer);
- CHECK_RESULT(result);
-
- result = net_nfc_create_ndef_record_with_carrier_config (&carrier_record ,carrier);
- CHECK_RESULT(result);
-
- result = net_nfc_free_carrier_config (carrier); /* this free all data include group */
- CHECK_RESULT(result);
-
- result = net_nfc_create_handover_request_message (&message);
- if (result != NET_NFC_OK) {
- net_nfc_free_record(carrier_record);
- }
- CHECK_RESULT(result);
-
- //net_nfc_ndef_print_message (message);
-
- result = net_nfc_append_carrier_config_record (message, carrier_record, NET_NFC_CONN_HANDOVER_CARRIER_ACTIVATE);
- CHECK_RESULT(result);
-
- //net_nfc_ndef_print_message (message);
-
-
- // Create BT config
- result = net_nfc_create_carrier_config (&carrier ,NET_NFC_CONN_HANDOVER_CARRIER_BT);
- CHECK_RESULT(result);
-
- buffer[0] = btdev_addr[0];
- buffer[1] = btdev_addr[1];
- buffer[2] = btdev_addr[2];
- buffer[3] = btdev_addr[3];
- buffer[4] = btdev_addr[4];
- buffer[5] = btdev_addr[5];
- if(carrier == NULL){
- result = NET_NFC_NULL_PARAMETER;
- }else{
- result = net_nfc_add_carrier_config_property (carrier ,NET_NFC_BT_ATTRIBUTE_ADDRESS ,6 ,buffer);
- }
- CHECK_RESULT(result);
-
- buffer[0] = 0x08;
- buffer[1] = 0x06;
- buffer[2] = 0x20;
- result = net_nfc_add_carrier_config_property (carrier ,NET_NFC_BT_ATTRIBUTE_OOB_COD ,3 ,buffer);
- CHECK_RESULT(result);
-
-
- result = net_nfc_add_carrier_config_property (carrier ,NET_NFC_BT_ATTRIBUTE_OOB_HASH_C ,16 ,buffer);
- CHECK_RESULT(result);
-
- result = net_nfc_add_carrier_config_property (carrier ,NET_NFC_BT_ATTRIBUTE_OOB_HASH_R ,16 ,buffer);
- CHECK_RESULT(result);
-
- buffer[0] = 0x06;
- buffer[1] = 0x11;
- buffer[2] = 0x20;
- buffer[3] = 0x11;
- result = net_nfc_add_carrier_config_property (carrier ,NET_NFC_BT_ATTRIBUTE_UUID16 ,4 ,buffer);
- CHECK_RESULT(result);
-
- length = sprintf ((char*)buffer, "%s", dev_name);
- result = net_nfc_add_carrier_config_property (carrier ,NET_NFC_BT_ATTRIBUTE_NAME ,length ,buffer);
- CHECK_RESULT(result);
-
- result = net_nfc_create_ndef_record_with_carrier_config (&carrier_record ,carrier);
- if (result != NET_NFC_OK) {
- net_nfc_free_carrier_config(carrier);
- }
- CHECK_RESULT(result);
-
- result = net_nfc_append_carrier_config_record (message, carrier_record, NET_NFC_CONN_HANDOVER_CARRIER_ACTIVATING);
- if (result != NET_NFC_OK) {
- net_nfc_free_carrier_config(carrier);
- }
- CHECK_RESULT(result);
-
- //net_nfc_ndef_print_message (message);
-
- result = net_nfc_free_carrier_config (carrier);
- CHECK_RESULT(result);
-
- result = net_nfc_get_carrier_config_record (message,0 ,&carrier_record);
- CHECK_RESULT(result);
-
- result = net_nfc_create_carrier_config_from_config_record (&carrier ,carrier_record);
- CHECK_RESULT(result);
-
- result = net_nfc_get_carrier_config_property (carrier ,NET_NFC_WIFI_ATTRIBUTE_VERSION , (uint16_t*)&length, &pdata);
- CHECK_RESULT(result);
- if (pdata[0] != 0x10){
- PRINT_RESULT_FAIL("FILE:%s, LINE:%d, value %d",__FILE__,__LINE__, pdata[0]);
- return NET_NFC_TEST_FAIL;
- }
-
- result = net_nfc_get_carrier_config_group (carrier ,0 , &group);
- CHECK_RESULT(result);
-
- result = net_nfc_get_carrier_config_group_property (group ,NET_NFC_WIFI_ATTRIBUTE_SSID, (uint16_t*)&length, &pdata);
- CHECK_RESULT(result);
- if (memcmp (pdata, SSID, length) != 0){
- PRINT_RESULT_FAIL("FILE:%s, LINE:%d,",__FILE__,__LINE__);
- return NET_NFC_TEST_FAIL;
- }
-
- result = net_nfc_remove_carrier_config_group_property (group,NET_NFC_WIFI_ATTRIBUTE_VEN_EXT);
- CHECK_RESULT(result);
-
- result = net_nfc_get_carrier_config_record (message,1 ,&carrier_record);
- CHECK_RESULT(result);
-
- result = net_nfc_create_carrier_config_from_config_record (&carrier ,carrier_record);
- CHECK_RESULT(result);
-
- result = net_nfc_get_carrier_config_property (carrier ,NET_NFC_BT_ATTRIBUTE_ADDRESS , (uint16_t*)&length, &pdata);
- CHECK_RESULT(result);
- if (memcmp (pdata, btdev_addr, length) != 0) {
- PRINT_RESULT_FAIL("FILE:%s, LINE:%d,",__FILE__,__LINE__);
- return NET_NFC_TEST_FAIL;
- }
-
- result = net_nfc_get_carrier_config_property (carrier ,NET_NFC_BT_ATTRIBUTE_NAME , (uint16_t*)&length, &pdata);
- CHECK_RESULT(result);
- if (memcmp (pdata, dev_name, length) != 0){
- PRINT_RESULT_FAIL("FILE:%s, LINE:%d,",__FILE__,__LINE__);
- return NET_NFC_TEST_FAIL;
- }
-
- result = net_nfc_get_alternative_carrier_record_count (message, &length);
- CHECK_RESULT(result);
-
- if (length != 2) {
- PRINT_RESULT_FAIL("FILE:%s, LINE:%d, count = %d",__FILE__,__LINE__, length);
- return NET_NFC_TEST_FAIL;
- }
-
- net_nfc_conn_handover_carrier_state_e power_state;
- result = net_nfc_get_alternative_carrier_power_status (message,0 ,&power_state);
- CHECK_RESULT(result);
-
- if (power_state != NET_NFC_CONN_HANDOVER_CARRIER_ACTIVATE){
- PRINT_RESULT_FAIL("FILE:%s, LINE:%d,",__FILE__,__LINE__);
- return NET_NFC_TEST_FAIL;
- }
- result = net_nfc_set_alternative_carrier_power_status (message,1 ,NET_NFC_CONN_HANDOVER_CARRIER_INACTIVATE);
- CHECK_RESULT(result);
-
- result = net_nfc_get_alternative_carrier_power_status (message,1 ,&power_state);
- CHECK_RESULT(result);
-
- if (power_state != NET_NFC_CONN_HANDOVER_CARRIER_INACTIVATE){
- PRINT_RESULT_FAIL("FILE:%s, LINE:%d, status = %d",__FILE__,__LINE__, power_state);
- return NET_NFC_TEST_FAIL;
- }
-
- net_nfc_conn_handover_carrier_type_e ctype;
- result = net_nfc_get_alternative_carrier_type (message, 0 , &ctype);
-
- if (ctype != NET_NFC_CONN_HANDOVER_CARRIER_WIFI_BSS){
- PRINT_RESULT_FAIL("FILE:%s, LINE:%d,",__FILE__,__LINE__);
- return NET_NFC_TEST_FAIL;
- }
-
- unsigned short r_num;
- result = net_nfc_get_handover_random_number (message, &r_num);
-
- result = net_nfc_get_carrier_config_record (message,0 ,&carrier_record);
- CHECK_RESULT(result);
-
- result = net_nfc_remove_carrier_config_record (message, carrier_record);
- CHECK_RESULT(result);
-
- result = net_nfc_get_carrier_config_record (message,0 ,&carrier_record);
- CHECK_RESULT(result);
-
- result = net_nfc_create_carrier_config_from_config_record (&carrier ,carrier_record);
- CHECK_RESULT(result);
-
- result = net_nfc_get_carrier_config_property (carrier ,NET_NFC_BT_ATTRIBUTE_ADDRESS, (uint16_t*)&length, &pdata);
- CHECK_RESULT(result);
- if (memcmp (pdata, btdev_addr, length) != 0) {
- PRINT_RESULT_FAIL("FILE:%s, LINE:%d,",__FILE__,__LINE__);
- return NET_NFC_TEST_FAIL;
- }
-
- result = net_nfc_get_carrier_config_property (carrier ,NET_NFC_BT_ATTRIBUTE_NAME , (uint16_t*)&length, &pdata);
- CHECK_RESULT(result);
- if (memcmp (pdata, dev_name, length) != 0){
- PRINT_RESULT_FAIL("FILE:%s, LINE:%d,",__FILE__,__LINE__);
- return NET_NFC_TEST_FAIL;
- }
-
- result = net_nfc_get_alternative_carrier_record_count (message, &length);
- CHECK_RESULT(result);
-
- if (length != 1) {
- PRINT_RESULT_FAIL("FILE:%s, LINE:%d,",__FILE__,__LINE__);
- return NET_NFC_TEST_FAIL;
- }
-
- result = net_nfc_get_alternative_carrier_power_status (message,0 ,&power_state);
- CHECK_RESULT(result);
-
- if (power_state != NET_NFC_CONN_HANDOVER_CARRIER_INACTIVATE){
- PRINT_RESULT_FAIL("FILE:%s, LINE:%d,",__FILE__,__LINE__);
- return NET_NFC_TEST_FAIL;
- }
-
- result = net_nfc_get_alternative_carrier_type (message, 0 , &ctype);
-
- if (ctype != NET_NFC_CONN_HANDOVER_CARRIER_BT){
- PRINT_RESULT_FAIL("FILE:%s, LINE:%d,",__FILE__,__LINE__);
- return NET_NFC_TEST_FAIL;
- }
-
- //net_nfc_ndef_print_message (message);
-
- return NET_NFC_TEST_OK;
-
-}
-
-/*=================================================================================*/
-
-
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
-
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef __NFC_API_TEST_H__
-#define __NFC_API_TEST_H__
-
-typedef enum {
- NET_NFC_TEST_NOT_YET,
- NET_NFC_TEST_OK,
- NET_NFC_TEST_FAIL,
-}net_nfc_test_result_e;
-
-
-#define LOG_COLOR_RED "\033[0;31m"
-#define LOG_COLOR_GREEN "\033[0;32m"
-#define LOG_COLOR_BROWN "\033[0;33m"
-#define LOG_COLOR_BLUE "\033[0;34m"
-#define LOG_COLOR_PURPLE "\033[0;35m"
-#define LOG_COLOR_CYAN "\033[0;36m"
-#define LOG_COLOR_LIGHTBLUE "\033[0;37m"
-#define LOG_COLOR_END "\033[0;m"
-
-#define PRINT_INSTRUCT(format,args...) \
-do {\
- printf(LOG_COLOR_BLUE""format""LOG_COLOR_END"\n", ##args);\
-}while(0);
-
-#define PRINT_RESULT_FAIL(format,args...) \
-do {\
- printf(LOG_COLOR_RED""format""LOG_COLOR_END"\n", ##args);\
-}while(0);
-
-#define PRINT_RESULT_SUCCESS(format,args...) \
-do {\
- printf(LOG_COLOR_GREEN""format""LOG_COLOR_END"\n", ##args);\
-}while(0);
-
-#define PRINT_INFO(format,args...) \
-do {\
- printf(format"\n", ##args);\
-}while(0);
-
-
-#define CHECK_RESULT(X)\
- do{\
- if(X!=NET_NFC_OK){\
- PRINT_RESULT_FAIL("FILE:%s, LINE:%d, RESULT:%d",__FILE__,__LINE__,X);\
- return NET_NFC_TEST_FAIL;\
- }\
- }while(0)
-
-
-#define CHECK_ASSULT(X)\
- do{\
- if(!(X)){\
- PRINT_RESULT_FAIL("FILE:%s, LINE:%d, RESULT:%d",__FILE__,__LINE__,X);\
- return NET_NFC_TEST_FAIL;\
- }\
- }while(0)
-
-/* struct defines */
-typedef int nfcTestStartFn_t(uint8_t testNumber,void* arg_ptr2);
-
-typedef struct
-{
- char* testName;
- nfcTestStartFn_t* testFn;
- uint8_t testResult;
-} nfcTestType;
-
-#endif //__NFC_API_TEST_H__
\ No newline at end of file
-CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
-
-PROJECT(tests C)
+LINK_DIRECTORIES(${CMAKE_BINARY_DIR})
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/common)
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/common/include)
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/client/include)
SET(NFC_CLIENT_TEST "nfc-client-test")
-include_directories(${CMAKE_SOURCE_DIR}/src/clientlib/include)
-include_directories(${CMAKE_SOURCE_DIR}/src/commonlib/include)
-include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
+FILE(GLOB TESTS_SRCS *.c)
-INCLUDE(FindPkgConfig)
pkg_check_modules(tests_pkgs REQUIRED glib-2.0)
-
FOREACH(flag ${tests_pkgs_CFLAGS})
SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
ENDFOREACH(flag)
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
-SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fpie")
-SET(CMAKE_C_FLAGS_DEBUG "-O0 -g")
-
-SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie")
-ADD_EXECUTABLE(${NFC_CLIENT_TEST}
- main.c
- net_nfc_test_manager.c
- net_nfc_test_tag.c
- net_nfc_test_ndef.c
- net_nfc_test_test.c
- net_nfc_test_p2p.c
- net_nfc_test_transceive.c
- net_nfc_test_handover.c
- net_nfc_test_client.c
- net_nfc_test_jewel.c
- net_nfc_test_tag_mifare.c
- net_nfc_test_tag_felica.c
- net_nfc_test_exchanger.c
- net_nfc_test_llcp.c
- net_nfc_test_snep.c
- net_nfc_test_se.c
- net_nfc_test_sys_handler.c
- net_nfc_test_util.c
- )
-
-TARGET_LINK_LIBRARIES(${NFC_CLIENT_TEST} ${tests_pkgs_LD_FLAGS} nfc)
-LINK_DIRECTORIES(${CMAKE_BUILD_DIR}/src/clientlib
- ${CMAKE_BUILD_DIR}/src/commonlib)
+ADD_EXECUTABLE(${NFC_CLIENT_TEST} ${TESTS_SRCS})
+TARGET_LINK_LIBRARIES(${NFC_CLIENT_TEST} ${tests_pkgs_LDFLAGS} nfc)
+++ /dev/null
-/*
-* Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-
-#ifndef __NET_NFC_TEST_CLIENT_H__
-#define __NET_NFC_TEST_CLIENT_H__
-
-#include <glib.h>
-
-
-void net_nfc_test_initialize(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_deinitialize(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_is_nfc_supported(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_get_nfc_state(gpointer data,
- gpointer user_data);
-
-#endif//__NET_NFC_TEST_CLIENT_H__
-
+++ /dev/null
-/*
-* Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-
-#ifndef __NET_NFC_TEST_EXCHANGER_H__
-#define __NET_NFC_TEST_EXCHANGER_H__
-
-
-#include <glib.h>
-#include "net_nfc_typedef.h"
-
-
-void net_nfc_test_handle_exchanger_data(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_send_exchanger_data(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_exchanger_request_connection_handover(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_exchanger_get_alternative_carrier_type(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_exchanger_get_alternative_carrier_data(gpointer data,
- gpointer user_data);
-
-#endif//__NET_NFC_TEST_EXCHANGER_H__
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __NET_NFC_TEST_HANDOVER_H__
-#define __NET_NFC_TEST_HANDOVER_H__
-
-#include <glib.h>
-
-
-void net_nfc_test_p2p_connection_handover(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_p2p_connection_handover_sync(gpointer data,
- gpointer user_data);
-
-/*
-void net_nfc_test_handover_get_alternative_carrier_data(gpointer data,
- gpointer user_data);
-*/
-
-void net_nfc_test_handover_handle_alternative_carrier_data(gpointer data,
- gpointer user_datarrierData);
-
-void net_nfc_test_handover_get_alternative_carrier_type(gpointer data,
- gpointer user_data);
-
-
-#endif//__NET_NFC_TEST_HANDOVER_H__
-
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __NET_NFC_TEST_JEWEL_TAG_H__
-#define __NET_NFC_TEST_JEWEL_TAG_H__
-
-#include <glib.h>
-
-
-void net_nfc_test_tag_jewel_read_id(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_tag_jewel_read_byte(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_tag_jewel_read_all(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_tag_jewel_write_with_erase(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_tag_jewel_write_with_no_erase(gpointer data,
- gpointer user_data);
-
-#endif
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __NET_NFC_TEST_LLCP_H__
-#define __NET_NFC_TEST_LLCP_H__
-
-#include <glib.h>
-
-
-void net_nfc_test_llcp_default_config(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_llcp_default_config_sync(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_llcp_get_local_config(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_llcp_custom_config(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_llcp_custom_config_sync(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_llcp_get_local_config(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_llcp_get_config_miu(gpointer data,
- gpointer user_data);
-
-
-void net_nfc_test_llcp_get_config_wks(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_llcp_get_config_lto(gpointer data,
- gpointer user_data);
-
-
-void net_nfc_test_llcp_get_config_option(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_llcp_set_config_miu(gpointer data,
- gpointer user_data);
-
-
-void net_nfc_test_llcp_set_config_wks(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_llcp_set_config_lto(gpointer data,
- gpointer user_data);
-
-
-void net_nfc_test_llcp_set_config_option(gpointer data,
- gpointer user_data);
-
-
-void net_nfc_test_llcp_free_config(gpointer data,
- gpointer user_data);
-
-
-void net_nfc_test_llcp_create_custom_socket_option(gpointer data,
- gpointer user_data);
-
-
-void net_nfc_test_llcp_create_default_socket_option(gpointer data,
- gpointer user_data);
-
-
-void net_nfc_test_llcp_get_local_socket_option(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_llcp_get_socket_option_miu(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_llcp_set_socket_option_miu(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_llcp_get_socket_option_rw(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_llcp_set_socket_option_rw(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_llcp_get_socket_option_type(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_llcp_set_socket_option_type(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_llcp_free_socket_option(gpointer data,
- gpointer user_data);
-
-
-void net_nfc_test_llcp_listen(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_llcp_listen_sync(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_llcp_receive(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_llcp_receive_sync(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_llcp_receive_from(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_llcp_receive_from_sync(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_llcp_create_socket(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_llcp_close_socket(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_llcp_close_socket_sync(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_llcp_connect(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_llcp_connect_sync(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_llcp_connect_sap(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_llcp_connect_sap_sync(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_llcp_send(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_llcp_send_sync(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_llcp_send_to(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_llcp_send_to_sync(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_llcp_disconnect(gpointer func_data,
- gpointer user_data);
-
-void net_nfc_test_llcp_disconnect_server(gpointer func_data,
- gpointer user_data);
-
-void net_nfc_test_llcp_disconnect_sync(gpointer func_data,
- gpointer user_data);
-
-#endif//__NET_NFC_TEST_LLCP_H__
-
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef __NET_NFC_TEST_MANAGER_H__
-#define __NET_NFC_TEST_MANAGER_H__
-
-#include <glib.h>
-
-void net_nfc_test_manager_set_active(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_manager_get_server_state(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_manager_set_active_sync(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_manager_get_server_state_sync(gpointer data,
- gpointer user_data);
-
-#endif //__NET_NFC_TEST_MANAGER_H__
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef __NET_NFC_TEST_NDEF_H__
-#define __NET_NFC_TEST_NDEF_H__
-
-#include <glib.h>
-
-void net_nfc_test_ndef_read(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_ndef_write(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_ndef_make_read_only(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_ndef_format(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_ndef_read_sync(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_ndef_write_sync(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_ndef_make_read_only_sync(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_ndef_format_sync(gpointer data,
- gpointer user_data);
-
-#endif //__NET_NFC_TEST_NDEF_H__
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __NET_NFC_TEST_P2P_H__
-#define __NET_NFC_TEST_P2P_H__
-
-
-#include <glib.h>
-#include "net_nfc_target_info.h"
-
-void net_nfc_test_p2p_send(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_p2p_send_sync(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_p2p_set_device_discovered(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_p2p_set_device_detached(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_p2p_set_data_received(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_p2p_unset_device_discovered(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_p2p_unset_device_detached(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_p2p_unset_data_received(gpointer data,
- gpointer user_data);
-
-net_nfc_target_handle_h net_nfc_test_device_get_target_handle(void);
-
-#endif
-
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef __NET_NFC_TEST_SE_H__
-#define __NET_NFC_TEST_SE_H__
-
-#include <glib.h>
-
-
-void net_nfc_test_se_send_apdu(gpointer data,
- gpointer user_data );
-
-void net_nfc_test_se_send_apdu_sync(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_se_set_secure_element_type(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_se_set_secure_element_type_sync(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_se_open_internal_secure_element(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_se_open_internal_secure_element_sync(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_se_close_internal_secure_element(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_se_close_internal_secure_element_sync(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_se_get_atr(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_se_get_atr_sync(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_se_set_event_cb(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_se_unset_event_cb(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_se_set_ese_detection_cb(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_se_unset_ese_detection_cb(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_se_set_transaction_event_cb(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_se_unset_transaction_event_cb(gpointer data,
- gpointer user_data);
-
-#endif
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __NET_NFC_TEST_SNEP_H__
-#define __NET_NFC_TEST_SNEP_H__
-
-#include <glib.h>
-
-
-void net_nfc_test_snep_set_tag_discovered(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_snep_start_server(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_snep_start_server_sync(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_snep_start_client(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_snep_start_client_sync(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_snep_send_client_request(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_snep_send_client_request_sync(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_snep_register_server(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_snep_unregister_server(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_snep_stop_service(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_snep_stop_service_sync(gpointer data,
- gpointer user_data);
-#endif
-
+++ /dev/null
-/*
-* Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-#ifndef __NET_NFC_TEST_SYS_HANDLER_H__
-#define __NET_NFC_TEST_SYS_HANDLER_H__
-
-#include <glib.h>
-
-void net_nfc_test_sys_handler_set_launch_popup_state(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_sys_handler_get_launch_popup_state(gpointer data,
- gpointer user_data);
-
-#endif//__NET_NFC_TEST_SYS_HANDLER_H__
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef __NET_NFC_TEST_TAG_H__
-#define __NET_NFC_TEST_TAG_H__
-
-#include <glib.h>
-
-#include "net_nfc_target_info.h"
-
-void net_nfc_test_tag_is_tag_connected(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_tag_get_current_tag_info(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_tag_get_current_target_handle(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_tag_is_tag_connected_sync(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_tag_get_current_tag_info_sync(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_tag_get_current_target_handle_sync(gpointer data,
- gpointer user_data);
-
-/* waiting for signal */
-void net_nfc_test_tag_set_tag_discovered(gpointer data,
- gpointer user_data);
-
-net_nfc_target_info_h net_nfc_test_tag_get_target_info(void);
-
-void net_nfc_test_tag_set_tag_detached(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_tag_set_filter(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_tag_get_filter(gpointer data,
- gpointer user_data);
-
-
-#endif //__NET_NFC_TEST_TAG_H__
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __NET_NFC_TEST_FELICA_TAG_H__
-#define __NET_NFC_TEST_FELICA_TAG_H__
-
-#include <glib.h>
-
-
-void net_nfc_test_felica_poll(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_felica_request_service(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_felica_request_response(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_felica_read_without_encryption(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_felica_write_without_encryption(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_felica_request_system_code(gpointer data,
- gpointer user_data);
-
-#endif
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __NET_NFC_TEST_TAG_MIFARE_H__
-#define __NET_NFC_TEST_TAG_MIFARE_H__
-
-#include <glib.h>
-
-
-void net_nfc_test_tag_mifare_read(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_tag_mifare_authenticate_with_keyA(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_tag_mifare_authenticate_with_keyB(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_tag_mifare_write_block(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_tag_mifare_write_page(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_tag_mifare_increment(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_tag_mifare_decrement(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_tag_mifare_transfer(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_tag_mifare_restore(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_tag_mifare_create_default_key(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_tag_mifare_create_net_nfc_forum_key(gpointer data,
- gpointer user_data);
-
-#endif
-
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef __NET_NFC_TEST_TEST_H__
-#define __NET_NFC_TEST_TEST_H__
-
-#include <glib.h>
-
-void net_nfc_test_test_sim_test(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_test_prbs_test(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_test_get_firmware_version(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_test_set_ee_data(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_test_sim_test_sync(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_test_prbs_test_sync(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_test_get_firmware_version_sync(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_test_set_ee_data_sync(gpointer data,
- gpointer user_data);
-
-#endif //__NET_NFC_TEST_TEST_H__
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __NET_NFC_TEST_TRANSCEIVE_H__
-#define __NET_NFC_TEST_TRANSCEIVE_H__
-
-#include <glib.h>
-
-
-void net_nfc_test_transceive(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_transceive_sync(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_transceive_data(gpointer data,
- gpointer user_data);
-
-void net_nfc_test_transceive_data_sync(gpointer data,
- gpointer user_data);
-
-#endif
-
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef _NET_NFC_TEST_UTIL_H_
-#define _NET_NFC_TEST_UTIL_H_
-
-#include <glib-object.h>
-#include <string.h>
-#include "net_nfc_data.h"
-
-
-void print_received_data(data_h data);
-
-
-#endif
{
gint i;
- g_type_init();
-
if (argc == 2 && strcmp(argv[1], "--help") == 0)
{
g_print("nfc-client-test: nfc-client-test [inteface.name]\n");
strv = pos->data;
if (strcmp(strv[0], "Manager") != 0 ||
- strcmp(strv[1], "SetActive") != 0)
+ strcmp(strv[1], "SetActive") != 0)
{
gchar **manager_strv;
*/
#include <glib-object.h>
+
#include "net_nfc_test_client.h"
#include "net_nfc_client_context.h"
#include "net_nfc_test_client.h"
}
}
-void net_nfc_test_initialize(gpointer data,
- gpointer user_data)
+void net_nfc_test_initialize(gpointer data, gpointer user_data)
{
net_nfc_error_e result = NET_NFC_OK;
run_next_callback(user_data);
}
-void net_nfc_test_deinitialize(gpointer data,
- gpointer user_data)
+void net_nfc_test_deinitialize(gpointer data, gpointer user_data)
{
net_nfc_error_e result = NET_NFC_OK;
g_print("Client Deinitialization Completed & Result is %d\n", result);
}
-void net_nfc_test_is_nfc_supported(gpointer data,
- gpointer user_data)
+void net_nfc_test_is_nfc_supported(gpointer data, gpointer user_data)
{
int feature = 0;
net_nfc_error_e result = NET_NFC_OK;
run_next_callback(user_data);
}
-void net_nfc_test_get_nfc_state(gpointer data,
- gpointer user_data)
+void net_nfc_test_get_nfc_state(gpointer data, gpointer user_data)
{
int state = 0;
net_nfc_error_e result = NET_NFC_OK;
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_TEST_CLIENT_H__
+#define __NET_NFC_TEST_CLIENT_H__
+
+#include <glib.h>
+
+void net_nfc_test_initialize(gpointer data, gpointer user_data);
+void net_nfc_test_deinitialize(gpointer data, gpointer user_data);
+void net_nfc_test_is_nfc_supported(gpointer data, gpointer user_data);
+void net_nfc_test_get_nfc_state(gpointer data, gpointer user_data);
+
+#endif //__NET_NFC_TEST_CLIENT_H__
+
return exch_data;
}
-void net_nfc_test_handle_exchanger_data(gpointer data,
- gpointer user_data)
+void net_nfc_test_handle_exchanger_data(gpointer data, gpointer user_data)
{
net_nfc_error_e result = NET_NFC_OK;
ndef_message_h msg = NULL;
return;
}
-void net_nfc_test_send_exchanger_data(gpointer data,
- gpointer user_data)
+void net_nfc_test_send_exchanger_data(gpointer data, gpointer user_data)
{
net_nfc_error_e result = NET_NFC_OK;
net_nfc_target_handle_h handle = NULL;
handle = net_nfc_test_device_get_target_handle();
result = net_nfc_client_send_exchanger_data(exch_data,
- handle,
- user_data);
+ handle,
+ user_data);
g_print("Send exchanger result : %d\n", result);
run_next_callback(user_data);
}
-void net_nfc_test_exchanger_request_connection_handover(gpointer data,
- gpointer user_data)
+void net_nfc_test_exchanger_request_connection_handover(gpointer data, gpointer user_data)
{
net_nfc_error_e result = NET_NFC_OK;
net_nfc_conn_handover_carrier_type_e type = NET_NFC_CONN_HANDOVER_CARRIER_BT;
run_next_callback(user_data);
}
-void net_nfc_test_exchanger_get_alternative_carrier_type(gpointer data,
- gpointer user_data)
+void net_nfc_test_exchanger_get_alternative_carrier_type(gpointer data, gpointer user_data)
{
net_nfc_error_e result = NET_NFC_OK;
/*Handover info needs to check-.As of now passing NULL*/
}
void net_nfc_test_exchanger_get_alternative_carrier_data(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_error_e result = NET_NFC_OK;
/*Handover info needs to check-.As of now passing NULL*/
--- /dev/null
+/*
+* Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+*
+* Licensed under the Flora License, Version 1.1 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://floralicense.org/license/
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+
+#ifndef __NET_NFC_TEST_EXCHANGER_H__
+#define __NET_NFC_TEST_EXCHANGER_H__
+
+
+#include <glib.h>
+#include "net_nfc_typedef.h"
+
+
+void net_nfc_test_handle_exchanger_data(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_send_exchanger_data(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_exchanger_request_connection_handover(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_exchanger_get_alternative_carrier_type(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_exchanger_get_alternative_carrier_data(gpointer data,
+ gpointer user_data);
+
+#endif //__NET_NFC_TEST_EXCHANGER_H__
static void run_next_callback(gpointer user_data);
static void p2p_connection_handover_cb(net_nfc_error_e result,
- net_nfc_conn_handover_carrier_type_e type,
- data_h data,
- void *user_data);
+ net_nfc_conn_handover_carrier_type_e type,
+ data_h data,
+ void *user_data);
net_nfc_connection_handover_info_h global_info = NULL;
}
static void p2p_connection_handover_cb(net_nfc_error_e result,
- net_nfc_conn_handover_carrier_type_e type,
- data_h data,
- void *user_data)
+ net_nfc_conn_handover_carrier_type_e type,
+ data_h data,
+ void *user_data)
{
g_print("Connection handover completed\n");
}
void net_nfc_test_p2p_connection_handover(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_error_e result = NET_NFC_OK;
net_nfc_conn_handover_carrier_type_e type = NET_NFC_CONN_HANDOVER_CARRIER_BT;
g_print("handle for handover : %p \n", handle);
result = net_nfc_client_p2p_connection_handover(
- handle,
- type,
- p2p_connection_handover_cb,
- user_data);
+ handle,
+ type,
+ p2p_connection_handover_cb,
+ user_data);
}
void net_nfc_test_p2p_connection_handover_sync(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_error_e result = NET_NFC_OK;
net_nfc_conn_handover_carrier_type_e type;
handle = net_nfc_test_device_get_target_handle();
result = net_nfc_client_p2p_connection_handover_sync(
- handle,
- type,
- &out_carrier,
- &out_data);
+ handle,
+ type,
+ &out_carrier,
+ &out_data);
g_print("Received out carrier type & carrier type %d, %d\n", out_carrier, type);
print_received_data(out_data);
run_next_callback(user_data);
}
-
void net_nfc_test_handover_get_alternative_carrier_type(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_error_e result = NET_NFC_OK;
net_nfc_conn_handover_carrier_type_e type;
}
void net_nfc_test_handover_handle_alternative_carrier_data(gpointer data,
- gpointer user_datarrierData)
+ gpointer user_data)
{
net_nfc_error_e result = NET_NFC_OK;
data_h out_data = NULL;
result = net_nfc_client_handover_free_alternative_carrier_data(hand_info);
g_print("Free alternative carrier data %d", result);
-
}
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __NET_NFC_TEST_HANDOVER_H__
+#define __NET_NFC_TEST_HANDOVER_H__
+
+#include <glib.h>
+
+
+void net_nfc_test_p2p_connection_handover(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_p2p_connection_handover_sync(gpointer data,
+ gpointer user_data);
+
+/*
+void net_nfc_test_handover_get_alternative_carrier_data(gpointer data,
+ gpointer user_data);
+*/
+
+void net_nfc_test_handover_handle_alternative_carrier_data(gpointer data,
+ gpointer user_datarrierData);
+
+void net_nfc_test_handover_get_alternative_carrier_type(gpointer data,
+ gpointer user_data);
+
+
+#endif //__NET_NFC_TEST_HANDOVER_H__
+
/*
-* Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
#include "net_nfc_test_jewel.h"
#include "net_nfc_typedef_internal.h"
static void run_next_callback(gpointer user_data);
static void jewel_read_cb(net_nfc_error_e result,
- data_h resp_data,
- void *user_data);
+ data_h resp_data,
+ void *user_data);
;
static void jewel_write_cb(net_nfc_error_e result,
- void* user_data);
+ void* user_data);
static net_nfc_target_handle_h get_handle()
/*********************************** Callbacks *************************************/
static void jewel_read_cb(net_nfc_error_e result,
- data_h resp_data,
- void *user_data)
+ data_h resp_data,
+ void *user_data)
{
g_print("jewel_read_cb Completed %d\n", result);
}
static void jewel_write_cb(net_nfc_error_e result,
- void* user_data)
+ void* user_data)
{
g_print("jewel_write_cb Completed %d\n", result);
void net_nfc_test_tag_jewel_read_id(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_error_e result = NET_NFC_OK;
net_nfc_target_handle_h handle = NULL;
handle = get_handle();
result = net_nfc_client_jewel_read_id(handle,
- jewel_read_cb,
- user_data);
+ jewel_read_cb,
+ user_data);
}
void net_nfc_test_tag_jewel_read_byte(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_error_e result = NET_NFC_OK;
net_nfc_target_handle_h handle = NULL;
handle = get_handle();
result = net_nfc_client_jewel_read_byte(handle,
- block,
- byte,
- jewel_read_cb,
- user_data);
+ block,
+ byte,
+ jewel_read_cb,
+ user_data);
}
void net_nfc_test_tag_jewel_read_all(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_error_e result = NET_NFC_OK;
net_nfc_target_handle_h handle = NULL;
handle = get_handle();
result = net_nfc_client_jewel_read_all(handle,
- jewel_read_cb,
- user_data);
+ jewel_read_cb,
+ user_data);
}
void net_nfc_test_tag_jewel_write_with_erase(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_error_e result = NET_NFC_OK;
net_nfc_target_handle_h handle = NULL;
handle = get_handle();
result = net_nfc_client_jewel_write_with_erase(handle,
- block,
- byte,
- data_to_write,
- jewel_write_cb,
- user_data);
+ block,
+ byte,
+ data_to_write,
+ jewel_write_cb,
+ user_data);
}
void net_nfc_test_tag_jewel_write_with_no_erase(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_error_e result = NET_NFC_OK;
net_nfc_target_handle_h handle = NULL;
handle = get_handle();
result = net_nfc_client_jewel_write_with_erase(handle,
- block,
- byte,
- data_to_write,
- jewel_write_cb,
- user_data);
+ block,
+ byte,
+ data_to_write,
+ jewel_write_cb,
+ user_data);
}
-
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __NET_NFC_TEST_JEWEL_TAG_H__
+#define __NET_NFC_TEST_JEWEL_TAG_H__
+
+#include <glib.h>
+
+
+void net_nfc_test_tag_jewel_read_id(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_tag_jewel_read_byte(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_tag_jewel_read_all(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_tag_jewel_write_with_erase(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_tag_jewel_write_with_no_erase(gpointer data,
+ gpointer user_data);
+
+#endif
}
static void llcp_listen_socket_cb(net_nfc_error_e result,
- net_nfc_llcp_socket_t client_socket,
- void *user_data)
+ net_nfc_llcp_socket_t client_socket,
+ void *user_data)
{
g_print("llcp_listen_socket_cb Completed %d\n", client_socket);
}
static void llcp_receive_socket_cb(net_nfc_error_e result,
- data_h data,
- void *user_data)
+ data_h data,
+ void *user_data)
{
data_h received_data = data;
}
static void llcp_receive_from_socket_cb(net_nfc_error_e result,
- sap_t sap,
- data_h data,
- void *user_data)
+ sap_t sap,
+ data_h data,
+ void *user_data)
{
data_h received_data = data;
static void llcp_connect_socket_cb(net_nfc_error_e result,
- net_nfc_llcp_socket_t client_socket,
- void *user_data)
+ net_nfc_llcp_socket_t client_socket,
+ void *user_data)
{
g_print("llcp_connect_socket_cb Completed %d\n", client_socket);
g_print("llcp_connect_socket_cb Completed %d\n", result);
static void llcp_connect_sap_cb(net_nfc_error_e result,
- net_nfc_llcp_socket_t client_socket,
- void *user_data)
+ net_nfc_llcp_socket_t client_socket,
+ void *user_data)
{
g_print("llcp_connect_socket_cb Completed %d\n", client_socket);
g_print("llcp_connect_socket_cb Completed %d\n", result);
static void llcp_send_socket_cb(net_nfc_error_e result,
- net_nfc_llcp_socket_t client_socket,
- void *user_data)
+ net_nfc_llcp_socket_t client_socket,
+ void *user_data)
{
g_print("llcp_send_socket_cb Completed %d\n", client_socket);
g_print("llcp_send_socket_cb Completed %d\n", result);
}
static void llcp_send_to_socket_cb(net_nfc_error_e result,
- net_nfc_llcp_socket_t client_socket,
- void *user_data)
+ net_nfc_llcp_socket_t client_socket,
+ void *user_data)
{
g_print("llcp_send_to_socket_cb Completed %d\n", client_socket);
g_print("llcp_send_to_socket_cb Completed %d\n", result);
}
static void llcp_disconnect_socket_cb(net_nfc_error_e result,
- net_nfc_llcp_socket_t client_socket,
- void *user_data)
+ net_nfc_llcp_socket_t client_socket,
+ void *user_data)
{
g_print("llcp_send_to_socket_cb Completed %d\n", client_socket);
g_print("llcp_send_to_socket_cb Completed %d\n", result);
}
static void llcp_close_completed_cb(net_nfc_error_e result,
- net_nfc_llcp_socket_t client_socket,
- void *user_data)
+ net_nfc_llcp_socket_t client_socket,
+ void *user_data)
{
g_print("llcp_close_completed_cb Completed %d\n", client_socket);
/*********************************** Function Calls *************************************/
void net_nfc_test_llcp_default_config(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_error_e result;
}
result = net_nfc_client_llcp_config(llcp_config_default,
- llcp_default_config_cb,
- user_data);
+ llcp_default_config_cb,
+ user_data);
}
void net_nfc_test_llcp_default_config_sync(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_error_e result;
void net_nfc_test_llcp_custom_config(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_error_e result;
}
result = net_nfc_client_llcp_config(llcp_config,
- llcp_custom_config_cb,
- user_data);
+ llcp_custom_config_cb,
+ user_data);
}
void net_nfc_test_llcp_custom_config_sync(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_error_e result;
}
void net_nfc_test_llcp_get_local_config(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_llcp_config_info_h local_config;
net_nfc_error_e result;
/*commented because remote config API is not available*/
/*
-void net_nfc_test_llcp_get_remote_config(gpointer data,
- gpointer user_data)
-{
+ void net_nfc_test_llcp_get_remote_config(gpointer data,
+ gpointer user_data)
+ {
net_nfc_llcp_config_info_h local_config;
net_nfc_error_e result;
if(result != NET_NFC_OK)
{
- g_print(" llcp create custom config failed: %d\n", result);
- run_next_callback(user_data);
- return;
+ g_print(" llcp create custom config failed: %d\n", result);
+ run_next_callback(user_data);
+ return;
}
g_print(" net_nfc_test_llcp_get_local_config: %d\n", local_config->lto);
g_print("net_nfc_test_llcp_get_local_config: %d\n", local_config->option);
-}
-*/
+ }
+ */
void net_nfc_test_llcp_get_config_miu(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_error_e result;
void net_nfc_test_llcp_get_config_wks(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_error_e result;
uint16_t wks;
}
void net_nfc_test_llcp_get_config_lto(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_error_e result;
uint8_t lto;
void net_nfc_test_llcp_get_config_option(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_error_e result;
uint8_t option;
void net_nfc_test_llcp_set_config_miu(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_error_e result;
uint16_t miu = 128;
void net_nfc_test_llcp_set_config_wks(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_error_e result;
uint16_t wks = 1;
void net_nfc_test_llcp_set_config_lto(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_error_e result;
uint16_t lto = 10;
void net_nfc_test_llcp_set_config_option(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_error_e result;
void net_nfc_test_llcp_free_config(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_error_e result;
void net_nfc_test_llcp_create_custom_socket_option(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
-
net_nfc_error_e result;
result = net_nfc_client_llcp_create_socket_option(&test_option,
- 128,
- 1,
- NET_NFC_LLCP_SOCKET_TYPE_CONNECTIONORIENTED);
+ 128,
+ 1,
+ NET_NFC_LLCP_SOCKET_TYPE_CONNECTIONORIENTED);
if(result != NET_NFC_OK)
{
}
void net_nfc_test_llcp_create_default_socket_option(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
-
net_nfc_error_e result;
result = net_nfc_client_llcp_create_socket_option_default(&test_option);
}
void net_nfc_test_llcp_get_local_socket_option(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_error_e result;
net_nfc_llcp_socket_option_h option_local;
result = net_nfc_client_llcp_get_local_socket_option(client_test_socket,&option_local);
-if(result != NET_NFC_OK)
-{
- g_print(" net_nfc_test_llcp_get_local_socket_option failed: %d\n", result);
- run_next_callback(user_data);
- return;
-}
-
-g_print(" net_nfc_test_llcp_get_local_socket_option: %d\n", option_local->miu);
-g_print("net_nfc_test_llcp_get_local_socket_option: %d\n", option_local->rw);
-g_print(" net_nfc_test_llcp_get_local_socket_option: %d\n", option_local->type);
-
-run_next_callback(user_data);
+ if(result != NET_NFC_OK)
+ {
+ g_print(" net_nfc_test_llcp_get_local_socket_option failed: %d\n", result);
+ run_next_callback(user_data);
+ return;
+ }
+ g_print(" net_nfc_test_llcp_get_local_socket_option: %d\n", option_local->miu);
+ g_print("net_nfc_test_llcp_get_local_socket_option: %d\n", option_local->rw);
+ g_print(" net_nfc_test_llcp_get_local_socket_option: %d\n", option_local->type);
+ run_next_callback(user_data);
}
void net_nfc_test_llcp_get_socket_option_miu(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_error_e result;
uint16_t miu;
void net_nfc_test_llcp_set_socket_option_miu(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_error_e result;
uint16_t miu = 128;
}
void net_nfc_test_llcp_get_socket_option_rw(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
-
net_nfc_error_e result;
uint8_t rw;
void net_nfc_test_llcp_set_socket_option_rw(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
-
net_nfc_error_e result;
uint8_t rw = 1;
}
void net_nfc_test_llcp_get_socket_option_type(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_error_e result;
net_nfc_socket_type_e type;
void net_nfc_test_llcp_set_socket_option_type(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
-
net_nfc_error_e result;
net_nfc_socket_type_e type = NET_NFC_LLCP_SOCKET_TYPE_CONNECTIONORIENTED;
}
void net_nfc_test_llcp_free_socket_option(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_error_e result;
void net_nfc_test_llcp_listen(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_error_e result;
net_nfc_client_llcp_create_socket(&server_test_socket,NULL);
result = net_nfc_client_llcp_listen(server_test_socket,
- "urn:nfc:xsn:samsung.com:testllcp" ,
- 16 ,
- llcp_listen_socket_cb,
- NULL);
+ "urn:nfc:xsn:samsung.com:testllcp" ,
+ 16 ,
+ llcp_listen_socket_cb,
+ NULL);
if(result != NET_NFC_OK)
{
}
void net_nfc_test_llcp_listen_sync(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_error_e result;
net_nfc_llcp_socket_t out_socket;
net_nfc_client_llcp_create_socket(&server_test_socket,NULL);
result = net_nfc_client_llcp_listen_sync(server_test_socket,
- "urn:nfc:xsn:samsung.com:testllcp" ,
- 16 ,
- &out_socket);
+ "urn:nfc:xsn:samsung.com:testllcp" ,
+ 16 ,
+ &out_socket);
if(result != NET_NFC_OK)
{
void net_nfc_test_llcp_receive(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_error_e result;
result = net_nfc_client_llcp_receive(server_test_socket,
- 512,
- llcp_receive_socket_cb,
- NULL);
+ 512,
+ llcp_receive_socket_cb,
+ NULL);
if(result != NET_NFC_OK)
{
void net_nfc_test_llcp_receive_sync(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_error_e result;
data_h out_data;
result = net_nfc_client_llcp_receive_sync(server_test_socket,
- 512,
- &out_data);
+ 512,
+ &out_data);
if(result != NET_NFC_OK)
{
void net_nfc_test_llcp_receive_from(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_error_e result;
result = net_nfc_client_llcp_receive_from(server_test_socket,
- 512,
- llcp_receive_from_socket_cb,
- NULL);
+ 512,
+ llcp_receive_from_socket_cb,
+ NULL);
if(result != NET_NFC_OK)
{
}
void net_nfc_test_llcp_receive_from_sync(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_error_e result;
data_h out_data;
sap_t sap_data;
result = net_nfc_client_llcp_receive_from_sync(server_test_socket,
- 512,
- &sap_data,
- &out_data);
+ 512,
+ &sap_data,
+ &out_data);
if(result != NET_NFC_OK)
{
void net_nfc_test_llcp_create_socket(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_client_llcp_create_socket(&client_test_socket, NULL);
void net_nfc_test_llcp_close_socket(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_error_e result;
result = net_nfc_client_llcp_close(client_test_socket,
- llcp_close_completed_cb,
- user_data);
+ llcp_close_completed_cb,
+ user_data);
g_print(" net_nfc_test_llcp_close_socket %d\n",result);
void net_nfc_test_llcp_close_socket_sync(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_llcp_socket_t out_socket;
net_nfc_error_e result;
result = net_nfc_client_llcp_close_sync(client_test_socket,
- &out_socket);
+ &out_socket);
g_print(" net_nfc_test_llcp_close_socket %d\n",result);
void net_nfc_test_llcp_connect(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_error_e result;
net_nfc_client_llcp_create_socket(&client_test_socket, NULL);
result = net_nfc_client_llcp_connect(client_test_socket,
- "urn:nfc:xsn:samsung.com:testllcp",
- llcp_connect_socket_cb,
- user_data);
+ "urn:nfc:xsn:samsung.com:testllcp",
+ llcp_connect_socket_cb,
+ user_data);
if(result != NET_NFC_OK)
{
}
void net_nfc_test_llcp_connect_sync(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_error_e result;
net_nfc_llcp_socket_t out_socket;
net_nfc_client_llcp_create_socket(&client_test_socket, NULL);
result = net_nfc_client_llcp_connect_sync(client_test_socket,
- "urn:nfc:xsn:samsung.com:testllcp",
- &out_socket);
+ "urn:nfc:xsn:samsung.com:testllcp",
+ &out_socket);
if(result != NET_NFC_OK)
{
}
void net_nfc_test_llcp_connect_sap(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_error_e result;
net_nfc_client_llcp_create_socket(&client_test_socket, NULL);
result = net_nfc_client_llcp_connect_sap(client_test_socket,
- 16,
- llcp_connect_sap_cb,
- user_data);
+ 16,
+ llcp_connect_sap_cb,
+ user_data);
if(result != NET_NFC_OK)
{
}
void net_nfc_test_llcp_connect_sap_sync(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_error_e result;
net_nfc_llcp_socket_t out_socket;
net_nfc_client_llcp_create_socket(&client_test_socket, NULL);
result = net_nfc_client_llcp_connect_sap_sync(client_test_socket,
- 16,
- &out_socket);
+ 16,
+ &out_socket);
if(result != NET_NFC_OK)
{
void net_nfc_test_llcp_send(gpointer func_data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_error_e result;
data_h data;
net_nfc_create_data (&data, (const uint8_t*)str ,strlen (str) + 1);
result = net_nfc_client_llcp_send(client_test_socket,
- data,
- llcp_send_socket_cb,
- user_data);
+ data,
+ llcp_send_socket_cb,
+ user_data);
if(result != NET_NFC_OK)
{
void net_nfc_test_llcp_send_sync(gpointer func_data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_error_e result;
data_h data;
net_nfc_create_data (&data, (const uint8_t*)str ,strlen (str) + 1);
result = net_nfc_client_llcp_send_sync(client_test_socket,
- data,
- &out_socket);
+ data,
+ &out_socket);
if(result != NET_NFC_OK)
{
void net_nfc_test_llcp_send_to(gpointer func_data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_error_e result;
data_h data;
net_nfc_create_data (&data, (const uint8_t*)str ,strlen (str) + 1);
result = net_nfc_client_llcp_send_to(client_test_socket,
- 16,
- data,
- llcp_send_to_socket_cb,
- user_data);
+ 16,
+ data,
+ llcp_send_to_socket_cb,
+ user_data);
if(result != NET_NFC_OK)
{
void net_nfc_test_llcp_send_to_sync(gpointer func_data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_error_e result;
data_h data;
net_nfc_create_data (&data, (const uint8_t*)str ,strlen (str) + 1);
result = net_nfc_client_llcp_send_to_sync(client_test_socket,
- 16,
- data,
- &out_socket);
+ 16,
+ data,
+ &out_socket);
if(result != NET_NFC_OK)
{
void net_nfc_test_llcp_disconnect(gpointer func_data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_error_e result;
result = net_nfc_client_llcp_disconnect(client_test_socket,
- llcp_disconnect_socket_cb,
- user_data);
+ llcp_disconnect_socket_cb,
+ user_data);
if(result != NET_NFC_OK)
{
}
void net_nfc_test_llcp_disconnect_server(gpointer func_data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_error_e result;
result = net_nfc_client_llcp_disconnect(server_test_socket,
- llcp_disconnect_socket_cb,
- user_data);
+ llcp_disconnect_socket_cb,
+ user_data);
if(result != NET_NFC_OK)
{
void net_nfc_test_llcp_disconnect_sync(gpointer func_data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_error_e result;
net_nfc_llcp_socket_t out_socket;
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __NET_NFC_TEST_LLCP_H__
+#define __NET_NFC_TEST_LLCP_H__
+
+#include <glib.h>
+
+
+void net_nfc_test_llcp_default_config(gpointer data, gpointer user_data);
+void net_nfc_test_llcp_default_config_sync(gpointer data, gpointer user_data);
+void net_nfc_test_llcp_get_local_config(gpointer data, gpointer user_data);
+void net_nfc_test_llcp_custom_config(gpointer data, gpointer user_data);
+void net_nfc_test_llcp_custom_config_sync(gpointer data, gpointer user_data);
+void net_nfc_test_llcp_get_local_config(gpointer data, gpointer user_data);
+void net_nfc_test_llcp_get_config_miu(gpointer data, gpointer user_data);
+void net_nfc_test_llcp_get_config_wks(gpointer data, gpointer user_data);
+void net_nfc_test_llcp_get_config_lto(gpointer data, gpointer user_data);
+void net_nfc_test_llcp_get_config_option(gpointer data, gpointer user_data);
+void net_nfc_test_llcp_set_config_miu(gpointer data, gpointer user_data);
+void net_nfc_test_llcp_set_config_wks(gpointer data, gpointer user_data);
+void net_nfc_test_llcp_set_config_lto(gpointer data, gpointer user_data);
+void net_nfc_test_llcp_set_config_option(gpointer data, gpointer user_data);
+void net_nfc_test_llcp_free_config(gpointer data, gpointer user_data);
+void net_nfc_test_llcp_create_custom_socket_option(gpointer data,
+ gpointer user_data);
+void net_nfc_test_llcp_create_default_socket_option(gpointer data,
+ gpointer user_data);
+void net_nfc_test_llcp_get_local_socket_option(gpointer data,
+ gpointer user_data);
+void net_nfc_test_llcp_get_socket_option_miu(gpointer data, gpointer user_data);
+void net_nfc_test_llcp_set_socket_option_miu(gpointer data, gpointer user_data);
+void net_nfc_test_llcp_get_socket_option_rw(gpointer data, gpointer user_data);
+void net_nfc_test_llcp_set_socket_option_rw(gpointer data, gpointer user_data);
+void net_nfc_test_llcp_get_socket_option_type(gpointer data,
+ gpointer user_data);
+void net_nfc_test_llcp_set_socket_option_type(gpointer data,
+ gpointer user_data);
+void net_nfc_test_llcp_free_socket_option(gpointer data, gpointer user_data);
+void net_nfc_test_llcp_listen(gpointer data, gpointer user_data);
+void net_nfc_test_llcp_listen_sync(gpointer data, gpointer user_data);
+void net_nfc_test_llcp_receive(gpointer data, gpointer user_data);
+void net_nfc_test_llcp_receive_sync(gpointer data, gpointer user_data);
+void net_nfc_test_llcp_receive_from(gpointer data, gpointer user_data);
+void net_nfc_test_llcp_receive_from_sync(gpointer data, gpointer user_data);
+void net_nfc_test_llcp_create_socket(gpointer data, gpointer user_data);
+void net_nfc_test_llcp_close_socket(gpointer data, gpointer user_data);
+void net_nfc_test_llcp_close_socket_sync(gpointer data, gpointer user_data);
+void net_nfc_test_llcp_connect(gpointer data, gpointer user_data);
+void net_nfc_test_llcp_connect_sync(gpointer data, gpointer user_data);
+void net_nfc_test_llcp_connect_sap(gpointer data, gpointer user_data);
+void net_nfc_test_llcp_connect_sap_sync(gpointer data, gpointer user_data);
+void net_nfc_test_llcp_send(gpointer data, gpointer user_data);
+void net_nfc_test_llcp_send_sync(gpointer data, gpointer user_data);
+void net_nfc_test_llcp_send_to(gpointer data, gpointer user_data);
+void net_nfc_test_llcp_send_to_sync(gpointer data, gpointer user_data);
+void net_nfc_test_llcp_disconnect(gpointer func_data, gpointer user_data);
+void net_nfc_test_llcp_disconnect_server(gpointer func_data, gpointer user_data);
+void net_nfc_test_llcp_disconnect_sync(gpointer func_data, gpointer user_data);
+
+#endif //__NET_NFC_TEST_LLCP_H__
\ No newline at end of file
void *user_data);
static void set_active_completed_cb(net_nfc_error_e result,
- void *user_data);
+ void *user_data);
static void get_server_state_completed_cb(net_nfc_error_e result,
- unsigned int state,
- void *user_data);
+ unsigned int state,
+ void *user_data);
static void run_next_callback(gpointer user_data)
{
if (state & NET_NFC_SNEP_CLIENT_CONNECTED)
{
g_print("\tNET_NFC_SNEP_CLIENT_CONNECTED(%d)\n",
- state);
+ state);
}
if (state & NET_NFC_NPP_CLIENT_CONNECTED)
g_print("\tNET_NFC_NPP_CLIENT_CONNECTED(%d)\n", state);
}
static void set_activated_cb(bool state,
- void *user_data)
+ void *user_data)
{
g_print("Activated state %d\n", state);
}
static void set_active_completed_cb(net_nfc_error_e result,
- void *user_data)
+ void *user_data)
{
g_print("SetActive Completed %d\n", result);
run_next_callback(user_data);
}
static void get_server_state_completed_cb(net_nfc_error_e result,
- unsigned int state,
- void *user_data)
+ unsigned int state,
+ void *user_data)
{
g_print("GetServerState Completed %d\n", result);
}
void net_nfc_test_manager_set_active(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_client_manager_set_activated(set_activated_cb, NULL);
net_nfc_client_manager_set_active(1,
- set_active_completed_cb,
- user_data);
+ set_active_completed_cb,
+ user_data);
}
void net_nfc_test_manager_get_server_state(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_client_manager_get_server_state(get_server_state_completed_cb,
- user_data);
+ user_data);
}
void net_nfc_test_manager_set_active_sync(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
gint i;
}
void net_nfc_test_manager_get_server_state_sync(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_error_e result;
guint state = 0;
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_TEST_MANAGER_H__
+#define __NET_NFC_TEST_MANAGER_H__
+
+#include <glib.h>
+
+void net_nfc_test_manager_set_active(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_manager_get_server_state(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_manager_set_active_sync(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_manager_get_server_state_sync(gpointer data,
+ gpointer user_data);
+
+#endif //__NET_NFC_TEST_MANAGER_H__
static net_nfc_target_handle_h ndef_get_handle(void);
static ndef_message_h create_ndef_message_text(const gchar *str,
- const gchar *lang,
- net_nfc_encode_type_e encode);
+ const gchar *lang,
+ net_nfc_encode_type_e encode);
static void set_string(const gchar *str);
void *user_data);
static void ndef_make_read_only_cb(net_nfc_error_e result,
- void *user_data);
+ void *user_data);
static void ndef_format_cb(net_nfc_error_e result,
void *user_data);
net_nfc_get_encoding_type_from_text_record(record, &enc);
switch (enc)
{
- case NET_NFC_ENCODE_UTF_8:
- g_print("Encoding: UTF-8\n");
- break;
- case NET_NFC_ENCODE_UTF_16:
- g_print("Encoding: UTF-16\n");
- break;
- default:
- g_print("Encoding: Unknown\n");
+ case NET_NFC_ENCODE_UTF_8:
+ g_print("Encoding: UTF-8\n");
+ break;
+ case NET_NFC_ENCODE_UTF_16:
+ g_print("Encoding: UTF-16\n");
+ break;
+ default:
+ g_print("Encoding: Unknown\n");
}
}
switch(tnf)
{
- case NET_NFC_RECORD_EMPTY:
- break;
- case NET_NFC_RECORD_WELL_KNOWN_TYPE:
- print_record_well_known_type(record);
- break;
- case NET_NFC_RECORD_MIME_TYPE:
- break;
- case NET_NFC_RECORD_URI:
- break;
- case NET_NFC_RECORD_EXTERNAL_RTD:
- break;
- case NET_NFC_RECORD_UNKNOWN:
- break;
- case NET_NFC_RECORD_UNCHAGNED:
- break;
- default:
- g_print("TNF: unknown error\n");
- break;
+ case NET_NFC_RECORD_EMPTY:
+ break;
+ case NET_NFC_RECORD_WELL_KNOWN_TYPE:
+ print_record_well_known_type(record);
+ break;
+ case NET_NFC_RECORD_MIME_TYPE:
+ break;
+ case NET_NFC_RECORD_URI:
+ break;
+ case NET_NFC_RECORD_EXTERNAL_RTD:
+ break;
+ case NET_NFC_RECORD_UNKNOWN:
+ break;
+ case NET_NFC_RECORD_UNCHAGNED:
+ break;
+ default:
+ g_print("TNF: unknown error\n");
+ break;
}
}
}
if (net_nfc_get_ndef_message_record_count(message,
- &count) != NET_NFC_OK)
+ &count) != NET_NFC_OK)
{
g_print("can not get count of record\n");
return;
g_print("Record count : %d\n", i+1);
if (net_nfc_get_record_by_index(message,
- i,
- &record) != NET_NFC_OK)
+ i,
+ &record) != NET_NFC_OK)
{
g_print("can not get record from index %d\n", i);
continue;
}
static ndef_message_h create_ndef_message_text(const gchar *str,
- const gchar *lang,
- net_nfc_encode_type_e encode)
+ const gchar *lang,
+ net_nfc_encode_type_e encode)
{
ndef_record_h record = NULL;
ndef_message_h message = NULL;
}
if (net_nfc_create_text_type_record(&record,
- str,
- lang,
- encode) != NET_NFC_OK)
+ str,
+ lang,
+ encode) != NET_NFC_OK)
{
g_printerr("Can not create text record(%s, %d): %s\n",
lang, encode, str);
}
if (net_nfc_append_record_to_ndef_message(message,
- record) != NET_NFC_OK)
+ record) != NET_NFC_OK)
{
g_printerr("Can not append record to message\n");
net_nfc_free_ndef_message(message);
static void ndef_make_read_only_cb(net_nfc_error_e result,
- void *user_data)
+ void *user_data)
{
g_print("Make Read only Completed %d\n", result);
void net_nfc_test_ndef_read(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_target_handle_h handle;
g_print("Handle is %#x\n", GPOINTER_TO_UINT(handle));
net_nfc_client_ndef_read(handle,
- ndef_read_cb,
- user_data);
+ ndef_read_cb,
+ user_data);
}
void net_nfc_test_ndef_write(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_target_handle_h handle;
ndef_message_h message;
}
message = create_ndef_message_text(str,
- "en-US",
- NET_NFC_ENCODE_UTF_8);
+ "en-US",
+ NET_NFC_ENCODE_UTF_8);
g_free(str);
}
net_nfc_client_ndef_write(handle,
- message,
- ndef_write_cb,
- user_data);
+ message,
+ ndef_write_cb,
+ user_data);
}
void net_nfc_test_ndef_make_read_only(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_target_handle_h handle;
g_print("Handle is %#x\n", GPOINTER_TO_UINT(handle));
net_nfc_client_ndef_make_read_only(handle,
- ndef_make_read_only_cb,
- user_data);
+ ndef_make_read_only_cb,
+ user_data);
}
void net_nfc_test_ndef_format(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_target_handle_h handle;
data_h key;
net_nfc_create_data(&key, format_data, 6);
net_nfc_client_ndef_format(handle,
- key,
- ndef_format_cb,
- user_data);
+ key,
+ ndef_format_cb,
+ user_data);
net_nfc_free_data(key);
}
void net_nfc_test_ndef_read_sync(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_target_handle_h handle;
ndef_message_h message = NULL;
g_print("Handle is %#x\n", GPOINTER_TO_UINT(handle));
result = net_nfc_client_ndef_read_sync(handle,
- &message);
+ &message);
g_print("Read Ndef: %d\n", result);
}
void net_nfc_test_ndef_write_sync(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
gchar *str = NULL;
}
message = create_ndef_message_text(str,
- "en-US",
- NET_NFC_ENCODE_UTF_8);
+ "en-US",
+ NET_NFC_ENCODE_UTF_8);
g_free(str);
}
void net_nfc_test_ndef_make_read_only_sync(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_target_handle_h handle;
net_nfc_error_e result;
}
void net_nfc_test_ndef_format_sync(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_target_handle_h handle;
net_nfc_error_e result;
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_TEST_NDEF_H__
+#define __NET_NFC_TEST_NDEF_H__
+
+#include <glib.h>
+
+void net_nfc_test_ndef_read(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_ndef_write(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_ndef_make_read_only(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_ndef_format(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_ndef_read_sync(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_ndef_write_sync(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_ndef_make_read_only_sync(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_ndef_format_sync(gpointer data,
+ gpointer user_data);
+
+#endif //__NET_NFC_TEST_NDEF_H__
static void run_next_callback(gpointer user_data);
static void p2p_send(net_nfc_error_e result,
- void *user_data);
+ void *user_data);
static void p2p_device_discovered(net_nfc_target_handle_h handle,
- void *user_data);
+ void *user_data);
static void p2p_device_detached(void * user_data);
}
static void p2p_send(net_nfc_error_e result,
- void *user_data)
+ void *user_data)
{
g_print("P2P send Completed %d\n", result);
}
static void p2p_device_discovered(net_nfc_target_handle_h handle,
- void *user_data)
+ void *user_data)
{
g_print("Target is Discovered\n");
global_handle = handle;
}
void net_nfc_test_p2p_send(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_error_e result = NET_NFC_OK;
g_print("Handle is %#x\n", GPOINTER_TO_UINT(global_handle));
net_nfc_client_p2p_send(
- exch_data,
- global_handle,
- p2p_send,
- user_data);
+ exch_data,
+ global_handle,
+ p2p_send,
+ user_data);
}
void net_nfc_test_p2p_send_sync(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_error_e result = NET_NFC_OK;
ndef_message_h msg = NULL;
}
void net_nfc_test_p2p_set_device_discovered(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
g_print("Waiting for Device Discovered Singal\n");
}
void net_nfc_test_p2p_set_device_detached(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_client_p2p_set_device_detached(p2p_device_detached,
- user_data);
+ user_data);
}
void net_nfc_test_p2p_set_data_received(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_client_p2p_set_data_received(p2p_device_data_received,
- user_data);
+ user_data);
}
net_nfc_target_handle_h net_nfc_test_device_get_target_handle(void)
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __NET_NFC_TEST_P2P_H__
+#define __NET_NFC_TEST_P2P_H__
+
+
+#include <glib.h>
+#include "net_nfc_target_info.h"
+
+void net_nfc_test_p2p_send(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_p2p_send_sync(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_p2p_set_device_discovered(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_p2p_set_device_detached(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_p2p_set_data_received(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_p2p_unset_device_discovered(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_p2p_unset_device_detached(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_p2p_unset_data_received(gpointer data,
+ gpointer user_data);
+
+net_nfc_target_handle_h net_nfc_test_device_get_target_handle(void);
+
+#endif
+
static void set_secure_element_cb(net_nfc_error_e result, void *user_data);
static void open_secure_element_cb(net_nfc_error_e result,
- net_nfc_target_handle_h handle, void *user_data);
+ net_nfc_target_handle_h handle, void *user_data);
static void close_secure_element_cb(net_nfc_error_e result, void *user_data);
static void get_atr_secure_element_cb(net_nfc_error_e result, data_h data,
- void *user_data);
+ void *user_data);
static void se_set_event_cb(net_nfc_message_e event, void *user_data);
static void se_ese_detection_cb(net_nfc_target_handle_h handle,
- int dev_type, data_h data, void *user_data);
+ int dev_type, data_h data, void *user_data);
static void se_set_transaction_cb(data_h aid,
- data_h param,
- void *user_data);
+ data_h param,
+ void *user_data);
/*This handle would be intialized by open secure element callback function*/
static net_nfc_target_handle_h global_handle = NULL;
}
static void open_secure_element_cb(net_nfc_error_e result,
- net_nfc_target_handle_h handle, void* user_data)
+ net_nfc_target_handle_h handle, void* user_data)
{
g_print("Open secure element completed\n");
// assigning received handle
}
static void get_atr_secure_element_cb(net_nfc_error_e result, data_h data,
- void* user_data)
+ void* user_data)
{
g_print("get atr completed\n");
print_received_data(data);
}
static void se_ese_detection_cb(net_nfc_target_handle_h handle,
- int dev_type,
- data_h data,
- void *user_data)
+ int dev_type,
+ data_h data,
+ void *user_data)
{
g_print("Set ese detection callback successfully\n");
g_print("Handle is %#x\n", GPOINTER_TO_UINT(handle));
}
static void se_set_transaction_cb(data_h aid,
- data_h param,
- void *user_data)
+ data_h param,
+ void *user_data)
{
g_print("Set transaction callback successfully\n");
g_print("*****displaying Aid data****\n");
}
void net_nfc_test_se_send_apdu(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_error_e result = NET_NFC_OK;
data_h apdu_data = NULL;
net_nfc_create_data(&apdu_data, apdu_cmd, 4);
result = net_nfc_client_se_send_apdu(global_handle,
- apdu_data,
- send_apdu_cb,
- user_data);
+ apdu_data,
+ send_apdu_cb,
+ user_data);
}
void net_nfc_test_se_send_apdu_sync(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_error_e result = NET_NFC_OK;
data_h apdu_data = NULL;
net_nfc_create_data(&apdu_data, apdu_cmd, 4);
result = net_nfc_client_se_send_apdu_sync(global_handle,
- apdu_data,
- &response);
+ apdu_data,
+ &response);
g_print(" Send apdu data sync completed %d\n", result);
print_received_data(response);
}
void net_nfc_test_se_set_secure_element_type(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_error_e result = NET_NFC_OK;
net_nfc_se_type_e se_type = NET_NFC_SE_TYPE_UICC;
result = net_nfc_client_se_set_secure_element_type(
- se_type,
- set_secure_element_cb,
- user_data);
+ se_type,
+ set_secure_element_cb,
+ user_data);
}
void net_nfc_test_se_set_secure_element_type_sync(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_error_e result = NET_NFC_OK;
net_nfc_se_type_e se_type = NET_NFC_SE_TYPE_UICC;
}
void net_nfc_test_se_open_internal_secure_element(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_error_e result = NET_NFC_OK;
net_nfc_se_type_e se_type = NET_NFC_SE_TYPE_UICC;
result = net_nfc_client_se_open_internal_secure_element(
- se_type,
- open_secure_element_cb,
- user_data);
-
+ se_type,
+ open_secure_element_cb,
+ user_data);
}
void net_nfc_test_se_open_internal_secure_element_sync(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_error_e result = NET_NFC_OK;
net_nfc_se_type_e se_type = NET_NFC_SE_TYPE_UICC;
result = net_nfc_client_se_open_internal_secure_element_sync(
- se_type,
- &global_handle);
+ se_type,
+ &global_handle);
g_print("Handle is %#x\n", GPOINTER_TO_UINT(global_handle));
g_print(" open secure element completed %d\n", result);
}
void net_nfc_test_se_close_internal_secure_element(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_error_e result = NET_NFC_OK;
result = net_nfc_client_se_close_internal_secure_element(
- global_handle,
- close_secure_element_cb,
- user_data);
-
+ global_handle,
+ close_secure_element_cb,
+ user_data);
}
void net_nfc_test_se_close_internal_secure_element_sync(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_error_e result = NET_NFC_OK;
}
void net_nfc_test_se_get_atr(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_error_e result = NET_NFC_OK;
result = net_nfc_client_se_get_atr(
- global_handle,
- get_atr_secure_element_cb,
- user_data);
-
+ global_handle,
+ get_atr_secure_element_cb,
+ user_data);
}
void net_nfc_test_se_get_atr_sync(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_error_e result = NET_NFC_OK;
data_h attr_data = NULL;
result = net_nfc_client_se_get_atr_sync(
- global_handle,
- &attr_data);
+ global_handle,
+ &attr_data);
g_print("Get atr data sync completed %d\n", result);
print_received_data(attr_data);
}
void net_nfc_test_se_set_event_cb(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_client_se_set_event_cb(se_set_event_cb,
- user_data);
+ user_data);
}
void net_nfc_test_se_unset_event_cb(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_client_se_unset_event_cb();
g_print(" Event unset callback successfully\n");
}
void net_nfc_test_se_set_ese_detection_cb(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_client_se_set_ese_detection_cb(se_ese_detection_cb,
- user_data);
+ user_data);
}
void net_nfc_test_se_unset_ese_detection_cb(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_client_se_unset_ese_detection_cb();
g_print("Detection unset callback successfuly\n");
}
void net_nfc_test_se_set_transaction_event_cb(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_client_se_set_transaction_event_cb(se_set_transaction_cb,
- user_data);
+ user_data);
}
void net_nfc_test_se_unset_transaction_event_cb(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_client_se_unset_transaction_event_cb();
g_print("Transaction unset callback successfully\n");
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_TEST_SE_H__
+#define __NET_NFC_TEST_SE_H__
+
+#include <glib.h>
+
+
+void net_nfc_test_se_send_apdu(gpointer data,
+ gpointer user_data );
+
+void net_nfc_test_se_send_apdu_sync(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_se_set_secure_element_type(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_se_set_secure_element_type_sync(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_se_open_internal_secure_element(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_se_open_internal_secure_element_sync(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_se_close_internal_secure_element(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_se_close_internal_secure_element_sync(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_se_get_atr(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_se_get_atr_sync(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_se_set_event_cb(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_se_unset_event_cb(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_se_set_ese_detection_cb(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_se_unset_ese_detection_cb(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_se_set_transaction_event_cb(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_se_unset_transaction_event_cb(gpointer data,
+ gpointer user_data);
+
+#endif
static void run_next_callback(gpointer user_data);
static void snep_tag_discovered_cb(net_nfc_target_info_h info,
- void *user_data);
+ void *user_data);
static void snep_tag_detached_cb(void *user_data);
static void snep_start_server_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);
+ net_nfc_snep_type_t event,
+ net_nfc_error_e result,
+ ndef_message_h msg,
+ void *user_data);
static void snep_start_client_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);
+ net_nfc_snep_type_t event,
+ net_nfc_error_e result,
+ ndef_message_h msg,
+ void *user_data);
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);
+ net_nfc_snep_type_t event,
+ net_nfc_error_e result,
+ ndef_message_h msg,
+ void *user_data);
static void snep_register_server_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);
+ net_nfc_snep_type_t event,
+ net_nfc_error_e result,
+ ndef_message_h msg,
+ void *user_data);
/******************************Callbacks*********************************************/
}
static void snep_tag_discovered_cb(net_nfc_target_info_h info,
- void *user_data)
+ void *user_data)
{
g_print("TagDiscovered\n");
}
static void snep_start_server_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)
+ net_nfc_snep_type_t event,
+ net_nfc_error_e result,
+ ndef_message_h msg,
+ void *user_data)
{
snep_handle = target;
}
static void snep_start_client_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)
+ net_nfc_snep_type_t event,
+ net_nfc_error_e result,
+ ndef_message_h msg,
+ void *user_data)
{
g_print("snep_start_client_cb Completed %d\n", event);
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)
+ net_nfc_snep_type_t event,
+ net_nfc_error_e result,
+ ndef_message_h msg,
+ void *user_data)
{
g_print("snep_send_request_cb Completed %d\n", event);
static void snep_register_server_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)
- {
+ net_nfc_snep_type_t event,
+ net_nfc_error_e result,
+ ndef_message_h msg,
+ void *user_data)
+{
- g_print("snep_register_server_cb Completed %d\n", event);
- g_print("snep_register_server_cb Completed %d\n", result);
+ g_print("snep_register_server_cb Completed %d\n", event);
+ g_print("snep_register_server_cb Completed %d\n", result);
- net_nfc_util_print_ndef_message (msg);
+ net_nfc_util_print_ndef_message (msg);
- run_next_callback(user_data);
- }
+ run_next_callback(user_data);
+}
/*
static void snep_unregister_server_cb(net_nfc_snep_handle_h target,
/******************************API Calls*********************************************/
void net_nfc_test_snep_set_tag_discovered(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
g_print("Waiting for TagDiscovered Singal\n");
void net_nfc_test_snep_start_server(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_error_e result;
result = net_nfc_client_snep_start_server(target_info->handle,
- "urn:nfc:xsn:samsung.com:testllcp",
- 16,
- snep_start_server_cb,
- user_data);
+ "urn:nfc:xsn:samsung.com:testllcp",
+ 16,
+ snep_start_server_cb,
+ user_data);
if(result != NET_NFC_OK)
{
void net_nfc_test_snep_start_server_sync(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
/*
void net_nfc_test_snep_start_client(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_error_e result;
result = net_nfc_client_snep_start_client(target_info->handle,
- "urn:nfc:xsn:samsung.com:testllcp",
- 16,
- snep_start_client_cb,
- user_data);
+ "urn:nfc:xsn:samsung.com:testllcp",
+ 16,
+ snep_start_client_cb,
+ user_data);
if(result != NET_NFC_OK)
{
void net_nfc_test_snep_start_client_sync(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
/*
}
void net_nfc_test_snep_send_client_request(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_error_e result= NET_NFC_OK;
net_nfc_error_e error = NET_NFC_OK;
ndef_record_h record = NULL;
if( (error = net_nfc_create_uri_type_record(&record,
- "http://www.naver.com",
- NET_NFC_SCHEMA_FULL_URI)) == NET_NFC_OK)
+ "http://www.naver.com",
+ NET_NFC_SCHEMA_FULL_URI)) == NET_NFC_OK)
+ {
+ if( (error = net_nfc_create_ndef_message(&msg)) == NET_NFC_OK)
{
- if( (error = net_nfc_create_ndef_message(&msg)) == NET_NFC_OK)
- {
- if( (error = net_nfc_append_record_to_ndef_message(
+ if( (error = net_nfc_append_record_to_ndef_message(
msg,
record)) == NET_NFC_OK)
- {
- result = net_nfc_client_snep_send_client_request(
- target_info->handle,
- NET_NFC_SNEP_GET,
- msg,
- snep_send_request_cb,
- user_data);
- }
- }
+ {
+ result = net_nfc_client_snep_send_client_request(
+ target_info->handle,
+ NET_NFC_SNEP_GET,
+ msg,
+ snep_send_request_cb,
+ user_data);
+ }
}
+ }
if(result != NET_NFC_OK)
{
void net_nfc_test_snep_send_client_request_sync(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
/*
void net_nfc_test_snep_register_server(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_error_e result= NET_NFC_OK;
result = net_nfc_client_snep_register_server(
- "urn:nfc:xsn:samsung.com:testllcp",
- 16,
- snep_register_server_cb,
- user_data);
+ "urn:nfc:xsn:samsung.com:testllcp",
+ 16,
+ snep_register_server_cb,
+ user_data);
if(result != NET_NFC_OK)
{
}
void net_nfc_test_snep_unregister_server(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_error_e result= NET_NFC_OK;
result = net_nfc_client_snep_unregister_server(
- "urn:nfc:xsn:samsung.com:testllcp",
- 16);
+ "urn:nfc:xsn:samsung.com:testllcp",
+ 16);
if(result != NET_NFC_OK)
{
void net_nfc_test_snep_stop_service(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
/*
net_nfc_error_e result= NET_NFC_OK;
void net_nfc_test_snep_stop_service_sync(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_error_e result= NET_NFC_OK;
result = net_nfc_client_snep_stop_service_sync(
- target_info->handle,
- snep_handle);
+ target_info->handle,
+ snep_handle);
if(result != NET_NFC_OK)
{
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __NET_NFC_TEST_SNEP_H__
+#define __NET_NFC_TEST_SNEP_H__
+
+#include <glib.h>
+
+
+void net_nfc_test_snep_set_tag_discovered(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_snep_start_server(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_snep_start_server_sync(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_snep_start_client(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_snep_start_client_sync(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_snep_send_client_request(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_snep_send_client_request_sync(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_snep_register_server(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_snep_unregister_server(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_snep_stop_service(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_snep_stop_service_sync(gpointer data,
+ gpointer user_data);
+#endif
+
/*
-* Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
#include <glib-object.h>
static void run_next_callback(gpointer user_data)
{
- if (user_data)
+ if (user_data)
{
GCallback callback;
/********************** Function Calls ******************************/
void net_nfc_test_sys_handler_set_launch_popup_state(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_error_e result;
int enable = 1;
}
void net_nfc_test_sys_handler_get_launch_popup_state(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_error_e result;
int state = 0;
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __NET_NFC_TEST_SYS_HANDLER_H__
+#define __NET_NFC_TEST_SYS_HANDLER_H__
+
+#include <glib.h>
+
+void net_nfc_test_sys_handler_set_launch_popup_state(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_sys_handler_get_launch_popup_state(gpointer data,
+ gpointer user_data);
+
+#endif //__NET_NFC_TEST_SYS_HANDLER_H__
static void print_get_current_target_handle(net_nfc_target_handle_h handle);
static void is_tag_connected_completed(net_nfc_error_e result,
- net_nfc_target_type_e dev_type,
- void *user_data);
+ net_nfc_target_type_e dev_type,
+ void *user_data);
static void get_current_tag_info_completed(net_nfc_error_e result,
- net_nfc_target_info_h info,
- void *user_data);
+ net_nfc_target_info_h info,
+ void *user_data);
static void get_current_target_handle_completed(net_nfc_error_e result,
- net_nfc_target_handle_h handle,
- void *user_data);
+ net_nfc_target_handle_h handle,
+ void *user_data);
static void tag_detached(void *user_data);
static void tag_discovered(net_nfc_target_info_h info,
- void *user_data);
+ void *user_data);
static net_nfc_target_info_h global_info = NULL;
{
switch(dev_type)
{
- case NET_NFC_UNKNOWN_TARGET:
- return "Unknown Target";
- case NET_NFC_GENERIC_PICC:
- return "Generic PICC";
- case NET_NFC_ISO14443_A_PICC:
- return "ISO14443 PICC";
- case NET_NFC_ISO14443_4A_PICC:
- return "ISO14443 4A PICC";
- case NET_NFC_ISO14443_3A_PICC:
- return "ISO14443 3A PICC";
- case NET_NFC_MIFARE_MINI_PICC:
- return "Mifare mini PICC";
- case NET_NFC_MIFARE_1K_PICC:
- return "Mifare 1K PICC";
- case NET_NFC_MIFARE_4K_PICC:
- return "Mifare 4K PICC";
- case NET_NFC_MIFARE_ULTRA_PICC:
- return "Mifare Ultra PICC";
- case NET_NFC_MIFARE_DESFIRE_PICC:
- return "Mifare Desfire PICC";
- case NET_NFC_ISO14443_B_PICC:
- return "ISO14443 B PICC";
- case NET_NFC_ISO14443_4B_PICC:
- return "ISO14443 4B PICC";
- case NET_NFC_ISO14443_BPRIME_PICC:
- return "ISO14443 BPRIME PICC";
- case NET_NFC_FELICA_PICC:
- return "Felica PICC";
- case NET_NFC_JEWEL_PICC:
- return "Jewel PICC";
- case NET_NFC_ISO15693_PICC:
- return "ISO15693 PICC";
- case NET_NFC_NFCIP1_TARGET:
- return "NFCIP1 Target";
- case NET_NFC_NFCIP1_INITIATOR:
- return "NFCIP1 Initiator";
- default:
- break;
+ case NET_NFC_UNKNOWN_TARGET:
+ return "Unknown Target";
+ case NET_NFC_GENERIC_PICC:
+ return "Generic PICC";
+ case NET_NFC_ISO14443_A_PICC:
+ return "ISO14443 PICC";
+ case NET_NFC_ISO14443_4A_PICC:
+ return "ISO14443 4A PICC";
+ case NET_NFC_ISO14443_3A_PICC:
+ return "ISO14443 3A PICC";
+ case NET_NFC_MIFARE_MINI_PICC:
+ return "Mifare mini PICC";
+ case NET_NFC_MIFARE_1K_PICC:
+ return "Mifare 1K PICC";
+ case NET_NFC_MIFARE_4K_PICC:
+ return "Mifare 4K PICC";
+ case NET_NFC_MIFARE_ULTRA_PICC:
+ return "Mifare Ultra PICC";
+ case NET_NFC_MIFARE_DESFIRE_PICC:
+ return "Mifare Desfire PICC";
+ case NET_NFC_ISO14443_B_PICC:
+ return "ISO14443 B PICC";
+ case NET_NFC_ISO14443_4B_PICC:
+ return "ISO14443 4B PICC";
+ case NET_NFC_ISO14443_BPRIME_PICC:
+ return "ISO14443 BPRIME PICC";
+ case NET_NFC_FELICA_PICC:
+ return "Felica PICC";
+ case NET_NFC_JEWEL_PICC:
+ return "Jewel PICC";
+ case NET_NFC_ISO15693_PICC:
+ return "ISO15693 PICC";
+ case NET_NFC_NFCIP1_TARGET:
+ return "NFCIP1 Target";
+ case NET_NFC_NFCIP1_INITIATOR:
+ return "NFCIP1 Initiator";
+ default:
+ break;
}
return "Invalid Target";
}
handle_id = GPOINTER_TO_UINT(handle);
g_print("Tag handle %x, Current Tag handle %x\n",
- global_handle_id,
- handle_id);
+ global_handle_id,
+ handle_id);
if (global_handle_id == handle_id)
g_print("Current Tag is matched discovered Tag\n");
}
}
static void is_tag_connected_completed(net_nfc_error_e result,
- net_nfc_target_type_e dev_type,
- void *user_data)
+ net_nfc_target_type_e dev_type,
+ void *user_data)
{
g_print("IsTagConnected Completed %d\n", result);
g_print("--- dev type : %s (%d)\n", tag_type_to_string(dev_type),
- dev_type);
+ dev_type);
if (result == NET_NFC_OK)
print_is_tag_connected(dev_type);
}
static void get_current_tag_info_completed(net_nfc_error_e result,
- net_nfc_target_info_h info,
- void *user_data)
+ net_nfc_target_info_h info,
+ void *user_data)
{
g_print("GetCurrentTagInfo Completed %d\n", result);
}
static void get_current_target_handle_completed(net_nfc_error_e result,
- net_nfc_target_handle_h handle,
- void *user_data)
+ net_nfc_target_handle_h handle,
+ void *user_data)
{
g_print("GetCurrentTargetHandle Completed %d\n", result);
static void tag_discovered(net_nfc_target_info_h info,
- void *user_data)
+ void *user_data)
{
g_print("TagDiscovered\n");
void net_nfc_test_tag_is_tag_connected(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_client_tag_is_tag_connected(is_tag_connected_completed,
- user_data);
+ user_data);
}
void net_nfc_test_tag_get_current_tag_info(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_client_tag_get_current_tag_info(get_current_tag_info_completed,
- user_data);
+ user_data);
}
void net_nfc_test_tag_get_current_target_handle(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_client_tag_get_current_target_handle(
- get_current_target_handle_completed,
- user_data);
+ get_current_target_handle_completed,
+ user_data);
}
void net_nfc_test_tag_is_tag_connected_sync(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_error_e result;
net_nfc_target_type_e dev_type;
}
void net_nfc_test_tag_get_current_tag_info_sync(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_error_e result;
net_nfc_target_info_h info;
}
void net_nfc_test_tag_get_current_target_handle_sync(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_error_e result;
net_nfc_target_handle_h handle;
}
void net_nfc_test_tag_set_tag_discovered(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
g_print("Waiting for TagDiscovered Signal\n");
}
void net_nfc_test_tag_set_tag_detached(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
g_print("Waiting for TagDetached Singal\n");
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_TEST_TAG_H__
+#define __NET_NFC_TEST_TAG_H__
+
+#include <glib.h>
+
+#include "net_nfc_target_info.h"
+
+void net_nfc_test_tag_is_tag_connected(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_tag_get_current_tag_info(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_tag_get_current_target_handle(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_tag_is_tag_connected_sync(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_tag_get_current_tag_info_sync(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_tag_get_current_target_handle_sync(gpointer data,
+ gpointer user_data);
+
+/* waiting for signal */
+void net_nfc_test_tag_set_tag_discovered(gpointer data,
+ gpointer user_data);
+
+net_nfc_target_info_h net_nfc_test_tag_get_target_info(void);
+
+void net_nfc_test_tag_set_tag_detached(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_tag_set_filter(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_tag_get_filter(gpointer data,
+ gpointer user_data);
+
+
+#endif //__NET_NFC_TEST_TAG_H__
/*
-* Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
#include "net_nfc_test_tag_felica.h"
#include "net_nfc_typedef_internal.h"
static void run_next_callback(gpointer user_data);
static void felica_cb(net_nfc_error_e result,
- data_h resp_data,
- void *user_data);
+ data_h resp_data,
+ void *user_data);
static net_nfc_target_handle_h get_handle()
}
static void felica_cb(net_nfc_error_e result,
- data_h resp_data,
- void *user_data)
+ data_h resp_data,
+ void *user_data)
{
g_print("felica_cb Completed %d\n", result);
}
void net_nfc_test_felica_poll(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_error_e result = NET_NFC_OK;
net_nfc_target_handle_h handle = NULL;
if (handle == NULL)
return ;
- result = net_nfc_client_felica_poll(handle,
- req_code,
- time_slot,
- felica_cb,
- user_data);
+ result = net_nfc_client_felica_poll(handle, req_code, time_slot, felica_cb, user_data);
}
void net_nfc_test_felica_request_service(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_error_e result = NET_NFC_OK;
net_nfc_target_handle_h handle = NULL;
return ;
result = net_nfc_client_felica_request_service(handle,
- number_of_area_service,
- area_service_list,
- number_of_services,
- felica_cb,
- user_data);
+ number_of_area_service,
+ area_service_list,
+ number_of_services,
+ felica_cb,
+ user_data);
}
void net_nfc_test_felica_request_response(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_error_e result = NET_NFC_OK;
net_nfc_target_handle_h handle = NULL;
if (handle == NULL)
return ;
- result = net_nfc_client_felica_request_response(handle,
- felica_cb,
- user_data);
+ result = net_nfc_client_felica_request_response(handle, felica_cb, user_data);
}
void net_nfc_test_felica_read_without_encryption(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_error_e result = NET_NFC_OK;
net_nfc_target_handle_h handle = NULL;
return ;
result = net_nfc_client_felica_read_without_encryption(handle,
- number_of_services,
- service_list,
- number_of_blocks,
- block_list,
- felica_cb,
- user_data);
+ number_of_services,
+ service_list,
+ number_of_blocks,
+ block_list,
+ felica_cb,
+ user_data);
}
void net_nfc_test_felica_write_without_encryption(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_error_e result = NET_NFC_OK;
net_nfc_target_handle_h handle = NULL;
return ;
result = net_nfc_client_felica_write_without_encryption(handle,
- number_of_services,
- service_list,
- number_of_blocks,
- block_list,
- data_to_write,
- felica_cb,
- user_data);
+ number_of_services,
+ service_list,
+ number_of_blocks,
+ block_list,
+ data_to_write,
+ felica_cb,
+ user_data);
}
void net_nfc_test_felica_request_system_code(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_error_e result = NET_NFC_OK;
net_nfc_target_handle_h handle = NULL;
if (handle == NULL)
return ;
- result = net_nfc_client_felica_request_system_code(handle,
- felica_cb,
- user_data);
+ result = net_nfc_client_felica_request_system_code(handle, felica_cb, user_data);
}
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __NET_NFC_TEST_FELICA_TAG_H__
+#define __NET_NFC_TEST_FELICA_TAG_H__
+
+#include <glib.h>
+
+
+void net_nfc_test_felica_poll(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_felica_request_service(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_felica_request_response(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_felica_read_without_encryption(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_felica_write_without_encryption(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_felica_request_system_code(gpointer data,
+ gpointer user_data);
+
+#endif
*/
-#include "net_nfc_tag_mifare.h"
+#include "net_nfc_client_tag_mifare.h"
#include "net_nfc_test_tag_mifare.h"
#include "net_nfc_target_info.h"
#include "net_nfc_typedef_internal.h"
static net_nfc_target_handle_h tag_get_handle(void);
static void mifare_read_cb(net_nfc_error_e result,
- data_h resp_data,
- void *user_data);
+ data_h resp_data,
+ void *user_data);
static void mifare_write_block_cb(net_nfc_error_e result, void* user_data);
}
static void mifare_read_cb(net_nfc_error_e result,
- data_h resp_data,
- void *user_data)
+ data_h resp_data,
+ void *user_data)
{
g_print("mifare_read_cb Completed %d\n", result);
print_received_data(resp_data);
void net_nfc_test_tag_mifare_read(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_error_e result = NET_NFC_OK;
net_nfc_target_handle_h handle = NULL;
g_print("Handle is %#x\n", GPOINTER_TO_UINT(handle));
result = net_nfc_client_mifare_read(handle,
- block_index,
- mifare_read_cb,
- user_data);
+ block_index,
+ mifare_read_cb,
+ user_data);
}
void net_nfc_test_tag_mifare_write_block(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_error_e result = NET_NFC_OK;
net_nfc_target_handle_h handle = NULL;
g_print("Handle is %#x\n", GPOINTER_TO_UINT(handle));
result = net_nfc_client_mifare_write_block(handle,
- block_index,
- (data_h)& write_data,
- mifare_write_block_cb,
- user_data);
+ block_index,
+ (data_h)& write_data,
+ mifare_write_block_cb,
+ user_data);
}
void net_nfc_test_tag_mifare_write_page(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_error_e result = NET_NFC_OK;
net_nfc_target_handle_h handle = NULL;
g_print("Handle is %#x\n", GPOINTER_TO_UINT(handle));
result = net_nfc_client_mifare_write_page(handle,
- block_index,
- (data_h)& write_data,
- mifare_write_page_cb,
- user_data);
+ block_index,
+ (data_h)& write_data,
+ mifare_write_page_cb,
+ user_data);
}
void net_nfc_test_tag_mifare_increment(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_error_e result = NET_NFC_OK;
net_nfc_target_handle_h handle = NULL;
return;
}
g_print("Handle is %#x\n", GPOINTER_TO_UINT(handle));
+
result = net_nfc_client_mifare_increment(handle,
- block_index,
- value,
- mifare_write_mifare_incr_cb,
- user_data);
+ block_index,
+ value,
+ mifare_write_mifare_incr_cb,
+ user_data);
}
void net_nfc_test_tag_mifare_decrement(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_error_e result = NET_NFC_OK;
net_nfc_target_handle_h handle = NULL;
return;
}
g_print("Handle is %#x\n", GPOINTER_TO_UINT(handle));
+
result = net_nfc_client_mifare_decrement(handle,
- block_index,
- value,
- mifare_write_mifare_decr_cb,
- user_data);
+ block_index,
+ value,
+ mifare_write_mifare_decr_cb,
+ user_data);
}
void net_nfc_test_tag_mifare_transfer(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_error_e result = NET_NFC_OK;
net_nfc_target_handle_h handle = NULL;
return;
}
g_print("Handle is %#x\n", GPOINTER_TO_UINT(handle));
+
result = net_nfc_client_mifare_transfer(handle,
- block_index,
- mifare_write_mifare_transfer_cb,
- user_data);
+ block_index,
+ mifare_write_mifare_transfer_cb,
+ user_data);
}
void net_nfc_test_tag_mifare_restore(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_error_e result = NET_NFC_OK;
net_nfc_target_handle_h handle = NULL;
g_print("Handle is %#x\n", GPOINTER_TO_UINT(handle));
result = net_nfc_client_mifare_restore(handle,
- block_index,
- mifare_write_mifare_restore_cb,
- user_data);
+ block_index,
+ mifare_write_mifare_restore_cb,
+ user_data);
}
void net_nfc_test_tag_mifare_authenticate_with_keyA(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_error_e result = NET_NFC_OK;
net_nfc_target_handle_h handle = NULL;
g_print("default key create %d", result);
result = net_nfc_client_mifare_authenticate_with_keyA(
- handle,
- sector_index,
- auth_key,
- mifare_write_auth_keyA_cb,
- user_data);
+ handle,
+ sector_index,
+ auth_key,
+ mifare_write_auth_keyA_cb,
+ user_data);
}
void net_nfc_test_tag_mifare_authenticate_with_keyB(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_error_e result = NET_NFC_OK;
net_nfc_target_handle_h handle = NULL;
g_print("default key create %d", result);
result = net_nfc_client_mifare_authenticate_with_keyB(
- handle,
- sector_index,
- auth_key,
- mifare_write_auth_keyB_cb,
- user_data);
+ handle,
+ sector_index,
+ auth_key,
+ mifare_write_auth_keyB_cb,
+ user_data);
}
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __NET_NFC_TEST_TAG_MIFARE_H__
+#define __NET_NFC_TEST_TAG_MIFARE_H__
+
+#include <glib.h>
+
+
+void net_nfc_test_tag_mifare_read(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_tag_mifare_authenticate_with_keyA(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_tag_mifare_authenticate_with_keyB(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_tag_mifare_write_block(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_tag_mifare_write_page(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_tag_mifare_increment(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_tag_mifare_decrement(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_tag_mifare_transfer(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_tag_mifare_restore(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_tag_mifare_create_default_key(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_tag_mifare_create_net_nfc_forum_key(gpointer data,
+ gpointer user_data);
+
+#endif
+
static void run_next_callback(gpointer user_data);
static void sim_test_completed(net_nfc_error_e result,
- void *user_data);
+ void *user_data);
static void prbs_test_completed(net_nfc_error_e result,
- void *user_data);
+ void *user_data);
static void get_firmware_version_completed(net_nfc_error_e result,
- char *version,
- void *user_data);
+ char *version,
+ void *user_data);
static void set_ee_data_completed(net_nfc_error_e reuslt,
- void *user_data);
+ void *user_data);
static void sim_test_completed(net_nfc_error_e result,
- void *user_data)
+ void *user_data)
{
g_print("SimTestCompleted Completed %d\n", result);
run_next_callback(user_data);
static void prbs_test_completed(net_nfc_error_e result,
- void *user_data)
+ void *user_data)
{
g_print("PrbsTest Completed %d\n", result);
run_next_callback(user_data);
static void get_firmware_version_completed(net_nfc_error_e result,
- char *version,
- void *user_data)
+ char *version,
+ void *user_data)
{
g_print("GetFirmwareVersion Completed %d: %s\n", result, version);
run_next_callback(user_data);
static void set_ee_data_completed(net_nfc_error_e result,
- void *user_data)
+ void *user_data)
{
g_print("SetEeData Completed %d\n", result);
run_next_callback(user_data);
void net_nfc_test_test_sim_test(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_client_test_sim_test(sim_test_completed, user_data);
}
void net_nfc_test_test_prbs_test(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
/* FIXME : fill right value */
uint32_t tech = 0;
uint32_t rate = 0;
net_nfc_client_test_prbs_test(tech,
- rate,
- prbs_test_completed,
- user_data);
+ rate,
+ prbs_test_completed,
+ user_data);
}
void net_nfc_test_test_get_firmware_version(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_client_test_get_firmware_version(
- get_firmware_version_completed,
- user_data);
+ get_firmware_version_completed,
+ user_data);
}
void net_nfc_test_test_set_ee_data(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
/* FIXME : fill right value */
data_h ee_data = (data_h)data;
net_nfc_client_test_set_ee_data(mode,
- reg_id,
- ee_data,
- set_ee_data_completed,
- user_data);
+ reg_id,
+ ee_data,
+ set_ee_data_completed,
+ user_data);
}
void net_nfc_test_test_sim_test_sync(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_error_e result;
result = net_nfc_client_test_sim_test_sync();
void net_nfc_test_test_prbs_test_sync(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_error_e result;
void net_nfc_test_test_get_firmware_version_sync(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_error_e result;
char *version = NULL;
void net_nfc_test_test_set_ee_data_sync(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_error_e result;
data_h ee_data = (data_h)data;
result = net_nfc_client_test_set_ee_data_sync(mode,
- reg_id,
- ee_data);
+ reg_id,
+ ee_data);
g_print("SetEeData: %d\n", result);
run_next_callback(user_data);
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_TEST_TEST_H__
+#define __NET_NFC_TEST_TEST_H__
+
+#include <glib.h>
+
+void net_nfc_test_test_sim_test(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_test_prbs_test(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_test_get_firmware_version(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_test_set_ee_data(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_test_sim_test_sync(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_test_prbs_test_sync(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_test_get_firmware_version_sync(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_test_set_ee_data_sync(gpointer data,
+ gpointer user_data);
+
+#endif //__NET_NFC_TEST_TEST_H__
static void call_transceive_data_cb(net_nfc_error_e result,
- data_h resp_data,
- void *user_data);
+ data_h resp_data,
+ void *user_data);
static void call_transceive_cb(net_nfc_error_e result,
- void* user_data);
+ void* user_data);
static void run_next_callback(gpointer user_data);
static void call_transceive_cb(net_nfc_error_e result,
- void* user_data)
+ void* user_data)
{
g_print("call_transceive_cb Completed %d\n", result);
}
static void call_transceive_data_cb(net_nfc_error_e result,
- data_h resp_data,
- void *user_data)
+ data_h resp_data,
+ void *user_data)
{
g_print("call_transceive_data_cb Completed %d\n", result);
print_received_data(resp_data);
}
void net_nfc_test_transceive(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_error_e result = NET_NFC_OK;
data_s raw_data = {NULL,};
net_nfc_get_tag_handle(info, &handle);
result =net_nfc_client_transceive(handle,
- (data_h)&raw_data,
- call_transceive_cb,
- user_data);
+ (data_h)&raw_data,
+ call_transceive_cb,
+ user_data);
}
void net_nfc_test_transceive_sync(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_error_e result = NET_NFC_OK;
data_s raw_data = {NULL,};
}
void net_nfc_test_transceive_data(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_error_e result = NET_NFC_OK;
data_s raw_data = {NULL,};
net_nfc_get_tag_handle(info, &handle);
result = net_nfc_client_transceive_data(handle,
- (data_h) &raw_data,
- call_transceive_data_cb,
- user_data);
+ (data_h) &raw_data,
+ call_transceive_data_cb,
+ user_data);
}
void net_nfc_test_transceive_data_sync(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
net_nfc_error_e result = NET_NFC_OK;
data_s raw_data = {NULL};
net_nfc_get_tag_handle(info, &handle);
- result = net_nfc_client_transceive_data_sync(handle,
- &raw_data,
- &response);
- print_received_data(response);
+ result = net_nfc_client_transceive_data_sync(handle, &raw_data, &response);
+
+ if (NET_NFC_OK == result)
+ print_received_data(response);
}
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __NET_NFC_TEST_TRANSCEIVE_H__
+#define __NET_NFC_TEST_TRANSCEIVE_H__
+
+#include <glib.h>
+
+
+void net_nfc_test_transceive(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_transceive_sync(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_transceive_data(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_transceive_data_sync(gpointer data,
+ gpointer user_data);
+
+#endif
+
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _NET_NFC_TEST_UTIL_H_
+#define _NET_NFC_TEST_UTIL_H_
+
+#include <glib-object.h>
+#include <string.h>
+#include "net_nfc_data.h"
+
+
+void print_received_data(data_h data);
+
+
+#endif
--- /dev/null
+LINK_DIRECTORIES(${CMAKE_BINARY_DIR})
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/common/include)
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/client/include)
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include)
+
+SET(BT_PARING "bt-paring")
+
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/ BT_SRC)
+
+pkg_check_modules(bt_pkgs REQUIRED bluetooth-api)
+
+FOREACH(flag ${bt_pkgs_CFLAGS})
+ SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+
+ADD_EXECUTABLE(${BT_PARING} ${BT_SRC})
+
+TARGET_LINK_LIBRARIES(${BT_PARING} ${bt_pkgs_LDFLAGS} pthread nfc)
+
+INSTALL(TARGETS ${BT_PARING} DESTINATION bin)
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <bluetooth-api.h>
+#include <glib.h>
+
+#include <net_nfc.h>
+
+#include <pthread.h>
+
+void bt_event_callback(int event, bluetooth_event_param_t* param, void *user_data);
+void bt_test_bond_device(bluetooth_device_address_t* bt_address);
+GMainLoop* main_loop = NULL;
+
+void initialize()
+{
+ if(!g_thread_supported())
+ {
+ g_thread_init(NULL);
+ }
+
+ dbus_g_thread_init();
+ g_type_init();
+}
+
+
+int main()
+{
+ initialize();
+
+ //bluetooth_enable_adapter();
+
+ //main_loop = g_main_loop_new(NULL, FALSE);
+ //g_main_loop_run(main_loop);
+
+#if 1
+
+ ndef_message_h ndef_message = NULL;
+ net_nfc_conn_handover_info_h conn_handover_info = NULL;
+
+
+ if(net_nfc_retrieve_current_ndef_message(&ndef_message) == NET_NFC_OK)
+ {
+ printf("retrieve ndef message from nfc storage \n");
+
+ int count = 0;
+
+ net_nfc_get_ndef_message_record_count(ndef_message, &count);
+
+ int i = 0;
+ while(i < count)
+ {
+ ndef_record_h record = NULL;
+ net_nfc_get_record_by_index(ndef_message, i++, &record);
+
+ if (record != NULL)
+ {
+
+ net_nfc_record_tnf_e TNF = NET_NFC_RECORD_EMPTY;
+ data_h record_type = NULL;
+
+ if ((net_nfc_get_record_tnf(record, &TNF) == NET_NFC_OK)
+ && (net_nfc_get_record_type(record, &record_type) == NET_NFC_OK ))
+ {
+
+ uint8_t* buffer = net_nfc_get_data_buffer(record_type);
+ int buffer_length = net_nfc_get_data_length(record_type);
+
+ // record is WTK and Hs
+ if((TNF == NET_NFC_RECORD_WELL_KNOWN_TYPE) && (buffer != NULL)
+ && (buffer_length > 1) && (buffer[0] == 'H') && (buffer[1] == 's'))
+ {
+ printf("record is found \n");
+ net_nfc_parse_connection_handover_ndef_message(ndef_message, &conn_handover_info);
+
+ if (conn_handover_info != NULL)
+ {
+ uint8_t carrier_count = 0;
+ net_nfc_get_connection_handover_alternative_carrier_count(conn_handover_info, &carrier_count);
+
+ int j = 0;
+ while(j < carrier_count)
+ {
+ net_nfc_conn_handover_carrier_info_h carrier_info = NULL;
+ net_nfc_get_connection_handover_carrier_handle_by_index(conn_handover_info, j++, &carrier_info);
+
+ if(carrier_info != NULL)
+ {
+ data_h configuration = NULL;
+ net_nfc_get_carrier_configuration(carrier_info, &configuration);
+
+ if(configuration != NULL)
+ {
+ uint8_t* buffer = net_nfc_get_data_buffer(configuration);
+ if(buffer != NULL)
+ {
+ printf("bt addr [%X][%X][%X][%X][%X][%X] \n", buffer[2], buffer[3], buffer[4], buffer[5], buffer[6], buffer[7]);
+ bluetooth_device_address_t bt_address = {{buffer[2], buffer[3], buffer[4], buffer[5], buffer[6], buffer[7]}};
+ bt_test_bond_device(&bt_address);
+ }
+ else
+ printf("buffer is NULL");
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ }
+
+#endif
+ return 0;
+}
+
+void bt_test_bond_device(bluetooth_device_address_t* bt_address)
+{
+ int ret_val;
+
+ ret_val = bluetooth_register_callback(bt_event_callback, NULL);
+
+ if (ret_val >= BLUETOOTH_ERROR_NONE)
+ {
+ printf("bluetooth_register_callback returned Success");
+ }
+ else
+ {
+ printf("bluetooth_register_callback returned failiure [0x%04x]", ret_val);
+ return ;
+ }
+
+ ret_val = bluetooth_check_adapter();
+
+ if (ret_val < BLUETOOTH_ERROR_NONE)
+ {
+ printf("bluetooth_check_adapter returned failiure [0x%04x]", ret_val);
+ }
+ else
+ {
+ printf("BT state [0x%04x]", ret_val);
+ }
+
+ int error = 0;
+
+ if((error = bluetooth_bond_device(bt_address)) < 0)
+ {
+ printf("Api failed: %d", error);
+ }
+ else
+ {
+ main_loop = g_main_loop_new(NULL, FALSE);
+ g_main_loop_run(main_loop);
+ }
+
+}
+
+void bt_event_callback(int event, bluetooth_event_param_t* param, void *user_data)
+{
+ switch(event)
+ {
+ case BLUETOOTH_EVENT_ENABLED:
+ printf("BLUETOOTH_EVENT_ENABLED:\n");
+ break;
+ case BLUETOOTH_EVENT_DISABLED:
+ printf("BLUETOOTH_EVENT_DISABLED:\n");
+ break;
+ case BLUETOOTH_EVENT_LOCAL_NAME_CHANGED:
+ printf("BLUETOOTH_EVENT_LOCAL_NAME_CHANGED:\n");
+ break;
+ case BLUETOOTH_EVENT_DISCOVERY_STARTED:
+ printf("BLUETOOTH_EVENT_DISCOVERY_STARTED:\n");
+ break;
+ case BLUETOOTH_EVENT_REMOTE_DEVICE_FOUND:
+ printf("BLUETOOTH_EVENT_REMOTE_DEVICE_FOUND:\n");
+ break;
+ case BLUETOOTH_EVENT_REMOTE_DEVICE_NAME_UPDATED:
+ printf("BLUETOOTH_EVENT_REMOTE_DEVICE_NAME_UPDATED:\n");
+ break;
+ case BLUETOOTH_EVENT_DISCOVERY_FINISHED:
+ printf("BLUETOOTH_EVENT_DISCOVERY_FINISHED:\n");
+ break;
+ case BLUETOOTH_EVENT_BONDING_FINISHED:
+ printf("BLUETOOTH_EVENT_BONDING_FINISHED:\n");
+
+ if (param->result >= BLUETOOTH_ERROR_NONE)
+ {
+ bluetooth_device_info_t *device_info = NULL;
+ device_info = (bluetooth_device_info_t *)param->param_data;
+ printf("dev [%s] [%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X] mjr[%#x] min[%#x] srv[%#x] \n", device_info->device_name.name, \
+ device_info->device_address.addr[0], device_info->device_address.addr[1], device_info->device_address.addr[2], \
+ device_info->device_address.addr[3], device_info->device_address.addr[4], device_info->device_address.addr[5], \
+ device_info->device_class.major_class, device_info->device_class.minor_class, device_info->device_class.service_class);
+ }
+
+ g_main_loop_quit (main_loop);
+
+ break;
+ default:
+ printf("BLUETOOTH_EVENT = [%d]:\n", event);
+ break;
+ }
+}
--- /dev/null
+LINK_DIRECTORIES(${CMAKE_BINARY_DIR})
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/common/include)
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/client/include)
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include)
+
+SET(NDEF_TOOL "ndef-tool")
+
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/ TOOL_SRC)
+
+pkg_check_modules(tool_pkgs REQUIRED glib-2.0 gobject-2.0)
+
+FOREACH(flag ${tool_pkgs_CFLAGS})
+ SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+
+ADD_EXECUTABLE(${NDEF_TOOL} ${TOOL_SRC})
+
+TARGET_LINK_LIBRARIES(${NDEF_TOOL} ${tool_pkgs_LDFLAGS} pthread dl rt nfc)
+
+INSTALL(TARGETS ${NDEF_TOOL} DESTINATION bin)
+
+
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#include <stddef.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+#include "net_nfc.h"
+#include "net_nfc_sign_record.h"
+#include "ndef-tool.h"
+
+typedef struct _net_nfc_sub_field_s
+{
+ uint16_t length;
+ uint8_t value[0];
+}
+__attribute__((packed)) net_nfc_sub_field_s;
+
+typedef struct _net_nfc_signature_record_s
+{
+ uint8_t version;
+ uint8_t sign_type : 7;
+ uint8_t uri_present : 1;
+ net_nfc_sub_field_s signature;
+}
+__attribute__((packed)) net_nfc_signature_record_s;
+
+typedef struct _net_nfc_certificate_chain_s
+{
+ uint8_t num_of_certs : 4;
+ uint8_t cert_format : 3;
+ uint8_t uri_present : 1;
+ uint8_t cert_store[0];
+}
+__attribute__((packed)) net_nfc_certificate_chain_s;
+
+void _display_ndef_message(ndef_message_h msg);
+
+static void _display_buffer(char *title, uint8_t *buffer, uint32_t length)
+{
+ int32_t i;
+
+ if (length > 0)
+ {
+ fprintf(stdout, " %s[%d] = {", title, length);
+
+ for (i = 0; i < length; i++)
+ {
+ if ((i % 16) == 0)
+ fprintf(stdout, "\n");
+
+ if ((i % 8) == 0)
+ fprintf(stdout, " ");
+
+ fprintf(stdout, "%02X ", buffer[i]);
+ }
+
+ fprintf(stdout, "\n };\n");
+ }
+ else
+ {
+ fprintf(stdout, " %s[%d] = Empty", title, length);
+ }
+}
+
+static void _display_id(ndef_record_h record)
+{
+ data_h data = NULL;
+
+ net_nfc_get_record_id(record, &data);
+ if (net_nfc_get_data_length(data) > 0)
+ {
+ char temp_buffer[1024] = { 0, };
+
+ memcpy(temp_buffer, (void *)net_nfc_get_data_buffer(data), net_nfc_get_data_length(data));
+ fprintf(stdout, " ID string : %s\n", temp_buffer);
+ }
+}
+
+static void _display_signature(ndef_record_h record)
+{
+ data_h data = NULL;
+
+ _display_id(record);
+
+ net_nfc_get_record_payload(record, &data);
+ if (net_nfc_get_data_length(data) > 0)
+ {
+ int32_t i;
+ char temp_buffer[1024];
+ net_nfc_signature_record_s *sign = (net_nfc_signature_record_s *)net_nfc_get_data_buffer(data);
+
+ fprintf(stdout, " Version : %d\n", sign->version);
+ fprintf(stdout, " Signature URI present : %s\n", sign->uri_present ? "present" : "not present");
+
+ switch (sign->sign_type)
+ {
+ case NET_NFC_SIGN_TYPE_NO_SIGN :
+ fprintf(stdout, " Signing method : Not signed (%d)\n", sign->sign_type);
+ break;
+
+ case NET_NFC_SIGN_TYPE_PKCS_1 :
+ fprintf(stdout, " Signing method : RSASSA-PSS with SHA1 (%d)\n", sign->sign_type);
+ break;
+
+ case NET_NFC_SIGN_TYPE_PKCS_1_V_1_5 :
+ fprintf(stdout, " Signing method : PKCS #1 v1.5 with SHA1 (%d)\n", sign->sign_type);
+ break;
+
+ case NET_NFC_SIGN_TYPE_DSA :
+ fprintf(stdout, " Signing method : DSA (%d)\n", sign->sign_type);
+ break;
+
+ case NET_NFC_SIGN_TYPE_ECDSA :
+ fprintf(stdout, " Signing method : ECDSA (%d)\n", sign->sign_type);
+ break;
+
+ default :
+ fprintf(stdout, " Signing method : Unknown (%d)\n", sign->sign_type);
+ break;
+ }
+
+ if (sign->uri_present)
+ {
+ memset(temp_buffer, 0, sizeof(temp_buffer));
+ memcpy(temp_buffer, sign->signature.value, sign->signature.length);
+ fprintf(stdout, " URI : %s\n", temp_buffer);
+ }
+ else
+ {
+ _display_buffer("Signature", sign->signature.value, sign->signature.length);
+ }
+
+ net_nfc_certificate_chain_s *chain = (net_nfc_certificate_chain_s *)(sign->signature.value + sign->signature.length);
+ fprintf(stdout, " Cert. URI : %s\n", chain->uri_present ? "present" : "not present");
+
+ switch (chain->cert_format)
+ {
+ case NET_NFC_CERT_FORMAT_X_509 :
+ fprintf(stdout, " Cert. format : X.509 (%d)\n", chain->cert_format);
+ break;
+
+ case NET_NFC_CERT_FORMAT_X9_86 :
+ fprintf(stdout, " Cert. format : X9.86 (%d)\n", chain->cert_format);
+ break;
+
+ default :
+ fprintf(stdout, " Cert. format : Unknown (%d)\n", chain->cert_format);
+ break;
+ }
+
+ fprintf(stdout, " Cert. count : %d\n", chain->num_of_certs);
+
+ net_nfc_sub_field_s *field = NULL;
+
+ for (i = 0, field = (net_nfc_sub_field_s *)chain->cert_store; i < chain->num_of_certs; i++, field = (net_nfc_sub_field_s *)(field->value + field->length))
+ {
+ memset(temp_buffer, 0, sizeof(temp_buffer));
+ snprintf(temp_buffer, sizeof(temp_buffer), "Certificate %d", i);
+ _display_buffer(temp_buffer, field->value, field->length);
+ }
+
+ if (chain->uri_present)
+ {
+ memset(temp_buffer, 0, sizeof(temp_buffer));
+ memcpy(temp_buffer, field->value, field->length);
+ fprintf(stdout, " URI : %s\n", temp_buffer);
+ }
+ }
+}
+
+static void _display_smart_poster(ndef_record_h record)
+{
+ data_h data = NULL;
+
+ _display_id(record);
+
+ net_nfc_get_record_payload(record, &data);
+ if (net_nfc_get_data_length(data) > 0)
+ {
+ char temp_buffer[1024] = { 0, };
+
+ memcpy(temp_buffer, (void *)net_nfc_get_data_buffer(data), net_nfc_get_data_length(data));
+ fprintf(stdout, " Type string : %s (Signature)\n", temp_buffer);
+ }
+}
+
+static void _display_text(ndef_record_h record)
+{
+ data_h data = NULL;
+ net_nfc_encode_type_e encoding = 0;
+
+ _display_id(record);
+
+ net_nfc_get_encoding_type_from_text_record(record, &encoding);
+ switch (encoding)
+ {
+ case NET_NFC_ENCODE_UTF_8 :
+ fprintf(stdout, " Encoding : UTF-8\n");
+ break;
+
+ case NET_NFC_ENCODE_UTF_16 :
+ fprintf(stdout, " Encoding : UTF-16\n");
+ break;
+ }
+
+ net_nfc_get_record_payload(record, &data);
+ if (net_nfc_get_data_length(data) > 0)
+ {
+ uint8_t *buffer = net_nfc_get_data_buffer(data);
+ uint32_t length = net_nfc_get_data_length(data);
+ char temp_buffer[1024] = { 0, };
+ int code_length = buffer[0] & 0x3F;
+
+ memcpy(temp_buffer, buffer + 1, code_length);
+ fprintf(stdout, " Language code[%d] : %s\n", code_length, temp_buffer);
+
+ memset(temp_buffer, 0, sizeof(temp_buffer));
+
+ memcpy(temp_buffer, buffer + code_length + 1, length - code_length - 1);
+ fprintf(stdout, " Text[%d] : %s\n", length - code_length - 1, temp_buffer);
+ }
+}
+
+static void _display_uri(ndef_record_h record)
+{
+ data_h data = NULL;
+
+ _display_id(record);
+
+ net_nfc_get_record_payload(record, &data);
+ if (net_nfc_get_data_length(data) > 0)
+ {
+ uint8_t *buffer = net_nfc_get_data_buffer(data);
+ uint32_t length = net_nfc_get_data_length(data);
+ char temp_buffer[1024] = { 0, };
+ char *uri = NULL;
+
+ fprintf(stdout, " URI scheme : 0x%02X\n", buffer[0]);
+
+ memcpy(temp_buffer, buffer + 1, length - 1);
+ fprintf(stdout, " Raw URI payload[%d] : %s\n", length - 1, temp_buffer);
+
+ net_nfc_create_uri_string_from_uri_record(record, &uri);
+ if (uri != NULL)
+ {
+ fprintf(stdout, " Resolved URI[%d] : %s\n", strlen(uri), uri);
+ free(uri);
+ }
+ }
+}
+
+static void _display_hs(ndef_record_h record)
+{
+ data_h data = NULL;
+
+ _display_id(record);
+
+ net_nfc_get_record_payload(record, &data);
+ if (net_nfc_get_data_length(data) > 0)
+ {
+ uint8_t *buffer = net_nfc_get_data_buffer(data);
+ uint32_t length = net_nfc_get_data_length(data);
+
+ fprintf(stdout, " Version : %d.%d\n", ((*buffer) >> 4) & 0x0F,
+ (*buffer) & 0x0F);
+ fprintf(stdout, " -- Containing NDEF message -- \n");
+
+ ndef_message_h msg;
+ data_h temp;
+
+ net_nfc_create_data(&temp, buffer + 1, length - 1);
+ net_nfc_create_ndef_message_from_rawdata(&msg, temp);
+
+ _display_ndef_message(msg);
+
+ net_nfc_free_ndef_message(msg);
+ net_nfc_free_data(temp);
+ }
+}
+
+static void _display_hr(ndef_record_h record)
+{
+ data_h data = NULL;
+
+ _display_id(record);
+
+ net_nfc_get_record_payload(record, &data);
+ if (net_nfc_get_data_length(data) > 0)
+ {
+ uint8_t *buffer = net_nfc_get_data_buffer(data);
+ uint32_t length = net_nfc_get_data_length(data);
+
+ fprintf(stdout, " Version : %d.%d\n", ((*buffer) >> 4) & 0x0F,
+ (*buffer) & 0x0F);
+ fprintf(stdout, " -- Containing NDEF message -- \n");
+
+ ndef_message_h msg;
+ data_h temp;
+
+ net_nfc_create_data(&temp, buffer + 1, length - 1);
+ net_nfc_create_ndef_message_from_rawdata(&msg, temp);
+
+ _display_ndef_message(msg);
+
+ net_nfc_free_ndef_message(msg);
+ net_nfc_free_data(temp);
+ }
+}
+
+static void _display_ac(ndef_record_h record)
+{
+ data_h data = NULL;
+
+ _display_id(record);
+
+ net_nfc_get_record_payload(record, &data);
+ if (net_nfc_get_data_length(data) > 0)
+ {
+ uint8_t *buffer = net_nfc_get_data_buffer(data);
+ int i, len;
+ const char *flag = "unknown";
+
+ switch (*buffer)
+ {
+ case 0 :
+ flag = "inactive";
+ break;
+
+ case 1 :
+ flag = "active";
+ break;
+
+ case 2 :
+ flag = "activating";
+ break;
+
+ default :
+ break;
+ }
+
+ fprintf(stdout, " Carrier Flags : 0x%x (%s)\n", *buffer++, flag);
+ len = *buffer++;
+ fprintf(stdout, " Carrier Data Ref. len : %d byte(s)\n", len);
+
+ for (i = 0; i < len; i++)
+ {
+ fprintf(stdout, " Carrier Data Ref. [%d] : %c\n", i, *buffer++);
+ }
+
+ len = *buffer++;
+ fprintf(stdout, " Aux. Data Ref. len : %d byte(s)\n", len);
+
+ for (i = 0; i < len; i++)
+ {
+ fprintf(stdout, " Aux. Data Ref. [%d] : %c\n", i, *buffer++);
+ }
+ }
+}
+
+static void _display_hc(ndef_record_h record)
+{
+ data_h data = NULL;
+
+ _display_id(record);
+
+ net_nfc_get_record_payload(record, &data);
+ if (net_nfc_get_data_length(data) > 0)
+ {
+ uint8_t *buffer = net_nfc_get_data_buffer(data);
+ int i, len;
+ const char *flag = "unknown";
+ uint8_t ctf = (*buffer) & 0x07;
+
+ switch (ctf)
+ {
+ case 1 :
+ flag = "Well-known type";
+ break;
+
+ case 2 :
+ flag = "MIME type";
+ break;
+
+ case 3 :
+ flag = "Absolute URI";
+ break;
+
+ case 4 :
+ flag = "External";
+ break;
+
+ default :
+ break;
+ }
+
+ fprintf(stdout, " Carrier type format : 0x%02x (%s)\n", ctf, flag);
+ buffer++;
+
+ len = *buffer++;
+ fprintf(stdout, " Carrier type length : %d byte(s)\n", len);
+
+ for (i = 0; i < len; i++)
+ {
+ fprintf(stdout, " Carrier type [%d] : 0x%02x\n", i, *buffer++);
+ }
+
+ len = net_nfc_get_data_length(data) - len - 2;
+
+ for (i = 0; i < len; i++)
+ {
+ fprintf(stdout, " Carrier data [%d] : 0x%02x\n", i, *buffer++);
+ }
+ }
+}
+
+static void _display_cr(ndef_record_h record)
+{
+ data_h data = NULL;
+
+ _display_id(record);
+
+ net_nfc_get_record_payload(record, &data);
+ if (net_nfc_get_data_length(data) > 0)
+ {
+ uint8_t *buffer = net_nfc_get_data_buffer(data);
+
+ fprintf(stdout, " Random number : %02X %02X\n", buffer[0], buffer[1]);
+ }
+}
+
+static void _display_err(ndef_record_h record)
+{
+ data_h data = NULL;
+
+ _display_id(record);
+
+ net_nfc_get_record_payload(record, &data);
+ if (net_nfc_get_data_length(data) > 0)
+ {
+ uint8_t *buffer = net_nfc_get_data_buffer(data);
+ const char *reason = "unknown";
+
+ switch (buffer[0])
+ {
+ case 1 :
+ reason = "temporary memory constraint";
+ break;
+
+ case 2 :
+ reason = "permanent memory constraint";
+ break;
+
+ case 3 :
+ reason = "carrier-specific constraint";
+ break;
+
+ default :
+ break;
+ }
+
+ fprintf(stdout, " Error reason : %s\n", reason);
+ fprintf(stdout, " Error data : %d ms\n", buffer[1]);
+ }
+}
+
+static void _display_well_known(ndef_record_h record)
+{
+ data_h data = NULL;
+
+ net_nfc_get_record_type(record, &data);
+ if (net_nfc_get_data_length(data) > 0)
+ {
+ uint8_t *buffer = net_nfc_get_data_buffer(data);
+ uint32_t length = net_nfc_get_data_length(data);
+ char temp_buffer[1024] = { 0, };
+
+ memcpy(temp_buffer, buffer, length);
+
+ if (strncmp(temp_buffer, "Sig", 3) == 0)
+ {
+ fprintf(stdout, " Type string[%d] : %s (Signature)\n", length, temp_buffer);
+ _display_signature(record);
+ }
+ else if (strncmp(temp_buffer, "Sp", 2) == 0)
+ {
+ fprintf(stdout, " Type string[%d] : %s (Smart poster)\n", length, temp_buffer);
+ _display_smart_poster(record);
+ }
+ else if (strncmp(temp_buffer, "Gc", 2) == 0)
+ {
+ fprintf(stdout, " Type string[%d] : %s (Generic control)\n", length, temp_buffer);
+ }
+ else if (strncmp(temp_buffer, "U", 1) == 0)
+ {
+ fprintf(stdout, " Type string[%d] : %s (URI)\n", length, temp_buffer);
+ _display_uri(record);
+ }
+ else if (strncmp(temp_buffer, "T", 1) == 0)
+ {
+ fprintf(stdout, " Type string[%d] : %s (Text)\n", length, temp_buffer);
+ _display_text(record);
+ }
+ else if (strncmp(temp_buffer, "Hc", 2) == 0)
+ {
+ fprintf(stdout, " Type string[%d] : %s (Handover carrier)\n", length, temp_buffer);
+ _display_hc(record);
+ }
+ else if (strncmp(temp_buffer, "Hr", 2) == 0)
+ {
+ fprintf(stdout, " Type string[%d] : %s (Handover request)\n", length, temp_buffer);
+ _display_hr(record);
+ }
+ else if (strncmp(temp_buffer, "Hs", 2) == 0)
+ {
+ fprintf(stdout, " Type string[%d] : %s (Handover select)\n", length, temp_buffer);
+ _display_hs(record);
+ }
+ else if (strncmp(temp_buffer, "ac", 2) == 0)
+ {
+ fprintf(stdout, " Type string[%d] : %s (alternative carrier)\n", length, temp_buffer);
+ _display_ac(record);
+ }
+ else if (strncmp(temp_buffer, "cr", 2) == 0)
+ {
+ fprintf(stdout, " Type string[%d] : %s (Collision Resolution)\n", length, temp_buffer);
+ _display_cr(record);
+ }
+ else if (strncmp(temp_buffer, "err", 3) == 0)
+ {
+ fprintf(stdout, " Type string[%d] : %s (Error record)\n", length, temp_buffer);
+ _display_err(record);
+ }
+ else
+ {
+ fprintf(stdout, " Type string[%d] : %s (Unknown)\n", length, temp_buffer);
+ }
+ }
+}
+
+static void _display_general_record(ndef_record_h record)
+{
+ data_h data = NULL;
+
+ net_nfc_get_record_type(record, &data);
+ if (net_nfc_get_data_length(data) > 0)
+ {
+ uint8_t *buffer = net_nfc_get_data_buffer(data);
+ uint32_t length = net_nfc_get_data_length(data);
+ char temp_buffer[1024] = { 0, };
+
+ memcpy(temp_buffer, buffer, length);
+
+ fprintf(stdout, " Type string[%d] : %s\n", length, temp_buffer);
+ }
+
+ _display_id(record);
+
+ net_nfc_get_record_payload(record, &data);
+ if (net_nfc_get_data_length(data) > 0)
+ {
+ uint32_t length = net_nfc_get_data_length(data);
+ uint8_t temp_buffer[512] = { 0, };
+
+ if (length > sizeof(temp_buffer))
+ {
+ memcpy(temp_buffer, net_nfc_get_data_buffer(data), sizeof(temp_buffer));
+
+ fprintf(stdout, " Real payload length : %d\n", length);
+ _display_buffer("Abb. payload", temp_buffer, sizeof(temp_buffer));
+ }
+ else
+ {
+ _display_buffer("Payload", net_nfc_get_data_buffer(data), length);
+ }
+ }
+}
+
+static void _display_absolute_uri(ndef_record_h record)
+{
+ data_h data = NULL;
+
+ _display_id(record);
+
+ net_nfc_get_record_type(record, &data);
+ if (net_nfc_get_data_length(data) > 0)
+ {
+ uint8_t *buffer = net_nfc_get_data_buffer(data);
+ uint32_t length = net_nfc_get_data_length(data);
+ char temp_buffer[2048] = { 0, };
+
+ memcpy(temp_buffer, buffer, length);
+
+ fprintf(stdout, " URI[%d] : %s\n", length, temp_buffer);
+ }
+#if 0
+ nfc_ndef_record_get_payload(record, &buffer, &length);
+ if (length > 0)
+ {
+ char temp_buffer[512] = { 0, };
+
+ if (length > sizeof(temp_buffer))
+ {
+ memcpy(temp_buffer, buffer, sizeof(temp_buffer));
+
+ fprintf(stdout, " Real payload length : %d\n", length);
+ _display_buffer("Abb. payload", temp_buffer, sizeof(temp_buffer));
+ }
+ else
+ {
+ _display_buffer("Payload", temp_buffer, length);
+ }
+ }
+#endif
+}
+
+static void _display_tnf(ndef_record_h record)
+{
+ net_nfc_record_tnf_e tnf = NET_NFC_RECORD_UNKNOWN;
+
+ net_nfc_get_record_tnf(record, &tnf);
+
+ switch (tnf)
+ {
+ case NET_NFC_RECORD_EMPTY :
+ fprintf(stdout, " TNF : Empty (%d)\n", tnf);
+ break;
+
+ case NET_NFC_RECORD_WELL_KNOWN_TYPE :
+ fprintf(stdout, " TNF : Well-known (%d)\n", tnf);
+ _display_well_known(record);
+ break;
+
+ case NET_NFC_RECORD_MIME_TYPE :
+ fprintf(stdout, " TNF : MIME (%d)\n", tnf);
+ _display_general_record(record);
+ break;
+
+ case NET_NFC_RECORD_URI :
+ fprintf(stdout, " TNF : Absolute URI (%d)\n", tnf);
+ _display_absolute_uri(record);
+ break;
+
+ case NET_NFC_RECORD_EXTERNAL_RTD :
+ fprintf(stdout, " TNF : External (%d)\n", tnf);
+ _display_general_record(record);
+ break;
+
+ case NET_NFC_RECORD_UNKNOWN :
+ fprintf(stdout, " TNF : Unknown (%d)\n", tnf);
+ _display_general_record(record);
+ break;
+
+ case NET_NFC_RECORD_UNCHAGNED :
+ fprintf(stdout, " TNF : Unchanged (%d)\n", tnf);
+ _display_general_record(record);
+ break;
+
+ default :
+ fprintf(stdout, " Invalid TNF\n");
+ break;
+ }
+}
+
+static void _display_record_length(ndef_record_h record)
+{
+ int length = 2; /* header : 1 byte, type length : 1 byte */
+
+ net_nfc_record_tnf_e tnf = NET_NFC_RECORD_UNKNOWN;
+
+ net_nfc_get_record_tnf(record, &tnf);
+ if (tnf != NET_NFC_RECORD_EMPTY &&
+ tnf != NET_NFC_RECORD_UNKNOWN &&
+ tnf != NET_NFC_RECORD_UNCHAGNED)
+ {
+ data_h data;
+
+ net_nfc_get_record_type(record, &data);
+ length += net_nfc_get_data_length(data);
+ }
+
+ uint8_t header;
+
+ net_nfc_get_record_flags(record, &header);
+ /* to check if payloadlength is 8bit or 32bit*/
+ if (net_nfc_get_record_sr(header) == 1)
+ {
+ /* ++ is for the Payload Length Byte */
+ length++;/* for short record*/
+ }
+ else
+ {
+ /* + NET_NFC_NDEF_NORMAL_RECORD_BYTE is for the Payload Length Byte */
+ length += 4;/* for normal record*/
+ }
+
+ /* for non empty record */
+ if (tnf != NET_NFC_RECORD_EMPTY)
+ {
+ data_h data;
+
+ net_nfc_get_record_payload(record, &data);
+ length += net_nfc_get_data_length(data);
+ }
+
+ /* ID and IDlength are present only if IL flag is set*/
+ if (net_nfc_get_record_il(header) == 1)
+ {
+ data_h data;
+
+ /* ++ is for the ID Length Byte */
+ length++;
+
+ net_nfc_get_record_id(record, &data);
+ length += net_nfc_get_data_length(data);
+ }
+
+ fprintf(stdout, " Length : %d\n", length);
+}
+
+static void _display_record(ndef_record_h record, int index)
+{
+ uint8_t header;
+
+ fprintf(stdout, "------------------ NDEF record %02d ------------------\n", index);
+
+ _display_record_length(record);
+
+ net_nfc_get_record_flags(record, &header);
+
+ fprintf(stdout, " MB[%d], ME[%d], CF[%d], SR[%d], IL[%d]\n", net_nfc_get_record_mb(header), net_nfc_get_record_me(header),
+ net_nfc_get_record_cf(header), net_nfc_get_record_sr(header), net_nfc_get_record_il(header));
+
+ _display_tnf(record);
+
+ fprintf(stdout, "----------------------------------------------------\n");
+}
+
+void _display_ndef_message(ndef_message_h msg)
+{
+ uint32_t length;
+ int count = 0;
+ int32_t i = 0;
+ ndef_record_h record = NULL;
+
+ net_nfc_get_ndef_message_byte_length(msg, &length);
+
+ fprintf(stdout, "================ NDEF message begin ================\n");
+ fprintf(stdout, "Length : %d\n", length);
+
+ net_nfc_get_ndef_message_record_count(msg, &count);
+
+ for (i = 0; i < count; i++)
+ {
+ net_nfc_get_record_by_index(msg, i, &record);
+
+ _display_record(record, i);
+ }
+
+ fprintf(stdout, "================= NDEF message end =================\n");
+}
+
+
+void ndef_tool_display_ndef_message_from_file(const char *file_name)
+{
+ int length = 0;
+ ndef_message_h msg = NULL;
+
+ if ((length = ndef_tool_read_ndef_message_from_file(file_name, &msg)) > 0)
+ {
+ fprintf(stdout, "\n");
+
+ _display_ndef_message(msg);
+
+ fprintf(stdout, "\n");
+
+ net_nfc_free_ndef_message(msg);
+ }
+ else
+ {
+ fprintf(stdout, "No file exists : %s\n\n", file_name);
+ }
+}
+
+void _display_target_type(net_nfc_target_type_e type)
+{
+ char *text = NULL;
+
+ switch (type)
+ {
+ case NET_NFC_GENERIC_PICC :
+ text = "Generic";
+ break;
+
+ case NET_NFC_ISO14443_A_PICC :
+ text = "ISO 14443 A";
+ break;
+
+ case NET_NFC_ISO14443_4A_PICC :
+ text = "ISO 14443 4A";
+ break;
+
+ case NET_NFC_ISO14443_3A_PICC :
+ text = "ISO 14443 3A";
+ break;
+
+ case NET_NFC_MIFARE_MINI_PICC :
+ text = "Mifare Mini";
+ break;
+
+ case NET_NFC_MIFARE_1K_PICC :
+ text = "Mifare 1k";
+ break;
+
+ case NET_NFC_MIFARE_4K_PICC :
+ text = "Mifare 4k";
+ break;
+
+ case NET_NFC_MIFARE_ULTRA_PICC :
+ text = "Mifare Ultralight";
+ break;
+
+ case NET_NFC_MIFARE_DESFIRE_PICC :
+ text = "Mifare Desfire";
+ break;
+
+ case NET_NFC_ISO14443_B_PICC :
+ text = "ISO 14443 B";
+ break;
+
+ case NET_NFC_ISO14443_4B_PICC :
+ text = "ISO 14443 4B";
+ break;
+
+ case NET_NFC_ISO14443_BPRIME_PICC :
+ text = "ISO 14443 B Prime";
+ break;
+
+ case NET_NFC_FELICA_PICC :
+ text = "Felica";
+ break;
+
+ case NET_NFC_JEWEL_PICC :
+ text = "Jewel";
+ break;
+
+ case NET_NFC_ISO15693_PICC :
+ text = "ISO 15693";
+ break;
+
+ case NET_NFC_NFCIP1_TARGET :
+ text = "P2P Target (NFCIP1)";
+ break;
+
+ case NET_NFC_NFCIP1_INITIATOR :
+ text = "P2P Initiator (NFCIP1)";
+ break;
+
+ default :
+ text = "Unknown";
+ break;
+ }
+
+ fprintf(stdout, "Target Type : %s (%d)\n", text, type);
+}
+
+void _display_tag_info(net_nfc_target_info_h target)
+{
+ int count, i;
+ char **keys;
+ data_h data;
+
+ fprintf(stdout, "Target information\n");
+ net_nfc_get_tag_info_keys(target, &keys, &count);
+ for (i = 0; i < count; i++)
+ {
+ if (keys[i] != NULL)
+ {
+ if (net_nfc_get_tag_info_value(target, keys[i], &data) == 0)
+ {
+ _display_buffer(keys[i], net_nfc_get_data_buffer(data), net_nfc_get_data_length(data));
+ }
+ }
+ }
+}
+
+void ndef_tool_display_discovered_tag(net_nfc_target_info_h target)
+{
+ net_nfc_target_type_e type;
+ bool is_ndef;
+ uint32_t size;
+
+ if (target == NULL)
+ {
+ return;
+ }
+
+ fprintf(stdout, "\n************* Tag discovered *************\n");
+
+ net_nfc_get_tag_type(target, &type);
+ _display_target_type(type);
+
+ net_nfc_get_tag_ndef_support(target, &is_ndef);
+ fprintf(stdout, "Including NDEF? : %s\n", is_ndef ? "Yes" : "No");
+
+ net_nfc_get_tag_max_data_size(target, &size);
+ fprintf(stdout, "Maximum size : %d\n", size);
+
+ net_nfc_get_tag_actual_data_size(target, &size);
+ fprintf(stdout, "Actual size : %d\n", size);
+
+ _display_tag_info(target);
+
+ fprintf(stdout, "******************************************\n");
+}
+
+void ndef_tool_display_discovered_target(net_nfc_target_handle_h handle)
+{
+ if (handle == NULL)
+ {
+ return;
+ }
+
+ fprintf(stdout, "\n************* Target discovered *************\n");
+ fprintf(stdout, "Target Type : P2P Target (NFCIP1) (%d)\n", NET_NFC_NFCIP1_TARGET);
+ fprintf(stdout, "*********************************************\n");
+}
+
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#include <stddef.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+#include "net_nfc.h"
+#include "net_nfc_sign_record.h"
+#include "ndef-tool.h"
+
+bool ndef_tool_sign_message_from_file(const char *file_name, int begin_index, int end_index, char *cert_file, char *password)
+{
+ bool result = false;
+ ndef_message_h msg = NULL;
+ int32_t count = 0;
+
+ if (ndef_tool_read_ndef_message_from_file(file_name, &msg) > 0)
+ {
+ net_nfc_get_ndef_message_record_count(msg, &count);
+
+ if (count > end_index)
+ {
+ fprintf(stdout, "count : %d\n", count);
+
+ net_nfc_sign_records(msg, begin_index, end_index, cert_file, password);
+
+ ndef_tool_write_ndef_message_to_file(file_name, msg);
+
+ result = true;
+ }
+
+ net_nfc_free_ndef_message(msg);
+ }
+
+ return result;
+}
+
+bool ndef_tool_verify_message_from_file(const char *file_name)
+{
+ bool result = false;
+ ndef_message_h msg = NULL;
+
+ if (ndef_tool_read_ndef_message_from_file(file_name, &msg) > 0)
+ {
+ result = (net_nfc_verify_signature_ndef_message(msg) == 0);
+
+ net_nfc_free_ndef_message(msg);
+ }
+
+ return result;
+}
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#include <stddef.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <glib.h>
+
+#include "net_nfc.h"
+#include "net_nfc_exchanger.h"
+#include "ndef-tool.h"
+
+typedef struct _response_context_t
+{
+ int type;
+ void *user_param;
+} response_context_t;
+
+static GMainLoop *main_loop = NULL;
+static response_context_t response_context = { 0, };
+
+static void _tag_read_completed_cb(ndef_message_h msg, void *user_data)
+{
+ response_context_t *context = (response_context_t *)user_data;
+
+ fprintf(stdout, "read complete!!!\n");
+ if (msg != NULL)
+ {
+ ndef_tool_write_ndef_message_to_file((char *)context->user_param, msg);
+
+ ndef_tool_display_ndef_message_from_file((char *)context->user_param);
+ }
+
+ g_main_loop_quit(main_loop);
+}
+
+static void _tag_read_cb(net_nfc_target_handle_h handle, void *user_data)
+{
+ fprintf(stdout, "\nreading...\n\n");
+
+ net_nfc_read_tag(handle, user_data);
+}
+
+static void _tag_write_completed_cb(net_nfc_error_e result, void *user_data)
+{
+ if (result == NET_NFC_OK)
+ fprintf(stdout, "write success!!!\n\n");
+ else
+ fprintf(stdout, "write failed.\n\n");
+
+ g_main_loop_quit(main_loop);
+}
+
+static void _tag_write_cb(net_nfc_target_handle_h handle, void *user_data)
+{
+ response_context_t *context = (response_context_t *)user_data;
+
+ fprintf(stdout, "\nwriting...\n\n");
+
+ net_nfc_write_ndef(handle, (ndef_message_h)context->user_param, user_data);
+}
+
+static void _p2p_receive_completed_cb(data_h data, void *user_data)
+{
+ response_context_t *context = (response_context_t *)user_data;
+
+ fprintf(stdout, "\np2p receive complete!!!\n\n");
+ if (data != NULL)
+ {
+ ndef_message_h msg;
+
+ net_nfc_create_ndef_message_from_rawdata(&msg, data);
+
+ ndef_tool_write_ndef_message_to_file((char *)context->user_param, msg);
+
+ net_nfc_free_ndef_message(msg);
+
+ ndef_tool_display_ndef_message_from_file((char *)context->user_param);
+ }
+
+ g_main_loop_quit(main_loop);
+}
+
+static void _p2p_send_completed_cb(net_nfc_error_e result, void *user_data)
+{
+ if (result == NET_NFC_OK)
+ fprintf(stdout, "send success!!!\n\n");
+ else
+ fprintf(stdout, "send failed.\n\n");
+
+ g_main_loop_quit(main_loop);
+}
+
+static void _p2p_send_cb(net_nfc_target_handle_h handle, void *user_data)
+{
+ response_context_t *context = (response_context_t *)user_data;
+
+ fprintf(stdout, "\nsending...\n\n");
+
+ net_nfc_exchanger_data_h data_handle;
+ data_h rawdata;
+
+ net_nfc_create_rawdata_from_ndef_message((ndef_message_h)context->user_param, &rawdata);
+ net_nfc_create_exchanger_data(&data_handle, rawdata);
+ net_nfc_free_data(rawdata);
+
+ net_nfc_send_exchanger_data(data_handle, handle, user_data);
+ net_nfc_free_exchanger_data(data_handle);
+}
+
+static void _handover_completed_cb(net_nfc_error_e result,
+ data_h data, void *user_data)
+{
+ // response_context_t *context = (response_context_t *)user_data;
+ // data_h rawdata;
+
+ if (result == NET_NFC_OK)
+ fprintf(stdout, "handover success!!!\n\n");
+ else
+ fprintf(stdout, "handover failed.\n\n");
+
+ // net_nfc_create_rawdata_from_ndef_message((ndef_message_h)context->user_param, &rawdata);
+ //
+ // net_nfc_ex
+ g_main_loop_quit(main_loop);
+}
+
+static void _open_se_cb(net_nfc_error_e result, net_nfc_target_handle_h handle,
+ void *user_data)
+{
+ response_context_t *context = (response_context_t *)user_data;
+
+ if (result == NET_NFC_OK)
+ {
+ data_h data = NULL;
+
+ fprintf(stdout, "net_nfc_open_internal_secure_element success!!!\n\n");
+
+ net_nfc_create_data(&data, (uint8_t *)context->user_param,
+ context->type);
+ if (data != NULL) {
+ net_nfc_send_apdu(handle, data, handle);
+ net_nfc_free_data(data);
+ }
+ }
+ else
+ {
+ fprintf(stdout, "net_nfc_open_internal_secure_element failed.\n\n");
+ g_main_loop_quit(main_loop);
+ }
+}
+
+static void _send_apdu_se_cb(net_nfc_error_e result, net_nfc_target_handle_h handle, void *user_data)
+{
+ // response_context_t *context = (response_context_t *)user_data;
+ // data_h rawdata;
+
+ if (result == NET_NFC_OK)
+ {
+ fprintf(stdout, "net_nfc_send_apdu success!!!\n\n");
+ net_nfc_close_internal_secure_element(handle, user_data);
+ }
+ else
+ {
+ fprintf(stdout, "net_nfc_send_apdu failed.\n\n");
+ g_main_loop_quit(main_loop);
+ }
+}
+
+static void _close_se_cb(net_nfc_error_e result, void *user_data)
+{
+ if (result == NET_NFC_OK)
+ fprintf(stdout, "net_nfc_close_internal_secure_element success!!!\n\n");
+ else
+ fprintf(stdout, "net_nfc_close_internal_secure_element failed.\n\n");
+
+ g_main_loop_quit(main_loop);
+}
+
+static void _handover_cb(net_nfc_target_handle_h handle, void *user_data)
+{
+ fprintf(stdout, "\ntry to handover...\n\n");
+
+ net_nfc_exchanger_request_connection_handover(handle,
+ NET_NFC_CONN_HANDOVER_CARRIER_BT);
+}
+
+void _nfc_response_cb(net_nfc_message_e message, net_nfc_error_e result,
+ void *data, void *user_param, void *trans_data)
+{
+ response_context_t *context = (response_context_t *)user_param;
+
+ switch (message)
+ {
+ case NET_NFC_MESSAGE_TAG_DISCOVERED :
+ {
+ net_nfc_target_handle_h handle = NULL;
+ bool is_ndef = false;
+
+ net_nfc_get_tag_handle((net_nfc_target_info_h)data, &handle);
+ net_nfc_get_tag_ndef_support((net_nfc_target_info_h)data, &is_ndef);
+
+ ndef_tool_display_discovered_tag(data);
+
+ if (is_ndef == true)
+ {
+ if (context->type == 0) /* read */
+ {
+ _tag_read_cb(handle, user_param);
+ }
+ else
+ {
+ _tag_write_cb(handle, user_param);
+ }
+ }
+ else
+ {
+ fprintf(stdout, "No NDEF tag.. read failed.\n\n");
+ g_main_loop_quit(main_loop);
+ }
+ }
+ break;
+
+ case NET_NFC_MESSAGE_READ_NDEF :
+ _tag_read_completed_cb((ndef_message_h)data, user_param);
+ break;
+
+ case NET_NFC_MESSAGE_WRITE_NDEF :
+ _tag_write_completed_cb(result, user_param);
+ break;
+
+ case NET_NFC_MESSAGE_P2P_DISCOVERED :
+
+ ndef_tool_display_discovered_target(data);
+
+ if (context->type == 1) /* receive */
+ {
+ _p2p_send_cb((net_nfc_target_handle_h)data, user_param);
+ }
+ else if (context->type == 2) /* handover */
+ {
+ _handover_cb((net_nfc_target_handle_h)data, user_param);
+ }
+ break;
+
+ case NET_NFC_MESSAGE_P2P_SEND :
+ _p2p_send_completed_cb(result, user_param);
+ break;
+
+ case NET_NFC_MESSAGE_P2P_RECEIVE :
+ _p2p_receive_completed_cb(data, user_param);
+ break;
+
+ case NET_NFC_MESSAGE_CONNECTION_HANDOVER :
+ _handover_completed_cb(result, data, user_param);
+ break;
+
+ case NET_NFC_MESSAGE_OPEN_INTERNAL_SE :
+ _open_se_cb(result, data, user_param);
+ break;
+
+ case NET_NFC_MESSAGE_SEND_APDU_SE :
+ _send_apdu_se_cb(result, trans_data, user_param);
+ break;
+
+ case NET_NFC_MESSAGE_CLOSE_INTERNAL_SE :
+ _close_se_cb(result, user_param);
+ break;
+
+ default :
+ break;
+ }
+}
+
+static void _initialize_tag_context(response_context_t *context)
+{
+ int ret = 0;
+
+ ret = net_nfc_initialize();
+ if (ret == NET_NFC_OK)
+ {
+ net_nfc_set_response_callback(_nfc_response_cb, (void *)context);
+ }
+}
+
+static void _run_tag_action()
+{
+ main_loop = g_main_new(TRUE);
+ g_main_loop_run(main_loop);
+}
+
+static void _release_tag_context(void)
+{
+ net_nfc_unset_response_callback();
+
+ net_nfc_deinitialize();
+}
+
+int ndef_tool_read_ndef_from_tag(const char *file)
+{
+ int result = 0;
+
+ response_context.type = 0;
+ response_context.user_param = (void *)file;
+
+ _initialize_tag_context(&response_context);
+
+ fprintf(stdout, "Contact a tag to device.....\n");
+
+ _run_tag_action();
+
+ _release_tag_context();
+
+ return result;
+}
+
+int ndef_tool_receive_ndef_via_p2p(const char *file)
+{
+ int result = 0;
+
+ response_context.type = 0;
+ response_context.user_param = (void *)file;
+
+ _initialize_tag_context(&response_context);
+
+ fprintf(stdout, "Contact a target to device.....\n");
+
+ _run_tag_action();
+
+ _release_tag_context();
+
+ return result;
+}
+
+int ndef_tool_write_ndef_to_tag(const char *file)
+{
+ int result = 0;
+ ndef_message_h msg = NULL;
+
+ if (ndef_tool_read_ndef_message_from_file(file, &msg) > 0)
+ {
+ response_context.type = 1;
+ response_context.user_param = (void *)msg;
+
+ _initialize_tag_context(&response_context);
+
+ fprintf(stdout, "Contact a tag to device.....\n");
+
+ _run_tag_action();
+
+ net_nfc_free_ndef_message(msg);
+
+ _release_tag_context();
+ }
+
+ return result;
+}
+
+int ndef_tool_send_ndef_via_p2p(const char *file)
+{
+ int result = 0;
+ ndef_message_h msg = NULL;
+
+ if (ndef_tool_read_ndef_message_from_file(file, &msg) > 0)
+ {
+ response_context.type = 1;
+ response_context.user_param = (void *)msg;
+
+ _initialize_tag_context(&response_context);
+
+ fprintf(stdout, "Contact a target to device.....\n");
+
+ _run_tag_action();
+
+ net_nfc_free_ndef_message(msg);
+
+ _release_tag_context();
+ }
+
+ return result;
+}
+
+static int _make_file_to_ndef_message(ndef_message_h *msg, const char *file_name)
+{
+ int result = 0;
+ FILE *file = NULL;
+
+ file = fopen(file_name, "rb");
+ if (file != NULL)
+ {
+ long int file_size = 0;
+ size_t read = 0;
+
+ fseek(file, 0, SEEK_END);
+ file_size = ftell(file);
+ fseek(file, 0, SEEK_SET);
+
+ if (file_size > 0)
+ {
+ data_h data;
+
+ net_nfc_create_data(&data, NULL, file_size);
+ if (data != NULL)
+ {
+ ndef_record_h record;
+ data_h type;
+
+ read = fread((void *)net_nfc_get_data_buffer(data), 1, file_size, file);
+
+ net_nfc_create_ndef_message(msg);
+
+ net_nfc_create_data(&type, (uint8_t *)"image/jpeg", 10);
+
+ net_nfc_create_record(&record, NET_NFC_RECORD_MIME_TYPE, type, NULL, data);
+
+ net_nfc_append_record_to_ndef_message(*msg, record);
+
+ net_nfc_free_data(type);
+ net_nfc_free_data(data);
+
+ result = file_size;
+ }
+ }
+
+ fclose(file);
+ }
+
+ return result;
+}
+
+int ndef_tool_connection_handover(const char *file)
+{
+ int result = 0;
+ ndef_message_h msg = NULL;
+
+ if (_make_file_to_ndef_message(&msg, file) > 0)
+ {
+ response_context.type = 2;
+ response_context.user_param = (void *)msg;
+
+ _initialize_tag_context(&response_context);
+
+ fprintf(stdout, "Contact a target to device.....\n");
+
+ _run_tag_action();
+
+ net_nfc_free_ndef_message(msg);
+
+ _release_tag_context();
+ }
+
+ return result;
+}
+
+static unsigned char char_to_num[] =
+{
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1,
+ -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+};
+
+int _convert_string_to_hex(const char *str, unsigned char *buffer, size_t length)
+{
+ size_t i, j, len = strlen(str);
+
+ for (i = 0, j = 0; i < len; j++)
+ {
+ buffer[j] = (char_to_num[(unsigned char)str[i++]] << 4);
+ if (i < len)
+ {
+ buffer[j] |= char_to_num[(unsigned char)str[i++]];
+ }
+ }
+
+ return (int)j;
+}
+
+int ndef_tool_send_apdu(const char *apdu)
+{
+ int result = 0;
+ unsigned char *buffer;
+ unsigned int length = (strlen(apdu) >> 1) + 1;
+
+ buffer = calloc(1, length);
+ if (buffer != NULL)
+ {
+ length = _convert_string_to_hex(apdu, buffer, length);
+ if (length > 0)
+ {
+ response_context.type = length;
+ response_context.user_param = (void *)buffer;
+
+ _initialize_tag_context(&response_context);
+
+ fprintf(stdout, "try to open eSE.....\n");
+
+ net_nfc_open_internal_secure_element(NET_NFC_SE_TYPE_ESE, buffer);
+
+ _run_tag_action();
+
+
+ _release_tag_context();
+ }
+
+ free(buffer);
+ }
+
+ return result;
+}
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#include <stddef.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <glib.h>
+
+#include "net_nfc.h"
+#include "ndef-tool.h"
+
+static GMainLoop *main_loop = NULL;
+
+void _activation_complete_cb(net_nfc_message_e message, net_nfc_error_e result,
+ void *data, void *user_param, void *trans_data)
+{
+ switch (message)
+ {
+ case NET_NFC_MESSAGE_INIT :
+ if (result == NET_NFC_OK)
+ fprintf(stdout, "power on success\n\n");
+ else
+ fprintf(stdout, "failed to power on (%d)\n\n", result);
+
+ net_nfc_unset_response_callback();
+ net_nfc_deinitialize();
+ g_main_loop_quit(main_loop);
+ break;
+
+ case NET_NFC_MESSAGE_DEINIT :
+ if (result == NET_NFC_OK)
+ fprintf(stdout, "power off success\n\n");
+ else
+ fprintf(stdout, "failed to power off (%d)\n\n", result);
+
+ net_nfc_unset_response_callback();
+ net_nfc_deinitialize();
+ g_main_loop_quit(main_loop);
+ break;
+
+ default :
+ break;
+ }
+}
+
+int ndef_tool_read_ndef_message_from_file(const char *file_name, ndef_message_h *msg)
+{
+ int result = -1;
+ FILE *file = NULL;
+
+ file = fopen(file_name, "rb");
+ if (file != NULL)
+ {
+ long int file_size = 0;
+ size_t read = 0;
+
+ fseek(file, 0, SEEK_END);
+ file_size = ftell(file);
+ fseek(file, 0, SEEK_SET);
+
+ if (file_size > 0)
+ {
+ data_h data;
+
+ net_nfc_create_data(&data, NULL, file_size);
+ if (data != NULL)
+ {
+ read = fread((void *)net_nfc_get_data_buffer(data), 1, file_size, file);
+
+ net_nfc_create_ndef_message_from_rawdata(msg, data);
+
+ net_nfc_free_data(data);
+
+ result = file_size;
+ }
+ }
+
+ fclose(file);
+ }
+
+ return result;
+}
+
+int ndef_tool_write_ndef_message_to_file(const char *file_name, ndef_message_h msg)
+{
+ int result = -1;
+ FILE *file = NULL;
+ data_h data = NULL;
+
+ net_nfc_create_rawdata_from_ndef_message(msg, &data);
+ if (data != NULL)
+ {
+ file = fopen(file_name, "wb");
+ if (file != NULL)
+ {
+ fwrite((void *)net_nfc_get_data_buffer(data), 1, net_nfc_get_data_length(data), file);
+ fflush(file);
+ fclose(file);
+
+ result = 0;
+ }
+
+ net_nfc_free_data(data);
+ }
+
+ return result;
+}
+
+static void print_usage(char *file_name)
+{
+ fprintf(stdout, "Usage : %s OPERATION [OPTION]... FILE\n", file_name);
+ fprintf(stdout, "\n");
+ fprintf(stdout, " Operation\n");
+ fprintf(stdout, " -a, --append-record Append a record to file\n");
+ fprintf(stdout, " Options\n");
+ fprintf(stdout, " -t, --tnf tnf Input TNF value\n");
+ fprintf(stdout, " (WKT : Well-known, EXT : External, \n");
+ fprintf(stdout, " MIME : MIME-type, URI : Absolute-URI)\n");
+ fprintf(stdout, " -T, --type-data data Input Type-field data\n");
+ fprintf(stdout, " -I, --id-data data Input ID-field data\n");
+ fprintf(stdout, " -P, --payload-data data Input Payload-field data. You can input hexa-style data using '%%' prefix\n");
+ fprintf(stdout, " ex) (0x20)abc : %%20abc\n");
+ fprintf(stdout, " it is possible to input '%%' by using '%%%%'\n");
+ fprintf(stdout, " ex) 120%%20 : 120%%%%20\n");
+ fprintf(stdout, " --payload-file file Input Payload-field data from binary file\n");
+ fprintf(stdout, " -E, --encoding data Input encoding method of Well-known Text type record\n");
+ fprintf(stdout, "\n");
+ fprintf(stdout, " -r, --remove-record Remove a specific record from file\n");
+ fprintf(stdout, " Options\n");
+ fprintf(stdout, " -i, --index value Input a record index\n");
+ fprintf(stdout, "\n");
+ fprintf(stdout, " -d, --display Display all records in file\n");
+ fprintf(stdout, " -s, --sign-records Sign some continuous records in file\n");
+ fprintf(stdout, " Options\n");
+ fprintf(stdout, " -b, --begin-index value Input a beginning record index\n");
+ fprintf(stdout, " -e, --end-index value Input a last record index\n");
+ fprintf(stdout, " -c, --cert-file file Input a PKCS #12 certificate file (DER file, not PEM file)\n");
+ fprintf(stdout, " -p, --password pass Input a password of PKCS #12 certificate file\n");
+ fprintf(stdout, "\n");
+ fprintf(stdout, " -v, --verify-signed-records Verify signature in file\n");
+ fprintf(stdout, " --read-tag Read a ndef from tag and store to file\n");
+ fprintf(stdout, " --write-tag Write a ndef file to tag\n");
+ fprintf(stdout, " --receive-ndef Receive a ndef from target device and store to file\n");
+ fprintf(stdout, " --send-ndef Send a ndef file to target device\n");
+ fprintf(stdout, " --handover Try to handover another carrier\n");
+ fprintf(stdout, "\n");
+ fprintf(stdout, " -h, --help Show this help messages\n");
+ fprintf(stdout, "\n");
+}
+
+static net_nfc_record_tnf_e _parse_tnf_string(const char *tnf)
+{
+ net_nfc_record_tnf_e result = -1;
+
+ if (tnf == NULL)
+ return result;
+
+ if (strncasecmp(tnf, "EMT", 3) == 0)
+ {
+ result = NET_NFC_RECORD_EMPTY;
+ }
+ else if (strncasecmp(tnf, "WKT", 3) == 0)
+ {
+ result = NET_NFC_RECORD_WELL_KNOWN_TYPE;
+ }
+ else if (strncasecmp(tnf, "MIME", 4) == 0)
+ {
+ result = NET_NFC_RECORD_MIME_TYPE;
+ }
+ else if (strncasecmp(tnf, "URI", 3) == 0)
+ {
+ result = NET_NFC_RECORD_URI;
+ }
+ else if (strncasecmp(tnf, "EXT", 3) == 0)
+ {
+ result = NET_NFC_RECORD_EXTERNAL_RTD;
+ }
+ else if (strncasecmp(tnf, "UNK", 3) == 0)
+ {
+ result = NET_NFC_RECORD_UNKNOWN;
+ }
+ else if (strncasecmp(tnf, "UNC", 3) == 0)
+ {
+ result = NET_NFC_RECORD_UNCHAGNED;
+ }
+
+ return result;
+}
+
+static int _append_record_to_file(const char *file_name, ndef_record_h record)
+{
+ int result = -1;
+ ndef_message_h msg = NULL;
+
+ if (ndef_tool_read_ndef_message_from_file(file_name, &msg) <= 0)
+ {
+ net_nfc_create_ndef_message(&msg);
+ }
+
+ net_nfc_append_record_to_ndef_message(msg, record);
+
+ ndef_tool_write_ndef_message_to_file(file_name, msg);
+
+ net_nfc_free_ndef_message(msg);
+
+ result = 0;
+
+ return result;
+}
+
+ndef_record_h _create_record(net_nfc_record_tnf_e tnf, data_h type, data_h id , data_h payload, char *encoding)
+{
+ ndef_record_h result = NULL;
+
+ switch (tnf)
+ {
+ case NET_NFC_RECORD_WELL_KNOWN_TYPE :
+ if (net_nfc_get_data_length(type) == 1 && memcmp((void *)net_nfc_get_data_buffer(type), "T", 1) == 0)
+ {
+ if (encoding == NULL)
+ {
+ fprintf(stdout, "encoding type is not present.\n");
+ return result;
+ }
+
+ char *temp_str = calloc(1, net_nfc_get_data_length(payload) + 1);
+ memcpy(temp_str, (void *)net_nfc_get_data_buffer(payload), net_nfc_get_data_length(payload));
+
+ net_nfc_create_text_type_record(&result, temp_str, encoding, NET_NFC_ENCODE_UTF_8);
+ free(temp_str);
+
+ if (id != NULL)
+ {
+ net_nfc_set_record_id(result, id);
+ }
+ }
+ else if (net_nfc_get_data_length(type) == 1 && memcmp((void *)net_nfc_get_data_buffer(type), "U", 1) == 0)
+ {
+ char *temp_str = calloc(1, net_nfc_get_data_length(payload) + 1);
+ memcpy(temp_str, (void *)net_nfc_get_data_buffer(payload), net_nfc_get_data_length(payload));
+
+ net_nfc_create_uri_type_record(&result, temp_str, 0);
+ free(temp_str);
+
+ if (id != NULL)
+ {
+ net_nfc_set_record_id(result, id);
+ }
+ }
+ else
+ {
+ net_nfc_create_record(&result, tnf, type, id, payload);
+ }
+ break;
+
+ default :
+ net_nfc_create_record(&result, tnf, type, id, payload);
+ break;
+ }
+
+ return result;
+}
+
+bool _remove_record_from_file(const char *file_name, int index)
+{
+ bool result = false;
+ ndef_message_h msg = NULL;
+
+ if (ndef_tool_read_ndef_message_from_file(file_name, &msg) > 0)
+ {
+ net_nfc_remove_record_by_index(msg, index);
+
+ ndef_tool_write_ndef_message_to_file(file_name, msg);
+
+ net_nfc_free_ndef_message(msg);
+
+ result = true;
+ }
+
+ return result;
+}
+
+#define __IS_SHORT_OPTION(__dst) ((strlen(__dst) == 2) && ((__dst)[0] == '-'))
+#define __IS_LONG_OPTION(__dst) ((strlen(__dst) > 2) && ((__dst)[0] == '-') && ((__dst)[1] == '-'))
+#define __IS_OPTION(__dst) (__IS_SHORT_OPTION(__dst) || __IS_LONG_OPTION(__dst))
+
+#define __COMPARE_OPTION(__dst, __s, __l) \
+ ((__IS_SHORT_OPTION(__dst) && ((__dst)[1] == (__s))) || \
+ (__IS_LONG_OPTION(__dst) && (strcmp((__dst) + 2, (__l)) == 0)))
+
+#define __DO_NEXT_ARG \
+ if (++i >= argc || __IS_OPTION(argv[i]) == true) \
+ { \
+ operation = OPERATION_ERROR; \
+ break; \
+ }
+
+int main(int argc, char *argv[])
+{
+ int remove_index = -1;
+ int begin_index = -1;
+ int end_index = -1;
+ int operation = OPERATION_ERROR;
+ net_nfc_record_tnf_e tnf = -1;
+ data_h type = NULL;
+ data_h id = NULL;
+ data_h payload = NULL;
+ char *file_name = NULL;
+ char *cert_file = NULL;
+ char *password = NULL;
+ char *encoding = NULL;
+ ndef_record_h record = NULL;
+
+ int i = 1;
+ int len = 0;
+
+ for (i = 1; i < argc; i++)
+ {
+ if (__COMPARE_OPTION(argv[i], 'a', "append-record"))
+ {
+ operation = OPERATION_APPEND;
+ }
+ else if (__COMPARE_OPTION(argv[i], 's', "sign-records"))
+ {
+ operation = OPERATION_SIGN;
+ }
+ else if (__COMPARE_OPTION(argv[i], 'd', "display-record"))
+ {
+ operation = OPERATION_DISPLAY;
+ }
+ else if (__COMPARE_OPTION(argv[i], 'v', "verify-signed-records"))
+ {
+ operation = OPERATION_VERIFY;
+ }
+ else if (__COMPARE_OPTION(argv[i], 'r', "remove-record"))
+ {
+ operation = OPERATION_REMOVE;
+ }
+ else if (__COMPARE_OPTION(argv[i], 0, "read-tag"))
+ {
+ operation = OPERATION_READ_TAG;
+ }
+ else if (__COMPARE_OPTION(argv[i], 0, "write-tag"))
+ {
+ operation = OPERATION_WRITE_TAG;
+ }
+ else if (__COMPARE_OPTION(argv[i], 0, "receive-ndef"))
+ {
+ operation = OPERATION_RECEIVE_NDEF;
+ }
+ else if (__COMPARE_OPTION(argv[i], 0, "send-ndef"))
+ {
+ operation = OPERATION_SEND_NDEF;
+ }
+ else if (__COMPARE_OPTION(argv[i], 0, "handover"))
+ {
+ operation = OPERATION_HANDOVER;
+ }
+ else if (__COMPARE_OPTION(argv[i], 0, "off")) /* hidden operation */
+ {
+ operation = OPERATION_OFF;
+ }
+ else if (__COMPARE_OPTION(argv[i], 0, "on")) /* hidden operation */
+ {
+ operation = OPERATION_ON;
+ }
+ else if (__COMPARE_OPTION(argv[i], 0, "send-apdu")) /* hidden operation */
+ {
+ operation = OPERATION_SEND_APDU;
+ }
+ else if (__COMPARE_OPTION(argv[i], 0, "set-se")) /* hidden operation */
+ {
+ operation = OPERATION_SET_SE;
+ }
+ else if (__COMPARE_OPTION(argv[i], 'i', "record-index"))
+ {
+ __DO_NEXT_ARG;
+ remove_index = atoi(argv[i]);
+ }
+ else if (__COMPARE_OPTION(argv[i], 'c', "cert-file"))
+ {
+ __DO_NEXT_ARG;
+ cert_file = strdup(argv[i]);
+ }
+ else if (__COMPARE_OPTION(argv[i], 'p', "password"))
+ {
+ __DO_NEXT_ARG;
+ password = strdup(argv[i]);
+ }
+ else if (__COMPARE_OPTION(argv[i], 'b', "begin-index"))
+ {
+ __DO_NEXT_ARG;
+ begin_index = atoi(argv[i]);
+ }
+ else if (__COMPARE_OPTION(argv[i], 'e', "end-index"))
+ {
+ __DO_NEXT_ARG;
+ end_index = atoi(argv[i]);
+ }
+ else if (__COMPARE_OPTION(argv[i], 't', "tnf"))
+ {
+ __DO_NEXT_ARG;
+ tnf = _parse_tnf_string(argv[i]);
+ }
+ else if (__COMPARE_OPTION(argv[i], 'T', "type-data"))
+ {
+ __DO_NEXT_ARG;
+ len = strlen(argv[i]);
+ if (len > 0)
+ {
+ net_nfc_create_data(&type, (const uint8_t *)argv[i], len);
+ }
+ }
+ else if (__COMPARE_OPTION(argv[i], 'I', "id-data"))
+ {
+ __DO_NEXT_ARG;
+ len = strlen(argv[i]);
+ if (len > 0)
+ {
+ net_nfc_create_data(&id, (const uint8_t *)argv[i], len);
+ }
+ }
+ else if (__COMPARE_OPTION(argv[i], 'P', "payload-data"))
+ {
+ __DO_NEXT_ARG;
+ len = strlen(argv[i]);
+ if (len > 0)
+ {
+ uint8_t *buffer = NULL;
+
+ buffer = calloc(1, len);
+ if (buffer != NULL)
+ {
+ int j, current = 0;
+
+ for (j = 0; j < len; j++)
+ {
+ if (argv[i][j] == '%')
+ {
+ if (j + 2 < len)
+ {
+ if (argv[i][j + 1] != '%')
+ {
+ char temp[3] = { 0, };
+
+ temp[0] = argv[i][j + 1];
+ temp[1] = argv[i][j + 2];
+
+ buffer[current++] = (uint8_t)strtol(temp, NULL, 16);
+ j += 2;
+ }
+ else
+ {
+ buffer[current++] = '%';
+ j++;
+ }
+ }
+ else if (j + 1 < len)
+ {
+ if (argv[i][j + 1] == '%')
+ {
+ buffer[current++] = '%';
+ j++;
+ }
+ else
+ {
+ buffer[current++] = argv[i][j];
+ }
+ }
+ else
+ {
+ /* invalid param. error? */
+ }
+ }
+ else
+ {
+ buffer[current++] = argv[i][j];
+ }
+ }
+
+ net_nfc_create_data(&payload, buffer, current);
+
+ free(buffer);
+ }
+ }
+ }
+ else if (__COMPARE_OPTION(argv[i], 0, "payload-file"))
+ {
+ __DO_NEXT_ARG;
+ len = strlen(argv[i]);
+ if (len > 0)
+ {
+ FILE *file = NULL;
+
+ file = fopen(argv[i], "rb");
+ if (file != NULL)
+ {
+ long int file_size = 0;
+ size_t read = 0;
+
+ fseek(file, 0, SEEK_END);
+ file_size = ftell(file);
+ fseek(file, 0, SEEK_SET);
+
+ if (file_size > 0)
+ {
+ uint8_t *buffer = NULL;
+
+ buffer = calloc(1, file_size);
+ if (buffer != NULL)
+ {
+ read = fread(buffer, 1, file_size, file);
+
+ net_nfc_create_data(&payload, buffer, read);
+
+ free(buffer);
+ }
+ }
+
+ fclose(file);
+ }
+ }
+ }
+ else if (__COMPARE_OPTION(argv[i], 'E', "encoding"))
+ {
+ __DO_NEXT_ARG;
+ encoding = strdup(argv[i]);
+ }
+ else if (__COMPARE_OPTION(argv[i], 'h', "help"))
+ {
+ operation = OPERATION_ERROR;
+ break;
+ }
+ else
+ {
+ if (file_name == NULL)
+ {
+ file_name = strdup(argv[i]);
+ }
+ else
+ {
+ operation = OPERATION_ERROR;
+ break;
+ }
+ }
+ }
+
+ if (operation != OPERATION_ON && operation != OPERATION_OFF && file_name == NULL)
+ operation = OPERATION_ERROR;
+
+ switch (operation)
+ {
+ case OPERATION_DISPLAY :
+ ndef_tool_display_ndef_message_from_file(file_name);
+ break;
+
+ case OPERATION_APPEND :
+ if (tnf >= 0 && type != NULL)
+ {
+ record = _create_record(tnf, type, id, payload, encoding);
+
+ if (record != NULL)
+ {
+ _append_record_to_file(file_name, record);
+
+ ndef_tool_display_ndef_message_from_file(file_name);
+ }
+ else
+ {
+ print_usage(argv[0]);
+ }
+ }
+ else
+ {
+ print_usage(argv[0]);
+ }
+ break;
+
+ case OPERATION_REMOVE :
+ _remove_record_from_file(file_name, remove_index);
+ ndef_tool_display_ndef_message_from_file(file_name);
+ break;
+
+ case OPERATION_SIGN :
+ if (begin_index < 0 || end_index < 0 || begin_index > end_index || cert_file == NULL || password == NULL)
+ {
+ print_usage(argv[0]);
+ }
+ else
+ {
+ fprintf(stdout, "file : %s\ncert file : %s\npassword : %s\nbegin index : %d\nend index : %d\n", file_name, cert_file, password, begin_index, end_index);
+ ndef_tool_sign_message_from_file(file_name, begin_index, end_index, cert_file, password);
+ ndef_tool_display_ndef_message_from_file(file_name);
+ }
+ break;
+
+ case OPERATION_VERIFY :
+ fprintf(stdout, "verify %s\n", ndef_tool_verify_message_from_file(file_name) ? "success" : "failed");
+ break;
+
+ case OPERATION_READ_TAG :
+ ndef_tool_read_ndef_from_tag(file_name);
+ break;
+
+ case OPERATION_WRITE_TAG :
+ ndef_tool_write_ndef_to_tag(file_name);
+ break;
+
+ case OPERATION_RECEIVE_NDEF :
+ ndef_tool_receive_ndef_via_p2p(file_name);
+ break;
+
+ case OPERATION_SEND_NDEF :
+ ndef_tool_send_ndef_via_p2p(file_name);
+ break;
+
+ case OPERATION_HANDOVER :
+ ndef_tool_connection_handover(file_name);
+ break;
+
+ case OPERATION_ON :
+ {
+ int state = 0;
+
+ net_nfc_get_state(&state);
+
+ if (state == 0)
+ {
+ fprintf(stdout, "Power on....\n\n");
+
+ if(!g_thread_supported())
+ {
+ g_thread_init(NULL);
+ }
+
+ main_loop = g_main_new(true);
+
+ net_nfc_initialize();
+ net_nfc_set_response_callback(_activation_complete_cb, NULL);
+ net_nfc_set_state(true, NULL);
+
+ g_main_loop_run(main_loop);
+ }
+ else
+ {
+ fprintf(stdout, "Already power is on.\n\n");
+ }
+ }
+ break;
+
+ case OPERATION_OFF :
+ {
+ int state = 0;
+
+ net_nfc_get_state(&state);
+
+ if (state == 1)
+ {
+ fprintf(stdout, "Power off....\n\n");
+
+ if(!g_thread_supported())
+ {
+ g_thread_init(NULL);
+ }
+
+ main_loop = g_main_new(true);
+
+ net_nfc_initialize();
+ net_nfc_set_response_callback(_activation_complete_cb, NULL);
+ net_nfc_set_state(false, NULL);
+
+ g_main_loop_run(main_loop);
+ }
+ else
+ {
+ fprintf(stdout, "Already power is off.\n\n");
+ }
+ }
+ break;
+
+ case OPERATION_SEND_APDU :
+ ndef_tool_send_apdu(file_name);
+ break;
+
+ case OPERATION_SET_SE :
+ net_nfc_initialize();
+
+ if (strcmp(file_name, "SIM1") == 0) {
+ net_nfc_set_secure_element_type(NET_NFC_SE_TYPE_UICC, NULL);
+ } else if (strcmp(file_name, "eSE") == 0) {
+ net_nfc_set_secure_element_type(NET_NFC_SE_TYPE_ESE, NULL);
+ } else {
+ fprintf(stdout, "Unknown SE name.\n\n");
+ }
+ break;
+
+ case OPERATION_ERROR :
+ default :
+ print_usage(argv[0]);
+ break;
+ }
+
+ return 0;
+}
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NDEF_TOOL_H__
+#define __NDEF_TOOL_H__
+
+#include "net_nfc_typedef.h"
+
+enum
+{
+ OPERATION_ERROR,
+ OPERATION_DISPLAY,
+ OPERATION_APPEND,
+ OPERATION_REMOVE,
+ OPERATION_SIGN,
+ OPERATION_VERIFY,
+ OPERATION_READ_TAG,
+ OPERATION_WRITE_TAG,
+ OPERATION_RECEIVE_NDEF,
+ OPERATION_SEND_NDEF,
+ OPERATION_HANDOVER,
+ OPERATION_SEND_APDU,
+ OPERATION_ON, /* hidden operation */
+ OPERATION_OFF, /* hidden operation */
+ OPERATION_SET_SE, /* hidden operation */
+};
+
+int ndef_tool_read_ndef_message_from_file(const char *file_name, ndef_message_h *msg);
+int ndef_tool_write_ndef_message_to_file(const char *file_name, ndef_message_h msg);
+
+void ndef_tool_display_ndef_message_from_file(const char *file_name);
+void ndef_tool_display_discovered_tag(net_nfc_target_info_h target);
+void ndef_tool_display_discovered_target(net_nfc_target_handle_h handle);
+
+bool ndef_tool_sign_message_from_file(const char *file_name, int begin_index, int end_index, char *cert_file, char *password);
+bool ndef_tool_verify_message_from_file(const char *file_name);
+
+int ndef_tool_read_ndef_from_tag(const char *file);
+int ndef_tool_write_ndef_to_tag(const char *file);
+int ndef_tool_receive_ndef_via_p2p(const char *file);
+int ndef_tool_send_ndef_via_p2p(const char *file);
+int ndef_tool_connection_handover(const char *file);
+int ndef_tool_send_apdu(const char *apdu);
+
+
+#endif //__NDEF_TOOL_H__
--- /dev/null
+LINK_DIRECTORIES(${CMAKE_BINARY_DIR})
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/common/include)
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/client/include)
+
+SET(NFC_CLIENT "nfc-client")
+
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/ TOOL_SRC)
+
+IF("${CMAKE_BUILD_TYPE}" STREQUAL "")
+ SET(CMAKE_BUILD_TYPE "Release")
+ENDIF("${CMAKE_BUILD_TYPE}" STREQUAL "")
+
+pkg_check_modules(tool_pkgs REQUIRED glib-2.0 gobject-2.0)
+
+FOREACH(flag ${tool_pkgs_CFLAGS})
+ SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+
+ADD_EXECUTABLE(${NFC_CLIENT} ${TOOL_SRC})
+TARGET_LINK_LIBRARIES(${NFC_CLIENT} ${tool_pkgs_LDFLAGS} pthread dl rt nfc)
+
+INSTALL(TARGETS ${NFC_CLIENT} DESTINATION bin)
+
+
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <net_nfc.h>
+#include <unistd.h>
+#include <pthread.h>
+#include "nfc_api_test.h"
+
+#include <glib.h>
+
+/* Function definition list*/
+int nfcTestClientInit(uint8_t testNumber,void* arg_ptr2);
+int nfcTestNdefParser(uint8_t testNumber,void* arg_ptr2);
+int nfcTestWriteMode(uint8_t testNumber,void* arg_ptr2);
+int nfcTestReaderMode(uint8_t testNumber,void* arg_ptr2);
+int nfcTestTransceive(uint8_t testNumber,void* arg_ptr2);
+int nfcTestAPIBasicTest1(uint8_t testNumber,void* arg_ptr2);
+int nfcTestAPIBasicTest2(uint8_t testNumber,void* arg_ptr2);
+int nfcTestAPIBasicTest3(uint8_t testNumber,void* arg_ptr2);
+int nfcTestReadWriteMode(uint8_t testNumber,void* arg_ptr2);
+int nfcTestAPIMultipleRequest(uint8_t testNumber,void* arg_ptr2);
+int nfcTestLLCP(uint8_t testNumber,void* arg_ptr2);
+int nfcTestStressLLCP(uint8_t testNumber,void* arg_ptr2);
+int nfcTestExchanger(uint8_t testNumber,void* arg_ptr2);
+int nfcConnHandover(uint8_t testNumber,void* arg_ptr2);
+int nfcTestAPIException (uint8_t testNumber,void* arg_ptr);
+int nfcTestAPIException_tagAPI (uint8_t testNumber,void* arg_ptr);
+int nfcTestAPIException_targetInfo (uint8_t testNumber,void* arg_ptr);
+int nfcConnHandoverMessageTest (uint8_t testNumber,void* arg_ptr);
+int nfcTestFormatNdef(uint8_t testNumber,void* arg_ptr2);
+int nfcTestInternalSe(uint8_t testNumber,void* arg_ptr2);
+int nfcTestSnep(uint8_t testNumber,void* arg_ptr);
+
+
+void print_test_result (char * str, net_nfc_test_result_e result);
+
+#define NET_NFC_TAG_DISCOVERED 1
+#define NET_NFC_TAG_CONNECT (1 << 1)
+#define NET_NFC_TAG_CHECK_NDEF (1 << 2)
+#define NET_NFC_TAG_NDEF_READ (1 << 3)
+#define NET_NFC_TAG_NDEF_WRITE (1 << 4)
+#define NET_NFC_TAG_NDEF_READ_BIG (1 << 5)
+#define NET_NFC_TAG_NDEF_WRITE_BIG (1 << 6)
+#define NET_NFC_TAG_DISCONNECT (1 << 7)
+#define NET_NFC_MAX_TAG_TYPE 20
+
+static nfcTestType nfcTestMatrix[] =
+{
+ // {"API STRESS_WRITE_READ TEST", nfcTestReadWriteMode, NET_NFC_TEST_NOT_YET}, // OK
+ // {"Remove tag while writing", nfcTestWriteMode, NET_NFC_TEST_NOT_YET}, //OK
+ // {"Remove tag while reading", nfcTestAPIBasicTest2, NET_NFC_TEST_NOT_YET}, // OK
+ //{"API BASIC TEST3", nfcTestAPIBasicTest3, NET_NFC_TEST_NOT_YET},
+ // {"API MUTIPLE REQUEST", nfcTestAPIMultipleRequest, NET_NFC_TEST_NOT_YET}, // OK
+ // {"API BASIC TEST1", nfcTestAPIBasicTest1, NET_NFC_TEST_NOT_YET}, // OK
+ // {"Check NDEF message", nfcTestNdefParser, NET_NFC_TEST_NOT_YET}, // OK
+ // {"write mode", nfcTestWriteMode, NET_NFC_TEST_NOT_YET},
+ // {"reader mode", nfcTestReaderMode, NET_NFC_TEST_NOT_YET},
+ // {"format ndef", nfcTestFormatNdef, NET_NFC_TEST_NOT_YET},
+ // {"internal_se_test", nfcTestInternalSe, NET_NFC_TEST_NOT_YET},
+ // {"exchange mode", nfcTestExchanger, NET_NFC_TEST_NOT_YET},
+ // {"Transceive Test", nfcTestTransceive, NET_NFC_TEST_NOT_YET},
+ // {"LLCP Test", nfcTestLLCP, NET_NFC_TEST_NOT_YET},
+ // {"connection handover msg test", nfcConnHandover, NET_NFC_TEST_NOT_YET},
+ // {"API Exception Test", nfcTestAPIException, NET_NFC_TEST_NOT_YET},
+ // {"API Exception Test2", nfcTestAPIException_tagAPI, NET_NFC_TEST_NOT_YET},
+ /// {"API Exception Test3", nfcTestAPIException_targetInfo, NET_NFC_TEST_NOT_YET},
+ // {"LLCP Test", nfcTestLLCP, NET_NFC_TEST_NOT_YET},
+ // {"LLCP Test", nfcTestStressLLCP, NET_NFC_TEST_NOT_YET},
+ // {"Handover Message", nfcConnHandoverMessageTest , NET_NFC_TEST_NOT_YET},
+ {"snep test", nfcTestSnep, NET_NFC_TEST_NOT_YET},
+ {NULL, NULL, NET_NFC_TEST_NOT_YET},
+};
+
+//static uint32_t testDevType = 0;
+//static uint32_t testCardMaxNdefLength = 0;
+//static uint8_t tagTestResult[NET_NFC_MAX_TAG_TYPE];
+
+static int read_count = 0;
+static int write_count = 0;
+static int detect_count = 0;
+
+static net_nfc_target_handle_h tag_handle = NULL;
+static int test_count = 0;
+
+
+
+/* Below smart poster data can has problem or parser has some problem.
+ Need to check */
+uint8_t nfcTestSpHex[]= {0xD1,0x02,0x37,0x53,0x70,0x91,0x01,0x18,0x54,0x04,
+ 0x74,0x65,0x73,0x74,0x53,0x6D,0x61,0x72,0x74,0x70,
+ 0x6F,0x73,0x74,0x65,0x72,0x20,0x45,0x78,0x61,0x6D,
+ 0x70,0x6C,0x65,0x11,0x03,0x01,0x61,0x63,0x74,0x00,
+ 0x51,0x01,0x10,0x55,0x00,0x77,0x77,0x77,0x2E,0x73,
+ 0x61,0x6D,0x73,0x75,0x6E,0x67,0x2E,0x63,0x6F,0x6D};
+
+/*
+ uint8_t nfcTestSp[]={0xD1,0x02,0x24,0x53,0x70,0x91,0x01,0x14,0x54
+ ,0x00,0x53,0x6D,0x61,0x72,0x74,0x70,0x6F,0x73
+ ,0x74,0x65,0x72,0x20,0x45,0x78,0x61,0x6D,0x70
+ ,0x6C,0x65,0x11,0x03,0x01,0x61,0x63,0x74,0x00
+ ,0x51,0x01,0x01,0x55,0x00};
+ */
+
+// test Text "Samsung Linux Platform NFC TEST"
+uint8_t nfcTestTextHex[]= {0xD1,0x01,0x20,0x54,0x00,0x53,0x61,0x6D,0x73,0x75
+ ,0x6E,0x67,0x20,0x4C,0x69,0x6E,0x75,0x78,0x20,0x50
+ ,0x6C,0x61,0x74,0x66,0x6F,0x72,0x6D,0x20,0x4E,0x46
+ ,0x43,0x20,0x54,0x45,0x53,0x54};
+
+
+// test URI "http://www.samsunglinuxplatform.nfctest.com"
+uint8_t nfcTestUriHex[]={0xD1,0x01,0x2C,0x55,0x00,0x68,0x74,0x74,0x70,0x3A
+ ,0x2F,0x2F,0x77,0x77,0x77,0x2E,0x73,0x61,0x6D,0x73
+ ,0x75,0x6E,0x67,0x6C,0x69,0x6E,0x75,0x78,0x70,0x6C
+ ,0x61,0x74,0x66,0x6F,0x72,0x6D,0x2E,0x6E,0x66,0x63
+ ,0x74,0x65,0x73,0x74,0x2E,0x63,0x6F,0x6D};
+
+uint8_t nfcTestText[] = "payload http://www.samsunglinuxplatform.nfctest.com";
+uint8_t nfcTestUri[] = {0xD1,0x01,0x13,0x55,0x1,0x73,0x61,0x6D,0x73,0x75,0x6E,0x67,0x6D,0x6F,0x62,0x69,0x6C,0x65,0x2E,0x63,0x6F,0x6D,0x2F};
+
+
+
+static pthread_cond_t pcond = PTHREAD_COND_INITIALIZER;
+static pthread_mutex_t plock = PTHREAD_MUTEX_INITIALIZER;
+
+static gboolean test_process_func(gpointer data)
+{
+ uint8_t i;
+ int count = 0;
+
+ while (nfcTestMatrix[count].testName != NULL){
+ count ++;
+ }
+
+ for(i=0; i<count; i++)
+ {
+ PRINT_INFO("%d. %s START\n", i, nfcTestMatrix[i].testName);
+
+ if(nfcTestMatrix[i].testFn !=NULL){
+ nfcTestMatrix[i].testResult = nfcTestMatrix[i].testFn(i, NULL);
+ //print_test_result (nfcTestMatrix[i].testName, nfcTestMatrix[i].testResult);
+ }
+ }
+
+ return false;
+}
+
+int main()
+{
+
+ GMainLoop* loop = NULL;
+ loop = g_main_new(TRUE);
+
+ g_timeout_add_seconds(1, test_process_func, NULL); // 1secs
+ g_main_loop_run(loop);
+
+ return 0;
+}
+
+void print_test_result (char * str, net_nfc_test_result_e result)
+{
+ if (result == NET_NFC_TEST_OK){
+ PRINT_RESULT_SUCCESS("TEST [%s] is PASSED",str);
+ }
+ else if (result == NET_NFC_TEST_FAIL){
+ PRINT_RESULT_FAIL("TEST [%s] is FAILED",str);
+ }
+ else {
+ PRINT_INFO("TEST is being tested\n");
+ }
+}
+
+
+/*=================================================================================*/
+
+static net_nfc_test_result_e test_case_result;
+
+static void net_nfc_test_read_write_cb(net_nfc_message_e message, net_nfc_error_e result, void* data, void* user_param, void * trans_data );
+static void net_nfc_test_static_handover_cb(net_nfc_message_e message, net_nfc_error_e result, void* data, void* user_param, void * trans_data);
+
+static void net_nfc_test_client_cb(net_nfc_message_e message, net_nfc_error_e result, void* data, void* user_param, void * trans_data )
+{
+ // do nothing
+}
+
+int nfcTestClientInit(uint8_t testNumber,void* arg_ptr2)
+{
+ net_nfc_error_e result;
+ result = net_nfc_initialize();
+ CHECK_RESULT(result);
+
+
+ result = net_nfc_set_response_callback (net_nfc_test_client_cb, NULL);
+ CHECK_RESULT(result);
+
+ result = net_nfc_unset_response_callback ();
+ CHECK_RESULT(result);
+
+ result = net_nfc_deinitialize ();
+ CHECK_RESULT(result);
+
+ return NET_NFC_TEST_OK;
+}
+
+
+net_nfc_exchanger_data_h net_nfc_exchanger_callback(net_nfc_exchanger_event_e event, void * user_param)
+{
+ PRINT_INFO(" event = [%d] \n", event);
+ test_case_result = NET_NFC_TEST_OK;
+
+ switch(event)
+ {
+ case NET_NFC_EXCHANGER_DATA_REQUESTED:
+ {
+ PRINT_INFO("exchange is requested");
+ net_nfc_exchanger_data_h ex_data = NULL;
+ net_nfc_error_e error = NET_NFC_OK;
+ data_h payload = NULL;
+
+ /*
+ uint8_t buffer[1024] = {0};
+
+ int i = 0;
+ for(; i< 1024; i++){
+ buffer[i] = 'a';
+ }
+
+ net_nfc_create_data(&payload, buffer, 1024);
+ */
+
+ if((error = net_nfc_create_exchanger_data(&ex_data, payload/*(uint8_t *)"http://www.samsung.com"*/)) == NET_NFC_OK)
+ //if((error = net_nfc_create_exchanger_url_type_data(&ex_data, NET_NFC_SCHEMA_FULL_URI, (uint8_t *)"file://test.txt")) == NET_NFC_OK)
+ //if((error = net_nfc_create_exchanger_raw_type_data(&ex_data, "text/plain", payload)) == NET_NFC_OK)
+ {
+ return ex_data;
+ }
+ else
+ {
+ PRINT_INFO("create exchanger data is failed = [%d]", error);
+ //pthread_cond_signal (&pcond);
+ return NULL;
+ }
+ }
+ case NET_NFC_EXCHANGER_TRANSFER_FAILED:
+ case NET_NFC_EXCHANGER_TRANSFER_COMPLETED:
+ default:
+ {
+ //pthread_cond_signal (&pcond);
+
+ if(event == NET_NFC_EXCHANGER_TRANSFER_COMPLETED)
+ {
+ PRINT_INFO("transfer exchanger msg is completed");
+ }
+ else
+ {
+ PRINT_INFO("transfer exchanger msg is failed");
+ }
+
+ return NULL;
+ }
+ }
+
+}
+
+/*=================================================================================*/
+static void net_nfc_test_reader_cb(net_nfc_message_e message, net_nfc_error_e result, void* data, void* user_param, void * trans_data)
+{
+ //int user_context;
+
+ PRINT_INFO("user_param = [%d] trans_param = [%d]", (int)user_param, (int)trans_data);
+
+ switch(message)
+ {
+ case NET_NFC_MESSAGE_TAG_DISCOVERED:{
+ net_nfc_target_type_e type;
+ net_nfc_target_handle_h id;
+ bool is_ndef;
+ net_nfc_target_info_h target_info = (net_nfc_target_info_h)data;
+
+ net_nfc_get_tag_type (target_info, &type);
+ net_nfc_get_tag_handle(target_info, &id);
+ net_nfc_get_tag_ndef_support (target_info, &is_ndef);
+ PRINT_INFO("target type: %d\n", type);
+ PRINT_INFO("target id: %X\n", (unsigned int)id);
+ PRINT_INFO("Is NDEF supoort: %d\n", is_ndef);
+
+ if (is_ndef){
+ uint32_t actual_size;
+ uint32_t max_size;
+ net_nfc_get_tag_actual_data_size (target_info, &actual_size);
+ net_nfc_get_tag_max_data_size (target_info ,&max_size);
+ PRINT_INFO("\tmax data [%d]\tactual data [%d]\n", max_size,actual_size );
+ net_nfc_read_tag (id, (void *)2);
+ }
+ else{
+ PRINT_INSTRUCT("Please use NDEF formated tag!!");
+ test_case_result = NET_NFC_TEST_FAIL;
+ }
+ break;
+ }
+ case NET_NFC_MESSAGE_READ_NDEF:{
+ if(data != NULL){
+ ndef_message_h ndef = (ndef_message_h)(data);
+ data_h rawdata;
+ net_nfc_create_rawdata_from_ndef_message (ndef ,&rawdata);
+ PRINT_INFO("read ndef message is ok, length is [%d]", net_nfc_get_data_length(rawdata));
+ net_nfc_free_data(rawdata);
+ //_//net_nfc_ndef_print_message (ndef);
+ /*
+
+ if (memcmp(net_nfc_get_data_buffer (rawdata),nfcTestSpHex, net_nfc_get_data_length (rawdata)) == 0){
+ test_case_result = NET_NFC_TEST_OK;
+ }
+ */
+ }
+ pthread_mutex_lock (&plock);
+ pthread_cond_signal (&pcond);
+ pthread_mutex_unlock (&plock);
+ break;
+ }
+ default:
+ break;
+ }
+}
+
+
+static void net_nfc_test_format_cb(net_nfc_message_e message, net_nfc_error_e result, void* data, void* user_param, void * trans_data)
+{
+ //int user_context;
+
+ PRINT_INFO("user_param = [%d] trans_param = [%d]", (int)user_param, (int)trans_data);
+
+ switch(message)
+ {
+ case NET_NFC_MESSAGE_TAG_DISCOVERED:{
+
+ PRINT_INFO("NET_NFC_MESSAGE_TAG_DISCOVERED");
+
+ net_nfc_target_type_e type;
+ net_nfc_target_handle_h id;
+ bool is_ndef;
+ net_nfc_target_info_h target_info = (net_nfc_target_info_h)data;
+
+ net_nfc_get_tag_type (target_info, &type);
+ net_nfc_get_tag_handle(target_info, &id);
+ net_nfc_get_tag_ndef_support (target_info, &is_ndef);
+ PRINT_INFO("target type: %d\n", type);
+ PRINT_INFO("target id: %X\n", (unsigned int)id);
+ PRINT_INFO("Is NDEF supoort: %d\n", is_ndef);
+
+ data_h ndef_key = NULL;
+ net_nfc_mifare_create_net_nfc_forum_key(&ndef_key);
+ net_nfc_format_ndef(id, ndef_key, NULL);
+ net_nfc_free_data(ndef_key);
+
+ }
+ break;
+
+ case NET_NFC_MESSAGE_FORMAT_NDEF:{
+ PRINT_INFO("NET_NFC_MESSAGE_FORMAT_NDEF");
+ PRINT_INFO("result = [%d]", result);
+ }
+ break;
+ case NET_NFC_MESSAGE_TAG_DETACHED:
+ {
+ PRINT_INFO("NET_NFC_MESSAGE_TAG_DETACHED");
+ }
+ break;
+ default:
+ break;
+ }
+}
+
+static void net_nfc_test_se_cb(net_nfc_message_e message, net_nfc_error_e result, void* data, void* user_param, void * trans_data)
+{
+ switch(message)
+ {
+ case NET_NFC_MESSAGE_GET_SE :
+ {
+ PRINT_INFO("NET_NFC_MESSAGE_GET_SE result = [%d] se type = [%d]", result, *((uint8_t *)data));
+ //net_nfc_set_secure_element_type(NET_NFC_SE_TYPE_ESE, NULL);
+ net_nfc_set_secure_element_type(NET_NFC_SE_TYPE_UICC, NULL);
+ }
+ break;
+ case NET_NFC_MESSAGE_SET_SE :
+ {
+ PRINT_INFO("NET_NFC_MESSAGE_SET_SE result = [%d] se type = [%d]", result, *((uint8_t *)data));
+ net_nfc_open_internal_secure_element(NET_NFC_SE_TYPE_ESE, NULL);
+ //net_nfc_open_internal_secure_element(NET_NFC_SE_TYPE_UICC, NULL);
+ }
+ break;
+ case NET_NFC_MESSAGE_OPEN_INTERNAL_SE :
+ {
+ PRINT_INFO("NET_NFC_MESSAGE_OPEN_INTERNAL_SE result = [%d] and handle = [0x%x]", result, (unsigned int)data);
+ data_h apdu = NULL;
+ uint8_t apdu_cmd[4] = {0x00, 0xA4, 0x00, 0x0C} ; // CLA 0-> use default channel and no secure message. 0xA4 -> select instruction
+ net_nfc_create_data(&apdu, apdu_cmd, 4);
+ net_nfc_send_apdu((net_nfc_target_handle_h)(data), apdu, data);
+ net_nfc_free_data(apdu);
+
+ }
+ break;
+ case NET_NFC_MESSAGE_SEND_APDU_SE:
+ {
+ PRINT_INFO("NET_NFC_MESSAGE_SEND_APDU_SE result = [%d]", result);
+
+ if(data != NULL)
+ {
+ uint8_t * r_buffer = net_nfc_get_data_buffer (data);
+ uint32_t r_buffer_length = net_nfc_get_data_length (data);
+
+ PRINT_INFO ("Received data [size:%d] \n", net_nfc_get_data_length (data));
+
+ int idx = 0;
+ for (idx = 0; idx < r_buffer_length; idx++){
+ printf (" %02X", r_buffer[idx]);
+ }printf ("\n");
+ }
+
+ net_nfc_close_internal_secure_element((net_nfc_target_handle_h)trans_data, NULL);
+ }
+ break;
+ case NET_NFC_MESSAGE_CLOSE_INTERNAL_SE :
+ {
+
+ PRINT_INFO("NET_NFC_MESSAGE_CLOSE_INTERNAL_SE result = [%d]", result);
+ }
+ break;
+ default:
+ break;
+ }
+
+ PRINT_INFO("user_param = [%d] trans_param = [%d]", (int)user_param, (int)trans_data);
+}
+
+/*=================================================================================*/
+static void net_nfc_test_static_handover_cb(net_nfc_message_e message, net_nfc_error_e result, void* data, void* user_param, void * trans_data)
+{
+ //int user_context;
+ switch(message)
+ {
+ case NET_NFC_MESSAGE_TAG_DISCOVERED:{
+ net_nfc_target_type_e type;
+ net_nfc_target_handle_h id;
+ bool is_ndef;
+ net_nfc_target_info_h target_info = (net_nfc_target_info_h)data;
+ net_nfc_carrier_config_h config;
+ ndef_record_h record;
+
+ net_nfc_get_tag_type (target_info, &type);
+ net_nfc_get_tag_handle(target_info, &id);
+ net_nfc_get_tag_ndef_support (target_info, &is_ndef);
+ PRINT_INFO("target type: %d\n", type);
+ PRINT_INFO("target id: %X\n", (unsigned int)id);
+ PRINT_INFO("Is NDEF supoort: %d\n", is_ndef);
+
+ if (is_ndef){
+
+ ndef_message_h ndef = NULL;
+ data_h bt_config = NULL;
+ net_nfc_create_data_only(&bt_config);
+
+ // 2byte :: OOB length, 6byte :: bt addr
+ uint8_t temp[8] = {0x00, 0x08, 0x00, 0x02, 0x78, 0xDD, 0xC4, 0x8A};
+ net_nfc_create_carrier_config (&config,NET_NFC_CONN_HANDOVER_CARRIER_BT );
+ net_nfc_add_carrier_config_property (config ,NET_NFC_BT_ATTRIBUTE_ADDRESS ,8 ,temp);
+ net_nfc_create_ndef_record_with_carrier_config (&record, config);
+ net_nfc_create_handover_select_message (&ndef);
+ net_nfc_append_carrier_config_record (ndef,record,NET_NFC_CONN_HANDOVER_CARRIER_ACTIVATE);
+ net_nfc_write_ndef(id, ndef, NULL);
+ net_nfc_free_record(record);
+ net_nfc_free_data(bt_config);
+ net_nfc_free_carrier_config(config);
+
+ }
+ else{
+ PRINT_INSTRUCT("Please use NDEF formated tag!!");
+ test_case_result = NET_NFC_TEST_FAIL;
+ }
+ break;
+ }
+ case NET_NFC_MESSAGE_WRITE_NDEF:{
+
+ if(result == NET_NFC_OK){
+ PRINT_INFO("write ndef message is ok");
+ test_case_result = NET_NFC_TEST_OK;
+ }
+
+ pthread_mutex_lock (&plock);
+ pthread_cond_signal (&pcond);
+ pthread_mutex_unlock (&plock);
+ break;
+ }
+ default:
+ break;
+ }
+}
+
+int nfcConnHandover(uint8_t testNumber,void* arg_ptr2)
+{
+ //int user_context = 0;
+ net_nfc_error_e result;
+#if 1
+ test_case_result = NET_NFC_TEST_FAIL;
+
+ result = net_nfc_initialize();
+
+ net_nfc_state_activate();
+
+ CHECK_RESULT(result);
+ result = net_nfc_set_response_callback (net_nfc_test_static_handover_cb, NULL);
+ CHECK_RESULT(result);
+
+ PRINT_INSTRUCT("Please close a tag to device!!");
+
+ //pthread_cond_wait (&pcond,&plock );
+ /*
+ PRINT_INFO("operation is end");
+
+ result = net_nfc_unset_response_callback ();
+
+ CHECK_RESULT(result);
+ result = net_nfc_deinitialize ();
+ CHECK_RESULT(result);
+ */
+#else
+
+/*
+ ndef_message_h ndef = NULL;
+
+ if(net_nfc_retrieve_current_ndef_message(&ndef) == NET_NFC_OK){
+ PRINT_INFO("retrieve is ok");
+ }
+ else{
+ PRINT_INFO("retrieve is failed");
+ return NET_NFC_TEST_FAIL;
+ }
+*/
+ ndef_message_h ndef = NULL;
+ data_h bt_config = NULL;
+ net_nfc_create_data_only(&bt_config);
+
+ // 2byte :: OOB length, 6byte :: bt addr
+ uint8_t temp[8] = {0x00, 0x08, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05};
+
+ net_nfc_set_data(bt_config, temp, 8);
+ net_nfc_create_static_connection_handover_select_message(&ndef, bt_config, NULL);
+
+ net_nfc_conn_handover_info_h handover_info = NULL;
+
+ if(net_nfc_parse_connection_handover_ndef_message(ndef, &handover_info) == NET_NFC_OK){
+ PRINT_INFO("parsing is ok");
+
+ uint8_t version = 0;
+
+ if((result = net_nfc_get_connection_handover_version(handover_info, &version)) == NET_NFC_OK){
+ PRINT_INFO("version = [%d]", version);
+ }
+ else{
+ PRINT_INFO("get version is failed = [%d]", result);
+ }
+
+
+ unsigned short random_number = 0;
+ if((result = net_nfc_get_connection_handover_random_number(handover_info, &random_number)) == NET_NFC_OK)
+ {
+ PRINT_INFO("random_number = [%d]", random_number);
+ }
+ else
+ {
+ PRINT_INFO("get random_number is failed = [%d]", result);
+ }
+
+ data_h record_type = NULL;
+ net_nfc_get_connection_handover_record_type(handover_info, &record_type);
+ PRINT_INFO("record type = [%c] [%c]", (net_nfc_get_data_buffer(record_type))[0], (net_nfc_get_data_buffer(record_type))[1]);
+
+ uint8_t carrier_count = 0;
+ net_nfc_get_connection_handover_alternative_carrier_count(handover_info, &carrier_count);
+
+ int i = 0;
+ for(; i < carrier_count; i++)
+ {
+ net_nfc_conn_handover_carrier_info_h carrier_info = NULL;
+ net_nfc_get_connection_handover_carrier_handle_by_index(handover_info, i, &carrier_info);
+
+ if(carrier_info != NULL){
+ net_nfc_conn_handover_carrier_type_e carrier_type = 0;
+ net_nfc_get_carrier_type(carrier_info, &carrier_type);
+
+ if(carrier_type == NET_NFC_CONN_HANDOVER_CARRIER_BT)
+ {
+ PRINT_INFO("carrier is BT");
+ }
+ else if(carrier_type == NET_NFC_CONN_HANDOVER_CARRIER_WIFI)
+ {
+ PRINT_INFO("carrier is WIFI");
+ }
+ else
+ {
+ PRINT_INFO("carrier is unknown");
+ }
+
+ data_h id = NULL;
+ net_nfc_get_carrier_id(carrier_info, &id);
+
+ PRINT_INFO("id = [0x%x]", (net_nfc_get_data_buffer(id))[0]);
+
+ net_nfc_conn_handover_carrier_state_e carrier_state = 0;
+ net_nfc_get_carrier_power_state(carrier_info, &carrier_state);
+
+ PRINT_INFO("cps is = [0x%x]", carrier_state);
+
+ data_h config = NULL;
+ if((result = net_nfc_get_carrier_configuration(carrier_info, &config)) == NET_NFC_OK)
+ {
+ PRINT_INFO("good to get config");
+ }
+ else
+ {
+ PRINT_INFO("failed to get config = [%d]", result);
+ }
+
+ uint8_t* buffer = NULL;
+ if((buffer = net_nfc_get_data_buffer(config)) != NULL)
+ {
+ unsigned short size = ( buffer[0] << 8 ) |buffer[1];
+ PRINT_INFO("size is = [%d]", size);
+
+ if(size == 8)
+ {
+ PRINT_INFO("carrier addr is [0x%x]", buffer[2]);
+ PRINT_INFO("carrier addr is [0x%x]", buffer[3]);
+ PRINT_INFO("carrier addr is [0x%x]", buffer[4]);
+ PRINT_INFO("carrier addr is [0x%x]", buffer[5]);
+ PRINT_INFO("carrier addr is [0x%x]", buffer[6]);
+ PRINT_INFO("carrier addr is [0x%x]", buffer[7]);
+ }
+ else
+ {
+ PRINT_INFO("more data -_-;; ");
+ }
+ }
+ else
+ {
+ PRINT_INFO("failed to buffer");
+ }
+ }
+
+ }
+ }
+ else{
+
+ PRINT_INFO("parsing is failed");
+
+ return NET_NFC_TEST_FAIL;
+ }
+
+
+ if(handover_info != NULL){
+ if((net_nfc_free_connection_handover_info(handover_info)) == NET_NFC_OK){
+ PRINT_INFO("free is good");
+ }
+ else{
+ PRINT_INFO("free is failed");
+ }
+ }
+#endif
+
+ return test_case_result;
+}
+
+int nfcTestFormatNdef(uint8_t testNumber,void* arg_ptr2)
+{
+ PRINT_INFO("%s is start", __func__);
+
+ //int user_context = 0;
+ net_nfc_error_e result;
+ test_case_result = NET_NFC_TEST_FAIL;
+
+ result = net_nfc_initialize();
+
+ net_nfc_state_activate();
+
+ CHECK_RESULT(result);
+ result = net_nfc_set_response_callback (net_nfc_test_format_cb, (void *)1);
+ CHECK_RESULT(result);
+
+ PRINT_INSTRUCT("Please close a tag to device!!");
+
+ //pthread_cond_wait (&pcond,&plock );
+
+/*
+ PRINT_INFO("operation is end");
+
+ result = net_nfc_unset_response_callback ();
+
+ CHECK_RESULT(result);
+ result = net_nfc_deinitialize ();
+ CHECK_RESULT(result);
+
+*/
+
+ return test_case_result;
+}
+
+int nfcTestInternalSe(uint8_t testNumber,void* arg_ptr2)
+{
+ PRINT_INFO("%s is start", __func__);
+
+ //int user_context = 0;
+ net_nfc_error_e result;
+ test_case_result = NET_NFC_TEST_FAIL;
+
+ result = net_nfc_initialize();
+
+ net_nfc_state_activate();
+
+ CHECK_RESULT(result);
+ result = net_nfc_set_response_callback (net_nfc_test_se_cb, (void *)1);
+ CHECK_RESULT(result);
+
+ net_nfc_get_secure_element_type(NULL);
+
+ PRINT_INSTRUCT("Please close a tag to device!!");
+
+ return test_case_result;
+}
+
+
+
+int nfcTestReaderMode(uint8_t testNumber,void* arg_ptr2)
+{
+ PRINT_INFO("%s is start", __func__);
+
+ //int user_context = 0;
+ net_nfc_error_e result;
+ test_case_result = NET_NFC_TEST_FAIL;
+
+ result = net_nfc_initialize();
+
+ net_nfc_state_activate();
+
+ CHECK_RESULT(result);
+ result = net_nfc_set_response_callback (net_nfc_test_reader_cb, (void *)1);
+ CHECK_RESULT(result);
+
+ PRINT_INSTRUCT("Please close a tag to device!!");
+
+ //pthread_cond_wait (&pcond,&plock );
+
+/*
+ PRINT_INFO("operation is end");
+
+ result = net_nfc_unset_response_callback ();
+
+ CHECK_RESULT(result);
+ result = net_nfc_deinitialize ();
+ CHECK_RESULT(result);
+
+*/
+
+ return test_case_result;
+}
+
+
+/*=================================================================================*/
+
+static void net_nfc_test_write_cb(net_nfc_message_e message, net_nfc_error_e result, void* data, void* user_param, void * trans_data)
+{
+ int user_context;
+
+ switch(message)
+ {
+ case NET_NFC_MESSAGE_TAG_DISCOVERED:{
+ net_nfc_target_type_e type;
+ net_nfc_target_handle_h handle;
+ bool is_ndef;
+ net_nfc_target_info_h target_info = (net_nfc_target_info_h)data;
+
+ net_nfc_get_tag_type (target_info, &type);
+ net_nfc_get_tag_handle (target_info, &handle);
+ net_nfc_get_tag_ndef_support (target_info, &is_ndef);
+ PRINT_INFO("target type: %d\n", type);
+ PRINT_INFO("target id: %X\n", (unsigned int)handle);
+ PRINT_INFO("Is NDEF supoort: %d\n", is_ndef);
+
+ tag_handle = handle;
+
+ if (is_ndef){
+
+ net_nfc_error_e error = NET_NFC_OK;
+ ndef_message_h msg = NULL;
+ ndef_record_h record = NULL;
+
+ if( (error = net_nfc_create_uri_type_record(&record, "http://www.naver.com", NET_NFC_SCHEMA_FULL_URI)) == NET_NFC_OK)
+ {
+ if( (error = net_nfc_create_ndef_message(&msg)) == NET_NFC_OK)
+ {
+ if( (error = net_nfc_append_record_to_ndef_message(msg, record)) == NET_NFC_OK)
+ {
+ ////net_nfc_ndef_print_message(msg);
+ net_nfc_write_ndef(tag_handle, msg, &user_context);
+ net_nfc_free_ndef_message(msg);
+ }
+ else
+ {
+ PRINT_INFO("failed to append ndef message = [%d]", error);
+ net_nfc_free_record(record);
+ net_nfc_free_ndef_message(msg);
+
+ pthread_mutex_lock (&plock);
+ pthread_cond_signal (&pcond);
+ pthread_mutex_unlock (&plock);
+ }
+ }
+ else
+ {
+ PRINT_INFO("failed to create ndef msg");
+ net_nfc_free_record(record);
+
+ pthread_mutex_lock (&plock);
+ pthread_cond_signal (&pcond);
+ pthread_mutex_unlock (&plock);
+ }
+ }
+ else
+ {
+ PRINT_INFO("failed to create text type record");
+
+ pthread_mutex_lock (&plock);
+ pthread_cond_signal (&pcond);
+ pthread_mutex_unlock (&plock);
+ }
+ }
+ else{
+ PRINT_INSTRUCT("Please use NDEF formated tag!!");
+ break;
+ }
+
+ break;
+ }
+ case NET_NFC_MESSAGE_TAG_DETACHED:
+ {
+ if (write_count++ >= 20) {
+ test_case_result = NET_NFC_TEST_OK;
+ pthread_mutex_lock (&plock);
+ pthread_cond_signal (&pcond);
+ pthread_mutex_unlock (&plock);
+ }
+ else {
+ PRINT_INSTRUCT("Please close a tag to device again!!");
+ }
+ }
+ break;
+
+ case NET_NFC_MESSAGE_WRITE_NDEF:
+ {
+ /*if (result == NET_NFC_OK) {
+ test_case_result = NET_NFC_TEST_OK;
+ }
+ else {
+ PRINT_INFO("received error: %d\n", result);
+ test_case_result = NET_NFC_TEST_FAIL;
+ }
+ */
+
+ /* pthread_mutex_lock (&plock);
+ pthread_cond_signal (&pcond);
+ pthread_mutex_unlock (&plock);
+ */
+
+ if(write_count++ == 20)
+ {
+
+ PRINT_INSTRUCT("completed, please remove tag");
+ }
+
+ {
+
+ net_nfc_error_e error = NET_NFC_OK;
+ ndef_message_h msg = NULL;
+ ndef_record_h record = NULL;
+
+ if( (error = net_nfc_create_text_type_record(&record, "This is real NFC", "en-US", NET_NFC_ENCODE_UTF_8)) == NET_NFC_OK)
+ {
+ if( (error = net_nfc_create_ndef_message(&msg)) == NET_NFC_OK)
+ {
+ if( (error = net_nfc_append_record_to_ndef_message(msg, record)) == NET_NFC_OK)
+ {
+ ////net_nfc_ndef_print_message(msg);
+ net_nfc_write_ndef(tag_handle, msg, &user_context);
+ net_nfc_free_ndef_message(msg);
+ }
+ else
+ {
+ PRINT_INFO("failed to append ndef message = [%d]", error);
+ net_nfc_free_record(record);
+ net_nfc_free_ndef_message(msg);
+ test_case_result = NET_NFC_TEST_FAIL;
+
+ pthread_mutex_lock (&plock);
+ pthread_cond_signal (&pcond);
+ pthread_mutex_unlock (&plock);
+ }
+ }
+ else
+ {
+ PRINT_INFO("failed to create ndef msg");
+ net_nfc_free_record(record);
+ test_case_result = NET_NFC_TEST_FAIL;
+
+ pthread_mutex_lock (&plock);
+ pthread_cond_signal (&pcond);
+ pthread_mutex_unlock (&plock);
+ }
+ }
+ else
+ {
+ PRINT_INFO("failed to create text type record");
+ test_case_result = NET_NFC_TEST_FAIL;
+
+ pthread_mutex_lock (&plock);
+ pthread_cond_signal (&pcond);
+ pthread_mutex_unlock (&plock);
+
+ }
+ }
+
+ break;
+ }
+ default:
+ break;
+ }
+}
+
+
+int nfcTestWriteMode(uint8_t testNumber,void* arg_ptr2)
+{
+ //int user_context = 0;
+ net_nfc_error_e result;
+ test_case_result = NET_NFC_TEST_FAIL;
+
+ result = net_nfc_initialize();
+ CHECK_RESULT(result);
+
+ net_nfc_state_activate();
+
+ result = net_nfc_set_response_callback (net_nfc_test_write_cb, NULL);
+ CHECK_RESULT(result);
+
+ write_count = 0;
+ PRINT_INSTRUCT("TEST: remove tag while write");
+ PRINT_INSTRUCT("Please close a tag to device!!");
+
+ //pthread_cond_wait (&pcond,&plock );
+
+/*
+ result = net_nfc_unset_response_callback ();
+ CHECK_RESULT(result);
+ result = net_nfc_deinitialize ();
+ CHECK_RESULT(result);
+*/
+ return test_case_result;
+
+}
+
+
+int nfcTestReadWriteMode(uint8_t testNumber,void* arg_ptr2)
+{
+ //int user_context = 0;
+ net_nfc_error_e result;
+ test_case_result = NET_NFC_TEST_FAIL;
+
+ read_count = 0;
+ write_count = 0;
+
+ result = net_nfc_initialize();
+ CHECK_RESULT(result);
+
+ net_nfc_state_activate();
+
+ result = net_nfc_set_response_callback (net_nfc_test_read_write_cb, NULL);
+ CHECK_RESULT(result);
+
+ PRINT_INSTRUCT("Testing (50 each) read and write test");
+ PRINT_INSTRUCT("Please close a tag to device!!");
+
+ //pthread_cond_wait (&pcond,&plock );
+/*
+ result = net_nfc_unset_response_callback ();
+ CHECK_RESULT(result);
+ result = net_nfc_deinitialize ();
+ CHECK_RESULT(result);
+*/
+
+
+ return test_case_result;
+
+}
+
+/*=================================================================================*/
+
+static void net_nfc_test_transceive_cb(net_nfc_message_e message, net_nfc_error_e result, void* data, void* user_param, void * trans_data)
+{
+ //int user_context;
+
+ printf ("callback is called with message %d\n", message);
+ switch(message)
+ {
+ case NET_NFC_MESSAGE_TAG_DISCOVERED:{
+ net_nfc_target_type_e type;
+ net_nfc_target_handle_h id;
+ bool is_ndef;
+ net_nfc_target_info_h target_info = (net_nfc_target_info_h)data;
+ net_nfc_error_e result = NET_NFC_OK;
+
+ net_nfc_get_tag_type (target_info, &type);
+ net_nfc_get_tag_handle (target_info, &id);
+ net_nfc_get_tag_ndef_support (target_info, &is_ndef);
+ PRINT_INFO("target type: %d\n", type);
+ PRINT_INFO("target id: %X\n", (unsigned int)id);
+ PRINT_INFO("Is NDEF supoort: %d\n", is_ndef);
+
+ tag_handle = id;
+
+ if(type == NET_NFC_MIFARE_ULTRA_PICC){
+
+ if((result = net_nfc_mifare_read(tag_handle, 0, NULL)) != NET_NFC_OK){
+ PRINT_INFO("failed to read = [%d]", result);
+ }
+ }
+
+ else if(type >= NET_NFC_MIFARE_MINI_PICC && type <= NET_NFC_MIFARE_4K_PICC){
+
+ data_h mad_key = NULL;
+ data_h net_nfc_forum_key = NULL;
+ data_h default_key = NULL;
+
+ net_nfc_mifare_create_application_directory_key(&mad_key);
+ net_nfc_mifare_create_net_nfc_forum_key(&net_nfc_forum_key);
+ net_nfc_mifare_create_default_key(&default_key);
+
+ int sector = 1;
+
+ data_h key = NULL;
+ test_count = 4;
+
+ if(sector == 0){
+ key = mad_key;
+ }
+ else{
+ key = default_key;
+// key = net_nfc_forum_key;
+ }
+
+// if(net_nfc_mifare_authenticate_with_keyB(id, sector, key, NULL) != NET_NFC_OK){
+ if(net_nfc_mifare_authenticate_with_keyA(id, sector, default_key, NULL) != NET_NFC_OK){
+ PRINT_INFO("failed to authenticate sector");
+
+ }
+ else{
+
+ int nBlocks = 0;
+
+// if(type == NET_NFC_MIFARE_4K_PICC && sector > 31){
+//
+// nBlocks = 16;
+// }
+// else{
+// nBlocks = 4;
+// }
+
+ nBlocks = 4;
+
+
+/*
+ int j = 0;
+
+ for(; j < nBlocks; j++){
+ if((result = net_nfc_mifare_read(tag_handle, sector * 4 + j, NULL)) != NET_NFC_OK){
+ PRINT_INFO("failed to read = [%d]", result);
+ }else{
+ PRINT_INFO("block [%d] is read", sector * 4 + j);
+ }
+ }
+*/
+/*
+ data_h write_block = NULL;
+ uint8_t buffer[16] = {0x00,};
+ uint8_t* temp = buffer;
+
+ int value = 1000;
+ int value_comp = 1 + ~value;
+ uint8_t addr = 5;
+ uint8_t addr_comp = 1 + ~addr;
+
+
+ // read block 5 and write block 5 and read again
+ if((result = net_nfc_mifare_read(tag_handle, addr, NULL)) != NET_NFC_OK){
+ PRINT_INFO("failed to read = [%d]", result);
+ }else{
+ PRINT_INFO("block 5 is read");
+ }
+
+ // read block 5 and write block 5 and read again
+
+ memcpy(temp, &value, sizeof(int));
+ temp = temp + sizeof(int);
+
+ memcpy(temp, &value_comp, sizeof(int));
+ temp = temp + sizeof(int);
+
+ memcpy(temp, &value, sizeof(int));
+ temp = temp + sizeof(int);
+
+ *temp = addr;
+ temp = temp + 1;
+
+ *temp = addr_comp;
+ temp = temp + 1;
+
+ *temp = addr;
+ temp = temp + 1;
+
+ *temp = addr_comp;
+
+ net_nfc_create_data(&write_block, buffer, 16);
+
+ if((result = net_nfc_mifare_write_block(tag_handle, addr, write_block,NULL)) != NET_NFC_OK){
+ PRINT_INFO("failed to write = [%d]", result);
+ }else{
+ PRINT_INFO("block 5 is written");
+ }
+
+ if((result = net_nfc_mifare_read(tag_handle, addr, NULL)) != NET_NFC_OK){
+ PRINT_INFO("failed to read = [%d]", result);
+ }else{
+ PRINT_INFO("block 5 is read");
+ }
+*/
+
+ // read block 6 and decrease 6 and read again
+
+/*
+ if((result = net_nfc_mifare_read(tag_handle, 7, NULL)) != NET_NFC_OK){
+ PRINT_INFO("failed to read = [%d]", result);
+ }else{
+ PRINT_INFO("read sector trailor of sector 1. it will be a block 7 th");
+ }
+*/
+
+/*
+ data_h write_block = NULL;
+ uint8_t buffer[16] = {0x00, 0x00, 0x03, 0xE8, 0xFF, 0xFF, 0xFC, 0x18, 0x00, 0x00, 0x03, 0xE8, 0x05, 0xFB, 0x05, 0xFB};
+
+ net_nfc_create_data(&write_block, buffer, 16);
+
+ if((result = net_nfc_mifare_write_block(tag_handle, 5, write_block, NULL)) != NET_NFC_OK){
+ PRINT_INFO("failed to write = [%d]", result);
+ }else{
+ PRINT_INFO("block 5 is written");
+ }
+
+
+ if((result = net_nfc_mifare_read(tag_handle, 5, NULL)) != NET_NFC_OK){
+ PRINT_INFO("failed to read = [%d]", result);
+ }else{
+ PRINT_INFO("block 5 is read");
+ }
+*/
+
+
+ if((result = net_nfc_mifare_read(tag_handle, 5, NULL)) != NET_NFC_OK){
+ PRINT_INFO("failed to read = [%d]", result);
+ }
+
+
+ int decrease_amount = 10; // 10 won
+
+ if((result = net_nfc_mifare_decrement(tag_handle, 5, decrease_amount, NULL)) != NET_NFC_OK){
+ PRINT_INFO("failed to decrease = [%d]", result);
+ }else{
+ PRINT_INFO("block 5 is decreased");
+ }
+
+ if((result = net_nfc_mifare_transfer(tag_handle, 5, NULL)) != NET_NFC_OK){
+ PRINT_INFO("failed to transfer = [%d]", result);
+ }else{
+ PRINT_INFO("internal register is transfered to block 5");
+ }
+
+/*
+ if((result = net_nfc_mifare_read(tag_handle, 5, NULL)) != NET_NFC_OK){
+ PRINT_INFO("failed to read = [%d]", result);
+ }
+*/
+
+
+ }
+ net_nfc_free_data(key);
+ net_nfc_free_data(default_key);
+ net_nfc_free_data(mad_key);
+ net_nfc_free_data(net_nfc_forum_key);
+
+ }
+ else if(type == NET_NFC_JEWEL_PICC){
+
+ if(net_nfc_jewel_read_id(id, NULL) != NET_NFC_OK){
+ PRINT_INFO("failed to read ID");
+ }
+
+ test_count = 0;
+
+ }else if(type == NET_NFC_FELICA_PICC){
+
+ test_count = 4;
+ net_nfc_error_e result = NET_NFC_OK;
+
+/*
+ if((result = net_nfc_felica_poll(id, NET_NFC_FELICA_POLL_COMM_SPEED_REQUEST, 0x0, NULL)) != NET_NFC_OK){
+ PRINT_INFO("can not execute cmd felica poll");
+ }
+ else{
+ PRINT_INFO("send poll req cmd is success");
+ }
+
+ if((result = net_nfc_felica_request_system_code(id, NULL)) != NET_NFC_OK){
+ PRINT_INFO("can not execute cmd felica request system code");
+ }
+ else{
+ PRINT_INFO("send request system req cmd is success");
+ }
+
+ if((result = net_nfc_felica_request_response(id, NULL)) != NET_NFC_OK){
+ PRINT_INFO("can not execute cmd felica request response");
+ }
+ else{
+ PRINT_INFO("send request response cmd is success");
+ }
+
+ uint16_t service_code = 0xffff;
+ if((result = net_nfc_felica_request_service(id, 1, &service_code, 1, NULL)) != NET_NFC_OK){
+ PRINT_INFO("can not execute cmd felica request response");
+ }
+ else{
+ PRINT_INFO("send request response cmd is success");
+ }
+*/
+
+ uint16_t service_code = 0xffff;
+ uint8_t blocks = 0x2;
+
+ if((result = net_nfc_felica_read_without_encryption(id, 1, &service_code, 1, &blocks, NULL)) != NET_NFC_OK){
+ PRINT_INFO("can not execute cmd felica request response");
+ }
+ else{
+ PRINT_INFO("send request response cmd is success");
+ }
+ }
+
+ break;
+ }
+ case NET_NFC_MESSAGE_TRANSCEIVE:{
+ if (result == NET_NFC_OK) {
+
+ if(test_count == 0){
+ int idx;
+ data_h r_data = (data_h) data;
+
+ uint8_t * r_buffer = net_nfc_get_data_buffer (r_data);
+ uint32_t r_buffer_length = net_nfc_get_data_length (r_data);
+
+ PRINT_INFO ("read uid is ok. format is = > [HeadRom0][HeadRom1][UID0][UID1][UID2][UID3]");
+ PRINT_INFO ("Received data [size:%d] \n", net_nfc_get_data_length (r_data));
+
+ for (idx = 0; idx < r_buffer_length; idx++){
+ printf (" %02X", r_buffer[idx]);
+ }printf ("\n");
+
+ PRINT_INFO("READ ALL DATA");
+ if((result = net_nfc_jewel_read_all(tag_handle, NULL)) != NET_NFC_OK){
+ PRINT_INFO("failed to read all jewel tag = [%d]", result);
+ }
+
+ test_count = 1;
+ }
+ else if(test_count == 1){
+ int idx;
+ data_h r_data = (data_h) data;
+
+ uint8_t * r_buffer = net_nfc_get_data_buffer (r_data);
+ uint32_t r_buffer_length = net_nfc_get_data_length (r_data);
+
+ PRINT_INFO ("Received data [size:%d] \n", net_nfc_get_data_length (r_data));
+
+ for (idx = 0; idx < r_buffer_length; idx++){
+ printf (" %02X", r_buffer[idx]);
+ }printf ("\n");
+
+ test_case_result = NET_NFC_TEST_OK;
+
+ // read UID0
+
+ PRINT_INFO("READ one byte. addr is the first byte of block 0");
+ if((result = net_nfc_jewel_read_byte(tag_handle, 0, 0, NULL)) != NET_NFC_OK){
+ PRINT_INFO("failed to read all jewel tag = [%d]", result);
+ }
+
+ test_count = 2;
+
+ }
+ else if(test_count == 2){
+ int idx;
+ data_h r_data = (data_h) data;
+
+ uint8_t * r_buffer = net_nfc_get_data_buffer (r_data);
+ uint32_t r_buffer_length = net_nfc_get_data_length (r_data);
+
+ PRINT_INFO ("Received data [size:%d] \n", net_nfc_get_data_length (r_data));
+
+ for (idx = 0; idx < r_buffer_length; idx++){
+ printf (" %02X", r_buffer[idx]);
+ }printf ("\n");
+
+ test_case_result = NET_NFC_TEST_OK;
+
+ // read UID0
+ PRINT_INFO("erase and write data 0xff . addr is the first byte of block 1");
+ if((result = net_nfc_jewel_write_with_erase(tag_handle, 1, 0, 0xff, NULL)) != NET_NFC_OK){
+ PRINT_INFO("failed to read all jewel tag = [%d]", result);
+ }
+
+ test_count = 3;
+ }
+ else if(test_count == 3){
+ int idx;
+ data_h r_data = (data_h) data;
+
+ uint8_t * r_buffer = net_nfc_get_data_buffer (r_data);
+ uint32_t r_buffer_length = net_nfc_get_data_length (r_data);
+
+ PRINT_INFO ("Received data [size:%d] \n", net_nfc_get_data_length (r_data));
+
+ for (idx = 0; idx < r_buffer_length; idx++){
+ printf (" %02X", r_buffer[idx]);
+ }printf ("\n");
+
+ test_case_result = NET_NFC_TEST_OK;
+
+ // read UID0
+ PRINT_INFO("read one byte . addr is the first byte of block 1");
+ if((result = net_nfc_jewel_read_byte(tag_handle, 1, 0, NULL)) != NET_NFC_OK){
+ PRINT_INFO("failed to read all jewel tag = [%d]", result);
+ }
+
+ test_count = 4;
+ }
+ else if(test_count == 4){
+
+ int idx;
+ data_h r_data = (data_h) data;
+
+ uint8_t * r_buffer = net_nfc_get_data_buffer (r_data);
+ uint32_t r_buffer_length = net_nfc_get_data_length (r_data);
+
+ PRINT_INFO ("Received data [size:%d] \n", net_nfc_get_data_length (r_data));
+
+ for (idx = 0; idx < r_buffer_length; idx++){
+ printf (" %02X", r_buffer[idx]);
+ }printf ("\n");
+ }
+ else if(test_count == 5){
+ PRINT_INFO("auth key A is success = [%d]", result);
+ test_case_result = NET_NFC_TEST_OK;
+ //net_nfc_error_e result = NET_NFC_OK;
+ /*
+ if((result = net_nfc_mifare_read(tag_handle, 0, NULL)) != NET_NFC_OK){
+
+ PRINT_INFO("failed to read = [%d]", result);
+ }else{
+ PRINT_INFO("calling read is ok");
+ }
+
+ test_count = 4;
+ */
+ }
+ }
+ else {
+
+ PRINT_INFO("trancecive is failed with %d\n", result);
+ test_case_result = NET_NFC_TEST_FAIL;
+
+ //pthread_mutex_lock (&plock);
+ //pthread_cond_signal (&pcond);
+ //pthread_mutex_unlock (&plock);
+ }
+ }
+
+ default:
+ break;
+ }
+}
+
+
+#define NUM_OF_THREAD 10
+#define REQUEST_PER_THREAD 5
+
+static int number_of_read_completed = 0;
+
+static void* net_nfc_read_ndef_test(void* handle)
+{
+ net_nfc_target_handle_h target_handle = (net_nfc_target_handle_h)handle;
+ int count = 0;
+
+ for (count = 0; count < REQUEST_PER_THREAD ; count ++)
+ {
+ if(net_nfc_read_tag(target_handle, NULL) == NET_NFC_OK)
+ {
+ PRINT_INFO("send request is success");
+ }
+ else
+ {
+ PRINT_INFO("send request is failed");
+ }
+ }
+
+ return (void *)NULL;
+}
+static void net_nfc_test_multiple_request_cb(net_nfc_message_e message, net_nfc_error_e result, void* data, void* user_param, void * trans_data)
+{
+ //int user_context;
+
+ printf ("callback is called with message %d\n", message);
+
+ switch(message)
+ {
+ case NET_NFC_MESSAGE_TAG_DISCOVERED:
+ {
+ net_nfc_target_type_e type;
+ net_nfc_target_handle_h handle;
+ bool is_ndef;
+ net_nfc_target_info_h target_info = (net_nfc_target_info_h)data;
+
+ net_nfc_get_tag_type (target_info, &type);
+ net_nfc_get_tag_handle (target_info, &handle);
+ net_nfc_get_tag_ndef_support (target_info, &is_ndef);
+ PRINT_INFO("target type: %d\n", type);
+ PRINT_INFO("target handle: %X\n", (unsigned int)handle);
+ PRINT_INFO("Is NDEF supoort: %d\n", is_ndef);
+
+ test_case_result = NET_NFC_TEST_OK;
+ number_of_read_completed = 0;
+
+ pthread_t read_thread[NUM_OF_THREAD];
+ pthread_attr_t attr;
+ pthread_attr_init(&attr);
+ pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
+
+ int i =0;
+ for(; i < NUM_OF_THREAD; i++)
+ {
+ pthread_create(&read_thread[i], &attr, net_nfc_read_ndef_test, handle);
+ }
+
+ }
+ break;
+
+ case NET_NFC_MESSAGE_READ_NDEF:
+ {
+ PRINT_INFO("NET_NFC_MESSAGE_READ_NDEF result = [%d]\n", result);
+
+ if(data != NULL)
+ {
+ PRINT_INFO("read ndef msg");
+ number_of_read_completed ++;
+
+ //ndef_message_h ndef = (ndef_message_h)(data);
+
+ ////net_nfc_ndef_print_message(ndef);
+
+ if (number_of_read_completed == NUM_OF_THREAD * REQUEST_PER_THREAD)
+ {
+ test_case_result = NET_NFC_TEST_OK;
+ PRINT_INSTRUCT("Test is completed. please remove the tag !!");
+ }
+ }
+ }
+ break;
+
+ case NET_NFC_MESSAGE_TAG_DETACHED:
+ {
+ PRINT_INFO("NET_NFC_MESSAGE_TAG_DETACHED \n");
+
+ pthread_mutex_lock (&plock);
+ pthread_cond_signal (&pcond);
+ pthread_mutex_unlock (&plock);
+ }
+ break;
+
+ case NET_NFC_MESSAGE_NOTIFY:
+ {
+ PRINT_INFO("NET_NFC_MESSAGE_NOTIFY \n");
+ }
+ break;
+
+ default:
+ break;
+ }
+}
+
+#define NUM_OF_DETECT_TRY 10
+
+static void net_nfc_test_detected_cb(net_nfc_message_e message, net_nfc_error_e result, void* data, void* user_param, void * trans_data)
+{
+ //int user_context;
+
+ printf ("callback is called with message %d\n", message);
+
+ switch(message)
+ {
+ case NET_NFC_MESSAGE_TAG_DISCOVERED:
+ {
+ net_nfc_target_type_e type;
+ net_nfc_target_handle_h id;
+ bool is_ndef;
+ net_nfc_target_info_h target_info = (net_nfc_target_info_h)data;
+
+ net_nfc_get_tag_type (target_info, &type);
+ net_nfc_get_tag_handle (target_info, &id);
+ net_nfc_get_tag_ndef_support (target_info, &is_ndef);
+
+ PRINT_INFO("target type: %d\n", type);
+ PRINT_INFO("target handle: %X\n", (unsigned int)id);
+ PRINT_INFO("Is NDEF supoort: %d\n", is_ndef);
+
+ char** keys = NULL;
+ int nok = 0; // number of keys
+ net_nfc_error_e error = NET_NFC_OK;
+
+ if((error = net_nfc_get_tag_info_keys(target_info, &keys, &nok)) == NET_NFC_OK)
+ {
+ int i = 0;
+ for(; i < nok; i++)
+ {
+ PRINT_INFO("key [%s]", keys[i]);
+
+ data_h value = NULL;
+ if((error = net_nfc_get_tag_info_value(target_info, keys[i], &value)) == NET_NFC_OK)
+ {
+ int index = 0;
+ uint32_t data_length = net_nfc_get_data_length(value);
+ uint8_t* data_buffer = net_nfc_get_data_buffer(value);
+
+ PRINT_INFO("\n key [%s] >> ", keys[i]);
+ if(data_length > 1)
+ {
+ for(; index < data_length; index++)
+ {
+ printf(" [0x%x] ", data_buffer[index]);
+ }
+ }
+ else
+ {
+ printf(" [0x%x] ", *data_buffer);
+ }
+
+
+ PRINT_INFO("<< \n");
+ }
+ else
+ {
+ PRINT_INFO("get value is failed = [0x%x]", error);
+ }
+ }
+ }
+ else
+ {
+ PRINT_INFO("failed to get keys = [%d]", error);
+ }
+
+ free(keys);
+
+
+ detect_count++;
+
+ PRINT_INFO("TAG is detected = [%d]", detect_count);
+ PRINT_INSTRUCT("please remove the tag !! Test left [%d] times", NUM_OF_DETECT_TRY - detect_count);
+
+ }
+ break;
+
+ case NET_NFC_MESSAGE_TAG_DETACHED:
+ {
+ PRINT_INSTRUCT("please close the tag again!!");
+
+ //pthread_mutex_lock (&plock);
+ //pthread_cond_signal (&pcond);
+ //pthread_mutex_unlock (&plock);
+
+ if(detect_count >= NUM_OF_DETECT_TRY)
+ {
+ test_case_result = NET_NFC_TEST_OK;
+ pthread_mutex_lock (&plock);
+ pthread_cond_signal (&pcond);
+ pthread_mutex_unlock (&plock);
+ }
+ }
+ break;
+
+ case NET_NFC_MESSAGE_NOTIFY:
+ {
+ PRINT_INFO("NET_NFC_MESSAGE_NOTIFY \n");
+ }
+ break;
+
+ default:
+ break;
+ }
+}
+
+
+static void* net_nfc_read_stress_ndef_test(void* handle)
+{
+ net_nfc_target_handle_h target_handle = (net_nfc_target_handle_h)handle;
+ int count = 0;
+
+ for (count = 0; count < 200 ; count ++)
+ {
+ if(net_nfc_read_tag(target_handle, NULL) == NET_NFC_OK)
+ {
+ }
+ else
+ {
+ PRINT_INFO("send request is failed");
+ }
+ }
+
+ PRINT_INFO("send request is completed");
+
+ return (void *)NULL;
+}
+
+static void net_nfc_test_read_cb(net_nfc_message_e message, net_nfc_error_e result, void* data, void* user_param, void * trans_data)
+{
+ //int user_context;
+
+ switch(message)
+ {
+ case NET_NFC_MESSAGE_TAG_DISCOVERED:
+ {
+ net_nfc_target_type_e type;
+ net_nfc_target_handle_h handle;
+ bool is_ndef;
+ net_nfc_target_info_h target_info = (net_nfc_target_info_h)data;
+
+ net_nfc_get_tag_type (target_info, &type);
+ net_nfc_get_tag_handle (target_info, &handle);
+ net_nfc_get_tag_ndef_support (target_info, &is_ndef);
+ PRINT_INFO("target type: %d\n", type);
+ PRINT_INFO("target handle: %X\n", (unsigned int)handle);
+ PRINT_INFO("Is NDEF supoort: %d\n", is_ndef);
+
+ if(is_ndef)
+ {
+ pthread_t read_thread;
+ pthread_attr_t attr;
+ pthread_attr_init(&attr);
+ pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
+
+ pthread_create(&read_thread, &attr, net_nfc_read_stress_ndef_test, handle);
+ }
+ else
+ {
+ PRINT_INFO("non ndef tag.");
+
+ test_case_result = NET_NFC_TEST_FAIL;
+
+ pthread_mutex_lock (&plock);
+ pthread_cond_signal (&pcond);
+ pthread_mutex_unlock (&plock);
+ }
+
+ }
+ break;
+
+ case NET_NFC_MESSAGE_READ_NDEF:
+ {
+ if(data != NULL){
+
+ //ndef_message_h ndef = (ndef_message_h)(data);
+
+ ////net_nfc_ndef_print_message(ndef);
+
+ test_case_result = NET_NFC_TEST_OK;
+
+ read_count++;
+ }
+
+ if(read_count == 20)
+ {
+ PRINT_INSTRUCT("please remove the tag !!");
+ }
+
+ break;
+ }
+ break;
+
+ case NET_NFC_MESSAGE_TAG_DETACHED:
+ {
+ PRINT_INFO("NET_NFC_MESSAGE_TAG_DETACHED \n");
+
+ if (read_count >= 20 && read_count < 200){
+ test_case_result = NET_NFC_TEST_OK;
+ pthread_mutex_lock (&plock);
+ pthread_cond_signal (&pcond);
+ pthread_mutex_unlock (&plock);
+ }
+ else {
+ PRINT_INSTRUCT("please close the tag again !!");
+ }
+
+
+ }
+ break;
+
+ case NET_NFC_MESSAGE_NOTIFY:
+ {
+ PRINT_INFO("NET_NFC_MESSAGE_NOTIFY \n");
+ }
+ break;
+
+ default:
+ break;
+ }
+}
+
+
+static void net_nfc_test_read_write_cb(net_nfc_message_e message, net_nfc_error_e result, void* data, void* user_param, void * trans_data)
+{
+ int user_context;
+
+ printf ("callback is called with message %d\n", message);
+
+ switch(message)
+ {
+ case NET_NFC_MESSAGE_TAG_DISCOVERED:
+ {
+ net_nfc_target_type_e type;
+ net_nfc_target_handle_h handle;
+ bool is_ndef;
+ net_nfc_target_info_h target_info = (net_nfc_target_info_h)data;
+
+ net_nfc_get_tag_type (target_info, &type);
+ net_nfc_get_tag_handle (target_info, &handle);
+ net_nfc_get_tag_ndef_support (target_info, &is_ndef);
+ PRINT_INFO("target type: %d\n", type);
+ PRINT_INFO("target handle: %X\n", (unsigned int)handle);
+ PRINT_INFO("Is NDEF supoort: %d\n", is_ndef);
+
+ if(is_ndef)
+ {
+ tag_handle = handle;
+ if(net_nfc_read_tag(handle, user_param) == NET_NFC_OK)
+ {
+ PRINT_INFO("try to read ndef");
+ }
+ }
+ else
+ {
+ PRINT_INFO("non ndef tag.");
+
+ test_case_result = NET_NFC_TEST_FAIL;
+
+ pthread_mutex_lock (&plock);
+ pthread_cond_signal (&pcond);
+ pthread_mutex_unlock (&plock);
+ }
+
+ }
+ break;
+
+ case NET_NFC_MESSAGE_READ_NDEF:
+ {
+ if (write_count >= 50){
+ PRINT_INSTRUCT("Test is finished. Please remove the tag from device!!");
+ test_case_result = NET_NFC_TEST_OK;
+ break;
+ }
+ if(data != NULL){
+
+ //ndef_message_h ndef = (ndef_message_h)(data);
+
+ ////net_nfc_ndef_print_message(ndef);
+
+ test_case_result = NET_NFC_TEST_OK;
+
+ net_nfc_error_e error = NET_NFC_OK;
+ ndef_message_h msg = NULL;
+ ndef_record_h record = NULL;
+
+ if( (error = net_nfc_create_text_type_record(&record, "This is real NFC", "en-US", NET_NFC_ENCODE_UTF_8)) == NET_NFC_OK)
+ {
+ if( (error = net_nfc_create_ndef_message(&msg)) == NET_NFC_OK)
+ {
+ if( (error = net_nfc_append_record_to_ndef_message(msg, record)) == NET_NFC_OK)
+ {
+ ////net_nfc_ndef_print_message(msg);
+
+ if(net_nfc_write_ndef(tag_handle, msg, &user_context) == NET_NFC_OK)
+ {
+ PRINT_INFO("write count = [%d] \n", write_count++);
+ PRINT_INFO("write ndef msg");
+ }
+ net_nfc_free_ndef_message(msg);
+ }
+ else
+ {
+ PRINT_INFO("failed to append ndef message = [%d]", error);
+ net_nfc_free_record(record);
+ net_nfc_free_ndef_message(msg);
+
+ pthread_mutex_lock (&plock);
+ pthread_cond_signal (&pcond);
+ pthread_mutex_unlock (&plock);
+ }
+ }
+ else
+ {
+ PRINT_INFO("failed to create ndef msg");
+ net_nfc_free_record(record);
+
+ pthread_mutex_lock (&plock);
+ pthread_cond_signal (&pcond);
+ pthread_mutex_unlock (&plock);
+ }
+ }
+ else
+ {
+ PRINT_INFO("failed to create text type record");
+
+ pthread_mutex_lock (&plock);
+ pthread_cond_signal (&pcond);
+ pthread_mutex_unlock (&plock);
+
+ }
+
+ }
+ else
+ {
+ test_case_result = NET_NFC_TEST_FAIL;
+
+ pthread_mutex_lock (&plock);
+ pthread_cond_signal (&pcond);
+ pthread_mutex_unlock (&plock);
+
+ break;
+ }
+
+ //net_nfc_read_ndef(tag_handle, user_param);
+
+ break;
+ }
+ break;
+
+ case NET_NFC_MESSAGE_WRITE_NDEF:
+ {
+ if (result == NET_NFC_OK) {
+
+ test_case_result = NET_NFC_TEST_OK;
+
+ if(net_nfc_read_tag(tag_handle, user_param) == NET_NFC_OK)
+ {
+ PRINT_INFO("read count = [%d] \n", read_count++);
+ PRINT_INFO("try to read ndef");
+ }
+ }
+ else {
+ PRINT_INFO("received error: %d\n", result);
+ test_case_result = NET_NFC_TEST_FAIL;
+
+ pthread_mutex_lock (&plock);
+ pthread_cond_signal (&pcond);
+ pthread_mutex_unlock (&plock);
+ }
+ }
+ break;
+
+ case NET_NFC_MESSAGE_TAG_DETACHED:
+ {
+ PRINT_INFO("NET_NFC_MESSAGE_TAG_DETACHED \n");
+
+ pthread_mutex_lock (&plock);
+ pthread_cond_signal (&pcond);
+ pthread_mutex_unlock (&plock);
+ }
+ break;
+
+ case NET_NFC_MESSAGE_NOTIFY:
+ {
+ PRINT_INFO("NET_NFC_MESSAGE_NOTIFY \n");
+ }
+ break;
+
+ default:
+ break;
+ }
+}
+
+
+int nfcTestAPIMultipleRequest(uint8_t testNumber,void* arg_ptr2)
+{
+ //int user_context = 0;
+ net_nfc_error_e result;
+ test_case_result = NET_NFC_TEST_FAIL;
+
+ result = net_nfc_initialize();
+ CHECK_RESULT(result);
+
+ net_nfc_state_activate();
+
+ result = net_nfc_set_response_callback (net_nfc_test_multiple_request_cb, NULL);
+ CHECK_RESULT(result);
+
+ PRINT_INSTRUCT("Please close a tag to device for a while!!");
+
+ //pthread_cond_wait (&pcond,&plock );
+/*
+ result = net_nfc_unset_response_callback ();
+ CHECK_RESULT(result);
+
+ result = net_nfc_deinitialize ();
+ CHECK_RESULT(result);
+*/
+ return test_case_result;
+}
+
+
+int nfcTestAPIBasicTest1(uint8_t testNumber,void* arg_ptr2)
+{
+ //int user_context = 0;
+ net_nfc_error_e result;
+ test_case_result = NET_NFC_TEST_FAIL;
+
+ //int length = 0;
+
+/*
+ char** keys = NULL;
+
+ int i = 0;
+
+ for(i; i < NET_NFC_NFCIP1_INITIATOR; i++)
+ {
+ if(net_nfc_get_tag_info_keys(i, &keys, &length) == NET_NFC_OK)
+ {
+ int index = 0;
+
+ PRINT_INFO("############################\n") ;
+ for(; index < length; index++)
+ {
+ PRINT_INFO("supported key = [%s] \n", keys[index]);
+ }
+ PRINT_INFO("############################\n") ;
+
+ test_case_result = NET_NFC_TEST_OK;
+ }
+ }
+*/
+
+ result = net_nfc_initialize();
+ CHECK_RESULT(result);
+
+ net_nfc_state_activate();
+
+ result = net_nfc_set_response_callback (net_nfc_test_detected_cb, NULL);
+
+// net_nfc_set_tag_filter(NET_NFC_ALL_DISABLE);
+// net_nfc_set_tag_filter(NET_NFC_ISO14443A_ENABLE);
+// net_nfc_set_tag_filter(NET_NFC_ISO14443B_ENABLE);
+// net_nfc_set_tag_filter(NET_NFC_ISO15693_ENABLE );
+// net_nfc_set_tag_filter(NET_NFC_FELICA_ENABLE );
+// net_nfc_set_tag_filter(NET_NFC_JEWEL_ENABLE );
+// net_nfc_set_tag_filter(NET_NFC_ALL_ENABLE );
+
+
+ CHECK_RESULT(result);
+
+ //PRINT_INSTRUCT("Please close a tag to device!!");
+
+ //pthread_cond_wait (&pcond,&plock );
+
+/*
+ result = net_nfc_unset_response_callback ();
+ CHECK_RESULT(result);
+
+ result = net_nfc_deinitialize ();
+
+ sleep(1000);
+
+ CHECK_RESULT(result);
+*/
+
+ return test_case_result;
+}
+
+int nfcTestAPIBasicTest2(uint8_t testNumber,void* arg_ptr2)
+{
+ //int user_context = 0;
+ net_nfc_error_e result;
+ test_case_result = NET_NFC_TEST_FAIL;
+
+ result = net_nfc_initialize();
+ CHECK_RESULT(result);
+
+ net_nfc_state_activate();
+
+ read_count = 0;
+
+ result = net_nfc_set_response_callback (net_nfc_test_read_cb, NULL);
+ CHECK_RESULT(result);
+
+ PRINT_INSTRUCT("remove tag while reading operation !!");
+ PRINT_INSTRUCT("Please close a tag to device!!");
+
+/*
+ pthread_cond_wait (&pcond,&plock );
+
+ result = net_nfc_unset_response_callback ();
+ CHECK_RESULT(result);
+
+ result = net_nfc_deinitialize ();
+ CHECK_RESULT(result);
+*/
+ return test_case_result;
+}
+
+int nfcTestAPIBasicTest3(uint8_t testNumber,void* arg_ptr2)
+{
+ //int user_context = 0;
+ //net_nfc_error_e result;
+ test_case_result = NET_NFC_TEST_FAIL;
+
+ ndef_message_h ndef_message = NULL;
+
+ if(net_nfc_retrieve_current_ndef_message(&ndef_message) == NET_NFC_OK)
+ {
+ int count = 0;
+ if(net_nfc_get_ndef_message_record_count(ndef_message, &count) == NET_NFC_OK)
+ {
+ int i = 0;
+ for(; i < count; i++)
+ {
+ ndef_record_h record = NULL;
+ if(net_nfc_get_record_by_index(ndef_message, i, &record) == NET_NFC_OK)
+ {
+ net_nfc_record_tnf_e tnf;
+ if(net_nfc_get_record_tnf(record, &tnf) == NET_NFC_OK)
+ {
+ switch(tnf)
+ {
+ case NET_NFC_RECORD_WELL_KNOWN_TYPE:
+ {
+ data_h type = NULL;
+ data_h payload = NULL;
+
+ if(net_nfc_get_record_type(record, &type) == NET_NFC_OK && net_nfc_get_record_payload(record, &payload) == NET_NFC_OK)
+ {
+ if(strcmp((const char*)net_nfc_get_data_buffer(type), "Sp") == 0)
+ {
+
+ }
+ else if(strcmp((const char*)net_nfc_get_data_buffer(type), "T") == 0)
+ {
+
+ net_nfc_encode_type_e utf;
+ //uint32_t utf_length = 0;
+ //uint32_t lang_length = 0;
+ char* text = NULL;
+ //uint32_t text_length = 0;
+ char* language_code_str = NULL;
+
+ if(net_nfc_get_encoding_type_from_text_record(record, &utf) == NET_NFC_OK)
+ {
+ PRINT_INFO("utf = [%X]", utf);
+ }
+ else
+ {
+ PRINT_INFO("failed to get utf");
+ }
+
+ if(net_nfc_get_languange_code_string_from_text_record(record, &language_code_str) == NET_NFC_OK)
+ {
+ PRINT_INFO("language_code = [%s]", language_code_str);
+ }
+ else
+ {
+ PRINT_INFO("failed to get language code");
+ }
+
+ if(net_nfc_create_text_string_from_text_record(record, &text) == NET_NFC_OK)
+ {
+ PRINT_INFO("text = [%s]", text);
+ }
+ else
+ {
+ PRINT_INFO("failed to get text");
+ }
+
+ if(text != NULL)
+ free(text);
+ if(language_code_str != NULL)
+ free(language_code_str);
+/*
+ uint8_t* utf = NULL;
+ uint8_t* language_code = NULL;
+ uint8_t* text = NULL;
+ int index = 0;
+
+ uint8_t* buffer = net_nfc_get_data_buffer(payload);
+ uint32_t buffer_length = net_nfc_get_data_length(payload);
+
+ PRINT_INFO("\n from file >>>");
+
+ for(; index < buffer_length; index++)
+ {
+ printf(" [%d] ", buffer[index]);
+ }
+
+ PRINT_INFO("\n from file <<<");
+
+ index = 0;
+
+ int controllbyte = buffer[0];
+
+ if((controllbyte & 0x80)== 1)
+ {
+ PRINT_INFO("UTF-16");
+ utf = (uint8_t*)"UTF-16";
+ }
+ else
+ {
+ PRINT_INFO("UTF-8");
+ utf = (uint8_t*)"UTF-8";
+ }
+
+ int lang_code_length = controllbyte & 0x3F;
+
+ index = 1;
+
+ language_code = (uint8_t *)malloc(lang_code_length + 1);
+
+ memset(language_code, 0x00, lang_code_length + 1);
+ memcpy(language_code, &(buffer[index]), lang_code_length);
+
+ PRINT_INFO("lang_code = [%s]", language_code);
+
+ index = lang_code_length + 1;
+
+ int text_length = buffer_length - (lang_code_length + 1); // payload length - (lang code length + control byte)
+
+ PRINT_INFO("buffer length = [%d]", buffer_length);
+ PRINT_INFO("lang_code_length = [%d]", lang_code_length);
+ PRINT_INFO("text_length = [%d]", text_length);
+
+ text = (uint8_t *)malloc(text_length + 1);
+
+ memset(text, 0x00, text_length + 1);
+ memcpy(text, &(buffer[index]), text_length);
+
+ PRINT_INFO("encoding type = [%s]", utf);
+ PRINT_INFO("lang_code = [%s]", language_code);
+ PRINT_INFO("text = [%s]", text);
+ test_case_result = NET_NFC_TEST_OK;
+*/
+ }
+ else if(strcmp((const char*)net_nfc_get_data_buffer(type), "U") == 0)
+ {
+
+ }
+ else
+ {
+
+ }
+ }
+
+ }
+ break;
+
+ default:
+ PRINT_INFO("unknow type");
+ break;
+ }
+ }
+ }
+ }
+ }
+ }
+
+ net_nfc_free_ndef_message(ndef_message);
+ //CHECK_RESULT(result);
+
+ return test_case_result;
+}
+
+int nfcTestTransceive(uint8_t testNumber,void* arg_ptr2)
+{
+ //int user_context = 0;
+ net_nfc_error_e result;
+ test_case_result = NET_NFC_TEST_FAIL;
+
+ result = net_nfc_initialize();
+ CHECK_RESULT(result);
+
+ net_nfc_state_activate();
+
+ result = net_nfc_set_response_callback (net_nfc_test_transceive_cb, NULL);
+ CHECK_RESULT(result);
+
+ PRINT_INSTRUCT("Please close a tag to device!!");
+
+ //pthread_cond_wait (&pcond,&plock );
+ /*
+ result = net_nfc_unset_response_callback ();
+ CHECK_RESULT(result);
+ result = net_nfc_deinitialize ();
+ CHECK_RESULT(result);
+ */
+
+ return test_case_result;
+}
+
+/*=================================================================================*/
+
+
+int nfcTestNdefParser(uint8_t testNumber,void* arg_ptr2)
+{
+ net_nfc_error_e result;
+
+ ndef_message_h uriMsg = NULL;
+ ndef_message_h spMsg = NULL;
+ ndef_record_h uriRecord = NULL;
+ ndef_record_h spRecord = NULL;
+ data_h type_data = NULL;
+ data_h raw_data = NULL;
+ char smart_poster_type[] = "Sp";
+ ndef_record_h record = NULL;
+ test_case_result = NET_NFC_TEST_OK;
+
+ result = net_nfc_create_ndef_message (&uriMsg);
+ CHECK_RESULT(result);
+
+ result = net_nfc_create_uri_type_record (&record ,"http://www.naver.com", NET_NFC_SCHEMA_FULL_URI);
+ CHECK_RESULT(result);
+
+ result = net_nfc_append_record_to_ndef_message (uriMsg, record);
+ CHECK_RESULT(result);
+
+ uriRecord = record;
+
+ result = net_nfc_create_text_type_record (&record ,"This is the URI Test" ,"en-US" ,NET_NFC_ENCODE_UTF_8);
+ CHECK_RESULT(result);
+
+ result = net_nfc_append_record_to_ndef_message (uriMsg, record);
+ CHECK_RESULT(result);
+
+ result = net_nfc_create_text_type_record (&record ,"Hello World" ,"en-US" ,NET_NFC_ENCODE_UTF_8);
+ CHECK_RESULT(result);
+
+ result = net_nfc_append_record_by_index (uriMsg,0 ,record);
+ CHECK_RESULT(result);
+
+ result = net_nfc_create_text_type_record (&record ,"TEST1" ,"en-US" ,NET_NFC_ENCODE_UTF_8);
+ CHECK_RESULT(result);
+
+ result = net_nfc_append_record_by_index (uriMsg,1 ,record);
+ CHECK_RESULT(result);
+
+ result = net_nfc_create_text_type_record (&record ,"TEST2" ,"en-US" ,NET_NFC_ENCODE_UTF_8);
+ CHECK_RESULT(result);
+
+ result = net_nfc_append_record_by_index (uriMsg,2 ,record);
+ CHECK_RESULT(result);
+
+ result = net_nfc_create_text_type_record (&record ,"TEST3" ,"en-US" ,NET_NFC_ENCODE_UTF_8);
+ CHECK_RESULT(result);
+
+ int position;
+ result = net_nfc_get_ndef_message_record_count (uriMsg,&position);
+ CHECK_RESULT(result);
+
+ result = net_nfc_append_record_by_index (uriMsg, position ,record);
+ CHECK_RESULT(result);
+
+ //_//net_nfc_ndef_print_message (uriMsg);
+
+ result = net_nfc_create_data (&type_data ,(const uint8_t*)"U", 1);
+ CHECK_RESULT(result);
+
+ result = net_nfc_search_record_by_type (uriMsg ,NET_NFC_RECORD_WELL_KNOWN_TYPE ,type_data ,&record);
+ CHECK_RESULT(result);
+ if (record != uriRecord){
+ PRINT_RESULT_FAIL("Record search result does not matched");
+ return NET_NFC_TEST_FAIL;
+ }
+
+ result = net_nfc_remove_record_by_index (uriMsg ,1);
+ CHECK_RESULT(result);
+
+ result = net_nfc_remove_record_by_index (uriMsg ,0);
+ CHECK_RESULT(result);
+
+ result = net_nfc_get_ndef_message_record_count (uriMsg,&position);
+ CHECK_RESULT(result);
+
+ result = net_nfc_remove_record_by_index (uriMsg, position - 1);
+ CHECK_RESULT(result);
+
+ result = net_nfc_remove_record_by_index (uriMsg ,2);
+ CHECK_RESULT(result);
+
+ //_//net_nfc_ndef_print_message (uriMsg);
+
+ result = net_nfc_create_rawdata_from_ndef_message (uriMsg, &raw_data);
+ CHECK_RESULT(result);
+
+ result = net_nfc_create_data (&type_data, (const uint8_t*)smart_poster_type, strlen (smart_poster_type));
+ if (result != NET_NFC_OK) {
+ net_nfc_free_data(raw_data);
+ net_nfc_free_data(type_data);
+ net_nfc_free_ndef_message(uriMsg);
+ }
+ CHECK_RESULT(result);
+
+ result = net_nfc_create_record (&spRecord, NET_NFC_RECORD_WELL_KNOWN_TYPE,type_data , NULL, raw_data);
+ if (result != NET_NFC_OK) {
+ net_nfc_free_data(raw_data);
+ net_nfc_free_data(type_data);
+ net_nfc_free_ndef_message(uriMsg);
+ }
+ CHECK_RESULT(result);
+
+ result = net_nfc_create_ndef_message (&spMsg);
+ CHECK_RESULT(result);
+
+ result = net_nfc_append_record_to_ndef_message (spMsg, spRecord);
+ CHECK_RESULT(result);
+
+ net_nfc_free_data (type_data);
+ net_nfc_free_data (raw_data);
+ net_nfc_free_ndef_message(uriMsg);
+
+ return test_case_result;
+}
+
+/*=================================================================================*/
+
+net_nfc_llcp_socket_t server_socket;
+net_nfc_llcp_socket_t accepted_socket;
+net_nfc_llcp_socket_t client_socket;
+
+static void net_nfc_client_socket_cb (net_nfc_llcp_message_e message, net_nfc_error_e result, void * data, void * user_data, void * trans_data)
+{
+ PRINT_INFO ("\nCLIENT callback is called MESSAGE[%d]", message);
+ //int x;
+ switch (message)
+ {
+ case NET_NFC_MESSAGE_LLCP_LISTEN:
+ break;
+ case NET_NFC_MESSAGE_LLCP_ACCEPTED:
+ break;
+ case NET_NFC_MESSAGE_LLCP_CONNECT:
+ {
+ PRINT_INFO ("LLCP connect is completed with error code %d", result);
+ data_h data;
+ char * str = "Client message: Hello, server!";
+ net_nfc_create_data (&data, (const uint8_t*)str ,strlen (str) + 1);
+ net_nfc_send_llcp (client_socket, data, NULL);
+ net_nfc_free_data(data);
+ }
+ break;
+ case NET_NFC_MESSAGE_LLCP_CONNECT_SAP:
+ break;
+ case NET_NFC_MESSAGE_LLCP_SEND:
+ {
+ PRINT_INFO ("LLCP send is completed with error code %d", result);
+ net_nfc_receive_llcp (client_socket, 512 ,NULL);
+ }
+ break;
+
+ case NET_NFC_MESSAGE_LLCP_RECEIVE:
+ PRINT_INFO ("LLCP receive is completed with error code %d", result);
+ data_h received_data = (data_h) data;
+ PRINT_INFO ("Server --> Client : %s" , net_nfc_get_data_buffer (received_data));
+
+ net_nfc_disconnect_llcp (client_socket ,NULL);
+ break;
+ case NET_NFC_MESSAGE_LLCP_DISCONNECT:
+ {
+ PRINT_INFO ("LLCP disconnect is completed with error code %d", result);
+ net_nfc_close_llcp_socket (client_socket, NULL);
+ }
+ break;
+ case NET_NFC_MESSAGE_LLCP_ERROR:
+ PRINT_INFO ("LLCP socket error is completed with error code %d", result);
+ net_nfc_close_llcp_socket (client_socket, NULL);
+ break;
+ default:
+ break;
+ }
+
+}
+
+
+static void net_nfc_server_socket_cb (net_nfc_llcp_message_e message, net_nfc_error_e result, void * data, void * user_data, void * trans_data)
+{
+ PRINT_INFO ("\nSERVER callback is called MESSAGE[%d]", message);
+ switch (message)
+ {
+ case NET_NFC_MESSAGE_LLCP_LISTEN:
+ {
+ PRINT_INFO ("LLCP Listen is completed with error code %d", result);
+ }
+ break;
+
+ case NET_NFC_MESSAGE_LLCP_ACCEPTED:
+ {
+ PRINT_INFO ("LLCP accept is completed with error code %d", result);
+ accepted_socket = *(net_nfc_llcp_socket_t *)(data);
+ net_nfc_set_llcp_socket_callback (accepted_socket, net_nfc_server_socket_cb, NULL);
+ net_nfc_receive_llcp (accepted_socket, 512 ,NULL);
+ }
+ break;
+ case NET_NFC_MESSAGE_LLCP_CONNECT:
+ break;
+ case NET_NFC_MESSAGE_LLCP_CONNECT_SAP:
+ break;
+ case NET_NFC_MESSAGE_LLCP_SEND:
+ {
+ PRINT_INFO ("LLCP send is completed with error code %d", result);
+ net_nfc_disconnect_llcp (accepted_socket ,NULL);
+ }
+ break;
+
+ case NET_NFC_MESSAGE_LLCP_RECEIVE:
+ {
+ PRINT_INFO ("LLCP receive is completed with error code %d", result);
+ data_h received_data = (data_h) data;
+ PRINT_INFO ("Server <-- Client : %s" , net_nfc_get_data_buffer (received_data));
+
+ data_h data;
+ char * str = "Server message: Welcome NFC llcp world!";
+ net_nfc_create_data (&data, (const uint8_t*)str ,strlen (str) + 1);
+ net_nfc_send_llcp (accepted_socket, data, NULL);
+ net_nfc_free_data(data);
+ }
+ break;
+
+ case NET_NFC_MESSAGE_LLCP_DISCONNECT:
+ {
+ PRINT_INFO ("LLCP disconnect is completed with error code %d", result);
+ net_nfc_close_llcp_socket (accepted_socket, NULL);
+ }
+ break;
+ case NET_NFC_MESSAGE_LLCP_ERROR:
+ {
+ PRINT_INFO ("LLCP socket error is received with code %d", result);
+ net_nfc_close_llcp_socket (accepted_socket, NULL);
+ net_nfc_close_llcp_socket (server_socket, NULL);
+ }
+ break;
+ default:
+ break;
+ }
+}
+
+net_nfc_target_handle_h snep_handle;
+net_nfc_exchanger_data_h snep_ex_data = NULL;
+int temp_count;
+
+static void net_nfc_test_snep_cb(net_nfc_message_e message, net_nfc_error_e result, void* data, void* user_param, void * trans_data)
+{
+ PRINT_INFO ("client message received [%d]", message);
+
+ switch (message) {
+#if 0
+ case NET_NFC_MESSAGE_P2P_DISCOVERED:
+ {
+ snep_handle = (net_nfc_target_handle_h) data;
+ //= (net_nfc_target_handle_h) target_info->handle;
+ /* Fill the data to send. */
+
+ if(NET_NFC_OK == net_nfc_create_exchanger_data(&snep_ex_data, nfcTestUri))
+ {
+ if(net_nfc_send_exchanger_data(snep_ex_data, snep_handle) == NET_NFC_OK)
+ {
+ PRINT_INFO ("exchanger data send success");
+ }
+ else
+ {
+ PRINT_INFO ("exchanger data send fail");
+ }
+ }
+ else
+ {
+ PRINT_INFO ("create exchanger data fail");
+ }
+
+ }
+ break;
+#endif
+ case NET_NFC_MESSAGE_P2P_SEND:
+ {
+ PRINT_INFO ("NET_NFC_MESSAGE_P2P_SEND result [%d]", result);
+
+ }
+ break;
+
+ case NET_NFC_MESSAGE_P2P_DETACHED:
+ {
+ PRINT_INFO ("Target disconnected.");
+ temp_count = 0;
+ }
+ break;
+
+ case NET_NFC_MESSAGE_P2P_RECEIVE:
+ {
+// int i;
+// data_h received_data = (data_h)data;
+
+// PRINT_INFO ("NET_NFC_MESSAGE_P2P_RECEIVE [%s]", net_nfc_get_data_buffer(received_data));
+// PRINT_INFO (" length [%d]", net_nfc_get_data_length(received_data));
+ }
+ break;
+
+ default:
+ break;
+ }
+}
+
+static void net_nfc_test_llcp_cb(net_nfc_message_e message, net_nfc_error_e result, void* data, void* user_param, void * trans_data)
+{
+ // do nothing
+ switch (message) {
+ case NET_NFC_MESSAGE_LLCP_DISCOVERED:
+ {
+ net_nfc_llcp_config_info_h config = (net_nfc_llcp_config_info_h) data;
+ uint8_t lto, option;
+ uint16_t wks, miu;
+ net_nfc_get_llcp_configure_lto (config , <o);
+ net_nfc_get_llcp_configure_wks (config , &wks);
+ net_nfc_get_llcp_configure_miu (config , &miu);
+ net_nfc_get_llcp_configure_option (config , &option);
+
+ PRINT_INFO ("Remote Device llcp info:\n \tlto: %d, \twks: %d, \tmiu: %d, \toption: %d", lto, wks, miu, option);
+
+ net_nfc_create_llcp_socket (&server_socket, NULL);
+ net_nfc_set_llcp_socket_callback (server_socket, net_nfc_server_socket_cb, NULL);
+ net_nfc_listen_llcp (server_socket, "urn:nfc:xsn:samsung.com:testllcp" ,16 ,NULL);
+
+ net_nfc_create_llcp_socket (&client_socket, NULL);
+ net_nfc_set_llcp_socket_callback (client_socket, net_nfc_client_socket_cb, NULL);
+ net_nfc_connect_llcp (client_socket,"urn:nfc:xsn:samsung.com:testllcp",NULL);
+ }
+ break;
+
+ case NET_NFC_MESSAGE_LLCP_CONFIG:
+ {
+ PRINT_INFO ("LLCP llcp local config is completed with error code %d", result);
+ }
+ break;
+
+ case NET_NFC_MESSAGE_P2P_DETACHED:
+ {
+ PRINT_INFO ("LLCP NET_NFC_MESSAGE_P2P_DETACHED %d", result);
+ }
+ break;
+
+ default:
+ break;
+ }
+}
+
+int nfcTestSnep(uint8_t testNumber,void* arg_ptr)
+{
+ net_nfc_error_e result;
+
+ result = net_nfc_initialize();
+ CHECK_RESULT(result);
+ net_nfc_state_activate ();
+ result = net_nfc_set_response_callback (net_nfc_test_snep_cb, NULL);
+
+ PRINT_INSTRUCT("START SNEP test !!");
+ return NET_NFC_TEST_OK;
+}
+
+int nfcTestLLCP(uint8_t testNumber,void* arg_ptr2)
+{
+ net_nfc_error_e result;
+ net_nfc_llcp_config_info_h config;
+ result = net_nfc_initialize();
+ CHECK_RESULT(result);
+ net_nfc_state_activate ();
+ result = net_nfc_set_response_callback (net_nfc_test_llcp_cb, NULL);
+ CHECK_RESULT(result);
+ result = net_nfc_create_llcp_configure_default (&config);
+ CHECK_RESULT(result);
+ result = net_nfc_set_llcp_local_configure (config ,NULL);
+
+ PRINT_INSTRUCT("Please start P2P communicate!!");
+
+/*
+ pthread_cond_wait (&pcond,&plock );
+
+ result = net_nfc_unset_response_callback ();
+ CHECK_RESULT(result);
+ result = net_nfc_deinitialize ();
+ CHECK_RESULT(result);
+*/
+ net_nfc_free_llcp_configure(config);
+ return NET_NFC_TEST_OK;
+}
+
+/*=================================================================================*/
+
+/* LLCP Stress Test */
+
+net_nfc_llcp_socket_t server_socket;
+net_nfc_llcp_socket_t client_socket;
+
+static void net_nfc_client_stress_socket_cb (net_nfc_llcp_message_e message, net_nfc_error_e result, void * data, void * user_data, void * trans_data)
+{
+ PRINT_INFO ("\nCLIENT callback is called MESSAGE[%d]", message);
+ //int x;
+ switch (message)
+ {
+ case NET_NFC_MESSAGE_LLCP_LISTEN:
+ break;
+ case NET_NFC_MESSAGE_LLCP_ACCEPTED:
+ break;
+ case NET_NFC_MESSAGE_LLCP_CONNECT:
+ {
+ PRINT_INFO ("LLCP connect is completed with error code %d", result);
+ data_h data;
+ char * str = "Client message: Hello, server!";
+ net_nfc_create_data (&data, (const uint8_t*)str ,strlen (str) + 1);
+ net_nfc_send_llcp (client_socket, data, NULL);
+ net_nfc_free_data(data);
+ }
+ break;
+ case NET_NFC_MESSAGE_LLCP_CONNECT_SAP:
+ break;
+ case NET_NFC_MESSAGE_LLCP_SEND:
+ {
+ PRINT_INFO ("LLCP send is completed with error code %d", result);
+ net_nfc_receive_llcp (client_socket, 512 ,NULL);
+ }
+ break;
+
+ case NET_NFC_MESSAGE_LLCP_RECEIVE:
+ PRINT_INFO ("LLCP receive is completed with error code %d", result);
+ data_h received_data = (data_h) data;
+ PRINT_INFO ("Server --> Client : %s" , net_nfc_get_data_buffer (received_data));
+
+ net_nfc_disconnect_llcp (client_socket ,NULL);
+ break;
+ case NET_NFC_MESSAGE_LLCP_DISCONNECT:
+ {
+ PRINT_INFO ("LLCP disconnect is completed with error code %d", result);
+ net_nfc_close_llcp_socket (client_socket, NULL);
+ }
+ break;
+ case NET_NFC_MESSAGE_LLCP_ERROR:
+ PRINT_INFO ("LLCP socket error is completed with error code %d", result);
+ net_nfc_close_llcp_socket (client_socket, NULL);
+ break;
+ default:
+ break;
+ }
+
+}
+
+
+static void net_nfc_server_stress_socket_cb (net_nfc_llcp_message_e message, net_nfc_error_e result, void * data, void * user_data, void * trans_data)
+{
+ PRINT_INFO ("\nSERVER callback is called MESSAGE[%d]", message);
+ switch (message)
+ {
+ case NET_NFC_MESSAGE_LLCP_LISTEN:
+ {
+ PRINT_INFO ("LLCP Listen is completed with error code %d", result);
+ }
+ break;
+
+ case NET_NFC_MESSAGE_LLCP_ACCEPTED:
+ {
+ PRINT_INFO ("LLCP accept is completed with error code %d", result);
+ net_nfc_receive_llcp (server_socket, 512 ,NULL);
+ }
+ break;
+ case NET_NFC_MESSAGE_LLCP_CONNECT:
+ break;
+ case NET_NFC_MESSAGE_LLCP_CONNECT_SAP:
+ break;
+ case NET_NFC_MESSAGE_LLCP_SEND:
+ {
+ PRINT_INFO ("LLCP send is completed with error code %d", result);
+ net_nfc_disconnect_llcp (server_socket ,NULL);
+ }
+ break;
+
+ case NET_NFC_MESSAGE_LLCP_RECEIVE:
+ {
+ PRINT_INFO ("LLCP receive is completed with error code %d", result);
+ data_h received_data = (data_h) data;
+ PRINT_INFO ("Server <-- Client : %s" , net_nfc_get_data_buffer (received_data));
+
+ data_h data;
+ char * str = "Server message: Welcome NFC llcp world!";
+ net_nfc_create_data (&data, (const uint8_t*)str ,strlen (str) + 1);
+ net_nfc_send_llcp (server_socket, data, NULL);
+ net_nfc_free_data(data);
+ }
+ break;
+
+ case NET_NFC_MESSAGE_LLCP_DISCONNECT:
+ {
+ PRINT_INFO ("LLCP disconnect is completed with error code %d", result);
+ net_nfc_close_llcp_socket (server_socket, NULL);
+ }
+ break;
+
+ case NET_NFC_MESSAGE_LLCP_ERROR:
+ {
+ PRINT_INFO ("LLCP socket error is received with code %d", result);
+ net_nfc_close_llcp_socket (server_socket, NULL);
+ }
+ break;
+ default:
+ break;
+ }
+}
+
+static void net_nfc_test_llcp_stress_cb(net_nfc_message_e message, net_nfc_error_e result, void* data, void* user_param, void * trans_data)
+{
+ // do nothing
+ switch (message) {
+ case NET_NFC_MESSAGE_LLCP_DISCOVERED:
+ {
+ net_nfc_llcp_config_info_h config = (net_nfc_llcp_config_info_h) data;
+ uint8_t lto, option;
+ uint16_t wks, miu;
+ net_nfc_get_llcp_configure_lto (config , <o);
+ net_nfc_get_llcp_configure_wks (config , &wks);
+ net_nfc_get_llcp_configure_miu (config , &miu);
+ net_nfc_get_llcp_configure_option (config , &option);
+
+ PRINT_INFO ("Remote Device llcp info:\n \tlto: %d, \twks: %d, \tmiu: %d, \toption: %d", lto, wks, miu, option);
+
+ net_nfc_create_llcp_socket (&server_socket, NULL);
+ net_nfc_set_llcp_socket_callback (server_socket, net_nfc_server_stress_socket_cb, NULL);
+ net_nfc_listen_llcp (server_socket, "urn:nfc:xsn:samsung.com:testllcp" ,16 ,NULL);
+
+ net_nfc_create_llcp_socket (&client_socket, NULL);
+ net_nfc_set_llcp_socket_callback (client_socket, net_nfc_client_stress_socket_cb, NULL);
+ net_nfc_connect_llcp (client_socket,"urn:nfc:xsn:samsung.com:testllcp",NULL);
+ }
+ break;
+
+ case NET_NFC_MESSAGE_LLCP_CONFIG:
+ {
+ PRINT_INFO ("LLCP llcp local config is completed with error code %d", result);
+ }
+ break;
+
+ case NET_NFC_MESSAGE_P2P_DETACHED:
+ {
+ PRINT_INFO ("LLCP NET_NFC_MESSAGE_P2P_DETACHED %d", result);
+ }
+ break;
+
+ default:
+ break;
+ }
+}
+
+int nfcTestStressLLCP(uint8_t testNumber,void* arg_ptr2)
+{
+ net_nfc_error_e result;
+ net_nfc_llcp_config_info_h config;
+ result = net_nfc_initialize();
+ CHECK_RESULT(result);
+ net_nfc_state_activate ();
+ result = net_nfc_set_response_callback (net_nfc_test_llcp_stress_cb, NULL);
+ CHECK_RESULT(result);
+ result = net_nfc_create_llcp_configure_default (&config);
+ CHECK_RESULT(result);
+ result = net_nfc_set_llcp_local_configure (config ,NULL);
+
+ PRINT_INSTRUCT("Please start P2P communicate!!");
+/*
+ pthread_cond_wait (&pcond,&plock );
+
+ result = net_nfc_unset_response_callback ();
+ CHECK_RESULT(result);
+ result = net_nfc_deinitialize ();
+ CHECK_RESULT(result);
+*/
+ net_nfc_free_llcp_configure(config);
+ return NET_NFC_TEST_OK;
+}
+
+/*=================================================================================*/
+
+
+static void net_nfc_test_API_exception_cb1(net_nfc_message_e message, net_nfc_error_e result, void* data, void* user_param, void * trans_data)
+{
+ PRINT_INFO ("Message is received 1 %d", result);
+ test_case_result = NET_NFC_TEST_FAIL;
+ pthread_mutex_lock (&plock);
+ pthread_cond_signal (&pcond);
+ pthread_mutex_unlock (&plock);
+}
+
+static void net_nfc_test_API_exception_cb2(net_nfc_message_e message, net_nfc_error_e result, void* data, void* user_param, void * trans_data)
+{
+ PRINT_INFO ("Message is received 2 %d", result);
+ test_case_result = NET_NFC_TEST_FAIL;
+ pthread_mutex_lock (&plock);
+ pthread_cond_signal (&pcond);
+ pthread_mutex_unlock (&plock);
+}
+
+static void net_nfc_test_API_exception_cb3(net_nfc_message_e message, net_nfc_error_e result, void* data, void* user_param, void * trans_data)
+{
+ PRINT_INFO ("Message is received 3 %d", result);
+ test_case_result = NET_NFC_TEST_OK;
+ pthread_mutex_lock (&plock);
+ pthread_cond_signal (&pcond);
+ pthread_mutex_unlock (&plock);
+}
+
+
+
+
+int nfcTestAPIException (uint8_t testNumber,void* arg_ptr)
+{
+ //net_nfc_error_e result;
+ test_case_result = NET_NFC_TEST_FAIL;
+
+ CHECK_ASSULT(net_nfc_initialize() == NET_NFC_OK);
+ CHECK_ASSULT(net_nfc_initialize() == NET_NFC_ALREADY_INITIALIZED);
+ CHECK_ASSULT(net_nfc_deinitialize () == NET_NFC_OK);
+
+ int count_try = 0;
+ for (count_try = 0; count_try < 20; count_try ++)
+ {
+ CHECK_ASSULT(net_nfc_initialize() == NET_NFC_OK);
+ CHECK_ASSULT(net_nfc_deinitialize () == NET_NFC_OK);
+ }
+
+ CHECK_ASSULT(net_nfc_deinitialize () == NET_NFC_NOT_INITIALIZED);
+ CHECK_ASSULT(net_nfc_deinitialize () == NET_NFC_NOT_INITIALIZED);
+
+
+ CHECK_ASSULT(net_nfc_initialize() == NET_NFC_OK);
+
+ CHECK_ASSULT (NET_NFC_OK == net_nfc_set_response_callback (net_nfc_test_API_exception_cb1, NULL));
+ CHECK_ASSULT (NET_NFC_OK == net_nfc_set_response_callback (net_nfc_test_API_exception_cb2, NULL));
+ CHECK_ASSULT (NET_NFC_OK == net_nfc_set_response_callback (net_nfc_test_API_exception_cb3, NULL));
+ net_nfc_state_activate ();
+
+ PRINT_INSTRUCT("Please close a tag to device!!");
+
+ pthread_cond_wait (&pcond,&plock );
+ if (!test_case_result) return test_case_result;
+
+ PRINT_INSTRUCT("Please remove the tag from device!!");
+ pthread_cond_wait (&pcond,&plock );
+
+ CHECK_ASSULT (NET_NFC_OK == net_nfc_set_response_callback (net_nfc_test_API_exception_cb2, NULL));
+ CHECK_ASSULT (NET_NFC_OK != net_nfc_set_response_callback (NULL, NULL));
+
+ CHECK_ASSULT (NET_NFC_OK == net_nfc_set_response_callback (net_nfc_test_API_exception_cb2, NULL));
+ CHECK_ASSULT (NET_NFC_OK == net_nfc_unset_response_callback ());
+
+ PRINT_INSTRUCT("Please close a tag to device!! in 10 sec");
+
+ int idx = 0;
+ for (idx = 10 ;idx > 0 ; idx --)
+ {
+ PRINT_INSTRUCT("count down [%d]", idx);
+ sleep (1);
+ }
+ if (!test_case_result) return test_case_result;
+
+ PRINT_INSTRUCT("Please remove the tag from device!!");
+ sleep (2);
+
+ CHECK_ASSULT (NET_NFC_OK == net_nfc_set_response_callback (net_nfc_test_API_exception_cb3, NULL));
+ net_nfc_state_activate ();
+ net_nfc_state_activate ();
+ net_nfc_state_activate ();
+
+ PRINT_INSTRUCT("Please close a tag to device!!");
+
+ pthread_cond_wait (&pcond,&plock );
+ if (!test_case_result) return test_case_result;
+ PRINT_INSTRUCT("Please remove the tag from device!!");
+ pthread_cond_wait (&pcond,&plock );
+
+ net_nfc_state_deactivate ();
+ PRINT_INSTRUCT("Please close a tag to device!! in 10 sec");
+
+ for (idx = 10 ;idx > 0 ; idx --)
+ {
+ PRINT_INSTRUCT("count down [%d]", idx);
+ sleep (1);
+ }
+ if (!test_case_result) return test_case_result;
+ PRINT_INSTRUCT("Please remove the tag from device!!");
+ sleep (2);
+
+ net_nfc_state_activate ();
+ CHECK_ASSULT(net_nfc_deinitialize () == NET_NFC_OK);
+
+ PRINT_INSTRUCT("Please close a tag to device!! in 10 sec");
+
+
+ for (idx = 10 ;idx > 0 ; idx --)
+ {
+ PRINT_INSTRUCT("count down [%d]", idx);
+ sleep (1);
+ }
+ if (!test_case_result) return test_case_result;
+
+ PRINT_INSTRUCT("Please remove the tag from device!!");
+ sleep (2);
+
+ CHECK_ASSULT(net_nfc_initialize() == NET_NFC_OK);
+ CHECK_ASSULT (NET_NFC_OK == net_nfc_set_response_callback (net_nfc_test_API_exception_cb3, NULL));
+ net_nfc_state_activate ();
+
+ PRINT_INSTRUCT("Please close a tag to device!!");
+
+ pthread_cond_wait (&pcond,&plock );
+ if (!test_case_result) return test_case_result;
+
+ return NET_NFC_TEST_OK;
+}
+
+/*=================================================================================*/
+
+
+static void net_nfc_test_API_exception_tagAPI(net_nfc_message_e message, net_nfc_error_e result, void* data, void* user_param, void * trans_data)
+{
+ PRINT_INFO ("Message is received 3 %d", result);
+ test_case_result = NET_NFC_TEST_OK;
+
+ switch(message)
+ {
+ case NET_NFC_MESSAGE_TAG_DISCOVERED:
+ {
+ switch (*(int*) user_param)
+ {
+ case 0: // transceive
+ {
+ net_nfc_target_type_e type;
+ net_nfc_target_handle_h id;
+ bool is_ndef;
+ net_nfc_target_info_h target_info = (net_nfc_target_info_h)data;
+ //net_nfc_error_e e_ret ;
+
+ net_nfc_get_tag_type (target_info, &type);
+ net_nfc_get_tag_handle (target_info, &id);
+ net_nfc_get_tag_ndef_support (target_info, &is_ndef);
+ PRINT_INFO("target type: %d\n", type);
+ PRINT_INFO("target id: %X\n", (unsigned int)id);
+ PRINT_INFO("Is NDEF supoort: %d\n", is_ndef);
+
+ net_nfc_deinitialize (); // Before calling transceive
+
+ }
+ break;
+ case 1:
+ {
+ net_nfc_target_info_h target_info = (net_nfc_target_info_h)data;
+ net_nfc_target_handle_h id;
+ net_nfc_get_tag_handle (target_info, &id);
+ net_nfc_deinitialize();
+ if (NET_NFC_OK == net_nfc_read_tag (id ,NULL)){
+ test_case_result = NET_NFC_TEST_FAIL;
+ }
+ }
+ break;
+ case 2:
+ {
+ net_nfc_target_info_h target_info = (net_nfc_target_info_h)data;
+ net_nfc_target_handle_h id;
+ ndef_message_h message = NULL;
+ ndef_record_h record = NULL;
+
+ net_nfc_get_tag_handle (target_info, &id);
+ net_nfc_deinitialize();
+
+ net_nfc_create_ndef_message (&message);
+ net_nfc_create_text_type_record (&record, "abc" ,"en-US" ,NET_NFC_ENCODE_UTF_8);
+ net_nfc_append_record_to_ndef_message (message ,record);
+ if (NET_NFC_OK == net_nfc_write_ndef (id ,message ,NULL)){
+ test_case_result = NET_NFC_TEST_FAIL;
+ }
+ net_nfc_free_ndef_message(message);
+
+ }
+ break;
+ case 3:
+ {
+ net_nfc_target_info_h target_info = (net_nfc_target_info_h)data;
+ net_nfc_target_handle_h id;
+ data_h key;
+ char data [] = {0xff,0xff,0xff,0xff,0xff,0xff};
+ net_nfc_create_data (&key, (const uint8_t*)data, 6);
+ net_nfc_get_tag_handle (target_info, &id);
+ net_nfc_deinitialize();
+ if (NET_NFC_OK == net_nfc_format_ndef(id, key, NULL)){
+ test_case_result = NET_NFC_TEST_FAIL;
+ }
+ net_nfc_free_data(key);
+ }
+ break;
+ default:
+ break;
+ }
+
+ pthread_mutex_lock (&plock);
+ pthread_cond_signal (&pcond);
+ pthread_mutex_unlock (&plock);
+ }
+ break;
+ default:
+ break;
+ }
+}
+
+
+int nfcTestAPIException_tagAPI (uint8_t testNumber,void* arg_ptr)
+{
+ int test_case = 0;
+
+ /* Call API before initailize */
+
+ data_h key;
+ net_nfc_error_e result;
+ uint8_t data [] = {0xff,0xff,0xff,0xff,0xff,0xff};
+ net_nfc_create_data (&key, data, 6);
+ result = net_nfc_format_ndef((net_nfc_target_handle_h) 0x302023, key, NULL);
+ if(NET_NFC_OK == result){
+ net_nfc_free_data(key);
+ }
+ CHECK_ASSULT (NET_NFC_OK != result);
+ result = net_nfc_format_ndef(NULL, key, NULL);
+ if((NET_NFC_NULL_PARAMETER != result)||(NET_NFC_OK == net_nfc_format_ndef((net_nfc_target_handle_h) 0x302023, NULL, NULL))||(NET_NFC_OK == net_nfc_read_tag ((net_nfc_target_handle_h) 0x302023 ,NULL))||(NET_NFC_NULL_PARAMETER != net_nfc_read_tag (NULL ,NULL))){
+ net_nfc_free_data(key);
+ }
+ CHECK_ASSULT (NET_NFC_NULL_PARAMETER == result);
+ CHECK_ASSULT (NET_NFC_OK != net_nfc_format_ndef((net_nfc_target_handle_h) 0x302023, NULL, NULL));
+
+ CHECK_ASSULT (NET_NFC_OK != net_nfc_read_tag ((net_nfc_target_handle_h) 0x302023 ,NULL));
+ CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_read_tag (NULL ,NULL));
+ net_nfc_free_data(key);
+
+ ndef_message_h message = NULL;
+ ndef_record_h record = NULL;
+ net_nfc_create_ndef_message (&message);
+ net_nfc_create_text_type_record (&record, "abc" ,"en-US" ,NET_NFC_ENCODE_UTF_8);
+ net_nfc_append_record_to_ndef_message (message ,record);
+ result = net_nfc_write_ndef ((net_nfc_target_handle_h)0x302023 ,message,NULL);
+ if(NET_NFC_OK == result){
+ net_nfc_free_ndef_message (message);
+ }
+ CHECK_ASSULT (NET_NFC_OK != result);
+ result = net_nfc_write_ndef (NULL ,message,NULL);
+ if((NET_NFC_NULL_PARAMETER != result)||(NET_NFC_NULL_PARAMETER != net_nfc_write_ndef ((net_nfc_target_handle_h)0x302023 ,NULL,NULL))){
+ net_nfc_free_ndef_message (message);
+ }
+ CHECK_ASSULT (NET_NFC_NULL_PARAMETER == result);
+ CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_write_ndef ((net_nfc_target_handle_h)0x302023 ,NULL,NULL));
+ net_nfc_free_ndef_message (message);
+
+
+ for (test_case = 0 ; test_case < 4; test_case++){
+ CHECK_ASSULT(net_nfc_initialize() == NET_NFC_OK);
+ net_nfc_state_activate ();
+ PRINT_INSTRUCT("Please close a tag to device!!");
+ CHECK_ASSULT (NET_NFC_OK == net_nfc_set_response_callback (net_nfc_test_API_exception_tagAPI, &test_case));
+ pthread_cond_wait (&pcond,&plock );
+ if (test_case_result == NET_NFC_TEST_FAIL) return test_case_result;
+ PRINT_INSTRUCT("Please remoe the tag from device!!");
+ sleep(2);
+ }
+
+ CHECK_ASSULT(net_nfc_deinitialize () != NET_NFC_OK);
+
+ return NET_NFC_TEST_OK;
+}
+/*=================================================================================*/
+
+
+static void net_nfc_test_API_exception_targetInfo(net_nfc_message_e message, net_nfc_error_e result, void* data, void* user_param, void * trans_data)
+{
+ PRINT_INFO ("Message is received 3 %d", result);
+ test_case_result = NET_NFC_TEST_OK;
+
+ char **keys;
+ int length;
+ data_h value;
+
+ switch(message)
+ {
+ case NET_NFC_MESSAGE_TAG_DISCOVERED:
+ {
+
+ if (NET_NFC_OK != net_nfc_get_tag_info_keys((net_nfc_target_info_h)data, &keys, &length)){
+ test_case_result = NET_NFC_TEST_FAIL;
+ return;
+ }
+
+ if (NET_NFC_OK == net_nfc_get_tag_info_value ((net_nfc_target_info_h)data, "abc", &value)){
+ test_case_result = NET_NFC_TEST_FAIL;
+ return;
+ }
+ PRINT_INSTRUCT("Please remove the tag from device!!");
+
+ }
+ break;
+ case NET_NFC_MESSAGE_TAG_DETACHED:
+
+ if (NET_NFC_OK == net_nfc_get_tag_info_keys((net_nfc_target_info_h)data, &keys, &length)){
+ test_case_result = NET_NFC_TEST_FAIL;
+ return;
+ }
+
+ pthread_mutex_lock (&plock);
+ pthread_cond_signal (&pcond);
+ pthread_mutex_unlock (&plock);
+
+
+ break;
+ default:
+ break;
+ }
+}
+
+int nfcTestAPIException_targetInfo (uint8_t testNumber,void* arg_ptr)
+{
+ net_nfc_target_type_e target_type;
+ net_nfc_target_handle_h target_id;
+ bool is_support;
+ unsigned int size;
+ CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_get_tag_type ((net_nfc_target_info_h)0x302023, NULL));
+ CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_get_tag_type (NULL, &target_type));
+
+ CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_get_tag_handle((net_nfc_target_info_h)0x302023, NULL));
+ CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_get_tag_handle(NULL, &target_id));
+
+ CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_get_tag_ndef_support ((net_nfc_target_info_h)0x302023, NULL));
+ CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_get_tag_ndef_support (NULL, &is_support));
+
+ CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_get_tag_max_data_size ((net_nfc_target_info_h)0x302023, NULL));
+ CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_get_tag_max_data_size (NULL, &size));
+
+ CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_get_tag_actual_data_size ((net_nfc_target_info_h)0x302023, NULL));
+ CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_get_tag_actual_data_size (NULL, &size));
+
+ char **keys;
+ int length;
+ CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_get_tag_info_keys((net_nfc_target_info_h)0x302023, NULL, &length));
+ CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_get_tag_info_keys((net_nfc_target_info_h)0x302023, &keys, NULL));
+ CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_get_tag_info_keys(NULL, &keys, &length));
+
+ const char* key = "hello";
+ data_h value;
+
+ CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_get_tag_info_value((net_nfc_target_info_h)0x302023, key , NULL));
+ CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_get_tag_info_value((net_nfc_target_info_h)0x302023, NULL, &value));
+ CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_get_tag_info_value(NULL, key, &value));
+
+ CHECK_ASSULT(net_nfc_initialize() == NET_NFC_OK);
+ net_nfc_state_activate ();
+ CHECK_ASSULT (NET_NFC_OK == net_nfc_set_response_callback (net_nfc_test_API_exception_targetInfo, NULL));
+ PRINT_INSTRUCT("Please close a tag to device!!");
+
+ pthread_cond_wait (&pcond,&plock );
+
+ CHECK_ASSULT(net_nfc_deinitialize() == NET_NFC_OK);
+ return NET_NFC_TEST_OK;
+}
+
+/*=================================================================================*/
+
+
+int nfcConnHandoverMessageTest (uint8_t testNumber,void* arg_ptr)
+{
+ net_nfc_carrier_config_h carrier;
+ net_nfc_property_group_h group;
+ ndef_record_h carrier_record;
+ ndef_message_h message;
+ uint8_t buffer[256] = {0,};
+ uint8_t * pdata;
+ unsigned int length = 0;
+ net_nfc_error_e result;
+ char SSID[] = "HomeWLAN";
+ char dev_name[] = "DeviceName";
+ uint8_t btdev_addr[] = {0x01, 0x07, 0x80, 0x80, 0xBF, 0xA1};
+
+ result = net_nfc_create_carrier_config (&carrier ,NET_NFC_CONN_HANDOVER_CARRIER_WIFI_BSS);
+ CHECK_RESULT(result);
+
+ buffer[0] = 0x10;
+ result = net_nfc_add_carrier_config_property (carrier, NET_NFC_WIFI_ATTRIBUTE_VERSION, 1, buffer);
+ CHECK_RESULT(result);
+ result = net_nfc_create_carrier_config_group (&group, NET_NFC_WIFI_ATTRIBUTE_CREDENTIAL);
+ CHECK_RESULT(result);
+
+ buffer[0] = 0x1;
+ result = net_nfc_add_carrier_config_group_property (group, NET_NFC_WIFI_ATTRIBUTE_NET_INDEX, 1, buffer);
+ CHECK_RESULT(result);
+
+ length = sprintf ((char*)buffer, "%s", SSID);
+ result = net_nfc_add_carrier_config_group_property (group, NET_NFC_WIFI_ATTRIBUTE_SSID, length, buffer);
+ CHECK_RESULT(result);
+
+ *((uint16_t*) buffer ) = 0x20;
+ result = net_nfc_add_carrier_config_group_property (group, NET_NFC_WIFI_ATTRIBUTE_AUTH_TYPE, 2, buffer);
+ CHECK_RESULT(result);
+
+ *((uint16_t*) buffer ) = 0x0008;
+ result = net_nfc_add_carrier_config_group_property (group, NET_NFC_WIFI_ATTRIBUTE_ENC_TYPE, 2, buffer);
+ CHECK_RESULT(result);
+
+ length = sprintf ((char*)buffer, "MyPreSharedKey");
+ result = net_nfc_add_carrier_config_group_property (group, NET_NFC_WIFI_ATTRIBUTE_NET_KEY, length, buffer);
+ CHECK_RESULT(result);
+
+ buffer[0] = 0x00;
+ buffer[1] = 0x07;
+ buffer[2] = 0xE9;
+ buffer[3] = 0x4C;
+ buffer[4] = 0xA8;
+ buffer[5] = 0x1C;
+ result = net_nfc_add_carrier_config_group_property (group, NET_NFC_WIFI_ATTRIBUTE_MAC_ADDR, 6, buffer);
+ CHECK_RESULT(result);
+
+
+ *((uint16_t*) buffer ) = 0x0001;
+ result = net_nfc_add_carrier_config_group_property (group, NET_NFC_WIFI_ATTRIBUTE_CHANNEL, 2, buffer);
+ if (result != NET_NFC_OK) {
+ net_nfc_free_carrier_group(group);
+ }
+ CHECK_RESULT(result);
+
+ buffer[0] = 0x00;
+ buffer[1] = 0x37;
+ buffer[2] = 0x2A;
+ result = net_nfc_add_carrier_config_group_property (group, NET_NFC_WIFI_ATTRIBUTE_VEN_EXT, 3, buffer);
+ if (result != NET_NFC_OK) {
+ net_nfc_free_carrier_group(group);
+ }
+ CHECK_RESULT(result);
+
+ result = net_nfc_append_carrier_config_group (carrier, group);
+ CHECK_RESULT(result);
+
+ buffer[0] = 0x20;
+ result = net_nfc_add_carrier_config_property (carrier, NET_NFC_WIFI_ATTRIBUTE_VERSION2, 1, buffer);
+ CHECK_RESULT(result);
+
+ result = net_nfc_create_ndef_record_with_carrier_config (&carrier_record ,carrier);
+ CHECK_RESULT(result);
+
+ result = net_nfc_free_carrier_config (carrier); /* this free all data include group */
+ CHECK_RESULT(result);
+
+ result = net_nfc_create_handover_request_message (&message);
+ if (result != NET_NFC_OK) {
+ net_nfc_free_record(carrier_record);
+ }
+ CHECK_RESULT(result);
+
+ //net_nfc_ndef_print_message (message);
+
+ result = net_nfc_append_carrier_config_record (message, carrier_record, NET_NFC_CONN_HANDOVER_CARRIER_ACTIVATE);
+ CHECK_RESULT(result);
+
+ //net_nfc_ndef_print_message (message);
+
+
+ // Create BT config
+ result = net_nfc_create_carrier_config (&carrier ,NET_NFC_CONN_HANDOVER_CARRIER_BT);
+ CHECK_RESULT(result);
+
+ buffer[0] = btdev_addr[0];
+ buffer[1] = btdev_addr[1];
+ buffer[2] = btdev_addr[2];
+ buffer[3] = btdev_addr[3];
+ buffer[4] = btdev_addr[4];
+ buffer[5] = btdev_addr[5];
+ if(carrier == NULL){
+ result = NET_NFC_NULL_PARAMETER;
+ }else{
+ result = net_nfc_add_carrier_config_property (carrier ,NET_NFC_BT_ATTRIBUTE_ADDRESS ,6 ,buffer);
+ }
+ CHECK_RESULT(result);
+
+ buffer[0] = 0x08;
+ buffer[1] = 0x06;
+ buffer[2] = 0x20;
+ result = net_nfc_add_carrier_config_property (carrier ,NET_NFC_BT_ATTRIBUTE_OOB_COD ,3 ,buffer);
+ CHECK_RESULT(result);
+
+
+ result = net_nfc_add_carrier_config_property (carrier ,NET_NFC_BT_ATTRIBUTE_OOB_HASH_C ,16 ,buffer);
+ CHECK_RESULT(result);
+
+ result = net_nfc_add_carrier_config_property (carrier ,NET_NFC_BT_ATTRIBUTE_OOB_HASH_R ,16 ,buffer);
+ CHECK_RESULT(result);
+
+ buffer[0] = 0x06;
+ buffer[1] = 0x11;
+ buffer[2] = 0x20;
+ buffer[3] = 0x11;
+ result = net_nfc_add_carrier_config_property (carrier ,NET_NFC_BT_ATTRIBUTE_UUID16 ,4 ,buffer);
+ CHECK_RESULT(result);
+
+ length = sprintf ((char*)buffer, "%s", dev_name);
+ result = net_nfc_add_carrier_config_property (carrier ,NET_NFC_BT_ATTRIBUTE_NAME ,length ,buffer);
+ CHECK_RESULT(result);
+
+ result = net_nfc_create_ndef_record_with_carrier_config (&carrier_record ,carrier);
+ if (result != NET_NFC_OK) {
+ net_nfc_free_carrier_config(carrier);
+ }
+ CHECK_RESULT(result);
+
+ result = net_nfc_append_carrier_config_record (message, carrier_record, NET_NFC_CONN_HANDOVER_CARRIER_ACTIVATING);
+ if (result != NET_NFC_OK) {
+ net_nfc_free_carrier_config(carrier);
+ }
+ CHECK_RESULT(result);
+
+ //net_nfc_ndef_print_message (message);
+
+ result = net_nfc_free_carrier_config (carrier);
+ CHECK_RESULT(result);
+
+ result = net_nfc_get_carrier_config_record (message,0 ,&carrier_record);
+ CHECK_RESULT(result);
+
+ result = net_nfc_create_carrier_config_from_config_record (&carrier ,carrier_record);
+ CHECK_RESULT(result);
+
+ result = net_nfc_get_carrier_config_property (carrier ,NET_NFC_WIFI_ATTRIBUTE_VERSION , (uint16_t*)&length, &pdata);
+ CHECK_RESULT(result);
+ if (pdata[0] != 0x10){
+ PRINT_RESULT_FAIL("FILE:%s, LINE:%d, value %d",__FILE__,__LINE__, pdata[0]);
+ return NET_NFC_TEST_FAIL;
+ }
+
+ result = net_nfc_get_carrier_config_group (carrier ,0 , &group);
+ CHECK_RESULT(result);
+
+ result = net_nfc_get_carrier_config_group_property (group ,NET_NFC_WIFI_ATTRIBUTE_SSID, (uint16_t*)&length, &pdata);
+ CHECK_RESULT(result);
+ if (memcmp (pdata, SSID, length) != 0){
+ PRINT_RESULT_FAIL("FILE:%s, LINE:%d,",__FILE__,__LINE__);
+ return NET_NFC_TEST_FAIL;
+ }
+
+ result = net_nfc_remove_carrier_config_group_property (group,NET_NFC_WIFI_ATTRIBUTE_VEN_EXT);
+ CHECK_RESULT(result);
+
+ result = net_nfc_get_carrier_config_record (message,1 ,&carrier_record);
+ CHECK_RESULT(result);
+
+ result = net_nfc_create_carrier_config_from_config_record (&carrier ,carrier_record);
+ CHECK_RESULT(result);
+
+ result = net_nfc_get_carrier_config_property (carrier ,NET_NFC_BT_ATTRIBUTE_ADDRESS , (uint16_t*)&length, &pdata);
+ CHECK_RESULT(result);
+ if (memcmp (pdata, btdev_addr, length) != 0) {
+ PRINT_RESULT_FAIL("FILE:%s, LINE:%d,",__FILE__,__LINE__);
+ return NET_NFC_TEST_FAIL;
+ }
+
+ result = net_nfc_get_carrier_config_property (carrier ,NET_NFC_BT_ATTRIBUTE_NAME , (uint16_t*)&length, &pdata);
+ CHECK_RESULT(result);
+ if (memcmp (pdata, dev_name, length) != 0){
+ PRINT_RESULT_FAIL("FILE:%s, LINE:%d,",__FILE__,__LINE__);
+ return NET_NFC_TEST_FAIL;
+ }
+
+ result = net_nfc_get_alternative_carrier_record_count (message, &length);
+ CHECK_RESULT(result);
+
+ if (length != 2) {
+ PRINT_RESULT_FAIL("FILE:%s, LINE:%d, count = %d",__FILE__,__LINE__, length);
+ return NET_NFC_TEST_FAIL;
+ }
+
+ net_nfc_conn_handover_carrier_state_e power_state;
+ result = net_nfc_get_alternative_carrier_power_status (message,0 ,&power_state);
+ CHECK_RESULT(result);
+
+ if (power_state != NET_NFC_CONN_HANDOVER_CARRIER_ACTIVATE){
+ PRINT_RESULT_FAIL("FILE:%s, LINE:%d,",__FILE__,__LINE__);
+ return NET_NFC_TEST_FAIL;
+ }
+ result = net_nfc_set_alternative_carrier_power_status (message,1 ,NET_NFC_CONN_HANDOVER_CARRIER_INACTIVATE);
+ CHECK_RESULT(result);
+
+ result = net_nfc_get_alternative_carrier_power_status (message,1 ,&power_state);
+ CHECK_RESULT(result);
+
+ if (power_state != NET_NFC_CONN_HANDOVER_CARRIER_INACTIVATE){
+ PRINT_RESULT_FAIL("FILE:%s, LINE:%d, status = %d",__FILE__,__LINE__, power_state);
+ return NET_NFC_TEST_FAIL;
+ }
+
+ net_nfc_conn_handover_carrier_type_e ctype;
+ result = net_nfc_get_alternative_carrier_type (message, 0 , &ctype);
+
+ if (ctype != NET_NFC_CONN_HANDOVER_CARRIER_WIFI_BSS){
+ PRINT_RESULT_FAIL("FILE:%s, LINE:%d,",__FILE__,__LINE__);
+ return NET_NFC_TEST_FAIL;
+ }
+
+ unsigned short r_num;
+ result = net_nfc_get_handover_random_number (message, &r_num);
+
+ result = net_nfc_get_carrier_config_record (message,0 ,&carrier_record);
+ CHECK_RESULT(result);
+
+ result = net_nfc_remove_carrier_config_record (message, carrier_record);
+ CHECK_RESULT(result);
+
+ result = net_nfc_get_carrier_config_record (message,0 ,&carrier_record);
+ CHECK_RESULT(result);
+
+ result = net_nfc_create_carrier_config_from_config_record (&carrier ,carrier_record);
+ CHECK_RESULT(result);
+
+ result = net_nfc_get_carrier_config_property (carrier ,NET_NFC_BT_ATTRIBUTE_ADDRESS, (uint16_t*)&length, &pdata);
+ CHECK_RESULT(result);
+ if (memcmp (pdata, btdev_addr, length) != 0) {
+ PRINT_RESULT_FAIL("FILE:%s, LINE:%d,",__FILE__,__LINE__);
+ return NET_NFC_TEST_FAIL;
+ }
+
+ result = net_nfc_get_carrier_config_property (carrier ,NET_NFC_BT_ATTRIBUTE_NAME , (uint16_t*)&length, &pdata);
+ CHECK_RESULT(result);
+ if (memcmp (pdata, dev_name, length) != 0){
+ PRINT_RESULT_FAIL("FILE:%s, LINE:%d,",__FILE__,__LINE__);
+ return NET_NFC_TEST_FAIL;
+ }
+
+ result = net_nfc_get_alternative_carrier_record_count (message, &length);
+ CHECK_RESULT(result);
+
+ if (length != 1) {
+ PRINT_RESULT_FAIL("FILE:%s, LINE:%d,",__FILE__,__LINE__);
+ return NET_NFC_TEST_FAIL;
+ }
+
+ result = net_nfc_get_alternative_carrier_power_status (message,0 ,&power_state);
+ CHECK_RESULT(result);
+
+ if (power_state != NET_NFC_CONN_HANDOVER_CARRIER_INACTIVATE){
+ PRINT_RESULT_FAIL("FILE:%s, LINE:%d,",__FILE__,__LINE__);
+ return NET_NFC_TEST_FAIL;
+ }
+
+ result = net_nfc_get_alternative_carrier_type (message, 0 , &ctype);
+
+ if (ctype != NET_NFC_CONN_HANDOVER_CARRIER_BT){
+ PRINT_RESULT_FAIL("FILE:%s, LINE:%d,",__FILE__,__LINE__);
+ return NET_NFC_TEST_FAIL;
+ }
+
+ //net_nfc_ndef_print_message (message);
+
+ return NET_NFC_TEST_OK;
+
+}
+
+/*=================================================================================*/
+
+
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NFC_API_TEST_H__
+#define __NFC_API_TEST_H__
+
+typedef enum {
+ NET_NFC_TEST_NOT_YET,
+ NET_NFC_TEST_OK,
+ NET_NFC_TEST_FAIL,
+}net_nfc_test_result_e;
+
+
+#define LOG_COLOR_RED "\033[0;31m"
+#define LOG_COLOR_GREEN "\033[0;32m"
+#define LOG_COLOR_BROWN "\033[0;33m"
+#define LOG_COLOR_BLUE "\033[0;34m"
+#define LOG_COLOR_PURPLE "\033[0;35m"
+#define LOG_COLOR_CYAN "\033[0;36m"
+#define LOG_COLOR_LIGHTBLUE "\033[0;37m"
+#define LOG_COLOR_END "\033[0;m"
+
+#define PRINT_INSTRUCT(format,args...) \
+do {\
+ printf(LOG_COLOR_BLUE""format""LOG_COLOR_END"\n", ##args);\
+}while(0);
+
+#define PRINT_RESULT_FAIL(format,args...) \
+do {\
+ printf(LOG_COLOR_RED""format""LOG_COLOR_END"\n", ##args);\
+}while(0);
+
+#define PRINT_RESULT_SUCCESS(format,args...) \
+do {\
+ printf(LOG_COLOR_GREEN""format""LOG_COLOR_END"\n", ##args);\
+}while(0);
+
+#define PRINT_INFO(format,args...) \
+do {\
+ printf(format"\n", ##args);\
+}while(0);
+
+
+#define CHECK_RESULT(X)\
+ do{\
+ if(X!=NET_NFC_OK){\
+ PRINT_RESULT_FAIL("FILE:%s, LINE:%d, RESULT:%d",__FILE__,__LINE__,X);\
+ return NET_NFC_TEST_FAIL;\
+ }\
+ }while(0)
+
+
+#define CHECK_ASSULT(X)\
+ do{\
+ if(!(X)){\
+ PRINT_RESULT_FAIL("FILE:%s, LINE:%d, RESULT:%d",__FILE__,__LINE__,X);\
+ return NET_NFC_TEST_FAIL;\
+ }\
+ }while(0)
+
+/* struct defines */
+typedef int nfcTestStartFn_t(uint8_t testNumber,void* arg_ptr2);
+
+typedef struct
+{
+ char* testName;
+ nfcTestStartFn_t* testFn;
+ uint8_t testResult;
+} nfcTestType;
+
+#endif //__NFC_API_TEST_H__
\ No newline at end of file